Convert PatchSetInserter to use a builder pattern

Instead of multiplying methods based on various parameters, store the
parameters as instance variables in the PatchSetInserter object, and
use a single insert() method with no arguments to do the insertion.
Writing setter methods for each of the "optional arguments" increases
boilerplate slightly, but allows us to do per-argument validation in a
cleanly separated way.

Change-Id: I694c8a1f381d6ba01a31acf904802ea99e8f50e8
This commit is contained in:
Dave Borowitz
2013-05-15 08:19:39 -07:00
parent e539c87f09
commit d838b4355d
5 changed files with 87 additions and 45 deletions

View File

@@ -25,7 +25,6 @@ import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.GerritPersonIdent;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.change.PatchSetInserter;
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.validators.CommitValidators;
import com.google.gerrit.server.mail.CommitMessageEditedSender;
@@ -65,7 +64,7 @@ class EditCommitMessageHandler extends Handler<ChangeDetail> {
private final CommitValidators.Factory commitValidatorsFactory;
private final GitRepositoryManager gitManager;
private final PersonIdent myIdent;
private final PatchSetInserter patchSetInserter;
private final PatchSetInserter.Factory patchSetInserterFactory;
@Inject
EditCommitMessageHandler(final ChangeControl.Factory changeControlFactory,
@@ -77,7 +76,7 @@ class EditCommitMessageHandler extends Handler<ChangeDetail> {
final CommitValidators.Factory commitValidatorsFactory,
final GitRepositoryManager gitManager,
@GerritPersonIdent final PersonIdent myIdent,
final PatchSetInserter patchSetInserter) {
final PatchSetInserter.Factory patchSetInserterFactory) {
this.changeControlFactory = changeControlFactory;
this.db = db;
this.currentUser = currentUser;
@@ -88,7 +87,7 @@ class EditCommitMessageHandler extends Handler<ChangeDetail> {
this.commitValidatorsFactory = commitValidatorsFactory;
this.gitManager = gitManager;
this.myIdent = myIdent;
this.patchSetInserter = patchSetInserter;
this.patchSetInserterFactory = patchSetInserterFactory;
}
@Override
@@ -114,8 +113,9 @@ class EditCommitMessageHandler extends Handler<ChangeDetail> {
CommitValidators commitValidators =
commitValidatorsFactory.create(control.getRefControl(), new NoSshInfo(), git);
ChangeUtil.editCommitMessage(patchSetId, control.getRefControl(), commitValidators, currentUser, message, db,
commitMessageEditedSenderFactory, git, myIdent, patchSetInserter);
ChangeUtil.editCommitMessage(patchSetId, control.getRefControl(),
commitValidators, currentUser, message, db,
commitMessageEditedSenderFactory, git, myIdent, patchSetInserterFactory);
return changeDetailFactory.create(changeId).call();
} finally {