Simplify [ReceivePack]MessageSender logic
In AsyncReceiveCommits, messageSender is always null. This obviates MessageSender as a separate interface. Change-Id: I3d88613780d6c5c93754c70f06a079ed83f2bd0c
This commit is contained in:
@@ -331,7 +331,7 @@ class InProcessProtocol extends TestProtocol<Context> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AsyncReceiveCommits arc =
|
AsyncReceiveCommits arc =
|
||||||
factory.create(projectState, identifiedUser, db, null, ImmutableSetMultimap.of());
|
factory.create(projectState, identifiedUser, db, ImmutableSetMultimap.of());
|
||||||
ReceivePack rp = arc.getReceivePack();
|
ReceivePack rp = arc.getReceivePack();
|
||||||
|
|
||||||
Capable r = arc.canUpload();
|
Capable r = arc.canUpload();
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ public class GitOverHttpServlet extends GitServlet {
|
|||||||
|
|
||||||
AsyncReceiveCommits arc =
|
AsyncReceiveCommits arc =
|
||||||
factory.create(
|
factory.create(
|
||||||
state, userProvider.get().asIdentifiedUser(), db, null, ImmutableSetMultimap.of());
|
state, userProvider.get().asIdentifiedUser(), db, ImmutableSetMultimap.of());
|
||||||
ReceivePack rp = arc.getReceivePack();
|
ReceivePack rp = arc.getReceivePack();
|
||||||
req.setAttribute(ATT_ARC, arc);
|
req.setAttribute(ATT_ARC, arc);
|
||||||
return rp;
|
return rp;
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ package com.google.gerrit.server.git.receive;
|
|||||||
|
|
||||||
import com.google.common.collect.SetMultimap;
|
import com.google.common.collect.SetMultimap;
|
||||||
import com.google.common.flogger.FluentLogger;
|
import com.google.common.flogger.FluentLogger;
|
||||||
import com.google.gerrit.common.Nullable;
|
|
||||||
import com.google.gerrit.common.data.Capable;
|
import com.google.gerrit.common.data.Capable;
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
@@ -76,7 +75,6 @@ public class AsyncReceiveCommits implements PreReceiveHook {
|
|||||||
ProjectState projectState,
|
ProjectState projectState,
|
||||||
IdentifiedUser user,
|
IdentifiedUser user,
|
||||||
Repository repository,
|
Repository repository,
|
||||||
@Nullable MessageSender messageSender,
|
|
||||||
SetMultimap<ReviewerStateInternal, Account.Id> extraReviewers);
|
SetMultimap<ReviewerStateInternal, Account.Id> extraReviewers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,24 +101,23 @@ public class AsyncReceiveCommits implements PreReceiveHook {
|
|||||||
final MultiProgressMonitor progress;
|
final MultiProgressMonitor progress;
|
||||||
|
|
||||||
private final Collection<ReceiveCommand> commands;
|
private final Collection<ReceiveCommand> commands;
|
||||||
private final ReceiveCommits rc;
|
private final ReceiveCommits receiveCommits;
|
||||||
|
|
||||||
private Worker(Collection<ReceiveCommand> commands) {
|
private Worker(Collection<ReceiveCommand> commands) {
|
||||||
this.commands = commands;
|
this.commands = commands;
|
||||||
rc = factory.create(projectState, user, rp, allRefsWatcher, extraReviewers);
|
receiveCommits = factory.create(projectState, user, rp, allRefsWatcher, extraReviewers);
|
||||||
rc.init();
|
receiveCommits.init();
|
||||||
rc.setMessageSender(messageSender);
|
|
||||||
progress = new MultiProgressMonitor(new MessageSenderOutputStream(), "Processing changes");
|
progress = new MultiProgressMonitor(new MessageSenderOutputStream(), "Processing changes");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
rc.processCommands(commands, progress);
|
receiveCommits.processCommands(commands, progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Project.NameKey getProjectNameKey() {
|
public Project.NameKey getProjectNameKey() {
|
||||||
return rc.getProject().getNameKey();
|
return receiveCommits.getProject().getNameKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -139,28 +136,28 @@ public class AsyncReceiveCommits implements PreReceiveHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void sendMessages() {
|
void sendMessages() {
|
||||||
rc.sendMessages();
|
receiveCommits.sendMessages();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MessageSenderOutputStream extends OutputStream {
|
private class MessageSenderOutputStream extends OutputStream {
|
||||||
@Override
|
@Override
|
||||||
public void write(int b) {
|
public void write(int b) {
|
||||||
rc.getMessageSender().sendBytes(new byte[] {(byte) b});
|
receiveCommits.getMessageSender().sendBytes(new byte[] {(byte) b});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(byte[] what, int off, int len) {
|
public void write(byte[] what, int off, int len) {
|
||||||
rc.getMessageSender().sendBytes(what, off, len);
|
receiveCommits.getMessageSender().sendBytes(what, off, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(byte[] what) {
|
public void write(byte[] what) {
|
||||||
rc.getMessageSender().sendBytes(what);
|
receiveCommits.getMessageSender().sendBytes(what);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void flush() {
|
public void flush() {
|
||||||
rc.getMessageSender().flush();
|
receiveCommits.getMessageSender().flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,7 +173,6 @@ public class AsyncReceiveCommits implements PreReceiveHook {
|
|||||||
private final ProjectState projectState;
|
private final ProjectState projectState;
|
||||||
private final IdentifiedUser user;
|
private final IdentifiedUser user;
|
||||||
private final Repository repo;
|
private final Repository repo;
|
||||||
private final MessageSender messageSender;
|
|
||||||
private final SetMultimap<ReviewerStateInternal, Account.Id> extraReviewers;
|
private final SetMultimap<ReviewerStateInternal, Account.Id> extraReviewers;
|
||||||
private final AllRefsWatcher allRefsWatcher;
|
private final AllRefsWatcher allRefsWatcher;
|
||||||
|
|
||||||
@@ -195,7 +191,6 @@ public class AsyncReceiveCommits implements PreReceiveHook {
|
|||||||
@Assisted ProjectState projectState,
|
@Assisted ProjectState projectState,
|
||||||
@Assisted IdentifiedUser user,
|
@Assisted IdentifiedUser user,
|
||||||
@Assisted Repository repo,
|
@Assisted Repository repo,
|
||||||
@Assisted @Nullable MessageSender messageSender,
|
|
||||||
@Assisted SetMultimap<ReviewerStateInternal, Account.Id> extraReviewers)
|
@Assisted SetMultimap<ReviewerStateInternal, Account.Id> extraReviewers)
|
||||||
throws PermissionBackendException {
|
throws PermissionBackendException {
|
||||||
this.factory = factory;
|
this.factory = factory;
|
||||||
@@ -207,7 +202,6 @@ public class AsyncReceiveCommits implements PreReceiveHook {
|
|||||||
this.projectState = projectState;
|
this.projectState = projectState;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
this.messageSender = messageSender;
|
|
||||||
this.extraReviewers = extraReviewers;
|
this.extraReviewers = extraReviewers;
|
||||||
|
|
||||||
Project.NameKey projectName = projectState.getNameKey();
|
Project.NameKey projectName = projectState.getNameKey();
|
||||||
|
|||||||
@@ -256,23 +256,19 @@ class ReceiveCommits {
|
|||||||
SetMultimap<ReviewerStateInternal, Account.Id> extraReviewers);
|
SetMultimap<ReviewerStateInternal, Account.Id> extraReviewers);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ReceivePackMessageSender implements MessageSender {
|
public class MessageSender {
|
||||||
@Override
|
|
||||||
public void sendMessage(String what) {
|
public void sendMessage(String what) {
|
||||||
receivePack.sendMessage(what);
|
receivePack.sendMessage(what);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendError(String what) {
|
public void sendError(String what) {
|
||||||
receivePack.sendError(what);
|
receivePack.sendError(what);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendBytes(byte[] what) {
|
public void sendBytes(byte[] what) {
|
||||||
sendBytes(what, 0, what.length);
|
sendBytes(what, 0, what.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendBytes(byte[] what, int off, int len) {
|
public void sendBytes(byte[] what, int off, int len) {
|
||||||
try {
|
try {
|
||||||
receivePack.getMessageOutputStream().write(what, off, len);
|
receivePack.getMessageOutputStream().write(what, off, len);
|
||||||
@@ -281,7 +277,6 @@ class ReceiveCommits {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void flush() {
|
public void flush() {
|
||||||
try {
|
try {
|
||||||
receivePack.getMessageOutputStream().flush();
|
receivePack.getMessageOutputStream().flush();
|
||||||
@@ -515,7 +510,7 @@ class ReceiveCommits {
|
|||||||
projectState.is(BooleanProjectConfig.CREATE_NEW_CHANGE_FOR_ALL_NOT_IN_TARGET);
|
projectState.is(BooleanProjectConfig.CREATE_NEW_CHANGE_FOR_ALL_NOT_IN_TARGET);
|
||||||
|
|
||||||
// Handles for outputting back over the wire to the end user.
|
// Handles for outputting back over the wire to the end user.
|
||||||
messageSender = new ReceivePackMessageSender();
|
messageSender = new MessageSender();
|
||||||
}
|
}
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
@@ -524,15 +519,7 @@ class ReceiveCommits {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Set a message sender for this operation. */
|
|
||||||
void setMessageSender(MessageSender ms) {
|
|
||||||
messageSender = ms != null ? ms : new ReceivePackMessageSender();
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageSender getMessageSender() {
|
MessageSender getMessageSender() {
|
||||||
if (messageSender == null) {
|
|
||||||
setMessageSender(null);
|
|
||||||
}
|
|
||||||
return messageSender;
|
return messageSender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ final class Receive extends AbstractGitCommand {
|
|||||||
throw new Failure(1, "fatal: unable to check permissions " + e);
|
throw new Failure(1, "fatal: unable to check permissions " + e);
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncReceiveCommits arc = factory.create(projectState, currentUser, repo, null, reviewers);
|
AsyncReceiveCommits arc = factory.create(projectState, currentUser, repo, reviewers);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Capable r = arc.canUpload();
|
Capable r = arc.canUpload();
|
||||||
|
|||||||
Reference in New Issue
Block a user