OSDN Git Service

Remove IBugTraqProvider intermediate files from repository
[tortoisegit/TortoiseGitJp.git] / src / Git / GitRev.cpp
1 #include "StdAfx.h"\r
2 #include "GitRev.h"\r
3 #include "Git.h"\r
4 \r
5 GitRev::GitRev(void)\r
6 {\r
7         m_Action=0;\r
8         m_IsFull = 0;\r
9         m_IsUpdateing = 0;\r
10 }\r
11 \r
12 GitRev::~GitRev(void)\r
13 {\r
14 }\r
15 \r
16 #if 0\r
17 GitRev::GitRev(GitRev & rev)\r
18 {\r
19 }\r
20 GitRev& GitRev::operator=(GitRev &rev)\r
21 {\r
22         return *this;\r
23 }\r
24 #endif\r
25 void GitRev::Clear()\r
26 {\r
27         this->m_Action=0;\r
28         this->m_Files.Clear();\r
29         this->m_Action=0;\r
30         this->m_ParentHash.clear();\r
31         m_CommitterName.Empty();\r
32         m_CommitterEmail.Empty();\r
33         m_Body.Empty();\r
34         m_Subject.Empty();\r
35         m_CommitHash.Empty();\r
36         m_Mark=0;\r
37 \r
38 }\r
39 int GitRev::CopyFrom(GitRev &rev)\r
40 {\r
41         m_AuthorName    =rev.m_AuthorName       ;\r
42         m_AuthorEmail   =rev.m_AuthorEmail      ;\r
43         m_AuthorDate    =rev.m_AuthorDate       ;\r
44         m_CommitterName =rev.m_CommitterName    ;\r
45         m_CommitterEmail=rev.m_CommitterEmail;\r
46         m_CommitterDate =rev.m_CommitterDate    ;\r
47         m_Subject               =rev.m_Subject          ;\r
48         m_Body                  =rev.m_Body                     ;\r
49         m_CommitHash    =rev.m_CommitHash       ;\r
50         m_ParentHash    =rev.m_ParentHash       ;\r
51         m_Files                 =rev.m_Files                    ;       \r
52         m_Action                =rev.m_Action           ;\r
53         m_Mark                  =rev.m_Mark;\r
54         return 0;\r
55 }\r
56 int GitRev::ParserFromLog(BYTE_VECTOR &log,int start)\r
57 {\r
58         int pos=start;\r
59         CString one;\r
60         CString key;\r
61         CString text;\r
62         BYTE_VECTOR filelist;\r
63         BYTE mode=0;\r
64         CTGitPath  path;\r
65         this->m_Files.Clear();\r
66     m_Action=0;\r
67         int begintime=0;\r
68         BYTE *p=&log[0];\r
69         int filebegin=-1;\r
70 \r
71         while( pos < log.size() && pos>=0)\r
72         {\r
73                 \r
74                 //one=log.Tokenize(_T("\n"),pos);\r
75                 if(log[pos]==_T('#') && log[pos+1] == _T('<') && log[pos+3] == _T('>'))\r
76                 {\r
77                         //text = one.Right(one.GetLength()-4);\r
78                         text.Empty();\r
79                         g_Git.StringAppend(&text,&log[pos+4],CP_UTF8);\r
80                         mode = log[pos+2];\r
81                         \r
82                         switch(mode)\r
83                         {\r
84                         case LOG_REV_ITEM_BEGIN:\r
85                                 begintime++;\r
86                                 if(begintime>1)\r
87                                         break;\r
88                                 else\r
89                                         this->Clear();\r
90                                 break;\r
91                         case LOG_REV_AUTHOR_NAME:\r
92                                 this->m_AuthorName = text;\r
93                                 break;\r
94                         case LOG_REV_AUTHOR_EMAIL:\r
95                                 this->m_AuthorEmail = text;\r
96                                 break;\r
97                         case LOG_REV_AUTHOR_DATE:\r
98                                 this->m_AuthorDate =ConverFromString(text);\r
99                                 break;\r
100                         case LOG_REV_COMMIT_NAME:\r
101                                 this->m_CommitterName = text;\r
102                                 break;\r
103                         case LOG_REV_COMMIT_EMAIL:\r
104                                 this->m_CommitterEmail = text;\r
105                                 break;\r
106                         case LOG_REV_COMMIT_DATE:\r
107                                 this->m_CommitterDate =ConverFromString(text);\r
108                                 break;\r
109                         case LOG_REV_COMMIT_SUBJECT:\r
110                                 this->m_Subject = text;\r
111                                 break;\r
112                         case LOG_REV_COMMIT_BODY:\r
113                                 this->m_Body = text +_T("\n");\r
114                                 break;\r
115                         case LOG_REV_COMMIT_HASH:\r
116                                 this->m_CommitHash = text.Right(40);\r
117                                 if(text.GetLength()>40)\r
118                                 {\r
119                                         this->m_Mark=text[0];\r
120                                 }\r
121                                 break;\r
122                         case LOG_REV_COMMIT_PARENT:\r
123                                 while(text.GetLength()>0)\r
124                                 {\r
125                                         this->m_ParentHash.insert(this->m_ParentHash.end(),text.Left(40));\r
126                                         if(text.GetLength()>40)\r
127                                                 text=text.Right(text.GetLength()-41);\r
128                                         else\r
129                                                 break;\r
130                                 }\r
131                                 break;\r
132                         case LOG_REV_COMMIT_FILE:\r
133                                 break;\r
134                         }\r
135                 }else\r
136                 {\r
137                         switch(mode)\r
138                         {\r
139 //                      case LOG_REV_COMMIT_BODY:\r
140 //                              this->m_Body += one+_T("\n");\r
141 //                              break;\r
142                         case LOG_REV_COMMIT_FILE:\r
143                                 //filelist += one +_T("\n");\r
144                                 //filelist.append(log,pos,log.find(0,pos));\r
145                                 if(filebegin<0)\r
146                                         filebegin=pos;\r
147                                 break;\r
148                         }\r
149                 }\r
150                 \r
151                 if(begintime>1)\r
152                 {\r
153                         break;\r
154                 }\r
155 \r
156                 //find next string start \r
157                 pos=log.findNextString(pos);\r
158         }\r
159         \r
160         if(filebegin>=0)\r
161         {\r
162                 filelist.append(log,filebegin,pos);     \r
163                 this->m_Files.ParserFromLog(filelist);\r
164                 this->m_Action=this->m_Files.GetAction();\r
165         }\r
166         return pos;\r
167 }\r
168 \r
169 CTime GitRev::ConverFromString(CString input)\r
170 {\r
171         CTime tm(_wtoi(input.Mid(0,4)),\r
172                          _wtoi(input.Mid(5,2)),\r
173                          _wtoi(input.Mid(8,2)),\r
174                          _wtoi(input.Mid(11,2)),\r
175                          _wtoi(input.Mid(14,2)),\r
176                          _wtoi(input.Mid(17,2)),\r
177                          _wtoi(input.Mid(20,4)));\r
178         return tm;\r
179 }\r
180 \r
181 int GitRev::SafeFetchFullInfo(CGit *git)\r
182 {\r
183         if(InterlockedExchange(&m_IsUpdateing,TRUE) == FALSE)\r
184         {\r
185                 //GitRev rev;\r
186                 BYTE_VECTOR onelog;\r
187                 TCHAR oldmark=this->m_Mark;\r
188         \r
189                 git->GetLog(onelog,m_CommitHash,NULL,1,CGit::LOG_INFO_STAT|CGit::LOG_INFO_FILESTATE|CGit::LOG_INFO_DETECT_COPYRENAME);\r
190                 CString oldhash=m_CommitHash;\r
191                 GIT_REV_LIST oldlist=this->m_ParentHash;\r
192                 ParserFromLog(onelog);\r
193                 \r
194                 //ASSERT(oldhash==m_CommitHash);\r
195                 if(oldmark!=0)\r
196                         this->m_Mark=oldmark;  //parser full log will cause old mark overwrited. \r
197                                                                //So we need keep old bound mark.\r
198                 this->m_ParentHash=oldlist;\r
199                 InterlockedExchange(&m_IsUpdateing,FALSE);\r
200                 InterlockedExchange(&m_IsFull,TRUE);\r
201                 return 0;\r
202         }\r
203         return -1;\r
204 }