Mercurial > hg
annotate hgext/relink.py @ 16719:e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
For the PyPy repo with 744 branches and 843 branch heads, this brings
hg log -r default over NFS from:
CallCount Recursive Total(ms) Inline(ms) module:lineno(function)
3249 0 1.3222 1.3222 <open>
3244 0 0.6211 0.6211 <method 'close' of 'file' objects>
3243 0 0.0800 0.0800 <method 'read' of 'file' objects>
3241 0 0.0660 0.0660 <method 'seek' of 'file' objects>
3905 0 0.0476 0.0476 <zlib.decompress>
3281 0 2.6756 0.0472 mercurial.changelog:182(read)
+3281 0 2.5256 0.0453 +mercurial.revlog:881(revision)
+3276 0 0.0389 0.0196 +mercurial.changelog:28(decodeextra)
+6562 0 0.0123 0.0123 +<method 'split' of 'str' objects>
+6562 0 0.0408 0.0073 +mercurial.encoding:61(tolocal)
+3281 0 0.0054 0.0054 +<method 'index' of 'str' objects>
3241 0 2.2464 0.0456 mercurial.revlog:818(_loadchunk)
+3241 0 0.6205 0.6205 +<method 'close' of 'file' objects>
+3241 0 0.0765 0.0765 +<method 'read' of 'file' objects>
+3241 0 0.0660 0.0660 +<method 'seek' of 'file' objects>
+3241 0 1.4209 0.0135 +mercurial.store:374(__call__)
+3241 0 0.0122 0.0107 +mercurial.revlog:810(_addchunk)
3281 0 2.5256 0.0453 mercurial.revlog:881(revision)
+3280 0 0.0175 0.0175 +mercurial.revlog:305(rev)
+3281 0 2.2819 0.0119 +mercurial.revlog:847(_chunkraw)
+3281 0 0.0603 0.0083 +mercurial.revlog:945(_checkhash)
+3281 0 0.0051 0.0051 +mercurial.revlog:349(flags)
+3281 0 0.0040 0.0040 +<mercurial.mpatch.patches>
13682 0 0.0479 0.0248 <method 'decode' of 'str' objects>
+7418 0 0.0228 0.0076 +encodings.utf_8:15(decode)
+1 0 0.0003 0.0000 +encodings:71(search_function)
3248 0 1.3995 0.0246 mercurial.scmutil:218(__call__)
+3248 0 1.3222 1.3222 +<open>
+3248 0 0.0235 0.0184 +os.path:80(split)
+3248 0 0.0084 0.0068 +mercurial.scmutil:92(__call__)
Time: real 2.750 secs (user 0.680+0.000 sys 0.360+0.000)
down to:
CallCount Recursive Total(ms) Inline(ms) module:lineno(function)
55 31 0.0197 0.0163 <__import__>
+1 0 0.0006 0.0002 +mercurial.context:8(<module>)
+1 0 0.0042 0.0001 +mercurial.revlog:12(<module>)
+1 0 0.0002 0.0001 +mercurial.match:8(<module>)
+1 0 0.0003 0.0001 +mercurial.dirstate:7(<module>)
+1 0 0.0057 0.0001 +mercurial.changelog:8(<module>)
1 0 0.0117 0.0032 mercurial.localrepo:525(_readbranchcache)
+844 0 0.0015 0.0015 +<binascii.unhexlify>
+845 0 0.0010 0.0010 +<method 'split' of 'str' objects>
+843 0 0.0045 0.0009 +mercurial.encoding:61(tolocal)
+843 0 0.0004 0.0004 +<method 'setdefault' of 'dict' objects>
+1 0 0.0003 0.0003 +<method 'close' of 'file' objects>
3 0 0.0029 0.0029 <method 'read' of 'file' objects>
9 0 0.0018 0.0018 <open>
990 0 0.0017 0.0017 <binascii.unhexlify>
53 0 0.0016 0.0016 mercurial.demandimport:43(__init__)
862 0 0.0015 0.0015 <_codecs.utf_8_decode>
862 0 0.0037 0.0014 <method 'decode' of 'str' objects>
+862 0 0.0023 0.0008 +encodings.utf_8:15(decode)
981 0 0.0011 0.0011 <method 'split' of 'str' objects>
861 0 0.0046 0.0009 mercurial.encoding:61(tolocal)
+861 0 0.0037 0.0014 +<method 'decode' of 'str' objects>
862 0 0.0023 0.0008 encodings.utf_8:15(decode)
+862 0 0.0015 0.0015 +<_codecs.utf_8_decode>
4 0 0.0008 0.0008 <method 'close' of 'file' objects>
179 154 0.0202 0.0004 mercurial.demandimport:83(__getattribute__)
+36 11 0.0199 0.0003 +mercurial.demandimport:55(_load)
+72 0 0.0001 0.0001 +mercurial.demandimport:83(__getattribute__)
+36 0 0.0000 0.0000 +<getattr>
1 0 0.0015 0.0004 mercurial.tags:148(_readtagcache)
Time: real 0.060 secs (user 0.030+0.000 sys 0.010+0.000)
author | Brodie Rao <brodie@sf.io> |
---|---|
date | Sun, 13 May 2012 14:04:04 +0200 |
parents | 67964cda8701 |
children | 38caf405d010 |
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 |
10263 | 6 # GNU General Public License version 2 or any later version. |
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 |
12062
c327bfa5e831
cleanup: remove unused imports
Brodie Rao <brodie@bitheap.org>
parents:
11357
diff
changeset
|
10 from mercurial import hg, util |
9729
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 |
9886
56af3f240a22
relink: wrap long lines in docstring
Martin Geisler <mg@lazybytes.net>
parents:
9790
diff
changeset
|
17 When repositories are cloned locally, their data files will be |
56af3f240a22
relink: wrap long lines in docstring
Martin Geisler <mg@lazybytes.net>
parents:
9790
diff
changeset
|
18 hardlinked so that they only use the space of a single repository. |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
19 |
9886
56af3f240a22
relink: wrap long lines in docstring
Martin Geisler <mg@lazybytes.net>
parents:
9790
diff
changeset
|
20 Unfortunately, subsequent pulls into either repository will break |
56af3f240a22
relink: wrap long lines in docstring
Martin Geisler <mg@lazybytes.net>
parents:
9790
diff
changeset
|
21 hardlinks for any files touched by the new changesets, even if |
56af3f240a22
relink: wrap long lines in docstring
Martin Geisler <mg@lazybytes.net>
parents:
9790
diff
changeset
|
22 both repositories end up pulling the same changes. |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
23 |
9886
56af3f240a22
relink: wrap long lines in docstring
Martin Geisler <mg@lazybytes.net>
parents:
9790
diff
changeset
|
24 Similarly, passing --rev to "hg clone" will fail to use any |
56af3f240a22
relink: wrap long lines in docstring
Martin Geisler <mg@lazybytes.net>
parents:
9790
diff
changeset
|
25 hardlinks, falling back to a complete copy of the source |
56af3f240a22
relink: wrap long lines in docstring
Martin Geisler <mg@lazybytes.net>
parents:
9790
diff
changeset
|
26 repository. |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
27 |
9886
56af3f240a22
relink: wrap long lines in docstring
Martin Geisler <mg@lazybytes.net>
parents:
9790
diff
changeset
|
28 This command lets you recreate those hardlinks and reclaim that |
56af3f240a22
relink: wrap long lines in docstring
Martin Geisler <mg@lazybytes.net>
parents:
9790
diff
changeset
|
29 wasted space. |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
30 |
9886
56af3f240a22
relink: wrap long lines in docstring
Martin Geisler <mg@lazybytes.net>
parents:
9790
diff
changeset
|
31 This repository will be relinked to share space with ORIGIN, which |
56af3f240a22
relink: wrap long lines in docstring
Martin Geisler <mg@lazybytes.net>
parents:
9790
diff
changeset
|
32 must be on the same local disk. If ORIGIN is omitted, looks for |
56af3f240a22
relink: wrap long lines in docstring
Martin Geisler <mg@lazybytes.net>
parents:
9790
diff
changeset
|
33 "default-relink", then "default", in [paths]. |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
34 |
9886
56af3f240a22
relink: wrap long lines in docstring
Martin Geisler <mg@lazybytes.net>
parents:
9790
diff
changeset
|
35 Do not attempt any read operations on this repository while the |
56af3f240a22
relink: wrap long lines in docstring
Martin Geisler <mg@lazybytes.net>
parents:
9790
diff
changeset
|
36 command is running. (Both repositories will be locked against |
56af3f240a22
relink: wrap long lines in docstring
Martin Geisler <mg@lazybytes.net>
parents:
9790
diff
changeset
|
37 writes.) |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
38 """ |
14945
11aad09a6370
hgext: replace uses of hasattr with util.safehasattr
Augie Fackler <durin42@gmail.com>
parents:
14709
diff
changeset
|
39 if (not util.safehasattr(util, 'samefile') or |
11aad09a6370
hgext: replace uses of hasattr with util.safehasattr
Augie Fackler <durin42@gmail.com>
parents:
14709
diff
changeset
|
40 not util.safehasattr(util, 'samedevice')): |
10218
750b7a4f01f6
Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents:
9790
diff
changeset
|
41 raise util.Abort(_('hardlinks are not supported on this system')) |
14556
517e1d88bf7e
hg: change various repository() users to use peer() where appropriate
Matt Mackall <mpm@selenic.com>
parents:
14235
diff
changeset
|
42 src = hg.repository(ui, ui.expandpath(origin or 'default-relink', |
517e1d88bf7e
hg: change various repository() users to use peer() where appropriate
Matt Mackall <mpm@selenic.com>
parents:
14235
diff
changeset
|
43 origin or 'default')) |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
44 if not src.local(): |
13658
6cc306093b99
relink: mark abort message for translation
Martin Geisler <mg@lazybytes.net>
parents:
13657
diff
changeset
|
45 raise util.Abort(_('must specify local origin repository')) |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
46 ui.status(_('relinking %s to %s\n') % (src.store.path, repo.store.path)) |
13657
b69102740e57
relink: avoid trying to lock the same repo twice
Martin Geisler <mg@lazybytes.net>
parents:
12744
diff
changeset
|
47 if repo.root == src.root: |
b69102740e57
relink: avoid trying to lock the same repo twice
Martin Geisler <mg@lazybytes.net>
parents:
12744
diff
changeset
|
48 ui.status(_('there is nothing to relink\n')) |
b69102740e57
relink: avoid trying to lock the same repo twice
Martin Geisler <mg@lazybytes.net>
parents:
12744
diff
changeset
|
49 return |
b69102740e57
relink: avoid trying to lock the same repo twice
Martin Geisler <mg@lazybytes.net>
parents:
12744
diff
changeset
|
50 |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
51 locallock = repo.lock() |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
52 try: |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
53 remotelock = src.lock() |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
54 try: |
11355
9011036ba79d
relink/progress: Adding progress for collecting stage
timeless <timeless@gmail.com>
parents:
11354
diff
changeset
|
55 candidates = sorted(collect(src, ui)) |
10218
750b7a4f01f6
Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents:
9790
diff
changeset
|
56 targets = prune(candidates, src.store.path, repo.store.path, ui) |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
57 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
|
58 finally: |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
59 remotelock.release() |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
60 finally: |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
61 locallock.release() |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
62 |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
63 def collect(src, ui): |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
64 seplen = len(os.path.sep) |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
65 candidates = [] |
11355
9011036ba79d
relink/progress: Adding progress for collecting stage
timeless <timeless@gmail.com>
parents:
11354
diff
changeset
|
66 live = len(src['tip'].manifest()) |
9011036ba79d
relink/progress: Adding progress for collecting stage
timeless <timeless@gmail.com>
parents:
11354
diff
changeset
|
67 # Your average repository has some files which were deleted before |
9011036ba79d
relink/progress: Adding progress for collecting stage
timeless <timeless@gmail.com>
parents:
11354
diff
changeset
|
68 # the tip revision. We account for that by assuming that there are |
9011036ba79d
relink/progress: Adding progress for collecting stage
timeless <timeless@gmail.com>
parents:
11354
diff
changeset
|
69 # 3 tracked files for every 2 live files as of the tip version of |
9011036ba79d
relink/progress: Adding progress for collecting stage
timeless <timeless@gmail.com>
parents:
11354
diff
changeset
|
70 # the repository. |
9011036ba79d
relink/progress: Adding progress for collecting stage
timeless <timeless@gmail.com>
parents:
11354
diff
changeset
|
71 # |
9011036ba79d
relink/progress: Adding progress for collecting stage
timeless <timeless@gmail.com>
parents:
11354
diff
changeset
|
72 # mozilla-central as of 2010-06-10 had a ratio of just over 7:5. |
9011036ba79d
relink/progress: Adding progress for collecting stage
timeless <timeless@gmail.com>
parents:
11354
diff
changeset
|
73 total = live * 3 // 2 |
9011036ba79d
relink/progress: Adding progress for collecting stage
timeless <timeless@gmail.com>
parents:
11354
diff
changeset
|
74 src = src.store.path |
9011036ba79d
relink/progress: Adding progress for collecting stage
timeless <timeless@gmail.com>
parents:
11354
diff
changeset
|
75 pos = 0 |
9011036ba79d
relink/progress: Adding progress for collecting stage
timeless <timeless@gmail.com>
parents:
11354
diff
changeset
|
76 ui.status(_("tip has %d files, estimated total number of files: %s\n") |
9011036ba79d
relink/progress: Adding progress for collecting stage
timeless <timeless@gmail.com>
parents:
11354
diff
changeset
|
77 % (live, total)) |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
78 for dirpath, dirnames, filenames in os.walk(src): |
11357
7914628b4751
relink: ensure deterministic directory walk in collect
Martin Geisler <mg@aragost.com>
parents:
11355
diff
changeset
|
79 dirnames.sort() |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
80 relpath = dirpath[len(src) + seplen:] |
11357
7914628b4751
relink: ensure deterministic directory walk in collect
Martin Geisler <mg@aragost.com>
parents:
11355
diff
changeset
|
81 for filename in sorted(filenames): |
16686
67964cda8701
cleanup: "not x in y" -> "x not in y"
Brodie Rao <brodie@sf.io>
parents:
14945
diff
changeset
|
82 if filename[-2:] not in ('.d', '.i'): |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
83 continue |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
84 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
|
85 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
|
86 continue |
11355
9011036ba79d
relink/progress: Adding progress for collecting stage
timeless <timeless@gmail.com>
parents:
11354
diff
changeset
|
87 pos += 1 |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
88 candidates.append((os.path.join(relpath, filename), st)) |
11355
9011036ba79d
relink/progress: Adding progress for collecting stage
timeless <timeless@gmail.com>
parents:
11354
diff
changeset
|
89 ui.progress(_('collecting'), pos, filename, _('files'), total) |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
90 |
11355
9011036ba79d
relink/progress: Adding progress for collecting stage
timeless <timeless@gmail.com>
parents:
11354
diff
changeset
|
91 ui.progress(_('collecting'), None) |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
92 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
|
93 return candidates |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
94 |
10218
750b7a4f01f6
Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents:
9790
diff
changeset
|
95 def prune(candidates, src, dst, ui): |
750b7a4f01f6
Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents:
9790
diff
changeset
|
96 def linkfilter(src, dst, st): |
4270
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
97 try: |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
98 ts = os.stat(dst) |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
99 except OSError: |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
100 # Destination doesn't have this file? |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
101 return False |
10218
750b7a4f01f6
Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents:
9790
diff
changeset
|
102 if util.samefile(src, dst): |
4270
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
103 return False |
10218
750b7a4f01f6
Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents:
9790
diff
changeset
|
104 if not util.samedevice(src, dst): |
4270
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
105 # 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
|
106 raise util.Abort( |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
107 _('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
|
108 if st.st_size != ts.st_size: |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
109 return False |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
110 return st |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
111 |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
112 targets = [] |
11354
412a6e749f8d
relink/progress: Adding progress for pruning stage
timeless <timeless@gmail.com>
parents:
11273
diff
changeset
|
113 total = len(candidates) |
412a6e749f8d
relink/progress: Adding progress for pruning stage
timeless <timeless@gmail.com>
parents:
11273
diff
changeset
|
114 pos = 0 |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
115 for fn, st in candidates: |
11354
412a6e749f8d
relink/progress: Adding progress for pruning stage
timeless <timeless@gmail.com>
parents:
11273
diff
changeset
|
116 pos += 1 |
10218
750b7a4f01f6
Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents:
9790
diff
changeset
|
117 srcpath = os.path.join(src, fn) |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
118 tgt = os.path.join(dst, fn) |
10218
750b7a4f01f6
Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents:
9790
diff
changeset
|
119 ts = linkfilter(srcpath, tgt, st) |
4270
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
120 if not ts: |
14709
6c7283faa967
check-code: don't mark debug messages for translation
Matt Mackall <mpm@selenic.com>
parents:
14556
diff
changeset
|
121 ui.debug('not linkable: %s\n' % fn) |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
122 continue |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
123 targets.append((fn, ts.st_size)) |
12744
0793d763e413
progress: dropping superfluous space from units
timeless <timeless@gmail.com>
parents:
12062
diff
changeset
|
124 ui.progress(_('pruning'), pos, fn, _('files'), total) |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
125 |
11354
412a6e749f8d
relink/progress: Adding progress for pruning stage
timeless <timeless@gmail.com>
parents:
11273
diff
changeset
|
126 ui.progress(_('pruning'), None) |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
127 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
|
128 return targets |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
129 |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
130 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
|
131 def relinkfile(src, dst): |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
132 bak = dst + '.bak' |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
133 os.rename(dst, bak) |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
134 try: |
14235
b9e1b041744f
rename util.os_link to oslink
Adrian Buehlmann <adrian@cadifra.com>
parents:
13898
diff
changeset
|
135 util.oslink(src, dst) |
4270
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
136 except OSError: |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
137 os.rename(bak, dst) |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
138 raise |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
139 os.remove(bak) |
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
140 |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
141 CHUNKLEN = 65536 |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
142 relinked = 0 |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
143 savedbytes = 0 |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
144 |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
145 pos = 0 |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
146 total = len(files) |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
147 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
|
148 pos += 1 |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
149 source = os.path.join(src, f) |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
150 tgt = os.path.join(dst, f) |
10218
750b7a4f01f6
Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents:
9790
diff
changeset
|
151 # Binary mode, so that read() works correctly, especially on Windows |
750b7a4f01f6
Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents:
9790
diff
changeset
|
152 sfp = file(source, 'rb') |
750b7a4f01f6
Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents:
9790
diff
changeset
|
153 dfp = file(tgt, 'rb') |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
154 sin = sfp.read(CHUNKLEN) |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
155 while sin: |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
156 din = dfp.read(CHUNKLEN) |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
157 if sin != din: |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
158 break |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
159 sin = sfp.read(CHUNKLEN) |
10218
750b7a4f01f6
Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents:
9790
diff
changeset
|
160 sfp.close() |
750b7a4f01f6
Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents:
9790
diff
changeset
|
161 dfp.close() |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
162 if sin: |
14709
6c7283faa967
check-code: don't mark debug messages for translation
Matt Mackall <mpm@selenic.com>
parents:
14556
diff
changeset
|
163 ui.debug('not linkable: %s\n' % f) |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
164 continue |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
165 try: |
4270
29eb88bd5c8d
hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents:
4249
diff
changeset
|
166 relinkfile(source, tgt) |
12744
0793d763e413
progress: dropping superfluous space from units
timeless <timeless@gmail.com>
parents:
12062
diff
changeset
|
167 ui.progress(_('relinking'), pos, f, _('files'), total) |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
168 relinked += 1 |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
169 savedbytes += sz |
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
170 except OSError, inst: |
9790
819e6c7085fc
relink: do not translate format string with no text
Martin Geisler <mg@lazybytes.net>
parents:
9729
diff
changeset
|
171 ui.warn('%s: %s\n' % (tgt, str(inst))) |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
172 |
10724
cb0a7faa29ea
progress: drop extra args for pos=None calls (issue2087)
Matt Mackall <mpm@selenic.com>
parents:
10698
diff
changeset
|
173 ui.progress(_('relinking'), None) |
10424
93b5abcf5101
relink: properly use the progress API
Augie Fackler <durin42@gmail.com>
parents:
10264
diff
changeset
|
174 |
13656
0e200e1801f4
relink: format reclaimed byte count nicely
Martin Geisler <mg@lazybytes.net>
parents:
12744
diff
changeset
|
175 ui.status(_('relinked %d files (%s reclaimed)\n') % |
0e200e1801f4
relink: format reclaimed byte count nicely
Martin Geisler <mg@lazybytes.net>
parents:
12744
diff
changeset
|
176 (relinked, util.bytecount(savedbytes))) |
4249
7663780b55a7
Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
177 |
9729
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
178 cmdtable = { |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
179 'relink': ( |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
180 relink, |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
181 [], |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
182 _('[ORIGIN]') |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
183 ) |
aa9ccab5af37
Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents:
8225
diff
changeset
|
184 } |