1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2007-2008 - TortoiseSVN
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.
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.
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.
20 Description: start-up repository opening and reading
22 Author: Marco Costalba (C) 2005-2007
24 Copyright: See COPYING file that comes with this distribution
29 #include "TortoiseProc.h"
30 #include "GitLogListBase.h"
32 //#include "VssStyle.h"
38 #include "SVNProgressDlg.h"
39 #include "ProgressDlg.h"
40 //#include "RepositoryBrowser.h"
41 //#include "CopyDlg.h"
42 //#include "StatGraphDlg.h"
44 #include "MessageBox.h"
47 #include "PathUtils.h"
48 #include "StringUtils.h"
49 #include "UnicodeUtils.h"
51 //#include "GitInfo.h"
52 //#include "GitDiff.h"
54 //#include "RevisionRangeDlg.h"
55 //#include "BrowseFolder.h"
56 //#include "BlameDlg.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"
66 void CLogDataVector::ClearAll()
77 m_RawLogStart
.clear();
80 int CLogDataVector::ParserShortLog(CTGitPath
*path
,CString
&hash
,int count
,int mask
)
85 if(g_Git
.IsInitRepos())
89 begin
.Format(_T("#<%c>"),LOG_REV_ITEM_BEGIN
);
91 //g_Git.GetShortLog(log,path,count);
93 g_Git
.GetLog(log
,hash
,path
,count
,mask
);
101 while( next
>=0 && next
<log
.size())
103 next
=rev
.ParserFromLog(log
,next
);
105 rev
.m_Subject
=_T("Load .................................");
106 this->push_back(rev
);
107 m_HashMap
[rev
.m_CommitHash
]=size()-1;
109 //next=log.find(0,next);
115 int CLogDataVector::FetchShortLog(CTGitPath
*path
,CString
&hash
,int count
,int mask
, int ShowWC
)
118 m_RawlogData
.clear();
119 m_RawLogStart
.clear();
123 if(g_Git
.IsInitRepos())
127 begin
.Format(_T("#<%c>"),LOG_REV_ITEM_BEGIN
);
129 //g_Git.GetShortLog(log,path,count);
132 g_Git
.GetLog(m_RawlogData
, hash
,path
,count
,mask
);
135 TRACE(_T("GetLog Time %ld\r\n"),t2
-t1
);
137 if(m_RawlogData
.size()==0)
146 while( next
>=0 && next
<m_RawlogData
.size())
148 static const BYTE dataToFind
[]={0,0};
149 m_RawLogStart
.push_back(next
);
150 //this->at(i).m_Subject=_T("parser...");
151 next
=m_RawlogData
.findData(dataToFind
,2,next
+1);
152 //next=log.find(0,next);
155 resize(m_RawLogStart
.size() + ShowWC
);
161 int CLogDataVector::FetchFullInfo(int i
)
163 return at(i
).SafeFetchFullInfo(&g_Git
);
165 //CLogDataVector Class
166 int CLogDataVector::ParserFromLog(CTGitPath
*path
,int count
,int infomask
,CString
*from
,CString
*to
)
171 g_Git
.GetLog(log
,emptyhash
,path
,count
,infomask
,from
,to
);
174 begin
.Format(_T("#<%c>"),LOG_REV_ITEM_BEGIN
);
184 next
=rev
.ParserFromLog(log
,next
);
185 this->push_back(rev
);
186 m_HashMap
[rev
.m_CommitHash
]=size()-1;
192 int CLogDataVector::ParserFromRefLog(CString ref
)
196 cmd
.Format(_T("git.exe reflog show %s"),ref
);
197 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
203 CString one
=out
.Tokenize(_T("\n"),pos
);
204 int ref
=one
.Find(_T(' '),0);
210 rev
.m_CommitHash
=one
.Left(ref
);
211 int action
=one
.Find(_T(' '),ref
+1);
215 rev
.m_Ref
=one
.Mid(ref
+1,action
-ref
-2);
216 message
=one
.Find(_T(":"),action
);
219 rev
.m_RefAction
=one
.Mid(action
+1,message
-action
-1);
220 rev
.m_Subject
=one
.Right(one
.GetLength()-message
-1);
223 this->push_back(rev
);
228 void CLogDataVector::setLane(CString
& sha
)
230 Lanes
* l
= &(this->m_Lns
);
231 int i
= m_FirstFreeLane
;
233 // QVector<QByteArray> ba;
234 // const ShaString& ss = toPersistentSha(sha, ba);
235 // const ShaVect& shaVec(fh->revOrder);
237 for (int cnt
= size(); i
< cnt
; ++i
) {
239 GitRev
* r
= &(*this)[i
];
240 CString
&curSha
=r
->m_CommitHash
;
242 if (r
->m_Lanes
.size() == 0)
243 updateLanes(*r
, *l
, curSha
);
248 m_FirstFreeLane
= ++i
;
251 Lanes
* l
= &(this->m_Lanes
);
252 int i
= m_FirstFreeLane
;
254 QVector
<QByteArray
> ba
;
255 const ShaString
& ss
= toPersistentSha(sha
, ba
);
256 const ShaVect
& shaVec(fh
->revOrder
);
258 for (uint cnt
= shaVec
.count(); i
< cnt
; ++i
) {
260 const ShaString
& curSha
= shaVec
[i
];
261 Rev
* r
= m_HashMap
[curSha
]const_cast<Rev
*>(revLookup(curSha
, fh
));
262 if (r
->lanes
.count() == 0)
263 updateLanes(*r
, *l
, curSha
);
268 fh
->firstFreeLane
= ++i
;
273 void CLogDataVector::updateLanes(GitRev
& c
, Lanes
& lns
, CString
&sha
)
275 // we could get third argument from c.sha(), but we are in fast path here
276 // and c.sha() involves a deep copy, so we accept a little redundancy
281 bool isDiscontinuity
;
282 bool isFork
= lns
.isFork(sha
, isDiscontinuity
);
283 bool isMerge
= (c
.ParentsCount() > 1);
284 bool isInitial
= (c
.ParentsCount() == 0);
287 lns
.changeActiveLane(sha
); // uses previous isBoundary state
289 lns
.setBoundary(c
.IsBoundary() == TRUE
); // update must be here
290 TRACE(_T("%s %d"),c
.m_CommitHash
,c
.IsBoundary());
295 lns
.setMerge(c
.m_ParentHash
);
301 lns
.getLanes(c
.m_Lanes
); // here lanes are snapshotted
303 CString nextSha
= (isInitial
) ? CString(_T("")) : QString(c
.m_ParentHash
[0]);
305 lns
.nextParent(nextSha
);
308 // lns.afterApplied();
316 // QString tmp = "", tmp2;
317 // for (uint i = 0; i < c.lanes.count(); i++) {
318 // tmp2.setNum(c.lanes[i]);
319 // tmp.append(tmp2 + "-");
321 // qDebug("%s %s",tmp.latin1(), c.sha.latin1());