mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
[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:
20
scm.py
20
scm.py
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user