From b16b9d26bd2d05d704da3e38f3eee743f2b110c6 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 20 May 2021 01:48:17 -0400 Subject: [PATCH] project: fix error display when output_redir is disabled We always pass in output_redir when syncing, but that's the common case: there are a few situations (like `repo init`) where we don't pass in a buffer, and if any errors show up in that case, we'd crash. Rely on the print function to handle this logic for us. Bug: https://crbug.com/gerrit/14568 Change-Id: I8cd47e82329797ffc42534418a3dfbd8429205be Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/307222 Reviewed-by: Raman Tenneti Tested-by: Mike Frysinger --- project.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/project.py b/project.py index 2f83d796..2ab0b389 100644 --- a/project.py +++ b/project.py @@ -2197,7 +2197,7 @@ class Project(object): ret = prunecmd.Wait() if ret: break - output_redir.write('retrying fetch after pruning remote branches') + print('retrying fetch after pruning remote branches', file=output_redir) # Continue right away so we don't sleep as we shouldn't need to. continue elif current_branch_only and is_sha1 and ret == 128: @@ -2210,10 +2210,11 @@ class Project(object): break # Figure out how long to sleep before the next attempt, if there is one. - if not verbose: - output_redir.write('\n%s:\n%s' % (self.name, gitcmd.stdout)) + if not verbose and gitcmd.stdout: + print('\n%s:\n%s' % (self.name, gitcmd.stdout), end='', file=output_redir) if try_n < retry_fetches - 1: - output_redir.write('sleeping %s seconds before retrying' % retry_cur_sleep) + print('%s: sleeping %s seconds before retrying' % (self.name, retry_cur_sleep), + file=output_redir) time.sleep(retry_cur_sleep) retry_cur_sleep = min(retry_exp_factor * retry_cur_sleep, MAXIMUM_RETRY_SLEEP_SEC)