Show More
@@ -14,7 +14,7 b'' | |||
|
14 | 14 | from mercurial.demandload import * |
|
15 | 15 | from mercurial.i18n import gettext as _ |
|
16 | 16 | demandload(globals(), 'time sys signal os') |
|
17 |
demandload(globals(), 'mercurial:hg,mdiff,fancyopts,c |
|
|
17 | demandload(globals(), 'mercurial:hg,mdiff,fancyopts,cmdutil,ui,util,templater,node') | |
|
18 | 18 | |
|
19 | 19 | def __gather(ui, repo, node1, node2): |
|
20 | 20 | def dirtywork(f, mmap1, mmap2): |
@@ -150,7 +150,7 b' def churn(ui, repo, **opts):' | |||
|
150 | 150 | amap = get_aliases(f) |
|
151 | 151 | f.close() |
|
152 | 152 | |
|
153 |
revs = [int(r) for r in c |
|
|
153 | revs = [int(r) for r in cmdutil.revrange(ui, repo, opts['rev'])] | |
|
154 | 154 | revs.sort() |
|
155 | 155 | stats = gather_stats(ui, repo, amap, revs, opts.get('progress')) |
|
156 | 156 |
@@ -45,7 +45,7 b'' | |||
|
45 | 45 | from mercurial.demandload import demandload |
|
46 | 46 | from mercurial.i18n import gettext as _ |
|
47 | 47 | from mercurial.node import * |
|
48 |
demandload(globals(), 'mercurial:c |
|
|
48 | demandload(globals(), 'mercurial:cmdutil,util os shutil tempfile') | |
|
49 | 49 | |
|
50 | 50 | def dodiff(ui, repo, diffcmd, diffopts, pats, opts): |
|
51 | 51 | def snapshot_node(files, node): |
@@ -90,7 +90,7 b' def dodiff(ui, repo, diffcmd, diffopts, ' | |||
|
90 | 90 | fp.write(chunk) |
|
91 | 91 | return dirname |
|
92 | 92 | |
|
93 |
node1, node2 = c |
|
|
93 | node1, node2 = cmdutil.revpair(ui, repo, opts['rev']) | |
|
94 | 94 | files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) |
|
95 | 95 | modified, added, removed, deleted, unknown = repo.status( |
|
96 | 96 | node1, node2, files, match=matchfn)[:5] |
@@ -11,6 +11,76 b' from i18n import gettext as _' | |||
|
11 | 11 | demandload(globals(), 'mdiff util') |
|
12 | 12 | demandload(globals(), 'os sys') |
|
13 | 13 | |
|
14 | revrangesep = ':' | |
|
15 | ||
|
16 | def revfix(repo, val, defval): | |
|
17 | '''turn user-level id of changeset into rev number. | |
|
18 | user-level id can be tag, changeset, rev number, or negative rev | |
|
19 | number relative to number of revs (-1 is tip, etc).''' | |
|
20 | if not val: | |
|
21 | return defval | |
|
22 | try: | |
|
23 | num = int(val) | |
|
24 | if str(num) != val: | |
|
25 | raise ValueError | |
|
26 | if num < 0: | |
|
27 | num += repo.changelog.count() | |
|
28 | if num < 0: | |
|
29 | num = 0 | |
|
30 | elif num >= repo.changelog.count(): | |
|
31 | raise ValueError | |
|
32 | except ValueError: | |
|
33 | try: | |
|
34 | num = repo.changelog.rev(repo.lookup(val)) | |
|
35 | except KeyError: | |
|
36 | raise util.Abort(_('invalid revision identifier %s') % val) | |
|
37 | return num | |
|
38 | ||
|
39 | def revpair(ui, repo, revs): | |
|
40 | '''return pair of nodes, given list of revisions. second item can | |
|
41 | be None, meaning use working dir.''' | |
|
42 | if not revs: | |
|
43 | return repo.dirstate.parents()[0], None | |
|
44 | end = None | |
|
45 | if len(revs) == 1: | |
|
46 | start = revs[0] | |
|
47 | if revrangesep in start: | |
|
48 | start, end = start.split(revrangesep, 1) | |
|
49 | start = revfix(repo, start, 0) | |
|
50 | end = revfix(repo, end, repo.changelog.count() - 1) | |
|
51 | else: | |
|
52 | start = revfix(repo, start, None) | |
|
53 | elif len(revs) == 2: | |
|
54 | if revrangesep in revs[0] or revrangesep in revs[1]: | |
|
55 | raise util.Abort(_('too many revisions specified')) | |
|
56 | start = revfix(repo, revs[0], None) | |
|
57 | end = revfix(repo, revs[1], None) | |
|
58 | else: | |
|
59 | raise util.Abort(_('too many revisions specified')) | |
|
60 | if end is not None: end = repo.lookup(str(end)) | |
|
61 | return repo.lookup(str(start)), end | |
|
62 | ||
|
63 | def revrange(ui, repo, revs): | |
|
64 | """Yield revision as strings from a list of revision specifications.""" | |
|
65 | seen = {} | |
|
66 | for spec in revs: | |
|
67 | if revrangesep in spec: | |
|
68 | start, end = spec.split(revrangesep, 1) | |
|
69 | start = revfix(repo, start, 0) | |
|
70 | end = revfix(repo, end, repo.changelog.count() - 1) | |
|
71 | step = start > end and -1 or 1 | |
|
72 | for rev in xrange(start, end+step, step): | |
|
73 | if rev in seen: | |
|
74 | continue | |
|
75 | seen[rev] = 1 | |
|
76 | yield str(rev) | |
|
77 | else: | |
|
78 | rev = revfix(repo, spec, None) | |
|
79 | if rev in seen: | |
|
80 | continue | |
|
81 | seen[rev] = 1 | |
|
82 | yield str(rev) | |
|
83 | ||
|
14 | 84 | def make_filename(repo, pat, node, |
|
15 | 85 | total=None, seqno=None, revwidth=None, pathname=None): |
|
16 | 86 | node_expander = { |
@@ -108,7 +108,7 b' def walkchangerevs(ui, repo, pats, opts)' | |||
|
108 | 108 | defrange = '%s:0' % start |
|
109 | 109 | else: |
|
110 | 110 | defrange = 'tip:0' |
|
111 | revs = map(int, revrange(ui, repo, opts['rev'] or [defrange])) | |
|
111 | revs = map(int, cmdutil.revrange(ui, repo, opts['rev'] or [defrange])) | |
|
112 | 112 | wanted = {} |
|
113 | 113 | slowpath = anypats |
|
114 | 114 | fncache = {} |
@@ -252,76 +252,6 b' def walkchangerevs(ui, repo, pats, opts)' | |||
|
252 | 252 | yield 'iter', rev, None |
|
253 | 253 | return iterate(), getchange, matchfn |
|
254 | 254 | |
|
255 | revrangesep = ':' | |
|
256 | ||
|
257 | def revfix(repo, val, defval): | |
|
258 | '''turn user-level id of changeset into rev number. | |
|
259 | user-level id can be tag, changeset, rev number, or negative rev | |
|
260 | number relative to number of revs (-1 is tip, etc).''' | |
|
261 | if not val: | |
|
262 | return defval | |
|
263 | try: | |
|
264 | num = int(val) | |
|
265 | if str(num) != val: | |
|
266 | raise ValueError | |
|
267 | if num < 0: | |
|
268 | num += repo.changelog.count() | |
|
269 | if num < 0: | |
|
270 | num = 0 | |
|
271 | elif num >= repo.changelog.count(): | |
|
272 | raise ValueError | |
|
273 | except ValueError: | |
|
274 | try: | |
|
275 | num = repo.changelog.rev(repo.lookup(val)) | |
|
276 | except KeyError: | |
|
277 | raise util.Abort(_('invalid revision identifier %s') % val) | |
|
278 | return num | |
|
279 | ||
|
280 | def revpair(ui, repo, revs): | |
|
281 | '''return pair of nodes, given list of revisions. second item can | |
|
282 | be None, meaning use working dir.''' | |
|
283 | if not revs: | |
|
284 | return repo.dirstate.parents()[0], None | |
|
285 | end = None | |
|
286 | if len(revs) == 1: | |
|
287 | start = revs[0] | |
|
288 | if revrangesep in start: | |
|
289 | start, end = start.split(revrangesep, 1) | |
|
290 | start = revfix(repo, start, 0) | |
|
291 | end = revfix(repo, end, repo.changelog.count() - 1) | |
|
292 | else: | |
|
293 | start = revfix(repo, start, None) | |
|
294 | elif len(revs) == 2: | |
|
295 | if revrangesep in revs[0] or revrangesep in revs[1]: | |
|
296 | raise util.Abort(_('too many revisions specified')) | |
|
297 | start = revfix(repo, revs[0], None) | |
|
298 | end = revfix(repo, revs[1], None) | |
|
299 | else: | |
|
300 | raise util.Abort(_('too many revisions specified')) | |
|
301 | if end is not None: end = repo.lookup(str(end)) | |
|
302 | return repo.lookup(str(start)), end | |
|
303 | ||
|
304 | def revrange(ui, repo, revs): | |
|
305 | """Yield revision as strings from a list of revision specifications.""" | |
|
306 | seen = {} | |
|
307 | for spec in revs: | |
|
308 | if revrangesep in spec: | |
|
309 | start, end = spec.split(revrangesep, 1) | |
|
310 | start = revfix(repo, start, 0) | |
|
311 | end = revfix(repo, end, repo.changelog.count() - 1) | |
|
312 | step = start > end and -1 or 1 | |
|
313 | for rev in xrange(start, end+step, step): | |
|
314 | if rev in seen: | |
|
315 | continue | |
|
316 | seen[rev] = 1 | |
|
317 | yield str(rev) | |
|
318 | else: | |
|
319 | rev = revfix(repo, spec, None) | |
|
320 | if rev in seen: | |
|
321 | continue | |
|
322 | seen[rev] = 1 | |
|
323 | yield str(rev) | |
|
324 | ||
|
325 | 255 | def write_bundle(cg, filename=None, compress=True): |
|
326 | 256 | """Write a bundle file and return its filename. |
|
327 | 257 | |
@@ -1344,7 +1274,7 b' def diff(ui, repo, *pats, **opts):' | |||
|
1344 | 1274 | it detects as binary. With -a, diff will generate a diff anyway, |
|
1345 | 1275 | probably with undesirable results. |
|
1346 | 1276 | """ |
|
1347 | node1, node2 = revpair(ui, repo, opts['rev']) | |
|
1277 | node1, node2 = cmdutil.revpair(ui, repo, opts['rev']) | |
|
1348 | 1278 | |
|
1349 | 1279 | fns, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) |
|
1350 | 1280 | |
@@ -1380,7 +1310,7 b' def export(ui, repo, *changesets, **opts' | |||
|
1380 | 1310 | """ |
|
1381 | 1311 | if not changesets: |
|
1382 | 1312 | raise util.Abort(_("export requires at least one changeset")) |
|
1383 | revs = list(revrange(ui, repo, changesets)) | |
|
1313 | revs = list(cmdutil.revrange(ui, repo, changesets)) | |
|
1384 | 1314 | if len(revs) > 1: |
|
1385 | 1315 | ui.note(_('exporting patches:\n')) |
|
1386 | 1316 | else: |
General Comments 0
You need to be logged in to leave comments.
Login now