Update diff del rename ignore document.
[TortoiseGit.git] / src / TortoiseProc / GitDiff.cpp
blob3f45e1f9c4e55a1daf1606220057db5f3e07277e
1 #include "StdAfx.h"
2 #include "GitDiff.h"
3 #include "AppUtils.h"
4 #include "git.h"
5 #include "resource.h"
7 CGitDiff::CGitDiff(void)
11 CGitDiff::~CGitDiff(void)
14 int CGitDiff::Parser(git_revnum_t &rev)
16 if(rev == GIT_REV_ZERO)
17 return 0;
18 if(rev.GetLength() > 40)
20 CString cmd;
21 cmd.Format(_T("git.exe rev-parse %s"),rev);
22 CString output;
23 if(!g_Git.Run(cmd,&output,CP_UTF8))
25 //int start=output.Find(_T('\n'));
26 rev=output.Left(40);
29 return 0;
31 int CGitDiff::DiffNull(CTGitPath *pPath, git_revnum_t &rev1,bool bIsAdd)
33 CString temppath;
34 GetTempPath(temppath);
35 Parser(rev1);
36 CString file1;
37 CString nullfile;
38 CString cmd;
39 if(rev1 != GIT_REV_ZERO )
41 file1.Format(_T("%s%s_%s%s"),
42 temppath,
43 pPath->GetBaseFilename(),
44 rev1.Left(6),
45 pPath->GetFileExtension());
46 cmd.Format(_T("git.exe cat-file -p %s:\"%s\""),rev1,pPath->GetGitPathString());
47 g_Git.RunLogFile(cmd,file1);
48 }else
50 file1=g_Git.m_CurrentDir+_T("\\")+pPath->GetWinPathString();
53 CString tempfile=::GetTempFile();
54 CStdioFile file(tempfile,CFile::modeReadWrite|CFile::modeCreate );
55 //file.WriteString();
56 file.Close();
58 CAppUtils::DiffFlags flags;
60 if(bIsAdd)
61 CAppUtils::StartExtDiff(tempfile,file1,
62 _T("NULL"),
63 pPath->GetGitPathString()+_T(":")+rev1.Left(6)
64 ,flags);
65 else
66 CAppUtils::StartExtDiff(file1,tempfile,
67 pPath->GetGitPathString()+_T(":")+rev1.Left(6)
68 ,_T("NULL"),flags);
70 return 0;
73 int CGitDiff::Diff(CTGitPath * pPath,CTGitPath * pPath2, git_revnum_t & rev1, git_revnum_t & rev2, bool /*blame*/, bool /*unified*/)
75 CString temppath;
76 GetTempPath(temppath);
77 Parser(rev1);
78 Parser(rev2);
79 CString file1;
80 CString title1;
81 CString cmd;
82 if(rev1 != GIT_REV_ZERO )
84 file1.Format(_T("%s%s_%s%s"),
85 temppath,
86 pPath->GetBaseFilename(),
87 rev1.Left(6),
88 pPath->GetFileExtension());
89 title1 = pPath->GetFileOrDirectoryName()+_T(":")+rev1.Left(6);
90 cmd.Format(_T("git.exe cat-file -p %s:\"%s\""),rev1,pPath->GetGitPathString());
91 g_Git.RunLogFile(cmd,file1);
92 }else
94 file1=g_Git.m_CurrentDir+_T("\\")+pPath->GetWinPathString();
95 title1.Format( IDS_DIFF_WCNAME, pPath->GetFileOrDirectoryName() );
98 CString file2;
99 CString title2;
100 if(rev2 != GIT_REV_ZERO)
103 file2.Format(_T("%s%s_%s%s"),
104 temppath,
105 pPath2->GetBaseFilename(),
106 rev2.Left(6),
107 pPath2->GetFileExtension());
108 title2 = pPath2->GetFileOrDirectoryName()+_T(":")+rev2.Left(6);
109 cmd.Format(_T("git.exe cat-file -p %s:\"%s\""),rev2,pPath2->GetGitPathString());
110 g_Git.RunLogFile(cmd,file2);
111 }else
113 file2=g_Git.m_CurrentDir+_T("\\")+pPath2->GetWinPathString();
114 title2.Format( IDS_DIFF_WCNAME, pPath2->GetFileOrDirectoryName() );
117 CAppUtils::DiffFlags flags;
118 CAppUtils::StartExtDiff(file2,file1,
119 title2,
120 title1
121 ,flags);
123 return 0;