changeset 374:758d9dbae9f9

Extract branch closing from stupid/editor into separate function.
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Fri, 29 May 2009 15:29:40 +0200
parents 8c91e6a69d05
children af9fc01299b4
files hgsubversion/hg_delta_editor.py hgsubversion/stupid.py
diffstat 2 files changed, 20 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/hg_delta_editor.py
+++ b/hgsubversion/hg_delta_editor.py
@@ -749,29 +749,29 @@ class HgChangeReceiver(delta.Editor):
             ha = closebranches.get(branch)
             if ha is None:
                 continue
-            parentctx = self.repo.changectx(ha)
-            parents = (ha, closed)
-            def del_all_files(*args):
-                raise IOError
-            files = parentctx.manifest().keys()
-            extra = {}
-            if self.usebranchnames:
-                extra['branch'] = 'closed-branches'
-            current_ctx = context.memctx(self.repo,
-                                         parents,
-                                         rev.message or ' ',
-                                         files,
-                                         del_all_files,
-                                         self.authors[rev.author],
-                                         date,
-                                         extra)
-            new_hash = self.repo.commitctx(current_ctx)
-            self.ui.status('Marked branch %s as closed.\n' % (branch or
-                                                              'default'))
+            self.delbranch(branch, (ha, closed), rev)
 
         self._save_metadata()
         self.clear_current_info()
 
+    def delbranch(self, branch, parents, rev):
+        def del_all_files(*args):
+            raise IOError
+        files = self.repo[parents[0]].manifest().keys()
+        extra = {}
+        if self.usebranchnames:
+            extra['branch'] = 'closed-branches'
+        ctx = context.memctx(self.repo,
+                             parents,
+                             rev.message or util.default_commit_msg,
+                             files,
+                             del_all_files,
+                             self.authors[rev.author],
+                             self.fixdate(rev.date),
+                             extra)
+        new = self.repo.commitctx(ctx)
+        self.ui.status('Marked branch %s as closed.\n' % (branch or 'default'))
+
     def readfilemap(self, filemapfile):
         self.ui.note(
             ('Reading file map from %s\n')
--- a/hgsubversion/stupid.py
+++ b/hgsubversion/stupid.py
@@ -551,27 +551,10 @@ def convert_rev(ui, hg_editor, svn, r, t
     for b, parent in deleted_branches.iteritems():
         if parent == node.nullid:
             continue
-        parentctx = hg_editor.repo[parent]
-        files_touched = parentctx.manifest().keys()
-        def filectxfn(repo, memctx, path):
-            raise IOError()
         closed = node.nullid
         if 'closed-branches' in hg_editor.repo.branchtags():
             closed = hg_editor.repo['closed-branches'].node()
-        parents = (parent, closed)
-        extra = {}
-        if hg_editor.usebranchnames:
-                extra['branch'] = 'closed-branches'
-        current_ctx = context.memctx(hg_editor.repo,
-                                     parents,
-                                     r.message or util.default_commit_msg,
-                                     files_touched,
-                                     filectxfn,
-                                     hg_editor.authors[r.author],
-                                     date,
-                                     extra)
-        ha = hg_editor.repo.commitctx(current_ctx)
-        ui.status('Marked branch %s as closed.\n' % (b or 'default'))
+        hg_editor.delbranch(b, (parent, closed), r)
 
     # save the changed metadata
     hg_editor._save_metadata()