Re: [PATCH v3 3/6] setup: handle ODB-related environment variables in `odb_new()`
Patrick Steinhardt <[email protected]> Thu, 6 Aug 2026 08:04:47 +0200
| Newsgroups | org.kernel.vger.git |
|---|---|
| Message-ID | <[email protected]> |
On Wed, Aug 05, 2026 at 03:29:21PM +0200, Toon Claes wrote: > Patrick Steinhardt <[email protected]> writes: > > diff --git a/odb.c b/odb.c > > index cf6e7938c0..b463afa072 100644 > > --- a/odb.c > > +++ b/odb.c > > @@ -1004,26 +1004,30 @@ int odb_write_object_stream(struct object_database *odb, > > } > > > > struct object_database *odb_new(struct repository *repo, > > - const char *primary_source, > > - const char *secondary_sources) > > + enum odb_new_flags flags) > > { > > - struct object_database *o = xmalloc(sizeof(*o)); > > - char *to_free = NULL; > > + char *primary_source = NULL, *secondary_sources = NULL; > > + struct object_database *o; > > > > - memset(o, 0, sizeof(*o)); > > + CALLOC_ARRAY(o, 1); > > o->repo = repo; > > pthread_mutex_init(&o->replace_mutex, NULL); > > string_list_init_dup(&o->submodule_source_paths); > > > > + if (flags & ODB_NEW_HONOR_ENV) { > > + primary_source = xstrdup_or_null(getenv(DB_ENVIRONMENT)); > > + secondary_sources = xstrdup_or_null(getenv(ALTERNATE_DB_ENVIRONMENT)); > > + } > > if (!primary_source) > > - primary_source = to_free = xstrfmt("%s/objects", repo->commondir); > > + primary_source = xstrfmt("%s/objects", repo->commondir); > > + > > o->sources = odb_source_new(o, primary_source, true); > > o->sources_tail = &o->sources->next; > > o->alternate_db = xstrdup_or_null(secondary_sources); > > I'd say this xstrdup_or_null() is not needed no more, and so is the > free() of that variable below. True indeed. Patrick