Patchwork [4,of,4,marmoute-reviewed] filemerge: move post-merge checks into a separate function

login
register
mail settings
Submitter Siddharth Agarwal
Date Oct. 9, 2015, 4:40 a.m.
Message ID <9f16a3c6df3b715b1640.1444365635@dev6666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/10905/
State Accepted
Headers show

Comments

Siddharth Agarwal - Oct. 9, 2015, 4:40 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1444286130 25200
#      Wed Oct 07 23:35:30 2015 -0700
# Node ID 9f16a3c6df3b715b164029b13c8970d4021c65cd
# Parent  e550d45ce05dbd503f897b4143c302aded345cdc
filemerge: move post-merge checks into a separate function

This makes the overall filemerge function easier to follow, and makes upcoming
work simpler.
Pierre-Yves David - Oct. 9, 2015, 12:29 p.m.
On 10/08/2015 09:40 PM, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0@fb.com>
> # Date 1444286130 25200
> #      Wed Oct 07 23:35:30 2015 -0700
> # Node ID 9f16a3c6df3b715b164029b13c8970d4021c65cd
> # Parent  e550d45ce05dbd503f897b4143c302aded345cdc
> filemerge: move post-merge checks into a separate function

These are pushed to the clowcopter, thanks.

Patch

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -521,41 +521,8 @@  def filemerge(repo, mynode, orig, fcd, f
             needcheck, r = func(repo, mynode, orig, fcd, fco, fca, toolconf,
                                 files, labels=labels)
 
-        if not needcheck:
-            if r:
-                if onfailure:
-                    ui.warn(onfailure % fd)
-            else:
-                util.unlink(back)
-
-            util.unlink(b)
-            util.unlink(c)
-            return r
-
-        if not r and (_toolbool(ui, tool, "checkconflicts") or
-                      'conflicts' in _toollist(ui, tool, "check")):
-            if re.search("^(<<<<<<< .*|=======|>>>>>>> .*)$", fcd.data(),
-                         re.MULTILINE):
-                r = 1
-
-        checked = False
-        if 'prompt' in _toollist(ui, tool, "check"):
-            checked = True
-            if ui.promptchoice(_("was merge of '%s' successful (yn)?"
-                                 "$$ &Yes $$ &No") % fd, 1):
-                r = 1
-
-        if not r and not checked and (_toolbool(ui, tool, "checkchanged") or
-                                      'changed' in
-                                      _toollist(ui, tool, "check")):
-            if filecmp.cmp(a, back):
-                if ui.promptchoice(_(" output file %s appears unchanged\n"
-                                     "was merge successful (yn)?"
-                                     "$$ &Yes $$ &No") % fd, 1):
-                    r = 1
-
-        if _toolbool(ui, tool, "fixeol"):
-            _matcheol(a, back)
+        if needcheck:
+            r = _check(r, ui, tool, fcd, files)
 
         if r:
             if onfailure:
@@ -567,5 +534,36 @@  def filemerge(repo, mynode, orig, fcd, f
         util.unlink(c)
         return r
 
+def _check(r, ui, tool, fcd, files):
+    fd = fcd.path()
+    a, b, c, back = files
+
+    if not r and (_toolbool(ui, tool, "checkconflicts") or
+                  'conflicts' in _toollist(ui, tool, "check")):
+        if re.search("^(<<<<<<< .*|=======|>>>>>>> .*)$", fcd.data(),
+                     re.MULTILINE):
+            r = 1
+
+    checked = False
+    if 'prompt' in _toollist(ui, tool, "check"):
+        checked = True
+        if ui.promptchoice(_("was merge of '%s' successful (yn)?"
+                             "$$ &Yes $$ &No") % fd, 1):
+            r = 1
+
+    if not r and not checked and (_toolbool(ui, tool, "checkchanged") or
+                                  'changed' in
+                                  _toollist(ui, tool, "check")):
+        if filecmp.cmp(a, back):
+            if ui.promptchoice(_(" output file %s appears unchanged\n"
+                                 "was merge successful (yn)?"
+                                 "$$ &Yes $$ &No") % fd, 1):
+                r = 1
+
+    if _toolbool(ui, tool, "fixeol"):
+        _matcheol(a, back)
+
+    return r
+
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = internals.values()