Skip to content

Commit a220e2b

Browse files
committed
Merge branch 'pb/commit-editmsg-path' into maint
Code clean-up. * pb/commit-editmsg-path: builtin/commit.c: memoize git-path for COMMIT_EDITMSG
2 parents 8d64216 + e51b0df commit a220e2b

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

builtin/commit.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ N_("If you wish to skip this commit, use:\n"
9292
"Then \"git cherry-pick --continue\" will resume cherry-picking\n"
9393
"the remaining commits.\n");
9494

95+
static GIT_PATH_FUNC(git_path_commit_editmsg, "COMMIT_EDITMSG")
96+
9597
static const char *use_message_buffer;
96-
static const char commit_editmsg[] = "COMMIT_EDITMSG";
9798
static struct lock_file index_lock; /* real index */
9899
static struct lock_file false_lock; /* used only for partial commits */
99100
static enum {
@@ -772,9 +773,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
772773
hook_arg2 = "";
773774
}
774775

775-
s->fp = fopen_for_writing(git_path(commit_editmsg));
776+
s->fp = fopen_for_writing(git_path_commit_editmsg());
776777
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());
778779

779780
/* Ignore status.displayCommentPrefix: we do need comments in COMMIT_EDITMSG. */
780781
old_display_comment_prefix = s->display_comment_prefix;
@@ -951,23 +952,23 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
951952
}
952953

953954
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))
955956
return 0;
956957

957958
if (use_editor) {
958959
char index[PATH_MAX];
959960
const char *env[2] = { NULL };
960961
env[0] = index;
961962
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)) {
963964
fprintf(stderr,
964965
_("Please supply the message using either -m or -F option.\n"));
965966
exit(1);
966967
}
967968
}
968969

969970
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)) {
971972
return 0;
972973
}
973974

@@ -1738,7 +1739,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
17381739

17391740
/* Finally, get the commit message */
17401741
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) {
17421743
int saved_errno = errno;
17431744
rollback_index_files();
17441745
die(_("could not read commit message: %s"), strerror(saved_errno));

0 commit comments

Comments
 (0)