[PATCH 5 of 9] revset: abort the query when there is no revision for "rev()" (BC)

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Sun Mar 29 13:34:27 CDT 2015


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1427653752 -32400
#      Mon Mar 30 03:29:12 2015 +0900
# Node ID f9e9783d4f10af2974d77dbfaacd217f24fd3035
# Parent  efa05b47238ba2a0bca69cd40b8e2e1aed3a2cf2
revset: abort the query when there is no revision for "rev()" (BC)

Before this patch, "REV" and "rev(REV)" differ from each other:

    target      REV          rev(REV)
    ----------- ------------ ------------
    known       pass         pass
    hidden      abort (*1)   pass (=> empty set)
    unknown     abort        pass (=> empty set)

    (*1) abort with "use --hidden" hint

For equivalence between them, "rev(REV)" should abort the query for
hidden or unknown revisions, even though this may break backward
compatibility for existing tools, which expect that "rev()" doesn't
abort the query in any cases.

This patch uses "context.findbyrevnum()" (via repo) to abort if the
target revision doesn't exist or isn't visible.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1540,6 +1540,10 @@ def removes(repo, subset, x):
 def rev(repo, subset, x):
     """``rev(number)``
     Revision with the given numeric identifier.
+
+    This predicate aborts the query, if the specified number doesn't
+    refer any (visible) existing revision. Use this with ``present()``
+    to continue the query even in such case.
     """
     # i18n: "rev" is a keyword
     l = getargs(x, 1, 1, _("rev requires one argument"))
@@ -1549,8 +1553,9 @@ def rev(repo, subset, x):
     except (TypeError, ValueError):
         # i18n: "rev" is a keyword
         raise error.ParseError(_("rev expects a number"))
-    if l not in repo.changelog and l != node.nullrev:
-        return baseset()
+
+    repo.findbyrevnum(l, abort=True)
+
     return subset & baseset([l])
 
 def matching(repo, subset, x):
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -186,7 +186,14 @@ check that various commands work well wi
   (use --hidden to access hidden revisions)
   [255]
   $ hg debugrevspec 'rev(6)'
+  abort: unknown revision '6'!
+  [255]
   $ hg debugrevspec 'rev(4)'
+  abort: hidden revision '4'!
+  (use --hidden to access hidden revisions)
+  [255]
+  $ hg debugrevspec --hidden 'rev(4)'
+  4
   $ hg debugrevspec 'null'
   -1
 
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -543,6 +543,8 @@ Test the order of operations
 
 Test explicit numeric revision
   $ log 'rev(-2)'
+  abort: unknown revision '-2'!
+  [255]
   $ log 'rev(-1)'
   -1
   $ log 'rev(0)'
@@ -550,6 +552,9 @@ Test explicit numeric revision
   $ log 'rev(9)'
   9
   $ log 'rev(10)'
+  abort: unknown revision '10'!
+  [255]
+  $ log 'present(rev(10))'
   $ log 'rev(tip)'
   hg: parse error: rev expects a number
   [255]


More information about the Mercurial-devel mailing list