diff options
| author | Ian Kasprzak <iankaz@google.com> | 2021-01-06 16:26:31 -0800 |
|---|---|---|
| committer | Ian Kasprzak <iankaz@google.com> | 2021-01-07 14:31:51 +0000 |
| commit | 343d585ff99c5748d33823e92507fa06a037c608 (patch) | |
| tree | 8f655c130e017872fc73530e9e63d92677c88b08 /git_trace2_event_log.py | |
| parent | acf63b28928b33d1335dfed1af7e2d8fc6bb5fc4 (diff) | |
| download | git-repo-343d585ff99c5748d33823e92507fa06a037c608.tar.gz | |
Fix bug in git trace2 event Write() function when no config present.
See https://bugs.chromium.org/p/gerrit/issues/detail?id=13706#c9
Added additional unit tests for Write() for additional test coverage.
Testing:
- Unit tests
- Verified repo works with:
- Valid trace2.eventtarget
- Invalid trace2.eventtarget
Bug: https://crbug.com/gerrit/13706
Tested-by: Ian Kasprzak <iankaz@google.com>
Change-Id: I6b027cb2399bd03e453a132ad82e022a1f48476e
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/292762
Reviewed-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'git_trace2_event_log.py')
| -rw-r--r-- | git_trace2_event_log.py | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/git_trace2_event_log.py b/git_trace2_event_log.py index 4a8e0347..dfbded15 100644 --- a/git_trace2_event_log.py +++ b/git_trace2_event_log.py | |||
| @@ -132,6 +132,30 @@ class EventLog(object): | |||
| 132 | exit_event['code'] = result | 132 | exit_event['code'] = result |
| 133 | self._log.append(exit_event) | 133 | self._log.append(exit_event) |
| 134 | 134 | ||
| 135 | def _GetEventTargetPath(self): | ||
| 136 | """Get the 'trace2.eventtarget' path from git configuration. | ||
| 137 | |||
| 138 | Returns: | ||
| 139 | path: git config's 'trace2.eventtarget' path if it exists, or None | ||
| 140 | """ | ||
| 141 | path = None | ||
| 142 | cmd = ['config', '--get', 'trace2.eventtarget'] | ||
| 143 | # TODO(https://crbug.com/gerrit/13706): Use GitConfig when it supports | ||
| 144 | # system git config variables. | ||
| 145 | p = GitCommand(None, cmd, capture_stdout=True, capture_stderr=True, | ||
| 146 | bare=True) | ||
| 147 | retval = p.Wait() | ||
| 148 | if retval == 0: | ||
| 149 | # Strip trailing carriage-return in path. | ||
| 150 | path = p.stdout.rstrip('\n') | ||
| 151 | elif retval != 1: | ||
| 152 | # `git config --get` is documented to produce an exit status of `1` if | ||
| 153 | # the requested variable is not present in the configuration. Report any | ||
| 154 | # other return value as an error. | ||
| 155 | print("repo: error: 'git config --get' call failed with return code: %r, stderr: %r" % ( | ||
| 156 | retval, p.stderr), file=sys.stderr) | ||
| 157 | return path | ||
| 158 | |||
| 135 | def Write(self, path=None): | 159 | def Write(self, path=None): |
| 136 | """Writes the log out to a file. | 160 | """Writes the log out to a file. |
| 137 | 161 | ||
| @@ -150,21 +174,11 @@ class EventLog(object): | |||
| 150 | log_path = None | 174 | log_path = None |
| 151 | # If no logging path is specified, get the path from 'trace2.eventtarget'. | 175 | # If no logging path is specified, get the path from 'trace2.eventtarget'. |
| 152 | if path is None: | 176 | if path is None: |
| 153 | cmd = ['config', '--get', 'trace2.eventtarget'] | 177 | path = self._GetEventTargetPath() |
| 154 | # TODO(https://crbug.com/gerrit/13706): Use GitConfig when it supports | 178 | |
| 155 | # system git config variables. | 179 | # If no logging path is specified, exit. |
| 156 | p = GitCommand(None, cmd, capture_stdout=True, capture_stderr=True, | 180 | if path is None: |
| 157 | bare=True) | 181 | return None |
| 158 | retval = p.Wait() | ||
| 159 | if retval == 0: | ||
| 160 | # Strip trailing carriage-return in path. | ||
| 161 | path = p.stdout.rstrip('\n') | ||
| 162 | elif retval != 1: | ||
| 163 | # `git config --get` is documented to produce an exit status of `1` if | ||
| 164 | # the requested variable is not present in the configuration. Report any | ||
| 165 | # other return value as an error. | ||
| 166 | print("repo: error: 'git config --get' call failed with return code: %r, stderr: %r" % ( | ||
| 167 | retval, p.stderr), file=sys.stderr) | ||
| 168 | 182 | ||
| 169 | if isinstance(path, str): | 183 | if isinstance(path, str): |
| 170 | # Get absolute path. | 184 | # Get absolute path. |
