[PATCH] convert: replace old sha1s in the description

Angel Ezquerra angel.ezquerra at gmail.com
Wed Mar 27 18:35:24 CDT 2013


On Wed, Mar 27, 2013 at 11:42 PM, Sean Farley
<sean.michael.farley at gmail.com> wrote:
> # HG changeset patch
> # User Sean Farley <sean.michael.farley at gmail.com>
> # Date 1363449738 18000
> #      Sat Mar 16 11:02:18 2013 -0500
> # Node ID d7639b2cb14271ab88ed71ecb3ce0a7595d41d25
> # Parent  3839baf52f2f24c289487111a95e9e835d1e1c4d
> 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.
>
> diff --git a/hgext/convert/hg.py b/hgext/convert/hg.py
> --- a/hgext/convert/hg.py
> +++ b/hgext/convert/hg.py
> @@ -23,10 +23,13 @@
>  from mercurial.node import bin, hex, nullid
>  from mercurial import hg, util, context, bookmarks, error
>
>  from common import NoRepo, commit, converter_source, converter_sink
>
> +import re
> +sha1re = re.compile(r'\b[0-9a-f]{12,40}\b')
> +
>  class mercurial_sink(converter_sink):
>      def __init__(self, ui, path):
>          converter_sink.__init__(self, ui, path)
>          self.branchnames = ui.configbool('convert', 'hg.usebranchnames', True)
>          self.clonebranches = ui.configbool('convert', 'hg.clonebranches', False)
> @@ -155,10 +158,18 @@
>          if len(parents) < 2:
>              parents.append(nullid)
>          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
>          if commit.rev:
>              extra['convert_revision'] = commit.rev
> diff --git a/tests/test-convert-hg-sink.t b/tests/test-convert-hg-sink.t
> --- a/tests/test-convert-hg-sink.t
> +++ b/tests/test-convert-hg-sink.t
> @@ -117,8 +117,8 @@
>    2 add foo/file
>    1 Added tag some-tag for changeset ad681a868e44
>    0 add baz
>    $ cd new-filemap
>    $ hg tags
> -  tip                                2:6f4fd1df87fb
> +  tip                                2:3c74706b1ff8
>    some-tag                           0:ba8636729451
>    $ cd ..

+1 to this. This would have come very, very handy this week, where
I've had to manually redo a few converted repos because the "tag
commits" had the wrong message.

What about actually "retagging" the repo during conversion? That is,
if a commit that only modifies the .hgtags file is found, try to
replicate it by running "hg tag" on the target repo...

Note that I know next to nothing about the internals of hgext/convert
so this may not be possible...

Cheers,

Angel


More information about the Mercurial-devel mailing list