git/builtin
Qin ShiCheng babe131bd7 pack-objects: reset kept-pack cache for cruft walk
When writing a cruft pack with an expiration, pack-objects first
collects the recent objects and then walks from them to rescue
whatever they reach, expired or not. A pack the caller did not list is
marked kept while collecting, so that its objects are not copied into
the cruft pack, and unmarked before the walk, so that the walk can go
through it.

The walk does not see the unmarking. Whether an object sits in a kept
pack is answered from a cache that is built on first use and only
dropped when asked about a different kind of kept pack. Collecting
builds it while the unlisted pack is still marked, the walk asks the
same kind of question, and so the unlisted pack stays in it: the walk
stops there, and whatever lies beyond it in an expired pack is left
out of the cruft pack, to go when that pack is deleted.

This went unnoticed because of "--honor-pack-keep". repack passes it,
and when there is a ".keep" file it makes the collecting side ask
about on-disk and in-core kept packs together while the walk asks
about in-core ones alone; the cache is rebuilt each time the question
changes, and by accident the walk sees the current marks. Take the
".keep" file away and the objects are lost today. A later commit stops
repack from passing "--honor-pack-keep" at all, so fix this first.

Drop the cache after re-marking. The loop over the object sources
that does so lives in packfile.c, as repo_invalidate_kept_pack_caches(),
next to has_object_kept_pack() which reads the cache. Like it, the
loop assumes every source is a files backend; keeping that assumption
in packfile.c rather than adding it to pack-objects means the two can
move together once packfile management is pushed down into that
backend.

The test builds an unreachable chain whose middle commit sits in a
pack pack-objects is not told about and whose oldest objects have
expired; without the fix the cruft pack holds only the recent tip.

