From 04cba4add52b11a27d09d73c2cbfebcd67a1f2cc Mon Sep 17 00:00:00 2001 From: Gavin Mak Date: Wed, 24 May 2023 21:28:28 +0000 Subject: [PATCH] sync: Show number of running fetch jobs Last of the recent `repo sync` UX changes. Show number of fetch jobs eg: "Fetching: 3% (8/251) 0:03 | 8 jobs | 0:01 chromiumos/overlays/chrom.." Bug: https://crbug.com/gerrit/11293 Change-Id: I1b3dcf3e56ae6731c6c6cb73cfce069b2f374b69 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/374920 Reviewed-by: Josip Sokcevic Commit-Queue: Gavin Mak Tested-by: Gavin Mak Reviewed-by: Joanna Wang --- progress.py | 9 +++++---- subcmds/sync.py | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/progress.py b/progress.py index 6686ad4a..69c95927 100644 --- a/progress.py +++ b/progress.py @@ -76,6 +76,10 @@ def elapsed_str(total): return ret +def jobs_str(total): + return f"{total} job{'s' if total > 1 else ''}" + + class Progress(object): def __init__( self, @@ -170,10 +174,7 @@ class Progress(object): else: p = (100 * self._done) / self._total if self._show_jobs: - jobs = "[%d job%s] " % ( - self._active, - "s" if self._active > 1 else "", - ) + jobs = f"[{jobs_str(self._active)}] " else: jobs = "" if self._show_elapsed: diff --git a/subcmds/sync.py b/subcmds/sync.py index da9918b9..a44ed5b4 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -66,7 +66,7 @@ from command import ( from error import RepoChangedException, GitError import platform_utils from project import SyncBuffer -from progress import Progress, elapsed_str +from progress import Progress, elapsed_str, jobs_str from repo_trace import Trace import ssh from wrapper import Wrapper @@ -673,7 +673,7 @@ later is required to fix a server side protocol bug. def _FetchInitChild(cls, ssh_proxy): cls.ssh_proxy = ssh_proxy - def _GetLongestSyncMessage(self): + def _GetSyncProgressMessage(self): if len(self._sync_dict) == 0: return None @@ -685,7 +685,8 @@ later is required to fix a server side protocol bug. earliest_proj = project elapsed = time.time() - earliest_time - return f"{elapsed_str(elapsed)} {earliest_proj}" + jobs = jobs_str(len(self._sync_dict)) + return f"{jobs} | {elapsed_str(elapsed)} {earliest_proj}" def _Fetch(self, projects, opt, err_event, ssh_proxy): ret = True @@ -707,7 +708,7 @@ later is required to fix a server side protocol bug. def _MonitorSyncLoop(): while True: - pm.update(inc=0, msg=self._GetLongestSyncMessage()) + pm.update(inc=0, msg=self._GetSyncProgressMessage()) if sync_event.wait(timeout=1): return