Patchwork [1,of,6] filemerge: clean up temp files in a finally block

login
register
mail settings
Submitter Siddharth Agarwal
Date Oct. 9, 2015, 6:46 p.m.
Message ID <f32ecec8697102c6daed.1444416368@dev6666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/10920/
State Accepted
Headers show

Comments

Siddharth Agarwal - Oct. 9, 2015, 6:46 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1444279884 25200
#      Wed Oct 07 21:51:24 2015 -0700
# Node ID f32ecec8697102c6daeda1f3a98711a8305f928d
# Parent  c22f7a4cc983588c6759f869d5c94f667bad1f70
filemerge: clean up temp files in a finally block

This isn't really a big deal because the temp files are created in $TMPDIR, but
it makes some upcoming work simpler.

Patch

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -505,13 +505,14 @@  def filemerge(repo, mynode, orig, fcd, f
         util.copyfile(a, back)
         files = (a, b, c, back)
 
+    r = 1
+    try:
         markerstyle = ui.config('ui', 'mergemarkers', 'basic')
         if not labels:
             labels = _defaultconflictlabels
         if markerstyle != 'basic':
             labels = _formatlabels(repo, fcd, fco, fca, labels)
 
-        r = 1
         if mergetype == fullmerge:
             r = _premerge(repo, toolconf, files, labels=labels)
 
@@ -527,12 +528,13 @@  def filemerge(repo, mynode, orig, fcd, f
         if r:
             if onfailure:
                 ui.warn(onfailure % fd)
-        else:
+
+        return r
+    finally:
+        if not r:
             util.unlink(back)
-
         util.unlink(b)
         util.unlink(c)
-        return r
 
 def _check(r, ui, tool, fcd, files):
     fd = fcd.path()