Skip to content

Commit

Permalink
trace: restore Progress indicator.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Tested-by: LaMont Jones <[email protected]>
Reviewed-by: Xin Li <[email protected]>
  • Loading branch information
lamontj committed Nov 10, 2022
1 parent 5ed8c63 commit 47020ba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
6 changes: 3 additions & 3 deletions progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import os
import sys
from time import time
from repo_trace import IsTrace
from repo_trace import IsTraceToStderr

_NOT_TTY = not os.isatty(2)

Expand Down Expand Up @@ -80,7 +80,7 @@ def finish(self, name):
def update(self, inc=1, msg=''):
self._done += inc

if _NOT_TTY or IsTrace():
if _NOT_TTY or IsTraceToStderr():
return

if not self._show:
Expand Down Expand Up @@ -113,7 +113,7 @@ def update(self, inc=1, msg=''):
sys.stderr.flush()

def end(self):
if _NOT_TTY or IsTrace() or not self._show:
if _NOT_TTY or IsTraceToStderr() or not self._show:
return

duration = duration_str(time() - self._start)
Expand Down
11 changes: 3 additions & 8 deletions repo_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,14 @@

# Temporarily set tracing to always on unless user expicitly sets to 0.
_TRACE = os.environ.get(REPO_TRACE) != '0'

_TRACE_TO_STDERR = False

_TRACE_FILE = None

_TRACE_FILE_NAME = 'TRACE_FILE'

_MAX_SIZE = 70 # in mb

_NEW_COMMAND_SEP = '+++++++++++++++NEW COMMAND+++++++++++++++++++'


def IsStraceToStderr():
def IsTraceToStderr():
return _TRACE_TO_STDERR


Expand Down Expand Up @@ -90,7 +85,7 @@ def __enter__(self):
if not IsTrace():
return self

print_msg = f"PID: {os.getpid()} START: {self._time()} :" + self._trace_msg + '\n'
print_msg = f'PID: {os.getpid()} START: {self._time()} :' + self._trace_msg + '\n'

with open(_TRACE_FILE, 'a') as f:
print(print_msg, file=f)
Expand All @@ -104,7 +99,7 @@ def __exit__(self, *exc):
if not IsTrace():
return False

print_msg = f"PID: {os.getpid()} END: {self._time()} :" + self._trace_msg + '\n'
print_msg = f'PID: {os.getpid()} END: {self._time()} :' + self._trace_msg + '\n'

with open(_TRACE_FILE, 'a') as f:
print(print_msg, file=f)
Expand Down

0 comments on commit 47020ba

Please sign in to comment.