Show More
@@ -23,13 +23,14 b' import sys, os, tempfile' | |||||
23 | import optparse |
|
23 | import optparse | |
24 | from mercurial import ui as ui_, hg, revlog, transaction, node, util |
|
24 | from mercurial import ui as ui_, hg, revlog, transaction, node, util | |
25 | from mercurial import changegroup |
|
25 | from mercurial import changegroup | |
|
26 | from mercurial.i18n import _ | |||
26 |
|
27 | |||
27 | def toposort(ui, rl): |
|
28 | def toposort(ui, rl): | |
28 |
|
29 | |||
29 | children = {} |
|
30 | children = {} | |
30 | root = [] |
|
31 | root = [] | |
31 | # build children and roots |
|
32 | # build children and roots | |
32 | ui.status('reading revs\n') |
|
33 | ui.status(_('reading revs\n')) | |
33 | try: |
|
34 | try: | |
34 | for i in rl: |
|
35 | for i in rl: | |
35 | ui.progress(_('reading'), i, total=len(rl)) |
|
36 | ui.progress(_('reading'), i, total=len(rl)) | |
@@ -50,7 +51,7 b' def toposort(ui, rl):' | |||||
50 | # XXX this is a reimplementation of the 'branchsort' topo sort |
|
51 | # XXX this is a reimplementation of the 'branchsort' topo sort | |
51 | # algorithm in hgext.convert.convcmd... would be nice not to duplicate |
|
52 | # algorithm in hgext.convert.convcmd... would be nice not to duplicate | |
52 | # the algorithm |
|
53 | # the algorithm | |
53 | ui.status('sorting revs\n') |
|
54 | ui.status(_('sorting revs\n')) | |
54 | visit = root |
|
55 | visit = root | |
55 | ret = [] |
|
56 | ret = [] | |
56 | while visit: |
|
57 | while visit: | |
@@ -71,7 +72,7 b' def toposort(ui, rl):' | |||||
71 |
|
72 | |||
72 | def writerevs(ui, r1, r2, order, tr): |
|
73 | def writerevs(ui, r1, r2, order, tr): | |
73 |
|
74 | |||
74 | ui.status('writing revs\n') |
|
75 | ui.status(_('writing revs\n')) | |
75 |
|
76 | |||
76 | count = [0] |
|
77 | count = [0] | |
77 | def progress(*args): |
|
78 | def progress(*args): | |
@@ -97,14 +98,15 b' def report(ui, olddatafn, newdatafn):' | |||||
97 |
|
98 | |||
98 | # argh: have to pass an int to %d, because a float >= 2^32 |
|
99 | # argh: have to pass an int to %d, because a float >= 2^32 | |
99 | # blows up under Python 2.5 or earlier |
|
100 | # blows up under Python 2.5 or earlier | |
100 | ui.write('old file size: %12d bytes (%6.1f MiB)\n' |
|
101 | ui.write(_('old file size: %12d bytes (%6.1f MiB)\n') | |
101 | % (int(oldsize), oldsize / 1024 / 1024)) |
|
102 | % (int(oldsize), oldsize / 1024 / 1024)) | |
102 | ui.write('new file size: %12d bytes (%6.1f MiB)\n' |
|
103 | ui.write(_('new file size: %12d bytes (%6.1f MiB)\n') | |
103 | % (int(newsize), newsize / 1024 / 1024)) |
|
104 | % (int(newsize), newsize / 1024 / 1024)) | |
104 |
|
105 | |||
105 | shrink_percent = (oldsize - newsize) / oldsize * 100 |
|
106 | shrink_percent = (oldsize - newsize) / oldsize * 100 | |
106 | shrink_factor = oldsize / newsize |
|
107 | shrink_factor = oldsize / newsize | |
107 |
ui.write('shrinkage: %.1f%% (%.1fx)\n' |
|
108 | ui.write(_('shrinkage: %.1f%% (%.1fx)\n') | |
|
109 | % (shrink_percent, shrink_factor)) | |||
108 |
|
110 | |||
109 | def shrink(ui, repo, **opts): |
|
111 | def shrink(ui, repo, **opts): | |
110 | """ |
|
112 | """ | |
@@ -115,43 +117,44 b' def shrink(ui, repo, **opts):' | |||||
115 | sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) |
|
117 | sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) | |
116 |
|
118 | |||
117 | if not repo.local(): |
|
119 | if not repo.local(): | |
118 | raise util.Abort('not a local repository: %s' % repo.root) |
|
120 | raise util.Abort(_('not a local repository: %s') % repo.root) | |
119 |
|
121 | |||
120 | fn = opts.get('revlog') |
|
122 | fn = opts.get('revlog') | |
121 | if not fn: |
|
123 | if not fn: | |
122 | indexfn = repo.sjoin('00manifest.i') |
|
124 | indexfn = repo.sjoin('00manifest.i') | |
123 | else: |
|
125 | else: | |
124 | if not fn.endswith('.i'): |
|
126 | if not fn.endswith('.i'): | |
125 | raise util.Abort('--revlog option must specify the revlog index ' |
|
127 | raise util.Abort(_('--revlog option must specify the revlog index ' | |
126 | 'file (*.i), not %s' % opts.get('revlog')) |
|
128 | 'file (*.i), not %s') % opts.get('revlog')) | |
127 |
|
129 | |||
128 | indexfn = os.path.realpath(fn) |
|
130 | indexfn = os.path.realpath(fn) | |
129 | store = repo.sjoin('') |
|
131 | store = repo.sjoin('') | |
130 | if not indexfn.startswith(store): |
|
132 | if not indexfn.startswith(store): | |
131 | raise util.Abort('--revlog option must specify a revlog in %s, ' |
|
133 | raise util.Abort(_('--revlog option must specify a revlog in %s, ' | |
132 | 'not %s' % (store, indexfn)) |
|
134 | 'not %s') % (store, indexfn)) | |
133 |
|
135 | |||
134 | datafn = indexfn[:-2] + '.d' |
|
136 | datafn = indexfn[:-2] + '.d' | |
135 | if not os.path.exists(indexfn): |
|
137 | if not os.path.exists(indexfn): | |
136 | raise util.Abort('no such file: %s' % indexfn) |
|
138 | raise util.Abort(_('no such file: %s') % indexfn) | |
137 | if '00changelog' in indexfn: |
|
139 | if '00changelog' in indexfn: | |
138 |
raise util.Abort('shrinking the changelog |
|
140 | raise util.Abort(_('shrinking the changelog ' | |
|
141 | 'will corrupt your repository')) | |||
139 | if not os.path.exists(datafn): |
|
142 | if not os.path.exists(datafn): | |
140 | # This is just a lazy shortcut because I can't be bothered to |
|
143 | # This is just a lazy shortcut because I can't be bothered to | |
141 | # handle all the special cases that entail from no .d file. |
|
144 | # handle all the special cases that entail from no .d file. | |
142 | raise util.Abort('%s does not exist: revlog not big enough ' |
|
145 | raise util.Abort(_('%s does not exist: revlog not big enough ' | |
143 | 'to be worth shrinking' % datafn) |
|
146 | 'to be worth shrinking') % datafn) | |
144 |
|
147 | |||
145 | oldindexfn = indexfn + '.old' |
|
148 | oldindexfn = indexfn + '.old' | |
146 | olddatafn = datafn + '.old' |
|
149 | olddatafn = datafn + '.old' | |
147 | if os.path.exists(oldindexfn) or os.path.exists(olddatafn): |
|
150 | if os.path.exists(oldindexfn) or os.path.exists(olddatafn): | |
148 | raise util.Abort('one or both of\n' |
|
151 | raise util.Abort(_('one or both of\n' | |
149 | ' %s\n' |
|
152 | ' %s\n' | |
150 | ' %s\n' |
|
153 | ' %s\n' | |
151 |
'exists from a previous run; please clean up |
|
154 | 'exists from a previous run; please clean up ' | |
152 | 'running again' % (oldindexfn, olddatafn)) |
|
155 | 'before running again') % (oldindexfn, olddatafn)) | |
153 |
|
156 | |||
154 | ui.write('shrinking %s\n' % indexfn) |
|
157 | ui.write(_('shrinking %s\n') % indexfn) | |
155 | prefix = os.path.basename(indexfn)[:-1] |
|
158 | prefix = os.path.basename(indexfn)[:-1] | |
156 | (tmpfd, tmpindexfn) = tempfile.mkstemp(dir=os.path.dirname(indexfn), |
|
159 | (tmpfd, tmpindexfn) = tempfile.mkstemp(dir=os.path.dirname(indexfn), | |
157 | prefix=prefix, |
|
160 | prefix=prefix, | |
@@ -199,20 +202,20 b' def shrink(ui, repo, **opts):' | |||||
199 | lock.release() |
|
202 | lock.release() | |
200 |
|
203 | |||
201 | if not opts.get('dry_run'): |
|
204 | if not opts.get('dry_run'): | |
202 | ui.write('note: old revlog saved in:\n' |
|
205 | ui.write(_('note: old revlog saved in:\n' | |
203 | ' %s\n' |
|
206 | ' %s\n' | |
204 | ' %s\n' |
|
207 | ' %s\n' | |
205 | '(You can delete those files when you are satisfied that your\n' |
|
208 | '(You can delete those files when you are satisfied that your\n' | |
206 | 'repository is still sane. ' |
|
209 | 'repository is still sane. ' | |
207 | 'Running \'hg verify\' is strongly recommended.)\n' |
|
210 | 'Running \'hg verify\' is strongly recommended.)\n') | |
208 | % (oldindexfn, olddatafn)) |
|
211 | % (oldindexfn, olddatafn)) | |
209 |
|
212 | |||
210 | cmdtable = { |
|
213 | cmdtable = { | |
211 | 'shrink': (shrink, |
|
214 | 'shrink': (shrink, | |
212 | [('', 'revlog', '', 'index (.i) file of the revlog to shrink'), |
|
215 | [('', 'revlog', '', _('index (.i) file of the revlog to shrink')), | |
213 | ('n', 'dry-run', None, 'do not shrink, simulate only'), |
|
216 | ('n', 'dry-run', None, _('do not shrink, simulate only')), | |
214 | ], |
|
217 | ], | |
215 | 'hg shrink [--revlog PATH]') |
|
218 | _('hg shrink [--revlog PATH]')) | |
216 | } |
|
219 | } | |
217 |
|
220 | |||
218 | if __name__ == "__main__": |
|
221 | if __name__ == "__main__": |
General Comments 0
You need to be logged in to leave comments.
Login now