[meld] Fix VC listing when we have an empty directory



commit 6dbbff5cd7f90ad8d2a4b33a7efa75adfeb10eb1
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Fri Dec 7 06:23:28 2012 +1000

    Fix VC listing when we have an empty directory
    
    Previously, if we had no files or folders in a directory, we skipped
    a lookup step and simply returned nothing. This breaks when we have
    nothing but MISSING or REMOVED files in the directory, which should be
    shown but are instead simply skipped. This commit changes our scanning
    to always run a lookup even for empty directories.

 meld/vc/_vc.py |   33 +++++++++++++--------------------
 1 files changed, 13 insertions(+), 20 deletions(-)
---
diff --git a/meld/vc/_vc.py b/meld/vc/_vc.py
index 322bf34..ef556b0 100644
--- a/meld/vc/_vc.py
+++ b/meld/vc/_vc.py
@@ -171,7 +171,7 @@ class Vc(object):
         return True
 
     def listdir(self, start):
-        if start=="": start="."
+        start = start or "."
         cfiles = []
         cdirs = []
         try:
@@ -183,27 +183,20 @@ class Vc(object):
             fname = os.path.join(start, f)
             lname = fname
             if os.path.isdir(fname):
-                cdirs.append( (f, lname) )
+                cdirs.append((f, lname))
             else:
-                cfiles.append( (f, lname) )
-        dirs, files = self.lookup_files(cdirs, cfiles)
-        return dirs+files
-
-    def lookup_files(self, dirs, files):
-        "Assume all files are in the same dir, files is an array of (name, path) tuples."
-        directory = self._get_directoryname(files, dirs)
-        if directory is None:
-            return [], []
-        else:
-            return self._get_dirsandfiles(directory, dirs, files)
-
-    def _get_directoryname(self, dirs, files):
-        directory = None
-        if len(files):
-            directory = os.path.dirname(files[0][1])
-        elif len(dirs):
+                cfiles.append((f, lname))
+        dirs, files = self.lookup_files(cdirs, cfiles, start)
+        return dirs + files
+
+    def lookup_files(self, dirs, files, directory=None):
+        # Assumes that all files are in the same directory. files is an array
+        # of (name, path) tuples.
+        if len(dirs):
             directory = os.path.dirname(dirs[0][1])
-        return directory
+        elif len(files):
+            directory = os.path.dirname(files[0][1])
+        return self._get_dirsandfiles(directory, dirs, files)
 
     def _get_dirsandfiles(self, directory, dirs, files):
         raise NotImplementedError()



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