1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2015, 2017-2018 - 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.
21 #include "RepositoryFixtures.h"
22 #include "LogDlgHelper.h"
24 class CLogDataVectorCBasicGitWithTestRepoFixture
: public CBasicGitWithTestRepoFixture
28 class CLogDataVectorCBasicGitWithEmptyRepositoryFixturee
: public CBasicGitWithEmptyRepositoryFixture
32 class CLogDataVectorCBasicGitWithTestRepoBareFixture
: public CBasicGitWithTestRepoBareFixture
36 class CLogDataVectorCBasicGitWithEmptyBareRepositoryFixturee
: public CBasicGitWithEmptyBareRepositoryFixture
40 INSTANTIATE_TEST_CASE_P(CLogDataVector
, CLogDataVectorCBasicGitWithTestRepoFixture
, testing::Values(LIBGIT
));
41 INSTANTIATE_TEST_CASE_P(CLogDataVector
, CLogDataVectorCBasicGitWithTestRepoBareFixture
, testing::Values(LIBGIT
));
42 INSTANTIATE_TEST_CASE_P(CLogDataVector
, CLogDataVectorCBasicGitWithEmptyRepositoryFixturee
, testing::Values(LIBGIT
));
43 INSTANTIATE_TEST_CASE_P(CLogDataVector
, CLogDataVectorCBasicGitWithEmptyBareRepositoryFixturee
, testing::Values(LIBGIT
));
45 TEST(CLogDataVector
, Empty
)
47 CLogDataVector logDataVector
;
48 logDataVector
.m_logOrderBy
= CGit::LOG_ORDER_TOPOORDER
;
50 EXPECT_EQ(0U, logDataVector
.size());
51 EXPECT_EQ(0U, logDataVector
.m_HashMap
.size());
54 TEST(CLogCache
, GetCacheData
)
57 EXPECT_EQ(0U, logCache
.m_HashMap
.size());
58 CGitHash
hash1(L
"4c5c93d2a0b368bc4570d5ec02ab03b9c4334d44");
59 GitRevLoglist
* pRev
= logCache
.GetCacheData(hash1
);
61 EXPECT_EQ(hash1
, pRev
->m_CommitHash
);
62 EXPECT_EQ(1U, logCache
.m_HashMap
.size());
64 CGitHash
hash2(L
"dead91b4aedeaddeaddead2a56d3c473c705dead");
65 pRev
= logCache
.GetCacheData(hash2
);
67 EXPECT_EQ(hash2
, pRev
->m_CommitHash
);
68 EXPECT_EQ(2U, logCache
.m_HashMap
.size());
71 TEST(CLogCache
, ClearAllParent
)
74 CGitHash
hash1(L
"4c5c93d2a0b368bc4570d5ec02ab03b9c4334d44");
75 GitRevLoglist
* pRev
= logCache
.GetCacheData(hash1
);
77 pRev
->m_ParentHash
.push_back(CGitHash(L
"0000000000000000000000000000000000000000"));
78 EXPECT_EQ(1U, pRev
->m_ParentHash
.size());
79 pRev
->m_Lanes
.push_back(1);
80 pRev
->m_Lanes
.push_back(2);
81 pRev
->m_Lanes
.push_back(3);
82 EXPECT_EQ(3U, pRev
->m_Lanes
.size());
83 CGitHash
hash2(L
"dead91b4aedeaddeaddead2a56d3c473c705dead");
84 pRev
= logCache
.GetCacheData(hash2
);
86 pRev
->m_ParentHash
.push_back(CGitHash(L
"1111111111111111111111111111111111111111"));
87 pRev
->m_ParentHash
.push_back(CGitHash(L
"1111111111111111111111111111111111111112"));
88 EXPECT_EQ(2U, pRev
->m_ParentHash
.size());
89 pRev
->m_Lanes
.push_back(4);
90 EXPECT_EQ(1U, pRev
->m_Lanes
.size());
92 logCache
.ClearAllParent();
93 pRev
= logCache
.GetCacheData(hash1
);
95 EXPECT_EQ(0U, pRev
->m_ParentHash
.size());
96 EXPECT_EQ(0U, pRev
->m_Lanes
.size());
98 pRev
= logCache
.GetCacheData(hash2
);
100 EXPECT_EQ(0U, pRev
->m_ParentHash
.size());
101 EXPECT_EQ(0U, pRev
->m_Lanes
.size());
104 TEST(CLogCache
, ClearAllLanes
)
107 CGitHash
hash1(L
"4c5c93d2a0b368bc4570d5ec02ab03b9c4334d44");
108 GitRevLoglist
* pRev
= logCache
.GetCacheData(hash1
);
110 pRev
->m_ParentHash
.push_back(CGitHash(L
"0000000000000000000000000000000000000000"));
111 EXPECT_EQ(1U, pRev
->m_ParentHash
.size());
112 pRev
->m_Lanes
.push_back(1);
113 pRev
->m_Lanes
.push_back(2);
114 pRev
->m_Lanes
.push_back(3);
115 EXPECT_EQ(3U, pRev
->m_Lanes
.size());
116 CGitHash
hash2(L
"dead91b4aedeaddeaddead2a56d3c473c705dead");
117 pRev
= logCache
.GetCacheData(hash2
);
119 pRev
->m_ParentHash
.push_back(CGitHash(L
"1111111111111111111111111111111111111111"));
120 pRev
->m_ParentHash
.push_back(CGitHash(L
"1111111111111111111111111111111111111112"));
121 EXPECT_EQ(2U, pRev
->m_ParentHash
.size());
122 pRev
->m_Lanes
.push_back(4);
123 EXPECT_EQ(1U, pRev
->m_Lanes
.size());
125 logCache
.ClearAllLanes();
126 pRev
= logCache
.GetCacheData(hash1
);
128 EXPECT_EQ(1U, pRev
->m_ParentHash
.size());
129 EXPECT_EQ(0U, pRev
->m_Lanes
.size());
131 pRev
= logCache
.GetCacheData(hash2
);
133 EXPECT_EQ(2U, pRev
->m_ParentHash
.size());
134 EXPECT_EQ(0U, pRev
->m_Lanes
.size());
137 static void ParserFromLogTests()
140 CLogDataVector logDataVector
;
141 logDataVector
.m_logOrderBy
= CGit::LOG_ORDER_TOPOORDER
;
142 logDataVector
.SetLogCache(&logCache
);
144 EXPECT_EQ(0, logDataVector
.ParserFromLog());
145 EXPECT_EQ(12U, logDataVector
.size());
146 EXPECT_EQ(12U, logDataVector
.m_HashMap
.size());
147 EXPECT_EQ(12U, logCache
.m_HashMap
.size());
149 logCache
.m_HashMap
.clear();
150 logDataVector
.ClearAll();
151 EXPECT_EQ(0U, logDataVector
.size());
152 EXPECT_EQ(0U, logDataVector
.m_HashMap
.size());
153 EXPECT_EQ(0U, logCache
.m_HashMap
.size());
155 EXPECT_EQ(0, logDataVector
.ParserFromLog(nullptr, 5));
156 ASSERT_EQ(5U, logDataVector
.size());
157 EXPECT_EQ(5U, logDataVector
.m_HashMap
.size());
158 EXPECT_EQ(5U, logCache
.m_HashMap
.size());
159 EXPECT_STREQ(L
"Changed ASCII file", logDataVector
.GetGitRevAt(0).GetSubject());
160 EXPECT_STREQ(L
"7c3cbfe13a929d2291a574dca45e4fd2d2ac1aa6", logDataVector
.GetGitRevAt(0).m_CommitHash
.ToString());
161 EXPECT_STREQ(L
"49ecdfff36bfe2b9b499b33e5034f427e2fa54dd", logDataVector
.GetGitRevAt(2).m_CommitHash
.ToString());
162 EXPECT_STREQ(L
"560deea87853158b22d0c0fd73f60a458d47838a", logDataVector
.GetGitRevAt(4).m_CommitHash
.ToString());
164 logCache
.m_HashMap
.clear();
165 logDataVector
.ClearAll();
166 EXPECT_EQ(0, logDataVector
.ParserFromLog(nullptr, 0, CGit::LOG_INFO_ALL_BRANCH
));
167 ASSERT_EQ(24U, logDataVector
.size());
168 EXPECT_EQ(24U, logDataVector
.m_HashMap
.size());
169 EXPECT_EQ(24U, logCache
.m_HashMap
.size());
170 EXPECT_STREQ(L
"31ff87c86e9f6d3853e438cb151043f30f09029a", logDataVector
.GetGitRevAt(0).m_CommitHash
.ToString());
171 EXPECT_STREQ(L
"4c5c93d2a0b368bc4570d5ec02ab03b9c4334d44", logDataVector
.GetGitRevAt(1).m_CommitHash
.ToString());
172 EXPECT_STREQ(L
"4517b91ee8f7497d40cf93d112f12196a7cec995", logDataVector
.GetGitRevAt(12).m_CommitHash
.ToString());
173 EXPECT_STREQ(L
"c5b89de0335fd674e2e421ac4543098cb2f22cde", logDataVector
.GetGitRevAt(15).m_CommitHash
.ToString());
174 EXPECT_STREQ(L
"844309789a13614b52d5e7cbfe6350dd73d1dc72", logDataVector
.GetGitRevAt(23).m_CommitHash
.ToString());
176 logCache
.m_HashMap
.clear();
177 logDataVector
.ClearAll();
178 CString
range(L
"does-not-exist");
179 EXPECT_EQ(-1, logDataVector
.ParserFromLog(nullptr, 0, CGit::LOG_INFO_ALL_BRANCH
, &range
));
180 EXPECT_EQ(0U, logDataVector
.size());
181 EXPECT_EQ(0U, logDataVector
.m_HashMap
.size());
182 EXPECT_EQ(0U, logCache
.m_HashMap
.size());
184 EXPECT_EQ(-1, logDataVector
.ParserFromLog(nullptr, 0, 0, &range
));
185 EXPECT_EQ(0U, logDataVector
.size());
186 EXPECT_EQ(0U, logDataVector
.m_HashMap
.size());
187 EXPECT_EQ(0U, logCache
.m_HashMap
.size());
189 logCache
.m_HashMap
.clear();
190 logDataVector
.ClearAll();
191 range
= L
"master2..master";
192 EXPECT_EQ(0, logDataVector
.ParserFromLog(nullptr, 0, 0, &range
));
193 ASSERT_EQ(2U, logDataVector
.size());
194 EXPECT_EQ(2U, logDataVector
.m_HashMap
.size());
195 EXPECT_EQ(2U, logCache
.m_HashMap
.size());
196 EXPECT_STREQ(L
"7c3cbfe13a929d2291a574dca45e4fd2d2ac1aa6", logDataVector
.GetGitRevAt(0).m_CommitHash
.ToString());
197 EXPECT_STREQ(L
"1fc3c9688e27596d8717b54f2939dc951568f6cb", logDataVector
.GetGitRevAt(1).m_CommitHash
.ToString());
199 logCache
.m_HashMap
.clear();
200 logDataVector
.ClearAll();
201 EXPECT_EQ(0, logDataVector
.ParserFromLog(nullptr, 0, CGit::LOG_INFO_ALL_BRANCH
, &range
)); // useless test?, all branches has higher precedence
202 ASSERT_EQ(24U, logDataVector
.size());
203 EXPECT_EQ(24U, logDataVector
.m_HashMap
.size());
204 EXPECT_EQ(24U, logCache
.m_HashMap
.size());
206 logCache
.m_HashMap
.clear();
207 logDataVector
.ClearAll();
208 CTGitPath
path(L
"does-not-exist.txt");
209 EXPECT_EQ(0, logDataVector
.ParserFromLog(&path
));
210 EXPECT_EQ(0U, logDataVector
.size());
211 EXPECT_EQ(0U, logDataVector
.m_HashMap
.size());
212 EXPECT_EQ(0U, logCache
.m_HashMap
.size());
214 logCache
.m_HashMap
.clear();
215 logDataVector
.ClearAll();
216 path
= CTGitPath(L
"copy/utf16-be-bom.txt");
217 EXPECT_EQ(0, logDataVector
.ParserFromLog(&path
));
218 ASSERT_EQ(2U, logDataVector
.size());
219 EXPECT_EQ(2U, logDataVector
.m_HashMap
.size());
220 EXPECT_EQ(2U, logCache
.m_HashMap
.size());
221 EXPECT_STREQ(L
"49ecdfff36bfe2b9b499b33e5034f427e2fa54dd", logDataVector
.GetGitRevAt(0).m_CommitHash
.ToString());
222 EXPECT_STREQ(L
"560deea87853158b22d0c0fd73f60a458d47838a", logDataVector
.GetGitRevAt(1).m_CommitHash
.ToString());
224 logCache
.m_HashMap
.clear();
225 logDataVector
.ClearAll();
226 EXPECT_EQ(0, logDataVector
.ParserFromLog(&path
, 0, CGit::LOG_INFO_FOLLOW
));
227 ASSERT_EQ(4U, logDataVector
.size());
228 EXPECT_EQ(4U, logDataVector
.m_HashMap
.size());
229 EXPECT_EQ(4U, logCache
.m_HashMap
.size());
230 EXPECT_STREQ(L
"49ecdfff36bfe2b9b499b33e5034f427e2fa54dd", logDataVector
.GetGitRevAt(0).m_CommitHash
.ToString());
231 EXPECT_STREQ(L
"560deea87853158b22d0c0fd73f60a458d47838a", logDataVector
.GetGitRevAt(1).m_CommitHash
.ToString());
232 EXPECT_STREQ(L
"ff1fbef1a54a9849afd4a5e94d2ca4d80d5b96c2", logDataVector
.GetGitRevAt(3).m_CommitHash
.ToString());
234 logCache
.m_HashMap
.clear();
235 logDataVector
.ClearAll();
236 range
= L
"4c5c93d2a0b368bc4570d5ec02ab03b9c4334d44";
237 EXPECT_EQ(0, logDataVector
.ParserFromLog(&path
, 0, CGit::LOG_INFO_FOLLOW
, &range
));
238 ASSERT_EQ(3U, logDataVector
.size());
239 EXPECT_EQ(3U, logDataVector
.m_HashMap
.size());
240 EXPECT_EQ(3U, logCache
.m_HashMap
.size());
241 EXPECT_STREQ(L
"560deea87853158b22d0c0fd73f60a458d47838a", logDataVector
.GetGitRevAt(0).m_CommitHash
.ToString());
242 EXPECT_STREQ(L
"a9d53b535cb49640a6099860ac4999f5a0857b91", logDataVector
.GetGitRevAt(1).m_CommitHash
.ToString());
243 EXPECT_STREQ(L
"ff1fbef1a54a9849afd4a5e94d2ca4d80d5b96c2", logDataVector
.GetGitRevAt(2).m_CommitHash
.ToString());
245 logCache
.m_HashMap
.clear();
246 logDataVector
.ClearAll();
247 EXPECT_EQ(0, logDataVector
.ParserFromLog(&path
, 0, CGit::LOG_INFO_FULL_DIFF
, &range
));
248 ASSERT_EQ(1U, logDataVector
.size());
249 EXPECT_EQ(1U, logDataVector
.m_HashMap
.size());
250 EXPECT_EQ(1U, logCache
.m_HashMap
.size());
251 EXPECT_STREQ(L
"560deea87853158b22d0c0fd73f60a458d47838a", logDataVector
.GetGitRevAt(0).m_CommitHash
.ToString());
253 // check whether libgit ref_cache is correctly invalidated
255 EXPECT_EQ(0, g_Git
.Run(L
"git.exe branch -D simple-conflict", &output
, CP_UTF8
)); // normal ref in refs/heads
256 EXPECT_STRNE(L
"", output
);
257 logCache
.m_HashMap
.clear();
258 logDataVector
.ClearAll();
259 EXPECT_EQ(0, logDataVector
.ParserFromLog(nullptr, 0, CGit::LOG_INFO_ALL_BRANCH
));
260 ASSERT_EQ(23U, logDataVector
.size());
261 EXPECT_EQ(23U, logDataVector
.m_HashMap
.size());
262 EXPECT_EQ(23U, logCache
.m_HashMap
.size());
263 EXPECT_STREQ(L
"31ff87c86e9f6d3853e438cb151043f30f09029a", logDataVector
.GetGitRevAt(0).m_CommitHash
.ToString());
264 EXPECT_STREQ(L
"4c5c93d2a0b368bc4570d5ec02ab03b9c4334d44", logDataVector
.GetGitRevAt(1).m_CommitHash
.ToString());
265 EXPECT_STREQ(L
"4517b91ee8f7497d40cf93d112f12196a7cec995", logDataVector
.GetGitRevAt(12).m_CommitHash
.ToString());
266 EXPECT_STREQ(L
"10385764a4d42d7428bbeb245015f8f338fc1e40", logDataVector
.GetGitRevAt(15).m_CommitHash
.ToString());
267 EXPECT_STREQ(L
"844309789a13614b52d5e7cbfe6350dd73d1dc72", logDataVector
.GetGitRevAt(22).m_CommitHash
.ToString());
268 EXPECT_TRUE(logDataVector
.m_HashMap
.find(CGitHash(L
"c5b89de0335fd674e2e421ac4543098cb2f22cde")) == logDataVector
.m_HashMap
.end());
269 EXPECT_TRUE(logCache
.m_HashMap
.find(CGitHash(L
"c5b89de0335fd674e2e421ac4543098cb2f22cde")) == logCache
.m_HashMap
.end());
271 EXPECT_EQ(0, g_Git
.Run(L
"git.exe branch -D forconflict", &output
, CP_UTF8
)); // ref in packed-refs
272 EXPECT_STRNE(L
"", output
);
273 logCache
.m_HashMap
.clear();
274 logDataVector
.ClearAll();
275 EXPECT_EQ(0, logDataVector
.ParserFromLog(nullptr, 0, CGit::LOG_INFO_ALL_BRANCH
));
276 ASSERT_EQ(22U, logDataVector
.size());
277 EXPECT_EQ(22U, logDataVector
.m_HashMap
.size());
278 EXPECT_EQ(22U, logCache
.m_HashMap
.size());
279 EXPECT_STREQ(L
"31ff87c86e9f6d3853e438cb151043f30f09029a", logDataVector
.GetGitRevAt(0).m_CommitHash
.ToString());
280 EXPECT_STREQ(L
"4c5c93d2a0b368bc4570d5ec02ab03b9c4334d44", logDataVector
.GetGitRevAt(1).m_CommitHash
.ToString());
281 EXPECT_STREQ(L
"4517b91ee8f7497d40cf93d112f12196a7cec995", logDataVector
.GetGitRevAt(12).m_CommitHash
.ToString());
282 EXPECT_STREQ(L
"b9ef30183497cdad5c30b88d32dc1bed7951dfeb", logDataVector
.GetGitRevAt(15).m_CommitHash
.ToString());
283 EXPECT_STREQ(L
"844309789a13614b52d5e7cbfe6350dd73d1dc72", logDataVector
.GetGitRevAt(21).m_CommitHash
.ToString());
284 EXPECT_TRUE(logDataVector
.m_HashMap
.find(CGitHash(L
"10385764a4d42d7428bbeb245015f8f338fc1e40")) == logDataVector
.m_HashMap
.end());
285 EXPECT_TRUE(logCache
.m_HashMap
.find(CGitHash(L
"10385764a4d42d7428bbeb245015f8f338fc1e40")) == logCache
.m_HashMap
.end());
288 TEST_P(CLogDataVectorCBasicGitWithTestRepoFixture
, ParserFromLog
)
290 ParserFromLogTests();
293 TEST_P(CLogDataVectorCBasicGitWithTestRepoBareFixture
, ParserFromLog
)
295 ParserFromLogTests();
298 static void ParserFromLogTests_EmptyRepo()
301 CLogDataVector logDataVector
;
302 logDataVector
.m_logOrderBy
= CGit::LOG_ORDER_TOPOORDER
;
303 logDataVector
.SetLogCache(&logCache
);
304 EXPECT_EQ(-1, logDataVector
.ParserFromLog());
305 EXPECT_EQ(0U, logDataVector
.size());
306 EXPECT_EQ(0U, logDataVector
.m_HashMap
.size());
307 EXPECT_EQ(0U, logCache
.m_HashMap
.size());
310 TEST_P(CLogDataVectorCBasicGitWithEmptyRepositoryFixturee
, ParserFromLog
)
312 ParserFromLogTests_EmptyRepo();
315 TEST_P(CLogDataVectorCBasicGitWithEmptyBareRepositoryFixturee
, ParserFromLog
)
317 ParserFromLogTests_EmptyRepo();
320 static void FillTests()
323 CLogDataVector logDataVector
;
324 logDataVector
.m_logOrderBy
= CGit::LOG_ORDER_TOPOORDER
;
325 logDataVector
.SetLogCache(&logCache
);
327 std::unordered_set
<CGitHash
> hashes
;
328 EXPECT_EQ(0, logDataVector
.Fill(hashes
));
329 EXPECT_EQ(0U, logDataVector
.size());
330 EXPECT_EQ(0U, logCache
.m_HashMap
.size());
332 hashes
.insert(CGitHash(L
"35c91b4ae2f77f4f21a7aba56d3c473c705d89e6"));
333 logCache
.m_HashMap
.clear();
334 logDataVector
.ClearAll();
335 EXPECT_EQ(0, logDataVector
.Fill(hashes
));
336 ASSERT_EQ(1U, logDataVector
.size());
337 EXPECT_TRUE(logDataVector
.GetGitRevAt(0).m_CommitHash
.ToString() == L
"35c91b4ae2f77f4f21a7aba56d3c473c705d89e6");
338 EXPECT_EQ(1U, logCache
.m_HashMap
.size());
340 hashes
.insert(CGitHash(L
"7c3cbfe13a929d2291a574dca45e4fd2d2ac1aa6"));
341 logCache
.m_HashMap
.clear();
342 logDataVector
.ClearAll();
343 EXPECT_EQ(0, logDataVector
.Fill(hashes
));
344 EXPECT_EQ(2U, logDataVector
.size());
345 EXPECT_EQ(2U, logCache
.m_HashMap
.size());
347 hashes
.insert(CGitHash(L
"dead91b4aedeaddeaddead2a56d3c473c705dead")); // non-existent commit
348 logCache
.m_HashMap
.clear();
349 logDataVector
.ClearAll();
350 EXPECT_EQ(-1, logDataVector
.Fill(hashes
));
351 EXPECT_EQ(0U, logDataVector
.size());
352 // size of logCache.m_HashMap.size() depends on the order of the set
356 TEST_P(CLogDataVectorCBasicGitWithTestRepoFixture
, Fill
)
361 TEST_P(CLogDataVectorCBasicGitWithTestRepoBareFixture
, Fill
)