[PATCH 2/7] path: introduce `safe_create_leading_directories_no_share_const()`
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Sep 24, 2026, 09:19 UTC
- Message-ID
- <20260924-pks-create-repository-stateless-v1-2-11499557cf31@pks.im>
- In-Reply-To
- <20260924-pks-create-repository-stateless-v1-0-11499557cf31@pks.im>
The `safe_create_leading_directories()` family of functions modify the passed-in path so that we can obtain all the different segments of the path. This is done by overwriting path separators with a NUL byte for every component. While we ultimately restore the original string, the consequence is that the caller needs to pass a non-constant string.
While it would be trivial to modify the function to not modify the path in-place anymore, the intent of this whole mechanism is to save an allocation. It's quite dubious whether this optimization really matters in the grand scheme of things, but here we are.
In any case, we provide a `_const()` variant that handles the case where the caller only has a string constant. But we lack such a variant for the `safe_create_leading_directories_no_share()` function, and we're about to add a couple of callers that would need it.
Add this helper function.
Signed-off-by: Patrick Steinhardt <ps@pks.im> --- path.c | 5 +++++ path.h | 1 + 2 files changed, 6 insertions(+)
diff --git a/path.c b/path.c index 69b06c9464..f8f5a9dd28 100644 --- a/path.c +++ b/path.c @@ -889,6 +889,11 @@ enum scld_error safe_create_leading_directories_no_share(char *path) return safe_create_leading_directories(NULL, path); } +enum scld_error safe_create_leading_directories_no_share_const(const char *path) +{ + return safe_create_leading_directories_const(NULL, path); +} + enum scld_error safe_create_leading_directories_const(struct repository *repo, const char *path) { diff --git a/path.h b/path.h index 7e7408dd05..e2d62c4978 100644 --- a/path.h +++ b/path.h @@ -254,6 +254,7 @@ enum scld_error safe_create_leading_directories(struct repository *repo, char *p enum scld_error safe_create_leading_directories_const(struct repository *repo, const char *path); enum scld_error safe_create_leading_directories_no_share(char *path); +enum scld_error safe_create_leading_directories_no_share_const(const char *path); /* * Create a file, potentially creating its leading directories in case they
-- 2.56.0.rc2.329.gd58861e689.dirty