changeset 21765:44255f7ce886

convert: update the transplant, rebase and graft references in 'extra' This change allows the origin() and destination() revsets to yield the same results in the new and old repos after a conversion. Previously, nothing would be listed for queries in the new repo. Like the SHA1 updates to the commit messages, this is only operational when the 'convert.hg.saverev=True' option is specified. If the old reference cannot be found, it is left as-is. It seems slightly better to leave stale evidence of the graft/transplant/rebase than to eliminate it entirely.
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 11 Jun 2014 22:19:29 -0400
parents cd3c79392056
children a039e1f2326f
files hgext/convert/hg.py tests/test-graft.t
diffstat 2 files changed, 49 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/hg.py	Wed Jun 18 20:59:36 2014 -0500
+++ b/hgext/convert/hg.py	Wed Jun 11 22:19:29 2014 -0400
@@ -165,6 +165,24 @@
                 text = text.replace(sha1, newrev[:len(sha1)])
 
         extra = commit.extra.copy()
+
+        for label in ('source', 'transplant_source', 'rebase_source'):
+            node = extra.get(label)
+
+            if node is None:
+                continue
+
+            # Only transplant stores its reference in binary
+            if label == 'transplant_source':
+                node = hex(node)
+
+            newrev = revmap.get(node)
+            if newrev is not None:
+                if label == 'transplant_source':
+                    newrev = bin(newrev)
+
+                extra[label] = newrev
+
         if self.branchnames and commit.branch:
             extra['branch'] = commit.branch
         if commit.rev:
--- a/tests/test-graft.t	Wed Jun 18 20:59:36 2014 -0500
+++ b/tests/test-graft.t	Wed Jun 11 22:19:29 2014 -0400
@@ -461,6 +461,37 @@
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     2
   
+Test that the graft and transplant markers in extra are converted, allowing
+origin() to still work.  Note that these recheck the immediately preceeding two
+tests.
+  $ hg --quiet --config extensions.convert= --config convert.hg.saverev=True convert . ../converted
+
+The graft case
+  $ hg -R ../converted log -r 7 --template "{rev}: {node}\n{join(extras, '\n')}\n"
+  7: 7ae846e9111fc8f57745634250c7b9ac0a60689b
+  branch=default
+  convert_revision=ef0ef43d49e79e81ddafdc7997401ba0041efc82
+  source=e0213322b2c1a5d5d236c74e79666441bee67a7d
+  $ hg -R ../converted log -r 'origin(7)'
+  changeset:   2:e0213322b2c1
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     2
+  
+The transplant case
+  $ hg -R ../converted log -r tip --template "{rev}: {node}\n{join(extras, '\n')}\n"
+  21: fbb6c5cc81002f2b4b49c9d731404688bcae5ade
+  branch=dev
+  convert_revision=7e61b508e709a11d28194a5359bc3532d910af21
+  transplant_source=z\xe8F\xe9\x11\x1f\xc8\xf5wEcBP\xc7\xb9\xac (esc)
+  `h\x9b (esc)
+  $ hg -R ../converted log -r 'origin(tip)'
+  changeset:   2:e0213322b2c1
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     2
+  
+
 Test simple destination
   $ hg log -r 'destination()'
   changeset:   7:ef0ef43d49e7