From: qeesung via GitGitGadget Date: Tue, 24 Nov 2026 06:12:43 GMT Subject: [PATCH v5 0/3] repack: don't lose objects to a ".keep" that appears mid-run Message-ID: In-Reply-To: "git repack -d" could lose objects when a ".keep" file appeared on a pack it had already decided to delete. repack now tells pack-objects which packs it may delete, and pack-objects ignores ".keep" files on those packs. We hit this in production (a ref pointing at a missing commit, on git 2.43), and it reproduces on master: * repack scans for ".keep" files and decides which packs to delete; pack-objects scans again when it opens the packs; * in between, a fetch or a push brings in a pack identical to one of those, and a ".keep" ends up next to it; * pack-objects then leaves that pack's objects out, or does not loosen or keep them for -A, -k and --cruft, and repack deletes the pack anyway. v3 passed pack-objects the kept packs repack saw at startup instead of --honor-pack-keep. That missed -A, -k and --cruft, which skip packs with a ".keep" file regardless of that option. v4 goes the other way: * 1/3 fixes a stale kept-pack cache in the cruft walk. It reproduces on master, but under --honor-pack-keep any ".keep" file happens to hide it, including the one the race leaves; 3/3 takes that one away, so this comes first. * 2/3 adds pack-objects --ignore-pack-keep-from=, which treats the packs named in the file as having no ".keep". * 3/3 makes "repack -d" pass the packs it may delete that way. Each fix has a test that fails without it; the race is reproduced in t7700 and t7703. The full suite passes. Known limitations: * Unreachable objects of a deleted pack are still dropped by "-a -d" and by the expiration options, as before. A pack written again under the same name keeps its old mtime, so objects a push brings back that way can still expire. Freshening the pack on such a collision would help, but that is for a separate series. * The cruft walk now goes through the packs of an alternate, as it must (see 1/3). On a "clone --shared" fork of git.git this took the walk in "repack -d -l --cruft" from about 2ms to about 3.3s, which is what master already does when a ".keep" file is around. This is based on current master and merges cleanly with next. jt/odb-keep-lockfile-fix, Justin's fix for the receive-pack side that v1 had a patch for, leaves the race as it is. Changes since v4: * Rebased onto current master to resolve a conflict in t7700 with ds/path-walk-tagged-tree-revisit, which added a test at the same place. No other changes. Changes since v3: * Redesigned as above. v3's 1/5, 3/5 and 4/5 are dropped, since nothing passes --keep-pack any more; 2/3 and 3/3 are new. * 1/3 (v3's 2/5) also lets the walk go through --keep-pack packs while still leaving their objects out, and its message explains why the walk goes through alternates. There are tests for both. Qin ShiCheng (3): pack-objects: reset kept-pack cache for cruft walk pack-objects: add --ignore-pack-keep-from repack: tell pack-objects which packs it may delete Documentation/git-pack-objects.adoc | 12 ++++ builtin/pack-objects.c | 55 +++++++++++++++- builtin/repack.c | 23 +++++++ odb/source-packed.h | 3 +- packfile.c | 18 +++++- packfile.h | 7 +++ repack.c | 26 ++++++++ repack.h | 14 ++++- t/t5329-pack-objects-cruft.sh | 98 +++++++++++++++++++++++++++++ t/t7700-repack.sh | 86 +++++++++++++++++++++++++ t/t7703-repack-geometric.sh | 39 ++++++++++++ 11 files changed, 375 insertions(+), 6 deletions(-) base-commit: 77904e546de3bd940621092ecec47a88d0cede5d Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2219%2Fqeesung%2Frepack-kept-packs-snapshot-v5 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2219/qeesung/repack-kept-packs-snapshot-v5 Pull-Request: https://github.com/gitgitgadget/git/pull/2219 Range-diff vs v4: 1: 8cce2b6eb5 = 1: 228b7a690f pack-objects: reset kept-pack cache for cruft walk 2: 91ffbdf4fa = 2: 6641abfa49 pack-objects: add --ignore-pack-keep-from 3: 001875455b ! 3: 95c7bcab92 repack: tell pack-objects which packs it may delete @@ Commit message ## builtin/repack.c ## @@ builtin/repack.c: int cmd_repack(int argc, - existing.repo = repo; + string_list_sort(&keep_pack_list); existing_packs_collect(&existing, &keep_pack_list); + /* @@ repack.h: void pack_geometry_remove_redundant(struct pack_geometry *geometry, REPACK_WRITE_MIDX_DEFAULT, ## t/t7700-repack.sh ## -@@ t/t7700-repack.sh: test_expect_success 'pending objects are repacked appropriately' ' +@@ t/t7700-repack.sh: test_expect_success '--path-walk keeps blobs from tagged trees at already visite ) ' -- gitgitgadget