refs: replace `refs_for_each_glob_ref_in()`
Replace calls to `refs_for_each_glob_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
4091d2989353aaf14080ee64ee2e94b60ceaf18d
5 files changed
+55
-36
builtin/bisect.c
+27
-10
@@ -422,13 +422,17 @@ static void bisect_status(struct bisect_state *state,
422
{
423
char *bad_ref = xstrfmt("refs/bisect/%s", terms->term_bad);
424
char *good_glob = xstrfmt("%s-*", terms->term_good);
425
+ struct refs_for_each_ref_options opts = {
426
+ .pattern = good_glob,
427
+ .prefix = "refs/bisect/",
428
+ .trim_prefix = strlen("refs/bisect/"),
429
+ };
430
431
if (refs_ref_exists(get_main_ref_store(the_repository), bad_ref))
432
state->nr_bad = 1;
433
429
- refs_for_each_glob_ref_in(get_main_ref_store(the_repository), inc_nr,
430
- good_glob, "refs/bisect/",
431
- (void *) &state->nr_good);
434
+ refs_for_each_ref_ext(get_main_ref_store(the_repository),
435
+ inc_nr, &state->nr_good, &opts);
436
437
free(good_glob);
438
free(bad_ref);
@@ -562,6 +566,10 @@ static int add_bisect_ref(const struct reference *ref, void *cb)
566
567
static int prepare_revs(struct bisect_terms *terms, struct rev_info *revs)
568
{
569
+ struct refs_for_each_ref_options opts = {
570
+ .prefix = "refs/bisect/",
571
+ .trim_prefix = strlen("refs/bisect/"),
572
+ };
573
int res = 0;
574
struct add_bisect_ref_data cb = { revs };
575
char *good = xstrfmt("%s-*", terms->term_good);
@@ -581,11 +589,16 @@ static int prepare_revs(struct bisect_terms *terms, struct rev_info *revs)
589
reset_revision_walk();
590
repo_init_revisions(the_repository, revs, NULL);
591
setup_revisions(0, NULL, revs, NULL);
584
- refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
585
- add_bisect_ref, bad, "refs/bisect/", &cb);
592
+
593
+ opts.pattern = bad;
594
+ refs_for_each_ref_ext(get_main_ref_store(the_repository),
595
+ add_bisect_ref, &cb, &opts);
596
+
597
cb.object_flags = UNINTERESTING;
587
- refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
588
- add_bisect_ref, good, "refs/bisect/", &cb);
598
+ opts.pattern = good;
599
+ refs_for_each_ref_ext(get_main_ref_store(the_repository),
600
+ add_bisect_ref, &cb, &opts);
601
+
602
if (prepare_revision_walk(revs))
603
res = error(_("revision walk setup failed"));
604
@@ -1191,10 +1204,14 @@ static int verify_good(const struct bisect_terms *terms, const char *command)
1204
char *good_glob = xstrfmt("%s-*", terms->term_good);
1205
int no_checkout = refs_ref_exists(get_main_ref_store(the_repository),
1206
"BISECT_HEAD");
1207
+ struct refs_for_each_ref_options opts = {
1208
+ .pattern = good_glob,
1209
+ .prefix = "refs/bisect/",
1210
+ .trim_prefix = strlen("refs/bisect/"),
1211
+ };
1212
1195
- refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
1196
- get_first_good, good_glob, "refs/bisect/",
1197
- &good_rev);
1213
+ refs_for_each_ref_ext(get_main_ref_store(the_repository),
1214
+ get_first_good, &good_rev, &opts);
1215
free(good_glob);
1216
1217
if (refs_read_ref(get_main_ref_store(the_repository), no_checkout ? "BISECT_HEAD" : "HEAD", ¤t_rev))
builtin/rev-parse.c
+7
-3
@@ -614,9 +614,13 @@ static int opt_with_value(const char *arg, const char *opt, const char **value)
614
static void handle_ref_opt(const char *pattern, const char *prefix)
615
{
616
if (pattern) {
617
- refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
618
- show_reference, pattern, prefix,
619
- NULL);
617
+ struct refs_for_each_ref_options opts = {
618
+ .pattern = pattern,
619
+ .prefix = prefix,
620
+ .trim_prefix = prefix ? strlen(prefix) : 0,
621
+ };
622
+ refs_for_each_ref_ext(get_main_ref_store(the_repository),
623
+ show_reference, NULL, &opts);
624
} else {
625
struct refs_for_each_ref_options opts = {
626
.prefix = prefix,
refs.c
-11
@@ -607,17 +607,6 @@ void normalize_glob_ref(struct string_list_item *item, const char *prefix,
607
strbuf_release(&normalized_pattern);
608
}
609
610
-int refs_for_each_glob_ref_in(struct ref_store *refs, refs_for_each_cb cb,
611
- const char *pattern, const char *prefix, void *cb_data)
612
-{
613
- struct refs_for_each_ref_options opts = {
614
- .pattern = pattern,
615
- .prefix = prefix,
616
- .trim_prefix = prefix ? strlen(prefix) : 0,
617
- };
618
- return refs_for_each_ref_ext(refs, cb, cb_data, &opts);
619
-}
620
-
610
int refs_for_each_glob_ref(struct ref_store *refs, refs_for_each_cb cb,
611
const char *pattern, void *cb_data)
612
{
refs.h
-3
@@ -531,9 +531,6 @@ int refs_for_each_ref_in_prefixes(struct ref_store *refs,
531
int refs_for_each_glob_ref(struct ref_store *refs, refs_for_each_cb fn,
532
const char *pattern, void *cb_data);
533
534
-int refs_for_each_glob_ref_in(struct ref_store *refs, refs_for_each_cb fn,
535
- const char *pattern, const char *prefix, void *cb_data);
536
-
534
/*
535
* references matching any pattern in "exclude_patterns" are omitted from the
536
* result set on a best-effort basis.
revision.c
+21
-9
@@ -2827,34 +2827,46 @@ static int handle_revision_pseudo_opt(struct rev_info *revs,
2827
exclude_hidden_refs(&revs->ref_excludes, optarg);
2828
return argcount;
2829
} else if (skip_prefix(arg, "--branches=", &optarg)) {
2830
+ struct refs_for_each_ref_options opts = {
2831
+ .prefix = "refs/heads/",
2832
+ .trim_prefix = strlen("refs/heads/"),
2833
+ .pattern = optarg,
2834
+ };
2835
struct all_refs_cb cb;
2836
if (revs->ref_excludes.hidden_refs_configured)
2837
return error(_("options '%s' and '%s' cannot be used together"),
2838
"--exclude-hidden", "--branches");
2839
init_all_refs_cb(&cb, revs, *flags);
2835
- refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
2836
- handle_one_ref, optarg,
2837
- "refs/heads/", &cb);
2840
+ refs_for_each_ref_ext(get_main_ref_store(the_repository),
2841
+ handle_one_ref, &cb, &opts);
2842
clear_ref_exclusions(&revs->ref_excludes);
2843
} else if (skip_prefix(arg, "--tags=", &optarg)) {
2844
+ struct refs_for_each_ref_options opts = {
2845
+ .prefix = "refs/tags/",
2846
+ .trim_prefix = strlen("refs/tags/"),
2847
+ .pattern = optarg,
2848
+ };
2849
struct all_refs_cb cb;
2850
if (revs->ref_excludes.hidden_refs_configured)
2851
return error(_("options '%s' and '%s' cannot be used together"),
2852
"--exclude-hidden", "--tags");
2853
init_all_refs_cb(&cb, revs, *flags);
2845
- refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
2846
- handle_one_ref, optarg,
2847
- "refs/tags/", &cb);
2854
+ refs_for_each_ref_ext(get_main_ref_store(the_repository),
2855
+ handle_one_ref, &cb, &opts);
2856
clear_ref_exclusions(&revs->ref_excludes);
2857
} else if (skip_prefix(arg, "--remotes=", &optarg)) {
2858
+ struct refs_for_each_ref_options opts = {
2859
+ .prefix = "refs/remotes/",
2860
+ .trim_prefix = strlen("refs/remotes/"),
2861
+ .pattern = optarg,
2862
+ };
2863
struct all_refs_cb cb;
2864
if (revs->ref_excludes.hidden_refs_configured)
2865
return error(_("options '%s' and '%s' cannot be used together"),
2866
"--exclude-hidden", "--remotes");
2867
init_all_refs_cb(&cb, revs, *flags);
2855
- refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
2856
- handle_one_ref, optarg,
2857
- "refs/remotes/", &cb);
2868
+ refs_for_each_ref_ext(get_main_ref_store(the_repository),
2869
+ handle_one_ref, &cb, &opts);
2870
clear_ref_exclusions(&revs->ref_excludes);
2871
} else if (!strcmp(arg, "--reflog")) {
2872
add_reflogs_to_pending(revs, *flags);