repack: respect kept objects with '--write-midx -b'

Historically, we needed a single packfile in order to have reachability bitmaps. This introduced logic that when 'git repack' had a '-b' option that we should stop sending the '--honor-pack-keep' option to the 'git pack-objects' child process, ensuring that we create a packfile containing all reachable objects. In the world of multi-pack-index bitmaps, we no longer need to repack all objects into a single pack to have valid bitmaps. Thus, we should continue sending the '--honor-pack-keep' flag to 'git pack-objects'. The fix is very simple: only disable the flag when writing bitmaps but also _not_ writing the multi-pack-index. This opens the door to new repacking strategies that might want to keep some historical set of objects in a stable pack-file while only repacking more recent objects. To test, create a new 'test_subcommand_inexact' helper that is more flexible than 'test_subcommand'. This allows us to look for the --honor-pack-keep flag without over-indexing on the exact set of arguments. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Dec 20, 2021 at 14:48 UTC e4d0c11c04ec3c28922168844ae2694e0d015b4e
3 files changed +41 -1
builtin/repack.c
+1 -1
@@ -691,7 +691,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
691 write_bitmaps = 0;
692 }
693 if (pack_kept_objects < 0)
694 - pack_kept_objects = write_bitmaps > 0;
694 + pack_kept_objects = write_bitmaps > 0 && !write_midx;
695
696 if (write_bitmaps && !(pack_everything & ALL_INTO_ONE) && !write_midx)
697 die(_(incremental_bitmap_conflict_error));
t/t7700-repack.sh
+6
@@ -372,4 +372,10 @@ test_expect_success '--write-midx with preferred bitmap tips' '
372 )
373 '
374
375 +test_expect_success '--write-midx -b packs non-kept objects' '
376 + GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
377 + git repack --write-midx -a -b &&
378 + test_subcommand_inexact git pack-objects --honor-pack-keep <trace.txt
379 +'
380 +
381 test_done
t/test-lib-functions.sh
+34
@@ -1748,6 +1748,40 @@ test_subcommand () {
1748 fi
1749 }
1750
1751 +# Check that the given command was invoked as part of the
1752 +# trace2-format trace on stdin, but without an exact set of
1753 +# arguments.
1754 +#
1755 +# test_subcommand [!] <command> <args>... < <trace>
1756 +#
1757 +# For example, to look for an invocation of "git pack-objects"
1758 +# with the "--honor-pack-keep" argument, use
1759 +#
1760 +# GIT_TRACE2_EVENT=event.log git repack ... &&
1761 +# test_subcommand git pack-objects --honor-pack-keep <event.log
1762 +#
1763 +# If the first parameter passed is !, this instead checks that
1764 +# the given command was not called.
1765 +#
1766 +test_subcommand_inexact () {
1767 + local negate=
1768 + if test "$1" = "!"
1769 + then
1770 + negate=t
1771 + shift
1772 + fi
1773 +
1774 + local expr=$(printf '"%s".*' "$@")
1775 + expr="${expr%,}"
1776 +
1777 + if test -n "$negate"
1778 + then
1779 + ! grep "\"event\":\"child_start\".*\[$expr\]"
1780 + else
1781 + grep "\"event\":\"child_start\".*\[$expr\]"
1782 + fi
1783 +}
1784 +
1785 # Check that the given command was invoked as part of the
1786 # trace2-format trace on stdin.
1787 #