Re: [PATCH 02/13] odb: introduce `odb_source_new()`
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Oct 24, 2025, 16:37 UTC
- Message-ID
- <xmqqjz0kp86k.fsf@gitster.g>
- In-Reply-To
- <20251024-b4-pks-odb-loose-backend-v1-2-1a4202273c38@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 33 quoted lines
> 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.