summary refs log tree commit diff stats
path: root/ranger
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 /ranger
parent8a43e6ca153768555cf75079f36137df2be1a6c1 (diff)
downloadranger-9c80132600b764ff913c18c1bae9171343680c82.tar.gz
VCS: Fix output handling
Diffstat (limited to 'ranger')
-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
 
com> 2011-09-24 17:57:00 +0200 committer hut <hut@lavabit.com> 2011-09-24 17:57:00 +0200 Overhauled manpage. It's in POD format now.' href='/akspecs/ranger/commit/Makefile?h=v1.7.0-emacs&id=c7720fff4fc500dab7cfb2d2b3b63e2b966502d2'>c7720fff ^
8d21b83c ^


e9e4b4ff ^
25a4162d ^
e9e4b4ff ^
0c2c782d ^
636d9393 ^
b0a216f5 ^
b3bc8431 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77