summary refs log tree commit diff stats
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
parent7485cd37f6f9f7addd482c33a50a224ded46d443 (diff)
downloadranger-79cad207f3843576655b2e07e573937fd611e358.tar.gz
VCS: Implement directory statuses properly, Change function names
-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
 
f='#n139'>139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380