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
Justin Tobler <jltobler@gmail.com>
Date
Jun 29, 2026, 17:49 UTC
Message-ID
<akKtc4ybxFRVJmNv@denethor>
In-Reply-To
<20260624-b4-pks-odb-drop-whence-v1-3-8d1877b790ac@pks.im>
On 26/06/24 02:19PM, Patrick Steinhardt wrote:
Show 9 quoted lines
> The previous commit introduced `struct object_info_source` as an opt-in
> container for backend-specific information, but for now we only moved
> preexisting data into this structure. Most importantly, the caller has
> no way yet to learn about which source an object was actually looked up
> from. Instead, callers have to rely on the `whence` enum to distinguish
> the object type, but cannot use that enum to tell the object source.
> 
> Add a `struct odb_source *source` field to the structure and populate it
> from each backend's lookup path.
Makes sense.
Show 22 quoted lines
> The `whence` enum is still set and used by callers; it will be removed
> in a subsequent commit now that `sourcep->source` can identify the
> backend on its own.
> 
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  odb.h                 | 3 +++
>  odb/source-inmemory.c | 3 +++
>  odb/source-loose.c    | 2 ++
>  packfile.c            | 6 +++++-
>  4 files changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/odb.h b/odb.h
> index 770900289a..330a55879e 100644
> --- a/odb.h
> +++ b/odb.h
> @@ -253,6 +253,9 @@ int odb_pretend_object(struct object_database *odb,
>   * more about how exactly it is stored.
>   */
>  struct object_info_source {
> +	/* The source that this object has been looked up from. */
> +	struct odb_source *source;
Here we add the `struct odb_source` so we can begin recording it.
Show 14 quoted lines
> +
>  	/*
>  	 * Backend-specific information about the specific object. This can be
>  	 * used for example to uniquely identify a given object in case it
> diff --git a/odb/source-inmemory.c b/odb/source-inmemory.c
> index e004566d76..2328e62687 100644
> --- a/odb/source-inmemory.c
> +++ b/odb/source-inmemory.c
> @@ -52,6 +52,9 @@ static void populate_object_info(struct odb_source_inmemory *source,
>  		*oi->contentp = xmemdupz(object->buf, object->size);
>  	if (oi->mtimep)
>  		*oi->mtimep = 0;
> +	if (oi->sourcep)
> +		oi->sourcep->source = &source->base;
Here we set the source for the in-memory backend.
Show 14 quoted lines
> +
>  	oi->whence = OI_CACHED;
>  }
>  
> diff --git a/odb/source-loose.c b/odb/source-loose.c
> index 66e6bb8d3f..5c4e9892b5 100644
> --- a/odb/source-loose.c
> +++ b/odb/source-loose.c
> @@ -196,6 +196,8 @@ static int read_object_info_from_path(struct odb_source_loose *loose,
>  			oi->typep = NULL;
>  		if (oi->delta_base_oid)
>  			oidclr(oi->delta_base_oid, loose->base.odb->repo->hash_algo);
> +		if (oi->sourcep && !ret)
> +			oi->sourcep->source = &loose->base;
Here it is set for the loose backend.
Show 23 quoted lines
>  		if (!ret)
>  			oi->whence = OI_LOOSE;
>  	}
> diff --git a/packfile.c b/packfile.c
> index 688c410b35..fa22095b75 100644
> --- a/packfile.c
> +++ b/packfile.c
> @@ -1324,7 +1324,7 @@ static void add_delta_base_cache(struct packed_git *p, off_t base_offset,
>  	hashmap_add(&delta_base_cache, &ent->ent);
>  }
>  
> -int packed_object_info_with_index_pos(struct odb_source_packed *source UNUSED,
> +int packed_object_info_with_index_pos(struct odb_source_packed *source,
>  				      struct packed_git *p, off_t obj_offset,
>  				      uint32_t *maybe_index_pos, struct object_info *oi)
>  {
> @@ -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.

-Justin
Previous: Patrick SteinhardtNext: Junio C Hamano
Message 9 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.