[git_cl] Add _shortname property

Removes redundant param

Bug: b/351071334
Change-Id: I1040f72df49851fe87e5ea9bf5e9e2fb50ca46b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5718640
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
Commit-Queue: Allen Li <ayatane@chromium.org>
changes/40/5718640/4
Allen Li 1 year ago committed by LUCI CQ
parent 1c81122f69
commit fa224cdb07

@ -3703,7 +3703,6 @@ class GitAuthConfigChanger(object):
def __init__( def __init__(
self, self,
*, *,
host_shortname: str,
mode: GitConfigMode, mode: GitConfigMode,
remote_url: str, remote_url: str,
set_config_func: Callable[..., None] = scm.GIT.SetConfig, set_config_func: Callable[..., None] = scm.GIT.SetConfig,
@ -3711,7 +3710,6 @@ class GitAuthConfigChanger(object):
"""Create a new GitAuthConfigChanger. """Create a new GitAuthConfigChanger.
Args: Args:
host_shortname: Gerrit host shortname, e.g., chromium
mode: How to configure auth mode: How to configure auth
remote_url: Git repository's remote URL, e.g., remote_url: Git repository's remote URL, e.g.,
https://chromium.googlesource.com/chromium/tools/depot_tools.git https://chromium.googlesource.com/chromium/tools/depot_tools.git
@ -3720,10 +3718,18 @@ class GitAuthConfigChanger(object):
""" """
self.mode: GitConfigMode = mode self.mode: GitConfigMode = mode
self._shortname: str = host_shortname
self._remote_url: str = remote_url self._remote_url: str = remote_url
self._set_config_func: Callable[..., str] = set_config_func self._set_config_func: Callable[..., str] = set_config_func
@functools.cached_property
def _shortname(self) -> str:
parts: urllib.parse.SplitResult = urllib.parse.urlsplit(
self._remote_url)
name: str = parts.netloc.split('.')[0]
if name.endswith('-review'):
name = name[:-len('-review')]
return name
@functools.cached_property @functools.cached_property
def _base_url(self) -> str: def _base_url(self) -> str:
# Base URL looks like https://chromium.googlesource.com/ # Base URL looks like https://chromium.googlesource.com/
@ -3737,15 +3743,11 @@ class GitAuthConfigChanger(object):
cl = Changelist() cl = Changelist()
# chromium-review.googlesource.com # chromium-review.googlesource.com
gerrit_host: str = cl.GetGerritHost() gerrit_host: str = cl.GetGerritHost()
# chromium
host_shortname: str = gerrit_host.split('.')[0][:-len('-review')]
# These depend on what the user set for their remote # These depend on what the user set for their remote
# https://chromium.googlesource.com/chromium/tools/depot_tools.git # https://chromium.googlesource.com/chromium/tools/depot_tools.git
remote_url: str = cl.GetRemoteUrl() remote_url: str = cl.GetRemoteUrl()
return cls( return cls(
host_shortname=host_shortname,
mode=cls._infer_mode(gerrit_host), mode=cls._infer_mode(gerrit_host),
remote_url=remote_url, remote_url=remote_url,
) )

Loading…
Cancel
Save