OSDN Git Service

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