repo_trace: drop notification of trace file name.

The trace file is local to the workspace. We shouldn't tell the user
that on every command that they run.

Change-Id: I8674ab485bd5142814a043a225bf8aaca7795752
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/351234
Tested-by: LaMont Jones <lamontjones@google.com>
Reviewed-by: Xin Li <delphij@google.com>
This commit is contained in:
LaMont Jones 2022-11-10 02:31:19 +00:00
parent afd767103e
commit ed25be569e

View File

@ -57,9 +57,9 @@ def SetTrace():
_TRACE = True
def _SetTraceFile():
def _SetTraceFile(quiet):
global _TRACE_FILE
_TRACE_FILE = _GetTraceFile()
_TRACE_FILE = _GetTraceFile(quiet)
class Trace(ContextDecorator):
@ -68,13 +68,21 @@ class Trace(ContextDecorator):
"""Generate nanoseconds of time in a py3.6 safe way"""
return int(time.time() * 1e+9)
def __init__(self, fmt, *args, first_trace=False):
def __init__(self, fmt, *args, first_trace=False, quiet=True):
"""Initialize the object.
Args:
fmt: The format string for the trace.
*args: Arguments to pass to formatting.
first_trace: Whether this is the first trace of a `repo` invocation.
quiet: Whether to suppress notification of trace file location.
"""
if not IsTrace():
return
self._trace_msg = fmt % args
if not _TRACE_FILE:
_SetTraceFile()
_SetTraceFile(quiet)
if first_trace:
_ClearOldTraces()
@ -109,11 +117,12 @@ class Trace(ContextDecorator):
return False
def _GetTraceFile():
def _GetTraceFile(quiet):
"""Get the trace file or create one."""
# TODO: refactor to pass repodir to Trace.
repo_dir = os.path.dirname(os.path.dirname(__file__))
trace_file = os.path.join(repo_dir, _TRACE_FILE_NAME)
if not quiet:
print(f'Trace outputs in {trace_file}', file=sys.stderr)
return trace_file