git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[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
Previous: Patrick SteinhardtNext: Karthik Nayak
Message 2 of 13 in “Improvements for storage format handling”
  1. 0/5 Improvements for storage format handlingPatrick Steinhardt, Nov 5, 2026
  2. 1/5 refs: create leading directoriesPatrick Steinhardt, Nov 5, 2026
  3. Karthik NayakNov 6, 2026
  4. Patrick SteinhardtNov 6, 2026
  5. 2/5 odb/files: create leading directoriesPatrick Steinhardt, Nov 5, 2026
  6. 3/5 setup: allow speciyfing payloads with default storage formatsPatrick Steinhardt, Nov 5, 2026
  7. 4/5 builtin/rev-parse: print payload for the ref storage formatPatrick Steinhardt, Nov 5, 2026
  8. Karthik NayakNov 6, 2026
  9. 5/5 t: allow testing with a non-default object storage foramtPatrick Steinhardt, Nov 5, 2026
  10. Junio C HamanoNov 6, 2026
  11. Patrick SteinhardtNov 9, 2026
  12. Karthik NayakNov 6, 2026
  13. Patrick SteinhardtNov 6, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.