hgext/convert/hg.py
changeset 20372 45562379ce4e
parent 19891 e271970b9821
child 20373 e8203629371b
equal deleted inserted replaced
20371:6f3fb6a974e0 20372:45562379ce4e
    22 from mercurial.i18n import _
    22 from mercurial.i18n import _
    23 from mercurial.node import bin, hex, nullid
    23 from mercurial.node import bin, hex, nullid
    24 from mercurial import hg, util, context, bookmarks, error, scmutil
    24 from mercurial import hg, util, context, bookmarks, error, scmutil
    25 
    25 
    26 from common import NoRepo, commit, converter_source, converter_sink
    26 from common import NoRepo, commit, converter_source, converter_sink
       
    27 
       
    28 import re
       
    29 sha1re = re.compile(r'\b[0-9a-f]{6,40}\b')
    27 
    30 
    28 class mercurial_sink(converter_sink):
    31 class mercurial_sink(converter_sink):
    29     def __init__(self, ui, path):
    32     def __init__(self, ui, path):
    30         converter_sink.__init__(self, ui, path)
    33         converter_sink.__init__(self, ui, path)
    31         self.branchnames = ui.configbool('convert', 'hg.usebranchnames', True)
    34         self.branchnames = ui.configbool('convert', 'hg.usebranchnames', True)
   155         if len(parents) < 2:
   158         if len(parents) < 2:
   156             parents.append(nullid)
   159             parents.append(nullid)
   157         p2 = parents.pop(0)
   160         p2 = parents.pop(0)
   158 
   161 
   159         text = commit.desc
   162         text = commit.desc
       
   163 
       
   164         sha1s = re.findall(sha1re, text)
       
   165         for sha1 in sha1s:
       
   166             oldrev = source.lookuprev(sha1)
       
   167             newrev = revmap.get(oldrev)
       
   168             if newrev is not None:
       
   169                 text = text.replace(sha1, newrev[:len(sha1)])
       
   170 
   160         extra = commit.extra.copy()
   171         extra = commit.extra.copy()
   161         if self.branchnames and commit.branch:
   172         if self.branchnames and commit.branch:
   162             extra['branch'] = commit.branch
   173             extra['branch'] = commit.branch
   163         if commit.rev:
   174         if commit.rev:
   164             extra['convert_revision'] = commit.rev
   175             extra['convert_revision'] = commit.rev