[PATCH v4 0/4] Fix misuse of `refs_for_each_ref_in()`
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Feb 19, 2026, 07:57 UTC
- Message-ID
- <20260219-b4-pks-fix-for-each-ref-in-misuse-v4-0-57ac30172fae@pks.im>
- In-Reply-To
- <20260128-b4-pks-fix-for-each-ref-in-misuse-v1-0-deccae3ea725@pks.im>
Hi,
this small patch series fixes a bug I have discovered where configuring "pack.preferBitmapTips" to an exact branch will cause Git to `BUG()`.
The root cause of this bug is misuse of `refs_for_each_ref_in()`: this function accepts a prefix to yield refs for, and then strips the prefix for each ref. Consequently, if passed an exact refname, then stripping the prefix would make us end up with an empty refname, and that is not supposed to happen.
There was one other caller that got it wrong, too, and which is also fixed in this patch series.
Changes in v4: - Fix a typo in the documentation. - Link to v3: https://lore.kernel.org/r/20260206-b4-pks-fix-for-each-ref-in-misuse-v3-0-1e050c3d6a50@pks.im
Changes in v3:
- Switch the approach to perform ref hierarchy matches instead, which
is in line with the changes in 10e8a9352b (refs.c: stop matching
non-directory prefixes in exclude patterns, 2025-03-06).
- Link to v2: https://lore.kernel.org/r/20260130-b4-pks-fix-for-each-ref-in-misuse-v2-0-0449b198a681@pks.imChanges in v2:
- Explain my thought process against why I chose to also allow exact
ref matches in the second commit and clarify the documentation a
bit. As said, I'm very open to changing this if my spelled-out
thoughts are not convincing.
- Apply Peff's patch to further simplify code.
- Link to v1: https://lore.kernel.org/r/20260128-b4-pks-fix-for-each-ref-in-misuse-v1-0-deccae3ea725@pks.imThanks!
Patrick
---
Jeff King (1):
bisect: simplify string_list memory handlingPatrick Steinhardt (3):
pack-bitmap: deduplicate logic to iterate over preferred bitmap tips
pack-bitmap: fix bug with exact ref match in "pack.preferBitmapTips"
bisect: fix misuse of `refs_for_each_ref_in()`Documentation/config/pack.adoc | 9 +++++---- bisect.c | 16 +++++++--------- builtin/pack-objects.c | 19 ++----------------- pack-bitmap.c | 29 +++++++++++++++++++++++++++- pack-bitmap.h | 9 ++++++++- repack-midx.c | 14 +++----------- t/t5310-pack-bitmaps.sh | 41 ++++++++++++++++++++++++++++++++++++++++ t/t5319-multi-pack-index.sh | 43 ++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 137 insertions(+), 43 deletions(-)
Range-diff versus v3:
1: aa71011718 = 1: 0c2a2a122e pack-bitmap: deduplicate logic to iterate over preferred bitmap tips
2: d15aa04be6 ! 2: a923e92ddd pack-bitmap: fix bug with exact ref match in "pack.preferBitmapTips"
@@ Documentation/config/pack.adoc: pack.usePathWalk::
- commit at the tip of any reference that is a suffix of any value
- of this configuration over any other commits in the "selection
- window".
-+ commmit at the tip of a reference that is contained in any of
++ commit at the tip of a reference that is contained in any of
+ the configured hierarchies.
+
-Note that setting this configuration to `refs/foo` does not mean that
3: 2f1b73dd08 = 3: 7e1dbf1b4e bisect: fix misuse of `refs_for_each_ref_in()`
4: f579e31633 = 4: 094aa2345c bisect: simplify string_list memory handling--- base-commit: ea717645d199f6f1b66058886475db3e8c9330e9 change-id: 20260128-b4-pks-fix-for-each-ref-in-misuse-96ae62e313a5