[PATCH 3 of 5 RFC] revset: add a predicate for finding grafts
Matt Harbison
matt_harbison at yahoo.com
Mon May 14 00:30:01 CDT 2012
# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1336879967 14400
# Node ID 2612b6d41579adce0df8f6b744f2879868125b5b
# Parent eabdd37ccf00e44c0f94c2494fa82f5dce773e2a
revset: add a predicate for finding grafts
This selects changesets added because of grafts. If a revision is specified,
the set will be empty if that revision is not the source of a graft, or it will
contain a destination changeset for each time the specified revision was
grafted. This can be useful for figuring out where a particular changeset has
been propagated.
The source revision may be a local identifier, the short changeset hash or the
full hash. The revision must exist, or the query is aborted.
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -561,6 +561,23 @@
getargs(x, 0, 0, _("all takes no arguments"))
return subset
+def graftof(repo, subset, x):
+ """``graftof([rev])``
+ Changesets grafted from rev, or all grafted changesets.
+ """
+
+ # i18n: "graftof" is a keyword
+ l = getargs(x, 0, 1, _('graftof takes one or no arguments'))
+
+ # i18n: "graftof" is a keyword
+ rev = l and getrev(repo, l[0], _('graftof requires a revision')) or None
+
+ def _matchvalue(r):
+ source = repo[r].extra().get('source', None)
+ return source is not None and (rev is None or rev == source)
+
+ return [r for r in subset if _matchvalue(r)]
+
def grep(repo, subset, x):
"""``grep(regex)``
Like ``keyword(string)`` but accepts a regex. Use ``grep(r'...')``
@@ -1199,6 +1216,7 @@
"first": first,
"follow": follow,
"_followfirst": _followfirst,
+ "graftof":graftof,
"grep": grep,
"head": head,
"heads": heads,
More information about the Mercurial-devel
mailing list