path: drop `git_path_buf()` in favor of `repo_git_path_replace()`

Remove `git_path_buf()` in favor of `repo_git_path_replace()`. The latter does essentially the same, with the only exception that it does not rely on `the_repository` but takes the repo as separate parameter. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Feb 7, 2025 at 12:03 UTC 3859e3965993493defd39cd54a2ab2097957e270
6 files changed +24 -41
builtin/worktree.c
+1 -1
@@ -457,7 +457,7 @@ static int add_worktree(const char *path, const char *refname,
457 BUG("How come '%s' becomes empty after sanitization?", sb.buf);
458 strbuf_reset(&sb);
459 name = sb_name.buf;
460 - git_path_buf(&sb_repo, "worktrees/%s", name);
460 + repo_git_path_replace(the_repository, &sb_repo, "worktrees/%s", name);
461 len = sb_repo.len;
462 if (safe_create_leading_directories_const(sb_repo.buf))
463 die_errno(_("could not create leading directories of '%s'"),
compat/precompose_utf8.c
+3 -3
@@ -50,15 +50,15 @@ void probe_utf8_pathname_composition(void)
50 int output_fd;
51 if (precomposed_unicode != -1)
52 return; /* We found it defined in the global config, respect it */
53 - git_path_buf(&path, "%s", auml_nfc);
53 + repo_git_path_replace(the_repository, &path, "%s", auml_nfc);
54 output_fd = open(path.buf, O_CREAT|O_EXCL|O_RDWR, 0600);
55 if (output_fd >= 0) {
56 close(output_fd);
57 - git_path_buf(&path, "%s", auml_nfd);
57 + repo_git_path_replace(the_repository, &path, "%s", auml_nfd);
58 precomposed_unicode = access(path.buf, R_OK) ? 0 : 1;
59 git_config_set("core.precomposeunicode",
60 precomposed_unicode ? "true" : "false");
61 - git_path_buf(&path, "%s", auml_nfc);
61 + repo_git_path_replace(the_repository, &path, "%s", auml_nfc);
62 if (unlink(path.buf))
63 die_errno(_("failed to unlink '%s'"), path.buf);
64 }
notes-merge.c
+2 -2
@@ -695,7 +695,7 @@ int notes_merge_commit(struct notes_merge_options *o,
695 const char *msg = strstr(buffer, "\n\n");
696 int baselen;
697
698 - git_path_buf(&path, NOTES_MERGE_WORKTREE);
698 + repo_git_path_replace(the_repository, &path, NOTES_MERGE_WORKTREE);
699 if (o->verbosity >= 3)
700 printf("Committing notes in notes merge worktree at %s\n",
701 path.buf);
@@ -757,7 +757,7 @@ int notes_merge_abort(struct notes_merge_options *o)
757 struct strbuf buf = STRBUF_INIT;
758 int ret;
759
760 - git_path_buf(&buf, NOTES_MERGE_WORKTREE);
760 + repo_git_path_replace(the_repository, &buf, NOTES_MERGE_WORKTREE);
761 if (o->verbosity >= 3)
762 printf("Removing notes merge worktree at %s/*\n", buf.buf);
763 ret = remove_dir_recursively(&buf, REMOVE_DIR_KEEP_TOPLEVEL);
object-file.c
+2 -2
@@ -476,14 +476,14 @@ int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
476 * restrictive except to remove write permission.
477 */
478 int mode = 0444;
479 - git_path_buf(temp_filename, "objects/%s", pattern);
479 + repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern);
480 fd = git_mkstemp_mode(temp_filename->buf, mode);
481 if (0 <= fd)
482 return fd;
483
484 /* slow path */
485 /* some mkstemp implementations erase temp_filename on failure */
486 - git_path_buf(temp_filename, "objects/%s", pattern);
486 + repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern);
487 safe_create_leading_directories(temp_filename->buf);
488 return xmkstemp_mode(temp_filename->buf, mode);
489 }
path.h
-16
@@ -256,22 +256,6 @@ static inline const char *git_common_path(const char *fmt, ...)
256 return pathname->buf;
257 }
258
259 -/*
260 - * Construct a path into the main repository's (the_repository) git directory
261 - * and place it in the provided buffer `buf`, the contents of the buffer will
262 - * be overridden.
263 - */
264 -__attribute__((format (printf, 2, 3)))
265 -static inline char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
266 -{
267 - va_list args;
268 - strbuf_reset(buf);
269 - va_start(args, fmt);
270 - repo_git_pathv(the_repository, NULL, buf, fmt, args);
271 - va_end(args);
272 - return buf->buf;
273 -}
274 -
259 /*
260 * Return a statically allocated path into the main repository's
261 * (the_repository) git directory.
setup.c
+16 -17
@@ -2264,7 +2264,7 @@ static int is_reinit(void)
2264 char junk[2];
2265 int ret;
2266
2267 - git_path_buf(&buf, "HEAD");
2267 + repo_git_path_replace(the_repository, &buf, "HEAD");
2268 ret = !access(buf.buf, R_OK) || readlink(buf.buf, junk, sizeof(junk) - 1) != -1;
2269 strbuf_release(&buf);
2270 return ret;
@@ -2316,8 +2316,7 @@ static int create_default_files(const char *template_path,
2316 int init_shared_repository)
2317 {
2318 struct stat st1;
2319 - struct strbuf buf = STRBUF_INIT;
2320 - char *path;
2319 + struct strbuf path = STRBUF_INIT;
2320 int reinit;
2321 int filemode;
2322 const char *work_tree = repo_get_work_tree(the_repository);
@@ -2358,14 +2357,14 @@ static int create_default_files(const char *template_path,
2357 initialize_repository_version(fmt->hash_algo, fmt->ref_storage_format, reinit);
2358
2359 /* Check filemode trustability */
2361 - path = git_path_buf(&buf, "config");
2360 + repo_git_path_replace(the_repository, &path, "config");
2361 filemode = TEST_FILEMODE;
2363 - if (TEST_FILEMODE && !lstat(path, &st1)) {
2362 + if (TEST_FILEMODE && !lstat(path.buf, &st1)) {
2363 struct stat st2;
2365 - filemode = (!chmod(path, st1.st_mode ^ S_IXUSR) &&
2366 - !lstat(path, &st2) &&
2364 + filemode = (!chmod(path.buf, st1.st_mode ^ S_IXUSR) &&
2365 + !lstat(path.buf, &st2) &&
2366 st1.st_mode != st2.st_mode &&
2368 - !chmod(path, st1.st_mode));
2367 + !chmod(path.buf, st1.st_mode));
2368 if (filemode && !reinit && (st1.st_mode & S_IXUSR))
2369 filemode = 0;
2370 }
@@ -2384,24 +2383,24 @@ static int create_default_files(const char *template_path,
2383
2384 if (!reinit) {
2385 /* Check if symlink is supported in the work tree */
2387 - path = git_path_buf(&buf, "tXXXXXX");
2388 - if (!close(xmkstemp(path)) &&
2389 - !unlink(path) &&
2390 - !symlink("testing", path) &&
2391 - !lstat(path, &st1) &&
2386 + repo_git_path_replace(the_repository, &path, "tXXXXXX");
2387 + if (!close(xmkstemp(path.buf)) &&
2388 + !unlink(path.buf) &&
2389 + !symlink("testing", path.buf) &&
2390 + !lstat(path.buf, &st1) &&
2391 S_ISLNK(st1.st_mode))
2393 - unlink(path); /* good */
2392 + unlink(path.buf); /* good */
2393 else
2394 git_config_set("core.symlinks", "false");
2395
2396 /* Check if the filesystem is case-insensitive */
2398 - path = git_path_buf(&buf, "CoNfIg");
2399 - if (!access(path, F_OK))
2397 + repo_git_path_replace(the_repository, &path, "CoNfIg");
2398 + if (!access(path.buf, F_OK))
2399 git_config_set("core.ignorecase", "true");
2400 probe_utf8_pathname_composition();
2401 }
2402
2404 - strbuf_release(&buf);
2403 + strbuf_release(&path);
2404 return reinit;
2405 }
2406