diff options
author | Galin Simeonov <gts@volconst.com> | 2021-09-25 11:09:51 +0300 |
---|---|---|
committer | Galin Simeonov <gts@volconst.com> | 2021-09-25 11:09:51 +0300 |
commit | 4e7e1184d5b8b1d067134e7c7459f1c610ac55e6 (patch) | |
tree | ab42fad7572f86b8ba2c77bc2b4c0c9d37b8cd01 | |
parent | 5a51dd322d438845617c2d43b6481e5c4bbe3bf8 (diff) | |
download | volgit-4e7e1184d5b8b1d067134e7c7459f1c610ac55e6.tar.gz |
basic git-log functionality
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | .volgit.c.swp | bin | 0 -> 12288 bytes | |||
-rw-r--r-- | volgit.c | 53 |
3 files changed, 54 insertions, 1 deletions
@@ -1,3 +1,5 @@ *.o volgit .gdb_history +tags +cscope* diff --git a/.volgit.c.swp b/.volgit.c.swp Binary files differnew file mode 100644 index 0000000..8e92964 --- /dev/null +++ b/.volgit.c.swp @@ -1,11 +1,51 @@ #include <stdio.h> #include <git2.h> +int print_diff_line(const git_diff_delta *delta,const git_diff_hunk *hunk,const git_diff_line *line,void *payload) +{ + size_t i; + for(i=0;i<line->content_len;++i) + printf("%c",line->content[i]); + printf("\n"); + return 0; +} + +void print_diff(git_tree *parent_tree,git_tree *current_tree,git_repository *repo) +{ + git_diff *diff_from_parent; + size_t number_of_deltas=0; + size_t i; + + git_diff_tree_to_tree(&diff_from_parent,repo,current_tree,parent_tree,NULL); + + git_diff_print(diff_from_parent,GIT_DIFF_FORMAT_PATCH,print_diff_line,NULL); + + if(diff_from_parent) + git_diff_free(diff_from_parent); +} +void print_headers_and_commit_message(git_commit *current_commit,git_oid *current) +{ + const git_signature *who_commited; + printf("COMMIT: %s\n",git_oid_tostr_s(current)); + + who_commited=git_commit_committer(current_commit); + + printf("AUTHOR: %s <%s>\n",who_commited->name,who_commited->email); + + printf("DATE: %s\n",ctime(&who_commited->when.time)); + + + printf("\t%s\n",git_commit_message(current_commit)); +} void print_commits(const git_reference *branch, git_repository *repo) { const git_oid *id; git_revwalk *walker; git_oid current; + git_commit *current_commit; + git_time_t time_of_commit; + git_tree *parent_tree=NULL; + git_tree *current_tree; git_revwalk_new(&walker,repo); id=git_reference_target(branch); @@ -13,7 +53,18 @@ void print_commits(const git_reference *branch, git_repository *repo) while(!git_revwalk_next(¤t,walker)) { - printf("%s\n",git_oid_tostr_s(¤t)); + git_commit_lookup(¤t_commit,repo,¤t); + git_commit_tree(¤t_tree,current_commit); + if(parent_tree!=NULL) + { + print_diff(current_tree,parent_tree,repo); + git_tree_free(parent_tree); + } + + print_headers_and_commit_message(current_commit,¤t); + + parent_tree=current_tree; + git_commit_free(current_commit); } |