[PATCH v4 08/10] refs/reftable-backend: manually parse "core.sharedRepository"
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Jun 19, 2026, 11:27 UTC
- Message-ID
- <20260619-b4-pks-refs-avoid-chdir-notify-reparent-v4-8-a6472be7acc4@pks.im>
- In-Reply-To
- <20260619-b4-pks-refs-avoid-chdir-notify-reparent-v4-0-a6472be7acc4@pks.im>
We're using `calc_shared_perm()` when creating a reftable repository. This function internally uses `repo_settings_get_shared_repository()`, which results in the same chicken-and-egg problem as mentioned in the preceding commit.
Prepare for a fix by handling parsing of "core.sharedRepository" manually in `reftable_be_config()` so that we have full control over how exactly this configuration is read.
Note that this change requires a small reording in "setup.c" when creating the repositroy, as we only write "core.sharedRepository" into the configuration after we've already created the reference database. This is too late though now that we parse the value directly from the configuration, so we have to reverse the order.
Signed-off-by: Patrick Steinhardt <ps@pks.im> --- path.c | 11 ++++++----- path.h | 2 +- refs/reftable-backend.c | 8 +++++++- setup.c | 8 ++++---- 4 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/path.c b/path.c index d7e17bf174..c28b057374 100644 --- a/path.c +++ b/path.c @@ -736,11 +736,10 @@ char *interpolate_path(const char *path, int real_home) return NULL; } -int calc_shared_perm(struct repository *repo, - int mode) +int calc_shared_perm(int shared_repo, int mode) { int tweak; - int shared_repo = repo_settings_get_shared_repository(repo); + if (shared_repo < 0) tweak = -shared_repo; else @@ -763,13 +762,15 @@ int adjust_shared_perm(struct repository *repo, const char *path) { int old_mode, new_mode; + int shared_repository; - if (!repo_settings_get_shared_repository(repo)) + shared_repository = repo_settings_get_shared_repository(repo); + if (!shared_repository) return 0; if (get_st_mode_bits(path, &old_mode) < 0) return -1; - new_mode = calc_shared_perm(repo, old_mode); + new_mode = calc_shared_perm(shared_repository, old_mode); if (S_ISDIR(old_mode)) { /* Copy read bits to execute bits */ new_mode |= (new_mode & 0444) >> 2; diff --git a/path.h b/path.h index 0434ba5e07..1188dc4729 100644 --- a/path.h +++ b/path.h @@ -145,7 +145,7 @@ const char *git_path_shallow(struct repository *r); int ends_with_path_components(const char *path, const char *components); -int calc_shared_perm(struct repository *repo, int mode); +int calc_shared_perm(int shared_repository, int mode); int adjust_shared_perm(struct repository *repo, const char *path); char *interpolate_path(const char *path, int real_home); diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index 5115a3f4ce..ee92bd9c70 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -362,6 +362,11 @@ static int reftable_be_config(const char *var, const char *value, refs->write_options.lock_timeout_ms = lock_timeout; } else if (!strcmp(var, "core.logallrefupdates")) { refs->log_all_ref_updates = refs_parse_log_all_ref_updates_config(value); + } else if (!strcmp(var, "core.sharedrepository")) { + mode_t mask = umask(0); + umask(mask); + refs->write_options.default_permissions = calc_shared_perm(git_config_perm(var, value), + 0666 & ~mask); } return 0; @@ -412,7 +417,8 @@ static struct ref_store *reftable_be_init(struct repository *repo, default: BUG("unknown hash algorithm %d", repo->hash_algo->format_id); } - refs->write_options.default_permissions = calc_shared_perm(repo, 0666 & ~mask); + + refs->write_options.default_permissions = 0666 & ~mask; refs->write_options.disable_auto_compact = !git_env_bool("GIT_TEST_REFTABLE_AUTOCOMPACTION", 1); refs->write_options.lock_timeout_ms = 100; diff --git a/setup.c b/setup.c index 0c6efb0560..03ff359070 100644 --- a/setup.c +++ b/setup.c @@ -2846,10 +2846,6 @@ int init_db(struct repository *repo, reinit = create_default_files(repo, template_dir, original_git_dir, &repo_fmt, init_shared_repository); - if (!(flags & INIT_DB_SKIP_REFDB)) - create_reference_database(repo, initial_branch, flags & INIT_DB_QUIET); - create_object_directory(repo); - if (repo_settings_get_shared_repository(repo)) { char buf[10]; /* We do not spell "group" and such, so that @@ -2871,6 +2867,10 @@ int init_db(struct repository *repo, repo_config_set(repo, "receive.denyNonFastforwards", "true"); } + if (!(flags & INIT_DB_SKIP_REFDB)) + create_reference_database(repo, initial_branch, flags & INIT_DB_QUIET); + create_object_directory(repo); + if (!(flags & INIT_DB_QUIET)) { int len = strlen(git_dir);
-- 2.55.0.rc1.722.g2b3ac350e6.dirty