]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs: drop `current_ref_iter` hack
authorPatrick Steinhardt <ps@pks.im>
Thu, 23 Oct 2025 07:16:18 +0000 (09:16 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 4 Nov 2025 15:32:25 +0000 (07:32 -0800)
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>
refs.c
refs/iterator.c
refs/refs-internal.h

diff --git a/refs.c b/refs.c
index 1b1551f9814394e76fd9d6e45cea9d84d4a86c1b..9d8f0a9ca4a3a63114d4a76202952d9444c7176c 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -2324,16 +2324,6 @@ int refs_optimize(struct ref_store *refs, struct pack_refs_opts *opts)
        return refs->be->optimize(refs, opts);
 }
 
-int peel_iterated_oid(struct repository *r, const struct object_id *base, struct object_id *peeled)
-{
-       if (current_ref_iter &&
-           (current_ref_iter->ref.oid == base ||
-            oideq(current_ref_iter->ref.oid, base)))
-               return ref_iterator_peel(current_ref_iter, peeled);
-
-       return peel_object(r, base, peeled) ? -1 : 0;
-}
-
 int reference_get_peeled_oid(struct repository *repo,
                             const struct reference *ref,
                             struct object_id *peeled_oid)
index fe5980e1b6c96bfeed125b1d9602c480f5595470..072c6aacdb0341d3af0bb28c8a5fe5d208a23deb 100644 (file)
@@ -458,15 +458,11 @@ struct ref_iterator *prefix_ref_iterator_begin(struct ref_iterator *iter0,
        return ref_iterator;
 }
 
-struct ref_iterator *current_ref_iter = NULL;
-
 int do_for_each_ref_iterator(struct ref_iterator *iter,
                             each_ref_fn fn, void *cb_data)
 {
        int retval = 0, ok;
-       struct ref_iterator *old_ref_iter = current_ref_iter;
 
-       current_ref_iter = iter;
        while ((ok = ref_iterator_advance(iter)) == ITER_OK) {
                retval = fn(&iter->ref, cb_data);
                if (retval)
@@ -474,7 +470,6 @@ int do_for_each_ref_iterator(struct ref_iterator *iter,
        }
 
 out:
-       current_ref_iter = old_ref_iter;
        if (ok == ITER_ERROR)
                retval = -1;
        ref_iterator_free(iter);
index ed749d16572dac93f16efb93e6e6962cde877862..f4f845bbeaf673bb144f74b6d24fff41aeb802b2 100644 (file)
@@ -376,19 +376,6 @@ struct ref_iterator_vtable {
        ref_iterator_release_fn *release;
 };
 
-/*
- * current_ref_iter is a performance hack: when iterating over
- * references using the for_each_ref*() functions, current_ref_iter is
- * set to the reference iterator before calling the callback function.
- * If the callback function calls peel_ref(), then peel_ref() first
- * checks whether the reference to be peeled is the one referred to by
- * the iterator (it usually is) and if so, asks the iterator for the
- * peeled version of the reference if it is available. This avoids a
- * refname lookup in a common case. current_ref_iter is set to NULL
- * when the iteration is over.
- */
-extern struct ref_iterator *current_ref_iter;
-
 struct ref_store;
 
 /* refs backends */