7 #include "MessageBox.h"
8 #include "FileDiffDlg.h"
10 CGitDiff::CGitDiff(void)
14 CGitDiff::~CGitDiff(void)
17 int CGitDiff::Parser(git_revnum_t
&rev
)
19 if(rev
== GIT_REV_ZERO
)
21 if(rev
.GetLength() > 40)
24 cmd
.Format(_T("git.exe rev-parse %s"),rev
);
26 if(!g_Git
.Run(cmd
,&output
,CP_UTF8
))
28 //int start=output.Find(_T('\n'));
34 int CGitDiff::DiffNull(CTGitPath
*pPath
, git_revnum_t
&rev1
,bool bIsAdd
)
37 GetTempPath(temppath
);
42 if(rev1
!= GIT_REV_ZERO
)
44 file1
.Format(_T("%s%s_%s%s"),
46 pPath
->GetBaseFilename(),
48 pPath
->GetFileExtension());
49 cmd
.Format(_T("git.exe cat-file -p %s:\"%s\""),rev1
,pPath
->GetGitPathString());
50 g_Git
.RunLogFile(cmd
,file1
);
53 file1
=g_Git
.m_CurrentDir
+_T("\\")+pPath
->GetWinPathString();
56 CString tempfile
=::GetTempFile();
57 CStdioFile
file(tempfile
,CFile::modeReadWrite
|CFile::modeCreate
);
61 CAppUtils::DiffFlags flags
;
64 CAppUtils::StartExtDiff(tempfile
,file1
,
66 pPath
->GetGitPathString()+_T(":")+rev1
.Left(6)
69 CAppUtils::StartExtDiff(file1
,tempfile
,
70 pPath
->GetGitPathString()+_T(":")+rev1
.Left(6)
76 int CGitDiff::SubmoduleDiff(CTGitPath
* pPath
,CTGitPath
* pPath2
, git_revnum_t
& rev1
, git_revnum_t
& rev2
, bool /*blame*/, bool /*unified*/)
83 if( rev2
== GIT_REV_ZERO
|| rev1
== GIT_REV_ZERO
)
85 oldhash
= GIT_REV_ZERO
;
86 newhash
= GIT_REV_ZERO
;
89 if( rev2
!= GIT_REV_ZERO
)
91 if( rev1
!= GIT_REV_ZERO
)
94 workingcopy
= _T("(Work Copy)");
96 cmd
.Format(_T("git.exe diff %s -- \"%s\""),
97 rev
,pPath
->GetGitPathString());
100 if(g_Git
.Run(cmd
,&output
,CP_ACP
))
102 CMessageBox::Show(NULL
,output
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
106 int oldstart
= output
.Find(_T("-Subproject commit"),start
);
109 CMessageBox::Show(NULL
,_T("Subproject Diff Format error") ,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
112 oldhash
= output
.Mid(oldstart
+ CString(_T("-Subproject commit")).GetLength()+1,40);
114 int newstart
= output
.Find(_T("+Subproject commit"),start
);
117 CMessageBox::Show(NULL
,_T("Subproject Diff Format error") ,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
120 newhash
= output
.Mid(newstart
+ CString(_T("+Subproject commit")).GetLength()+1,40);
124 cmd
.Format(_T("git.exe diff-tree -r -z %s %s -- \"%s\""),
125 rev2
,rev1
,pPath
->GetGitPathString());
128 if(g_Git
.Run(cmd
,&bytes
))
131 g_Git
.StringAppend(&err
,&bytes
[0],CP_ACP
);
132 CMessageBox::Show(NULL
,err
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
136 g_Git
.StringAppend(&oldhash
,&bytes
[15],CP_ACP
,40);
137 g_Git
.StringAppend(&newhash
,&bytes
[15+41],CP_ACP
,40);
145 subgit
.m_CurrentDir
=g_Git
.m_CurrentDir
+_T("\\")+pPath
->GetWinPathString();
147 if(pPath
->HasAdminDir())
149 int encode
=CAppUtils::GetLogOutputEncode(&subgit
);
151 if(oldhash
!= GIT_REV_ZERO
)
153 cmd
.Format(_T("git log -n1 --pretty=format:\"%%s\" %s"),oldhash
);
154 subgit
.Run(cmd
,&oldsub
,encode
);
156 if(newsub
!= GIT_REV_ZERO
)
158 cmd
.Format(_T("git log -n1 --pretty=format:\"%%s\" %s"),newhash
);
159 subgit
.Run(cmd
,&newsub
,encode
);
163 msg
.Format(_T("Submodule <b>%s</b> Change\r\n\r\n<b>From:</b> %s\r\n\t%s\r\n\r\n<b>To%s:</b> %s\r\n\t\t%s"),
170 CMessageBox::Show(NULL
,msg
,_T("TortoiseGit"),MB_OK
);
175 int CGitDiff::Diff(CTGitPath
* pPath
,CTGitPath
* pPath2
, git_revnum_t
& rev1
, git_revnum_t
& rev2
, bool /*blame*/, bool /*unified*/)
178 GetTempPath(temppath
);
185 if(pPath
->IsDirectory() || pPath2
->IsDirectory())
187 return SubmoduleDiff(pPath
,pPath2
,rev1
,rev2
);
190 if(rev1
!= GIT_REV_ZERO
)
192 file1
.Format(_T("%s%s_%s%s"),
194 pPath
->GetBaseFilename(),
196 pPath
->GetFileExtension());
197 title1
= pPath
->GetFileOrDirectoryName()+_T(":")+rev1
.Left(6);
198 cmd
.Format(_T("git.exe cat-file -p %s:\"%s\""),rev1
,pPath
->GetGitPathString());
199 g_Git
.RunLogFile(cmd
,file1
);
202 file1
=g_Git
.m_CurrentDir
+_T("\\")+pPath
->GetWinPathString();
203 title1
.Format( IDS_DIFF_WCNAME
, pPath
->GetFileOrDirectoryName() );
208 if(rev2
!= GIT_REV_ZERO
)
211 file2
.Format(_T("%s%s_%s%s"),
213 pPath2
->GetBaseFilename(),
215 pPath2
->GetFileExtension());
216 title2
= pPath2
->GetFileOrDirectoryName()+_T(":")+rev2
.Left(6);
217 cmd
.Format(_T("git.exe cat-file -p %s:\"%s\""),rev2
,pPath2
->GetGitPathString());
218 g_Git
.RunLogFile(cmd
,file2
);
221 file2
=g_Git
.m_CurrentDir
+_T("\\")+pPath2
->GetWinPathString();
222 title2
.Format( IDS_DIFF_WCNAME
, pPath2
->GetFileOrDirectoryName() );
225 CAppUtils::DiffFlags flags
;
226 CAppUtils::StartExtDiff(file2
,file1
,
234 int CGitDiff::DiffCommit(CTGitPath
&path
, GitRev
*r1
, GitRev
*r2
)
236 if( path
.GetWinPathString().IsEmpty() || path
.IsDirectory() )
239 dlg
.SetDiff(NULL
,*r1
,*r2
);
243 Diff(&path
,&path
,r1
->m_CommitHash
.ToString(),r2
->m_CommitHash
.ToString());
248 int CGitDiff::DiffCommit(CTGitPath
&path
, CString
&r1
, CString
&r2
)
250 if( path
.GetWinPathString().IsEmpty() || path
.IsDirectory() )
253 dlg
.SetDiff(NULL
,r1
,r2
);
257 Diff(&path
,&path
,r1
,r2
);