Browse Source

Report PackProtocolExceptions to client during receive-pack

We have done this since forever with the "wanted old new ref" error,
so let's do it for other such errors thrown in the same block as well.

Change-Id: Ib3b1c7f05e31a5b3e40e85eb07b16736920a033b
tags/v4.1.0.201509280440-r
Dave Borowitz 8 years ago
parent
commit
6e4e34bb9e

+ 2
- 1
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java View File

import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;


import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.errors.PackProtocolException;
import org.eclipse.jgit.errors.UnpackException; import org.eclipse.jgit.errors.UnpackException;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.InternalHttpServerGlue; import org.eclipse.jgit.transport.InternalHttpServerGlue;
consumeRequestBody(req); consumeRequestBody(req);
out.close(); out.close();


} catch (UnpackException e) {
} catch (UnpackException | PackProtocolException e) {
// This should be already reported to the client. // This should be already reported to the client.
log(rp.getRepository(), e.getCause()); log(rp.getRepository(), e.getCause());
consumeRequestBody(req); consumeRequestBody(req);

+ 4
- 4
org.eclipse.jgit/src/org/eclipse/jgit/errors/PackProtocolException.java View File

* @param uri * @param uri
* URI used for transport * URI used for transport
* @param s * @param s
* message
* message, which may be shown to an end-user.
*/ */
public PackProtocolException(final URIish uri, final String s) { public PackProtocolException(final URIish uri, final String s) {
super(uri + ": " + s); //$NON-NLS-1$ super(uri + ": " + s); //$NON-NLS-1$
* @param uri * @param uri
* URI used for transport * URI used for transport
* @param s * @param s
* message
* message, which may be shown to an end-user.
* @param cause * @param cause
* root cause exception * root cause exception
*/ */
* Constructs an PackProtocolException with the specified detail message. * Constructs an PackProtocolException with the specified detail message.
* *
* @param s * @param s
* message
* message, which may be shown to an end-user.
*/ */
public PackProtocolException(final String s) { public PackProtocolException(final String s) {
super(s); super(s);
* Constructs an PackProtocolException with the specified detail message. * Constructs an PackProtocolException with the specified detail message.
* *
* @param s * @param s
* message
* message, which may be shown to an end-user.
* @param cause * @param cause
* root cause exception * root cause exception
*/ */

+ 48
- 43
org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java View File

protected void recvCommands() throws IOException { protected void recvCommands() throws IOException {
PushCertificateParser certParser = getPushCertificateParser(); PushCertificateParser certParser = getPushCertificateParser();
FirstLine firstLine = null; FirstLine firstLine = null;
for (;;) {
String line;
try {
line = pckIn.readString();
} catch (EOFException eof) {
if (commands.isEmpty())
return;
throw eof;
}
if (line == PacketLineIn.END) {
break;
}
try {
for (;;) {
String line;
try {
line = pckIn.readString();
} catch (EOFException eof) {
if (commands.isEmpty())
return;
throw eof;
}
if (line == PacketLineIn.END) {
break;
}


if (line.length() >= 48 && line.startsWith("shallow ")) { //$NON-NLS-1$
clientShallowCommits.add(ObjectId.fromString(line.substring(8, 48)));
continue;
}
if (line.length() >= 48 && line.startsWith("shallow ")) { //$NON-NLS-1$
clientShallowCommits.add(ObjectId.fromString(line.substring(8, 48)));
continue;
}


if (firstLine == null) {
firstLine = new FirstLine(line);
enabledCapabilities = firstLine.getCapabilities();
line = firstLine.getLine();
if (firstLine == null) {
firstLine = new FirstLine(line);
enabledCapabilities = firstLine.getCapabilities();
line = firstLine.getLine();


if (line.equals(GitProtocolConstants.OPTION_PUSH_CERT)) {
certParser.receiveHeader(pckIn, !isBiDirectionalPipe());
continue;
if (line.equals(GitProtocolConstants.OPTION_PUSH_CERT)) {
certParser.receiveHeader(pckIn, !isBiDirectionalPipe());
continue;
}
} }
}


if (line.equals(PushCertificateParser.BEGIN_SIGNATURE)) {
certParser.receiveSignature(pckIn);
continue;
}
if (line.equals(PushCertificateParser.BEGIN_SIGNATURE)) {
certParser.receiveSignature(pckIn);
continue;
}


ReceiveCommand cmd;
try {
cmd = parseCommand(line);
} catch (PackProtocolException e) {
sendError(e.getMessage());
throw e;
}
if (cmd.getRefName().equals(Constants.HEAD)) {
cmd.setResult(Result.REJECTED_CURRENT_BRANCH);
} else {
cmd.setRef(refs.get(cmd.getRefName()));
}
commands.add(cmd);
if (certParser.enabled()) {
certParser.addCommand(cmd);
ReceiveCommand cmd;
try {
cmd = parseCommand(line);
} catch (PackProtocolException e) {
sendError(e.getMessage());
throw e;
}
if (cmd.getRefName().equals(Constants.HEAD)) {
cmd.setResult(Result.REJECTED_CURRENT_BRANCH);
} else {
cmd.setRef(refs.get(cmd.getRefName()));
}
commands.add(cmd);
if (certParser.enabled()) {
certParser.addCommand(cmd);
}
} }
} catch (PackProtocolException e) {
sendError(e.getMessage());
throw e;
} }
} }



Loading…
Cancel
Save