From 8d37f6147174fe170cc00a1d82b1cc5fe8ec0a7b Mon Sep 17 00:00:00 2001 From: Gavin Mak Date: Mon, 5 May 2025 14:13:48 -0700 Subject: upload: Add superproject identifier as push option When uploading, add the root superproject repo as a push option in the format `-o custom-keyed-value=rootRepo:$HOST/$PROJECT`. Bug: b/401147338 Change-Id: I00230256eb7ae307b03840bb4090c28dc8a0505e Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/472601 Reviewed-by: Josip Sokcevic Tested-by: Gavin Mak Commit-Queue: Gavin Mak --- git_superproject.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'git_superproject.py') diff --git a/git_superproject.py b/git_superproject.py index ce8161fd..aba836a3 100644 --- a/git_superproject.py +++ b/git_superproject.py @@ -28,6 +28,7 @@ import os import sys import time from typing import NamedTuple +import urllib.parse from git_command import git_require from git_command import GitCommand @@ -140,6 +141,23 @@ class Superproject: self._manifest_path if os.path.exists(self._manifest_path) else None ) + @property + def repo_id(self): + """Returns the repo ID for the superproject. + + For example, if the superproject points to: + https://android-review.googlesource.com/platform/superproject/ + Then the repo_id would be: + android/platform/superproject + """ + if review_url := self.remote.review: + parsed_url = urllib.parse.urlparse(review_url) + if netloc := parsed_url.netloc: + parts = netloc.split("-review", 1) + host = parts[0] + return f"{host}/{self.name}" + return None + def _LogMessage(self, fmt, *inputs): """Logs message to stderr and _git_event_log.""" message = f"{self._LogMessagePrefix()} {fmt.format(*inputs)}" -- cgit v1.2.3-54-g00ecf