builtin/commit.c: memoize git-path for COMMIT_EDITMSG
This is a follow up commit for f932729c (memoize common git-path "constant" files, 10-Aug-2015). The many function calls to git_path() are replaced by git_path_commit_editmsg() and which thus eliminates the need to repeatedly compute the location of "COMMIT_EDITMSG". Mentored-by: Lars Schneider <larsxschneider@gmail.com> Mentored-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pranit Bauva committed
May 25, 2016 at 00:49 UTC
e51b0dfc978649b9f0e3a594030810cc472a8b08
1 file changed
+8
-7
builtin/commit.c
+8
-7
@@ -92,8 +92,9 @@ N_("If you wish to skip this commit, use:\n"
92
"Then \"git cherry-pick --continue\" will resume cherry-picking\n"
93
"the remaining commits.\n");
94
95
+static GIT_PATH_FUNC(git_path_commit_editmsg, "COMMIT_EDITMSG")
96
+
97
static const char *use_message_buffer;
96
-static const char commit_editmsg[] = "COMMIT_EDITMSG";
98
static struct lock_file index_lock; /* real index */
99
static struct lock_file false_lock; /* used only for partial commits */
100
static enum {
@@ -772,9 +773,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
773
hook_arg2 = "";
774
}
775
775
- s->fp = fopen_for_writing(git_path(commit_editmsg));
776
+ s->fp = fopen_for_writing(git_path_commit_editmsg());
777
if (s->fp == NULL)
777
- die_errno(_("could not open '%s'"), git_path(commit_editmsg));
778
+ die_errno(_("could not open '%s'"), git_path_commit_editmsg());
779
780
/* Ignore status.displayCommentPrefix: we do need comments in COMMIT_EDITMSG. */
781
old_display_comment_prefix = s->display_comment_prefix;
@@ -951,7 +952,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
952
}
953
954
if (run_commit_hook(use_editor, index_file, "prepare-commit-msg",
954
- git_path(commit_editmsg), hook_arg1, hook_arg2, NULL))
955
+ git_path_commit_editmsg(), hook_arg1, hook_arg2, NULL))
956
return 0;
957
958
if (use_editor) {
@@ -959,7 +960,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
960
const char *env[2] = { NULL };
961
env[0] = index;
962
snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file);
962
- if (launch_editor(git_path(commit_editmsg), NULL, env)) {
963
+ if (launch_editor(git_path_commit_editmsg(), NULL, env)) {
964
fprintf(stderr,
965
_("Please supply the message using either -m or -F option.\n"));
966
exit(1);
@@ -967,7 +968,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
968
}
969
970
if (!no_verify &&
970
- run_commit_hook(use_editor, index_file, "commit-msg", git_path(commit_editmsg), NULL)) {
971
+ run_commit_hook(use_editor, index_file, "commit-msg", git_path_commit_editmsg(), NULL)) {
972
return 0;
973
}
974
@@ -1738,7 +1739,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1739
1740
/* Finally, get the commit message */
1741
strbuf_reset(&sb);
1741
- if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {
1742
+ if (strbuf_read_file(&sb, git_path_commit_editmsg(), 0) < 0) {
1743
int saved_errno = errno;
1744
rollback_index_files();
1745
die(_("could not read commit message: %s"), strerror(saved_errno));