]> source.dussan.org Git - jgit.git/commitdiff
ReceivePack: integrate push option parsing into recvCommands 57/79957/2
authorShawn Pearce <spearce@spearce.org>
Mon, 29 Aug 2016 19:11:11 +0000 (12:11 -0700)
committerShawn Pearce <spearce@spearce.org>
Mon, 29 Aug 2016 19:31:22 +0000 (12:31 -0700)
This allows the same try/catch to handle parsing the command list,
push certificate and push options. Any errors will be caught and
handled by the same catch block, as the client is in the same state.

Change-Id: I13a66f9100e2dc8ca8f72cd701a5bd44d093ec84

org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java

index 5a61edd6ab1ad6b1566841119044fd26b4e6174b..0724eac701a695e7fa0213de81464b1cf5ae4b80 100644 (file)
@@ -1171,6 +1171,9 @@ public abstract class BaseReceivePack {
                                }
                        }
                        pushCert = certParser.build();
+                       if (hasCommands()) {
+                               readPostCommands(pckIn);
+                       }
                } catch (PackProtocolException e) {
                        if (sideBand) {
                                try {
@@ -1217,6 +1220,16 @@ public abstract class BaseReceivePack {
                return new ReceiveCommand(oldId, newId, name);
        }
 
+       /**
+        * @param in
+        *            request stream.
+        * @throws IOException
+        *             request line cannot be read.
+        */
+       void readPostCommands(PacketLineIn in) throws IOException {
+               // Do nothing by default.
+       }
+
        /** Enable capabilities based on a previously read capabilities line. */
        protected void enableCapabilities() {
                sideBand = isCapabilityEnabled(CAPABILITY_SIDE_BAND_64K);
index 2e3d74a1474c1f36e4dbc1840b4f09b59356cdde..cc20d50a7fe17cbfec33f534fcbc11937b7f4676 100644 (file)
@@ -220,14 +220,17 @@ public class ReceivePack extends BaseReceivePack {
                super.enableCapabilities();
        }
 
-       private void readPushOptions() throws IOException {
-               pushOptions = new ArrayList<>(4);
-               for (;;) {
-                       String option = pckIn.readString();
-                       if (option == PacketLineIn.END) {
-                               break;
+       @Override
+       void readPostCommands(PacketLineIn in) throws IOException {
+               if (usePushOptions) {
+                       pushOptions = new ArrayList<>(4);
+                       for (;;) {
+                               String option = in.readString();
+                               if (option == PacketLineIn.END) {
+                                       break;
+                               }
+                               pushOptions.add(option);
                        }
-                       pushOptions.add(option);
                }
        }
 
@@ -241,10 +244,6 @@ public class ReceivePack extends BaseReceivePack {
                        return;
                recvCommands();
                if (hasCommands()) {
-                       if (usePushOptions) {
-                               readPushOptions();
-                       }
-
                        Throwable unpackError = null;
                        if (needPack()) {
                                try {