index
:
ranger
this commit
master
mirror of ranger - a simple, vim-like file manager
akspecs <akspecs@tilde.institute>
summary
refs
log
tree
commit
diff
stats
log msg
author
committer
range
path:
root
/
ranger
diff options
context:
1
2
3
4
5
6
7
8
9
10
15
20
25
30
35
40
space:
include
ignore
mode:
unified
ssdiff
stat only
author
hut <hut@lepus.uberspace.de>
2016-08-26 23:51:49 +0200
committer
hut <hut@lepus.uberspace.de>
2016-08-26 23:51:49 +0200
commit
fe95e13de7e306e77e63a5819170fe814a9af5bc
(
patch
)
tree
e4d91797ee39d62e9b1416296d1aaa232dd76d76
/
ranger
parent
a053b45a2d50a60b06a4cabe6c39992559883f3b
(
diff
)
parent
- line = json.loads(line)
- line['date'] = datetime.fromtimestamp(line['date'])
- log.append(line)
+ for line in output[:-2].split('\0\0\n'):
+ commit_hash_abbrev, commit_hash, author, timestamp, subject = line.split('\0')
+ log.append({
+ 'short': commit_hash_abbrev,
+ 'revid': commit_hash,
+ 'author': string_control_replace(author, ' '),
+ 'date': datetime.fromtimestamp(int(timestamp)),
+ 'summary': string_control_replace(subject, ' '),
+ })
return log
def _status_translate(self, code):
@@ -100,10 +101,10 @@ class Git(Vcs):
# Paths with status
skip = False
- output = self._run(['status', '--porcelain', '-z']).rstrip('\x00')
- if not output:
+ lines = self._run(['status', '--porcelain', '-z']).split('\0')[:-1]
+ if not lines:
return 'sync'
- for line in output.split('\x00'):
+ for line in lines:
if skip:
skip = False
continue
@@ -114,39 +115,37 @@ class Git(Vcs):
for status in self.DIRSTATUSES:
if status in statuses:
return status
+
return 'sync'
def data_status_subpaths(self):
statuses = {}
# Ignored directories
- output = self._run([
+ paths = self._run([
'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'
+ ]).split('\0')[:-1]
+ for path in paths:
+ if path.endswith('/'):
+ statuses[os.path.normpath(path)] = 'ignored'
# Empty directories
- output = self._run(
- ['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 = self._run(
+ ['ls-files', '-z', '--others', '--directory', '--exclude-standard']).split('\0')[:-1]
+ for path in paths:
+ if path.endswith('/'):
+ statuses[os.path.normpath(path)] = 'none'
# Paths with status
- output = self._run(['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
+ lines = self._run(['status', '--porcelain', '-z', '--ignored']).split('\0')[:-1]
+ skip = False
+ for line in lines:
+ 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 cf15e35e..21460975 100644 --- a/
ranger/ext/vcs/hg.py
+++ b/
ranger/ext/vcs/hg.py
@@ -36,7 +36,7 @@ class Hg(Vcs):
args += ['--'] + filelist
try:
- output = self._run(args).rstrip('\n')
+ output = self._run(args)
except VcsError:
return None
if not output:
@@ -56,13 +56,13 @@ class Hg(Vcs):
def _remote_url(self):
"""Remote url"""
try:
- return self._run(['showconfig', 'paths.default']).rstrip('\n') or None
+ return self._run(['showconfig', 'paths.default']) or None
except VcsError:
return None
def _status_translate(self, code):
"""Translate status code"""
- for code_x, status in self._status_translations: # pylint: disable=invalid-name
+ for code_x, status in self._status_translations:
if code in code_x:
return status
return 'unknown'
@@ -80,7 +80,7 @@ class Hg(Vcs):
if filelist:
args += filelist
else:
- args += self.rootvcs.status_subpaths.keys()
+ args += self.rootvcs.status_subpaths.keys() # pylint: disable=no-member
self._run(args, catchout=False)
# Data interface
@@ -117,7 +117,7 @@ class Hg(Vcs):
return 'unknown'
def data_branch(self):
- return self._run(['branch']).rstrip('\n') or None
+ return self._run(['branch']) or None
def data_info(self, rev=None):
if rev is None:
diff --git a/ranger/ext/vcs/svn.py b/ranger/ext/vcs/svn.py index 1813f857..1f09cd52 100644 --- a/
ranger/ext/vcs/svn.py
+++ b/
ranger/ext/vcs/svn.py
@@ -36,7 +36,7 @@ class SVN(Vcs):
args += ['--'] + filelist
try:
- output = self._run(args).rstrip('\n')
+ output = self._run(args)
except VcsError:
return None
if not output:
@@ -66,7 +66,7 @@ class SVN(Vcs):
def _remote_url(self):
"""Remote url"""
try:
- output = self._run(['info', '--xml']).rstrip('\n')
+ output = self._run(['info', '--xml'])
except VcsError:
return None
if not output:
@@ -86,7 +86,7 @@ class SVN(Vcs):
if filelist:
args += filelist
else:
- args += self.rootvcs.status_subpaths.keys()
+ args += self.rootvcs.status_subpaths.keys() # pylint: disable=no-member
self._run(args, catchout=False)
# Data Interface
@@ -95,10 +95,10 @@ class SVN(Vcs):
statuses = set()
# Paths with status
- output = self._run(['status']).rstrip('\n')
- if not output:
+ lines = self._run(['status']).split('\n')
+ if not lines:
return 'sync'
- for line in output.split('\n'):
+ for line in lines:
code = line[0]
if code == ' ':
continue
@@ -113,13 +113,12 @@ class SVN(Vcs):
statuses = {}
# Paths with status
- output = self._run(['status']).rstrip('\n')
- if output:
- for line in output.split('\n'):
- code, path = line[0], line[8:]
- if code == ' ':
- continue
- statuses[os.path.normpath(path)] = self._status_translate(code)
+ lines = self._run(['status']).split('\n')
+ for line in lines:
+ code, path = line[0], line[8:]
+ if code == ' ':
+ continue
+ statuses[os.path.normpath(path)] = self._status_translate(code)
return statuses
diff --git a/ranger/ext/vcs/vcs.py b/ranger/ext/vcs/vcs.py index 487c9405..9c7be653 100644 --- a/
ranger/ext/vcs/vcs.py
+++ b/
ranger/ext/vcs/vcs.py
@@ -109,7 +109,8 @@ class Vcs(object): # pylint: disable=too-many-instance-attributes
# Generic
- def _run(self, args, path=None, catchout=True, retbytes=False):
+ def _run(self, args, path=None, # pylint: disable=too-many-arguments
+ catchout=True, retbytes=False, rstrip_newline=True):
"""Run a command"""
cmd = [self.repotype] + args
if path is None:
@@ -119,7 +120,13 @@ class Vcs(object): # pylint: disable=too-many-instance-attributes
try:
if catchout:
output = subprocess.check_output(cmd, cwd=path, stderr=devnull)
- return output if retbytes else output.decode('UTF-8')
+ if retbytes:
+ return output
+ else:
+ output = output.decode('UTF-8')
+ if rstrip_newline and output.endswith('\n'):
+ return output[:-1]
+ return output
else:
subprocess.check_call(cmd, cwd=path, stdout=devnull, stderr=devnull)
except (subprocess.CalledProcessError, FileNotFoundError):