diff options
| author | Ramsay Jones <ramsay@ramsay1.demon.co.uk> | 2008-12-10 18:31:28 +0000 |
|---|---|---|
| committer | Shawn O. Pearce <spearce@spearce.org> | 2008-12-10 11:49:06 -0800 |
| commit | 7b6e8067ec96acef9a4184b43210d583b6d2f99a (patch) | |
| tree | 20c4a63e8cd8a70bc0f894ada6a54afbdefffadf /src/odb.c | |
| parent | b3be0fc7562d51df415c14abf671deb37d8f89ef (diff) | |
| download | libgit2-7b6e8067ec96acef9a4184b43210d583b6d2f99a.tar.gz | |
Add some git_otype string conversion and testing routines
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'src/odb.c')
| -rw-r--r-- | src/odb.c | 54 |
1 files changed, 54 insertions, 0 deletions
@@ -24,6 +24,7 @@ */ #include "git/odb.h" +#include "util.h" struct git_odb { /** Path to the "objects" directory. */ @@ -33,6 +34,48 @@ struct git_odb { git_odb **alternates; }; +static struct { + const char *str; /* type name string */ + int loose; /* valid loose object type flag */ +} obj_type_table [] = { + { "", 0 }, /* 0 = GIT_OBJ__EXT1 */ + { "commit", 1 }, /* 1 = GIT_OBJ_COMMIT */ + { "tree", 1 }, /* 2 = GIT_OBJ_TREE */ + { "blob", 1 }, /* 3 = GIT_OBJ_BLOB */ + { "tag", 1 }, /* 4 = GIT_OBJ_TAG */ + { "", 0 }, /* 5 = GIT_OBJ__EXT2 */ + { "OFS_DELTA", 0 }, /* 6 = GIT_OBJ_OFS_DELTA */ + { "REF_DELTA", 0 } /* 7 = GIT_OBJ_REF_DELTA */ +}; + +const char *git_obj_type_to_string(git_otype type) +{ + if (type < 0 || type >= ARRAY_SIZE(obj_type_table)) + return ""; + return obj_type_table[type].str; +} + +git_otype git_obj_string_to_type(const char *str) +{ + int i; + + if (!str || !*str) + return GIT_OBJ_BAD; + + for (i = 0; i < ARRAY_SIZE(obj_type_table); i++) + if (!strcmp(str, obj_type_table[i].str)) + return (git_otype) i; + + return GIT_OBJ_BAD; +} + +int git_obj__loose_object_type(git_otype type) +{ + if (type < 0 || type >= ARRAY_SIZE(obj_type_table)) + return 0; + return obj_type_table[type].loose; +} + static int open_alternates(git_odb *db) { unsigned n = 0; @@ -95,3 +138,14 @@ attempt: out->data = NULL; return GIT_ENOTFOUND; } + +int git_odb__read_loose(git_obj *out, git_odb *db, const git_oid *id) +{ + return GIT_SUCCESS; +} + +int git_odb__read_packed(git_obj *out, git_odb *db, const git_oid *id) +{ + return GIT_SUCCESS; +} + |
