Factor out writing of commit for notedb updates
For the sake of rebuilding the notedb, we would like to write all commits for all AbstractChangeUpdates on a project to the object database, before committing a single BatchRefUpdate to update all the refs. This refactoring makes that possible. Change-Id: I864b2845b32426a55a3f62910ae09910bc25901e
This commit is contained in:
@@ -25,6 +25,7 @@ import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.MetaDataUpdate;
|
||||
import com.google.gerrit.server.git.VersionedMetaData;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.lib.BatchRefUpdate;
|
||||
@@ -178,6 +179,10 @@ public abstract class AbstractChangeUpdate extends VersionedMetaData {
|
||||
anonymousCowardName);
|
||||
}
|
||||
|
||||
/** Writes commit to a BatchMetaDataUpdate without committing the batch. */
|
||||
abstract public void writeCommit(BatchMetaDataUpdate batch)
|
||||
throws OrmException, IOException;
|
||||
|
||||
/**
|
||||
* @return the NameKey for the project where the update will be stored,
|
||||
* which is not necessarily the same as the change's project.
|
||||
|
@@ -262,19 +262,7 @@ public class ChangeDraftUpdate extends AbstractChangeUpdate {
|
||||
public RevCommit commit() throws IOException {
|
||||
BatchMetaDataUpdate batch = openUpdate();
|
||||
try {
|
||||
CommitBuilder builder = new CommitBuilder();
|
||||
if (migration.write()) {
|
||||
AtomicBoolean removedAllComments = new AtomicBoolean();
|
||||
ObjectId treeId = storeCommentsInNotes(removedAllComments);
|
||||
if (treeId != null) {
|
||||
if (removedAllComments.get()) {
|
||||
batch.removeRef(getRefName());
|
||||
} else {
|
||||
builder.setTreeId(treeId);
|
||||
batch.write(builder);
|
||||
}
|
||||
}
|
||||
}
|
||||
writeCommit(batch);
|
||||
return batch.commit();
|
||||
} catch (OrmException e) {
|
||||
throw new IOException(e);
|
||||
@@ -283,6 +271,24 @@ public class ChangeDraftUpdate extends AbstractChangeUpdate {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCommit(BatchMetaDataUpdate batch)
|
||||
throws OrmException, IOException {
|
||||
CommitBuilder builder = new CommitBuilder();
|
||||
if (migration.write()) {
|
||||
AtomicBoolean removedAllComments = new AtomicBoolean();
|
||||
ObjectId treeId = storeCommentsInNotes(removedAllComments);
|
||||
if (treeId != null) {
|
||||
if (removedAllComments.get()) {
|
||||
batch.removeRef(getRefName());
|
||||
} else {
|
||||
builder.setTreeId(treeId);
|
||||
batch.write(builder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Project.NameKey getProjectName() {
|
||||
return draftsProject;
|
||||
|
@@ -389,14 +389,7 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
||||
public RevCommit commit() throws IOException {
|
||||
BatchMetaDataUpdate batch = openUpdate();
|
||||
try {
|
||||
CommitBuilder builder = new CommitBuilder();
|
||||
if (migration.write()) {
|
||||
ObjectId treeId = storeCommentsInNotes();
|
||||
if (treeId != null) {
|
||||
builder.setTreeId(treeId);
|
||||
}
|
||||
}
|
||||
batch.write(builder);
|
||||
writeCommit(batch);
|
||||
if (draftUpdate != null) {
|
||||
draftUpdate.commit();
|
||||
}
|
||||
@@ -409,6 +402,19 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCommit(BatchMetaDataUpdate batch) throws OrmException,
|
||||
IOException {
|
||||
CommitBuilder builder = new CommitBuilder();
|
||||
if (migration.write()) {
|
||||
ObjectId treeId = storeCommentsInNotes();
|
||||
if (treeId != null) {
|
||||
builder.setTreeId(treeId);
|
||||
}
|
||||
}
|
||||
batch.write(builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRefName() {
|
||||
return ChangeNoteUtil.changeRefName(getChange().getId());
|
||||
|
Reference in New Issue
Block a user