453
git -C dup commit-graph verify
454
'
455
456
+NUM_FIRST_LAYER_COMMITS=64
457
+NUM_SECOND_LAYER_COMMITS=16
458
+NUM_THIRD_LAYER_COMMITS=7
459
+NUM_FOURTH_LAYER_COMMITS=8
460
+NUM_FIFTH_LAYER_COMMITS=16
461
+SECOND_LAYER_SEQUENCE_START=$(($NUM_FIRST_LAYER_COMMITS + 1))
462
+SECOND_LAYER_SEQUENCE_END=$(($SECOND_LAYER_SEQUENCE_START + $NUM_SECOND_LAYER_COMMITS - 1))
463
+THIRD_LAYER_SEQUENCE_START=$(($SECOND_LAYER_SEQUENCE_END + 1))
464
+THIRD_LAYER_SEQUENCE_END=$(($THIRD_LAYER_SEQUENCE_START + $NUM_THIRD_LAYER_COMMITS - 1))
465
+FOURTH_LAYER_SEQUENCE_START=$(($THIRD_LAYER_SEQUENCE_END + 1))
466
+FOURTH_LAYER_SEQUENCE_END=$(($FOURTH_LAYER_SEQUENCE_START + $NUM_FOURTH_LAYER_COMMITS - 1))
467
+FIFTH_LAYER_SEQUENCE_START=$(($FOURTH_LAYER_SEQUENCE_END + 1))
468
+FIFTH_LAYER_SEQUENCE_END=$(($FIFTH_LAYER_SEQUENCE_START + $NUM_FIFTH_LAYER_COMMITS - 1))
469
+
470
+# Current split graph chain:
471
+#
472
+# 16 commits (No GDAT)
473
+# ------------------------
474
+# 64 commits (GDAT)
475
+#
476
+test_expect_success 'setup repo for mixed generation commit-graph-chain' '
477
+ graphdir=".git/objects/info/commit-graphs" &&
478
+ test_oid_cache <<-EOF &&
479
+ oid_version sha1:1
480
+ oid_version sha256:2
481
+ EOF
482
+ git init mixed &&
483
+ (
484
+ cd mixed &&
485
+ git config core.commitGraph true &&
486
+ git config gc.writeCommitGraph false &&
487
+ for i in $(test_seq $NUM_FIRST_LAYER_COMMITS)
488
+ do
489
+ test_commit $i &&
490
+ git branch commits/$i || return 1
491
+ done &&
492
+ git commit-graph write --reachable --split &&
493
+ graph_read_expect $NUM_FIRST_LAYER_COMMITS &&
494
+ test_line_count = 1 $graphdir/commit-graph-chain &&
495
+ for i in $(test_seq $SECOND_LAYER_SEQUENCE_START $SECOND_LAYER_SEQUENCE_END)
496
+ do
497
+ test_commit $i &&
498
+ git branch commits/$i || return 1
499
+ done &&
500
+ GIT_TEST_COMMIT_GRAPH_NO_GDAT=1 git commit-graph write --reachable --split=no-merge &&
501
+ test_line_count = 2 $graphdir/commit-graph-chain &&
502
+ test-tool read-graph >output &&
503
+ cat >expect <<-EOF &&
504
+ header: 43475048 1 $(test_oid oid_version) 4 1
505
+ num_commits: $NUM_SECOND_LAYER_COMMITS
506
+ chunks: oid_fanout oid_lookup commit_metadata
507
+ EOF
508
+ test_cmp expect output &&
509
+ git commit-graph verify &&
510
+ cat $graphdir/commit-graph-chain
511
+ )
512
+'
513
+
514
+# The new layer will be added without generation data chunk as it was not
515
+# present on the layer underneath it.
516
+#
517
+# 7 commits (No GDAT)
518
+# ------------------------
519
+# 16 commits (No GDAT)
520
+# ------------------------
521
+# 64 commits (GDAT)
522
+#
523
+test_expect_success 'do not write generation data chunk if not present on existing tip' '
524
+ git clone mixed mixed-no-gdat &&
525
+ (
526
+ cd mixed-no-gdat &&
527
+ for i in $(test_seq $THIRD_LAYER_SEQUENCE_START $THIRD_LAYER_SEQUENCE_END)
528
+ do
529
+ test_commit $i &&
530
+ git branch commits/$i || return 1
531
+ done &&
532
+ git commit-graph write --reachable --split=no-merge &&
533
+ test_line_count = 3 $graphdir/commit-graph-chain &&
534
+ test-tool read-graph >output &&
535
+ cat >expect <<-EOF &&
536
+ header: 43475048 1 $(test_oid oid_version) 4 2
537
+ num_commits: $NUM_THIRD_LAYER_COMMITS
538
+ chunks: oid_fanout oid_lookup commit_metadata
539
+ EOF
540
+ test_cmp expect output &&
541
+ git commit-graph verify
542
+ )
543
+'
544
+
545
+# Number of commits in each layer of the split-commit graph before merge:
546
+#
547
+# 8 commits (No GDAT)
548
+# ------------------------
549
+# 7 commits (No GDAT)
550
+# ------------------------
551
+# 16 commits (No GDAT)
552
+# ------------------------
553
+# 64 commits (GDAT)
554
+#
555
+# The top two layers are merged and do not have generation data chunk as layer below them does
556
+# not have generation data chunk.
557
+#
558
+# 15 commits (No GDAT)
559
+# ------------------------
560
+# 16 commits (No GDAT)
561
+# ------------------------
562
+# 64 commits (GDAT)
563
+#
564
+test_expect_success 'do not write generation data chunk if the topmost remaining layer does not have generation data chunk' '
565
+ git clone mixed-no-gdat mixed-merge-no-gdat &&
566
+ (
567
+ cd mixed-merge-no-gdat &&
568
+ for i in $(test_seq $FOURTH_LAYER_SEQUENCE_START $FOURTH_LAYER_SEQUENCE_END)
569
+ do
570
+ test_commit $i &&
571
+ git branch commits/$i || return 1
572
+ done &&
573
+ git commit-graph write --reachable --split --size-multiple 1 &&
574
+ test_line_count = 3 $graphdir/commit-graph-chain &&
575
+ test-tool read-graph >output &&
576
+ cat >expect <<-EOF &&
577
+ header: 43475048 1 $(test_oid oid_version) 4 2
578
+ num_commits: $(($NUM_THIRD_LAYER_COMMITS + $NUM_FOURTH_LAYER_COMMITS))
579
+ chunks: oid_fanout oid_lookup commit_metadata
580
+ EOF
581
+ test_cmp expect output &&
582
+ git commit-graph verify
583
+ )
584
+'
585
+
586
+# Number of commits in each layer of the split-commit graph before merge:
587
+#
588
+# 16 commits (No GDAT)
589
+# ------------------------
590
+# 15 commits (No GDAT)
591
+# ------------------------
592
+# 16 commits (No GDAT)
593
+# ------------------------
594
+# 64 commits (GDAT)
595
+#
596
+# The top three layers are merged and has generation data chunk as the topmost remaining layer
597
+# has generation data chunk.
598
+#
599
+# 47 commits (GDAT)
600
+# ------------------------
601
+# 64 commits (GDAT)
602
+#
603
+test_expect_success 'write generation data chunk if topmost remaining layer has generation data chunk' '
604
+ git clone mixed-merge-no-gdat mixed-merge-gdat &&
605
+ (
606
+ cd mixed-merge-gdat &&
607
+ for i in $(test_seq $FIFTH_LAYER_SEQUENCE_START $FIFTH_LAYER_SEQUENCE_END)
608
+ do
609
+ test_commit $i &&
610
+ git branch commits/$i || return 1
611
+ done &&
612
+ git commit-graph write --reachable --split --size-multiple 1 &&
613
+ test_line_count = 2 $graphdir/commit-graph-chain &&
614
+ test-tool read-graph >output &&
615
+ cat >expect <<-EOF &&
616
+ header: 43475048 1 $(test_oid oid_version) 5 1
617
+ num_commits: $(($NUM_SECOND_LAYER_COMMITS + $NUM_THIRD_LAYER_COMMITS + $NUM_FOURTH_LAYER_COMMITS + $NUM_FIFTH_LAYER_COMMITS))
618
+ chunks: oid_fanout oid_lookup commit_metadata generation_data
619
+ EOF
620
+ test_cmp expect output
621
+ )
622
+'
623
+
624
+test_expect_success 'write generation data chunk when commit-graph chain is replaced' '
625
+ git clone mixed mixed-replace &&
626
+ (
627
+ cd mixed-replace &&
628
+ git commit-graph write --reachable --split=replace &&
629
+ test_path_is_file $graphdir/commit-graph-chain &&
630
+ test_line_count = 1 $graphdir/commit-graph-chain &&
631
+ verify_chain_files_exist $graphdir &&
632
+ graph_read_expect $(($NUM_FIRST_LAYER_COMMITS + $NUM_SECOND_LAYER_COMMITS)) &&
633
+ git commit-graph verify
634
+ )
635
+'
636
+
637
test_done