##// END OF EJS Templates
git: use subprocessio for hooks execution to use non-blocking subprocess.
marcink -
r369:defc08d9 default
parent child Browse files
Show More
@@ -24,7 +24,6 b' import json'
24 import logging
24 import logging
25 import collections
25 import collections
26 import importlib
26 import importlib
27 import subprocess
28
27
29 from httplib import HTTPConnection
28 from httplib import HTTPConnection
30
29
@@ -33,7 +32,7 b' import mercurial.scmutil'
33 import mercurial.node
32 import mercurial.node
34 import simplejson as json
33 import simplejson as json
35
34
36 from vcsserver import exceptions
35 from vcsserver import exceptions, subprocessio, settings
37
36
38 log = logging.getLogger(__name__)
37 log = logging.getLogger(__name__)
39
38
@@ -385,16 +384,19 b' def _run_command(arguments):'
385 :param arguments: sequence of program arguments (including the program name)
384 :param arguments: sequence of program arguments (including the program name)
386 :type arguments: list[str]
385 :type arguments: list[str]
387 """
386 """
388 # TODO(skreft): refactor this method and all the other similar ones.
389 # Probably this should be using subprocessio.
390 process = subprocess.Popen(
391 arguments, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
392 stdout, stderr = process.communicate()
393
387
394 if process.returncode != 0:
388 cmd = arguments
395 raise Exception(
389 try:
396 'Command %s exited with exit code %s: stderr:%s' % (
390 gitenv = os.environ.copy()
397 arguments, process.returncode, stderr))
391 _opts = {'env': gitenv, 'shell': False, 'fail_on_stderr': False}
392 p = subprocessio.SubprocessIOChunker(cmd, **_opts)
393 stdout = ''.join(p)
394 except (EnvironmentError, OSError) as err:
395 cmd = ' '.join(cmd) # human friendly CMD
396 tb_err = ("Couldn't run git command (%s).\n"
397 "Original error was:%s\n" % (cmd, err))
398 log.exception(tb_err)
399 raise Exception(tb_err)
398
400
399 return stdout
401 return stdout
400
402
@@ -433,21 +435,21 b' def git_post_receive(unused_repo_path, r'
433 branches.append(push_ref['name'])
435 branches.append(push_ref['name'])
434
436
435 # Fix up head revision if needed
437 # Fix up head revision if needed
436 cmd = ['git', 'show', 'HEAD']
438 cmd = [settings.GIT_EXECUTABLE, 'show', 'HEAD']
437 try:
439 try:
438 _run_command(cmd)
440 _run_command(cmd)
439 except Exception:
441 except Exception:
440 cmd = ['git', 'symbolic-ref', 'HEAD',
442 cmd = [settings.GIT_EXECUTABLE, 'symbolic-ref', 'HEAD',
441 'refs/heads/%s' % push_ref['name']]
443 'refs/heads/%s' % push_ref['name']]
442 print("Setting default branch to %s" % push_ref['name'])
444 print("Setting default branch to %s" % push_ref['name'])
443 _run_command(cmd)
445 _run_command(cmd)
444
446
445 cmd = ['git', 'for-each-ref', '--format=%(refname)',
447 cmd = [settings.GIT_EXECUTABLE, 'for-each-ref', '--format=%(refname)',
446 'refs/heads/*']
448 'refs/heads/*']
447 heads = _run_command(cmd)
449 heads = _run_command(cmd)
448 heads = heads.replace(push_ref['ref'], '')
450 heads = heads.replace(push_ref['ref'], '')
449 heads = ' '.join(head for head in heads.splitlines() if head)
451 heads = ' '.join(head for head in heads.splitlines() if head)
450 cmd = ['git', 'log', '--reverse', '--pretty=format:%H',
452 cmd = [settings.GIT_EXECUTABLE, 'log', '--reverse', '--pretty=format:%H',
451 '--', push_ref['new_rev'], '--not', heads]
453 '--', push_ref['new_rev'], '--not', heads]
452 git_revs.extend(_run_command(cmd).splitlines())
454 git_revs.extend(_run_command(cmd).splitlines())
453 elif push_ref['new_rev'] == empty_commit_id:
455 elif push_ref['new_rev'] == empty_commit_id:
@@ -457,7 +459,7 b' def git_post_receive(unused_repo_path, r'
457 if push_ref['name'] not in branches:
459 if push_ref['name'] not in branches:
458 branches.append(push_ref['name'])
460 branches.append(push_ref['name'])
459
461
460 cmd = ['git', 'log',
462 cmd = [settings.GIT_EXECUTABLE, 'log',
461 '{old_rev}..{new_rev}'.format(**push_ref),
463 '{old_rev}..{new_rev}'.format(**push_ref),
462 '--reverse', '--pretty=format:%H']
464 '--reverse', '--pretty=format:%H']
463 git_revs.extend(_run_command(cmd).splitlines())
465 git_revs.extend(_run_command(cmd).splitlines())
General Comments 0
You need to be logged in to leave comments. Login now