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
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)
19 // fetch local machine timezone info
20 if ( GetTimeZoneInformation( &m_TimeZone
) == TIME_ZONE_ID_INVALID
)
31 GitRev::GitRev(GitRev
& rev
)
34 GitRev
& GitRev::operator=(GitRev
&rev
)
42 this->m_Files
.Clear();
44 this->m_ParentHash
.clear();
45 m_CommitterName
.Empty();
46 m_CommitterEmail
.Empty();
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
;
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
;
74 int GitRev::ParserFromLog(BYTE_VECTOR
&log
,int start
)
83 this->m_Files
.Clear();
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);
96 g_Git
.StringAppend(&text
,&log
[pos
+4],CP_UTF8
);
101 case LOG_REV_ITEM_BEGIN
:
108 case LOG_REV_AUTHOR_NAME
:
109 this->m_AuthorName
= text
;
111 case LOG_REV_AUTHOR_EMAIL
:
112 this->m_AuthorEmail
= text
;
114 case LOG_REV_AUTHOR_DATE
:
115 this->m_AuthorDate
=ConverFromString(text
);
117 case LOG_REV_COMMIT_NAME
:
118 this->m_CommitterName
= text
;
120 case LOG_REV_COMMIT_EMAIL
:
121 this->m_CommitterEmail
= text
;
123 case LOG_REV_COMMIT_DATE
:
124 this->m_CommitterDate
=ConverFromString(text
);
126 case LOG_REV_COMMIT_SUBJECT
:
127 this->m_Subject
= text
;
129 case LOG_REV_COMMIT_BODY
:
130 this->m_Body
= text
+_T("\n");
132 case LOG_REV_COMMIT_HASH
:
133 this->m_CommitHash
= text
.Right(40);
134 if(text
.GetLength()>40)
136 this->m_Mark
=text
[0];
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);
148 if(m_ParentHash
.size()>1)
153 case LOG_REV_COMMIT_FILE
:
160 // case LOG_REV_COMMIT_BODY:
161 // this->m_Body += one+_T("\n");
163 case LOG_REV_COMMIT_FILE
:
164 //filelist += one +_T("\n");
165 //filelist.append(log,pos,log.find(0,pos));
177 //find next string start
178 pos
=log
.findNextString(pos
);
184 filelist
.append(log
,filebegin
,pos
);
185 this->m_Files
.ParserFromLog(filelist
);
186 this->m_Action
=this->m_Files
.GetAction();
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)),
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));
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
219 // get local timezone
221 tm
.GetAsSystemTime( sysTime
);
223 if ( SystemTimeToTzSpecificLocalTime( &m_TimeZone
, &sysTime
, &local
) )
231 tm
= CTime( sysTime
, 0 );
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
);