2 #include "ATLComTime.h"
6 class CException
; //Just in case afx.h is not included (cannot be included in every project which uses this file)
8 // provide an ASSERT macro for when compiled without MFC
10 // Don't use _asm here, it isn't supported by x64 version of compiler. In fact, MFC's ASSERT() is the same with _ASSERTE().
11 #define ASSERT(x) _ASSERTE(x)
20 // fetch local machine timezone info
21 if ( GetTimeZoneInformation( &m_TimeZone
) == TIME_ZONE_ID_INVALID
)
32 GitRev::GitRev(GitRev
& rev
)
35 GitRev
& GitRev::operator=(GitRev
&rev
)
43 this->m_Files
.Clear();
45 this->m_ParentHash
.clear();
46 m_CommitterName
.Empty();
47 m_CommitterEmail
.Empty();
54 int GitRev::CopyFrom(GitRev
&rev
,bool OmitParentAndMark
)
56 m_AuthorName
=rev
.m_AuthorName
;
57 m_AuthorEmail
=rev
.m_AuthorEmail
;
58 m_AuthorDate
=rev
.m_AuthorDate
;
59 m_CommitterName
=rev
.m_CommitterName
;
60 m_CommitterEmail
=rev
.m_CommitterEmail
;
61 m_CommitterDate
=rev
.m_CommitterDate
;
62 m_Subject
=rev
.m_Subject
;
64 m_CommitHash
=rev
.m_CommitHash
;
65 m_Files
=rev
.m_Files
;
66 m_Action
=rev
.m_Action
;
68 if(!OmitParentAndMark
)
70 m_ParentHash
=rev
.m_ParentHash
;
75 int GitRev::ParserFromLog(BYTE_VECTOR
&log
,int start
)
84 this->m_Files
.Clear();
89 while( pos
< log
.size() && pos
>=0)
92 //one=log.Tokenize(_T("\n"),pos);
93 if(log
[pos
]==_T('#') && log
[pos
+1] == _T('<') && log
[pos
+3] == _T('>'))
95 //text = one.Right(one.GetLength()-4);
97 g_Git
.StringAppend(&text
,&log
[pos
+4],CGit::m_LogEncode
);
102 case LOG_REV_ITEM_BEGIN
:
109 case LOG_REV_AUTHOR_NAME
:
110 this->m_AuthorName
= text
;
112 case LOG_REV_AUTHOR_EMAIL
:
113 this->m_AuthorEmail
= text
;
115 case LOG_REV_AUTHOR_DATE
:
116 this->m_AuthorDate
=ConverFromString(text
);
118 case LOG_REV_COMMIT_NAME
:
119 this->m_CommitterName
= text
;
121 case LOG_REV_COMMIT_EMAIL
:
122 this->m_CommitterEmail
= text
;
124 case LOG_REV_COMMIT_DATE
:
125 this->m_CommitterDate
=ConverFromString(text
);
127 case LOG_REV_COMMIT_SUBJECT
:
128 this->m_Subject
= text
;
130 case LOG_REV_COMMIT_BODY
:
131 this->m_Body
= text
+_T("\n");
133 case LOG_REV_COMMIT_HASH
:
134 this->m_CommitHash
= text
.Right(40);
135 if(text
.GetLength()>40)
137 this->m_Mark
=text
[0];
140 case LOG_REV_COMMIT_PARENT
:
141 while(text
.GetLength()>0)
143 this->m_ParentHash
.insert(this->m_ParentHash
.end(),text
.Left(40));
144 if(text
.GetLength()>40)
145 text
=text
.Right(text
.GetLength()-41);
149 if(m_ParentHash
.size()>1)
154 case LOG_REV_COMMIT_FILE
:
161 // case LOG_REV_COMMIT_BODY:
162 // this->m_Body += one+_T("\n");
164 case LOG_REV_COMMIT_FILE
:
165 //filelist += one +_T("\n");
166 //filelist.append(log,pos,log.find(0,pos));
178 //find next string start
179 pos
=log
.findNextString(pos
);
185 filelist
.append(log
,filebegin
,pos
);
186 this->m_Files
.ParserFromLog(filelist
);
187 this->m_Action
=this->m_Files
.GetAction();
192 CTime
GitRev::ConverFromString(CString input
)
194 // pick up date from string
197 COleDateTime
tm(_wtoi(input
.Mid(0,4)),
198 _wtoi(input
.Mid(5,2)),
199 _wtoi(input
.Mid(8,2)),
200 _wtoi(input
.Mid(11,2)),
201 _wtoi(input
.Mid(14,2)),
202 _wtoi(input
.Mid(17,2)));
203 if( tm
.GetStatus() != COleDateTime::valid
)
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 // convert to a fraction of a day
211 double offset
= (hoursOffset
*60 + minsOffset
) / 1440.0; // 1440 mins = 1 day
216 // we have to subtract this from the time given to get UTC
218 // get utc time as a SYSTEMTIME
220 tm
.GetAsSystemTime( sysTime
);
221 // and convert to users local time
223 if ( SystemTimeToTzSpecificLocalTime( &m_TimeZone
, &sysTime
, &local
) )
229 ASSERT(false); // this should not happen but leave time in utc if it does
231 // convert to CTime and return
232 return CTime( sysTime
, -1 );;
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.
245 return CTime(); //Return an invalid time
248 int GitRev::SafeFetchFullInfo(CGit
*git
)
250 if(InterlockedExchange(&m_IsUpdateing
,TRUE
) == FALSE
)
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);
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
);