From 945c006f406550add8a3cad32ada0791f5a15c53 Mon Sep 17 00:00:00 2001 From: Gavin Mak Date: Tue, 30 May 2023 20:04:07 +0000 Subject: [PATCH] sync: Update sync progress even when _sync_dict is empty By chance, _sync_dict can be empty even though repo sync is still working. In that case, the progress message shows incorrect info. Handle this case and fix a bug where "0 jobs" can show. Bug: http://b/284465096 Change-Id: If915d953ba60e7cf84a6fb2d137fd6ed82abd3cc Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/375494 Tested-by: Gavin Mak Reviewed-by: Josip Sokcevic Commit-Queue: Gavin Mak --- subcmds/sync.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/subcmds/sync.py b/subcmds/sync.py index 0e4f34c0..224d9885 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -679,16 +679,20 @@ later is required to fix a server side protocol bug. def _GetSyncProgressMessage(self): earliest_time = float("inf") earliest_proj = None - for project, t in self._sync_dict.items(): + items = self._sync_dict.items() + for project, t in items: if t < earliest_time: earliest_time = t earliest_proj = project if not earliest_proj: - return None + # This function is called when sync is still running but in some + # cases (by chance), _sync_dict can contain no entries. Return some + # text to indicate that sync is still working. + return "..working.." elapsed = time.time() - earliest_time - jobs = jobs_str(len(self._sync_dict)) + jobs = jobs_str(len(items)) return f"{jobs} | {elapsed_str(elapsed)} {earliest_proj}" def _Fetch(self, projects, opt, err_event, ssh_proxy):