# HG changeset patch # User Dan Villiom Podlaski Christiansen # Date 1279016356 -7200 # Node ID 67513cca972fbbe7080aa0383e7f5013b461268c # Parent a3d20d6e96b000aea6a5257231ce6b0e356759a9 rebuildmeta: handle mapped branch names. diff --git a/hgsubversion/svncommands.py b/hgsubversion/svncommands.py --- a/hgsubversion/svncommands.py +++ b/hgsubversion/svncommands.py @@ -219,15 +219,36 @@ def rebuildmeta(ui, repo, args, **opts): last_rev = revision # deal with branches - if ctx.extra().get('close'): - continue - branch = ctx.branch() - if branch == 'default': + if not commitpath: branch = None + elif not commitpath.startswith('../'): + branch = commitpath + elif ctx.parents()[0].node() != node.nullid: + parent = ctx + while parent.node() != node.nullid: + parentextra = parent.extra() + parentinfo = parentextra.get('convert_revision') + assert parentinfo + parent = parent.parents()[0] + + parentpath = parentinfo[40:].split('@')[0][len(subdir) + 1:] + + if parentpath.startswith('tags/') and parentextra.get('close'): + continue + elif parentpath.startswith('branches/'): branch = parentpath[len('branches/'):] + elif parentpath == 'trunk': + branch = None + else: + branch = '../' + parentpath + break + else: + branch = commitpath if rev in closed: # a direct child of this changeset closes the branch; drop it branchinfo.pop(branch, None) + elif ctx.extra().get('close'): + pass elif branch not in branchinfo: parent = ctx.parents()[0] if (parent.node() in noderevnums diff --git a/tests/test_fetch_mappings.py b/tests/test_fetch_mappings.py --- a/tests/test_fetch_mappings.py +++ b/tests/test_fetch_mappings.py @@ -4,12 +4,14 @@ import os import unittest from mercurial import commands +from mercurial import hg from mercurial import node from mercurial import util as hgutil import test_util from hgsubversion import maps +from hgsubversion import svncommands class MapTests(test_util.TestBase): @property @@ -177,6 +179,35 @@ class MapTests(test_util.TestBase): '''test combining two branches, but retaining heads (stupid)''' self.test_branchmap_combine(True) + def test_branchmap_rebuildmeta(self, stupid=False): + '''test rebuildmeta on a branchmapped clone''' + test_util.load_svndump_fixture(self.repo_path, 'branchmap.svndump') + branchmap = open(self.branchmap, 'w') + branchmap.write("badname = dit\n") + branchmap.write("feature = dah\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) + originfo = self.repo.svnmeta().branches + + # clone & rebuild + ui = self.ui(stupid) + src, dest = hg.clone(ui, self.wc_path, self.wc_path + '_clone', + update=False) + svncommands.rebuildmeta(ui, dest, + args=[test_util.fileurl(self.repo_path)]) + + # just check the keys; assume the contents are unaffected by the branch + # map and thus properly tested by other tests + self.assertEquals(sorted(src.svnmeta().branches), + sorted(dest.svnmeta().branches)) + + def test_branchmap_rebuildmeta_stupid(self): + '''test rebuildmeta on a branchmapped clone (stupid)''' + self.test_branchmap_rebuildmeta(True) + def test_branchmap_no_replacement(self): ''' test that empty mappings are rejected