Remove CommitValidators.Policy

Almost all callers are just switching between a single policy, e.g. the
default of GERRIT for ChangeInserter/PatchSetInserter, and no
validation. The internals of CommitValidators.Factory#create just called
one of the for* factory methods depending on the enum value; it's just
as readable to do this at the source.

Within ChangeInserter/PatchSetInserter, it's just as easy to represent
do/don't validate with a single boolean value. The interaction with
RebaseChangeOp is slightly nonobvious: it used a null enum field value
to mean don't override PatchSetInserter's default. Thus we need to
explicitly set the default of the boolean value to true. (Or use
tri-state Boolean, but boolean is more consistent with the rest of the
fields in this class.)

It's worth noting that forGerritCommits is always called from within a
BatchUpdateOp, which means we can later change its parameters to not
pass a full Repository instance. By contrast forReceiveCommits is only
called from ReceiveCommits, outside of the BatchUpdate, so it always has
a full Repository available. Splitting the factory methods up in this
way allows us to pass different arguments to the different paths.

Change-Id: I833b739f2c4ab4a65ea80382b1c147dd6adc1892
This commit is contained in:
Dave Borowitz
2017-04-06 15:51:05 -04:00
parent 17e262e92b
commit 9bad11795a
14 changed files with 37 additions and 94 deletions

View File

@@ -45,7 +45,6 @@ import com.google.gerrit.server.change.ChangeInserter;
import com.google.gerrit.server.change.ConsistencyChecker;
import com.google.gerrit.server.change.PatchSetInserter;
import com.google.gerrit.server.config.AnonymousCowardName;
import com.google.gerrit.server.git.validators.CommitValidators;
import com.google.gerrit.server.notedb.ChangeNoteUtil;
import com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage;
import com.google.gerrit.server.project.ChangeControl;
@@ -802,7 +801,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
ins =
changeInserterFactory
.create(id, commit, dest)
.setValidatePolicy(CommitValidators.Policy.NONE)
.setValidate(false)
.setNotify(NotifyHandling.NONE)
.setFireRevisionCreated(false)
.setSendMail(false);
@@ -826,7 +825,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
ins =
patchSetInserterFactory
.create(ctl, nextPatchSetId(ctl), commit)
.setValidatePolicy(CommitValidators.Policy.NONE)
.setValidate(false)
.setFireRevisionCreated(false)
.setNotify(NotifyHandling.NONE);
bu.addOp(ctl.getId(), ins).execute();