summary refs log tree commit diff stats
diff options
context:
space:
mode:
authornfnty <git@nfnty.se>2016-02-08 01:47:56 +0100
committernfnty <git@nfnty.se>2016-02-08 04:43:05 +0100
commit9c80132600b764ff913c18c1bae9171343680c82 (patch)
treece410a9fd5775f44265b08a273d8a346f157d6ab
parent8a43e6ca153768555cf75079f36137df2be1a6c1 (diff)
downloadranger-9c80132600b764ff913c18c1bae9171343680c82.tar.gz
VCS: Fix output handling
-rw-r--r--ranger/ext/vcs/bzr.py14
-rw-r--r--ranger/ext/vcs/git.py54
-rw-r--r--ranger/ext/vcs/hg.py25
3 files changed, 58 insertions, 35 deletions
diff --git a/ranger/ext/vcs/bzr.py b/ranger/ext/vcs/bzr.py
index f39ac00f..3461c3d2 100644
--- a/ranger/ext/vcs/bzr.py
+++ b/ranger/ext/vcs/bzr.py
@@ -91,7 +91,10 @@ class Bzr(Vcs):
         statuses = set()
 
         # Paths with status
-        for line in self._bzr(['status', '--short', '--no-classify']).splitlines():
+        output = self._bzr(['status', '--short', '--no-classify']).rstrip('\n')
+        if not output:
+            return 'sync'
+        for line in output.split('\n'):
             statuses.add(self._bzr_status_translate(line[:2]))
 
         for status in self.DIRSTATUSES:
@@ -103,11 +106,14 @@ class Bzr(Vcs):
         statuses = {}
 
         # Ignored
-        for path in self._bzr(['ls', '--null', '--ignored']).rstrip('\x00').split('\x00'):
-            statuses[path] = 'ignored'
+        output = self._bzr(['ls', '--null', '--ignored']).rstrip('\x00')
+        if output:
+            for path in output.split('\x00'):
+                statuses[path] = 'ignored'
 
         # Paths with status
-        for line in self._bzr(['status', '--short', '--no-classify']).splitlines():
+        output = self._bzr(['status', '--short', '--no-classify']).rstrip('\n')
+        for line in output.split('\n'):
             statuses[os.path.normpath(line[4:])] = self._bzr_status_translate(line[:2])
 
         return statuses
diff --git a/ranger/ext/vcs/git.py b/ranger/ext/vcs/git.py
index e50ed3de..32003d5b 100644
--- a/ranger/ext/vcs/git.py
+++ b/ranger/ext/vcs/git.py
@@ -62,13 +62,15 @@ class Git(Vcs):
             args += ['--'] + filelist
 
         try:
-            output = self._git(args)\
-                .replace('\\', '\\\\').replace('"', '\\"').replace('\x00', '"').splitlines()
+            output = self._git(args).rstrip('\n')
         except VcsError:
             return None
+        if not output:
+            return None
 
         log = []
-        for line in output:
+        for line in output\
+                .replace('\\', '\\\\').replace('"', '\\"').replace('\x00', '"').split('\n'):
             line = json.loads(line)
             line['date'] = datetime.fromtimestamp(line['date'])
             log.append(line)
@@ -102,7 +104,10 @@ class Git(Vcs):
 
         # Paths with status
         skip = False
-        for line in self._git(['status', '--porcelain', '-z']).rstrip('\x00').split('\x00'):
+        output = self._git(['status', '--porcelain', '-z']).rstrip('\x00')
+        if not output:
+            return 'sync'
+        for line in output.split('\x00'):
             if skip:
                 skip = False
                 continue
@@ -119,28 +124,33 @@ class Git(Vcs):
         statuses = {}
 
         # Ignored directories
-        for path in self._git(
-                ['ls-files', '-z', '--others', '--directory', '--ignored', '--exclude-standard'])\
-                .rstrip('\x00').split('\x00'):
-            if path.endswith('/'):
-                statuses[os.path.normpath(path)] = 'ignored'
+        output = self._git([
+            'ls-files', '-z', '--others', '--directory', '--ignored', '--exclude-standard'
+        ]).rstrip('\x00')
+        if output:
+            for path in output.split('\x00'):
+                if path.endswith('/'):
+                    statuses[os.path.normpath(path)] = 'ignored'
 
         # Empty directories
-        for path in self._git(['ls-files', '-z', '--others', '--directory', '--exclude-standard'])\
-                .rstrip('\x00').split('\x00'):
-            if path.endswith('/'):
-                statuses[os.path.normpath(path)] = 'none'
+        output = self._git(
+            ['ls-files', '-z', '--others', '--directory', '--exclude-standard']).rstrip('\x00')
+        if output:
+            for path in output.split('\x00'):
+                if path.endswith('/'):
+                    statuses[os.path.normpath(path)] = 'none'
 
         # Paths with status
-        skip = False
-        for line in self._git(['status', '--porcelain', '-z', '--ignored'])\
-                .rstrip('\x00').split('\x00'):
-            if skip:
-                skip = False
-                continue
-            statuses[os.path.normpath(line[3:])] = self._status_translate(line[:2])
-            if line.startswith('R'):
-                skip = True
+        output = self._git(['status', '--porcelain', '-z', '--ignored']).rstrip('\x00')
+        if output:
+            skip = False
+            for line in output.split('\x00'):
+                if skip:
+                    skip = False
+                    continue
+                statuses[os.path.normpath(line[3:])] = self._status_translate(line[:2])
+                if line.startswith('R'):
+                    skip = True
 
         return statuses
 
diff --git a/ranger/ext/vcs/hg.py b/ranger/ext/vcs/hg.py
index 92ca583a..7c5507eb 100644
--- a/ranger/ext/vcs/hg.py
+++ b/ranger/ext/vcs/hg.py
@@ -49,13 +49,15 @@ class Hg(Vcs):
             args += ['--'] + filelist
 
         try:
-            output = self._hg(args)\
-                .replace('\\', '\\\\').replace('"', '\\"').replace('\x00', '"').splitlines()
+            output = self._hg(args).rstrip('\n')
         except VcsError:
             return None
+        if not output:
+            return None
 
         log = []
-        for line in output:
+        for line in output\
+                .replace('\\', '\\\\').replace('"', '\\"').replace('\x00', '"').split('\n'):
             line = json.loads(line)
             line['date'] = datetime.fromtimestamp(float(line['date'].split('-')[0]))
             log.append(line)
@@ -97,7 +99,10 @@ class Hg(Vcs):
         statuses = set()
 
         # Paths with status
-        for line in self._hg(['status', '--all', '--print0']).rstrip('\x00').split('\x00'):
+        output = self._hg(['status', '--all', '--print0']).rstrip('\x00')
+        if not output:
+            return 'sync'
+        for line in output.split('\x00'):
             code = line[0]
             if code == 'C':
                 continue
@@ -112,11 +117,13 @@ class Hg(Vcs):
         statuses = {}
 
         # Paths with status
-        for line in self._hg(['status', '--all', '--print0']).rstrip('\x00').split('\x00'):
-            code, path = line[0], line[2:]
-            if code == 'C':
-                continue
-            statuses[os.path.normpath(path)] = self._status_translate(code)
+        output = self._hg(['status', '--all', '--print0']).rstrip('\x00')
+        if output:
+            for line in output.split('\x00'):
+                code, path = line[0], line[2:]
+                if code == 'C':
+                    continue
+                statuses[os.path.normpath(path)] = self._status_translate(code)
 
         return statuses