Mercurial > public > mercurial-scm > hg
comparison contrib/shrink-revlog.py @ 10621:c93f0a23f381
shrink-revlog: rename some local variables for consistency.
author | Greg Ward <greg-hg@gerg.ca> |
---|---|
date | Tue, 09 Mar 2010 21:30:19 -0500 |
parents | 1ee14abe07b4 |
children | bc81f126139f |
comparison
equal
deleted
inserted
replaced
10620:1ee14abe07b4 | 10621:c93f0a23f381 |
---|---|
29 children = {} | 29 children = {} |
30 root = [] | 30 root = [] |
31 # build children and roots | 31 # build children and roots |
32 ui.status(_('reading revs\n')) | 32 ui.status(_('reading revs\n')) |
33 try: | 33 try: |
34 for i in rl: | 34 for rev in rl: |
35 ui.progress(_('reading'), i, total=len(rl)) | 35 ui.progress(_('reading'), rev, total=len(rl)) |
36 children[i] = [] | 36 children[rev] = [] |
37 parents = [p for p in rl.parentrevs(i) if p != node.nullrev] | 37 parents = [p for p in rl.parentrevs(rev) if p != node.nullrev] |
38 # in case of duplicate parents | 38 # in case of duplicate parents |
39 if len(parents) == 2 and parents[0] == parents[1]: | 39 if len(parents) == 2 and parents[0] == parents[1]: |
40 del parents[1] | 40 del parents[1] |
41 for p in parents: | 41 for p in parents: |
42 assert p in children | 42 assert p in children |
43 children[p].append(i) | 43 children[p].append(rev) |
44 | 44 |
45 if len(parents) == 0: | 45 if len(parents) == 0: |
46 root.append(i) | 46 root.append(rev) |
47 finally: | 47 finally: |
48 ui.progress(_('reading'), None, total=len(rl)) | 48 ui.progress(_('reading'), None, total=len(rl)) |
49 | 49 |
50 # XXX this is a reimplementation of the 'branchsort' topo sort | 50 # XXX this is a reimplementation of the 'branchsort' topo sort |
51 # algorithm in hgext.convert.convcmd... would be nice not to duplicate | 51 # algorithm in hgext.convert.convcmd... would be nice not to duplicate |
52 # the algorithm | 52 # the algorithm |
53 ui.status(_('sorting revs\n')) | 53 ui.status(_('sorting revs\n')) |
54 visit = root | 54 visit = root |
55 ret = [] | 55 result = [] |
56 | 56 |
57 # suboptimal: nodes whose predecessor is not first parent | 57 # suboptimal: nodes whose predecessor is not first parent |
58 suboptimal = 0 | 58 suboptimal = 0 |
59 | 59 |
60 while visit: | 60 while visit: |
61 i = visit.pop(0) | 61 cur = visit.pop(0) |
62 # revlog will compute delta relative to ret[-1], so keep track | 62 # revlog will compute delta relative to result[-1], so keep track |
63 # of nodes where this might result in a large delta | 63 # of nodes where this might result in a large delta |
64 parents = rl.parentrevs(i) | 64 parents = rl.parentrevs(cur) |
65 if ret: | 65 if result: |
66 if ret[-1] != parents[0]: | 66 if result[-1] != parents[0]: |
67 suboptimal += 1 | 67 suboptimal += 1 |
68 | 68 |
69 ret.append(i) | 69 result.append(cur) |
70 if i not in children: | 70 if cur not in children: |
71 # This only happens if some node's p1 == p2, which can | 71 # This only happens if some node's p1 == p2, which can |
72 # happen in the manifest in certain circumstances. | 72 # happen in the manifest in certain circumstances. |
73 continue | 73 continue |
74 next = [] | 74 next = [] |
75 for c in children.pop(i): | 75 for c in children.pop(cur): |
76 parents_unseen = [p for p in rl.parentrevs(c) | 76 parents_unseen = [p for p in rl.parentrevs(c) |
77 if p != node.nullrev and p in children] | 77 if p != node.nullrev and p in children] |
78 if len(parents_unseen) == 0: | 78 if len(parents_unseen) == 0: |
79 next.append(c) | 79 next.append(c) |
80 visit = next + visit | 80 visit = next + visit |
81 ui.note(_('%d suboptimal nodes\n') % suboptimal) | 81 ui.note(_('%d suboptimal nodes\n') % suboptimal) |
82 return ret | 82 return result |
83 | 83 |
84 def writerevs(ui, r1, r2, order, tr): | 84 def writerevs(ui, r1, r2, order, tr): |
85 | 85 |
86 ui.status(_('writing revs\n')) | 86 ui.status(_('writing revs\n')) |
87 | 87 |