summaryrefslogtreecommitdiff
path: root/http-backend.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-10-23 09:16:10 +0200
committerJunio C Hamano <gitster@pobox.com>2025-11-04 07:32:24 -0800
commitbdbebe5714b25dc9d215b48efbb80f410925d7dd (patch)
tree4717bd456f36f6927c4c9aa31fdc0bea1c29c709 /http-backend.c
parentf2bf477c7e05ebc9541c708d11b616bf1a2a9105 (diff)
refs: introduce wrapper struct for `each_ref_fn`
The `each_ref_fn` callback function type is used across our code base for several different functions that iterate through reference. There's a bunch of callbacks implementing this type, which makes any changes to the callback signature extremely noisy. An example of the required churn is e8207717f1 (refs: add referent to each_ref_fn, 2024-08-09): adding a single argument required us to change 48 files. It was already proposed back then [1] that we might want to introduce a wrapper structure to alleviate the pain going forward. While this of course requires the same kind of global refactoring as just introducing a new parameter, it at least allows us to more change the callback type afterwards by just extending the wrapper structure. One counterargument to this refactoring is that it makes the structure more opaque. While it is obvious which callsites need to be fixed up when we change the function type, it's not obvious anymore once we use a structure. That being said, we only have a handful of sites that actually need to populate this wrapper structure: our ref backends, "refs/iterator.c" as well as very few sites that invoke the iterator callback functions directly. Introduce this wrapper structure so that we can adapt the iterator interfaces more readily. [1]: <ZmarVcF5JjsZx0dl@tanuki> Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'http-backend.c')
-rw-r--r--http-backend.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/http-backend.c b/http-backend.c
index 9084058f1e..92e1733f14 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -513,18 +513,17 @@ static void run_service(const char **argv, int buffer_input)
exit(1);
}
-static int show_text_ref(const char *name, const char *referent UNUSED, const struct object_id *oid,
- int flag UNUSED, void *cb_data)
+static int show_text_ref(const struct reference *ref, void *cb_data)
{
- const char *name_nons = strip_namespace(name);
+ const char *name_nons = strip_namespace(ref->name);
struct strbuf *buf = cb_data;
- struct object *o = parse_object(the_repository, oid);
+ struct object *o = parse_object(the_repository, ref->oid);
if (!o)
return 0;
- strbuf_addf(buf, "%s\t%s\n", oid_to_hex(oid), name_nons);
+ strbuf_addf(buf, "%s\t%s\n", oid_to_hex(ref->oid), name_nons);
if (o->type == OBJ_TAG) {
- o = deref_tag(the_repository, o, name, 0);
+ o = deref_tag(the_repository, o, ref->name, 0);
if (!o)
return 0;
strbuf_addf(buf, "%s\t%s^{}\n", oid_to_hex(&o->oid),
@@ -569,21 +568,20 @@ static void get_info_refs(struct strbuf *hdr, char *arg UNUSED)
strbuf_release(&buf);
}
-static int show_head_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
- int flag, void *cb_data)
+static int show_head_ref(const struct reference *ref, void *cb_data)
{
struct strbuf *buf = cb_data;
- if (flag & REF_ISSYMREF) {
+ if (ref->flags & REF_ISSYMREF) {
const char *target = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
- refname,
+ ref->name,
RESOLVE_REF_READING,
NULL, NULL);
if (target)
strbuf_addf(buf, "ref: %s\n", strip_namespace(target));
} else {
- strbuf_addf(buf, "%s\n", oid_to_hex(oid));
+ strbuf_addf(buf, "%s\n", oid_to_hex(ref->oid));
}
return 0;