Skip to content

Commit 62979ad

Browse files
pks-tgitster
authored andcommitted
refs: replace refs_for_each_fullref_in()
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>
1 parent 162d001 commit 62979ad

8 files changed

Lines changed: 37 additions & 46 deletions

File tree

bisect.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,13 +1190,15 @@ static int mark_for_removal(const struct reference *ref, void *cb_data)
11901190

11911191
int bisect_clean_state(void)
11921192
{
1193+
struct refs_for_each_ref_options opts = {
1194+
.prefix = "refs/bisect/",
1195+
};
11931196
int result = 0;
11941197

11951198
/* There may be some refs packed during bisection */
11961199
struct string_list refs_for_removal = STRING_LIST_INIT_DUP;
1197-
refs_for_each_fullref_in(get_main_ref_store(the_repository),
1198-
"refs/bisect/", NULL, mark_for_removal,
1199-
&refs_for_removal);
1200+
refs_for_each_ref_ext(get_main_ref_store(the_repository),
1201+
mark_for_removal, &refs_for_removal, &opts);
12001202
string_list_append(&refs_for_removal, "BISECT_HEAD");
12011203
string_list_append(&refs_for_removal, "BISECT_EXPECTED_REV");
12021204
result = refs_delete_refs(get_main_ref_store(the_repository),

builtin/receive-pack.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,22 +343,22 @@ static void show_one_alternate_ref(const struct object_id *oid,
343343

344344
static void write_head_info(void)
345345
{
346+
struct refs_for_each_ref_options opts = { 0 };
346347
static struct oidset seen = OIDSET_INIT;
347348
struct strvec excludes_vector = STRVEC_INIT;
348-
const char **exclude_patterns;
349349

350350
/*
351351
* We need access to the reference names both with and without their
352352
* namespace and thus cannot use `refs_for_each_namespaced_ref()`. We
353353
* thus have to adapt exclude patterns to carry the namespace prefix
354354
* ourselves.
355355
*/
356-
exclude_patterns = get_namespaced_exclude_patterns(
356+
opts.exclude_patterns = get_namespaced_exclude_patterns(
357357
hidden_refs_to_excludes(&hidden_refs),
358358
get_git_namespace(), &excludes_vector);
359359

360-
refs_for_each_fullref_in(get_main_ref_store(the_repository), "",
361-
exclude_patterns, show_ref_cb, &seen);
360+
refs_for_each_ref_ext(get_main_ref_store(the_repository),
361+
show_ref_cb, &seen, &opts);
362362
odb_for_each_alternate_ref(the_repository->objects,
363363
show_one_alternate_ref, &seen);
364364

builtin/rev-parse.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -939,14 +939,13 @@ int cmd_rev_parse(int argc,
939939
continue;
940940
}
941941
if (!strcmp(arg, "--bisect")) {
942-
refs_for_each_fullref_in(get_main_ref_store(the_repository),
943-
"refs/bisect/bad",
944-
NULL, show_reference,
945-
NULL);
946-
refs_for_each_fullref_in(get_main_ref_store(the_repository),
947-
"refs/bisect/good",
948-
NULL, anti_reference,
949-
NULL);
942+
struct refs_for_each_ref_options opts = { 0 };
943+
opts.prefix = "refs/bisect/bad";
944+
refs_for_each_ref_ext(get_main_ref_store(the_repository),
945+
show_reference, NULL, &opts);
946+
opts.prefix = "refs/bisect/good";
947+
refs_for_each_ref_ext(get_main_ref_store(the_repository),
948+
anti_reference, NULL, &opts);
950949
continue;
951950
}
952951
if (opt_with_value(arg, "--branches", &arg)) {

builtin/show-ref.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,19 @@ static int cmd_show_ref__patterns(const struct patterns_options *opts,
215215
refs_head_ref(get_main_ref_store(the_repository), show_ref,
216216
&show_ref_data);
217217
if (opts->branches_only || opts->tags_only) {
218-
if (opts->branches_only)
219-
refs_for_each_fullref_in(get_main_ref_store(the_repository),
220-
"refs/heads/", NULL,
221-
show_ref, &show_ref_data);
222-
if (opts->tags_only)
223-
refs_for_each_fullref_in(get_main_ref_store(the_repository),
224-
"refs/tags/", NULL, show_ref,
225-
&show_ref_data);
218+
struct refs_for_each_ref_options for_each_ref_opts = { 0 };
219+
220+
if (opts->branches_only) {
221+
for_each_ref_opts.prefix = "refs/heads/";
222+
refs_for_each_ref_ext(get_main_ref_store(the_repository),
223+
show_ref, &show_ref_data, &for_each_ref_opts);
224+
}
225+
226+
if (opts->tags_only) {
227+
for_each_ref_opts.prefix = "refs/tags/";
228+
refs_for_each_ref_ext(get_main_ref_store(the_repository),
229+
show_ref, &show_ref_data, &for_each_ref_opts);
230+
}
226231
} else {
227232
refs_for_each_ref(get_main_ref_store(the_repository),
228233
show_ref, &show_ref_data);

refs.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,17 +1920,6 @@ int refs_for_each_ref(struct ref_store *refs, refs_for_each_cb cb, void *cb_data
19201920
return refs_for_each_ref_ext(refs, cb, cb_data, &opts);
19211921
}
19221922

1923-
int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,
1924-
const char **exclude_patterns,
1925-
refs_for_each_cb cb, void *cb_data)
1926-
{
1927-
struct refs_for_each_ref_options opts = {
1928-
.prefix = prefix,
1929-
.exclude_patterns = exclude_patterns,
1930-
};
1931-
return refs_for_each_ref_ext(refs, cb, cb_data, &opts);
1932-
}
1933-
19341923
int refs_for_each_replace_ref(struct ref_store *refs, refs_for_each_cb cb, void *cb_data)
19351924
{
19361925
const char *git_replace_ref_base = ref_namespace[NAMESPACE_REPLACE].ref;

refs.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -509,14 +509,6 @@ int refs_for_each_remote_ref(struct ref_store *refs,
509509
int refs_for_each_replace_ref(struct ref_store *refs,
510510
refs_for_each_cb fn, void *cb_data);
511511

512-
/*
513-
* references matching any pattern in "exclude_patterns" are omitted from the
514-
* result set on a best-effort basis.
515-
*/
516-
int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,
517-
const char **exclude_patterns,
518-
refs_for_each_cb fn, void *cb_data);
519-
520512
/**
521513
* Iterate all refs in "prefixes" by partitioning prefixes into disjoint sets
522514
* and iterating the longest-common prefix of each set.

revision.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2731,10 +2731,12 @@ void revision_opts_finish(struct rev_info *revs)
27312731
static int for_each_bisect_ref(struct ref_store *refs, refs_for_each_cb fn,
27322732
void *cb_data, const char *term)
27332733
{
2734+
struct refs_for_each_ref_options opts = { 0 };
27342735
struct strbuf bisect_refs = STRBUF_INIT;
27352736
int status;
27362737
strbuf_addf(&bisect_refs, "refs/bisect/%s", term);
2737-
status = refs_for_each_fullref_in(refs, bisect_refs.buf, NULL, fn, cb_data);
2738+
opts.prefix = bisect_refs.buf;
2739+
status = refs_for_each_ref_ext(refs, fn, cb_data, &opts);
27382740
strbuf_release(&bisect_refs);
27392741
return status;
27402742
}

t/helper/test-ref-store.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,12 @@ static int cmd_for_each_ref(struct ref_store *refs, const char **argv)
173173
static int cmd_for_each_ref__exclude(struct ref_store *refs, const char **argv)
174174
{
175175
const char *prefix = notnull(*argv++, "prefix");
176-
const char **exclude_patterns = argv;
176+
struct refs_for_each_ref_options opts = {
177+
.prefix = prefix,
178+
.exclude_patterns = argv,
179+
};
177180

178-
return refs_for_each_fullref_in(refs, prefix, exclude_patterns, each_ref,
179-
NULL);
181+
return refs_for_each_ref_ext(refs, each_ref, NULL, &opts);
180182
}
181183

182184
static int cmd_resolve_ref(struct ref_store *refs, const char **argv)

0 commit comments

Comments
 (0)