]> git.proxmox.com Git - libgit2.git/blame - tests/revwalk/basic.c
New upstream version 1.1.0+dfsg.1
[libgit2.git] / tests / revwalk / basic.c
CommitLineData
8f7be6ca
CMN
1#include "clar_libgit2.h"
2
3/*
06e6eab0 4 * a4a7dce [0] Merge branch 'master' into br2
8f7be6ca 5 |\
06e6eab0
GP
6 | * 9fd738e [1] a fourth commit
7 | * 4a202b3 [2] a third commit
8 * | c47800c [3] branch commit one
8f7be6ca 9 |/
06e6eab0
GP
10 * 5b5b025 [5] another commit
11 * 8496071 [4] testing
8f7be6ca
CMN
12*/
13static const char *commit_head = "a4a7dce85cf63874e984719f4fdd239f5145052f";
14
15static const char *commit_ids[] = {
16 "a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */
17 "9fd738e8f7967c078dceed8190330fc8648ee56a", /* 1 */
18 "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", /* 2 */
19 "c47800c7266a2be04c571c04d5a6614691ea99bd", /* 3 */
20 "8496071c1b46c854b31185ea97743be6a8774479", /* 4 */
21 "5b5b025afb0b4c913b4c338a42934a3863bf3644", /* 5 */
22};
23
24/* Careful: there are two possible topological sorts */
25static const int commit_sorting_topo[][6] = {
26 {0, 1, 2, 3, 5, 4}, {0, 3, 1, 2, 5, 4}
27};
28
29static const int commit_sorting_time[][6] = {
30 {0, 3, 1, 2, 5, 4}
31};
32
33static const int commit_sorting_topo_reverse[][6] = {
34 {4, 5, 3, 2, 1, 0}, {4, 5, 2, 1, 3, 0}
35};
36
37static const int commit_sorting_time_reverse[][6] = {
38 {4, 5, 2, 1, 3, 0}
39};
40
6708618c 41/* This is specified unsorted, so both combinations are possible */
af079d8b 42static const int commit_sorting_segment[][6] = {
6708618c 43 {1, 2, -1, -1, -1, -1}, {2, 1, -1, -1, -1, -1}
af079d8b
GP
44};
45
8f7be6ca
CMN
46#define commit_count 6
47static const int result_bytes = 24;
48
49
50static int get_commit_index(git_oid *raw_oid)
51{
52 int i;
3b2cb2c9 53 char oid[GIT_OID_HEXSZ];
8f7be6ca
CMN
54
55 git_oid_fmt(oid, raw_oid);
56
57 for (i = 0; i < commit_count; ++i)
3b2cb2c9 58 if (memcmp(oid, commit_ids[i], GIT_OID_HEXSZ) == 0)
8f7be6ca
CMN
59 return i;
60
61 return -1;
62}
63
2932c882
GP
64static int test_walk_only(git_revwalk *walk,
65 const int possible_results[][commit_count], int results_count)
8f7be6ca
CMN
66{
67 git_oid oid;
8f7be6ca
CMN
68 int i;
69 int result_array[commit_count];
70
8f7be6ca
CMN
71 for (i = 0; i < commit_count; ++i)
72 result_array[i] = -1;
73
74 i = 0;
e172cf08 75 while (git_revwalk_next(&oid, walk) == 0) {
8f7be6ca
CMN
76 result_array[i++] = get_commit_index(&oid);
77 /*{
3b2cb2c9 78 char str[GIT_OID_HEXSZ+1];
8f7be6ca 79 git_oid_fmt(str, &oid);
3b2cb2c9 80 str[GIT_OID_HEXSZ] = 0;
8f7be6ca
CMN
81 printf(" %d) %s\n", i, str);
82 }*/
83 }
84
85 for (i = 0; i < results_count; ++i)
86 if (memcmp(possible_results[i],
87 result_array, result_bytes) == 0)
e172cf08 88 return 0;
8f7be6ca
CMN
89
90 return GIT_ERROR;
91}
92
2932c882
GP
93static int test_walk(git_revwalk *walk, const git_oid *root,
94 int flags, const int possible_results[][6], int results_count)
95{
96 git_revwalk_sorting(walk, flags);
97 git_revwalk_push(walk, root);
98
99 return test_walk_only(walk, possible_results, results_count);
100}
101
4cee9b86
RB
102static git_repository *_repo = NULL;
103static git_revwalk *_walk = NULL;
104static const char *_fixture = NULL;
8f7be6ca
CMN
105
106void test_revwalk_basic__initialize(void)
107{
8f7be6ca
CMN
108}
109
110void test_revwalk_basic__cleanup(void)
111{
112 git_revwalk_free(_walk);
4cee9b86
RB
113
114 if (_fixture)
115 cl_git_sandbox_cleanup();
116 else
117 git_repository_free(_repo);
118
119 _fixture = NULL;
9094d30b 120 _repo = NULL;
4cee9b86
RB
121 _walk = NULL;
122}
123
124static void revwalk_basic_setup_walk(const char *fixture)
125{
126 if (fixture) {
127 _fixture = fixture;
128 _repo = cl_git_sandbox_init(fixture);
129 } else {
130 cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git")));
131 }
132
133 cl_git_pass(git_revwalk_new(&_walk, _repo));
8f7be6ca
CMN
134}
135
136void test_revwalk_basic__sorting_modes(void)
137{
138 git_oid id;
139
4cee9b86
RB
140 revwalk_basic_setup_walk(NULL);
141
8f7be6ca
CMN
142 git_oid_fromstr(&id, commit_head);
143
144 cl_git_pass(test_walk(_walk, &id, GIT_SORT_TIME, commit_sorting_time, 1));
145 cl_git_pass(test_walk(_walk, &id, GIT_SORT_TOPOLOGICAL, commit_sorting_topo, 2));
146 cl_git_pass(test_walk(_walk, &id, GIT_SORT_TIME | GIT_SORT_REVERSE, commit_sorting_time_reverse, 1));
147 cl_git_pass(test_walk(_walk, &id, GIT_SORT_TOPOLOGICAL | GIT_SORT_REVERSE, commit_sorting_topo_reverse, 2));
148}
f0fa1c1a
CMN
149
150void test_revwalk_basic__glob_heads(void)
151{
152 int i = 0;
153 git_oid oid;
154
4cee9b86
RB
155 revwalk_basic_setup_walk(NULL);
156
f0fa1c1a
CMN
157 cl_git_pass(git_revwalk_push_glob(_walk, "heads"));
158
6708618c 159 while (git_revwalk_next(&oid, _walk) == 0)
f0fa1c1a 160 i++;
f0fa1c1a 161
5b071115 162 /* git log --branches --oneline | wc -l => 14 */
3bc3d797 163 cl_assert_equal_i(i, 14);
f0fa1c1a 164}
f7367993 165
b7107131
RB
166void test_revwalk_basic__glob_heads_with_invalid(void)
167{
168 int i;
169 git_oid oid;
170
4cee9b86 171 revwalk_basic_setup_walk("testrepo");
b7107131 172
b7107131 173 cl_git_mkfile("testrepo/.git/refs/heads/garbage", "not-a-ref");
b7107131
RB
174 cl_git_pass(git_revwalk_push_glob(_walk, "heads"));
175
176 for (i = 0; !git_revwalk_next(&oid, _walk); ++i)
177 /* walking */;
178
179 /* git log --branches --oneline | wc -l => 16 */
eae0bfdc 180 cl_assert_equal_i(20, i);
b7107131
RB
181}
182
f7367993
CMN
183void test_revwalk_basic__push_head(void)
184{
185 int i = 0;
186 git_oid oid;
187
4cee9b86
RB
188 revwalk_basic_setup_walk(NULL);
189
f7367993
CMN
190 cl_git_pass(git_revwalk_push_head(_walk));
191
e172cf08 192 while (git_revwalk_next(&oid, _walk) == 0) {
f7367993
CMN
193 i++;
194 }
195
196 /* git log HEAD --oneline | wc -l => 7 */
3bc3d797 197 cl_assert_equal_i(i, 7);
f7367993 198}
a4a910dd 199
ac3d33df
JK
200void test_revwalk_basic__sorted_after_reset(void)
201{
202 int i = 0;
203 git_oid oid;
204
205 revwalk_basic_setup_walk(NULL);
206
207 git_oid_fromstr(&oid, commit_head);
208
209 /* push, sort, and test the walk */
210 cl_git_pass(git_revwalk_push(_walk, &oid));
211 git_revwalk_sorting(_walk, GIT_SORT_TIME);
212
213 cl_git_pass(test_walk_only(_walk, commit_sorting_time, 2));
214
215 /* reset, push, and test again - we should see all entries */
216 git_revwalk_reset(_walk);
217 cl_git_pass(git_revwalk_push(_walk, &oid));
218
219 while (git_revwalk_next(&oid, _walk) == 0)
220 i++;
221
222 cl_assert_equal_i(i, commit_count);
223}
224
06b9d915 225void test_revwalk_basic__push_head_hide_ref(void)
a4a910dd
CMN
226{
227 int i = 0;
228 git_oid oid;
229
4cee9b86
RB
230 revwalk_basic_setup_walk(NULL);
231
a4a910dd 232 cl_git_pass(git_revwalk_push_head(_walk));
06b9d915 233 cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/packed-test"));
a4a910dd 234
e172cf08 235 while (git_revwalk_next(&oid, _walk) == 0) {
a4a910dd
CMN
236 i++;
237 }
238
239 /* git log HEAD --oneline --not refs/heads/packed-test | wc -l => 4 */
3bc3d797 240 cl_assert_equal_i(i, 4);
a4a910dd 241}
5cf7bccd
CMN
242
243void test_revwalk_basic__push_head_hide_ref_nobase(void)
244{
245 int i = 0;
246 git_oid oid;
247
4cee9b86
RB
248 revwalk_basic_setup_walk(NULL);
249
5cf7bccd
CMN
250 cl_git_pass(git_revwalk_push_head(_walk));
251 cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/packed"));
252
e172cf08 253 while (git_revwalk_next(&oid, _walk) == 0) {
5cf7bccd
CMN
254 i++;
255 }
256
257 /* git log HEAD --oneline --not refs/heads/packed | wc -l => 7 */
3bc3d797
AG
258 cl_assert_equal_i(i, 7);
259}
260
261/*
262* $ git rev-list HEAD 5b5b02 ^refs/heads/packed-test
263* a65fedf39aefe402d3bb6e24df4d4f5fe4547750
264* be3563ae3f795b2b4353bcce3a527ad0a4f7f644
265* c47800c7266a2be04c571c04d5a6614691ea99bd
266* 9fd738e8f7967c078dceed8190330fc8648ee56a
267
268* $ git log HEAD 5b5b02 --oneline --not refs/heads/packed-test | wc -l => 4
269* a65fedf
270* be3563a Merge branch 'br2'
271* c47800c branch commit one
272* 9fd738e a fourth commit
273*/
274void test_revwalk_basic__multiple_push_1(void)
275{
276 int i = 0;
277 git_oid oid;
278
279 revwalk_basic_setup_walk(NULL);
280
281 cl_git_pass(git_revwalk_push_head(_walk));
282
283 cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/packed-test"));
284
285 cl_git_pass(git_oid_fromstr(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644"));
286 cl_git_pass(git_revwalk_push(_walk, &oid));
287
288 while (git_revwalk_next(&oid, _walk) == 0)
289 i++;
290
291 cl_assert_equal_i(i, 4);
292}
293
294/*
ac3d33df 295* Difference between test_revwalk_basic__multiple_push_1 and
3bc3d797 296* test_revwalk_basic__multiple_push_2 is in the order reference
ac3d33df 297* refs/heads/packed-test and commit 5b5b02 are pushed.
3bc3d797
AG
298* revwalk should return same commits in both the tests.
299
300* $ git rev-list 5b5b02 HEAD ^refs/heads/packed-test
301* a65fedf39aefe402d3bb6e24df4d4f5fe4547750
302* be3563ae3f795b2b4353bcce3a527ad0a4f7f644
303* c47800c7266a2be04c571c04d5a6614691ea99bd
304* 9fd738e8f7967c078dceed8190330fc8648ee56a
305
306* $ git log 5b5b02 HEAD --oneline --not refs/heads/packed-test | wc -l => 4
307* a65fedf
308* be3563a Merge branch 'br2'
309* c47800c branch commit one
310* 9fd738e a fourth commit
311*/
312void test_revwalk_basic__multiple_push_2(void)
313{
314 int i = 0;
315 git_oid oid;
316
317 revwalk_basic_setup_walk(NULL);
318
319 cl_git_pass(git_oid_fromstr(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644"));
320 cl_git_pass(git_revwalk_push(_walk, &oid));
321
322 cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/packed-test"));
323
324 cl_git_pass(git_revwalk_push_head(_walk));
325
326 while (git_revwalk_next(&oid, _walk) == 0)
327 i++;
328
329 cl_assert_equal_i(i, 4);
5cf7bccd 330}
4e323ef0
MS
331
332void test_revwalk_basic__disallow_non_commit(void)
333{
334 git_oid oid;
335
4cee9b86
RB
336 revwalk_basic_setup_walk(NULL);
337
4e323ef0
MS
338 cl_git_pass(git_oid_fromstr(&oid, "521d87c1ec3aef9824daf6d96cc0ae3710766d91"));
339 cl_git_fail(git_revwalk_push(_walk, &oid));
340}
af079d8b 341
5a503fff
CMN
342void test_revwalk_basic__hide_then_push(void)
343{
344 git_oid oid;
345 int i = 0;
346
347 revwalk_basic_setup_walk(NULL);
348 cl_git_pass(git_oid_fromstr(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644"));
349
350 cl_git_pass(git_revwalk_hide(_walk, &oid));
351 cl_git_pass(git_revwalk_push(_walk, &oid));
352
353 while (git_revwalk_next(&oid, _walk) == 0)
354 i++;
355
356 cl_assert_equal_i(i, 0);
357}
358
390431c3
AN
359void test_revwalk_basic__topo_crash(void)
360{
361 git_oid oid;
362 git_oid_fromstr(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644");
363
364 revwalk_basic_setup_walk(NULL);
365 git_revwalk_sorting(_walk, GIT_SORT_TOPOLOGICAL);
366
367 cl_git_pass(git_revwalk_push(_walk, &oid));
368 cl_git_pass(git_revwalk_hide(_walk, &oid));
369
370 git_revwalk_next(&oid, _walk);
371}
372
c11c08a5
AN
373void test_revwalk_basic__from_new_to_old(void)
374{
375 git_oid from_oid, to_oid, oid;
376 int i = 0;
377
378 revwalk_basic_setup_walk(NULL);
379 git_revwalk_sorting(_walk, GIT_SORT_TIME);
380
381 cl_git_pass(git_oid_fromstr(&to_oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644"));
382 cl_git_pass(git_oid_fromstr(&from_oid, "a4a7dce85cf63874e984719f4fdd239f5145052f"));
383
384 cl_git_pass(git_revwalk_push(_walk, &to_oid));
385 cl_git_pass(git_revwalk_hide(_walk, &from_oid));
386
387 while (git_revwalk_next(&oid, _walk) == 0)
388 i++;
389
390 cl_assert_equal_i(i, 0);
391}
392
af079d8b
GP
393void test_revwalk_basic__push_range(void)
394{
4cee9b86
RB
395 revwalk_basic_setup_walk(NULL);
396
af079d8b
GP
397 git_revwalk_reset(_walk);
398 git_revwalk_sorting(_walk, 0);
399 cl_git_pass(git_revwalk_push_range(_walk, "9fd738e~2..9fd738e"));
6708618c 400 cl_git_pass(test_walk_only(_walk, commit_sorting_segment, 2));
af079d8b 401}
b4ef67d5 402
22a2d3d5
UG
403void test_revwalk_basic__push_range_merge_base(void)
404{
405 revwalk_basic_setup_walk(NULL);
406
407 git_revwalk_reset(_walk);
408 git_revwalk_sorting(_walk, 0);
409 cl_git_fail_with(GIT_EINVALIDSPEC, git_revwalk_push_range(_walk, "HEAD...HEAD~2"));
410}
411
412void test_revwalk_basic__push_range_no_range(void)
413{
414 revwalk_basic_setup_walk(NULL);
415
416 git_revwalk_reset(_walk);
417 git_revwalk_sorting(_walk, 0);
418 cl_git_fail_with(GIT_EINVALIDSPEC, git_revwalk_push_range(_walk, "HEAD"));
419}
420
b4ef67d5
CMN
421void test_revwalk_basic__push_mixed(void)
422{
d465e4e9
CMN
423 git_oid oid;
424 int i = 0;
425
b4ef67d5
CMN
426 revwalk_basic_setup_walk(NULL);
427
428 git_revwalk_reset(_walk);
429 git_revwalk_sorting(_walk, 0);
430 cl_git_pass(git_revwalk_push_glob(_walk, "tags"));
d465e4e9
CMN
431
432 while (git_revwalk_next(&oid, _walk) == 0) {
433 i++;
434 }
435
436 /* git rev-list --count --glob=tags #=> 9 */
437 cl_assert_equal_i(9, i);
b4ef67d5 438}
d18209ee
CMN
439
440void test_revwalk_basic__push_all(void)
441{
442 git_oid oid;
443 int i = 0;
444
445 revwalk_basic_setup_walk(NULL);
446
447 git_revwalk_reset(_walk);
448 git_revwalk_sorting(_walk, 0);
449 cl_git_pass(git_revwalk_push_glob(_walk, "*"));
450
451 while (git_revwalk_next(&oid, _walk) == 0) {
452 i++;
453 }
454
455 /* git rev-list --count --all #=> 15 */
456 cl_assert_equal_i(15, i);
457}
5302a885
RB
458
459/*
460* $ git rev-list br2 master e908
461* a65fedf39aefe402d3bb6e24df4d4f5fe4547750
462* e90810b8df3e80c413d903f631643c716887138d
463* 6dcf9bf7541ee10456529833502442f385010c3d
464* a4a7dce85cf63874e984719f4fdd239f5145052f
465* be3563ae3f795b2b4353bcce3a527ad0a4f7f644
466* c47800c7266a2be04c571c04d5a6614691ea99bd
467* 9fd738e8f7967c078dceed8190330fc8648ee56a
468* 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
469* 5b5b025afb0b4c913b4c338a42934a3863bf3644
470* 8496071c1b46c854b31185ea97743be6a8774479
471*/
472
473void test_revwalk_basic__mimic_git_rev_list(void)
474{
475 git_oid oid;
476
477 revwalk_basic_setup_walk(NULL);
478 git_revwalk_sorting(_walk, GIT_SORT_TIME);
479
480 cl_git_pass(git_revwalk_push_ref(_walk, "refs/heads/br2"));
481 cl_git_pass(git_revwalk_push_ref(_walk, "refs/heads/master"));
482 cl_git_pass(git_oid_fromstr(&oid, "e90810b8df3e80c413d903f631643c716887138d"));
483 cl_git_pass(git_revwalk_push(_walk, &oid));
484
485 cl_git_pass(git_revwalk_next(&oid, _walk));
486 cl_assert(!git_oid_streq(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"));
487
488 cl_git_pass(git_revwalk_next(&oid, _walk));
489 cl_assert(!git_oid_streq(&oid, "e90810b8df3e80c413d903f631643c716887138d"));
490
491 cl_git_pass(git_revwalk_next(&oid, _walk));
492 cl_assert(!git_oid_streq(&oid, "6dcf9bf7541ee10456529833502442f385010c3d"));
493
494 cl_git_pass(git_revwalk_next(&oid, _walk));
495 cl_assert(!git_oid_streq(&oid, "a4a7dce85cf63874e984719f4fdd239f5145052f"));
496
497 cl_git_pass(git_revwalk_next(&oid, _walk));
498 cl_assert(!git_oid_streq(&oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
499
500 cl_git_pass(git_revwalk_next(&oid, _walk));
501 cl_assert(!git_oid_streq(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
502
503 cl_git_pass(git_revwalk_next(&oid, _walk));
504 cl_assert(!git_oid_streq(&oid, "9fd738e8f7967c078dceed8190330fc8648ee56a"));
505
506 cl_git_pass(git_revwalk_next(&oid, _walk));
507 cl_assert(!git_oid_streq(&oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045"));
508
509 cl_git_pass(git_revwalk_next(&oid, _walk));
510 cl_assert(!git_oid_streq(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644"));
511
512 cl_git_pass(git_revwalk_next(&oid, _walk));
513 cl_assert(!git_oid_streq(&oid, "8496071c1b46c854b31185ea97743be6a8774479"));
514
515 cl_git_fail_with(git_revwalk_next(&oid, _walk), GIT_ITEROVER);
516}
5ffdea6f
CMN
517
518void test_revwalk_basic__big_timestamp(void)
519{
520 git_reference *head;
521 git_commit *tip;
522 git_signature *sig;
523 git_tree *tree;
524 git_oid id;
525 int error;
526
527 revwalk_basic_setup_walk("testrepo.git");
528
529 cl_git_pass(git_repository_head(&head, _repo));
ac3d33df 530 cl_git_pass(git_reference_peel((git_object **) &tip, head, GIT_OBJECT_COMMIT));
5ffdea6f
CMN
531
532 /* Commit with a far-ahead timestamp, we should be able to parse it in the revwalk */
ac3d33df 533 cl_git_pass(git_signature_new(&sig, "Joe", "joe@example.com", 2399662595ll, 0));
5ffdea6f
CMN
534 cl_git_pass(git_commit_tree(&tree, tip));
535
bbe1957b
VM
536 cl_git_pass(git_commit_create(&id, _repo, "HEAD", sig, sig, NULL, "some message", tree, 1,
537 (const git_commit **)&tip));
5ffdea6f
CMN
538
539 cl_git_pass(git_revwalk_push_head(_walk));
540
541 while ((error = git_revwalk_next(&id, _walk)) == 0) {
542 /* nothing */
543 }
544
545 cl_assert_equal_i(GIT_ITEROVER, error);
546
547 git_tree_free(tree);
548 git_commit_free(tip);
549 git_reference_free(head);
550 git_signature_free(sig);
551
552}
565fb8dc
ET
553
554/* Ensure that we correctly hide a commit that is (timewise) older
555 * than the commits that we are showing.
556 *
557 * % git rev-list 8e73b76..bd75801
558 * bd758010071961f28336333bc41e9c64c9a64866
559 */
560void test_revwalk_basic__old_hidden_commit_one(void)
561{
562 git_oid new_id, old_id, oid;
563
564 revwalk_basic_setup_walk("testrepo.git");
565
566 cl_git_pass(git_oid_fromstr(&new_id, "bd758010071961f28336333bc41e9c64c9a64866"));
567 cl_git_pass(git_revwalk_push(_walk, &new_id));
568
569 cl_git_pass(git_oid_fromstr(&old_id, "8e73b769e97678d684b809b163bebdae2911720f"));
570 cl_git_pass(git_revwalk_hide(_walk, &old_id));
571
572 cl_git_pass(git_revwalk_next(&oid, _walk));
573 cl_assert(!git_oid_streq(&oid, "bd758010071961f28336333bc41e9c64c9a64866"));
574
575 cl_git_fail_with(GIT_ITEROVER, git_revwalk_next(&oid, _walk));
576}
577
578/* Ensure that we correctly hide a commit that is (timewise) older
579 * than the commits that we are showing.
580 *
581 * % git rev-list bd75801 ^b91e763
582 * bd758010071961f28336333bc41e9c64c9a64866
583 */
584void test_revwalk_basic__old_hidden_commit_two(void)
585{
586 git_oid new_id, old_id, oid;
587
588 revwalk_basic_setup_walk("testrepo.git");
589
590 cl_git_pass(git_oid_fromstr(&new_id, "bd758010071961f28336333bc41e9c64c9a64866"));
591 cl_git_pass(git_revwalk_push(_walk, &new_id));
592
593 cl_git_pass(git_oid_fromstr(&old_id, "b91e763008b10db366442469339f90a2b8400d0a"));
594 cl_git_pass(git_revwalk_hide(_walk, &old_id));
595
596 cl_git_pass(git_revwalk_next(&oid, _walk));
597 cl_assert(!git_oid_streq(&oid, "bd758010071961f28336333bc41e9c64c9a64866"));
598
599 cl_git_fail_with(GIT_ITEROVER, git_revwalk_next(&oid, _walk));
600}
4b3ec53c
XL
601
602/*
603 * Ensure that we correctly hide all parent commits of a newer
604 * commit when first hiding older commits.
605 *
606 * % git rev-list D ^B ^A ^E
607 * 790ba0facf6fd103699a5c40cd19dad277ff49cd
608 * b82cee5004151ae0c4f82b69fb71b87477664b6f
609 */
610void test_revwalk_basic__newer_hidden_commit_hides_old_commits(void)
611{
612 git_oid oid;
613
614 revwalk_basic_setup_walk("revwalk.git");
615
616 cl_git_pass(git_revwalk_push_ref(_walk, "refs/heads/D"));
617 cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/B"));
618 cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/A"));
619 cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/E"));
620
621 cl_git_pass(git_revwalk_next(&oid, _walk));
622 cl_assert(git_oid_streq(&oid, "b82cee5004151ae0c4f82b69fb71b87477664b6f"));
623 cl_git_pass(git_revwalk_next(&oid, _walk));
624 cl_assert(git_oid_streq(&oid, "790ba0facf6fd103699a5c40cd19dad277ff49cd"));
625
626 cl_git_fail_with(GIT_ITEROVER, git_revwalk_next(&oid, _walk));
627}