From: Patrick Steinhardt Date: Mon, 27 Oct 2025 11:21:30 GMT Subject: Re: [PATCH 02/13] odb: introduce `odb_source_new()` Message-ID: In-Reply-To: On Fri, Oct 24, 2025 at 09:37:39AM -0700, Junio C Hamano wrote: > 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. Yeah. I plan on revamping this area so that we create the primary object source only after we have figured out all details about the repository. But for now we'll continue to reach into the already allocated source and replace its path. Patrick