evolve: extract function for solving one revision, including merges
authorMartin von Zweigbergk <martinvonz@google.com>
Fri, 19 Apr 2019 10:01:32 -0700
changeset 4606 6c3f4cfa582e
parent 4605 f8790714b741
child 4607 d314deb12f08
evolve: extract function for solving one revision, including merges Will make the next patch simpler.
hgext3rd/evolve/evolvecmd.py
--- a/hgext3rd/evolve/evolvecmd.py	Thu Apr 25 17:20:32 2019 +0800
+++ b/hgext3rd/evolve/evolvecmd.py	Fri Apr 19 10:01:32 2019 -0700
@@ -1724,37 +1724,9 @@
 
         activetopic = getattr(repo, 'currenttopic', '')
         for rev in revs:
-            curctx = repo[rev]
-            revtopic = getattr(curctx, 'topic', lambda: '')()
-            topicidx = getattr(curctx, 'topicidx', lambda: None)()
-            stacktmplt = False
-            # check if revision being evolved is in active topic to make sure
-            # that we can use stack aliases s# in evolve msgs.
-            if activetopic and (activetopic == revtopic) and topicidx is not None:
-                stacktmplt = True
-            progresscb()
-            ret = _solveone(ui, repo, curctx, evolvestate, dryrunopt,
-                            confirmopt, progresscb, targetcat,
-                            lastsolved=lastsolved, stacktmplt=stacktmplt)
-            if ret[0]:
-                evolvestate['replacements'][curctx.node()] = ret[1]
-                lastsolved = ret[1]
-            else:
-                evolvestate['skippedrevs'].append(curctx.node())
-
-            if evolvestate['orphanmerge']:
-                # we were processing an orphan merge with both parents obsolete,
-                # stabilized for second parent, re-stabilize for the first parent
-                ret = _solveone(ui, repo, repo[ret[1]], evolvestate, dryrunopt,
-                                confirmopt, progresscb, targetcat,
-                                stacktmplt=stacktmplt)
-                if ret[0]:
-                    evolvestate['replacements'][curctx.node()] = ret[1]
-                    lastsolved = ret[1]
-                else:
-                    evolvestate['skippedrevs'].append(curctx.node())
-
-                evolvestate['orphanmerge'] = False
+            lastsolved = _solveonerev(ui, repo, rev, evolvestate, activetopic,
+                                      dryrunopt, confirmopt, progresscb,
+                                      targetcat, lastsolved)
             seen += 1
 
         if showprogress:
@@ -1762,6 +1734,46 @@
 
     _cleanup(ui, repo, startnode, shouldupdate)
 
+def _solveonerev(ui, repo, rev, evolvestate, activetopic, dryrunopt, confirmopt,
+                 progresscb, targetcat, lastsolved):
+    """solves one trouble, including orphan merges
+
+    Like _solveone(), this solves one trouble. Unlike _solveone(), it
+    stabilizes for both parents of orphan merges.
+    """
+    curctx = repo[rev]
+    revtopic = getattr(curctx, 'topic', lambda: '')()
+    topicidx = getattr(curctx, 'topicidx', lambda: None)()
+    stacktmplt = False
+    # check if revision being evolved is in active topic to make sure
+    # that we can use stack aliases s# in evolve msgs.
+    if activetopic and (activetopic == revtopic) and topicidx is not None:
+        stacktmplt = True
+    progresscb()
+    ret = _solveone(ui, repo, curctx, evolvestate, dryrunopt,
+                    confirmopt, progresscb, targetcat,
+                    lastsolved=lastsolved, stacktmplt=stacktmplt)
+    if ret[0]:
+        evolvestate['replacements'][curctx.node()] = ret[1]
+        lastsolved = ret[1]
+    else:
+        evolvestate['skippedrevs'].append(curctx.node())
+
+    if evolvestate['orphanmerge']:
+        # we were processing an orphan merge with both parents obsolete,
+        # stabilized for second parent, re-stabilize for the first parent
+        ret = _solveone(ui, repo, repo[ret[1]], evolvestate, dryrunopt,
+                        confirmopt, progresscb, targetcat,
+                        stacktmplt=stacktmplt)
+        if ret[0]:
+            evolvestate['replacements'][curctx.node()] = ret[1]
+            lastsolved = ret[1]
+        else:
+            evolvestate['skippedrevs'].append(curctx.node())
+
+        evolvestate['orphanmerge'] = False
+    return lastsolved
+
 def solveobswdp(ui, repo, opts):
     """this function updates to the successor of obsolete wdir parent"""
     oldid = repo['.'].node()