[meld/VersionControlRework: 29/123] vc: Add common _get_dirsandfiles implementation for generalisation



commit 961deacbc93f9fecd45b6272b4a69ef2f19ae478
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Mar 22 09:05:09 2015 +1000

    vc: Add common _get_dirsandfiles implementation for generalisation

 meld/vc/_vc.py       |   20 +++++++++++++++++++-
 meld/vc/git.py       |   21 ---------------------
 meld/vc/mercurial.py |   20 --------------------
 3 files changed, 19 insertions(+), 42 deletions(-)
---
diff --git a/meld/vc/_vc.py b/meld/vc/_vc.py
index 83758b2..8c8a7c3 100644
--- a/meld/vc/_vc.py
+++ b/meld/vc/_vc.py
@@ -228,7 +228,25 @@ class Vc(object):
         return self._get_dirsandfiles(directory, dirs, files)
 
     def _get_dirsandfiles(self, directory, dirs, files):
-        raise NotImplementedError()
+
+        tree = self._get_tree_cache()
+
+        retfiles = []
+        retdirs = []
+        for name, path in files:
+            state = tree.get(path, STATE_NORMAL)
+            meta = self._tree_meta_cache.get(path, "")
+            retfiles.append(File(path, name, state, options=meta))
+        for name, path in dirs:
+            state = tree.get(path, STATE_NORMAL)
+            retdirs.append(Dir(path, name, state))
+        for path, state in tree.items():
+            # removed files are not in the filesystem, so must be added here
+            if state in (STATE_REMOVED, STATE_MISSING):
+                folder, name = os.path.split(path)
+                if folder == directory:
+                    retfiles.append(File(path, name, state))
+        return retdirs, retfiles
 
     def get_entry(self, path):
         """Return the entry associated with the given path in this VC
diff --git a/meld/vc/git.py b/meld/vc/git.py
index d01aa0e..353758f 100644
--- a/meld/vc/git.py
+++ b/meld/vc/git.py
@@ -361,24 +361,3 @@ class Vc(_vc.Vc):
 
             for path in unversioned_entries:
                 self._tree_cache[get_real_path(path)] = _vc.STATE_NONE
-
-    def _get_dirsandfiles(self, directory, dirs, files):
-
-        tree = self._get_tree_cache()
-
-        retfiles = []
-        retdirs = []
-        for name, path in files:
-            state = tree.get(path, _vc.STATE_NORMAL)
-            meta = self._tree_meta_cache.get(path, "")
-            retfiles.append(_vc.File(path, name, state, options=meta))
-        for name, path in dirs:
-            state = tree.get(path, _vc.STATE_NORMAL)
-            retdirs.append(_vc.Dir(path, name, state))
-        for path, state in tree.items():
-            # removed files are not in the filesystem, so must be added here
-            if state in (_vc.STATE_REMOVED, _vc.STATE_MISSING):
-                folder, name = os.path.split(path)
-                if folder == directory:
-                    retfiles.append(_vc.File(path, name, state))
-        return retdirs, retfiles
diff --git a/meld/vc/mercurial.py b/meld/vc/mercurial.py
index 8bb765b..26c66cb 100644
--- a/meld/vc/mercurial.py
+++ b/meld/vc/mercurial.py
@@ -121,23 +121,3 @@ class Vc(_vc.Vc):
                 path = os.path.join(self.location, name.strip())
                 state = self.state_map.get(statekey.strip(), _vc.STATE_NONE)
                 self._tree_cache[path] = state
-
-    def _get_dirsandfiles(self, directory, dirs, files):
-
-        tree = self._get_tree_cache()
-
-        retfiles = []
-        retdirs = []
-        for name, path in files:
-            state = tree.get(path, _vc.STATE_NORMAL)
-            retfiles.append(_vc.File(path, name, state))
-        for name, path in dirs:
-            # mercurial does not operate on dirs, just files
-            retdirs.append(_vc.Dir(path, name, _vc.STATE_NORMAL))
-        for path, state in tree.items():
-            # removed files are not in the filesystem, so must be added here
-            if state in (_vc.STATE_REMOVED, _vc.STATE_MISSING):
-                folder, name = os.path.split(path)
-                if folder == directory:
-                    retfiles.append(_vc.File(path, name, state))
-        return retdirs, retfiles


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