pulled latest translations from Transifex
[TortoiseGit.git] / src / TortoiseProc / LogDataVector.cpp
blob4a8c6057d61e6f1f59bb5b4cef96b1b2251553ba
1 // TortoiseGit - 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
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 "GITProgressDlg.h"
38 #include "ProgressDlg.h"
39 //#include "RepositoryBrowser.h"
40 //#include "CopyDlg.h"
41 //#include "StatGraphDlg.h"
42 #include "Logdlg.h"
43 #include "MessageBox.h"
44 #include "Registry.h"
45 #include "AppUtils.h"
46 #include "PathUtils.h"
47 #include "StringUtils.h"
48 #include "UnicodeUtils.h"
49 #include "TempFile.h"
50 //#include "GitInfo.h"
51 //#include "GitDiff.h"
52 #include "IconMenu.h"
53 //#include "RevisionRangeDlg.h"
54 //#include "BrowseFolder.h"
55 //#include "BlameDlg.h"
56 //#include "Blame.h"
57 //#include "GitHelpers.h"
58 #include "GitStatus.h"
59 //#include "LogDlgHelper.h"
60 //#include "CachedLogInfo.h"
61 //#include "RepositoryInfo.h"
62 //#include "EditPropertiesDlg.h"
63 #include "FileDiffDlg.h"
64 #include "GitHash.h"
65 CGitHashMap a;
67 void CLogDataVector::ClearAll()
70 clear();
71 m_HashMap.clear();
72 m_Lns.clear();
74 m_FirstFreeLane=0;
75 m_Lns.clear();
77 m_RawlogData.clear();
78 m_RawLogStart.clear();
81 //CLogDataVector Class
82 int CLogDataVector::ParserFromLog(CTGitPath *path ,int count ,int infomask,CString *from,CString *to)
84 // only enable --follow on files
85 if ((path == NULL || path->IsDirectory()) && (infomask & CGit::LOG_INFO_FOLLOW))
86 infomask = infomask ^ CGit::LOG_INFO_FOLLOW;
88 CString hash;
89 CString cmd=g_Git.GetLogCmd(hash,path,count,infomask,from,to,true);
91 if(g_Git.IsInitRepos())
92 return 0;
94 git_init();
96 GIT_LOG handle;
97 if (git_open_log(&handle,CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
99 return -1;
102 git_get_log_firstcommit(handle);
104 GIT_COMMIT commit;
106 GitRev rev;
108 while (git_get_log_nextcommit(handle, &commit, infomask & CGit::LOG_INFO_FOLLOW) == 0)
110 if (commit.m_ignore == 1)
112 git_free_commit(&commit);
113 continue;
116 CGitHash hash = (char*)commit.m_hash ;
117 rev.Clear();
119 GitRev *pRev = this->m_pLogCache->GetCacheData(hash);
121 char *note=NULL;
122 git_get_notes(commit.m_hash,&note);
123 if(note)
125 pRev->m_Notes.Empty();
126 g_Git.StringAppend(&pRev->m_Notes,(BYTE*)note);
129 if(pRev == NULL || !pRev->m_IsFull)
131 pRev->ParserFromCommit(&commit);
132 pRev->ParserParentFromCommit(&commit);
133 git_free_commit(&commit);
134 //Must call free commit before SafeFetchFullInfo, commit parent is rewrite by log.
135 //file list will wrong if parent rewrite.
136 pRev->SafeFetchFullInfo(&g_Git);
139 else
141 ASSERT(pRev->m_CommitHash == hash);
142 pRev->ParserParentFromCommit(&commit);
143 git_free_commit(&commit);
146 this->push_back(pRev->m_CommitHash);
148 m_HashMap[rev.m_CommitHash]=size()-1;
152 git_close_log(handle);
154 return 0;
157 int AddTolist(unsigned char * /*osha1*/, unsigned char *nsha1, const char * /*name*/, unsigned long /*time*/, int /*sz*/, const char *msg, void *data)
159 CLogDataVector *vector = (CLogDataVector*)data;
160 GitRev rev;
161 rev.m_CommitHash=(char*)nsha1;
163 CString one;
164 g_Git.StringAppend(&one, (BYTE *)msg);
166 int message=one.Find(_T(":"),0);
167 if(message>0)
169 rev.m_RefAction=one.Left(message);
170 rev.GetSubject()=one.Mid(message+1);
173 vector->m_pLogCache->m_HashMap[rev.m_CommitHash]=rev;
174 vector->insert(vector->begin(),rev.m_CommitHash);
176 return 0;
179 int CLogDataVector::ParserFromRefLog(CString ref)
181 if(g_Git.m_IsUseGitDLL)
183 git_for_each_reflog_ent(CUnicodeUtils::GetUTF8(ref),AddTolist,this);
184 for(int i=0;i<size();i++)
186 m_pLogCache->m_HashMap[at(i)].m_Ref.Format(_T("%s{%d}"), ref,i);
190 else
193 CString cmd, out;
194 GitRev rev;
195 cmd.Format(_T("git.exe reflog show %s"),ref);
196 if (g_Git.Run(cmd, &out, NULL, CP_UTF8))
197 return -1;
199 int pos=0;
200 while(pos>=0)
202 CString one=out.Tokenize(_T("\n"),pos);
203 int ref=one.Find(_T(' '),0);
204 if(ref<0)
205 continue;
207 rev.Clear();
209 rev.m_CommitHash=g_Git.GetHash(one.Left(ref));
210 int action=one.Find(_T(' '),ref+1);
211 int message;
212 if(action>0)
214 rev.m_Ref=one.Mid(ref+1,action-ref-2);
215 message=one.Find(_T(":"),action);
216 if(message>0)
218 rev.m_RefAction=one.Mid(action+1,message-action-1);
219 rev.GetSubject()=one.Right(one.GetLength()-message-1);
223 this->m_pLogCache->m_HashMap[rev.m_CommitHash]=rev;
225 this->push_back(rev.m_CommitHash);
229 return 0;
232 void CLogDataVector::setLane(CGitHash& sha)
234 Lanes* l = &(this->m_Lns);
235 int i = m_FirstFreeLane;
237 // QVector<QByteArray> ba;
238 // const ShaString& ss = toPersistentSha(sha, ba);
239 // const ShaVect& shaVec(fh->revOrder);
241 for (int cnt = size(); i < cnt; ++i) {
243 GitRev* r = & this->GetGitRevAt(i);
244 CGitHash curSha=r->m_CommitHash;
246 if (r->m_Lanes.size() == 0)
247 updateLanes(*r, *l, curSha);
249 if (curSha == sha)
250 break;
252 m_FirstFreeLane = ++i;
254 #if 0
255 Lanes* l = &(this->m_Lanes);
256 int i = m_FirstFreeLane;
258 QVector<QByteArray> ba;
259 const ShaString& ss = toPersistentSha(sha, ba);
260 const ShaVect& shaVec(fh->revOrder);
262 for (uint cnt = shaVec.count(); i < cnt; ++i) {
264 const ShaString& curSha = shaVec[i];
265 Rev* r = m_HashMap[curSha]const_cast<Rev*>(revLookup(curSha, fh));
266 if (r->lanes.count() == 0)
267 updateLanes(*r, *l, curSha);
269 if (curSha == ss)
270 break;
272 fh->firstFreeLane = ++i;
273 #endif
277 void CLogDataVector::updateLanes(GitRev& c, Lanes& lns, CGitHash &sha)
279 // we could get third argument from c.sha(), but we are in fast path here
280 // and c.sha() involves a deep copy, so we accept a little redundancy
282 if (lns.isEmpty())
283 lns.init(sha);
285 bool isDiscontinuity;
286 bool isFork = lns.isFork(sha, isDiscontinuity);
287 bool isMerge = (c.ParentsCount() > 1);
288 bool isInitial = (c.ParentsCount() == 0);
290 if (isDiscontinuity)
291 lns.changeActiveLane(sha); // uses previous isBoundary state
293 lns.setBoundary(c.IsBoundary() == TRUE); // update must be here
294 TRACE(_T("%s %d"),c.m_CommitHash.ToString(),c.IsBoundary());
296 if (isFork)
297 lns.setFork(sha);
298 if (isMerge)
299 lns.setMerge(c.m_ParentHash);
300 //if (c.isApplied)
301 // lns.setApplied();
302 if (isInitial)
303 lns.setInitial();
305 lns.getLanes(c.m_Lanes); // here lanes are snapshotted
307 CGitHash nextSha;
308 if( !isInitial)
309 nextSha = c.m_ParentHash[0];
311 lns.nextParent(nextSha);
313 //if (c.isApplied)
314 // lns.afterApplied();
315 if (isMerge)
316 lns.afterMerge();
317 if (isFork)
318 lns.afterFork();
319 if (lns.isBranch())
320 lns.afterBranch();
322 // QString tmp = "", tmp2;
323 // for (uint i = 0; i < c.lanes.count(); i++) {
324 // tmp2.setNum(c.lanes[i]);
325 // tmp.append(tmp2 + "-");
326 // }
327 // qDebug("%s %s",tmp.latin1(), c.sha.latin1());