Show More
@@ -50,21 +50,6 b' def logmessage(opts):' | |||||
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 | |||
@@ -114,7 +99,7 b' def walkchangerevs(ui, repo, pats, opts)' | |||||
114 | return [], False, matchfn |
|
99 | return [], False, matchfn | |
115 |
|
100 | |||
116 | if follow: |
|
101 | if follow: | |
117 |
defrange = '%s:0' % |
|
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])) | |
@@ -646,7 +631,7 b' def annotate(ui, repo, *pats, **opts):' | |||||
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( |
|
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()): | |
@@ -693,7 +678,7 b' def archive(ui, repo, dest, **opts):' | |||||
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. |
|
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')) | |
@@ -810,7 +795,7 b' def cat(ui, repo, file1, *pats, **opts):' | |||||
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( |
|
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) | |
@@ -2228,7 +2213,10 b' def revert(ui, repo, *pats, **opts):' | |||||
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 | |
@@ -2528,10 +2516,10 b' def tag(ui, repo, name, rev_=None, **opt' | |||||
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: |
@@ -8,10 +8,19 b'' | |||||
8 | class changectx(object): |
|
8 | class changectx(object): | |
9 | """A changecontext object makes access to data related to a particular |
|
9 | """A changecontext object makes access to data related to a particular | |
10 | changeset convenient.""" |
|
10 | changeset convenient.""" | |
11 | def __init__(self, repo, changeid): |
|
11 | def __init__(self, repo, changeid=None): | |
12 | """changeid is a revision number, node, or tag""" |
|
12 | """changeid is a revision number, node, or tag""" | |
13 | self._repo = repo |
|
13 | self._repo = repo | |
14 |
|
14 | |||
|
15 | if not changeid: | |||
|
16 | p1, p2 = self._repo.dirstate.parents() | |||
|
17 | self._rev = self._repo.changelog.rev(p1) | |||
|
18 | if self._rev == -1: | |||
|
19 | changeid = 'tip' | |||
|
20 | else: | |||
|
21 | self._node = p1 | |||
|
22 | return | |||
|
23 | ||||
15 | self._node = self._repo.lookup(changeid) |
|
24 | self._node = self._repo.lookup(changeid) | |
16 | self._rev = self._repo.changelog.rev(self._node) |
|
25 | self._rev = self._repo.changelog.rev(self._node) | |
17 |
|
26 |
@@ -318,7 +318,7 b' class localrepository(repo.repository):' | |||||
318 | f = f[1:] |
|
318 | f = f[1:] | |
319 | return filelog.filelog(self.opener, f, self.revlogversion) |
|
319 | return filelog.filelog(self.opener, f, self.revlogversion) | |
320 |
|
320 | |||
321 | def changectx(self, changeid): |
|
321 | def changectx(self, changeid=None): | |
322 | return context.changectx(self, changeid) |
|
322 | return context.changectx(self, changeid) | |
323 |
|
323 | |||
324 | def filectx(self, path, changeid=None, fileid=None): |
|
324 | def filectx(self, path, changeid=None, fileid=None): |
General Comments 0
You need to be logged in to leave comments.
Login now