From: Patrick Steinhardt Date: Thu, 24 Sep 2026 09:19:21 GMT Subject: [PATCH 3/7] builtin/init: refactor messy creation of leading directories Message-ID: <20260924-pks-create-repository-stateless-v1-3-11499557cf31@pks.im> In-Reply-To: <20260924-pks-create-repository-stateless-v1-0-11499557cf31@pks.im> When creating a new repository via git-init(1) we potentially have to create any leading directories via `safe_create_leading_directories()`. This function optionally knows to handle "core.sharedRepository" to adjust the permissions of the created directories. The value of that setting is taken from the passed-in repository. When creating a new repository we don't want to honor it though, so we painstakingly: 1. Save the current value of that setting. 2. Set it to 0. 3. Create the directory with `safe_create_leading_directories()`. This has the effect that `adjust_shared_perm()` will exit early and not adjust permissions. 4. Restore the old value. This is extremely awkward, but it achieves the desired effect that we ignore the configuration. There's a significantly easier way to achieve this though: we can just call the `_no_share()` variant, whose entire purpose it is to ignore "core.sharedRepository". Refactor the code to use that variant accordingly. Signed-off-by: Patrick Steinhardt --- builtin/init-db.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/builtin/init-db.c b/builtin/init-db.c index 5c22eae2f3..e45268f1ff 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -131,15 +131,7 @@ int cmd_init_db(int argc, retry: if (chdir(argv[0]) < 0) { if (!mkdir_tried) { - int saved; - /* - * At this point we haven't read any configuration, - * and we know shared_repository should always be 0; - * but just in case we play safe. - */ - saved = repo_settings_get_shared_repository(the_repository); - repo_settings_set_shared_repository(the_repository, 0); - switch (safe_create_leading_directories_const(the_repository, argv[0])) { + switch (safe_create_leading_directories_no_share_const(argv[0])) { case SCLD_OK: case SCLD_PERMS: break; @@ -150,7 +142,7 @@ int cmd_init_db(int argc, die_errno(_("cannot mkdir %s"), argv[0]); break; } - repo_settings_set_shared_repository(the_repository, saved); + if (mkdir(argv[0], 0777) < 0) die_errno(_("cannot mkdir %s"), argv[0]); mkdir_tried = 1; -- 2.56.0.rc2.329.gd58861e689.dirty