Receive: Only attempt to create UpdateGroupsRequest for patch-set refs

Before [1] all refs in existingRefs were guaranteed to be patchset refs,
whereas the refs taken from ReceivePackRefsCache are all refs in the
"refs/changes/*" namespace and these aren't guaranteed to be patchset
refs.
By getting the Patchset.Id from the refs in the UpdateGroupRequest
constructor we risk an NPE when a non-patchset ref is present in the
"refs/changes/*" namespace.

Filter out any non-patchset refs before attempting to create the
Patchset.Ids from them and pass the Patchset.Id instead of Ref to
UpdateGroupRequest constructor.

[1] https://gerrit-review.googlesource.com/c/gerrit/+/241932

Change-Id: Ibac9dc43b303d5cae86a209be782237259cca941
This commit is contained in:
Sven Selberg
2020-06-22 17:19:33 +02:00
parent aaab236700
commit a4c41c01be

View File

@@ -2144,9 +2144,10 @@ class ReceiveCommits {
// A's group.
// C) Commit is a PatchSet of a pre-existing change uploaded with a
// different target branch.
for (Ref ref : existingRefs) {
updateGroups.add(new UpdateGroupsRequest(ref, c));
}
existingRefs.stream()
.map(r -> PatchSet.Id.fromRef(r.getName()))
.filter(Objects::nonNull)
.forEach(i -> updateGroups.add(new UpdateGroupsRequest(i, c)));
if (!(newChangeForAllNotInTarget || magicBranch.base != null)) {
continue;
}
@@ -3019,8 +3020,8 @@ class ReceiveCommits {
final RevCommit commit;
List<String> groups = ImmutableList.of();
UpdateGroupsRequest(Ref ref, RevCommit commit) {
this.psId = requireNonNull(PatchSet.Id.fromRef(ref.getName()));
UpdateGroupsRequest(PatchSet.Id psId, RevCommit commit) {
this.psId = psId;
this.commit = commit;
}