From ac78d859db300fde6182ff472536cf80d850c55e Mon Sep 17 00:00:00 2001 From: aleks1k Date: Mon, 29 Apr 2013 17:48:59 +0400 Subject: [PATCH 1/3] Issue #72 https://github.com/gitpython-developers/GitPython/issues/72 Fix hanging when clone or pull execute See http://www.popekim.com/2008/12/never-use-pipe-with-python-popen.html --- git/cmd.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/git/cmd.py b/git/cmd.py index 576a5300a..0f406e1a4 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -5,6 +5,7 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php import os, sys +import tempfile from util import ( LazyMixin, stream_copy @@ -328,19 +329,30 @@ def execute(self, command, cwd = os.getcwd() else: cwd=self._working_dir - + + if as_process: + temp_file_err = tempfile.TemporaryFile() + temp_file_out = tempfile.TemporaryFile() + stderr_pipe=temp_file_err.fileno() + stdout_pipe=temp_file_out.fileno() + else: + stderr_pipe=PIPE + stdout_pipe=PIPE + # Start the process proc = Popen(command, - cwd=cwd, - stdin=istream, - stderr=PIPE, - stdout=PIPE, - close_fds=(os.name=='posix'),# unsupported on linux - **subprocess_kwargs - ) + cwd=cwd, + stdin=istream, + stderr=stderr_pipe, + stdout=stdout_pipe, + close_fds=(os.name=='posix'),# unsupported on linux + **subprocess_kwargs + ) if as_process: + proc.stderr = temp_file_err + proc.stdout = temp_file_out return self.AutoInterrupt(proc, command) - + # Wait for the process to return status = 0 stdout_value = '' From 166f9b001267d2718f6cadd617aa3adb3e00d631 Mon Sep 17 00:00:00 2001 From: aleks1k Date: Mon, 29 Apr 2013 17:48:59 +0400 Subject: [PATCH 2/3] Issue #72 https://github.com/gitpython-developers/GitPython/issues/72 Fix hanging when clone or pull execute See http://www.popekim.com/2008/12/never-use-pipe-with-python-popen.html Fix version parsing for msysgit --- git/cmd.py | 40 ++++++++++++++++++++++++++++++---------- git/remote.py | 7 +++++-- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/git/cmd.py b/git/cmd.py index 576a5300a..1276efa40 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -5,6 +5,7 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php import os, sys +import tempfile from util import ( LazyMixin, stream_copy @@ -234,7 +235,15 @@ def _set_cache_(self, attr): if attr == '_version_info': # We only use the first 4 numbers, as everthing else could be strings in fact (on windows) version_numbers = self._call_process('version').split(' ')[2] - self._version_info = tuple(int(n) for n in version_numbers.split('.')[:4]) + ver_list = version_numbers.split('.') + version_info = list() + for n_str in ver_list: + try: + n_int = int(n_str) + version_info.append(n_int) + except ValueError: + pass + self._version_info = tuple(n for n in version_info) else: super(Git, self)._set_cache_(attr) #END handle version info @@ -328,19 +337,30 @@ def execute(self, command, cwd = os.getcwd() else: cwd=self._working_dir - + + if as_process: + temp_file_err = tempfile.TemporaryFile() + temp_file_out = tempfile.TemporaryFile() + stderr_pipe=temp_file_err.fileno() + stdout_pipe=temp_file_out.fileno() + else: + stderr_pipe=PIPE + stdout_pipe=PIPE + # Start the process proc = Popen(command, - cwd=cwd, - stdin=istream, - stderr=PIPE, - stdout=PIPE, - close_fds=(os.name=='posix'),# unsupported on linux - **subprocess_kwargs - ) + cwd=cwd, + stdin=istream, + stderr=stderr_pipe, + stdout=stdout_pipe, + close_fds=(os.name=='posix'),# unsupported on linux + **subprocess_kwargs + ) if as_process: + proc.stderr = temp_file_err + proc.stdout = temp_file_out return self.AutoInterrupt(proc, command) - + # Wait for the process to return status = 0 stdout_value = '' diff --git a/git/remote.py b/git/remote.py index ed01783ca..89b59e449 100644 --- a/git/remote.py +++ b/git/remote.py @@ -513,8 +513,11 @@ def update(self, **kwargs): def _get_fetch_info_from_stderr(self, proc, progress): # skip first line as it is some remote info we are not interested in output = IterableList('name') - - + + finalize_process(proc) + proc.strerr.seek(0) + proc.strout.seek(0) + # lines which are no progress are fetch info lines # this also waits for the command to finish # Skip some progress lines that don't provide relevant information From f735103cb047a53e52baa29f6eb653aa0e82b0a3 Mon Sep 17 00:00:00 2001 From: aleks1k Date: Mon, 29 Apr 2013 19:29:49 +0400 Subject: [PATCH 3/3] fix --- git/remote.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git/remote.py b/git/remote.py index 89b59e449..6462b1c90 100644 --- a/git/remote.py +++ b/git/remote.py @@ -515,8 +515,8 @@ def _get_fetch_info_from_stderr(self, proc, progress): output = IterableList('name') finalize_process(proc) - proc.strerr.seek(0) - proc.strout.seek(0) + proc.stderr.seek(0) + proc.stdout.seek(0) # lines which are no progress are fetch info lines # this also waits for the command to finish