Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2012-07-11 18:14:12 +0400
committernulltoken <emeric.fermas@gmail.com>2012-07-12 03:06:11 +0400
commitb1aca6eae084ebe59c5a092314e94019c59ecec6 (patch)
tree3e8f251d9a98e23c30003a39e23741807b9bae04 /src/commit.c
parent2b92a154b66f213b664e44544048a2df7708b9de (diff)
commit: introduce git_commit_nth_gen_ancestor()
Diffstat (limited to 'src/commit.c')
-rw-r--r--src/commit.c34
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;
+}