[PATCH 6 of 6 v4] revset: add pattern matching to 'extra' revset expression

Simon King simon at simonking.org.uk
Wed May 30 18:36:19 CDT 2012


# HG changeset patch
# User Simon King <simon at simonking.org.uk>
# Date 1338416044 -3600
# Node ID e2a89e3b29741d68f337d640281b347e374e7b51
# Parent  fc8c4e6bb44a2d8d12929d3a0361e0923c057ec8
revset: add pattern matching to 'extra' revset expression

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -502,7 +502,12 @@
 def extra(repo, subset, x):
     """``extra(label, [value])``
     Changesets with the given label in the extra metadata, with the given
-    optional value."""
+    optional value.
+
+    If `value` starts with `re:`, the remainder of the value is treated as
+    a regular expression. To match a value that actually starts with `re:`,
+    use the prefix `literal:`.
+    """
 
     l = getargs(x, 1, 2, _('extra takes at least 1 and at most 2 arguments'))
     label = getstring(l[0], _('first argument to extra must be a string'))
@@ -510,10 +515,11 @@
 
     if len(l) > 1:
         value = getstring(l[1], _('second argument to extra must be a string'))
+        kind, value, matcher = _stringmatcher(value)
 
     def _matchvalue(r):
         extra = repo[r].extra()
-        return label in extra and (value is None or value == extra[label])
+        return label in extra and (value is None or matcher(extra[label]))
 
     return [r for r in subset if _matchvalue(r)]
 
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -38,6 +38,9 @@
   0
   1
   2
+  $ hg log -r "extra('branch', 're:a')" --template '{rev} {branch}\n'
+  0 a
+  2 a-b-c-
 
   $ hg co 1
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved


More information about the Mercurial-devel mailing list