evolve: factor out logic to merge branches in separate function
authorPulkit Goyal <7895pulkit@gmail.com>
Mon, 11 Jun 2018 15:38:43 +0530
changeset 3829 cb45a7173e5b
parent 3828 c58ebf5d2f57
child 3830 e0a20dc69126
evolve: factor out logic to merge branches in separate function This patch moves the logic to merge branches while resolving content-divergence to a separate function. This makes code clear and better to understand.
hgext3rd/evolve/evolvecmd.py
--- a/hgext3rd/evolve/evolvecmd.py	Mon Jun 11 01:00:57 2018 +0530
+++ b/hgext3rd/evolve/evolvecmd.py	Mon Jun 11 15:38:43 2018 +0530
@@ -525,35 +525,9 @@
         # interrupted evolve
         evolvestate.delete()
 
-        divbranch = divergent.branch()
-        basebranch = base.branch()
-        othbranch = other.branch()
-        # content divergent changes were on different branches, ask user to
-        # select one
-        if divbranch != othbranch:
-
-            if basebranch == othbranch and basebranch != divbranch:
-                # we will be amending the divergent changeset so branch will be
-                # preserved
-                pass
-            elif basebranch == divbranch and basebranch != othbranch:
-                repo.dirstate.setbranch(othbranch)
-            else:
-                # all the three branches are different
-                index = ui.promptchoice(_("content divergent changesets on "
-                                          "different branches.\nchoose branch"
-                                          " for the resolution changeset. (a) "
-                                          "%s or (b) %s or (c) %s? $$ &a $$ &b"
-                                          " $$ &c") %
-                                        (basebranch, divbranch, othbranch), 0)
-
-                if index == 0:
-                    repo.dirstate.setbranch(basebranch)
-                elif index == 1:
-                    pass
-                elif index == 2:
-                    repo.dirstate.setbranch(othbranch)
-
+        # merge the branches
+        mergebranches(repo, divergent, other, base)
+        # merge the commit messages
         desc, conflicts = mergecommitmessages(base.description(),
                                               divergent.description(),
                                               other.description())
@@ -590,6 +564,43 @@
     finally:
         repo.ui.restoreconfig(emtpycommitallowed)
 
+def mergebranches(repo, divergent, other, base):
+    """merges the branch information for content-divergent changesets and sets
+    the dirstate branch accordingly
+    If unable to merge, prompts user to select a branch
+
+    If the branch name is different from the branch of divergent changeset, it
+    sets the current branch using repo.dirstate.setbranch()
+    """
+    divbranch = divergent.branch()
+    basebranch = base.branch()
+    othbranch = other.branch()
+    # content divergent changes were on different branches, ask user to
+    # select one
+    if divbranch != othbranch:
+
+        if basebranch == othbranch and basebranch != divbranch:
+            # we will be amending the divergent changeset so branch will be
+            # preserved
+            pass
+        elif basebranch == divbranch and basebranch != othbranch:
+            repo.dirstate.setbranch(othbranch)
+        else:
+            # all the three branches are different
+            index = repo.ui.promptchoice(_("content divergent changesets on "
+                                           "different branches.\nchoose branch"
+                                           " for the resolution changeset. (a) "
+                                           "%s or (b) %s or (c) %s? $$ &a $$ &b"
+                                           " $$ &c") %
+                                         (basebranch, divbranch, othbranch), 0)
+
+            if index == 0:
+                repo.dirstate.setbranch(basebranch)
+            elif index == 1:
+                pass
+            elif index == 2:
+                repo.dirstate.setbranch(othbranch)
+
 def mergecommitmessages(basedesc, divdesc, othdesc):
     """merges the commit messages and return the new merged message and whether
     there were conflicts or not while merging the messages"""