Initial version of BrowseRefsDlg
[TortoiseGit.git] / src / TortoiseProc / GitDiff.cpp
blob49ea5e6742a0e8215187b68c16ae1ad71c416e06
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)
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;
59 CAppUtils::StartExtDiff(tempfile,file1,
60 _T("NULL"),
61 pPath->GetGitPathString()+_T(":")+rev1.Left(6)
62 ,flags);
63 return 0;
66 int CGitDiff::Diff(CTGitPath * pPath,CTGitPath * pPath2, git_revnum_t & rev1, git_revnum_t & rev2, bool /*blame*/, bool /*unified*/)
68 CString temppath;
69 GetTempPath(temppath);
70 Parser(rev1);
71 Parser(rev2);
72 CString file1;
73 CString title1;
74 CString cmd;
75 if(rev1 != GIT_REV_ZERO )
77 file1.Format(_T("%s%s_%s%s"),
78 temppath,
79 pPath->GetBaseFilename(),
80 rev1.Left(6),
81 pPath->GetFileExtension());
82 title1 = pPath->GetFileOrDirectoryName()+_T(":")+rev1.Left(6);
83 cmd.Format(_T("git.exe cat-file -p %s:\"%s\""),rev1,pPath->GetGitPathString());
84 g_Git.RunLogFile(cmd,file1);
85 }else
87 file1=g_Git.m_CurrentDir+_T("\\")+pPath->GetWinPathString();
88 title1.Format( IDS_DIFF_WCNAME, pPath->GetFileOrDirectoryName() );
91 CString file2;
92 CString title2;
93 if(rev2 != GIT_REV_ZERO)
96 file2.Format(_T("%s%s_%s%s"),
97 temppath,
98 pPath2->GetBaseFilename(),
99 rev2.Left(6),
100 pPath2->GetFileExtension());
101 title2 = pPath2->GetFileOrDirectoryName()+_T(":")+rev2.Left(6);
102 cmd.Format(_T("git.exe cat-file -p %s:\"%s\""),rev2,pPath2->GetGitPathString());
103 g_Git.RunLogFile(cmd,file2);
104 }else
106 file2=g_Git.m_CurrentDir+_T("\\")+pPath2->GetWinPathString();
107 title2.Format( IDS_DIFF_WCNAME, pPath2->GetFileOrDirectoryName() );
110 CAppUtils::DiffFlags flags;
111 CAppUtils::StartExtDiff(file2,file1,
112 title2,
113 title1
114 ,flags);
116 return 0;