[PATCH 1/5] refs: create leading directories
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Nov 5, 2026, 15:02 UTC
- Message-ID
- <20261105-pks-storage-format-improvements-v1-1-870bb4212518@pks.im>
- In-Reply-To
- <20261105-pks-storage-format-improvements-v1-0-870bb4212518@pks.im>
Both the "files" and "reftable" backends accept a payload that allows the user to use a non-default location for their files. So e.g. if the user specifies "files://refdir" as the ref storage format, then we would put files into ".git/refdir/refs" instead of ".git/refs".
Using this is somewhat unwieldy though, as the directory must exist before we create the ref storage as we'd otherwise die. This isn't that bad in the case where the user specifies an absolute path that is outside of the repository. But it becomes quite weird when asked to create the directory relative to commondir, as the user would first have to "mkdir -p repo/.git/refdir".
Adapt the reference backends to create leading directories. Note that we use the `noshare()` variant for this because it's very much possible that it will exist outside of the repository, and if so we shouldn't adapt permissions on such leading directories.
Signed-off-by: Patrick Steinhardt <ps@pks.im> --- refs/files-backend.c | 1 + refs/reftable-backend.c | 1 + t/t1423-ref-backend.sh | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+)
diff --git a/refs/files-backend.c b/refs/files-backend.c index 87d04557a53..1bdb16c0e7b 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -3699,6 +3699,7 @@ static int files_ref_store_create_on_disk(struct ref_store *ref_store, * they do not understand the reference format extension. */ strbuf_addf(&sb, "%s/refs", ref_store->gitdir); + safe_create_leading_directories_no_share(sb.buf); safe_create_dir(refs->base.repo, sb.buf, 1); adjust_shared_perm(refs->base.repo, sb.buf); diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index d0de0663552..3ba6a9ac0db 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -504,6 +504,7 @@ static int reftable_be_create_on_disk(struct ref_store *ref_store, struct strbuf sb = STRBUF_INIT; strbuf_addf(&sb, "%s/reftable", refs->base.gitdir); + safe_create_leading_directories_no_share(sb.buf); safe_create_dir(ref_store->repo, sb.buf, 1); strbuf_reset(&sb); diff --git a/t/t1423-ref-backend.sh b/t/t1423-ref-backend.sh index ee2bb66b99c..85d1e876b82 100755 --- a/t/t1423-ref-backend.sh +++ b/t/t1423-ref-backend.sh @@ -284,6 +284,30 @@ test_expect_success 'initializing repository with --ref-storage-format and paylo test_cmp expect actual ' +for format in files reftable +do + test_expect_success "default ref storage format with $format backend and payload" ' + test_when_finished "rm -rf repo refdir" && + BACKEND="$format://$(pwd)/refdir" && + echo "$BACKEND" >expect && + git init --ref-storage-format="$BACKEND" repo && + test_path_is_dir refdir && + case "$format" in + files) + test_path_is_file refdir/HEAD && + test_path_is_dir refdir/refs + ;; + reftable) + test_path_is_dir refdir/reftable && + test_path_is_file refdir/reftable/tables.list + ;; + *) + BUG "unknown ref storage format: $format" + ;; + esac + ' +done + test_expect_success 'cloning repository with alt ref directory' ' test_when_finished "rm -rf source repo refdir" && mkdir refdir &&
-- 2.56.0.500.g5d06dc02cd.dirty