[scm] Add lock around all set calls

Bug: b/356935829
Change-Id: I886d20b71af26efd828d18cb1b01f1271f42d053
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5786165
Commit-Queue: Allen Li <ayatane@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
changes/65/5786165/3
Allen Li 11 months ago committed by LUCI CQ
parent 6a06d8934e
commit 39ca85acf5

@ -404,16 +404,18 @@ class GitConfigStateReal(GitConfigStateBase):
args = ['config', f'--{scope}', '--replace-all', key, value]
if value_pattern is not None:
args.append(value_pattern)
GIT.Capture(args, cwd=self.root)
with self._scope_lock(scope):
GIT.Capture(args, cwd=self.root)
def unset_config(self, key: str, *, scope: GitConfigScope,
missing_ok: bool):
# NOTE: `git config` already canonicalizes key.
accepted_retcodes = (0, 5) if missing_ok else (0, )
try:
GIT.Capture(['config', f'--{scope}', '--unset', key],
cwd=self.root,
accepted_retcodes=accepted_retcodes)
with self._scope_lock(scope):
GIT.Capture(['config', f'--{scope}', '--unset', key],
cwd=self.root,
accepted_retcodes=accepted_retcodes)
except subprocess2.CalledProcessError as cpe:
if cpe.returncode == 5:
if b'multiple values' in cpe.stderr:
@ -429,9 +431,10 @@ class GitConfigStateReal(GitConfigStateBase):
if value_pattern is not None:
args.append(value_pattern)
try:
GIT.Capture(args,
cwd=self.root,
accepted_retcodes=accepted_retcodes)
with self._scope_lock(scope):
GIT.Capture(args,
cwd=self.root,
accepted_retcodes=accepted_retcodes)
except subprocess2.CalledProcessError as cpe:
if cpe.returncode == 5:
raise GitConfigUnsetMissingValue(key, scope)

Loading…
Cancel
Save