OSDN Git Service

GitDLL log basic work.
authorFrank Li <lznuaa@gmail.com>
Tue, 29 Dec 2009 14:14:21 +0000 (22:14 +0800)
committerFrank Li <lznuaa@gmail.com>
Tue, 29 Dec 2009 14:14:21 +0000 (22:14 +0800)
Signed-off-by: Frank Li <lznuaa@gmail.com>
ext/gitdll/gitdll.c
ext/gitdll/gitdll.h
ext/gitdll/gitdll.vcproj
ext/gitdlltest/gitdlltest.cpp
ext/gitdlltest/gitdlltest.vcproj
ext/tgit

index 4ef95d4..83834cf 100644 (file)
@@ -2,9 +2,16 @@
 //\r
 \r
 #include "stdafx.h"\r
+#include "git-compat-util.h"\r
+#include "msvc.h"\r
 #include "gitdll.h"\r
 #include "cache.h"\r
 #include "commit.h"\r
+#include "diff.h"\r
+#include "revision.h"\r
+\r
+const char git_version_string[] = GIT_VERSION;\r
+\r
 #if 0\r
 \r
 // This is an example of an exported variable\r
@@ -26,6 +33,7 @@ Cgitdll::Cgitdll()
 \r
 #define MAX_ERROR_STR_SIZE 512\r
 char g_last_error[MAX_ERROR_STR_SIZE]={0};\r
+void * g_prefix;\r
 \r
 char * get_git_last_error()\r
 {\r
@@ -77,7 +85,7 @@ int git_init()
        convert_slash(path);\r
 \r
        git_extract_argv0_path(path);\r
-       prefix = setup_git_directory();\r
+       g_prefix = prefix = setup_git_directory();\r
        return git_config(git_default_config, NULL);\r
 }\r
 \r
@@ -114,7 +122,7 @@ static int git_parse_commit_author(struct GIT_COMMIT_AUTHOR *author, char *pbuff
        return 0;\r
 }\r
 \r
