changeset 48118:5105a9975407

errors: raise InputError from revsingle() iff revset provided by the user Same reasoning as for `revrange()` in an earlier patch. Differential Revision: https://phab.mercurial-scm.org/D11562
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 28 Sep 2021 15:11:22 -0700
parents b74e128676d4
children aec5b0981c26
files hgext/censor.py hgext/children.py hgext/closehead.py hgext/extdiff.py hgext/fastannotate/commands.py hgext/largefiles/overrides.py hgext/rebase.py mercurial/cmdutil.py mercurial/commands.py mercurial/debugcommands.py mercurial/logcmdutil.py tests/test-commandserver.t tests/test-directaccess.t tests/test-manifest.t tests/test-obshistory.t tests/test-rebase-dest.t tests/test-strip.t
diffstat 17 files changed, 64 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/censor.py	Tue Sep 28 13:59:01 2021 -0700
+++ b/hgext/censor.py	Tue Sep 28 15:11:22 2021 -0700
@@ -35,6 +35,7 @@
 
 from mercurial import (
     error,
+    logcmdutil,
     registrar,
     scmutil,
 )
@@ -84,7 +85,7 @@
     if not len(flog):
         raise error.Abort(_(b'cannot censor file with no history'))
 
-    rev = scmutil.revsingle(repo, rev, rev).rev()
+    rev = logcmdutil.revsingle(repo, rev, rev).rev()
     try:
         ctx = repo[rev]
     except KeyError:
--- a/hgext/children.py	Tue Sep 28 13:59:01 2021 -0700
+++ b/hgext/children.py	Tue Sep 28 15:11:22 2021 -0700
@@ -22,7 +22,6 @@
     logcmdutil,
     pycompat,
     registrar,
-    scmutil,
 )
 
 templateopts = cmdutil.templateopts
