Fixed uninitialized field
[TortoiseGit.git] / src / Git / GitRevLoglist.h
blob2fe507d7993215695a9d9bc6584a33b563c6e701
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2020 - TortoiseGit
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 #pragma once
21 #include "GitRev.h"
22 #include "TGitPath.h"
23 #include "gitdll.h"
25 class CGit;
26 extern CGit g_Git;
27 class GitRevLoglist;
28 class CLogCache;
29 class IAsyncDiffCB;
31 typedef void CALL_UPDATE_DIFF_ASYNC(GitRevLoglist* pRev, IAsyncDiffCB* data);
33 class GitRevLoglist : public GitRev
35 public:
36 friend class CLogCache;
38 GitRevLoglist(void);
39 ~GitRevLoglist(void);
41 class GitRevLoglistSharedFiles
43 public:
44 GitRevLoglistSharedFiles(PSRWLOCK lock, const CTGitPathList& files)
45 : m_lock(lock)
46 , m_files(files)
48 AcquireSRWLockShared(m_lock);
51 ~GitRevLoglistSharedFiles() { ReleaseSRWLockShared(m_lock); }
53 inline int GetCount() const { return m_files.GetCount(); }
54 inline const CTGitPath& operator[](INT_PTR index) const { return m_files[index]; }
56 const CTGitPathList& m_files;
58 private:
59 PSRWLOCK m_lock;
62 class GitRevLoglistSharedFilesWriter
64 public:
65 GitRevLoglistSharedFilesWriter(PSRWLOCK lock, CTGitPathList& files, CTGitPathList& unrevfiles)
66 : m_lock(lock)
67 , m_files(files)
68 , m_UnRevFiles(unrevfiles)
70 AcquireSRWLockExclusive(m_lock);
73 ~GitRevLoglistSharedFilesWriter() { ReleaseSRWLockExclusive(m_lock); }
75 CTGitPathList& m_files;
76 CTGitPathList& m_UnRevFiles;
78 private:
79 PSRWLOCK m_lock;
82 protected:
83 int m_RebaseAction;
84 unsigned int m_Action;
85 CTGitPathList m_Files;
86 CTGitPathList m_UnRevFiles;
88 SRWLOCK m_lock;
90 public:
91 CString m_Notes;
93 TCHAR m_Mark;
94 CString m_Ref; // for Refloglist
95 CString m_RefAction; // for Refloglist
97 // Show version tree Graphic
98 std::vector<int> m_Lanes;
100 static std::shared_ptr<CGitMailmap> s_Mailmap;
102 volatile LONG m_IsDiffFiles;
104 CALL_UPDATE_DIFF_ASYNC *m_CallDiffAsync;
106 int CheckAndDiff()
108 if (!m_IsDiffFiles && !m_CommitHash.IsEmpty())
110 int ret = 0;
111 ret = SafeFetchFullInfo(&g_Git);
112 InterlockedExchange(&m_IsDiffFiles, TRUE);
113 return ret;
115 return 1;
118 public:
119 unsigned int& GetAction(IAsyncDiffCB* data)
121 if (!m_IsDiffFiles && m_CallDiffAsync)
122 m_CallDiffAsync(this, data);
123 else
124 CheckAndDiff();
125 return m_Action;
128 int& GetRebaseAction()
130 return m_RebaseAction;
133 GitRevLoglistSharedFiles GetFiles(IAsyncDiffCB* data)
135 // data might be nullptr when instant data is requested, cf. CGitLogListAction
136 if (data && !m_IsDiffFiles && m_CallDiffAsync)
137 m_CallDiffAsync(this, data);
138 else
139 CheckAndDiff();
140 return GitRevLoglistSharedFiles(&m_lock, m_Files);
143 GitRevLoglistSharedFilesWriter GetFilesWriter()
145 return GitRevLoglistSharedFilesWriter(&m_lock, m_Files, m_UnRevFiles);
148 CTGitPathList& GetUnRevFiles()
150 return m_UnRevFiles;
153 void Parse(GIT_COMMIT* commit, const CGitMailmap* mailmap)
155 ParserParentFromCommit(commit);
156 ParserFromCommit(commit);
157 // no caching here, because mailmap might have changed
158 if (mailmap)
159 ApplyMailmap(*mailmap);
162 public:
163 CString& GetAuthorName()
165 return m_AuthorName;
168 CString& GetAuthorEmail()
170 return m_AuthorEmail;
173 CTime& GetAuthorDate()
175 return m_AuthorDate;
178 CString& GetCommitterName()
180 return m_CommitterName;
183 CString& GetCommitterEmail()
185 return m_CommitterEmail;
188 CTime& GetCommitterDate()
190 return m_CommitterDate;
193 CString& GetSubject()
195 return m_Subject;
198 CString& GetBody()
200 return m_Body;
203 CString GetSubjectBody(bool crlf = false) const
205 CString ret(m_Subject);
206 if (!crlf)
208 ret += L"\n";
209 ret += m_Body;
211 else
213 ret.TrimRight();
214 ret += L"\r\n";
215 CString body(m_Body);
216 body.Replace(L"\n", L"\r\n");
217 ret += body.TrimRight();
219 return ret;
222 BOOL IsBoundary() const { return m_Mark == L'-'; }
224 virtual void Clear() override;
226 int SafeFetchFullInfo(CGit* git);
228 int SafeGetSimpleList(CGit* git);
229 volatile LONG m_IsSimpleListReady;
230 STRING_VECTOR m_SimpleFileList; /* use for find and filter, no rename detection and line num stat info */
232 static int GetRefLog(const CString& ref, std::vector<GitRevLoglist>& refloglist, CString& error);