diff options
author | Mike Frysinger <vapier@google.com> | 2021-02-23 16:57:56 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2021-02-25 20:13:18 +0000 |
commit | 4e05f650e0b314fa80ea5811c0abe4b71ea0758c (patch) | |
tree | 88e3ca1485726bd3edaa949f94bf0af4d71fc574 /progress.py | |
parent | 23882b33feaa0104dcbe372a9fde496cffc2b246 (diff) | |
download | git-repo-4e05f650e0b314fa80ea5811c0abe4b71ea0758c.tar.gz |
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 <mmortensen@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'progress.py')
-rw-r--r-- | progress.py | 26 |
1 files changed, 10 insertions, 16 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' | |||
26 | 26 | ||
27 | 27 | ||
28 | class Progress(object): | 28 | class Progress(object): |
29 | def __init__(self, title, total=0, units='', print_newline=False, | 29 | def __init__(self, title, total=0, units='', print_newline=False): |
30 | always_print_percentage=False): | ||
31 | self._title = title | 30 | self._title = title |
32 | self._total = total | 31 | self._total = total |
33 | self._done = 0 | 32 | self._done = 0 |
34 | self._lastp = -1 | ||
35 | self._start = time() | 33 | self._start = time() |
36 | self._show = False | 34 | self._show = False |
37 | self._units = units | 35 | self._units = units |
38 | self._print_newline = print_newline | 36 | self._print_newline = print_newline |
39 | self._always_print_percentage = always_print_percentage | ||
40 | 37 | ||
41 | def update(self, inc=1, msg=''): | 38 | def update(self, inc=1, msg=''): |
42 | self._done += inc | 39 | self._done += inc |
@@ -58,18 +55,15 @@ class Progress(object): | |||
58 | sys.stderr.flush() | 55 | sys.stderr.flush() |
59 | else: | 56 | else: |
60 | p = (100 * self._done) / self._total | 57 | p = (100 * self._done) / self._total |
61 | 58 | sys.stderr.write('%s\r%s: %3d%% (%d%s/%d%s)%s%s%s' % ( | |
62 | if self._lastp != p or self._always_print_percentage: | 59 | CSI_ERASE_LINE, |
63 | self._lastp = p | 60 | self._title, |
64 | sys.stderr.write('%s\r%s: %3d%% (%d%s/%d%s)%s%s%s' % ( | 61 | p, |
65 | CSI_ERASE_LINE, | 62 | self._done, self._units, |
66 | self._title, | 63 | self._total, self._units, |
67 | p, | 64 | ' ' if msg else '', msg, |
68 | self._done, self._units, | 65 | '\n' if self._print_newline else '')) |
69 | self._total, self._units, | 66 | sys.stderr.flush() |
70 | ' ' if msg else '', msg, | ||
71 | "\n" if self._print_newline else "")) | ||
72 | sys.stderr.flush() | ||
73 | 67 | ||
74 | def end(self): | 68 | def end(self): |
75 | if _NOT_TTY or IsTrace() or not self._show: | 69 | if _NOT_TTY or IsTrace() or not self._show: |