]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs: replace `refs_for_each_fullref_in()`
authorPatrick Steinhardt <ps@pks.im>
Mon, 23 Feb 2026 11:59:51 +0000 (12:59 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 23 Feb 2026 21:21:19 +0000 (13:21 -0800)
Replace calls to `refs_for_each_fullref_in()` with the newly introduced
`refs_for_each_ref_ext()` function.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
bisect.c
builtin/receive-pack.c
builtin/rev-parse.c
builtin/show-ref.c
refs.c
refs.h
revision.c
t/helper/test-ref-store.c

index 296836c15450c9bc598137c9b4a34b6ff62ef357..ef17a442e55d2c738249247e58ea4fb15a6c0b92 100644 (file)
--- a/bisect.c
+++ b/bisect.c
@@ -1190,13 +1190,15 @@ static int mark_for_removal(const struct reference *ref, void *cb_data)
 
 int bisect_clean_state(void)
 {
+       struct refs_for_each_ref_options opts = {
+               .prefix = "refs/bisect/",
+       };
        int result = 0;
 
        /* There may be some refs packed during bisection */
        struct string_list refs_for_removal = STRING_LIST_INIT_DUP;
-       refs_for_each_fullref_in(get_main_ref_store(the_repository),
-                                "refs/bisect/", NULL, mark_for_removal,
-                                &refs_for_removal);
+       refs_for_each_ref_ext(get_main_ref_store(the_repository),
+                             mark_for_removal, &refs_for_removal, &opts);
        string_list_append(&refs_for_removal, "BISECT_HEAD");
        string_list_append(&refs_for_removal, "BISECT_EXPECTED_REV");
        result = refs_delete_refs(get_main_ref_store(the_repository),
index 4c0112b4bc2189f97d18c16a700be05b9b3a7cab..8c5ad5b81e9bd6e49aa1612295a47c30501e30e0 100644 (file)
@@ -343,9 +343,9 @@ static void show_one_alternate_ref(const struct object_id *oid,
 
 static void write_head_info(void)
 {
+       struct refs_for_each_ref_options opts = { 0 };
        static struct oidset seen = OIDSET_INIT;
        struct strvec excludes_vector = STRVEC_INIT;
-       const char **exclude_patterns;
 
        /*
         * We need access to the reference names both with and without their
@@ -353,12 +353,12 @@ static void write_head_info(void)
         * thus have to adapt exclude patterns to carry the namespace prefix
         * ourselves.
         */
-       exclude_patterns = get_namespaced_exclude_patterns(
+       opts.exclude_patterns = get_namespaced_exclude_patterns(
                hidden_refs_to_excludes(&hidden_refs),
                get_git_namespace(), &excludes_vector);
 
-       refs_for_each_fullref_in(get_main_ref_store(the_repository), "",
-                                exclude_patterns, show_ref_cb, &seen);
+       refs_for_each_ref_ext(get_main_ref_store(the_repository),
+                             show_ref_cb, &seen, &opts);
        odb_for_each_alternate_ref(the_repository->objects,
                                   show_one_alternate_ref, &seen);
 
index 61a3f0fdb99b360ad500746832adaf15d349722d..01a62800e879380defdab9d0e16684adc5b387a1 100644 (file)
@@ -940,14 +940,13 @@ int cmd_rev_parse(int argc,
                                continue;
                        }
                        if (!strcmp(arg, "--bisect")) {
-                               refs_for_each_fullref_in(get_main_ref_store(the_repository),
-                                                        "refs/bisect/bad",
-                                                        NULL, show_reference,
-                                                        NULL);
-                               refs_for_each_fullref_in(get_main_ref_store(the_repository),
-                                                        "refs/bisect/good",
-                                                        NULL, anti_reference,
-                                                        NULL);
+                               struct refs_for_each_ref_options opts = { 0 };
+                               opts.prefix = "refs/bisect/bad";
+                               refs_for_each_ref_ext(get_main_ref_store(the_repository),
+                                                     show_reference, NULL, &opts);
+                               opts.prefix = "refs/bisect/good";
+                               refs_for_each_ref_ext(get_main_ref_store(the_repository),
+                                                     anti_reference, NULL, &opts);
                                continue;
                        }
                        if (opt_with_value(arg, "--branches", &arg)) {
index 4d4984e4e0c244b32d46affc658a699bb04f1c82..5d31acea7c779a6e07b6323c542dd9ddafa198e3 100644 (file)
@@ -215,14 +215,19 @@ static int cmd_show_ref__patterns(const struct patterns_options *opts,
                refs_head_ref(get_main_ref_store(the_repository), show_ref,
                              &show_ref_data);
        if (opts->branches_only || opts->tags_only) {
-               if (opts->branches_only)
-                       refs_for_each_fullref_in(get_main_ref_store(the_repository),
-                                                "refs/heads/", NULL,
-                                                show_ref, &show_ref_data);
-               if (opts->tags_only)
-                       refs_for_each_fullref_in(get_main_ref_store(the_repository),
-                                                "refs/tags/", NULL, show_ref,
-                                                &show_ref_data);
+               struct refs_for_each_ref_options for_each_ref_opts = { 0 };
+
+               if (opts->branches_only) {
+                       for_each_ref_opts.prefix = "refs/heads/";
+                       refs_for_each_ref_ext(get_main_ref_store(the_repository),
+                                             show_ref, &show_ref_data, &for_each_ref_opts);
+               }
+
+               if (opts->tags_only) {
+                       for_each_ref_opts.prefix = "refs/tags/";
+                       refs_for_each_ref_ext(get_main_ref_store(the_repository),
+                                             show_ref, &show_ref_data, &for_each_ref_opts);
+               }
        } else {
                refs_for_each_ref(get_main_ref_store(the_repository),
                                  show_ref, &show_ref_data);
diff --git a/refs.c b/refs.c
index 35a4925ac4e50d1d8695bababbe62abfc25d31c7..af51a648d59d4986f7037241e3bdc9a1029401c5 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -1929,17 +1929,6 @@ int refs_for_each_ref(struct ref_store *refs, refs_for_each_cb cb, void *cb_data
        return refs_for_each_ref_ext(refs, cb, cb_data, &opts);
 }
 
-int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,
-                            const char **exclude_patterns,
-                            refs_for_each_cb cb, void *cb_data)
-{
-       struct refs_for_each_ref_options opts = {
-               .prefix = prefix,
-               .exclude_patterns = exclude_patterns,
-       };
-       return refs_for_each_ref_ext(refs, cb, cb_data, &opts);
-}
-
 int refs_for_each_replace_ref(struct ref_store *refs, refs_for_each_cb cb, void *cb_data)
 {
        const char *git_replace_ref_base = ref_namespace[NAMESPACE_REPLACE].ref;
diff --git a/refs.h b/refs.h
index 1b468c4ffb7166f99d0d8b100c7bd492878a09cc..9b5d57a9b7994fba38e962d3a67673ba7b664f6c 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -510,14 +510,6 @@ int refs_for_each_remote_ref(struct ref_store *refs,
 int refs_for_each_replace_ref(struct ref_store *refs,
                              refs_for_each_cb fn, void *cb_data);
 
-/*
- * references matching any pattern in "exclude_patterns" are omitted from the
- * result set on a best-effort basis.
- */
-int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,
-                            const char **exclude_patterns,
-                            refs_for_each_cb fn, void *cb_data);
-
 /**
  * Iterate all refs in "prefixes" by partitioning prefixes into disjoint sets
  * and iterating the longest-common prefix of each set.
index 4ddb3370c6cb10f589bb103bc118aeed3fa6703c..0136ef64f533582687de3f658226ee76b4e696b5 100644 (file)
@@ -2731,10 +2731,12 @@ void revision_opts_finish(struct rev_info *revs)
 static int for_each_bisect_ref(struct ref_store *refs, refs_for_each_cb fn,
                               void *cb_data, const char *term)
 {
+       struct refs_for_each_ref_options opts = { 0 };
        struct strbuf bisect_refs = STRBUF_INIT;
        int status;
        strbuf_addf(&bisect_refs, "refs/bisect/%s", term);
-       status = refs_for_each_fullref_in(refs, bisect_refs.buf, NULL, fn, cb_data);
+       opts.prefix = bisect_refs.buf;
+       status = refs_for_each_ref_ext(refs, fn, cb_data, &opts);
        strbuf_release(&bisect_refs);
        return status;
 }
index a2ef1b69495abfc23af50d1aea9389810be90676..74edf2029a28fcb081d522a74a30127f73f2a74e 100644 (file)
@@ -173,10 +173,12 @@ static int cmd_for_each_ref(struct ref_store *refs, const char **argv)
 static int cmd_for_each_ref__exclude(struct ref_store *refs, const char **argv)
 {
        const char *prefix = notnull(*argv++, "prefix");
-       const char **exclude_patterns = argv;
+       struct refs_for_each_ref_options opts = {
+               .prefix = prefix,
+               .exclude_patterns = argv,
+       };
 
-       return refs_for_each_fullref_in(refs, prefix, exclude_patterns, each_ref,
-                                       NULL);
+       return refs_for_each_ref_ext(refs, each_ref, NULL, &opts);
 }
 
 static int cmd_resolve_ref(struct ref_store *refs, const char **argv)