Pass an ObjectInserter into NotesBranchUtil

CreateCodeReviewNotes does not need to flush its inserter before
calling NotesBranchUtil.commitAllNotes(), so take advantage of the
existing inserter to create one less pack when creating review notes.

Change-Id: I632aadfed822230101442c1e6fce139b57825f6b
This commit is contained in:
Dave Borowitz
2012-10-10 15:23:47 -07:00
parent 38bc1cf6a7
commit 0f1851c068
3 changed files with 11 additions and 8 deletions

View File

@@ -92,7 +92,8 @@ public class BanCommit {
banCommitNotes.set(commitToBan, createNoteContent(reason, inserter));
}
inserter.flush();
NotesBranchUtil notesBranchUtil = notesBranchUtilFactory.create(repo);
NotesBranchUtil notesBranchUtil = notesBranchUtilFactory.create(repo,
inserter);
NoteMap newlyCreated =
notesBranchUtil.commitNewNotes(banCommitNotes, REF_REJECT_COMMITS,
createPersonIdent(), buildCommitMessage(commitsToBan, reason));

View File

@@ -114,7 +114,8 @@ public class CreateCodeReviewNotes {
message.append("* ").append(c.getShortMessage()).append("\n");
}
NotesBranchUtil notesBranchUtil = notesBranchUtilFactory.create(db);
NotesBranchUtil notesBranchUtil = notesBranchUtilFactory.create(db,
inserter);
notesBranchUtil.commitAllNotes(notes, REFS_NOTES_REVIEW, author,
message.toString());
inserter.flush();
@@ -149,7 +150,8 @@ public class CreateCodeReviewNotes {
notes.set(commitId, createNoteContent(c, commitId));
}
NotesBranchUtil notesBranchUtil = notesBranchUtilFactory.create(db);
NotesBranchUtil notesBranchUtil = notesBranchUtilFactory.create(db,
inserter);
notesBranchUtil.commitAllNotes(notes, REFS_NOTES_REVIEW, author,
commitMessage);
inserter.flush();

View File

@@ -47,7 +47,7 @@ import java.io.IOException;
*/
public class NotesBranchUtil {
public interface Factory {
NotesBranchUtil create(Repository db);
NotesBranchUtil create(Repository db, ObjectInserter inserter);
}
private static final int MAX_LOCK_FAILURE_CALLS = 10;
@@ -55,6 +55,7 @@ public class NotesBranchUtil {
private PersonIdent gerritIdent;
private final Repository db;
private final ObjectInserter inserter;
private RevCommit baseCommit;
private NoteMap base;
@@ -63,7 +64,6 @@ public class NotesBranchUtil {
private NoteMap ours;
private RevWalk revWalk;
private ObjectInserter inserter;
private ObjectReader reader;
private boolean overwrite;
@@ -71,9 +71,11 @@ public class NotesBranchUtil {
@Inject
public NotesBranchUtil(@GerritPersonIdent final PersonIdent gerritIdent,
@Assisted Repository db) {
@Assisted Repository db,
@Assisted ObjectInserter inserter) {
this.gerritIdent = gerritIdent;
this.db = db;
this.inserter = inserter;
}
/**
@@ -128,7 +130,6 @@ public class NotesBranchUtil {
ConcurrentRefUpdateException {
try {
revWalk = new RevWalk(db);
inserter = db.newObjectInserter();
reader = db.newObjectReader();
loadBase(notesBranch);
if (overwrite) {
@@ -144,7 +145,6 @@ public class NotesBranchUtil {
updateRef(notesBranch);
} finally {
revWalk.release();
inserter.release();
reader.release();
}
}