Move new change display to PostReceiveHook

Future versions of Git (and JGit) will support sending messages from
the server side down a muxed side-band channel, so we can put custom
messages onto the client's terminal even over protocols like http://.

Instead of writing these new change links only in the SSH code,
write them in our onPostReceive hook so they can become part of
that side-band channel once we upgrade to a JGit that supports it.
Until then, these will still appear on ssh:// connections, but
won't show on http://.

Change-Id: Ibcc94cf93191f8b2fb9c5c446dee05d5e168b28e
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2010-02-10 20:00:07 -08:00
parent 7e28358bf7
commit f33c39a87e
2 changed files with 11 additions and 55 deletions

View File

@@ -15,11 +15,8 @@
package com.google.gerrit.sshd.commands;
import com.google.gerrit.reviewdb.Account;
import com.google.gerrit.reviewdb.Change;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.config.CanonicalWebUrl;
import com.google.gerrit.server.git.ReceiveCommits;
import com.google.gerrit.server.git.ReceiveCommits.MessageListener;
import com.google.gerrit.sshd.AbstractGitCommand;
import com.google.inject.Inject;
@@ -31,8 +28,6 @@ import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
import javax.annotation.Nullable;
/** Receives change upload over SSH using the Git receive-pack protocol. */
final class Receive extends AbstractGitCommand {
@Inject
@@ -44,11 +39,6 @@ final class Receive extends AbstractGitCommand {
@Inject
private IdentifiedUser.GenericFactory identifiedUserFactory;
@Inject
@CanonicalWebUrl
@Nullable
private String canonicalWebUrl;
private final Set<Account.Id> reviewerId = new HashSet<Account.Id>();
private final Set<Account.Id> ccId = new HashSet<Account.Id>();
@@ -75,35 +65,12 @@ final class Receive extends AbstractGitCommand {
verifyProjectVisible("reviewer", reviewerId);
verifyProjectVisible("CC", ccId);
receive.setMessageListener(new MessageListener() {
@Override
public void warn(String warning) {
msg.print("warning: " + warning + "\n");
msg.flush();
}
});
receive.addReviewers(reviewerId);
receive.addExtraCC(ccId);
final ReceivePack rp = receive.getReceivePack();
rp.setRefLogIdent(currentUser.newRefLogIdent());
rp.receive(in, out, err);
if (!receive.getNewChanges().isEmpty() && canonicalWebUrl != null) {
// Make sure there isn't anything buffered; we want to give the
// push client a chance to display its status report before we
// show our own messages on standard error.
//
out.flush();
final String url = canonicalWebUrl;
msg.write("\nNew Changes:\n");
for (final Change.Id c : receive.getNewChanges()) {
msg.write(" " + url + c.get() + "\n");
}
msg.write('\n');
msg.flush();
}
}
private void verifyProjectVisible(final String type, final Set<Account.Id> who)