diff hgsubversion/svnmeta.py @ 634:a400f3bf5611

replay/stupid: fix tagging on a branch renamed using a branch map Previously, both convert_rev() functions used parentctx.extra() to determine the branch to pass to meta.movetag(). This assumed that the branch name stored in the changeset matches the internal branch. The introduction of branch maps made this assumption unsafe, however: Now, the Mercurial branch can be completely unrelated to the origin of the changeset. It turns out, however, that movetag() already has sufficient knowledge to determine the branch. Given the hash of the new changeset to be tagged, we walk its ancestors until we find an open changeset, which we then know to be the originating branch. This assumes that there were `few' commits made to the tag; an assumption I would consider reasonable.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Sun, 11 Jul 2010 11:46:19 +0200
parents eea224fa1156
children d0692ce98ea6
line wrap: on
line diff
--- a/hgsubversion/svnmeta.py
+++ b/hgsubversion/svnmeta.py
@@ -229,14 +229,15 @@ class SVNMeta(object):
     def mapbranch(self, extra, close=False):
         if close:
             extra['close'] = 1
-        if extra.get('branch') == 'default':
-            extra.pop('branch', None)
-        mapped = self.branchmap.get(extra.get('branch'))
+        mapped = self.branchmap.get(extra.get('branch', 'default'))
         if not self.usebranchnames or mapped == 'default':
             extra.pop('branch', None)
         elif mapped:
             extra['branch'] = mapped
 
+        if extra.get('branch') == 'default':
+            extra.pop('branch', None)
+
     def normalize(self, path):
         '''Normalize a path to strip of leading slashes and our subdir if we
         have one.
@@ -555,11 +556,16 @@ class SVNMeta(object):
             del self.branches[br]
         self.branches.update(tbdelta['branches'][0])
 
-    def movetag(self, tag, hash, branch, rev, date):
+    def movetag(self, tag, hash, rev, date):
         if tag in self.tags and self.tags[tag] == hash:
             return
-        if branch == 'default':
-            branch = None
+
+        # determine branch from earliest unclosed ancestor
+        branchparent = self.repo[hash]
+        while branchparent.extra().get('close'):
+            branchparent = branchparent.parents()[0]
+        branch = self.get_source_rev(ctx=branchparent)[1]
+
         parentctx = self.repo[self.get_parent_revision(rev.revnum+1, branch)]
         if '.hgtags' in parentctx:
             tagdata = parentctx.filectx('.hgtags').data()