project: simplify GetRemote a bit

We almost always use self.remote.name when calling self.GetRemote,
so make that the default to simplify the code a bit.

Change-Id: Ifdf6e1370d6b8963b44e6d384b0fac8fa5c4f2ba
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/343184
Tested-by: Mike Frysinger <vapier@google.com>
Reviewed-by: LaMont Jones <lamontjones@google.com>
This commit is contained in:
Mike Frysinger 2022-07-10 04:56:04 -04:00
parent ac76fd3e3a
commit dede564c3d
3 changed files with 18 additions and 14 deletions

View File

@ -284,7 +284,7 @@ class _XmlSubmanifest:
if self.project: if self.project:
manifestUrl = remote.ToRemoteSpec(self.project).url manifestUrl = remote.ToRemoteSpec(self.project).url
else: else:
manifestUrl = mp.GetRemote(mp.remote.name).url manifestUrl = mp.GetRemote().url
manifestName = self.manifestName or 'default.xml' manifestName = self.manifestName or 'default.xml'
revision = self.revision or self.name revision = self.revision or self.name
path = self.path or revision.split('/')[-1] path = self.path or revision.split('/')[-1]
@ -1385,7 +1385,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
def _AddMetaProjectMirror(self, m): def _AddMetaProjectMirror(self, m):
name = None name = None
m_url = m.GetRemote(m.remote.name).url m_url = m.GetRemote().url
if m_url.endswith('/.git'): if m_url.endswith('/.git'):
raise ManifestParseError('refusing to mirror %s' % m_url) raise ManifestParseError('refusing to mirror %s' % m_url)

View File

