Last active
December 14, 2015 23:18
-
-
Save nathan-osman/5164101 to your computer and use it in GitHub Desktop.
Walks through the commits in the specified Git repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <git2.h> | |
#include <stdio.h> | |
#define REPOSITORY_DIR "Repository" | |
void print_error() | |
{ | |
const git_error * last_error = giterr_last(); | |
printf("Error: %s\n", last_error->message); | |
} | |
int main (int argc, char ** argv) | |
{ | |
git_repository * repo = NULL; | |
git_revwalk * revwalk = NULL; | |
git_oid oid; | |
if(git_repository_open(&repo, REPOSITORY_DIR) || | |
git_revwalk_new(&revwalk, repo) || | |
git_revwalk_push_head(revwalk)) | |
goto error; | |
while(!git_revwalk_next(&oid, revwalk)) | |
{ | |
git_commit * commit; | |
if(!git_commit_lookup(&commit, repo, &oid)) | |
{ | |
printf("- %s", git_commit_message(commit)); | |
git_commit_free(commit); | |
} | |
else | |
printf("** Error looking up commit **\n"); | |
} | |
goto done; | |
error: | |
print_error(); | |
done: | |
if(revwalk) git_revwalk_free(revwalk); | |
if(repo) git_repository_free(repo); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CC=gcc | |
git2-walk: git2-walk.o | |
$(CC) git2-walk.o -lgit2 -o git2-walk | |
git2-walk.o: git2-walk.c | |
$(CC) -c git2-walk.c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment