From patchwork Tue Feb 27 09:16:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Triplett X-Patchwork-Id: 13573423 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2BFC9537F3 for ; Tue, 27 Feb 2024 09:16:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.111.4.26 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709025375; cv=none; b=Nwc6KKcoh/rLbnD/34uqPc4d8JTDyJazOFJG4meKjoM+6hk/ZFi0dOXHiEKWniTO4T8FueO6rF8d+LU+bvt9Wb+lxNwvAbG+bW+WtgX3Z8SjWTyN4WIwmasEja7YxP3/m0DftO8oBO4xJ+qtKJc8OcYx8/rc4MJDn+szRFm2R/M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709025375; c=relaxed/simple; bh=OLs0x86k5dQEw6JGJPwQvHkwGZK8WpJVl/TslXlrtkU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bq4KrMg0BW/NC4y4PerpGWWhZsLHMLWPrOsHXCvy9dFkXGJodyweL8+2cWcKuqLXCgBRH5bObJkk0q2v/zCXBsDB+cuV5z0ZeVKqmYFEuTmdFiCYt8XAM2TkbJnsh6Yxwtq2nJtfHPx/b8EaERo/eDkvl2Hs3Hg7pQthT2hn+6w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=joshtriplett.org; spf=pass smtp.mailfrom=joshtriplett.org; dkim=pass (2048-bit key) header.d=joshtriplett.org header.i=@joshtriplett.org header.b=Q0PT5Gan; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=oYp1JmYU; arc=none smtp.client-ip=66.111.4.26 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=joshtriplett.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=joshtriplett.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=joshtriplett.org header.i=@joshtriplett.org header.b="Q0PT5Gan"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="oYp1JmYU" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 415695C00BB; Tue, 27 Feb 2024 04:16:11 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Tue, 27 Feb 2024 04:16:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= joshtriplett.org; h=cc:cc:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1709025371; x=1709111771; bh=wBH8bbXYme91rPp8sZwRt5uXgD8fz6vv9xvlXY6fvcI=; b= Q0PT5GanGj4Wd/odesZ5Vf8HqF/kEJu1nQombVdZ5VxWbQf4Bznx+aLkNXjUYMJ4 R6Sk1Y08R5zCUh8VOwQ6uqwzcy9f4r0KZmXnvicRFVMdeW5UZrX9DY8DRdWMoxNt YNtGt7bvDPacnIh62jr4RVQQavAkbL6aegqNgPFxvVFZak2TSNY6VN71cDt1fq+m 6Q0P6DQ/T4VDi74fKc7PIWuLY+VDItBVOipG2bZknO4jtGTqolTib211s2aI9Ro+ He5SQmilFmCCzlpgfDQP5q9xrdmVdSITzXqzigpWgbpCUyUpNhw4lRJEyeEytfCN MJs6RDPUMtP/An0Bou9McQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1709025371; x=1709111771; bh=wBH8bbXYme91rPp8sZwRt5uXgD8f z6vv9xvlXY6fvcI=; b=oYp1JmYUVEqMuKSFksDwTI5byLyuVPGUI7g6W4v8Gzn5 HqAyFG4lCgca39YpIczMjARN9Soztj+PUnhasLdIqz8nXRiUUmnmIXpTOmn0QIGX jlL2d6STcg35LjLp+5OQ9yynnTCD+EWRB2icu5nq3Le/oA08pZ2UcJMpvNfbfRin R1FZyv9ZS1fyiWeLHk2T+EldI4SJ8nUCXm6AsHz6Wx30eEJfBjb+i/zRivjfow5G PhTTuoyU3fJ5FEeyUHl788fIyFlRkn2Hb1BJIEbP4meUZkow8QeQ/2Dx3PS5x7OO MAN9uxKkj5iESr9B/jzrvftSGa87qmgH46cFydtU0w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrgeeggddtvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvfevuffkfhggtggujgesthdtre dttddtvdenucfhrhhomheplfhoshhhucfvrhhiphhlvghtthcuoehjohhshhesjhhoshhh thhrihhplhgvthhtrdhorhhgqeenucggtffrrghtthgvrhhnpeduieegheeijeeuvdetud efvedtjeefgeeufefghfekgfelfeetteelvddtffetgfenucevlhhushhtvghrufhiiigv pedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehjohhshhesjhhoshhhthhrihhplhgvth htrdhorhhg X-ME-Proxy: Feedback-ID: i83e94755:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 27 Feb 2024 04:16:10 -0500 (EST) Date: Tue, 27 Feb 2024 01:16:09 -0800 From: Josh Triplett To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH v2 1/2] commit: Avoid redundant scissor line with --cleanup=scissors -v Message-ID: <4f97933f173220544a5be2bf05c2bee2b044d2b1.1709024540.git.josh@joshtriplett.org> References: <9c09cea2679e14258720ee63e932e3b9459dbd8c.1708921369.git.josh@joshtriplett.org> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: `git commit --cleanup=scissors -v` currently 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 --- v2: Make wt_status_add_cut_line remember if it has added a cut line, rather than making later callers try to figure out if it has been called before. Add a test. Note that other parts of the code do already try to figure out if the *merge* logic has added scissors already, which is where merge_contains_scissors comes from. Patch 2/2 unifies that machinery. builtin/commit.c | 4 ++-- t/t7502-commit-porcelain.sh | 5 +++++ wt-status.c | 12 ++++++++---- wt-status.h | 3 ++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 6d1fa71676..e0a6d43179 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); diff --git a/t/t7502-commit-porcelain.sh b/t/t7502-commit-porcelain.sh index a87c211d0b..b37e2018a7 100755 --- a/t/t7502-commit-porcelain.sh +++ b/t/t7502-commit-porcelain.sh @@ -736,6 +736,11 @@ test_expect_success 'message shows date when it is explicitly set' ' .git/COMMIT_EDITMSG ' +test_expect_success 'message does not have multiple scissors lines' ' + git commit --cleanup=scissors -v --allow-empty -e -m foo && + test $(grep -c -e "--- >8 ---" .git/COMMIT_EDITMSG) -eq 1 +' + test_expect_success AUTOIDENT 'message shows committer when it is automatic' ' echo >>negative && diff --git a/wt-status.c b/wt-status.c index ea13f5d8db..2d576f7a44 100644 --- a/wt-status.c +++ b/wt-status.c @@ -1108,12 +1108,15 @@ void wt_status_append_cut_line(struct strbuf *buf) strbuf_add_commented_lines(buf, explanation, strlen(explanation), comment_line_char); } -void wt_status_add_cut_line(FILE *fp) +void wt_status_add_cut_line(struct wt_status *s) { struct strbuf buf = STRBUF_INIT; + if (s->added_cut_line) + return; + s->added_cut_line = 1; wt_status_append_cut_line(&buf); - fputs(buf.buf, fp); + fputs(buf.buf, s->fp); strbuf_release(&buf); } @@ -1144,11 +1147,12 @@ static void wt_longstatus_print_verbose(struct wt_status *s) * file (and even the "auto" setting won't work, since it * will have checked isatty on stdout). But we then do want * to insert the scissor line here to reliably remove the - * diff before committing. + * diff before committing, if we didn't already include one + * before. */ if (s->fp != stdout) { rev.diffopt.use_color = 0; - wt_status_add_cut_line(s->fp); + wt_status_add_cut_line(s); } if (s->verbose > 1 && s->committable) { /* print_updated() printed a header, so do we */ diff --git a/wt-status.h b/wt-status.h index 819dcad723..5e99ba4707 100644 --- a/wt-status.h +++ b/wt-status.h @@ -130,6 +130,7 @@ struct wt_status { int rename_score; int rename_limit; enum wt_status_format status_format; + unsigned char added_cut_line; /* boolean */ struct wt_status_state state; struct object_id oid_commit; /* when not Initial */ @@ -147,7 +148,7 @@ struct wt_status { size_t wt_status_locate_end(const char *s, size_t len); void wt_status_append_cut_line(struct strbuf *buf); -void wt_status_add_cut_line(FILE *fp); +void wt_status_add_cut_line(struct wt_status *s); void wt_status_prepare(struct repository *r, struct wt_status *s); void wt_status_print(struct wt_status *s); void wt_status_collect(struct wt_status *s); From patchwork Tue Feb 27 09:17:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Triplett X-Patchwork-Id: 13573424 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB178135A6A for ; Tue, 27 Feb 2024 09:17:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.111.4.26 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709025461; cv=none; b=FnmRvN8eLjtBScm+Kgt/JUDnBO5NnQpJUgVwg1rmeAxcy+hORdzzdgUNSojylTtFh3U059K8bGuioSvNGFOPl/2cnppN06WbynhfutJBcRie0RNkREqxbmfpo/ZCJD1eBbvdBWgMxAeNUNFSmTfBb61SEqcS6ON9SBqMx4+H1wM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709025461; c=relaxed/simple; bh=gJzYYURtOPWrw4NO2nGwgewlQXqmE4MmIfLPpJykbaI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JlcLtPzLz6pc4MT2dVjsSfOBvJ5/fb+Bkru1+Xwk3z04KnLjv1RPD9OtBkC2LYgwufr+xb6T44ETdPVBy9BkSX132886hcn8LljxzYyKcfO7EvfaQJO89BlklDGxcwNl16SQnKsMJqbbr0oJKPKGLvmrQRoiF3TjGqUDTT5q1cE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=joshtriplett.org; spf=pass smtp.mailfrom=joshtriplett.org; dkim=pass (2048-bit key) header.d=joshtriplett.org header.i=@joshtriplett.org header.b=eQtk91p5; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=aznaYZh2; arc=none smtp.client-ip=66.111.4.26 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=joshtriplett.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=joshtriplett.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=joshtriplett.org header.i=@joshtriplett.org header.b="eQtk91p5"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="aznaYZh2" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 118DC5C00BC; Tue, 27 Feb 2024 04:17:38 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 27 Feb 2024 04:17:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= joshtriplett.org; h=cc:cc:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1709025458; x=1709111858; bh=temUcWyBzm3OjpdyHumKRCKV8CPbF7DI39UrSJPSQpA=; b= eQtk91p530f58Fic8HP/8PdbY9BR9S8PgP//IdGnRZkazEVy96cSQubPoMIQgbGv 0qgUpQZORN9n0144kSHL2ZnxYJQ0L3ujz8eH66GEjqoYyCEM/DwDJsQAkiLlMO4I wT9RLi+YA2SbJ34z2VT5WgsC1jUwswhjRbCwT7UMVwk/iYTC0YKxHiB5NQBC1gmM GC2G3pEQziuYLGyvxKgrA2KamGW3nidhS8qxNVhLXUDm5lhgneRn/wFD75BiFrga BLPjtqgUoTb1u//nLVLlyeED6E+H7n8WQf8zjzjtlkb+R9iETqAv87xFaxTt/K99 WsibSlO6IlOTZ67/qPd2ug== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1709025458; x=1709111858; bh=temUcWyBzm3OjpdyHumKRCKV8CPb F7DI39UrSJPSQpA=; b=aznaYZh2RClmtpB6Z0ZCJ/suV0nM7I6XBm9MemDqrFds gxtgkoDrIWKZZ8ZjqN39yqbQmOeEI6ZW8ir1emrgHozEXXb5Vpajt7FVTTWEd7kf YJW9rt9vk2XF2FJxzXHU3RYU01hT5annaxwGMh6UeJZ1RI8uVpYoTZ28+8Mwj9fB r3tqhBpW1s7RAkir8W3Ac6lPm4K1SA5yzlYpR8XkIoNsiXqARRd1PWC4XioEopii BuQCWMZ6tqYBrHqs8RnS7Rvhq8ip2bgXV7Eud21Kuf47uBog7BxS4txLiAbLg0a5 KquOyIduvh211gSo7w1PEpesFemhAM/L6XWNHCI9bw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrgeeggddtvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvfevuffkfhggtggujgesthdtre dttddtvdenucfhrhhomheplfhoshhhucfvrhhiphhlvghtthcuoehjohhshhesjhhoshhh thhrihhplhgvthhtrdhorhhgqeenucggtffrrghtthgvrhhnpeduieegheeijeeuvdetud efvedtjeefgeeufefghfekgfelfeetteelvddtffetgfenucevlhhushhtvghrufhiiigv pedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehjohhshhesjhhoshhhthhrihhplhgvth htrdhorhhg X-ME-Proxy: Feedback-ID: i83e94755:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 27 Feb 2024 04:17:37 -0500 (EST) Date: Tue, 27 Feb 2024 01:17:36 -0800 From: Josh Triplett To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH v2 2/2] commit: Unify logic to avoid multiple scissors lines when merging Message-ID: <553c8692e9f0f0159bfba5b15e0abb3190a6f5f3.1709025354.git.josh@joshtriplett.org> References: <9c09cea2679e14258720ee63e932e3b9459dbd8c.1708921369.git.josh@joshtriplett.org> <4f97933f173220544a5be2bf05c2bee2b044d2b1.1709024540.git.josh@joshtriplett.org> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4f97933f173220544a5be2bf05c2bee2b044d2b1.1709024540.git.josh@joshtriplett.org> 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 --- v2: New patch. builtin/commit.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index e0a6d43179..142f54ea7c 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);