OSDN Git Service

9955dc73bf0adb0b9e2317057b64b813584d77b9
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / LogDataVector.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control
2
3 // Copyright (C) 2007-2008 - TortoiseSVN
4
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 /*
20         Description: start-up repository opening and reading
21
22         Author: Marco Costalba (C) 2005-2007
23
24         Copyright: See COPYING file that comes with this distribution
25
26 */
27
28 #include "stdafx.h"
29 #include "TortoiseProc.h"
30 #include "GitLogListBase.h"
31 #include "GitRev.h"
32 //#include "VssStyle.h"
33 #include "IconMenu.h"
34 // CGitLogList
35 #include "cursor.h"
36 #include "InputDlg.h"
37 #include "PropDlg.h"
38 #include "SVNProgressDlg.h"
39 #include "ProgressDlg.h"
40 //#include "RepositoryBrowser.h"
41 //#include "CopyDlg.h"
42 //#include "StatGraphDlg.h"
43 #include "Logdlg.h"
44 #include "MessageBox.h"
45 #include "Registry.h"
46 #include "AppUtils.h"
47 #include "PathUtils.h"
48 #include "StringUtils.h"
49 #include "UnicodeUtils.h"
50 #include "TempFile.h"
51 //#include "GitInfo.h"
52 //#include "GitDiff.h"
53 #include "IconMenu.h"
54 //#include "RevisionRangeDlg.h"
55 //#include "BrowseFolder.h"
56 //#include "BlameDlg.h"
57 //#include "Blame.h"
58 //#include "GitHelpers.h"
59 #include "GitStatus.h"
60 //#include "LogDlgHelper.h"
61 //#include "CachedLogInfo.h"
62 //#include "RepositoryInfo.h"
63 //#include "EditPropertiesDlg.h"
64 #include "FileDiffDlg.h"
65
66
67 int CLogDataVector::ParserShortLog(CTGitPath *path ,CString &hash,int count ,int mask )
68 {
69         BYTE_VECTOR log;
70         GitRev rev;
71
72         if(g_Git.IsInitRepos())
73                 return 0;
74
75         CString begin;
76         begin.Format(_T("#<%c>"),LOG_REV_ITEM_BEGIN);
77
78         //g_Git.GetShortLog(log,path,count);
79
80         g_Git.GetLog(log,hash,path,count,mask);
81
82         if(log.size()==0)
83                 return 0;
84         
85         int start=4;
86         int length;
87         int next =0;
88         while( next>=0 && next<log.size())
89         {
90                 next=rev.ParserFromLog(log,next);
91
92                 rev.m_Subject=_T("Load .................................");
93                 this->push_back(rev);
94                 m_HashMap[rev.m_CommitHash]=size()-1;
95
96                 //next=log.find(0,next);
97         }
98
99         return 0;
100
101 }
102 int CLogDataVector::FetchFullInfo(int i)
103 {
104         return at(i).SafeFetchFullInfo(&g_Git);
105 }
106 //CLogDataVector Class
107 int CLogDataVector::ParserFromLog(CTGitPath *path ,int count ,int infomask,CString *from,CString *to)
108 {
109         BYTE_VECTOR log;
110         GitRev rev;
111         CString emptyhash;
112         g_Git.GetLog(log,emptyhash,path,count,infomask,from,to);
113
114         CString begin;
115         begin.Format(_T("#<%c>"),LOG_REV_ITEM_BEGIN);
116         
117         if(log.size()==0)
118                 return 0;
119         
120         int start=4;
121         int length;
122         int next =0;
123         while( next>=0 )
124         {
125                 next=rev.ParserFromLog(log,next);
126                 this->push_back(rev);
127                 m_HashMap[rev.m_CommitHash]=size()-1;           
128         }
129
130         return 0;
131 }
132
133 int CLogDataVector::ParserFromRefLog(CString ref)
134 {
135         CString cmd,out;
136         GitRev rev;
137         cmd.Format(_T("git.exe reflog show %s"),ref);
138         if(g_Git.Run(cmd,&out,CP_UTF8))
139                 return -1;
140         
141         int pos=0;
142         while(pos>=0)
143         {
144                 CString one=out.Tokenize(_T("\n"),pos);
145                 int ref=one.Find(_T(' '),0);
146                 if(ref<0)
147                         continue;
148
149                 rev.m_CommitHash=one.Left(ref);
150                 int action=one.Find(_T(' '),ref+1);
151                 int message;
152                 if(action>0)
153                 {
154                         rev.m_Ref=one.Mid(ref+1,action-ref-2);
155                         message=one.Find(_T(":"),action);
156                         if(message>0)
157                         {
158                                 rev.m_RefAction=one.Mid(action+1,message-action-1);
159                                 rev.m_Subject=one.Right(one.GetLength()-message-1);
160                         }
161                 }
162         }
163         return 0;
164 }
165
166 void CLogDataVector::setLane(CString& sha) 
167 {
168         Lanes* l = &(this->m_Lns);
169         int i = m_FirstFreeLane;
170         
171 //      QVector<QByteArray> ba;
172 //      const ShaString& ss = toPersistentSha(sha, ba);
173 //      const ShaVect& shaVec(fh->revOrder);
174
175         for (int cnt = size(); i < cnt; ++i) {
176
177                 GitRev* r = &(*this)[i]; 
178                 CString &curSha=r->m_CommitHash;
179
180                 if (r->m_Lanes.size() == 0)
181                         updateLanes(*r, *l, curSha);
182
183                 if (curSha == sha)
184                         break;
185         }
186         m_FirstFreeLane = ++i;
187
188 #if 0
189         Lanes* l = &(this->m_Lanes);
190         int i = m_FirstFreeLane;
191         
192         QVector<QByteArray> ba;
193         const ShaString& ss = toPersistentSha(sha, ba);
194         const ShaVect& shaVec(fh->revOrder);
195
196         for (uint cnt = shaVec.count(); i < cnt; ++i) {
197
198                 const ShaString& curSha = shaVec[i];
199                 Rev* r = m_HashMap[curSha]const_cast<Rev*>(revLookup(curSha, fh));
200                 if (r->lanes.count() == 0)
201                         updateLanes(*r, *l, curSha);
202
203                 if (curSha == ss)
204                         break;
205         }
206         fh->firstFreeLane = ++i;
207 #endif
208 }
209
210
211 void CLogDataVector::updateLanes(GitRev& c, Lanes& lns, CString &sha) 
212 {
213 // we could get third argument from c.sha(), but we are in fast path here
214 // and c.sha() involves a deep copy, so we accept a little redundancy
215
216         if (lns.isEmpty())
217                 lns.init(sha);
218
219         bool isDiscontinuity;
220         bool isFork = lns.isFork(sha, isDiscontinuity);
221         bool isMerge = (c.ParentsCount() > 1);
222         bool isInitial = (c.ParentsCount() == 0);
223
224         if (isDiscontinuity)
225                 lns.changeActiveLane(sha); // uses previous isBoundary state
226
227         lns.setBoundary(c.IsBoundary() == TRUE); // update must be here
228         TRACE(_T("%s %d"),c.m_CommitHash,c.IsBoundary());
229
230         if (isFork)
231                 lns.setFork(sha);
232         if (isMerge)
233                 lns.setMerge(c.m_ParentHash);
234         //if (c.isApplied)
235         //      lns.setApplied();
236         if (isInitial)
237                 lns.setInitial();
238
239         lns.getLanes(c.m_Lanes); // here lanes are snapshotted
240
241         CString nextSha = (isInitial) ? CString(_T("")) : QString(c.m_ParentHash[0]);
242
243         lns.nextParent(nextSha);
244
245         //if (c.isApplied)
246         //      lns.afterApplied();
247         if (isMerge)
248                 lns.afterMerge();
249         if (isFork)
250                 lns.afterFork();
251         if (lns.isBranch())
252                 lns.afterBranch();
253
254 //      QString tmp = "", tmp2;
255 //      for (uint i = 0; i < c.lanes.count(); i++) {
256 //              tmp2.setNum(c.lanes[i]);
257 //              tmp.append(tmp2 + "-");
258 //      }
259 //      qDebug("%s %s",tmp.latin1(), c.sha.latin1());
260 }