-static int git_parse_commit(GIT_COMMIT *commit)\r
+int git_parse_commit(GIT_COMMIT *commit)\r
 {\r
        int ret = 0;\r
        char *pbuf;\r
@@ -176,7 +184,7 @@ int git_get_commit_from_hash(GIT_COMMIT *commit, GIT_HASH hash)
 {\r
        int ret = 0;\r
        \r
-       struct commit *p = (struct commit*)commit;\r
+       struct commit *p;\r
        commit->m_pGitCommit = p = lookup_commit(hash);\r
 \r
        if(commit == NULL)\r
@@ -192,3 +200,128 @@ int git_get_commit_from_hash(GIT_COMMIT *commit, GIT_HASH hash)
        return git_parse_commit(commit);\r
 }\r
 \r
+int git_free_commit(GIT_COMMIT *commit)\r
+{\r
+       struct commit *p = commit->m_pGitCommit;\r
+\r
+       if( p->parents)\r
+               free_commit_list(p->parents);   \r
+\r
+       if( p->buffer )\r
+       {\r
+               free(p->buffer);\r
+       }\r
+       memset(commit,0,sizeof(GIT_COMMIT));\r
+       return 0;\r
+}\r
+\r
+int git_get_diff(GIT_COMMIT *commit, GIT_DIFF *diff)\r
+{\r
+\r
+}\r
+\r
+char **strtoargv(char *arg, int *size)\r
+{\r
+       int count=0;\r
+       char *p=arg;\r
+       char **argv;\r
+       int i=0;\r
+       while(*p)\r
+       {\r
+               if(*p == ' ')\r
+                       count ++;\r
+               p++;\r
+       }\r
+       \r
+       argv=malloc(strlen(arg)+1 + (count +2)*sizeof(void*));\r
+       p=(char*)(argv+count+2);\r
+\r
+       while(*arg)\r
+       {\r
+               if(*arg == '"')\r
+               {\r
+                       argv[i] = p;\r
+                       arg++;\r
+                       *p=*arg;\r
+                       while(*arg && *arg!= '"')\r
+                               *p++=*arg++;\r
+                       *p++=0;\r
+                       arg++;\r
+                       i++;\r
+                       if(*arg == 0)\r
+                               break;\r
+               }\r
+               if(*arg != ' ')\r
+               {\r
+                       argv[i]=p;\r
+                       while(*arg && *arg !=' ')\r
+                               *p++ = *arg++;\r
+                       i++;\r
+                       *p++=0;\r
+               }\r
+               arg++;\r
+       }\r
+       argv[i]=NULL;\r
+       *size = i;\r
+       return argv;\r
+}\r
+int git_open_log(GIT_LOG * handle, char * arg)\r
+{\r
+       struct rev_info *p_Rev;\r
+       int size;\r
+       char ** argv=0;\r
+       int argc=0;\r
+       \r
+       if(arg != NULL)\r
+               argv = strtoargv(arg,&argc);\r
+\r
+       p_Rev = malloc(sizeof(struct rev_info));\r
+       memset(p_Rev,0,sizeof(struct rev_info));\r
+\r
+       if(p_Rev == NULL)\r
+               return -1;\r
+\r
+       init_revisions(p_Rev, g_prefix);\r
+       p_Rev->diff = 1;\r
+       p_Rev->simplify_history = 0;\r
+       \r
+       cmd_log_init(argc, argv, g_prefix,p_Rev);\r
+\r
+       p_Rev->pPrivate = argv;\r
+       *handle = p_Rev;\r
+       return 0;\r
+\r
+}\r
+int git_get_log_firstcommit(GIT_LOG handle)\r
+{\r
+       return prepare_revision_walk(handle);\r
+}\r
+\r
+int git_get_log_nextcommit(GIT_LOG handle, GIT_COMMIT *commit)\r
+{\r
+       int ret =0;\r
+\r
+       commit->m_pGitCommit = get_revision(handle);\r
+       if( commit->m_pGitCommit == NULL)\r
+               return -2;\r
+       \r
+       ret=git_parse_commit(commit);\r
+       if(ret)\r
+               return ret;\r
+\r
+       return 0;\r
+}\r
+\r
+int git_close_log(GIT_LOG handle)\r
+{\r
+       if(handle)\r
+       {\r
+               struct rev_info *p_Rev;\r
+               p_Rev=(struct rev_info *)handle;\r
+               if(p_Rev->pPrivate)\r
+                       free(p_Rev->pPrivate);\r
+               free(handle);\r
+       }\r
+       \r
+       return 0;\r
+}
\ No newline at end of file
index 3cec3d7..2bac468 100644 (file)
@@ -80,14 +80,31 @@ GITDLL_API int git_get_sha1(const char *name, GIT_HASH sha1);
 GITDLL_API int git_init();\r
 \r
 GITDLL_API int git_open_log(GIT_LOG * handle, char * arg);\r
-GITDLL_API int git_get_log_count(GIT_LOG handle);\r
-GITDLL_API int git_get_log_firstcommit(GIT_LOG handle, GIT_COMMIT *commit);\r
-GITDLL_API int git_get_log_nextcommit(GIT_LOG handle, GIT_COMMIT *commit, int skip);\r
+GITDLL_API int git_get_log_firstcommit(GIT_LOG handle);\r
+\r
+/**\r
+ *     Get Next Commit\r
+ *  @param handle      [IN]handle  Get handle from git_open_log\r
+ *     @param commit   [OUT]commit     Caller need prepare buffer for this call\r
+ *  @return                    0       success\r
+ *     @remark                 Caller need call git_free_commit to free internal buffer after use it;\r
+ */\r
+GITDLL_API int git_get_log_nextcommit(GIT_LOG handle, GIT_COMMIT *commit);\r
+\r
 GITDLL_API int git_close_log(GIT_LOG handle);\r
 \r
+/**\r
+ *     Get Commit information from commit hash\r
+ *     @param  commit  [OUT] output commit information\r
+ *  @param     hash    [in] hash \r
+ *     @return         0       success\r
+ */\r
 GITDLL_API int git_get_commit_from_hash(GIT_COMMIT *commit, GIT_HASH hash);\r
+GITDLL_API int git_parse_commit(GIT_COMMIT *commit);\r
+GITDLL_API int git_free_commit(GIT_COMMIT *commit);\r
+\r
+GITDLL_API int git_get_diff(GIT_COMMIT *commit, GIT_DIFF *diff);\r
 \r
-GITDLL_API int git_get_diff(GIT_COMMIT commit, GIT_DIFF *diff);\r
 GITDLL_API int git_get_diff_firstfile(GIT_DIFF diff, GIT_FILE * file);\r
 GITDLL_API int git_get_diff_nextfile(GIT_DIFF diff, GIT_FILE *file);\r
 GITDLL_API int git_get_diff_status(GIT_DIFF diff, int * status);\r
index 0175fa3..e4c2f0c 100644 (file)
                        <Tool\r
                                Name="VCCLCompilerTool"\r
                                Optimization="0"\r
+                               AdditionalIncludeDirectories="..\tgit;..\tgit\compat;..\tgit\compat\vcbuild;;..\tgit\compat\vcbuild\include;..\tgit\compat\fnmatch;..\tgit\compat\regex;..\zlib;"\r
                                PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;GITDLL_EXPORTS"\r
                                MinimalRebuild="true"\r
                                BasicRuntimeChecks="3"\r
                        OutputDirectory="$(SolutionDir)\..\bin\$(ConfigurationName)\bin"\r
                        IntermediateDirectory="$(ConfigurationName)"\r
                        ConfigurationType="2"\r
-                       CharacterSet="1"\r
+                       CharacterSet="0"\r
                        WholeProgramOptimization="1"\r
                        >\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
                                Optimization="2"\r
                                EnableIntrinsicFunctions="true"\r
+                               AdditionalIncludeDirectories="..\tgit;..\tgit\compat;..\tgit\compat\vcbuild;;..\tgit\compat\vcbuild\include;..\tgit\compat\fnmatch;..\tgit\compat\regex;..\zlib;"\r
                                PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;GITDLL_EXPORTS"\r
                                RuntimeLibrary="2"\r
                                EnableFunctionLevelLinking="true"\r
                                Name="VCCLCompilerTool"\r
                                Optimization="2"\r
                                EnableIntrinsicFunctions="true"\r
+                               AdditionalIncludeDirectories="..\tgit;..\tgit\compat;..\tgit\compat\vcbuild;;..\tgit\compat\vcbuild\include;..\tgit\compat\fnmatch;..\tgit\compat\regex;..\zlib;"\r
                                PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;GITDLL_EXPORTS"\r
                                RuntimeLibrary="2"\r
                                EnableFunctionLevelLinking="true"\r
index 7298439..39aaeb7 100644 (file)
@@ -28,7 +28,22 @@ int _tmain(int argc, _TCHAR* argv[])
        output(ret,"git_get_sha1");\r
        ret=git_get_commit_from_hash(&commit, hash);\r
        output(ret,"git_get_commit_from_hash");\r
-\r
+       \r
+       GIT_HANDLE handle;\r
+       ret=git_open_log(&handle,"--stat -c -- \"build.txt\"");\r
+       output(ret,"git_open_log");\r
+       ret=git_get_log_firstcommit(handle);\r
+       output(ret,"git_get_log_firstcommit");\r
+       int count = 0;\r
+       while( git_get_log_nextcommit(handle,&commit) == 0)\r
+       {\r
+               //printf("%s\r\n",commit.m_Subject);\r
+               count ++;\r
+               git_free_commit(&commit);\r
+       }\r
+       printf("commit number %d\r\n",count);\r
+       ret=git_close_log(handle);\r
+       output(ret,"git_close_log");\r
        return ret;\r
 }\r
 \r
index f5953be..0aec371 100644 (file)
                </Configuration>\r
                <Configuration\r
                        Name="Release|Win32"\r
-                       OutputDirectory="$(SolutionDir)\..\bin\$(ConfigurationName)"\r
+                       OutputDirectory="$(SolutionDir)\..\bin\$(ConfigurationName)\bin"\r
                        IntermediateDirectory="$(ConfigurationName)"\r
                        ConfigurationType="1"\r
-                       CharacterSet="1"\r
+                       CharacterSet="0"\r
                        WholeProgramOptimization="1"\r
                        >\r
                        <Tool\r
index 9b982c6..e7c7ab5 160000 (submodule)
--- a/ext/tgit
+++ b/ext/tgit
@@ -1 +1 @@
-Subproject commit 9b982c62073508ee53f39ee175ca914a0903d49e
+Subproject commit e7c7ab5be4faa63f2278e7218078470a25fffd7d