@@ -71,7 +70,7 @@
     """
     opts = pycompat.byteskwargs(opts)
     rev = opts.get(b'rev')
-    ctx = scmutil.revsingle(repo, rev)
+    ctx = logcmdutil.revsingle(repo, rev)
     if file_:
         fctx = repo.filectx(file_, changeid=ctx.rev())
         childctxs = [fcctx.changectx() for fcctx in fctx.children()]
--- a/hgext/closehead.py	Tue Sep 28 13:59:01 2021 -0700
+++ b/hgext/closehead.py	Tue Sep 28 15:11:22 2021 -0700
@@ -13,9 +13,9 @@
     cmdutil,
     context,
     error,
+    logcmdutil,
     pycompat,
     registrar,
-    logcmdutil,
 )
 
 cmdtable = {}
--- a/hgext/extdiff.py	Tue Sep 28 13:59:01 2021 -0700
+++ b/hgext/extdiff.py	Tue Sep 28 15:11:22 2021 -0700
@@ -559,15 +559,15 @@
     do3way = b'$parent2' in cmdline
 
     if change:
-        ctx2 = scmutil.revsingle(repo, change, None)
+        ctx2 = logcmdutil.revsingle(repo, change, None)
         ctx1a, ctx1b = ctx2.p1(), ctx2.p2()
     elif from_rev or to_rev:
         repo = scmutil.unhidehashlikerevs(
             repo, [from_rev] + [to_rev], b'nowarn'
         )
-        ctx1a = scmutil.revsingle(repo, from_rev, None)
+        ctx1a = logcmdutil.revsingle(repo, from_rev, None)
         ctx1b = repo[nullrev]
-        ctx2 = scmutil.revsingle(repo, to_rev, None)
+        ctx2 = logcmdutil.revsingle(repo, to_rev, None)
     else:
         ctx1a, ctx2 = logcmdutil.revpair(repo, revs)
         if not revs:
--- a/hgext/fastannotate/commands.py	Tue Sep 28 13:59:01 2021 -0700
+++ b/hgext/fastannotate/commands.py	Tue Sep 28 15:11:22 2021 -0700
@@ -15,6 +15,7 @@
     encoding,
     error,
     extensions,
+    logcmdutil,
     patch,
     pycompat,
     registrar,
@@ -75,7 +76,7 @@
         def bad(x, y):
             raise error.Abort(b"%s: %s" % (x, y))
 
-        ctx = scmutil.revsingle(repo, rev)
+        ctx = logcmdutil.revsingle(repo, rev)
         m = scmutil.match(ctx, pats, opts, badfn=bad)
         for p in ctx.walk(m):
             yield p
@@ -317,7 +318,7 @@
         )
     if ui.configbool(b'fastannotate', b'unfilteredrepo'):
         repo = repo.unfiltered()
-    ctx = scmutil.revsingle(repo, rev)
+    ctx = logcmdutil.revsingle(repo, rev)
     m = scmutil.match(ctx, pats, opts)
     paths = list(ctx.walk(m))
     if util.safehasattr(repo, 'prefetchfastannotate'):
--- a/hgext/largefiles/overrides.py	Tue Sep 28 13:59:01 2021 -0700
+++ b/hgext/largefiles/overrides.py	Tue Sep 28 15:11:22 2021 -0700
@@ -1667,7 +1667,7 @@
 @eh.wrapcommand(b'cat')
 def overridecat(orig, ui, repo, file1, *pats, **opts):
     opts = pycompat.byteskwargs(opts)
-    ctx = scmutil.revsingle(repo, opts.get(b'rev'))
+    ctx = logcmdutil.revsingle(repo, opts.get(b'rev'))
     err = 1
     notbad = set()
     m = scmutil.match(ctx, (file1,) + pats, opts)
--- a/hgext/rebase.py	Tue Sep 28 13:59:01 2021 -0700
+++ b/hgext/rebase.py	Tue Sep 28 15:11:22 2021 -0700
@@ -1323,7 +1323,7 @@
             return None
         if destf:
             # --base does not support multiple destinations
-            dest = scmutil.revsingle(repo, destf)
+            dest = logcmdutil.revsingle(repo, destf)
         else:
             dest = repo[_destrebase(repo, base, destspace=destspace)]
             destf = bytes(dest)
--- a/mercurial/cmdutil.py	Tue Sep 28 13:59:01 2021 -0700
+++ b/mercurial/cmdutil.py	Tue Sep 28 15:11:22 2021 -0700
@@ -1480,7 +1480,7 @@
             # TODO: Remove this restriction and make it also create the copy
             #       targets (and remove the rename source if rename==True).
             raise error.InputError(_(b'--at-rev requires --after'))
-        ctx = scmutil.revsingle(repo, rev)
+        ctx = logcmdutil.revsingle(repo, rev)
         if len(ctx.parents()) > 1:
             raise error.InputError(
                 _(b'cannot mark/unmark copy in merge commit')
--- a/mercurial/commands.py	Tue Sep 28 13:59:01 2021 -0700
+++ b/mercurial/commands.py	Tue Sep 28 15:11:22 2021 -0700
@@ -445,7 +445,7 @@
     rev = opts.get(b'rev')
     if rev:
         repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn')
-    ctx = scmutil.revsingle(repo, rev)
+    ctx = logcmdutil.revsingle(repo, rev)
 
     ui.pager(b'annotate')
     rootfm = ui.formatter(b'annotate', opts)
@@ -649,7 +649,7 @@
     rev = opts.get(b'rev')
     if rev:
         repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn')
-    ctx = scmutil.revsingle(repo, rev)
+    ctx = logcmdutil.revsingle(repo, rev)
     if not ctx:
         raise error.InputError(
             _(b'no working directory: please specify a revision')
@@ -791,7 +791,7 @@
 
     cmdutil.checkunfinished(repo)
     cmdutil.bailifchanged(repo)
-    ctx = scmutil.revsingle(repo, rev)
+    ctx = logcmdutil.revsingle(repo, rev)
     node = ctx.node()
 
     op1, op2 = repo.dirstate.parents()
@@ -1761,7 +1761,7 @@
     rev = opts.get(b'rev')
     if rev:
         repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn')
-    ctx = scmutil.revsingle(repo, rev)
+    ctx = logcmdutil.revsingle(repo, rev)
     m = scmutil.match(ctx, (file1,) + pats, opts)
     fntemplate = opts.pop(b'output', b'')
     if cmdutil.isstdiofilename(fntemplate):
@@ -2600,14 +2600,14 @@
     cmdutil.check_incompatible_arguments(opts, b'to', [b'rev', b'change'])
     if change:
         repo = scmutil.unhidehashlikerevs(repo, [change], b'nowarn')
-        ctx2 = scmutil.revsingle(repo, change, None)
+        ctx2 = logcmdutil.revsingle(repo, change, None)
         ctx1 = logcmdutil.diff_parent(ctx2)
     elif from_rev or to_rev:
         repo = scmutil.unhidehashlikerevs(
             repo, [from_rev] + [to_rev], b'nowarn'
         )
-        ctx1 = scmutil.revsingle(repo, from_rev, None)
-        ctx2 = scmutil.revsingle(repo, to_rev, None)
+        ctx1 = logcmdutil.revsingle(repo, from_rev, None)
+        ctx2 = logcmdutil.revsingle(repo, to_rev, None)
     else:
         repo = scmutil.unhidehashlikerevs(repo, revs, b'nowarn')
         ctx1, ctx2 = logcmdutil.revpair(repo, revs)
@@ -2864,7 +2864,7 @@
     rev = opts.get(b'rev')
     if rev:
         repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn')
-    ctx = scmutil.revsingle(repo, rev, None)
+    ctx = logcmdutil.revsingle(repo, rev, None)
 
     end = b'\n'
     if opts.get(b'print0'):
@@ -3175,7 +3175,7 @@
     skipped = set()
     basectx = None
     if opts.get('base'):
-        basectx = scmutil.revsingle(repo, opts['base'], None)
+        basectx = logcmdutil.revsingle(repo, opts['base'], None)
     if basectx is None:
         # check for merges
         for rev in repo.revs(b'%ld and merge()', revs):
@@ -3696,7 +3696,7 @@
     rev = opts.get(b'rev')
     if rev:
         repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn')
-        start = scmutil.revsingle(repo, rev, None).node()
+        start = logcmdutil.revsingle(repo, rev, None).node()
 
     if opts.get(b'topo'):
         heads = [repo[h] for h in repo.heads(start)]
@@ -3932,7 +3932,7 @@
         else:
             if rev:
                 repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn')
-            ctx = scmutil.revsingle(repo, rev, None)
+            ctx = logcmdutil.revsingle(repo, rev, None)
 
             if ctx.rev() is None:
                 ctx = repo[None]
@@ -4445,7 +4445,7 @@
         end = b'\0'
     else:
         end = b'\n'
-    ctx = scmutil.revsingle(repo, opts.get(b'rev'), None)
+    ctx = logcmdutil.revsingle(repo, opts.get(b'rev'), None)
 
     ret = 1
     m = scmutil.match(
@@ -4790,7 +4790,7 @@
     mode = {b'l': b'644', b'x': b'755', b'': b'644', b't': b'755'}
     if node:
         repo = scmutil.unhidehashlikerevs(repo, [node], b'nowarn')
-    ctx = scmutil.revsingle(repo, node)
+    ctx = logcmdutil.revsingle(repo, node)
     mf = ctx.manifest()
     ui.pager(b'manifest')
     for f in ctx:
@@ -4877,7 +4877,7 @@
         node = opts.get(b'rev')
 
     if node:
-        ctx = scmutil.revsingle(repo, node)
+        ctx = logcmdutil.revsingle(repo, node)
     else:
         if ui.configbool(b'commands', b'merge.require-rev'):
             raise error.InputError(
@@ -5056,7 +5056,7 @@
     rev = opts.get(b'rev')
     if rev:
         repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn')
-    ctx = scmutil.revsingle(repo, rev, None)
+    ctx = logcmdutil.revsingle(repo, rev, None)
 
     if file_:
         m = scmutil.match(ctx, (file_,), opts)
@@ -6347,7 +6347,7 @@
     rev = opts.get(b'rev')
     if rev:
         repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn')
-    ctx = scmutil.revsingle(repo, rev)
+    ctx = logcmdutil.revsingle(repo, rev)
 
     if not (
         pats
@@ -6905,7 +6905,7 @@
         raise error.InputError(msg)
     elif change:
         repo = scmutil.unhidehashlikerevs(repo, [change], b'nowarn')
-        ctx2 = scmutil.revsingle(repo, change, None)
+        ctx2 = logcmdutil.revsingle(repo, change, None)
         ctx1 = ctx2.p1()
     else:
         repo = scmutil.unhidehashlikerevs(repo, revs, b'nowarn')
@@ -7453,7 +7453,7 @@
                         b'(use -f to force)'
                     )
                 )
-        node = scmutil.revsingle(repo, rev_).node()
+        node = logcmdutil.revsingle(repo, rev_).node()
 
         if not message:
             # we don't translate commit messages
@@ -7477,7 +7477,7 @@
         # don't allow tagging the null rev
         if (
             not opts.get(b'remove')
-            and scmutil.revsingle(repo, rev_).rev() == nullrev
+            and logcmdutil.revsingle(repo, rev_).rev() == nullrev
         ):
             raise error.InputError(_(b"cannot tag null revision"))
 
@@ -7840,7 +7840,7 @@
         brev = rev
         if rev:
             repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn')
-        ctx = scmutil.revsingle(repo, rev, default=None)
+        ctx = logcmdutil.revsingle(repo, rev, default=None)
         rev = ctx.rev()
         hidden = ctx.hidden()
         overrides = {(b'ui', b'forcemerge'): opts.get('tool', b'')}
--- a/mercurial/debugcommands.py	Tue Sep 28 13:59:01 2021 -0700
+++ b/mercurial/debugcommands.py	Tue Sep 28 15:11:22 2021 -0700
@@ -506,7 +506,7 @@
 )
 def debugchangedfiles(ui, repo, rev, **opts):
     """list the stored files changes for a revision"""
-    ctx = scmutil.revsingle(repo, rev, None)
+    ctx = logcmdutil.revsingle(repo, rev, None)
     files = None
 
     if opts['compute']:
@@ -1373,7 +1373,7 @@
 
     fileset.symbols  # force import of fileset so we have predicates to optimize
     opts = pycompat.byteskwargs(opts)
-    ctx = scmutil.revsingle(repo, opts.get(b'rev'), None)
+    ctx = logcmdutil.revsingle(repo, opts.get(b'rev'), None)
 
     stages = [
         (b'parsed', pycompat.identity),
--- a/mercurial/logcmdutil.py	Tue Sep 28 13:59:01 2021 -0700
+++ b/mercurial/logcmdutil.py	Tue Sep 28 15:11:22 2021 -0700
@@ -912,6 +912,18 @@
     return None
 
 
+def revsingle(repo, revspec, default=b'.', localalias=None):
+    """Resolves user-provided revset(s) into a single revision.
+
+    This just wraps the lower-level scmutil.revsingle() in order to raise an
+    exception indicating user error.
+    """
+    try:
+        return scmutil.revsingle(repo, revspec, default, localalias)
+    except error.RepoLookupError as e:
+        raise error.InputError(e.args[0], hint=e.hint)
+
+
 def revpair(repo, revs):
     """Resolves user-provided revset(s) into two revisions.
 
