ChangeBundle: Ignore originalSubject between ReviewDb and NoteDb

The migration path in Change#setCurrentPatchSet means that the
original subject field in ReviewDb may be null, or may be the actual
original subject of PS1, or may be the subject of any intervening
patch set, if that patch set was the first one pushed after adding the
column to ReviewDb. This means we can't reliably compare these after
converting to NoteDb, at least without changing the implementation of
ChangeBundle substantially in order to give it access to the
repository.

Satisfy ourselves with explicitly checking the subject and
originalSubject in ChangeRebuilderIT to ensure it's populated properly
in the common case.

Change-Id: I2160bf6f38b5ea97e0c3ee512a0450854e1af265
This commit is contained in:
Dave Borowitz
2016-05-03 21:42:31 -04:00
parent 9a5fc785ed
commit 7672de4d26
3 changed files with 54 additions and 19 deletions

View File

@@ -459,6 +459,35 @@ public class ChangeRebuilderIT extends AbstractDaemonTest {
checker.rebuildAndCheckChanges(id);
}
@Test
public void noteDbUsesOriginalSubjectFromPatchSetAndIgnoresChangeField()
throws Exception {
PushOneCommit.Result r = createChange();
String orig = r.getChange().change().getSubject();
r = pushFactory.create(
db, admin.getIdent(), testRepo, orig + " v2",
PushOneCommit.FILE_NAME, "new contents", r.getChangeId())
.to("refs/heads/master");
r.assertOkStatus();
PatchSet.Id psId = r.getPatchSetId();
Change.Id id = psId.getParentKey();
Change c = db.changes().get(id);
c.setCurrentPatchSet(psId, c.getSubject(), "Bogus original subject");
db.changes().update(Collections.singleton(c));
checker.rebuildAndCheckChanges(id);
notesMigration.setAllEnabled(true);
ChangeNotes notes = notesFactory.create(db, project, id);
Change nc = notes.getChange();
assertThat(nc.getSubject()).isEqualTo(c.getSubject());
assertThat(nc.getSubject()).isEqualTo(orig + " v2");
assertThat(nc.getOriginalSubject()).isNotEqualTo(c.getOriginalSubject());
assertThat(nc.getOriginalSubject()).isEqualTo(orig);
}
private void setInvalidNoteDbState(Change.Id id) throws Exception {
ReviewDb db = unwrapDb();
Change c = db.changes().get(id);