changeset 367:ce64d57172a3

Generate separate data structure containing revision's tags/branches changes.
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Fri, 29 May 2009 17:33:52 +0200
parents 25ebdc16b05b
children e786253eb565
files hgsubversion/cmdutil.py hgsubversion/hg_delta_editor.py hgsubversion/stupid.py hgsubversion/wrappers.py
diffstat 4 files changed, 24 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/cmdutil.py
+++ b/hgsubversion/cmdutil.py
@@ -54,9 +54,10 @@ def parentrev(ui, repo, hge, svn_commit_
     return workingctx
 
 
-def replay_convert_rev(ui, hg_editor, svn, r):
+def replay_convert_rev(ui, hg_editor, svn, r, tbdelta):
     # ui is only passed in for similarity with stupid.convert_rev()
     hg_editor.set_current_rev(r)
+    hg_editor.save_tbdelta(tbdelta) # needed by get_replay()
     svn.get_replay(r.revnum, hg_editor)
     i = 1
     if hg_editor.missing_plaintexts:
@@ -85,7 +86,7 @@ def replay_convert_rev(ui, hg_editor, sv
             hg_editor.set_file(p, data, 'x' in mode, 'l' in mode)
         hg_editor.missing_plaintexts = set()
         hg_editor.ui.note('\n')
-    hg_editor.commit_current_delta()
+    hg_editor.commit_current_delta(tbdelta)
 
 
 def _isdir(svn, branchpath, svndir):
--- a/hgsubversion/hg_delta_editor.py
+++ b/hgsubversion/hg_delta_editor.py
@@ -566,16 +566,21 @@ class HgChangeReceiver(delta.Editor):
                     and branch not in added_branches):
                     parent = {branch: (None, 0, revision.revnum)}
             added_branches.update(parent)
-        for t in tags_to_delete:
+        return {
+            'tags': (added_tags, tags_to_delete),
+            'branches': (added_branches, self.branches_to_delete),
+        }
+
+    def save_tbdelta(self, tbdelta):
+        for t in tbdelta['tags'][1]:
             del self.tags[t]
-        for br in self.branches_to_delete:
+        for br in tbdelta['branches'][1]:
             del self.branches[br]
-        for t, info in added_tags.items():
+        for t, info in tbdelta['tags'][0].items():
             self.ui.status('Tagged %s@%s as %s\n' %
                            (info[0] or 'trunk', info[1], t))
-        self.tags.update(added_tags)
-        self.branches.update(added_branches)
-        self._save_metadata()
+        self.tags.update(tbdelta['tags'][0])
+        self.branches.update(tbdelta['branches'][0])
 
     def _updateexternals(self):
         if not self.externals:
@@ -607,7 +612,7 @@ class HgChangeReceiver(delta.Editor):
             else:
                 self.delete_file(path)
 
-    def commit_current_delta(self):
+    def commit_current_delta(self, tbdelta):
         if hasattr(self, '_exception_info'):  #pragma: no cover
             traceback.print_exception(*self._exception_info)
             raise ReplayException()
@@ -636,7 +641,7 @@ class HgChangeReceiver(delta.Editor):
             branch_batches[b].append((p, f))
         # close any branches that need it
         closed_revs = set()
-        for branch in self.branches_to_delete:
+        for branch in tbdelta['branches'][1]:
             closed = revlog.nullid
             if 'closed-branches' in self.repo.branchtags():
                 closed = self.repo['closed-branches'].node()
--- a/hgsubversion/stupid.py
+++ b/hgsubversion/stupid.py
@@ -430,8 +430,10 @@ def fetch_branchrev(svn, hg_editor, bran
 
     return files, filectxfn
 
-def convert_rev(ui, hg_editor, svn, r):
+def convert_rev(ui, hg_editor, svn, r, tbdelta):
     # this server fails at replay
+
+    hg_editor.save_tbdelta(tbdelta)
     branches = hg_editor.branches_in_paths(r.paths, r.revnum, svn.checkpath, svn.list_files)
     deleted_branches = {}
     brpaths = branches.values()
@@ -533,7 +535,6 @@ def convert_rev(ui, hg_editor, svn, r):
             if not branch in hg_editor.branches:
                 hg_editor.branches[branch] = None, 0, r.revnum
             hg_editor.add_to_revmap(r.revnum, b, ha)
-            hg_editor._save_metadata()
             util.describe_commit(ui, ha, b)
     # These are branches which would have an 'R' status in svn log. This means they were
     # replaced by some other branch, so we need to verify they get marked as closed.
@@ -573,4 +574,6 @@ def convert_rev(ui, hg_editor, svn, r):
                                      extra)
         ha = hg_editor.repo.commitctx(current_ctx)
         ui.status('Marked branch %s as closed.\n' % (b or 'default'))
-        hg_editor._save_metadata()
+
+    # save the changed metadata
+    hg_editor._save_metadata()
--- a/hgsubversion/wrappers.py
+++ b/hgsubversion/wrappers.py
@@ -228,14 +228,14 @@ def pull(repo, source, heads=[], force=F
             if (r.author is None and
                 r.message == 'This is an empty revision for padding.'):
                 continue
-            hg_editor.update_branch_tag_map_for_rev(r)
+            tbdelta = hg_editor.update_branch_tag_map_for_rev(r)
             # got a 502? Try more than once!
             tries = 0
             converted = False
             while not converted:
                 try:
                     util.describe_revision(ui, r)
-                    pullfuns[have_replay](ui, hg_editor, svn, r)
+                    pullfuns[have_replay](ui, hg_editor, svn, r, tbdelta)
                     converted = True
                 except svnwrap.SubversionRepoCanNotReplay, e: #pragma: no cover
                     ui.status('%s\n' % e.message)