From patchwork Fri Nov 27 14:59:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pratyush Yadav X-Patchwork-Id: 11936507 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F407C63798 for ; Fri, 27 Nov 2020 14:59:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C6B952223F for ; Fri, 27 Nov 2020 14:59:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731012AbgK0O75 (ORCPT ); Fri, 27 Nov 2020 09:59:57 -0500 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:42409 "EHLO relay6-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730920AbgK0O74 (ORCPT ); Fri, 27 Nov 2020 09:59:56 -0500 X-Originating-IP: 103.82.80.46 Received: from localhost.localdomain (unknown [103.82.80.46]) (Authenticated sender: me@yadavpratyush.com) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 7AFEBC0011; Fri, 27 Nov 2020 14:59:54 +0000 (UTC) From: Pratyush Yadav To: Cc: =?utf-8?q?Martin_Sch=C3=B6n?= Subject: [PATCH v2 1/2] git-gui: Only touch GITGUI_MSG when needed Date: Fri, 27 Nov 2020 20:29:26 +0530 Message-Id: <20201127145927.26222-2-me@yadavpratyush.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201127145927.26222-1-me@yadavpratyush.com> References: <20201127145927.26222-1-me@yadavpratyush.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In 4e55d19 (git-gui: Cleanup end-of-line whitespace in commit messages., 2007-01-25), the logic to decide if GITGUI_MSG should be saved or deleted was updated to not require the commit message buffer to be modified. This fixes a situation where if the user quits and restarts git-gui multiple times the commit message buffer was lost. Unfortunately, the fix was not quite correct. The check for whether the commit message buffer has been modified is useless. If the commit is _not_ amend, then the check is never performed. If the commit is amend, then saving the message does not matter anyway. Amend state is destroyed on exit and the next time git-gui is opened it starts from scratch, but with the older message retained in the buffer. If amend is selected, the current message is over-written by the amend commit's message. The correct fix would be to not touch GITGUI_MSG at all if the commit message buffer is not modified. This way, the file is not deleted even on multiple restarts. It has the added benefit of not writing the file unnecessarily on every exit. Signed-off-by: Pratyush Yadav --- git-gui.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 867b8ce..8ee67e6 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -2305,11 +2305,10 @@ proc do_quit {{rc {1}}} { if {$GITGUI_BCK_exists && ![$ui_comm edit modified]} { file rename -force [gitdir GITGUI_BCK] $save set GITGUI_BCK_exists 0 - } else { + } elseif {[$ui_comm edit modified]} { set msg [string trim [$ui_comm get 0.0 end]] regsub -all -line {[ \r\t]+$} $msg {} msg - if {(![string match amend* $commit_type] - || [$ui_comm edit modified]) + if {![string match amend* $commit_type] && $msg ne {}} { catch { set fd [open $save w] From patchwork Fri Nov 27 14:59:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pratyush Yadav X-Patchwork-Id: 11936509 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C98CC2D0E4 for ; Fri, 27 Nov 2020 15:00:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 29DFA221EB for ; Fri, 27 Nov 2020 15:00:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731049AbgK0PAA (ORCPT ); Fri, 27 Nov 2020 10:00:00 -0500 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:57885 "EHLO relay6-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731015AbgK0O76 (ORCPT ); Fri, 27 Nov 2020 09:59:58 -0500 X-Originating-IP: 103.82.80.46 Received: from localhost.localdomain (unknown [103.82.80.46]) (Authenticated sender: me@yadavpratyush.com) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 0DBBEC0008; Fri, 27 Nov 2020 14:59:55 +0000 (UTC) From: Pratyush Yadav To: Cc: =?utf-8?q?Martin_Sch=C3=B6n?= Subject: [PATCH v2 2/2] git-gui: use commit message template Date: Fri, 27 Nov 2020 20:29:27 +0530 Message-Id: <20201127145927.26222-3-me@yadavpratyush.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201127145927.26222-1-me@yadavpratyush.com> References: <20201127145927.26222-1-me@yadavpratyush.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Martin Schön Use the file described by commit.template (if set) to show the commit message template, just like other GUIs. Signed-off-by: Martin Schön Signed-off-by: Pratyush Yadav --- git-gui.sh | 7 +++++++ lib/commit.tcl | 1 + 2 files changed, 8 insertions(+) diff --git a/git-gui.sh b/git-gui.sh index 8ee67e6..cc6c2aa 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1482,6 +1482,7 @@ proc rescan {after {honor_trustmtime 1}} { } elseif {[run_prepare_commit_msg_hook]} { } elseif {[load_message MERGE_MSG]} { } elseif {[load_message SQUASH_MSG]} { + } elseif {[load_message [get_config commit.template]]} { } $ui_comm edit reset $ui_comm edit modified false @@ -1616,6 +1617,12 @@ proc run_prepare_commit_msg_hook {} { fconfigure $fd_sm -encoding utf-8 puts -nonewline $fd_pcm [read $fd_sm] close $fd_sm + } elseif {[file isfile [get_config commit.template]]} { + set pcm_source "template" + set fd_sm [open [get_config commit.template] r] + fconfigure $fd_sm -encoding utf-8 + puts -nonewline $fd_pcm [read $fd_sm] + close $fd_sm } else { set pcm_source "" } diff --git a/lib/commit.tcl b/lib/commit.tcl index b516aa2..11379f8 100644 --- a/lib/commit.tcl +++ b/lib/commit.tcl @@ -456,6 +456,7 @@ A rescan will be automatically started now. } $ui_comm delete 0.0 end + load_message [get_config commit.template] $ui_comm edit reset $ui_comm edit modified false if {$::GITGUI_BCK_exists} {