In notedb change messages are stored as part of the commit messages on the refs/changes/XX/YYYY/meta branch. The order of the change messages is defined by the commit order and there is no need to sort the messages by commit timestamp. The current sorting of all change messages by commit timestamp does not work when commits have the same timestamp because then the order for these change messages is left as in the input and in the input the order may be wrong. Hence some change messages that have the same timestamp may be returned in the wrong order. As result some tests that check the correct order of the change messages do fail, because when running the tests it happens frequently that commits on the refs/changes/XX/YYYY/meta branch have the same timestamp. Add a new list for all change messages to ChangeNotesParser so that the order of all change messages can be preserved. So far we only preserved the order of the change messages for each patch set. Instead of sorting the change messages by date, now we just reverse this list. Reversion of the list is needed because the parsing is done from the tip of the branch and hence the newest change messages are parsed first. This fixes the RevisionIT#cherryPick() test when notedb is enabled. Change-Id: Iff497c4c19ad57d1b87fe58eee301ba841444762 Signed-off-by: Edwin Kempin <ekempin@google.com>
75 lines
2.5 KiB
Java
75 lines
2.5 KiB
Java
// Copyright (C) 2014 The Android Open Source Project
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package com.google.gerrit.server;
|
|
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
|
import com.google.gerrit.server.notedb.ChangeNotes;
|
|
import com.google.gerrit.server.notedb.ChangeUpdate;
|
|
import com.google.gerrit.server.notedb.NotesMigration;
|
|
import com.google.gwtorm.server.OrmException;
|
|
import com.google.inject.Inject;
|
|
import com.google.inject.Singleton;
|
|
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* Utility functions to manipulate ChangeMessages.
|
|
* <p>
|
|
* These methods either query for and update ChangeMessages in the NoteDb or
|
|
* ReviewDb, depending on the state of the NotesMigration.
|
|
*/
|
|
@Singleton
|
|
public class ChangeMessagesUtil {
|
|
private static List<ChangeMessage> sortChangeMessages(
|
|
Iterable<ChangeMessage> changeMessage) {
|
|
return ChangeNotes.MESSAGE_BY_TIME.sortedCopy(changeMessage);
|
|
}
|
|
|
|
private final NotesMigration migration;
|
|
|
|
@VisibleForTesting
|
|
@Inject
|
|
public ChangeMessagesUtil(NotesMigration migration) {
|
|
this.migration = migration;
|
|
}
|
|
|
|
public List<ChangeMessage> byChange(ReviewDb db, ChangeNotes notes) throws OrmException {
|
|
if (!migration.readChanges()) {
|
|
return
|
|
sortChangeMessages(db.changeMessages().byChange(notes.getChangeId()));
|
|
} else {
|
|
return notes.load().getChangeMessages();
|
|
}
|
|
}
|
|
|
|
public Iterable<ChangeMessage> byPatchSet(ReviewDb db, ChangeNotes notes,
|
|
PatchSet.Id psId) throws OrmException {
|
|
if (!migration.readChanges()) {
|
|
return db.changeMessages().byPatchSet(psId);
|
|
}
|
|
return notes.load().getChangeMessagesByPatchSet().get(psId);
|
|
}
|
|
|
|
public void addChangeMessage(ReviewDb db, ChangeUpdate update,
|
|
ChangeMessage changeMessage) throws OrmException {
|
|
update.setChangeMessage(changeMessage.getMessage());
|
|
db.changeMessages().insert(Collections.singleton(changeMessage));
|
|
}
|
|
}
|