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 <vapier@google.com>
Tested-by: Raman Tenneti <rtenneti@google.com>
This commit is contained in:
Raman Tenneti 2021-09-27 15:15:47 -07:00
parent 9d96f58f5f
commit bbe8836494
2 changed files with 5 additions and 5 deletions

View File

@ -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)

View File

@ -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):