refs: drop `current_ref_iter` hack

In preceding commits we have refactored all callers of `peel_iterated_oid()` to instead use `reference_get_peeled_oid()`. This allows us to thus get rid of the former function. Getting rid of that function is nice, but even nicer is that this also allows us to get rid of the `current_ref_iter` hack. This global variable tracked the currently-active ref iterator so that we can use it to peel an object ID. Now that the peeled object ID is propagated via `struct reference` though we don't have to depend on this hack anymore, which makes for a more robust and easier-to-understand infrastructure. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Oct 23, 2025 at 09:16 UTC 5a5c7359f77ecd1bc4b0e172563161d602f131d3
3 files changed -28
refs.c
-10
@@ -2324,16 +2324,6 @@ int refs_optimize(struct ref_store *refs, struct pack_refs_opts *opts)
2324 return refs->be->optimize(refs, opts);
2325 }
2326
2327 -int peel_iterated_oid(struct repository *r, const struct object_id *base, struct object_id *peeled)
2328 -{
2329 - if (current_ref_iter &&
2330 - (current_ref_iter->ref.oid == base ||
2331 - oideq(current_ref_iter->ref.oid, base)))
2332 - return ref_iterator_peel(current_ref_iter, peeled);
2333 -
2334 - return peel_object(r, base, peeled) ? -1 : 0;
2335 -}
2336 -
2327 int reference_get_peeled_oid(struct repository *repo,
2328 const struct reference *ref,
2329 struct object_id *peeled_oid)
refs/iterator.c
-5
@@ -458,15 +458,11 @@ struct ref_iterator *prefix_ref_iterator_begin(struct ref_iterator *iter0,
458 return ref_iterator;
459 }
460
461 -struct ref_iterator *current_ref_iter = NULL;
462 -
461 int do_for_each_ref_iterator(struct ref_iterator *iter,
462 each_ref_fn fn, void *cb_data)
463 {
464 int retval = 0, ok;
467 - struct ref_iterator *old_ref_iter = current_ref_iter;
465
469 - current_ref_iter = iter;
466 while ((ok = ref_iterator_advance(iter)) == ITER_OK) {
467 retval = fn(&iter->ref, cb_data);
468 if (retval)
@@ -474,7 +470,6 @@ int do_for_each_ref_iterator(struct ref_iterator *iter,
470 }
471
472 out:
477 - current_ref_iter = old_ref_iter;
473 if (ok == ITER_ERROR)
474 retval = -1;
475 ref_iterator_free(iter);
refs/refs-internal.h
-13
@@ -376,19 +376,6 @@ struct ref_iterator_vtable {
376 ref_iterator_release_fn *release;
377 };
378
379 -/*
380 - * current_ref_iter is a performance hack: when iterating over
381 - * references using the for_each_ref*() functions, current_ref_iter is
382 - * set to the reference iterator before calling the callback function.
383 - * If the callback function calls peel_ref(), then peel_ref() first
384 - * checks whether the reference to be peeled is the one referred to by
385 - * the iterator (it usually is) and if so, asks the iterator for the
386 - * peeled version of the reference if it is available. This avoids a
387 - * refname lookup in a common case. current_ref_iter is set to NULL
388 - * when the iteration is over.
389 - */
390 -extern struct ref_iterator *current_ref_iter;
391 -
379 struct ref_store;
380
381 /* refs backends */