Skip to content

Commit 8d37f61

Browse files
Gavin MakLUCI
Gavin Mak
authored and
LUCI
committed
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 <[email protected]> Tested-by: Gavin Mak <[email protected]> Commit-Queue: Gavin Mak <[email protected]>
1 parent 1acbc14 commit 8d37f61

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

git_superproject.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import sys
2929
import time
3030
from typing import NamedTuple
31+
import urllib.parse
3132

3233
from git_command import git_require
3334
from git_command import GitCommand
@@ -140,6 +141,23 @@ def manifest_path(self):
140141
self._manifest_path if os.path.exists(self._manifest_path) else None
141142
)
142143

144+
@property
145+
def repo_id(self):
146+
"""Returns the repo ID for the superproject.
147+
148+
For example, if the superproject points to:
149+
https://android-review.googlesource.com/platform/superproject/
150+
Then the repo_id would be:
151+
android/platform/superproject
152+
"""
153+
if review_url := self.remote.review:
154+
parsed_url = urllib.parse.urlparse(review_url)
155+
if netloc := parsed_url.netloc:
156+
parts = netloc.split("-review", 1)
157+
host = parts[0]
158+
return f"{host}/{self.name}"
159+
return None
160+
143161
def _LogMessage(self, fmt, *inputs):
144162
"""Logs message to stderr and _git_event_log."""
145163
message = f"{self._LogMessagePrefix()} {fmt.format(*inputs)}"

subcmds/upload.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,13 @@ def _ExpandCommaList(value):
628628
branch.uploaded = False
629629
return
630630

631+
# If using superproject, add the root repo as a push option.
632+
manifest = branch.project.manifest
633+
push_options = list(opt.push_options)
634+
sp = manifest.superproject
635+
if sp and sp.repo_id and manifest.manifestProject.use_superproject:
636+
push_options.append(f"custom-keyed-value=rootRepo:{sp.repo_id}")
637+
631638
branch.UploadForReview(
632639
people,
633640
dryrun=opt.dryrun,
@@ -640,7 +647,7 @@ def _ExpandCommaList(value):
640647
ready=opt.ready,
641648
dest_branch=destination,
642649
validate_certs=opt.validate_certs,
643-
push_options=opt.push_options,
650+
push_options=push_options,
644651
patchset_description=opt.patchset_description,
645652
)
646653

0 commit comments

Comments
 (0)