Browse Source

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>
tags/v5.0.0.201806050710-rc3
Jonathan Tan 6 years ago
parent
commit
62c4d3a133
1 changed files with 28 additions and 24 deletions
  1. 28
    24
      org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

+ 28
- 24
org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java View File

@@ -1371,6 +1371,33 @@ public class UploadPack {
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 @@ public class UploadPack {
}
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;
}


Loading…
Cancel
Save