git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v5 0/3] repack: don't lose objects to a ".keep" that appears mid-run

From
QGqeesung via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 24, 2026, 06:12 UTC
Message-ID
<pull.2219.v5.git.1795500766.gitgitgadget@gmail.com>
In-Reply-To
<pull.2219.git.1789385483.gitgitgadget@gmail.com>

"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=<file>, 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
Previous: Qin ShiCheng via GitGitGadgetNext: Qin ShiCheng via GitGitGadget
Message 32 of 35 in “repack: don't lose objects to a ".keep" that appears mid-run”
  1. 0/6 repack: don't lose objects to a ".keep" that appears mid-runqeesung via GitGitGadget, Sep 14, 2026
  2. 1/6 odb: don't remove a ".keep" we never installedQin ShiCheng via GitGitGadget, Sep 14, 2026
  3. Justin ToblerSep 15, 2026
  4. Qin ShiChengSep 16, 2026
  5. 2/6 pack-objects: keep --keep-pack open when followingQin ShiCheng via GitGitGadget, Sep 14, 2026
  6. 3/6 pack-objects: reset kept-pack cache for cruft walkQin ShiCheng via GitGitGadget, Sep 14, 2026
  7. 4/6 pack-objects: sort --keep-pack list for lookupQin ShiCheng via GitGitGadget, Sep 14, 2026
  8. 5/6 pack-objects: add --keep-pack-from-fileQin ShiCheng via GitGitGadget, Sep 14, 2026
  9. 6/6 repack: tell pack-objects which packs are keptQin ShiCheng via GitGitGadget, Sep 14, 2026
  10. 0/5 repack: don't lose objects to a ".keep" that appears mid-runqeesung via GitGitGadget, Sep 18, 2026
  11. 1/5 pack-objects: keep --keep-pack open when followingQin ShiCheng via GitGitGadget, Sep 18, 2026
  12. 2/5 pack-objects: reset kept-pack cache for cruft walkQin ShiCheng via GitGitGadget, Sep 18, 2026
  13. Junio C HamanoSep 22, 2026
  14. Qin ShiChengSep 23, 2026
  15. Junio C HamanoSep 23, 2026
  16. 4/5 pack-objects: add --keep-pack-from-fileQin ShiCheng via GitGitGadget, Sep 18, 2026
  17. 3/5 pack-objects: sort --keep-pack list for lookupQin ShiCheng via GitGitGadget, Sep 18, 2026
  18. 5/5 repack: tell pack-objects which packs are keptQin ShiCheng via GitGitGadget, Sep 18, 2026
  19. 0/5 repack: don't lose objects to a ".keep" that appears mid-runqeesung via GitGitGadget, Oct 8, 2026
  20. 1/5 pack-objects: keep --keep-pack open when followingQin ShiCheng via GitGitGadget, Oct 8, 2026
  21. 2/5 pack-objects: reset kept-pack cache for cruft walkQin ShiCheng via GitGitGadget, Oct 8, 2026
  22. 3/5 pack-objects: sort --keep-pack list for lookupQin ShiCheng via GitGitGadget, Oct 8, 2026
  23. 4/5 pack-objects: add --keep-pack-from-fileQin ShiCheng via GitGitGadget, Oct 8, 2026
  24. 5/5 repack: tell pack-objects which packs are keptQin ShiCheng via GitGitGadget, Oct 8, 2026
  25. Junio C HamanoOct 8, 2026
  26. Qin ShiChengOct 9, 2026
  27. Junio C HamanoOct 9, 2026
  28. 0/3 repack: don't lose objects to a ".keep" that appears mid-runqeesung via GitGitGadget, Oct 26, 2026
  29. 1/3 pack-objects: reset kept-pack cache for cruft walkQin ShiCheng via GitGitGadget, Oct 26, 2026
  30. 2/3 pack-objects: add --ignore-pack-keep-fromQin ShiCheng via GitGitGadget, Oct 26, 2026
  31. 3/3 repack: tell pack-objects which packs it may deleteQin ShiCheng via GitGitGadget, Oct 26, 2026
  32. 0/3 repack: don't lose objects to a ".keep" that appears mid-runqeesung via GitGitGadget, Nov 24, 2026
  33. 1/3 pack-objects: reset kept-pack cache for cruft walkQin ShiCheng via GitGitGadget, Nov 24, 2026
  34. 2/3 pack-objects: add --ignore-pack-keep-fromQin ShiCheng via GitGitGadget, Nov 24, 2026
  35. 3/3 repack: tell pack-objects which packs it may deleteQin ShiCheng via GitGitGadget, Nov 24, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.