object-file: move safe_create_leading_directories() into "path.c"

The `safe_create_leading_directories()` function and its relatives are
located in "object-file.c", which is not a good fit as they provide
generic functionality not related to objects at all. Move them into
"path.c", which already hosts `safe_create_dir()` and its relative
`safe_create_dir_in_gitdir()`.

"path.c" is free of `the_repository`, but the moved functions depend on
`the_repository` to read the "core.sharedRepository" config. Adapt the
function signature to accept a repository as argument to fix the issue
and adjust callers accordingly.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2025-04-15 11:38:15 +02:00
committed by Junio C Hamano
parent d1fa670de0
commit 1a99fe8010
27 changed files with 173 additions and 167 deletions

5
dir.c
View File

@@ -17,7 +17,6 @@
#include "environment.h"
#include "gettext.h"
#include "name-hash.h"
#include "object-file.h"
#include "object-store-ll.h"
#include "path.h"
#include "refs.h"
@@ -4063,12 +4062,12 @@ void connect_work_tree_and_git_dir(const char *work_tree_,
/* Prepare .git file */
strbuf_addf(&gitfile_sb, "%s/.git", work_tree_);
if (safe_create_leading_directories_const(gitfile_sb.buf))
if (safe_create_leading_directories_const(the_repository, gitfile_sb.buf))
die(_("could not create directories for %s"), gitfile_sb.buf);
/* Prepare config file */
strbuf_addf(&cfg_sb, "%s/config", git_dir_);
if (safe_create_leading_directories_const(cfg_sb.buf))
if (safe_create_leading_directories_const(the_repository, cfg_sb.buf))
die(_("could not create directories for %s"), cfg_sb.buf);
git_dir = real_pathdup(git_dir_, 1);