Browse Source

transport: Consolidate status reporting code

BaseReceivePack#sendStatusReport anyway needs to know
CAPABILITY_REPORT_STATUS. By moving this flag to BaseReceivePack,
simplify the status reporting code.

Change-Id: Iaa0878b1fc13057b687a7f01d25c85fd78c0423e
Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
stable-5.7
Masaya Suzuki 5 years ago
parent
commit
4fcc43a1de
  1. 192
      org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java

192
org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java

@ -1853,98 +1853,113 @@ public class ReceivePack {
/**
* Send a status report.
*
* @param forClient
* true if this report is for a Git client, false if it is for an
* end-user.
* @param unpackError
* an error that occurred during unpacking, or {@code null}
* @param out
* the reporter for sending the status strings.
* @throws java.io.IOException
* an error occurred writing the status report.
* @since 5.6
*/
private void sendStatusReport(final boolean forClient,
final Throwable unpackError, final Reporter out)
throws IOException {
if (unpackError != null) {
out.sendString("unpack error " + unpackError.getMessage()); //$NON-NLS-1$
if (forClient) {
for (ReceiveCommand cmd : commands) {
out.sendString("ng " + cmd.getRefName() //$NON-NLS-1$
+ " n/a (unpacker error)"); //$NON-NLS-1$
private void sendStatusReport(Throwable unpackError) throws IOException {
Reporter out = new Reporter() {
@Override
void sendString(String s) throws IOException {
if (reportStatus) {
pckOut.writeString(s + "\n"); //$NON-NLS-1$
} else if (msgOut != null) {
msgOut.write(Constants.encode(s + "\n")); //$NON-NLS-1$
}
}
return;
}
};
if (forClient)
out.sendString("unpack ok"); //$NON-NLS-1$
for (ReceiveCommand cmd : commands) {
if (cmd.getResult() == Result.OK) {
if (forClient)
out.sendString("ok " + cmd.getRefName()); //$NON-NLS-1$
continue;
try {
if (unpackError != null) {
out.sendString("unpack error " + unpackError.getMessage()); //$NON-NLS-1$
if (reportStatus) {
for (ReceiveCommand cmd : commands) {
out.sendString("ng " + cmd.getRefName() //$NON-NLS-1$
+ " n/a (unpacker error)"); //$NON-NLS-1$
}
}
return;
}
final StringBuilder r = new StringBuilder();
if (forClient)
r.append("ng ").append(cmd.getRefName()).append(" "); //$NON-NLS-1$ //$NON-NLS-2$
else
r.append(" ! [rejected] ").append(cmd.getRefName()) //$NON-NLS-1$
.append(" ("); //$NON-NLS-1$
switch (cmd.getResult()) {
case NOT_ATTEMPTED:
r.append("server bug; ref not processed"); //$NON-NLS-1$
break;
case REJECTED_NOCREATE:
r.append("creation prohibited"); //$NON-NLS-1$
break;
case REJECTED_NODELETE:
r.append("deletion prohibited"); //$NON-NLS-1$
break;
case REJECTED_NONFASTFORWARD:
r.append("non-fast forward"); //$NON-NLS-1$
break;
case REJECTED_CURRENT_BRANCH:
r.append("branch is currently checked out"); //$NON-NLS-1$
break;
case REJECTED_MISSING_OBJECT:
if (cmd.getMessage() == null)
r.append("missing object(s)"); //$NON-NLS-1$
else if (cmd.getMessage()
.length() == Constants.OBJECT_ID_STRING_LENGTH) {
r.append("object "); //$NON-NLS-1$
r.append(cmd.getMessage());
r.append(" missing"); //$NON-NLS-1$
} else
r.append(cmd.getMessage());
break;
case REJECTED_OTHER_REASON:
if (cmd.getMessage() == null)
r.append("unspecified reason"); //$NON-NLS-1$
else
r.append(cmd.getMessage());
break;
case LOCK_FAILURE:
r.append("failed to lock"); //$NON-NLS-1$
break;
case OK:
// We shouldn't have reached this case (see 'ok' case above).
continue;
if (reportStatus) {
out.sendString("unpack ok"); //$NON-NLS-1$
}
for (ReceiveCommand cmd : commands) {
if (cmd.getResult() == Result.OK) {
if (reportStatus) {
out.sendString("ok " + cmd.getRefName()); //$NON-NLS-1$
}
continue;
}
final StringBuilder r = new StringBuilder();
if (reportStatus) {
r.append("ng ").append(cmd.getRefName()).append(" "); //$NON-NLS-1$ //$NON-NLS-2$
} else {
r.append(" ! [rejected] ").append(cmd.getRefName()) //$NON-NLS-1$
.append(" ("); //$NON-NLS-1$
}
switch (cmd.getResult()) {
case NOT_ATTEMPTED:
r.append("server bug; ref not processed"); //$NON-NLS-1$
break;
case REJECTED_NOCREATE:
r.append("creation prohibited"); //$NON-NLS-1$
break;
case REJECTED_NODELETE:
r.append("deletion prohibited"); //$NON-NLS-1$
break;
case REJECTED_NONFASTFORWARD:
r.append("non-fast forward"); //$NON-NLS-1$
break;
case REJECTED_CURRENT_BRANCH:
r.append("branch is currently checked out"); //$NON-NLS-1$
break;
case REJECTED_MISSING_OBJECT:
if (cmd.getMessage() == null)
r.append("missing object(s)"); //$NON-NLS-1$
else if (cmd.getMessage()
.length() == Constants.OBJECT_ID_STRING_LENGTH) {
r.append("object "); //$NON-NLS-1$
r.append(cmd.getMessage());
r.append(" missing"); //$NON-NLS-1$
} else
r.append(cmd.getMessage());
break;
case REJECTED_OTHER_REASON:
if (cmd.getMessage() == null)
r.append("unspecified reason"); //$NON-NLS-1$
else
r.append(cmd.getMessage());
break;
case LOCK_FAILURE:
r.append("failed to lock"); //$NON-NLS-1$
break;
case OK:
// We shouldn't have reached this case (see 'ok' case
// above).
continue;
}
if (!reportStatus) {
r.append(")"); //$NON-NLS-1$
}
out.sendString(r.toString());
}
} finally {
if (reportStatus) {
pckOut.end();
}
if (!forClient)
r.append(")"); //$NON-NLS-1$
out.sendString(r.toString());
}
}
@ -2228,22 +2243,7 @@ public class ReceivePack {
unlockPack();
}
if (reportStatus) {
sendStatusReport(true, unpackError, new Reporter() {
@Override
void sendString(String s) throws IOException {
pckOut.writeString(s + "\n"); //$NON-NLS-1$
}
});
pckOut.end();
} else if (msgOut != null) {
sendStatusReport(false, unpackError, new Reporter() {
@Override
void sendString(String s) throws IOException {
msgOut.write(Constants.encode(s + "\n")); //$NON-NLS-1$
}
});
}
sendStatusReport(unpackError);
if (unpackError != null) {
// we already know which exception to throw. Ignore

Loading…
Cancel
Save