diff options
author | Vicent Marti <tanoku@gmail.com> | 2010-11-05 03:20:17 +0200 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2010-11-05 03:20:17 +0200 |
commit | 1795f87952a68155a618523799f70473483c7265 (patch) | |
tree | 239c2fef7674cc0407523be0a250b563361efc6b /src/git | |
parent | 1714826fa08ad8612b720c8fdea636a4fc49c480 (diff) | |
download | libgit2-1795f87952a68155a618523799f70473483c7265.tar.gz |
Improve error handling
All initialization functions now return error codes instead of pointers.
Error codes are now properly propagated on most functions. Several new
and more specific error codes have been added in common.h
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'src/git')
-rw-r--r-- | src/git/commit.h | 10 | ||||
-rw-r--r-- | src/git/common.h | 22 | ||||
-rw-r--r-- | src/git/index.h | 5 | ||||
-rw-r--r-- | src/git/repository.h | 14 | ||||
-rw-r--r-- | src/git/revwalk.h | 7 | ||||
-rw-r--r-- | src/git/tag.h | 10 | ||||
-rw-r--r-- | src/git/tree.h | 14 |
7 files changed, 56 insertions, 26 deletions
diff --git a/src/git/commit.h b/src/git/commit.h index 5d3fa0adb..8cb3401b6 100644 --- a/src/git/commit.h +++ b/src/git/commit.h @@ -23,12 +23,13 @@ typedef struct git_commit git_commit; * The generated commit object is owned by the revision * repo and shall not be freed by the user. * + * @param commit pointer to the looked up 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 + * @return 0 on success; error code otherwise */ -GIT_EXTERN(git_commit *) git_commit_lookup(git_repository *repo, const git_oid *id); +GIT_EXTERN(int) git_commit_lookup(git_commit **commit, git_repository *repo, const git_oid *id); /** * Create a new in-memory git_commit. @@ -37,10 +38,11 @@ GIT_EXTERN(git_commit *) git_commit_lookup(git_repository *repo, const git_oid * * setter methods before it can be written to its * repository. * + * @param commit pointer to the new commit * @param repo The repository where the object will reside - * @return the object if creation was possible; NULL otherwise + * @return 0 on success; error code otherwise */ -GIT_EXTERN(git_commit *) git_commit_new(git_repository *repo); +GIT_EXTERN(int) git_commit_new(git_commit ** commit, git_repository *repo); /** * Get the id of a commit. diff --git a/src/git/common.h b/src/git/common.h index 35408413d..82f08ac5d 100644 --- a/src/git/common.h +++ b/src/git/common.h @@ -84,6 +84,28 @@ /** The specified object has its data corrupted */ #define GIT_EOBJCORRUPTED (GIT_ERROR - 6) +/** The specified repository is invalid */ +#define GIT_ENOTAREPO (GIT_ERROR - 7) + +/** The object type is invalid or doesn't match */ +#define GIT_EINVALIDTYPE (GIT_ERROR - 8) + +/** The object cannot be written that because it's missing internal data */ +#define GIT_EMISSINGOBJDATA (GIT_ERROR - 9) + +/** The packfile for the ODB is corrupted */ +#define GIT_EPACKCORRUPTED (GIT_ERROR - 10) + +/** Failed to adquire or release a file lock */ +#define GIT_EFLOCKFAIL (GIT_ERROR - 11) + +/** The Z library failed to inflate/deflate an object's data */ +#define GIT_EZLIB (GIT_ERROR - 12) + +/** The queried object is currently busy */ +#define GIT_EBUSY (GIT_ERROR - 13) + + GIT_BEGIN_DECL /** diff --git a/src/git/index.h b/src/git/index.h index 3b262355e..ee410865d 100644 --- a/src/git/index.h +++ b/src/git/index.h @@ -56,11 +56,12 @@ typedef struct git_index_entry { * If 'working _dir' is NULL (e.g for bare repositories), the * methods working on on-disk files will fail. * + * @param index the pointer for the new index * @param index_path the path to the index file in disk * @param working_dir working dir for the git repository - * @return the index object; NULL if the index could not be created + * @return 0 on success; error code otherwise */ -GIT_EXTERN(git_index *) git_index_alloc(const char *index_path, const char *working_dir); +GIT_EXTERN(int) git_index_open(git_index **index, const char *index_path, const char *working_dir); /** * Clear the contents (all the entries) of an index object. diff --git a/src/git/repository.h b/src/git/repository.h index 058849b7f..81eb1ea59 100644 --- a/src/git/repository.h +++ b/src/git/repository.h @@ -34,10 +34,11 @@ GIT_BEGIN_DECL * The method will automatically detect if 'path' is a normal * or bare repository or fail is 'path' is neither. * + * @param repository pointer to the repo which will be opened * @param path the path to the repository * @return the new repository handle; NULL on error */ -GIT_EXTERN(git_repository *) git_repository_open(const char *path); +GIT_EXTERN(int) git_repository_open(git_repository **repository, const char *path); /** @@ -45,23 +46,19 @@ GIT_EXTERN(git_repository *) git_repository_open(const char *path); * * 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 object pointer to the looked-up object * @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_object *) git_repository_lookup(git_repository *repo, const git_oid *id, git_otype type); +GIT_EXTERN(int) git_repository_lookup(git_object **object, git_repository *repo, const git_oid *id, git_otype type); /** * Get the object database behind a Git repository @@ -96,11 +93,12 @@ GIT_EXTERN(git_index *) git_repository_index(git_repository *rpeo); * will be automatically generated when writing to the * repository. * + * @param object pointer to the new object * @parem repo Repository where the object belongs * @param type Type of the object to be created * @return the new object */ -GIT_EXTERN(git_object *) git_object_new(git_repository *repo, git_otype type); +GIT_EXTERN(int) git_repository_newobject(git_object **object, git_repository *repo, git_otype type); /** * Write back an object to disk. diff --git a/src/git/revwalk.h b/src/git/revwalk.h index 42ffbc3e7..49fd32174 100644 --- a/src/git/revwalk.h +++ b/src/git/revwalk.h @@ -48,10 +48,11 @@ typedef struct git_revwalk git_revwalk; /** * Allocate a new revision walker to iterate through a repo. * + * @param walker pointer to the new revision walker * @param repo the repo to walk through - * @return the new walker handle; NULL if memory is exhausted. + * @return 0 on success; error code otherwise */ -GIT_EXTERN(git_revwalk *) git_revwalk_alloc(git_repository *repo); +GIT_EXTERN(int) git_revwalk_new(git_revwalk **walker, git_repository *repo); /** * Reset the walking machinery for reuse. @@ -89,7 +90,7 @@ GIT_EXTERN(git_commit *) git_revwalk_next(git_revwalk *walk); * @param walk the walker being used for the traversal. * @param sort_mode combination of GIT_RPSORT_XXX flags */ -GIT_EXTERN(void) git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode); +GIT_EXTERN(int) git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode); /** * Free a revwalk previously allocated. diff --git a/src/git/tag.h b/src/git/tag.h index e1cd1ab85..cc15651ab 100644 --- a/src/git/tag.h +++ b/src/git/tag.h @@ -23,11 +23,12 @@ typedef struct git_tag git_tag; * The generated tag object is owned by the revision * repo and shall not be freed by the user. * + * @param tag pointer to the looked up 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 + * @return 0 on success; error code otherwise */ -GIT_EXTERN(git_tag *) git_tag_lookup(git_repository *repo, const git_oid *id); +GIT_EXTERN(int) git_tag_lookup(git_tag **tag, git_repository *repo, const git_oid *id); /** * Create a new in-memory git_tag. @@ -36,10 +37,11 @@ GIT_EXTERN(git_tag *) git_tag_lookup(git_repository *repo, const git_oid *id); * setter methods before it can be written to its * repository. * + * @param tag pointer to the new tag * @param repo The repository where the object will reside - * @return the object if creation was possible; NULL otherwise + * @return 0 on success; error code otherwise */ -GIT_EXTERN(git_tag *) git_tag_new(git_repository *repo); +GIT_EXTERN(int) git_tag_new(git_tag **tag, git_repository *repo); /** * Get the id of a tag. diff --git a/src/git/tree.h b/src/git/tree.h index 190fe95d6..f471113a8 100644 --- a/src/git/tree.h +++ b/src/git/tree.h @@ -26,11 +26,12 @@ typedef struct git_tree git_tree; * The generated tree object is owned by the revision * repo and shall not be freed by the user. * + * @param tree pointer to the looked up 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 + * @return 0 on success; error code otherwise */ -GIT_EXTERN(git_tree *) git_tree_lookup(git_repository *repo, const git_oid *id); +GIT_EXTERN(int) git_tree_lookup(git_tree **tree, git_repository *repo, const git_oid *id); /** * Create a new in-memory git_tree. @@ -39,10 +40,11 @@ GIT_EXTERN(git_tree *) git_tree_lookup(git_repository *repo, const git_oid *id); * setter methods before it can be written to its * repository. * + * @param tree pointer to the new tree * @param repo The repository where the object will reside - * @return the object if creation was possible; NULL otherwise + * @return 0 on success; error code otherwise */ -GIT_EXTERN(git_tree *) git_tree_new(git_repository *repo); +GIT_EXTERN(int) git_tree_new(git_tree **tree, git_repository *repo); /** * Get the id of a tree. @@ -98,10 +100,12 @@ GIT_EXTERN(const git_oid *) git_tree_entry_id(git_tree_entry *entry); /** * Convert a tree entry to the git_object it points too. + * + * @param object pointer to the converted object * @param entry a tree entry * @return a reference to the pointed object in the repository */ -GIT_EXTERN(git_object *) git_tree_entry_2object(git_tree_entry *entry); +GIT_EXTERN(int) git_tree_entry_2object(git_object **object, git_tree_entry *entry); /** * Add a new entry to a tree. |