about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/fsobject/directory.py31
-rw-r--r--ranger/fsobject/fsobject.py39
2 files changed, 42 insertions, 28 deletions
diff --git a/ranger/fsobject/directory.py b/ranger/fsobject/directory.py
index 9bd728c1..546fc6d0 100644
--- a/ranger/fsobject/directory.py
+++ b/ranger/fsobject/directory.py
@@ -16,7 +16,6 @@ from ranger.core.shared import SettingsAware
 from ranger.ext.accumulator import Accumulator
 from ranger.ext.lazy_property import lazy_property
 from ranger.ext.human_readable import human_readable
-from ranger.ext.vcs import VcsError
 from ranger.container.settingobject import LocalSettingObject
 
 def sort_by_basename(path):
@@ -71,7 +70,7 @@ class Directory(FileSystemObject, Accumulator, Loadable, SettingsAware):
     content_outdated = False
     content_loaded = False
 
-    has_vcschild=False
+    has_vcschild = False
 
     _cumulative_size_calculated = False
 
@@ -259,32 +258,8 @@ class Directory(FileSystemObject, Accumulator, Loadable, SettingsAware):
                     # Load vcs data
                     if self.settings.vcs_aware:
                         item.load_vcs()
-                        if item.vcs:
-                            if item.vcs.vcsname == 'git':   backend_state = self.settings.vcs_backend_git
-                            elif item.vcs.vcsname == 'hg':  backend_state = self.settings.vcs_backend_hg
-                            elif item.vcs.vcsname == 'bzr': backend_state = self.settings.vcs_backend_bzr
-                            else:                           backend_state = 'disabled'
-
-                            if backend_state in set(['enabled', 'local']):
-                                self.has_vcschild = True
-                                try:
-                                    if self.vcs_outdated or item.vcs_outdated:
-                                        item.vcs_outdated = False
-                                        item.vcs.get_status()  # caches the file status for get_file_status()
-                                        item.vcsbranch = item.vcs.get_branch()
-                                        item.vcshead = item.vcs.get_info(item.vcs.HEAD)
-                                        if item.path == item.vcs.root and backend_state == 'enabled':
-                                            item.vcsremotestatus = item.vcs.get_remote_status()
-                                    else:
-                                        item.vcsbranch = self.vcsbranch
-                                        item.vcshead = self.vcshead
-                                    item.vcsfilestatus = item.vcs.get_file_status(item.path)
-                                except VcsError as err:
-                                    item.vcsbranch = None
-                                    item.vcshead = None
-                                    item.vcsremotestatus = 'unknown'
-                                    item.vcsfilestatus = 'unknown'
-                                    self.fm.notify("Can not load vcs data on %s: %s" % (item.path, err), bad=True)
+                        if item.vcs_enabled:
+                            self.has_vcschild = True
 
                     files.append(item)
                     self.percent = 100 * len(files) // len(filenames)
diff --git a/ranger/fsobject/fsobject.py b/ranger/fsobject/fsobject.py
index 506f13d9..737e3f5c 100644
--- a/ranger/fsobject/fsobject.py
+++ b/ranger/fsobject/fsobject.py
@@ -75,6 +75,7 @@ class FileSystemObject(FileManagerAware):
      vcshead) = (None,) * 5
 
     vcs_outdated = False
+    vcs_enabled = False
 
     def __init__(self, path, preload=None, path_is_abs=False):
         if not path_is_abs:
@@ -198,6 +199,7 @@ class FileSystemObject(FileManagerAware):
         Reads data regarding the version control system the object is on.
         Does not load content specific data.
         """
+        from ranger.ext.vcs import VcsError
 
         vcs = Vcs(self.path)
 
@@ -225,6 +227,43 @@ class FileSystemObject(FileManagerAware):
             if rootdir.vcs_outdated:
                 self.vcs_outdated = True
 
+        if self.vcs:
+            if self.vcs.vcsname == 'git':
+                backend_state = self.settings.vcs_backend_git
+            elif self.vcs.vcsname == 'hg':
+                backend_state = self.settings.vcs_backend_hg
+            elif item.vcs.vcsname == 'bzr':
+                backend_state = self.settings.vcs_backend_bzr
+            else:
+                backend_state = 'disabled'
+
+            self.vcs_enabled = backend_state in set(['enabled', 'local'])
+            if self.vcs_enabled:
+                try:
+                    if self.vcs_outdated or self.vcs_outdated:
+                        self.vcs_outdated = False
+                        # this caches the file status for get_file_status():
+                        self.vcs.get_status()
+                        self.vcsbranch = self.vcs.get_branch()
+                        self.vcshead = self.vcs.get_info(self.vcs.HEAD)
+                        if self.path == self.vcs.root and \
+                                backend_state == 'enabled':
+                            self.vcsremotestatus = \
+                                    self.vcs.get_remote_status()
+                    else:
+                        self.vcsbranch = self.vcsbranch
+                        self.vcshead = self.vcshead
+                    self.vcsfilestatus = self.vcs.get_file_status(self.path)
+                except VcsError as err:
+                    self.vcsbranch = None
+                    self.vcshead = None
+                    self.vcsremotestatus = 'unknown'
+                    self.vcsfilestatus = 'unknown'
+                    self.fm.notify("Can not load vcs data on %s: %s" %
+                            (self.path, err), bad=True)
+        else:
+            self.vcs_enabled = False
+
     def load(self):
         """Loads information about the directory itself.