{"thread":{"id":"54724","subject":"[PATCH v2 0/2] git-gui: Use commit message template","startedAt":"2020-11-27T14:59:57Z","lastAt":"2020-12-01T19:14:20Z","messageCount":4,"participants":["Pratyush Yadav"],"isPatch":true,"patchVersion":2,"patchTotal":2},"messages":[{"id":"410930","messageId":"20201127145927.26222-1-me@yadavpratyush.com","threadId":"54724","inReplyTo":null,"subject":"[PATCH v2 0/2] git-gui: Use commit message template","fromName":"Pratyush Yadav","fromEmail":"me@yadavpratyush.com","sentAt":"2020-11-27T14:59:25Z","receivedAt":"2020-11-27T14:59:57Z","isPatch":true,"sender":{"key":"me@yadavpratyush.com","avatar":"https://avatars.githubusercontent.com/u/8817931?v=4"},"body":"Hi,\n\nThis series is a revival of [0] which was pointed to me by [1]. I have\nmade some changes to the patch by Martin.\n\n- The rescan call in proc commit_committree is removed. git-gui goes to\n  great lengths to avoid a rescan after commit by calculating the status\n  of the files in memory. It makes sense to keep it that way. The\n  purpose of the rescan was to reload the commit template in the buffer\n  after a commit. The rescan path handles that, but we can do that\n  manually as well.\n\n- Add a call to load the commit message template in 'rescan' directly\n  instead of relying on 'run_prepare_commit_msg_hook' to do it when the\n  commit-msg hook does not exist.\n\nIn addition, patch 1/2 fixes a small bug in the commit message buffer\nbackup logic that would be exposed by using the template mechanism. If\nyou load git-gui, do some things, and exit it. Then if you change the\ncommit message template (or even remove it), and open git-gui again it\nwill use the previous message for the first commit and then use the new\none from the next commit onwards.\n\nThis happens because if the commit message buffer in not empty, git-gui\nsaves the contents to save accidental loss of data. And when opening it\nagain, the saved message (which is the older template) obviously gets\npriority.\n\n[0] https://public-inbox.org/git/1530608011429.41203@loewensteinmedical.de/T/\n[1] https://github.com/prati0100/git-gui/issues/24\n\nMartin Schön (1):\n  git-gui: use commit message template\n\nPratyush Yadav (1):\n  git-gui: Only touch GITGUI_MSG when needed\n\n git-gui.sh     | 12 +++++++++---\n lib/commit.tcl |  1 +\n 2 files changed, 10 insertions(+), 3 deletions(-)\n\n--\n2.29.2\n\n"},{"id":"410931","messageId":"20201127145927.26222-2-me@yadavpratyush.com","threadId":"54724","inReplyTo":"20201127145927.26222-1-me@yadavpratyush.com","subject":"[PATCH v2 1/2] git-gui: Only touch GITGUI_MSG when needed","fromName":"Pratyush Yadav","fromEmail":"me@yadavpratyush.com","sentAt":"2020-11-27T14:59:26Z","receivedAt":"2020-11-27T14:59:58Z","isPatch":true,"sender":{"key":"me@yadavpratyush.com","avatar":"https://avatars.githubusercontent.com/u/8817931?v=4"},"body":"In 4e55d19 (git-gui: Cleanup end-of-line whitespace in commit messages.,\n2007-01-25), the logic to decide if GITGUI_MSG should be saved or\ndeleted was updated to not require the commit message buffer to be\nmodified. This fixes a situation where if the user quits and restarts\ngit-gui multiple times the commit message buffer was lost.\n\nUnfortunately, the fix was not quite correct. The check for whether the\ncommit message buffer has been modified is useless. If the commit is\n_not_ amend, then the check is never performed. If the commit is amend,\nthen saving the message does not matter anyway. Amend state is destroyed\non exit and the next time git-gui is opened it starts from scratch, but\nwith the older message retained in the buffer. If amend is selected,\nthe current message is over-written by the amend commit's message.\n\nThe correct fix would be to not touch GITGUI_MSG at all if the commit\nmessage buffer is not modified. This way, the file is not deleted even\non multiple restarts. It has the added benefit of not writing the file\nunnecessarily on every exit.\n\nSigned-off-by: Pratyush Yadav <me@yadavpratyush.com>\n---\n git-gui.sh | 5 ++---\n 1 file changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/git-gui.sh b/git-gui.sh\nindex 867b8ce..8ee67e6 100755\n--- a/git-gui.sh\n+++ b/git-gui.sh\n@@ -2305,11 +2305,10 @@ proc do_quit {{rc {1}}} {\n \t\tif {$GITGUI_BCK_exists && ![$ui_comm edit modified]} {\n \t\t\tfile rename -force [gitdir GITGUI_BCK] $save\n \t\t\tset GITGUI_BCK_exists 0\n-\t\t} else {\n+\t\t} elseif {[$ui_comm edit modified]} {\n \t\t\tset msg [string trim [$ui_comm get 0.0 end]]\n \t\t\tregsub -all -line {[ \\r\\t]+$} $msg {} msg\n-\t\t\tif {(![string match amend* $commit_type]\n-\t\t\t\t|| [$ui_comm edit modified])\n+\t\t\tif {![string match amend* $commit_type]\n \t\t\t\t&& $msg ne {}} {\n \t\t\t\tcatch {\n \t\t\t\t\tset fd [open $save w]\n-- \n2.29.2\n\n"},{"id":"410932","messageId":"20201127145927.26222-3-me@yadavpratyush.com","threadId":"54724","inReplyTo":"20201127145927.26222-1-me@yadavpratyush.com","subject":"[PATCH v2 2/2] git-gui: use commit message template","fromName":"Pratyush Yadav","fromEmail":"me@yadavpratyush.com","sentAt":"2020-11-27T14:59:27Z","receivedAt":"2020-11-27T15:00:43Z","isPatch":true,"sender":{"key":"me@yadavpratyush.com","avatar":"https://avatars.githubusercontent.com/u/8817931?v=4"},"body":"From: Martin Schön <Martin.Schoen@loewensteinmedical.de>\n\nUse the file described by commit.template (if set) to show the commit message\ntemplate, just like other GUIs.\n\nSigned-off-by: Martin Schön <Martin.Schoen@loewensteinmedical.de>\nSigned-off-by: Pratyush Yadav <me@yadavpratyush.com>\n---\n git-gui.sh     | 7 +++++++\n lib/commit.tcl | 1 +\n 2 files changed, 8 insertions(+)\n\ndiff --git a/git-gui.sh b/git-gui.sh\nindex 8ee67e6..cc6c2aa 100755\n--- a/git-gui.sh\n+++ b/git-gui.sh\n@@ -1482,6 +1482,7 @@ proc rescan {after {honor_trustmtime 1}} {\n \t\t} elseif {[run_prepare_commit_msg_hook]} {\n \t\t} elseif {[load_message MERGE_MSG]} {\n \t\t} elseif {[load_message SQUASH_MSG]} {\n+\t\t} elseif {[load_message [get_config commit.template]]} {\n \t\t}\n \t\t$ui_comm edit reset\n \t\t$ui_comm edit modified false\n@@ -1616,6 +1617,12 @@ proc run_prepare_commit_msg_hook {} {\n \t\tfconfigure $fd_sm -encoding utf-8\n \t\tputs -nonewline $fd_pcm [read $fd_sm]\n \t\tclose $fd_sm\n+\t} elseif {[file isfile [get_config commit.template]]} {\n+\t\tset pcm_source \"template\"\n+\t\tset fd_sm [open [get_config commit.template] r]\n+\t\tfconfigure $fd_sm -encoding utf-8\n+\t\tputs -nonewline $fd_pcm [read $fd_sm]\n+\t\tclose $fd_sm\n \t} else {\n \t\tset pcm_source \"\"\n \t}\ndiff --git a/lib/commit.tcl b/lib/commit.tcl\nindex b516aa2..11379f8 100644\n--- a/lib/commit.tcl\n+++ b/lib/commit.tcl\n@@ -456,6 +456,7 @@ A rescan will be automatically started now.\n \t}\n \n \t$ui_comm delete 0.0 end\n+\tload_message [get_config commit.template]\n \t$ui_comm edit reset\n \t$ui_comm edit modified false\n \tif {$::GITGUI_BCK_exists} {\n-- \n2.29.2\n\n"},{"id":"411084","messageId":"20201201191241.6cdzrdcihdzoylwo@yadavpratyush.com","threadId":"54724","inReplyTo":"20201127145927.26222-1-me@yadavpratyush.com","subject":"Re: [PATCH v2 0/2] git-gui: Use commit message template","fromName":"Pratyush Yadav","fromEmail":"me@yadavpratyush.com","sentAt":"2020-12-01T19:12:41Z","receivedAt":"2020-12-01T19:14:20Z","isPatch":true,"sender":{"key":"me@yadavpratyush.com","avatar":"https://avatars.githubusercontent.com/u/8817931?v=4"},"body":"On 27/11/20 08:29PM, Pratyush Yadav wrote:\n> Hi,\n> \n> This series is a revival of [0] which was pointed to me by [1]. I have\n> made some changes to the patch by Martin.\n> \n> - The rescan call in proc commit_committree is removed. git-gui goes to\n>   great lengths to avoid a rescan after commit by calculating the status\n>   of the files in memory. It makes sense to keep it that way. The\n>   purpose of the rescan was to reload the commit template in the buffer\n>   after a commit. The rescan path handles that, but we can do that\n>   manually as well.\n> \n> - Add a call to load the commit message template in 'rescan' directly\n>   instead of relying on 'run_prepare_commit_msg_hook' to do it when the\n>   commit-msg hook does not exist.\n> \n> In addition, patch 1/2 fixes a small bug in the commit message buffer\n> backup logic that would be exposed by using the template mechanism. If\n> you load git-gui, do some things, and exit it. Then if you change the\n> commit message template (or even remove it), and open git-gui again it\n> will use the previous message for the first commit and then use the new\n> one from the next commit onwards.\n> \n> This happens because if the commit message buffer in not empty, git-gui\n> saves the contents to save accidental loss of data. And when opening it\n> again, the saved message (which is the older template) obviously gets\n> priority.\n> \n> [0] https://public-inbox.org/git/1530608011429.41203@loewensteinmedical.de/T/\n> [1] https://github.com/prati0100/git-gui/issues/24\n\nSeries merged to git-gui/master.\n \n> Martin Schön (1):\n>   git-gui: use commit message template\n> \n> Pratyush Yadav (1):\n>   git-gui: Only touch GITGUI_MSG when needed\n> \n>  git-gui.sh     | 12 +++++++++---\n>  lib/commit.tcl |  1 +\n>  2 files changed, 10 insertions(+), 3 deletions(-)\n> \n> --\n> 2.29.2\n> \n\n-- \nRegards,\nPratyush Yadav\n"}]}