convert: replace old sha1s in the description
This is a simple find-and-replace strategy for matching anything in the
old description of a converted commit and, if that matched sha1 exists
in the mapping, replacing it with the new sha1.
In particular, this is helpful for descriptions that contain tags with
messages such as, "Added tag 1.0 for commit abcde1234567" which will now
be automatically converted.
Tests have been updated accordingly.
--- a/hgext/convert/hg.py Wed Feb 05 20:22:28 2014 -0800
+++ b/hgext/convert/hg.py Thu Apr 18 10:05:50 2013 -0500
@@ -25,6 +25,9 @@
from common import NoRepo, commit, converter_source, converter_sink
+import re
+sha1re = re.compile(r'\b[0-9a-f]{6,40}\b')
+
class mercurial_sink(converter_sink):
def __init__(self, ui, path):
converter_sink.__init__(self, ui, path)
@@ -157,6 +160,14 @@
p2 = parents.pop(0)
text = commit.desc
+
+ sha1s = re.findall(sha1re, text)
+ for sha1 in sha1s:
+ oldrev = source.lookuprev(sha1)
+ newrev = revmap.get(oldrev)
+ if newrev is not None:
+ text = text.replace(sha1, newrev[:len(sha1)])
+
extra = commit.extra.copy()
if self.branchnames and commit.branch:
extra['branch'] = commit.branch
--- a/tests/test-convert-hg-sink.t Wed Feb 05 20:22:28 2014 -0800
+++ b/tests/test-convert-hg-sink.t Thu Apr 18 10:05:50 2013 -0500
@@ -119,7 +119,7 @@
0 add baz
$ cd new-filemap
$ hg tags
- tip 2:6f4fd1df87fb
+ tip 2:3c74706b1ff8
some-tag 0:ba8636729451
$ cd ..