[PATCH v3 6/7] builtin/clone: introduce "--object-storage-format="
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Oct 23, 2026, 11:49 UTC
- Message-ID
- <20261023-b4-pks-odb-extension-v3-6-b1bb30a006db@pks.im>
- In-Reply-To
- <20261023-b4-pks-odb-extension-v3-0-b1bb30a006db@pks.im>
Wire up the new object storage format in git-clone(1) via a new `--object-storage-format=` option, same as we have introduced in the preceding commit for git-init(1).
Note that "--local" clones will not work if either of the object databases is not using the "files" format. This is because we hardlink loose objects and packfiles into the new repository, and that is something that simply won't work with alternative backends. Consequently, we either downgrade to a non-local clone with a warning, or we die in case the user has explicitly asked for a local clone.
We _could_ in theory handle the case where the "files" backend has been configured with an alternative object directory path (that is, with "files:///path/to/dir"). But that's left for a future patch series to implement for the sake of simplicity.
Signed-off-by: Patrick Steinhardt <ps@pks.im> --- Documentation/git-clone.adoc | 11 +++++++ builtin/clone.c | 45 +++++++++++++++++++++++++++-- t/t5601-clone.sh | 68 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-clone.adoc b/Documentation/git-clone.adoc index 07f7cf1a98..dd3b44817a 100644 --- a/Documentation/git-clone.adoc +++ b/Documentation/git-clone.adoc @@ -360,6 +360,17 @@ include::ref-storage-format.adoc[] `--ref-format=<format>`:: Deprecated alias of `--ref-storage-format=<format>`. +`--object-storage-format=<format>`:: +Specify the given object storage _<format>_ for the repository. Backends that +require additional configuration accept a payload in the form +`<format>://<payload>`, for example a path or a connection string identifying +the database that shall store the objects. The valid values are: ++ +include::object-storage-format.adoc[] ++ +Local clones (see `--local`) fall back to the regular transport when either +repository uses a non-default object storage. + `-j<n>`:: `--jobs=<n>`:: The number of submodules fetched at the same time. diff --git a/builtin/clone.c b/builtin/clone.c index 95e641b1a4..437dd2b277 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -378,6 +378,24 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest, dir_iterator_free(iter); } +static bool is_using_default_object_storage_format(const char *repo_path) +{ + struct repository_format format = REPOSITORY_FORMAT_INIT; + struct strbuf config = STRBUF_INIT; + bool is_default; + + get_common_dir(&config, repo_path); + strbuf_addstr(&config, "/config"); + read_repository_format(&format, config.buf); + + is_default = format.object_storage_format == OBJECT_STORAGE_FORMAT_FILES && + !format.object_storage_payload; + + clear_repository_format(&format); + strbuf_release(&config); + return is_default; +} + static void clone_local(const char *src_repo, const char *dest_repo) { if (!option_shared) { @@ -927,6 +945,7 @@ int cmd_clone(int argc, struct string_list option_not = STRING_LIST_INIT_NODUP; const char *real_git_dir = NULL; const char *ref_storage_format_uri = NULL; + const char *object_storage_format_uri = NULL; const char *option_upload_pack = "git-upload-pack"; int option_progress = -1; int option_sparse_checkout = 0; @@ -1008,6 +1027,8 @@ int cmd_clone(int argc, N_("separate git dir from working tree")), OPT_STRING(0, "ref-storage-format", &ref_storage_format_uri, N_("format"), N_("specify the reference storage format to use")), + OPT_STRING(0, "object-storage-format", &object_storage_format_uri, N_("format"), + N_("specify the object storage format to use")), OPT_ALIAS_F(0, "ref-format", "ref-storage-format", PARSE_OPT_HIDDEN), OPT_STRING_LIST('c', "config", &option_config, N_("key=value"), N_("set config inside the new repository")), @@ -1060,6 +1081,10 @@ int cmd_clone(int argc, die(_("unknown ref storage format '%s'"), ref_storage_format_uri); } + if (object_storage_format_uri && + object_storage_format_by_uri(object_storage_format_uri, NULL) == OBJECT_STORAGE_FORMAT_UNKNOWN) + die(_("unknown object storage format '%s'"), object_storage_format_uri); + if (option_mirror) { option_bare = 1; option_tags = 0; @@ -1213,8 +1238,9 @@ int cmd_clone(int argc, * their on-disk data structures. */ create_repository(the_repository, git_dir, real_git_dir, work_tree, - option_template, GIT_HASH_UNKNOWN, ref_storage_format_uri, - NULL, do_not_override_repo_unix_permissions, NULL); + option_template, GIT_HASH_UNKNOWN, + ref_storage_format_uri, object_storage_format_uri, + do_not_override_repo_unix_permissions, NULL); if (real_git_dir) { free((char *)git_dir); @@ -1363,6 +1389,21 @@ int cmd_clone(int argc, is_local = 0; } } + + /* + * Local clones copy or hardlink the object directory of the source repository + * into the destination. This only works when both repositories use the "files" + * object storage format. + */ + if (is_local && + (!is_using_default_object_storage_format(path) || !is_using_default_object_storage_format(git_dir))) { + if (option_local > 0) + die(_("cannot perform local clone with non-default object storage format")); + else + warning(_("falling back to non-local clone because of non-default object storage format")); + is_local = 0; + } + if (option_local > 0 && !is_local) warning(_("--local is ignored")); diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 06f6121f82..85f439d6b6 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -181,6 +181,74 @@ test_expect_success 'clone with garbage ref format' ' test_path_is_missing ref-storage ' +test_expect_success 'clone with files object storage format' ' + test_when_finished "rm -rf object-storage" && + git clone --object-storage-format=files --bare src object-storage && + test_must_fail git -C object-storage config get extensions.objectstorage && + git -C object-storage rev-parse --show-object-storage-format >actual && + echo files >expect && + test_cmp expect actual +' + +test_expect_success 'clone with object storage payload' ' + test_when_finished "rm -rf object-storage" && + git clone --object-storage-format=files://objs --bare src object-storage && + git -C object-storage config get extensions.objectstorage >actual && + echo files://objs >expect && + test_cmp expect actual && + git -C object-storage rev-parse --show-object-storage-format >actual && + test_cmp expect actual && + test_path_is_dir object-storage/objs/pack && + test_path_is_missing object-storage/objects/pack +' + +test_expect_success 'clone with object storage payload and bundle URI' ' + test_when_finished "rm -rf object-storage src.bundle" && + git -C src bundle create ../src.bundle --all && + git clone --object-storage-format=files://objs --bundle-uri="$PWD/src.bundle" \ + src object-storage && + git -C object-storage rev-parse --show-object-storage-format >actual && + echo files://objs >expect && + test_cmp expect actual +' + +test_expect_success 'clone with garbage object storage format' ' + cat >expect <<-EOF && + fatal: unknown object storage format ${SQ}garbage${SQ} + EOF + test_must_fail git clone --object-storage-format=garbage --bare src object-storage 2>err && + test_cmp expect err && + test_path_is_missing object-storage +' + +test_expect_success 'local clone into non-default object storage bails' ' + test_when_finished "rm -rf object-storage" && + test_must_fail git clone --local --object-storage-format=files://objs src object-storage 2>err && + test_grep "cannot perform local clone with non-default object storage format" err +' + +test_expect_success 'local clone from explicit files object storage succeeds' ' + test_when_finished "rm -rf object-storage object-storage-dest" && + git clone src object-storage && + git -C object-storage config set core.repositoryformatversion 1 && + git -C object-storage config set extensions.objectstorage files && + git clone --local object-storage object-storage-dest +' + +test_expect_success 'local clone from non-default object storage bails' ' + test_when_finished "rm -rf object-storage object-storage-dest" && + git clone --object-storage-format=files://objs src object-storage && + test_must_fail git clone --local object-storage object-storage-dest 2>err && + test_grep "cannot perform local clone with non-default object storage format" err +' + +test_expect_success 'local clone from non-default object storage without --local warns' ' + test_when_finished "rm -rf object-storage object-storage-dest" && + git clone --object-storage-format=files://objs src object-storage && + git clone object-storage object-storage-dest 2>err && + test_grep "falling back to non-local clone" err +' + test_expect_success 'clone to destination with trailing /' ' git clone src target-1/ &&
-- 2.56.0.307.g5fe7bd680c.dirty