|
3 | 3 |
|
4 | 4 | #include "libgit2/include/git2.h" |
5 | 5 |
|
| 6 | +// doh ~stub |
| 7 | +void get_master_hex(char *hex) { |
| 8 | + FILE *f = fopen(".git/refs/heads/master", "r"); |
| 9 | + fgets(hex, 41, f); |
| 10 | + fclose(f); |
| 11 | +} |
| 12 | + |
6 | 13 | int main (int argc, char** argv) { |
| 14 | + /* |
| 15 | + if (argc != 2) { |
| 16 | + printf("Usage: git2 rev-list <commit>\n"); |
| 17 | + exit(1); |
| 18 | + } |
| 19 | +
|
| 20 | + if (strcmp(argv[1], "rev-list") != 0) { |
| 21 | + printf("Not implemented!\n"); |
| 22 | + exit(1); |
| 23 | + } |
| 24 | + */ |
| 25 | + int bac = 5; |
| 26 | + printf("Motiejus: %d, %X\n", bac, &bac); |
7 | 27 |
|
8 | 28 | git_repository *repo; |
9 | 29 | git_repository_open(&repo, "."); |
| 30 | + char *hex = (char*)malloc(41*sizeof(char)); |
| 31 | + get_master_hex(hex); // do not look what's inside |
| 32 | + |
| 33 | + // Start rev-list code // |
| 34 | + |
| 35 | + git_oid id; |
| 36 | + git_revwalk *walk; |
| 37 | + git_commit *head; |
| 38 | + git_commit *commit; |
| 39 | + |
| 40 | + git_oid_mkstr(&id, hex); |
| 41 | + git_commit_lookup(&head, repo, &id); |
| 42 | + |
| 43 | + git_revwalk_new(&walk, repo); |
| 44 | + git_revwalk_sorting(walk, GIT_SORT_TOPOLOGICAL | GIT_SORT_REVERSE); |
| 45 | + git_revwalk_push(walk, &id); |
10 | 46 |
|
11 | | - printf("I've been loaded!\n"); |
| 47 | + git_signature *author; |
| 48 | + while ((commit = git_revwalk_next(&id, walk)) != NULL) { |
| 49 | + char * msg = git_commit_message_short(commit); |
| 50 | + author = git_commit_author(commit); |
| 51 | + printf("%s (%s)\n", msg, author->email); |
| 52 | + } |
12 | 53 | return 0; |
13 | 54 | } |
0 commit comments