[PATCH 5 of 5 RFC] revset: add a predicate for finding converted changesets

Matt Harbison matt_harbison at yahoo.com
Mon May 14 00:30:03 CDT 2012


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1336885946 14400
# Node ID 9fc84795772b70acbb5f2e724d229752063dac90
# Parent  5de639cd52e36c27b4c8bbbaa5fdb44803efee72
revset: add a predicate for finding converted changesets

This selects changesets added because of repo conversions.  If a revision is
specified, the set will be empty if that revision is not the source of a
changeset in the current repository, otherwise it will contain the destination
changeset.  This can be useful for cross referencing an old repository into the
current one.

The source revision may be the short changeset hash or the full hash from the
source repository.  The local identifier isn't useful.  An interesting
ramification of this is if a short revision is specified, it may cause more
than one changeset to be selected.  (e.g. convertof(6) matches changesets with
a convert_revision field of 6e..e and 67..0)

The convert.hg.saverev option must have been specified when converting the hg
source repository for this to work.  The other sources automatically embed the
converted marker.  Repositories converted from SVN may be searchable by
specifying the revision in the form "svn:%s@%s" % (uuid, rev).

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -428,6 +428,24 @@
                     break
     return s
 
+def convertof(repo, subset, x):
+    """``convertof([rev])``
+    Changeset converted from rev in the old repo, or all converted changesets.
+    """
+
+    # There is exactly no chance of resolving the revision, so do a simple
+    # string compare and hope for the best
+
+    # i18n: "convertof" is a keyword
+    l   = getargs(x, 0, 1, _('convertof takes one or no arguments'))
+    rev = l and getstring(l[0], _('convertof requires a revision')) or None
+
+    def _matchvalue(r):
+        source = repo[r].extra().get('convert_revision', None)
+        return source is not None and (rev is None or source.startswith(rev))
+
+    return [r for r in subset if _matchvalue(r)]
+
 def date(repo, subset, x):
     """``date(interval)``
     Changesets within the interval, see :hg:`help dates`.
@@ -1230,6 +1248,7 @@
     "children": children,
     "closed": closed,
     "contains": contains,
+    "convertof": convertof,
     "date": date,
     "desc": desc,
     "descendants": descendants,


More information about the Mercurial-devel mailing list