Git development
 help / color / mirror / Atom feed
From: Toon Claes <toon@iotcl.com>
To: Patrick Steinhardt <ps@pks.im>, git@vger.kernel.org
Subject: Re: [PATCH 2/2] odb: introduce `odb_prepare()`
Date: Fri, 26 Jun 2026 14:09:47 +0200	[thread overview]
Message-ID: <87o6gx4i5w.fsf@emacs.iotcl.com> (raw)
In-Reply-To: <20260622-b4-pks-odb-generalize-prepare-v1-2-d2a5c5d13144@pks.im>

Patrick Steinhardt <ps@pks.im> writes:

> Introduce `odb_prepare()` as a simple wrapper to prepare alternates and
> then prepare each individual source. Adapt git-grep(1) to use it.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  builtin/grep.c |  9 ++-------
>  odb.c          | 18 ++++++++++++------
>  odb.h          |  8 ++++++--
>  3 files changed, 20 insertions(+), 15 deletions(-)
>
> diff --git a/builtin/grep.c b/builtin/grep.c
> index 7361bf071e..a7252d56a1 100644
> --- a/builtin/grep.c
> +++ b/builtin/grep.c
> @@ -1356,13 +1356,8 @@ int cmd_grep(int argc,
>  		if (recurse_submodules)
>  			repo_read_gitmodules(the_repository, 1);
>  
> -		if (startup_info->have_repository) {
> -			struct odb_source *source;
> -
> -			odb_prepare_alternates(the_repository->objects);
> -			for (source = the_repository->objects->sources; source; source = source->next)
> -				odb_source_prepare(source, 0);
> -		}
> +		if (startup_info->have_repository)
> +			odb_prepare(the_repository->objects, 0);
>  
>  		start_threads(&opt);
>  	} else {
> diff --git a/odb.c b/odb.c
> index 7b45390e12..11414c49a8 100644
> --- a/odb.c
> +++ b/odb.c
> @@ -1070,7 +1070,7 @@ void odb_free(struct object_database *o)
>  	free(o);
>  }
>  
> -void odb_reprepare(struct object_database *o)
> +void odb_prepare(struct object_database *o, enum odb_prepare_flags flags)
>  {
>  	struct odb_source *source;
>  
> @@ -1082,13 +1082,19 @@ void odb_reprepare(struct object_database *o)
>  	 * the linked list, so existing odbs will continue to exist for
>  	 * the lifetime of the process.
>  	 */
> -	o->loaded_alternates = 0;
> -	odb_prepare_alternates(o);
> +	if (flags & ODB_PREPARE_FLUSH_CACHES) {
> +		o->loaded_alternates = 0;
> +		o->object_count_valid = 0;
> +	}
>  
> +	odb_prepare_alternates(o);
>  	for (source = o->sources; source; source = source->next)
> -		odb_source_prepare(source, ODB_PREPARE_FLUSH_CACHES);
> -
> -	o->object_count_valid = 0;
> +		odb_source_prepare(source, flags);
>  
>  	obj_read_unlock();
>  }
> +
> +void odb_reprepare(struct object_database *o)
> +{
> +	odb_prepare(o, ODB_PREPARE_FLUSH_CACHES);
> +}
> diff --git a/odb.h b/odb.h
> index c14c9030e4..b1c0f3767b 100644
> --- a/odb.h
> +++ b/odb.h
> @@ -133,9 +133,13 @@ enum odb_prepare_flags {
>  };
>  
>  /*
> - * Clear caches, reload alternates and then reload object sources so that new
> - * objects may become accessible.
> + * Prepare the object database for use. Calling this function is generally not
> + * needed, but can be useful in case the caller wants to pre-open individual
> + * sources.
>   */
> +void odb_prepare(struct object_database *o, enum odb_prepare_flags flags);
> +
> +/* Equivalent to `odb_prepare(o, ODB_PREPARE_FLUSH_CACHES)`. */
>  void odb_reprepare(struct object_database *o);

According to my grep results are there 17 callsites for odb_reprepare(),
then I agree it makes sense to create this wrapper.

-- 
Cheers,
Toon

      reply	other threads:[~2026-06-26 12:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-22  8:47 [PATCH 0/2] odb: generalize `reprepare()` callback Patrick Steinhardt
2026-06-22  8:47 ` [PATCH 1/2] odb/source: " Patrick Steinhardt
2026-06-26 12:10   ` Toon Claes
2026-06-22  8:47 ` [PATCH 2/2] odb: introduce `odb_prepare()` Patrick Steinhardt
2026-06-26 12:09   ` Toon Claes [this message]

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=87o6gx4i5w.fsf@emacs.iotcl.com \
    --to=toon@iotcl.com \
    --cc=git@vger.kernel.org \
    --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