mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-07 18:11:43 +00:00
Added new error codes. Improved error handling.
Signed-off-by: Vicent Marti <tanoku@gmail.com> Signed-off-by: Andreas Ericsson <ae@op5.se>
This commit is contained in:
parent
0daa6cdcad
commit
6bb7aa1318
38
src/commit.c
38
src/commit.c
@ -81,7 +81,7 @@ int git_commit_parse_existing(git_commit *commit)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (git_odb_read(&commit_obj, commit->object.pool->db, &commit->object.id) < 0)
|
if (git_odb_read(&commit_obj, commit->object.pool->db, &commit->object.id) < 0)
|
||||||
return -1;
|
return GIT_ENOTFOUND;
|
||||||
|
|
||||||
if (commit_obj.type != GIT_OBJ_COMMIT)
|
if (commit_obj.type != GIT_OBJ_COMMIT)
|
||||||
goto error_cleanup;
|
goto error_cleanup;
|
||||||
@ -128,27 +128,27 @@ git_commit *git_commit_lookup(git_revpool *pool, const git_oid *id)
|
|||||||
int git_commit__parse_time(time_t *commit_time, char *buffer, const char *buffer_end)
|
int git_commit__parse_time(time_t *commit_time, char *buffer, const char *buffer_end)
|
||||||
{
|
{
|
||||||
if (memcmp(buffer, "author ", 7) != 0)
|
if (memcmp(buffer, "author ", 7) != 0)
|
||||||
return -1;
|
return GIT_EOBJCORRUPTED;
|
||||||
|
|
||||||
buffer = memchr(buffer, '\n', buffer_end - buffer);
|
buffer = memchr(buffer, '\n', buffer_end - buffer);
|
||||||
if (buffer == 0 || ++buffer >= buffer_end)
|
if (buffer == 0 || ++buffer >= buffer_end)
|
||||||
return -1;
|
return GIT_EOBJCORRUPTED;
|
||||||
|
|
||||||
if (memcmp(buffer, "committer ", 10) != 0)
|
if (memcmp(buffer, "committer ", 10) != 0)
|
||||||
return -1;
|
return GIT_EOBJCORRUPTED;
|
||||||
|
|
||||||
buffer = memchr(buffer, '>', buffer_end - buffer);
|
buffer = memchr(buffer, '>', buffer_end - buffer);
|
||||||
if (buffer == 0 || ++buffer >= buffer_end)
|
if (buffer == 0 || ++buffer >= buffer_end)
|
||||||
return -1;
|
return GIT_EOBJCORRUPTED;
|
||||||
|
|
||||||
*commit_time = strtol(buffer, &buffer, 10);
|
*commit_time = strtol(buffer, &buffer, 10);
|
||||||
|
|
||||||
if (*commit_time == 0)
|
if (*commit_time == 0)
|
||||||
return -1;
|
return GIT_EOBJCORRUPTED;
|
||||||
|
|
||||||
buffer = memchr(buffer, '\n', buffer_end - buffer);
|
buffer = memchr(buffer, '\n', buffer_end - buffer);
|
||||||
if (buffer == 0 || ++buffer >= buffer_end)
|
if (buffer == 0 || ++buffer >= buffer_end)
|
||||||
return -1;
|
return GIT_EOBJCORRUPTED;
|
||||||
|
|
||||||
return (buffer < buffer_end) ? 0 : -1;
|
return (buffer < buffer_end) ? 0 : -1;
|
||||||
}
|
}
|
||||||
@ -161,16 +161,16 @@ int git_commit__parse_oid(git_oid *oid, char **buffer_out, const char *buffer_en
|
|||||||
char *buffer = *buffer_out;
|
char *buffer = *buffer_out;
|
||||||
|
|
||||||
if (buffer + (header_len + sha_len + 1) > buffer_end)
|
if (buffer + (header_len + sha_len + 1) > buffer_end)
|
||||||
return -1;
|
return GIT_EOBJCORRUPTED;
|
||||||
|
|
||||||
if (memcmp(buffer, header, header_len) != 0)
|
if (memcmp(buffer, header, header_len) != 0)
|
||||||
return -1;
|
return GIT_EOBJCORRUPTED;
|
||||||
|
|
||||||
if (buffer[header_len + sha_len] != '\n')
|
if (buffer[header_len + sha_len] != '\n')
|
||||||
return -1;
|
return GIT_EOBJCORRUPTED;
|
||||||
|
|
||||||
if (git_oid_mkstr(oid, buffer + header_len) < 0)
|
if (git_oid_mkstr(oid, buffer + header_len) < 0)
|
||||||
return -1;
|
return GIT_EOBJCORRUPTED;
|
||||||
|
|
||||||
*buffer_out = buffer + (header_len + sha_len + 1);
|
*buffer_out = buffer + (header_len + sha_len + 1);
|
||||||
|
|
||||||
@ -188,7 +188,7 @@ int git_commit__parse_buffer(git_commit *commit, void *data, size_t len)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (git_commit__parse_oid(&oid, &buffer, buffer_end, "tree ") < 0)
|
if (git_commit__parse_oid(&oid, &buffer, buffer_end, "tree ") < 0)
|
||||||
return -1;
|
return GIT_EOBJCORRUPTED;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO: load tree into commit object
|
* TODO: load tree into commit object
|
||||||
@ -199,7 +199,7 @@ int git_commit__parse_buffer(git_commit *commit, void *data, size_t len)
|
|||||||
git_commit *parent;
|
git_commit *parent;
|
||||||
|
|
||||||
if ((parent = git_commit_lookup(commit->object.pool, &oid)) == NULL)
|
if ((parent = git_commit_lookup(commit->object.pool, &oid)) == NULL)
|
||||||
return -1;
|
return GIT_ENOTFOUND;
|
||||||
|
|
||||||
// Inherit uninteresting flag
|
// Inherit uninteresting flag
|
||||||
if (commit->uninteresting)
|
if (commit->uninteresting)
|
||||||
@ -209,21 +209,21 @@ int git_commit__parse_buffer(git_commit *commit, void *data, size_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (git_commit__parse_time(&commit->commit_time, buffer, buffer_end) < 0)
|
if (git_commit__parse_time(&commit->commit_time, buffer, buffer_end) < 0)
|
||||||
return -1;
|
return GIT_EOBJCORRUPTED;
|
||||||
|
|
||||||
commit->parsed = 1;
|
commit->parsed = 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void git_commit_list_push_back(git_commit_list *list, git_commit *commit)
|
int git_commit_list_push_back(git_commit_list *list, git_commit *commit)
|
||||||
{
|
{
|
||||||
git_commit_node *node = NULL;
|
git_commit_node *node = NULL;
|
||||||
|
|
||||||
node = git__malloc(sizeof(git_commit_list));
|
node = git__malloc(sizeof(git_commit_list));
|
||||||
|
|
||||||
if (node == NULL)
|
if (node == NULL)
|
||||||
return;
|
return GIT_ENOMEM;
|
||||||
|
|
||||||
node->commit = commit;
|
node->commit = commit;
|
||||||
node->next = NULL;
|
node->next = NULL;
|
||||||
@ -237,16 +237,17 @@ void git_commit_list_push_back(git_commit_list *list, git_commit *commit)
|
|||||||
}
|
}
|
||||||
|
|
||||||
list->size++;
|
list->size++;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void git_commit_list_push_front(git_commit_list *list, git_commit *commit)
|
int git_commit_list_push_front(git_commit_list *list, git_commit *commit)
|
||||||
{
|
{
|
||||||
git_commit_node *node = NULL;
|
git_commit_node *node = NULL;
|
||||||
|
|
||||||
node = git__malloc(sizeof(git_commit_list));
|
node = git__malloc(sizeof(git_commit_list));
|
||||||
|
|
||||||
if (node == NULL)
|
if (node == NULL)
|
||||||
return;
|
return GIT_ENOMEM;
|
||||||
|
|
||||||
node->commit = commit;
|
node->commit = commit;
|
||||||
node->next = list->head;
|
node->next = list->head;
|
||||||
@ -260,6 +261,7 @@ void git_commit_list_push_front(git_commit_list *list, git_commit *commit)
|
|||||||
}
|
}
|
||||||
|
|
||||||
list->size++;
|
list->size++;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,8 +44,8 @@ void git_commit__mark_uninteresting(git_commit *commit);
|
|||||||
int git_commit_parse_existing(git_commit *commit);
|
int git_commit_parse_existing(git_commit *commit);
|
||||||
|
|
||||||
|
|
||||||
void git_commit_list_push_back(git_commit_list *list, git_commit *commit);
|
int git_commit_list_push_back(git_commit_list *list, git_commit *commit);
|
||||||
void git_commit_list_push_front(git_commit_list *list, git_commit *commit);
|
int git_commit_list_push_front(git_commit_list *list, git_commit *commit);
|
||||||
|
|
||||||
git_commit *git_commit_list_pop_back(git_commit_list *list);
|
git_commit *git_commit_list_pop_back(git_commit_list *list);
|
||||||
git_commit *git_commit_list_pop_front(git_commit_list *list);
|
git_commit *git_commit_list_pop_front(git_commit_list *list);
|
||||||
|
@ -77,6 +77,12 @@
|
|||||||
/** Consult the OS error information. */
|
/** Consult the OS error information. */
|
||||||
#define GIT_EOSERR (GIT_ERROR - 4)
|
#define GIT_EOSERR (GIT_ERROR - 4)
|
||||||
|
|
||||||
|
/** The specified object is of invalid type */
|
||||||
|
#define GIT_EOBJTYPE (GIT_ERROR - 5)
|
||||||
|
|
||||||
|
/** The specified object has its data corrupted */
|
||||||
|
#define GIT_EOBJCORRUPTED (GIT_ERROR - 6)
|
||||||
|
|
||||||
GIT_BEGIN_DECL
|
GIT_BEGIN_DECL
|
||||||
|
|
||||||
/** A revision traversal pool. */
|
/** A revision traversal pool. */
|
||||||
|
@ -67,14 +67,14 @@ GIT_EXTERN(void) gitrp_reset(git_revpool *pool);
|
|||||||
* @param pool the pool being used for the traversal.
|
* @param pool the pool being used for the traversal.
|
||||||
* @param commit the commit to start from.
|
* @param commit the commit to start from.
|
||||||
*/
|
*/
|
||||||
GIT_EXTERN(void) gitrp_push(git_revpool *pool, git_commit *commit);
|
GIT_EXTERN(int) gitrp_push(git_revpool *pool, git_commit *commit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark a commit (and its ancestors) uninteresting for the output.
|
* Mark a commit (and its ancestors) uninteresting for the output.
|
||||||
* @param pool the pool being used for the traversal.
|
* @param pool the pool being used for the traversal.
|
||||||
* @param commit the commit that will be ignored during the traversal
|
* @param commit the commit that will be ignored during the traversal
|
||||||
*/
|
*/
|
||||||
GIT_EXTERN(void) gitrp_hide(git_revpool *pool, git_commit *commit);
|
GIT_EXTERN(int) gitrp_hide(git_revpool *pool, git_commit *commit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the next commit from the revision traversal.
|
* Get the next commit from the revision traversal.
|
||||||
|
@ -62,17 +62,17 @@ void gitrp_sorting(git_revpool *pool, unsigned int sort_mode)
|
|||||||
gitrp_reset(pool);
|
gitrp_reset(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gitrp_push(git_revpool *pool, git_commit *commit)
|
int gitrp_push(git_revpool *pool, git_commit *commit)
|
||||||
{
|
{
|
||||||
if (commit == NULL || commit->seen)
|
if (commit == NULL || commit->seen)
|
||||||
return;
|
return GIT_ENOTFOUND;
|
||||||
|
|
||||||
if (commit->object.pool != pool || pool->walking)
|
if (commit->object.pool != pool || pool->walking)
|
||||||
return;
|
return GIT_ERROR;
|
||||||
|
|
||||||
if (!commit->parsed) {
|
if (!commit->parsed) {
|
||||||
if (git_commit_parse_existing(commit) < 0)
|
if (git_commit_parse_existing(commit) < 0)
|
||||||
return;
|
return GIT_EOBJCORRUPTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sanity check: make sure that if the commit
|
// Sanity check: make sure that if the commit
|
||||||
@ -81,36 +81,48 @@ void gitrp_push(git_revpool *pool, git_commit *commit)
|
|||||||
if (commit->uninteresting)
|
if (commit->uninteresting)
|
||||||
git_commit__mark_uninteresting(commit);
|
git_commit__mark_uninteresting(commit);
|
||||||
|
|
||||||
git_commit_list_push_back(&pool->roots, commit);
|
if (git_commit_list_push_back(&pool->roots, commit) < 0)
|
||||||
|
return GIT_ENOMEM;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gitrp_hide(git_revpool *pool, git_commit *commit)
|
int gitrp_hide(git_revpool *pool, git_commit *commit)
|
||||||
{
|
{
|
||||||
if (pool->walking)
|
if (pool->walking)
|
||||||
return;
|
return GIT_ERROR;
|
||||||
|
|
||||||
git_commit__mark_uninteresting(commit);
|
git_commit__mark_uninteresting(commit);
|
||||||
gitrp_push(pool, commit);
|
return gitrp_push(pool, commit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gitrp__enroot(git_revpool *pool, git_commit *commit)
|
int gitrp__enroot(git_revpool *pool, git_commit *commit)
|
||||||
{
|
{
|
||||||
|
int error;
|
||||||
git_commit_node *parents;
|
git_commit_node *parents;
|
||||||
|
|
||||||
if (commit->seen)
|
if (commit->seen)
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
if (commit->parsed == 0)
|
if (commit->parsed == 0) {
|
||||||
git_commit_parse_existing(commit);
|
if (git_commit_parse_existing(commit))
|
||||||
|
return GIT_EOBJCORRUPTED;
|
||||||
|
}
|
||||||
|
|
||||||
commit->seen = 1;
|
commit->seen = 1;
|
||||||
|
|
||||||
for (parents = commit->parents.head; parents != NULL; parents = parents->next) {
|
for (parents = commit->parents.head; parents != NULL; parents = parents->next) {
|
||||||
parents->commit->in_degree++;
|
parents->commit->in_degree++;
|
||||||
gitrp__enroot(pool, parents->commit);
|
|
||||||
|
error = gitrp__enroot(pool, parents->commit);
|
||||||
|
if (error < 0)
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
git_commit_list_push_back(&pool->iterator, commit);
|
if (git_commit_list_push_back(&pool->iterator, commit))
|
||||||
|
return GIT_ENOMEM;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gitrp__prepare_walk(git_revpool *pool)
|
void gitrp__prepare_walk(git_revpool *pool)
|
||||||
|
@ -18,6 +18,6 @@ struct git_revpool {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void gitrp__prepare_walk(git_revpool *pool);
|
void gitrp__prepare_walk(git_revpool *pool);
|
||||||
void gitrp__enroot(git_revpool *pool, git_commit *commit);
|
int gitrp__enroot(git_revpool *pool, git_commit *commit);
|
||||||
|
|
||||||
#endif /* INCLUDE_revwalk_h__ */
|
#endif /* INCLUDE_revwalk_h__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user