OSDN Git Service

2da12e519ed4d4fc7b2ef422da0a94ce2691beff
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / GitDiff.cpp
1 #include "StdAfx.h"\r
2 #include "GitDiff.h"\r
3 #include "AppUtils.h"\r
4 #include "git.h"\r
5 \r
6 CGitDiff::CGitDiff(void)\r
7 {\r
8 }\r
9 \r
10 CGitDiff::~CGitDiff(void)\r
11 {\r
12 }\r
13 int CGitDiff::Parser(git_revnum_t &rev)\r
14 {\r
15         if(rev == GIT_REV_ZERO)\r
16                 return 0;\r
17         if(rev.GetLength() > 40)\r
18         {\r
19                 CString cmd;\r
20                 cmd.Format(_T("git.exe rev-parse %s"),rev);\r
21                 CString output;\r
22                 if(!g_Git.Run(cmd,&output,CP_UTF8))\r
23                 {\r
24                         //int start=output.Find(_T('\n'));\r
25                         rev=output.Left(40);\r
26                 }\r
27         }\r
28         return 0;\r
29 }\r
30 int CGitDiff::DiffNull(CTGitPath *pPath, git_revnum_t &rev1)\r
31 {\r
32         CString temppath;\r
33         GetTempPath(temppath);\r
34         Parser(rev1);\r
35         CString file1;\r
36         CString nullfile;\r
37         CString cmd;\r
38         if(rev1 != GIT_REV_ZERO )\r
39         {\r
40                 file1.Format(_T("%s%s_%s%s"),\r
41                                 temppath,                                               \r
42                                 pPath->GetBaseFilename(),\r
43                                 rev1.Left(6),\r
44                                 pPath->GetFileExtension());\r
45                 cmd.Format(_T("git.exe cat-file -p %s:%s"),rev1,pPath->GetGitPathString());\r
46                                 g_Git.RunLogFile(cmd,file1);\r
47         }else\r
48         {\r
49                 file1=g_Git.m_CurrentDir+_T("\\")+pPath->GetWinPathString();\r
50         }\r
51 \r
52         CString tempfile=::GetTempFile();\r
53         CStdioFile file(tempfile,CFile::modeReadWrite|CFile::modeCreate );\r
54         //file.WriteString();\r
55         file.Close();\r
56         \r
57         CAppUtils::DiffFlags flags;\r
58         CAppUtils::StartExtDiff(tempfile,file1,\r
59                                                         _T("NULL"),\r
60                                                         pPath->GetGitPathString()+_T(":")+rev1.Left(6)\r
61                                                         ,flags);\r
62         return 0;\r
63 }\r
64 \r
65 int CGitDiff::Diff(CTGitPath * pPath,CTGitPath * pPath2, git_revnum_t & rev1, git_revnum_t & rev2, bool blame, bool unified)\r
66 {\r
67         CString temppath;\r
68         GetTempPath(temppath);\r
69         Parser(rev1);\r
70         Parser(rev2);\r
71         CString file1;\r
72         CString cmd;\r
73         if(rev1 != GIT_REV_ZERO )\r
74         {\r
75                 file1.Format(_T("%s%s_%s%s"),\r
76                                 temppath,                                               \r
77                                 pPath->GetBaseFilename(),\r
78                                 rev1.Left(6),\r
79                                 pPath->GetFileExtension());\r
80                 cmd.Format(_T("git.exe cat-file -p %s:%s"),rev1,pPath->GetGitPathString());\r
81                                 g_Git.RunLogFile(cmd,file1);\r
82         }else\r
83         {\r
84                 file1=g_Git.m_CurrentDir+_T("\\")+pPath->GetWinPathString();\r
85         }\r
86 \r
87         CString file2;\r
88         if(rev2 != GIT_REV_ZERO)\r
89         {\r
90                 \r
91                 file2.Format(_T("%s%s_%s%s"),\r
92                                 temppath,                                               \r
93                                 pPath2->GetBaseFilename(),\r
94                                 rev2.Left(6),\r
95                                 pPath2->GetFileExtension());\r
96                 cmd.Format(_T("git.exe cat-file -p %s:%s"),rev2,pPath2->GetGitPathString());\r
97                 g_Git.RunLogFile(cmd,file2);\r
98         }else\r
99         {\r
100                 file2=g_Git.m_CurrentDir+_T("\\")+pPath2->GetWinPathString();\r
101         }\r
102         \r
103         CAppUtils::DiffFlags flags;\r
104         CAppUtils::StartExtDiff(file2,file1,\r
105                                                         pPath2->GetGitPathString()+_T(":")+rev2.Left(6),\r
106                                                         pPath->GetGitPathString()+_T(":")+rev1.Left(6)\r
107                                                         ,flags);\r
108 \r
109         return 0;\r
110 }\r
111 \r
112 int CGitDiff::StartConflictEditor(CTGitPath* file)\r
113 {\r
114         return 0;\r
115 }