@@ -360,43 +360,6 @@ test_expect_success 'expired objects are pruned' '
360360 )
361361'
362362
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-
400363test_expect_success ' loose objects mtimes upsert others' '
401364 git init repo &&
402365 test_when_finished "rm -fr repo" &&
@@ -470,219 +433,6 @@ test_expect_success 'expiring cruft objects with git gc' '
470433 )
471434'
472435
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-
686436test_expect_success ' cruft --local drops unreachable objects' '
687437 git init alternate &&
688438 git init repo &&
0 commit comments