[PATCH v2] revset: add function for matching extra data (issue2767)
Henrik Stuart
hg at hstuart.dk
Sat May 12 02:29:21 CDT 2012
# HG changeset patch
# User Henrik Stuart <hg at hstuart.dk>
# Date 1336807743 -7200
# Node ID 3f29a2abe5fc2b142045fabd30d2b92930c958a2
# Parent 775a8d33e6f0526efab8b24a47cd1d72b396b22c
revset: add function for matching extra data (issue2767)
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -464,6 +464,24 @@
getargs(x, 0, 0, _("draft takes no arguments"))
return [r for r in subset if repo._phaserev[r] == phases.draft]
+def extra(repo, subset, x):
+ """``extra(label, [value])``
+ Changesets with the given label in the extra metadata, with the given
+ optional value."""
+
+ 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'))
+ value = None
+
+ if len(l) > 1:
+ value = getstring(l[1], _('second argument to extra must be a string'))
+
+ def _matchvalue(r):
+ v = repo[r].extra().get(label)
+ return value is None or v == value
+
+ return [r for r in subset if _matchvalue(r)]
+
def filelog(repo, subset, x):
"""``filelog(pattern)``
Changesets connected to the specified filelog.
@@ -1145,6 +1163,7 @@
"descendants": descendants,
"_firstdescendants": _firstdescendants,
"draft": draft,
+ "extra": extra,
"file": hasfile,
"filelog": filelog,
"first": first,
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -32,6 +32,13 @@
(branches are permanent and global, did you want a bookmark?)
$ hg ci -Aqm2 -u Bob
+ $ hg log -r "extra('branch', 'a-b-c-')" --template '{rev}\n'
+ 2
+ $ hg log -r "extra('branch')" --template '{rev}\n'
+ 0
+ 1
+ 2
+
$ hg co 1
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg branch +a+b+c+
More information about the Mercurial-devel
mailing list