From fa224cdb07f4e7e8e8540bc4af6794d1350179ed Mon Sep 17 00:00:00 2001 From: Allen Li Date: Fri, 19 Jul 2024 23:12:07 +0000 Subject: [PATCH] [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 Reviewed-by: Robbie Iannucci Commit-Queue: Allen Li --- git_cl.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/git_cl.py b/git_cl.py index 8e92ee333..96759ac06 100755 --- a/git_cl.py +++ b/git_cl.py @@ -3703,7 +3703,6 @@ class GitAuthConfigChanger(object): def __init__( self, *, - host_shortname: str, mode: GitConfigMode, remote_url: str, set_config_func: Callable[..., None] = scm.GIT.SetConfig, @@ -3711,7 +3710,6 @@ class GitAuthConfigChanger(object): """Create a new GitAuthConfigChanger. Args: - host_shortname: Gerrit host shortname, e.g., chromium mode: How to configure auth remote_url: Git repository's remote URL, e.g., https://chromium.googlesource.com/chromium/tools/depot_tools.git @@ -3720,10 +3718,18 @@ class GitAuthConfigChanger(object): """ self.mode: GitConfigMode = mode - self._shortname: str = host_shortname self._remote_url: str = remote_url 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 def _base_url(self) -> str: # Base URL looks like https://chromium.googlesource.com/ @@ -3737,15 +3743,11 @@ class GitAuthConfigChanger(object): cl = Changelist() # chromium-review.googlesource.com 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 # https://chromium.googlesource.com/chromium/tools/depot_tools.git remote_url: str = cl.GetRemoteUrl() return cls( - host_shortname=host_shortname, mode=cls._infer_mode(gerrit_host), remote_url=remote_url, )