use git_path_* helper functions

Long ago we added functions like git_path_merge_msg() to replace the more dangerous git_path("MERGE_MSG"). Over time some new calls to the latter have crept it. Let's convert them to use the safer form. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Apr 20, 2017 at 17:08 UTC ca03e0670c3ba71400b0f5ed199b045481efdb1e
3 files changed +11 -11
builtin/commit.c
+3 -3
@@ -821,9 +821,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
821 "If this is not correct, please remove the file\n"
822 " %s\n"
823 "and try again.\n"),
824 - git_path(whence == FROM_MERGE
825 - ? "MERGE_HEAD"
826 - : "CHERRY_PICK_HEAD"));
824 + whence == FROM_MERGE ?
825 + git_path_merge_head() :
826 + git_path_cherry_pick_head());
827 }
828
829 fprintf(s->fp, "\n");
builtin/pull.c
+2 -2
@@ -332,7 +332,7 @@ static int git_pull_config(const char *var, const char *value, void *cb)
332 */
333 static void get_merge_heads(struct sha1_array *merge_heads)
334 {
335 - const char *filename = git_path("FETCH_HEAD");
335 + const char *filename = git_path_fetch_head();
336 FILE *fp;
337 struct strbuf sb = STRBUF_INIT;
338 unsigned char sha1[GIT_SHA1_RAWSZ];
@@ -791,7 +791,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
791 if (read_cache_unmerged())
792 die_resolve_conflict("pull");
793
794 - if (file_exists(git_path("MERGE_HEAD")))
794 + if (file_exists(git_path_merge_head()))
795 die_conclude_merge();
796
797 if (get_sha1("HEAD", orig_head))
sequencer.c
+6 -6
@@ -1057,12 +1057,12 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
1057 cleanup_commit_message = 1;
1058 msg_file = rebase_path_fixup_msg();
1059 } else {
1060 - const char *dest = git_path("SQUASH_MSG");
1060 + const char *dest = git_path_squash_msg();
1061 unlink(dest);
1062 if (copy_file(dest, rebase_path_squash_msg(), 0666))
1063 return error(_("could not rename '%s' to '%s'"),
1064 rebase_path_squash_msg(), dest);
1065 - unlink(git_path("MERGE_MSG"));
1065 + unlink(git_path_merge_msg());
1066 msg_file = dest;
1067 edit = 1;
1068 }
@@ -1812,10 +1812,10 @@ static int error_failed_squash(struct commit *commit,
1812 return error(_("could not rename '%s' to '%s'"),
1813 rebase_path_squash_msg(), rebase_path_message());
1814 unlink(rebase_path_fixup_msg());
1815 - unlink(git_path("MERGE_MSG"));
1816 - if (copy_file(git_path("MERGE_MSG"), rebase_path_message(), 0666))
1815 + unlink(git_path_merge_msg());
1816 + if (copy_file(git_path_merge_msg(), rebase_path_message(), 0666))
1817 return error(_("could not copy '%s' to '%s'"),
1818 - rebase_path_message(), git_path("MERGE_MSG"));
1818 + rebase_path_message(), git_path_merge_msg());
1819 return error_with_patch(commit, subject, subject_len, opts, 1, 0);
1820 }
1821
@@ -2158,7 +2158,7 @@ static int commit_staged_changes(struct replay_opts *opts)
2158 if (has_unstaged_changes(1))
2159 return error(_("cannot rebase: You have unstaged changes."));
2160 if (!has_uncommitted_changes(0)) {
2161 - const char *cherry_pick_head = git_path("CHERRY_PICK_HEAD");
2161 + const char *cherry_pick_head = git_path_cherry_pick_head();
2162
2163 if (file_exists(cherry_pick_head) && unlink(cherry_pick_head))
2164 return error(_("could not remove CHERRY_PICK_HEAD"));