ref-filter: simplify return type of match_points_at

We return the oid that matched, but the sole caller only cares whether we matched anything at all. This is mostly academic, since there's only one caller, but the lifetime of the returned pointer is not immediately clear. Sometimes it points to an oid in a tag struct, which should live forever. And sometimes to the oid passed in, which only lives as long as the each_ref_fn callback we're called from. Simplify this to a boolean return which is more direct and obvious. As a bonus, this lets us avoid the weird pattern of overwriting our "oid" parameter in the loop (since we now only refer to the tagged oid one time, and can just inline the call to get it). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jul 2, 2023 at 18:38 UTC d9e00621591549cd2d9989d290a7e0c63eadd03b
1 file changed +10 -9
ref-filter.c
+10 -9
@@ -2330,20 +2330,22 @@ static int for_each_fullref_in_pattern(struct ref_filter *filter,
2330 /*
2331 * Given a ref (oid, refname), check if the ref belongs to the array
2332 * of oids. If the given ref is a tag, check if the given tag points
2333 - * at one of the oids in the given oid array.
2333 + * at one of the oids in the given oid array. Returns non-zero if a
2334 + * match is found.
2335 + *
2336 * NEEDSWORK:
2337 * As the refs are cached we might know what refname peels to without
2338 * the need to parse the object via parse_object(). peel_ref() might be a
2339 * more efficient alternative to obtain the pointee.
2340 */
2339 -static const struct object_id *match_points_at(struct oid_array *points_at,
2340 - const struct object_id *oid,
2341 - const char *refname)
2341 +static int match_points_at(struct oid_array *points_at,
2342 + const struct object_id *oid,
2343 + const char *refname)
2344 {
2345 struct object *obj;
2346
2347 if (oid_array_lookup(points_at, oid) >= 0)
2346 - return oid;
2348 + return 1;
2349 obj = parse_object_with_flags(the_repository, oid,
2350 PARSE_OBJECT_SKIP_HASH_CHECK);
2351 while (obj && obj->type == OBJ_TAG) {
@@ -2354,15 +2356,14 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
2356 break;
2357 }
2358
2357 - oid = get_tagged_oid(tag);
2358 - if (oid_array_lookup(points_at, oid) >= 0)
2359 - return oid;
2359 + if (oid_array_lookup(points_at, get_tagged_oid(tag)) >= 0)
2360 + return 1;
2361
2362 obj = tag->tagged;
2363 }
2364 if (!obj)
2365 die(_("malformed object at '%s'"), refname);
2365 - return NULL;
2366 + return 0;
2367 }
2368
2369 /*