1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2012 - TortoiseGit
4 // Copyright (C) 2007-2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 Description: start-up repository opening and reading
23 Author: Marco Costalba (C) 2005-2007
25 Copyright: See COPYING file that comes with this distribution
30 #include "TortoiseProc.h"
31 #include "GitLogListBase.h"
33 //#include "VssStyle.h"
38 #include "GITProgressDlg.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
)
85 // only enable --follow on files
86 if ((path
== NULL
|| path
->IsDirectory()) && (infomask
& CGit::LOG_INFO_FOLLOW
))
87 infomask
= infomask
^ CGit::LOG_INFO_FOLLOW
;
90 CString cmd
=g_Git
.GetLogCmd(hash
,path
,count
,infomask
,from
,to
,true);
92 if (g_Git
.IsOrphanBranch(hash
))
100 if (git_open_log(&handle
,CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
105 catch (char * g_last_error
)
107 MessageBox(NULL
, CString(g_last_error
), _T("TortoiseGit"), MB_ICONERROR
);
111 git_get_log_firstcommit(handle
);
115 while (git_get_log_nextcommit(handle
, &commit
, infomask
& CGit::LOG_INFO_FOLLOW
) == 0)
117 if (commit
.m_ignore
== 1)
119 git_free_commit(&commit
);
123 CGitHash hash
= (char*)commit
.m_hash
;
125 GitRev
*pRev
= this->m_pLogCache
->GetCacheData(hash
);
128 git_get_notes(commit
.m_hash
,¬e
);
131 pRev
->m_Notes
.Empty();
132 g_Git
.StringAppend(&pRev
->m_Notes
,(BYTE
*)note
);
135 if((pRev
== NULL
|| !pRev
->m_IsFull
) && infomask
& CGit::LOG_INFO_FULL_DIFF
)
137 pRev
->ParserFromCommit(&commit
);
138 pRev
->ParserParentFromCommit(&commit
);
139 git_free_commit(&commit
);
140 //Must call free commit before SafeFetchFullInfo, commit parent is rewrite by log.
141 //file list will wrong if parent rewrite.
144 pRev
->SafeFetchFullInfo(&g_Git
);
146 catch (char * g_last_error
)
148 MessageBox(NULL
, _T("Could not fetch full info of a commit.\nlibgit reports:\n") + CString(g_last_error
), _T("TortoiseGit"), MB_ICONERROR
);
154 ASSERT(pRev
->m_CommitHash
== hash
);
155 pRev
->ParserFromCommit(&commit
);
156 pRev
->ParserParentFromCommit(&commit
);
157 git_free_commit(&commit
);
160 this->push_back(pRev
->m_CommitHash
);
162 m_HashMap
[pRev
->m_CommitHash
] = (int)size() - 1;
166 git_close_log(handle
);
171 int AddTolist(unsigned char * /*osha1*/, unsigned char *nsha1
, const char * /*name*/, unsigned long /*time*/, int /*sz*/, const char *msg
, void *data
)
173 CLogDataVector
*vector
= (CLogDataVector
*)data
;
175 rev
.m_CommitHash
=(char*)nsha1
;
178 g_Git
.StringAppend(&one
, (BYTE
*)msg
);
180 int message
=one
.Find(_T(":"),0);
183 rev
.m_RefAction
=one
.Left(message
);
184 rev
.GetSubject()=one
.Mid(message
+1);
187 vector
->m_pLogCache
->m_HashMap
[rev
.m_CommitHash
]=rev
;
188 vector
->insert(vector
->begin(),rev
.m_CommitHash
);
193 int CLogDataVector::ParserFromRefLog(CString ref
)
195 if(g_Git
.m_IsUseGitDLL
)
197 git_for_each_reflog_ent(CUnicodeUtils::GetUTF8(ref
),AddTolist
,this);
198 for(int i
=0;i
<size();i
++)
200 m_pLogCache
->m_HashMap
[at(i
)].m_Ref
.Format(_T("%s{%d}"), ref
,i
);
209 cmd
.Format(_T("git.exe reflog show %s"),ref
);
210 if (g_Git
.Run(cmd
, &out
, NULL
, CP_UTF8
))
216 CString one
=out
.Tokenize(_T("\n"),pos
);
217 int ref
=one
.Find(_T(' '),0);
223 rev
.m_CommitHash
=g_Git
.GetHash(one
.Left(ref
));
224 int action
=one
.Find(_T(' '),ref
+1);
228 rev
.m_Ref
=one
.Mid(ref
+1,action
-ref
-2);
229 message
=one
.Find(_T(":"),action
);
232 rev
.m_RefAction
=one
.Mid(action
+1,message
-action
-1);
233 rev
.GetSubject()=one
.Right(one
.GetLength()-message
-1);
237 this->m_pLogCache
->m_HashMap
[rev
.m_CommitHash
]=rev
;
239 this->push_back(rev
.m_CommitHash
);
246 void CLogDataVector::setLane(CGitHash
& sha
)
248 Lanes
* l
= &(this->m_Lns
);
249 int i
= m_FirstFreeLane
;
251 // QVector<QByteArray> ba;
252 // const ShaString& ss = toPersistentSha(sha, ba);
253 // const ShaVect& shaVec(fh->revOrder);
255 for (int cnt
= (int)size(); i
< cnt
; ++i
) {
257 GitRev
* r
= & this->GetGitRevAt(i
);
258 CGitHash curSha
=r
->m_CommitHash
;
260 if (r
->m_Lanes
.empty())
261 updateLanes(*r
, *l
, curSha
);
266 m_FirstFreeLane
= ++i
;
269 Lanes
* l
= &(this->m_Lanes
);
270 int i
= m_FirstFreeLane
;
272 QVector
<QByteArray
> ba
;
273 const ShaString
& ss
= toPersistentSha(sha
, ba
);
274 const ShaVect
& shaVec(fh
->revOrder
);
276 for (uint cnt
= shaVec
.count(); i
< cnt
; ++i
) {
278 const ShaString
& curSha
= shaVec
[i
];
279 Rev
* r
= m_HashMap
[curSha
]const_cast<Rev
*>(revLookup(curSha
, fh
));
280 if (r
->lanes
.count() == 0)
281 updateLanes(*r
, *l
, curSha
);
286 fh
->firstFreeLane
= ++i
;
291 void CLogDataVector::updateLanes(GitRev
& c
, Lanes
& lns
, CGitHash
&sha
)
293 // we could get third argument from c.sha(), but we are in fast path here
294 // and c.sha() involves a deep copy, so we accept a little redundancy
299 bool isDiscontinuity
;
300 bool isFork
= lns
.isFork(sha
, isDiscontinuity
);
301 bool isMerge
= (c
.ParentsCount() > 1);
302 bool isInitial
= (c
.ParentsCount() == 0);
305 lns
.changeActiveLane(sha
); // uses previous isBoundary state
307 lns
.setBoundary(c
.IsBoundary() == TRUE
); // update must be here
308 TRACE(_T("%s %d"),c
.m_CommitHash
.ToString(),c
.IsBoundary());
313 lns
.setMerge(c
.m_ParentHash
);
319 lns
.getLanes(c
.m_Lanes
); // here lanes are snapshotted
323 nextSha
= c
.m_ParentHash
[0];
325 lns
.nextParent(nextSha
);
328 // lns.afterApplied();
336 // QString tmp = "", tmp2;
337 // for (uint i = 0; i < c.lanes.count(); i++) {
338 // tmp2.setNum(c.lanes[i]);
339 // tmp.append(tmp2 + "-");
341 // qDebug("%s %s",tmp.latin1(), c.sha.latin1());