summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authornfnty <git@nfnty.se>2015-10-08 16:52:55 +0200
committernfnty <git@nfnty.se>2016-02-08 04:43:04 +0100
commit79cad207f3843576655b2e07e573937fd611e358 (patch)
tree782750a745898646f51a2c69c1bbdef1a758e271 /ranger
parent7485cd37f6f9f7addd482c33a50a224ded46d443 (diff)
downloadranger-79cad207f3843576655b2e07e573937fd611e358.tar.gz
VCS: Implement directory statuses properly, Change function names
Diffstat (limited to 'ranger')
-rw-r--r--ranger/ext/vcs/bzr.py4
-rw-r--r--ranger/ext/vcs/git.py35
-rw-r--r--ranger/ext/vcs/hg.py6
-rw-r--r--ranger/ext/vcs/svn.py6
-rw-r--r--ranger/ext/vcs/vcs.py10
5 files changed, 40 insertions, 21 deletions
diff --git a/ranger/ext/vcs/bzr.py b/ranger/ext/vcs/bzr.py
index 2a52cf02..b3d631ec 100644
--- a/ranger/ext/vcs/bzr.py
+++ b/ranger/ext/vcs/bzr.py
@@ -148,7 +148,7 @@ class Bzr(Vcs):
     # Data Interface
     #---------------------------
 
-    def get_status_allfiles(self):
+    def get_status_subpaths(self):
         """Returns a dict indexed by files not in sync their status as values.
            Paths are given relative to the root. Strips trailing '/' from dirs."""
         raw = self._bzr(self.path, ['status', '--short', '--no-classify'], catchout=True, bytes=True)
@@ -167,7 +167,7 @@ class Bzr(Vcs):
 
 
     # TODO: slow due to net access
-    def get_remote_status(self):
+    def get_status_remote(self):
         """Checks the status of the repo regarding sync state with remote branch"""
         if self.get_remote() == None:
             return "none"
diff --git a/ranger/ext/vcs/git.py b/ranger/ext/vcs/git.py
index c97cc9e5..54250026 100644
--- a/ranger/ext/vcs/git.py
+++ b/ranger/ext/vcs/git.py
@@ -16,7 +16,7 @@ from .vcs import Vcs, VcsError
 class Git(Vcs):
     """VCS implementation for Git"""
     vcsname = 'git'
