Skip to content

Commit c8c696b

Browse files
committed
fix(remote): don't close stdout on fetch/pull
Reverted changes of `fe2fbc5~2`. This caused `git-pull` to error, which now actually results in a fatal error while fetching or pulling. Previously we simply didn't check for this issue. Now we are back to a `poll` based or threaded concurrent reading from stdout and stderr to prevent a git process deadlock, and the aforementioned error. Related to #297
1 parent 22d2e4a commit c8c696b

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

git/remote.py

+2-13
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,6 @@ def update(self, **kwargs):
538538

539539
def _get_fetch_info_from_stderr(self, proc, progress):
540540
# skip first line as it is some remote info we are not interested in
541-
# TODO: Use poll() to process stdout and stderr at same time
542541
output = IterableList('name')
543542

544543
# lines which are no progress are fetch info lines
@@ -551,9 +550,7 @@ def _get_fetch_info_from_stderr(self, proc, progress):
551550

552551
progress_handler = progress.new_message_handler()
553552

554-
for line in proc.stderr:
555-
line = line.decode(defenc)
556-
line = line.rstrip()
553+
def my_progress_handler(line):
557554
for pline in progress_handler(line):
558555
if line.startswith('fatal:') or line.startswith('error:'):
559556
raise GitCommandError(("Error when fetching: %s" % line,), 2)
@@ -568,12 +565,7 @@ def _get_fetch_info_from_stderr(self, proc, progress):
568565
# end
569566

570567
# We are only interested in stderr here ...
571-
try:
572-
finalize_process(proc)
573-
except Exception:
574-
if len(fetch_info_lines) == 0:
575-
raise
576-
# end exception handler
568+
handle_process_output(proc, None, my_progress_handler, finalize_process)
577569

578570
# read head information
579571
fp = open(join(self.repo.git_dir, 'FETCH_HEAD'), 'rb')
@@ -593,7 +585,6 @@ def _get_push_info(self, proc, progress):
593585
# we hope stdout can hold all the data, it should ...
594586
# read the lines manually as it will use carriage returns between the messages
595587
# to override the previous one. This is why we read the bytes manually
596-
# TODO: poll() on file descriptors to know what to read next, process streams concurrently
597588
progress_handler = progress.new_message_handler()
598589
output = IterableList('name')
599590

@@ -647,7 +638,6 @@ def fetch(self, refspec=None, progress=None, **kwargs):
647638
args = [refspec]
648639

649640
proc = self.repo.git.fetch(self, *args, with_extended_output=True, as_process=True, v=True, **kwargs)
650-
proc.stdout.close()
651641
res = self._get_fetch_info_from_stderr(proc, progress or RemoteProgress())
652642
if hasattr(self.repo.odb, 'update_cache'):
653643
self.repo.odb.update_cache()
@@ -663,7 +653,6 @@ def pull(self, refspec=None, progress=None, **kwargs):
663653
:return: Please see 'fetch' method """
664654
kwargs = add_progress(kwargs, self.repo.git, progress)
665655
proc = self.repo.git.pull(self, refspec, with_extended_output=True, as_process=True, v=True, **kwargs)
666-
proc.stdout.close()
667656
res = self._get_fetch_info_from_stderr(proc, progress or RemoteProgress())
668657
if hasattr(self.repo.odb, 'update_cache'):
669658
self.repo.odb.update_cache()

0 commit comments

Comments
 (0)