]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs: replace `refs_for_each_ref_in()`
authorPatrick Steinhardt <ps@pks.im>
Mon, 23 Feb 2026 11:59:45 +0000 (12:59 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 23 Feb 2026 21:21:18 +0000 (13:21 -0800)
Replace calls to `refs_for_each_ref_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/rev-parse.c
pack-bitmap.c
refs.c
refs.h
t/helper/test-ref-store.c

index 2bdad4ee42e93782e6664316e531e4b945754c14..296836c15450c9bc598137c9b4a34b6ff62ef357 100644 (file)
--- a/bisect.c
+++ b/bisect.c
@@ -473,8 +473,12 @@ static int register_ref(const struct reference *ref, void *cb_data UNUSED)
 
 static int read_bisect_refs(void)
 {
-       return refs_for_each_ref_in(get_main_ref_store(the_repository),
-                                   "refs/bisect/", register_ref, NULL);
+       struct refs_for_each_ref_options opts = {
+               .prefix = "refs/bisect/",
+               .trim_prefix = strlen("refs/bisect/"),
+       };
+       return refs_for_each_ref_ext(get_main_ref_store(the_repository),
+                                    register_ref, NULL, &opts);
 }
 
 static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES")
index 9032cc6327c004d520d35f52e01a00a5d160c607..02703f2fb889873efba95f39992375d9a2cda05f 100644 (file)
@@ -613,13 +613,18 @@ static int opt_with_value(const char *arg, const char *opt, const char **value)
 
 static void handle_ref_opt(const char *pattern, const char *prefix)
 {
-       if (pattern)
+       if (pattern) {
                refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
                                          show_reference, pattern, prefix,
                                          NULL);
-       else
-               refs_for_each_ref_in(get_main_ref_store(the_repository),
-                                    prefix, show_reference, NULL);
+       } else {
+               struct refs_for_each_ref_options opts = {
+                       .prefix = prefix,
+                       .trim_prefix = strlen(prefix),
+               };
+               refs_for_each_ref_ext(get_main_ref_store(the_repository),
+                                     show_reference, NULL, &opts);
+       }
        clear_ref_exclusions(&ref_excludes);
 }
 
index efef7081e6a00444ee53f8e9b0d8ecc9a27b7749..22419bfb33dd4e2af04e0978883709f993987c06 100644 (file)
@@ -3326,6 +3326,7 @@ static const struct string_list *bitmap_preferred_tips(struct repository *r)
 void for_each_preferred_bitmap_tip(struct repository *repo,
                                   refs_for_each_cb cb, void *cb_data)
 {
+       struct refs_for_each_ref_options opts = { 0 };
        struct string_list_item *item;
        const struct string_list *preferred_tips;
        struct strbuf buf = STRBUF_INIT;
@@ -3335,16 +3336,16 @@ void for_each_preferred_bitmap_tip(struct repository *repo,
                return;
 
        for_each_string_list_item(item, preferred_tips) {
-               const char *pattern = item->string;
+               opts.prefix = item->string;
 
-               if (!ends_with(pattern, "/")) {
+               if (!ends_with(opts.prefix, "/")) {
                        strbuf_reset(&buf);
-                       strbuf_addf(&buf, "%s/", pattern);
-                       pattern = buf.buf;
+                       strbuf_addf(&buf, "%s/", opts.prefix);
+                       opts.prefix = buf.buf;
                }
 
-               refs_for_each_ref_in(get_main_ref_store(repo),
-                                    pattern, cb, cb_data);
+               refs_for_each_ref_ext(get_main_ref_store(repo),
+                                     cb, cb_data, &opts);
        }
 
        strbuf_release(&buf);
diff --git a/refs.c b/refs.c
index a57eafd6de607c4385c8ac99a4f18d3c5fb5dacf..7b1ef769c0ee9dd36e353008ba897a712d952d9b 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -529,19 +529,31 @@ void refs_warn_dangling_symrefs(struct ref_store *refs, FILE *fp,
        refs_for_each_rawref(refs, warn_if_dangling_symref, &data);
 }
 
-int refs_for_each_tag_ref(struct ref_store *refs, refs_for_each_cb fn, void *cb_data)
+int refs_for_each_tag_ref(struct ref_store *refs, refs_for_each_cb cb, void *cb_data)
 {
-       return refs_for_each_ref_in(refs, "refs/tags/", fn, cb_data);
+       struct refs_for_each_ref_options opts = {
+               .prefix = "refs/tags/",
+               .trim_prefix = strlen("refs/tags/"),
+       };
+       return refs_for_each_ref_ext(refs, cb, cb_data, &opts);
 }
 
-int refs_for_each_branch_ref(struct ref_store *refs, refs_for_each_cb fn, void *cb_data)
+int refs_for_each_branch_ref(struct ref_store *refs, refs_for_each_cb cb, void *cb_data)
 {
-       return refs_for_each_ref_in(refs, "refs/heads/", fn, cb_data);
+       struct refs_for_each_ref_options opts = {
+               .prefix = "refs/heads/",
+               .trim_prefix = strlen("refs/heads/"),
+       };
+       return refs_for_each_ref_ext(refs, cb, cb_data, &opts);
 }
 
-int refs_for_each_remote_ref(struct ref_store *refs, refs_for_each_cb fn, void *cb_data)
+int refs_for_each_remote_ref(struct ref_store *refs, refs_for_each_cb cb, void *cb_data)
 {
-       return refs_for_each_ref_in(refs, "refs/remotes/", fn, cb_data);
+       struct refs_for_each_ref_options opts = {
+               .prefix = "refs/remotes/",
+               .trim_prefix = strlen("refs/remotes/"),
+       };
+       return refs_for_each_ref_ext(refs, cb, cb_data, &opts);
 }
 
 int refs_head_ref_namespaced(struct ref_store *refs, refs_for_each_cb fn, void *cb_data)
@@ -1934,16 +1946,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_ref_in(struct ref_store *refs, const char *prefix,
-                        refs_for_each_cb cb, void *cb_data)
-{
-       struct refs_for_each_ref_options opts = {
-               .prefix = prefix,
-               .trim_prefix = strlen(prefix),
-       };
-       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)
diff --git a/refs.h b/refs.h
index faed63aa812718e2ce9e0e038ab90ceca6d49b72..7a3bc9e5b70200d65d22d4e380fba7ff8c9bd5c5 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -501,8 +501,6 @@ int refs_for_each_ref(struct ref_store *refs,
 int refs_for_each_ref_ext(struct ref_store *refs,
                          refs_for_each_cb cb, void *cb_data,
                          const struct refs_for_each_ref_options *opts);
-int refs_for_each_ref_in(struct ref_store *refs, const char *prefix,
-                        refs_for_each_cb fn, void *cb_data);
 int refs_for_each_tag_ref(struct ref_store *refs,
                          refs_for_each_cb fn, void *cb_data);
 int refs_for_each_branch_ref(struct ref_store *refs,
index b1215947c5e67a87a46f7705bfce38c36c3f2a72..a2ef1b69495abfc23af50d1aea9389810be90676 100644 (file)
@@ -163,8 +163,11 @@ static int each_ref(const struct reference *ref, void *cb_data UNUSED)
 static int cmd_for_each_ref(struct ref_store *refs, const char **argv)
 {
        const char *prefix = notnull(*argv++, "prefix");
-
-       return refs_for_each_ref_in(refs, prefix, each_ref, NULL);
+       struct refs_for_each_ref_options opts = {
+               .prefix = prefix,
+               .trim_prefix = strlen(prefix),
+       };
+       return refs_for_each_ref_ext(refs, each_ref, NULL, &opts);
 }
 
 static int cmd_for_each_ref__exclude(struct ref_store *refs, const char **argv)