From a3ff64cae54fca4738f49668c4ee6678969000c3 Mon Sep 17 00:00:00 2001 From: LaMont Jones Date: Mon, 7 Nov 2022 23:19:14 +0000 Subject: Improve always-on-trace Notes to the user need to go to stderr, and tracing should not be on for fast exiting invocations (such as --help). This makes it so that release/update-manpages works. Change-Id: Ib183193c868a78c295a184c01c4532cd53d512eb Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/350794 Tested-by: LaMont Jones Reviewed-by: Xin Li --- main.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'main.py') diff --git a/main.py b/main.py index e629b30f..a22c6a1f 100755 --- a/main.py +++ b/main.py @@ -216,6 +216,21 @@ class _Repo(object): self._PrintHelp(short=True) return 1 + run = lambda: self._RunLong(name, gopts, argv) or 0 + with Trace('starting new command: %s', ', '.join([name] + argv), + first_trace=True): + if gopts.trace_python: + import trace + tracer = trace.Trace(count=False, trace=True, timing=True, + ignoredirs=set(sys.path[1:])) + result = tracer.runfunc(run) + else: + result = run() + return result + + def _RunLong(self, name, gopts, argv): + """Execute the (longer running) requested subcommand.""" + result = 0 SetDefaultColoring(gopts.color) git_trace2_event_log = EventLog() @@ -663,15 +678,7 @@ def _Main(argv): if gopts.trace_to_stderr: SetTraceToStderr() - with Trace('starting new command: %s', ', '.join([name] + argv), first_trace=True): - run = lambda: repo._Run(name, gopts, argv) or 0 - if gopts.trace_python: - import trace - tracer = trace.Trace(count=False, trace=True, timing=True, - ignoredirs=set(sys.path[1:])) - result = tracer.runfunc(run) - else: - result = run() + result = repo._Run(name, gopts, argv) or 0 except KeyboardInterrupt: print('aborted by user', file=sys.stderr) result = 1 -- cgit v1.2.3-54-g00ecf