Skip to content

Commit e7bbc89

Browse files
committed
Yay! Traversing!
1 parent c9b662c commit e7bbc89

File tree

2 files changed

+15
-34
lines changed

2 files changed

+15
-34
lines changed

Makefile

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

65
libgit2: libgit2.a
76

git2.c

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,12 @@ int main (int argc, char** argv) {
3333
printf("Error code: %d" , e);
3434
}
3535

36-
37-
38-
/*
39-
git_odb *odb;
40-
git_odb_object *obj;
41-
git_oid *oid;
42-
43-
unsigned char *data;
44-
const char *str_type;
45-
int error;
46-
47-
if ((e = git_odb_open(&odb, ".git/objects")) != 0) {
48-
printf ("Fail on odb open: %d\n", e);
49-
}
50-
if (&odb == NULL) {
51-
printf("odb is null!\n");
52-
}
53-
54-
//odb = git_repository_database(repo);
55-
git_oid_mkstr(&oid, "969b6084cbad1cb3f60443856b851340de30dc37");
56-
error = git_odb_read(&obj, odb, oid);
57-
*/
58-
5936
git_oid id;
6037
git_revwalk *walk;
6138
git_commit *head, *commit;
6239

6340
git_oid_mkstr(&id, hex);
64-
printf("Raw 20 bytes: [%s]\n", (&id)->id);
41+
//printf("Raw 20 bytes: [%s]\n", (&id)->id);
6542

6643
git_odb *odb; // fetch the object!
6744
odb = git_repository_database(repo);
@@ -73,16 +50,21 @@ int main (int argc, char** argv) {
7350
char *msg = git_commit_message(head);
7451
printf("Commit message: %s\n", msg); // YAY!!!
7552

53+
if (e = git_revwalk_new(&walk, repo)) printf("Fail walker: %d\n", e);
54+
//git_revwalk_sorting(walk, GIT_SORT_TOPOLOGICAL | GIT_SORT_REVERSE);
55+
if (e = git_revwalk_push(walk, &id))
56+
printf("Failed revwalk push: %d\n", e);
57+
58+
int ret = git_revwalk_next(&id, walk);
59+
char *hex2 = (char*) malloc(41*sizeof(char));
7660

77-
if (e = git_revwalk_new(&walk, repo)) printf("Fail: %d\n");
78-
git_revwalk_sorting(walk, GIT_SORT_TOPOLOGICAL | GIT_SORT_REVERSE);
79-
git_revwalk_push(walk, &id);
61+
git_oid_fmt(hex2, &id);
62+
printf("Hex2: %40s\n", hex2);
8063

81-
git_signature *author;
82-
while ((commit = git_revwalk_next(&id, walk)) != NULL) {
83-
char * msg = git_commit_message_short(commit);
84-
author = git_commit_author(commit);
85-
printf("%s (%s)\n", msg, author->email);
64+
65+
while (git_revwalk_next(&id, walk) == GIT_SUCCESS) {
66+
git_oid_fmt(hex2, &id);
67+
printf("%s\n", hex2);
8668
}
8769
return 0;
8870
}

0 commit comments

Comments
 (0)