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:
Yacob Yonas
2014-08-14 14:49:20 -07:00
parent 4c77d3cd3f
commit 6f4a64f0e4
3 changed files with 38 additions and 21 deletions

View File

@@ -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;