[PATCH 1 of 8 V2] revset: add a predicate for finding converted changesets

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


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

This selects changesets added because of repo conversions.  For example

    hg log -r "converted()"      # all csets created by a convertion
    hg log -r "converted(rev)"   # the cset converted from rev in the src repo

The converted(rev) form is analogous to remote(id), where the remote repo is
the source of the conversion.  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. converted(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.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -490,6 +490,25 @@
                     break
     return s
 
+def converted(repo, subset, x):
+    """``converted([id])``
+    Changesets converted from the given identifier in the old repository if
+    present, or all converted changesets if no identifier is specified.
+    """
+
+    # There is exactly no chance of resolving the revision, so do a simple
+    # string compare and hope for the best
+
+    # i18n: "converted" is a keyword
+    l   = getargs(x, 0, 1, _('converted takes one or no arguments'))
+    rev = l and getstring(l[0], _('converted 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`.
@@ -1302,6 +1321,7 @@
     "children": children,
     "closed": closed,
     "contains": contains,
+    "converted": converted,
     "date": date,
     "desc": desc,
     "descendants": descendants,
diff --git a/tests/test-convert.t b/tests/test-convert.t
--- a/tests/test-convert.t
+++ b/tests/test-convert.t
@@ -393,3 +393,52 @@
   $ hg convert -q bzr+ssh://foobar@selenic.com/baz baz
   abort: bzr+ssh://foobar@selenic.com/baz: missing or unsupported repository
   [255]
+
+test revset converted() lookup
+
+  $ hg --config convert.hg.saverev=True convert a c  
+  initializing destination c repository
+  scanning source...
+  sorting...
+  converting...
+  4 a
+  3 b
+  2 c
+  1 d
+  0 e
+  $ echo f > c/f
+  $ hg -R c ci -d'0 0' -Amf
+  adding f
+  created new head
+  $ hg -R c log -r "converted(09d945a62ce6)"
+  changeset:   1:98c3dd46a874
+  user:        test
+  date:        Thu Jan 01 00:00:01 1970 +0000
+  summary:     b
+  
+  $ hg -R c log -r "converted()"
+  changeset:   0:31ed57b2037c
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     a
+  
+  changeset:   1:98c3dd46a874
+  user:        test
+  date:        Thu Jan 01 00:00:01 1970 +0000
+  summary:     b
+  
+  changeset:   2:3b9ca06ef716
+  user:        test
+  date:        Thu Jan 01 00:00:02 1970 +0000
+  summary:     c
+  
+  changeset:   3:4e0debd37cf2
+  user:        test
+  date:        Thu Jan 01 00:00:03 1970 +0000
+  summary:     d
+  
+  changeset:   4:9de3bc9349c5
+  user:        test
+  date:        Thu Jan 01 00:00:04 1970 +0000
+  summary:     e
+  


More information about the Mercurial-devel mailing list