提交 b80f629f 编写于 作者: J Junio C Hamano

Merge branch 'jk/war-on-git-path'

While handy, "git_path()" is a dangerous function to use as a
callsite that uses it safely one day can be broken by changes
to other code that calls it.  Reduction of its use continues.

* jk/war-on-git-path:
  am: drop "dir" parameter from am_state_init
  replace strbuf_addstr(git_path()) with git_path_buf()
  replace xstrdup(git_path(...)) with git_pathdup(...)
  use git_path_* helper functions
  branch: add edit_description() helper
  bisect: add git_path_bisect_terms helper
......@@ -432,6 +432,7 @@ static int read_bisect_refs(void)
static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES")
static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV")
static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS")
static void read_bisect_paths(struct argv_array *array)
{
......@@ -906,7 +907,7 @@ static void show_diff_tree(const char *prefix, struct commit *commit)
void read_bisect_terms(const char **read_bad, const char **read_good)
{
struct strbuf str = STRBUF_INIT;
const char *filename = git_path("BISECT_TERMS");
const char *filename = git_path_bisect_terms();
FILE *fp = fopen(filename, "r");
if (!fp) {
......
......@@ -134,17 +134,15 @@ struct am_state {
};
/**
* Initializes am_state with the default values. The state directory is set to
* dir.
* Initializes am_state with the default values.
*/
static void am_state_init(struct am_state *state, const char *dir)
static void am_state_init(struct am_state *state)
{
int gpgsign;
memset(state, 0, sizeof(*state));
assert(dir);
state->dir = xstrdup(dir);
state->dir = git_pathdup("rebase-apply");
state->prec = 4;
......@@ -2323,7 +2321,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
git_config(git_am_config, NULL);
am_state_init(&state, git_path("rebase-apply"));
am_state_init(&state);
in_progress = am_in_progress(&state);
if (in_progress)
......
......@@ -504,7 +504,7 @@ static void rename_branch(const char *oldname, const char *newname, int force)
strbuf_release(&newsection);
}
static const char edit_description[] = "BRANCH_DESCRIPTION";
static GIT_PATH_FUNC(edit_description, "EDIT_DESCRIPTION")
static int edit_branch_description(const char *branch_name)
{
......@@ -519,9 +519,9 @@ static int edit_branch_description(const char *branch_name)
" %s\n"
"Lines starting with '%c' will be stripped.\n"),
branch_name, comment_line_char);
write_file_buf(git_path(edit_description), buf.buf, buf.len);
write_file_buf(edit_description(), buf.buf, buf.len);
strbuf_reset(&buf);
if (launch_editor(git_path(edit_description), &buf, NULL)) {
if (launch_editor(edit_description(), &buf, NULL)) {
strbuf_release(&buf);
return -1;
}
......
......@@ -821,9 +821,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
"If this is not correct, please remove the file\n"
" %s\n"
"and try again.\n"),
git_path(whence == FROM_MERGE
? "MERGE_HEAD"
: "CHERRY_PICK_HEAD"));
whence == FROM_MERGE ?
git_path_merge_head() :
git_path_cherry_pick_head());
}
fprintf(s->fp, "\n");
......
......@@ -600,8 +600,9 @@ int cmd_config(int argc, const char **argv, const char *prefix)
if (given_config_source.blob)
die("editing blobs is not supported");
git_config(git_default_config, NULL);
config_file = xstrdup(given_config_source.file ?
given_config_source.file : git_path("config"));
config_file = given_config_source.file ?
xstrdup(given_config_source.file) :
git_pathdup("config");
if (use_global_config) {
int fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY, 0666);
if (fd >= 0) {
......
......@@ -332,7 +332,7 @@ static int git_pull_config(const char *var, const char *value, void *cb)
*/
static void get_merge_heads(struct oid_array *merge_heads)
{
const char *filename = git_path("FETCH_HEAD");
const char *filename = git_path_fetch_head();
FILE *fp;
struct strbuf sb = STRBUF_INIT;
struct object_id oid;
......@@ -791,7 +791,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
if (read_cache_unmerged())
die_resolve_conflict("pull");
if (file_exists(git_path("MERGE_HEAD")))
if (file_exists(git_path_merge_head()))
die_conclude_merge();
if (get_oid("HEAD", &orig_head))
......
......@@ -106,8 +106,7 @@ static void prune_worktrees(void)
printf("%s\n", reason.buf);
if (show_only)
continue;
strbuf_reset(&path);
strbuf_addstr(&path, git_path("worktrees/%s", d->d_name));
git_path_buf(&path, "worktrees/%s", d->d_name);
ret = remove_dir_recursively(&path, 0);
if (ret < 0 && errno == ENOTDIR)
ret = unlink(path.buf);
......@@ -215,8 +214,7 @@ static int add_worktree(const char *path, const char *refname,
}
name = worktree_basename(path, &len);
strbuf_addstr(&sb_repo,
git_path("worktrees/%.*s", (int)(path + len - name), name));
git_path_buf(&sb_repo, "worktrees/%.*s", (int)(path + len - name), name);
len = sb_repo.len;
if (safe_create_leading_directories_const(sb_repo.buf))
die_errno(_("could not create leading directories of '%s'"),
......
......@@ -3202,7 +3202,7 @@ static char* make_fast_import_path(const char *path)
{
if (!relative_marks_paths || is_absolute_path(path))
return xstrdup(path);
return xstrdup(git_path("info/fast-import/%s", path));
return git_pathdup("info/fast-import/%s", path);
}
static void option_import_marks(const char *marks,
......
......@@ -676,7 +676,7 @@ int notes_merge_commit(struct notes_merge_options *o,
const char *msg = strstr(buffer, "\n\n");
int baselen;
strbuf_addstr(&path, git_path(NOTES_MERGE_WORKTREE));
git_path_buf(&path, NOTES_MERGE_WORKTREE);
if (o->verbosity >= 3)
printf("Committing notes in notes merge worktree at %s\n",
path.buf);
......@@ -741,7 +741,7 @@ int notes_merge_abort(struct notes_merge_options *o)
struct strbuf buf = STRBUF_INIT;
int ret;
strbuf_addstr(&buf, git_path(NOTES_MERGE_WORKTREE));
git_path_buf(&buf, NOTES_MERGE_WORKTREE);
if (o->verbosity >= 3)
printf("Removing notes merge worktree at %s/*\n", buf.buf);
ret = remove_dir_recursively(&buf, REMOVE_DIR_KEEP_TOPLEVEL);
......
......@@ -1065,12 +1065,12 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
flags |= CLEANUP_MSG;
msg_file = rebase_path_fixup_msg();
} else {
const char *dest = git_path("SQUASH_MSG");
const char *dest = git_path_squash_msg();
unlink(dest);
if (copy_file(dest, rebase_path_squash_msg(), 0666))
return error(_("could not rename '%s' to '%s'"),
rebase_path_squash_msg(), dest);
unlink(git_path("MERGE_MSG"));
unlink(git_path_merge_msg());
msg_file = dest;
flags |= EDIT_MSG;
}
......@@ -1820,10 +1820,10 @@ static int error_failed_squash(struct commit *commit,
return error(_("could not rename '%s' to '%s'"),
rebase_path_squash_msg(), rebase_path_message());
unlink(rebase_path_fixup_msg());
unlink(git_path("MERGE_MSG"));
if (copy_file(git_path("MERGE_MSG"), rebase_path_message(), 0666))
unlink(git_path_merge_msg());
if (copy_file(git_path_merge_msg(), rebase_path_message(), 0666))
return error(_("could not copy '%s' to '%s'"),
rebase_path_message(), git_path("MERGE_MSG"));
rebase_path_message(), git_path_merge_msg());
return error_with_patch(commit, subject, subject_len, opts, 1, 0);
}
......@@ -2167,7 +2167,7 @@ static int commit_staged_changes(struct replay_opts *opts)
if (has_unstaged_changes(1))
return error(_("cannot rebase: You have unstaged changes."));
if (!has_uncommitted_changes(0)) {
const char *cherry_pick_head = git_path("CHERRY_PICK_HEAD");
const char *cherry_pick_head = git_path_cherry_pick_head();
if (file_exists(cherry_pick_head) && unlink(cherry_pick_head))
return error(_("could not remove CHERRY_PICK_HEAD"));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册