evolvecmd: move remaining logic to merge commit desc to existing utility fn
authorPulkit Goyal <7895pulkit@gmail.com>
Sun, 08 Jul 2018 21:18:33 +0530
changeset 3878 dc2b53b3573f
parent 3877 96bbea985b25
child 3879 1fa3bf6e9e93
evolvecmd: move remaining logic to merge commit desc to existing utility fn This was a bit awful because we had a utility function and still we did some of merging outside of that fn. So let's move the remaining parts there.
hgext3rd/evolve/evolvecmd.py
--- a/hgext3rd/evolve/evolvecmd.py	Sun Jul 08 22:52:33 2018 +0530
+++ b/hgext3rd/evolve/evolvecmd.py	Sun Jul 08 21:18:33 2018 +0530
@@ -542,21 +542,9 @@
         # merge the branches
         mergebranches(repo, divergent, other, base)
         # merge the commit messages
-        desc, conflicts = mergecommitmessages(base.description(),
-                                              divergent.description(),
-                                              other.description())
-        if conflicts:
-
-            prefixes = ("HG: Conflicts while merging changeset description of"
-                        " content-divergent changesets.\nHG: Resolve conflicts"
-                        " in commit messages to continue.\n\n")
-
-            resolveddesc = ui.edit(prefixes + desc, ui.username(), action='desc')
-            # make sure we remove the prefixes part from final commit message
-            if prefixes in resolveddesc:
-                # hack, we should find something better
-                resolveddesc = resolveddesc[len(prefixes):]
-            desc = resolveddesc
+        desc = mergecommitmessages(ui, base.description(),
+                                   divergent.description(),
+                                   other.description())
 
         # new node if any formed as the replacement
         newnode = None
@@ -692,7 +680,7 @@
             elif index == 2:
                 repo.dirstate.setbranch(othbranch)
 
-def mergecommitmessages(basedesc, divdesc, othdesc):
+def mergecommitmessages(ui, basedesc, divdesc, othdesc):
     """merges the commit messages and return the new merged message and whether
     there were conflicts or not while merging the messages"""
 
@@ -705,7 +693,21 @@
                                    **kwargs):
         mdesc.append(line)
 
-    return ''.join(mdesc), merger.conflicts
+    desc = ''.join(mdesc)
+    if merger.conflicts:
+
+        prefixes = ("HG: Conflicts while merging changeset description of"
+                    " content-divergent changesets.\nHG: Resolve conflicts"
+                    " in commit messages to continue.\n\n")
+
+        resolveddesc = ui.edit(prefixes + desc, ui.username(), action='desc')
+        # make sure we remove the prefixes part from final commit message
+        if prefixes in resolveddesc:
+            # hack, we should find something better
+            resolveddesc = resolveddesc[len(prefixes):]
+        desc = resolveddesc
+
+    return desc
 
 class MergeFailure(error.Abort):
     pass