Skip to content

Commit

Permalink
refs: drop "broken" flag from for_each_fullref_in()
Browse files Browse the repository at this point in the history
No callers pass in anything but "0" here. Likewise to our sibling
functions. Note that some of them ferry along the flag, but none of
their callers pass anything but "0" either.

Nor is anybody likely to change that. Callers which really want to see
all of the raw refs use for_each_rawref(). And anybody interested in
iterating a subset of the refs will likely be happy to use the
now-default behavior of showing broken refs, but omitting dangling
symlinks.

So we can get rid of this whole feature.

Signed-off-by: Jeff King <[email protected]>
Reviewed-by: Jonathan Tan <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
peff authored and gitster committed Sep 27, 2021
1 parent 2d653c5 commit 67985e4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 36 deletions.
4 changes: 2 additions & 2 deletions builtin/rev-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
continue;
}
if (!strcmp(arg, "--bisect")) {
for_each_fullref_in("refs/bisect/bad", show_reference, NULL, 0);
for_each_fullref_in("refs/bisect/good", anti_reference, NULL, 0);
for_each_fullref_in("refs/bisect/bad", show_reference, NULL);
for_each_fullref_in("refs/bisect/good", anti_reference, NULL);
continue;
}
if (opt_with_value(arg, "--branches", &arg)) {
Expand Down
2 changes: 1 addition & 1 deletion ls-refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ int ls_refs(struct repository *r, struct packet_reader *request)
if (!data.prefixes.nr)
strvec_push(&data.prefixes, "");
for_each_fullref_in_prefixes(get_git_namespace(), data.prefixes.v,
send_ref, &data, 0);
send_ref, &data);
packet_fflush(stdout);
strvec_clear(&data.prefixes);
strbuf_release(&data.buf);
Expand Down
19 changes: 9 additions & 10 deletions ref-filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -2100,16 +2100,15 @@ static int filter_pattern_match(struct ref_filter *filter, const char *refname)
*/
static int for_each_fullref_in_pattern(struct ref_filter *filter,
each_ref_fn cb,
void *cb_data,
int broken)
void *cb_data)
{
if (!filter->match_as_path) {
/*
* in this case, the patterns are applied after
* prefixes like "refs/heads/" etc. are stripped off,
* so we have to look at everything:
*/
return for_each_fullref_in("", cb, cb_data, broken);
return for_each_fullref_in("", cb, cb_data);
}

if (filter->ignore_case) {
Expand All @@ -2118,16 +2117,16 @@ static int for_each_fullref_in_pattern(struct ref_filter *filter,
* so just return everything and let the caller
* sort it out.
*/
return for_each_fullref_in("", cb, cb_data, broken);
return for_each_fullref_in("", cb, cb_data);
}

if (!filter->name_patterns[0]) {
/* no patterns; we have to look at everything */
return for_each_fullref_in("", cb, cb_data, broken);
return for_each_fullref_in("", cb, cb_data);
}

return for_each_fullref_in_prefixes(NULL, filter->name_patterns,
cb, cb_data, broken);
cb, cb_data);
}

/*
Expand Down Expand Up @@ -2425,13 +2424,13 @@ int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int
* of filter_ref_kind().
*/
if (filter->kind == FILTER_REFS_BRANCHES)
ret = for_each_fullref_in("refs/heads/", ref_filter_handler, &ref_cbdata, 0);
ret = for_each_fullref_in("refs/heads/", ref_filter_handler, &ref_cbdata);
else if (filter->kind == FILTER_REFS_REMOTES)
ret = for_each_fullref_in("refs/remotes/", ref_filter_handler, &ref_cbdata, 0);
ret = for_each_fullref_in("refs/remotes/", ref_filter_handler, &ref_cbdata);
else if (filter->kind == FILTER_REFS_TAGS)
ret = for_each_fullref_in("refs/tags/", ref_filter_handler, &ref_cbdata, 0);
ret = for_each_fullref_in("refs/tags/", ref_filter_handler, &ref_cbdata);
else if (filter->kind & FILTER_REFS_ALL)
ret = for_each_fullref_in_pattern(filter, ref_filter_handler, &ref_cbdata, 0);
ret = for_each_fullref_in_pattern(filter, ref_filter_handler, &ref_cbdata);
if (!ret && (filter->kind & FILTER_REFS_DETACHED_HEAD))
head_ref(ref_filter_handler, &ref_cbdata);
}
Expand Down
22 changes: 6 additions & 16 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1522,25 +1522,16 @@ int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)
return refs_for_each_ref_in(get_main_ref_store(the_repository), prefix, fn, cb_data);
}

