diff options
author | LaMont Jones <lamontjones@google.com> | 2022-11-10 00:11:51 +0000 |
---|---|---|
committer | LaMont Jones <lamontjones@google.com> | 2022-11-10 00:44:33 +0000 |
commit | 47020ba249c39783a66c0031fd9200caecfbbdc8 (patch) | |
tree | 164f70aa5a05e306538dcb42d52e38416bd8ef29 | |
parent | 5ed8c639421c1669b5a945114bc169722b242697 (diff) | |
download | git-repo-47020ba249c39783a66c0031fd9200caecfbbdc8.tar.gz |
trace: restore Progress indicator.v2.29.9
If we are not tracing to stderr, then we should still have progress
indication.
Change-Id: Ifc9678e1fccbd92251e972fcf25aad6369d60e15
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/351195
Reviewed-by: Sam Saccone <samccone@google.com>
Tested-by: LaMont Jones <lamontjones@google.com>
Reviewed-by: Xin Li <delphij@google.com>
-rw-r--r-- | progress.py | 6 | ||||
-rw-r--r-- | repo_trace.py | 11 |
2 files changed, 6 insertions, 11 deletions
diff --git a/progress.py b/progress.py index f9ac53a1..526ce6c1 100644 --- a/progress.py +++ b/progress.py | |||
@@ -15,7 +15,7 @@ | |||
15 | import os | 15 | import os |
16 | import sys | 16 | import sys |
17 | from time import time | 17 | from time import time |
18 | from repo_trace import IsTrace | 18 | from repo_trace import IsTraceToStderr |
19 | 19 | ||
20 | _NOT_TTY = not os.isatty(2) | 20 | _NOT_TTY = not os.isatty(2) |
21 | 21 | ||
@@ -80,7 +80,7 @@ class Progress(object): | |||
80 | def update(self, inc=1, msg=''): | 80 | def update(self, inc=1, msg=''): |
81 | self._done += inc | 81 | self._done += inc |
82 | 82 | ||
83 | if _NOT_TTY or IsTrace(): | 83 | if _NOT_TTY or IsTraceToStderr(): |
84 | return | 84 | return |
85 | 85 | ||
86 | if not self._show: | 86 | if not self._show: |
@@ -113,7 +113,7 @@ class Progress(object): | |||
113 | sys.stderr.flush() | 113 | sys.stderr.flush() |
114 | 114 | ||
115 | def end(self): | 115 | def end(self): |
116 | if _NOT_TTY or IsTrace() or not self._show: | 116 | if _NOT_TTY or IsTraceToStderr() or not self._show: |
117 | return | 117 | return |
118 | 118 | ||
119 | duration = duration_str(time() - self._start) | 119 | duration = duration_str(time() - self._start) |
diff --git a/repo_trace.py b/repo_trace.py index 86cbfc62..9016cb0c 100644 --- a/repo_trace.py +++ b/repo_trace.py | |||
@@ -32,19 +32,14 @@ REPO_TRACE = 'REPO_TRACE' | |||
32 | 32 | ||
33 | # Temporarily set tracing to always on unless user expicitly sets to 0. | 33 | # Temporarily set tracing to always on unless user expicitly sets to 0. |
34 | _TRACE = os.environ.get(REPO_TRACE) != '0' | 34 | _TRACE = os.environ.get(REPO_TRACE) != '0' |
35 | |||
36 | _TRACE_TO_STDERR = False | 35 | _TRACE_TO_STDERR = False |
37 | |||
38 | _TRACE_FILE = None | 36 | _TRACE_FILE = None |
39 | |||
40 | _TRACE_FILE_NAME = 'TRACE_FILE' | 37 | _TRACE_FILE_NAME = 'TRACE_FILE' |
41 | |||
42 | _MAX_SIZE = 70 # in mb | 38 | _MAX_SIZE = 70 # in mb |
43 | |||
44 | _NEW_COMMAND_SEP = '+++++++++++++++NEW COMMAND+++++++++++++++++++' | 39 | _NEW_COMMAND_SEP = '+++++++++++++++NEW COMMAND+++++++++++++++++++' |
45 | 40 | ||
46 | 41 | ||
47 | def IsStraceToStderr(): | 42 | def IsTraceToStderr(): |
48 | return _TRACE_TO_STDERR | 43 | return _TRACE_TO_STDERR |
49 | 44 | ||
50 | 45 | ||
@@ -90,7 +85,7 @@ class Trace(ContextDecorator): | |||
90 | if not IsTrace(): | 85 | if not IsTrace(): |
91 | return self | 86 | return self |
92 | 87 | ||
93 | print_msg = f"PID: {os.getpid()} START: {self._time()} :" + self._trace_msg + '\n' | 88 | print_msg = f'PID: {os.getpid()} START: {self._time()} :' + self._trace_msg + '\n' |
94 | 89 | ||
95 | with open(_TRACE_FILE, 'a') as f: | 90 | with open(_TRACE_FILE, 'a') as f: |
96 | print(print_msg, file=f) | 91 | print(print_msg, file=f) |
@@ -104,7 +99,7 @@ class Trace(ContextDecorator): | |||
104 | if not IsTrace(): | 99 | if not IsTrace(): |
105 | return False | 100 | return False |
106 | 101 | ||
107 | print_msg = f"PID: {os.getpid()} END: {self._time()} :" + self._trace_msg + '\n' | 102 | print_msg = f'PID: {os.getpid()} END: {self._time()} :' + self._trace_msg + '\n' |
108 | 103 | ||
109 | with open(_TRACE_FILE, 'a') as f: | 104 | with open(_TRACE_FILE, 'a') as f: |
110 | print(print_msg, file=f) | 105 | print(print_msg, file=f) |