[PATCH 2 of 8 V2] revset: add a utility for obtaining the source of a given rev

Matt Harbison matt_harbison at yahoo.com
Thu Jun 7 23:58:20 CDT 2012


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1338942934 14400
# Node ID 356bb037ddc0c9ee510cb46e379bc715bce9e139
# Parent  e01c0a7fc5fdd197150500b4845e53634d196db4
revset: add a utility for obtaining the source of a given rev

graft, transplant and rebase all embed a different type of source marker in
extra, and each with a different name.  The current implementation of each is
such that there will never be more than one of these markers on a node.

Note that the rebase marker can only be resolved if the source is still present,
which excludes the typical rebase usage (without --keep) from consideration
(unless the resulting bundle in strip-backup is overlayed).  There probably
isn't any reason to use rebase --keep as a substitute for transplant or graft at
this point, but maybe there was at one point and there are even a few rebases in
the hg repo, so it may be of historical interest.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -186,6 +186,21 @@
         raise error.ParseError(_("missing argument"))
     return methods[x[0]](repo, subset, *x[1:])
 
+def _getrevsource(repo, r):
+    extra = repo[r].extra()
+
+    try:
+        for label in ('source', 'transplant_source', 'rebase_source'):
+            src = extra.get(label)
+
+            if src is not None:
+                return repo[src].rev()
+
+    except error.RepoLookupError:
+        pass
+
+    return None
+
 # operator methods
 
 def stringset(repo, subset, x):


More information about the Mercurial-devel mailing list