From 5a51dd322d438845617c2d43b6481e5c4bbe3bf8 Mon Sep 17 00:00:00 2001 From: Galin Simeonov Date: Fri, 24 Sep 2021 21:13:13 +0300 Subject: learned how to iterate over commits --- volgit.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'volgit.c') diff --git a/volgit.c b/volgit.c index 76ae0d7..f279e55 100644 --- a/volgit.c +++ b/volgit.c @@ -1,21 +1,59 @@ #include #include +void print_commits(const git_reference *branch, git_repository *repo) +{ + const git_oid *id; + git_revwalk *walker; + git_oid current; + + git_revwalk_new(&walker,repo); + id=git_reference_target(branch); + git_revwalk_push(walker,id); + + while(!git_revwalk_next(¤t,walker)) + { + printf("%s\n",git_oid_tostr_s(¤t)); + } + + +} int main() { + const char *name; + git_branch_iterator *it; git_repository *repo; + git_reference *ref; + git_branch_t branch_type=GIT_BRANCH_LOCAL; + git_libgit2_init(); git_repository_open(&repo,"."); - git_branch_iterator_new(&it,repo,GIT_BRANCH_LOCAL); + git_branch_iterator_new(&it,repo,branch_type); + + + while(git_branch_next(&ref,&branch_type,it)==0) + { + git_branch_name(&name,ref); + if(name) + { + printf("------- %s -------\n",name); + print_commits(ref,repo); + printf("------------------\n"); + }else + { + printf("NULL\n"); + } + } git_repository_free(repo); git_branch_iterator_free(it); + git_libgit2_shutdown(); return 0; } -- cgit v1.2.3