From a6c52f566acfbff5b0f37158c0d33adf05d250e5 Mon Sep 17 00:00:00 2001 From: Joanna Wang Date: Thu, 3 Nov 2022 16:51:19 -0400 Subject: 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 Tested-by: Joanna Wang --- git_command.py | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'git_command.py') diff --git a/git_command.py b/git_command.py index 19100fa9..56e18e02 100644 --- a/git_command.py +++ b/git_command.py @@ -230,12 +230,11 @@ class GitCommand(object): stderr = (subprocess.STDOUT if merge_output else (subprocess.PIPE if capture_stderr else None)) + dbg = '' if IsTrace(): global LAST_CWD global LAST_GITDIR - dbg = '' - if cwd and LAST_CWD != cwd: if LAST_GITDIR or LAST_CWD: dbg += '\n' @@ -263,31 +262,31 @@ class GitCommand(object): dbg += ' 2>|' elif stderr == subprocess.STDOUT: dbg += ' 2>&1' - Trace('%s', dbg) - - try: - p = subprocess.Popen(command, - cwd=cwd, - env=env, - encoding='utf-8', - errors='backslashreplace', - stdin=stdin, - stdout=stdout, - stderr=stderr) - except Exception as e: - raise GitError('%s: %s' % (command[1], e)) - - if ssh_proxy: - ssh_proxy.add_client(p) - self.process = p + with Trace('git command %s %s with debug: %s', LAST_GITDIR, command, dbg): + try: + p = subprocess.Popen(command, + cwd=cwd, + env=env, + encoding='utf-8', + errors='backslashreplace', + stdin=stdin, + stdout=stdout, + stderr=stderr) + except Exception as e: + raise GitError('%s: %s' % (command[1], e)) - try: - self.stdout, self.stderr = p.communicate(input=input) - finally: if ssh_proxy: - ssh_proxy.remove_client(p) - self.rc = p.wait() + ssh_proxy.add_client(p) + + self.process = p + + try: + self.stdout, self.stderr = p.communicate(input=input) + finally: + if ssh_proxy: + ssh_proxy.remove_client(p) + self.rc = p.wait() @staticmethod def _GetBasicEnv(): -- cgit v1.2.3-54-g00ecf