changeset 375:af9fc01299b4

Make branch closing more Mercurial-like. We now use the 'close' value from extra instead of the old closed-branches branch.
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Fri, 29 May 2009 15:24:12 +0200
parents 758d9dbae9f9
children 9327e9325645
files hgsubversion/hg_delta_editor.py hgsubversion/stupid.py hgsubversion/svncommands.py tests/test_fetch_branches.py tests/test_tags.py
diffstat 5 files changed, 29 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/hg_delta_editor.py
+++ b/hgsubversion/hg_delta_editor.py
@@ -742,27 +742,24 @@ class HgChangeReceiver(delta.Editor):
 
         # 3. close any branches that need it
         for branch in tbdelta['branches'][1]:
-            closed = revlog.nullid
-            if 'closed-branches' in self.repo.branchtags():
-                closed = self.repo['closed-branches'].node()
             # self.get_parent_revision(rev.revnum, branch)
             ha = closebranches.get(branch)
             if ha is None:
                 continue
-            self.delbranch(branch, (ha, closed), rev)
+            self.delbranch(branch, ha, rev)
 
         self._save_metadata()
         self.clear_current_info()
 
-    def delbranch(self, branch, parents, rev):
+    def delbranch(self, branch, node, rev):
         def del_all_files(*args):
             raise IOError
-        files = self.repo[parents[0]].manifest().keys()
-        extra = {}
+        files = self.repo[node].manifest().keys()
+        extra = {'close': 1}
         if self.usebranchnames:
-            extra['branch'] = 'closed-branches'
+            extra['branch'] = branch or 'default'
         ctx = context.memctx(self.repo,
-                             parents,
+                             (node, revlog.nullid),
                              rev.message or util.default_commit_msg,
                              files,
                              del_all_files,
--- a/hgsubversion/stupid.py
+++ b/hgsubversion/stupid.py
@@ -436,7 +436,8 @@ def checkbranch(hg_editor, r, branch):
         return None
     branchtip = branchedits[0][1]
     for child in hg_editor.repo[branchtip].children():
-        if child.branch() == 'closed-branches':
+        b = child.branch() != 'default' and child.branch() or None
+        if b == branch and child.extra().get('close'):
             return None
     return branchtip
 
@@ -551,10 +552,7 @@ def convert_rev(ui, hg_editor, svn, r, t
     for b, parent in deleted_branches.iteritems():
         if parent == node.nullid:
             continue
-        closed = node.nullid
-        if 'closed-branches' in hg_editor.repo.branchtags():
-            closed = hg_editor.repo['closed-branches'].node()
-        hg_editor.delbranch(b, (parent, closed), r)
+        hg_editor.delbranch(b, parent, r)
 
     # save the changed metadata
     hg_editor._save_metadata()
--- a/hgsubversion/svncommands.py
+++ b/hgsubversion/svncommands.py
@@ -111,11 +111,14 @@ def rebuildmeta(ui, repo, hg_repo_path, 
             assert False, 'Unhandled case in rebuildmeta'
         revmap.write('%s %s %s\n' % (revision, ctx.hex(), commitpath))
 
-        # deal with branches
         revision = int(revision)
         noderevnums[ctx.node()] = revision
         if revision > last_rev:
             last_rev = revision
+
+        # deal with branches
+        if ctx.extra().get('close'): # don't re-add, we just deleted!
+            continue
         branch = ctx.branch()
         if branch == 'default':
             branch = None
@@ -132,10 +135,10 @@ def rebuildmeta(ui, repo, hg_repo_path, 
                                   noderevnums.get(parent.node(), 0),
                                   revision)
 
-        # deal with branch closing
-        for c in ctx.children():
-            if c.branch() == 'closed-branches':
+        for cctx in ctx.children():
+            if cctx.extra().get('close'):
                 branchinfo.pop(branch, None)
+                break
 
     # save off branch info
     branchinfofile = open(os.path.join(svnmetadir, 'branch_info'), 'w')
--- a/tests/test_fetch_branches.py
+++ b/tests/test_fetch_branches.py
@@ -64,10 +64,8 @@ class TestFetchBranches(test_util.TestBa
         repo = self._load_fixture_and_fetch('replace_trunk_with_branch.svndump',
                                             stupid)
         self.assertEqual(repo['default'].parents()[0].branch(), 'test')
-        self.assertEqual(node.hex(repo['closed-branches'].parents()[0].node()),
-                         '2cd09772e0f6ddf2d13c60ef3c1be11ad5a7dfae')
-        self.assertEqual(node.hex(repo['default'].node()),
-                         '8a525ca0671f456e6b1417187bf86c6115d2cb78')
+        self.assertEqual(repo['tip'].branch(), 'default')
+        self.assertEqual(repo['tip'].extra().get('close'), '1')
         self.assertEqual(self.openbranches(repo), ['default'])
 
     def test_replace_trunk_with_branch_stupid(self):
--- a/tests/test_tags.py
+++ b/tests/test_tags.py
@@ -71,14 +71,17 @@ class TestTags(test_util.TestBase):
         repo = self._load_fixture_and_fetch('tag_by_rename_branch.svndump',
                                             stupid=stupid)
         repo = self.repo
-        self.assertEqual(repo['tip'], repo['closed-branches'])
-        self.assertEqual(node.hex(repo['tip'].node()),
-                         '2f0a3abe2004c0fa01f5f6074a8b5441e9c80c2a')
-        taggedrev = repo['tip'].parents()[0]
-        self.assertEqual(node.hex(taggedrev.node()),
-                         '50c67c73267987de705ee335183c5486641e56e9')
-        self.assertEqual(node.hex(repo['tag/dummy'].node()),
-                         '50c67c73267987de705ee335183c5486641e56e9')
+        branches = set()
+        for h in repo.heads():
+            ctx = repo[h]
+            if 'close' not in ctx.extra():
+                branches.add(ctx.branch())
+
+        self.assert_('dummy' not in branches)
+        self.assertEqual(repo['tag/dummy'], repo['tip'].parents()[0])
+        extra = repo['tip'].extra().copy()
+        extra.pop('convert_revision', None)
+        self.assertEqual(extra, {'branch': 'dummy', 'close': '1'})
 
     def test_tag_by_renaming_branch_stupid(self):
         self.test_tag_by_renaming_branch(stupid=True)