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

Re: [PATCH 1/9] odb: compute compat object ID in `odb_write_object_ext()`

From
Justin Tobler <jltobler@gmail.com>
Date
Jul 28, 2026, 22:02 UTC
Message-ID
<amkk_0C8joQKH43M@denethor>
In-Reply-To
<20260717-pks-odb-move-loose-object-writing-v1-1-46446a3cb5b7@pks.im>
On 26/07/17 11:32AM, Patrick Steinhardt wrote:
Show 6 quoted lines
> Repositories can have a compatibility hash configured, which means that
> such a repository is expected to maintain a mapping between canonical
> and compatibility object hashes. Maintaining this mapping is the
> responsibility of the object database sources, where we either store
> them as part of the loose objects map or in packfile indices v3 (once we
> gain support for this feature).

Makes sense. Each ODB source should be responsible to tracking how an objects maps from one hash to another for compatibility.

Show 6 quoted lines
> But besides storing these compatibility hashes, the sources are also
> responsible for generating the compatibility hash in the first place.
> This is somewhat unnecessary though, as the compatibility hash should be
> computed the same no matter which source is being used. The consequence
> is that we need to duplicate this functionality across the different
> backends, which does not make a lot of sense.

Agreed, there is no need to duplicate logic as the hashes that get generated should be the same regardless of the backend.

Show 49 quoted lines
> Refactor the code so that we instead compute the compatibility hash in
> `odb_write_object_ext()` and then pass the computed value to the
> sources. No callers need adjustment as there are none that write objects
> via the source interfaces directly.
> 
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  odb.c                 | 26 ++++++++++++++++++++++++--
>  odb.h                 | 10 ++++++----
>  odb/source-files.c    |  2 +-
>  odb/source-inmemory.c |  2 +-
>  odb/source-loose.c    | 24 +++---------------------
>  odb/source-packed.c   |  2 +-
>  odb/source.h          |  4 ++--
>  7 files changed, 38 insertions(+), 32 deletions(-)
> 
> diff --git a/odb.c b/odb.c
> index cf6e7938c0..1d6538163b 100644
> --- a/odb.c
> +++ b/odb.c
> @@ -989,11 +989,33 @@ int odb_write_object_ext(struct object_database *odb,
>  			 const void *buf, unsigned long len,
>  			 enum object_type type,
>  			 struct object_id *oid,
> -			 struct object_id *compat_oid,
> +			 const struct object_id *compat_oid_in,
>  			 enum odb_write_object_flags flags)
>  {
> +	const struct git_hash_algo *compat = odb->repo->compat_hash_algo;
> +	struct object_id compat_oid, *compat_oid_p = NULL;
> +
> +	if (compat) {
> +		const struct git_hash_algo *algo = odb->repo->hash_algo;
> +
> +		if (compat_oid_in) {
> +			oidcpy(&compat_oid, compat_oid_in);
> +		} else if (type == OBJ_BLOB) {
> +			hash_object_file(compat, buf, len, type, &compat_oid);
> +		} else {
> +			struct strbuf converted = STRBUF_INIT;
> +			convert_object_file(odb->repo, &converted, algo, compat,
> +					    buf, len, type, 0);
> +			hash_object_file(compat, converted.buf, converted.len,
> +					 type, &compat_oid);
> +			strbuf_release(&converted);
> +		}
> +
> +		compat_oid_p = &compat_oid;
> +	}

Here we lift up the logic to gnerate the compat hash out of the backend and into `odb_write_object_ext()` so the resulting hash can be wired to the ODB source callback to write the object. The logic itself is the same and looks good.

The rest of this patch is mainly just updating the callsites accordingly and also looks good.

-Justin
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 3 of 17 in “object-file: move writing of loose objects into "loose" source”
  1. 0/9 object-file: move writing of loose objects into "loose" sourcePatrick Steinhardt, Jul 17, 2026
  2. 1/9 odb: compute compat object ID in `odb_write_object_ext()`Patrick Steinhardt, Jul 17, 2026
  3. Justin ToblerJul 28, 2026
  4. 2/9 t/u-odb-inmemory: implement wrapper for writing objectsPatrick Steinhardt, Jul 17, 2026
  5. Justin ToblerJul 28, 2026
  6. 3/9 odb: compute object hash in `odb_write_object_ext()`Patrick Steinhardt, Jul 17, 2026
  7. 4/9 odb: lift object existence check out of the "loose" backendPatrick Steinhardt, Jul 17, 2026
  8. Toon ClaesJul 22, 2026
  9. 5/9 odb: support setting mtime when writing objectsPatrick Steinhardt, Jul 17, 2026
  10. 6/9 object-file: fix memory leak in `force_object_loose()`Patrick Steinhardt, Jul 17, 2026
  11. 7/9 object-file: force objects loose via generic interfacePatrick Steinhardt, Jul 17, 2026
  12. 8/9 object-file: move `force_object_loose()`Patrick Steinhardt, Jul 17, 2026
  13. 9/9 object-file: move logic to write loose objectsPatrick Steinhardt, Jul 17, 2026
  14. Toon ClaesJul 22, 2026
  15. SZEDER GáborJul 18, 2026
  16. Junio C HamanoJul 19, 2026
  17. Junio C HamanoJul 19, 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.