]> source.dussan.org Git - jgit.git/commitdiff
Extract path segment check function in ObjectChecker 25/23225/2
authorShawn Pearce <spearce@spearce.org>
Wed, 12 Mar 2014 00:42:01 +0000 (17:42 -0700)
committerShawn Pearce <spearce@spearce.org>
Wed, 12 Mar 2014 22:43:38 +0000 (15:43 -0700)
Start pulling out the path segment checking. This will be used
later to support DirCacheCheckout verification of paths, after
folding that logic into this location.

Change-Id: I66eaee5c988eb7d425fb7a708ef6f5419ab77348

org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java

index 14cb5289840d08ef86d0e98b1b5d19d883507541..6e470c9b2b8a9e07fcff813c42e8c0c7e75ad710 100644 (file)
@@ -346,15 +346,7 @@ public class ObjectChecker {
                                if (c == '/')
                                        throw new CorruptObjectException("name contains '/'");
                        }
-                       if (thisNameB + 1 == ptr)
-                               throw new CorruptObjectException("zero length name");
-                       if (raw[thisNameB] == '.') {
-                               final int nameLen = (ptr - 1) - thisNameB;
-                               if (nameLen == 1)
-                                       throw new CorruptObjectException("invalid name '.'");
-                               if (nameLen == 2 && raw[thisNameB + 1] == '.')
-                                       throw new CorruptObjectException("invalid name '..'");
-                       }
+                       checkPathSegment(raw, thisNameB, ptr - 1);
                        if (duplicateName(raw, thisNameB, ptr - 1))
                                throw new CorruptObjectException("duplicate entry names");
 
@@ -375,6 +367,19 @@ public class ObjectChecker {
                }
        }
 
+       private static void checkPathSegment(byte[] raw, int ptr, int end)
+                       throws CorruptObjectException {
+               if (ptr == end)
+                       throw new CorruptObjectException("zero length name");
+               if (raw[ptr] == '.') {
+                       int nameLen = end - ptr;
+                       if (nameLen == 1)
+                               throw new CorruptObjectException("invalid name '.'");
+                       if (nameLen == 2 && raw[ptr + 1] == '.')
+                               throw new CorruptObjectException("invalid name '..'");
+               }
+       }
+
        /**
         * Check a blob for errors.
         *