[PATCH 05 of 12] histedit: move `continue` logic into a dedicated function

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Thu Sep 27 07:23:24 CDT 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1348746887 -7200
# Node ID 395622e18051ea08908bcb745ac6cef41b967c5c
# Parent  8ec2ed9d2c24ff8c5de10444e68fd9809254be9d
histedit: move `continue` logic into a dedicated function

When histedit "continue", there is several complicated logic to apply in order to
detect intermediate changeset and concluded pending operation.

This changeset extract this logic in a dedicated function to lighten the main
one. No alteration to the logic is done.

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -417,66 +417,15 @@ def histedit(ui, repo, *parent, **opts):
     if opts.get('continue', False):
         if len(parent) != 0:
             raise util.Abort(_('no arguments allowed with --continue'))
         (parentctxnode, created, replaced, tmpnodes,
          existing, rules, keep, topmost, replacemap) = readstate(repo)
-        currentparent, wantnull = repo.dirstate.parents()
         parentctx = repo[parentctxnode]
-        # existing is the list of revisions initially considered by
-        # histedit. Here we use it to list new changesets, descendants
-        # of parentctx without an 'existing' changeset in-between. We
-        # also have to exclude 'existing' changesets which were
-        # previously dropped.
-        descendants = set(c.node() for c in
-                repo.set('(%n::) - %n', parentctxnode, parentctxnode))
         existing = set(existing)
-        notdropped = set(n for n in existing if n in descendants and
-                (n not in replacemap or replacemap[n] in descendants))
-        # Discover any nodes the user has added in the interim. We can
-        # miss changesets which were dropped and recreated the same.
-        newchildren = list(c.node() for c in repo.set(
-            'sort(%ln - (%ln or %ln::))', descendants, existing, notdropped))
-        action, currentnode = rules.pop(0)
-        if action in ('f', 'fold'):
-            tmpnodes.extend(newchildren)
-        else:
-            created.extend(newchildren)
-
-        m, a, r, d = repo.status()[:4]
-        oldctx = repo[currentnode]
-        message = oldctx.description() + '\n'
-        if action in ('e', 'edit', 'm', 'mess'):
-            message = ui.edit(message, ui.username())
-        elif action in ('f', 'fold'):
-            message = 'fold-temp-revision %s' % currentnode
-        new = None
-        if m or a or r or d:
-            new = repo.commit(text=message, user=oldctx.user(),
-                              date=oldctx.date(), extra=oldctx.extra())
-
-        # If we're resuming a fold and we have new changes, mark the
-        # replacements and finish the fold. If not, it's more like a
-        # drop of the changesets that disappeared, and we can skip
-        # this step.
-        if action in ('f', 'fold') and (new or newchildren):
-            if new:
-                tmpnodes.append(new)
-            else:
-                new = newchildren[-1]
-            (parentctx, created_, replaced_, tmpnodes_) = finishfold(
-                ui, repo, parentctx, oldctx, new, opts, newchildren)
-            replaced.extend(replaced_)
-            created.extend(created_)
-            tmpnodes.extend(tmpnodes_)
-        elif action not in ('d', 'drop'):
-            if new != oldctx.node():
-                replaced.append(oldctx.node())
-            if new:
-                if new != oldctx.node():
-                    created.append(new)
-                parentctx = repo[new]
-
+        parentctx = bootstrapcontinue(ui, repo, parentctx, existing,
+                                      replacemap, rules, tmpnodes, created,
+                                      replaced, opts)
     elif opts.get('abort', False):
         if len(parent) != 0:
             raise util.Abort(_('no arguments allowed with --abort'))
         (parentctxnode, created, replaced, tmpnodes,
          existing, rules, keep, topmost, replacemap) = readstate(repo)
@@ -597,10 +546,68 @@ def histedit(ui, repo, *parent, **opts):
     os.unlink(os.path.join(repo.path, 'histedit-state'))
     if os.path.exists(repo.sjoin('undo')):
         os.unlink(repo.sjoin('undo'))
 
 
+def bootstrapcontinue(ui, repo, parentctx, existing, replacemap, rules,
+                      tmpnodes, created, replaced, opts):
+    currentparent, wantnull = repo.dirstate.parents()
+    # existing is the list of revisions initially considered by
+    # histedit. Here we use it to list new changesets, descendants
+    # of parentctx without an 'existing' changeset in-between. We
+    # also have to exclude 'existing' changesets which were
+    # previously dropped.
+    descendants = set(c.node() for c in
+            repo.set('(%d::) - %d', parentctx, parentctx))
+    notdropped = set(n for n in existing if n in descendants and
+            (n not in replacemap or replacemap[n] in descendants))
+    # Discover any nodes the user has added in the interim. We can
+    # miss changesets which were dropped and recreated the same.
+    newchildren = list(c.node() for c in repo.set(
+        'sort(%ln - (%ln or %ln::))', descendants, existing, notdropped))
+    action, currentnode = rules.pop(0)
+    if action in ('f', 'fold'):
+        tmpnodes.extend(newchildren)
+    else:
+        created.extend(newchildren)
+
+    m, a, r, d = repo.status()[:4]
+    oldctx = repo[currentnode]
+    message = oldctx.description() + '\n'
+    if action in ('e', 'edit', 'm', 'mess'):
+        message = ui.edit(message, ui.username())
+    elif action in ('f', 'fold'):
+        message = 'fold-temp-revision %s' % currentnode
+    new = None
+    if m or a or r or d:
+        new = repo.commit(text=message, user=oldctx.user(),
+                          date=oldctx.date(), extra=oldctx.extra())
+
+    # If we're resuming a fold and we have new changes, mark the
+    # replacements and finish the fold. If not, it's more like a
+    # drop of the changesets that disappeared, and we can skip
+    # this step.
+    if action in ('f', 'fold') and (new or newchildren):
+        if new:
+            tmpnodes.append(new)
+        else:
+            new = newchildren[-1]
+        (parentctx, created_, replaced_, tmpnodes_) = finishfold(
+            ui, repo, parentctx, oldctx, new, opts, newchildren)
+        replaced.extend(replaced_)
+        created.extend(created_)
+        tmpnodes.extend(tmpnodes_)
+    elif action not in ('d', 'drop'):
+        if new != oldctx.node():
+            replaced.append(oldctx.node())
+        if new:
+            if new != oldctx.node():
+                created.append(new)
+            parentctx = repo[new]
+    return parentctx
+
+
 def between(repo, old, new, keep):
     """select and validate the set of revision to edit
 
     When keep is false, the specified set can't have children."""
     revs = [old]


More information about the Mercurial-devel mailing list