Patchwork D11562: errors: raise InputError from revsingle() iff revset provided by the user

login
register
mail settings
Submitter phabricator
Date Oct. 1, 2021, 7:55 p.m.
Message ID <differential-rev-PHID-DREV-cl3b2aqngj7mzwif4j3d-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49885/
State Superseded
Headers show

Comments

phabricator - Oct. 1, 2021, 7:55 p.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Same reasoning as for `revrange()` in an earlier patch.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11562

AFFECTED 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

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-strip.t b/tests/test-strip.t
--- a/tests/test-strip.t
+++ b/tests/test-strip.t
@@ -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)
diff --git a/tests/test-rebase-dest.t b/tests/test-rebase-dest.t
--- a/tests/test-rebase-dest.t
+++ b/tests/test-rebase-dest.t
@@ -162,7 +162,7 @@ 
   > A D
   > EOS
   abort: unknown revision 'SRC'
-  [255]
+  [10]
 
 Rebase to null should work:
 
diff --git a/tests/test-obshistory.t b/tests/test-obshistory.t
--- a/tests/test-obshistory.t
+++ b/tests/test-obshistory.t
@@ -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
diff --git a/tests/test-manifest.t b/tests/test-manifest.t
--- a/tests/test-manifest.t
+++ b/tests/test-manifest.t
@@ -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
diff --git a/tests/test-directaccess.t b/tests/test-directaccess.t
--- a/tests/test-directaccess.t
+++ b/tests/test-directaccess.t
@@ -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
diff --git a/tests/test-commandserver.t b/tests/test-commandserver.t
--- a/tests/test-commandserver.t
+++ b/tests/test-commandserver.t
@@ -101,7 +101,7 @@ 
   000000000000 tip
   *** runcommand id -runknown
   abort: unknown revision 'unknown'
-   [255]
+   [10]
 
   >>> from hgclient import bprint, check, readchannel
   >>> @check
diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py
+++ b/mercurial/logcmdutil.py
@@ -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.
 
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -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']:
@@ -1388,7 +1388,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),
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -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'')}
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -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')
diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -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)
diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -1663,7 +1663,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)
diff --git a/hgext/fastannotate/commands.py b/hgext/fastannotate/commands.py
--- a/hgext/fastannotate/commands.py
+++ b/hgext/fastannotate/commands.py
@@ -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'):
diff --git a/hgext/extdiff.py b/hgext/extdiff.py
--- a/hgext/extdiff.py
+++ b/hgext/extdiff.py
@@ -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:
diff --git a/hgext/closehead.py b/hgext/closehead.py
--- a/hgext/closehead.py
+++ b/hgext/closehead.py
@@ -13,9 +13,9 @@ 
     cmdutil,
     context,
     error,
+    logcmdutil,
     pycompat,
     registrar,
-    logcmdutil,
 )
 
 cmdtable = {}
diff --git a/hgext/children.py b/hgext/children.py
--- a/hgext/children.py
+++ b/hgext/children.py
@@ -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()]
diff --git a/hgext/censor.py b/hgext/censor.py
--- a/hgext/censor.py
+++ b/hgext/censor.py
@@ -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: