ls-refs: use repository parameter to iterate refs

The ls_refs() function (for the v2 protocol command of the same name) takes a repository parameter (like all v2 commands), but ignores it. It should use it to access the refs. This isn't a bug in practice, since we only call this function when serving upload-pack from the main repository. But it's an awkward gotcha, and it causes -Wunused-parameter to complain. The main reason we don't use the repository parameter is that the ref iteration interface we call doesn't have a "refs_" variant that takes a ref_store. However we can easily add one. In fact, since there is only one other caller (in ref-filter.c), there is no need to maintain the non-repository wrapper; that caller can just use the_repository. It's still a long way from consistently using a repository object, but it's one small step in the right direction. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Dec 13, 2022 at 06:11 UTC 91e2ab1587d8ee18e3d2978f2b7bc250faf5df8f
4 files changed +15 -10
ls-refs.c
+3 -2
@@ -194,8 +194,9 @@ int ls_refs(struct repository *r, struct packet_reader *request)
194 send_possibly_unborn_head(&data);
195 if (!data.prefixes.nr)
196 strvec_push(&data.prefixes, "");
197 - for_each_fullref_in_prefixes(get_git_namespace(), data.prefixes.v,
198 - send_ref, &data);
197 + refs_for_each_fullref_in_prefixes(get_main_ref_store(r),
198 + get_git_namespace(), data.prefixes.v,
199 + send_ref, &data);
200 packet_fflush(stdout);
201 strvec_clear(&data.prefixes);
202 strbuf_release(&data.buf);
ref-filter.c
+3 -2
@@ -2128,8 +2128,9 @@ static int for_each_fullref_in_pattern(struct ref_filter *filter,
2128 return for_each_fullref_in("", cb, cb_data);
2129 }
2130
2131 - return for_each_fullref_in_prefixes(NULL, filter->name_patterns,
2132 - cb, cb_data);
2131 + return refs_for_each_fullref_in_prefixes(get_main_ref_store(the_repository),
2132 + NULL, filter->name_patterns,
2133 + cb, cb_data);
2134 }
2135
2136 /*
refs.c
+5 -4
@@ -1723,9 +1723,10 @@ static void find_longest_prefixes(struct string_list *out,
1723 strbuf_release(&prefix);
1724 }
1725
1726 -int for_each_fullref_in_prefixes(const char *namespace,
1727 - const char **patterns,
1728 - each_ref_fn fn, void *cb_data)
1726 +int refs_for_each_fullref_in_prefixes(struct ref_store *ref_store,
1727 + const char *namespace,
1728 + const char **patterns,
1729 + each_ref_fn fn, void *cb_data)
1730 {
1731 struct string_list prefixes = STRING_LIST_INIT_DUP;
1732 struct string_list_item *prefix;
@@ -1740,7 +1741,7 @@ int for_each_fullref_in_prefixes(const char *namespace,
1741
1742 for_each_string_list_item(prefix, &prefixes) {
1743 strbuf_addstr(&buf, prefix->string);
1743 - ret = for_each_fullref_in(buf.buf, fn, cb_data);
1744 + ret = refs_for_each_fullref_in(ref_store, buf.buf, fn, cb_data);
1745 if (ret)
1746 break;
1747 strbuf_setlen(&buf, namespace_len);
refs.h
+4 -2
@@ -354,8 +354,10 @@ int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data);
354 *
355 * callers should be prepared to ignore references that they did not ask for.
356 */
357 -int for_each_fullref_in_prefixes(const char *namespace, const char **patterns,
358 - each_ref_fn fn, void *cb_data);
357 +int refs_for_each_fullref_in_prefixes(struct ref_store *refs,
358 + const char *namespace, const char **patterns,
359 + each_ref_fn fn, void *cb_data);
360 +
361 /**
362 * iterate refs from the respective area.
363 */