From d1e446550a966a1dbc5d765aa79fe9bc47a1c1a3 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 30 Nov 2017 15:52:47 +0000 Subject: object: introduce git_object_stringn2type Introduce an internal API to get the object type based on a length-specified (not null terminated) string representation. This can be used to compare the (space terminated) object type name in a loose object. Reimplement `git_object_string2type` based on this API. --- src/object.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/object.c') diff --git a/src/object.c b/src/object.c index 4d069a34c..48f561384 100644 --- a/src/object.c +++ b/src/object.c @@ -235,14 +235,23 @@ const char *git_object_type2string(git_otype type) } git_otype git_object_string2type(const char *str) +{ + if (!str) + return GIT_OBJ_BAD; + + return git_object_stringn2type(str, strlen(str)); +} + +git_otype git_object_stringn2type(const char *str, size_t len) { size_t i; - if (!str || !*str) + if (!str || !len || !*str) return GIT_OBJ_BAD; for (i = 0; i < ARRAY_SIZE(git_objects_table); i++) - if (!strcmp(str, git_objects_table[i].str)) + if (*git_objects_table[i].str && + !git__prefixncmp(str, len, git_objects_table[i].str)) return (git_otype)i; return GIT_OBJ_BAD; -- cgit v1.2.1