summaryrefslogtreecommitdiff
path: root/log-tree.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 /log-tree.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 'log-tree.c')
-rw-r--r--log-tree.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/log-tree.c b/log-tree.c
index 7d917f2a83..1729b0c201 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -147,9 +147,7 @@ static int ref_filter_match(const char *refname,
return 1;
}
-static int add_ref_decoration(const char *refname, const char *referent UNUSED, const struct object_id *oid,
- int flags UNUSED,
- void *cb_data)
+static int add_ref_decoration(const struct reference *ref, void *cb_data)
{
int i;
struct object *obj;
@@ -158,16 +156,16 @@ static int add_ref_decoration(const char *refname, const char *referent UNUSED,
struct decoration_filter *filter = (struct decoration_filter *)cb_data;
const char *git_replace_ref_base = ref_namespace[NAMESPACE_REPLACE].ref;
- if (filter && !ref_filter_match(refname, filter))
+ if (filter && !ref_filter_match(ref->name, filter))
return 0;
- if (starts_with(refname, git_replace_ref_base)) {
+ if (starts_with(ref->name, git_replace_ref_base)) {
struct object_id original_oid;
if (!replace_refs_enabled(the_repository))
return 0;
- if (get_oid_hex(refname + strlen(git_replace_ref_base),
+ if (get_oid_hex(ref->name + strlen(git_replace_ref_base),
&original_oid)) {
- warning("invalid replace ref %s", refname);
+ warning("invalid replace ref %s", ref->name);
return 0;
}
obj = parse_object(the_repository, &original_oid);
@@ -176,10 +174,10 @@ static int add_ref_decoration(const char *refname, const char *referent UNUSED,
return 0;
}
- objtype = odb_read_object_info(the_repository->objects, oid, NULL);
+ objtype = odb_read_object_info(the_repository->objects, ref->oid, NULL);
if (objtype < 0)
return 0;
- obj = lookup_object_by_type(the_repository, oid, objtype);
+ obj = lookup_object_by_type(the_repository, ref->oid, objtype);
for (i = 0; i < ARRAY_SIZE(ref_namespace); i++) {
struct ref_namespace_info *info = &ref_namespace[i];
@@ -187,24 +185,24 @@ static int add_ref_decoration(const char *refname, const char *referent UNUSED,
if (!info->decoration)
continue;
if (info->exact) {
- if (!strcmp(refname, info->ref)) {
+ if (!strcmp(ref->name, info->ref)) {
deco_type = info->decoration;
break;
}
- } else if (starts_with(refname, info->ref)) {
+ } else if (starts_with(ref->name, info->ref)) {
deco_type = info->decoration;
break;
}
}
- add_name_decoration(deco_type, refname, obj);
+ add_name_decoration(deco_type, ref->name, obj);
while (obj->type == OBJ_TAG) {
if (!obj->parsed)
parse_object(the_repository, &obj->oid);
obj = ((struct tag *)obj)->tagged;
if (!obj)
break;
- add_name_decoration(DECORATION_REF_TAG, refname, obj);
+ add_name_decoration(DECORATION_REF_TAG, ref->name, obj);
}
return 0;
}