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

Re: [PATCH 3/6] odb: add `source` field to struct object_info_source

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 30, 2026, 16:54 UTC
Message-ID
<xmqqv7b0rmt6.fsf@gitster.g>
In-Reply-To
<akOod6X1a2axIXKZ@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 36 quoted lines
> On Mon, Jun 29, 2026 at 01:47:41PM -0700, Junio C Hamano wrote:
>> Justin Tobler <jltobler@gmail.com> writes:
>> 
>> >> @@ -1424,6 +1424,10 @@ int packed_object_info_with_index_pos(struct odb_source_packed *source UNUSED,
>> >>  	oi->whence = OI_PACKED;
>> >>  
>> >>  	if (oi->sourcep) {
>> >> +		if (!source)
>> >> +			BUG("cannot request source without an owning source");
>> >> +		oi->sourcep->source = &source->base;
>> >
>> > And here it is set for the packed backend. Looks good.
>> >
>> > Naive question: I understand that some `packed_info_object()` callers
>> > may not have the `struct odb_source` on hand, but when the `struct
>> > packed_git` is intially setup, is it not always known the ODB source it
>> > comes from? It makes me wonder if the ODB source should also be recorded
>> > when `struct packed_git` is initialized.
>
> I've addressed this comment on patch 1.
>
>> As with your reaction to [PATCH 1/6], I do share this puzzlement: if
>> the source can almost always be NULL, what is it good for and isn't
>> it something that can be computed from the available information?
>
> It's not almost always NULL, even though it looks like this because we
> ended up adapting more callers to pass `NULL` than we adapted callers to
> pass an actual source. But in the end it's rather the opposite: there
> are very few low-level callers that don't have the source info
> available, and everyone else instead uses `odb_read_object_info()`,
> where we do have it available. But those callers don't need to be
> adjusted, so they weren't visible in the diff.
>
>> Perhaps it is the naming?
>
> Yeah, as Justin pointed out, calling this `sourcep` is confusing.
OK, everything makes sense.
Show 17 quoted lines
>> I am confused what the above quoted code actually is doing ("if you
>> have a source, then grab its base and set it to .source member of
>> the struct the out parameter points at", makes it sound like the out
>> parameter sourcep should be pointing at a structure with .base
>> member, not .source member, or perhaps the caller should be passing
>> &oi->sourcep->source as *base to be assigned to, or something).
>
> We have to return the generic source here, not the specialized source,
> so that this interface can be used by every implementation. Other sites
> would end up storing their own source, which of course would have a
> different specialized backend.
>
> So an alternative to write this would have been:
>
>     oi->sourcep->source = (struct odb_source *) source;
>
> But by assigning the base we avoid having to cast.
Yuck.

I guess it may be OK as the caller or whategver the caller calls later may have to downcast this pointer the usual way to access what we return here anyway. As a pointer to a struct object, when suitably converted, points to its first member, this upcast should always be safe. And taking the address of the .base member is far more explicit.

While it hides the fact that there is such an upcast involved, which might be confusing to readers not familiar with this corner of the codebase, I am fine with the way it was written.

Thanks.
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 12 of 26 in “odb: refactor source-specific information in object info”
  1. 0/6 odb: refactor source-specific information in object infoPatrick Steinhardt, Jun 24, 2026
  2. 1/6 packfile: thread odb_source_packed through packed_object_info()Patrick Steinhardt, Jun 24, 2026
  3. Justin ToblerJun 29, 2026
  4. Patrick SteinhardtJun 30, 2026
  5. 2/6 odb: make backend-specific fields optionalPatrick Steinhardt, Jun 24, 2026
  6. Justin ToblerJun 29, 2026
  7. Patrick SteinhardtJun 30, 2026
  8. 3/6 odb: add `source` field to struct object_info_sourcePatrick Steinhardt, Jun 24, 2026
  9. Justin ToblerJun 29, 2026
  10. Junio C HamanoJun 29, 2026
  11. Patrick SteinhardtJun 30, 2026
  12. Junio C HamanoJun 30, 2026
  13. 4/6 treewide: convert users of `whence` to the new source fieldPatrick Steinhardt, Jun 24, 2026
  14. Justin ToblerJun 29, 2026
  15. 5/6 odb: drop `whence` field from object infoPatrick Steinhardt, Jun 24, 2026
  16. Justin ToblerJun 29, 2026
  17. 6/6 odb: document object info fieldsPatrick Steinhardt, Jun 24, 2026
  18. Junio C HamanoJun 24, 2026
  19. 0/6 odb: refactor source-specific information in object infoPatrick Steinhardt, Jul 2, 2026
  20. 1/6 packfile: thread odb_source_packed through packed_object_info()Patrick Steinhardt, Jul 2, 2026
  21. 2/6 odb: make backend-specific fields optionalPatrick Steinhardt, Jul 2, 2026
  22. 3/6 odb: add `source` field to struct object_info_sourcePatrick Steinhardt, Jul 2, 2026
  23. 4/6 treewide: convert users of `whence` to the new source fieldPatrick Steinhardt, Jul 2, 2026
  24. 5/6 odb: drop `whence` field from object infoPatrick Steinhardt, Jul 2, 2026
  25. 6/6 odb: document object info fieldsPatrick Steinhardt, Jul 2, 2026
  26. Junio C HamanoJul 5, 2026

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.