[git_cl] Remove uses of RunGit which interact with git config.

The previous interactions were incorrect w.r.t. scm.GIT's config
cache.

This moves depot_tools towards having one fewer git wrapper
(converging towards scm.GIT).

R=ayatane, yiwzhang@google.com

Change-Id: I507628b53f6a87a1eecbbe3e1e27c1eb6af3b878
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5648617
Auto-Submit: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Yiwei Zhang <yiwzhang@google.com>
This commit is contained in:
Robert Iannucci
2024-07-23 16:32:51 +00:00
committed by LUCI CQ
parent 1a616deaac
commit a6502426b5
3 changed files with 90 additions and 112 deletions

20
scm.py
View File

@@ -172,14 +172,19 @@ class CachedGitConfigState(object):
"""Returns all values of `key` as a list of strings."""
return self._maybe_load_config().get(key, [])
def YieldConfigRegexp(self, pattern: str) -> Iterable[Tuple[str, str]]:
def YieldConfigRegexp(self, pattern: Optional[str]) -> Iterable[Tuple[str, str]]:
"""Yields (key, value) pairs for any config keys matching `pattern`.
This use re.match, so `pattern` needs to be for the entire config key.
If pattern is None, this returns all config items.
"""
p = re.compile(pattern)
if pattern is None:
pred = lambda _: True
else:
pred = re.compile(pattern).match
for name, values in sorted(self._maybe_load_config().items()):
if p.match(name):
if pred(name):
for value in values:
yield name, value
@@ -515,8 +520,13 @@ class GIT(object):
return GIT._get_config_state(cwd).GetConfigList(key)
@staticmethod
def YieldConfigRegexp(cwd: str, pattern: str) -> Iterable[Tuple[str, str]]:
"""Yields (key, value) pairs for any config keys matching `pattern`."""
def YieldConfigRegexp(cwd: str, pattern: Optional[str] = None) -> Iterable[Tuple[str, str]]:
"""Yields (key, value) pairs for any config keys matching `pattern`.
This use re.match, so `pattern` needs to be for the entire config key.
If pattern is None, this returns all config items.
"""
yield from GIT._get_config_state(cwd).YieldConfigRegexp(pattern)
@staticmethod