Commit 7d7cd885 by Vicent Marti

Decouple storage from ODB logic

Comes with two default backends: loose object and packfiles.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
parent 86bfec39
...@@ -17,17 +17,53 @@ GIT_BEGIN_DECL ...@@ -17,17 +17,53 @@ GIT_BEGIN_DECL
/** An open object database handle. */ /** An open object database handle. */
typedef struct git_odb git_odb; typedef struct git_odb git_odb;
/** A custom backend in an ODB */
typedef struct git_odb_backend git_odb_backend;
/** /**
* Open an object database for read/write access. * Create a new object database with no backends.
*
* Before the ODB can be used for read/writing, a custom database
* backend must be manually added using `git_odb_add_backend()`
*
* @param out location to store the database pointer, if opened.
* Set to NULL if the open failed.
* @return GIT_SUCCESS if the database was created; otherwise an error
* code describing why the open was not possible.
*/
GIT_EXTERN(int) git_odb_new(git_odb **out);
/**
* Create a new object database and automatically add
* the two default backends:
*
* - git_odb_backend_loose: read and write loose object files
* from disk, assuming `objects_dir` as the Objects folder
*
* - git_odb_backend_pack: read objects from packfiles,
* assuming `objects_dir` as the Objects folder which
* contains a 'pack/' folder with the corresponding data
*
* @param out location to store the database pointer, if opened. * @param out location to store the database pointer, if opened.
* Set to NULL if the open failed. * Set to NULL if the open failed.
* @param objects_dir path of the database's "objects" directory. * @param objects_dir path of the backends' "objects" directory.
* @return GIT_SUCCESS if the database opened; otherwise an error * @return GIT_SUCCESS if the database opened; otherwise an error
* code describing why the open was not possible. * code describing why the open was not possible.
*/ */
GIT_EXTERN(int) git_odb_open(git_odb **out, const char *objects_dir); GIT_EXTERN(int) git_odb_open(git_odb **out, const char *objects_dir);
/** /**
* Add a custom backend to an existing Object DB
*
* Read <odb_backends.h> for more information.
*
* @param odb database to add the backend to
* @paramm backend pointer to a git_odb_backend instance
* @return 0 on sucess; error code otherwise
*/
GIT_EXTERN(int) git_odb_add_backend(git_odb *odb, git_odb_backend *backend);
/**
* Close an open object database. * Close an open object database.
* @param db database pointer to close. If NULL no action is taken. * @param db database pointer to close. If NULL no action is taken.
*/ */
...@@ -76,7 +112,7 @@ GIT_EXTERN(int) git_odb_read(git_rawobj *out, git_odb *db, const git_oid *id); ...@@ -76,7 +112,7 @@ GIT_EXTERN(int) git_odb_read(git_rawobj *out, git_odb *db, const git_oid *id);
* are filled. The 'data' pointer will always be NULL. * are filled. The 'data' pointer will always be NULL.
* *
* The raw object pointed by 'out' doesn't need to be manually * The raw object pointed by 'out' doesn't need to be manually
* closed with git_obj_close(). * closed with git_rawobj_close().
* *
* @param out object descriptor to populate upon reading. * @param out object descriptor to populate upon reading.
* @param db database to search for the object in. * @param db database to search for the object in.
...@@ -88,44 +124,45 @@ GIT_EXTERN(int) git_odb_read(git_rawobj *out, git_odb *db, const git_oid *id); ...@@ -88,44 +124,45 @@ GIT_EXTERN(int) git_odb_read(git_rawobj *out, git_odb *db, const git_oid *id);
GIT_EXTERN(int) git_odb_read_header(git_rawobj *out, git_odb *db, const git_oid *id); GIT_EXTERN(int) git_odb_read_header(git_rawobj *out, git_odb *db, const git_oid *id);
/** /**
* Read an object from the database using only pack files. * Write an object to the database.
*
* If GIT_ENOTFOUND then out->data is set to NULL.
* *
* @param out object descriptor to populate upon reading. * @param id identity of the object written.
* @param db database to search for the object in. * @param db database to which the object should be written.
* @param id identity of the object to read. * @param obj object descriptor for the object to write.
* @return * @return
* - GIT_SUCCESS if the object was read. * - GIT_SUCCESS if the object was written;
* - GIT_ENOTFOUND if the object is not in the database. * - GIT_ERROR otherwise.
*/ */
GIT_EXTERN(int) git_odb__read_packed(git_rawobj *out, git_odb *db, const git_oid *id); GIT_EXTERN(int) git_odb_write(git_oid *id, git_odb *db, git_rawobj *obj);
/** /**
* Read an object from the database using only loose object files. * Determine if the given object can be found in the object database.
*
* If GIT_ENOTFOUND then out->data is set to NULL.
* *
* @param out object descriptor to populate upon reading. * @param db database to be searched for the given object.
* @param db database to search for the object in. * @param id the object to search for.
* @param id identity of the object to read.
* @return * @return
* - GIT_SUCCESS if the object was read. * - true, if the object was found
* - GIT_ENOTFOUND if the object is not in the database. * - false, otherwise
*/ */
GIT_EXTERN(int) git_odb__read_loose(git_rawobj *out, git_odb *db, const git_oid *id); GIT_EXTERN(int) git_odb_exists(git_odb *db, const git_oid *id);
/** /**
* Write an object to the database. * Determine the object-ID (sha1 hash) of the given git_rawobj.
* *
* @param id identity of the object written. * The input obj must be a valid loose object type and the data
* @param db database to which the object should be written. * pointer must not be NULL, unless the len field is also zero.
* @param obj object descriptor for the object to write. *
* @param id the resulting object-ID.
* @param obj the object whose hash is to be determined.
* @return * @return
* - GIT_SUCCESS if the object was written; * - GIT_SUCCESS if the object-ID was correctly determined.
* - GIT_ERROR otherwise. * - GIT_ERROR if the given object is malformed.
*/ */
GIT_EXTERN(int) git_odb_write(git_oid *id, git_odb *db, git_rawobj *obj); GIT_EXTERN(int) git_rawobj_hash(git_oid *id, git_rawobj *obj);
/** /**
* Release all memory used by the obj structure. * Release all memory used by the obj structure.
...@@ -136,12 +173,15 @@ GIT_EXTERN(int) git_odb_write(git_oid *id, git_odb *db, git_rawobj *obj); ...@@ -136,12 +173,15 @@ GIT_EXTERN(int) git_odb_write(git_oid *id, git_odb *db, git_rawobj *obj);
* *
* @param obj object descriptor to free. * @param obj object descriptor to free.
*/ */
GIT_INLINE(void) git_obj_close(git_rawobj *obj) GIT_INLINE(void) git_rawobj_close(git_rawobj *obj)
{ {
free(obj->data); free(obj->data);
obj->data = NULL; obj->data = NULL;
} }
/** /**
* Convert an object type to it's string representation. * Convert an object type to it's string representation.
* *
...@@ -151,7 +191,7 @@ GIT_INLINE(void) git_obj_close(git_rawobj *obj) ...@@ -151,7 +191,7 @@ GIT_INLINE(void) git_obj_close(git_rawobj *obj)
* @param type object type to convert. * @param type object type to convert.
* @return the corresponding string representation. * @return the corresponding string representation.
*/ */
GIT_EXTERN(const char *) git_obj_type_to_string(git_otype type); GIT_EXTERN(const char *) git_otype_tostring(git_otype type);
/** /**
* Convert a string object type representation to it's git_otype. * Convert a string object type representation to it's git_otype.
...@@ -159,7 +199,7 @@ GIT_EXTERN(const char *) git_obj_type_to_string(git_otype type); ...@@ -159,7 +199,7 @@ GIT_EXTERN(const char *) git_obj_type_to_string(git_otype type);
* @param str the string to convert. * @param str the string to convert.
* @return the corresponding git_otype. * @return the corresponding git_otype.
*/ */
GIT_EXTERN(git_otype) git_obj_string_to_type(const char *str); GIT_EXTERN(git_otype) git_otype_fromstring(const char *str);
/** /**
* Determine if the given git_otype is a valid loose object type. * Determine if the given git_otype is a valid loose object type.
...@@ -168,32 +208,7 @@ GIT_EXTERN(git_otype) git_obj_string_to_type(const char *str); ...@@ -168,32 +208,7 @@ GIT_EXTERN(git_otype) git_obj_string_to_type(const char *str);
* @return true if the type represents a valid loose object type, * @return true if the type represents a valid loose object type,
* false otherwise. * false otherwise.
*/ */
GIT_EXTERN(int) git_obj__loose_object_type(git_otype type); GIT_EXTERN(int) git_otype_is_loose(git_otype type);
/**
* Determine the object-ID (sha1 hash) of the given git_rawobj.
*
* The input obj must be a valid loose object type and the data
* pointer must not be NULL, unless the len field is also zero.
*
* @param id the resulting object-ID.
* @param obj the object whose hash is to be determined.
* @return
* - GIT_SUCCESS if the object-ID was correctly determined.
* - GIT_ERROR if the given object is malformed.
*/
GIT_EXTERN(int) git_obj_hash(git_oid *id, git_rawobj *obj);
/**
* Determine if the given object can be found in the object database.
*
* @param db database to be searched for the given object.
* @param id the object to search for.
* @return
* - true, if the object was found
* - false, otherwise
*/
GIT_EXTERN(int) git_odb_exists(git_odb *db, const git_oid *id);
/** @} */ /** @} */
GIT_END_DECL GIT_END_DECL
......
#ifndef INCLUDE_odb_h__ #ifndef INCLUDE_odb_h__
#define INCLUDE_odb_h__ #define INCLUDE_odb_h__
/** First 4 bytes of a pack-*.idx file header. #include <git/odb.h>
* #include <git/oid.h>
* Note this header exists only in idx v2 and later. The idx v1
* file format does not have a magic sequence at the front, and #include "vector.h"
* must be detected by the first four bytes *not* being this value
* and the first 8 bytes matching the following expression: struct git_odb {
* void *_internal;
* uint32_t *fanout = ... the file data at offset 0 ... git_vector backends;
* ntohl(fanout[0]) < ntohl(fanout[1]) };
*
* The value chosen here for PACK_TOC is such that the above struct git_odb_backend {
* cannot be true for an idx v1 file. git_odb *odb;
*/
#define PACK_TOC 0xff744f63 /* -1tOc */ int priority;
/** First 4 bytes of a pack-*.pack file header. */ int (* read)(
#define PACK_SIG 0x5041434b /* PACK */ git_rawobj *,
struct git_odb_backend *,
const git_oid *);
int (* read_header)(
git_rawobj *,
struct git_odb_backend *,
const git_oid *);
int (* write)(
git_oid *id,
struct git_odb_backend *,
git_rawobj *obj);
int (* exists)(
struct git_odb_backend *,
const git_oid *);
void (* free)(struct git_odb_backend *);
};
int git_odb__hash_obj(git_oid *id, char *hdr, size_t n, int *len, git_rawobj *obj);
int git_odb__inflate_buffer(void *in, size_t inlen, void *out, size_t outlen);
int git_odb_backend_loose(git_odb_backend **backend_out, const char *objects_dir);
int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir);
#endif #endif
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
...@@ -445,7 +445,7 @@ void git_object__source_close(git_object *object) ...@@ -445,7 +445,7 @@ void git_object__source_close(git_object *object)
assert(object); assert(object);
if (object->source.open) { if (object->source.open) {
git_obj_close(&object->source.raw); git_rawobj_close(&object->source.raw);
object->source.open = 0; object->source.open = 0;
} }
} }
......
...@@ -215,7 +215,7 @@ int git_tag__writeback(git_tag *tag, git_odb_source *src) ...@@ -215,7 +215,7 @@ int git_tag__writeback(git_tag *tag, git_odb_source *src)
return GIT_EMISSINGOBJDATA; return GIT_EMISSINGOBJDATA;
git__write_oid(src, "object", git_object_id(tag->target)); git__write_oid(src, "object", git_object_id(tag->target));
git__source_printf(src, "type %s\n", git_obj_type_to_string(tag->type)); git__source_printf(src, "type %s\n", git_otype_tostring(tag->type));
git__source_printf(src, "tag %s\n", tag->tag_name); git__source_printf(src, "tag %s\n", tag->tag_name);
git_person__write(src, "tagger", tag->tagger); git_person__write(src, "tagger", tag->tagger);
......
...@@ -3,48 +3,48 @@ ...@@ -3,48 +3,48 @@
#include <git/odb.h> #include <git/odb.h>
BEGIN_TEST(type_to_string) BEGIN_TEST(type_to_string)
must_be_true(!strcmp(git_obj_type_to_string(GIT_OBJ_BAD), "")); must_be_true(!strcmp(git_otype_tostring(GIT_OBJ_BAD), ""));
must_be_true(!strcmp(git_obj_type_to_string(GIT_OBJ__EXT1), "")); must_be_true(!strcmp(git_otype_tostring(GIT_OBJ__EXT1), ""));
must_be_true(!strcmp(git_obj_type_to_string(GIT_OBJ_COMMIT), "commit")); must_be_true(!strcmp(git_otype_tostring(GIT_OBJ_COMMIT), "commit"));
must_be_true(!strcmp(git_obj_type_to_string(GIT_OBJ_TREE), "tree")); must_be_true(!strcmp(git_otype_tostring(GIT_OBJ_TREE), "tree"));
must_be_true(!strcmp(git_obj_type_to_string(GIT_OBJ_BLOB), "blob")); must_be_true(!strcmp(git_otype_tostring(GIT_OBJ_BLOB), "blob"));
must_be_true(!strcmp(git_obj_type_to_string(GIT_OBJ_TAG), "tag")); must_be_true(!strcmp(git_otype_tostring(GIT_OBJ_TAG), "tag"));
must_be_true(!strcmp(git_obj_type_to_string(GIT_OBJ__EXT2), "")); must_be_true(!strcmp(git_otype_tostring(GIT_OBJ__EXT2), ""));
must_be_true(!strcmp(git_obj_type_to_string(GIT_OBJ_OFS_DELTA), "OFS_DELTA")); must_be_true(!strcmp(git_otype_tostring(GIT_OBJ_OFS_DELTA), "OFS_DELTA"));
must_be_true(!strcmp(git_obj_type_to_string(GIT_OBJ_REF_DELTA), "REF_DELTA")); must_be_true(!strcmp(git_otype_tostring(GIT_OBJ_REF_DELTA), "REF_DELTA"));
must_be_true(!strcmp(git_obj_type_to_string(-2), "")); must_be_true(!strcmp(git_otype_tostring(-2), ""));
must_be_true(!strcmp(git_obj_type_to_string(8), "")); must_be_true(!strcmp(git_otype_tostring(8), ""));
must_be_true(!strcmp(git_obj_type_to_string(1234), "")); must_be_true(!strcmp(git_otype_tostring(1234), ""));
END_TEST END_TEST
BEGIN_TEST(string_to_type) BEGIN_TEST(string_to_type)
must_be_true(git_obj_string_to_type(NULL) == GIT_OBJ_BAD); must_be_true(git_otype_fromstring(NULL) == GIT_OBJ_BAD);
must_be_true(git_obj_string_to_type("") == GIT_OBJ_BAD); must_be_true(git_otype_fromstring("") == GIT_OBJ_BAD);
must_be_true(git_obj_string_to_type("commit") == GIT_OBJ_COMMIT); must_be_true(git_otype_fromstring("commit") == GIT_OBJ_COMMIT);
must_be_true(git_obj_string_to_type("tree") == GIT_OBJ_TREE); must_be_true(git_otype_fromstring("tree") == GIT_OBJ_TREE);
must_be_true(git_obj_string_to_type("blob") == GIT_OBJ_BLOB); must_be_true(git_otype_fromstring("blob") == GIT_OBJ_BLOB);
must_be_true(git_obj_string_to_type("tag") == GIT_OBJ_TAG); must_be_true(git_otype_fromstring("tag") == GIT_OBJ_TAG);
must_be_true(git_obj_string_to_type("OFS_DELTA") == GIT_OBJ_OFS_DELTA); must_be_true(git_otype_fromstring("OFS_DELTA") == GIT_OBJ_OFS_DELTA);
must_be_true(git_obj_string_to_type("REF_DELTA") == GIT_OBJ_REF_DELTA); must_be_true(git_otype_fromstring("REF_DELTA") == GIT_OBJ_REF_DELTA);
must_be_true(git_obj_string_to_type("CoMmIt") == GIT_OBJ_BAD); must_be_true(git_otype_fromstring("CoMmIt") == GIT_OBJ_BAD);
must_be_true(git_obj_string_to_type("hohoho") == GIT_OBJ_BAD); must_be_true(git_otype_fromstring("hohoho") == GIT_OBJ_BAD);
END_TEST END_TEST
BEGIN_TEST(loose_object) BEGIN_TEST(loose_object)
must_be_true(git_obj__loose_object_type(GIT_OBJ_BAD) == 0); must_be_true(git_otype_is_loose(GIT_OBJ_BAD) == 0);
must_be_true(git_obj__loose_object_type(GIT_OBJ__EXT1) == 0); must_be_true(git_otype_is_loose(GIT_OBJ__EXT1) == 0);
must_be_true(git_obj__loose_object_type(GIT_OBJ_COMMIT) == 1); must_be_true(git_otype_is_loose(GIT_OBJ_COMMIT) == 1);
must_be_true(git_obj__loose_object_type(GIT_OBJ_TREE) == 1); must_be_true(git_otype_is_loose(GIT_OBJ_TREE) == 1);
must_be_true(git_obj__loose_object_type(GIT_OBJ_BLOB) == 1); must_be_true(git_otype_is_loose(GIT_OBJ_BLOB) == 1);
must_be_true(git_obj__loose_object_type(GIT_OBJ_TAG) == 1); must_be_true(git_otype_is_loose(GIT_OBJ_TAG) == 1);
must_be_true(git_obj__loose_object_type(GIT_OBJ__EXT2) == 0); must_be_true(git_otype_is_loose(GIT_OBJ__EXT2) == 0);
must_be_true(git_obj__loose_object_type(GIT_OBJ_OFS_DELTA) == 0); must_be_true(git_otype_is_loose(GIT_OBJ_OFS_DELTA) == 0);
must_be_true(git_obj__loose_object_type(GIT_OBJ_REF_DELTA) == 0); must_be_true(git_otype_is_loose(GIT_OBJ_REF_DELTA) == 0);
must_be_true(git_obj__loose_object_type(-2) == 0); must_be_true(git_otype_is_loose(-2) == 0);
must_be_true(git_obj__loose_object_type(8) == 0); must_be_true(git_otype_is_loose(8) == 0);
must_be_true(git_obj__loose_object_type(1234) == 0); must_be_true(git_otype_is_loose(1234) == 0);
END_TEST END_TEST
...@@ -326,28 +326,28 @@ BEGIN_TEST(hash_junk) ...@@ -326,28 +326,28 @@ BEGIN_TEST(hash_junk)
/* invalid types: */ /* invalid types: */
junk_obj.data = some_data; junk_obj.data = some_data;
must_fail(git_obj_hash(&id, &junk_obj)); must_fail(git_rawobj_hash(&id, &junk_obj));
junk_obj.type = GIT_OBJ__EXT1; junk_obj.type = GIT_OBJ__EXT1;
must_fail(git_obj_hash(&id, &junk_obj)); must_fail(git_rawobj_hash(&id, &junk_obj));
junk_obj.type = GIT_OBJ__EXT2; junk_obj.type = GIT_OBJ__EXT2;
must_fail(git_obj_hash(&id, &junk_obj)); must_fail(git_rawobj_hash(&id, &junk_obj));
junk_obj.type = GIT_OBJ_OFS_DELTA; junk_obj.type = GIT_OBJ_OFS_DELTA;
must_fail(git_obj_hash(&id, &junk_obj)); must_fail(git_rawobj_hash(&id, &junk_obj));
junk_obj.type = GIT_OBJ_REF_DELTA; junk_obj.type = GIT_OBJ_REF_DELTA;
must_fail(git_obj_hash(&id, &junk_obj)); must_fail(git_rawobj_hash(&id, &junk_obj));
/* data can be NULL only if len is zero: */ /* data can be NULL only if len is zero: */
junk_obj.type = GIT_OBJ_BLOB; junk_obj.type = GIT_OBJ_BLOB;
junk_obj.data = NULL; junk_obj.data = NULL;
must_pass(git_obj_hash(&id, &junk_obj)); must_pass(git_rawobj_hash(&id, &junk_obj));
must_be_true(git_oid_cmp(&id, &id_zero) == 0); must_be_true(git_oid_cmp(&id, &id_zero) == 0);
junk_obj.len = 1; junk_obj.len = 1;
must_fail(git_obj_hash(&id, &junk_obj)); must_fail(git_rawobj_hash(&id, &junk_obj));
END_TEST END_TEST
BEGIN_TEST(hash_commit) BEGIN_TEST(hash_commit)
...@@ -355,7 +355,7 @@ BEGIN_TEST(hash_commit) ...@@ -355,7 +355,7 @@ BEGIN_TEST(hash_commit)
must_pass(git_oid_mkstr(&id1, commit_id)); must_pass(git_oid_mkstr(&id1, commit_id));
must_pass(git_obj_hash(&id2, &commit_obj)); must_pass(git_rawobj_hash(&id2, &commit_obj));
must_be_true(git_oid_cmp(&id1, &id2) == 0); must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST END_TEST
...@@ -365,7 +365,7 @@ BEGIN_TEST(hash_tree) ...@@ -365,7 +365,7 @@ BEGIN_TEST(hash_tree)
must_pass(git_oid_mkstr(&id1, tree_id)); must_pass(git_oid_mkstr(&id1, tree_id));
must_pass(git_obj_hash(&id2, &tree_obj)); must_pass(git_rawobj_hash(&id2, &tree_obj));
must_be_true(git_oid_cmp(&id1, &id2) == 0); must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST END_TEST
...@@ -375,7 +375,7 @@ BEGIN_TEST(hash_tag) ...@@ -375,7 +375,7 @@ BEGIN_TEST(hash_tag)
must_pass(git_oid_mkstr(&id1, tag_id)); must_pass(git_oid_mkstr(&id1, tag_id));
must_pass(git_obj_hash(&id2, &tag_obj)); must_pass(git_rawobj_hash(&id2, &tag_obj));
must_be_true(git_oid_cmp(&id1, &id2) == 0); must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST END_TEST
...@@ -385,7 +385,7 @@ BEGIN_TEST(hash_zero) ...@@ -385,7 +385,7 @@ BEGIN_TEST(hash_zero)
must_pass(git_oid_mkstr(&id1, zero_id)); must_pass(git_oid_mkstr(&id1, zero_id));
must_pass(git_obj_hash(&id2, &zero_obj)); must_pass(git_rawobj_hash(&id2, &zero_obj));
must_be_true(git_oid_cmp(&id1, &id2) == 0); must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST END_TEST
...@@ -395,7 +395,7 @@ BEGIN_TEST(hash_one) ...@@ -395,7 +395,7 @@ BEGIN_TEST(hash_one)
must_pass(git_oid_mkstr(&id1, one_id)); must_pass(git_oid_mkstr(&id1, one_id));
must_pass(git_obj_hash(&id2, &one_obj)); must_pass(git_rawobj_hash(&id2, &one_obj));
must_be_true(git_oid_cmp(&id1, &id2) == 0); must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST END_TEST
...@@ -405,7 +405,7 @@ BEGIN_TEST(hash_two) ...@@ -405,7 +405,7 @@ BEGIN_TEST(hash_two)
must_pass(git_oid_mkstr(&id1, two_id)); must_pass(git_oid_mkstr(&id1, two_id));
must_pass(git_obj_hash(&id2, &two_obj)); must_pass(git_rawobj_hash(&id2, &two_obj));
must_be_true(git_oid_cmp(&id1, &id2) == 0); must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST END_TEST
...@@ -415,7 +415,7 @@ BEGIN_TEST(hash_some) ...@@ -415,7 +415,7 @@ BEGIN_TEST(hash_some)
must_pass(git_oid_mkstr(&id1, some_id)); must_pass(git_oid_mkstr(&id1, some_id));
must_pass(git_obj_hash(&id2, &some_obj)); must_pass(git_rawobj_hash(&id2, &some_obj));
must_be_true(git_oid_cmp(&id1, &id2) == 0); must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST END_TEST
......
...@@ -532,10 +532,10 @@ BEGIN_TEST(read_loose_commit) ...@@ -532,10 +532,10 @@ BEGIN_TEST(read_loose_commit)
must_pass(git_odb_open(&db, odb_dir)); must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, commit.id)); must_pass(git_oid_mkstr(&id, commit.id));
must_pass(git_odb__read_loose(&obj, db, &id)); must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &commit)); must_pass(cmp_objects(&obj, &commit));
git_obj_close(&obj); git_rawobj_close(&obj);
git_odb_close(db); git_odb_close(db);
must_pass(remove_object_files(odb_dir, &commit)); must_pass(remove_object_files(odb_dir, &commit));
END_TEST END_TEST
...@@ -549,10 +549,10 @@ BEGIN_TEST(read_loose_tree) ...@@ -549,10 +549,10 @@ BEGIN_TEST(read_loose_tree)
must_pass(git_odb_open(&db, odb_dir)); must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, tree.id)); must_pass(git_oid_mkstr(&id, tree.id));
must_pass(git_odb__read_loose(&obj, db, &id)); must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &tree)); must_pass(cmp_objects(&obj, &tree));
git_obj_close(&obj); git_rawobj_close(&obj);
git_odb_close(db); git_odb_close(db);
must_pass(remove_object_files(odb_dir, &tree)); must_pass(remove_object_files(odb_dir, &tree));
END_TEST END_TEST
...@@ -566,10 +566,10 @@ BEGIN_TEST(read_loose_tag) ...@@ -566,10 +566,10 @@ BEGIN_TEST(read_loose_tag)
must_pass(git_odb_open(&db, odb_dir)); must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, tag.id)); must_pass(git_oid_mkstr(&id, tag.id));
must_pass(git_odb__read_loose(&obj, db, &id)); must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &tag)); must_pass(cmp_objects(&obj, &tag));
git_obj_close(&obj); git_rawobj_close(&obj);
git_odb_close(db); git_odb_close(db);
must_pass(remove_object_files(odb_dir, &tag)); must_pass(remove_object_files(odb_dir, &tag));
END_TEST END_TEST
...@@ -583,10 +583,10 @@ BEGIN_TEST(read_loose_zero) ...@@ -583,10 +583,10 @@ BEGIN_TEST(read_loose_zero)
must_pass(git_odb_open(&db, odb_dir)); must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, zero.id)); must_pass(git_oid_mkstr(&id, zero.id));
must_pass(git_odb__read_loose(&obj, db, &id)); must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &zero)); must_pass(cmp_objects(&obj, &zero));
git_obj_close(&obj); git_rawobj_close(&obj);
git_odb_close(db); git_odb_close(db);
must_pass(remove_object_files(odb_dir, &zero)); must_pass(remove_object_files(odb_dir, &zero));
END_TEST END_TEST
...@@ -600,10 +600,10 @@ BEGIN_TEST(read_loose_one) ...@@ -600,10 +600,10 @@ BEGIN_TEST(read_loose_one)
must_pass(git_odb_open(&db, odb_dir)); must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, one.id)); must_pass(git_oid_mkstr(&id, one.id));
must_pass(git_odb__read_loose(&obj, db, &id)); must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &one)); must_pass(cmp_objects(&obj, &one));
git_obj_close(&obj); git_rawobj_close(&obj);
git_odb_close(db); git_odb_close(db);
must_pass(remove_object_files(odb_dir, &one)); must_pass(remove_object_files(odb_dir, &one));
END_TEST END_TEST
...@@ -617,10 +617,10 @@ BEGIN_TEST(read_loose_two) ...@@ -617,10 +617,10 @@ BEGIN_TEST(read_loose_two)
must_pass(git_odb_open(&db, odb_dir)); must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, two.id)); must_pass(git_oid_mkstr(&id, two.id));
must_pass(git_odb__read_loose(&obj, db, &id)); must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &two)); must_pass(cmp_objects(&obj, &two));
git_obj_close(&obj); git_rawobj_close(&obj);
git_odb_close(db); git_odb_close(db);
must_pass(remove_object_files(odb_dir, &two)); must_pass(remove_object_files(odb_dir, &two));
END_TEST END_TEST
...@@ -634,10 +634,10 @@ BEGIN_TEST(read_loose_some) ...@@ -634,10 +634,10 @@ BEGIN_TEST(read_loose_some)
must_pass(git_odb_open(&db, odb_dir)); must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, some.id)); must_pass(git_oid_mkstr(&id, some.id));
must_pass(git_odb__read_loose(&obj, db, &id)); must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &some)); must_pass(cmp_objects(&obj, &some));
git_obj_close(&obj); git_rawobj_close(&obj);
git_odb_close(db); git_odb_close(db);
must_pass(remove_object_files(odb_dir, &some)); must_pass(remove_object_files(odb_dir, &some));
END_TEST END_TEST
......
...@@ -533,10 +533,10 @@ BEGIN_TEST(read_loose_commit) ...@@ -533,10 +533,10 @@ BEGIN_TEST(read_loose_commit)
must_pass(git_odb_open(&db, odb_dir)); must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, commit.id)); must_pass(git_oid_mkstr(&id, commit.id));
must_pass(git_odb__read_loose(&obj, db, &id)); must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &commit)); must_pass(cmp_objects(&obj, &commit));
git_obj_close(&obj); git_rawobj_close(&obj);
git_odb_close(db); git_odb_close(db);
must_pass(remove_object_files(odb_dir, &commit)); must_pass(remove_object_files(odb_dir, &commit));
END_TEST END_TEST
...@@ -550,10 +550,10 @@ BEGIN_TEST(read_loose_tree) ...@@ -550,10 +550,10 @@ BEGIN_TEST(read_loose_tree)
must_pass(git_odb_open(&db, odb_dir)); must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, tree.id)); must_pass(git_oid_mkstr(&id, tree.id));
must_pass(git_odb__read_loose(&obj, db, &id)); must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &tree)); must_pass(cmp_objects(&obj, &tree));
git_obj_close(&obj); git_rawobj_close(&obj);
git_odb_close(db); git_odb_close(db);
must_pass(remove_object_files(odb_dir, &tree)); must_pass(remove_object_files(odb_dir, &tree));
END_TEST END_TEST
...@@ -567,10 +567,10 @@ BEGIN_TEST(read_loose_tag) ...@@ -567,10 +567,10 @@ BEGIN_TEST(read_loose_tag)
must_pass(git_odb_open(&db, odb_dir)); must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, tag.id)); must_pass(git_oid_mkstr(&id, tag.id));
must_pass(git_odb__read_loose(&obj, db, &id)); must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &tag)); must_pass(cmp_objects(&obj, &tag));
git_obj_close(&obj); git_rawobj_close(&obj);
git_odb_close(db); git_odb_close(db);
must_pass(remove_object_files(odb_dir, &tag)); must_pass(remove_object_files(odb_dir, &tag));
END_TEST END_TEST
...@@ -584,10 +584,10 @@ BEGIN_TEST(read_loose_zero) ...@@ -584,10 +584,10 @@ BEGIN_TEST(read_loose_zero)
must_pass(git_odb_open(&db, odb_dir)); must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, zero.id)); must_pass(git_oid_mkstr(&id, zero.id));
must_pass(git_odb__read_loose(&obj, db, &id)); must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &zero)); must_pass(cmp_objects(&obj, &zero));
git_obj_close(&obj); git_rawobj_close(&obj);
git_odb_close(db); git_odb_close(db);
must_pass(remove_object_files(odb_dir, &zero)); must_pass(remove_object_files(odb_dir, &zero));
END_TEST END_TEST
...@@ -601,10 +601,10 @@ BEGIN_TEST(read_loose_one) ...@@ -601,10 +601,10 @@ BEGIN_TEST(read_loose_one)
must_pass(git_odb_open(&db, odb_dir)); must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, one.id)); must_pass(git_oid_mkstr(&id, one.id));
must_pass(git_odb__read_loose(&obj, db, &id)); must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &one)); must_pass(cmp_objects(&obj, &one));
git_obj_close(&obj); git_rawobj_close(&obj);
git_odb_close(db); git_odb_close(db);
must_pass(remove_object_files(odb_dir, &one)); must_pass(remove_object_files(odb_dir, &one));
END_TEST END_TEST
...@@ -618,10 +618,10 @@ BEGIN_TEST(read_loose_two) ...@@ -618,10 +618,10 @@ BEGIN_TEST(read_loose_two)
must_pass(git_odb_open(&db, odb_dir)); must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, two.id)); must_pass(git_oid_mkstr(&id, two.id));
must_pass(git_odb__read_loose(&obj, db, &id)); must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &two)); must_pass(cmp_objects(&obj, &two));
git_obj_close(&obj); git_rawobj_close(&obj);
git_odb_close(db); git_odb_close(db);
must_pass(remove_object_files(odb_dir, &two)); must_pass(remove_object_files(odb_dir, &two));
END_TEST END_TEST
...@@ -635,10 +635,10 @@ BEGIN_TEST(read_loose_some) ...@@ -635,10 +635,10 @@ BEGIN_TEST(read_loose_some)
must_pass(git_odb_open(&db, odb_dir)); must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, some.id)); must_pass(git_oid_mkstr(&id, some.id));
must_pass(git_odb__read_loose(&obj, db, &id)); must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &some)); must_pass(cmp_objects(&obj, &some));
git_obj_close(&obj); git_rawobj_close(&obj);
git_odb_close(db); git_odb_close(db);
must_pass(remove_object_files(odb_dir, &some)); must_pass(remove_object_files(odb_dir, &some));
END_TEST END_TEST
......
...@@ -143,9 +143,9 @@ BEGIN_TEST(readpacked_test) ...@@ -143,9 +143,9 @@ BEGIN_TEST(readpacked_test)
must_pass(git_oid_mkstr(&id, packed_objects[i])); must_pass(git_oid_mkstr(&id, packed_objects[i]));
must_be_true(git_odb_exists(db, &id) == 1); must_be_true(git_odb_exists(db, &id) == 1);
must_pass(git_odb__read_packed(&obj, db, &id)); must_pass(git_odb_read(&obj, db, &id));
git_obj_close(&obj); git_rawobj_close(&obj);
} }
git_odb_close(db); git_odb_close(db);
......
...@@ -172,7 +172,7 @@ BEGIN_TEST(readheader_packed_test) ...@@ -172,7 +172,7 @@ BEGIN_TEST(readheader_packed_test)
must_be_true(obj.len == header.len); must_be_true(obj.len == header.len);
must_be_true(obj.type == header.type); must_be_true(obj.type == header.type);
git_obj_close(&obj); git_rawobj_close(&obj);
} }
git_odb_close(db); git_odb_close(db);
...@@ -199,7 +199,7 @@ BEGIN_TEST(readheader_loose_test) ...@@ -199,7 +199,7 @@ BEGIN_TEST(readheader_loose_test)
must_be_true(obj.len == header.len); must_be_true(obj.len == header.len);
must_be_true(obj.type == header.type); must_be_true(obj.type == header.type);
git_obj_close(&obj); git_rawobj_close(&obj);
} }
git_odb_close(db); git_odb_close(db);
......
...@@ -414,10 +414,10 @@ BEGIN_TEST(write_commit) ...@@ -414,10 +414,10 @@ BEGIN_TEST(write_commit)
must_be_true(git_oid_cmp(&id1, &id2) == 0); must_be_true(git_oid_cmp(&id1, &id2) == 0);
must_pass(check_object_files(&commit)); must_pass(check_object_files(&commit));
must_pass(git_odb__read_loose(&obj, db, &id1)); must_pass(git_odb_read(&obj, db, &id1));
must_pass(cmp_objects(&obj, &commit_obj)); must_pass(cmp_objects(&obj, &commit_obj));
git_obj_close(&obj); git_rawobj_close(&obj);
git_odb_close(db); git_odb_close(db);
must_pass(remove_object_files(&commit)); must_pass(remove_object_files(&commit));
END_TEST END_TEST
...@@ -435,10 +435,10 @@ BEGIN_TEST(write_tree) ...@@ -435,10 +435,10 @@ BEGIN_TEST(write_tree)
must_be_true(git_oid_cmp(&id1, &id2) == 0); must_be_true(git_oid_cmp(&id1, &id2) == 0);
must_pass(check_object_files(&tree)); must_pass(check_object_files(&tree));
must_pass(git_odb__read_loose(&obj, db, &id1)); must_pass(git_odb_read(&obj, db, &id1));
must_pass(cmp_objects(&obj, &tree_obj)); must_pass(cmp_objects(&obj, &tree_obj));
git_obj_close(&obj); git_rawobj_close(&obj);
git_odb_close(db); git_odb_close(db);
must_pass(remove_object_files(&tree)); must_pass(remove_object_files(&tree));
END_TEST END_TEST
...@@ -456,10 +456,10 @@ BEGIN_TEST(write_tag) ...@@ -456,10 +456,10 @@ BEGIN_TEST(write_tag)
must_be_true(git_oid_cmp(&id1, &id2) == 0); must_be_true(git_oid_cmp(&id1, &id2) == 0);
must_pass(check_object_files(&tag)); must_pass(check_object_files(&tag));
must_pass(git_odb__read_loose(&obj, db, &id1)); must_pass(git_odb_read(&obj, db, &id1));
must_pass(cmp_objects(&obj, &tag_obj)); must_pass(cmp_objects(&obj, &tag_obj));
git_obj_close(&obj); git_rawobj_close(&obj);
git_odb_close(db); git_odb_close(db);
must_pass(remove_object_files(&tag)); must_pass(remove_object_files(&tag));
END_TEST END_TEST
...@@ -477,10 +477,10 @@ BEGIN_TEST(write_zero) ...@@ -477,10 +477,10 @@ BEGIN_TEST(write_zero)
must_be_true(git_oid_cmp(&id1, &id2) == 0); must_be_true(git_oid_cmp(&id1, &id2) == 0);
must_pass(check_object_files(&zero)); must_pass(check_object_files(&zero));
must_pass(git_odb__read_loose(&obj, db, &id1)); must_pass(git_odb_read(&obj, db, &id1));
must_pass(cmp_objects(&obj, &zero_obj)); must_pass(cmp_objects(&obj, &zero_obj));
git_obj_close(&obj); git_rawobj_close(&obj);
git_odb_close(db); git_odb_close(db);
must_pass(remove_object_files(&zero)); must_pass(remove_object_files(&zero));
END_TEST END_TEST
...@@ -498,10 +498,10 @@ BEGIN_TEST(write_one) ...@@ -498,10 +498,10 @@ BEGIN_TEST(write_one)
must_be_true(git_oid_cmp(&id1, &id2) == 0); must_be_true(git_oid_cmp(&id1, &id2) == 0);
must_pass(check_object_files(&one)); must_pass(check_object_files(&one));
must_pass(git_odb__read_loose(&obj, db, &id1)); must_pass(git_odb_read(&obj, db, &id1));
must_pass(cmp_objects(&obj, &one_obj)); must_pass(cmp_objects(&obj, &one_obj));
git_obj_close(&obj); git_rawobj_close(&obj);
git_odb_close(db); git_odb_close(db);
must_pass(remove_object_files(&one)); must_pass(remove_object_files(&one));
END_TEST END_TEST
...@@ -519,10 +519,10 @@ BEGIN_TEST(write_two) ...@@ -519,10 +519,10 @@ BEGIN_TEST(write_two)
must_be_true(git_oid_cmp(&id1, &id2) == 0); must_be_true(git_oid_cmp(&id1, &id2) == 0);
must_pass(check_object_files(&two)); must_pass(check_object_files(&two));
must_pass(git_odb__read_loose(&obj, db, &id1)); must_pass(git_odb_read(&obj, db, &id1));
must_pass(cmp_objects(&obj, &two_obj)); must_pass(cmp_objects(&obj, &two_obj));
git_obj_close(&obj); git_rawobj_close(&obj);
git_odb_close(db); git_odb_close(db);
must_pass(remove_object_files(&two)); must_pass(remove_object_files(&two));
END_TEST END_TEST
...@@ -540,10 +540,10 @@ BEGIN_TEST(write_some) ...@@ -540,10 +540,10 @@ BEGIN_TEST(write_some)
must_be_true(git_oid_cmp(&id1, &id2) == 0); must_be_true(git_oid_cmp(&id1, &id2) == 0);
must_pass(check_object_files(&some)); must_pass(check_object_files(&some));
must_pass(git_odb__read_loose(&obj, db, &id1)); must_pass(git_odb_read(&obj, db, &id1));
must_pass(cmp_objects(&obj, &some_obj)); must_pass(cmp_objects(&obj, &some_obj));
git_obj_close(&obj); git_rawobj_close(&obj);
git_odb_close(db); git_odb_close(db);
must_pass(remove_object_files(&some)); must_pass(remove_object_files(&some));
END_TEST END_TEST
......
...@@ -125,7 +125,7 @@ int remove_loose_object(const char *repository_folder, git_object *object) ...@@ -125,7 +125,7 @@ int remove_loose_object(const char *repository_folder, git_object *object)
int cmp_objects(git_rawobj *o, object_data *d) int cmp_objects(git_rawobj *o, object_data *d)
{ {
if (o->type != git_obj_string_to_type(d->type)) if (o->type != git_otype_fromstring(d->type))
return -1; return -1;
if (o->len != d->dlen) if (o->len != d->dlen)
return -1; return -1;
......
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