summaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2019-08-27 00:36:46 -0400
committerMike Frysinger <vapier@google.com>2019-08-27 18:44:17 +0000
commit3fc157285cb61d6a4faa55dc4f011fb94d598c20 (patch)
treebc1888814e31a72997e7a1635df72fd177731988 /main.py
parent8a11f6f24cecac28e7cdb3f5d0d7c83aec0df017 (diff)
downloadgit-repo-3fc157285cb61d6a4faa55dc4f011fb94d598c20.tar.gz
git-repo-3fc157285cb61d6a4faa55dc4f011fb94d598c20.zip
add a --trace-python option
This can help debug issues by tracing all the repo python code with the standard trace module. Change-Id: Ibb7f4496ab6c7f9e130238ddf3a07c831952697a Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/234833 Tested-by: Mike Frysinger <vapier@google.com> Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Diffstat (limited to 'main.py')
-rwxr-xr-xmain.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/main.py b/main.py
index 35023d52d..889fc2161 100755
--- a/main.py
+++ b/main.py
@@ -85,6 +85,9 @@ global_options.add_option('--color',
global_options.add_option('--trace',
dest='trace', action='store_true',
help='trace git command execution (REPO_TRACE=1)')
+global_options.add_option('--trace-python',
+ dest='trace_python', action='store_true',
+ help='trace python command execution')
global_options.add_option('--time',
dest='time', action='store_true',
help='time repo command execution')
@@ -102,8 +105,8 @@ class _Repo(object):
# add 'branch' as an alias for 'branches'
all_commands['branch'] = all_commands['branches']
- def _Run(self, argv):
- result = 0
+ def _ParseArgs(self, argv):
+ """Parse the main `repo` command line options."""
name = None
glob = []
@@ -120,6 +123,12 @@ class _Repo(object):
argv = []
gopts, _gargs = global_options.parse_args(glob)
+ return (name, gopts, argv)
+
+ def _Run(self, name, gopts, argv):
+ """Execute the requested subcommand."""
+ result = 0
+
if gopts.trace:
SetTrace()
if gopts.show_version:
@@ -526,7 +535,15 @@ def _Main(argv):
try:
init_ssh()
init_http()
- result = repo._Run(argv) or 0
+ name, gopts, argv = repo._ParseArgs(argv)
+ 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()
finally:
close_ssh()
except KeyboardInterrupt: