[PATCH 1 of 1 RFC] revset: predicate to avoid lookup errors

Wagner Bruna wagner.bruna+mercurial at gmail.com
Tue Jun 22 17:31:24 CDT 2010


# HG changeset patch
# User Wagner Bruna <wbruna at softwareexpress.com.br>
# Date 1277245324 10800
# Branch stable
# Node ID 62f765f97c0519300c82a5c55a25477ebd57c845
# Parent  2186124f08e4789b4eb45617e7efee19ff790b34
revset: predicate to avoid lookup errors

Currently, querying for any unknown revision throws a RepoLookupError.
So, a query like

head() and (descendants("badrev") and not descendants("fixrev"))

(testing if repo heads are affected by a bug) will abort if either
badrev or fixrev aren't found inside the repository.

The new predicate simply replaces the exception with an empty
set, so

head() and (descendants(present("badrev")) and not descendants(present("fix")))

will behave as wanted, even if those revisions aren't found.

diff --git a/mercurial/help/revsets.txt b/mercurial/help/revsets.txt
--- a/mercurial/help/revsets.txt
+++ b/mercurial/help/revsets.txt
@@ -119,6 +119,10 @@
 ``parents(set)``
   The set of all parents for all changesets in set.
 
+``present(set)``
+  An empty set, if any revision in set isn't found; otherwise,
+  all revisions in set.
+
 ``removes(pattern)``
   Changesets which remove files matching pattern.
 
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -354,6 +354,12 @@
     l.reverse()
     return l
 
+def present(repo, subset, x):
+    try:
+        return getset(repo, subset, x)
+    except error.RepoLookupError:
+        return []
+
 def sort(repo, subset, x):
     l = getargs(x, 1, 2, _("sort wants one or two arguments"))
     keys = "rev"
@@ -457,6 +463,7 @@
     "p1": p1,
     "p2": p2,
     "parents": parents,
+    "present": present,
     "removes": removes,
     "reverse": reverse,
     "roots": roots,


More information about the Mercurial-devel mailing list