OSDN Git Service

Add git diff support at gitdll
authorFrank Li <lznuaa@gmail.com>
Wed, 30 Dec 2009 14:35:14 +0000 (22:35 +0800)
committerFrank Li <lznuaa@gmail.com>
Wed, 30 Dec 2009 14:35:14 +0000 (22:35 +0800)
Signed-off-by: Frank Li <lznuaa@gmail.com>
ext/gitdll/gitdll.c
ext/gitdll/gitdll.h
ext/gitdll/gitdll.vcproj

index 83834cf..5098a8b 100644 (file)
@@ -9,9 +9,10 @@
 #include "commit.h"\r
 #include "diff.h"\r
 #include "revision.h"\r
-\r
+#include "diffcore.h"\r
 const char git_version_string[] = GIT_VERSION;\r
 \r
+\r
 #if 0\r
 \r
 // This is an example of an exported variable\r
@@ -215,11 +216,6 @@ int git_free_commit(GIT_COMMIT *commit)
        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
@@ -324,4 +320,75 @@ int git_close_log(GIT_LOG handle)
        }\r
        \r
        return 0;\r
-}
\ No newline at end of file
+}\r
+\r
+int git_open_diff(GIT_DIFF *diff, 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
+       p_Rev->pPrivate = argv;\r
+       *diff = (GIT_DIFF)p_Rev;\r
+\r
+       init_revisions(p_Rev, g_prefix);\r
+       git_config(git_diff_basic_config, NULL); /* no "diff" UI options */\r
+       p_Rev->abbrev = 0;\r
+       p_Rev->diff = 1;\r
+       argc = setup_revisions(argc, argv, p_Rev, NULL);\r
+\r
+       return 0;\r
+}\r
+int git_diff_flush(struct diff_options *options)\r
+{\r
+       struct diff_queue_struct *q = &diff_queued_diff;\r
+       int i;\r
+       for (i = 0; i < q->nr; i++)\r
+               diff_free_filepair(q->queue[i]);\r
+\r
+       if(q->queue)\r
+       {\r
+               free(q->queue);\r
+               q->queue = NULL;\r
+               q->nr = q->alloc = 0;\r
+       }\r
+\r
+       if (options->close_file)\r
+               fclose(options->file);\r
+\r
+}\r
+int git_diff(GIT_DIFF diff, GIT_HASH hash1, GIT_HASH hash2)\r
+{\r
+       struct rev_info *p_Rev;\r
+       int ret;\r
+       int i;\r
+       struct diff_queue_struct *q = &diff_queued_diff;\r
+       \r
+       p_Rev = (struct rev_info *)diff;\r
+\r
+       git_diff_flush(&p_Rev->diffopt);\r
+\r
+       ret = diff_tree_sha1(hash1,hash2,"",&p_Rev->diffopt);\r
+       if( ret )\r
+               return ret;\r
+       \r
+       diffcore_std(&p_Rev->diffopt);\r
+\r
+       memset(&p_Rev->diffstat, 0, sizeof(struct diffstat_t));\r
+       for (i = 0; i < q->nr; i++) {\r
+               struct diff_filepair *p = q->queue[i];\r
+               if (check_pair_status(p))\r
+                               diff_flush_stat(p, &p_Rev->diffopt, &p_Rev->diffstat);\r
+       }\r
+       free_diffstat_info(&p_Rev->diffstat);\r
+\r
+       return 0;\r
+}\r
+\r
index 2bac468..2053fc4 100644 (file)
@@ -31,8 +31,8 @@ typedef unsigned char GIT_HASH[GIT_HASH_SIZE];
 typedef unsigned int  GIT_HANDLE;\r
 typedef unsigned int  GIT_LOG;\r
 \r
-typedef unsigned int  GIT_DIFF;\r
-typedef unsigned int  GIT_FILE;\r
+typedef unsigned int GIT_DIFF;\r
+typedef unsigned int GIT_FILE;\r
 \r
 struct GIT_COMMIT_AUTHOR\r
 {\r
@@ -103,7 +103,9 @@ GITDLL_API int git_get_commit_from_hash(GIT_COMMIT *commit, GIT_HASH hash);
 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
+GITDLL_API int git_open_diff(GIT_DIFF *diff, char * arg);\r
+GITDLL_API int git_diff(GIT_DIFF diff, GIT_HASH hash1,GIT_HASH hash2);\r
+GITDLL_API int git_close_diff(GIT_DIFF diff);\r
 \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
index e4c2f0c..74e5654 100644 (file)
@@ -67,6 +67,7 @@
                                AdditionalDependencies="wininet.lib ws2_32.lib "\r
                                LinkIncremental="2"\r
                                GenerateDebugInformation="true"\r
+                               GenerateMapFile="true"\r
                                SubSystem="2"\r
                                TargetMachine="1"\r
                        />\r