diff options
author | nulltoken <emeric.fermas@gmail.com> | 2012-07-11 18:14:12 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2012-07-12 03:06:11 +0400 |
commit | b1aca6eae084ebe59c5a092314e94019c59ecec6 (patch) | |
tree | 3e8f251d9a98e23c30003a39e23741807b9bae04 /src/commit.c | |
parent | 2b92a154b66f213b664e44544048a2df7708b9de (diff) |
commit: introduce git_commit_nth_gen_ancestor()
Diffstat (limited to 'src/commit.c')
-rw-r--r-- | src/commit.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/commit.c b/src/commit.c index 5acbbc39b..32c47944b 100644 --- a/src/commit.c +++ b/src/commit.c @@ -255,3 +255,37 @@ int git_commit_parent(git_commit **parent, git_commit *commit, unsigned int n) return git_commit_lookup(parent, commit->object.repo, parent_oid); } + +int git_commit_nth_gen_ancestor( + git_commit **ancestor, + const git_commit *commit, + unsigned int n) +{ + git_commit *current, *parent; + int error; + + assert(ancestor && commit); + + current = (git_commit *)commit; + + if (n == 0) + return git_commit_lookup( + ancestor, + commit->object.repo, + git_object_id((const git_object *)commit)); + + while (n--) { + error = git_commit_parent(&parent, (git_commit *)current, 0); + + if (current != commit) + git_commit_free(current); + + if (error < 0) + return error; + + current = parent; + } + + *ancestor = parent; + return 0; +} |