Re: [PATCH v2 4/8] repository: stop initializing the object database in `repo_set_gitdir()`
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Jun 4, 2026, 06:08 UTC
- Message-ID
- <aiEWZo7Y-UXK4N3x@pks.im>
- In-Reply-To
- <CAOLa=ZQ5u+J-f=xS7RDym0cwt+=R2dzMFo5P34cp-CBbza7NRg@mail.gmail.com>
On Wed, Jun 03, 2026 at 05:49:50AM -0700, Karthik Nayak wrote:
Show 19 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> > diff --git a/repository.c b/repository.c
> > index 58a13f7c4f..2c2395105f 100644
> > --- a/repository.c
> > +++ b/repository.c
> > @@ -181,12 +181,6 @@ void repo_set_gitdir(struct repository *repo,
> > free(old_gitdir);
> >
> > repo_set_commondir(repo, o->commondir);
> > -
> > - if (!repo->objects)
> > - repo->objects = odb_new(repo, o->object_dir, o->alternate_db);
> > - else if (!o->skip_initializing_odb)
> > - BUG("cannot reinitialize an already-initialized object directory");
> > -
>
> This always confuses me, so we were creating the odb even if
> `o->skip_initializing_odb` was set to true, if `repo->objects` didn't
> exist. Weird.Agreed, it was weird. It was my first iteration towards centralizing `odb_new()`: before we had the above logic we were basically recreating the ODB multiple times, which was even more weird. At least things are getting somewhat sensible with this patch now.
Patrick