Fixed issue #1620: Apply Patch serial can't open file dialog on WinXP
[TortoiseGit.git] / src / Git / GitRev.h
blob9f4b6144d8d009bf533fe797bfb91a7c0d243b07
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #pragma once
21 #include "gittype.h"
22 #include "GitStatus.h"
23 #include "AtlTime.h"
24 #include "GitHash.h"
25 #include "GitDll.h"
26 #include "git.h"
28 typedef std::vector<CGitHash> GIT_REV_LIST;
30 #define LOG_REV_AUTHOR_NAME _T('0')
31 #define LOG_REV_AUTHOR_EMAIL _T('1')
32 #define LOG_REV_AUTHOR_DATE _T('2')
33 #define LOG_REV_COMMIT_NAME _T('3')
34 #define LOG_REV_COMMIT_EMAIL _T('4')
35 #define LOG_REV_COMMIT_DATE _T('5')
36 #define LOG_REV_COMMIT_SUBJECT _T('6')
37 #define LOG_REV_COMMIT_BODY _T('7')
38 #define LOG_REV_COMMIT_HASH _T('8')
39 #define LOG_REV_COMMIT_PARENT _T('9')
40 #define LOG_REV_COMMIT_FILE _T('A')
41 #define LOG_REV_ITEM_BEGIN _T('B')
42 #define LOG_REV_ITEM_END _T('C')
44 class CGit;
45 extern CGit g_Git;
46 class GitRev;
47 class CLogCache;
49 typedef int CALL_UPDATE_DIFF_ASYNC(GitRev *pRev, void *data);
51 class GitRev
53 public:
54 friend class CLogCache;
56 protected:
57 CString m_AuthorName;
58 CString m_AuthorEmail;
59 CTime m_AuthorDate;
60 CString m_CommitterName;
61 CString m_CommitterEmail;
62 CTime m_CommitterDate;
63 CString m_Subject;
64 CString m_Body;
66 CTGitPathList m_Files;
67 int m_Action;
68 CTGitPathList m_UnRevFiles;
70 public:
71 GitRev(void);
73 CALL_UPDATE_DIFF_ASYNC *m_CallDiffAsync;
74 int CheckAndDiff()
76 if(!m_IsDiffFiles && !m_CommitHash.IsEmpty())
78 SafeFetchFullInfo(&g_Git);
79 InterlockedExchange(&m_IsDiffFiles, TRUE);
80 if(m_IsDiffFiles && m_IsCommitParsed)
81 InterlockedExchange(&m_IsFull, TRUE);
82 return 0;
84 return 1;
87 int & GetAction(void * data)
89 CheckAndParser();
90 if(!m_IsDiffFiles && m_CallDiffAsync)
91 m_CallDiffAsync(this, data);
92 else
93 CheckAndDiff();
94 return m_Action;
97 CTGitPathList & GetFiles(void * data)
99 CheckAndParser();
100 if(data && !m_IsDiffFiles && m_CallDiffAsync)
101 m_CallDiffAsync(this, data);
102 else
103 CheckAndDiff();
104 return m_Files;
107 CTGitPathList & GetUnRevFiles()
109 return m_UnRevFiles;
112 // GitRev(GitRev &rev);
113 // GitRev &operator=(GitRev &rev);
114 int CheckAndParser()
116 if(!m_IsCommitParsed && m_GitCommit.m_pGitCommit)
118 ParserFromCommit(&m_GitCommit);
119 InterlockedExchange(&m_IsCommitParsed, TRUE);
120 git_free_commit(&m_GitCommit);
121 if(m_IsDiffFiles && m_IsCommitParsed)
122 InterlockedExchange(&m_IsFull, TRUE);
123 return 0;
125 return 1;
128 CString & GetAuthorName()
130 CheckAndParser();
131 return m_AuthorName;
134 CString & GetAuthorEmail()
136 CheckAndParser();
137 return m_AuthorEmail;
140 CTime & GetAuthorDate()
142 CheckAndParser();
143 return m_AuthorDate;
146 CString & GetCommitterName()
148 CheckAndParser();
149 return m_CommitterName;
152 CString &GetCommitterEmail()
154 CheckAndParser();
155 return m_CommitterEmail;
158 CTime &GetCommitterDate()
160 CheckAndParser();
161 return m_CommitterDate;
164 CString & GetSubject()
166 CheckAndParser();
167 return m_Subject;
170 CString & GetBody()
172 CheckAndParser();
173 return m_Body;
177 ~GitRev(void);
179 GIT_COMMIT m_GitCommit;
181 enum
183 REV_HEAD = -1, ///< head revision
184 REV_BASE = -2, ///< base revision
185 REV_WC = -3, ///< revision of the working copy
186 REV_UNSPECIFIED = -4, ///< unspecified revision
189 int CopyFrom(GitRev &rev,bool OmitParentAndMark=false);
191 static CString GetHead(){return CString(_T("HEAD"));};
192 static CString GetWorkingCopy(){return CString(GIT_REV_ZERO);};
194 CString m_Notes;
196 CGitHash m_CommitHash;
197 GIT_REV_LIST m_ParentHash;
200 TCHAR m_Mark;
201 CString m_Ref;
202 CString m_RefAction;
204 BOOL IsBoundary(){return m_Mark == _T('-');}
206 void Clear();
207 //int ParserFromLog(BYTE_VECTOR &log,int start=0);
208 CTime ConverFromString(CString input);
209 inline int ParentsCount(){ return (int)m_ParentHash.size(); }
211 //Show version tree Graphic
212 std::vector<int> m_Lanes;
214 volatile LONG m_IsFull;
215 volatile LONG m_IsUpdateing;
216 volatile LONG m_IsCommitParsed;
217 volatile LONG m_IsDiffFiles;
219 int SafeFetchFullInfo(CGit *git);
221 int ParserFromCommit(GIT_COMMIT *commit);
222 int ParserParentFromCommit(GIT_COMMIT *commit);
225 int GetParentFromHash(CGitHash &hash);
226 int GetCommitFromHash(CGitHash &hash);
227 int GetCommit(CString Rev);
229 int SafeGetSimpleList(CGit *git);
230 volatile LONG m_IsSimpleListReady;
231 std::vector<CString> m_SimpleFileList; /* use for find and filter*/
232 /* no rename detect and line num stat infor*/
234 public:
235 void DbgPrint();
236 int AddMergeFiles();
237 private:
238 int GetCommitFromHash_withoutLock(CGitHash &hash);
239 TIME_ZONE_INFORMATION m_TimeZone;