Mercurial > hg
annotate contrib/shrink-revlog.py @ 10622:bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
author | Greg Ward <greg-hg@gerg.ca> |
---|---|
date | Thu, 25 Feb 2010 09:16:39 -0500 |
parents | c93f0a23f381 |
children | 64e286c22f29 |
rev | line source |
---|---|
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
2 |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
3 """\ |
10236
49a8625b8cac
shrink-revlog: help/doc tweaks
Greg Ward <greg-hg@gerg.ca>
parents:
10234
diff
changeset
|
4 reorder a revlog (the manifest by default) to save space |
49a8625b8cac
shrink-revlog: help/doc tweaks
Greg Ward <greg-hg@gerg.ca>
parents:
10234
diff
changeset
|
5 |
49a8625b8cac
shrink-revlog: help/doc tweaks
Greg Ward <greg-hg@gerg.ca>
parents:
10234
diff
changeset
|
6 Specifically, this topologically sorts the revisions in the revlog so that |
49a8625b8cac
shrink-revlog: help/doc tweaks
Greg Ward <greg-hg@gerg.ca>
parents:
10234
diff
changeset
|
7 revisions on the same branch are adjacent as much as possible. This is a |
49a8625b8cac
shrink-revlog: help/doc tweaks
Greg Ward <greg-hg@gerg.ca>
parents:
10234
diff
changeset
|
8 workaround for the fact that Mercurial computes deltas relative to the |
10216
843f6ee6d14b
contrib: small documentation fixes in shrink-revlog.py
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10215
diff
changeset
|
9 previous revision rather than relative to a parent revision. |
843f6ee6d14b
contrib: small documentation fixes in shrink-revlog.py
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10215
diff
changeset
|
10 |
843f6ee6d14b
contrib: small documentation fixes in shrink-revlog.py
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10215
diff
changeset
|
11 This is *not* safe to run on a changelog. |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
12 """ |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
13 |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
14 # Originally written by Benoit Boissinot <benoit.boissinot at ens-lyon.org> |
10216
843f6ee6d14b
contrib: small documentation fixes in shrink-revlog.py
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10215
diff
changeset
|
15 # as a patch to rewrite-log. Cleaned up, refactored, documented, and |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
16 # renamed by Greg Ward <greg at gerg.ca>. |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
17 |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
18 # XXX would be nice to have a way to verify the repository after shrinking, |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
19 # e.g. by comparing "before" and "after" states of random changesets |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
20 # (maybe: export before, shrink, export after, diff). |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
21 |
10542
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
22 import os, tempfile, errno |
10509
3e7e789d9494
shrink-revlog: remove unneeded imports and useless code
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10508
diff
changeset
|
23 from mercurial import revlog, transaction, node, util |
10009
69dca8574a6a
shrink-revlog: improve performance: use changegroup instead of revisions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9712
diff
changeset
|
24 from mercurial import changegroup |
10508
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
25 from mercurial.i18n import _ |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
26 |
10622
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
27 def toposort_branchsort(ui, rl): |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
28 |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
29 children = {} |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
30 root = [] |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
31 # build children and roots |
10508
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
32 ui.status(_('reading revs\n')) |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
33 try: |
10621
c93f0a23f381
shrink-revlog: rename some local variables for consistency.
Greg Ward <greg-hg@gerg.ca>
parents:
10620
diff
changeset
|
34 for rev in rl: |
c93f0a23f381
shrink-revlog: rename some local variables for consistency.
Greg Ward <greg-hg@gerg.ca>
parents:
10620
diff
changeset
|
35 ui.progress(_('reading'), rev, total=len(rl)) |
c93f0a23f381
shrink-revlog: rename some local variables for consistency.
Greg Ward <greg-hg@gerg.ca>
parents:
10620
diff
changeset
|
36 children[rev] = [] |
c93f0a23f381
shrink-revlog: rename some local variables for consistency.
Greg Ward <greg-hg@gerg.ca>
parents:
10620
diff
changeset
|
37 parents = [p for p in rl.parentrevs(rev) if p != node.nullrev] |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
38 # in case of duplicate parents |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
39 if len(parents) == 2 and parents[0] == parents[1]: |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
40 del parents[1] |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
41 for p in parents: |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
42 assert p in children |
10621
c93f0a23f381
shrink-revlog: rename some local variables for consistency.
Greg Ward <greg-hg@gerg.ca>
parents:
10620
diff
changeset
|
43 children[p].append(rev) |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
44 |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
45 if len(parents) == 0: |
10621
c93f0a23f381
shrink-revlog: rename some local variables for consistency.
Greg Ward <greg-hg@gerg.ca>
parents:
10620
diff
changeset
|
46 root.append(rev) |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
47 finally: |
10496
45734b51c99b
progress: mark strings for translation
Martin Geisler <mg@lazybytes.net>
parents:
10440
diff
changeset
|
48 ui.progress(_('reading'), None, total=len(rl)) |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
49 |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
50 # XXX this is a reimplementation of the 'branchsort' topo sort |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
51 # algorithm in hgext.convert.convcmd... would be nice not to duplicate |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
52 # the algorithm |
10508
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
53 ui.status(_('sorting revs\n')) |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
54 visit = root |
10621
c93f0a23f381
shrink-revlog: rename some local variables for consistency.
Greg Ward <greg-hg@gerg.ca>
parents:
10620
diff
changeset
|
55 result = [] |
10620
1ee14abe07b4
shrink-revlog: instrument sort code to record statistics.
Greg Ward <greg-hg@gerg.ca>
parents:
10542
diff
changeset
|
56 |
1ee14abe07b4
shrink-revlog: instrument sort code to record statistics.
Greg Ward <greg-hg@gerg.ca>
parents:
10542
diff
changeset
|
57 # suboptimal: nodes whose predecessor is not first parent |
1ee14abe07b4
shrink-revlog: instrument sort code to record statistics.
Greg Ward <greg-hg@gerg.ca>
parents:
10542
diff
changeset
|
58 suboptimal = 0 |
1ee14abe07b4
shrink-revlog: instrument sort code to record statistics.
Greg Ward <greg-hg@gerg.ca>
parents:
10542
diff
changeset
|
59 |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
60 while visit: |
10621
c93f0a23f381
shrink-revlog: rename some local variables for consistency.
Greg Ward <greg-hg@gerg.ca>
parents:
10620
diff
changeset
|
61 cur = visit.pop(0) |
c93f0a23f381
shrink-revlog: rename some local variables for consistency.
Greg Ward <greg-hg@gerg.ca>
parents:
10620
diff
changeset
|
62 # revlog will compute delta relative to result[-1], so keep track |
10620
1ee14abe07b4
shrink-revlog: instrument sort code to record statistics.
Greg Ward <greg-hg@gerg.ca>
parents:
10542
diff
changeset
|
63 # of nodes where this might result in a large delta |
10621
c93f0a23f381
shrink-revlog: rename some local variables for consistency.
Greg Ward <greg-hg@gerg.ca>
parents:
10620
diff
changeset
|
64 parents = rl.parentrevs(cur) |
c93f0a23f381
shrink-revlog: rename some local variables for consistency.
Greg Ward <greg-hg@gerg.ca>
parents:
10620
diff
changeset
|
65 if result: |
c93f0a23f381
shrink-revlog: rename some local variables for consistency.
Greg Ward <greg-hg@gerg.ca>
parents:
10620
diff
changeset
|
66 if result[-1] != parents[0]: |
10620
1ee14abe07b4
shrink-revlog: instrument sort code to record statistics.
Greg Ward <greg-hg@gerg.ca>
parents:
10542
diff
changeset
|
67 suboptimal += 1 |
1ee14abe07b4
shrink-revlog: instrument sort code to record statistics.
Greg Ward <greg-hg@gerg.ca>
parents:
10542
diff
changeset
|
68 |
10621
c93f0a23f381
shrink-revlog: rename some local variables for consistency.
Greg Ward <greg-hg@gerg.ca>
parents:
10620
diff
changeset
|
69 result.append(cur) |
c93f0a23f381
shrink-revlog: rename some local variables for consistency.
Greg Ward <greg-hg@gerg.ca>
parents:
10620
diff
changeset
|
70 if cur not in children: |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
71 # This only happens if some node's p1 == p2, which can |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
72 # happen in the manifest in certain circumstances. |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
73 continue |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
74 next = [] |
10621
c93f0a23f381
shrink-revlog: rename some local variables for consistency.
Greg Ward <greg-hg@gerg.ca>
parents:
10620
diff
changeset
|
75 for c in children.pop(cur): |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
76 parents_unseen = [p for p in rl.parentrevs(c) |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
77 if p != node.nullrev and p in children] |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
78 if len(parents_unseen) == 0: |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
79 next.append(c) |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
80 visit = next + visit |
10620
1ee14abe07b4
shrink-revlog: instrument sort code to record statistics.
Greg Ward <greg-hg@gerg.ca>
parents:
10542
diff
changeset
|
81 ui.note(_('%d suboptimal nodes\n') % suboptimal) |
10621
c93f0a23f381
shrink-revlog: rename some local variables for consistency.
Greg Ward <greg-hg@gerg.ca>
parents:
10620
diff
changeset
|
82 return result |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
83 |
10213
9e6848f352b0
contrib: use ui to write in shrink-revlog.py
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10009
diff
changeset
|
84 def writerevs(ui, r1, r2, order, tr): |
10009
69dca8574a6a
shrink-revlog: improve performance: use changegroup instead of revisions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9712
diff
changeset
|
85 |
10508
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
86 ui.status(_('writing revs\n')) |
10440
b39b32c33269
shrink: use progress API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
87 |
10009
69dca8574a6a
shrink-revlog: improve performance: use changegroup instead of revisions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9712
diff
changeset
|
88 count = [0] |
69dca8574a6a
shrink-revlog: improve performance: use changegroup instead of revisions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9712
diff
changeset
|
89 def progress(*args): |
10496
45734b51c99b
progress: mark strings for translation
Martin Geisler <mg@lazybytes.net>
parents:
10440
diff
changeset
|
90 ui.progress(_('writing'), count[0], total=len(order)) |
10009
69dca8574a6a
shrink-revlog: improve performance: use changegroup instead of revisions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9712
diff
changeset
|
91 count[0] += 1 |
69dca8574a6a
shrink-revlog: improve performance: use changegroup instead of revisions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9712
diff
changeset
|
92 |
69dca8574a6a
shrink-revlog: improve performance: use changegroup instead of revisions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9712
diff
changeset
|
93 order = [r1.node(r) for r in order] |
69dca8574a6a
shrink-revlog: improve performance: use changegroup instead of revisions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9712
diff
changeset
|
94 |
69dca8574a6a
shrink-revlog: improve performance: use changegroup instead of revisions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9712
diff
changeset
|
95 # this is a bit ugly, but it works |
69dca8574a6a
shrink-revlog: improve performance: use changegroup instead of revisions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9712
diff
changeset
|
96 lookup = lambda x: "%020d" % r1.linkrev(r1.rev(x)) |
69dca8574a6a
shrink-revlog: improve performance: use changegroup instead of revisions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9712
diff
changeset
|
97 unlookup = lambda x: int(x, 10) |
69dca8574a6a
shrink-revlog: improve performance: use changegroup instead of revisions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9712
diff
changeset
|
98 |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
99 try: |
10009
69dca8574a6a
shrink-revlog: improve performance: use changegroup instead of revisions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9712
diff
changeset
|
100 group = util.chunkbuffer(r1.group(order, lookup, progress)) |
69dca8574a6a
shrink-revlog: improve performance: use changegroup instead of revisions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9712
diff
changeset
|
101 chunkiter = changegroup.chunkiter(group) |
69dca8574a6a
shrink-revlog: improve performance: use changegroup instead of revisions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9712
diff
changeset
|
102 r2.addgroup(chunkiter, unlookup, tr) |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
103 finally: |
10496
45734b51c99b
progress: mark strings for translation
Martin Geisler <mg@lazybytes.net>
parents:
10440
diff
changeset
|
104 ui.progress(_('writing'), None, len(order)) |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
105 |
10542
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
106 def report(ui, r1, r2): |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
107 def getsize(r): |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
108 s = 0 |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
109 for fn in (r.indexfile, r.datafile): |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
110 try: |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
111 s += os.stat(fn).st_size |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
112 except OSError, inst: |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
113 if inst.errno != errno.ENOENT: |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
114 raise |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
115 return s |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
116 |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
117 oldsize = float(getsize(r1)) |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
118 newsize = float(getsize(r2)) |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
119 |
9712
18b134ef294c
kill trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9515
diff
changeset
|
120 # argh: have to pass an int to %d, because a float >= 2^32 |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
121 # blows up under Python 2.5 or earlier |
10508
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
122 ui.write(_('old file size: %12d bytes (%6.1f MiB)\n') |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10241
diff
changeset
|
123 % (int(oldsize), oldsize / 1024 / 1024)) |
10508
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
124 ui.write(_('new file size: %12d bytes (%6.1f MiB)\n') |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10241
diff
changeset
|
125 % (int(newsize), newsize / 1024 / 1024)) |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
126 |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
127 shrink_percent = (oldsize - newsize) / oldsize * 100 |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
128 shrink_factor = oldsize / newsize |
10508
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
129 ui.write(_('shrinkage: %.1f%% (%.1fx)\n') |
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
130 % (shrink_percent, shrink_factor)) |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
131 |
10215
9d79b8f58bea
contrib: turn shrink-revlog.py into an extension
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10214
diff
changeset
|
132 def shrink(ui, repo, **opts): |
10622
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
133 """shrink a revlog by reordering revisions |
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
134 |
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
135 Rewrites all the entries in some revlog of the current repository |
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
136 (by default, the manifest log) to save space. |
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
137 |
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
138 Different sort algorithms have different performance |
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
139 characteristics. Use ``--sort`` to select a sort algorithm so you |
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
140 can determine which works best for your data. The default |
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
141 algorithm, ``branchsort``, works well for workflows with lots of |
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
142 active (unmerged) branches, but not so well when all branches have |
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
143 been merged and there is only one repository head. |
10215
9d79b8f58bea
contrib: turn shrink-revlog.py into an extension
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10214
diff
changeset
|
144 """ |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
145 |
10215
9d79b8f58bea
contrib: turn shrink-revlog.py into an extension
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10214
diff
changeset
|
146 if not repo.local(): |
10508
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
147 raise util.Abort(_('not a local repository: %s') % repo.root) |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
148 |
10215
9d79b8f58bea
contrib: turn shrink-revlog.py into an extension
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10214
diff
changeset
|
149 fn = opts.get('revlog') |
9d79b8f58bea
contrib: turn shrink-revlog.py into an extension
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10214
diff
changeset
|
150 if not fn: |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
151 indexfn = repo.sjoin('00manifest.i') |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
152 else: |
10215
9d79b8f58bea
contrib: turn shrink-revlog.py into an extension
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10214
diff
changeset
|
153 if not fn.endswith('.i'): |
10508
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
154 raise util.Abort(_('--revlog option must specify the revlog index ' |
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
155 'file (*.i), not %s') % opts.get('revlog')) |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
156 |
10215
9d79b8f58bea
contrib: turn shrink-revlog.py into an extension
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10214
diff
changeset
|
157 indexfn = os.path.realpath(fn) |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
158 store = repo.sjoin('') |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
159 if not indexfn.startswith(store): |
10508
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
160 raise util.Abort(_('--revlog option must specify a revlog in %s, ' |
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
161 'not %s') % (store, indexfn)) |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
162 |
10622
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
163 sortname = opts['sort'] |
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
164 try: |
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
165 toposort = globals()['toposort_' + sortname] |
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
166 except KeyError: |
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
167 raise util.Abort(_('no such toposort algorithm: %s') % sortname) |
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
168 |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
169 if not os.path.exists(indexfn): |
10508
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
170 raise util.Abort(_('no such file: %s') % indexfn) |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
171 if '00changelog' in indexfn: |
10508
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
172 raise util.Abort(_('shrinking the changelog ' |
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
173 'will corrupt your repository')) |
10542
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
174 |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
175 ui.write(_('shrinking %s\n') % indexfn) |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
176 prefix = os.path.basename(indexfn)[:-1] |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
177 (tmpfd, tmpindexfn) = tempfile.mkstemp(dir=os.path.dirname(indexfn), |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
178 prefix=prefix, |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
179 suffix='.i') |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
180 os.close(tmpfd) |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
181 |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
182 r1 = revlog.revlog(util.opener(os.getcwd(), audit=False), indexfn) |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
183 r2 = revlog.revlog(util.opener(os.getcwd(), audit=False), tmpindexfn) |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
184 |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
185 datafn, tmpdatafn = r1.datafile, r2.datafile |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
186 |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
187 oldindexfn = indexfn + '.old' |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
188 olddatafn = datafn + '.old' |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
189 if os.path.exists(oldindexfn) or os.path.exists(olddatafn): |
10508
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
190 raise util.Abort(_('one or both of\n' |
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
191 ' %s\n' |
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
192 ' %s\n' |
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
193 'exists from a previous run; please clean up ' |
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
194 'before running again') % (oldindexfn, olddatafn)) |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
195 |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
196 # Don't use repo.transaction(), because then things get hairy with |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
197 # paths: some need to be relative to .hg, and some need to be |
10216
843f6ee6d14b
contrib: small documentation fixes in shrink-revlog.py
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10215
diff
changeset
|
198 # absolute. Doing it this way keeps things simple: everything is an |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
199 # absolute path. |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
200 lock = repo.lock(wait=False) |
10234
c8d6f339bbd7
shrink-revlog: make it work on windows (issue1976)
Patrick Mezard <pmezard@gmail.com>
parents:
10230
diff
changeset
|
201 tr = transaction.transaction(ui.warn, |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
202 open, |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
203 repo.sjoin('journal')) |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
204 |
10542
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
205 def ignoremissing(func): |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
206 def f(*args, **kw): |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
207 try: |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
208 return func(*args, **kw) |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
209 except OSError, inst: |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
210 if inst.errno != errno.ENOENT: |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
211 raise |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
212 return f |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
213 |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
214 try: |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
215 try: |
10213
9e6848f352b0
contrib: use ui to write in shrink-revlog.py
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10009
diff
changeset
|
216 order = toposort(ui, r1) |
9e6848f352b0
contrib: use ui to write in shrink-revlog.py
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10009
diff
changeset
|
217 writerevs(ui, r1, r2, order, tr) |
10542
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
218 report(ui, r1, r2) |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
219 tr.close() |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
220 except: |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
221 # Abort transaction first, so we truncate the files before |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
222 # deleting them. |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
223 tr.abort() |
10542
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
224 for fn in (tmpindexfn, tmpdatafn): |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
225 ignoremissing(os.unlink)(fn) |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
226 raise |
10241
4b2a086bee31
shrink-revlog: add --dry-run option
Patrick Mezard <pmezard@gmail.com>
parents:
10236
diff
changeset
|
227 if not opts.get('dry_run'): |
10542
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
228 # racy, both files cannot be renamed atomically |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
229 # copy files |
10241
4b2a086bee31
shrink-revlog: add --dry-run option
Patrick Mezard <pmezard@gmail.com>
parents:
10236
diff
changeset
|
230 util.os_link(indexfn, oldindexfn) |
10542
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
231 ignoremissing(util.os_link)(datafn, olddatafn) |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
232 # rename |
10241
4b2a086bee31
shrink-revlog: add --dry-run option
Patrick Mezard <pmezard@gmail.com>
parents:
10236
diff
changeset
|
233 util.rename(tmpindexfn, indexfn) |
10542
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
234 try: |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
235 util.rename(tmpdatafn, datafn) |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
236 except OSError, inst: |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
237 if inst.errno != errno.ENOENT: |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
238 raise |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
239 ignoremissing(os.unlink)(datafn) |
10241
4b2a086bee31
shrink-revlog: add --dry-run option
Patrick Mezard <pmezard@gmail.com>
parents:
10236
diff
changeset
|
240 else: |
10542
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
241 for fn in (tmpindexfn, tmpdatafn): |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
242 ignoremissing(os.unlink)(fn) |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
243 finally: |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
244 lock.release() |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
245 |
10241
4b2a086bee31
shrink-revlog: add --dry-run option
Patrick Mezard <pmezard@gmail.com>
parents:
10236
diff
changeset
|
246 if not opts.get('dry_run'): |
10508
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
247 ui.write(_('note: old revlog saved in:\n' |
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
248 ' %s\n' |
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
249 ' %s\n' |
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
250 '(You can delete those files when you are satisfied that your\n' |
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
251 'repository is still sane. ' |
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
252 'Running \'hg verify\' is strongly recommended.)\n') |
10241
4b2a086bee31
shrink-revlog: add --dry-run option
Patrick Mezard <pmezard@gmail.com>
parents:
10236
diff
changeset
|
253 % (oldindexfn, olddatafn)) |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
254 |
10215
9d79b8f58bea
contrib: turn shrink-revlog.py into an extension
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10214
diff
changeset
|
255 cmdtable = { |
9d79b8f58bea
contrib: turn shrink-revlog.py into an extension
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10214
diff
changeset
|
256 'shrink': (shrink, |
10508
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
257 [('', 'revlog', '', _('index (.i) file of the revlog to shrink')), |
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
258 ('n', 'dry-run', None, _('do not shrink, simulate only')), |
10622
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
259 ('', 'sort', 'branchsort', 'name of sort algorithm to use'), |
10241
4b2a086bee31
shrink-revlog: add --dry-run option
Patrick Mezard <pmezard@gmail.com>
parents:
10236
diff
changeset
|
260 ], |
10508
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
261 _('hg shrink [--revlog PATH]')) |
10215
9d79b8f58bea
contrib: turn shrink-revlog.py into an extension
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10214
diff
changeset
|
262 } |
10236
49a8625b8cac
shrink-revlog: help/doc tweaks
Greg Ward <greg-hg@gerg.ca>
parents:
10234
diff
changeset
|
263 |
49a8625b8cac
shrink-revlog: help/doc tweaks
Greg Ward <greg-hg@gerg.ca>
parents:
10234
diff
changeset
|
264 if __name__ == "__main__": |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10241
diff
changeset
|
265 print "shrink-revlog.py is now an extension (see hg help extensions)" |