--- a/tests/test-commandserver.t	Tue Sep 28 13:59:01 2021 -0700
+++ b/tests/test-commandserver.t	Tue Sep 28 15:11:22 2021 -0700
@@ -101,7 +101,7 @@
   000000000000 tip
   *** runcommand id -runknown
   abort: unknown revision 'unknown'
-   [255]
+   [10]
 
   >>> from hgclient import bprint, check, readchannel
   >>> @check
--- a/tests/test-directaccess.t	Tue Sep 28 13:59:01 2021 -0700
+++ b/tests/test-directaccess.t	Tue Sep 28 15:11:22 2021 -0700
@@ -75,7 +75,7 @@
   $ hg status --change 2 --config experimental.directaccess.revnums=False
   abort: hidden revision '2' was rewritten as: 2443a0e66469
   (use --hidden to access hidden revisions)
-  [255]
+  [10]
 
   $ hg diff -c 2
   diff -r 29becc82797a -r 28ad74487de9 c
--- a/tests/test-manifest.t	Tue Sep 28 13:59:01 2021 -0700
+++ b/tests/test-manifest.t	Tue Sep 28 15:11:22 2021 -0700
@@ -88,7 +88,7 @@
 
   $ hg manifest -r 2
   abort: unknown revision '2'
-  [255]
+  [10]
 
   $ hg manifest -r tip tip
   abort: please specify just one revision
