Commit d1e44655 by Edward Thomson

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.
parent dacc3291
...@@ -236,13 +236,22 @@ const char *git_object_type2string(git_otype type) ...@@ -236,13 +236,22 @@ const char *git_object_type2string(git_otype type)
git_otype git_object_string2type(const char *str) 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; size_t i;
if (!str || !*str) if (!str || !len || !*str)
return GIT_OBJ_BAD; return GIT_OBJ_BAD;
for (i = 0; i < ARRAY_SIZE(git_objects_table); i++) 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_otype)i;
return GIT_OBJ_BAD; return GIT_OBJ_BAD;
......
...@@ -30,6 +30,8 @@ int git_object__from_odb_object( ...@@ -30,6 +30,8 @@ int git_object__from_odb_object(
int git_object__resolve_to_type(git_object **obj, git_otype type); int git_object__resolve_to_type(git_object **obj, git_otype type);
git_otype git_object_stringn2type(const char *str, size_t len);
int git_oid__parse(git_oid *oid, const char **buffer_out, const char *buffer_end, const char *header); int git_oid__parse(git_oid *oid, const char **buffer_out, const char *buffer_end, const char *header);
void git_oid__writebuf(git_buf *buf, const char *header, const git_oid *oid); void git_oid__writebuf(git_buf *buf, const char *header, const git_oid *oid);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment