Merge branch 'stable-2.15'

* stable-2.15:
  Fix auto-rebuilding of changes with missing NoteDb refs
  NoteDbOnlyIT: Add test for ChangeNotes.Factory#create(Checked)

Change-Id: I5e5620381c7a53b5f8ada38582c79d4552790fdf
This commit is contained in:
Paladox
2017-12-22 15:59:41 +00:00
committed by Paladox none
3 changed files with 67 additions and 6 deletions

View File

@@ -732,16 +732,27 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
protected LoadHandle openHandle(Repository repo) throws NoSuchChangeException, IOException {
if (autoRebuild) {
NoteDbChangeState state = NoteDbChangeState.parse(change);
if (args.migration.disableChangeReviewDb()) {
checkState(
state != null,
"shouldn't have null NoteDbChangeState when ReviewDb disabled: %s",
change);
}
ObjectId id = readRef(repo);
if (id == null) {
// Meta ref doesn't exist in NoteDb.
if (state == null) {
// Either ReviewDb change is being newly created, or it exists in ReviewDb but has not yet
// been rebuilt for the first time, e.g. because we just turned on write-only mode. In
// both cases, we don't want to auto-rebuild, just proceed with an empty ChangeNotes.
return super.openHandle(repo, id);
} else if (shouldExist) {
// TODO(dborowitz): This means we have a state recorded in noteDbState but the ref doesn't
// exist for whatever reason. Doesn't this mean we should trigger an auto-rebuild, rather
// than throwing?
} else if (shouldExist && state.getPrimaryStorage() == PrimaryStorage.NOTE_DB) {
throw new NoSuchChangeException(getChangeId());
}
// ReviewDb claims NoteDb state exists, but meta ref isn't present: fall through and
// auto-rebuild if necessary.
}
RefCache refs = this.refs != null ? this.refs : new RepoRefCache(repo);
if (!NoteDbChangeState.isChangeUpToDate(state, refs, getChangeId())) {