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

[PATCH 0/9] refs: add a '--required' flag to 'git refs optimize'

From
Karthik Nayak <karthik.188@gmail.com>
Date
Oct 10, 2025, 10:27 UTC
Message-ID
<20251010-562-add-option-to-check-if-reference-backend-needs-repacking-v1-0-c7962be584fa@gmail.com>

At GitLab, we use a transaction manager in Gitaly (our service layer on top of Git) to manage incoming requests. This provides snapshotting capabilities and provides ACID properties. To optimize for performance, read snapshots are shared. This means they are cheaper to initiate than write snapshots. However, housekeeping requires a write snapshot.

Currently, we run housekeeping in write snapshots which includes optimizing references. If Git exposed information regarding if optimization was required, then we could spawn a read snapshot to check if optimization was required and only spawn a write snapshot if needed.

This patch series adds a '--required' flag to 'git refs optimize' which will indicate if optimization is required for the reference backend or not.

The series is structured as follows:

Patches 1-4 are mostly cleanup patches, cleaning up existing code post the addition of 'git refs optimize'. Some of them could be potentially dropped.

Patch 5 fixes the test which checks for inconsisten leading whitespaces in our documentation for builtin commands to also consider subcommands.

Patches 6-8 are preliminary patches which add the required changes to provide a functionality which only checks if optimization is required without running it.

Patch 9 adds the '--required' flag.

The series is based on top of 60f3f52f17 (The sixteenth batch, 2025-10-08) with 'ps/ref-peeled-tags' merged in.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
 Documentation/git-pack-refs.adoc     |  1 +
 Documentation/git-refs.adoc          |  1 +
 Documentation/pack-refs-options.adoc |  5 +++++
 builtin/pack-refs.c                  |  2 +-
 builtin/refs.c                       |  2 +-
 pack-refs.c                          | 19 ++++++++++++-----
 pack-refs.h                          | 10 +++++++--
 refs.c                               | 11 +++++-----
 refs.h                               | 31 +++++++++++++++------------
 refs/debug.c                         | 21 ++++++++++++++----
 refs/files-backend.c                 | 27 ++++++++++++------------
 refs/packed-backend.c                | 19 ++++++++++++++---
 refs/refs-internal.h                 | 11 ++++++----
 refs/reftable-backend.c              | 34 +++++++++++++++++++++++-------
 reftable/reftable-stack.h            |  3 +++
 reftable/stack.c                     | 41 ++++++++++++++++++++++++++----------
 t/pack-refs-tests.sh                 | 21 +++++++++++++++++-
 t/t0450-txt-doc-vs-help.sh           | 28 +++++++++++++-----------
 t/t0601-reffiles-pack-refs.sh        |  2 ++
 t/t1463-refs-optimize.sh             |  2 ++
 t/unit-tests/u-reftable-stack.c      | 12 +++++++++--
 21 files changed, 217 insertions(+), 86 deletions(-)
Karthik Nayak (9):
      refs: move to using the '.optimize' functions
      refs: cleanup code around optimization
      refs: rename 'pack_refs_opts' to 'optimize_refs_opts'
      t/pack-refs-tests: move the 'test_done' to callees
      t/t0450: split whitespace consistency check per subcommand
      reftable/stack: return stack segments directly
      reftable/stack: add function to check if optimization is required
      refs: add a `optimize_required` field to `struct ref_storage_be`
      refs: add a '--required' flag to 'git refs optimize'

base-commit: 9081ca56692a28ce89a49537e6c568b3ccdef405 change-id: 20250926-562-add-option-to-check-if-reference-backend-needs-repacking-aa600eb3e055

Thanks
- Karthik
Next: Karthik Nayak
Message 1 of 36 in “refs: add a '--required' flag to 'git refs optimize'”
  1. 0/9 refs: add a '--required' flag to 'git refs optimize'Karthik Nayak, Oct 10, 2025
  2. 1/9 refs: move to using the '.optimize' functionsKarthik Nayak, Oct 10, 2025
  3. Patrick SteinhardtOct 10, 2025
  4. Karthik NayakOct 13, 2025
  5. 2/9 refs: cleanup code around optimizationKarthik Nayak, Oct 10, 2025
  6. Patrick SteinhardtOct 10, 2025
  7. Karthik NayakOct 13, 2025
  8. 3/9 refs: rename 'pack_refs_opts' to 'optimize_refs_opts'Karthik Nayak, Oct 10, 2025
  9. Patrick SteinhardtOct 10, 2025
  10. Karthik NayakOct 13, 2025
  11. 4/9 t/pack-refs-tests: move the 'test_done' to calleesKarthik Nayak, Oct 10, 2025
  12. Patrick SteinhardtOct 10, 2025
  13. Karthik NayakOct 13, 2025
  14. 5/9 t/t0450: split whitespace consistency check per subcommandKarthik Nayak, Oct 10, 2025
  15. 6/9 reftable/stack: return stack segments directlyKarthik Nayak, Oct 10, 2025
  16. Patrick SteinhardtOct 10, 2025
  17. Karthik NayakOct 13, 2025
  18. Patrick SteinhardtOct 13, 2025
  19. 7/9 reftable/stack: add function to check if optimization is requiredKarthik Nayak, Oct 10, 2025
  20. Patrick SteinhardtOct 10, 2025
  21. Karthik NayakOct 13, 2025
  22. 8/9 refs: add a `optimize_required` field to `struct ref_storage_be`Karthik Nayak, Oct 10, 2025
  23. Patrick SteinhardtOct 10, 2025
  24. Karthik NayakOct 13, 2025
  25. 9/9 refs: add a '--required' flag to 'git refs optimize'Karthik Nayak, Oct 10, 2025
  26. Patrick SteinhardtOct 10, 2025
  27. Karthik NayakOct 13, 2025
  28. Junio C HamanoOct 13, 2025
  29. Junio C HamanoOct 13, 2025
  30. Karthik NayakOct 14, 2025
  31. Junio C HamanoOct 14, 2025
  32. Srivastava, NitinOct 15, 2025
  33. Karthik NayakOct 15, 2025
  34. Karthik NayakOct 15, 2025
  35. Patrick SteinhardtOct 15, 2025
  36. Junio C HamanoOct 15, 2025

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.