diff options
Diffstat (limited to 'main.py')
-rwxr-xr-x | main.py | 33 |
1 files changed, 21 insertions, 12 deletions
@@ -37,7 +37,7 @@ except ImportError: | |||
37 | 37 | ||
38 | from color import SetDefaultColoring | 38 | from color import SetDefaultColoring |
39 | import event_log | 39 | import event_log |
40 | from repo_trace import SetTrace | 40 | from repo_trace import SetTrace, Trace, SetTraceToStderr |
41 | from git_command import user_agent | 41 | from git_command import user_agent |
42 | from git_config import RepoConfig | 42 | from git_config import RepoConfig |
43 | from git_trace2_event_log import EventLog | 43 | from git_trace2_event_log import EventLog |
@@ -109,6 +109,9 @@ global_options.add_option('--color', | |||
109 | global_options.add_option('--trace', | 109 | global_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)') |
112 | global_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') | ||
112 | global_options.add_option('--trace-python', | 115 | global_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 |