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>
This commit is contained in:

committed by
Junio C Hamano

parent
bba59f58a4
commit
3859e39659
@ -457,7 +457,7 @@ static int add_worktree(const char *path, const char *refname,
|
|||||||
BUG("How come '%s' becomes empty after sanitization?", sb.buf);
|
BUG("How come '%s' becomes empty after sanitization?", sb.buf);
|
||||||
strbuf_reset(&sb);
|
strbuf_reset(&sb);
|
||||||
name = sb_name.buf;
|
name = sb_name.buf;
|
||||||
git_path_buf(&sb_repo, "worktrees/%s", name);
|
repo_git_path_replace(the_repository, &sb_repo, "worktrees/%s", name);
|
||||||
len = sb_repo.len;
|
len = sb_repo.len;
|
||||||
if (safe_create_leading_directories_const(sb_repo.buf))
|
if (safe_create_leading_directories_const(sb_repo.buf))
|
||||||
die_errno(_("could not create leading directories of '%s'"),
|
die_errno(_("could not create leading directories of '%s'"),
|
||||||
|
@ -50,15 +50,15 @@ void probe_utf8_pathname_composition(void)
|
|||||||
int output_fd;
|
int output_fd;
|
||||||
if (precomposed_unicode != -1)
|
if (precomposed_unicode != -1)
|
||||||
return; /* We found it defined in the global config, respect it */
|
return; /* We found it defined in the global config, respect it */
|
||||||
git_path_buf(&path, "%s", auml_nfc);
|
repo_git_path_replace(the_repository, &path, "%s", auml_nfc);
|
||||||
output_fd = open(path.buf, O_CREAT|O_EXCL|O_RDWR, 0600);
|
output_fd = open(path.buf, O_CREAT|O_EXCL|O_RDWR, 0600);
|
||||||
if (output_fd >= 0) {
|
if (output_fd >= 0) {
|
||||||
close(output_fd);
|
close(output_fd);
|
||||||
git_path_buf(&path, "%s", auml_nfd);
|
repo_git_path_replace(the_repository, &path, "%s", auml_nfd);
|
||||||
precomposed_unicode = access(path.buf, R_OK) ? 0 : 1;
|
precomposed_unicode = access(path.buf, R_OK) ? 0 : 1;
|
||||||
git_config_set("core.precomposeunicode",
|
git_config_set("core.precomposeunicode",
|
||||||
precomposed_unicode ? "true" : "false");
|
precomposed_unicode ? "true" : "false");
|
||||||
git_path_buf(&path, "%s", auml_nfc);
|
repo_git_path_replace(the_repository, &path, "%s", auml_nfc);
|
||||||
if (unlink(path.buf))
|
if (unlink(path.buf))
|
||||||
die_errno(_("failed to unlink '%s'"), path.buf);
|
die_errno(_("failed to unlink '%s'"), path.buf);
|
||||||
}
|
}
|
||||||
|
@ -695,7 +695,7 @@ int notes_merge_commit(struct notes_merge_options *o,
|
|||||||
const char *msg = strstr(buffer, "\n\n");
|
const char *msg = strstr(buffer, "\n\n");
|
||||||
int baselen;
|
int baselen;
|
||||||
|
|
||||||
git_path_buf(&path, NOTES_MERGE_WORKTREE);
|
repo_git_path_replace(the_repository, &path, NOTES_MERGE_WORKTREE);
|
||||||
if (o->verbosity >= 3)
|
if (o->verbosity >= 3)
|
||||||
printf("Committing notes in notes merge worktree at %s\n",
|
printf("Committing notes in notes merge worktree at %s\n",
|
||||||
path.buf);
|
path.buf);
|
||||||
@ -757,7 +757,7 @@ int notes_merge_abort(struct notes_merge_options *o)
|
|||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
git_path_buf(&buf, NOTES_MERGE_WORKTREE);
|
repo_git_path_replace(the_repository, &buf, NOTES_MERGE_WORKTREE);
|
||||||
if (o->verbosity >= 3)
|
if (o->verbosity >= 3)
|
||||||
printf("Removing notes merge worktree at %s/*\n", buf.buf);
|
printf("Removing notes merge worktree at %s/*\n", buf.buf);
|
||||||
ret = remove_dir_recursively(&buf, REMOVE_DIR_KEEP_TOPLEVEL);
|
ret = remove_dir_recursively(&buf, REMOVE_DIR_KEEP_TOPLEVEL);
|
||||||
|
@ -476,14 +476,14 @@ int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
|
|||||||
* restrictive except to remove write permission.
|
* restrictive except to remove write permission.
|
||||||
*/
|
*/
|
||||||
int mode = 0444;
|
int mode = 0444;
|
||||||
git_path_buf(temp_filename, "objects/%s", pattern);
|
repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern);
|
||||||
fd = git_mkstemp_mode(temp_filename->buf, mode);
|
fd = git_mkstemp_mode(temp_filename->buf, mode);
|
||||||
if (0 <= fd)
|
if (0 <= fd)
|
||||||
return fd;
|
return fd;
|
||||||
|
|
||||||
/* slow path */
|
/* slow path */
|
||||||
/* some mkstemp implementations erase temp_filename on failure */
|
/* some mkstemp implementations erase temp_filename on failure */
|
||||||
git_path_buf(temp_filename, "objects/%s", pattern);
|
repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern);
|
||||||
safe_create_leading_directories(temp_filename->buf);
|
safe_create_leading_directories(temp_filename->buf);
|
||||||
return xmkstemp_mode(temp_filename->buf, mode);
|
return xmkstemp_mode(temp_filename->buf, mode);
|
||||||
}
|
}
|
||||||
|
16
path.h
16
path.h
@ -256,22 +256,6 @@ static inline const char *git_common_path(const char *fmt, ...)
|
|||||||
return pathname->buf;
|
return pathname->buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Construct a path into the main repository's (the_repository) git directory
|
|
||||||
* and place it in the provided buffer `buf`, the contents of the buffer will
|
|
||||||
* be overridden.
|
|
||||||
*/
|
|
||||||
__attribute__((format (printf, 2, 3)))
|
|
||||||
static inline char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
strbuf_reset(buf);
|
|
||||||
va_start(args, fmt);
|
|
||||||
repo_git_pathv(the_repository, NULL, buf, fmt, args);
|
|
||||||
va_end(args);
|
|
||||||
return buf->buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return a statically allocated path into the main repository's
|
* Return a statically allocated path into the main repository's
|
||||||
* (the_repository) git directory.
|
* (the_repository) git directory.
|
||||||
|
33
setup.c
33
setup.c
@ -2264,7 +2264,7 @@ static int is_reinit(void)
|
|||||||
char junk[2];
|
char junk[2];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
git_path_buf(&buf, "HEAD");
|
repo_git_path_replace(the_repository, &buf, "HEAD");
|
||||||
ret = !access(buf.buf, R_OK) || readlink(buf.buf, junk, sizeof(junk) - 1) != -1;
|
ret = !access(buf.buf, R_OK) || readlink(buf.buf, junk, sizeof(junk) - 1) != -1;
|
||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
return ret;
|
return ret;
|
||||||
@ -2316,8 +2316,7 @@ static int create_default_files(const char *template_path,
|
|||||||
int init_shared_repository)
|
int init_shared_repository)
|
||||||
{
|
{
|
||||||
struct stat st1;
|
struct stat st1;
|
||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf path = STRBUF_INIT;
|
||||||
char *path;
|
|
||||||
int reinit;
|
int reinit;
|
||||||
int filemode;
|
int filemode;
|
||||||
const char *work_tree = repo_get_work_tree(the_repository);
|
const char *work_tree = repo_get_work_tree(the_repository);
|
||||||
@ -2358,14 +2357,14 @@ static int create_default_files(const char *template_path,
|
|||||||
initialize_repository_version(fmt->hash_algo, fmt->ref_storage_format, reinit);
|
initialize_repository_version(fmt->hash_algo, fmt->ref_storage_format, reinit);
|
||||||
|
|
||||||
/* Check filemode trustability */
|
/* Check filemode trustability */
|
||||||
path = git_path_buf(&buf, "config");
|
repo_git_path_replace(the_repository, &path, "config");
|
||||||
filemode = TEST_FILEMODE;
|
filemode = TEST_FILEMODE;
|
||||||
if (TEST_FILEMODE && !lstat(path, &st1)) {
|
if (TEST_FILEMODE && !lstat(path.buf, &st1)) {
|
||||||
struct stat st2;
|
struct stat st2;
|
||||||
filemode = (!chmod(path, st1.st_mode ^ S_IXUSR) &&
|
filemode = (!chmod(path.buf, st1.st_mode ^ S_IXUSR) &&
|
||||||
!lstat(path, &st2) &&
|
!lstat(path.buf, &st2) &&
|
||||||
st1.st_mode != st2.st_mode &&
|
st1.st_mode != st2.st_mode &&
|
||||||
!chmod(path, st1.st_mode));
|
!chmod(path.buf, st1.st_mode));
|
||||||
if (filemode && !reinit && (st1.st_mode & S_IXUSR))
|
if (filemode && !reinit && (st1.st_mode & S_IXUSR))
|
||||||
filemode = 0;
|
filemode = 0;
|
||||||
}
|
}
|
||||||
@ -2384,24 +2383,24 @@ static int create_default_files(const char *template_path,
|
|||||||
|
|
||||||
if (!reinit) {
|
if (!reinit) {
|
||||||
/* Check if symlink is supported in the work tree */
|
/* Check if symlink is supported in the work tree */
|
||||||
path = git_path_buf(&buf, "tXXXXXX");
|
repo_git_path_replace(the_repository, &path, "tXXXXXX");
|
||||||
if (!close(xmkstemp(path)) &&
|
if (!close(xmkstemp(path.buf)) &&
|
||||||
!unlink(path) &&
|
!unlink(path.buf) &&
|
||||||
!symlink("testing", path) &&
|
!symlink("testing", path.buf) &&
|
||||||
!lstat(path, &st1) &&
|
!lstat(path.buf, &st1) &&
|
||||||
S_ISLNK(st1.st_mode))
|
S_ISLNK(st1.st_mode))
|
||||||
unlink(path); /* good */
|
unlink(path.buf); /* good */
|
||||||
else
|
else
|
||||||
git_config_set("core.symlinks", "false");
|
git_config_set("core.symlinks", "false");
|
||||||
|
|
||||||
/* Check if the filesystem is case-insensitive */
|
/* Check if the filesystem is case-insensitive */
|
||||||
path = git_path_buf(&buf, "CoNfIg");
|
repo_git_path_replace(the_repository, &path, "CoNfIg");
|
||||||
if (!access(path, F_OK))
|
if (!access(path.buf, F_OK))
|
||||||
git_config_set("core.ignorecase", "true");
|
git_config_set("core.ignorecase", "true");
|
||||||
probe_utf8_pathname_composition();
|
probe_utf8_pathname_composition();
|
||||||
}
|
}
|
||||||
|
|
||||||
strbuf_release(&buf);
|
strbuf_release(&path);
|
||||||
return reinit;
|
return reinit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user