[PATCH 1 of 2] histedit: refactoring of cleanup

Laurent Charignon lcharignon at fb.com
Mon Aug 3 20:07:52 UTC 2015


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1438026153 25200
#      Mon Jul 27 12:42:33 2015 -0700
# Branch stable
# Node ID 1ce021437a02319df153e5e535c0ce9885160e89
# Parent  a74e9806d17d777595f02bef912da25b876cb56f
histedit: refactoring of cleanup

This patch refactors the cleanup at the end of an histedit. It is here to
improve the legibility of the next patch.

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -638,6 +638,30 @@ def findoutgoing(ui, repo, remote=None, 
         raise util.Abort(msg, hint=hint)
     return repo.lookup(roots[0])
 
+def cleanup(ui, repo, state, mapping, ntm, supportsmarkers, tmpnodes):
+    if not state.keep:
+        if mapping:
+            movebookmarks(ui, repo, mapping, state.topmost, ntm)
+            # TODO update mq state
+        if supportsmarkers:
+            markers = []
+            # sort by revision number because it sound "right"
+            for prec in sorted(mapping, key=repo.changelog.rev):
+                succs = mapping[prec]
+                markers.append((repo[prec],
+                                tuple(repo[s] for s in succs)))
+            if markers:
+                obsolete.createmarkers(repo, markers)
+        else:
+            cleanupnode(ui, repo, 'replaced', mapping)
+    if supportsmarkers:
+        obsolete.createmarkers(repo, ((repo[t],()) for t in sorted(tmpnodes)))
+    else:
+        cleanupnode(ui, repo, 'temp', tmpnodes)
+    state.clear()
+    if os.path.exists(repo.sjoin('undo')):
+        os.unlink(repo.sjoin('undo'))
+
 actiontable = {'p': pick,
                'pick': pick,
                'e': edit,
@@ -884,28 +908,7 @@ def _histedit(ui, repo, state, *freeargs
                     for n in succs[1:]:
                         ui.debug(m % node.short(n))
 
-    if not state.keep:
-        if mapping:
-            movebookmarks(ui, repo, mapping, state.topmost, ntm)
-            # TODO update mq state
-        if supportsmarkers:
-            markers = []
-            # sort by revision number because it sound "right"
-            for prec in sorted(mapping, key=repo.changelog.rev):
-                succs = mapping[prec]
-                markers.append((repo[prec],
-                                tuple(repo[s] for s in succs)))
-            if markers:
-                obsolete.createmarkers(repo, markers)
-        else:
-            cleanupnode(ui, repo, 'replaced', mapping)
-    if supportsmarkers:
-        obsolete.createmarkers(repo, ((repo[t],()) for t in sorted(tmpnodes)))
-    else:
-        cleanupnode(ui, repo, 'temp', tmpnodes)
-    state.clear()
-    if os.path.exists(repo.sjoin('undo')):
-        os.unlink(repo.sjoin('undo'))
+    cleanup(ui, repo, state, mapping, ntm, supportsmarkers, tmpnodes)
 
 def bootstrapcontinue(ui, state, opts):
     repo = state.repo


More information about the Mercurial-devel mailing list