Skip to content

Commit d9e0062

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

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

ref-filter.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,20 +2330,22 @@ static int for_each_fullref_in_pattern(struct ref_filter *filter,
23302330
/*
23312331
* Given a ref (oid, refname), check if the ref belongs to the array
23322332
* 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+
*
23342336
* NEEDSWORK:
23352337
* As the refs are cached we might know what refname peels to without
23362338
* the need to parse the object via parse_object(). peel_ref() might be a
23372339
* more efficient alternative to obtain the pointee.
23382340
*/
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)
23422344
{
23432345
struct object *obj;
23442346

23452347
if (oid_array_lookup(points_at, oid) >= 0)
2346-
return oid;
2348+
return 1;
23472349
obj = parse_object_with_flags(the_repository, oid,
23482350
PARSE_OBJECT_SKIP_HASH_CHECK);
23492351
while (obj && obj->type == OBJ_TAG) {
@@ -2354,15 +2356,14 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
23542356
break;
23552357
}
23562358

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;
23602361

23612362
obj = tag->tagged;
23622363
}
23632364
if (!obj)
23642365
die(_("malformed object at '%s'"), refname);
2365-
return NULL;
2366+
return 0;
23662367
}
23672368

23682369
/*

0 commit comments

Comments
 (0)