ReviewDbBatchUpdate: Avoid NPE when updating All-Users

If one change-update in a batch affects All-Users it is assumed that
all ChangeTasks updates NoteDb. This is not true when a stack of
changes is pushed and the changes(s) at the bottom of the stack are not
updated, existing last patchset is pushed.

Bug: Issue 11442
Change-Id: I0c828635920cc437da3da20785d3882a2e68d086
This commit is contained in:
Sven Selberg
2019-09-12 13:28:15 +02:00
parent c3d8920445
commit ad38bbb299
2 changed files with 15 additions and 0 deletions

View File

@@ -548,6 +548,9 @@ public class ReviewDbBatchUpdate extends BatchUpdate {
int objs = 0;
BatchRefUpdate allUsersRefUpdate = allUsersRepo.getRefDatabase().newBatchUpdate();
for (ChangeTask task : tasks) {
if (task.noteDbResult == null) {
continue;
}
for (ReceiveCommand cmd : task.noteDbResult.allUsersCommands()) {
allUsersRefUpdate.addCommand(cmd);
}

View File

@@ -2202,6 +2202,18 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
assertThat(getPublishedComments(r.getChangeId())).isEmpty();
}
@Test
public void noEditAndUpdateAllUsersInSameChangeStack() throws Exception {
assume().that(notesMigration.readChanges()).isTrue();
List<RevCommit> commits = createChanges(2, "refs/for/master");
String id2 = byCommit(commits.get(1)).change().getKey().get();
addDraft(id2, commits.get(1).name(), newDraft(FILE_NAME, 1, "comment2"));
// First change in stack unchanged.
RevCommit unChanged = commits.remove(0);
// Publishing draft comments on change 2 updates All-Users.
amendChanges(unChanged.toObjectId(), commits, "refs/for/master%publish-comments");
}
@Test
public void pushWithDraftOptionIsDisabledPerDefault() throws Exception {
for (String ref : ImmutableSet.of("refs/drafts/master", "refs/for/master%draft")) {