changeset 8058:ca9df5a30ab2

vcs: refactor run_git_command to just return stdout as unicode string This will be convenient for py3.
author Mads Kiilerich <mads@kiilerich.com>
date Thu, 26 Dec 2019 22:39:10 +0100
parents 450f34f29f89
children 000aa9cb25f1
files kallithea/controllers/compare.py kallithea/lib/hooks.py kallithea/lib/vcs/backends/git/changeset.py kallithea/lib/vcs/backends/git/repository.py
diffstat 4 files changed, 14 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/compare.py	Wed Dec 25 23:03:28 2019 +0100
+++ b/kallithea/controllers/compare.py	Thu Dec 26 22:39:10 2019 +0100
@@ -150,13 +150,13 @@
                 gitrepo_remote.close()
 
             else:
-                so, se = org_repo.run_git_command(
+                so = org_repo.run_git_command(
                     ['log', '--reverse', '--pretty=format:%H',
                      '-s', '%s..%s' % (org_rev, other_rev)]
                 )
                 other_changesets = [org_repo.get_changeset(cs)
                               for cs in re.findall(r'[0-9a-fA-F]{40}', so)]
-                so, se = org_repo.run_git_command(
+                so = org_repo.run_git_command(
                     ['merge-base', org_rev, other_rev]
                 )
                 ancestors = [re.findall(r'[0-9a-fA-F]{40}', so)[0]]
--- a/kallithea/lib/hooks.py	Wed Dec 25 23:03:28 2019 +0100
+++ b/kallithea/lib/hooks.py	Thu Dec 26 22:39:10 2019 +0100
@@ -368,14 +368,14 @@
 
                 # build exclude list without the ref
                 cmd = ['for-each-ref', '--format=%(refname)', 'refs/heads/*']
-                stdout, stderr = scm_repo.run_git_command(cmd)
+                stdout = scm_repo.run_git_command(cmd)
                 ref = push_ref['ref']
                 heads = [head for head in stdout.splitlines() if head != ref]
                 # now list the git revs while excluding from the list
                 cmd = ['log', push_ref['new_rev'], '--reverse', '--pretty=format:%H']
                 cmd.append('--not')
                 cmd.extend(heads) # empty list is ok
-                stdout, stderr = scm_repo.run_git_command(cmd)
+                stdout = scm_repo.run_git_command(cmd)
                 git_revs += stdout.splitlines()
 
             elif push_ref['new_rev'] == EmptyChangeset().raw_id:
@@ -384,7 +384,7 @@
             else:
                 cmd = ['log', '%(old_rev)s..%(new_rev)s' % push_ref,
                        '--reverse', '--pretty=format:%H']
-                stdout, stderr = scm_repo.run_git_command(cmd)
+                stdout = scm_repo.run_git_command(cmd)
                 git_revs += stdout.splitlines()
 
         elif _type == 'tags':
--- a/kallithea/lib/vcs/backends/git/changeset.py	Wed Dec 25 23:03:28 2019 +0100
+++ b/kallithea/lib/vcs/backends/git/changeset.py	Thu Dec 26 22:39:10 2019 +0100
@@ -194,7 +194,7 @@
         Returns list of children changesets.
         """
         rev_filter = settings.GIT_REV_FILTER
-        so, se = self.repository.run_git_command(
+        so = self.repository.run_git_command(
             ['rev-list', rev_filter, '--children']
         )
         return [
@@ -299,7 +299,7 @@
         else:
             cmd = ['log',
                    '--pretty=format:%H', '-s', cs_id, '--', f_path]
-        so, se = self.repository.run_git_command(cmd)
+        so = self.repository.run_git_command(cmd)
         ids = re.findall(r'[0-9a-fA-F]{40}', so)
         return [self.repository.get_changeset(sha) for sha in ids]
 
@@ -330,7 +330,7 @@
         # -l     ==> outputs long shas (and we need all 40 characters)
         # --root ==> doesn't put '^' character for boundaries
         # -r sha ==> blames for the given revision
-        so, se = self.repository.run_git_command(cmd)
+        so = self.repository.run_git_command(cmd)
 
         for i, blame_line in enumerate(so.split('\n')[:-1]):
             ln_no = i + 1
--- a/kallithea/lib/vcs/backends/git/repository.py	Wed Dec 25 23:03:28 2019 +0100
+++ b/kallithea/lib/vcs/backends/git/repository.py	Thu Dec 26 22:39:10 2019 +0100
@@ -137,13 +137,13 @@
     def run_git_command(self, cmd):
         """
         Runs given ``cmd`` as git command with cwd set to current repo.
-        Returns output bytes in a tuple (stdout, stderr) ... or raise
-        RepositoryError.
+        Returns stdout as unicode str ... or raise RepositoryError.
         """
         cwd = None
         if os.path.isdir(self.path):
             cwd = self.path
-        return self._run_git_command(cmd, cwd=cwd)
+        stdout, _stderr = self._run_git_command(cmd, cwd=cwd)
+        return safe_unicode(stdout)
 
     @classmethod
     def _check_url(cls, url):
@@ -243,7 +243,7 @@
         rev_filter = settings.GIT_REV_FILTER
         cmd = ['rev-list', rev_filter, '--reverse', '--date-order']
         try:
-            so, se = self.run_git_command(cmd)
+            so = self.run_git_command(cmd)
         except RepositoryError:
             # Can be raised for empty repositories
             return []
@@ -538,7 +538,7 @@
         else:
             cmd.append(settings.GIT_REV_FILTER)
 
-        revs = self.run_git_command(cmd)[0].splitlines()
+        revs = self.run_git_command(cmd).splitlines()
         start_pos = 0
         end_pos = len(revs)
         if start:
@@ -674,7 +674,7 @@
         Tries to pull changes from external location.
         """
         url = self._get_url(url)
-        so, se = self.run_git_command(['ls-remote', '-h', url])
+        so = self.run_git_command(['ls-remote', '-h', url])
         cmd = ['fetch', url, '--']
         for line in (x for x in so.splitlines()):
             sha, ref = line.split('\t')