]> source.dussan.org Git - jgit.git/commitdiff
ReceivePack: catch InvalidObjectIdException while parsing shallow 52/76652/2
authorShawn Pearce <spearce@spearce.org>
Tue, 5 Jul 2016 20:00:02 +0000 (13:00 -0700)
committerShawn Pearce <spearce@spearce.org>
Wed, 6 Jul 2016 00:17:50 +0000 (17:17 -0700)
The "shallow $id" parsing can also throw InvalidObjectIdException,
just like parseCommand. Move it into its own method with a proper
try-catch block to convert to the checked PackProtocolException.

Change-Id: I6839b95f0bc4fbf4d2c213331ebb9bd24ab2af65

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

index 9792df4d1a1f51c4c29a7b89c6ad854e82b3e880..f4eef5f48e690f94171dd02585c65250c59625c0 100644 (file)
@@ -1093,7 +1093,7 @@ public abstract class BaseReceivePack {
                                }
 
                                if (line.length() >= 48 && line.startsWith("shallow ")) { //$NON-NLS-1$
-                                       clientShallowCommits.add(ObjectId.fromString(line.substring(8, 48)));
+                                       parseShallow(line.substring(8, 48));
                                        continue;
                                }
 
@@ -1133,6 +1133,16 @@ public abstract class BaseReceivePack {
                }
        }
 
+       private void parseShallow(String idStr) throws PackProtocolException {
+               ObjectId id;
+               try {
+                       id = ObjectId.fromString(idStr);
+               } catch (InvalidObjectIdException e) {
+                       throw new PackProtocolException(e.getMessage(), e);
+               }
+               clientShallowCommits.add(id);
+       }
+
        static ReceiveCommand parseCommand(String line) throws PackProtocolException {
           if (line == null || line.length() < 83) {
                        throw new PackProtocolException(