Skip to content

Commit 3859e39

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bba59f5 commit 3859e39

File tree

6 files changed

+24
-41
lines changed

6 files changed

+24
-41
lines changed

builtin/worktree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ static int add_worktree(const char *path, const char *refname,
457457
BUG("How come '%s' becomes empty after sanitization?", sb.buf);
458458
strbuf_reset(&sb);
459459
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);
461461
len = sb_repo.len;
462462
if (safe_create_leading_directories_const(sb_repo.buf))
463463
die_errno(_("could not create leading directories of '%s'"),

compat/precompose_utf8.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ void probe_utf8_pathname_composition(void)
5050
int output_fd;
5151
if (precomposed_unicode != -1)
5252
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);
5454
output_fd = open(path.buf, O_CREAT|O_EXCL|O_RDWR, 0600);
5555
if (output_fd >= 0) {
5656
close(output_fd);
57-
git_path_buf(&path, "%s", auml_nfd);
57+
repo_git_path_replace(the_repository, &path, "%s", auml_nfd);
5858
precomposed_unicode = access(path.buf, R_OK) ? 0 : 1;
5959
git_config_set("core.precomposeunicode",
6060
precomposed_unicode ? "true" : "false");
61-
git_path_buf(&path, "%s", auml_nfc);
61+
repo_git_path_replace(the_repository, &path, "%s", auml_nfc);
6262
if (unlink(path.buf))
6363
die_errno(_("failed to unlink '%s'"), path.buf);
6464
}

notes-merge.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ int notes_merge_commit(struct notes_merge_options *o,
695695
const char *msg = strstr(buffer, "\n\n");
696696
int baselen;
697697

698-
git_path_buf(&path, NOTES_MERGE_WORKTREE);
698+
repo_git_path_replace(the_repository, &path, NOTES_MERGE_WORKTREE);
699699
if (o->verbosity >= 3)
700700
printf("Committing notes in notes merge worktree at %s\n",
701701
path.buf);
@@ -757,7 +757,7 @@ int notes_merge_abort(struct notes_merge_options *o)
757757
struct strbuf buf = STRBUF_INIT;
758758
int ret;
759759

760-
git_path_buf(&buf, NOTES_MERGE_WORKTREE);
760+
repo_git_path_replace(the_repository, &buf, NOTES_MERGE_WORKTREE);
761761
if (o->verbosity >= 3)
762762
printf("Removing notes merge worktree at %s/*\n", buf.buf);
763763
ret = remove_dir_recursively(&buf, REMOVE_DIR_KEEP_TOPLEVEL);

object-file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,14 +476,14 @@ int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
476476
* restrictive except to remove write permission.
477477
*/
478478
int mode = 0444;
479-
git_path_buf(temp_filename, "objects/%s", pattern);
479+
repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern);
480480
fd = git_mkstemp_mode(temp_filename->buf, mode);
481481
if (0 <= fd)
482482
return fd;
483483

484484
/* slow path */
485485
/* 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);
487487
safe_create_leading_directories(temp_filename->buf);
488488
return xmkstemp_mode(temp_filename->buf, mode);
489489
}

path.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -256,22 +256,6 @@ static inline const char *git_common_path(const char *fmt, ...)
256256
return pathname->buf;
257257
}
258258

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-
275259
/*
276260
* Return a statically allocated path into the main repository's
277261
* (the_repository) git directory.

setup.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,7 +2264,7 @@ static int is_reinit(void)
22642264
char junk[2];
22652265
int ret;
22662266

2267-
git_path_buf(&buf, "HEAD");
2267+
repo_git_path_replace(the_repository, &buf, "HEAD");
22682268
ret = !access(buf.buf, R_OK) || readlink(buf.buf, junk, sizeof(junk) - 1) != -1;
22692269
strbuf_release(&buf);
22702270
return ret;
@@ -2316,8 +2316,7 @@ static int create_default_files(const char *template_path,
23162316
int init_shared_repository)
23172317
{
23182318
struct stat st1;
2319-
struct strbuf buf = STRBUF_INIT;
2320-
char *path;
2319+
struct strbuf path = STRBUF_INIT;
23212320
int reinit;
23222321
int filemode;
23232322
const char *work_tree = repo_get_work_tree(the_repository);
@@ -2358,14 +2357,14 @@ static int create_default_files(const char *template_path,
23582357
initialize_repository_version(fmt->hash_algo, fmt->ref_storage_format, reinit);
23592358

23602359
/* Check filemode trustability */
2361-
path = git_path_buf(&buf, "config");
2360+
repo_git_path_replace(the_repository, &path, "config");
23622361
filemode = TEST_FILEMODE;
2363-
if (TEST_FILEMODE && !lstat(path, &st1)) {
2362+
if (TEST_FILEMODE && !lstat(path.buf, &st1)) {
23642363
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) &&
23672366
st1.st_mode != st2.st_mode &&
2368-
!chmod(path, st1.st_mode));
2367+
!chmod(path.buf, st1.st_mode));
23692368
if (filemode && !reinit && (st1.st_mode & S_IXUSR))
23702369
filemode = 0;
23712370
}
@@ -2384,24 +2383,24 @@ static int create_default_files(const char *template_path,
23842383

23852384
if (!reinit) {
23862385
/* 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) &&
23922391
S_ISLNK(st1.st_mode))
2393-
unlink(path); /* good */
2392+
unlink(path.buf); /* good */
23942393
else
23952394
git_config_set("core.symlinks", "false");
23962395

23972396
/* 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))
24002399
git_config_set("core.ignorecase", "true");
24012400
probe_utf8_pathname_composition();
24022401
}
24032402

2404-
strbuf_release(&buf);
2403+
strbuf_release(&path);
24052404
return reinit;
24062405
}
24072406

0 commit comments

Comments
 (0)