Patchwork [V2] convert: update the transplant, rebase and graft references in 'extra'

login
register
mail settings
Submitter Matt Harbison
Date June 13, 2014, 12:29 a.m.
Message ID <d5447e54d6bc38212947.1402619378@Envy>
Download mbox | patch
Permalink /patch/4984/
State Accepted
Headers show

Comments

Matt Harbison - June 13, 2014, 12:29 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1402618396 14400
#      Thu Jun 12 20:13:16 2014 -0400
# Node ID d5447e54d6bc382129478234b4d40484591ea8c1
# Parent  0f73ed6293629f69aa2f01d8940e91faeded49ae
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.

Patch

diff --git a/hgext/convert/hg.py b/hgext/convert/hg.py
--- a/hgext/convert/hg.py
+++ b/hgext/convert/hg.py
@@ -165,6 +165,24 @@ 
                 text = text.replace(sha1, newrev[:len(sha1)])
 
         extra = commit.extra.copy()
+
+        for label in ('source', 'transplant_source', 'rebase_source'):
+            id = extra.get(label)
+
+            if id is None:
+                continue
+
+            # Only transplant stores its reference in binary
+            if label == 'transplant_source':
+                id = hex(id)
+
+            newid = revmap.get(id)
+            if newid is not None:
+                if label == 'transplant_source':
+                    newid = bin(newid)
+
+                extra[label] = newid
+
         if self.branchnames and commit.branch:
             extra['branch'] = commit.branch
         if commit.rev:
diff --git a/tests/test-graft.t b/tests/test-graft.t
--- a/tests/test-graft.t
+++ b/tests/test-graft.t
@@ -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