type_from_string_gently: make sure length matches
[gitweb.git] / object.c
index a16b9f9e936d060ba190b6c7e82ff5f25795f490..91bdde25307ebfd853082c7e38d3806b388b08d5 100644 (file)
--- a/object.c
+++ b/object.c
@@ -33,13 +33,21 @@ const char *typename(unsigned int type)
        return object_type_strings[type];
 }
 
-int type_from_string(const char *str)
+int type_from_string_gently(const char *str, ssize_t len, int gentle)
 {
        int i;
 
+       if (len < 0)
+               len = strlen(str);
+
        for (i = 1; i < ARRAY_SIZE(object_type_strings); i++)
-               if (!strcmp(str, object_type_strings[i]))
+               if (!strncmp(str, object_type_strings[i], len) &&
+                   object_type_strings[i][len] == '\0')
                        return i;
+
+       if (gentle)
+               return -1;
+
        die("invalid object type \"%s\"", str);
 }