Patchwork [1,of,2,evolve-ext] evolve: extract logic to new method _relocatecommit

login
register
mail settings
Submitter Shusen LIU
Date Dec. 15, 2015, 1:26 a.m.
Message ID <0f231df1aba960973ae8.1450142811@dev1221.lla1.facebook.com>
Download mbox | patch
Permalink /patch/12046/
State Accepted
Delegated to: Laurent Charignon
Headers show

Comments

Shusen LIU - Dec. 15, 2015, 1:26 a.m.
# HG changeset patch
# User Shusen LIU <liushusen@fb.com>
# Date 1450141375 28800
#      Mon Dec 14 17:02:55 2015 -0800
# Node ID 0f231df1aba960973ae8cd1536632f63cb55372a
# Parent  42c30774e63d3aeace07687740b76c43c6fc37ad
evolve: extract logic to new method _relocatecommit

This patch introduces a new method _relocatecommit to commit current state
after merge states in relocate method.
This simplifies the code of the method relocate and allows us to modify it later to
support a continued keywork to implement evolve state.

Patch

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -953,22 +953,7 @@ 
             if r[-1]:  #some conflict
                 raise error.Abort(
                         'unresolved merge conflicts (see hg help resolve)')
-            if commitmsg is None:
-                commitmsg = orig.description()
-            extra = dict(orig.extra())
-            if 'branch' in extra:
-                del extra['branch']
-            extra['rebase_source'] = orig.hex()
-
-            backup = repo.ui.backupconfig('phases', 'new-commit')
-            try:
-                targetphase = max(orig.phase(), phases.draft)
-                repo.ui.setconfig('phases', 'new-commit', targetphase, 'rebase')
-                # Commit might fail if unresolved files exist
-                nodenew = repo.commit(text=commitmsg, user=orig.user(),
-                                      date=orig.date(), extra=extra)
-            finally:
-                repo.ui.restoreconfig(backup)
+            nodenew = _relocatecommit(repo, orig, commitmsg)
         except error.Abort as exc:
             repo.dirstate.beginparentchange()
             repo.setparents(repo['.'].node(), nullid)
@@ -3671,3 +3656,22 @@ 
         help.helptable.append((["evolution"], _("Safely Rewriting History"),
                       _helploader))
         help.helptable.sort()
+
+def _relocatecommit(repo, orig, commitmsg):
+    if commitmsg is None:
+        commitmsg = orig.description()
+    extra = dict(orig.extra())
+    if 'branch' in extra:
+        del extra['branch']
+    extra['rebase_source'] = orig.hex()
+
+    backup = repo.ui.backupconfig('phases', 'new-commit')
+    try:
+        targetphase = max(orig.phase(), phases.draft)
+        repo.ui.setconfig('phases', 'new-commit', targetphase, 'rebase')
+        # Commit might fail if unresolved files exist
+        nodenew = repo.commit(text=commitmsg, user=orig.user(),
+                              date=orig.date(), extra=extra)
+    finally:
+        repo.ui.restoreconfig(backup)
+    return nodenew