changeset 20378:9616b03113ce

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.
author Sean Farley <sean.michael.farley@gmail.com>
date Wed, 22 Jan 2014 15:40:17 -0600
parents 5842d63cfe56
children b75a04502ced
files hgext/convert/common.py hgext/convert/convcmd.py hgext/convert/hg.py hgext/convert/subversion.py
diffstat 4 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/common.py	Wed Jan 22 15:31:24 2014 -0600
+++ b/hgext/convert/common.py	Wed Jan 22 15:40:17 2014 -0600
@@ -208,7 +208,8 @@
         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
--- a/hgext/convert/convcmd.py	Wed Jan 22 15:31:24 2014 -0600
+++ b/hgext/convert/convcmd.py	Wed Jan 22 15:40:17 2014 -0600
@@ -121,6 +121,7 @@
         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
@@ -448,7 +449,7 @@
             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
@@ -484,6 +485,9 @@
             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]
--- a/hgext/convert/hg.py	Wed Jan 22 15:31:24 2014 -0600
+++ b/hgext/convert/hg.py	Wed Jan 22 15:40:17 2014 -0600
@@ -120,7 +120,7 @@
                 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)
@@ -129,17 +129,18 @@
             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))
 
--- a/hgext/convert/subversion.py	Wed Jan 22 15:31:24 2014 -0600
+++ b/hgext/convert/subversion.py	Wed Jan 22 15:40:17 2014 -0600
@@ -1183,7 +1183,8 @@
     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])