Git development
 help / color / mirror / Atom feed
From: Toon Claes <toon@iotcl.com>
To: Patrick Steinhardt <ps@pks.im>, git@vger.kernel.org
Cc: Patrick Ohly <patrick.ohly@intel.com>
Subject: Re: [PATCH 1/2] odb/source-loose: extract logic to retrieve subdirectory bitmap
Date: Fri, 13 Nov 2026 10:39:46 +0100	[thread overview]
Message-ID: <871p8p5au5.fsf@dev.null.iotcl.com.invalid> (raw)
In-Reply-To: <20261104-pks-odb-loose-stale-cache-v1-1-a00d5cdb5e7d@pks.im>

Patrick Steinhardt <ps@pks.im> writes:

> The loose object cache tracks which sharding directories have already
> been scanned via a bitmap. The logic to retrieve the bitmap and mask for
> a given object ID is inlined into the function that populates the cache,
> but we're about to add a second function that will need to perform the
> same logic.
>
> Extract the logic into a separate function to prepare for this.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  odb/source-loose.c | 24 +++++++++++++++++-------
>  1 file changed, 17 insertions(+), 7 deletions(-)
>
> diff --git a/odb/source-loose.c b/odb/source-loose.c
> index 50cb388c352..da8f9767257 100644
> --- a/odb/source-loose.c
> +++ b/odb/source-loose.c
> @@ -26,29 +26,39 @@ static int append_loose_object(const struct object_id *oid,
>  	return 0;
>  }
>  
> -static struct oidtree *odb_source_loose_cache(struct odb_source_loose *loose,
> -					      const struct object_id *oid)
> +static uint32_t *subdir_seen_bitmap(struct odb_source_loose *loose,
> +				    const struct object_id *oid,
> +				    uint32_t *mask)
>  {
>  	int subdir_nr = oid->hash[0];
> -	struct strbuf buf = STRBUF_INIT;
>  	size_t word_bits = bitsizeof(loose->subdir_seen[0]);
>  	size_t word_index = subdir_nr / word_bits;
> -	size_t mask = (size_t)1u << (subdir_nr % word_bits);
> -	uint32_t *bitmap;
>  
>  	if (subdir_nr < 0 ||
>  	    (size_t) subdir_nr >= bitsizeof(loose->subdir_seen))
>  		BUG("subdir_nr out of range");
>  
> -	bitmap = &loose->subdir_seen[word_index];
> +	*mask = (size_t)1u << (subdir_nr % word_bits);

So `mask`'s type is changed from `size_t` to `uint32_t`, which is fine
by me, but shall we use `uint32_t` here too?

> +
> +	return &loose->subdir_seen[word_index];
> +}
> +
> +static struct oidtree *odb_source_loose_cache(struct odb_source_loose *loose,
> +					      const struct object_id *oid)
> +{
> +	struct strbuf buf = STRBUF_INIT;
> +	uint32_t *bitmap, mask;
> +
> +	bitmap = subdir_seen_bitmap(loose, oid, &mask);
>  	if (*bitmap & mask)
>  		return loose->cache;
> +
>  	if (!loose->cache) {
>  		ALLOC_ARRAY(loose->cache, 1);
>  		oidtree_init(loose->cache);
>  	}
>  	strbuf_addstr(&buf, loose->base.path);
> -	for_each_file_in_obj_subdir(subdir_nr, &buf,
> +	for_each_file_in_obj_subdir(oid->hash[0], &buf,
>  				    loose->base.odb->repo->hash_algo,
>  				    append_loose_object,
>  				    NULL, NULL,
>
> -- 
> 2.56.0.500.g5d06dc02cd.dirty
>

-- 
Laters,
Toon

  reply	other threads:[~2026-11-13  9:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 12:16 [PATCH 0/2] odb/source-loose: fix failing existence checks caused by stale cache Patrick Steinhardt
2026-11-04 12:16 ` [PATCH 1/2] odb/source-loose: extract logic to retrieve subdirectory bitmap Patrick Steinhardt
2026-11-13  9:39   ` Toon Claes [this message]
2026-11-04 12:16 ` [PATCH 2/2] odb/source-loose: fix existence checks for newly written objects Patrick Steinhardt
2026-11-04 17:47   ` Junio C Hamano
2026-11-05 19:43   ` Jeff King
2026-11-06 11:16     ` Patrick Steinhardt
2026-11-06 16:02       ` Junio C Hamano
2026-11-09 13:44         ` Patrick Steinhardt
2026-11-09 18:50           ` Jeff King
2026-11-04 12:57 ` [PATCH 0/2] odb/source-loose: fix failing existence checks caused by stale cache Kristofer Karlsson
2026-11-04 16:27   ` Derrick Stolee
2026-11-05  0:09   ` Junio C Hamano

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=871p8p5au5.fsf@dev.null.iotcl.com.invalid \
    --to=toon@iotcl.com \
    --cc=git@vger.kernel.org \
    --cc=patrick.ohly@intel.com \
    --cc=ps@pks.im \
    /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