]> source.dussan.org Git - jgit.git/commitdiff
Refactor parsing of "filter" into its own method 58/123958/2
authorJonathan Tan <jonathantanmy@google.com>
Mon, 30 Apr 2018 19:49:02 +0000 (12:49 -0700)
committerJonathan Nieder <jrn@google.com>
Tue, 5 Jun 2018 05:08:29 +0000 (22:08 -0700)
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>
org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

index 8a4cae4bae4a39045f77d413822fc8047b34db09..4538ce2ee4a13cd94cbbe562eb9e056ab3d57b37 100644 (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;
                        }