Show More
@@ -22,13 +22,12 b' import optparse' | |||
|
22 | 22 | from mercurial import ui as ui_, hg, revlog, transaction, node, util |
|
23 | 23 | from mercurial import changegroup |
|
24 | 24 | |
|
25 | def toposort(rl): | |
|
26 | write = sys.stdout.write | |
|
25 | def toposort(ui, rl): | |
|
27 | 26 | |
|
28 | 27 | children = {} |
|
29 | 28 | root = [] |
|
30 | 29 | # build children and roots |
|
31 | write('reading %d revs ' % len(rl)) | |
|
30 | ui.write('reading %d revs ' % len(rl)) | |
|
32 | 31 | try: |
|
33 | 32 | for i in rl: |
|
34 | 33 | children[i] = [] |
@@ -44,14 +43,14 b' def toposort(rl):' | |||
|
44 | 43 | root.append(i) |
|
45 | 44 | |
|
46 | 45 | if i % 1000 == 0: |
|
47 | write('.') | |
|
46 | ui.write('.') | |
|
48 | 47 | finally: |
|
49 | write('\n') | |
|
48 | ui.write('\n') | |
|
50 | 49 | |
|
51 | 50 | # XXX this is a reimplementation of the 'branchsort' topo sort |
|
52 | 51 | # algorithm in hgext.convert.convcmd... would be nice not to duplicate |
|
53 | 52 | # the algorithm |
|
54 | write('sorting ...') | |
|
53 | ui.write('sorting ...') | |
|
55 | 54 | visit = root |
|
56 | 55 | ret = [] |
|
57 | 56 | while visit: |
@@ -68,17 +67,16 b' def toposort(rl):' | |||
|
68 | 67 | if len(parents_unseen) == 0: |
|
69 | 68 | next.append(c) |
|
70 | 69 | visit = next + visit |
|
71 | write('\n') | |
|
70 | ui.write('\n') | |
|
72 | 71 | return ret |
|
73 | 72 | |
|
74 | def writerevs(r1, r2, order, tr): | |
|
75 | write = sys.stdout.write | |
|
76 | write('writing %d revs ' % len(order)) | |
|
73 | def writerevs(ui, r1, r2, order, tr): | |
|
77 | 74 | |
|
75 | ui.write('writing %d revs ' % len(order)) | |
|
78 | 76 | count = [0] |
|
79 | 77 | def progress(*args): |
|
80 | 78 | if count[0] % 1000 == 0: |
|
81 | write('.') | |
|
79 | ui.write('.') | |
|
82 | 80 | count[0] += 1 |
|
83 | 81 | |
|
84 | 82 | order = [r1.node(r) for r in order] |
@@ -92,29 +90,27 b' def writerevs(r1, r2, order, tr):' | |||
|
92 | 90 | chunkiter = changegroup.chunkiter(group) |
|
93 | 91 | r2.addgroup(chunkiter, unlookup, tr) |
|
94 | 92 | finally: |
|
95 | write('\n') | |
|
93 | ui.write('\n') | |
|
96 | 94 | |
|
97 | def report(olddatafn, newdatafn): | |
|
95 | def report(ui, olddatafn, newdatafn): | |
|
98 | 96 | oldsize = float(os.stat(olddatafn).st_size) |
|
99 | 97 | newsize = float(os.stat(newdatafn).st_size) |
|
100 | 98 | |
|
101 | 99 | # argh: have to pass an int to %d, because a float >= 2^32 |
|
102 | 100 | # blows up under Python 2.5 or earlier |
|
103 |
|
|
|
101 | ui.write('old file size: %12d bytes (%6.1f MiB)\n' | |
|
104 | 102 |
|
|
105 |
|
|
|
103 | ui.write('new file size: %12d bytes (%6.1f MiB)\n' | |
|
106 | 104 |
|
|
107 | 105 | |
|
108 | 106 | shrink_percent = (oldsize - newsize) / oldsize * 100 |
|
109 | 107 | shrink_factor = oldsize / newsize |
|
110 |
|
|
|
111 | % (shrink_percent, shrink_factor)) | |
|
108 | ui.write('shrinkage: %.1f%% (%.1fx)\n' % (shrink_percent, shrink_factor)) | |
|
112 | 109 | |
|
113 | 110 | def main(): |
|
114 | 111 | |
|
115 | 112 | # Unbuffer stdout for nice progress output. |
|
116 | 113 | sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) |
|
117 | write = sys.stdout.write | |
|
118 | 114 | |
|
119 | 115 | parser = optparse.OptionParser(description=__doc__) |
|
120 | 116 | parser.add_option('-R', '--repository', |
@@ -168,7 +164,7 b' def main():' | |||
|
168 | 164 | 'running again' |
|
169 | 165 | % (oldindexfn, olddatafn)) |
|
170 | 166 | |
|
171 | write('shrinking %s\n' % indexfn) | |
|
167 | ui.write('shrinking %s\n' % indexfn) | |
|
172 | 168 | prefix = os.path.basename(indexfn)[:-1] |
|
173 | 169 | (tmpfd, tmpindexfn) = tempfile.mkstemp(dir=os.path.dirname(indexfn), |
|
174 | 170 | prefix=prefix, |
@@ -190,9 +186,9 b' def main():' | |||
|
190 | 186 | |
|
191 | 187 | try: |
|
192 | 188 | try: |
|
193 | order = toposort(r1) | |
|
194 | writerevs(r1, r2, order, tr) | |
|
195 | report(datafn, tmpdatafn) | |
|
189 | order = toposort(ui, r1) | |
|
190 | writerevs(ui, r1, r2, order, tr) | |
|
191 | report(ui, datafn, tmpdatafn) | |
|
196 | 192 | tr.close() |
|
197 | 193 | except: |
|
198 | 194 | # Abort transaction first, so we truncate the files before |
@@ -210,7 +206,7 b' def main():' | |||
|
210 | 206 | os.link(datafn, olddatafn) |
|
211 | 207 | os.rename(tmpindexfn, indexfn) |
|
212 | 208 | os.rename(tmpdatafn, datafn) |
|
213 | write('note: old revlog saved in:\n' | |
|
209 | ui.write('note: old revlog saved in:\n' | |
|
214 | 210 | ' %s\n' |
|
215 | 211 | ' %s\n' |
|
216 | 212 | '(You can delete those files when you are satisfied that your\n' |
General Comments 0
You need to be logged in to leave comments.
Login now