--- a/tests/test-obshistory.t	Tue Sep 28 13:59:01 2021 -0700
+++ b/tests/test-obshistory.t	Tue Sep 28 15:11:22 2021 -0700
@@ -54,7 +54,7 @@
   $ hg update 471f378eab4c
   abort: hidden revision '471f378eab4c' was rewritten as: 4ae3a4151de9
   (use --hidden to access hidden revisions)
-  [255]
+  [10]
   $ hg update --hidden "desc(A0)"
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   updated to hidden changeset 471f378eab4c
@@ -118,7 +118,7 @@
   $ hg up 0dec01379d3b
   abort: hidden revision '0dec01379d3b' is pruned
   (use --hidden to access hidden revisions)
-  [255]
+  [10]
   $ hg up --hidden -r 'desc(B0)'
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   updated to hidden changeset 0dec01379d3b
@@ -196,7 +196,7 @@
   $ hg update 471597cad322
   abort: hidden revision '471597cad322' was split as: 337fec4d2edc, f257fde29c7a
   (use --hidden to access hidden revisions)
-  [255]
+  [10]
   $ hg update --hidden 'min(desc(A0))'
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   updated to hidden changeset 471597cad322
@@ -296,7 +296,7 @@
   $ hg update de7290d8b885
   abort: hidden revision 'de7290d8b885' was split as: 337fec4d2edc, f257fde29c7a and 2 more
   (use --hidden to access hidden revisions)
