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.MetaDataUpdate;
|
||||||
import com.google.gerrit.server.git.VersionedMetaData;
|
import com.google.gerrit.server.git.VersionedMetaData;
|
||||||
import com.google.gerrit.server.project.ChangeControl;
|
import com.google.gerrit.server.project.ChangeControl;
|
||||||
|
import com.google.gwtorm.server.OrmException;
|
||||||
|
|
||||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||||
import org.eclipse.jgit.lib.BatchRefUpdate;
|
import org.eclipse.jgit.lib.BatchRefUpdate;
|
||||||
@@ -178,6 +179,10 @@ public abstract class AbstractChangeUpdate extends VersionedMetaData {
|
|||||||
anonymousCowardName);
|
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,
|
* @return the NameKey for the project where the update will be stored,
|
||||||
* which is not necessarily the same as the change's project.
|
* 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 {
|
public RevCommit commit() throws IOException {
|
||||||
BatchMetaDataUpdate batch = openUpdate();
|
BatchMetaDataUpdate batch = openUpdate();
|
||||||
try {
|
try {
|
||||||
CommitBuilder builder = new CommitBuilder();
|
writeCommit(batch);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return batch.commit();
|
return batch.commit();
|
||||||
} catch (OrmException e) {
|
} catch (OrmException e) {
|
||||||
throw new IOException(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
|
@Override
|
||||||
protected Project.NameKey getProjectName() {
|
protected Project.NameKey getProjectName() {
|
||||||
return draftsProject;
|
return draftsProject;
|
||||||
|
|||||||
@@ -389,14 +389,7 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
|||||||
public RevCommit commit() throws IOException {
|
public RevCommit commit() throws IOException {
|
||||||
BatchMetaDataUpdate batch = openUpdate();
|
BatchMetaDataUpdate batch = openUpdate();
|
||||||
try {
|
try {
|
||||||
CommitBuilder builder = new CommitBuilder();
|
writeCommit(batch);
|
||||||
if (migration.write()) {
|
|
||||||
ObjectId treeId = storeCommentsInNotes();
|
|
||||||
if (treeId != null) {
|
|
||||||
builder.setTreeId(treeId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
batch.write(builder);
|
|
||||||
if (draftUpdate != null) {
|
if (draftUpdate != null) {
|
||||||
draftUpdate.commit();
|
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
|
@Override
|
||||||
protected String getRefName() {
|
protected String getRefName() {
|
||||||
return ChangeNoteUtil.changeRefName(getChange().getId());
|
return ChangeNoteUtil.changeRefName(getChange().getId());
|
||||||
|
|||||||
Reference in New Issue
Block a user