Skip to content

Commit 166f9b0

Browse files
committed
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
1 parent 0b820e6 commit 166f9b0

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

git/cmd.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66

77
import os, sys
8+
import tempfile
89
from util import (
910
LazyMixin,
1011
stream_copy
@@ -234,7 +235,15 @@ def _set_cache_(self, attr):
234235
if attr == '_version_info':
235236
# We only use the first 4 numbers, as everthing else could be strings in fact (on windows)
236237
version_numbers = self._call_process('version').split(' ')[2]
237-
self._version_info = tuple(int(n) for n in version_numbers.split('.')[:4])
238+
ver_list = version_numbers.split('.')
239+
version_info = list()
240+
for n_str in ver_list:
241+
try:
242+
n_int = int(n_str)
243+
version_info.append(n_int)
244+
except ValueError:
245+
pass
246+
self._version_info = tuple(n for n in version_info)
238247
else:
239248
super(Git, self)._set_cache_(attr)
240249
#END handle version info
@@ -328,19 +337,30 @@ def execute(self, command,
328337
cwd = os.getcwd()
329338
else:
330339
cwd=self._working_dir
331-
340+
341+
if as_process:
342+
temp_file_err = tempfile.TemporaryFile()
343+
temp_file_out = tempfile.TemporaryFile()
344+
stderr_pipe=temp_file_err.fileno()
345+
stdout_pipe=temp_file_out.fileno()
346+
else:
347+
stderr_pipe=PIPE
348+
stdout_pipe=PIPE
349+
332350
# Start the process
333351
proc = Popen(command,
334-
cwd=cwd,
335-
stdin=istream,
336-
stderr=PIPE,
337-
stdout=PIPE,
338-
close_fds=(os.name=='posix'),# unsupported on linux
339-
**subprocess_kwargs
340-
)
352+
cwd=cwd,
353+
stdin=istream,
354+
stderr=stderr_pipe,
355+
stdout=stdout_pipe,
356+
close_fds=(os.name=='posix'),# unsupported on linux
357+
**subprocess_kwargs
358+
)
341359
if as_process:
360+
proc.stderr = temp_file_err
361+
proc.stdout = temp_file_out
342362
return self.AutoInterrupt(proc, command)
343-
363+
344364
# Wait for the process to return
345365
status = 0
346366
stdout_value = ''

git/remote.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,11 @@ def update(self, **kwargs):
513513
def _get_fetch_info_from_stderr(self, proc, progress):
514514
# skip first line as it is some remote info we are not interested in
515515
output = IterableList('name')
516-
517-
516+
517+
finalize_process(proc)
518+
proc.strerr.seek(0)
519+
proc.strout.seek(0)
520+
518521
# lines which are no progress are fetch info lines
519522
# this also waits for the command to finish
520523
# Skip some progress lines that don't provide relevant information

0 commit comments

Comments
 (0)