changeset 8693:68e0a55eee6e

convert: rewrite tags when converting from hg to hg
author Patrick Mezard <pmezard@gmail.com>
date Mon, 01 Jun 2009 17:12:42 +0200
parents 827d4e807d57
children ca8d05e1f1d1
files hgext/convert/common.py hgext/convert/convcmd.py hgext/convert/filemap.py hgext/convert/hg.py hgext/convert/subversion.py tests/test-convert-hg-sink tests/test-convert-hg-sink.out
diffstat 7 files changed, 64 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/common.py	Mon Jun 01 17:12:41 2009 +0200
+++ b/hgext/convert/common.py	Mon Jun 01 17:12:42 2009 +0200
@@ -144,6 +144,12 @@
         """
         return False
 
+    def lookuprev(self, rev):
+        """If rev is a meaningful revision reference in source, return
+        the referenced identifier in the same format used by getcommit().
+        return None otherwise.
+        """
+        return None
 
 class converter_sink(object):
     """Conversion sink (target) interface"""
@@ -174,13 +180,15 @@
         mapping equivalent authors identifiers for each system."""
         return None
 
-    def putcommit(self, files, copies, parents, commit, source):
+    def putcommit(self, files, copies, parents, commit, source, revmap):
         """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, and 'source' is the source repository.
-        Only getfile() and getmode() should be called on 'source'.
+        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,
+        'source' is the source repository, and 'revmap' is a mapfile
+        of source revisions to converted revisions. Only getfile(),
+        getmode(), and lookuprev() should be called on 'source'.
 
         Note that the sink repository is not told to update itself to
         a particular revision (or even what that revision would be)
--- a/hgext/convert/convcmd.py	Mon Jun 01 17:12:41 2009 +0200
+++ b/hgext/convert/convcmd.py	Mon Jun 01 17:12:42 2009 +0200
@@ -297,7 +297,8 @@
             parents = [self.map.get(p, p) for p in parents]
         except KeyError:
             parents = [b[0] for b in pbranches]
-        newnode = self.dest.putcommit(files, copies, parents, commit, self.source)
+        newnode = self.dest.putcommit(files, copies, parents, commit, 
+                                      self.source, self.map)
         self.source.converted(rev, newnode)
         self.map[rev] = newnode
 
--- a/hgext/convert/filemap.py	Mon Jun 01 17:12:41 2009 +0200
+++ b/hgext/convert/filemap.py	Mon Jun 01 17:12:42 2009 +0200
@@ -354,3 +354,6 @@
 
     def hasnativeorder(self):
         return self.base.hasnativeorder()
+
+    def lookuprev(self, rev):
+        return self.base.lookuprev(rev)
--- a/hgext/convert/hg.py	Mon Jun 01 17:12:41 2009 +0200
+++ b/hgext/convert/hg.py	Mon Jun 01 17:12:42 2009 +0200
@@ -18,7 +18,7 @@
 #   source.
 
 
-import os, time
+import os, time, cStringIO
 from mercurial.i18n import _
 from mercurial.node import bin, hex, nullid
 from mercurial import hg, util, context, error
@@ -112,13 +112,27 @@
                 self.repo.pull(prepo, [prepo.lookup(h) for h in heads])
             self.before()
 
-    def putcommit(self, files, copies, parents, commit, source):
+    def _rewritetags(self, source, revmap, 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]))
+        return fp.getvalue()
+
+    def putcommit(self, files, copies, parents, commit, source, revmap):
 
         files = dict(files)
         def getfilectx(repo, memctx, f):
             v = files[f]
             data = source.getfile(f, v)
             e = source.getmode(f, v)
+            if f == '.hgtags':
+                data = self._rewritetags(source, revmap, data)
             return context.memfilectx(f, data, 'l' in e, 'x' in e, copies.get(f))
 
         pl = []
@@ -341,3 +355,9 @@
 
     def hasnativeorder(self):
         return True
+
+    def lookuprev(self, rev):
+        try:
+            return hex(self.repo.lookup(rev))
+        except error.RepoError:
+            return None
--- a/hgext/convert/subversion.py	Mon Jun 01 17:12:41 2009 +0200
+++ b/hgext/convert/subversion.py	Mon Jun 01 17:12:42 2009 +0200
@@ -1170,7 +1170,7 @@
     def revid(self, rev):
         return u"svn:%s@%s" % (self.uuid, rev)
 
-    def putcommit(self, files, copies, parents, commit, source):
+    def putcommit(self, files, copies, parents, commit, source, revmap):
         # Apply changes to working copy
         for f, v in files:
             try:
--- a/tests/test-convert-hg-sink	Mon Jun 01 17:12:41 2009 +0200
+++ b/tests/test-convert-hg-sink	Mon Jun 01 17:12:42 2009 +0200
@@ -55,3 +55,13 @@
 echo '% no copies'
 hg up -C
 hg debugrename baz
+cd ..
+
+echo '% test tag rewriting'
+cat > filemap <<EOF
+exclude foo
+EOF
+hg convert --filemap filemap orig new-filemap 2>&1 | grep -v 'subversion python bindings could not be loaded'
+cd new-filemap
+hg tags
+cd ..
--- a/tests/test-convert-hg-sink.out	Mon Jun 01 17:12:41 2009 +0200
+++ b/tests/test-convert-hg-sink.out	Mon Jun 01 17:12:42 2009 +0200
@@ -48,3 +48,15 @@
 % no copies
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 baz not renamed
+% test tag rewriting
+initializing destination new-filemap repository
+scanning source...
+sorting...
+converting...
+4 add foo and bar
+3 remove foo
+2 add foo/file
+1 Added tag some-tag for changeset ad681a868e44
+0 add baz
+tip                                2:6f4fd1df87fb
+some-tag                           0:ba8636729451