Skip to content

Commit 5929e66

Browse files
committed
Merge branch 'jk/nested-points-at'
"git tag --list --points-at X" showed tags that directly refers to object X, but did not list a tag that points at such a tag, which has been corrected. * jk/nested-points-at: ref-filter: simplify return type of match_points_at ref-filter: avoid parsing non-tags in match_points_at() ref-filter: avoid parsing tagged objects in match_points_at() ref-filter: handle nested tags in --points-at option
2 parents 02f50d0 + d9e0062 commit 5929e66

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

ref-filter.c

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,32 +2344,40 @@ static int for_each_fullref_in_pattern(struct ref_filter *filter,
23442344
/*
23452345
* Given a ref (oid, refname), check if the ref belongs to the array
23462346
* of oids. If the given ref is a tag, check if the given tag points
2347-
* at one of the oids in the given oid array.
2347+
* at one of the oids in the given oid array. Returns non-zero if a
2348+
* match is found.
2349+
*
23482350
* NEEDSWORK:
2349-
* 1. Only a single level of indirection is obtained, we might want to
2350-
* change this to account for multiple levels (e.g. annotated tags
2351-
* pointing to annotated tags pointing to a commit.)
2352-
* 2. As the refs are cached we might know what refname peels to without
2351+
* As the refs are cached we might know what refname peels to without
23532352
* the need to parse the object via parse_object(). peel_ref() might be a
23542353
* more efficient alternative to obtain the pointee.
23552354
*/
2356-
static const struct object_id *match_points_at(struct oid_array *points_at,
2357-
const struct object_id *oid,
2358-
const char *refname)
2355+
static int match_points_at(struct oid_array *points_at,
2356+
const struct object_id *oid,
2357+
const char *refname)
23592358
{
2360-
const struct object_id *tagged_oid = NULL;
23612359
struct object *obj;
23622360

23632361
if (oid_array_lookup(points_at, oid) >= 0)
2364-
return oid;
2365-
obj = parse_object(the_repository, oid);
2362+
return 1;
2363+
obj = parse_object_with_flags(the_repository, oid,
2364+
PARSE_OBJECT_SKIP_HASH_CHECK);
2365+
while (obj && obj->type == OBJ_TAG) {
2366+
struct tag *tag = (struct tag *)obj;
2367+
2368+
if (parse_tag(tag) < 0) {
2369+
obj = NULL;
2370+
break;
2371+
}
2372+
2373+
if (oid_array_lookup(points_at, get_tagged_oid(tag)) >= 0)
2374+
return 1;
2375+
2376+
obj = tag->tagged;
2377+
}
23662378
if (!obj)
23672379
die(_("malformed object at '%s'"), refname);
2368-
if (obj->type == OBJ_TAG)
2369-
tagged_oid = get_tagged_oid((struct tag *)obj);
2370-
if (tagged_oid && oid_array_lookup(points_at, tagged_oid) >= 0)
2371-
return tagged_oid;
2372-
return NULL;
2380+
return 0;
23732381
}
23742382

23752383
/*

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)