Refactor parsing of "filter" into its own method

The implementation of protocol v2 will also need to parse the "filter"
option, so refactor it into its own method.

Change-Id: I751f6e6ca63fab873298594653a3885202297a2e
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
This commit is contained in:
Jonathan Tan 2018-04-30 12:49:02 -07:00 committed by Jonathan Nieder
parent 2f60804396
commit 62c4d3a133
1 changed files with 28 additions and 24 deletions

View File

@ -1371,6 +1371,33 @@ public OutputStream getMessageOutputStream() {
return msgOut;
}
private void parseFilter(String arg) throws PackProtocolException {
if (arg.equals("blob:none")) { //$NON-NLS-1$
filterBlobLimit = 0;
} else if (arg.startsWith("blob:limit=")) { //$NON-NLS-1$
try {
filterBlobLimit = Long.parseLong(
arg.substring("blob:limit=".length())); //$NON-NLS-1$
} catch (NumberFormatException e) {
throw new PackProtocolException(
MessageFormat.format(JGitText.get().invalidFilter,
arg));
}
}
/*
* We must have (1) either "blob:none" or
* "blob:limit=" set (because we only support
* blob size limits for now), and (2) if the
* latter, then it must be nonnegative. Throw
* if (1) or (2) is not met.
*/
if (filterBlobLimit < 0) {
throw new PackProtocolException(
MessageFormat.format(JGitText.get().invalidFilter,
arg));
}
}
private void recvWants() throws IOException {
boolean isFirst = true;
boolean filterReceived = false;
@ -1411,30 +1438,7 @@ private void recvWants() throws IOException {
}
filterReceived = true;
if (arg.equals("blob:none")) { //$NON-NLS-1$
filterBlobLimit = 0;
} else if (arg.startsWith("blob:limit=")) { //$NON-NLS-1$
try {
filterBlobLimit = Long.parseLong(
arg.substring("blob:limit=".length())); //$NON-NLS-1$
} catch (NumberFormatException e) {
throw new PackProtocolException(
MessageFormat.format(JGitText.get().invalidFilter,
arg));
}
}
/*
* We must have (1) either "blob:none" or
* "blob:limit=" set (because we only support
* blob size limits for now), and (2) if the
* latter, then it must be nonnegative. Throw
* if (1) or (2) is not met.
*/
if (filterBlobLimit < 0) {
throw new PackProtocolException(
MessageFormat.format(JGitText.get().invalidFilter,
arg));
}
parseFilter(arg);
continue;
}