diff options
author | Galin Simeonov <gts@volconst.com> | 2021-09-25 23:15:21 +0300 |
---|---|---|
committer | Galin Simeonov <gts@volconst.com> | 2021-09-25 23:15:21 +0300 |
commit | 7211f9c57204dc3b27327fc92352d99ad080a8db (patch) | |
tree | b154155aa4aa1c24817fcd062db3679767568845 /git_part.c | |
parent | 9868bd4ae045aadeb5cd9af6a13231462948077e (diff) | |
download | volgit-7211f9c57204dc3b27327fc92352d99ad080a8db.tar.gz |
made it create a directory with files containing the output of the program
Diffstat (limited to 'git_part.c')
-rw-r--r-- | git_part.c | 47 |
1 files changed, 30 insertions, 17 deletions
@@ -2,16 +2,16 @@ #define VOLGIT_GIT_PART_C VOLGIT_GIT_PART_C #include <git_part.h> -int print_diff_line(const git_diff_delta *delta,const git_diff_hunk *hunk,const git_diff_line *line,void *payload) +int print_diff_line(const git_diff_delta *delta,const git_diff_hunk *hunk,const git_diff_line *line,FILE *out) { size_t i; - printf("%c ",line->origin); + fprintf(out,"%c ",line->origin); for(i=0;i<line->content_len;++i) - printf("%c",line->content[i]); + fprintf(out,"%c",line->content[i]); return 0; } -void print_diff(git_tree *parent_tree,git_tree *current_tree,git_repository *repo) +void print_diff(FILE *out,git_tree *parent_tree,git_tree *current_tree,git_repository *repo) { git_diff *diff_from_parent; size_t number_of_deltas=0; @@ -19,28 +19,32 @@ void print_diff(git_tree *parent_tree,git_tree *current_tree,git_repository *rep 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); + git_diff_print(diff_from_parent,GIT_DIFF_FORMAT_PATCH_ID,(git_diff_line_cb)print_diff_line,out); if(diff_from_parent) git_diff_free(diff_from_parent); } -void print_headers_and_commit_message(git_commit *current_commit,git_oid *current) +void print_headers_and_commit_message(FILE *where,git_commit *current_commit,git_oid *current) { const git_signature *who_commited; - printf("COMMIT: %s\n",git_oid_tostr_s(current)); + fprintf(where,"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); + fprintf(where,"AUTHOR: %s <%s>\n",who_commited->name,who_commited->email); - printf("DATE: %s\n",ctime(&who_commited->when.time)); + fprintf(where,"DATE: %s\n",ctime(&who_commited->when.time)); - printf("\t%s\n",git_commit_message(current_commit)); + fprintf(where,"\t%s\n",git_commit_message(current_commit)); } -void print_commits(const git_reference *branch, git_repository *repo) +void print_commits(int dir_fd,const git_reference *branch, git_repository *repo) { const git_oid *id; + FILE *log_file; + FILE *diff_file; + int diff_directory_fd; + git_revwalk *walker; git_oid current; git_commit *current_commit; @@ -51,6 +55,10 @@ void print_commits(const git_reference *branch, git_repository *repo) git_revwalk_new(&walker,repo); id=git_reference_target(branch); git_revwalk_push(walker,id); + + + log_file=create_file(dir_fd,"log"); + diff_directory_fd=create_diff_dir(dir_fd); while(!git_revwalk_next(¤t,walker)) { @@ -58,22 +66,25 @@ void print_commits(const git_reference *branch, git_repository *repo) git_commit_tree(¤t_tree,current_commit); if(parent_tree!=NULL) { - print_diff(parent_tree,current_tree,repo); + diff_file=create_file(diff_directory_fd,git_oid_tostr_s(¤t)); + print_diff(diff_file,parent_tree,current_tree,repo); git_tree_free(parent_tree); } - print_headers_and_commit_message(current_commit,¤t); + print_headers_and_commit_message(log_file,current_commit,¤t); parent_tree=current_tree; git_commit_free(current_commit); } - + git_revwalk_free(walker); + fclose(log_file); } void print_branches(git_repository *repo) { const char *branch_name; + int branch_dir_fd; git_branch_iterator *it; git_reference *ref; git_branch_t branch_type=GIT_BRANCH_LOCAL; @@ -84,9 +95,11 @@ void print_branches(git_repository *repo) git_branch_name(&branch_name,ref); if(branch_name) { - printf("------- %s -------\n",branch_name); - print_commits(ref,repo); - printf("------------------\n"); + branch_dir_fd=create_branch_dir(branch_name); + + print_commits(branch_dir_fd,ref,repo); + + close(branch_dir_fd); }else { printf("NULL\n"); |