scmutil: introduce deprecated alias for revpair()
authorMartin von Zweigbergk <martinvonz@google.com>
Sat, 31 Mar 2018 23:37:25 -0700
changeset 44812 7c0f40f4f7bf8b09a8d6ee57e6cee6eca06afe17
parent 44811 9640ccf44ac0b8b9c1407e8e74a16fb2ea4b5120
child 44813 e9ee540af434092b40a9ea4990e0746642f3040f
push id775
push usergszorc@mozilla.com
push dateTue, 03 Apr 2018 03:53:32 +0000
scmutil: introduce deprecated alias for revpair() revsingle() returns a context object, revpair() returns nodeids, revrange() returns integer revisions (in a revset). I'm going to reduce this inconsistency by making revpair() return context objects. Changing the return type is not nice to extensions, so this patch introduces a nodeid-returning version of revpair() that they can detect and use. Update callers to the new function so we can change revpair() itself and then migrate them back one by one. Differential Revision: https://phab.mercurial-scm.org/D3005
hgext/extdiff.py
mercurial/commands.py
mercurial/fileset.py
mercurial/scmutil.py
tests/autodiff.py
--- a/hgext/extdiff.py
+++ b/hgext/extdiff.py
@@ -166,17 +166,17 @@ def dodiff(ui, repo, cmdline, pats, opts
 
     if revs and change:
         msg = _('cannot specify --rev and --change at the same time')
         raise error.Abort(msg)
     elif change:
         node2 = scmutil.revsingle(repo, change, None).node()
         node1a, node1b = repo.changelog.parents(node2)
     else:
-        node1a, node2 = scmutil.revpair(repo, revs)
+        node1a, node2 = scmutil.revpairnodes(repo, revs)
         if not revs:
             node1b = repo.dirstate.p2()
         else:
             node1b = nullid
 
     # Disable 3-way merge if there is only one parent
     if do3way:
         if node1b == nullid:
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1873,17 +1873,17 @@ def diff(ui, repo, *pats, **opts):
         msg = _('cannot specify --rev and --change at the same time')
         raise error.Abort(msg)
     elif change:
         repo = scmutil.unhidehashlikerevs(repo, [change], 'nowarn')
         node2 = scmutil.revsingle(repo, change, None).node()
         node1 = repo[node2].p1().node()
     else:
         repo = scmutil.unhidehashlikerevs(repo, revs, 'nowarn')
-        node1, node2 = scmutil.revpair(repo, revs)
+        node1, node2 = scmutil.revpairnodes(repo, revs)
 
     if reverse:
         node1, node2 = node2, node1
 
     diffopts = patch.diffallopts(ui, opts)
     m = scmutil.match(repo[node2], pats, opts)
     ui.pager('diff')
     logcmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat,
@@ -4875,17 +4875,17 @@ def status(ui, repo, *pats, **opts):
         msg = _('cannot use --terse with --rev')
         raise error.Abort(msg)
     elif change:
         repo = scmutil.unhidehashlikerevs(repo, [change], 'nowarn')
         node2 = scmutil.revsingle(repo, change, None).node()
         node1 = repo[node2].p1().node()
     else:
         repo = scmutil.unhidehashlikerevs(repo, revs, 'nowarn')
-        node1, node2 = scmutil.revpair(repo, revs)
+        node1, node2 = scmutil.revpairnodes(repo, revs)
 
     if pats or ui.configbool('commands', 'status.relative'):
         cwd = repo.getcwd()
     else:
         cwd = ''
 
     if opts.get('print0'):
         end = '\0'
--- a/mercurial/fileset.py
+++ b/mercurial/fileset.py
@@ -508,17 +508,17 @@ def status(mctx, x):
     baseerr = _("first argument to status must be a revision")
     baserevspec = getstring(b, baseerr)
     if not baserevspec:
         raise error.ParseError(baseerr)
     reverr = _("second argument to status must be a revision")
     revspec = getstring(r, reverr)
     if not revspec:
         raise error.ParseError(reverr)
-    basenode, node = scmutil.revpair(repo, [baserevspec, revspec])
+    basenode, node = scmutil.revpairnodes(repo, [baserevspec, revspec])
     basectx = repo[basenode]
     ctx = repo[node]
     return getset(mctx.switch(ctx, _buildstatus(ctx, x, basectx=basectx)), x)
 
 @predicate('subrepo([pattern])')
 def subrepo(mctx, x):
     """Subrepositories whose paths match the given pattern.
     """
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -441,16 +441,19 @@ def revsingle(repo, revspec, default='.'
     if not l:
         raise error.Abort(_('empty revision set'))
     return repo[l.last()]
 
 def _pairspec(revspec):
     tree = revsetlang.parse(revspec)
     return tree and tree[0] in ('range', 'rangepre', 'rangepost', 'rangeall')
 
+def revpairnodes(repo, revs):
+    return revpair(repo, revs)
+
 def revpair(repo, revs):
     if not revs:
         return repo.dirstate.p1(), None
 
     l = revrange(repo, revs)
 
     if not l:
         first = second = None
--- a/tests/autodiff.py
+++ b/tests/autodiff.py
@@ -35,16 +35,16 @@ def autodiff(ui, repo, *pats, **opts):
     elif git == b'abort':
         diffopts.git = False
         diffopts.upgrade = True
         def losedatafn(fn=None, **kwargs):
             raise error.Abort(b'losing data for %s' % fn)
     else:
         raise error.Abort(b'--git must be yes, no or auto')
 
-    node1, node2 = scmutil.revpair(repo, [])
+    node1, node2 = scmutil.revpairnodes(repo, [])
     m = scmutil.match(repo[node2], pats, opts)
     it = patch.diff(repo, node1, node2, match=m, opts=diffopts,
                     losedatafn=losedatafn)
     for chunk in it:
         ui.write(chunk)
     for fn in sorted(brokenfiles):
         ui.write((b'data lost for: %s\n' % fn))