mirror of
https://git.proxmox.com/git/libgit2
synced 2025-12-25 19:12:56 +00:00
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>
This commit is contained in:
parent
4569bfa55a
commit
c836c332f1
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "git2/oid.h"
|
||||
#include "git2/refs.h"
|
||||
#include "hashtable.h"
|
||||
|
||||
#define GIT_REFS_DIR "refs/"
|
||||
|
||||
@ -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)
|
||||
{
|
||||
if (repo->index == NULL) {
|
||||
if (git_index_open_inrepo(&repo->index, repo) < GIT_SUCCESS)
|
||||
return NULL;
|
||||
int error;
|
||||
|
||||
assert(repo->index);
|
||||
assert(index_out && repo);
|
||||
|
||||
if (repo->index == NULL) {
|
||||
error = git_index_open_inrepo(&repo->index, repo);
|
||||
if (error < GIT_SUCCESS)
|
||||
return error;
|
||||
|
||||
assert(repo->index != NULL);
|
||||
}
|
||||
|
||||
return repo->index;
|
||||
*index_out = repo->index;
|
||||
return GIT_SUCCESS;
|
||||
}
|
||||
|
||||
git_odb *git_repository_database(git_repository *repo)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user