Try to enable show merged file
[TortoiseGit.git] / src / Git / GitRev.cpp
blobf9ddc4fe578c92af4ac57dc30d08e6d335e209c4
1 #include "StdAfx.h"
2 #include "GitRev.h"
3 #include "Git.h"
5 class CException; //Just in case afx.h is not included (cannot be included in every project which uses this file)
7 // provide an ASSERT macro for when compiled without MFC
8 #if !defined ASSERT
9 // Don't use _asm here, it isn't supported by x64 version of compiler. In fact, MFC's ASSERT() is the same with _ASSERTE().
10 #define ASSERT(x) _ASSERTE(x)
11 #endif
14 GitRev::GitRev(void)
16 m_Action=0;
17 m_IsFull = 0;
18 m_IsUpdateing = 0;
19 // fetch local machine timezone info
20 if ( GetTimeZoneInformation( &m_TimeZone ) == TIME_ZONE_ID_INVALID )
22 ASSERT(false);
26 GitRev::~GitRev(void)
30 #if 0
31 GitRev::GitRev(GitRev & rev)
34 GitRev& GitRev::operator=(GitRev &rev)
36 return *this;
38 #endif
39 void GitRev::Clear()
41 this->m_Action=0;
42 this->m_Files.Clear();
43 this->m_Action=0;
44 this->m_ParentHash.clear();
45 m_CommitterName.Empty();
46 m_CommitterEmail.Empty();
47 m_Body.Empty();
48 m_Subject.Empty();
49 m_CommitHash.Empty();
50 m_Mark=0;
53 int GitRev::CopyFrom(GitRev &rev,bool OmitParentAndMark)
55 m_AuthorName =rev.m_AuthorName ;
56 m_AuthorEmail =rev.m_AuthorEmail ;
57 m_AuthorDate =rev.m_AuthorDate ;
58 m_CommitterName =rev.m_CommitterName ;
59 m_CommitterEmail=rev.m_CommitterEmail;
60 m_CommitterDate =rev.m_CommitterDate ;
61 m_Subject =rev.m_Subject ;
62 m_Body =rev.m_Body ;
63 m_CommitHash =rev.m_CommitHash ;
64 m_Files =rev.m_Files ;
65 m_Action =rev.m_Action ;
67 if(!OmitParentAndMark)
69 m_ParentHash =rev.m_ParentHash ;
70 m_Mark =rev.m_Mark;
72 return 0;
74 int GitRev::ParserFromLog(BYTE_VECTOR &log,int start)
76 int pos=start;
77 CString one;
78 CString key;
79 CString text;
80 BYTE_VECTOR filelist;
81 BYTE mode=0;
82 CTGitPath path;
83 this->m_Files.Clear();
84 m_Action=0;
85 int begintime=0;
86 int filebegin=-1;
88 while( pos < log.size() && pos>=0)
91 //one=log.Tokenize(_T("\n"),pos);
92 if(log[pos]==_T('#') && log[pos+1] == _T('<') && log[pos+3] == _T('>'))
94 //text = one.Right(one.GetLength()-4);
95 text.Empty();
96 g_Git.StringAppend(&text,&log[pos+4],CP_UTF8);
97 mode = log[pos+2];
99 switch(mode)
101 case LOG_REV_ITEM_BEGIN:
102 begintime++;
103 if(begintime>1)
104 break;
105 else
106 this->Clear();
107 break;
108 case LOG_REV_AUTHOR_NAME:
109 this->m_AuthorName = text;
110 break;
111 case LOG_REV_AUTHOR_EMAIL:
112 this->m_AuthorEmail = text;
113 break;
114 case LOG_REV_AUTHOR_DATE:
115 this->m_AuthorDate =ConverFromString(text);
116 break;
117 case LOG_REV_COMMIT_NAME:
118 this->m_CommitterName = text;
119 break;
120 case LOG_REV_COMMIT_EMAIL:
121 this->m_CommitterEmail = text;
122 break;
123 case LOG_REV_COMMIT_DATE:
124 this->m_CommitterDate =ConverFromString(text);
125 break;
126 case LOG_REV_COMMIT_SUBJECT:
127 this->m_Subject = text;
128 break;
129 case LOG_REV_COMMIT_BODY:
130 this->m_Body = text +_T("\n");
131 break;
132 case LOG_REV_COMMIT_HASH:
133 this->m_CommitHash = text.Right(40);
134 if(text.GetLength()>40)
136 this->m_Mark=text[0];
138 break;
139 case LOG_REV_COMMIT_PARENT:
140 while(text.GetLength()>0)
142 this->m_ParentHash.insert(this->m_ParentHash.end(),text.Left(40));
143 if(text.GetLength()>40)
144 text=text.Right(text.GetLength()-41);
145 else
146 break;
148 if(m_ParentHash.size()>1)
150 int a=1;
152 break;
153 case LOG_REV_COMMIT_FILE:
154 break;
156 }else
158 switch(mode)
160 // case LOG_REV_COMMIT_BODY:
161 // this->m_Body += one+_T("\n");
162 // break;
163 case LOG_REV_COMMIT_FILE:
164 //filelist += one +_T("\n");
165 //filelist.append(log,pos,log.find(0,pos));
166 if(filebegin<0)
167 filebegin=pos;
168 break;
172 if(begintime>1)
174 break;
177 //find next string start
178 pos=log.findNextString(pos);
181 if(filebegin>=0)
184 filelist.append(log,filebegin,pos);
185 this->m_Files.ParserFromLog(filelist);
186 this->m_Action=this->m_Files.GetAction();
188 return pos;
191 CTime GitRev::ConverFromString(CString input)
193 // pick up date from string
196 CTime tm(_wtoi(input.Mid(0,4)),
197 _wtoi(input.Mid(5,2)),
198 _wtoi(input.Mid(8,2)),
199 _wtoi(input.Mid(11,2)),
200 _wtoi(input.Mid(14,2)),
201 _wtoi(input.Mid(17,2)),
203 if(tm.GetTime()<=1)
204 return CTime();//Error parsing time-string
206 // pick up utc offset
207 CString sign = input.Mid(20,1); // + or -
208 int hoursOffset = _wtoi(input.Mid(21,2));
209 int minsOffset = _wtoi(input.Mid(23,2));
210 if ( sign == "-" )
212 hoursOffset = -hoursOffset;
213 minsOffset = -minsOffset;
215 // make a timespan object with this value
216 CTimeSpan offset( 0, hoursOffset, minsOffset, 0 );
217 // we have to subtract this from the time given to get UTC
218 tm -= offset;
219 // get local timezone
220 SYSTEMTIME sysTime;
221 tm.GetAsSystemTime( sysTime );
222 SYSTEMTIME local;
223 if ( SystemTimeToTzSpecificLocalTime( &m_TimeZone, &sysTime, &local ) )
225 sysTime = local;
227 else
229 ASSERT(false);
231 tm = CTime( sysTime, 0 );
232 return tm;
234 catch(CException* e)
236 //Probably the date was something like 1970-01-01 00:00:00. _mktime64() doesnt like this.
237 //Dont let the application crash on this exception
239 #ifdef _AFX //CException classes are only defined when afx.h is included.
240 //When afx.h is not included, the exception is leaked.
241 //This will probably never happen because when CException is not defined, it cannot be thrown.
242 e->Delete();
243 #endif //ifdef _AFX
245 return CTime(); //Return an invalid time
248 int GitRev::SafeFetchFullInfo(CGit *git)
250 if(InterlockedExchange(&m_IsUpdateing,TRUE) == FALSE)
252 //GitRev rev;
253 BYTE_VECTOR onelog;
254 TCHAR oldmark=this->m_Mark;
256 git->GetLog(onelog,m_CommitHash,NULL,1,CGit::LOG_INFO_STAT|CGit::LOG_INFO_FILESTATE|CGit::LOG_INFO_DETECT_COPYRENAME|CGit::LOG_INFO_SHOW_MERGEDFILE);
257 CString oldhash=m_CommitHash;
258 GIT_REV_LIST oldlist=this->m_ParentHash;
259 ParserFromLog(onelog);
261 //ASSERT(oldhash==m_CommitHash);
262 if(oldmark!=0)
263 this->m_Mark=oldmark; //parser full log will cause old mark overwrited.
264 //So we need keep old bound mark.
265 this->m_ParentHash=oldlist;
266 InterlockedExchange(&m_IsUpdateing,FALSE);
267 InterlockedExchange(&m_IsFull,TRUE);
268 return 0;
270 return -1;