commit: unify logic to avoid multiple scissors lines when merging

prepare_to_commit has some logic to figure out whether merge already added a scissors line, and therefore it shouldn't add another. Now that wt_status_add_cut_line has built-in state for whether it has already added a previous line, just set that state instead, and then remove that condition from subsequent calls to wt_status_add_cut_line. Signed-off-by: Josh Triplett <josh@joshtriplett.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Josh Triplett committed Feb 27, 2024 at 01:17 UTC e90cc075cc43f2bf08a8963ae84d3e4da50ebfc3
1 file changed +3 -5
builtin/commit.c
+3 -5
@@ -737,7 +737,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
737 const char *hook_arg2 = NULL;
738 int clean_message_contents = (cleanup_mode != COMMIT_MSG_CLEANUP_NONE);
739 int old_display_comment_prefix;
740 - int merge_contains_scissors = 0;
740 int invoked_hook;
741
742 /* This checks and barfs if author is badly specified */
@@ -841,7 +840,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
840 wt_status_locate_end(sb.buf + merge_msg_start,
841 sb.len - merge_msg_start) <
842 sb.len - merge_msg_start)
844 - merge_contains_scissors = 1;
843 + s->added_cut_line = 1;
844 } else if (!stat(git_path_squash_msg(the_repository), &statbuf)) {
845 if (strbuf_read_file(&sb, git_path_squash_msg(the_repository), 0) < 0)
846 die_errno(_("could not read SQUASH_MSG"));
@@ -924,8 +923,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
923 " yourself if you want to.\n"
924 "An empty message aborts the commit.\n");
925 if (whence != FROM_COMMIT) {
927 - if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS &&
928 - !merge_contains_scissors)
926 + if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS)
927 wt_status_add_cut_line(s);
928 status_printf_ln(
929 s, GIT_COLOR_NORMAL,
@@ -946,7 +944,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
944 if (cleanup_mode == COMMIT_MSG_CLEANUP_ALL)
945 status_printf(s, GIT_COLOR_NORMAL, hint_cleanup_all, comment_line_char);
946 else if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) {
949 - if (whence == FROM_COMMIT && !merge_contains_scissors)
947 + if (whence == FROM_COMMIT)
948 wt_status_add_cut_line(s);
949 } else /* COMMIT_MSG_CLEANUP_SPACE, that is. */
950 status_printf(s, GIT_COLOR_NORMAL, hint_cleanup_space, comment_line_char);