OSDN Git Service

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