Move ReceiveCommits#canUpload to AsyncReceiveCommits
Change-Id: Ic4a8b1e28164c08bd2af21c93a71fda4e2b72bb8
This commit is contained in:
parent
798b883b40
commit
fe84eaa819
@ -32,7 +32,6 @@ import com.google.gerrit.server.git.ReceivePackInitializer;
|
||||
import com.google.gerrit.server.git.TransferConfig;
|
||||
import com.google.gerrit.server.git.VisibleRefFilter;
|
||||
import com.google.gerrit.server.git.receive.AsyncReceiveCommits;
|
||||
import com.google.gerrit.server.git.receive.ReceiveCommits;
|
||||
import com.google.gerrit.server.git.validators.UploadValidators;
|
||||
import com.google.gerrit.server.project.NoSuchProjectException;
|
||||
import com.google.gerrit.server.project.ProjectControl;
|
||||
@ -297,10 +296,10 @@ class InProcessProtocol extends TestProtocol<Context> {
|
||||
throw new ServiceNotAuthorizedException();
|
||||
}
|
||||
|
||||
ReceiveCommits rc = factory.create(ctl, db).getReceiveCommits();
|
||||
ReceivePack rp = rc.getReceivePack();
|
||||
AsyncReceiveCommits arc = factory.create(ctl, db);
|
||||
ReceivePack rp = arc.getReceiveCommits().getReceivePack();
|
||||
|
||||
Capable r = rc.canUpload();
|
||||
Capable r = arc.canUpload();
|
||||
if (r != Capable.OK) {
|
||||
throw new ServiceNotAuthorizedException();
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.TransferConfig;
|
||||
import com.google.gerrit.server.git.VisibleRefFilter;
|
||||
import com.google.gerrit.server.git.receive.AsyncReceiveCommits;
|
||||
import com.google.gerrit.server.git.receive.ReceiveCommits;
|
||||
import com.google.gerrit.server.git.validators.UploadValidators;
|
||||
import com.google.gerrit.server.permissions.PermissionBackend;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
@ -80,7 +79,7 @@ public class GitOverHttpServlet extends GitServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final String ATT_CONTROL = ProjectControl.class.getName();
|
||||
private static final String ATT_RC = ReceiveCommits.class.getName();
|
||||
private static final String ATT_ARC = AsyncReceiveCommits.class.getName();
|
||||
private static final String ID_CACHE = "adv_bases";
|
||||
|
||||
public static final String URL_REGEX;
|
||||
@ -295,11 +294,11 @@ public class GitOverHttpServlet extends GitServlet {
|
||||
throw new ServiceNotAuthorizedException();
|
||||
}
|
||||
|
||||
ReceiveCommits rc = factory.create(pc, db).getReceiveCommits();
|
||||
rc.init();
|
||||
AsyncReceiveCommits arc = factory.create(pc, db);
|
||||
arc.getReceiveCommits().init();
|
||||
|
||||
ReceivePack rp = rc.getReceivePack();
|
||||
req.setAttribute(ATT_RC, rc);
|
||||
ReceivePack rp = arc.getReceiveCommits().getReceivePack();
|
||||
req.setAttribute(ATT_ARC, arc);
|
||||
return rp;
|
||||
}
|
||||
}
|
||||
@ -325,8 +324,8 @@ public class GitOverHttpServlet extends GitServlet {
|
||||
throws IOException, ServletException {
|
||||
boolean isGet = "GET".equalsIgnoreCase(((HttpServletRequest) request).getMethod());
|
||||
|
||||
ReceiveCommits rc = (ReceiveCommits) request.getAttribute(ATT_RC);
|
||||
ReceivePack rp = rc.getReceivePack();
|
||||
AsyncReceiveCommits arc = (AsyncReceiveCommits) request.getAttribute(ATT_ARC);
|
||||
ReceivePack rp = arc.getReceiveCommits().getReceivePack();
|
||||
rp.getAdvertiseRefsHook().advertiseRefs(rp);
|
||||
ProjectControl pc = (ProjectControl) request.getAttribute(ATT_CONTROL);
|
||||
Project.NameKey projectName = pc.getProject().getNameKey();
|
||||
@ -340,7 +339,7 @@ public class GitOverHttpServlet extends GitServlet {
|
||||
return;
|
||||
}
|
||||
|
||||
final Capable s = rc.canUpload();
|
||||
Capable s = arc.canUpload();
|
||||
if (s != Capable.OK) {
|
||||
GitSmartHttpTools.sendError(
|
||||
(HttpServletRequest) request,
|
||||
|
@ -14,12 +14,14 @@
|
||||
|
||||
package com.google.gerrit.server.git.receive;
|
||||
|
||||
import com.google.gerrit.common.data.Capable;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.config.ConfigUtil;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.git.MultiProgressMonitor;
|
||||
import com.google.gerrit.server.git.ProjectRunnable;
|
||||
import com.google.gerrit.server.project.ProjectControl;
|
||||
import com.google.gerrit.server.util.MagicBranch;
|
||||
import com.google.gerrit.server.util.RequestScopePropagator;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.PrivateModule;
|
||||
@ -130,23 +132,42 @@ public class AsyncReceiveCommits implements PreReceiveHook {
|
||||
private final ExecutorService executor;
|
||||
private final RequestScopePropagator scopePropagator;
|
||||
private final MultiProgressMonitor progress;
|
||||
private final ReceiveConfig receiveConfig;
|
||||
private final long timeoutMillis;
|
||||
private final ProjectControl projectControl;
|
||||
private final Repository repo;
|
||||
|
||||
@Inject
|
||||
AsyncReceiveCommits(
|
||||
ReceiveCommits.Factory factory,
|
||||
@ReceiveCommitsExecutor ExecutorService executor,
|
||||
RequestScopePropagator scopePropagator,
|
||||
ReceiveConfig receiveConfig,
|
||||
@Named(TIMEOUT_NAME) long timeoutMillis,
|
||||
@Assisted ProjectControl projectControl,
|
||||
@Assisted Repository repo) {
|
||||
this.executor = executor;
|
||||
this.scopePropagator = scopePropagator;
|
||||
this.receiveConfig = receiveConfig;
|
||||
this.projectControl = projectControl;
|
||||
this.repo = repo;
|
||||
this.timeoutMillis = timeoutMillis;
|
||||
|
||||
rc = factory.create(projectControl, repo);
|
||||
rc.getReceivePack().setPreReceiveHook(this);
|
||||
|
||||
progress = new MultiProgressMonitor(new MessageSenderOutputStream(), "Processing changes");
|
||||
this.timeoutMillis = timeoutMillis;
|
||||
}
|
||||
|
||||
/** Determine if the user can upload commits. */
|
||||
public Capable canUpload() {
|
||||
Capable result = projectControl.canPushToAtLeastOneRef();
|
||||
if (result != Capable.OK) {
|
||||
return result;
|
||||
}
|
||||
if (receiveConfig.checkMagicRefs) {
|
||||
result = MagicBranch.checkMagicBranchRefs(repo, projectControl.getProject());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,7 +51,6 @@ import com.google.common.collect.Sets;
|
||||
import com.google.common.collect.SortedSetMultimap;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.common.TimeUtil;
|
||||
import com.google.gerrit.common.data.Capable;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
@ -578,18 +577,6 @@ public class ReceiveCommits {
|
||||
return rp;
|
||||
}
|
||||
|
||||
/** Determine if the user can upload commits. */
|
||||
public Capable canUpload() {
|
||||
Capable result = projectControl.canPushToAtLeastOneRef();
|
||||
if (result != Capable.OK) {
|
||||
return result;
|
||||
}
|
||||
if (receiveConfig.checkMagicRefs) {
|
||||
result = MagicBranch.checkMagicBranchRefs(repo, project);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void addMessage(String message) {
|
||||
messages.add(new CommitValidationMessage(message, false));
|
||||
}
|
||||
|
@ -81,13 +81,14 @@ final class Receive extends AbstractGitCommand {
|
||||
throw new Failure(1, "fatal: receive-pack not permitted on this server");
|
||||
}
|
||||
|
||||
final ReceiveCommits receive = factory.create(projectControl, repo).getReceiveCommits();
|
||||
AsyncReceiveCommits arc = factory.create(projectControl, repo);
|
||||
|
||||
Capable r = receive.canUpload();
|
||||
Capable r = arc.canUpload();
|
||||
if (r != Capable.OK) {
|
||||
throw die(r.getMessage());
|
||||
}
|
||||
|
||||
ReceiveCommits receive = arc.getReceiveCommits();
|
||||
receive.init();
|
||||
receive.addReviewers(reviewerId);
|
||||
receive.addExtraCC(ccId);
|
||||
|
Loading…
Reference in New Issue
Block a user