Skip to content

Commit 468887f

Browse files
jkloetzkegitster
authored andcommitted
ref-filter: handle nested tags in --points-at option
Tags are dereferenced until reaching a different object type to handle nested tags, e.g. on checkout. In contrast, "git tag --points-at=..." fails to list such nested tags because only one level of indirection is obtained in filter_refs(). Implement the recursive dereferencing for the "--points-at" option when filtering refs to unify the behaviour. Signed-off-by: Jan Klötzke <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5e23854 commit 468887f

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

ref-filter.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,29 +2332,27 @@ static int for_each_fullref_in_pattern(struct ref_filter *filter,
23322332
* of oids. If the given ref is a tag, check if the given tag points
23332333
* at one of the oids in the given oid array.
23342334
* NEEDSWORK:
2335-
* 1. Only a single level of indirection is obtained, we might want to
2336-
* change this to account for multiple levels (e.g. annotated tags
2337-
* pointing to annotated tags pointing to a commit.)
2338-
* 2. As the refs are cached we might know what refname peels to without
2335+
* As the refs are cached we might know what refname peels to without
23392336
* the need to parse the object via parse_object(). peel_ref() might be a
23402337
* more efficient alternative to obtain the pointee.
23412338
*/
23422339
static const struct object_id *match_points_at(struct oid_array *points_at,
23432340
const struct object_id *oid,
23442341
const char *refname)
23452342
{
2346-
const struct object_id *tagged_oid = NULL;
23472343
struct object *obj;
23482344

23492345
if (oid_array_lookup(points_at, oid) >= 0)
23502346
return oid;
23512347
obj = parse_object(the_repository, oid);
2348+
while (obj && obj->type == OBJ_TAG) {
2349+
oid = get_tagged_oid((struct tag *)obj);
2350+
if (oid_array_lookup(points_at, oid) >= 0)
2351+
return oid;
2352+
obj = parse_object(the_repository, oid);
2353+
}
23522354
if (!obj)
23532355
die(_("malformed object at '%s'"), refname);
2354-
if (obj->type == OBJ_TAG)
2355-
tagged_oid = get_tagged_oid((struct tag *)obj);
2356-
if (tagged_oid && oid_array_lookup(points_at, tagged_oid) >= 0)
2357-
return tagged_oid;
23582356
return NULL;
23592357
}
23602358

t/t6302-for-each-ref-filter.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ test_expect_success 'check signed tags with --points-at' '
4545
sed -e "s/Z$//" >expect <<-\EOF &&
4646
refs/heads/side Z
4747
refs/tags/annotated-tag four
48+
refs/tags/doubly-annotated-tag An annotated tag
49+
refs/tags/doubly-signed-tag A signed tag
4850
refs/tags/four Z
4951
refs/tags/signed-tag four
5052
EOF

0 commit comments

Comments
 (0)