From 4e05f650e0b314fa80ea5811c0abe4b71ea0758c Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 23 Feb 2021 16:57:56 -0500 Subject: [PATCH] progress: always enable always_print_percentage The idea for skipping some progress updates was to avoid spending too much time on the progress bar itself. Unfortunately, for large projects (100s if not 1000s) of repos, we get into the situation with large/slow checkouts that we skip showing updates when a repo finishes, but not enough repos finished to increase the percent. Since the progress bar should be relatively fast compared to the actual network & local dick operations, have it show an update whenever the caller requests it. A test with ~1000 repos shows that the progress bar in total adds <100ms. Bug: https://crbug.com/gerrit/11293 Change-Id: I708a0c4bd923c59c7691a5b48ae33eb6fca4cd14 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/297903 Reviewed-by: Michael Mortensen Tested-by: Mike Frysinger --- progress.py | 26 ++++++++++---------------- subcmds/sync.py | 3 +-- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/progress.py b/progress.py index 9222fcfc..3764b9e2 100644 --- a/progress.py +++ b/progress.py @@ -26,17 +26,14 @@ CSI_ERASE_LINE = '\x1b[2K' class Progress(object): - def __init__(self, title, total=0, units='', print_newline=False, - always_print_percentage=False): + def __init__(self, title, total=0, units='', print_newline=False): self._title = title self._total = total self._done = 0 - self._lastp = -1 self._start = time() self._show = False self._units = units self._print_newline = print_newline - self._always_print_percentage = always_print_percentage def update(self, inc=1, msg=''): self._done += inc @@ -58,18 +55,15 @@ class Progress(object): sys.stderr.flush() else: p = (100 * self._done) / self._total - - if self._lastp != p or self._always_print_percentage: - self._lastp = p - sys.stderr.write('%s\r%s: %3d%% (%d%s/%d%s)%s%s%s' % ( - CSI_ERASE_LINE, - self._title, - p, - self._done, self._units, - self._total, self._units, - ' ' if msg else '', msg, - "\n" if self._print_newline else "")) - sys.stderr.flush() + sys.stderr.write('%s\r%s: %3d%% (%d%s/%d%s)%s%s%s' % ( + CSI_ERASE_LINE, + self._title, + p, + self._done, self._units, + self._total, self._units, + ' ' if msg else '', msg, + '\n' if self._print_newline else '')) + sys.stderr.flush() def end(self): if _NOT_TTY or IsTrace() or not self._show: diff --git a/subcmds/sync.py b/subcmds/sync.py index 47790cc8..0a3cde7d 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -403,8 +403,7 @@ later is required to fix a server side protocol bug. def _Fetch(self, projects, opt, err_event): fetched = set() lock = _threading.Lock() - pm = Progress('Fetching projects', len(projects), - always_print_percentage=opt.quiet) + pm = Progress('Fetching projects', len(projects)) objdir_project_map = dict() for project in projects: