summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGalin Simeonov <gts@volconst.com>2021-09-24 21:13:13 +0300
committerGalin Simeonov <gts@volconst.com>2021-09-24 21:13:13 +0300
commit5a51dd322d438845617c2d43b6481e5c4bbe3bf8 (patch)
treeb9593aee5806db7d56fa37d66e617d037de3b82f
parent64bf27391629388db4fcde1ae5eb8c184471874f (diff)
downloadvolgit-5a51dd322d438845617c2d43b6481e5c4bbe3bf8.tar.gz
learned how to iterate over commits
-rw-r--r--.gitignore1
-rw-r--r--makefile4
-rw-r--r--volgit.c40
3 files changed, 42 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index 9ab4708..153002f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
*.o
volgit
+.gdb_history
diff --git a/makefile b/makefile
index 93ab295..3117c76 100644
--- a/makefile
+++ b/makefile
@@ -1,8 +1,8 @@
volgit: volgit.o
- c99 volgit.o -lgit2 -o volgit
+ c99 -g volgit.o -lgit2 -o volgit
volgit.o: volgit.c
- c99 -c volgit.c -o volgit.o
+ c99 -g -c volgit.c -o volgit.o
clean:
rm -rf volgit.o volgit
diff --git a/volgit.c b/volgit.c
index 76ae0d7..f279e55 100644
--- a/volgit.c
+++ b/volgit.c
@@ -1,21 +1,59 @@
#include <stdio.h>
#include <git2.h>
+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(&current,walker))
+ {
+ printf("%s\n",git_oid_tostr_s(&current));
+ }
+
+
+}
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;
}