changeset 7362:a19f1649c8d4

hooks: slight cleanup of handling of scm_repo.run_git_command return values It would still be nice to have better error handling, but this makes it slightly more clear what is going on and what error handling we don't have..
author Mads Kiilerich <mads@kiilerich.com>
date Wed, 08 Aug 2018 02:23:11 +0200
parents 2b07e757a85f
children 6af08d44daa8
files kallithea/lib/hooks.py
diffstat 1 files changed, 12 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/hooks.py	Wed Aug 08 02:23:11 2018 +0200
+++ b/kallithea/lib/hooks.py	Wed Aug 08 02:23:11 2018 +0200
@@ -443,14 +443,17 @@
                         scm_repo._repo.refs.set_symbolic_ref('HEAD',
                                             'refs/heads/%s' % push_ref['name'])
 
+                    # build exclude list without the ref
                     cmd = ['for-each-ref', '--format=%(refname)', 'refs/heads/*']
-                    heads = scm_repo.run_git_command(cmd)[0]
-                    cmd = ['log', push_ref['new_rev'],
-                           '--reverse', '--pretty=format:%H', '--not']
-                    heads = heads.replace(push_ref['ref'], '')
-                    for l in heads.splitlines():
-                        cmd.append(l.strip())
-                    git_revs += scm_repo.run_git_command(cmd)[0].splitlines()
+                    stdout, stderr = scm_repo.run_git_command(cmd)
+                    ref = push_ref['ref']
+                    heads = [head if head != ref else '' for head in stdout.splitlines()]
+                    # 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)
+                    stdout, stderr = scm_repo.run_git_command(cmd)
+                    git_revs += stdout.splitlines()
 
                 elif push_ref['new_rev'] == EmptyChangeset().raw_id:
                     # delete branch case
@@ -458,7 +461,8 @@
                 else:
                     cmd = ['log', '%(old_rev)s..%(new_rev)s' % push_ref,
                            '--reverse', '--pretty=format:%H']
-                    git_revs += scm_repo.run_git_command(cmd)[0].splitlines()
+                    stdout, stderr = scm_repo.run_git_command(cmd)
+                    git_revs += stdout.splitlines()
 
             elif _type == 'tags':
                 git_revs += ['tag=>%s' % push_ref['name']]