diff options
Diffstat (limited to 'src/git')
-rw-r--r-- | src/git/blob.h | 4 | ||||
-rw-r--r-- | src/git/commit.h | 6 | ||||
-rw-r--r-- | src/git/common.h | 10 | ||||
-rw-r--r-- | src/git/errors.h | 2 | ||||
-rw-r--r-- | src/git/index.h | 6 | ||||
-rw-r--r-- | src/git/object.h | 108 | ||||
-rw-r--r-- | src/git/odb.h | 59 | ||||
-rw-r--r-- | src/git/odb_backend.h | 40 | ||||
-rw-r--r-- | src/git/oid.h | 18 | ||||
-rw-r--r-- | src/git/repository.h | 69 | ||||
-rw-r--r-- | src/git/revwalk.h | 5 | ||||
-rw-r--r-- | src/git/tag.h | 6 | ||||
-rw-r--r-- | src/git/tree.h | 9 | ||||
-rw-r--r-- | src/git/types.h | 64 | ||||
-rw-r--r-- | src/git/zlib.h | 1 |
15 files changed, 227 insertions, 180 deletions
diff --git a/src/git/blob.h b/src/git/blob.h index 93ced42ee..f94b1f963 100644 --- a/src/git/blob.h +++ b/src/git/blob.h @@ -2,6 +2,7 @@ #define INCLUDE_git_blob_h__ #include "common.h" +#include "types.h" #include "oid.h" /** @@ -13,9 +14,6 @@ */ GIT_BEGIN_DECL -/** In-memory representation of a blob object. */ -typedef struct git_blob git_blob; - /** * Lookup a blob object from a repository. * The generated blob object is owned by the revision diff --git a/src/git/commit.h b/src/git/commit.h index 056997f45..54ecb622e 100644 --- a/src/git/commit.h +++ b/src/git/commit.h @@ -2,9 +2,8 @@ #define INCLUDE_git_commit_h__ #include "common.h" +#include "types.h" #include "oid.h" -#include "tree.h" -#include "repository.h" /** * @file git/commit.h @@ -15,9 +14,6 @@ */ GIT_BEGIN_DECL -/** Parsed representation of a commit object. */ -typedef struct git_commit git_commit; - /** * Lookup a commit object from a repository. * The generated commit object is owned by the revision diff --git a/src/git/common.h b/src/git/common.h index cb1684863..0a7de41ea 100644 --- a/src/git/common.h +++ b/src/git/common.h @@ -113,16 +113,6 @@ GIT_BEGIN_DECL -/** - * Representation of an existing git repository, - * including all its object contents - */ -typedef struct git_repository git_repository; - -/** Representation of a generic object in a repository */ -typedef struct git_object git_object; - - /** Parsed representation of a person */ typedef struct git_person git_person; diff --git a/src/git/errors.h b/src/git/errors.h index 8e9e423ed..f4720bebe 100644 --- a/src/git/errors.h +++ b/src/git/errors.h @@ -1,8 +1,6 @@ #ifndef INCLUDE_git_errors_h__ #define INCLUDE_git_errors_h__ -#include "common.h" - /** * @file git/errors.h * @brief Git error handling routines and variables diff --git a/src/git/index.h b/src/git/index.h index fd5710622..8bdced6a3 100644 --- a/src/git/index.h +++ b/src/git/index.h @@ -2,7 +2,7 @@ #define INCLUDE_git_index_h__ #include "common.h" -#include "oid.h" +#include "types.h" /** * @file git/index.h @@ -19,10 +19,6 @@ GIT_BEGIN_DECL #define GIT_IDXENTRY_VALID (0x8000) #define GIT_IDXENTRY_STAGESHIFT 12 -/** Memory representation of an index file. */ -typedef struct git_index git_index; - - /** Time used in a git index entry */ typedef struct { unsigned int seconds; diff --git a/src/git/object.h b/src/git/object.h new file mode 100644 index 000000000..516591729 --- /dev/null +++ b/src/git/object.h @@ -0,0 +1,108 @@ +#ifndef INCLUDE_git_object_h__ +#define INCLUDE_git_object_h__ + +#include "common.h" +#include "types.h" +#include "oid.h" + +/** + * @file git/object.h + * @brief Git revision object management routines + * @defgroup git_object Git revision object management routines + * @ingroup Git + * @{ + */ +GIT_BEGIN_DECL + +/** + * Write back an object to disk. + * + * The object will be written to its corresponding + * repository. + * + * If the object has no changes since it was first + * read from the repository, no actions will take place. + * + * If the object has been modified since it was read from + * the repository, or it has been created from scratch + * in memory, it will be written to the repository and + * its SHA1 ID will be updated accordingly. + * + * @param object Git object to write back + * @return 0 on success; otherwise an error code + */ +GIT_EXTERN(int) git_object_write(git_object *object); + +/** + * Get the id (SHA1) of a repository object + * + * In-memory objects created by git_object_new() do not + * have a SHA1 ID until they are written on a repository. + * + * @param obj the repository object + * @return the SHA1 id + */ +GIT_EXTERN(const git_oid *) git_object_id(git_object *obj); + +/** + * Get the object type of an object + * + * @param obj the repository object + * @return the object's type + */ +GIT_EXTERN(git_otype) git_object_type(git_object *obj); + +/** + * Get the repository that owns this object + * + * @param obj the object + * @return the repository who owns this object + */ +GIT_EXTERN(git_repository *) git_object_owner(git_object *obj); + +/** + * Free a reference to one of the objects in the repository. + * + * Repository objects are managed automatically by the library, + * but this method can be used to force freeing one of the + * objects. + * + * Careful: freeing objects in the middle of a repository + * traversal will most likely cause errors. + * + * @param object the object to free + */ +GIT_EXTERN(void) git_object_free(git_object *object); + +/** + * Convert an object type to it's string representation. + * + * The result is a pointer to a string in static memory and + * should not be free()'ed. + * + * @param type object type to convert. + * @return the corresponding string representation. + */ +GIT_EXTERN(const char *) git_object_type2string(git_otype type); + +/** + * Convert a string object type representation to it's git_otype. + * + * @param str the string to convert. + * @return the corresponding git_otype. + */ +GIT_EXTERN(git_otype) git_object_string2type(const char *str); + +/** + * Determine if the given git_otype is a valid loose object type. + * + * @param type object type to test. + * @return true if the type represents a valid loose object type, + * false otherwise. + */ +GIT_EXTERN(int) git_object_typeisloose(git_otype type); + +/** @} */ +GIT_END_DECL + +#endif diff --git a/src/git/odb.h b/src/git/odb.h index 584a848c5..6be6ea2cf 100644 --- a/src/git/odb.h +++ b/src/git/odb.h @@ -2,8 +2,8 @@ #define INCLUDE_git_odb_h__ #include "common.h" +#include "types.h" #include "oid.h" -#include <stdlib.h> /** * @file git/odb.h @@ -14,12 +14,6 @@ */ 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; - /** * Create a new object database with no backends. * @@ -69,20 +63,6 @@ GIT_EXTERN(int) git_odb_add_backend(git_odb *odb, git_odb_backend *backend); */ GIT_EXTERN(void) git_odb_close(git_odb *db); -/** Basic type (loose or packed) of any Git object. */ -typedef enum { - GIT_OBJ_ANY = -2, /**< Object can be any of the following */ - GIT_OBJ_BAD = -1, /**< Object is invalid. */ - GIT_OBJ__EXT1 = 0, /**< Reserved for future use. */ - GIT_OBJ_COMMIT = 1, /**< A commit object. */ - GIT_OBJ_TREE = 2, /**< A tree (directory listing) object. */ - GIT_OBJ_BLOB = 3, /**< A file revision object. */ - GIT_OBJ_TAG = 4, /**< An annotated tag object. */ - GIT_OBJ__EXT2 = 5, /**< Reserved for future use. */ - GIT_OBJ_OFS_DELTA = 6, /**< A delta, base is given by an offset. */ - GIT_OBJ_REF_DELTA = 7, /**< A delta, base is given by object id. */ -} git_otype; - /** An object read from the database. */ typedef struct { void *data; /**< Raw, decompressed object data. */ @@ -173,42 +153,7 @@ GIT_EXTERN(int) git_rawobj_hash(git_oid *id, git_rawobj *obj); * * @param obj object descriptor to free. */ -GIT_INLINE(void) git_rawobj_close(git_rawobj *obj) -{ - free(obj->data); - obj->data = NULL; -} - - - - -/** - * Convert an object type to it's string representation. - * - * The result is a pointer to a string in static memory and - * should not be free()'ed. - * - * @param type object type to convert. - * @return the corresponding string representation. - */ -GIT_EXTERN(const char *) git_otype_tostring(git_otype type); - -/** - * Convert a string object type representation to it's git_otype. - * - * @param str the string to convert. - * @return the corresponding git_otype. - */ -GIT_EXTERN(git_otype) git_otype_fromstring(const char *str); - -/** - * Determine if the given git_otype is a valid loose object type. - * - * @param type object type to test. - * @return true if the type represents a valid loose object type, - * false otherwise. - */ -GIT_EXTERN(int) git_otype_is_loose(git_otype type); +GIT_EXTERN(void) git_rawobj_close(git_rawobj *obj); /** @} */ GIT_END_DECL diff --git a/src/git/odb_backend.h b/src/git/odb_backend.h new file mode 100644 index 000000000..747f4e97a --- /dev/null +++ b/src/git/odb_backend.h @@ -0,0 +1,40 @@ +#ifndef INCLUDE_git_odb_backend_h__ +#define INCLUDE_git_odb_backend_h__ + +#include "common.h" +#include "types.h" +#include "oid.h" + +GIT_BEGIN_DECL + +struct git_odb_backend { + git_odb *odb; + + int priority; + + int (* read)( + 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 *); + +}; + +GIT_END_DECL + +#endif diff --git a/src/git/oid.h b/src/git/oid.h index fe3c74b75..f0e39da68 100644 --- a/src/git/oid.h +++ b/src/git/oid.h @@ -1,9 +1,6 @@ #ifndef INCLUDE_git_oid_h__ #define INCLUDE_git_oid_h__ -#include "common.h" -#include <string.h> - /** * @file git/oid.h * @brief Git object id routines @@ -40,10 +37,7 @@ GIT_EXTERN(int) git_oid_mkstr(git_oid *out, const char *str); * @param out oid structure the result is written into. * @param raw the raw input bytes to be copied. */ -GIT_INLINE(void) git_oid_mkraw(git_oid *out, const unsigned char *raw) -{ - memcpy(out->id, raw, sizeof(out->id)); -} +GIT_EXTERN(void) git_oid_mkraw(git_oid *out, const unsigned char *raw); /** * Format a git_oid into a hex string. @@ -101,10 +95,7 @@ GIT_EXTERN(char *) git_oid_to_string(char *out, size_t n, const git_oid *oid); * @param out oid structure the result is written into. * @param src oid structure to copy from. */ -GIT_INLINE(void) git_oid_cpy(git_oid *out, const git_oid *src) -{ - memcpy(out->id, src->id, sizeof(out->id)); -} +GIT_EXTERN(void) git_oid_cpy(git_oid *out, const git_oid *src); /** * Compare two oid structures. @@ -112,10 +103,7 @@ GIT_INLINE(void) git_oid_cpy(git_oid *out, const git_oid *src) * @param b second oid structure. * @return <0, 0, >0 if a < b, a == b, a > b. */ -GIT_INLINE(int) git_oid_cmp(const git_oid *a, const git_oid *b) -{ - return memcmp(a->id, b->id, sizeof(a->id)); -} +GIT_EXTERN(int) git_oid_cmp(const git_oid *a, const git_oid *b); /** @} */ GIT_END_DECL diff --git a/src/git/repository.h b/src/git/repository.h index 661034719..683e78fc9 100644 --- a/src/git/repository.h +++ b/src/git/repository.h @@ -2,14 +2,13 @@ #define INCLUDE_git_repository_h__ #include "common.h" -#include "odb.h" -#include "commit.h" -#include "index.h" +#include "types.h" +#include "oid.h" /** * @file git/repository.h - * @brief Git revision object management routines - * @defgroup git_repository Git revision object management routines + * @brief Git repository management routines + * @defgroup git_repository Git repository management routines * @ingroup Git * @{ */ @@ -134,66 +133,6 @@ GIT_EXTERN(git_index *) git_repository_index(git_repository *rpeo); GIT_EXTERN(int) git_repository_newobject(git_object **object, git_repository *repo, git_otype type); /** - * Write back an object to disk. - * - * The object will be written to its corresponding - * repository. - * - * If the object has no changes since it was first - * read from the repository, no actions will take place. - * - * If the object has been modified since it was read from - * the repository, or it has been created from scratch - * in memory, it will be written to the repository and - * its SHA1 ID will be updated accordingly. - * - * @param object Git object to write back - * @return 0 on success; otherwise an error code - */ -GIT_EXTERN(int) git_object_write(git_object *object); - -/** - * Get the id (SHA1) of a repository object - * - * In-memory objects created by git_object_new() do not - * have a SHA1 ID until they are written on a repository. - * - * @param obj the repository object - * @return the SHA1 id - */ -GIT_EXTERN(const git_oid *) git_object_id(git_object *obj); - -/** - * Get the object type of an object - * - * @param obj the repository object - * @return the object's type - */ -GIT_EXTERN(git_otype) git_object_type(git_object *obj); - -/** - * Get the repository that owns this object - * - * @param obj the object - * @return the repository who owns this object - */ -GIT_EXTERN(git_repository *) git_object_owner(git_object *obj); - -/** - * Free a reference to one of the objects in the repository. - * - * Repository objects are managed automatically by the library, - * but this method can be used to force freeing one of the - * objects. - * - * Careful: freeing objects in the middle of a repository - * traversal will most likely cause errors. - * - * @param object the object to free - */ -GIT_EXTERN(void) git_object_free(git_object *object); - -/** * Free a previously allocated repository * @param repo repository handle to close. If NULL nothing occurs. */ diff --git a/src/git/revwalk.h b/src/git/revwalk.h index 49fd32174..6a761088a 100644 --- a/src/git/revwalk.h +++ b/src/git/revwalk.h @@ -2,8 +2,7 @@ #define INCLUDE_git_revwalk_h__ #include "common.h" -#include "odb.h" -#include "commit.h" +#include "types.h" /** * @file git/revwalk.h @@ -43,8 +42,6 @@ GIT_BEGIN_DECL */ #define GIT_SORT_REVERSE (1 << 2) -typedef struct git_revwalk git_revwalk; - /** * Allocate a new revision walker to iterate through a repo. * diff --git a/src/git/tag.h b/src/git/tag.h index cc15651ab..d57009870 100644 --- a/src/git/tag.h +++ b/src/git/tag.h @@ -2,9 +2,8 @@ #define INCLUDE_git_tag_h__ #include "common.h" +#include "types.h" #include "oid.h" -#include "tree.h" -#include "repository.h" /** * @file git/tag.h @@ -15,9 +14,6 @@ */ GIT_BEGIN_DECL -/** Parsed representation of a tag object. */ -typedef struct git_tag git_tag; - /** * Lookup a tag object from the repository. * The generated tag object is owned by the revision diff --git a/src/git/tree.h b/src/git/tree.h index f471113a8..d935169d8 100644 --- a/src/git/tree.h +++ b/src/git/tree.h @@ -2,8 +2,8 @@ #define INCLUDE_git_tree_h__ #include "common.h" +#include "types.h" #include "oid.h" -#include "repository.h" /** * @file git/tree.h @@ -14,13 +14,6 @@ */ GIT_BEGIN_DECL - -/** Representation of each one of the entries in a tree object. */ -typedef struct git_tree_entry git_tree_entry; - -/** Representation of a tree object. */ -typedef struct git_tree git_tree; - /** * Lookup a tree object from the repository. * The generated tree object is owned by the revision diff --git a/src/git/types.h b/src/git/types.h new file mode 100644 index 000000000..18684e13d --- /dev/null +++ b/src/git/types.h @@ -0,0 +1,64 @@ +#ifndef INCLUDE_git_types_h__ +#define INCLUDE_git_types_h__ + +/** + * @file git/types.h + * @brief libgit2 base types + * @ingroup Git + * @{ + */ +GIT_BEGIN_DECL + +/** Basic type (loose or packed) of any Git object. */ +typedef enum { + GIT_OBJ_ANY = -2, /**< Object can be any of the following */ + GIT_OBJ_BAD = -1, /**< Object is invalid. */ + GIT_OBJ__EXT1 = 0, /**< Reserved for future use. */ + GIT_OBJ_COMMIT = 1, /**< A commit object. */ + GIT_OBJ_TREE = 2, /**< A tree (directory listing) object. */ + GIT_OBJ_BLOB = 3, /**< A file revision object. */ + GIT_OBJ_TAG = 4, /**< An annotated tag object. */ + GIT_OBJ__EXT2 = 5, /**< Reserved for future use. */ + GIT_OBJ_OFS_DELTA = 6, /**< A delta, base is given by an offset. */ + GIT_OBJ_REF_DELTA = 7, /**< A delta, base is given by object id. */ +} git_otype; + +/** 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; + +/** + * Representation of an existing git repository, + * including all its object contents + */ +typedef struct git_repository git_repository; + +/** Representation of a generic object in a repository */ +typedef struct git_object git_object; + +typedef struct git_revwalk git_revwalk; + +/** Parsed representation of a tag object. */ +typedef struct git_tag git_tag; + +/** In-memory representation of a blob object. */ +typedef struct git_blob git_blob; + +/** Parsed representation of a commit object. */ +typedef struct git_commit git_commit; + +/** Representation of each one of the entries in a tree object. */ +typedef struct git_tree_entry git_tree_entry; + +/** Representation of a tree object. */ +typedef struct git_tree git_tree; + +/** Memory representation of an index file. */ +typedef struct git_index git_index; + +/** @} */ +GIT_END_DECL + +#endif diff --git a/src/git/zlib.h b/src/git/zlib.h index 1fec05920..b68db9bc1 100644 --- a/src/git/zlib.h +++ b/src/git/zlib.h @@ -1,7 +1,6 @@ #ifndef INCLUDE_git_zlib_h__ #define INCLUDE_git_zlib_h__ -#include "common.h" #include <zlib.h> /** |