|
2 | 2 | #include "git2.h"
|
3 | 3 |
|
4 | 4 | int main() {
|
5 |
| -git_libgit2_init(); |
6 |
| - |
7 |
| -git_repository *repo = NULL; |
8 |
| -git_repository_init(&repo, "/tmp/v", 0); |
9 |
| - |
10 |
| -git_oid oid; |
11 |
| -git_reference_name_to_id(&oid, repo, "HEAD"); |
12 |
| - |
13 |
| -git_commit *commit = NULL; |
14 |
| -git_commit_lookup(&commit, repo, &oid); |
15 |
| - |
16 |
| -git_revwalk *walker = NULL; |
17 |
| -git_revwalk_new(&walker, repo); |
18 |
| -git_revwalk_push(walker, &oid); |
19 |
| - |
20 |
| -git_oid current_oid; |
21 |
| -int i = 0; |
22 |
| -while (git_revwalk_next(¤t_oid, walker) == 0) { |
23 |
| - i++; |
24 |
| - if (i > 10) {break;} |
25 |
| -git_commit_lookup(&commit, repo, ¤t_oid); |
26 |
| -const git_signature *author = git_commit_author(commit); |
27 |
| - |
28 |
| -printf("Commit ID: %s\n", git_oid_tostr_s(¤t_oid)); |
29 |
| -printf("Author: %s <%s>\n", author->name, author->email); |
30 |
| -printf("Message: %s\n\n", git_commit_message(commit)); |
31 |
| -} |
32 |
| - |
33 |
| -git_revwalk_free(walker); |
34 |
| -git_commit_free(commit); |
35 |
| -git_repository_free(repo); |
36 |
| -git_libgit2_shutdown(); |
37 |
| - |
38 |
| -return 0; |
| 5 | + git_libgit2_init(); |
| 6 | + |
| 7 | + git_repository *repo = NULL; |
| 8 | + git_repository_init(&repo, "/tmp/v", 0); |
| 9 | + |
| 10 | + git_oid oid; |
| 11 | + git_reference_name_to_id(&oid, repo, "HEAD"); |
| 12 | + |
| 13 | + git_commit *commit = NULL; |
| 14 | + git_commit_lookup(&commit, repo, &oid); |
| 15 | + |
| 16 | + git_revwalk *walker = NULL; |
| 17 | + git_revwalk_new(&walker, repo); |
| 18 | + git_revwalk_push(walker, &oid); |
| 19 | + |
| 20 | + git_oid current_oid; |
| 21 | + int i = 0; |
| 22 | + while (git_revwalk_next(¤t_oid, walker) == 0) { |
| 23 | + i++; |
| 24 | + if (i > 10) {break;} |
| 25 | + git_commit_lookup(&commit, repo, ¤t_oid); |
| 26 | + const git_signature *author = git_commit_author(commit); |
| 27 | + printf("Commit ID: %s\n", git_oid_tostr_s(¤t_oid)); |
| 28 | + printf("Author: %s <%s>\n", author->name, author->email); |
| 29 | + printf("Message: %s\n\n", git_commit_message(commit)); |
| 30 | + } |
| 31 | + |
| 32 | + git_revwalk_free(walker); |
| 33 | + git_commit_free(commit); |
| 34 | + git_repository_free(repo); |
| 35 | + git_libgit2_shutdown(); |
| 36 | + |
| 37 | + return 0; |
39 | 38 | }
|
0 commit comments