[meld/Python3: 25/54] vc: Add file idenifier option for use in conflict naming, and port it



commit 00366db9cec8761dea6f3163f0c0a909d78087ce
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Nov 15 07:49:34 2015 +1000

    vc: Add file idenifier option for use in conflict naming, and port it

 meld/vc/_vc.py |    8 ++++++--
 meld/vc/git.py |   15 +++------------
 2 files changed, 9 insertions(+), 14 deletions(-)
---
diff --git a/meld/vc/_vc.py b/meld/vc/_vc.py
index 5d9912e..be855e7 100644
--- a/meld/vc/_vc.py
+++ b/meld/vc/_vc.py
@@ -373,11 +373,14 @@ def popen(cmd, cwd=None):
     return subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE).stdout
 
 
-def call_temp_output(cmd, cwd):
+def call_temp_output(cmd, cwd, file_id=''):
     """Call `cmd` in `cwd` and write the output to a temporary file
 
     This returns the name of the temporary file used. It is the
     caller's responsibility to delete this file.
+
+    If `file_id` is provided, it is used as part of the
+    temporary file's name, for ease of identification.
     """
     process = subprocess.Popen(
         cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@@ -386,7 +389,8 @@ def call_temp_output(cmd, cwd):
     # Error handling here involves doing nothing; in most cases, the only
     # sane response is to return an empty temp file.
 
-    with tempfile.NamedTemporaryFile(prefix='meld-tmp', delete=False) as f:
+    prefix = 'meld-tmp' + ('-' + file_id if file_id else '')
+    with tempfile.NamedTemporaryFile(prefix=prefix, delete=False) as f:
         shutil.copyfileobj(vc_file, f)
     return f.name
 
diff --git a/meld/vc/git.py b/meld/vc/git.py
index 967f454..264957f 100644
--- a/meld/vc/git.py
+++ b/meld/vc/git.py
@@ -229,18 +229,9 @@ class Vc(_vc.Vc):
             path = path.replace("\\", "/")
 
         args = ["git", "show", ":%s:%s" % (self.conflict_map[conflict], path)]
-        process = subprocess.Popen(args,
-                                   cwd=self.location, stdout=subprocess.PIPE,
-                                   stderr=subprocess.PIPE)
-        vc_file = process.stdout
-
-        # Error handling here involves doing nothing; in most cases, the only
-        # sane response is to return an empty temp file.
-
-        prefix = 'meld-tmp-%s-' % _vc.conflicts[conflict]
-        with tempfile.NamedTemporaryFile(prefix=prefix, delete=False) as f:
-            shutil.copyfileobj(vc_file, f)
-        return f.name, True
+        filename = _vc.call_temp_output(
+            args, cwd=self.location, file_id=_vc.conflicts[conflict])
+        return filename, True
 
     def get_path_for_repo_file(self, path, commit=None):
         if commit is None:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]