filemerge: indent filemerge.filemerge
authorSiddharth Agarwal <sid0@fb.com>
Tue, 06 Oct 2015 17:39:13 -0700
changeset 26512 4c52dd406adc
parent 26511 bb3d961c1648
child 26513 01224c28e0ed
filemerge: indent filemerge.filemerge This will make upcoming patches much easier to review.
mercurial/filemerge.py
--- a/mercurial/filemerge.py	Thu Oct 01 20:15:00 2015 -0700
+++ b/mercurial/filemerge.py	Tue Oct 06 17:39:13 2015 -0700
@@ -441,62 +441,98 @@
     fcd = local file context for current/destination file
     """
 
-    def temp(prefix, ctx):
-        pre = "%s~%s." % (os.path.basename(ctx.path()), prefix)
-        (fd, name) = tempfile.mkstemp(prefix=pre)
-        data = repo.wwritedata(ctx.path(), ctx.data())
-        f = os.fdopen(fd, "wb")
-        f.write(data)
-        f.close()
-        return name
+    if True:
+        def temp(prefix, ctx):
+            pre = "%s~%s." % (os.path.basename(ctx.path()), prefix)
+            (fd, name) = tempfile.mkstemp(prefix=pre)
+            data = repo.wwritedata(ctx.path(), ctx.data())
+            f = os.fdopen(fd, "wb")
+            f.write(data)
+            f.close()
+            return name
+
+        if not fco.cmp(fcd): # files identical?
+            return None
+
+        ui = repo.ui
+        fd = fcd.path()
+        binary = fcd.isbinary() or fco.isbinary() or fca.isbinary()
+        symlink = 'l' in fcd.flags() + fco.flags()
+        tool, toolpath = _picktool(repo, ui, fd, binary, symlink)
+        ui.debug("picked tool '%s' for %s (binary %s symlink %s)\n" %
+                   (tool, fd, binary, symlink))
 
-    if not fco.cmp(fcd): # files identical?
-        return None
+        if tool in internals:
+            func = internals[tool]
+            trymerge = func.trymerge
+            onfailure = func.onfailure
+        else:
+            func = _xmerge
+            trymerge = True
+            onfailure = _("merging %s failed!\n")
+
+        toolconf = tool, toolpath, binary, symlink
 
-    ui = repo.ui
-    fd = fcd.path()
-    binary = fcd.isbinary() or fco.isbinary() or fca.isbinary()
-    symlink = 'l' in fcd.flags() + fco.flags()
-    tool, toolpath = _picktool(repo, ui, fd, binary, symlink)
-    ui.debug("picked tool '%s' for %s (binary %s symlink %s)\n" %
-               (tool, fd, binary, symlink))
+        if not trymerge:
+            return func(repo, mynode, orig, fcd, fco, fca, toolconf)
+
+        a = repo.wjoin(fd)
+        b = temp("base", fca)
+        c = temp("other", fco)
+        back = a + ".orig"
+        util.copyfile(a, back)
+
+        if orig != fco.path():
+            ui.status(_("merging %s and %s to %s\n") % (orig, fco.path(), fd))
+        else:
+            ui.status(_("merging %s\n") % fd)
 
-    if tool in internals:
-        func = internals[tool]
-        trymerge = func.trymerge
-        onfailure = func.onfailure
-    else:
-        func = _xmerge
-        trymerge = True
-        onfailure = _("merging %s failed!\n")
+        ui.debug("my %s other %s ancestor %s\n" % (fcd, fco, fca))
+
+        markerstyle = ui.config('ui', 'mergemarkers', 'basic')
+        if not labels:
+            labels = _defaultconflictlabels
+        if markerstyle != 'basic':
+            labels = _formatlabels(repo, fcd, fco, fca, labels)
 
-    toolconf = tool, toolpath, binary, symlink
+        needcheck, r = func(repo, mynode, orig, fcd, fco, fca, toolconf,
+                            (a, b, c, back), labels=labels)
+        if not needcheck:
+            if r:
+                if onfailure:
+                    ui.warn(onfailure % fd)
+            else:
+                util.unlink(back)
 
-    if not trymerge:
-        return func(repo, mynode, orig, fcd, fco, fca, toolconf)
+            util.unlink(b)
+            util.unlink(c)
+            return r
 
-    a = repo.wjoin(fd)
-    b = temp("base", fca)
-    c = temp("other", fco)
-    back = a + ".orig"
-    util.copyfile(a, back)
+        if not r and (_toolbool(ui, tool, "checkconflicts") or
+                      'conflicts' in _toollist(ui, tool, "check")):
+            if re.search("^(<<<<<<< .*|=======|>>>>>>> .*)$", fcd.data(),
+                         re.MULTILINE):
+                r = 1
 
-    if orig != fco.path():
-        ui.status(_("merging %s and %s to %s\n") % (orig, fco.path(), fd))
-    else:
-        ui.status(_("merging %s\n") % fd)
+        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
 
-    ui.debug("my %s other %s ancestor %s\n" % (fcd, fco, fca))
+        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
 
-    markerstyle = ui.config('ui', 'mergemarkers', 'basic')
-    if not labels:
-        labels = _defaultconflictlabels
-    if markerstyle != 'basic':
-        labels = _formatlabels(repo, fcd, fco, fca, labels)
+        if _toolbool(ui, tool, "fixeol"):
+            _matcheol(a, back)
 
-    needcheck, r = func(repo, mynode, orig, fcd, fco, fca, toolconf,
-                        (a, b, c, back), labels=labels)
-    if not needcheck:
         if r:
             if onfailure:
                 ui.warn(onfailure % fd)
@@ -507,39 +543,5 @@
         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 r:
-        if onfailure:
-            ui.warn(onfailure % fd)
-    else:
-        util.unlink(back)
-
-    util.unlink(b)
-    util.unlink(c)
-    return r
-
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = internals.values()