t/t5329-pack-objects-cruft.sh: evict 'repack'-related tests

The cruft pack feature has two primary test scripts which exercise various parts of it, which are: - t5329-pack-objects-cruft.sh - t7704-repack-cruft.sh The former is designed to test low-level pack generation mechanics at the 'git pack-objects --cruft'-level, which is plumbing. The latter, on the other hand, is designed to test the user-facing behavior through 'git repack --cruft', which is porcelain (under the "ancillary manipulators" sub-section). At some point a handful of tests which should have been added to the latter script were instead written to the former. This isn't a huge deal, but rectifying it is straightforward. Move a handful of 'repack'-related tests out of t5329 and into their rightful home in t7704. Signed-off-by: Taylor Blau <me@ttaylorr.com> Acked-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Mar 19, 2025 at 18:52 UTC cee95f2670cefd19f16ec283a673bc6809564bc4
2 files changed +250 -250
t/t5329-pack-objects-cruft.sh
-250
@@ -360,43 +360,6 @@ test_expect_success 'expired objects are pruned' '
360 )
361 '
362
363 -test_expect_success 'repack --cruft generates a cruft pack' '
364 - git init repo &&
365 - test_when_finished "rm -fr repo" &&
366 - (
367 - cd repo &&
368 -
369 - test_commit reachable &&
370 - git branch -M main &&
371 - git checkout --orphan other &&
372 - test_commit unreachable &&
373 -
374 - git checkout main &&
375 - git branch -D other &&
376 - git tag -d unreachable &&
377 - # objects are not cruft if they are contained in the reflogs
378 - git reflog expire --all --expire=all &&
379 -
380 - git rev-list --objects --all --no-object-names >reachable.raw &&
381 - git cat-file --batch-all-objects --batch-check="%(objectname)" >objects &&
382 - sort <reachable.raw >reachable &&
383 - comm -13 reachable objects >unreachable &&
384 -
385 - git repack --cruft -d &&
386 -
387 - cruft=$(basename $(ls $packdir/pack-*.mtimes) .mtimes) &&
388 - pack=$(basename $(ls $packdir/pack-*.pack | grep -v $cruft) .pack) &&
389 -
390 - git show-index <$packdir/$pack.idx >actual.raw &&
391 - cut -f2 -d" " actual.raw | sort >actual &&
392 - test_cmp reachable actual &&
393 -
394 - git show-index <$packdir/$cruft.idx >actual.raw &&
395 - cut -f2 -d" " actual.raw | sort >actual &&
396 - test_cmp unreachable actual
397 - )
398 -'
399 -
363 test_expect_success 'loose objects mtimes upsert others' '
364 git init repo &&
365 test_when_finished "rm -fr repo" &&
@@ -470,219 +433,6 @@ test_expect_success 'expiring cruft objects with git gc' '
433 )
434 '
435
473 -test_expect_success 'cruft packs are not included in geometric repack' '
474 - git init repo &&
475 - test_when_finished "rm -fr repo" &&
476 - (
477 - cd repo &&
478 -
479 - test_commit reachable &&
480 - git repack -Ad &&
481 - git branch -M main &&
482 -
483 - git checkout --orphan other &&
484 - test_commit cruft &&
485 - git repack -d &&
486 -
487 - git checkout main &&
488 - git branch -D other &&
489 - git tag -d cruft &&
490 - git reflog expire --all --expire=all &&
491 -
492 - git repack --cruft &&
493 -
494 - find $packdir -type f | sort >before &&
495 - git repack --geometric=2 -d &&
496 - find $packdir -type f | sort >after &&
497 -
498 - test_cmp before after
499 - )
500 -'
501 -
502 -test_expect_success 'repack --geometric collects once-cruft objects' '
503 - git init repo &&
504 - test_when_finished "rm -fr repo" &&
505 - (
506 - cd repo &&
507 -
508 - test_commit reachable &&
509 - git repack -Ad &&
510 - git branch -M main &&
511 -
512 - git checkout --orphan other &&
513 - git rm -rf . &&
514 - test_commit --no-tag cruft &&
515 - cruft="$(git rev-parse HEAD)" &&
516 -
517 - git checkout main &&
518 - git branch -D other &&
519 - git reflog expire --all --expire=all &&
520 -
521 - # Pack the objects created in the previous step into a cruft
522 - # pack. Intentionally leave loose copies of those objects
523 - # around so we can pick them up in a subsequent --geometric
524 - # reapack.
525 - git repack --cruft &&
526 -
527 - # Now make those objects reachable, and ensure that they are
528 - # packed into the new pack created via a --geometric repack.
529 - git update-ref refs/heads/other $cruft &&
530 -
531 - # Without this object, the set of unpacked objects is exactly
532 - # the set of objects already in the cruft pack. Tweak that set
533 - # to ensure we do not overwrite the cruft pack entirely.
534 - test_commit reachable2 &&
535 -
536 - find $packdir -name "pack-*.idx" | sort >before &&
537 - git repack --geometric=2 -d &&
538 - find $packdir -name "pack-*.idx" | sort >after &&
539 -
540 - {
541 - git rev-list --objects --no-object-names $cruft &&
542 - git rev-list --objects --no-object-names reachable..reachable2
543 - } >want.raw &&
544 - sort want.raw >want &&
545 -
546 - pack=$(comm -13 before after) &&
547 - git show-index <$pack >objects.raw &&
548 -
549 - cut -d" " -f2 objects.raw | sort >got &&
550 -
551 - test_cmp want got
552 - )
553 -'
554 -
555 -test_expect_success 'cruft repack with no reachable objects' '
556 - git init repo &&
557 - test_when_finished "rm -fr repo" &&
558 - (
559 - cd repo &&
560 -
561 - test_commit base &&
562 - git repack -ad &&
563 -
564 - base="$(git rev-parse base)" &&
565 -
566 - git for-each-ref --format="delete %(refname)" >in &&
567 - git update-ref --stdin <in &&
568 - git reflog expire --all --expire=all &&
569 - rm -fr .git/index &&
570 -
571 - git repack --cruft -d &&
572 -
573 - git cat-file -t $base
574 - )
575 -'
576 -
577 -write_blob () {
578 - test-tool genrandom "$@" >in &&
579 - git hash-object -w -t blob in
580 -}
581 -
582 -find_pack () {
583 - for idx in $(ls $packdir/pack-*.idx)
584 - do
585 - git show-index <$idx >out &&
586 - if grep -q "$1" out
587 - then
588 - echo $idx
589 - fi || return 1
590 - done
591 -}
592 -
593 -test_expect_success 'cruft repack with --max-pack-size' '
594 - git init max-pack-size &&
595 - (
596 - cd max-pack-size &&
597 - test_commit base &&
598 -
599 - # two cruft objects which exceed the maximum pack size
600 - foo=$(write_blob foo 1048576) &&
601 - bar=$(write_blob bar 1048576) &&
602 - test-tool chmtime --get -1000 \
603 - "$objdir/$(test_oid_to_path $foo)" >foo.mtime &&
604 - test-tool chmtime --get -2000 \
605 - "$objdir/$(test_oid_to_path $bar)" >bar.mtime &&
606 - git repack --cruft --max-pack-size=1M &&
607 - find $packdir -name "*.mtimes" >cruft &&
608 - test_line_count = 2 cruft &&
609 -
610 - foo_mtimes="$(basename $(find_pack $foo) .idx).mtimes" &&
611 - bar_mtimes="$(basename $(find_pack $bar) .idx).mtimes" &&
612 - test-tool pack-mtimes $foo_mtimes >foo.actual &&
613 - test-tool pack-mtimes $bar_mtimes >bar.actual &&
614 -
615 - echo "$foo $(cat foo.mtime)" >foo.expect &&
616 - echo "$bar $(cat bar.mtime)" >bar.expect &&
617 -
618 - test_cmp foo.expect foo.actual &&
619 - test_cmp bar.expect bar.actual &&
620 - test "$foo_mtimes" != "$bar_mtimes"
621 - )
622 -'
623 -
624 -test_expect_success 'cruft repack with pack.packSizeLimit' '
625 - (
626 - cd max-pack-size &&
627 - # repack everything back together to remove the existing cruft
628 - # pack (but to keep its objects)
629 - git repack -adk &&
630 - git -c pack.packSizeLimit=1M repack --cruft &&
631 - # ensure the same post condition is met when --max-pack-size
632 - # would otherwise be inferred from the configuration
633 - find $packdir -name "*.mtimes" >cruft &&
634 - test_line_count = 2 cruft &&
635 - for pack in $(cat cruft)
636 - do
637 - test-tool pack-mtimes "$(basename $pack)" >objects &&
638 - test_line_count = 1 objects || return 1
639 - done
640 - )
641 -'
642 -
643 -test_expect_success 'cruft repack respects repack.cruftWindow' '
644 - git init repo &&
645 - test_when_finished "rm -fr repo" &&
646 - (
647 - cd repo &&
648 -
649 - test_commit base &&
650 -
651 - GIT_TRACE2_EVENT=$(pwd)/event.trace \
652 - git -c pack.window=1 -c repack.cruftWindow=2 repack \
653 - --cruft --window=3 &&
654 -
655 - grep "pack-objects.*--window=2.*--cruft" event.trace
656 - )
657 -'
658 -
659 -test_expect_success 'cruft repack respects --window by default' '
660 - git init repo &&
661 - test_when_finished "rm -fr repo" &&
662 - (
663 - cd repo &&
664 -
665 - test_commit base &&
666 -
667 - GIT_TRACE2_EVENT=$(pwd)/event.trace \
668 - git -c pack.window=2 repack --cruft --window=3 &&
669 -
670 - grep "pack-objects.*--window=3.*--cruft" event.trace
671 - )
672 -'
673 -
674 -test_expect_success 'cruft repack respects --quiet' '
675 - git init repo &&
676 - test_when_finished "rm -fr repo" &&
677 - (
678 - cd repo &&
679 -
680 - test_commit base &&
681 - GIT_PROGRESS_DELAY=0 git repack --cruft --quiet 2>err &&
682 - test_must_be_empty err
683 - )
684 -'
685 -
436 test_expect_success 'cruft --local drops unreachable objects' '
437 git init alternate &&
438 git init repo &&
t/t7704-repack-cruft.sh
+250
@@ -477,4 +477,254 @@ test_expect_success 'reachable packs are preferred over cruft ones' '
477 )
478 '
479
480 +test_expect_success 'repack --cruft generates a cruft pack' '
481 + git init repo &&
482 + test_when_finished "rm -fr repo" &&
483 + (
484 + cd repo &&
485 +
486 + test_commit reachable &&
487 + git branch -M main &&
488 + git checkout --orphan other &&
489 + test_commit unreachable &&
490 +
491 + git checkout main &&
492 + git branch -D other &&
493 + git tag -d unreachable &&
494 + # objects are not cruft if they are contained in the reflogs
495 + git reflog expire --all --expire=all &&
496 +
497 + git rev-list --objects --all --no-object-names >reachable.raw &&
498 + git cat-file --batch-all-objects --batch-check="%(objectname)" >objects &&
499 + sort <reachable.raw >reachable &&
500 + comm -13 reachable objects >unreachable &&
501 +
502 + git repack --cruft -d &&
503 +
504 + cruft=$(basename $(ls $packdir/pack-*.mtimes) .mtimes) &&
505 + pack=$(basename $(ls $packdir/pack-*.pack | grep -v $cruft) .pack) &&
506 +
507 + git show-index <$packdir/$pack.idx >actual.raw &&
508 + cut -f2 -d" " actual.raw | sort >actual &&
509 + test_cmp reachable actual &&
510 +
511 + git show-index <$packdir/$cruft.idx >actual.raw &&
512 + cut -f2 -d" " actual.raw | sort >actual &&
513 + test_cmp unreachable actual
514 + )
515 +'
516 +
517 +test_expect_success 'cruft packs are not included in geometric repack' '
518 + git init repo &&
519 + test_when_finished "rm -fr repo" &&
520 + (
521 + cd repo &&
522 +
523 + test_commit reachable &&
524 + git repack -Ad &&
525 + git branch -M main &&
526 +
527 + git checkout --orphan other &&
528 + test_commit cruft &&
529 + git repack -d &&
530 +
531 + git checkout main &&
532 + git branch -D other &&
533 + git tag -d cruft &&
534 + git reflog expire --all --expire=all &&
535 +
536 + git repack --cruft &&
537 +
538 + find $packdir -type f | sort >before &&
539 + git repack --geometric=2 -d &&
540 + find $packdir -type f | sort >after &&
541 +
542 + test_cmp before after
543 + )
544 +'
545 +
546 +test_expect_success 'repack --geometric collects once-cruft objects' '
547 + git init repo &&
548 + test_when_finished "rm -fr repo" &&
549 + (
550 + cd repo &&
551 +
552 + test_commit reachable &&
553 + git repack -Ad &&
554 + git branch -M main &&
555 +
556 + git checkout --orphan other &&
557 + git rm -rf . &&
558 + test_commit --no-tag cruft &&
559 + cruft="$(git rev-parse HEAD)" &&
560 +
561 + git checkout main &&
562 + git branch -D other &&
563 + git reflog expire --all --expire=all &&
564 +
565 + # Pack the objects created in the previous step into a cruft
566 + # pack. Intentionally leave loose copies of those objects
567 + # around so we can pick them up in a subsequent --geometric
568 + # reapack.
569 + git repack --cruft &&
570 +
571 + # Now make those objects reachable, and ensure that they are
572 + # packed into the new pack created via a --geometric repack.
573 + git update-ref refs/heads/other $cruft &&
574 +
575 + # Without this object, the set of unpacked objects is exactly
576 + # the set of objects already in the cruft pack. Tweak that set
577 + # to ensure we do not overwrite the cruft pack entirely.
578 + test_commit reachable2 &&
579 +
580 + find $packdir -name "pack-*.idx" | sort >before &&
581 + git repack --geometric=2 -d &&
582 + find $packdir -name "pack-*.idx" | sort >after &&
583 +
584 + {
585 + git rev-list --objects --no-object-names $cruft &&
586 + git rev-list --objects --no-object-names reachable..reachable2
587 + } >want.raw &&
588 + sort want.raw >want &&
589 +
590 + pack=$(comm -13 before after) &&
591 + git show-index <$pack >objects.raw &&
592 +
593 + cut -d" " -f2 objects.raw | sort >got &&
594 +
595 + test_cmp want got
596 + )
597 +'
598 +
599 +test_expect_success 'cruft repack with no reachable objects' '
600 + git init repo &&
601 + test_when_finished "rm -fr repo" &&
602 + (
603 + cd repo &&
604 +
605 + test_commit base &&
606 + git repack -ad &&
607 +
608 + base="$(git rev-parse base)" &&
609 +
610 + git for-each-ref --format="delete %(refname)" >in &&
611 + git update-ref --stdin <in &&
612 + git reflog expire --all --expire=all &&
613 + rm -fr .git/index &&
614 +
615 + git repack --cruft -d &&
616 +
617 + git cat-file -t $base
618 + )
619 +'
620 +
621 +write_blob () {
622 + test-tool genrandom "$@" >in &&
623 + git hash-object -w -t blob in
624 +}
625 +
626 +find_pack () {
627 + for idx in $(ls $packdir/pack-*.idx)
628 + do
629 + git show-index <$idx >out &&
630 + if grep -q "$1" out
631 + then
632 + echo $idx
633 + fi || return 1
634 + done
635 +}
636 +
637 +test_expect_success 'cruft repack with --max-pack-size' '
638 + git init max-pack-size &&
639 + (
640 + cd max-pack-size &&
641 + test_commit base &&
642 +
643 + # two cruft objects which exceed the maximum pack size
644 + foo=$(write_blob foo 1048576) &&
645 + bar=$(write_blob bar 1048576) &&
646 + test-tool chmtime --get -1000 \
647 + "$objdir/$(test_oid_to_path $foo)" >foo.mtime &&
648 + test-tool chmtime --get -2000 \
649 + "$objdir/$(test_oid_to_path $bar)" >bar.mtime &&
650 + git repack --cruft --max-pack-size=1M &&
651 + find $packdir -name "*.mtimes" >cruft &&
652 + test_line_count = 2 cruft &&
653 +
654 + foo_mtimes="$(basename $(find_pack $foo) .idx).mtimes" &&
655 + bar_mtimes="$(basename $(find_pack $bar) .idx).mtimes" &&
656 + test-tool pack-mtimes $foo_mtimes >foo.actual &&
657 + test-tool pack-mtimes $bar_mtimes >bar.actual &&
658 +
659 + echo "$foo $(cat foo.mtime)" >foo.expect &&
660 + echo "$bar $(cat bar.mtime)" >bar.expect &&
661 +
662 + test_cmp foo.expect foo.actual &&
663 + test_cmp bar.expect bar.actual &&
664 + test "$foo_mtimes" != "$bar_mtimes"
665 + )
666 +'
667 +
668 +test_expect_success 'cruft repack with pack.packSizeLimit' '
669 + (
670 + cd max-pack-size &&
671 + # repack everything back together to remove the existing cruft
672 + # pack (but to keep its objects)
673 + git repack -adk &&
674 + git -c pack.packSizeLimit=1M repack --cruft &&
675 + # ensure the same post condition is met when --max-pack-size
676 + # would otherwise be inferred from the configuration
677 + find $packdir -name "*.mtimes" >cruft &&
678 + test_line_count = 2 cruft &&
679 + for pack in $(cat cruft)
680 + do
681 + test-tool pack-mtimes "$(basename $pack)" >objects &&
682 + test_line_count = 1 objects || return 1
683 + done
684 + )
685 +'
686 +
687 +test_expect_success 'cruft repack respects repack.cruftWindow' '
688 + git init repo &&
689 + test_when_finished "rm -fr repo" &&
690 + (
691 + cd repo &&
692 +
693 + test_commit base &&
694 +
695 + GIT_TRACE2_EVENT=$(pwd)/event.trace \
696 + git -c pack.window=1 -c repack.cruftWindow=2 repack \
697 + --cruft --window=3 &&
698 +
699 + grep "pack-objects.*--window=2.*--cruft" event.trace
700 + )
701 +'
702 +
703 +test_expect_success 'cruft repack respects --window by default' '
704 + git init repo &&
705 + test_when_finished "rm -fr repo" &&
706 + (
707 + cd repo &&
708 +
709 + test_commit base &&
710 +
711 + GIT_TRACE2_EVENT=$(pwd)/event.trace \
712 + git -c pack.window=2 repack --cruft --window=3 &&
713 +
714 + grep "pack-objects.*--window=3.*--cruft" event.trace
715 + )
716 +'
717 +
718 +test_expect_success 'cruft repack respects --quiet' '
719 + git init repo &&
720 + test_when_finished "rm -fr repo" &&
721 + (
722 + cd repo &&
723 +
724 + test_commit base &&
725 + GIT_PROGRESS_DELAY=0 git repack --cruft --quiet 2>err &&
726 + test_must_be_empty err
727 + )
728 +'
729 +
730 test_done