diff mercurial/commit.py @ 46386:d6fa9fbd375d stable

commit: reorder if-else conditional to give mergestate info priority Looking at the code now, I was unable to find a good reason as why we only rely on mergestate extras info after checking whether a filelog parent is ancestor of other or not. I mean if we have stored in mergestate that `other` was chosed, we should blindly pick that one. This cleanup will also help introduce more cases when both `fparent1` and `fparent2` are non-null but using info from mergestate, we can fastpath. The test change actually demonstrates the point of the patch. During merge we were getting the other side of the file but on commit we were marking that as merged. Differential Revision: https://phab.mercurial-scm.org/D10147
author Pulkit Goyal <7895pulkit@gmail.com>
date Thu, 04 Mar 2021 17:35:58 +0530
parents 89a2afe31e82
children e2f7b2695ba1
line wrap: on
line diff
--- a/mercurial/commit.py	Wed Mar 10 15:24:52 2021 +1000
+++ b/mercurial/commit.py	Thu Mar 04 17:35:58 2021 +0530
@@ -355,19 +355,15 @@
     elif fparent1 == nullid:
         fparent1, fparent2 = fparent2, nullid
     elif fparent2 != nullid:
-        # is one parent an ancestor of the other?
-        fparentancestors = flog.commonancestorsheads(fparent1, fparent2)
-        if fparent1 in fparentancestors:
+        if ms.active() and ms.extras(fname).get(b'filenode-source') == b'other':
             fparent1, fparent2 = fparent2, nullid
-        elif fparent2 in fparentancestors:
-            fparent2 = nullid
-        elif not fparentancestors:
-            # TODO: this whole if-else might be simplified much more
-            if (
-                ms.active()
-                and ms.extras(fname).get(b'filenode-source') == b'other'
-            ):
+        # is one parent an ancestor of the other?
+        else:
+            fparentancestors = flog.commonancestorsheads(fparent1, fparent2)
+            if fparent1 in fparentancestors:
                 fparent1, fparent2 = fparent2, nullid
+            elif fparent2 in fparentancestors:
+                fparent2 = nullid
 
     force_new_node = False
     # The file might have been deleted by merge code and user explicitly choose