-    _status_combinations = (
+    _status_translations = (
         ('MADRC', ' ', 'staged'),
         (' MADRC', 'M', 'changed'),
         (' MARC', 'D', 'deleted'),
@@ -83,9 +83,9 @@ class Git(Vcs):
             log.append(line)
         return log
 
-    def _git_file_status(self, code):
+    def _git_status_translate(self, code):
         """Translate git status code"""
-        for X, Y, status in self._status_combinations:
+        for X, Y, status in self._status_translations:
             if code[0] in X and code[1] in Y:
                 return status
         return 'unknown'
@@ -156,21 +156,40 @@ class Git(Vcs):
     # Data Interface
     #---------------------------
 
-    def get_status_allfiles(self):
-        """Returs a dict (path: status) for paths not in sync. Strips trailing '/' from dirs"""
+    def get_status_subpaths(self):
+        """Returns a dict (path: status) for paths not in sync. Strips trailing '/' from dirs"""
         statuses = {}
+
+        # Ignored directories
+        for line in self._git(
+                ['ls-files', '-z', '--others', '--directory', '--ignored', '--exclude-standard'],
+                catchout=True, bytes=True
+        ).decode('utf-8').split('\x00')[:-1]:
+            if line.endswith('/'):
+                statuses[os.path.normpath(line)] = 'ignored'
+
+        # Empty directories
+        for line in self._git(
+                ['ls-files', '-z', '--others', '--directory', '--exclude-standard'],
+                catchout=True, bytes=True
+        ).decode('utf-8').split('\x00')[:-1]:
+            if line.endswith('/'):
+                statuses[os.path.normpath(line)] = 'none'
+
+        # Paths with status
         skip = False
-        for line in self._git(['status', '--ignored', '--porcelain', '-z'],
+        for line in self._git(['status', '--porcelain', '-z', '--ignored'],
                               catchout=True, bytes=True).decode('utf-8').split('\x00')[:-1]:
             if skip:
                 skip = False
                 continue
-            statuses[os.path.normpath(line[3:])] = self._git_file_status(line[:2])
+            statuses[os.path.normpath(line[3:])] = self._git_status_translate(line[:2])
             if line.startswith('R'):
                 skip = True
+
         return statuses
 
-    def get_remote_status(self):
+    def get_status_remote(self):
         """Checks the status of the repo regarding sync state with remote branch"""
         try:
             head = self._head_ref()
diff --git a/ranger/ext/vcs/hg.py b/ranger/ext/vcs/hg.py
index b8731dbf..de723878 100644
--- a/ranger/ext/vcs/hg.py
+++ b/ranger/ext/vcs/hg.py
@@ -124,7 +124,7 @@ class Hg(Vcs):
 
     def reset(self, filelist=None):
         """Removes files from the index"""
-        if filelist == None: filelist = self.get_status_allfiles().keys()
+        if filelist == None: filelist = self.get_status_subpaths().keys()
         self._hg(self.path, ['forget'] + filelist)
 
 
@@ -154,7 +154,7 @@ class Hg(Vcs):
     # Data Interface
     #---------------------------
 
-    def get_status_allfiles(self):
+    def get_status_subpaths(self):
         """Returns a dict indexed by files not in sync their status as values.
            Paths are given relative to the root. Strips trailing '/' from dirs."""
         raw = self._hg(self.path, ['status'], catchout=True, bytes=True)
@@ -175,7 +175,7 @@ class Hg(Vcs):
         return set(L)
 
 
-    def get_remote_status(self):
+    def get_status_remote(self):
         """Checks the status of the repo regarding sync state with remote branch"""
         if self.get_remote() == None:
             return "none"
diff --git a/ranger/ext/vcs/svn.py b/ranger/ext/vcs/svn.py
index 9bf8698c..579479aa 100644
--- a/ranger/ext/vcs/svn.py
+++ b/ranger/ext/vcs/svn.py
@@ -137,7 +137,7 @@ class SVN(Vcs):
 
     def reset(self, filelist=None):
         """Equivalent to svn revert"""
-        if filelist == None: filelist = self.get_status_allfiles().keys()
+        if filelist == None: filelist = self.get_status_subpaths().keys()
         self._svn(self.path, ['revert'] + filelist)
 
 
@@ -170,7 +170,7 @@ class SVN(Vcs):
     # Data Interface
     #---------------------------
 
-    def get_status_allfiles(self):
+    def get_status_subpaths(self):
         """Returns a dict indexed by files not in sync their status as values.
            Paths are given relative to the root. Strips trailing '/' from dirs."""
         raw = self._svn(self.path, ['status'], catchout=True, bytes=True)
@@ -193,7 +193,7 @@ class SVN(Vcs):
         return set(L)
 
 
-    def get_remote_status(self):
+    def get_status_remote(self):
         """Checks the status of the repo regarding sync state with remote branch.
 
         I'm not sure this make sense for SVN so we're just going to return 'sync'"""
diff --git a/ranger/ext/vcs/vcs.py b/ranger/ext/vcs/vcs.py
index 73ac68cc..7dc171e8 100644
--- a/ranger/ext/vcs/vcs.py
+++ b/ranger/ext/vcs/vcs.py
@@ -49,7 +49,7 @@ class Vcs(object):
         'staged',
         # 'ignored',
         'sync',
-        'none',
+        # 'none',
         'unknown',
     )
     REMOTE_STATUS = (
@@ -147,8 +147,8 @@ class Vcs(object):
         root = self if self.is_root else directoryobject.fm.get_directory(self.root).vcs
         root.head = root.get_info(root.HEAD)
         root.branch = root.get_branch()
-        root.remotestatus = root.get_remote_status()
-        root.status = root.get_status_allfiles()
+        root.remotestatus = root.get_status_remote()
+        root.status = root.get_status_subpaths()
 
         if self.is_root:
             directoryobject.vcspathstatus = self.get_root_status()
@@ -269,12 +269,12 @@ class Vcs(object):
                     return status
         return 'sync'
 
-    def get_status_allfiles(self):
+    def get_status_subpaths(self):
         """Returns a dict indexed by files not in sync their status as values.
            Paths are given relative to the root.  Strips trailing '/' from dirs."""
         raise NotImplementedError
 
-    def get_remote_status(self):
+    def get_status_remote(self):
         """Checks the status of the entire repo"""
         raise NotImplementedError