OSDN Git Service

Share resource file between TortoiseGitBlame and TortoiseProc
[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(CString &log)\r
57 {\r
58         int pos=0;\r
59         CString one;\r
60         CString key;\r
61         CString text;\r
62         CString filelist;\r
63         TCHAR mode=0;\r
64         CTGitPath  path;\r
65         this->m_Files.Clear();\r
66     m_Action=0;\r
67 \r
68         while( pos>=0 )\r
69         {\r
70                 one=log.Tokenize(_T("\n"),pos);\r
71                 if(one[0]==_T('#') && one[1] == _T('<') && one[3] == _T('>'))\r
72                 {\r
73                         text = one.Right(one.GetLength()-4);\r
74                         mode = one[2];\r
75                         switch(mode)\r
76                         {\r
77                         case LOG_REV_ITEM_BEGIN:\r
78                                 this->Clear();\r
79 \r
80                         case LOG_REV_AUTHOR_NAME:\r
81                                 this->m_AuthorName = text;\r
82                                 break;\r
83                         case LOG_REV_AUTHOR_EMAIL:\r
84                                 this->m_AuthorEmail = text;\r
85                                 break;\r
86                         case LOG_REV_AUTHOR_DATE:\r
87                                 this->m_AuthorDate =ConverFromString(text);\r
88                                 break;\r
89                         case LOG_REV_COMMIT_NAME:\r
90                                 this->m_CommitterName = text;\r
91                                 break;\r
92                         case LOG_REV_COMMIT_EMAIL:\r
93                                 this->m_CommitterEmail = text;\r
94                                 break;\r
95                         case LOG_REV_COMMIT_DATE:\r
96                                 this->m_CommitterDate =ConverFromString(text);\r
97                                 break;\r
98                         case LOG_REV_COMMIT_SUBJECT:\r
99                                 this->m_Subject = text;\r
100                                 break;\r
101                         case LOG_REV_COMMIT_BODY:\r
102                                 this->m_Body = text +_T("\n");\r
103                                 break;\r
104                         case LOG_REV_COMMIT_HASH:\r
105                                 this->m_CommitHash = text.Right(40);\r
106                                 if(text.GetLength()>40)\r
107                                 {\r
108                                         this->m_Mark=text[0];\r
109                                 }\r
110                                 break;\r
111                         case LOG_REV_COMMIT_PARENT:\r
112                                 while(text.GetLength()>0)\r
113                                 {\r
114                                         this->m_ParentHash.insert(this->m_ParentHash.end(),text.Left(40));\r
115                                         if(text.GetLength()>40)\r
116                                                 text=text.Right(text.GetLength()-41);\r
117                                         else\r
118                                                 break;\r
119                                 }\r
120                                 break;\r
121                         case LOG_REV_COMMIT_FILE:\r
122                                 break;\r
123                         }\r
124                 }else\r
125                 {\r
126                         switch(mode)\r
127                         {\r
128                         case LOG_REV_COMMIT_BODY:\r
129                                 this->m_Body += one+_T("\n");\r
130                                 break;\r
131                         case LOG_REV_COMMIT_FILE:\r
132                                 filelist += one +_T("\n");\r
133                                 break;\r
134                         }\r
135                 }\r
136         }\r
137         \r
138         this->m_Files.ParserFromLog(filelist);\r
139         this->m_Action=this->m_Files.GetAction();\r
140         return 0;\r
141 }\r
142 \r
143 CTime GitRev::ConverFromString(CString input)\r
144 {\r
145         CTime tm(_wtoi(input.Mid(0,4)),\r
146                          _wtoi(input.Mid(5,2)),\r
147                          _wtoi(input.Mid(8,2)),\r
148                          _wtoi(input.Mid(11,2)),\r
149                          _wtoi(input.Mid(14,2)),\r
150                          _wtoi(input.Mid(17,2)),\r
151                          _wtoi(input.Mid(20,4)));\r
152         return tm;\r
153 }\r
154 \r
155 int GitRev::SafeFetchFullInfo(CGit *git)\r
156 {\r
157         if(InterlockedExchange(&m_IsUpdateing,TRUE) == FALSE)\r
158         {\r
159                 //GitRev rev;\r
160                 CString onelog;\r
161                 TCHAR oldmark=this->m_Mark;\r
162         \r
163                 git->GetLog(onelog,m_CommitHash,NULL,1);\r
164                 CString oldhash=m_CommitHash;\r
165                 ParserFromLog(onelog);\r
166                 \r
167                 //ASSERT(oldhash==m_CommitHash);\r
168                 if(oldmark!=0)\r
169                         this->m_Mark=oldmark;  //parser full log will cause old mark overwrited. \r
170                                                                //So we need keep old bound mark.\r
171 \r
172                 InterlockedExchange(&m_IsUpdateing,FALSE);\r
173                 InterlockedExchange(&m_IsFull,TRUE);\r
174                 return 0;\r
175         }\r
176         return -1;\r
177 }