summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/container/directory.py9
-rw-r--r--ranger/ext/vcs/git.py4
-rw-r--r--ranger/ext/vcs/vcs.py85
-rw-r--r--ranger/gui/widgets/browsercolumn.py11
-rw-r--r--ranger/gui/widgets/statusbar.py21
5 files changed, 63 insertions, 67 deletions
diff --git a/ranger/container/directory.py b/ranger/container/directory.py
index 2c3c9f02..95dbd730 100644
--- a/ranger/container/directory.py
+++ b/ranger/container/directory.py
@@ -306,8 +306,10 @@ class Directory(FileSystemObject, Accumulator, Loadable):
                 files = []
                 disk_usage = 0
 
-                if self.vcs and self.vcs.track:
-                    self.vcs.update(self)
+                if self.vcs:
+                    self.vcs.check()
+                    if self.vcs.track:
+                        self.vcs.update()
 
                 for name in filenames:
                     try:
@@ -334,9 +336,10 @@ class Directory(FileSystemObject, Accumulator, Loadable):
                                 item = Directory(name, preload=stats, path_is_abs=True)
                                 item.load()
                         if item.vcs and item.vcs.track:
-                            item.vcs.update(item, child=True)
                             if item.vcs.is_root:
                                 self.has_vcschild = True
+                            else:
+                                item.vcspathstatus = self.vcs.get_status_subpath(item.path)
                     else:
                         item = File(name, preload=stats, path_is_abs=True,
                                     basename_is_rel_to=basename_is_rel_to)
diff --git a/ranger/ext/vcs/git.py b/ranger/ext/vcs/git.py
index ee0eb698..0a091064 100644
--- a/ranger/ext/vcs/git.py
+++ b/ranger/ext/vcs/git.py
@@ -155,8 +155,8 @@ class Git(Vcs):
     # Data Interface
     #---------------------------
 
-    def get_status_root_child(self):
-        """Returns the status of a child root, very cheap"""
+    def get_status_root_cheap(self):
+        """Returns the status of root, very cheap"""
         statuses = set()
         # Paths with status
         skip = False
diff --git a/ranger/ext/vcs/vcs.py b/ranger/ext/vcs/vcs.py
index 0ff3fe03..1bd101ed 100644
--- a/ranger/ext/vcs/vcs.py
+++ b/ranger/ext/vcs/vcs.py
@@ -69,33 +69,37 @@ class Vcs(object):
     # )
 
     def __init__(self, directoryobject):
+        self.obj = directoryobject
         self.path = directoryobject.path
         self.repotypes_settings = set(
             repotype for repotype, values in self.REPOTYPES.items()
             if getattr(directoryobject.settings, values['setting']) in ('enabled', 'local')
         )
-
-        self.status_subpaths = {}
-        self.head = None
-        self.remotestatus = None
-        self.branch = None
-
         self.root, self.repodir, self.repotype = self.find_root(self.path)
         self.is_root = True if self.path == self.root else False
 
         if self.root:
-            self.track = True
-            self.__class__ = getattr(getattr(ranger.ext.vcs, self.repotype),
-                                     self.REPOTYPES[self.repotype]['class'])
-
-            if not os.access(self.repodir, os.R_OK):
-                self.track = False
-                if self.is_root:
+            if self.is_root:
+                self.__class__ = getattr(getattr(ranger.ext.vcs, self.repotype),
+                                         self.REPOTYPES[self.repotype]['class'])
+                self.status_subpaths = {}
+                self.track = True
+                self.initiated = False
+                self.head = self.get_info(self.HEAD)
+                self.branch = self.get_branch()
+                self.remotestatus = self.get_status_remote()
+                self.obj.vcspathstatus = self.get_status_root_cheap()
+
+                if not os.access(self.repodir, os.R_OK):
+                    self.track = False
                     directoryobject.vcspathstatus = 'unknown'
                     self.remotestatus = 'unknown'
-            # Do not track self.repodir or its subpaths
-            if self.path == self.repodir or self.path.startswith(self.repodir + '/'):
-                self.track = False
+            else:
+                # Do not track self.repodir or its subpaths
+                if self.path == self.repodir or self.path.startswith(self.repodir + '/'):
+                    self.track = False
+                else:
+                    self.track = directoryobject.fm.get_directory(self.root).vcs.track
         else:
             self.track = False
 
@@ -138,31 +142,23 @@ class Vcs(object):
             path = os.path.dirname(path)
         return (None, None, None)
