summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2011-02-05 09:29:37 +0200
committerVicent Marti <tanoku@gmail.com>2011-02-05 09:29:37 +0200
commitc836c332f17ff2da8bdf6d18fb3d59eac2586ca9 (patch)
tree724bddb50a0c8f25e59845f9bd0587fb6724457a
parent4569bfa55a44be3a03cf925df44bf1af0f21ddaa (diff)
downloadlibgit2-c836c332f17ff2da8bdf6d18fb3d59eac2586ca9.tar.gz
Make more methods return error codes
git_revwalk_next now returns an error code when the iteration is over. git_repository_index now returns an error code when the index file could not be opened. Signed-off-by: Vicent Marti <tanoku@gmail.com>
-rw-r--r--src/errors.c4
-rw-r--r--src/git2/common.h3
-rw-r--r--src/git2/repository.h9
-rw-r--r--src/git2/revwalk.h7
-rw-r--r--src/refs.h1
-rw-r--r--src/repository.c16
-rw-r--r--src/revwalk.c14
-rw-r--r--tests/t05-revwalk.c2
8 files changed, 39 insertions, 17 deletions
diff --git a/src/errors.c b/src/errors.c
index 34a15b258..3616fdb93 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -24,7 +24,9 @@ static struct {
{GIT_EINVALIDREFNAME, "The name of the reference is not valid"},
{GIT_EREFCORRUPTED, "The specified reference has its data corrupted"},
{GIT_ETOONESTEDSYMREF, "The specified symbolic reference is too deeply nested"},
- {GIT_EPACKEDREFSCORRUPTED, "The pack-refs file is either corrupted of its format is not currently supported"}
+ {GIT_EPACKEDREFSCORRUPTED, "The pack-refs file is either corrupted of its format is not currently supported"},
+ {GIT_EINVALIDPATH, "The path is invalid" },
+ {GIT_EREVWALKOVER, "The revision walker is empty; there are no more commits left to iterate"}
};
const char *git_strerror(int num)
diff --git a/src/git2/common.h b/src/git2/common.h
index aae707cb6..3500a2b14 100644
--- a/src/git2/common.h
+++ b/src/git2/common.h
@@ -151,6 +151,9 @@
/** The path is invalid */
#define GIT_EINVALIDPATH (GIT_ERROR - 19)
+/** The revision walker is empty; there are no more commits left to iterate */
+#define GIT_EREVWALKOVER (GIT_ERROR - 20)
+
GIT_BEGIN_DECL
/** @} */
GIT_END_DECL
diff --git a/src/git2/repository.h b/src/git2/repository.h
index ecf3db99f..ec74305ae 100644
--- a/src/git2/repository.h
+++ b/src/git2/repository.h
@@ -163,11 +163,14 @@ GIT_EXTERN(git_odb *) git_repository_database(git_repository *repo);
/**
* Get the Index file of a Git repository
*
+ * This is a cheap operation; the index is only opened on the first call,
+ * and subsequent calls only retrieve the previous pointer.
+ *
+ * @param index Pointer where to store the index
* @param repo a repository object
- * @return a pointer to the Index object;
- * NULL if the index cannot be opened
+ * @return 0 on success; error code if the index could not be opened
*/
-GIT_EXTERN(git_index *) git_repository_index(git_repository *rpeo);
+GIT_EXTERN(int) git_repository_index(git_index **index, git_repository *repo);
/**
* Create a new in-memory repository object with
diff --git a/src/git2/revwalk.h b/src/git2/revwalk.h
index 960039a39..841110499 100644
--- a/src/git2/revwalk.h
+++ b/src/git2/revwalk.h
@@ -99,10 +99,13 @@ GIT_EXTERN(int) git_revwalk_hide(git_revwalk *walk, git_commit *commit);
/**
* Get the next commit from the revision traversal.
+ *
+ * @param commit Pointer where to store the next commit
* @param walk the walker to pop the commit from.
- * @return next commit; NULL if there is no more output.
+ * @return GIT_SUCCESS if the next commit was found;
+ * GIT_EREVWALKOVER if there are no commits left to iterate
*/
-GIT_EXTERN(git_commit *) git_revwalk_next(git_revwalk *walk);
+GIT_EXTERN(int) git_revwalk_next(git_commit **commit, git_revwalk *walk);
/**
* Change the sorting mode when iterating through the
diff --git a/src/refs.h b/src/refs.h
index 3b6d5673f..70196aa95 100644
--- a/src/refs.h
+++ b/src/refs.h
@@ -3,6 +3,7 @@
#include "common.h"
#include "git2/oid.h"
+#include "git2/refs.h"
#include "hashtable.h"
#define GIT_REFS_DIR "refs/"
diff --git a/src/repository.c b/src/repository.c
index d010d8c08..37d5a49f0 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -374,16 +374,22 @@ void git_repository_free(git_repository *repo)
free(repo);
}
-git_index *git_repository_index(git_repository *repo)
+int git_repository_index(git_index **index_out, git_repository *repo)
{
+ int error;
+
+ assert(index_out && repo);
+
if (repo->index == NULL) {
- if (git_index_open_inrepo(&repo->index, repo) < GIT_SUCCESS)
- return NULL;
+ error = git_index_open_inrepo(&repo->index, repo);
+ if (error < GIT_SUCCESS)
+ return error;
- assert(repo->index);
+ assert(repo->index != NULL);
}
- return repo->index;
+ *index_out = repo->index;
+ return GIT_SUCCESS;
}
git_odb *git_repository_database(git_repository *repo)
diff --git a/src/revwalk.c b/src/revwalk.c
index df8f47ab8..2237e333d 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -220,23 +220,27 @@ static void prepare_walk(git_revwalk *walk)
walk->walking = 1;
}
-git_commit *git_revwalk_next(git_revwalk *walk)
+int git_revwalk_next(git_commit **commit, git_revwalk *walk)
{
git_revwalk_commit *next;
- assert(walk);
+ assert(walk && commit);
if (!walk->walking)
prepare_walk(walk);
+ *commit = NULL;
+
while ((next = walk->next(&walk->iterator)) != NULL) {
- if (!next->uninteresting)
- return next->commit_object;
+ if (!next->uninteresting) {
+ *commit = next->commit_object;
+ return GIT_SUCCESS;
+ }
}
/* No commits left to iterate */
git_revwalk_reset(walk);
- return NULL;
+ return GIT_EREVWALKOVER;
}
void git_revwalk_reset(git_revwalk *walk)
diff --git a/tests/t05-revwalk.c b/tests/t05-revwalk.c
index 06f933fb4..473ea3350 100644
--- a/tests/t05-revwalk.c
+++ b/tests/t05-revwalk.c
@@ -99,7 +99,7 @@ static int test_walk(git_revwalk *walk, git_commit *start_from,
result_array[i] = -1;
i = 0;
- while ((commit = git_revwalk_next(walk)) != NULL)
+ while (git_revwalk_next(&commit, walk) == GIT_SUCCESS)
result_array[i++] = get_commit_index(commit);
for (i = 0; i < results_count; ++i)