mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-29 06:20:56 +00:00
add git_commit_parentcount
This commit is contained in:
parent
8c1f9e4dc3
commit
12114415ab
15
src/commit.c
15
src/commit.c
@ -257,6 +257,21 @@ time_t git_commit_time(git_commit *commit)
|
|||||||
return commit->commit_time;
|
return commit->commit_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int git_commit_parentcount(git_commit *commit)
|
||||||
|
{
|
||||||
|
git_commit_parents *parent;
|
||||||
|
unsigned int count = 0;
|
||||||
|
|
||||||
|
assert(commit);
|
||||||
|
CHECK_FULL_PARSE();
|
||||||
|
|
||||||
|
for (parent = commit->parents; parent != NULL; parent = parent->next) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
void git_commit_set_tree(git_commit *commit, git_tree *tree)
|
void git_commit_set_tree(git_commit *commit, git_tree *tree)
|
||||||
{
|
{
|
||||||
assert(commit && tree);
|
assert(commit && tree);
|
||||||
|
@ -93,6 +93,14 @@ GIT_EXTERN(const git_person *) git_commit_author(git_commit *commit);
|
|||||||
*/
|
*/
|
||||||
GIT_EXTERN(const git_tree *) git_commit_tree(git_commit *commit);
|
GIT_EXTERN(const git_tree *) git_commit_tree(git_commit *commit);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of parents of this commit
|
||||||
|
*
|
||||||
|
* @param commit a previously loaded commit.
|
||||||
|
* @return integer of count of parents
|
||||||
|
*/
|
||||||
|
GIT_EXTERN(unsigned int) git_commit_parentcount(git_commit *commit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new parent commit to an existing commit
|
* Add a new parent commit to an existing commit
|
||||||
* @param commit the commit object
|
* @param commit the commit object
|
||||||
|
@ -31,6 +31,7 @@ BEGIN_TEST(query_details_test)
|
|||||||
const git_person *author, *committer;
|
const git_person *author, *committer;
|
||||||
const char *message, *message_short;
|
const char *message, *message_short;
|
||||||
time_t commit_time;
|
time_t commit_time;
|
||||||
|
unsigned int parents;
|
||||||
|
|
||||||
git_oid_mkstr(&id, commit_ids[i]);
|
git_oid_mkstr(&id, commit_ids[i]);
|
||||||
|
|
||||||
@ -41,6 +42,7 @@ BEGIN_TEST(query_details_test)
|
|||||||
author = git_commit_author(commit);
|
author = git_commit_author(commit);
|
||||||
committer = git_commit_committer(commit);
|
committer = git_commit_committer(commit);
|
||||||
commit_time = git_commit_time(commit);
|
commit_time = git_commit_time(commit);
|
||||||
|
parents = git_commit_parentcount(commit);
|
||||||
|
|
||||||
must_be_true(strcmp(author->name, "Scott Chacon") == 0);
|
must_be_true(strcmp(author->name, "Scott Chacon") == 0);
|
||||||
must_be_true(strcmp(author->email, "schacon@gmail.com") == 0);
|
must_be_true(strcmp(author->email, "schacon@gmail.com") == 0);
|
||||||
@ -49,6 +51,7 @@ BEGIN_TEST(query_details_test)
|
|||||||
must_be_true(strchr(message, '\n') != NULL);
|
must_be_true(strchr(message, '\n') != NULL);
|
||||||
must_be_true(strchr(message_short, '\n') == NULL);
|
must_be_true(strchr(message_short, '\n') == NULL);
|
||||||
must_be_true(commit_time > 0);
|
must_be_true(commit_time > 0);
|
||||||
|
must_be_true(0 <= parents && parents <= 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
git_repository_free(repo);
|
git_repository_free(repo);
|
||||||
|
Loading…
Reference in New Issue
Block a user