changeset 23978:eeb5d5ab14a6 stable

revset: raise RepoLookupError to make present() predicate continue the query Before this patch, "bookmark()", "named()" and "tag()" predicates raise "Abort", when the specified pattern doesn't match against existing ones. This prevents "present()" predicate from continuing the query, because it only catches "RepoLookupError". This patch raises "RepoLookupError" instead of "Abort", to make "present()" predicate continue the query, even if "bookmark()", "named()" or "tag()" in the sub-query of it are aborted. This patch doesn't contain raising "RepoLookupError" for "re:" pattern in "tag()", because "tag()" treats it differently from others. Actions of each predicates at failure of pattern matching can be summarized as below: predicate "literal:" "re:" ---------- ----------- ------------ bookmark abort abort named abort abort tag abort continue (*1) branch abort continue (*2) ---------- ----------- ------------ "tag()" may have to abort in the (*1) case for similarity, but this change may break backward compatibility of existing revset queries. It seems to have to be changed on "default" branch (with "BC" ?). On the other hand, (*2) seems to be reasonable, even though it breaks similarity, because "branch()" in this case doesn't check exact existence of branches, but does pick up revisions of which branch matches against the pattern. This patch also adds tests for "branch()" to clarify behavior around "present()" of similar predicates, even though this patch doesn't change "branch()".
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Sat, 31 Jan 2015 01:00:50 +0900
parents 0870bb93573c
children 087603b50889
files mercurial/revset.py tests/test-bookmarks.t tests/test-revset.t
diffstat 3 files changed, 33 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Sun Feb 01 09:36:47 2015 +0900
+++ b/mercurial/revset.py	Sat Jan 31 01:00:50 2015 +0900
@@ -496,7 +496,8 @@
         if kind == 'literal':
             bmrev = repo._bookmarks.get(pattern, None)
             if not bmrev:
-                raise util.Abort(_("bookmark '%s' does not exist") % bm)
+                raise error.RepoLookupError(_("bookmark '%s' does not exist")
+                                            % bm)
             bms.add(repo[bmrev].rev())
         else:
             matchrevs = set()
@@ -504,8 +505,8 @@
                 if matcher(name):
                     matchrevs.add(bmrev)
             if not matchrevs:
-                raise util.Abort(_("no bookmarks exist that match '%s'")
-                                 % pattern)
+                raise error.RepoLookupError(_("no bookmarks exist"
+                                              " that match '%s'") % pattern)
             for bmrev in matchrevs:
                 bms.add(repo[bmrev].rev())
     else:
@@ -1262,15 +1263,16 @@
     namespaces = set()
     if kind == 'literal':
         if pattern not in repo.names:
-            raise util.Abort(_("namespace '%s' does not exist") % ns)
+            raise error.RepoLookupError(_("namespace '%s' does not exist")
+                                        % ns)
         namespaces.add(repo.names[pattern])
     else:
         for name, ns in repo.names.iteritems():
             if matcher(name):
                 namespaces.add(ns)
         if not namespaces:
-            raise util.Abort(_("no namespace exists that match '%s'")
-                             % pattern)
+            raise error.RepoLookupError(_("no namespace exists"
+                                          " that match '%s'") % pattern)
 
     names = set()
     for ns in namespaces:
@@ -1816,7 +1818,8 @@
             # avoid resolving all tags
             tn = repo._tagscache.tags.get(pattern, None)
             if tn is None:
-                raise util.Abort(_("tag '%s' does not exist") % pattern)
+                raise error.RepoLookupError(_("tag '%s' does not exist")
+                                            % pattern)
             s = set([repo[tn].rev()])
         else:
             s = set([cl.rev(n) for t, n in repo.tagslist() if matcher(t)])
--- a/tests/test-bookmarks.t	Sun Feb 01 09:36:47 2015 +0900
+++ b/tests/test-bookmarks.t	Sat Jan 31 01:00:50 2015 +0900
@@ -133,8 +133,13 @@
   
 
   $ hg log -r 'bookmark(unknown)'
-  abort: bookmark 'unknown' does not exist
+  abort: bookmark 'unknown' does not exist!
   [255]
+  $ hg log -r 'bookmark("re:unknown")'
+  abort: no bookmarks exist that match 'unknown'!
+  [255]
+  $ hg log -r 'present(bookmark("literal:unknown"))'
+  $ hg log -r 'present(bookmark("re:unknown"))'
 
   $ hg help revsets | grep 'bookmark('
       "bookmark([name])"
--- a/tests/test-revset.t	Sun Feb 01 09:36:47 2015 +0900
+++ b/tests/test-revset.t	Sat Jan 31 01:00:50 2015 +0900
@@ -709,7 +709,7 @@
 we can use patterns when searching for tags
 
   $ log 'tag("1..*")'
-  abort: tag '1..*' does not exist
+  abort: tag '1..*' does not exist!
   [255]
   $ log 'tag("re:1..*")'
   6
@@ -720,11 +720,17 @@
   $ log 'tag("re:0..*")'
 
   $ log 'tag(unknown)'
-  abort: tag 'unknown' does not exist
+  abort: tag 'unknown' does not exist!
   [255]
+  $ log 'tag("re:unknown")'
+  $ log 'present(tag("unknown"))'
+  $ log 'present(tag("re:unknown"))'
   $ log 'branch(unknown)'
   abort: unknown revision 'unknown'!
   [255]
+  $ log 'branch("re:unknown")'
+  $ log 'present(branch("unknown"))'
+  $ log 'present(branch("re:unknown"))'
   $ log 'user(bob)'
   2
 
@@ -772,6 +778,15 @@
   3
   1
 
+  $ log 'named("unknown")'
+  abort: namespace 'unknown' does not exist!
+  [255]
+  $ log 'named("re:unknown")'
+  abort: no namespace exists that match 'unknown'!
+  [255]
+  $ log 'present(named("unknown"))'
+  $ log 'present(named("re:unknown"))'
+
 issue2437
 
   $ log '3 and p1(5)'