git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v2 0/2] git-gui: Use commit message template
@ 2020-11-27 14:59 Pratyush Yadav
  2020-11-27 14:59 ` [PATCH v2 1/2] git-gui: Only touch GITGUI_MSG when needed Pratyush Yadav
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Pratyush Yadav @ 2020-11-27 14:59 UTC (permalink / raw)
  To: git; +Cc: Martin Schön

Hi,

This series is a revival of [0] which was pointed to me by [1]. I have
made some changes to the patch by Martin.

- The rescan call in proc commit_committree is removed. git-gui goes to
  great lengths to avoid a rescan after commit by calculating the status
  of the files in memory. It makes sense to keep it that way. The
  purpose of the rescan was to reload the commit template in the buffer
  after a commit. The rescan path handles that, but we can do that
  manually as well.

- Add a call to load the commit message template in 'rescan' directly
  instead of relying on 'run_prepare_commit_msg_hook' to do it when the
  commit-msg hook does not exist.

In addition, patch 1/2 fixes a small bug in the commit message buffer
backup logic that would be exposed by using the template mechanism. If
you load git-gui, do some things, and exit it. Then if you change the
commit message template (or even remove it), and open git-gui again it
will use the previous message for the first commit and then use the new
one from the next commit onwards.

This happens because if the commit message buffer in not empty, git-gui
saves the contents to save accidental loss of data. And when opening it
again, the saved message (which is the older template) obviously gets
priority.

[0] https://public-inbox.org/git/1530608011429.41203@loewensteinmedical.de/T/
[1] https://github.com/prati0100/git-gui/issues/24

Martin Schön (1):
  git-gui: use commit message template

Pratyush Yadav (1):
  git-gui: Only touch GITGUI_MSG when needed

 git-gui.sh     | 12 +++++++++---
 lib/commit.tcl |  1 +
 2 files changed, 10 insertions(+), 3 deletions(-)

--
2.29.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] git-gui: Only touch GITGUI_MSG when needed
  2020-11-27 14:59 [PATCH v2 0/2] git-gui: Use commit message template Pratyush Yadav
@ 2020-11-27 14:59 ` Pratyush Yadav
  2020-11-27 14:59 ` [PATCH v2 2/2] git-gui: use commit message template Pratyush Yadav
  2020-12-01 19:12 ` [PATCH v2 0/2] git-gui: Use " Pratyush Yadav
  2 siblings, 0 replies; 4+ messages in thread
From: Pratyush Yadav @ 2020-11-27 14:59 UTC (permalink / raw)
  To: git; +Cc: Martin Schön

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 <me@yadavpratyush.com>
---
 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]
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] git-gui: use commit message template
  2020-11-27 14:59 [PATCH v2 0/2] git-gui: Use commit message template Pratyush Yadav
  2020-11-27 14:59 ` [PATCH v2 1/2] git-gui: Only touch GITGUI_MSG when needed Pratyush Yadav
@ 2020-11-27 14:59 ` Pratyush Yadav
  2020-12-01 19:12 ` [PATCH v2 0/2] git-gui: Use " Pratyush Yadav
  2 siblings, 0 replies; 4+ messages in thread
From: Pratyush Yadav @ 2020-11-27 14:59 UTC (permalink / raw)
  To: git; +Cc: Martin Schön

From: Martin Schön <Martin.Schoen@loewensteinmedical.de>

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 <Martin.Schoen@loewensteinmedical.de>
Signed-off-by: Pratyush Yadav <me@yadavpratyush.com>
---
 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} {
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] git-gui: Use commit message template
  2020-11-27 14:59 [PATCH v2 0/2] git-gui: Use commit message template Pratyush Yadav
  2020-11-27 14:59 ` [PATCH v2 1/2] git-gui: Only touch GITGUI_MSG when needed Pratyush Yadav
  2020-11-27 14:59 ` [PATCH v2 2/2] git-gui: use commit message template Pratyush Yadav
@ 2020-12-01 19:12 ` Pratyush Yadav
  2 siblings, 0 replies; 4+ messages in thread
From: Pratyush Yadav @ 2020-12-01 19:12 UTC (permalink / raw)
  To: git; +Cc: Martin Schön

On 27/11/20 08:29PM, Pratyush Yadav wrote:
> Hi,
> 
> This series is a revival of [0] which was pointed to me by [1]. I have
> made some changes to the patch by Martin.
> 
> - The rescan call in proc commit_committree is removed. git-gui goes to
>   great lengths to avoid a rescan after commit by calculating the status
>   of the files in memory. It makes sense to keep it that way. The
>   purpose of the rescan was to reload the commit template in the buffer
>   after a commit. The rescan path handles that, but we can do that
>   manually as well.
> 
> - Add a call to load the commit message template in 'rescan' directly
>   instead of relying on 'run_prepare_commit_msg_hook' to do it when the
>   commit-msg hook does not exist.
> 
> In addition, patch 1/2 fixes a small bug in the commit message buffer
> backup logic that would be exposed by using the template mechanism. If
> you load git-gui, do some things, and exit it. Then if you change the
> commit message template (or even remove it), and open git-gui again it
> will use the previous message for the first commit and then use the new
> one from the next commit onwards.
> 
> This happens because if the commit message buffer in not empty, git-gui
> saves the contents to save accidental loss of data. And when opening it
> again, the saved message (which is the older template) obviously gets
> priority.
> 
> [0] https://public-inbox.org/git/1530608011429.41203@loewensteinmedical.de/T/
> [1] https://github.com/prati0100/git-gui/issues/24

Series merged to git-gui/master.
 
> Martin Schön (1):
>   git-gui: use commit message template
> 
> Pratyush Yadav (1):
>   git-gui: Only touch GITGUI_MSG when needed
> 
>  git-gui.sh     | 12 +++++++++---
>  lib/commit.tcl |  1 +
>  2 files changed, 10 insertions(+), 3 deletions(-)
> 
> --
> 2.29.2
> 

-- 
Regards,
Pratyush Yadav

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-12-01 19:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-27 14:59 [PATCH v2 0/2] git-gui: Use commit message template Pratyush Yadav
2020-11-27 14:59 ` [PATCH v2 1/2] git-gui: Only touch GITGUI_MSG when needed Pratyush Yadav
2020-11-27 14:59 ` [PATCH v2 2/2] git-gui: use commit message template Pratyush Yadav
2020-12-01 19:12 ` [PATCH v2 0/2] git-gui: Use " Pratyush Yadav

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).