int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data, unsigned int broken)
int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data)
{
enum do_for_each_ref_flags flag = 0;

if (broken)
flag = DO_FOR_EACH_INCLUDE_BROKEN;
return do_for_each_ref(get_main_ref_store(the_repository),
prefix, fn, 0, flag, cb_data);
prefix, fn, 0, 0, cb_data);
}

int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,
each_ref_fn fn, void *cb_data,
unsigned int broken)
each_ref_fn fn, void *cb_data)
{
enum do_for_each_ref_flags flag = 0;

if (broken)
flag = DO_FOR_EACH_INCLUDE_BROKEN;
return do_for_each_ref(refs, prefix, fn, 0, flag, cb_data);
return do_for_each_ref(refs, prefix, fn, 0, 0, cb_data);
}

int for_each_replace_ref(struct repository *r, each_repo_ref_fn fn, void *cb_data)
Expand Down Expand Up @@ -1632,8 +1623,7 @@ static void find_longest_prefixes(struct string_list *out,

int for_each_fullref_in_prefixes(const char *namespace,
const char **patterns,
each_ref_fn fn, void *cb_data,
unsigned int broken)
each_ref_fn fn, void *cb_data)
{
struct string_list prefixes = STRING_LIST_INIT_DUP;
struct string_list_item *prefix;
Expand All @@ -1648,7 +1638,7 @@ int for_each_fullref_in_prefixes(const char *namespace,

for_each_string_list_item(prefix, &prefixes) {
strbuf_addstr(&buf, prefix->string);
ret = for_each_fullref_in(buf.buf, fn, cb_data, broken);
ret = for_each_fullref_in(buf.buf, fn, cb_data);
if (ret)
break;
strbuf_setlen(&buf, namespace_len);
Expand Down
9 changes: 3 additions & 6 deletions refs.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,8 @@ int for_each_ref(each_ref_fn fn, void *cb_data);
int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data);

int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,
each_ref_fn fn, void *cb_data,
unsigned int broken);
int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data,
unsigned int broken);
each_ref_fn fn, void *cb_data);
int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data);

/**
* iterate all refs in "patterns" by partitioning patterns into disjoint sets
Expand All @@ -354,8 +352,7 @@ int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data,
* callers should be prepared to ignore references that they did not ask for.
*/
int for_each_fullref_in_prefixes(const char *namespace, const char **patterns,
each_ref_fn fn, void *cb_data,
unsigned int broken);
each_ref_fn fn, void *cb_data);
/**
* iterate refs from the respective area.
*/
Expand Down
2 changes: 1 addition & 1 deletion revision.c
Original file line number Diff line number Diff line change
Expand Up @@ -2548,7 +2548,7 @@ static int for_each_bisect_ref(struct ref_store *refs, each_ref_fn fn,
struct strbuf bisect_refs = STRBUF_INIT;
int status;
strbuf_addf(&bisect_refs, "refs/bisect/%s", term);
status = refs_for_each_fullref_in(refs, bisect_refs.buf, fn, cb_data, 0);
status = refs_for_each_fullref_in(refs, bisect_refs.buf, fn, cb_data);
strbuf_release(&bisect_refs);
return status;
}
Expand Down

0 comments on commit 67985e4

Please sign in to comment.