git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: "Jeff King" <peff@peff.net>, "Jan Klötzke" <jan@kloetzke.net>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
	Steve Kemp <steve@steve.org.uk>,
	Stefan Beller <stefanbeller@gmail.com>
Subject: Re: [PATCH] ref-filter: handle nested tags in --points-at option
Date: Sun, 2 Jul 2023 18:25:13 +0200	[thread overview]
Message-ID: <df912fc4-601b-4d43-c6e4-aa5f74ec031f@web.de> (raw)
In-Reply-To: <20230702125611.GA1036686@coredump.intra.peff.net>

Am 02.07.23 um 14:56 schrieb Jeff King:
> On Sat, Jul 01, 2023 at 10:57:02PM +0200, Jan Klötzke wrote:
>
>> @@ -2222,18 +2219,19 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
>>  					       const struct object_id *oid,
>>  					       const char *refname)
>>  {
>> -	const struct object_id *tagged_oid = NULL;
>>  	struct object *obj;
>>
>>  	if (oid_array_lookup(points_at, oid) >= 0)
>>  		return oid;
>>  	obj = parse_object(the_repository, oid);
>> +	while (obj && obj->type == OBJ_TAG) {
>> +		oid = get_tagged_oid((struct tag *)obj);
>> +		if (oid_array_lookup(points_at, oid) >= 0)
>> +			return oid;
>> +		obj = parse_object(the_repository, oid);
>> +	}
>
> OK, so we are doing the usual peeling loop here. I wondered if we might
> be able to use peel_object(), but it again suffers from the "peel all
> the way" syndrome. So we have to loop ourselves so that we can check at
> each level. Good.
>
>>  	if (!obj)
>>  		die(_("malformed object at '%s'"), refname);
>
> This will now trigger if refname points to a broken object, or if its
> tag does. I think the resulting message is OK in either case (and
> presumably lower level code would produce extra error messages, too).
>
>> -	if (obj->type == OBJ_TAG)
>> -		tagged_oid = get_tagged_oid((struct tag *)obj);
>> -	if (tagged_oid && oid_array_lookup(points_at, tagged_oid) >= 0)
>> -		return tagged_oid;
>
> This code is moved into the loop body, but your version there drops the
> "if (tagged_oid)" check. I think that is OK (and even preferable),
> though. In get_tagged_oid() we will die() if the tagged object is NULL
> (though even before switching to that function this check was
> questionable, because it is "tag->tagged" that may be NULL, and we were
> dereferencing that unconditionally).

The check is necessary in the current code because tagged_oid is NULL if
obj is not a tag.  The new code no longer needs it.

> So the code looks good.

I agree.

René

  reply	other threads:[~2023-07-02 16:25 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-01 20:57 [PATCH] ref-filter: handle nested tags in --points-at option Jan Klötzke
2023-07-02 12:56 ` Jeff King
2023-07-02 16:25   ` René Scharfe [this message]
2023-07-02 20:27     ` Jeff King
2023-07-02 22:02   ` Jeff King
2023-07-02 22:33     ` [PATCH 0/3] a few --points-at optimizations/cleanups Jeff King
2023-07-02 22:35       ` [PATCH 1/3] ref-filter: avoid parsing tagged objects in match_points_at() Jeff King
2023-07-02 22:37       ` [PATCH 2/3] ref-filter: avoid parsing non-tags " Jeff King
2023-07-02 22:38       ` [PATCH 3/3] ref-filter: simplify return type of match_points_at Jeff King
2023-07-03 20:25     ` [PATCH] ref-filter: handle nested tags in --points-at option Jan Klötzke
2023-07-05  6:10   ` Junio C Hamano
2023-07-05 12:41     ` Jeff King
2023-07-05 17:16       ` Junio C Hamano
2023-07-05 18:50         ` Jan Klötzke
2023-07-05 20:15           ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=df912fc4-601b-4d43-c6e4-aa5f74ec031f@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jan@kloetzke.net \
    --cc=peff@peff.net \
    --cc=stefanbeller@gmail.com \
    --cc=steve@steve.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).