Refactor rebase commit list: Don't fill list again and again when reordering commits
[TortoiseGit.git] / src / TortoiseProc / LogDlgHelper.h
blobe7af366ee61cf72f0dc0f7014fc003d35ec8900a
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2007 - TortoiseSVN
4 // Copyright (C) 2008-2017 - TortoiseGit
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #pragma once
21 #include "lanes.h"
22 #include "GitHash.h"
23 #include "Git.h"
24 #include "GitLogCache.h"
25 #include <unordered_map>
26 #include <unordered_set>
27 class CLogDlg;
29 /**
30 * \ingroup TortoiseProc
31 * Instances of CStoreSelection save the selection of the CLogDlg. When the instance
32 * is deleted the destructor restores the selection.
34 typedef std::unordered_map<CGitHash, int> MAP_HASH_REV;
36 /**
37 * \ingroup TortoiseProc
38 * Helper class for the log dialog, handles all the log entries, including
39 * sorting.
41 class CLogDataVector : public std::vector<CGitHash>
43 public:
44 CLogCache *m_pLogCache;
45 /// De-allocates log items.
46 CLogDataVector(CLogCache *pLogCache)
48 m_pLogCache=pLogCache;
49 m_FirstFreeLane=0;
50 // Default to value set in Registry
51 m_logOrderBy = CRegDWORD(L"Software\\TortoiseGit\\LogOrderBy", CGit::LOG_ORDER_TOPOORDER);
53 CLogDataVector()
55 m_pLogCache = nullptr;
56 m_FirstFreeLane=0;
57 // Default to value set in Registry
58 m_logOrderBy = CRegDWORD(L"Software\\TortoiseGit\\LogOrderBy", CGit::LOG_ORDER_TOPOORDER);
60 void SetLogCache(CLogCache *pLogCache)
62 m_pLogCache = pLogCache;
64 GitRevLoglist& GetGitRevAt(size_t i)
66 ASSERT(i<size());
67 return m_pLogCache->m_HashMap[(*this)[i]];
69 void ClearAll();
70 int ParserFromLog(CTGitPath* path = nullptr, DWORD count = 0, DWORD infomask = CGit::LOG_INFO_STAT | CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE, CString* range = nullptr);
71 int Fill(std::unordered_set<CGitHash>& hashes);
73 Lanes m_Lns;
74 int m_FirstFreeLane;
75 // Log order: LOG_ORDER_CHRONOLOGIALREVERSED, LOG_ORDER_TOPOORDER, LOG_ORDER_DATEORDER
76 int m_logOrderBy;
77 MAP_HASH_REV m_HashMap;
78 void updateLanes(GitRevLoglist& c, Lanes& lns, CGitHash& sha);
79 void setLane(CGitHash& sha) ;
80 void append(CGitHash& sha, bool storeInVector);
82 #if 0
83 /// Ascending date sorting.
84 struct AscDateSort
86 bool operator()(GitRev& pStart, GitRev& pEnd)
88 return pStart->tmDate < pEnd->tmDate;
91 /// Descending date sorting.
92 struct DescDateSort
94 bool operator()(GitRev& pStart, GitRev& pEnd)
96 return pStart->tmDate > pEnd->tmDate;
99 /// Ascending revision sorting.
100 struct AscRevSort
102 bool operator()(GitRev& pStart, GitRev& pEnd)
104 return pStart->Rev < pEnd->Rev;
107 /// Descending revision sorting.
108 struct DescRevSort
110 bool operator()(GitRev& pStart, GitRev& pEnd)
112 return pStart->Rev > pEnd->Rev;
115 /// Ascending author sorting.
116 struct AscAuthorSort
118 bool operator()(GitRev& pStart, GitRev& pEnd)
120 int ret = pStart->sAuthor.CompareNoCase(pEnd->sAuthor);
121 if (ret == 0)
122 return pStart->Rev < pEnd->Rev;
123 return ret<0;
126 /// Descending author sorting.
127 struct DescAuthorSort
129 bool operator()(GitRev& pStart, GitRev& pEnd)
131 int ret = pStart->sAuthor.CompareNoCase(pEnd->sAuthor);
132 if (ret == 0)
133 return pStart->Rev > pEnd->Rev;
134 return ret>0;
137 /// Ascending bugID sorting.
138 struct AscBugIDSort
140 bool operator()(GitRev& pStart, GitRev& pEnd)
142 int ret = pStart->sBugIDs.CompareNoCase(pEnd->sBugIDs);
143 if (ret == 0)
144 return pStart->Rev < pEnd->Rev;
145 return ret<0;
148 /// Descending bugID sorting.
149 struct DescBugIDSort
151 bool operator()(GitRev& pStart, GitRev& pEnd)
153 int ret = pStart->sBugIDs.CompareNoCase(pEnd->sBugIDs);
154 if (ret == 0)
155 return pStart->Rev > pEnd->Rev;
156 return ret>0;
159 /// Ascending message sorting.
160 struct AscMessageSort
162 bool operator()(GitRev& pStart, GitRev& pEnd)
164 return pStart->sShortMessage.CompareNoCase(pEnd->sShortMessage)<0;
167 /// Descending message sorting.
168 struct DescMessageSort
170 bool operator()(GitRev& pStart, GitRev& pEnd)
172 return pStart->sShortMessage.CompareNoCase(pEnd->sShortMessage)>0;
175 /// Ascending action sorting
176 struct AscActionSort
178 bool operator() (GitRev& pStart, GitRev& pEnd)
180 if (pStart->actions == pEnd->actions)
181 return pStart->Rev < pEnd->Rev;
182 return pStart->actions < pEnd->actions;
185 /// Descending action sorting
186 struct DescActionSort
188 bool operator() (GitRev& pStart, GitRev& pEnd)
190 if (pStart->actions == pEnd->actions)
191 return pStart->Rev > pEnd->Rev;
192 return pStart->actions > pEnd->actions;
195 #endif