Mercurial > hg-stable
changeset 3090:eeaf9bcdfa25
Move revision parsing into cmdutil.
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Thu, 14 Sep 2006 11:19:35 -0700 |
parents | e7fc04dc6349 |
children | 7fa3d38a99b6 |
files | contrib/churn.py hgext/extdiff.py mercurial/cmdutil.py mercurial/commands.py |
diffstat | 4 files changed, 77 insertions(+), 77 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/churn.py Wed Sep 13 14:37:51 2006 -0300 +++ b/contrib/churn.py Thu Sep 14 11:19:35 2006 -0700 @@ -14,7 +14,7 @@ from mercurial.demandload import * from mercurial.i18n import gettext as _ demandload(globals(), 'time sys signal os') -demandload(globals(), 'mercurial:hg,mdiff,fancyopts,commands,ui,util,templater,node') +demandload(globals(), 'mercurial:hg,mdiff,fancyopts,cmdutil,ui,util,templater,node') def __gather(ui, repo, node1, node2): def dirtywork(f, mmap1, mmap2): @@ -150,7 +150,7 @@ amap = get_aliases(f) f.close() - revs = [int(r) for r in commands.revrange(ui, repo, opts['rev'])] + revs = [int(r) for r in cmdutil.revrange(ui, repo, opts['rev'])] revs.sort() stats = gather_stats(ui, repo, amap, revs, opts.get('progress'))
--- a/hgext/extdiff.py Wed Sep 13 14:37:51 2006 -0300 +++ b/hgext/extdiff.py Thu Sep 14 11:19:35 2006 -0700 @@ -45,7 +45,7 @@ from mercurial.demandload import demandload from mercurial.i18n import gettext as _ from mercurial.node import * -demandload(globals(), 'mercurial:commands,cmdutil,util os shutil tempfile') +demandload(globals(), 'mercurial:cmdutil,util os shutil tempfile') def dodiff(ui, repo, diffcmd, diffopts, pats, opts): def snapshot_node(files, node): @@ -90,7 +90,7 @@ fp.write(chunk) return dirname - node1, node2 = commands.revpair(ui, repo, opts['rev']) + node1, node2 = cmdutil.revpair(ui, repo, opts['rev']) files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) modified, added, removed, deleted, unknown = repo.status( node1, node2, files, match=matchfn)[:5]
--- a/mercurial/cmdutil.py Wed Sep 13 14:37:51 2006 -0300 +++ b/mercurial/cmdutil.py Thu Sep 14 11:19:35 2006 -0700 @@ -11,6 +11,76 @@ demandload(globals(), 'mdiff util') demandload(globals(), 'os sys') +revrangesep = ':' + +def revfix(repo, val, defval): + '''turn user-level id of changeset into rev number. + user-level id can be tag, changeset, rev number, or negative rev + number relative to number of revs (-1 is tip, etc).''' + if not val: + return defval + try: + num = int(val) + if str(num) != val: + raise ValueError + if num < 0: + num += repo.changelog.count() + if num < 0: + num = 0 + elif num >= repo.changelog.count(): + raise ValueError + except ValueError: + try: + num = repo.changelog.rev(repo.lookup(val)) + except KeyError: + raise util.Abort(_('invalid revision identifier %s') % val) + return num + +def revpair(ui, repo, revs): + '''return pair of nodes, given list of revisions. second item can + be None, meaning use working dir.''' + if not revs: + return repo.dirstate.parents()[0], None + end = None + if len(revs) == 1: + start = revs[0] + if revrangesep in start: + start, end = start.split(revrangesep, 1) + start = revfix(repo, start, 0) + end = revfix(repo, end, repo.changelog.count() - 1) + else: + start = revfix(repo, start, None) + elif len(revs) == 2: + if revrangesep in revs[0] or revrangesep in revs[1]: + raise util.Abort(_('too many revisions specified')) + start = revfix(repo, revs[0], None) + end = revfix(repo, revs[1], None) + else: + raise util.Abort(_('too many revisions specified')) + if end is not None: end = repo.lookup(str(end)) + return repo.lookup(str(start)), end + +def revrange(ui, repo, revs): + """Yield revision as strings from a list of revision specifications.""" + seen = {} + for spec in revs: + if revrangesep in spec: + start, end = spec.split(revrangesep, 1) + start = revfix(repo, start, 0) + end = revfix(repo, end, repo.changelog.count() - 1) + step = start > end and -1 or 1 + for rev in xrange(start, end+step, step): + if rev in seen: + continue + seen[rev] = 1 + yield str(rev) + else: + rev = revfix(repo, spec, None) + if rev in seen: + continue + seen[rev] = 1 + yield str(rev) + def make_filename(repo, pat, node, total=None, seqno=None, revwidth=None, pathname=None): node_expander = {
--- a/mercurial/commands.py Wed Sep 13 14:37:51 2006 -0300 +++ b/mercurial/commands.py Thu Sep 14 11:19:35 2006 -0700 @@ -108,7 +108,7 @@ defrange = '%s:0' % start else: defrange = 'tip:0' - revs = map(int, revrange(ui, repo, opts['rev'] or [defrange])) + revs = map(int, cmdutil.revrange(ui, repo, opts['rev'] or [defrange])) wanted = {} slowpath = anypats fncache = {} @@ -252,76 +252,6 @@ yield 'iter', rev, None return iterate(), getchange, matchfn -revrangesep = ':' - -def revfix(repo, val, defval): - '''turn user-level id of changeset into rev number. - user-level id can be tag, changeset, rev number, or negative rev - number relative to number of revs (-1 is tip, etc).''' - if not val: - return defval - try: - num = int(val) - if str(num) != val: - raise ValueError - if num < 0: - num += repo.changelog.count() - if num < 0: - num = 0 - elif num >= repo.changelog.count(): - raise ValueError - except ValueError: - try: - num = repo.changelog.rev(repo.lookup(val)) - except KeyError: - raise util.Abort(_('invalid revision identifier %s') % val) - return num - -def revpair(ui, repo, revs): - '''return pair of nodes, given list of revisions. second item can - be None, meaning use working dir.''' - if not revs: - return repo.dirstate.parents()[0], None - end = None - if len(revs) == 1: - start = revs[0] - if revrangesep in start: - start, end = start.split(revrangesep, 1) - start = revfix(repo, start, 0) - end = revfix(repo, end, repo.changelog.count() - 1) - else: - start = revfix(repo, start, None) - elif len(revs) == 2: - if revrangesep in revs[0] or revrangesep in revs[1]: - raise util.Abort(_('too many revisions specified')) - start = revfix(repo, revs[0], None) - end = revfix(repo, revs[1], None) - else: - raise util.Abort(_('too many revisions specified')) - if end is not None: end = repo.lookup(str(end)) - return repo.lookup(str(start)), end - -def revrange(ui, repo, revs): - """Yield revision as strings from a list of revision specifications.""" - seen = {} - for spec in revs: - if revrangesep in spec: - start, end = spec.split(revrangesep, 1) - start = revfix(repo, start, 0) - end = revfix(repo, end, repo.changelog.count() - 1) - step = start > end and -1 or 1 - for rev in xrange(start, end+step, step): - if rev in seen: - continue - seen[rev] = 1 - yield str(rev) - else: - rev = revfix(repo, spec, None) - if rev in seen: - continue - seen[rev] = 1 - yield str(rev) - def write_bundle(cg, filename=None, compress=True): """Write a bundle file and return its filename. @@ -1344,7 +1274,7 @@ it detects as binary. With -a, diff will generate a diff anyway, probably with undesirable results. """ - node1, node2 = revpair(ui, repo, opts['rev']) + node1, node2 = cmdutil.revpair(ui, repo, opts['rev']) fns, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) @@ -1380,7 +1310,7 @@ """ if not changesets: raise util.Abort(_("export requires at least one changeset")) - revs = list(revrange(ui, repo, changesets)) + revs = list(cmdutil.revrange(ui, repo, changesets)) if len(revs) > 1: ui.note(_('exporting patches:\n')) else: