mirror of
https://gerrit.googlesource.com/git-repo
synced 2026-10-15 01:47:08 +00:00
upload: reuse the worker current-branch result
Carry the current branch through _GatherOne so the parent can report a failed current-branch upload without resolving HEAD a second time. Bug: 553599402 Change-Id: I3fc54be6c10c30470e14f792ff68c0a396519327 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/623905 Reviewed-by: Brian Gan <brgan@google.com> Commit-Queue: Gavin Mak <gavinmak@google.com> Tested-by: Gavin Mak <gavinmak@google.com>
This commit is contained in:
1 parent
5e8d2a6e3a
commit
d88ce8d952
2 files changed
+24
-3
No files matched your search
+4
-3
@@ -721,13 +721,14 @@ Gerrit Code Review: https://www.gerritcodereview.com/
|
||||
def _GatherOne(cls, opt, project_idx):
|
||||
"""Figure out the upload status for |project|."""
|
||||
project = cls.get_parallel_context()["projects"][project_idx]
|
||||
cbr = None
|
||||
if opt.current_branch:
|
||||
cbr = project.CurrentBranch
|
||||
up_branch = project.GetUploadableBranch(cbr)
|
||||
avail = [up_branch] if up_branch else None
|
||||
else:
|
||||
avail = project.GetUploadableBranches(opt.branch)
|
||||
return (project_idx, avail)
|
||||
return (project_idx, avail, cbr)
|
||||
|
||||
def Execute(self, opt, args):
|
||||
projects = self.GetProjects(
|
||||
@@ -737,7 +738,7 @@ Gerrit Code Review: https://www.gerritcodereview.com/
|
||||
def _ProcessResults(_pool, _out, results):
|
||||
pending = []
|
||||
for result in results:
|
||||
project_idx, avail = result
|
||||
project_idx, avail, current_branch = result
|
||||
project = projects[project_idx]
|
||||
if avail is None:
|
||||
logger.error(
|
||||
@@ -745,7 +746,7 @@ Gerrit Code Review: https://www.gerritcodereview.com/
|
||||
"You might be able to fix the branch by running:\n"
|
||||
" git branch --set-upstream-to m/%s",
|
||||
project.RelPath(local=opt.this_manifest_only),
|
||||
project.CurrentBranch,
|
||||
current_branch,
|
||||
project.manifest.branch,
|
||||
)
|
||||
elif avail:
|
||||
|
||||
@@ -97,3 +97,23 @@ def test_GetMergeBranch_none_when_no_branch(cmd: upload.Upload) -> None:
|
||||
|
||||
res = cmd._GetMergeBranch(mock_project, local_branch=None)
|
||||
assert res == ""
|
||||
|
||||
|
||||
def test_GatherOne_returns_resolved_current_branch(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Upload error reporting reuses the branch gathered by the worker."""
|
||||
project = mock.MagicMock()
|
||||
project.CurrentBranch = "topic"
|
||||
branch = mock.sentinel.branch
|
||||
project.GetUploadableBranch.return_value = branch
|
||||
monkeypatch.setattr(
|
||||
upload.Upload,
|
||||
"get_parallel_context",
|
||||
lambda: {"projects": [project]},
|
||||
)
|
||||
opt = mock.MagicMock(current_branch=True)
|
||||
|
||||
assert upload.Upload._GatherOne(opt, 0) == (0, [branch], "topic")
|
||||
|
||||
project.GetUploadableBranch.assert_called_once_with("topic")
|
||||
Reference in new issue
Block a user