Make ReceiveCommits only a PreReceiveHook
Previously, ReceiveCommits.onPostReceive() depended on state set up by onPreReceive(), making this class inappropriate for implementing a stateless RPC. The only benefit to splitting up the pre/post-receive steps was to let the ref updates fall through to core JGit in a few cases. Now that JGit has been refactored to make these ref updates trivial, just handle everything from within ReceiveCommits. Change-Id: Iaac64301c3ac3a33052cc30b2bb0b5cf61d4b1bd
This commit is contained in:
@@ -74,7 +74,6 @@ import org.eclipse.jgit.revwalk.RevObject;
|
||||
import org.eclipse.jgit.revwalk.RevSort;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.eclipse.jgit.revwalk.filter.RevFilter;
|
||||
import org.eclipse.jgit.transport.PostReceiveHook;
|
||||
import org.eclipse.jgit.transport.PreReceiveHook;
|
||||
import org.eclipse.jgit.transport.ReceiveCommand;
|
||||
import org.eclipse.jgit.transport.ReceiveCommand.Result;
|
||||
@@ -98,7 +97,7 @@ import java.util.regex.Pattern;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/** Receives change upload using the Git receive-pack protocol. */
|
||||
public class ReceiveCommits implements PreReceiveHook, PostReceiveHook {
|
||||
public class ReceiveCommits implements PreReceiveHook {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(ReceiveCommits.class);
|
||||
|
||||
@@ -212,7 +211,6 @@ public class ReceiveCommits implements PreReceiveHook, PostReceiveHook {
|
||||
rp.setAdvertiseRefsHook(new ReceiveCommitsAdvertiseRefsHook(rp.getAdvertiseRefsHook()));
|
||||
|
||||
rp.setPreReceiveHook(this);
|
||||
rp.setPostReceiveHook(this);
|
||||
}
|
||||
|
||||
/** Add reviewers for new (or updated) changes. */
|
||||
@@ -323,11 +321,7 @@ public class ReceiveCommits implements PreReceiveHook, PostReceiveHook {
|
||||
createNewChanges();
|
||||
}
|
||||
doReplaces();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostReceive(final ReceivePack arg0,
|
||||
final Collection<ReceiveCommand> commands) {
|
||||
for (final ReceiveCommand c : commands) {
|
||||
if (c.getResult() == Result.OK) {
|
||||
switch (c.getType()) {
|
||||
@@ -514,8 +508,7 @@ public class ReceiveCommits implements PreReceiveHook, PostReceiveHook {
|
||||
RefControl ctl = projectControl.controlForRef(cmd.getRefName());
|
||||
if (ctl.canCreate(rp.getRevWalk(), obj)) {
|
||||
validateNewCommits(ctl, cmd);
|
||||
|
||||
// Let the core receive process handle it
|
||||
cmd.execute(rp);
|
||||
} else {
|
||||
reject(cmd, "can not create new references");
|
||||
}
|
||||
@@ -529,7 +522,7 @@ public class ReceiveCommits implements PreReceiveHook, PostReceiveHook {
|
||||
}
|
||||
|
||||
validateNewCommits(ctl, cmd);
|
||||
// Let the core receive process handle it
|
||||
cmd.execute(rp);
|
||||
} else {
|
||||
reject(cmd, "can not update the reference as a fast forward");
|
||||
}
|
||||
@@ -557,7 +550,7 @@ public class ReceiveCommits implements PreReceiveHook, PostReceiveHook {
|
||||
private void parseDelete(final ReceiveCommand cmd) {
|
||||
RefControl ctl = projectControl.controlForRef(cmd.getRefName());
|
||||
if (ctl.canDelete()) {
|
||||
// Let the core receive process handle it
|
||||
cmd.execute(rp);
|
||||
} else {
|
||||
reject(cmd, "can not delete references");
|
||||
}
|
||||
@@ -585,7 +578,7 @@ public class ReceiveCommits implements PreReceiveHook, PostReceiveHook {
|
||||
}
|
||||
|
||||
if (ctl.canForceUpdate()) {
|
||||
// Let the core receive process handle it
|
||||
cmd.execute(rp);
|
||||
} else {
|
||||
cmd.setResult(ReceiveCommand.Result.REJECTED_NONFASTFORWARD, " need '"
|
||||
+ PermissionRule.FORCE_PUSH + "' privilege.");
|
||||
|
||||
Reference in New Issue
Block a user