From: Junio C Hamano Date: Thu, 30 Jul 2026 17:44:39 +0000 (-0700) Subject: Merge branch 'ps/odb-make-creation-pluggable' into seen X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3bc7f00cda1c3848aa29e6266b04e3ffcbaa5d97;p=thirdparty%2Fgit.git Merge branch 'ps/odb-make-creation-pluggable' into seen The creation of the on-disk data structures for the object database has been made pluggable, allowing future backends to customize their setup. As part of this, the initialization of the object database has been deferred, and the loading of the loose-object map has been detangled from repository initialization. * ps/odb-make-creation-pluggable: odb: make creation of on-disk structures pluggable odb/source: introduce function to map source type to name setup: defer object database creation setup: detangle loading of loose object maps loose: load loose object map for the correct source --- 3bc7f00cda1c3848aa29e6266b04e3ffcbaa5d97 diff --cc setup.c index 95909e9603,14ef119cb7..c6b05ea4aa --- a/setup.c +++ b/setup.c @@@ -2653,29 -2663,40 +2663,41 @@@ static int create_default_files(struct return reinit; } - static void create_object_directory(struct repository *repo) + static void create_object_database(struct repository *repo) { - struct strbuf path = STRBUF_INIT; - size_t baselen; + char *object_directory, *alternate_object_directories; - strbuf_addstr(&path, repo_get_object_directory(repo)); - baselen = path.len; + get_object_directories(&object_directory, &alternate_object_directories); - safe_create_dir(repo, path.buf, 1); + /* + * Create the "objects" directory in the common directory. This is done + * so that the repository can be discovered regardless of the backend + * used. + * + * Note that we only do this in case the object directory wasn't + * overwritten via an environment variable. If it _is_ being overridden + * then we skip this step, as the repository won't be discoverable + * anyway without the environment variable. + */ + if (!object_directory) { + struct strbuf objects_dir = STRBUF_INIT; + repo_common_path_append(repo, &objects_dir, "objects"); + safe_create_dir(repo, objects_dir.buf, 1); + strbuf_release(&objects_dir); + } - strbuf_setlen(&path, baselen); - strbuf_addstr(&path, "/pack"); - safe_create_dir(repo, path.buf, 1); + repo->objects = odb_new(repo, object_directory, + alternate_object_directories); - strbuf_setlen(&path, baselen); - strbuf_addstr(&path, "/info"); - safe_create_dir(repo, path.buf, 1); + if (odb_source_create_on_disk(repo->objects->sources) < 0) + die("failed creating object database"); - strbuf_release(&path); + free(alternate_object_directories); + free(object_directory); } -static void separate_git_dir(const char *git_dir, const char *git_link) +static void separate_git_dir(struct repository *repo, + const char *git_dir, const char *git_link) { struct stat st;