git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 1/3] refs: keep track of unresolved reference value in iterators

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 5, 2024, 15:40 UTC
Message-ID
<xmqqh6bz567d.fsf@gitster.g>
In-Reply-To
<ZrCwqqLKcwdOYclN@tanuki>
Patrick Steinhardt <ps@pks.im> writes:
Show 15 quoted lines
> On Thu, Aug 01, 2024 at 09:41:03AM -0700, Junio C Hamano wrote:
>> "John Cai via GitGitGadget" <gitgitgadget@gmail.com> writes:
>> > @@ -886,6 +889,9 @@ static int files_ref_iterator_advance(struct ref_iterator *ref_iterator)
>> >  		iter->base.refname = iter->iter0->refname;
>> >  		iter->base.oid = iter->iter0->oid;
>> >  		iter->base.flags = iter->iter0->flags;
>> > +		if (iter->iter0->flags & REF_ISSYMREF)
>> > +			iter->base.referent = iter->iter0->referent;
>> 
>> Presumably base.referent is initialized to NULL so this "if"
>> statement does not need an else clause?
>
> This function typically ends up being called in a loop though. So
> without the else clause, wouldn't we potentially leak the value of a
> preceding ref into subsequent iterations like this?

OK, so this does need to clear it when we tell the caller we have non SYMREF, as we do want to show NULL as base.referent to the caller in such a case. Thanks.

It does reinforce my larger point, which was:
Show 10 quoted lines
>> Makes me wonder if we should follow the same "ignore what the flag
>> says when filling the .referent member; if the ref is not a symref,
>> the referent variable is NULL, and if it is, referent is never NULL"
>> pattern?  Then ref->u.value.referent is _always_ defined---the
>> current code says "the u.value.referent member is undefined for ref
>> that is not a symref", but with the suggested change, it will be
>> "the u.value.referent member is NULL for ref that is not a symref,
>> and for a symref, it is the value of the symref".
>
> Yeah, I think that would be preferable indeed.

In other words, with .referent member introduced, checking for (.flags & REF_ISSYMREF) becomes a redundant&duplicated bit of information, as the bit should exactly match the non-NULL ness of the .referent member.

Thanks.
Previous: Patrick SteinhardtNext: John Cai via GitGitGadget
Message 25 of 44 in “keep track of unresolved value of symbolic-ref in ref iterators”
  1. 0/4 keep track of unresolved value of symbolic-ref in ref iteratorsJohn Cai via GitGitGadget, Jun 6, 2024
  2. 2/4 refs: keep track of unresolved reference value in iteratorsJohn Cai via GitGitGadget, Jun 6, 2024
  3. Jeff KingJun 11, 2024
  4. 1/4 refs: add referent parameter to refs_resolve_ref_unsafeJohn Cai via GitGitGadget, Jun 6, 2024
  5. Junio C HamanoJun 6, 2024
  6. Junio C HamanoJun 6, 2024
  7. John CaiJun 7, 2024
  8. Junio C HamanoJun 7, 2024
  9. Patrick SteinhardtJun 10, 2024
  10. Junio C HamanoJun 10, 2024
  11. John CaiJun 6, 2024
  12. Junio C HamanoJun 6, 2024
  13. Kristoffer HaugsbakkJun 28, 2024
  14. Junio C HamanoJun 28, 2024
  15. Linus ArverJun 30, 2024
  16. Junio C HamanoJun 30, 2024
  17. Jeff KingJun 11, 2024
  18. John CaiJul 30, 2024
  19. 4/4 ref-filter: populate symref from iteratorJohn Cai via GitGitGadget, Jun 6, 2024
  20. 3/4 refs: add referent to each_ref_fnJohn Cai via GitGitGadget, Jun 6, 2024
  21. 0/3 keep track of unresolved value of symbolic-ref in ref iteratorsJohn Cai via GitGitGadget, Aug 1, 2024
  22. 1/3 refs: keep track of unresolved reference value in iteratorsJohn Cai via GitGitGadget, Aug 1, 2024
  23. Junio C HamanoAug 1, 2024
  24. Patrick SteinhardtAug 5, 2024
  25. Junio C HamanoAug 5, 2024
  26. 3/3 ref-filter: populate symref from iteratorJohn Cai via GitGitGadget, Aug 1, 2024
  27. Junio C HamanoAug 1, 2024
  28. Junio C HamanoAug 1, 2024
  29. Junio C HamanoAug 1, 2024
  30. John CaiAug 6, 2024
  31. Junio C HamanoAug 6, 2024
  32. 2/3 refs: add referent to each_ref_fnJohn Cai via GitGitGadget, Aug 1, 2024
  33. 0/3 keep track of unresolved value of symbolic-ref in ref iteratorsJohn Cai via GitGitGadget, Aug 7, 2024
  34. 1/3 refs: keep track of unresolved reference value in iteratorsJohn Cai via GitGitGadget, Aug 7, 2024
  35. Junio C HamanoAug 7, 2024
  36. John CaiAug 8, 2024
  37. 2/3 refs: add referent to each_ref_fnJohn Cai via GitGitGadget, Aug 7, 2024
  38. 3/3 ref-filter: populate symref from iteratorJohn Cai via GitGitGadget, Aug 7, 2024
  39. 0/3 keep track of unresolved value of symbolic-ref in ref iteratorsJohn Cai via GitGitGadget, Aug 9, 2024
  40. 1/3 refs: keep track of unresolved reference value in iteratorsJohn Cai via GitGitGadget, Aug 9, 2024
  41. shejialuoNov 23, 2024
  42. 2/3 refs: add referent to each_ref_fnJohn Cai via GitGitGadget, Aug 9, 2024
  43. 3/3 ref-filter: populate symref from iteratorJohn Cai via GitGitGadget, Aug 9, 2024
  44. Junio C HamanoAug 9, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.