From: Junio C Hamano Date: Fri, 24 Oct 2025 16:37:39 GMT Subject: Re: [PATCH 02/13] odb: introduce `odb_source_new()` Message-ID: In-Reply-To: <20251024-b4-pks-odb-loose-backend-v1-2-1a4202273c38@pks.im> Patrick Steinhardt writes: > diff --git a/repository.c b/repository.c > index 6faf5c73981..6aaa7ba0086 100644 > --- a/repository.c > +++ b/repository.c > @@ -160,20 +160,24 @@ void repo_set_gitdir(struct repository *repo, > * until after xstrdup(root). Then we can free it. > */ > char *old_gitdir = repo->gitdir; > + char *objects_path = NULL; > > repo->gitdir = xstrdup(gitfile ? gitfile : root); > free(old_gitdir); > > repo_set_commondir(repo, o->commondir); > + expand_base_dir(&objects_path, o->object_dir, > + repo->commondir, "objects"); > > if (!repo->objects->sources) { > - CALLOC_ARRAY(repo->objects->sources, 1); > - repo->objects->sources->odb = repo->objects; > - repo->objects->sources->local = true; > + repo->objects->sources = odb_source_new(repo->objects, > + objects_path, true); > repo->objects->sources_tail = &repo->objects->sources->next; > + free(objects_path); > + } else { > + free(repo->objects->sources->path); > + repo->objects->sources->path = objects_path; > } > - expand_base_dir(&repo->objects->sources->path, o->object_dir, > - repo->commondir, "objects"); > > repo->objects->sources->disable_ref_updates = o->disable_ref_updates; Everything else is straight-forward, but this one is trickier. When the .sources structure already exists, we used to just change the path in it, but now because creation of .sources structure requires path to be computed beforehand, we need an "else" clause to handle the "when we already had .sources when we enter this section of code" case.