[meld/VersionControlRework: 16/123] meld.vc: Fix caching API to disallow inadventantly discarding data



commit 22309de503d16f79557255c7aee0a8ce5e245e37
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Mar 22 07:32:36 2015 +1000

    meld.vc: Fix caching API to disallow inadventantly discarding data
    
    The caching API that VCs needed to implement suggested that it would be
    fine to try and cache a subdirectory independently. This never worked.
    
    Now you can only call cache without args, and it will (shoudl) always
    cache the location under the VC. Updating the cache is left for other
    methods.

 meld/vc/_vc.py       |    2 +-
 meld/vc/bzr.py       |    7 ++++---
 meld/vc/git.py       |    3 +--
 meld/vc/mercurial.py |    4 +---
 meld/vc/svn.py       |   11 ++++++-----
 5 files changed, 13 insertions(+), 14 deletions(-)
---
diff --git a/meld/vc/_vc.py b/meld/vc/_vc.py
index 25b9ac0..edf88f1 100644
--- a/meld/vc/_vc.py
+++ b/meld/vc/_vc.py
@@ -197,7 +197,7 @@ class Vc(object):
 
     def _get_tree_cache(self, directory):
         if not self._tree_cache:
-            self._tree_cache = self.cache_tree(directory)
+            self._tree_cache = self.cache_tree()
         return self._tree_cache
 
     def update_file_state(self, path):
diff --git a/meld/vc/bzr.py b/meld/vc/bzr.py
index 5691d11..b60623e 100644
--- a/meld/vc/bzr.py
+++ b/meld/vc/bzr.py
@@ -142,7 +142,7 @@ class Vc(_vc.Vc):
             if os.path.isdir(p):
                 # FIXME: This used to be self._lookup_files(p), which
                 # definitely didn't do what we wanted.
-                entries = self.cache_tree(p)
+                entries = self.cache_tree()
                 names = [
                     x for x, y in entries.items() if y in self.commit_statuses]
                 files.extend(names)
@@ -150,9 +150,10 @@ class Vc(_vc.Vc):
                 files.append(os.path.relpath(p, self.root))
         return sorted(list(set(files)))
 
-    def cache_tree(self, rootdir):
+    def cache_tree(self):
         branch_root = _vc.popen(
-            [self.CMD] + self.CMDARGS + ["root", rootdir]).read().rstrip('\n')
+            [self.CMD] + self.CMDARGS + ["root", "./"],
+            cwd=self.location).read().rstrip('\n')
         entries = []
         while 1:
             try:
diff --git a/meld/vc/git.py b/meld/vc/git.py
index 5466ef6..4ececaf 100644
--- a/meld/vc/git.py
+++ b/meld/vc/git.py
@@ -367,8 +367,7 @@ class Vc(_vc.Vc):
             for path in unversioned_entries:
                 tree_state[get_real_path(path)] = _vc.STATE_NONE
 
-    def cache_tree(self, rootdir):
-        # Get a list of all files in rootdir, as well as their status
+    def cache_tree(self):
         tree_state = {}
         self._update_tree_state_cache("./", tree_state)
         return tree_state
diff --git a/meld/vc/mercurial.py b/meld/vc/mercurial.py
index a5ac73b..4a0f7a8 100644
--- a/meld/vc/mercurial.py
+++ b/meld/vc/mercurial.py
@@ -122,11 +122,9 @@ class Vc(_vc.Vc):
                 state = self.state_map.get(statekey.strip(), _vc.STATE_NONE)
                 tree_state[path] = state
 
-    def cache_tree(self, rootdir):
-        # Get a list of all files in rootdir, as well as their status
+    def cache_tree(self):
         tree_state = {}
         self._update_tree_state_cache("./", tree_state)
-
         return tree_state
 
     def update_file_state(self, path):
diff --git a/meld/vc/svn.py b/meld/vc/svn.py
index 05dcecf..75f31b2 100644
--- a/meld/vc/svn.py
+++ b/meld/vc/svn.py
@@ -185,8 +185,10 @@ class Vc(_vc.Vc):
     def _update_tree_state_cache(self, path, tree_state):
         while 1:
             try:
-                status_cmd = [self.CMD, "status", "-v", "--xml", path]
-                tree = ElementTree.parse(_vc.popen(status_cmd))
+                proc = _vc.popen(
+                    [self.CMD, "status", "-v", "--xml", path],
+                    cwd=self.location)
+                tree = ElementTree.parse(proc)
                 break
             except OSError as e:
                 if e.errno != errno.EAGAIN:
@@ -214,10 +216,9 @@ class Vc(_vc.Vc):
                         tree_state[mydir] = {}
                     tree_state[mydir][name] = (item, rev)
 
-    def cache_tree(self, rootdir):
-        # Get a list of all files in rootdir, as well as their status
+    def cache_tree(self):
         tree_state = {}
-        self._update_tree_state_cache(rootdir, tree_state)
+        self._update_tree_state_cache('./', tree_state)
         return tree_state
 
     def update_file_state(self, path):


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