RebaseDlg: Fetch log when change branch and upstream
[TortoiseGit.git] / src / TortoiseProc / LogDataVector.cpp
blob1b265d2224e0d37555c26feed8773e9997f670d5
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
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"
67 int CLogDataVector::ParserShortLog(CTGitPath *path ,CString &hash,int count ,int mask )
69 BYTE_VECTOR log;
70 GitRev rev;
72 if(g_Git.IsInitRepos())
73 return 0;
75 CString begin;
76 begin.Format(_T("#<%c>"),LOG_REV_ITEM_BEGIN);
78 //g_Git.GetShortLog(log,path,count);
80 g_Git.GetLog(log,hash,path,count,mask);
82 if(log.size()==0)
83 return 0;
85 int start=4;
86 int length;
87 int next =0;
88 while( next>=0 && next<log.size())
90 next=rev.ParserFromLog(log,next);
92 rev.m_Subject=_T("Load .................................");
93 this->push_back(rev);
94 m_HashMap[rev.m_CommitHash]=size()-1;
96 //next=log.find(0,next);
99 return 0;
102 int CLogDataVector::FetchFullInfo(int i)
104 return at(i).SafeFetchFullInfo(&g_Git);
106 //CLogDataVector Class
107 int CLogDataVector::ParserFromLog(CTGitPath *path ,int count ,int infomask,CString *from,CString *to)
109 BYTE_VECTOR log;
110 GitRev rev;
111 CString emptyhash;
112 g_Git.GetLog(log,emptyhash,path,count,infomask,from,to);
114 CString begin;
115 begin.Format(_T("#<%c>"),LOG_REV_ITEM_BEGIN);
117 if(log.size()==0)
118 return 0;
120 int start=4;
121 int length;
122 int next =0;
123 while( next>=0 )
125 next=rev.ParserFromLog(log,next);
126 this->push_back(rev);
127 m_HashMap[rev.m_CommitHash]=size()-1;
130 return 0;
133 void CLogDataVector::setLane(CString& sha)
135 Lanes* l = &(this->m_Lns);
136 int i = m_FirstFreeLane;
138 // QVector<QByteArray> ba;
139 // const ShaString& ss = toPersistentSha(sha, ba);
140 // const ShaVect& shaVec(fh->revOrder);
142 for (int cnt = size(); i < cnt; ++i) {
144 GitRev* r = &(*this)[i];
145 CString &curSha=r->m_CommitHash;
147 if (r->m_Lanes.size() == 0)
148 updateLanes(*r, *l, curSha);
150 if (curSha == sha)
151 break;
153 m_FirstFreeLane = ++i;
155 #if 0
156 Lanes* l = &(this->m_Lanes);
157 int i = m_FirstFreeLane;
159 QVector<QByteArray> ba;
160 const ShaString& ss = toPersistentSha(sha, ba);
161 const ShaVect& shaVec(fh->revOrder);
163 for (uint cnt = shaVec.count(); i < cnt; ++i) {
165 const ShaString& curSha = shaVec[i];
166 Rev* r = m_HashMap[curSha]const_cast<Rev*>(revLookup(curSha, fh));
167 if (r->lanes.count() == 0)
168 updateLanes(*r, *l, curSha);
170 if (curSha == ss)
171 break;
173 fh->firstFreeLane = ++i;
174 #endif
178 void CLogDataVector::updateLanes(GitRev& c, Lanes& lns, CString &sha)
180 // we could get third argument from c.sha(), but we are in fast path here
181 // and c.sha() involves a deep copy, so we accept a little redundancy
183 if (lns.isEmpty())
184 lns.init(sha);
186 bool isDiscontinuity;
187 bool isFork = lns.isFork(sha, isDiscontinuity);
188 bool isMerge = (c.ParentsCount() > 1);
189 bool isInitial = (c.ParentsCount() == 0);
191 if (isDiscontinuity)
192 lns.changeActiveLane(sha); // uses previous isBoundary state
194 lns.setBoundary(c.IsBoundary() == TRUE); // update must be here
195 TRACE(_T("%s %d"),c.m_CommitHash,c.IsBoundary());
197 if (isFork)
198 lns.setFork(sha);
199 if (isMerge)
200 lns.setMerge(c.m_ParentHash);
201 //if (c.isApplied)
202 // lns.setApplied();
203 if (isInitial)
204 lns.setInitial();
206 lns.getLanes(c.m_Lanes); // here lanes are snapshotted
208 CString nextSha = (isInitial) ? CString(_T("")) : QString(c.m_ParentHash[0]);
210 lns.nextParent(nextSha);
212 //if (c.isApplied)
213 // lns.afterApplied();
214 if (isMerge)
215 lns.afterMerge();
216 if (isFork)
217 lns.afterFork();
218 if (lns.isBranch())
219 lns.afterBranch();
221 // QString tmp = "", tmp2;
222 // for (uint i = 0; i < c.lanes.count(); i++) {
223 // tmp2.setNum(c.lanes[i]);
224 // tmp.append(tmp2 + "-");
225 // }
226 // qDebug("%s %s",tmp.latin1(), c.sha.latin1());