From eb095435f338b97f305148e122d6e12fd81621ca Mon Sep 17 00:00:00 2001 From: Justin Love Date: Tue, 30 Nov 2010 21:28:39 -0600 Subject: add git_commit_parent to retrieve a parent by index --- src/commit.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/commit.c') diff --git a/src/commit.c b/src/commit.c index b8d9f8784..8af92bff2 100644 --- a/src/commit.c +++ b/src/commit.c @@ -272,6 +272,20 @@ unsigned int git_commit_parentcount(git_commit *commit) return count; } +git_commit * git_commit_parent(git_commit *commit, unsigned int n) +{ + git_commit_parents *parent; + + assert(commit); + CHECK_FULL_PARSE(); + + for (parent = commit->parents; parent != NULL && n > 0; parent = parent->next) { + n--; + } + + return parent ? parent->commit : NULL; +} + void git_commit_set_tree(git_commit *commit, git_tree *tree) { assert(commit && tree); -- cgit v1.2.1