Git development
 help / color / mirror / Atom feed
From: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
To: Christian Couder <christian.couder@gmail.com>, git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
	"brian m . carlson" <sandals@crustytoothpaste.net>,
	Patrick Steinhardt <ps@pks.im>, Elijah Newren <newren@gmail.com>,
	Jeff King <peff@peff.net>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCH v2 04/13] odb: implement interoperability functions
Date: Thu, 26 Nov 2026 21:00:49 +0530	[thread overview]
Message-ID: <178121e9-dd6a-4193-9f3b-d81754a6d448@gmail.com> (raw)
In-Reply-To: <20261023072559.3204273-5-christian.couder@gmail.com>

I noticed a few issues in this patch which I'm sharing here.

On 10/23/26 12:55, Christian Couder wrote:
 >
> diff --git a/odb.h b/odb.h
> index 0ccc47ee73..70af2c7c78 100644
> --- a/odb.h
> +++ b/odb.h
> @@ -2,6 +2,7 @@
>   #define ODB_H
>   
>   #include "hashmap.h"
> +#include "loose.h"

This looks weird. I suppose this is creating a dependency on the 
specific loose backend just to pull in the value of OBJ_MAP_WRITE. It 
doesn't seem sensible to me.

> [... snip ...]
> +
> +enum odb_write_oid_map_flags {
> +	/*
> +	 * Serialize this data to disk instead of persisting it only in memory.
> +	 */
> +	ODB_WRITE_OID_MAP_WRITE = OBJ_MAP_WRITE,
> +};
> +

Could we turn this into something like:

   ODB_WRITE_OID_MAP_WRITE = (1 << 0).

... and make loose backend derive its value from this one as it needs?

> diff --git a/odb/source-files.c b/odb/source-files.c
> index 455f409db0..4f4f7f1f87 100644
> --- a/odb/source-files.c
> +++ b/odb/source-files.c
> @@ -6,6 +6,7 @@
>   #include "gettext.h"
>   #include "hex.h"
>   #include "lockfile.h"
> +#include "loose.h"

I guess this is not necessary actually. <Can we drop it?

