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

@@ -109,16 +109,6 @@ public class ReceiveCommits implements PreReceiveHook, PostReceiveHook {
ReceiveCommits create(ProjectControl projectControl, Repository repository);
}
public interface MessageListener {
public static final MessageListener DISABLED = new MessageListener() {
@Override
public void warn(String msg) {
}
};
void warn(String msg) throws IOException;
}
public static class Capable {
public static final Capable OK = new Capable("OK");
@@ -133,7 +123,6 @@ public class ReceiveCommits implements PreReceiveHook, PostReceiveHook {
}
}
private MessageListener messages = MessageListener.DISABLED;
private final Set<Account.Id> reviewerId = new HashSet<Account.Id>();
private final Set<Account.Id> ccId = new HashSet<Account.Id>();
@@ -207,11 +196,6 @@ public class ReceiveCommits implements PreReceiveHook, PostReceiveHook {
rp.setPostReceiveHook(this);
}
/** Set the logger where warning messages are sent to the user. */
public void setMessageListener(MessageListener logger) {
this.messages = logger;
}
/** Add reviewers for new (or updated) changes. */
public void addReviewers(Collection<Account.Id> who) {
reviewerId.addAll(who);
@@ -246,11 +230,6 @@ public class ReceiveCommits implements PreReceiveHook, PostReceiveHook {
}
}
/** @return the set of new changes, if any were created during receive. */
public List<Change.Id> getNewChanges() {
return allNewChanges;
}
public void onPreReceive(final ReceivePack arg0,
final Collection<ReceiveCommand> commands) {
parseCommands(commands);
@@ -287,6 +266,16 @@ public class ReceiveCommits implements PreReceiveHook, PostReceiveHook {
}
}
}
if (!allNewChanges.isEmpty() && canonicalWebUrl != null) {
final String url = canonicalWebUrl;
rp.sendMessage("");
rp.sendMessage("New Changes:");
for (final Change.Id c : allNewChanges) {
rp.sendMessage(" " + url + c.get());
}
rp.sendMessage("");
}
}
private Capable verifyActiveContributorAgreement() throws OrmException {
@@ -1003,7 +992,7 @@ public class ReceiveCommits implements PreReceiveHook, PostReceiveHook {
reject(request.cmd, "no changes made");
return null;
} else {
messages.warn(change.getKey().abbreviate() + ": " //
rp.sendMessage("warning: " + change.getKey().abbreviate() + ": " //
+ " no files changed, but" //
+ (!messageEq ? " message updated" : "") //
+ (!messageEq && !parentsEq ? " and" : "") //