Patchwork D2887: filemerge: move temp file unlinks to _maketempfiles

login
register
mail settings
Submitter phabricator
Date March 19, 2018, 2:37 p.m.
Message ID <557b62229080193c1d022c88173b5044@localhost.localdomain>
Download mbox | patch
Permalink /patch/29632/
State Not Applicable
Headers show

Comments

phabricator - March 19, 2018, 2:37 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG3723b42ff953: filemerge: move temp file unlinks to _maketempfiles (authored by spectral, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2887?vs=7085&id=7118

REVISION DETAIL
  https://phab.mercurial-scm.org/D2887

AFFECTED FILES
  mercurial/filemerge.py

CHANGE DETAILS




To: spectral, #hg-reviewers, yuja
Cc: mercurial-devel

Patch

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -7,6 +7,7 @@ 
 
 from __future__ import absolute_import
 
+import contextlib
 import os
 import re
 import tempfile
@@ -510,8 +511,8 @@ 
         return False, 1, None
     unused, unused, unused, back = files
     localpath = _workingpath(repo, fcd)
-    basepath, otherpath = _maketempfiles(repo, fco, fca)
-    try:
+    with _maketempfiles(repo, fco, fca) as temppaths:
+        basepath, otherpath = temppaths
         outpath = ""
         mylabel, otherlabel = labels[:2]
         if len(labels) >= 3:
@@ -549,9 +550,6 @@ 
         r = ui.system(cmd, cwd=repo.root, environ=env, blockedtag='mergetool')
         repo.ui.debug('merge tool returned: %d\n' % r)
         return True, r, False
-    finally:
-        util.unlink(basepath)
-        util.unlink(otherpath)
 
 def _formatconflictmarker(ctx, template, label, pad):
     """Applies the given template to the ctx, prefixed by the label.
@@ -665,6 +663,7 @@ 
         # the backup context regardless of where it lives.
         return context.arbitraryfilectx(back, repo=repo)
 
+@contextlib.contextmanager
 def _maketempfiles(repo, fco, fca):
     """Writes out `fco` and `fca` as temporary files, so an external merge
     tool may use them.
@@ -681,8 +680,11 @@ 
 
     b = temp("base", fca)
     c = temp("other", fco)
-
-    return b, c
+    try:
+        yield b, c
+    finally:
+        util.unlink(b)
+        util.unlink(c)
 
 def _filemerge(premerge, repo, wctx, mynode, orig, fcd, fco, fca, labels=None):
     """perform a 3-way merge in the working directory