upload-pack: only accept commits from "shallow" line

We only allow cuts at commits, not arbitrary objects. upload-pack will fail eventually in register_shallow if a non-commit is given with a generic error "Object %s is a %s, not a commit". Check it early and give a more accurate error. This should never show up in an ordinary session. It's for buggy clients, or when the user manually edits .git/shallow. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Jan 8, 2013 at 18:32 UTC 6293ded348a918e5644d286dcd8b05044097c27d
1 file changed +2
upload-pack.c
+2
@@ -603,6 +603,8 @@ static void receive_needs(void)
603 object = parse_object(sha1);
604 if (!object)
605 die("did not find object for %s", line);
606 + if (object->type != OBJ_COMMIT)
607 + die("invalid shallow object %s", sha1_to_hex(sha1));
608 object->flags |= CLIENT_SHALLOW;
609 add_object_array(object, NULL, &shallows);
610 continue;