>   #include "object-file.h"
>   #include "odb.h"
>   #include "odb/source.h"
> @@ -1234,6 +1235,41 @@ struct odb_files_dir *odb_source_files_find_dir(struct object_database *odb, con
>   	return dir;
>   }
>   
> +static int odb_source_files_map_oid(struct odb_source *source,
> +				    const struct object_id *src,
> +				    const struct git_hash_algo *to,
> +				    struct object_id *dest,
> +				    enum odb_map_oid_flags flags)
> +{
> +	struct odb_source_files *files = odb_source_files_downcast(source);
> +
> +	for (struct odb_files_dir *dir = files->dirs; dir; dir = dir->next) {
> +		int ret;
> +
> +		ret = odb_source_map_oid(&dir->loose->base, src, to, dest, flags);
> +		if (ret != -1)
> +			return ret;
> +		ret = odb_source_map_oid(&dir->packed->base, src, to, dest, flags);
> +		if (ret != -1)
> +			return ret;
> +		ret = odb_source_map_oid(&dir->loose->base, src, to, dest,
> +					 flags | ODB_MAP_OID_RELOAD);

This reloading the map per directory seems like a change in behaviour 
when we take the next patch into account. Previously, we reloaded after 
looking up every directory once. Is this change intentional?

Also, there's another problem. If the caller passes ODB_MAP_OID_RELOAD 
themsevles, the first loose lookup reloads, and then the third reloads 
again.

> +		if (ret != -1)
> +			return ret;
> +	}
> +
> +	return -1;
> +}
> +
> +static inline int odb_source_files_write_oid_map(struct odb_source *source,
> +						 const struct object_id *oid,
> +						 const struct object_id *compat_oid,
> +						 enum odb_write_oid_map_flags flags)
> +{

Nit: static inline does nothing on a function whose only use is having 
its address stored in a vtable. That applies to the files, loose and 
packed write callbacks. The map callbacks right next to them are plain 
static, so make these match.

> diff --git a/odb/source-packed.c b/odb/source-packed.c
> index 2226fbd313..ee1edfdb2b 100644
> --- a/odb/source-packed.c
> +++ b/odb/source-packed.c
> @@ -863,6 +863,23 @@ static void odb_source_packed_close(struct odb_source *source)
>   	packed->midx = NULL;
>   }
>   
> +static int odb_source_packed_map_oid(struct odb_source *source UNUSED,
> +				     const struct object_id *src UNUSED,
> +				     const struct git_hash_algo *to UNUSED,
> +				     struct object_id *dest UNUSED,
> +				     enum odb_map_oid_flags flags UNUSED)
> +{
> +	return -1;
> +}
> +
> +static inline int odb_source_packed_write_oid_map(struct odb_source *source UNUSED,
> +						  const struct object_id *oid UNUSED,
> +						  const struct object_id *compat_oid UNUSED,
> +						  enum odb_write_oid_map_flags flags UNUSED)
> +{
> +	return -1;

The commit message says packed sources "don't write any information", 
meaning the write is deliberately a no-op. Returning -1 means "error" by 
the contract in odb/source.h. Nothing reaches it today, because the 
files backend only writes to the loose source. Still, it should either 
return 0 or carry a BUG()/comment saying it must not be called.

> diff --git a/odb/source.h b/odb/source.h
> index 1867347dfc..e1f01359ce 100644
> --- a/odb/source.h
> +++ b/odb/source.h
> @@ -300,6 +300,42 @@ struct odb_source {
>   	 */
>   	int (*fsck)(struct odb_source *source,
>   		    struct odb_fsck_options *options);
> +
> +	/*
> +	 * This callback is expected to provide the mapping of an object from
> +	 * the algorithm specified in src to the algorithm specified in to,
> +	 * leaving the result in dest.  flags is a combination of `enum
> +	 * odb_map_oid_flags` values: with ODB_MAP_OID_RELOAD, the source should
> +	 * reload its mapping data before the lookup, as another process may
> +	 * have written new mappings in the meantime.
> +	 *
> +	 * The algo field in src must point to a valid algorithm (specifically,
> +	 * it must not be zero).  to must likewise point to a valid algorithm;
> +	 * it must be non-NULL.
> +	 *

Nit: algo is an index, not a pointer. "must be set to a valid algorithm" 
would be accurate.

> +	 * The callback is expected to return 0 on success, -1 if the object is
> +	 * not found, and a different negative error code on error.
> +	 */
> +	int (*map_oid)(struct odb_source *source, const struct object_id *src,
> +		       const struct git_hash_algo *to, struct object_id *dest,
> +		       enum odb_map_oid_flags flags);
> +
 > [ ... snip ... ]
 >
> +static inline int odb_source_map_oid(struct odb_source *source,
> +				    const struct object_id *src,
> +				    const struct git_hash_algo *to,
> +				    struct object_id *dest,
> +				    int flags)> +
> ... 
> +static inline int odb_source_write_oid_map(struct odb_source *source,
> +					   const struct object_id *oid,
> +					   const struct object_id *compat_oid,
> +					   int flags)

Nit: both new wrappers in odb/source.h take int flags. The callbacks 
they call take the enum, and so does every other wrapper in that file, 
like count_objects and write_object. Use the enum types here too.

-- 
Sivaraam


  reply	other threads:[~2026-11-26 15:30 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-23  7:25 [PATCH v2 00/13] SHA-1/SHA-256 interoperability, part 3: pack index v3 Christian Couder
2026-10-23  7:25 ` [PATCH v2 01/13] loose: allow looking up in object map with source Christian Couder
2026-11-26 13:28   ` Kaartic Sivaraam
2026-10-23  7:25 ` [PATCH v2 02/13] loose: rename repo_add_loose_object_map Christian Couder
2026-11-26 13:35   ` Kaartic Sivaraam
2026-10-23  7:25 ` [PATCH v2 03/13] loose: add a flag to control whether we write mapped OIDs Christian Couder
2026-11-26 13:57   ` Kaartic Sivaraam
2026-11-26 22:18     ` brian m. carlson
2026-10-23  7:25 ` [PATCH v2 04/13] odb: implement interoperability functions Christian Couder
2026-11-26 15:30   ` Kaartic Sivaraam [this message]
2026-10-23  7:25 ` [PATCH v2 05/13] object-file-convert: implement mapping in terms of object DB Christian Couder
2026-11-26 15:37   ` Kaartic Sivaraam
2026-10-23  7:25 ` [PATCH v2 06/13] pack-write: add support for pack index v3 Christian Couder
2026-11-30 16:05   ` Kaartic Sivaraam
2026-10-23  7:25 ` [PATCH v2 07/13] builtin: populate pack index v3 fields when indexing Christian Couder
2026-11-26 21:47   ` Junio C Hamano
2026-11-26 22:27     ` brian m. carlson
2026-11-26 22:58       ` Junio C Hamano
2026-10-23  7:25 ` [PATCH v2 08/13] object-file: handle compatibility algorithm Christian Couder
2026-10-23  7:25 ` [PATCH v2 09/13] packfile: add support for reading pack index v3 Christian Couder
2026-10-23  7:25 ` [PATCH v2 10/13] packfile: validate pack index v3 tables Christian Couder
2026-10-23  7:25 ` [PATCH v2 11/13] loose: map object IDs using pack index v3 Christian Couder
2026-10-23  7:25 ` [PATCH v2 12/13] packfile: allow looking up compat object IDs in packs Christian Couder
2026-10-23  7:25 ` [PATCH v2 13/13] doc: move pack index v3 documentation Christian Couder
2026-10-23 12:43 ` [PATCH v2 00/13] SHA-1/SHA-256 interoperability, part 3: pack index v3 Ben Knoble
2026-10-23 15:00 ` Junio C Hamano
2026-10-27 12:53   ` Christian Couder

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=178121e9-dd6a-4193-9f3b-d81754a6d448@gmail.com \
    --to=kaartic.sivaraam@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=newren@gmail.com \
    --cc=peff@peff.net \
    --cc=ps@pks.im \
    --cc=sandals@crustytoothpaste.net \
    /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