From: John Cai <johncai86@gmail.com>
To: Jeff King <peff@peff.net>
Cc: "John Cai via GitGitGadget" <gitgitgadget@gmail.com>,
git@vger.kernel.org, "Phillip Wood" <phillip.wood123@gmail.com>,
"Junio C Hamano" <gitster@pobox.com>,
"Kristoffer Haugsbakk" <code@khaugsbakk.name>,
"Patrick Steinhardt" <ps@pks.im>,
"Jean-Noël Avila" <avila.jn@gmail.com>
Subject: Re: [PATCH 1/4] refs: add referent parameter to refs_resolve_ref_unsafe
Date: Tue, 30 Jul 2024 10:38:52 -0400 [thread overview]
Message-ID: <45124B2F-BDE0-404A-BA85-54361F5877DF@gmail.com> (raw)
In-Reply-To: <20240611085058.GJ3248245@coredump.intra.peff.net>
Hey Peff,
On 11 Jun 2024, at 4:50, Jeff King wrote:
> On Thu, Jun 06, 2024 at 05:26:37PM +0000, John Cai via GitGitGadget wrote:
>
>> From: John Cai <johncai86@gmail.com>
>>
>> refs_resolve_ref_unsafe retrieves the referent, the unresolved value of
>> a reference. Add a parameter to allow refs_resolve_ref_unsafe to pass up
>> the value of referent to the caller so it can save this value in ref
>> iterators for more efficient access.
>
> This commit message left me with a lot of questions.
>
> For one, it wasn't immediately obvious to me what a "referent" is. ;) I
> think an example could help. If I understand, you mean that if you have
> a situation like:
>
> - refs/heads/one is a symref pointing to refs/heads/two
> - refs/heads/two is a regular ref
>
> and we resolve "one", then "two" is the referent? And the caller might
> want to know that?
>
> But I think we already pass that out as the return value from
> refs_resolve_ref_unsafe(). That is how something like "rev-parse
> --symbolic-full-name" works now.
Yes, exactly. I think you're right that it'd be preferable to just use the
output of refs_resolve_ref_unsafe() to get the value of the referent.
>
> But there are some subtleties. In a chain of symbolic refs (say, "two"
> is a symbolic ref to "three"), we return only the final name ("three").
> And you might want to know about "two".
>
> You can pass RESOLVE_REF_NO_RECURSE to inhibit this, and get back just
> "two". You can see that now with "git symbolic-ref --no-recurse". The
> downside is that we never look at the referent at all, so you get only
> the symref value (and no information about the actual oid, or if the
> referent even exists). You would still get an oid for any non-symrefs
> you examine.
>
> So reading between the lines, you have a caller in mind which wants to
> know the immediate referent in addition to the final recursive oid?
The goal is to keep track of the value that %(symref) would need in the
iterator so that a separate call doesn't need to be made.
>
> Looking at the rest of your series, I guess that caller is the one in
> loose_fill_ref_dir_regular_file(), so that it can get passed to the
> for-each-ref callback. But why is it right thing for it to record and
> pass along the immediate referent there, and not the final one? For that
> matter, would a caller ever want to see the whole chain of
> one/two/three?
Right, the final referent is the right one to pass down.
>
>> @@ -1761,6 +1761,7 @@ int refs_read_symbolic_ref(struct ref_store *ref_store, const char *refname,
>>
>> const char *refs_resolve_ref_unsafe(struct ref_store *refs,
>> const char *refname,
>> + const char *referent,
>> int resolve_flags,
>> struct object_id *oid,
>> int *flags)
>
> Unless I am misunderstanding the purpose of your patch completely, this
> "referent" is meant to be an out-parameter, right? In which case,
> shouldn't it be "const char **referent"?
>
> As the code is now:
>
>> @@ -1822,6 +1823,9 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
>> }
>>
>> *flags |= read_flags;
>> + if (referent && (read_flags & REF_ISSYMREF) &&
>> + sb_refname.len > 0)
>> + referent = sb_refname.buf;
>>
>> if (!(read_flags & REF_ISSYMREF)) {
>> if (*flags & REF_BAD_NAME) {
>
> ...we'd assign the local "referent" pointer to our refname buf, but
> the caller would never see that. Plus doing so would not help you
> anyway, since sb_refname will be used again as we recurse. So at best,
> you end up with the final name in the chain anyway. Or at worst,
> sb_refname gets reallocated and "referent" is left as a dangling
> pointer.
Going to include changes to remove the out-parameter which will simplify things
quite a bit.
>
> -Peff
thanks for the review!
John
next prev parent reply other threads:[~2024-07-30 14:38 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-06 17:26 [PATCH 0/4] keep track of unresolved value of symbolic-ref in ref iterators John Cai via GitGitGadget
2024-06-06 17:26 ` [PATCH 1/4] refs: add referent parameter to refs_resolve_ref_unsafe John Cai via GitGitGadget
2024-06-06 18:21 ` Junio C Hamano
2024-06-06 18:23 ` Junio C Hamano
2024-06-07 13:43 ` John Cai
2024-06-07 15:21 ` Junio C Hamano
2024-06-10 7:29 ` Patrick Steinhardt
2024-06-10 18:09 ` Junio C Hamano
2024-06-06 21:02 ` John Cai
2024-06-06 22:44 ` Junio C Hamano
2024-06-28 15:30 ` Kristoffer Haugsbakk
2024-06-28 19:47 ` Junio C Hamano
2024-06-30 10:12 ` Linus Arver
2024-06-30 18:19 ` Junio C Hamano
2024-06-11 8:50 ` Jeff King
2024-07-30 14:38 ` John Cai [this message]
2024-06-06 17:26 ` [PATCH 2/4] refs: keep track of unresolved reference value in iterators John Cai via GitGitGadget
2024-06-11 9:01 ` Jeff King
2024-06-06 17:26 ` [PATCH 3/4] refs: add referent to each_ref_fn John Cai via GitGitGadget
2024-06-06 17:26 ` [PATCH 4/4] ref-filter: populate symref from iterator John Cai via GitGitGadget
2024-08-01 14:58 ` [PATCH v2 0/3] keep track of unresolved value of symbolic-ref in ref iterators John Cai via GitGitGadget
2024-08-01 14:58 ` [PATCH v2 1/3] refs: keep track of unresolved reference value in iterators John Cai via GitGitGadget
2024-08-01 16:41 ` Junio C Hamano
2024-08-05 10:59 ` Patrick Steinhardt
2024-08-05 15:40 ` Junio C Hamano
2024-08-01 14:58 ` [PATCH v2 2/3] refs: add referent to each_ref_fn John Cai via GitGitGadget
2024-08-01 14:58 ` [PATCH v2 3/3] ref-filter: populate symref from iterator John Cai via GitGitGadget
2024-08-01 16:43 ` Junio C Hamano
2024-08-01 16:51 ` Junio C Hamano
2024-08-01 16:54 ` Junio C Hamano
2024-08-06 19:49 ` John Cai
2024-08-06 20:17 ` Junio C Hamano
2024-08-07 19:42 ` [PATCH v3 0/3] keep track of unresolved value of symbolic-ref in ref iterators John Cai via GitGitGadget
2024-08-07 19:42 ` [PATCH v3 1/3] refs: keep track of unresolved reference value in iterators John Cai via GitGitGadget
2024-08-07 21:40 ` Junio C Hamano
2024-08-08 18:09 ` John Cai
2024-08-07 19:42 ` [PATCH v3 2/3] refs: add referent to each_ref_fn John Cai via GitGitGadget
2024-08-07 19:42 ` [PATCH v3 3/3] ref-filter: populate symref from iterator John Cai via GitGitGadget
2024-08-09 15:37 ` [PATCH v4 0/3] keep track of unresolved value of symbolic-ref in ref iterators John Cai via GitGitGadget
2024-08-09 15:37 ` [PATCH v4 1/3] refs: keep track of unresolved reference value in iterators John Cai via GitGitGadget
2024-11-23 8:24 ` shejialuo
2024-08-09 15:37 ` [PATCH v4 2/3] refs: add referent to each_ref_fn John Cai via GitGitGadget
2024-08-09 15:37 ` [PATCH v4 3/3] ref-filter: populate symref from iterator John Cai via GitGitGadget
2024-08-09 16:51 ` [PATCH v4 0/3] keep track of unresolved value of symbolic-ref in ref iterators 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=45124B2F-BDE0-404A-BA85-54361F5877DF@gmail.com \
--to=johncai86@gmail.com \
--cc=avila.jn@gmail.com \
--cc=code@khaugsbakk.name \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
--cc=phillip.wood123@gmail.com \
--cc=ps@pks.im \
/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).