From 688a0a751e9ee032be9fb70d7d63220bc85acae1 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Tue, 27 Feb 2024 01:16:09 -0800 Subject: commit: avoid redundant scissor line with --cleanup=scissors -v `git commit --cleanup=scissors -v` prints two scissors lines: one at the start of the comment lines, and the other right before the diff. This is redundant, and pushes the diff further down in the user's editor than it needs to be. Make wt_status_add_cut_line() remember if it has added a cut line before, and avoid adding a redundant one. Add a test for this. Signed-off-by: Josh Triplett Signed-off-by: Junio C Hamano --- builtin/commit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'builtin/commit.c') diff --git a/builtin/commit.c b/builtin/commit.c index 65196a2827..7860af552e 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -926,7 +926,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, if (whence != FROM_COMMIT) { if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS && !merge_contains_scissors) - wt_status_add_cut_line(s->fp); + wt_status_add_cut_line(s); status_printf_ln( s, GIT_COLOR_NORMAL, whence == FROM_MERGE ? @@ -947,7 +947,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, status_printf(s, GIT_COLOR_NORMAL, hint_cleanup_all, comment_line_char); else if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) { if (whence == FROM_COMMIT && !merge_contains_scissors) - wt_status_add_cut_line(s->fp); + wt_status_add_cut_line(s); } else /* COMMIT_MSG_CLEANUP_SPACE, that is. */ status_printf(s, GIT_COLOR_NORMAL, hint_cleanup_space, comment_line_char); -- cgit v1.3 From e90cc075cc43f2bf08a8963ae84d3e4da50ebfc3 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Tue, 27 Feb 2024 01:17:36 -0800 Subject: 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 Signed-off-by: Junio C Hamano --- builtin/commit.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'builtin/commit.c') diff --git a/builtin/commit.c b/builtin/commit.c index 7860af552e..ef4cb92fc7 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -737,7 +737,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix, const char *hook_arg2 = NULL; int clean_message_contents = (cleanup_mode != COMMIT_MSG_CLEANUP_NONE); int old_display_comment_prefix; - int merge_contains_scissors = 0; int invoked_hook; /* 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, wt_status_locate_end(sb.buf + merge_msg_start, sb.len - merge_msg_start) < sb.len - merge_msg_start) - merge_contains_scissors = 1; + s->added_cut_line = 1; } else if (!stat(git_path_squash_msg(the_repository), &statbuf)) { if (strbuf_read_file(&sb, git_path_squash_msg(the_repository), 0) < 0) die_errno(_("could not read SQUASH_MSG")); @@ -924,8 +923,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, " yourself if you want to.\n" "An empty message aborts the commit.\n"); if (whence != FROM_COMMIT) { - if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS && - !merge_contains_scissors) + if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) wt_status_add_cut_line(s); status_printf_ln( s, GIT_COLOR_NORMAL, @@ -946,7 +944,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, if (cleanup_mode == COMMIT_MSG_CLEANUP_ALL) status_printf(s, GIT_COLOR_NORMAL, hint_cleanup_all, comment_line_char); else if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) { - if (whence == FROM_COMMIT && !merge_contains_scissors) + if (whence == FROM_COMMIT) wt_status_add_cut_line(s); } else /* COMMIT_MSG_CLEANUP_SPACE, that is. */ status_printf(s, GIT_COLOR_NORMAL, hint_cleanup_space, comment_line_char); -- cgit v1.3