summaryrefslogtreecommitdiffstats
path: root/git_part.c
diff options
context:
space:
mode:
Diffstat (limited to 'git_part.c')
-rw-r--r--git_part.c68
1 files changed, 67 insertions, 1 deletions
diff --git a/git_part.c b/git_part.c
index f3b0877..0467206 100644
--- a/git_part.c
+++ b/git_part.c
@@ -44,6 +44,7 @@ void print_commits(int dir_fd,const git_reference *branch, git_repository *repo)
FILE *log_file;
FILE *diff_file;
int diff_directory_fd;
+ int files_directory_fd;
git_revwalk *walker;
git_oid current;
@@ -58,17 +59,24 @@ void print_commits(int dir_fd,const git_reference *branch, git_repository *repo)
log_file=create_file(dir_fd,"log");
- diff_directory_fd=create_diff_dir(dir_fd);
+ diff_directory_fd=create_dir(dir_fd,"diffs");
+ files_directory_fd=create_dir(dir_fd,"files");
while(!git_revwalk_next(&current,walker))
{
git_commit_lookup(&current_commit,repo,&current);
git_commit_tree(&current_tree,current_commit);
+
if(parent_tree!=NULL)
{
diff_file=create_file(diff_directory_fd,git_oid_tostr_s(&current));
+
print_diff(diff_file,parent_tree,current_tree,repo);
+
git_tree_free(parent_tree);
+ }else/*we only print the files of the HEAD*/
+ {
+ print_files(files_directory_fd,current_tree,repo);
}
print_headers_and_commit_message(log_file,current_commit,&current);
@@ -108,4 +116,62 @@ void print_branches(git_repository *repo)
git_branch_iterator_free(it);
}
+void print_files(int dir_fd,git_tree *tree,git_repository *repo)
+{
+ size_t number_of_entries;
+ size_t i;
+ const git_tree_entry *current_entry;
+
+ number_of_entries=git_tree_entrycount(tree);
+
+ for(i=0;i<number_of_entries;++i)
+ {
+ current_entry=git_tree_entry_byindex(tree,i);
+ print_entry(current_entry,dir_fd,repo);
+ }
+}
+int print_entry(const git_tree_entry *entry,int base_dir_fd,git_repository *repo)
+{
+ git_object *obj;
+ const char *entry_name;
+
+ git_tree_entry_to_object(&obj,repo,entry);
+ entry_name=git_tree_entry_name(entry);
+
+ switch(git_object_type(obj))
+ {
+ case GIT_OBJECT_TREE:
+ {
+ int new_dir_fd;
+ git_tree *tree;
+
+ tree=(git_tree*)obj;
+
+ new_dir_fd=create_dir(base_dir_fd,entry_name);
+ print_files(new_dir_fd,tree,repo);
+ }
+ break;
+ case GIT_OBJECT_BLOB:
+ {
+ FILE *blob_file;
+ const void *blob_data;
+ size_t blob_size;
+ git_blob *blob;
+
+ blob=(git_blob*)obj;
+
+ blob_file=create_file(base_dir_fd,entry_name);
+ blob_size=git_blob_rawsize(blob);
+ blob_data=git_blob_rawcontent(blob);
+
+ fwrite(blob_data,blob_size,1,blob_file);
+
+ fclose(blob_file);
+ }
+ break;
+ }
+
+ git_object_free(obj);
+ return 0;
+}
#endif