488
test_must_be_empty err
489
'
490
491
+# chosen to be the same under all Unicode normalization forms
492
+CENT=$(printf "\302\242")
493
+
494
+test_expect_success 'ensure Bloom filter with incompatible versions are ignored' '
495
+ rm "$repo/$graph" &&
496
+
497
+ git -C $repo log --oneline --no-decorate -- $CENT >expect &&
498
+
499
+ # Compute v1 Bloom filters for commits at the bottom.
500
+ git -C $repo rev-parse HEAD^ >in &&
501
+ git -C $repo commit-graph write --stdin-commits --changed-paths \
502
+ --split <in &&
503
+
504
+ # Compute v2 Bloomfilters for the rest of the commits at the top.
505
+ git -C $repo rev-parse HEAD >in &&
506
+ git -C $repo -c commitGraph.changedPathsVersion=2 commit-graph write \
507
+ --stdin-commits --changed-paths --split=no-merge <in &&
508
+
509
+ test_line_count = 2 $repo/$chain &&
510
+
511
+ git -C $repo log --oneline --no-decorate -- $CENT >actual 2>err &&
512
+ test_cmp expect actual &&
513
+
514
+ layer="$(head -n 1 $repo/$chain)" &&
515
+ cat >expect.err <<-EOF &&
516
+ warning: disabling Bloom filters for commit-graph layer $SQ$layer$SQ due to incompatible settings
517
+ EOF
518
+ test_cmp expect.err err &&
519
+
520
+ # Merge the two layers with incompatible bloom filter versions,
521
+ # ensuring that the v2 filters are used.
522
+ >trace2.txt &&
523
+ GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
524
+ git -C $repo -c commitGraph.changedPathsVersion=2 commit-graph write --reachable --changed-paths 2>err &&
525
+ grep "disabling Bloom filters for commit-graph layer .$layer." err &&
526
+ grep "{\"hash_version\":2,\"num_hashes\":7,\"bits_per_entry\":10,\"max_changed_paths\":512" trace2.txt
527
+'
528
+
529
get_first_changed_path_filter () {
530
test-tool read-graph bloom-filters >filters.dat &&
531
head -n 1 filters.dat
532
}
533
496
-# chosen to be the same under all Unicode normalization forms
497
-CENT=$(printf "\302\242")
498
-
534
test_expect_success 'set up repo with high bit path, version 1 changed-path' '
535
git init highbit1 &&
536
test_commit -C highbit1 c1 "$CENT" &&
574
)
575
'
576
577
+test_expect_success 'version 1 changed-path not used when version 2 requested' '
578
+ (
579
+ cd highbit1 &&
580
+ git config --add commitGraph.changedPathsVersion 2 &&
581
+ test_bloom_filters_not_used "-- another$CENT"
582
+ )
583
+'
584
+
585
+test_expect_success 'version 1 changed-path used when autodetect requested' '
586
+ (
587
+ cd highbit1 &&
588
+ git config --add commitGraph.changedPathsVersion -1 &&
589
+ test_bloom_filters_used "-- another$CENT"
590
+ )
591
+'
592
+
593
+test_expect_success 'when writing another commit graph, preserve existing version 1 of changed-path' '
594
+ test_commit -C highbit1 c1double "$CENT$CENT" &&
595
+ git -C highbit1 commit-graph write --reachable --changed-paths &&
596
+ (
597
+ cd highbit1 &&
598
+ git config --add commitGraph.changedPathsVersion -1 &&
599
+ echo "options: bloom(1,10,7) read_generation_data" >expect &&
600
+ test-tool read-graph >full &&
601
+ grep options full >actual &&
602
+ test_cmp expect actual
603
+ )
604
+'
605
+
606
+test_expect_success 'set up repo with high bit path, version 2 changed-path' '
607
+ git init highbit2 &&
608
+ git -C highbit2 config --add commitGraph.changedPathsVersion 2 &&
609
+ test_commit -C highbit2 c2 "$CENT" &&
610
+ git -C highbit2 commit-graph write --reachable --changed-paths
611
+'
612
+
613
+test_expect_success 'check value of version 2 changed-path' '
614
+ (
615
+ cd highbit2 &&
616
+ echo "c01f" >expect &&
617
+ get_first_changed_path_filter >actual &&
618
+ test_cmp expect actual
619
+ )
620
+'
621
+
622
+test_expect_success 'setup make another commit' '
623
+ # "git log" does not use Bloom filters for root commits - see how, in
624
+ # revision.c, rev_compare_tree() (the only code path that eventually calls
625
+ # get_bloom_filter()) is only called by try_to_simplify_commit() when the commit
626
+ # has one parent. Therefore, make another commit so that we perform the tests on
627
+ # a non-root commit.
628
+ test_commit -C highbit2 anotherc2 "another$CENT"
629
+'
630
+
631
+test_expect_success 'version 2 changed-path used when version 2 requested' '
632
+ (
633
+ cd highbit2 &&
634
+ test_bloom_filters_used "-- another$CENT"
635
+ )
636
+'
637
+
638
+test_expect_success 'version 2 changed-path not used when version 1 requested' '
639
+ (
640
+ cd highbit2 &&
641
+ git config --add commitGraph.changedPathsVersion 1 &&
642
+ test_bloom_filters_not_used "-- another$CENT"
643
+ )
644
+'
645
+
646
+test_expect_success 'version 2 changed-path used when autodetect requested' '
647
+ (
648
+ cd highbit2 &&
649
+ git config --add commitGraph.changedPathsVersion -1 &&
650
+ test_bloom_filters_used "-- another$CENT"
651
+ )
652
+'
653
+
654
+test_expect_success 'when writing another commit graph, preserve existing version 2 of changed-path' '
655
+ test_commit -C highbit2 c2double "$CENT$CENT" &&
656
+ git -C highbit2 commit-graph write --reachable --changed-paths &&
657
+ (
658
+ cd highbit2 &&
659
+ git config --add commitGraph.changedPathsVersion -1 &&
660
+ echo "options: bloom(2,10,7) read_generation_data" >expect &&
661
+ test-tool read-graph >full &&
662
+ grep options full >actual &&
663
+ test_cmp expect actual
664
+ )
665
+'
666
+
667
+test_expect_success 'when writing commit graph, do not reuse changed-path of another version' '
668
+ git init doublewrite &&
669
+ test_commit -C doublewrite c "$CENT" &&
670
+ git -C doublewrite config --add commitGraph.changedPathsVersion 1 &&
671
+ git -C doublewrite commit-graph write --reachable --changed-paths &&
672
+ for v in -2 3
673
+ do
674
+ git -C doublewrite config --add commitGraph.changedPathsVersion $v &&
675
+ git -C doublewrite commit-graph write --reachable --changed-paths 2>err &&
676
+ cat >expect <<-EOF &&
677
+ warning: attempting to write a commit-graph, but ${SQ}commitGraph.changedPathsVersion${SQ} ($v) is not supported
678
+ EOF
679
+ test_cmp expect err || return 1
680
+ done &&
681
+ git -C doublewrite config --add commitGraph.changedPathsVersion 2 &&
682
+ git -C doublewrite commit-graph write --reachable --changed-paths &&
683
+ (
684
+ cd doublewrite &&
685
+ echo "c01f" >expect &&
686
+ get_first_changed_path_filter >actual &&
687
+ test_cmp expect actual
688
+ )
689
+'
690
+
691
corrupt_graph () {
692
test_when_finished "rm -rf $graph" &&
693
git commit-graph write --reachable --changed-paths &&