mirror of
https://gerrit.googlesource.com/git-repo
synced 2026-11-13 07:47:23 +00:00
style: use import git_config everywhere
Align with Google style guides and `import git_config` as a module rather than import symbols out of it. Change-Id: I467f1f8c0868c53b71917ca0a9610606e1ce4d83 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/654811 Reviewed-by: Brian Gan <brgan@google.com> Commit-Queue: Mike Frysinger <vapier@google.com> Tested-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
1 parent
e045aa19d8
commit
cc3f52cd6c
8 files changed
+65
-51
No files matched your search
@@ -9,7 +9,6 @@ per-file-ignores =
|
||||
command.py: IMR241,
|
||||
git_command.py: IMR241,
|
||||
git_status.py: IMR241,
|
||||
git_superproject.py: IMR241,
|
||||
git_trace2_event_log.py: IMR241,
|
||||
main.py: IMR241,
|
||||
manifest_xml.py: IMR241,
|
||||
|
||||
+5
-6
@@ -33,8 +33,7 @@ from typing import NamedTuple
|
||||
import urllib.parse
|
||||
|
||||
import git_command
|
||||
from git_config import IsId
|
||||
from git_config import RepoConfig
|
||||
import git_config
|
||||
import platform_utils
|
||||
|
||||
|
||||
@@ -324,7 +323,7 @@ class Superproject:
|
||||
# creating a local branch of the same name.
|
||||
refspec = (
|
||||
self.revision
|
||||
if IsId(self.revision)
|
||||
if git_config.IsId(self.revision)
|
||||
else f"{self.revision}:{self.revision}"
|
||||
)
|
||||
cmd.append(refspec)
|
||||
@@ -429,7 +428,7 @@ class Superproject:
|
||||
|
||||
if not self._Init():
|
||||
return SyncResult(False, should_exit)
|
||||
if IsId(self.revision) and self.commit_id:
|
||||
if git_config.IsId(self.revision) and self.commit_id:
|
||||
return SyncResult(True, False)
|
||||
if not self._Fetch():
|
||||
return SyncResult(False, should_exit)
|
||||
@@ -568,7 +567,7 @@ class Superproject:
|
||||
@functools.lru_cache(maxsize=None)
|
||||
def _UseSuperprojectFromConfiguration():
|
||||
"""Returns the user choice of whether to use superproject."""
|
||||
user_cfg = RepoConfig.ForUser()
|
||||
user_cfg = git_config.RepoConfig.ForUser()
|
||||
time_now = int(time.time())
|
||||
|
||||
user_value = user_cfg.GetBoolean("repo.superprojectChoice")
|
||||
@@ -602,7 +601,7 @@ def _UseSuperprojectFromConfiguration():
|
||||
return user_value
|
||||
|
||||
# We don't have an unexpired choice, ask for one.
|
||||
system_cfg = RepoConfig.ForSystem()
|
||||
system_cfg = git_config.RepoConfig.ForSystem()
|
||||
system_value = system_cfg.GetBoolean("repo.superprojectChoice")
|
||||
if system_value:
|
||||
# The system configuration is proposing that we should enable the
|
||||
|
||||
@@ -48,7 +48,7 @@ import editor
|
||||
import error
|
||||
import event_log
|
||||
import git_command
|
||||
from git_config import RepoConfig
|
||||
import git_config
|
||||
from git_trace2_event_log import EventLog
|
||||
from manifest_xml import RepoClient
|
||||
import pager
|
||||
@@ -229,9 +229,9 @@ class _Repo:
|
||||
return name, []
|
||||
|
||||
key = f"alias.{name}"
|
||||
alias = RepoConfig.ForRepository(self.repodir).GetString(key)
|
||||
alias = git_config.RepoConfig.ForRepository(self.repodir).GetString(key)
|
||||
if alias is None:
|
||||
alias = RepoConfig.ForUser().GetString(key)
|
||||
alias = git_config.RepoConfig.ForUser().GetString(key)
|
||||
if alias is None:
|
||||
return name, []
|
||||
|
||||
@@ -289,7 +289,7 @@ class _Repo:
|
||||
return result
|
||||
|
||||
def _autocorrect_command_name(
|
||||
self, name: str, config: RepoConfig
|
||||
self, name: str, config: git_config.RepoConfig
|
||||
) -> Optional[str]:
|
||||
"""Autocorrect command name based on user's git config."""
|
||||
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ import urllib.parse
|
||||
import xml.dom.minidom
|
||||
|
||||
import error
|
||||
from git_config import GitConfig
|
||||
import git_config
|
||||
import git_refs
|
||||
from git_superproject import Superproject
|
||||
import platform_utils
|
||||
@@ -414,7 +414,7 @@ class XmlManifest:
|
||||
default_groups: a string, the default manifest groups to use.
|
||||
"""
|
||||
# TODO(vapier): Move this out of this class.
|
||||
self.globalConfig = GitConfig.ForUser()
|
||||
self.globalConfig = git_config.GitConfig.ForUser()
|
||||
|
||||
self.repodir = os.path.abspath(repodir)
|
||||
self._CheckLocalPath(submanifest_path)
|
||||
|
||||
+36
-26
@@ -36,11 +36,7 @@ import color
|
||||
import error
|
||||
import fetch
|
||||
import git_command
|
||||
from git_config import Branch
|
||||
from git_config import GetSchemeFromUrl
|
||||
from git_config import GetUrlCookieFile
|
||||
from git_config import GitConfig
|
||||
from git_config import IsId
|
||||
import git_config
|
||||
import git_refs
|
||||
import git_status
|
||||
import git_superproject
|
||||
@@ -237,7 +233,7 @@ class ReviewableBranch:
|
||||
def __init__(
|
||||
self,
|
||||
project: "Project",
|
||||
branch: Branch,
|
||||
branch: git_config.Branch,
|
||||
base: str,
|
||||
ignore_remote_commits: bool = False,
|
||||
) -> None:
|
||||
@@ -788,7 +784,11 @@ class Project:
|
||||
def SetRevision(self, revisionExpr, revisionId=None):
|
||||
"""Set revisionId based on revision expression and id"""
|
||||
self.revisionExpr = revisionExpr
|
||||
if revisionId is None and revisionExpr and IsId(revisionExpr):
|
||||
if (
|
||||
revisionId is None
|
||||
and revisionExpr
|
||||
and git_config.IsId(revisionExpr)
|
||||
):
|
||||
self.revisionId = self.revisionExpr
|
||||
else:
|
||||
self.revisionId = revisionId
|
||||
@@ -803,7 +803,7 @@ class Project:
|
||||
self.worktree = None
|
||||
self.relpath = relpath
|
||||
|
||||
self.config = GitConfig.ForRepository(
|
||||
self.config = git_config.GitConfig.ForRepository(
|
||||
gitdir=self.gitdir, defaults=self.manifest.globalConfig
|
||||
)
|
||||
|
||||
@@ -1767,7 +1767,7 @@ class Project:
|
||||
|
||||
# Query the target hash from remote to see if we are up-to-date.
|
||||
target_hash = None
|
||||
if IsId(self.revisionExpr):
|
||||
if git_config.IsId(self.revisionExpr):
|
||||
target_hash = self.revisionExpr
|
||||
else:
|
||||
output = self._LsRemote(self.upstream or self.revisionExpr)
|
||||
@@ -2033,7 +2033,7 @@ class Project:
|
||||
has_shallow = self._HasShallow()
|
||||
skip_fetch = (
|
||||
optimized_fetch
|
||||
and IsId(self.revisionExpr)
|
||||
and git_config.IsId(self.revisionExpr)
|
||||
and self._CheckForImmutableRevision(
|
||||
use_superproject=use_superproject,
|
||||
depth=depth,
|
||||
@@ -2484,7 +2484,7 @@ class Project:
|
||||
)
|
||||
|
||||
branch.remote = self.GetRemote()
|
||||
if not IsId(self.revisionExpr):
|
||||
if not git_config.IsId(self.revisionExpr):
|
||||
# In case of manifest sync the revisionExpr might be a SHA1.
|
||||
branch.merge = self.revisionExpr
|
||||
if not branch.merge.startswith("refs/"):
|
||||
@@ -2780,7 +2780,9 @@ class Project:
|
||||
branch = self.GetBranch(name)
|
||||
branch.remote = self.GetRemote()
|
||||
branch.merge = branch_merge
|
||||
if not branch.merge.startswith("refs/") and not IsId(branch_merge):
|
||||
if not branch.merge.startswith("refs/") and not git_config.IsId(
|
||||
branch_merge
|
||||
):
|
||||
branch.merge = git_refs.R_HEADS + branch_merge
|
||||
|
||||
if revision is None:
|
||||
@@ -2934,7 +2936,7 @@ class Project:
|
||||
)
|
||||
b.Wait()
|
||||
finally:
|
||||
if IsId(old):
|
||||
if git_config.IsId(old):
|
||||
self.bare_git.DetachHead(old)
|
||||
else:
|
||||
branch = (
|
||||
@@ -3293,7 +3295,7 @@ class Project:
|
||||
) -> bool:
|
||||
"""Whether to verify upstream ancestry during immutable revision
|
||||
check."""
|
||||
if not (IsId(self.revisionExpr) and self.upstream):
|
||||
if not (git_config.IsId(self.revisionExpr) and self.upstream):
|
||||
return False
|
||||
if self._UseSuperprojectForUpstream(use_superproject):
|
||||
return True
|
||||
@@ -3386,9 +3388,9 @@ class Project:
|
||||
# let fetchcmd resolve REPO_RREV from its remote without a separate
|
||||
# git ls-remote round-trip.
|
||||
repo_trev = None
|
||||
if self.revisionId and IsId(self.revisionId):
|
||||
if self.revisionId and git_config.IsId(self.revisionId):
|
||||
repo_trev = self.revisionId
|
||||
elif self.revisionExpr and IsId(self.revisionExpr):
|
||||
elif self.revisionExpr and git_config.IsId(self.revisionExpr):
|
||||
repo_trev = self.revisionExpr
|
||||
|
||||
env = os.environ.copy()
|
||||
@@ -3435,7 +3437,7 @@ class Project:
|
||||
self._RefreshConfigIfModified(config_stat)
|
||||
|
||||
# Verify postconditions.
|
||||
if not IsId(self.revisionExpr):
|
||||
if not git_config.IsId(self.revisionExpr):
|
||||
try:
|
||||
ref_name = self.GetRemote().ToLocal(self.revisionExpr)
|
||||
except error.GitError as e:
|
||||
@@ -3489,7 +3491,11 @@ class Project:
|
||||
if not default:
|
||||
return None
|
||||
for cand in (default.upstreamExpr, default.revisionExpr):
|
||||
if cand and not IsId(cand) and not cand.startswith(git_refs.R_TAGS):
|
||||
if (
|
||||
cand
|
||||
and not git_config.IsId(cand)
|
||||
and not cand.startswith(git_refs.R_TAGS)
|
||||
):
|
||||
return cand
|
||||
return None
|
||||
|
||||
@@ -3524,7 +3530,7 @@ class Project:
|
||||
if depth:
|
||||
current_branch_only = True
|
||||
|
||||
is_sha1 = IsId(self.revisionExpr)
|
||||
is_sha1 = git_config.IsId(self.revisionExpr)
|
||||
upstream = self.upstream
|
||||
|
||||
if current_branch_only:
|
||||
@@ -3540,7 +3546,7 @@ class Project:
|
||||
upstream = self._GetUpstreamFallback()
|
||||
|
||||
if upstream:
|
||||
current_branch_only = not IsId(upstream)
|
||||
current_branch_only = not git_config.IsId(upstream)
|
||||
else:
|
||||
current_branch_only = False
|
||||
|
||||
@@ -3895,8 +3901,8 @@ class Project:
|
||||
|
||||
remote = self.GetRemote()
|
||||
bundle_url = remote.url + "/clone.bundle"
|
||||
bundle_url = GitConfig.ForUser().UrlInsteadOf(bundle_url)
|
||||
if GetSchemeFromUrl(bundle_url) not in (
|
||||
bundle_url = git_config.GitConfig.ForUser().UrlInsteadOf(bundle_url)
|
||||
if git_config.GetSchemeFromUrl(bundle_url) not in (
|
||||
"http",
|
||||
"https",
|
||||
"persistent-http",
|
||||
@@ -3966,7 +3972,7 @@ class Project:
|
||||
cmd += ["--continue-at", "%d" % (size,)]
|
||||
else:
|
||||
platform_utils.remove(tmpPath)
|
||||
with GetUrlCookieFile(srcUrl, quiet) as (cookiefile, proxy):
|
||||
with git_config.GetUrlCookieFile(srcUrl, quiet) as (cookiefile, proxy):
|
||||
if cookiefile:
|
||||
cmd += ["--cookie", cookiefile]
|
||||
if proxy:
|
||||
@@ -4394,7 +4400,7 @@ class Project:
|
||||
prefix=TMP_GITDIR_PREFIX,
|
||||
dir=os.path.dirname(self.gitdir),
|
||||
)
|
||||
curr_config = GitConfig.ForRepository(
|
||||
curr_config = git_config.GitConfig.ForRepository(
|
||||
gitdir=tmp_gitdir, defaults=self.manifest.globalConfig
|
||||
)
|
||||
curr_gitdir = tmp_gitdir
|
||||
@@ -5337,7 +5343,7 @@ class Project:
|
||||
# Normalize commit IDs to canonical lowercase hexadecimal,
|
||||
# matching the output format of `git rev-parse`.
|
||||
line_lower = line.lower()
|
||||
if IsId(line_lower):
|
||||
if git_config.IsId(line_lower):
|
||||
return line_lower
|
||||
return None
|
||||
|
||||
@@ -6212,7 +6218,11 @@ class ManifestProject(MetaProject):
|
||||
if verbose:
|
||||
print(
|
||||
"Downloading manifest from %s"
|
||||
% (GitConfig.ForUser().UrlInsteadOf(manifest_url),),
|
||||
% (
|
||||
git_config.GitConfig.ForUser().UrlInsteadOf(
|
||||
manifest_url
|
||||
),
|
||||
),
|
||||
file=sys.stderr,
|
||||
)
|
||||
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ from command import Command
|
||||
from command import DEFAULT_LOCAL_JOBS
|
||||
import error
|
||||
import git_command
|
||||
from git_config import IsImmutable
|
||||
import git_config
|
||||
from progress import Progress
|
||||
import repo_logging
|
||||
|
||||
@@ -87,7 +87,7 @@ revision specified in the manifest.
|
||||
branch_merge = ""
|
||||
err = None
|
||||
project = cls.get_parallel_context()["projects"][project_idx]
|
||||
if IsImmutable(project.revisionExpr):
|
||||
if git_config.IsImmutable(project.revisionExpr):
|
||||
if project.dest_branch:
|
||||
branch_merge = project.dest_branch
|
||||
else:
|
||||
|
||||
+3
-4
@@ -60,8 +60,7 @@ from command import WORKER_BATCH_SIZE
|
||||
import error
|
||||
import event_log
|
||||
import git_command
|
||||
from git_config import GetUrlCookieFile
|
||||
from git_config import RepoConfig
|
||||
import git_config
|
||||
import git_refs
|
||||
import git_superproject
|
||||
from hooks import RepoHook
|
||||
@@ -2533,7 +2532,7 @@ later is required to fix a server side protocol bug.
|
||||
checkout_pref = getattr(manifest.manifestProject, "smart_sync", None)
|
||||
if not isinstance(checkout_pref, bool):
|
||||
checkout_pref = None
|
||||
user_pref = RepoConfig.ForUser().GetBoolean("sync.smartsync")
|
||||
user_pref = git_config.RepoConfig.ForUser().GetBoolean("sync.smartsync")
|
||||
default_allowed = (
|
||||
opt.smart_sync is None
|
||||
and not opt.smart_tag
|
||||
@@ -3652,7 +3651,7 @@ class PersistentTransport(xmlrpc.client.Transport):
|
||||
self.proxy = proxy
|
||||
|
||||
def request(self, host, handler, request_body, verbose=False):
|
||||
with GetUrlCookieFile(self.orig_host, not verbose) as (
|
||||
with git_config.GetUrlCookieFile(self.orig_host, not verbose) as (
|
||||
cookiefile,
|
||||
cookie_proxy,
|
||||
):
|
||||
|
||||
@@ -34,6 +34,7 @@ import pytest
|
||||
import command
|
||||
import error
|
||||
import git_command
|
||||
import git_config
|
||||
import manifest_xml
|
||||
from project import SyncNetworkHalfResult
|
||||
from subcmds import sync
|
||||
@@ -556,7 +557,9 @@ def test_cli_smart_sync_with_config(
|
||||
cmd = sync.Sync(manifest=manifest)
|
||||
opts, args = cmd.OptionParser.parse_args(argv)
|
||||
cmd.ValidateOptions(opts, args)
|
||||
with mock.patch.object(sync.RepoConfig, "ForUser", return_value=user_cfg):
|
||||
with mock.patch.object(
|
||||
git_config.RepoConfig, "ForUser", return_value=user_cfg
|
||||
):
|
||||
implicit = cmd._ResolveSmartSyncOption(opts, manifest)
|
||||
assert opts.smart_sync == expected_smart_sync
|
||||
assert implicit == expected_implicit
|
||||
@@ -604,7 +607,9 @@ def test_user_config_smart_sync(
|
||||
cmd = sync.Sync(manifest=manifest)
|
||||
opts, args = cmd.OptionParser.parse_args(argv)
|
||||
cmd.ValidateOptions(opts, args)
|
||||
with mock.patch.object(sync.RepoConfig, "ForUser", return_value=user_cfg):
|
||||
with mock.patch.object(
|
||||
git_config.RepoConfig, "ForUser", return_value=user_cfg
|
||||
):
|
||||
implicit = cmd._ResolveSmartSyncOption(opts, manifest)
|
||||
user_cfg.GetBoolean.assert_called_once_with("sync.smartsync")
|
||||
assert opts.smart_sync == expected_smart_sync
|
||||
@@ -623,7 +628,7 @@ def test_user_config_smart_sync_from_file(
|
||||
) -> None:
|
||||
"""Tests that sync.smartsync is read from ~/.repoconfig/config."""
|
||||
# ForUser() caches its instance process-wide; make it pick up this HOME.
|
||||
monkeypatch.setattr(sync.RepoConfig, "_ForUser", None)
|
||||
monkeypatch.setattr(git_config.RepoConfig, "_ForUser", None)
|
||||
monkeypatch.delenv("REPO_CONFIG_DIR", raising=False)
|
||||
cfg_dir = tmp_home_dir / ".repoconfig"
|
||||
cfg_dir.mkdir()
|
||||
@@ -685,7 +690,9 @@ def test_cli_manifest_server_credentials(
|
||||
|
||||
cmd = sync.Sync(manifest=manifest)
|
||||
opts, args = cmd.OptionParser.parse_args(argv)
|
||||
with mock.patch.object(sync.RepoConfig, "ForUser", return_value=user_cfg):
|
||||
with mock.patch.object(
|
||||
git_config.RepoConfig, "ForUser", return_value=user_cfg
|
||||
):
|
||||
if expected_exception:
|
||||
with pytest.raises(expected_exception):
|
||||
cmd.ValidateOptions(opts, args)
|
||||
@@ -1862,7 +1869,7 @@ class SyncCommand(unittest.TestCase):
|
||||
user_cfg = mock.MagicMock()
|
||||
user_cfg.GetBoolean.return_value = False
|
||||
with mock.patch.object(
|
||||
sync.RepoConfig, "ForUser", return_value=user_cfg
|
||||
git_config.RepoConfig, "ForUser", return_value=user_cfg
|
||||
):
|
||||
with mock.patch.object(self.cmd, "_SmartSyncSetup") as mock_setup:
|
||||
with mock.patch.object(self.cmd, "_UpdateRepoProject"):
|
||||
@@ -1885,7 +1892,7 @@ class SyncCommand(unittest.TestCase):
|
||||
user_cfg = mock.MagicMock()
|
||||
user_cfg.GetBoolean.return_value = True
|
||||
with mock.patch.object(
|
||||
sync.RepoConfig, "ForUser", return_value=user_cfg
|
||||
git_config.RepoConfig, "ForUser", return_value=user_cfg
|
||||
):
|
||||
with mock.patch.object(
|
||||
self.cmd,
|
||||
|
||||
Reference in new issue
Block a user