Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
allow for timeout propagation
  • Loading branch information
sroet committed Sep 10, 2021
commit 1d265152263b548c296ec5e3f244de8a89377602
24 changes: 15 additions & 9 deletions git/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,8 @@ def update(self, **kwargs: Any) -> 'Remote':
return self

def _get_fetch_info_from_stderr(self, proc: 'Git.AutoInterrupt',
progress: Union[Callable[..., Any], RemoteProgress, None]
progress: Union[Callable[..., Any], RemoteProgress, None],
timeout: float = 60.0
) -> IterableList['FetchInfo']:

progress = to_progress_instance(progress)
Expand All @@ -724,7 +725,8 @@ def _get_fetch_info_from_stderr(self, proc: 'Git.AutoInterrupt',
cmds = set(FetchInfo._flag_map.keys())

progress_handler = progress.new_message_handler()
handle_process_output(proc, None, progress_handler, finalizer=None, decode_streams=False)
handle_process_output(proc, None, progress_handler, finalizer=None, decode_streams=False,
timeout=timeout)

stderr_text = progress.error_lines and '\n'.join(progress.error_lines) or ''
proc.wait(stderr=stderr_text)
Expand Down Expand Up @@ -769,7 +771,8 @@ def _get_fetch_info_from_stderr(self, proc: 'Git.AutoInterrupt',
return output

def _get_push_info(self, proc: 'Git.AutoInterrupt',
progress: Union[Callable[..., Any], RemoteProgress, None]) -> IterableList[PushInfo]:
progress: Union[Callable[..., Any], RemoteProgress, None],
timeout: float = 60.0) -> IterableList[PushInfo]:
progress = to_progress_instance(progress)

# read progress information from stderr
Expand All @@ -786,7 +789,8 @@ def stdout_handler(line: str) -> None:
# If an error happens, additional info is given which we parse below.
pass

handle_process_output(proc, stdout_handler, progress_handler, finalizer=None, decode_streams=False)
handle_process_output(proc, stdout_handler, progress_handler, finalizer=None, decode_streams=False,
timeout=timeout)
stderr_text = progress.error_lines and '\n'.join(progress.error_lines) or ''
try:
proc.wait(stderr=stderr_text)
Expand All @@ -813,7 +817,8 @@ def _assert_refspec(self) -> None:

def fetch(self, refspec: Union[str, List[str], None] = None,
progress: Union[RemoteProgress, None, 'UpdateProgress'] = None,
verbose: bool = True, **kwargs: Any) -> IterableList[FetchInfo]:
verbose: bool = True, timeout: float = 60.0,
**kwargs: Any) -> IterableList[FetchInfo]:
"""Fetch the latest changes for this remote

:param refspec:
Expand Down Expand Up @@ -853,13 +858,14 @@ def fetch(self, refspec: Union[str, List[str], None] = None,

proc = self.repo.git.fetch(self, *args, as_process=True, with_stdout=False,
universal_newlines=True, v=verbose, **kwargs)
res = self._get_fetch_info_from_stderr(proc, progress)
res = self._get_fetch_info_from_stderr(proc, progress, timeout=timeout)
if hasattr(self.repo.odb, 'update_cache'):
self.repo.odb.update_cache()
return res

def pull(self, refspec: Union[str, List[str], None] = None,
progress: Union[RemoteProgress, 'UpdateProgress', None] = None,
timeout: float = 60.0,
**kwargs: Any) -> IterableList[FetchInfo]:
"""Pull changes from the given branch, being the same as a fetch followed
by a merge of branch with your local branch.
Expand All @@ -874,14 +880,14 @@ def pull(self, refspec: Union[str, List[str], None] = None,
kwargs = add_progress(kwargs, self.repo.git, progress)
proc = self.repo.git.pull(self, refspec, with_stdout=False, as_process=True,
universal_newlines=True, v=True, **kwargs)
res = self._get_fetch_info_from_stderr(proc, progress)
res = self._get_fetch_info_from_stderr(proc, progress, timeout=timeout)
if hasattr(self.repo.odb, 'update_cache'):
self.repo.odb.update_cache()
return res

def push(self, refspec: Union[str, List[str], None] = None,
progress: Union[RemoteProgress, 'UpdateProgress', Callable[..., RemoteProgress], None] = None,
**kwargs: Any) -> IterableList[PushInfo]:
timeout: float = 60.0, **kwargs: Any) -> IterableList[PushInfo]:
"""Push changes from source branch in refspec to target branch in refspec.

:param refspec: see 'fetch' method
Expand Down Expand Up @@ -909,7 +915,7 @@ def push(self, refspec: Union[str, List[str], None] = None,
kwargs = add_progress(kwargs, self.repo.git, progress)
proc = self.repo.git.push(self, refspec, porcelain=True, as_process=True,
universal_newlines=True, **kwargs)
return self._get_push_info(proc, progress)
return self._get_push_info(proc, progress, timeout=timeout)

@ property
def config_reader(self) -> SectionConstraint[GitConfigParser]:
Expand Down