Mercurial > hg
annotate contrib/shrink-revlog.py @ 10625:add562abc28a
shrink-revlog: remove branchsort algorithm (it behaves poorly)
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Wed, 10 Mar 2010 09:48:15 +0100 |
parents | 432eb853a2c6 |
children | 3fc95c3bc3ba |
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 |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
27 |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
28 |
10623
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
29 def toposort_reversepostorder(ui, rl): |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
30 # postorder of the reverse directed graph |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
31 |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
32 # map rev to list of parent revs (p2 first) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
33 parents = {} |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
34 heads = set() |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
35 ui.status(_('reading revs\n')) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
36 try: |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
37 for rev in rl: |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
38 ui.progress(_('reading'), rev, total=len(rl)) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
39 (p1, p2) = rl.parentrevs(rev) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
40 if p1 == p2 == node.nullrev: |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
41 parents[rev] = () # root node |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
42 elif p1 == p2 or p2 == node.nullrev: |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
43 parents[rev] = (p1,) # normal node |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
44 else: |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
45 parents[rev] = (p2, p1) # merge node |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
46 |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
47 heads.add(rev) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
48 |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
49 for p in parents[rev]: |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
50 heads.discard(p) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
51 finally: |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
52 ui.progress(_('reading'), None, total=len(rl)) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
53 |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
54 ui.status(_('sorting revs\n')) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
55 result = [] |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
56 visit = list(heads) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
57 visit.sort(reverse=True) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
58 finished = set() |
10624
432eb853a2c6
shrink-revlog: add accounting of suboptimal nodes to the new algorithms.
Greg Ward <greg-hg@gerg.ca>
parents:
10623
diff
changeset
|
59 suboptimal = 0 |
10623
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
60 |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
61 while visit: |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
62 cur = visit[-1] |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
63 for p in parents[cur]: |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
64 if p not in finished: |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
65 visit.append(p) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
66 break |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
67 else: |
10624
432eb853a2c6
shrink-revlog: add accounting of suboptimal nodes to the new algorithms.
Greg Ward <greg-hg@gerg.ca>
parents:
10623
diff
changeset
|
68 curparents = rl.parentrevs(cur) |
432eb853a2c6
shrink-revlog: add accounting of suboptimal nodes to the new algorithms.
Greg Ward <greg-hg@gerg.ca>
parents:
10623
diff
changeset
|
69 if result and result[-1] != curparents[0]: |
432eb853a2c6
shrink-revlog: add accounting of suboptimal nodes to the new algorithms.
Greg Ward <greg-hg@gerg.ca>
parents:
10623
diff
changeset
|
70 suboptimal += 1 |
432eb853a2c6
shrink-revlog: add accounting of suboptimal nodes to the new algorithms.
Greg Ward <greg-hg@gerg.ca>
parents:
10623
diff
changeset
|
71 |
10623
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
72 result.append(cur) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
73 finished.add(cur) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
74 visit.pop() |
10624
432eb853a2c6
shrink-revlog: add accounting of suboptimal nodes to the new algorithms.
Greg Ward <greg-hg@gerg.ca>
parents:
10623
diff
changeset
|
75 |
432eb853a2c6
shrink-revlog: add accounting of suboptimal nodes to the new algorithms.
Greg Ward <greg-hg@gerg.ca>
parents:
10623
diff
changeset
|
76 ui.note(_('%d suboptimal nodes\n') % suboptimal) |
432eb853a2c6
shrink-revlog: add accounting of suboptimal nodes to the new algorithms.
Greg Ward <greg-hg@gerg.ca>
parents:
10623
diff
changeset
|
77 |
10623
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
78 return result |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
79 |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
80 def toposort_postorderreverse(ui, rl): |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
81 # reverse-postorder of the reverse directed graph |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
82 |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
83 children = {} |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
84 roots = set() |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
85 ui.status(_('reading revs\n')) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
86 try: |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
87 for rev in rl: |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
88 ui.progress(_('reading'), rev, total=len(rl)) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
89 (p1, p2) = rl.parentrevs(rev) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
90 if p1 == p2 == node.nullrev: |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
91 roots.add(rev) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
92 |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
93 children[rev] = [] |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
94 |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
95 if p1 != node.nullrev: |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
96 children[p1].append(rev) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
97 if p2 != node.nullrev: |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
98 children[p2].append(rev) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
99 finally: |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
100 ui.progress(_('reading'), None, total=len(rl)) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
101 |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
102 ui.status(_('sorting revs\n')) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
103 result = [] |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
104 visit = list(roots) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
105 visit.sort() |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
106 finished = set() |
10624
432eb853a2c6
shrink-revlog: add accounting of suboptimal nodes to the new algorithms.
Greg Ward <greg-hg@gerg.ca>
parents:
10623
diff
changeset
|
107 suboptimal = 0 |
432eb853a2c6
shrink-revlog: add accounting of suboptimal nodes to the new algorithms.
Greg Ward <greg-hg@gerg.ca>
parents:
10623
diff
changeset
|
108 |
10623
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
109 while visit: |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
110 cur = visit[-1] |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
111 for p in children[cur]: |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
112 if p not in finished: |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
113 visit.append(p) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
114 break |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
115 else: |
10624
432eb853a2c6
shrink-revlog: add accounting of suboptimal nodes to the new algorithms.
Greg Ward <greg-hg@gerg.ca>
parents:
10623
diff
changeset
|
116 # if cur is not the first parent of its successor, then the |
432eb853a2c6
shrink-revlog: add accounting of suboptimal nodes to the new algorithms.
Greg Ward <greg-hg@gerg.ca>
parents:
10623
diff
changeset
|
117 # successor is a suboptimal node |
432eb853a2c6
shrink-revlog: add accounting of suboptimal nodes to the new algorithms.
Greg Ward <greg-hg@gerg.ca>
parents:
10623
diff
changeset
|
118 if result: |
432eb853a2c6
shrink-revlog: add accounting of suboptimal nodes to the new algorithms.
Greg Ward <greg-hg@gerg.ca>
parents:
10623
diff
changeset
|
119 succparents = rl.parentrevs(result[-1]) |
432eb853a2c6
shrink-revlog: add accounting of suboptimal nodes to the new algorithms.
Greg Ward <greg-hg@gerg.ca>
parents:
10623
diff
changeset
|
120 if succparents[0] != cur: |
432eb853a2c6
shrink-revlog: add accounting of suboptimal nodes to the new algorithms.
Greg Ward <greg-hg@gerg.ca>
parents:
10623
diff
changeset
|
121 suboptimal += 1 |
432eb853a2c6
shrink-revlog: add accounting of suboptimal nodes to the new algorithms.
Greg Ward <greg-hg@gerg.ca>
parents:
10623
diff
changeset
|
122 |
10623
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
123 result.append(cur) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
124 finished.add(cur) |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
125 visit.pop() |
10624
432eb853a2c6
shrink-revlog: add accounting of suboptimal nodes to the new algorithms.
Greg Ward <greg-hg@gerg.ca>
parents:
10623
diff
changeset
|
126 |
432eb853a2c6
shrink-revlog: add accounting of suboptimal nodes to the new algorithms.
Greg Ward <greg-hg@gerg.ca>
parents:
10623
diff
changeset
|
127 ui.note(_('%d suboptimal nodes\n') % suboptimal) |
432eb853a2c6
shrink-revlog: add accounting of suboptimal nodes to the new algorithms.
Greg Ward <greg-hg@gerg.ca>
parents:
10623
diff
changeset
|
128 |
10623
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
129 result.reverse() |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
130 return result |
64e286c22f29
shrink-revlog: add "reverse postorder" and "postorder reverse" toposorts.
Greg Ward <greg-hg@gerg.ca>
parents:
10622
diff
changeset
|
131 |
10213
9e6848f352b0
contrib: use ui to write in shrink-revlog.py
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10009
diff
changeset
|
132 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
|
133 |
10508
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
134 ui.status(_('writing revs\n')) |
10440
b39b32c33269
shrink: use progress API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
135 |
10009
69dca8574a6a
shrink-revlog: improve performance: use changegroup instead of revisions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9712
diff
changeset
|
136 count = [0] |
69dca8574a6a
shrink-revlog: improve performance: use changegroup instead of revisions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9712
diff
changeset
|
137 def progress(*args): |
10496
45734b51c99b
progress: mark strings for translation
Martin Geisler <mg@lazybytes.net>
parents:
10440
diff
changeset
|
138 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
|
139 count[0] += 1 |
69dca8574a6a
shrink-revlog: improve performance: use changegroup instead of revisions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9712
diff
changeset
|
140 |
69dca8574a6a
shrink-revlog: improve performance: use changegroup instead of revisions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9712
diff
changeset
|
141 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
|
142 |
69dca8574a6a
shrink-revlog: improve performance: use changegroup instead of revisions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9712
diff
changeset
|
143 # 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
|
144 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
|
145 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
|
146 |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
147 try: |
10009
69dca8574a6a
shrink-revlog: improve performance: use changegroup instead of revisions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9712
diff
changeset
|
148 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
|
149 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
|
150 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
|
151 finally: |
10496
45734b51c99b
progress: mark strings for translation
Martin Geisler <mg@lazybytes.net>
parents:
10440
diff
changeset
|
152 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
|
153 |
10542
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
154 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
|
155 def getsize(r): |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
156 s = 0 |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
157 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
|
158 try: |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
159 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
|
160 except OSError, inst: |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
161 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
|
162 raise |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
163 return s |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
164 |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
165 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
|
166 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
|
167 |
9712
18b134ef294c
kill trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9515
diff
changeset
|
168 # 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
|
169 # 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
|
170 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
|
171 % (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
|
172 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
|
173 % (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
|
174 |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
175 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
|
176 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
|
177 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
|
178 % (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
|
179 |
10215
9d79b8f58bea
contrib: turn shrink-revlog.py into an extension
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10214
diff
changeset
|
180 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
|
181 """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
|
182 |
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
183 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
|
184 (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
|
185 |
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
186 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
|
187 characteristics. Use ``--sort`` to select a sort algorithm so you |
10625
add562abc28a
shrink-revlog: remove branchsort algorithm (it behaves poorly)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10624
diff
changeset
|
188 can determine which works best for your data. |
10215
9d79b8f58bea
contrib: turn shrink-revlog.py into an extension
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10214
diff
changeset
|
189 """ |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
190 |
10215
9d79b8f58bea
contrib: turn shrink-revlog.py into an extension
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10214
diff
changeset
|
191 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
|
192 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
|
193 |
10215
9d79b8f58bea
contrib: turn shrink-revlog.py into an extension
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10214
diff
changeset
|
194 fn = opts.get('revlog') |
9d79b8f58bea
contrib: turn shrink-revlog.py into an extension
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10214
diff
changeset
|
195 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
|
196 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
|
197 else: |
10215
9d79b8f58bea
contrib: turn shrink-revlog.py into an extension
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10214
diff
changeset
|
198 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
|
199 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
|
200 '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
|
201 |
10215
9d79b8f58bea
contrib: turn shrink-revlog.py into an extension
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10214
diff
changeset
|
202 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
|
203 store = repo.sjoin('') |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
204 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
|
205 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
|
206 '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
|
207 |
10622
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
208 sortname = opts['sort'] |
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
209 try: |
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
210 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
|
211 except KeyError: |
bc81f126139f
shrink-revlog: add --sort option for user-selectable toposort algorithm.
Greg Ward <greg-hg@gerg.ca>
parents:
10621
diff
changeset
|
212 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
|
213 |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
214 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
|
215 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
|
216 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
|
217 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
|
218 '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
|
219 |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
220 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
|
221 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
|
222 (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
|
223 prefix=prefix, |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
224 suffix='.i') |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
225 os.close(tmpfd) |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
226 |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
227 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
|
228 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
|
229 |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
230 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
|
231 |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
232 oldindexfn = indexfn + '.old' |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
233 olddatafn = datafn + '.old' |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
234 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
|
235 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
|
236 ' %s\n' |
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
237 ' %s\n' |
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
238 '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
|
239 '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
|
240 |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
241 # 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
|
242 # 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
|
243 # 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
|
244 # absolute path. |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
245 lock = repo.lock(wait=False) |
10234
c8d6f339bbd7
shrink-revlog: make it work on windows (issue1976)
Patrick Mezard <pmezard@gmail.com>
parents:
10230
diff
changeset
|
246 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
|
247 open, |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
248 repo.sjoin('journal')) |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
249 |
10542
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
250 def ignoremissing(func): |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
251 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
|
252 try: |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
253 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
|
254 except OSError, inst: |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
255 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
|
256 raise |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
257 return f |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
258 |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
259 try: |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
260 try: |
10213
9e6848f352b0
contrib: use ui to write in shrink-revlog.py
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10009
diff
changeset
|
261 order = toposort(ui, r1) |
9e6848f352b0
contrib: use ui to write in shrink-revlog.py
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10009
diff
changeset
|
262 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
|
263 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
|
264 tr.close() |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
265 except: |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
266 # 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
|
267 # deleting them. |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
268 tr.abort() |
10542
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
269 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
|
270 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
|
271 raise |
10241
4b2a086bee31
shrink-revlog: add --dry-run option
Patrick Mezard <pmezard@gmail.com>
parents:
10236
diff
changeset
|
272 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
|
273 # 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
|
274 # copy files |
10241
4b2a086bee31
shrink-revlog: add --dry-run option
Patrick Mezard <pmezard@gmail.com>
parents:
10236
diff
changeset
|
275 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
|
276 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
|
277 # rename |
10241
4b2a086bee31
shrink-revlog: add --dry-run option
Patrick Mezard <pmezard@gmail.com>
parents:
10236
diff
changeset
|
278 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
|
279 try: |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
280 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
|
281 except OSError, inst: |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
282 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
|
283 raise |
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
284 ignoremissing(os.unlink)(datafn) |
10241
4b2a086bee31
shrink-revlog: add --dry-run option
Patrick Mezard <pmezard@gmail.com>
parents:
10236
diff
changeset
|
285 else: |
10542
989b2a5eaaba
shrink: handle all combinations of inline/non-inline revlogs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10509
diff
changeset
|
286 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
|
287 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
|
288 finally: |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
289 lock.release() |
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
290 |
10241
4b2a086bee31
shrink-revlog: add --dry-run option
Patrick Mezard <pmezard@gmail.com>
parents:
10236
diff
changeset
|
291 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
|
292 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
|
293 ' %s\n' |
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
294 ' %s\n' |
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
295 '(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
|
296 '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
|
297 'Running \'hg verify\' is strongly recommended.)\n') |
10241
4b2a086bee31
shrink-revlog: add --dry-run option
Patrick Mezard <pmezard@gmail.com>
parents:
10236
diff
changeset
|
298 % (oldindexfn, olddatafn)) |
9515
f7d85980261c
Add script to rewrite revlog to workaround lack of parent deltas.
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
299 |
10215
9d79b8f58bea
contrib: turn shrink-revlog.py into an extension
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10214
diff
changeset
|
300 cmdtable = { |
9d79b8f58bea
contrib: turn shrink-revlog.py into an extension
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10214
diff
changeset
|
301 '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
|
302 [('', '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
|
303 ('n', 'dry-run', None, _('do not shrink, simulate only')), |
10625
add562abc28a
shrink-revlog: remove branchsort algorithm (it behaves poorly)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10624
diff
changeset
|
304 ('', 'sort', 'reversepostorder', 'name of sort algorithm to use'), |
10241
4b2a086bee31
shrink-revlog: add --dry-run option
Patrick Mezard <pmezard@gmail.com>
parents:
10236
diff
changeset
|
305 ], |
10508
cc35ad583e66
shrink-revlog: add strings for translation / import _ before using it
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10496
diff
changeset
|
306 _('hg shrink [--revlog PATH]')) |
10215
9d79b8f58bea
contrib: turn shrink-revlog.py into an extension
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10214
diff
changeset
|
307 } |
10236
49a8625b8cac
shrink-revlog: help/doc tweaks
Greg Ward <greg-hg@gerg.ca>
parents:
10234
diff
changeset
|
308 |
49a8625b8cac
shrink-revlog: help/doc tweaks
Greg Ward <greg-hg@gerg.ca>
parents:
10234
diff
changeset
|
309 if __name__ == "__main__": |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10241
diff
changeset
|
310 print "shrink-revlog.py is now an extension (see hg help extensions)" |