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"
68 void CLogDataVector::ClearAll()
79 m_RawLogStart
.clear();
82 //CLogDataVector Class
83 int CLogDataVector::ParserFromLog(CTGitPath
*path
,int count
,int infomask
,CString
*from
,CString
*to
)
86 CString cmd
=g_Git
.GetLogCmd(hash
,path
,count
,infomask
,from
,to
,true);
88 if(g_Git
.IsInitRepos())
94 if(git_open_log(&handle
,CUnicodeUtils::GetMulti(cmd
,CP_ACP
).GetBuffer()))
99 git_get_log_firstcommit(handle
);
105 while( git_get_log_nextcommit(handle
,&commit
) == 0)
108 CGitHash hash
= (char*)commit
.m_hash
;
111 GitRev
*pRev
= this->m_pLogCache
->GetCacheData(hash
);
114 git_get_notes(commit
.m_hash
,¬e
);
117 pRev
->m_Notes
.Empty();
118 g_Git
.StringAppend(&pRev
->m_Notes
,(BYTE
*)note
);
121 if(pRev
== NULL
|| !pRev
->m_IsFull
)
123 pRev
->ParserFromCommit(&commit
);
124 pRev
->ParserParentFromCommit(&commit
);
125 git_free_commit(&commit
);
126 //Must call free commit before SafeFetchFullInfo, commit parent is rewrite by log.
127 //file list will wrong if parent rewrite.
128 pRev
->SafeFetchFullInfo(&g_Git
);
133 ASSERT(pRev
->m_CommitHash
== hash
);
134 pRev
->ParserParentFromCommit(&commit
);
135 git_free_commit(&commit
);
138 this->push_back(pRev
->m_CommitHash
);
140 m_HashMap
[rev
.m_CommitHash
]=size()-1;
144 git_close_log(handle
);
149 int AddTolist(unsigned char * /*osha1*/, unsigned char *nsha1
, const char * /*name*/, unsigned long /*time*/, int /*sz*/, const char *msg
, void *data
)
151 CLogDataVector
*vector
= (CLogDataVector
*)data
;
153 rev
.m_CommitHash
=(char*)nsha1
;
156 g_Git
.StringAppend(&one
, (BYTE
*)msg
);
158 int message
=one
.Find(_T(":"),0);
161 rev
.m_RefAction
=one
.Left(message
);
162 rev
.GetSubject()=one
.Mid(message
+1);
165 vector
->m_pLogCache
->m_HashMap
[rev
.m_CommitHash
]=rev
;
166 vector
->insert(vector
->begin(),rev
.m_CommitHash
);
171 int CLogDataVector::ParserFromRefLog(CString ref
)
173 if(g_Git
.m_IsUseGitDLL
)
175 git_for_each_reflog_ent(CUnicodeUtils::GetUTF8(ref
),AddTolist
,this);
176 for(int i
=0;i
<size();i
++)
178 m_pLogCache
->m_HashMap
[at(i
)].m_Ref
.Format(_T("%s{%d}"), ref
,i
);
187 cmd
.Format(_T("git.exe reflog show %s"),ref
);
188 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
194 CString one
=out
.Tokenize(_T("\n"),pos
);
195 int ref
=one
.Find(_T(' '),0);
201 rev
.m_CommitHash
=g_Git
.GetHash(one
.Left(ref
));
202 int action
=one
.Find(_T(' '),ref
+1);
206 rev
.m_Ref
=one
.Mid(ref
+1,action
-ref
-2);
207 message
=one
.Find(_T(":"),action
);
210 rev
.m_RefAction
=one
.Mid(action
+1,message
-action
-1);
211 rev
.GetSubject()=one
.Right(one
.GetLength()-message
-1);
215 this->m_pLogCache
->m_HashMap
[rev
.m_CommitHash
]=rev
;
217 this->push_back(rev
.m_CommitHash
);
224 void CLogDataVector::setLane(CGitHash
& sha
)
226 Lanes
* l
= &(this->m_Lns
);
227 int i
= m_FirstFreeLane
;
229 // QVector<QByteArray> ba;
230 // const ShaString& ss = toPersistentSha(sha, ba);
231 // const ShaVect& shaVec(fh->revOrder);
233 for (int cnt
= size(); i
< cnt
; ++i
) {
235 GitRev
* r
= & this->GetGitRevAt(i
);
236 CGitHash curSha
=r
->m_CommitHash
;
238 if (r
->m_Lanes
.size() == 0)
239 updateLanes(*r
, *l
, curSha
);
244 m_FirstFreeLane
= ++i
;
247 Lanes
* l
= &(this->m_Lanes
);
248 int i
= m_FirstFreeLane
;
250 QVector
<QByteArray
> ba
;
251 const ShaString
& ss
= toPersistentSha(sha
, ba
);
252 const ShaVect
& shaVec(fh
->revOrder
);
254 for (uint cnt
= shaVec
.count(); i
< cnt
; ++i
) {
256 const ShaString
& curSha
= shaVec
[i
];
257 Rev
* r
= m_HashMap
[curSha
]const_cast<Rev
*>(revLookup(curSha
, fh
));
258 if (r
->lanes
.count() == 0)
259 updateLanes(*r
, *l
, curSha
);
264 fh
->firstFreeLane
= ++i
;
269 void CLogDataVector::updateLanes(GitRev
& c
, Lanes
& lns
, CGitHash
&sha
)
271 // we could get third argument from c.sha(), but we are in fast path here
272 // and c.sha() involves a deep copy, so we accept a little redundancy
277 bool isDiscontinuity
;
278 bool isFork
= lns
.isFork(sha
, isDiscontinuity
);
279 bool isMerge
= (c
.ParentsCount() > 1);
280 bool isInitial
= (c
.ParentsCount() == 0);
283 lns
.changeActiveLane(sha
); // uses previous isBoundary state
285 lns
.setBoundary(c
.IsBoundary() == TRUE
); // update must be here
286 TRACE(_T("%s %d"),c
.m_CommitHash
.ToString(),c
.IsBoundary());
291 lns
.setMerge(c
.m_ParentHash
);
297 lns
.getLanes(c
.m_Lanes
); // here lanes are snapshotted
301 nextSha
= c
.m_ParentHash
[0];
303 lns
.nextParent(nextSha
);
306 // lns.afterApplied();
314 // QString tmp = "", tmp2;
315 // for (uint i = 0; i < c.lanes.count(); i++) {
316 // tmp2.setNum(c.lanes[i]);
317 // tmp.append(tmp2 + "-");
319 // qDebug("%s %s",tmp.latin1(), c.sha.latin1());