refs: replace `refs_for_each_ref_in()`

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>

Patrick Steinhardt committed Feb 23, 2026 at 12:59 UTC 00be226f1f2a1036ea3920f8700b23b7cc55bf57
6 files changed +45 -32
bisect.c
+6 -2
@@ -473,8 +473,12 @@ static int register_ref(const struct reference *ref, void *cb_data UNUSED)
473
474 static int read_bisect_refs(void)
475 {
476 - return refs_for_each_ref_in(get_main_ref_store(the_repository),
477 - "refs/bisect/", register_ref, NULL);
476 + struct refs_for_each_ref_options opts = {
477 + .prefix = "refs/bisect/",
478 + .trim_prefix = strlen("refs/bisect/"),
479 + };
480 + return refs_for_each_ref_ext(get_main_ref_store(the_repository),
481 + register_ref, NULL, &opts);
482 }
483
484 static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES")
builtin/rev-parse.c
+9 -4
@@ -613,13 +613,18 @@ static int opt_with_value(const char *arg, const char *opt, const char **value)
613
614 static void handle_ref_opt(const char *pattern, const char *prefix)
615 {
616 - if (pattern)
616 + if (pattern) {
617 refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
618 show_reference, pattern, prefix,
619 NULL);
620 - else
621 - refs_for_each_ref_in(get_main_ref_store(the_repository),
622 - prefix, show_reference, NULL);
620 + } else {
621 + struct refs_for_each_ref_options opts = {
622 + .prefix = prefix,
623 + .trim_prefix = strlen(prefix),
624 + };
625 + refs_for_each_ref_ext(get_main_ref_store(the_repository),
626 + show_reference, NULL, &opts);
627 + }
628 clear_ref_exclusions(&ref_excludes);
629 }
630
pack-bitmap.c
+7 -6
@@ -3326,6 +3326,7 @@ static const struct string_list *bitmap_preferred_tips(struct repository *r)
3326 void for_each_preferred_bitmap_tip(struct repository *repo,
3327 refs_for_each_cb cb, void *cb_data)
3328 {
3329 + struct refs_for_each_ref_options opts = { 0 };
3330 struct string_list_item *item;
3331 const struct string_list *preferred_tips;
3332 struct strbuf buf = STRBUF_INIT;
@@ -3335,16 +3336,16 @@ void for_each_preferred_bitmap_tip(struct repository *repo,
3336 return;
3337
3338 for_each_string_list_item(item, preferred_tips) {
3338 - const char *pattern = item->string;
3339 + opts.prefix = item->string;
3340
3340 - if (!ends_with(pattern, "/")) {
3341 + if (!ends_with(opts.prefix, "/")) {
3342 strbuf_reset(&buf);
3342 - strbuf_addf(&buf, "%s/", pattern);
3343 - pattern = buf.buf;
3343 + strbuf_addf(&buf, "%s/", opts.prefix);
3344 + opts.prefix = buf.buf;
3345 }
3346
3346 - refs_for_each_ref_in(get_main_ref_store(repo),
3347 - pattern, cb, cb_data);
3347 + refs_for_each_ref_ext(get_main_ref_store(repo),
3348 + cb, cb_data, &opts);
3349 }
3350
3351 strbuf_release(&buf);
refs.c
+18 -16
@@ -529,19 +529,31 @@ void refs_warn_dangling_symrefs(struct ref_store *refs, FILE *fp,
529 refs_for_each_rawref(refs, warn_if_dangling_symref, &data);
530 }
531
532 -int refs_for_each_tag_ref(struct ref_store *refs, refs_for_each_cb fn, void *cb_data)
532 +int refs_for_each_tag_ref(struct ref_store *refs, refs_for_each_cb cb, void *cb_data)
533 {
534 - return refs_for_each_ref_in(refs, "refs/tags/", fn, cb_data);
534 + struct refs_for_each_ref_options opts = {
535 + .prefix = "refs/tags/",
536 + .trim_prefix = strlen("refs/tags/"),
537 + };
538 + return refs_for_each_ref_ext(refs, cb, cb_data, &opts);
539 }
540
537 -int refs_for_each_branch_ref(struct ref_store *refs, refs_for_each_cb fn, void *cb_data)
541 +int refs_for_each_branch_ref(struct ref_store *refs, refs_for_each_cb cb, void *cb_data)
542 {
539 - return refs_for_each_ref_in(refs, "refs/heads/", fn, cb_data);
543 + struct refs_for_each_ref_options opts = {
544 + .prefix = "refs/heads/",
545 + .trim_prefix = strlen("refs/heads/"),
546 + };
547 + return refs_for_each_ref_ext(refs, cb, cb_data, &opts);
548 }
549
542 -int refs_for_each_remote_ref(struct ref_store *refs, refs_for_each_cb fn, void *cb_data)
550 +int refs_for_each_remote_ref(struct ref_store *refs, refs_for_each_cb cb, void *cb_data)
551 {
544 - return refs_for_each_ref_in(refs, "refs/remotes/", fn, cb_data);
552 + struct refs_for_each_ref_options opts = {
553 + .prefix = "refs/remotes/",
554 + .trim_prefix = strlen("refs/remotes/"),
555 + };
556 + return refs_for_each_ref_ext(refs, cb, cb_data, &opts);
557 }
558
559 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
1946 return refs_for_each_ref_ext(refs, cb, cb_data, &opts);
1947 }
1948
1937 -int refs_for_each_ref_in(struct ref_store *refs, const char *prefix,
1938 - refs_for_each_cb cb, void *cb_data)
1939 -{
1940 - struct refs_for_each_ref_options opts = {
1941 - .prefix = prefix,
1942 - .trim_prefix = strlen(prefix),
1943 - };
1944 - return refs_for_each_ref_ext(refs, cb, cb_data, &opts);
1945 -}
1946 -
1949 int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,
1950 const char **exclude_patterns,
1951 refs_for_each_cb cb, void *cb_data)
refs.h
-2
@@ -501,8 +501,6 @@ int refs_for_each_ref(struct ref_store *refs,
501 int refs_for_each_ref_ext(struct ref_store *refs,
502 refs_for_each_cb cb, void *cb_data,
503 const struct refs_for_each_ref_options *opts);
504 -int refs_for_each_ref_in(struct ref_store *refs, const char *prefix,
505 - refs_for_each_cb fn, void *cb_data);
504 int refs_for_each_tag_ref(struct ref_store *refs,
505 refs_for_each_cb fn, void *cb_data);
506 int refs_for_each_branch_ref(struct ref_store *refs,
t/helper/test-ref-store.c
+5 -2
@@ -163,8 +163,11 @@ static int each_ref(const struct reference *ref, void *cb_data UNUSED)
163 static int cmd_for_each_ref(struct ref_store *refs, const char **argv)
164 {
165 const char *prefix = notnull(*argv++, "prefix");
166 -
167 - return refs_for_each_ref_in(refs, prefix, each_ref, NULL);
166 + struct refs_for_each_ref_options opts = {
167 + .prefix = prefix,
168 + .trim_prefix = strlen(prefix),
169 + };
170 + return refs_for_each_ref_ext(refs, each_ref, NULL, &opts);
171 }
172
173 static int cmd_for_each_ref__exclude(struct ref_store *refs, const char **argv)