summaryrefslogtreecommitdiffstats
path: root/main.py
diff options
context:
space:
mode:
authorJoanna Wang <jojwang@google.com>2022-11-03 16:51:19 -0400
committerJoanna Wang <jojwang@google.com>2022-11-03 21:07:07 +0000
commita6c52f566acfbff5b0f37158c0d33adf05d250e5 (patch)
treed79d55b872c3be39c54dcb6ef41749c40d39ccf2 /main.py
parent0d130d2da0754c546f654ede99a79aac2b8e6c5f (diff)
downloadgit-repo-a6c52f566acfbff5b0f37158c0d33adf05d250e5.tar.gz
Set tracing to always on and save to .repo/TRACE_FILE.
- add `--trace_to_stderr` option so stderr will include trace outputs and any other errors that get sent to stderr - while TRACE_FILE will only include trace outputs piggy-backing on: https://gerrit-review.googlesource.com/c/git-repo/+/349154 Change-Id: I3895a84de4b2784f17fac4325521cd5e72e645e2 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/350114 Reviewed-by: LaMont Jones <lamontjones@google.com> Tested-by: Joanna Wang <jojwang@google.com>
Diffstat (limited to 'main.py')
-rwxr-xr-xmain.py33
1 files changed, 21 insertions, 12 deletions
diff --git a/main.py b/main.py
index c54f9281..e629b30f 100755
--- a/main.py
+++ b/main.py
@@ -37,7 +37,7 @@ except ImportError:
37 37
38from color import SetDefaultColoring 38from color import SetDefaultColoring
39import event_log 39import event_log
40from repo_trace import SetTrace 40from repo_trace import SetTrace, Trace, SetTraceToStderr
41from git_command import user_agent 41from git_command import user_agent
42from git_config import RepoConfig 42from git_config import RepoConfig
43from git_trace2_event_log import EventLog 43from git_trace2_event_log import EventLog
@@ -109,6 +109,9 @@ global_options.add_option('--color',
109global_options.add_option('--trace', 109global_options.add_option('--trace',
110 dest='trace', action='store_true', 110 dest='trace', action='store_true',
111 help='trace git command execution (REPO_TRACE=1)') 111 help='trace git command execution (REPO_TRACE=1)')
112global_options.add_option('--trace_to_stderr',
113 dest='trace_to_stderr', action='store_true',
114 help='trace outputs go to stderr in addition to .repo/TRACE_FILE')
112global_options.add_option('--trace-python', 115global_options.add_option('--trace-python',
113 dest='trace_python', action='store_true', 116 dest='trace_python', action='store_true',
114 help='trace python command execution') 117 help='trace python command execution')
@@ -198,9 +201,6 @@ class _Repo(object):
198 """Execute the requested subcommand.""" 201 """Execute the requested subcommand."""
199 result = 0 202 result = 0
200 203
201 if gopts.trace:
202 SetTrace()
203
204 # Handle options that terminate quickly first. 204 # Handle options that terminate quickly first.
205 if gopts.help or gopts.help_all: 205 if gopts.help or gopts.help_all:
206 self._PrintHelp(short=False, all_commands=gopts.help_all) 206 self._PrintHelp(short=False, all_commands=gopts.help_all)
@@ -652,17 +652,26 @@ def _Main(argv):
652 Version.wrapper_path = opt.wrapper_path 652 Version.wrapper_path = opt.wrapper_path
653 653
654 repo = _Repo(opt.repodir) 654 repo = _Repo(opt.repodir)
655
655 try: 656 try:
656 init_http() 657 init_http()
657 name, gopts, argv = repo._ParseArgs(argv) 658 name, gopts, argv = repo._ParseArgs(argv)
658 run = lambda: repo._Run(name, gopts, argv) or 0 659
659 if gopts.trace_python: 660 if gopts.trace:
660 import trace 661 SetTrace()
661 tracer = trace.Trace(count=False, trace=True, timing=True, 662
662 ignoredirs=set(sys.path[1:])) 663 if gopts.trace_to_stderr:
663 result = tracer.runfunc(run) 664 SetTraceToStderr()
664 else: 665
665 result = run() 666 with Trace('starting new command: %s', ', '.join([name] + argv), first_trace=True):
667 run = lambda: repo._Run(name, gopts, argv) or 0
668 if gopts.trace_python:
669 import trace
670 tracer = trace.Trace(count=False, trace=True, timing=True,
671 ignoredirs=set(sys.path[1:]))
672 result = tracer.runfunc(run)
673 else:
674 result = run()
666 except KeyboardInterrupt: 675 except KeyboardInterrupt:
667 print('aborted by user', file=sys.stderr) 676 print('aborted by user', file=sys.stderr)
668 result = 1 677 result = 1