F diff --git a/.exrc b/.exrc
new file mode 100644
--- /dev/null
+++ b/.exrc
+ if &cp | set nocp | endif
+ nmap :
+ let s:cpo_save=&cpo
+ set cpo&vim
+ vmap gx <Plug>NetrwBrowseXVis
+ nmap gx <Plug>NetrwBrowseX
+ vnoremap <silent> <Plug>NetrwBrowseXVis :call netrw#BrowseXVis()
+ nnoremap <silent> <Plug>NetrwBrowseX :call netrw#BrowseX(netrw#GX(),netrw#CheckIfRemote(netrw#GX()))
+ nmap <Left> h
+ nmap <Right> l
+ nmap <Down> j
+ nmap <Up> k
+ nmap <F1> :echo "F1 - print function key keybinds (normal mode) \nF2 - !t \nF5 - make \nF6 - make clean \nF7 - set make directory \nF9 - git status \nF10 - git diff"<NL>
+ nmap <F7> :set makeprg=make\ -C
+ nmap <F6> :make clean<NL>
+ nmap <F5> :wa<NL>:make -j4<NL>
+ nmap <F10> :!git diff<NL>
+ nmap <F9> :!git status<NL>
+ nmap <F2> :!t<NL>
+ let &cpo=s:cpo_save
+ unlet s:cpo_save
+ set background=dark
+ set backspace=indent,eol,start
+ set cindent
+ set fileencodings=ucs-bom,utf-8,default,latin1
+ set helplang=en
+ set makeprg=make\ -C/tmp/a
+ set nomodeline
+ set mouse=a
+ set omnifunc=syntaxcomplete
+ set printoptions=paper:letter
+ set ruler
+ set showtabline=0
+ set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc
+ set tabline=%{g:tabline}
+ set tagcase=ignore
+ " vim: set ft=vim :
F diff --git a/git_part.c b/git_part.c
--- a/git_part.c
+++ b/git_part.c
FILE *log_file;
FILE *diff_file;
int diff_directory_fd;
+ int files_directory_fd;
git_revwalk *walker;
git_oid current;
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(¤t,walker))
{
git_commit_lookup(¤t_commit,repo,¤t);
git_commit_tree(¤t_tree,current_commit);
+
if(parent_tree!=NULL)
{
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);
+ }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,¤t);
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
F diff --git a/git_part.h b/git_part.h
--- a/git_part.h
+++ b/git_part.h
#include <git2.h>
#include <system_part.h>
+
+ struct Print_Files_Context
+ {
+ int base_dir_fd;
+ git_repository *repo;
+ };
+
int print_diff_line(const git_diff_delta *delta,const git_diff_hunk *hunk,const git_diff_line *line,FILE *out);
void print_diff(FILE *out,git_tree *parent_tree,git_tree *current_tree,git_repository *repo);
void print_headers_and_commit_message(FILE* where,git_commit *current_commit,git_oid *current);
void print_commits(int dir_fd,const git_reference *branch, git_repository *repo);
+ void print_files(int dir_fd,git_tree *tree,git_repository *repo);
+ int print_entry(const git_tree_entry *entry,int base_dir_fd,git_repository *repo);
void print_branches(git_repository *repo);
F diff --git a/system_part.c b/system_part.c
--- a/system_part.c
+++ b/system_part.c
die("Could not open the file '%s' for one of the branches\n",filename);
return fdopen(fd,"w");
}
- int create_files_dir(int branch_dir)
+ int create_dir(int base_dir,const char *dir_name)
{
int ret;
-
- ret=openat(branch_dir,"files",O_DIRECTORY|O_RDONLY);
+ ret=openat(base_dir,dir_name,O_DIRECTORY|O_RDONLY);
if(ret!=-1)
return ret;
- ret=mkdirat(branch_dir,"files",0770);
+ mkdirat(base_dir,dir_name,0770);
+ ret=openat(base_dir,dir_name,O_DIRECTORY|O_RDONLY);
if(ret==-1)
die("Could not create the 'files' subdirectory of one of the branch dirs\n");
return ret;
}
- int create_diff_dir(int branch_dir)
- {
- int ret;
-
- ret=openat(branch_dir,"diffs",O_DIRECTORY|O_RDONLY);
- if(ret!=-1)
- return ret;
- mkdirat(branch_dir,"diffs",0770);
- ret=openat(branch_dir,"diffs",O_DIRECTORY|O_RDONLY);
- if(ret==-1)
- die("Could not create the 'diffs' subdirectory of one of the branch dirs\n");
- return ret;
- }
void die(const char *format, ...)
{
F diff --git a/system_part.h b/system_part.h
--- a/system_part.h
+++ b/system_part.h
char* read_file(const char *filename);
int create_branch_dir(const char *branch_name);
FILE* create_file(int branch_dir,const char *filename);
- int create_files_dir(int branch_dir);
- int create_diff_dir(int branch_dir);
+ int create_dir(int base_dir,const char *dir_name);
#endif