[PATCH v5 0/6] odb: make creation of object database pluggable
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Aug 7, 2026, 03:34 UTC
- Message-ID
- <20260807-pks-odb-create-on-disk-v5-0-399da0b0b140@pks.im>
- In-Reply-To
- <20260724-pks-odb-create-on-disk-v1-0-3b3d265d979b@pks.im>
Hi,
when creating a new repository we create a couple of on-disk data structures for the object database. This includes the "objects/" directory hierarchy with "objects/info" and "objects/pack", which are specific to the backend.
This patch series makes the creation of the on-disk data structures pluggable. While we continue to always create "objects/" regardless of the backend (it's required for a repository to be recognized as such), the other subdirectories are now created by the backend. This will allow other backends to plug in their own logic.
The series starts with a small detour into the loose-object map. This detour is required so that we can defer initialization of the object database itself to a later point in time.
The series is based on 9a0c4701dc (The 7th batch, 2026-07-22).
Changes in v5: - Remove a leftover formatting change. - Fix a stale comment. - Link to v4: https://patch.msgid.link/20260806-pks-odb-create-on-disk-v4-0-ba8b4fdd2e3c@pks.im
Changes in v4:
- Drop `APPLY_REPOSITOY_FORMAT_SKIP_ODB_CREATION` in favor of explicit
calls to `odb_new()`.
- Remove a useless call to `xstrdup()`.
- Mark a string as translatable.
- Link to v3: https://patch.msgid.link/20260805-pks-odb-create-on-disk-v3-0-c0ee3ac5141f@pks.imChanges in v3:
- Move handling of GIT_OBJECT_DIRECTORY and
GIT_ALTERNATE_OBJECT_DIRECTORIES into `odb_new()` itself. This
deduplicates some of the logic and also preps us for a future where
alternates are handled in the "files" backend itself.
- Link to v2: https://patch.msgid.link/20260804-pks-odb-create-on-disk-v2-0-ddf8b59bd207@pks.imChanges in v2:
- Add a testcase that demonstrates the bug fixed with alternate loose
object maps.
- Rename the "inmemory" bakcend to "in-memory".
- Clarify some commit messages.
- Link to v1: https://patch.msgid.link/20260724-pks-odb-create-on-disk-v1-0-3b3d265d979b@pks.imThanks!
Patrick
---
Patrick Steinhardt (6):
loose: load loose object map for the correct source
setup: detangle loading of loose object maps
setup: handle ODB-related environment variables in `odb_new()`
setup: defer object database creation
odb/source: introduce function to map source type to name
odb: make creation of on-disk structures pluggableloose.c | 25 +++++++++++---------- loose.h | 1 + odb.c | 21 ++++++++++-------- odb.h | 17 +++++++++++++-- odb/source-files.c | 19 ++++++++++++++++ odb/source-files.h | 4 +++- odb/source-inmemory.h | 4 +++- odb/source-loose.c | 2 ++ odb/source-loose.h | 4 +++- odb/source-packed.h | 4 +++- odb/source.c | 19 ++++++++++++++++ odb/source.h | 29 ++++++++++++++++++++++++ repository.c | 3 +-- setup.c | 51 +++++++++++++++++++++---------------------- setup.h | 4 ++-- t/t1016-compatObjectFormat.sh | 18 +++++++++++++++ t/unit-tests/u-odb-inmemory.c | 2 +- 17 files changed, 169 insertions(+), 58 deletions(-)
Range-diff versus v4:
1: 40ca0d1345 = 1: 3a0fbf9498 loose: load loose object map for the correct source
2: d18ddec5dd = 2: 7ba250f4d7 setup: detangle loading of loose object maps
3: 9b6fbc510f = 3: fbe755388b setup: handle ODB-related environment variables in `odb_new()`
4: f27f8d45a4 ! 4: 4d7a12e3cb setup: defer object database creation
@@ setup.c: static int create_default_files(struct repository *repo,
baselen = path.len;
@@ setup.c: int init_db(struct repository *repo,
- */
- read_and_verify_repository_format(&repo_fmt, repo_get_git_dir(repo), NULL);
repository_format_configure(&repo_fmt, hash, ref_storage_format);
-- if (apply_repository_format(repo, &repo_fmt, APPLY_REPOSITORY_FORMAT_HONOR_ENV, &err) < 0)
-+ if (apply_repository_format(repo, &repo_fmt,
-+ APPLY_REPOSITORY_FORMAT_HONOR_ENV, &err) < 0)
+ if (apply_repository_format(repo, &repo_fmt, APPLY_REPOSITORY_FORMAT_HONOR_ENV, &err) < 0)
die("%s", err.buf);
- startup_info->have_repository = 1;
@@ setup.c: int init_db(struct repository *repo,
if (repo_settings_get_shared_repository(repo)) {
char buf[10];
+
+ ## setup.h ##
+@@ setup.h: enum apply_repository_format_flags {
+
+ /*
+ * Apply the given repository format to the repo. This initializes extensions
+- * and basic data structures required for normal operation. Returns 0 on
+- * success, a negative error code when the format is not valid as determined by
++ * required for normal operation. Returns 0 on success, a negative error code
++ * when the format is not valid as determined by
+ * `verify_repository_format()`.
+ */
+ int apply_repository_format(struct repository *repo,
5: 1c0afb893f = 5: 6bb4ecc76d odb/source: introduce function to map source type to name
6: 387fe6e204 = 6: 806f399c63 odb: make creation of on-disk structures pluggable--- base-commit: 9a0c4701dcd5725c4184599322b52933ff5005ca change-id: 20260710-pks-odb-create-on-disk-ae8757861c69