[meld] Support new-style file retrieval in Mercurial



commit ad1de76f5222b3686287f73a96ee8a029bfa965a
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Mon May 27 07:27:48 2013 +1000

    Support new-style file retrieval in Mercurial

 meld/vc/mercurial.py |   30 ++++++++++++++++++++----------
 1 files changed, 20 insertions(+), 10 deletions(-)
---
diff --git a/meld/vc/mercurial.py b/meld/vc/mercurial.py
index 3096dff..ab51f39 100644
--- a/meld/vc/mercurial.py
+++ b/meld/vc/mercurial.py
@@ -23,6 +23,9 @@
 
 import errno
 import os
+import shutil
+import subprocess
+import tempfile
 
 from . import _vc
 
@@ -32,10 +35,7 @@ class Vc(_vc.CachedVc):
     CMD = "hg"
     NAME = "Mercurial"
     VC_DIR = ".hg"
-    PATCH_STRIP_NUM = 1
-    # Mercurial diffs can be run in "git" mode
-    PATCH_INDEX_RE = "^diff (?:-r \w+ |--git a/.* b/)(.*)$"
-    DIFF_GIT_MODE = False
+
     state_map = {
         "?": _vc.STATE_NONE,
         "A": _vc.STATE_NEW,
@@ -49,12 +49,6 @@ class Vc(_vc.CachedVc):
     def commit_command(self, message):
         return [self.CMD, "commit", "-m", message]
 
-    def diff_command(self):
-        ret = [self.CMD, "diff"]
-        if self.DIFF_GIT_MODE:
-            ret.append("--git")
-        return ret
-
     def update_command(self):
         return [self.CMD, "update"]
 
@@ -79,6 +73,22 @@ class Vc(_vc.CachedVc):
         else:
             return ''
 
+    def get_path_for_repo_file(self, path, commit=None):
+        if commit is not None:
+            raise NotImplementedError()
+
+        if not path.startswith(self.root + os.path.sep):
+            raise _vc.InvalidVCPath(self, path, "Path not in repository")
+        path = path[len(self.root) + 1:]
+
+        process = subprocess.Popen([self.CMD, "cat", path], cwd=self.root,
+                                   stdout=subprocess.PIPE,
+                                   stderr=subprocess.PIPE)
+
+        with tempfile.NamedTemporaryFile(prefix='meld-tmp', delete=False) as f:
+            shutil.copyfileobj(process.stdout, f)
+        return f.name
+
     def _update_tree_state_cache(self, path, tree_state):
         """ Update the state of the file(s) at tree_state['path'] """
         while 1:


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