diff options
author | Vicent Marti <tanoku@gmail.com> | 2010-12-03 18:01:30 +0200 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2010-12-06 01:14:15 +0200 |
commit | 7d7cd8857a451ff50b126e452bcbdc0fb397db35 (patch) | |
tree | c9ddb750041ef6d22e8fef955df71dd6e7f2973f /src/git/odb.h | |
parent | 86bfec39b55c00ef499e635fdbdca7946c55fcde (diff) | |
download | libgit2-7d7cd8857a451ff50b126e452bcbdc0fb397db35.tar.gz |
Decouple storage from ODB logic
Comes with two default backends: loose object and packfiles.
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'src/git/odb.h')
-rw-r--r-- | src/git/odb.h | 129 |
1 files changed, 72 insertions, 57 deletions
diff --git a/src/git/odb.h b/src/git/odb.h index b4812424c..584a848c5 100644 --- a/src/git/odb.h +++ b/src/git/odb.h @@ -17,17 +17,53 @@ GIT_BEGIN_DECL /** An open object database handle. */ 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. * 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 * code describing why the open was not possible. */ 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. * @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); * are filled. The 'data' pointer will always be NULL. * * 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 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); 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. - * - * If GIT_ENOTFOUND then out->data is set to NULL. + * Write an object to the database. * - * @param out object descriptor to populate upon reading. - * @param db database to search for the object in. - * @param id identity of the object to read. + * @param id identity of the object written. + * @param db database to which the object should be written. + * @param obj object descriptor for the object to write. * @return - * - GIT_SUCCESS if the object was read. - * - GIT_ENOTFOUND if the object is not in the database. + * - GIT_SUCCESS if the object was written; + * - 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. - * - * If GIT_ENOTFOUND then out->data is set to NULL. + * Determine if the given object can be found in the object database. * - * @param out object descriptor to populate upon reading. - * @param db database to search for the object in. - * @param id identity of the object to read. + * @param db database to be searched for the given object. + * @param id the object to search for. * @return - * - GIT_SUCCESS if the object was read. - * - GIT_ENOTFOUND if the object is not in the database. + * - true, if the object was found + * - 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. - * @param db database to which the object should be written. - * @param obj object descriptor for the object to write. + * 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 was written; - * - GIT_ERROR otherwise. + * - GIT_SUCCESS if the object-ID was correctly determined. + * - 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. @@ -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. */ -GIT_INLINE(void) git_obj_close(git_rawobj *obj) +GIT_INLINE(void) git_rawobj_close(git_rawobj *obj) { free(obj->data); obj->data = NULL; } + + + /** * Convert an object type to it's string representation. * @@ -151,7 +191,7 @@ GIT_INLINE(void) git_obj_close(git_rawobj *obj) * @param type object type to convert. * @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. @@ -159,7 +199,7 @@ GIT_EXTERN(const char *) git_obj_type_to_string(git_otype type); * @param str the string to convert. * @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. @@ -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, * false otherwise. */ -GIT_EXTERN(int) git_obj__loose_object_type(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_EXTERN(int) git_otype_is_loose(git_otype type); /** @} */ GIT_END_DECL |