changeset 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 37b2adc64fb3
children e2c3349b2cca
files hgsubversion/replay.py hgsubversion/stupid.py hgsubversion/svnmeta.py tests/test_fetch_mappings.py
diffstat 4 files changed, 29 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/replay.py
+++ b/hgsubversion/replay.py
@@ -178,7 +178,7 @@ def convert_rev(ui, meta, svn, r, tbdelt
         if (rev.revnum, branch) not in meta.revmap and not tag:
             meta.revmap[rev.revnum, branch] = new_hash
         if tag:
-            meta.movetag(tag, new_hash, parentctx.extra().get('branch', None), rev, date)
+            meta.movetag(tag, new_hash, rev, date)
             meta.addedtags.pop(tag, None)
 
     # 2. handle branches that need to be committed without any files
--- a/hgsubversion/stupid.py
+++ b/hgsubversion/stupid.py
@@ -658,7 +658,7 @@ def convert_rev(ui, meta, svn, r, tbdelt
                 meta.branches[branch] = None, 0, r.revnum
             meta.revmap[r.revnum, b] = ha
         else:
-            meta.movetag(tag, ha, parentctx.extra().get('branch', None), r, date)
+            meta.movetag(tag, ha, r, date)
             meta.addedtags.pop(tag, None)
         util.describe_commit(ui, ha, b)
 
--- 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()
--- a/tests/test_fetch_mappings.py
+++ b/tests/test_fetch_mappings.py
@@ -118,6 +118,21 @@ class MapTests(test_util.TestBase):
     def test_branchmap_stupid(self):
         self.test_branchmap(True)
 
+    def test_branchmap_tagging(self, stupid=False):
+        '''test tagging a renamed branch, which used to raise an exception'''
+        test_util.load_svndump_fixture(self.repo_path, 'commit-to-tag.svndump')
+        branchmap = open(self.branchmap, 'w')
+        branchmap.write("magic = art\n")
+        branchmap.close()
+        ui = self.ui(stupid)
+        ui.setconfig('hgsubversion', 'branchmap', self.branchmap)
+        commands.clone(ui, test_util.fileurl(self.repo_path),
+                       self.wc_path, branchmap=self.branchmap)
+        branches = set(self.repo[i].branch() for i in self.repo)
+        self.assertEquals(sorted(branches), ['art', 'closeme'])
+
+    def test_branchmap_tagging_stupid(self):
+        self.test_branchmap_tagging(True)
 
 def suite():
     return unittest.TestLoader().loadTestsFromTestCase(MapTests)