1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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(¤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,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;
}
|