From f1486203f5aa5f813ead5cd8e8583514a101bb22 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Fri, 25 Mar 2022 19:02:46 +0000 Subject: t7700: check post-condition in kept-pack test The '--write-midx -b packs non-kept objects' test in t7700-repack.sh uses test_subcommand_inexact to check that 'git repack' properly adds the '--honor-pack-keep' flag to the 'git pack-objects' subcommand. However, the test_subcommand_inexact helper is more flexible than initially designed, and this instance is the only one that makes use of it: there are additional arguments between 'git pack-objects' and the '--honor-pack-keep' flag. In order to make test_subcommand_inexact more strict, we need to fix this instance. This test checks that 'git repack --write-midx -a -b -d' will create a new pack-file that does not contain the objects within the kept pack. This behavior is possible because of the multi-pack-index bitmap that will bitmap objects against multiple packs. Without --write-midx, the objects in the kept pack would be duplicated so the resulting pack is closed under reachability and bitmaps can be created against it. This is discussed in more detail in e4d0c11c0 (repack: respect kept objects with '--write-midx -b', 2021-12-20) which also introduced this instance of test_subcommand_inexact. To better verify the intended post-conditions while also removing this instance of test_subcommand_inexact, rewrite the test to check the list of packed objects in the kept pack and the list of the objects in the newly-repacked pack-file _other_ than the kept pack. These lists should be disjoint. Be sure to include a non-kept pack-file and loose objects to be extra careful that this is properly behaving with kept packs and not just avoiding repacking all pack-files. Co-authored-by: Taylor Blau Signed-off-by: Taylor Blau Signed-off-by: Derrick Stolee Signed-off-by: Junio C Hamano --- t/t7700-repack.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 770d143204..ca45c4cd2c 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -369,10 +369,61 @@ test_expect_success '--write-midx with preferred bitmap tips' ' ) ' +# The first argument is expected to be a filename +# and that file should contain the name of a .idx +# file. Send the list of objects in that .idx file +# into stdout. +get_sorted_objects_from_pack () { + git show-index <$(cat "$1") >raw && + cut -d" " -f2 raw +} + test_expect_success '--write-midx -b packs non-kept objects' ' - GIT_TRACE2_EVENT="$(pwd)/trace.txt" \ - git repack --write-midx -a -b && - test_subcommand_inexact git pack-objects --honor-pack-keep before && + test_line_count = 1 before && + before_name=$(cat before) && + >${before_name%.idx}.keep && + + # Create a non-kept pack-file + test_commit other && + git repack && + + # Create loose objects + test_commit loose && + + # Repack everything + git repack --write-midx -a -b -d && + + # There should be two pack-files now, the + # old, kept pack and the new, non-kept pack. + find $objdir/pack -name "*.idx" | sort >after && + test_line_count = 2 after && + find $objdir/pack -name "*.keep" >kept && + kept_name=$(cat kept) && + echo ${kept_name%.keep}.idx >kept-idx && + test_cmp before kept-idx && + + # Get object list from the kept pack. + get_sorted_objects_from_pack before >old.objects && + + # Get object list from the one non-kept pack-file + comm -13 before after >new-pack && + test_line_count = 1 new-pack && + get_sorted_objects_from_pack new-pack >new.objects && + + # None of the objects in the new pack should + # exist within the kept pack. + comm -12 old.objects new.objects >shared.objects && + test_must_be_empty shared.objects + ) ' test_expect_success TTY '--quiet disables progress' ' -- cgit v1.2.3 From 16dcec218b68e2712aea361550435da1d92c38e9 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Fri, 25 Mar 2022 19:02:47 +0000 Subject: test-lib-functions: remove test_subcommand_inexact The implementation of test_subcommand_inexact() was originally introduced in e4d0c11c0 (repack: respect kept objects with '--write-midx -b', 2021-12-20) with the intention to allow finding a subcommand based on an initial set of arguments. The inexactness was intended as a way to allow flexible options beyond that initial set, as opposed to test_subcommand() which requires that the full list of options is provided in its entirety. The implementation began by copying test_subcommand() and replaced the repeated argument 'printf' statement to append ".*" instead of "," to each argument. This caused it to be more flexible than initially intended. The previous change deleted the only use of test_subcommand_inexact, so instead of editing the helper, delete it. Helped-by: Taylor Blau Signed-off-by: Derrick Stolee Signed-off-by: Junio C Hamano --- t/test-lib-functions.sh | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 0f439c99d6..2501fc5706 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -1788,40 +1788,6 @@ test_subcommand () { fi } -# Check that the given command was invoked as part of the -# trace2-format trace on stdin, but without an exact set of -# arguments. -# -# test_subcommand [!] ... < -# -# For example, to look for an invocation of "git pack-objects" -# with the "--honor-pack-keep" argument, use -# -# GIT_TRACE2_EVENT=event.log git repack ... && -# test_subcommand git pack-objects --honor-pack-keep