Skip to content

Commit e4d0c11

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e9d7761 commit e4d0c11

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

builtin/repack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
691691
write_bitmaps = 0;
692692
}
693693
if (pack_kept_objects < 0)
694-
pack_kept_objects = write_bitmaps > 0;
694+
pack_kept_objects = write_bitmaps > 0 && !write_midx;
695695

696696
if (write_bitmaps && !(pack_everything & ALL_INTO_ONE) && !write_midx)
697697
die(_(incremental_bitmap_conflict_error));

t/t7700-repack.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,4 +372,10 @@ test_expect_success '--write-midx with preferred bitmap tips' '
372372
)
373373
'
374374

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+
375381
test_done

t/test-lib-functions.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,40 @@ test_subcommand () {
17481748
fi
17491749
}
17501750

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+
17511785
# Check that the given command was invoked as part of the
17521786
# trace2-format trace on stdin.
17531787
#

0 commit comments

Comments
 (0)