From bbe883649402d428d1996e1ef0d81e43c7a780a0 Mon Sep 17 00:00:00 2001 From: Raman Tenneti Date: Mon, 27 Sep 2021 15:15:47 -0700 Subject: [PATCH] superproject: Log syncstate's parameter as data-json it it is an array. All the values of syncstate are strings, check the first byte and last byte to see if it is an array. For syncstate data, there were no false positives. Tested: $ repo_dev sync Verified event logged for argv is "data-json". $./run_tests Bug: [google internal] b/201102002 Change-Id: Id56adb532b80267f08d09147ac663cdd5987ce87 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/319075 Reviewed-by: Mike Frysinger Tested-by: Raman Tenneti --- git_trace2_event_log.py | 8 ++++---- tests/test_git_trace2_event_log.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/git_trace2_event_log.py b/git_trace2_event_log.py index 0d4f23f4..0e5e9089 100644 --- a/git_trace2_event_log.py +++ b/git_trace2_event_log.py @@ -167,9 +167,9 @@ class EventLog(object): repo_config = {k: v for k, v in config.items() if k.startswith('repo.')} self.LogConfigEvents(repo_config, 'def_param') - def GetDataEventName(self, key): - """Returns the 'data-json' if the key is argv else returns 'data'.""" - return 'data-json' if key.endswith('sys.argv') else 'data' + def GetDataEventName(self, value): + """Returns 'data-json' if the value is an array else returns 'data'.""" + return 'data-json' if value[0] == '[' and value[-1] == ']' else 'data' def LogDataConfigEvents(self, config, prefix): """Append a 'data' event for each config key/value in |config| to the current log. @@ -182,7 +182,7 @@ class EventLog(object): prefix: Prefix for each key that is logged. """ for key, value in config.items(): - event = self._CreateEventDict(self.GetDataEventName(key)) + event = self._CreateEventDict(self.GetDataEventName(value)) event['key'] = f'{prefix}/{key}' event['value'] = value self._log.append(event) diff --git a/tests/test_git_trace2_event_log.py b/tests/test_git_trace2_event_log.py index 6131c7b3..7bd21e21 100644 --- a/tests/test_git_trace2_event_log.py +++ b/tests/test_git_trace2_event_log.py @@ -267,7 +267,7 @@ class EventLogTestCase(unittest.TestCase): self.assertIn('value', event) key = event['key'].removeprefix(f'{prefix_value}/') value = event['value'] - self.assertEqual(self._event_log_module.GetDataEventName(key), event['event']) + self.assertEqual(self._event_log_module.GetDataEventName(value), event['event']) self.assertTrue(key in config and value == config[key]) def test_error_event(self):