Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 3132:81da3c45aabd
Move defaultrev into changectx
This also causes tag on a repository with no working directory
to default to tip.
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Fri, 15 Sep 2006 15:23:52 -0700 |
parents | 25857e00af8e |
children | e69a0cbe268e |
comparison
equal
deleted
inserted
replaced
3131:cff3c58a5766 | 3132:81da3c45aabd |
---|---|
48 except IOError, inst: | 48 except IOError, inst: |
49 raise util.Abort(_("can't read commit message '%s': %s") % | 49 raise util.Abort(_("can't read commit message '%s': %s") % |
50 (logfile, inst.strerror)) | 50 (logfile, inst.strerror)) |
51 return message | 51 return message |
52 | 52 |
53 def defaultrev(repo, rev=None, default='tip'): | |
54 """returns rev if it is specified, otherwise the working dir | |
55 parent if there is only one, or tip if there is no working | |
56 dir""" | |
57 if rev: | |
58 return rev | |
59 | |
60 p1, p2 = repo.dirstate.parents() | |
61 if p2 != nullid: | |
62 raise util.Abort(_('uncommitted merge - please provide a ' | |
63 'specific revision')) | |
64 if p1 != nullid: | |
65 return hex(p1) | |
66 return default | |
67 | |
68 def walkchangerevs(ui, repo, pats, opts): | 53 def walkchangerevs(ui, repo, pats, opts): |
69 '''Iterate over files and the revs they changed in. | 54 '''Iterate over files and the revs they changed in. |
70 | 55 |
71 Callers most commonly need to iterate backwards over the history | 56 Callers most commonly need to iterate backwards over the history |
72 it is interested in. Doing so has awful (quadratic-looking) | 57 it is interested in. Doing so has awful (quadratic-looking) |
112 | 97 |
113 if repo.changelog.count() == 0: | 98 if repo.changelog.count() == 0: |
114 return [], False, matchfn | 99 return [], False, matchfn |
115 | 100 |
116 if follow: | 101 if follow: |
117 defrange = '%s:0' % defaultrev(repo) | 102 defrange = '%s:0' % repo.changectx().rev() |
118 else: | 103 else: |
119 defrange = 'tip:0' | 104 defrange = 'tip:0' |
120 revs = map(int, cmdutil.revrange(ui, repo, opts['rev'] or [defrange])) | 105 revs = map(int, cmdutil.revrange(ui, repo, opts['rev'] or [defrange])) |
121 wanted = {} | 106 wanted = {} |
122 slowpath = anypats | 107 slowpath = anypats |
644 opmap = [['user', getname], ['number', str], ['changeset', getnode], | 629 opmap = [['user', getname], ['number', str], ['changeset', getnode], |
645 ['date', getdate]] | 630 ['date', getdate]] |
646 if not opts['user'] and not opts['changeset'] and not opts['date']: | 631 if not opts['user'] and not opts['changeset'] and not opts['date']: |
647 opts['number'] = 1 | 632 opts['number'] = 1 |
648 | 633 |
649 ctx = repo.changectx(defaultrev(repo, opts['rev'])) | 634 ctx = repo.changectx(opts['rev']) |
650 | 635 |
651 for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, | 636 for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, |
652 node=ctx.node()): | 637 node=ctx.node()): |
653 fctx = ctx.filectx(abs) | 638 fctx = ctx.filectx(abs) |
654 if not opts['text'] and util.binary(fctx.data()): | 639 if not opts['text'] and util.binary(fctx.data()): |
691 Each member added to an archive file has a directory prefix | 676 Each member added to an archive file has a directory prefix |
692 prepended. Use "-p" to specify a format string for the prefix. | 677 prepended. Use "-p" to specify a format string for the prefix. |
693 The default is the basename of the archive, with suffixes removed. | 678 The default is the basename of the archive, with suffixes removed. |
694 ''' | 679 ''' |
695 | 680 |
696 node = repo.lookup(defaultrev(repo, opts['rev'])) | 681 node = repo.changectx(opts['rev']).node() |
697 dest = cmdutil.make_filename(repo, dest, node) | 682 dest = cmdutil.make_filename(repo, dest, node) |
698 if os.path.realpath(dest) == repo.root: | 683 if os.path.realpath(dest) == repo.root: |
699 raise util.Abort(_('repository root cannot be destination')) | 684 raise util.Abort(_('repository root cannot be destination')) |
700 dummy, matchfn, dummy = cmdutil.matchpats(repo, [], opts) | 685 dummy, matchfn, dummy = cmdutil.matchpats(repo, [], opts) |
701 kind = opts.get('type') or 'files' | 686 kind = opts.get('type') or 'files' |
808 | 793 |
809 %s basename of file being printed | 794 %s basename of file being printed |
810 %d dirname of file being printed, or '.' if in repo root | 795 %d dirname of file being printed, or '.' if in repo root |
811 %p root-relative path name of file being printed | 796 %p root-relative path name of file being printed |
812 """ | 797 """ |
813 ctx = repo.changectx(defaultrev(repo, opts['rev'])) | 798 ctx = repo.changectx(opts['rev']) |
814 for src, abs, rel, exact in cmdutil.walk(repo, (file1,) + pats, opts, | 799 for src, abs, rel, exact in cmdutil.walk(repo, (file1,) + pats, opts, |
815 ctx.node()): | 800 ctx.node()): |
816 fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs) | 801 fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs) |
817 fp.write(ctx.filectx(abs).data()) | 802 fp.write(ctx.filectx(abs).data()) |
818 | 803 |
2226 if not pats and not opts['all']: | 2211 if not pats and not opts['all']: |
2227 raise util.Abort(_('no files or directories specified; ' | 2212 raise util.Abort(_('no files or directories specified; ' |
2228 'use --all to revert the whole repo')) | 2213 'use --all to revert the whole repo')) |
2229 | 2214 |
2230 parent, p2 = repo.dirstate.parents() | 2215 parent, p2 = repo.dirstate.parents() |
2231 node = repo.lookup(defaultrev(repo, opts['rev'])) | 2216 if not opts['rev'] and p2 != nullid: |
2217 raise util.Abort(_('uncommitted merge - please provide a ' | |
2218 'specific revision')) | |
2219 node = repo.changectx(opts['rev']).node() | |
2232 mf = repo.manifest.read(repo.changelog.read(node)[0]) | 2220 mf = repo.manifest.read(repo.changelog.read(node)[0]) |
2233 if node == parent: | 2221 if node == parent: |
2234 pmf = mf | 2222 pmf = mf |
2235 else: | 2223 else: |
2236 pmf = None | 2224 pmf = None |
2526 "please use 'hg tag [-r REV] NAME' instead\n")) | 2514 "please use 'hg tag [-r REV] NAME' instead\n")) |
2527 if opts['rev']: | 2515 if opts['rev']: |
2528 raise util.Abort(_("use only one form to specify the revision")) | 2516 raise util.Abort(_("use only one form to specify the revision")) |
2529 if opts['rev']: | 2517 if opts['rev']: |
2530 rev_ = opts['rev'] | 2518 rev_ = opts['rev'] |
2531 r = defaultrev(repo, rev_, nullid) | 2519 if not rev_ and repo.dirstate.parents()[1] != nullid: |
2532 if r == nullid: | 2520 raise util.Abort(_('uncommitted merge - please provide a ' |
2533 raise util.Abort(_('no revision to tag')) | 2521 'specific revision')) |
2534 r = repo.lookup(r) | 2522 r = repo.changectx(rev_).node() |
2535 | 2523 |
2536 message = opts['message'] | 2524 message = opts['message'] |
2537 if not message: | 2525 if not message: |
2538 message = _('Added tag %s for changeset %s') % (name, short(r)) | 2526 message = _('Added tag %s for changeset %s') % (name, short(r)) |
2539 | 2527 |