diff options
author | Patrick Steinhardt <ps@pks.im> | 2024-03-25 11:03:20 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-03-25 17:54:07 +0100 |
commit | 6dcffc68f4cea97d4b4af8a9add0daae54a5c292 (patch) | |
tree | a9687964dd5ca66787a4d0a05054ea221d2dde12 /t/t0610-reftable-basics.sh | |
parent | builtin/pack-refs: release allocated memory (diff) | |
download | git-6dcffc68f4cea97d4b4af8a9add0daae54a5c292.tar.xz git-6dcffc68f4cea97d4b4af8a9add0daae54a5c292.zip |
builtin/pack-refs: introduce new "--auto" flag
Calling git-pack-refs(1) will unconditionally cause it to pack all
requested refs regardless of the current state of the ref database. For
example:
- With the "files" backend we will end up rewriting the complete
"packed-refs" file even if only a single ref would require
compaction.
- With the "reftable" backend we will end up always compacting all
tables into a single table.
This behaviour can be completely unnecessary depending on the backend
and is thus wasteful.
With the introduction of the `PACK_REFS_AUTO` flag in the preceding
commit we can improve this and let the backends decide for themselves
whether to pack refs in the first place. Expose this functionality via a
new "--auto" flag in git-pack-refs(1), which mirrors the same flag in
both git-gc(1) and git-maintenance(1).
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t0610-reftable-basics.sh')
-rwxr-xr-x | t/t0610-reftable-basics.sh | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/t/t0610-reftable-basics.sh b/t/t0610-reftable-basics.sh index a53d1dc493..6de7529575 100755 --- a/t/t0610-reftable-basics.sh +++ b/t/t0610-reftable-basics.sh @@ -387,6 +387,40 @@ test_expect_success 'pack-refs: compaction raises locking errors' ' test_cmp expect err ' +test_expect_success 'pack-refs: auto compaction' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + + test_commit A && + + # The tables should have been auto-compacted, and thus auto + # compaction should not have to do anything. + ls -1 .git/reftable >tables-expect && + test_line_count = 4 tables-expect && + git pack-refs --auto && + ls -1 .git/reftable >tables-actual && + test_cmp tables-expect tables-actual && + + # Lock all tables write some refs. Auto-compaction will be + # unable to compact tables and thus fails gracefully, leaving + # the stack in a sub-optimal state. + ls .git/reftable/*.ref | + while read table + do + touch "$table.lock" || exit 1 + done && + git branch B && + git branch C && + rm .git/reftable/*.lock && + test_line_count = 5 .git/reftable/tables.list && + + git pack-refs --auto && + test_line_count = 1 .git/reftable/tables.list + ) +' + test_expect_success 'pack-refs: prunes stale tables' ' test_when_finished "rm -rf repo" && git init repo && |