[PATCH 7 of 8] convert: add tagmap logic
Sean Farley
sean.michael.farley at gmail.com
Mon Feb 3 18:09:38 CST 2014
# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1390426817 21600
# Wed Jan 22 15:40:17 2014 -0600
# Node ID 110bfd6fac2ebf95cef12882b095bfce589f6851
# Parent dbfab8233ee5d78d8a1c07c59be7aed0270625bf
convert: add tagmap logic
Previously, there was no way to rewrite tags on the fly while converting. Now,
we add similar logic to branchmap to provide a way to map old tags to new tags.
Currently, this is not enabled since there is not yet a command-line option.
diff --git a/hgext/convert/common.py b/hgext/convert/common.py
--- a/hgext/convert/common.py
+++ b/hgext/convert/common.py
@@ -206,11 +206,12 @@ class converter_sink(object):
"""Path to a file that will contain lines
srcauthor=dstauthor
mapping equivalent authors identifiers for each system."""
return None
- def putcommit(self, files, copies, parents, commit, source, revmap):
+ def putcommit(self, files, copies, parents, commit, source,
+ revmap, tagmap):
"""Create a revision with all changed files listed in 'files'
and having listed parents. 'commit' is a commit object
containing at a minimum the author, date, and message for this
changeset. 'files' is a list of (path, version) tuples,
'copies' is a dictionary mapping destinations to sources,
diff --git a/hgext/convert/convcmd.py b/hgext/convert/convcmd.py
--- a/hgext/convert/convcmd.py
+++ b/hgext/convert/convcmd.py
@@ -119,10 +119,11 @@ class converter(object):
self.authorfile = self.dest.authorfile()
self.splicemap = self.parsesplicemap(opts.get('splicemap'))
self.branchmap = mapfile(ui, opts.get('branchmap'))
self.closemap = self.parseclosemap(opts.get('closemap'))
+ self.tagmap = mapfile(ui, opts.get('tagmap'))
def parseclosemap(self, path):
""" check and validate the closemap format and
return a list of revs to close.
Format checking has two parts.
@@ -446,11 +447,11 @@ class converter(object):
source = progresssource(self.ui, self.source, len(files))
if self.closemap and rev in self.closemap:
commit.extra['close'] = 1
newnode = self.dest.putcommit(files, copies, parents, commit,
- source, self.map)
+ source, self.map, self.tagmap)
source.close()
self.source.converted(rev, newnode)
self.map[rev] = newnode
def convert(self, sortmode):
@@ -482,10 +483,13 @@ class converter(object):
total=len(t))
self.copy(c)
self.ui.progress(_('converting'), None)
tags = self.source.gettags()
+ tags = dict((self.tagmap.get(k, k), v)
+ for k, v in tags.iteritems())
+
ctags = {}
for k in tags:
v = tags[k]
if self.map.get(v, SKIPREV) != SKIPREV:
ctags[k] = self.map[v]
diff --git a/hgext/convert/hg.py b/hgext/convert/hg.py
--- a/hgext/convert/hg.py
+++ b/hgext/convert/hg.py
@@ -118,30 +118,31 @@ class mercurial_sink(converter_sink):
prepo = hg.peer(self.ui, {}, pbranchpath)
self.ui.note(_('pulling from %s into %s\n') % (pbranch, branch))
self.repo.pull(prepo, [prepo.lookup(h) for h in heads])
self.before()
- def _rewritetags(self, source, revmap, data):
+ def _rewritetags(self, source, revmap, tagmap, data):
fp = cStringIO.StringIO()
for line in data.splitlines():
s = line.split(' ', 1)
if len(s) != 2:
continue
revid = revmap.get(source.lookuprev(s[0]))
if not revid:
continue
- fp.write('%s %s\n' % (revid, s[1]))
+ fp.write('%s %s\n' % (revid, tagmap.get(s[1], s[1])))
return fp.getvalue()
- def putcommit(self, files, copies, parents, commit, source, revmap):
+ def putcommit(self, files, copies, parents, commit, source,
+ revmap, tagmap):
files = dict(files)
def getfilectx(repo, memctx, f):
v = files[f]
data, mode = source.getfile(f, v)
if f == '.hgtags':
- data = self._rewritetags(source, revmap, data)
+ data = self._rewritetags(source, revmap, tagmap, data)
return context.memfilectx(f, data, 'l' in mode, 'x' in mode,
copies.get(f))
pl = []
for p in parents:
diff --git a/hgext/convert/subversion.py b/hgext/convert/subversion.py
--- a/hgext/convert/subversion.py
+++ b/hgext/convert/subversion.py
@@ -1181,11 +1181,12 @@ class svn_sink(converter_sink, commandli
self.childmap[parent] = child
def revid(self, rev):
return u"svn:%s@%s" % (self.uuid, rev)
- def putcommit(self, files, copies, parents, commit, source, revmap):
+ def putcommit(self, files, copies, parents, commit, source,
+ revmap, tagmap):
for parent in parents:
try:
return self.revid(self.childmap[parent])
except KeyError:
pass
More information about the Mercurial-devel
mailing list