From ed25be569e1c2e1c222010565c186b904eb8646c Mon Sep 17 00:00:00 2001 From: LaMont Jones Date: Thu, 10 Nov 2022 02:31:19 +0000 Subject: [PATCH] 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 Reviewed-by: Xin Li --- repo_trace.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/repo_trace.py b/repo_trace.py index fcd8650e..d79408d9 100644 --- a/repo_trace.py +++ b/repo_trace.py @@ -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,12 +117,13 @@ 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) - print(f'Trace outputs in {trace_file}', file=sys.stderr) + if not quiet: + print(f'Trace outputs in {trace_file}', file=sys.stderr) return trace_file