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

login
register
mail settings
Submitter Matt Harbison
Date June 12, 2014, 3:53 a.m.
Message ID <8c1d30924cc1a5ebbdc8.1402545186@Envy>
Download mbox | patch
Permalink /patch/4980/
State Superseded
Commit 44255f7ce886c0c4efc59ba8aea15e57ddc23f4c
Headers show

Comments

Matt Harbison - June 12, 2014, 3:53 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1402539569 14400
#      Wed Jun 11 22:19:29 2014 -0400
# Node ID 8c1d30924cc1a5ebbdc810565e1b73a4902653a7
# 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.
Pierre-Yves David - June 20, 2014, 3:23 p.m.
On 06/11/2014 09:15 PM, Kevin Bullock wrote:
> On Jun 11, 2014, at 10:53 PM, Matt Harbison <matt_harbison@yahoo.com> wrote:
>
>> # HG changeset patch
>> # User Matt Harbison <matt_harbison@yahoo.com>
>> # Date 1402539569 14400
>> #      Wed Jun 11 22:19:29 2014 -0400
>> # Node ID 8c1d30924cc1a5ebbdc810565e1b73a4902653a7
>> # 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.
>>
>> 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'):
>> +            rev = extra.get(label)
>
> Nit: it's a changeset ID, not a revision number. Call this 'node' or 'id'.
>
> Other than that, looks straightforward.

I applied the nit and pushed the changeset to clowncopter

(queued)

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'):
+            rev = extra.get(label)
+
+            if rev is None:
+                continue
+
+            # Only transplant stores its reference in binary
+            if label == 'transplant_source':
+                rev = hex(rev)
+
+            newrev = revmap.get(rev)
+            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:
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