diff options
Diffstat (limited to 'src/git')
| -rw-r--r-- | src/git/commit.h | 24 | ||||
| -rw-r--r-- | src/git/common.h | 10 | ||||
| -rw-r--r-- | src/git/odb.h | 1 | ||||
| -rw-r--r-- | src/git/repository.h | 60 | ||||
| -rw-r--r-- | src/git/revwalk.h | 66 | ||||
| -rw-r--r-- | src/git/tag.h | 23 | ||||
| -rw-r--r-- | src/git/tree.h | 21 |
7 files changed, 117 insertions, 88 deletions
diff --git a/src/git/commit.h b/src/git/commit.h index 89f0929c9..56243c5be 100644 --- a/src/git/commit.h +++ b/src/git/commit.h @@ -4,6 +4,7 @@ #include "common.h" #include "oid.h" #include "tree.h" +#include "repository.h" /** * @file git/commit.h @@ -18,31 +19,16 @@ GIT_BEGIN_DECL typedef struct git_commit git_commit; /** - * Locate a reference to a commit without loading it. + * Lookup a commit object from a repository. * The generated commit object is owned by the revision - * pool and shall not be freed by the user. + * repo and shall not be freed by the user. * - * @param pool the pool to use when locating the commit. + * @param repo the repo to use when locating the commit. * @param id identity of the commit to locate. If the object is * an annotated tag it will be peeled back to the commit. * @return the commit; NULL if the commit could not be created */ -GIT_EXTERN(git_commit *) git_commit_lookup(git_revpool *pool, const git_oid *id); - -/** - * Locate a reference to a commit, and try to load and parse it it from - * the commit cache or the object database. - * The generated commit object is owned by the revision - * pool and shall not be freed by the user. - * - * @param pool the pool to use when parsing/caching the commit. - * @param id identity of the commit to locate. If the object is - * an annotated tag it will be peeled back to the commit. - * @return the commit; NULL if the commit does not exist in the - * pool's git_odb, or if the commit is present but is - * too malformed to be parsed successfully. - */ -GIT_EXTERN(git_commit *) git_commit_parse(git_revpool *pool, const git_oid *id); +GIT_EXTERN(git_commit *) git_commit_lookup(git_repository *repo, const git_oid *id); /** * Get the id of a commit. diff --git a/src/git/common.h b/src/git/common.h index 09972aade..b43f4ee01 100644 --- a/src/git/common.h +++ b/src/git/common.h @@ -85,8 +85,14 @@ GIT_BEGIN_DECL -/** A revision traversal pool. */ -typedef struct git_revpool git_revpool; +/** + * 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_repository_object git_repository_object; /** Parsed representation of a person */ typedef struct git_person { diff --git a/src/git/odb.h b/src/git/odb.h index 58b932645..5d105ba70 100644 --- a/src/git/odb.h +++ b/src/git/odb.h @@ -35,6 +35,7 @@ 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. */ diff --git a/src/git/repository.h b/src/git/repository.h new file mode 100644 index 000000000..3b6981d50 --- /dev/null +++ b/src/git/repository.h @@ -0,0 +1,60 @@ +#ifndef INCLUDE_git_repository_h__ +#define INCLUDE_git_repository_h__ + +#include "common.h" +#include "odb.h" +#include "commit.h" + +/** + * @file git/repository.h + * @brief Git revision object management routines + * @defgroup git_repository Git revision object management routines + * @ingroup Git + * @{ + */ +GIT_BEGIN_DECL + +/** + * Allocate a new repository object. + * + * TODO: specify the repository's path instead + * of its object database + * + * @param odb an existing object database to back the repo + * @return the new repository handle; NULL on error + */ +GIT_EXTERN(git_repository *) git_repository_alloc(git_odb *odb); + + +/** + * Lookup a reference to one of the objects in the repostory. + * + * The generated reference is owned by the repository and + * should not be freed by the user. + * The generated reference should be cast back to the + * expected type; e.g. + * + * git_commit *c = (git_commit *) + * git_repository_lookup(repo, id, GIT_OBJ_COMMIT); + * + * The 'type' parameter must match the type of the object + * in the odb; the method will fail otherwise. + * The special value 'GIT_OBJ_ANY' may be passed to let + * the method guess the object's type. + * + * @param repo the repository to look up the object + * @param id the unique identifier for the object + * @param type the type of the object + * @return a reference to the object + */ +GIT_EXTERN(git_repository_object *) git_repository_lookup(git_repository *repo, const git_oid *id, git_otype type); + +/** + * Free a previously allocated repository + * @param repo repository handle to close. If NULL nothing occurs. + */ +GIT_EXTERN(void) git_repository_free(git_repository *repo); + +/** @} */ +GIT_END_DECL +#endif diff --git a/src/git/revwalk.h b/src/git/revwalk.h index 7aa92d44a..842503dea 100644 --- a/src/git/revwalk.h +++ b/src/git/revwalk.h @@ -15,87 +15,87 @@ GIT_BEGIN_DECL /** - * Sort the revpool contents in no particular ordering; + * Sort the repository contents in no particular ordering; * this sorting is arbritary, implementation-specific * and subject to change at any time. - * This is the default sorting for new revision pools. + * This is the default sorting for new walkers. */ -#define GIT_RPSORT_NONE (0) +#define GIT_SORT_NONE (0) /** - * Sort the revpool contents in topological order + * Sort the repository contents in topological order * (parents before children); this sorting mode * can be combined with time sorting. */ -#define GIT_RPSORT_TOPOLOGICAL (1 << 0) +#define GIT_SORT_TOPOLOGICAL (1 << 0) /** - * Sort the revpool contents by commit time; + * Sort the repository contents by commit time; * this sorting mode can be combined with * topological sorting. */ -#define GIT_RPSORT_TIME (1 << 1) +#define GIT_SORT_TIME (1 << 1) /** - * Iterate through the revpool contents in reverse + * Iterate through the repository contents in reverse * order; this sorting mode can be combined with * any of the above. */ -#define GIT_RPSORT_REVERSE (1 << 2) +#define GIT_SORT_REVERSE (1 << 2) + +typedef struct git_revwalk git_revwalk; /** - * Allocate a new revision traversal pool. - * - * The configuration is copied during allocation. Changes - * to the configuration after allocation do not affect the pool - * returned by this function. Callers may safely free the - * passed configuration after the function completes. + * Allocate a new revision walker to iterate through a repo. * - * @param db the database objects are read from. - * @return the new traversal handle; NULL if memory is exhausted. + * @param repo the repo to walk through + * @return the new walker handle; NULL if memory is exhausted. */ -GIT_EXTERN(git_revpool *) gitrp_alloc(git_odb *db); +GIT_EXTERN(git_revwalk *) git_revwalk_alloc(git_repository *repo); /** - * Reset the traversal machinary for reuse. - * @param pool traversal handle to reset. + * Reset the walking machinary for reuse. + * @param walker handle to reset. */ -GIT_EXTERN(void) gitrp_reset(git_revpool *pool); +GIT_EXTERN(void) git_revwalk_reset(git_revwalk *walker); /** - * Mark an object to start traversal from. - * @param pool the pool being used for the traversal. + * Mark a commit to start traversal from. + * The commit object must belong to the repo which is being walked through. + * + * @param walker the walker being used for the traversal. * @param commit the commit to start from. */ -GIT_EXTERN(int) gitrp_push(git_revpool *pool, git_commit *commit); +GIT_EXTERN(int) git_revwalk_push(git_revwalk *walk, git_commit *commit); /** * Mark a commit (and its ancestors) uninteresting for the output. - * @param pool the pool being used for the traversal. + * @param walker the walker being used for the traversal. * @param commit the commit that will be ignored during the traversal */ -GIT_EXTERN(int) gitrp_hide(git_revpool *pool, git_commit *commit); +GIT_EXTERN(int) git_revwalk_hide(git_revwalk *walk, git_commit *commit); /** * Get the next commit from the revision traversal. - * @param pool the pool to pop the commit from. + * @param walk the walker to pop the commit from. * @return next commit; NULL if there is no more output. */ -GIT_EXTERN(git_commit *) gitrp_next(git_revpool *pool); +GIT_EXTERN(git_commit *) git_revwalk_next(git_revwalk *walk); /** * Change the sorting mode when iterating through the - * revision pool's contents. - * @param pool the pool being used for the traversal. + * repository's contents. + * Changing the sorting mode resets the walker. + * @param walk the walker being used for the traversal. * @param sort_mode combination of GIT_RPSORT_XXX flags */ -GIT_EXTERN(void) gitrp_sorting(git_revpool *pool, unsigned int sort_mode); +GIT_EXTERN(void) git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode); /** * Free a revwalk previously allocated. - * @param pool traversal handle to close. If NULL nothing occurs. + * @param walk traversal handle to close. If NULL nothing occurs. */ -GIT_EXTERN(void) gitrp_free(git_revpool *pool); +GIT_EXTERN(void) git_revwalk_free(git_revwalk *walk); /** @} */ GIT_END_DECL diff --git a/src/git/tag.h b/src/git/tag.h index 509d2f047..d94083b11 100644 --- a/src/git/tag.h +++ b/src/git/tag.h @@ -4,6 +4,7 @@ #include "common.h" #include "oid.h" #include "tree.h" +#include "repository.h" /** * @file git/tag.h @@ -18,29 +19,15 @@ GIT_BEGIN_DECL typedef struct git_tag git_tag; /** - * Locate a reference to a tag without loading it. + * Lookup a tag object from the repository. * The generated tag object is owned by the revision - * pool and shall not be freed by the user. + * repo and shall not be freed by the user. * - * @param pool the pool to use when locating the tag. + * @param repo the repo to use when locating the tag. * @param id identity of the tag to locate. * @return the tag; NULL if the tag could not be created */ -GIT_EXTERN(git_tag *) git_tag_lookup(git_revpool *pool, const git_oid *id); - -/** - * Locate a reference to a tag, and try to load and parse it it from - * the object cache or the object database. - * The generated tag object is owned by the revision - * pool and shall not be freed by the user. - * - * @param pool the pool to use when parsing/caching the tag. - * @param id identity of the tag to locate. - * @return the tag; NULL if the tag does not exist in the - * pool's git_odb, or if the tag is present but is - * too malformed to be parsed successfully. - */ -GIT_EXTERN(git_tag *) git_tag_parse(git_revpool *pool, const git_oid *id); +GIT_EXTERN(git_tag *) git_tag_lookup(git_repository *repo, const git_oid *id); /** * Get the id of a tag. diff --git a/src/git/tree.h b/src/git/tree.h index 9a4973ba6..95b233009 100644 --- a/src/git/tree.h +++ b/src/git/tree.h @@ -3,6 +3,7 @@ #include "common.h" #include "oid.h" +#include "repository.h" /** * @file git/tree.h @@ -17,27 +18,15 @@ GIT_BEGIN_DECL typedef struct git_tree git_tree; /** - * Locate a reference to a tree without loading it. + * Lookup a tree object from the repository. * The generated tree object is owned by the revision - * pool and shall not be freed by the user. + * repo and shall not be freed by the user. * - * @param pool the pool to use when locating the tree. + * @param repo the repo to use when locating the tree. * @param id identity of the tree to locate. * @return the tree; NULL if the tree could not be created */ -GIT_EXTERN(git_tree *) git_tree_lookup(git_revpool *pool, const git_oid *id); - -/** - * Locate a reference to a tree object and parse its - * contents. - * The generated tree object is owned by the revision - * pool and shall not be freed by the user. - * - * @param pool the pool to use when locating the tree. - * @param id identity of the tree to locate. - * @return the tree; NULL if the tree could not be created - */ -GIT_EXTERN(git_tree *) git_tree_parse(git_revpool *pool, const git_oid *id); +GIT_EXTERN(git_tree *) git_tree_lookup(git_repository *repo, const git_oid *id); /** * Get the id of a tree. |
