Make MessageSender public and pass to AsyncReceiveCommits.Factory

Change-Id: I501b357943ad284f0a285170ae8ea643d716631b
This commit is contained in:
Dave Borowitz
2017-08-07 09:35:19 -04:00
parent 095467aa8f
commit 8c9115ce3f
6 changed files with 41 additions and 16 deletions

View File

@@ -297,7 +297,7 @@ class InProcessProtocol extends TestProtocol<Context> {
throw new ServiceNotAuthorizedException();
}
AsyncReceiveCommits arc = factory.create(ctl, db, ImmutableSetMultimap.of());
AsyncReceiveCommits arc = factory.create(ctl, db, null, ImmutableSetMultimap.of());
ReceivePack rp = arc.getReceivePack();
Capable r = arc.canUpload();

View File

@@ -295,7 +295,7 @@ public class GitOverHttpServlet extends GitServlet {
throw new ServiceNotAuthorizedException();
}
AsyncReceiveCommits arc = factory.create(pc, db, ImmutableSetMultimap.of());
AsyncReceiveCommits arc = factory.create(pc, db, null, ImmutableSetMultimap.of());
ReceivePack rp = arc.getReceivePack();
req.setAttribute(ATT_ARC, arc);
return rp;

View File

@@ -15,6 +15,7 @@
package com.google.gerrit.server.git.receive;
import com.google.common.collect.SetMultimap;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.data.Capable;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.reviewdb.client.Account;
@@ -72,6 +73,7 @@ public class AsyncReceiveCommits implements PreReceiveHook {
AsyncReceiveCommits create(
ProjectControl projectControl,
Repository repository,
@Nullable MessageSender messageSender,
SetMultimap<ReviewerStateInternal, Account.Id> extraReviewers);
}
@@ -104,6 +106,7 @@ public class AsyncReceiveCommits implements PreReceiveHook {
this.commands = commands;
rc = factory.create(projectControl, rp, allRefsWatcher, extraReviewers);
rc.init();
rc.setMessageSender(messageSender);
progress = new MultiProgressMonitor(new MessageSenderOutputStream(), "Processing changes");
}
@@ -167,6 +170,7 @@ public class AsyncReceiveCommits implements PreReceiveHook {
private final long timeoutMillis;
private final ProjectControl projectControl;
private final Repository repo;
private final MessageSender messageSender;
private final SetMultimap<ReviewerStateInternal, Account.Id> extraReviewers;
private final AllRefsWatcher allRefsWatcher;
@@ -184,15 +188,17 @@ public class AsyncReceiveCommits implements PreReceiveHook {
@Named(TIMEOUT_NAME) long timeoutMillis,
@Assisted ProjectControl projectControl,
@Assisted Repository repo,
@Assisted @Nullable MessageSender messageSender,
@Assisted SetMultimap<ReviewerStateInternal, Account.Id> extraReviewers)
throws PermissionBackendException {
this.factory = factory;
this.executor = executor;
this.scopePropagator = scopePropagator;
this.receiveConfig = receiveConfig;
this.timeoutMillis = timeoutMillis;
this.projectControl = projectControl;
this.repo = repo;
this.timeoutMillis = timeoutMillis;
this.messageSender = messageSender;
this.extraReviewers = extraReviewers;
IdentifiedUser user = projectControl.getUser().asIdentifiedUser();

View File

@@ -0,0 +1,31 @@
// Copyright (C) 2017 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.git.receive;
/**
* Interface used by {@link ReceiveCommits} for send messages over the wire during {@code
* receive-pack}.
*/
public interface MessageSender {
void sendMessage(String what);
void sendError(String what);
void sendBytes(byte[] what);
void sendBytes(byte[] what, int off, int len);
void flush();
}

View File

@@ -233,18 +233,6 @@ class ReceiveCommits {
SetMultimap<ReviewerStateInternal, Account.Id> extraReviewers);
}
interface MessageSender {
void sendMessage(String what);
void sendError(String what);
void sendBytes(byte[] what);
void sendBytes(byte[] what, int off, int len);
void flush();
}
private class ReceivePackMessageSender implements MessageSender {
@Override
public void sendMessage(String what) {

View File

@@ -81,7 +81,7 @@ final class Receive extends AbstractGitCommand {
throw new Failure(1, "fatal: receive-pack not permitted on this server");
}
AsyncReceiveCommits arc = factory.create(projectControl, repo, reviewers);
AsyncReceiveCommits arc = factory.create(projectControl, repo, null, reviewers);
Capable r = arc.canUpload();
if (r != Capable.OK) {