Skip to content

Commit 4091d29

Browse files
pks-tgitster
authored andcommitted
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>
1 parent 5ef6d59 commit 4091d29

5 files changed

Lines changed: 55 additions & 36 deletions

File tree

builtin/bisect.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,17 @@ static void bisect_status(struct bisect_state *state,
422422
{
423423
char *bad_ref = xstrfmt("refs/bisect/%s", terms->term_bad);
424424
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+
};
425430

426431
if (refs_ref_exists(get_main_ref_store(the_repository), bad_ref))
427432
state->nr_bad = 1;
428433

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);
432436

433437
free(good_glob);
434438
free(bad_ref);
@@ -562,6 +566,10 @@ static int add_bisect_ref(const struct reference *ref, void *cb)
562566

563567
static int prepare_revs(struct bisect_terms *terms, struct rev_info *revs)
564568
{
569+
struct refs_for_each_ref_options opts = {
570+
.prefix = "refs/bisect/",
571+
.trim_prefix = strlen("refs/bisect/"),
572+
};
565573
int res = 0;
566574
struct add_bisect_ref_data cb = { revs };
567575
char *good = xstrfmt("%s-*", terms->term_good);
@@ -581,11 +589,16 @@ static int prepare_revs(struct bisect_terms *terms, struct rev_info *revs)
581589
reset_revision_walk();
582590
repo_init_revisions(the_repository, revs, NULL);
583591
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+
586597
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+
589602
if (prepare_revision_walk(revs))
590603
res = error(_("revision walk setup failed"));
591604

@@ -1191,10 +1204,14 @@ static int verify_good(const struct bisect_terms *terms, const char *command)
11911204
char *good_glob = xstrfmt("%s-*", terms->term_good);
11921205
int no_checkout = refs_ref_exists(get_main_ref_store(the_repository),
11931206
"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+
};
11941212

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);
11981215
free(good_glob);
11991216

12001217
if (refs_read_ref(get_main_ref_store(the_repository), no_checkout ? "BISECT_HEAD" : "HEAD", &current_rev))

builtin/rev-parse.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,9 +614,13 @@ static int opt_with_value(const char *arg, const char *opt, const char **value)
614614
static void handle_ref_opt(const char *pattern, const char *prefix)
615615
{
616616
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);
620624
} else {
621625
struct refs_for_each_ref_options opts = {
622626
.prefix = prefix,

refs.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -607,17 +607,6 @@ void normalize_glob_ref(struct string_list_item *item, const char *prefix,
607607
strbuf_release(&normalized_pattern);
608608
}
609609

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-
621610
int refs_for_each_glob_ref(struct ref_store *refs, refs_for_each_cb cb,
622611
const char *pattern, void *cb_data)
623612
{

refs.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,6 @@ int refs_for_each_ref_in_prefixes(struct ref_store *refs,
531531
int refs_for_each_glob_ref(struct ref_store *refs, refs_for_each_cb fn,
532532
const char *pattern, void *cb_data);
533533

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-
537534
/*
538535
* references matching any pattern in "exclude_patterns" are omitted from the
539536
* result set on a best-effort basis.

revision.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,34 +2827,46 @@ static int handle_revision_pseudo_opt(struct rev_info *revs,
28272827
exclude_hidden_refs(&revs->ref_excludes, optarg);
28282828
return argcount;
28292829
} 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+
};
28302835
struct all_refs_cb cb;
28312836
if (revs->ref_excludes.hidden_refs_configured)
28322837
return error(_("options '%s' and '%s' cannot be used together"),
28332838
"--exclude-hidden", "--branches");
28342839
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);
28382842
clear_ref_exclusions(&revs->ref_excludes);
28392843
} 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+
};
28402849
struct all_refs_cb cb;
28412850
if (revs->ref_excludes.hidden_refs_configured)
28422851
return error(_("options '%s' and '%s' cannot be used together"),
28432852
"--exclude-hidden", "--tags");
28442853
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);
28482856
clear_ref_exclusions(&revs->ref_excludes);
28492857
} 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+
};
28502863
struct all_refs_cb cb;
28512864
if (revs->ref_excludes.hidden_refs_configured)
28522865
return error(_("options '%s' and '%s' cannot be used together"),
28532866
"--exclude-hidden", "--remotes");
28542867
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);
28582870
clear_ref_exclusions(&revs->ref_excludes);
28592871
} else if (!strcmp(arg, "--reflog")) {
28602872
add_reflogs_to_pending(revs, *flags);

0 commit comments

Comments
 (0)