Merge commit
2f6614658f13fd70a1a402d5b8ed443daa471be2
Merge branch 'ps/odb-make-creation-pluggable'
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: handle ODB-related environment variables in `odb_new()` setup: detangle loading of loose object maps loose: load loose object map for the correct source
Junio C Hamano <gitster@pobox.com> · 2026-08-20 14:30 UTC
Combined diff: only what this merge did beyond taking one side. Added lines are colored by the parent they came from; bold lines came from none of them; removed lines are red.
3 files changed,
+50
−23
modified odb.c
| @@@ -1034,26 -1003,13 +1034,25 @@@ int odb_write_object_stream(struct obje | ||
| 1034 | return odb_source_write_object_stream(odb->sources, stream, len, oid); | |
| 1035 | } | |
| 1036 | ||
| 1037 | + | int odb_optimize(struct object_database *odb, |
| 1038 | + | const struct odb_optimize_options *opts) |
| 1039 | + | { |
| 1040 | + | return odb_source_optimize(odb->sources, opts); |
| 1041 | + | } |
| 1042 | + | |
| 1043 | + | bool odb_optimize_required(struct object_database *odb, |
| 1044 | + | const struct odb_optimize_options *opts) |
| 1045 | + | { |
| 1046 | + | return odb_source_optimize_required(odb->sources, opts); |
| 1047 | + | } |
| 1048 | + | |
| 1049 | struct object_database *odb_new(struct repository *repo, | |
| - | const char *primary_source, | |
| - | const char *secondary_sources) | |
| 1050 | + | enum odb_new_flags flags) |
| 1051 | { | |
| - | struct object_database *o = xmalloc(sizeof(*o)); | |
| - | char *to_free = NULL; | |
| 1052 | + | char *primary_source = NULL, *secondary_sources = NULL; |
| 1053 | + | struct object_database *o; |
| 1054 | ||
| - | memset(o, 0, sizeof(*o)); | |
| 1055 | + | CALLOC_ARRAY(o, 1); |
| 1056 | o->repo = repo; | |
| 1057 | pthread_mutex_init(&o->replace_mutex, NULL); | |
| 1058 | string_list_init_dup(&o->submodule_source_paths); | |
modified setup.c
| @@@ -2653,29 -2647,32 +2647,33 @@@ static int create_default_files(struct | ||
| 2647 | return reinit; | |
| 2648 | } | |
| 2649 | ||
| - | static void create_object_directory(struct repository *repo) | |
| 2650 | + | static void create_object_database(struct repository *repo) |
| 2651 | { | |
| - | struct strbuf path = STRBUF_INIT; | |
| - | size_t baselen; | |
| - | ||
| - | strbuf_addstr(&path, repo_get_object_directory(repo)); | |
| - | baselen = path.len; | |
| - | ||
| - | safe_create_dir(repo, path.buf, 1); | |
| - | ||
| - | strbuf_setlen(&path, baselen); | |
| - | strbuf_addstr(&path, "/pack"); | |
| - | safe_create_dir(repo, path.buf, 1); | |
| 2652 | + | /* |
| 2653 | + | * Create the "objects" directory in the common directory. This is done |
| 2654 | + | * so that the repository can be discovered regardless of the backend |
| 2655 | + | * used. |
| 2656 | + | * |
| 2657 | + | * Note that we only do this in case the object directory wasn't |
| 2658 | + | * overwritten via an environment variable. If it _is_ being overridden |
| 2659 | + | * then we skip this step, as the repository won't be discoverable |
| 2660 | + | * anyway without the environment variable. |
| 2661 | + | */ |
| 2662 | + | if (!getenv(DB_ENVIRONMENT)) { |
| 2663 | + | struct strbuf objects_dir = STRBUF_INIT; |
| 2664 | + | repo_common_path_append(repo, &objects_dir, "objects"); |
| 2665 | + | safe_create_dir(repo, objects_dir.buf, 1); |
| 2666 | + | strbuf_release(&objects_dir); |
| 2667 | + | } |
| 2668 | ||
| - | strbuf_setlen(&path, baselen); | |
| - | strbuf_addstr(&path, "/info"); | |
| - | safe_create_dir(repo, path.buf, 1); | |
| 2669 | + | repo->objects = odb_new(repo, ODB_NEW_HONOR_ENV); |
| 2670 | ||
| - | strbuf_release(&path); | |
| 2671 | + | if (odb_source_create_on_disk(repo->objects->sources) < 0) |
| 2672 | + | die(_("failed creating object database")); |
| 2673 | } | |
| 2674 | ||
| - | static void separate_git_dir(const char *git_dir, const char *git_link) | |
| 2675 | + | static void separate_git_dir(struct repository *repo, |
| 2676 | + | const char *git_dir, const char *git_link) |
| 2677 | { | |
| 2678 | struct stat st; | |
| 2679 | ||
modified t/unit-tests/u-odb-inmemory.c
| @@@ -37,20 -36,9 +37,20 @@@ static void cl_assert_object_info(struc | ||
| 37 | free(actual_content); | |
| 38 | } | |
| 39 | ||
| 40 | + | static void cl_assert_write_object(struct odb_source_inmemory *source, |
| 41 | + | const char *content, |
| 42 | + | enum object_type type, |
| 43 | + | struct object_id *oid) |
| 44 | + | { |
| 45 | + | size_t content_len = strlen(content); |
| 46 | + | hash_object_file(repo.hash_algo, content, content_len, type, oid); |
| 47 | + | cl_must_pass(odb_source_write_object(&source->base, content, content_len, |
| 48 | + | type, oid, NULL, NULL, 0)); |
| 49 | + | } |
| 50 | + | |
| 51 | void test_odb_inmemory__initialize(void) | |
| 52 | { | |
| - | odb = odb_new(&repo, "", ""); | |
| 53 | + | odb = odb_new(&repo, 0); |
| 54 | } | |
| 55 | ||
| 56 | void test_odb_inmemory__cleanup(void) | |