Skip to content

Commit de8f026

Browse files
committed
Compile & segfault. Good night!
1 parent 969b608 commit de8f026

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
git2: git2.c libgit2.a
22
git2.c:
3+
#gcc -static src/git2.c -I. -L. -lgit2 -ogit2 -Wall -pedantic
34
gcc -static src/git2.c -I. -L. -lgit2 -ogit2
45

56
libgit2: libgit2.a

git2.c

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,52 @@
33

44
#include "libgit2/include/git2.h"
55

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+
613
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);
727

828
git_repository *repo;
929
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);
1046

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+
}
1253
return 0;
1354
}

0 commit comments

Comments
 (0)