@ -686,9 +686,13 @@ class Project(object):
self._userident_name = '' self._userident_name = ''
self._userident_email = '' self._userident_email = ''
def GetRemote(self, name): def GetRemote(self, name=None):
"""Get the configuration for a single remote. """Get the configuration for a single remote.
Defaults to the current project's remote.
""" """
if name is None:
name = self.remote.name
return self.config.GetRemote(name) return self.config.GetRemote(name)
def GetBranch(self, name): def GetBranch(self, name):
@ -1282,7 +1286,7 @@ class Project(object):
if self.revisionId: if self.revisionId:
return self.revisionId return self.revisionId
rem = self.GetRemote(self.remote.name) rem = self.GetRemote()
rev = rem.ToLocal(self.revisionExpr) rev = rem.ToLocal(self.revisionExpr)
if all_refs is not None and rev in all_refs: if all_refs is not None and rev in all_refs:
@ -1474,7 +1478,7 @@ class Project(object):
"discarding %d commits removed from upstream", "discarding %d commits removed from upstream",
len(local_changes) - cnt_mine) len(local_changes) - cnt_mine)
branch.remote = self.GetRemote(self.remote.name) branch.remote = self.GetRemote()
if not ID_RE.match(self.revisionExpr): if not ID_RE.match(self.revisionExpr):
# in case of manifest sync the revisionExpr might be a SHA1 # in case of manifest sync the revisionExpr might be a SHA1
branch.merge = self.revisionExpr branch.merge = self.revisionExpr
@ -1532,7 +1536,7 @@ class Project(object):
def DownloadPatchSet(self, change_id, patch_id): def DownloadPatchSet(self, change_id, patch_id):
"""Download a single patch set of a single change to FETCH_HEAD. """Download a single patch set of a single change to FETCH_HEAD.
""" """
remote = self.GetRemote(self.remote.name) remote = self.GetRemote()
cmd = ['fetch', remote.name] cmd = ['fetch', remote.name]
cmd.append('refs/changes/%2.2d/%d/%d' cmd.append('refs/changes/%2.2d/%d/%d'
@ -1680,7 +1684,7 @@ class Project(object):
capture_stderr=True).Wait() == 0 capture_stderr=True).Wait() == 0
branch = self.GetBranch(name) branch = self.GetBranch(name)
branch.remote = self.GetRemote(self.remote.name) branch.remote = self.GetRemote()
branch.merge = branch_merge branch.merge = branch_merge
if not branch.merge.startswith('refs/') and not ID_RE.match(branch_merge): if not branch.merge.startswith('refs/') and not ID_RE.match(branch_merge):
branch.merge = R_HEADS + branch_merge branch.merge = R_HEADS + branch_merge
@ -2048,7 +2052,7 @@ class Project(object):
self.bare_git.rev_list('-1', '--missing=allow-any', self.bare_git.rev_list('-1', '--missing=allow-any',
'%s^0' % self.revisionExpr, '--') '%s^0' % self.revisionExpr, '--')
if self.upstream: if self.upstream:
rev = self.GetRemote(self.remote.name).ToLocal(self.upstream) rev = self.GetRemote().ToLocal(self.upstream)
self.bare_git.rev_list('-1', '--missing=allow-any', self.bare_git.rev_list('-1', '--missing=allow-any',
'%s^0' % rev, '--') '%s^0' % rev, '--')
self.bare_git.merge_base('--is-ancestor', self.revisionExpr, rev) self.bare_git.merge_base('--is-ancestor', self.revisionExpr, rev)
@ -2339,7 +2343,7 @@ class Project(object):
if initial and (self.manifest.manifestProject.depth or self.clone_depth): if initial and (self.manifest.manifestProject.depth or self.clone_depth):
return False return False
remote = self.GetRemote(self.remote.name) remote = self.GetRemote()
bundle_url = remote.url + '/clone.bundle' bundle_url = remote.url + '/clone.bundle'
bundle_url = GitConfig.ForUser().UrlInsteadOf(bundle_url) bundle_url = GitConfig.ForUser().UrlInsteadOf(bundle_url)
if GetSchemeFromUrl(bundle_url) not in ('http', 'https', if GetSchemeFromUrl(bundle_url) not in ('http', 'https',
@ -2660,7 +2664,7 @@ class Project(object):
def _InitRemote(self): def _InitRemote(self):
if self.remote.url: if self.remote.url:
remote = self.GetRemote(self.remote.name) remote = self.GetRemote()
remote.url = self.remote.url remote.url = self.remote.url
remote.pushUrl = self.remote.pushUrl remote.pushUrl = self.remote.pushUrl
remote.review = self.remote.review remote.review = self.remote.review
@ -2710,7 +2714,7 @@ class Project(object):
dst = self.revisionId + '^0' dst = self.revisionId + '^0'
active_git.UpdateRef(ref, dst, message=msg, detach=True) active_git.UpdateRef(ref, dst, message=msg, detach=True)
else: else:
remote = self.GetRemote(self.remote.name) remote = self.GetRemote()
dst = remote.ToLocal(self.revisionExpr) dst = remote.ToLocal(self.revisionExpr)
if cur != dst: if cur != dst:
msg = 'manifest set to %s' % self.revisionExpr msg = 'manifest set to %s' % self.revisionExpr
@ -3702,7 +3706,7 @@ class ManifestProject(MetaProject):
# Set the remote URL before the remote branch as we might need it below. # Set the remote URL before the remote branch as we might need it below.
if manifest_url: if manifest_url:
r = self.GetRemote(self.remote.name) r = self.GetRemote()
r.url = manifest_url r.url = manifest_url
r.ResetFetch() r.ResetFetch()
r.Save() r.Save()
@ -3828,7 +3832,7 @@ class ManifestProject(MetaProject):
clone_bundle=clone_bundle, current_branch_only=current_branch_only, clone_bundle=clone_bundle, current_branch_only=current_branch_only,
tags=tags, submodules=submodules, clone_filter=clone_filter, tags=tags, submodules=submodules, clone_filter=clone_filter,
partial_clone_exclude=self.manifest.PartialCloneExclude): partial_clone_exclude=self.manifest.PartialCloneExclude):
r = self.GetRemote(self.remote.name) r = self.GetRemote()
print('fatal: cannot obtain manifest %s' % r.url, file=sys.stderr) print('fatal: cannot obtain manifest %s' % r.url, file=sys.stderr)
# Better delete the manifest git dir if we created it; otherwise next # Better delete the manifest git dir if we created it; otherwise next

View File

@ -33,7 +33,7 @@ class Version(Command, MirrorSafeCommand):
def Execute(self, opt, args): def Execute(self, opt, args):
rp = self.manifest.repoProject rp = self.manifest.repoProject
rem = rp.GetRemote(rp.remote.name) rem = rp.GetRemote()
branch = rp.GetBranch('default') branch = rp.GetBranch('default')
# These might not be the same. Report them both. # These might not be the same. Report them both.