CommitValidators: uniformize argument ordering for creation methods
Change-Id: Idf5a3bed6cbd3f90f5c9582e160c57a3a201933f
This commit is contained in:
@@ -552,8 +552,6 @@ public class ChangeInserter implements InsertChangeOp {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PermissionBackend.ForRef perm =
|
|
||||||
permissionBackend.user(ctx.getUser()).project(ctx.getProject()).ref(refName);
|
|
||||||
try {
|
try {
|
||||||
try (CommitReceivedEvent event =
|
try (CommitReceivedEvent event =
|
||||||
new CommitReceivedEvent(
|
new CommitReceivedEvent(
|
||||||
@@ -565,7 +563,7 @@ public class ChangeInserter implements InsertChangeOp {
|
|||||||
ctx.getIdentifiedUser())) {
|
ctx.getIdentifiedUser())) {
|
||||||
commitValidatorsFactory
|
commitValidatorsFactory
|
||||||
.forGerritCommits(
|
.forGerritCommits(
|
||||||
perm,
|
permissionBackend.user(ctx.getUser()).project(ctx.getProject()),
|
||||||
new Branch.NameKey(ctx.getProject(), refName),
|
new Branch.NameKey(ctx.getProject(), refName),
|
||||||
ctx.getIdentifiedUser(),
|
ctx.getIdentifiedUser(),
|
||||||
new NoSshInfo(),
|
new NoSshInfo(),
|
||||||
|
|||||||
@@ -323,9 +323,6 @@ public class PatchSetInserter implements BatchUpdateOp {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PermissionBackend.ForRef perm =
|
|
||||||
permissionBackend.user(ctx.getUser()).ref(origNotes.getChange().getDest());
|
|
||||||
|
|
||||||
String refName = getPatchSetId().toRefName();
|
String refName = getPatchSetId().toRefName();
|
||||||
try (CommitReceivedEvent event =
|
try (CommitReceivedEvent event =
|
||||||
new CommitReceivedEvent(
|
new CommitReceivedEvent(
|
||||||
@@ -340,7 +337,7 @@ public class PatchSetInserter implements BatchUpdateOp {
|
|||||||
ctx.getIdentifiedUser())) {
|
ctx.getIdentifiedUser())) {
|
||||||
commitValidatorsFactory
|
commitValidatorsFactory
|
||||||
.forGerritCommits(
|
.forGerritCommits(
|
||||||
perm,
|
permissionBackend.user(ctx.getUser()).project(ctx.getProject()),
|
||||||
origNotes.getChange().getDest(),
|
origNotes.getChange().getDest(),
|
||||||
ctx.getIdentifiedUser(),
|
ctx.getIdentifiedUser(),
|
||||||
new NoSshInfo(),
|
new NoSshInfo(),
|
||||||
|
|||||||
@@ -3115,7 +3115,6 @@ class ReceiveCommits {
|
|||||||
@Nullable Change change,
|
@Nullable Change change,
|
||||||
NoteMap rejectCommits)
|
NoteMap rejectCommits)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
PermissionBackend.ForRef perm = permissions.ref(branch.get());
|
|
||||||
|
|
||||||
ValidCommitKey key = new AutoValue_ReceiveCommits_ValidCommitKey(commit.copy(), branch);
|
ValidCommitKey key = new AutoValue_ReceiveCommits_ValidCommitKey(commit.copy(), branch);
|
||||||
if (validCommits.contains(key)) {
|
if (validCommits.contains(key)) {
|
||||||
@@ -3127,12 +3126,11 @@ class ReceiveCommits {
|
|||||||
CommitValidators validators;
|
CommitValidators validators;
|
||||||
if (isMerged) {
|
if (isMerged) {
|
||||||
validators =
|
validators =
|
||||||
commitValidatorsFactory.forMergedCommits(
|
commitValidatorsFactory.forMergedCommits(permissions, branch, user.asIdentifiedUser());
|
||||||
project.getNameKey(), perm, user.asIdentifiedUser());
|
|
||||||
} else {
|
} else {
|
||||||
validators =
|
validators =
|
||||||
commitValidatorsFactory.forReceiveCommits(
|
commitValidatorsFactory.forReceiveCommits(
|
||||||
perm,
|
permissions,
|
||||||
branch,
|
branch,
|
||||||
user.asIdentifiedUser(),
|
user.asIdentifiedUser(),
|
||||||
sshInfo,
|
sshInfo,
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ import com.google.gerrit.reviewdb.client.BooleanProjectConfig;
|
|||||||
import com.google.gerrit.reviewdb.client.Branch;
|
import com.google.gerrit.reviewdb.client.Branch;
|
||||||
import com.google.gerrit.reviewdb.client.Branch.NameKey;
|
import com.google.gerrit.reviewdb.client.Branch.NameKey;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
|
||||||
import com.google.gerrit.reviewdb.client.RefNames;
|
import com.google.gerrit.reviewdb.client.RefNames;
|
||||||
import com.google.gerrit.server.GerritPersonIdent;
|
import com.google.gerrit.server.GerritPersonIdent;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
@@ -48,7 +47,6 @@ import com.google.gerrit.server.events.CommitReceivedEvent;
|
|||||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||||
import com.google.gerrit.server.git.ValidationError;
|
import com.google.gerrit.server.git.ValidationError;
|
||||||
import com.google.gerrit.server.permissions.PermissionBackend;
|
import com.google.gerrit.server.permissions.PermissionBackend;
|
||||||
import com.google.gerrit.server.permissions.PermissionBackend.ForRef;
|
|
||||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||||
import com.google.gerrit.server.permissions.RefPermission;
|
import com.google.gerrit.server.permissions.RefPermission;
|
||||||
import com.google.gerrit.server.project.ProjectCache;
|
import com.google.gerrit.server.project.ProjectCache;
|
||||||
@@ -122,7 +120,7 @@ public class CommitValidators {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CommitValidators forReceiveCommits(
|
public CommitValidators forReceiveCommits(
|
||||||
PermissionBackend.ForRef perm,
|
PermissionBackend.ForProject forProject,
|
||||||
Branch.NameKey branch,
|
Branch.NameKey branch,
|
||||||
IdentifiedUser user,
|
IdentifiedUser user,
|
||||||
SshInfo sshInfo,
|
SshInfo sshInfo,
|
||||||
@@ -130,6 +128,7 @@ public class CommitValidators {
|
|||||||
RevWalk rw,
|
RevWalk rw,
|
||||||
@Nullable Change change)
|
@Nullable Change change)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
PermissionBackend.ForRef perm = forProject.ref(branch.get());
|
||||||
ProjectState projectState = projectCache.checkedGet(branch.getParentKey());
|
ProjectState projectState = projectCache.checkedGet(branch.getParentKey());
|
||||||
return new CommitValidators(
|
return new CommitValidators(
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
@@ -155,13 +154,14 @@ public class CommitValidators {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CommitValidators forGerritCommits(
|
public CommitValidators forGerritCommits(
|
||||||
ForRef perm,
|
PermissionBackend.ForProject forProject,
|
||||||
NameKey branch,
|
NameKey branch,
|
||||||
IdentifiedUser user,
|
IdentifiedUser user,
|
||||||
SshInfo sshInfo,
|
SshInfo sshInfo,
|
||||||
RevWalk rw,
|
RevWalk rw,
|
||||||
@Nullable Change change)
|
@Nullable Change change)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
PermissionBackend.ForRef perm = forProject.ref(branch.get());
|
||||||
ProjectState projectState = projectCache.checkedGet(branch.getParentKey());
|
ProjectState projectState = projectCache.checkedGet(branch.getParentKey());
|
||||||
return new CommitValidators(
|
return new CommitValidators(
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
@@ -185,7 +185,7 @@ public class CommitValidators {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CommitValidators forMergedCommits(
|
public CommitValidators forMergedCommits(
|
||||||
Project.NameKey project, PermissionBackend.ForRef perm, IdentifiedUser user)
|
PermissionBackend.ForProject forProject, Branch.NameKey branch, IdentifiedUser user)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
// Generally only include validators that are based on permissions of the
|
// Generally only include validators that are based on permissions of the
|
||||||
// user creating a change for a merged commit; generally exclude
|
// user creating a change for a merged commit; generally exclude
|
||||||
@@ -200,10 +200,11 @@ public class CommitValidators {
|
|||||||
// discuss what to do about it.
|
// discuss what to do about it.
|
||||||
// - Plugin validators may do things like require certain commit message
|
// - Plugin validators may do things like require certain commit message
|
||||||
// formats, so we play it safe and exclude them.
|
// formats, so we play it safe and exclude them.
|
||||||
|
PermissionBackend.ForRef perm = forProject.ref(branch.get());
|
||||||
return new CommitValidators(
|
return new CommitValidators(
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
new UploadMergesPermissionValidator(perm),
|
new UploadMergesPermissionValidator(perm),
|
||||||
new ProjectStateValidationListener(projectCache.checkedGet(project)),
|
new ProjectStateValidationListener(projectCache.checkedGet(branch.getParentKey())),
|
||||||
new AuthorUploaderValidator(user, perm, canonicalWebUrl),
|
new AuthorUploaderValidator(user, perm, canonicalWebUrl),
|
||||||
new CommitterUploaderValidator(user, perm, canonicalWebUrl)));
|
new CommitterUploaderValidator(user, perm, canonicalWebUrl)));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user