refs.h: let `for_each_namespaced_ref()` take excluded patterns

A future commit will want to call `for_each_namespaced_ref()` with a list of excluded patterns. We could introduce a variant of that function, say, `for_each_namespaced_ref_exclude()` which takes the extra parameter, and reimplement the original function in terms of that. But all but one caller (in `http-backend.c`) will supply the new parameter, so add the new parameter to `for_each_namespaced_ref()` itself instead of introducing a new function. For now, supply NULL for the list of excluded patterns at all callers to avoid changing behavior, which we will do in a future change. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Jul 10, 2023 at 17:12 UTC e6bf24d39a6a85e0a2257f22bffc09b9df749b4a
4 files changed +13 -7
http-backend.c
+1 -1
@@ -559,7 +559,7 @@ static void get_info_refs(struct strbuf *hdr, char *arg UNUSED)
559
560 } else {
561 select_getanyfile(hdr);
562 - for_each_namespaced_ref(show_text_ref, &buf);
562 + for_each_namespaced_ref(NULL, show_text_ref, &buf);
563 send_strbuf(hdr, "text/plain", &buf);
564 }
565 strbuf_release(&buf);
refs.c
+3 -2
@@ -1660,13 +1660,14 @@ int for_each_replace_ref(struct repository *r, each_repo_ref_fn fn, void *cb_dat
1660 DO_FOR_EACH_INCLUDE_BROKEN, cb_data);
1661 }
1662
1663 -int for_each_namespaced_ref(each_ref_fn fn, void *cb_data)
1663 +int for_each_namespaced_ref(const char **exclude_patterns,
1664 + each_ref_fn fn, void *cb_data)
1665 {
1666 struct strbuf buf = STRBUF_INIT;
1667 int ret;
1668 strbuf_addf(&buf, "%srefs/", get_git_namespace());
1669 ret = do_for_each_ref(get_main_ref_store(the_repository),
1669 - buf.buf, NULL, fn, 0, 0, cb_data);
1670 + buf.buf, exclude_patterns, fn, 0, 0, cb_data);
1671 strbuf_release(&buf);
1672 return ret;
1673 }
refs.h
+6 -1
@@ -376,7 +376,12 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
376 const char *prefix, void *cb_data);
377
378 int head_ref_namespaced(each_ref_fn fn, void *cb_data);
379 -int for_each_namespaced_ref(each_ref_fn fn, void *cb_data);
379 +/*
380 + * references matching any pattern in "exclude_patterns" are omitted from the
381 + * result set on a best-effort basis.
382 + */
383 +int for_each_namespaced_ref(const char **exclude_patterns,
384 + each_ref_fn fn, void *cb_data);
385
386 /* can be used to learn about broken ref and symref */
387 int refs_for_each_rawref(struct ref_store *refs, each_ref_fn fn, void *cb_data);
upload-pack.c
+3 -3
@@ -855,7 +855,7 @@ static void deepen(struct upload_pack_data *data, int depth)
855 * marked with OUR_REF.
856 */
857 head_ref_namespaced(check_ref, data);
858 - for_each_namespaced_ref(check_ref, data);
858 + for_each_namespaced_ref(NULL, check_ref, data);
859
860 get_reachable_list(data, &reachable_shallows);
861 result = get_shallow_commits(&reachable_shallows,
@@ -1386,7 +1386,7 @@ void upload_pack(const int advertise_refs, const int stateless_rpc,
1386 if (advertise_refs)
1387 data.no_done = 1;
1388 head_ref_namespaced(send_ref, &data);
1389 - for_each_namespaced_ref(send_ref, &data);
1389 + for_each_namespaced_ref(NULL, send_ref, &data);
1390 if (!data.sent_capabilities) {
1391 const char *refname = "capabilities^{}";
1392 write_v0_ref(&data, refname, refname, null_oid());
@@ -1400,7 +1400,7 @@ void upload_pack(const int advertise_refs, const int stateless_rpc,
1400 packet_flush(1);
1401 } else {
1402 head_ref_namespaced(check_ref, &data);
1403 - for_each_namespaced_ref(check_ref, &data);
1403 + for_each_namespaced_ref(NULL, check_ref, &data);
1404 }
1405
1406 if (!advertise_refs) {