'del'>- if not self.root: - directoryobject.vcspathstatus = None - return - - root = self if self.is_root else directoryobject.fm.get_directory(self.root).vcs - if child and self.is_root: - directoryobject.vcspathstatus = self.get_status_root_child() - elif not child: - root.head = root.get_info(root.HEAD) - root.branch = root.get_branch() - root.status_subpaths = root.get_status_subpaths() - if self.is_root: - directoryobject.vcspathstatus = self.get_status_root() + def check(self): + """Check repository health""" + if (self.track and not os.path.exists(self.repodir)) \ + or not self.track: + self.__init__(self.obj) - if self.is_root: - root.remotestatus = root.get_status_remote() - else: - self.head = root.head - self.branch = root.branch - self.status_subpaths = root.status_subpaths - directoryobject.vcspathstatus = root.get_status_subpath( + def update(self): + """Update repository""" + root = self.obj.fm.get_directory(self.root).vcs + root.head = root.get_info(self.HEAD) + root.branch = root.get_branch() + root.status_subpaths = root.get_status_subpaths() + root.remotestatus = root.get_status_remote() + root.obj.vcspathstatus = root.get_status_root() + + if not self.is_root: + self.obj.vcspathstatus = root.get_status_subpath( self.path, is_directory=True) # Repo creation @@ -238,7 +234,7 @@ class Vcs(object): """Checks whether HEAD is tracking a remote repo""" return self.get_remote(self.HEAD) is not None - def get_status_root_child(self): + def get_status_root_cheap(self): """Returns the status of a child root, very cheap""" raise NotImplementedError @@ -252,18 +248,19 @@ class Vcs(object): def get_status_subpath(self, path, is_directory=False): """Returns the status of path""" + root = self.obj.fm.get_directory(self.root).vcs relpath = os.path.relpath(path, self.root) # check if relpath or its parents has a status tmppath = relpath while tmppath: - if tmppath in self.status_subpaths: - return self.status_subpaths[tmppath] + if tmppath in root.status_subpaths: + return root.status_subpaths[tmppath] tmppath = os.path.dirname(tmppath) # check if path contains some file in status if is_directory: - statuses = set(status for subpath, status in self.status_subpaths.items() + statuses = set(status for subpath, status in root.status_subpaths.items() if subpath.startswith(relpath + '/')) for status in self.DIR_STATUS: if status in statuses: diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py index dc2c193e..40f804ba 100644 --- a/ranger/gui/widgets/browsercolumn.py +++ b/ranger/gui/widgets/browsercolumn.py @@ -375,20 +375,17 @@ class BrowserColumn(Pager): def _draw_vcsstring_display(self, drawn): vcsstring_display = [] directory = drawn if drawn.is_directory else self.target - if directory.vcs and \ - (directory.vcs.track or (drawn.is_directory and drawn.vcs.is_root)): - if drawn.is_directory and drawn.vcs.remotestatus: + if directory.vcs and directory.vcs.track: + if drawn.is_directory and drawn.vcs.is_root: vcsstr, vcscol = self.vcsremotestatus_symb[drawn.vcs.remotestatus] vcsstring_display.append([vcsstr, ['vcsremote'] + vcscol]) - else: - if self.target.has_vcschild: - vcsstring_display.insert(-1, [" ", []]) + elif self.target.has_vcschild: + vcsstring_display.insert(-1, [" ", []]) if drawn.vcspathstatus: vcsstr, vcscol = self.vcspathstatus_symb[drawn.vcspathstatus] vcsstring_display.append([vcsstr, ['vcsfile'] + vcscol]) else: vcsstring_display.append([" ", []]) - elif self.target.has_vcschild: vcsstring_display.append([" ", []]) diff --git a/ranger/gui/widgets/statusbar.py b/ranger/gui/widgets/statusbar.py index 20875ac9..b5e3b178 100644 --- a/ranger/gui/widgets/statusbar.py +++ b/ranger/gui/widgets/statusbar.py @@ -183,26 +183,25 @@ class StatusBar(Widget): directory = target if target.is_directory else \ target.fm.get_directory(os.path.dirname(target.path)) - if directory.vcs and directory.vcs.track: - if directory.vcs.branch: - vcsinfo = '(%s: %s)' % (directory.vcs.repotype, directory.vcs.branch) + vcsroot = directory.fm.get_directory(directory.vcs.root).vcs + if vcsroot.branch: + vcsinfo = '({0:s}: {1:s})'.format(vcsroot.repotype, vcsroot.branch) else: - vcsinfo = '(%s)' % (directory.vcs.repotype) - + vcsinfo = '({0:s})'.format(vcsroot.repotype) left.add_space() left.add(vcsinfo, 'vcsinfo') + left.add_space() + if vcsroot.remotestatus: + vcsstr, vcscol = self.vcsremotestatus_symb[vcsroot.remotestatus] + left.add(vcsstr.strip(), 'vcsremote', *vcscol) if target.vcspathstatus: - left.add_space() vcsstr, vcscol = self.vcspathstatus_symb[target.vcspathstatus] left.add(vcsstr.strip(), 'vcsfile', *vcscol) - if target.is_directory and target.vcs.is_root and directory.vcs.remotestatus: - vcsstr, vcscol = self.vcsremotestatus_symb[directory.vcs.remotestatus] - left.add(vcsstr.strip(), 'vcsremote', *vcscol) - if directory.vcs.head: + if vcsroot.head: left.add_space() - left.add('%s' % directory.vcs.head['summary'], 'vcscommit') + left.add('{0:s}'.format(vcsroot.head['summary']), 'vcscommit') def _get_owner(self, target): uid = target.stat.st_uid