ReceivePack: Use error message if set

ReceiveCommand can have an error message. This is shown only for some
cases even if it's set. This change uses the error message if it's set,
and fallback to the default message if unset.

Change-Id: I8d906e71ad08cf49bcdb28caea8fcc66798c68ff
Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
This commit is contained in:
Masaya Suzuki 2020-03-24 11:50:34 -07:00
parent 459fc28cf6
commit 7ad42d7416
1 changed files with 40 additions and 36 deletions

View File

@ -1814,6 +1814,22 @@ void sendString(String s) throws IOException {
.append(" ("); //$NON-NLS-1$ .append(" ("); //$NON-NLS-1$
} }
if (cmd.getResult() == Result.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) {
// TODO: Using get/setMessage to store an OID is a
// misuse. The caller should set a full error message.
r.append("object "); //$NON-NLS-1$
r.append(cmd.getMessage());
r.append(" missing"); //$NON-NLS-1$
} else {
r.append(cmd.getMessage());
}
} else if (cmd.getMessage() != null) {
r.append(cmd.getMessage());
} else {
switch (cmd.getResult()) { switch (cmd.getResult()) {
case NOT_ATTEMPTED: case NOT_ATTEMPTED:
r.append("server bug; ref not processed"); //$NON-NLS-1$ r.append("server bug; ref not processed"); //$NON-NLS-1$
@ -1835,34 +1851,22 @@ void sendString(String s) throws IOException {
r.append("branch is currently checked out"); //$NON-NLS-1$ r.append("branch is currently checked out"); //$NON-NLS-1$
break; 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: case REJECTED_OTHER_REASON:
if (cmd.getMessage() == null)
r.append("unspecified reason"); //$NON-NLS-1$ r.append("unspecified reason"); //$NON-NLS-1$
else
r.append(cmd.getMessage());
break; break;
case LOCK_FAILURE: case LOCK_FAILURE:
r.append("failed to lock"); //$NON-NLS-1$ r.append("failed to lock"); //$NON-NLS-1$
break; break;
case REJECTED_MISSING_OBJECT:
case OK: case OK:
// We shouldn't have reached this case (see 'ok' case // We shouldn't have reached this case (see 'ok' case
// above). // above and if-statement above).
continue; throw new AssertionError();
} }
}
if (!reportStatus) { if (!reportStatus) {
r.append(")"); //$NON-NLS-1$ r.append(")"); //$NON-NLS-1$
} }