OSDN Git Service

Add LogList To GitBlame
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / LogDataVector.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control
2
3 // Copyright (C) 2007-2008 - TortoiseSVN
4
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.
9
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.
14
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.
18 //
19 /*
20         Description: start-up repository opening and reading
21
22         Author: Marco Costalba (C) 2005-2007
23
24         Copyright: See COPYING file that comes with this distribution
25
26 */
27
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"
65
66 int CLogDataVector::ParserShortLog(CTGitPath *path ,int count  )
67 {
68         CString log;
69         GitRev rev;
70
71         if(g_Git.IsInitRepos())
72                 return 0;
73
74         CString begin;
75         begin.Format(_T("#<%c>"),LOG_REV_ITEM_BEGIN);
76
77         g_Git.GetShortLog(log,path,count);
78         if(log.GetLength()==0)
79                 return 0;
80         
81         int start=4;
82         int length;
83         int next =1;
84         while( next>0 )
85         {
86                 next=log.Find(begin,start);
87                 if(next >0 )
88                         length = next - start+4;
89                 else
90                         length = log.GetLength()-start+4;
91
92                 CString onelog =log;
93                 onelog=log.Mid(start -4,length);
94                 rev.ParserFromLog(onelog);
95                 rev.m_Subject=_T("Load .................................");
96                 this->push_back(rev);
97                 m_HashMap[rev.m_CommitHash]=size()-1;
98                 start = next +4;
99         }
100
101         return 0;
102         return 0;
103
104 }
105 int CLogDataVector::FetchFullInfo(int i)
106 {
107         return at(i).SafeFetchFullInfo(&g_Git);
108 }
109 //CLogDataVector Class
110 int CLogDataVector::ParserFromLog()
111 {
112         CString log;
113         GitRev rev;
114         CString emptyhash;
115         g_Git.GetLog(log,emptyhash);
116
117         CString begin;
118         begin.Format(_T("#<%c>"),LOG_REV_ITEM_BEGIN);
119         
120         if(log.GetLength()==0)
121                 return 0;
122         
123         int start=4;
124         int length;
125         int next =1;
126         while( next>0 )
127         {
128                 next=log.Find(begin,start);
129                 if(next >0 )
130                         length = next - start+4;
131                 else
132                         length = log.GetLength()-start+4;
133
134                 CString onelog =log;
135                 onelog=log.Mid(start -4,length);
136                 rev.ParserFromLog(onelog);
137                 this->push_back(rev);
138                 m_HashMap[rev.m_CommitHash]=size()-1;
139                 start = next +4;
140         }
141
142         return 0;
143 }
144
145 void CLogDataVector::setLane(CString& sha) 
146 {
147         Lanes* l = &(this->m_Lns);
148         int i = m_FirstFreeLane;
149         
150 //      QVector<QByteArray> ba;
151 //      const ShaString& ss = toPersistentSha(sha, ba);
152 //      const ShaVect& shaVec(fh->revOrder);
153
154         for (int cnt = size(); i < cnt; ++i) {
155
156                 GitRev* r = &(*this)[i]; 
157                 CString &curSha=r->m_CommitHash;
158
159                 if (r->m_Lanes.size() == 0)
160                         updateLanes(*r, *l, curSha);
161
162                 if (curSha == sha)
163                         break;
164         }
165         m_FirstFreeLane = ++i;
166
167 #if 0
168         Lanes* l = &(this->m_Lanes);
169         int i = m_FirstFreeLane;
170         
171         QVector<QByteArray> ba;
172         const ShaString& ss = toPersistentSha(sha, ba);
173         const ShaVect& shaVec(fh->revOrder);
174
175         for (uint cnt = shaVec.count(); i < cnt; ++i) {
176
177                 const ShaString& curSha = shaVec[i];
178                 Rev* r = m_HashMap[curSha]const_cast<Rev*>(revLookup(curSha, fh));
179                 if (r->lanes.count() == 0)
180                         updateLanes(*r, *l, curSha);
181
182                 if (curSha == ss)
183                         break;
184         }
185         fh->firstFreeLane = ++i;
186 #endif
187 }
188
189
190 void CLogDataVector::updateLanes(GitRev& c, Lanes& lns, CString &sha) 
191 {
192 // we could get third argument from c.sha(), but we are in fast path here
193 // and c.sha() involves a deep copy, so we accept a little redundancy
194
195         if (lns.isEmpty())
196                 lns.init(sha);
197
198         bool isDiscontinuity;
199         bool isFork = lns.isFork(sha, isDiscontinuity);
200         bool isMerge = (c.ParentsCount() > 1);
201         bool isInitial = (c.ParentsCount() == 0);
202
203         if (isDiscontinuity)
204                 lns.changeActiveLane(sha); // uses previous isBoundary state
205
206         lns.setBoundary(c.IsBoundary()); // update must be here
207         TRACE(_T("%s %d"),c.m_CommitHash,c.IsBoundary());
208
209         if (isFork)
210                 lns.setFork(sha);
211         if (isMerge)
212                 lns.setMerge(c.m_ParentHash);
213         //if (c.isApplied)
214         //      lns.setApplied();
215         if (isInitial)
216                 lns.setInitial();
217
218         lns.getLanes(c.m_Lanes); // here lanes are snapshotted
219
220         CString nextSha = (isInitial) ? CString(_T("")) : QString(c.m_ParentHash[0]);
221
222         lns.nextParent(nextSha);
223
224         //if (c.isApplied)
225         //      lns.afterApplied();
226         if (isMerge)
227                 lns.afterMerge();
228         if (isFork)
229                 lns.afterFork();
230         if (lns.isBranch())
231                 lns.afterBranch();
232
233 //      QString tmp = "", tmp2;
234 //      for (uint i = 0; i < c.lanes.count(); i++) {
235 //              tmp2.setNum(c.lanes[i]);
236 //              tmp.append(tmp2 + "-");
237 //      }
238 //      qDebug("%s %s",tmp.latin1(), c.sha.latin1());
239 }