OSDN Git Service

Add git diff support at gitdll
[tortoisegit/TortoiseGitJp.git] / ext / gitdll / gitdll.c
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