Signed-off-by: Qin ShiCheng <qeesung@live.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-10-08 11:47:13 -07:00
..
add.c Merge branch 'gr/add-e-use-apply-api' 2026-09-07 09:32:06 -07:00
am.c hook: mark non-parallelizable hooks 2026-04-10 07:58:53 -07:00
annotate.c
…
apply.c
…
archive.c connect: use "service" enum for "name" argument 2026-05-19 15:05:46 +09:00
backfill.c path-walk: add pl_sparse_trees to control tree pruning 2026-05-24 18:41:06 +09:00
bisect.c Merge branch 'js/coverity-unchecked-returns-fix' 2026-08-24 13:17:50 -07:00
blame.c Merge branch 'bc/parse-options-exit-0-on-help' 2026-07-19 10:42:16 -07:00
branch.c Merge branch 'hn/branch-delete-merged' 2026-08-20 07:30:51 -07:00
bugreport.c
…
bundle.c bundle: generate packfiles via the object database 2026-08-21 09:01:55 -07:00
cat-file.c Merge branch 'ps/cat-file-remote-object-info-type' 2026-08-23 18:01:42 -07:00
check-attr.c environment: stop using `the_repository` in `is_bare_repository()` 2026-06-11 05:05:54 -07:00
check-ignore.c
…
check-mailmap.c
…
check-ref-format.c refs: remove remaining uses of `the_repository` 2026-07-16 07:40:22 -07:00
checkout--worker.c
…
checkout-index.c setup: stop using `the_repository` in `prefix_path()` 2026-05-19 19:36:24 +09:00
checkout.c Merge branch 'ps/odb-stop-registering-in-memory-sources' 2026-09-15 11:07:36 -07:00
clean.c
…
clone.c Merge branch 'ps/ref-storage-format' 2026-10-01 11:26:40 -07:00
column.c
…
commit-graph.c
…
commit-tree.c
…
commit.c Revert "Merge branch 'en/no-amend-during-conflicts'" 2026-09-23 11:18:51 -07:00
config.c Merge branch 'js/coverity-unchecked-returns-fix' 2026-08-24 13:17:50 -07:00
count-objects.c
…
credential-cache--daemon.c
…
credential-cache.c
…
credential-store.c
…
credential.c
…
describe.c Merge branch 'kk/prio-queue-get-put-fusion' 2026-07-13 08:27:27 -07:00
diagnose.c
…
diff-files.c
…
diff-index.c setup: stop using `the_repository` in `setup_work_tree()` 2026-05-19 19:36:24 +09:00
diff-pairs.c
…
diff-tree.c
…
diff.c diff: handle NULL return from repo_get_commit_tree() 2026-07-10 08:13:54 -07:00
difftool.c Merge branch 'rs/tempfile-wo-the-repository' 2026-07-30 10:32:02 -07:00
fast-export.c Merge branch 'ps/refspec-wo-the-repository' 2026-07-27 09:09:00 -07:00
fast-import.c Merge branch 'js/pack-objects-delta-size-t' 2026-08-24 13:17:51 -07:00
fetch-pack.c repository: move fetch_if_missing into struct repository 2026-08-15 08:37:54 -07:00
fetch.c Merge branch 'ps/ref-storage-format' 2026-10-01 11:26:40 -07:00
fmt-merge-msg.c
…
for-each-ref.c
…
for-each-repo.c
…
fsck.c Merge branch 'ps/odb-pluggable-fsck' 2026-09-15 11:07:37 -07:00
fsmonitor--daemon.c fsmonitor: plug token-data leak on early daemon-startup failures 2026-07-05 09:12:10 -07:00
gc.c builtin/maintenance: improve heuristic for "rerere gc" 2026-09-04 07:27:14 -07:00
get-tar-commit-id.c
…
grep.c builtin/grep: stop registering submodule ODB as source 2026-09-11 08:46:10 -07:00
hash-object.c setup: stop using `the_repository` in `setup_git_directory()` 2026-05-19 19:36:25 +09:00
help.c setup: stop using `the_repository` in `setup_git_directory_gently()` 2026-05-19 19:36:24 +09:00
history.c Merge branch 'hn/history-squash' 2026-10-01 11:26:39 -07:00
hook.c hook: allow hook.jobs=-1 to use all available CPU cores 2026-04-10 07:58:55 -07:00
index-pack.c Merge branch 'ty/repository-fetch-if-missing' 2026-09-02 09:21:59 -07:00
init-db.c Merge branch 'ps/ref-storage-format' 2026-10-01 11:26:40 -07:00
interpret-trailers.c Merge branch 'kh/doc-interpret-trailers-1' 2026-03-27 11:00:02 -07:00
last-modified.c last-modified: handle repo_parse_commit() failures 2026-08-12 09:05:50 -07:00
log.c Merge branch 'jk/format-patch-leakfix' 2026-07-13 08:27:27 -07:00
ls-files.c Merge branch 'js/objects-larger-than-4gb-on-windows-more' 2026-06-21 16:41:38 -07:00
ls-remote.c
…
ls-tree.c odb: use size_t for object_info.sizep and the size APIs 2026-06-15 07:45:41 -07:00
mailinfo.c
…
mailsplit.c mailsplit: move NULL check before first use of file handle 2026-07-10 08:13:54 -07:00
merge-base.c commit-reach: early exit paint_down_to_common for single merge-base 2026-05-12 09:33:43 +09:00
merge-file.c setup: stop using `the_repository` in `setup_git_directory()` 2026-05-19 19:36:25 +09:00
merge-index.c
…
merge-ours.c
…
merge-recursive.c
…
merge-tree.c odb: use size_t for object_info.sizep and the size APIs 2026-06-15 07:45:41 -07:00
merge.c Merge branch 'tc/merge-default-to-upstream-leakfix' 2026-08-07 14:48:01 -07:00
mktag.c odb: use size_t for object_info.sizep and the size APIs 2026-06-15 07:45:41 -07:00
mktree.c mktree: do not use OBJECT_INFO_QUICK when checking objects 2026-08-30 13:37:42 -07:00
multi-pack-index.c builtin/multi-pack-index: refuse unknown sources with "--object-dir=" 2026-09-11 08:46:10 -07:00
mv.c Merge branch 'lo/mv-missing-dest-dir-check' 2026-08-11 10:07:00 -07:00
name-rev.c Merge branch 'kh/name-rev-custom-format' 2026-05-19 09:57:44 +09:00
notes.c worktree: pass repository to public functions 2026-07-16 07:40:22 -07:00
pack-objects.c pack-objects: reset kept-pack cache for cruft walk 2026-10-08 11:47:13 -07:00
pack-redundant.c
…
pack-refs.c
…
patch-id.c hash: use git_hash_init() consistently 2026-07-07 21:56:00 -07:00
prune-packed.c
…
prune.c repository: move fetch_if_missing into struct repository 2026-08-15 08:37:54 -07:00
pull.c Merge branch 'jk/pull-null-merge-head' 2026-10-03 21:45:55 -07:00
push.c Merge branch 'ty/migrate-excludes-file' 2026-07-30 10:32:03 -07:00
range-diff.c
…
read-tree.c setup: stop using `the_repository` in `setup_work_tree()` 2026-05-19 19:36:24 +09:00
rebase.c rebase, cherry-pick, revert: run auto maintenance when done 2026-09-17 12:37:00 -07:00
receive-pack.c receive-pack: coccinelle fix 2026-09-14 15:36:48 -07:00
reflog.c worktree: pass repository to public functions 2026-07-16 07:40:22 -07:00
refs.c builtin/refs: rename "--ref-format=" to "--ref-storage-format=" 2026-09-09 11:04:30 -07:00
remote-ext.c
…
remote-fd.c
…
remote.c odb: rename `odb_has_object()` flags 2026-03-31 20:43:14 -07:00
repack.c builtin/repack: add guards for --drop-filtered 2026-08-13 13:34:50 -07:00
replace.c hex: add and use strbuf_add_oid_hex() 2026-05-14 15:59:25 +09:00
replay.c replay: offer an option to linearize the commit topology 2026-08-31 10:29:06 -07:00
repo.c setup: move prefix into repository 2026-07-07 10:49:40 -07:00
rerere.c
…
reset.c environment: stop using `the_repository` in `is_bare_repository()` 2026-06-11 05:05:54 -07:00
rev-list.c Merge branch 'sa/rev-list-missing-only' 2026-09-14 14:02:53 -07:00
rev-parse.c builtin/rev-parse: rename "--show-ref-format" to "--show-ref-storage-format" 2026-09-09 11:04:31 -07:00
revert.c rebase, cherry-pick, revert: run auto maintenance when done 2026-09-17 12:37:00 -07:00
rm.c setup: stop using `the_repository` in `setup_work_tree()` 2026-05-19 19:36:24 +09:00
send-pack.c refspec: stop depending on `the_repository` 2026-07-16 13:58:25 -07:00
shortlog.c parse-options: exit 0 on -h 2026-07-07 17:48:57 -07:00
show-branch.c prio-queue: fold lazy_queue into prio_queue for automatic get+put fusion 2026-06-09 11:11:46 -07:00
show-index.c
…
show-ref.c odb: rename `odb_has_object()` flags 2026-03-31 20:43:14 -07:00
sparse-checkout.c use repo_hold_lock_file_for_update{,_mode,_timeout}() with custom repos 2026-07-14 12:54:25 -07:00
stash.c Merge branch 'hn/checkout-m-autostash-refine' 2026-09-14 14:02:53 -07:00
stripspace.c setup: stop using `the_repository` in `setup_git_directory_gently()` 2026-05-19 19:36:24 +09:00
submodule--helper.c Merge branch 'ps/ref-storage-format' 2026-10-01 11:26:40 -07:00
symbolic-ref.c
…
tag.c odb: use size_t for object_info.sizep and the size APIs 2026-06-15 07:45:41 -07:00
unpack-file.c odb: use size_t for object_info.sizep and the size APIs 2026-06-15 07:45:41 -07:00
unpack-objects.c Merge branch 'jt/receive-pack-pluggable-writes' 2026-08-31 08:25:00 -07:00
update-index.c Merge branch 'dk/use-nsec-runtime' 2026-10-01 11:26:41 -07:00
update-ref.c update-ref: handle rejections while adding updates 2026-05-05 16:34:08 +09:00
update-server-info.c
…
upload-archive.c setup: stop using `the_repository` in `enter_repo()` 2026-05-19 19:36:24 +09:00
upload-pack.c setup: stop using `the_repository` in `enter_repo()` 2026-05-19 19:36:24 +09:00
url-parse.c builtin: create url-parse command 2026-05-06 09:48:28 +09:00
var.c
…
verify-commit.c
…
verify-pack.c
…
verify-tag.c
…
worktree.c Merge branch 'rs/worktree-add-basename-fixes' 2026-09-10 05:36:16 -07:00
write-tree.c
…