-  [255]
+  [10]
   $ hg update --hidden 'min(desc(A0))'
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   updated to hidden changeset de7290d8b885
@@ -377,7 +377,7 @@
   $ hg update 471f378eab4c
   abort: hidden revision '471f378eab4c' was rewritten as: eb5a0daa2192
   (use --hidden to access hidden revisions)
-  [255]
+  [10]
   $ hg update --hidden 'desc(A0)'
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
   updated to hidden changeset 471f378eab4c
@@ -385,7 +385,7 @@
   $ hg update 0dec01379d3b
   abort: hidden revision '0dec01379d3b' was rewritten as: eb5a0daa2192
   (use --hidden to access hidden revisions)
-  [255]
+  [10]
   $ hg update --hidden 'desc(B0)'
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   updated to hidden changeset 0dec01379d3b
@@ -460,7 +460,7 @@
   $ hg update 471f378eab4c
   abort: hidden revision '471f378eab4c' has diverged
   (use --hidden to access hidden revisions)
-  [255]
+  [10]
   $ hg update --hidden 'desc(A0)'
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   updated to hidden changeset 471f378eab4c
@@ -557,7 +557,7 @@
   $ hg update 471f378eab4c
   abort: hidden revision '471f378eab4c' was rewritten as: eb5a0daa2192
   (use --hidden to access hidden revisions)
-  [255]
+  [10]
   $ hg update --hidden 'desc(A0)'
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
   updated to hidden changeset 471f378eab4c
--- a/tests/test-rebase-dest.t	Tue Sep 28 13:59:01 2021 -0700
+++ b/tests/test-rebase-dest.t	Tue Sep 28 15:11:22 2021 -0700
@@ -162,7 +162,7 @@
   > A D
   > EOS
   abort: unknown revision 'SRC'
-  [255]
+  [10]
 
 Rebase to null should work:
 
--- a/tests/test-strip.t	Tue Sep 28 13:59:01 2021 -0700
+++ b/tests/test-strip.t	Tue Sep 28 15:11:22 2021 -0700
@@ -709,7 +709,7 @@
   bookmark 'todelete' deleted
   $ hg id -ir dcbb326fdec2
   abort: unknown revision 'dcbb326fdec2'
-  [255]
+  [10]
   $ hg id -ir d62d843c9a01
   d62d843c9a01
   $ hg bookmarks
@@ -725,17 +725,17 @@
   bookmark 'multipledelete2' deleted
   $ hg id -ir e46a4836065c
   abort: unknown revision 'e46a4836065c'
-  [255]
+  [10]
   $ hg id -ir b4594d867745
   abort: unknown revision 'b4594d867745'
-  [255]
+  [10]
   $ hg strip -B singlenode1 -B singlenode2
   saved backup bundle to $TESTTMP/bookmarks/.hg/strip-backup/43227190fef8-8da858f2-backup.hg
   bookmark 'singlenode1' deleted
   bookmark 'singlenode2' deleted
   $ hg id -ir 43227190fef8
   abort: unknown revision '43227190fef8'
-  [255]
+  [10]
   $ hg strip -B unknownbookmark
   abort: bookmark 'unknownbookmark' not found
   [255]
@@ -750,7 +750,7 @@
   bookmark 'delete' deleted
   $ hg id -ir 6:2702dd0c91e7
   abort: unknown revision '2702dd0c91e7'
-  [255]
+  [10]
   $ hg update B
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   (activating bookmark B)