From 62c4d3a1335bcc237a290c110b6d95bcc498e18d Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Mon, 30 Apr 2018 12:49:02 -0700 Subject: [PATCH] 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 --- .../eclipse/jgit/transport/UploadPack.java | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java index 8a4cae4bae..4538ce2ee4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -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; } -- 2.39.5