MergeValidationListener: Also provide RevWalk to the onPreMerge method
This way implementors that need a RevWalk do not need to create a new
instance. The callers have the RevWalk anyway available, so it's no
extra effort for them to provide it.
This makes the objects that are available to implementors of
MergeValidationListener more consistent with the objects that are
available to implementors of CommitValidationListener, which already
contains the RevWalk inside of CommitReceivedEvent.
Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: Id93e378be10c91d3dc3365aec0bab9847ee8ef6d
diff --git a/java/com/google/gerrit/server/git/validators/MergeValidationListener.java b/java/com/google/gerrit/server/git/validators/MergeValidationListener.java
index b47d7d6..79d53ac 100644
--- a/java/com/google/gerrit/server/git/validators/MergeValidationListener.java
+++ b/java/com/google/gerrit/server/git/validators/MergeValidationListener.java
@@ -19,6 +19,7 @@
import com.google.gerrit.extensions.annotations.ExtensionPoint;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.git.CodeReviewCommit;
+import com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk;
import com.google.gerrit.server.project.ProjectState;
import org.eclipse.jgit.lib.Repository;
@@ -33,6 +34,7 @@
* Validate a commit before it is merged.
*
* @param repo the repository
+ * @param revWalk the rev walk
* @param commit commit details
* @param destProject the destination project
* @param destBranch the destination branch
@@ -42,6 +44,7 @@
*/
void onPreMerge(
Repository repo,
+ CodeReviewRevWalk revWalk,
CodeReviewCommit commit,
ProjectState destProject,
BranchNameKey destBranch,
diff --git a/java/com/google/gerrit/server/git/validators/MergeValidators.java b/java/com/google/gerrit/server/git/validators/MergeValidators.java
index 4e5ce0c..cbaa121 100644
--- a/java/com/google/gerrit/server/git/validators/MergeValidators.java
+++ b/java/com/google/gerrit/server/git/validators/MergeValidators.java
@@ -35,6 +35,7 @@
import com.google.gerrit.server.config.PluginConfig;
import com.google.gerrit.server.config.ProjectConfigEntry;
import com.google.gerrit.server.git.CodeReviewCommit;
+import com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk;
import com.google.gerrit.server.permissions.GlobalPermission;
import com.google.gerrit.server.permissions.PermissionBackend;
import com.google.gerrit.server.permissions.PermissionBackendException;
@@ -51,7 +52,6 @@
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.revwalk.RevWalk;
/**
* Collection of validators that run inside Gerrit before a change is submitted. The main purpose is
@@ -92,6 +92,7 @@
*/
public void validatePreMerge(
Repository repo,
+ CodeReviewRevWalk revWalk,
CodeReviewCommit commit,
ProjectState destProject,
BranchNameKey destBranch,
@@ -106,7 +107,7 @@
groupValidatorFactory.create());
for (MergeValidationListener validator : validators) {
- validator.onPreMerge(repo, commit, destProject, destBranch, patchSetId, caller);
+ validator.onPreMerge(repo, revWalk, commit, destProject, destBranch, patchSetId, caller);
}
}
@@ -168,11 +169,12 @@
@Override
public void onPreMerge(
- final Repository repo,
- final CodeReviewCommit commit,
- final ProjectState destProject,
- final BranchNameKey destBranch,
- final PatchSet.Id patchSetId,
+ Repository repo,
+ CodeReviewRevWalk revWalk,
+ CodeReviewCommit commit,
+ ProjectState destProject,
+ BranchNameKey destBranch,
+ PatchSet.Id patchSetId,
IdentifiedUser caller)
throws MergeValidationException {
if (RefNames.REFS_CONFIG.equals(destBranch.branch())) {
@@ -260,6 +262,7 @@
@Override
public void onPreMerge(
Repository repo,
+ CodeReviewRevWalk revWalk,
CodeReviewCommit commit,
ProjectState destProject,
BranchNameKey destBranch,
@@ -267,7 +270,7 @@
IdentifiedUser caller)
throws MergeValidationException {
mergeValidationListeners.runEach(
- l -> l.onPreMerge(repo, commit, destProject, destBranch, patchSetId, caller),
+ l -> l.onPreMerge(repo, revWalk, commit, destProject, destBranch, patchSetId, caller),
MergeValidationException.class);
}
}
@@ -294,6 +297,7 @@
@Override
public void onPreMerge(
Repository repo,
+ CodeReviewRevWalk revWalk,
CodeReviewCommit commit,
ProjectState destProject,
BranchNameKey destBranch,
@@ -316,8 +320,9 @@
throw new MergeValidationException("account validation unavailable");
}
- try (RevWalk rw = new RevWalk(repo)) {
- List<String> errorMessages = accountValidator.validate(accountId, repo, rw, null, commit);
+ try {
+ List<String> errorMessages =
+ accountValidator.validate(accountId, repo, revWalk, null, commit);
if (!errorMessages.isEmpty()) {
throw new MergeValidationException(
"invalid account configuration: " + Joiner.on("; ").join(errorMessages));
@@ -345,6 +350,7 @@
@Override
public void onPreMerge(
Repository repo,
+ CodeReviewRevWalk revWalk,
CodeReviewCommit commit,
ProjectState destProject,
BranchNameKey destBranch,
diff --git a/java/com/google/gerrit/server/submit/MergeOp.java b/java/com/google/gerrit/server/submit/MergeOp.java
index 58b0c8e..8a293a4 100644
--- a/java/com/google/gerrit/server/submit/MergeOp.java
+++ b/java/com/google/gerrit/server/submit/MergeOp.java
@@ -864,7 +864,8 @@
MergeValidators mergeValidators = mergeValidatorsFactory.create();
try {
- mergeValidators.validatePreMerge(or.repo, commit, or.project, destBranch, ps.id(), caller);
+ mergeValidators.validatePreMerge(
+ or.repo, or.rw, commit, or.project, destBranch, ps.id(), caller);
} catch (MergeValidationException mve) {
commitStatus.problem(changeId, mve.getMessage());
continue;
diff --git a/plugins/hooks b/plugins/hooks
index 7ed555f..ad4f877 160000
--- a/plugins/hooks
+++ b/plugins/hooks
@@ -1 +1 @@
-Subproject commit 7ed555fe88f4be028acbfd5c245ac78537ac3666
+Subproject commit ad4f877749928b69ef94b62176c5797f6648887d