Mercurial > hg
annotate hgext/relink.py @ 9735:97d0d910fa5d
minirst: remove unnecessary "elif:" statements
author | Martin Geisler <mg@lazybytes.net> |
---|---|
date | Thu, 05 Nov 2009 21:30:50 +0100 |
parents | aa9ccab5af37 |
children | 819e6c7085fc |
rev | line source |
---|---|
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
1 # Mercurial extension to provide 'hg relink' command |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
2 # |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
3 # Copyright (C) 2007 Brendan Cully <brendan@kublai.com> |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
4 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
4270
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
4270
diff
changeset
|
6 # GNU General Public License version 2, incorporated herein by reference. |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
7 |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
8 """recreates hardlinks between repository clones""" |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
9 |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
10 from mercurial import cmdutil, hg, util |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
11 from mercurial.i18n import _ |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
12 import os, stat |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
13 |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
14 def relink(ui, repo, origin=None, **opts): |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
15 """recreate hardlinks between two repositories |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
16 |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
17 When repositories are cloned locally, their data files will be hardlinked |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
18 so that they only use the space of a single repository. |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
19 |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
20 Unfortunately, subsequent pulls into either repository will break hardlinks |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
21 for any files touched by the new changesets, even if both repositories end |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
22 up pulling the same changes. |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
23 |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
24 Similarly, passing --rev to "hg clone" will fail to use |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
25 any hardlinks, falling back to a complete copy of the source repository. |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
26 |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
27 This command lets you recreate those hardlinks and reclaim that wasted |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
28 space. |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
29 |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
30 This repository will be relinked to share space with ORIGIN, which must be |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
31 on the same local disk. If ORIGIN is omitted, looks for "default-relink", |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
32 then "default", in [paths]. |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
33 |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
34 Do not attempt any read operations on this repository while the command is |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
35 running. (Both repositories will be locked against writes.) |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
36 """ |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
37 src = hg.repository( |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
38 cmdutil.remoteui(repo, opts), |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
39 ui.expandpath(origin or 'default-relink', origin or 'default')) |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
40 if not src.local(): |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
41 raise util.Abort('must specify local origin repository') |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
42 ui.status(_('relinking %s to %s\n') % (src.store.path, repo.store.path)) |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
43 locallock = repo.lock() |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
44 try: |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
45 remotelock = src.lock() |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
46 try: |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
47 candidates = collect(src.store.path, ui) |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
48 targets = prune(candidates, repo.store.path, ui) |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
49 do_relink(src.store.path, repo.store.path, targets, ui) |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
50 finally: |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
51 remotelock.release() |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
52 finally: |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
53 locallock.release() |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
54 |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
55 def collect(src, ui): |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
56 seplen = len(os.path.sep) |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
57 candidates = [] |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
58 for dirpath, dirnames, filenames in os.walk(src): |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
59 relpath = dirpath[len(src) + seplen:] |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
60 for filename in filenames: |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
61 if not filename[-2:] in ('.d', '.i'): |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
62 continue |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
63 st = os.stat(os.path.join(dirpath, filename)) |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
64 if not stat.S_ISREG(st.st_mode): |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
65 continue |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
66 candidates.append((os.path.join(relpath, filename), st)) |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
67 |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
68 ui.status(_('collected %d candidate storage files\n') % len(candidates)) |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
69 return candidates |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
70 |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
71 def prune(candidates, dst, ui): |
4270
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
72 def linkfilter(dst, st): |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
73 try: |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
74 ts = os.stat(dst) |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
75 except OSError: |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
76 # Destination doesn't have this file? |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
77 return False |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
78 if st.st_ino == ts.st_ino: |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
79 return False |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
80 if st.st_dev != ts.st_dev: |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
81 # No point in continuing |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
82 raise util.Abort( |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
83 _('source and destination are on different devices')) |
4270
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
84 if st.st_size != ts.st_size: |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
85 return False |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
86 return st |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
87 |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
88 targets = [] |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
89 for fn, st in candidates: |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
90 tgt = os.path.join(dst, fn) |
4270
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
91 ts = linkfilter(tgt, st) |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
92 if not ts: |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
93 ui.debug(_('not linkable: %s\n') % fn) |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
94 continue |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
95 targets.append((fn, ts.st_size)) |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
96 |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
97 ui.status(_('pruned down to %d probably relinkable files\n') % len(targets)) |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
98 return targets |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
99 |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
100 def do_relink(src, dst, files, ui): |
4270
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
101 def relinkfile(src, dst): |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
102 bak = dst + '.bak' |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
103 os.rename(dst, bak) |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
104 try: |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
105 os.link(src, dst) |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
106 except OSError: |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
107 os.rename(bak, dst) |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
108 raise |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
109 os.remove(bak) |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
110 |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
111 CHUNKLEN = 65536 |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
112 relinked = 0 |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
113 savedbytes = 0 |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
114 |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
115 pos = 0 |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
116 total = len(files) |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
117 for f, sz in files: |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
118 pos += 1 |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
119 source = os.path.join(src, f) |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
120 tgt = os.path.join(dst, f) |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
121 sfp = file(source) |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
122 dfp = file(tgt) |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
123 sin = sfp.read(CHUNKLEN) |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
124 while sin: |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
125 din = dfp.read(CHUNKLEN) |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
126 if sin != din: |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
127 break |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
128 sin = sfp.read(CHUNKLEN) |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
129 if sin: |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
130 ui.debug(_('not linkable: %s\n') % f) |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
131 continue |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
132 try: |
4270
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
133 relinkfile(source, tgt) |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
134 ui.progress(_('relink'), pos, f, _(' files'), total) |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
135 relinked += 1 |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
136 savedbytes += sz |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
137 except OSError, inst: |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
138 ui.warn(_('%s: %s\n') % (tgt, str(inst))) |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
139 |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
140 ui.status(_('relinked %d files (%d bytes reclaimed)\n') % |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
141 (relinked, savedbytes)) |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
142 |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
143 cmdtable = { |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
144 'relink': ( |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
145 relink, |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
146 [], |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
147 _('[ORIGIN]') |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
148 ) |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
149 } |