OSDN Git Service

Use new method to update log So the user don't wait for log full log
[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 \r
37 }\r
38 int GitRev::CopyFrom(GitRev &rev)\r
39 {\r
40         m_AuthorName    =rev.m_AuthorName       ;\r
41         m_AuthorEmail   =rev.m_AuthorEmail      ;\r
42         m_AuthorDate    =rev.m_AuthorDate       ;\r
43         m_CommitterName =rev.m_CommitterName    ;\r
44         m_CommitterEmail=rev.m_CommitterEmail;\r
45         m_CommitterDate =rev.m_CommitterDate    ;\r
46         m_Subject               =rev.m_Subject          ;\r
47         m_Body                  =rev.m_Body                     ;\r
48         m_CommitHash    =rev.m_CommitHash       ;\r
49         m_ParentHash    =rev.m_ParentHash       ;\r
50         m_Files                 =rev.m_Files                    ;       \r
51         m_Action                =rev.m_Action           ;\r
52         return 0;\r
53 }\r
54 int GitRev::ParserFromLog(CString &log)\r
55 {\r
56         int pos=0;\r
57         CString one;\r
58         CString key;\r
59         CString text;\r
60         CString filelist;\r
61         TCHAR mode;\r
62         CTGitPath  path;\r
63         this->m_Files.Clear();\r
64     m_Action=0;\r
65 \r
66         while( pos>=0 )\r
67         {\r
68                 one=log.Tokenize(_T("\n"),pos);\r
69                 if(one[0]==_T('#') && one[1] == _T('<') && one[3] == _T('>'))\r
70                 {\r
71                         text = one.Right(one.GetLength()-4);\r
72                         mode = one[2];\r
73                         switch(mode)\r
74                         {\r
75                         case LOG_REV_ITEM_BEGIN:\r
76                                 this->Clear();\r
77 \r
78                         case LOG_REV_AUTHOR_NAME:\r
79                                 this->m_AuthorName = text;\r
80                                 break;\r
81                         case LOG_REV_AUTHOR_EMAIL:\r
82                                 this->m_AuthorEmail = text;\r
83                                 break;\r
84                         case LOG_REV_AUTHOR_DATE:\r
85                                 this->m_AuthorDate =ConverFromString(text);\r
86                                 break;\r
87                         case LOG_REV_COMMIT_NAME:\r
88                                 this->m_CommitterName = text;\r
89                                 break;\r
90                         case LOG_REV_COMMIT_EMAIL:\r
91                                 this->m_CommitterEmail = text;\r
92                                 break;\r
93                         case LOG_REV_COMMIT_DATE:\r
94                                 this->m_CommitterDate =ConverFromString(text);\r
95                                 break;\r
96                         case LOG_REV_COMMIT_SUBJECT:\r
97                                 this->m_Subject = text;\r
98                                 break;\r
99                         case LOG_REV_COMMIT_BODY:\r
100                                 this->m_Body = text +_T("\n");\r
101                                 break;\r
102                         case LOG_REV_COMMIT_HASH:\r
103                                 this->m_CommitHash = text;\r
104                                 break;\r
105                         case LOG_REV_COMMIT_PARENT:\r
106                                 this->m_ParentHash.insert(this->m_ParentHash.end(),text);\r
107                                 break;\r
108                         case LOG_REV_COMMIT_FILE:\r
109                                 break;\r
110                         }\r
111                 }else\r
112                 {\r
113                         switch(mode)\r
114                         {\r
115                         case LOG_REV_COMMIT_BODY:\r
116                                 this->m_Body += one+_T("\n");\r
117                                 break;\r
118                         case LOG_REV_COMMIT_FILE:\r
119                                 filelist += one +_T("\n");\r
120                                 break;\r
121                         }\r
122                 }\r
123         }\r
124         \r
125         this->m_Files.ParserFromLog(filelist);\r
126         this->m_Action=this->m_Files.GetAction();\r
127         return 0;\r
128 }\r
129 \r
130 CTime GitRev::ConverFromString(CString input)\r
131 {\r
132         CTime tm(_wtoi(input.Mid(0,4)),\r
133                          _wtoi(input.Mid(5,2)),\r
134                          _wtoi(input.Mid(8,2)),\r
135                          _wtoi(input.Mid(11,2)),\r
136                          _wtoi(input.Mid(14,2)),\r
137                          _wtoi(input.Mid(17,2)),\r
138                          _wtoi(input.Mid(20,4)));\r
139         return tm;\r
140 }\r
141 \r
142 int GitRev::SafeFetchFullInfo(CGit *git)\r
143 {\r
144         if(InterlockedExchange(&m_IsUpdateing,TRUE) == FALSE)
145         {
146                 //GitRev rev;
147                 CString onelog;
148                 git->GetLog(onelog,m_CommitHash,1);
149                 CString oldhash=m_CommitHash;
150                 ParserFromLog(onelog);
151                 
152                 ASSERT(oldhash==m_CommitHash);
153
154                 InterlockedExchange(&m_IsUpdateing,FALSE);
155                 InterlockedExchange(&m_IsFull,TRUE);
156                 return 0;
157         }
158         return -1;\r
159 }