Skip to content

Commit 91e2ab1

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c48035d commit 91e2ab1

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

ls-refs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,9 @@ int ls_refs(struct repository *r, struct packet_reader *request)
194194
send_possibly_unborn_head(&data);
195195
if (!data.prefixes.nr)
196196
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);
199200
packet_fflush(stdout);
200201
strvec_clear(&data.prefixes);
201202
strbuf_release(&data.buf);

ref-filter.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,8 +2128,9 @@ static int for_each_fullref_in_pattern(struct ref_filter *filter,
21282128
return for_each_fullref_in("", cb, cb_data);
21292129
}
21302130

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);
21332134
}
21342135

21352136
/*

refs.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,9 +1723,10 @@ static void find_longest_prefixes(struct string_list *out,
17231723
strbuf_release(&prefix);
17241724
}
17251725

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)
17291730
{
17301731
struct string_list prefixes = STRING_LIST_INIT_DUP;
17311732
struct string_list_item *prefix;
@@ -1740,7 +1741,7 @@ int for_each_fullref_in_prefixes(const char *namespace,
17401741

17411742
for_each_string_list_item(prefix, &prefixes) {
17421743
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);
17441745
if (ret)
17451746
break;
17461747
strbuf_setlen(&buf, namespace_len);

refs.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,10 @@ int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data);
354354
*
355355
* callers should be prepared to ignore references that they did not ask for.
356356
*/
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+
359361
/**
360362
* iterate refs from the respective area.
361363
*/

0 commit comments

Comments
 (0)