summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGalin Simeonov <gts@volconst.com>2021-09-25 11:43:15 +0300
committerGalin Simeonov <gts@volconst.com>2021-09-25 11:43:15 +0300
commit9868bd4ae045aadeb5cd9af6a13231462948077e (patch)
tree14f48c77bf0a0a93ff311079502f05bcc3593324
parent4e7e1184d5b8b1d067134e7c7459f1c610ac55e6 (diff)
downloadvolgit-9868bd4ae045aadeb5cd9af6a13231462948077e.tar.gz
separating git stuff into a different file
-rw-r--r--.volgit.c.swpbin12288 -> 0 bytes
-rw-r--r--CMakeLists.txt14
-rw-r--r--git_part.c98
-rw-r--r--git_part.h13
-rw-r--r--makefile8
-rw-r--r--volgit.c100
6 files changed, 133 insertions, 100 deletions
diff --git a/.volgit.c.swp b/.volgit.c.swp
deleted file mode 100644
index 8e92964..0000000
--- a/.volgit.c.swp
+++ /dev/null
Binary files differ
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..a2b6a1c
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,14 @@
+cmake_minimum_required (VERSION 3.13.4)
+project (VOLGIT)
+if( NOT CMAKE_BUILD_TYPE)
+ set(CMAKE_BUILD_TYPE "Debug")
+endif( NOT CMAKE_BUILD_TYPE)
+include_directories(${CMAKE_SOURCE_DIR})
+set(SOURCES
+ git_part.c
+ volgit.c
+ )
+
+
+add_executable(volgit ${SOURCES})
+target_link_libraries(volgit git2)
diff --git a/git_part.c b/git_part.c
new file mode 100644
index 0000000..6d91717
--- /dev/null
+++ b/git_part.c
@@ -0,0 +1,98 @@
+#ifndef VOLGIT_GIT_PART_C
+#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)
+{
+ size_t i;
+ printf("%c ",line->origin);
+ for(i=0;i<line->content_len;++i)
+ printf("%c",line->content[i]);
+ 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);
+ git_revwalk_push(walker,id);
+
+ while(!git_revwalk_next(&current,walker))
+ {
+ git_commit_lookup(&current_commit,repo,&current);
+ git_commit_tree(&current_tree,current_commit);
+ if(parent_tree!=NULL)
+ {
+ print_diff(parent_tree,current_tree,repo);
+ git_tree_free(parent_tree);
+ }
+
+ print_headers_and_commit_message(current_commit,&current);
+
+ parent_tree=current_tree;
+ git_commit_free(current_commit);
+ }
+
+
+}
+
+void print_branches(git_repository *repo)
+{
+ const char *branch_name;
+ git_branch_iterator *it;
+ git_reference *ref;
+ git_branch_t branch_type=GIT_BRANCH_LOCAL;
+
+ git_branch_iterator_new(&it,repo,branch_type);
+ while(git_branch_next(&ref,&branch_type,it)==0)
+ {
+ git_branch_name(&branch_name,ref);
+ if(branch_name)
+ {
+ printf("------- %s -------\n",branch_name);
+ print_commits(ref,repo);
+ printf("------------------\n");
+ }else
+ {
+ printf("NULL\n");
+ }
+ }
+
+ git_branch_iterator_free(it);
+}
+#endif
diff --git a/git_part.h b/git_part.h
new file mode 100644
index 0000000..9f39423
--- /dev/null
+++ b/git_part.h
@@ -0,0 +1,13 @@
+#ifndef VOLGIT_GIT_PART_H
+#define VOLGIT_GIT_PART_H VOLGIT_GIT_PART_H
+#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);
+void print_diff(git_tree *parent_tree,git_tree *current_tree,git_repository *repo);
+void print_headers_and_commit_message(git_commit *current_commit,git_oid *current);
+void print_commits(const git_reference *branch, git_repository *repo);
+
+void print_branches(git_repository *repo);
+
+#endif
diff --git a/makefile b/makefile
deleted file mode 100644
index 3117c76..0000000
--- a/makefile
+++ /dev/null
@@ -1,8 +0,0 @@
-volgit: volgit.o
- c99 -g volgit.o -lgit2 -o volgit
-
-volgit.o: volgit.c
- c99 -g -c volgit.c -o volgit.o
-
-clean:
- rm -rf volgit.o volgit
diff --git a/volgit.c b/volgit.c
index 27b96fb..dc391e7 100644
--- a/volgit.c
+++ b/volgit.c
@@ -1,109 +1,25 @@
#include <stdio.h>
#include <git2.h>
+#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 main(int argc,char **argv)
{
- 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;
+ const char *repo_path;
- 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);
- git_revwalk_push(walker,id);
-
- while(!git_revwalk_next(&current,walker))
+ if(argc<=1)
{
- git_commit_lookup(&current_commit,repo,&current);
- git_commit_tree(&current_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,&current);
-
- parent_tree=current_tree;
- git_commit_free(current_commit);
+ fprintf(stderr,"You need to specify a source dir for the repo\n");
+ return 1;
}
-
-}
-
-int main()
-{
- const char *name;
-
- git_branch_iterator *it;
git_repository *repo;
- git_reference *ref;
- git_branch_t branch_type=GIT_BRANCH_LOCAL;
-
git_libgit2_init();
- git_repository_open(&repo,".");
- git_branch_iterator_new(&it,repo,branch_type);
-
-
- while(git_branch_next(&ref,&branch_type,it)==0)
- {
- git_branch_name(&name,ref);
- if(name)
- {
- printf("------- %s -------\n",name);
- print_commits(ref,repo);
- printf("------------------\n");
- }else
- {
- printf("NULL\n");
- }
- }
-
-
+ git_repository_open(&repo,argv[1]);
+ print_branches(repo);
git_repository_free(repo);
- git_branch_iterator_free(it);
git_libgit2_shutdown();
return 0;