{"thread":{"id":"55170","subject":"[PATCH v2] git-gui: remove lines starting with the comment character","startedAt":"2021-02-18T18:53:31Z","lastAt":"2021-02-28T23:02:00Z","messageCount":3,"participants":["Pratyush Yadav","Eric Sunshine"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"417331","messageId":"20210218181937.83419-1-me@yadavpratyush.com","threadId":"55170","inReplyTo":null,"subject":"[PATCH v2] git-gui: remove lines starting with the comment character","fromName":"Pratyush Yadav","fromEmail":"me@yadavpratyush.com","sentAt":"2021-02-18T18:19:37Z","receivedAt":"2021-02-18T18:53:31Z","isPatch":true,"sender":{"key":"me@yadavpratyush.com","avatar":"https://avatars.githubusercontent.com/u/8817931?v=4"},"body":"The comment character is specified by the config variable\n'core.commentchar'. Any lines starting with this character is considered\na comment and should not be included in the final commit message.\n\nTeach git-gui to filter out lines in the commit message that start with\nthe comment character using git-stripspace. If the config is not set,\n'#' is taken as the default. Also add a message educating users about\nthe comment character.\n\nSigned-off-by: Pratyush Yadav <me@yadavpratyush.com>\n---\n\nChanges in v2:\n- Use git-stripspace to sanitize the commit message.\n- Add a message above the commit message buffer mentioning what the\n  comment character is.\n\n git-gui.sh     |  5 +++++\n lib/commit.tcl | 18 ++++++++++++++++--\n 2 files changed, 21 insertions(+), 2 deletions(-)\n\ndiff --git a/git-gui.sh b/git-gui.sh\nindex 201524c..236bc4e 100755\n--- a/git-gui.sh\n+++ b/git-gui.sh\n@@ -875,6 +875,7 @@ set default_config(merge.summary) false\n set default_config(merge.verbosity) 2\n set default_config(user.name) {}\n set default_config(user.email) {}\n+set default_config(core.commentchar) \"#\"\n\n set default_config(gui.encoding) [encoding system]\n set default_config(gui.matchtrackingbranch) false\n@@ -3436,6 +3437,10 @@ proc trace_commit_type {varname args} {\n \tmerge         {set txt [mc \"Merge Commit Message:\"]}\n \t*             {set txt [mc \"Commit Message:\"]}\n \t}\n+\n+\tset comment_char [get_config core.commentchar]\n+\tset txt [string cat $txt \\\n+\t\t\t\t [mc \" (Lines starting with '$comment_char' will be ignored)\"]]\n \t$ui_coml conf -text $txt\n }\n trace add variable commit_type write trace_commit_type\ndiff --git a/lib/commit.tcl b/lib/commit.tcl\nindex 11379f8..23d67d4 100644\n--- a/lib/commit.tcl\n+++ b/lib/commit.tcl\n@@ -141,6 +141,20 @@ proc setup_commit_encoding {msg_wt {quiet 0}} {\n \t}\n }\n\n+proc strip_msg {msg} {\n+\tset cmd [concat [list | ] [_git_cmd stripspace] --strip-comments]\n+\t_trace_exec $cmd\n+\tset fd [open $cmd r+]\n+\tfconfigure $fd -translation binary -encoding utf-8\n+\n+\tputs -nonewline $fd $msg\n+\tclose $fd w\n+\tset result [read $fd]\n+\tclose $fd\n+\n+\treturn $result\n+}\n+\n proc commit_tree {} {\n \tglobal HEAD commit_type file_states ui_comm repo_config\n \tglobal pch_error\n@@ -207,8 +221,8 @@ You must stage at least 1 file before you can commit.\n\n \t# -- A message is required.\n \t#\n-\tset msg [string trim [$ui_comm get 1.0 end]]\n-\tregsub -all -line {[ \\t\\r]+$} $msg {} msg\n+\tset msg [strip_msg [$ui_comm get 1.0 end]]\n+\n \tif {$msg eq {}} {\n \t\terror_popup [mc \"Please supply a commit message.\n\n--\n2.30.0\n\n"},{"id":"417469","messageId":"20210222145137.b7lmgzpmm5q4m2qf@yadavpratyush.com","threadId":"55170","inReplyTo":"20210218181937.83419-1-me@yadavpratyush.com","subject":"Re: [PATCH v2] git-gui: remove lines starting with the comment character","fromName":"Pratyush Yadav","fromEmail":"me@yadavpratyush.com","sentAt":"2021-02-22T14:51:37Z","receivedAt":"2021-02-22T15:03:43Z","isPatch":true,"sender":{"key":"me@yadavpratyush.com","avatar":"https://avatars.githubusercontent.com/u/8817931?v=4"},"body":"On 18/02/21 11:49PM, Pratyush Yadav wrote:\n> The comment character is specified by the config variable\n> 'core.commentchar'. Any lines starting with this character is considered\n> a comment and should not be included in the final commit message.\n> \n> Teach git-gui to filter out lines in the commit message that start with\n> the comment character using git-stripspace. If the config is not set,\n> '#' is taken as the default. Also add a message educating users about\n> the comment character.\n> \n> Signed-off-by: Pratyush Yadav <me@yadavpratyush.com>\n\nApplied to git-gui/master.\n\n-- \nRegards,\nPratyush Yadav\n"},{"id":"418000","messageId":"CAPig+cT-sfgMDi9-6AEKF85NtOiXeqddJjk-pYuhDtTVAE-UEw@mail.gmail.com","threadId":"55170","inReplyTo":"20210218181937.83419-1-me@yadavpratyush.com","subject":"Re: [PATCH v2] git-gui: remove lines starting with the comment character","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2021-02-28T23:00:49Z","receivedAt":"2021-02-28T23:02:00Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"[Junio: please do not pull the latest git-gui changes yet; they break\non macOS, making git-gui unusable]\n\nOn Thu, Feb 18, 2021 at 1:20 PM Pratyush Yadav <me@yadavpratyush.com> wrote:\n> The comment character is specified by the config variable\n> 'core.commentchar'. Any lines starting with this character is considered\n> a comment and should not be included in the final commit message.\n>\n> Teach git-gui to filter out lines in the commit message that start with\n> the comment character using git-stripspace. If the config is not set,\n> '#' is taken as the default. Also add a message educating users about\n> the comment character.\n\nThanks for working on this. I've been looking forward to the\nimprovement; the old behavior of not stripping comment lines has been\na long-time annoyance.\n\nUnfortunately, however, the changes break git-gui badly on macOS. See below...\n\n> Signed-off-by: Pratyush Yadav <me@yadavpratyush.com>\n> ---\n> diff --git a/git-gui.sh b/git-gui.sh\n> @@ -3436,6 +3437,10 @@ proc trace_commit_type {varname args} {\n> +       set comment_char [get_config core.commentchar]\n> +       set txt [string cat $txt \\\n> +                                [mc \" (Lines starting with '$comment_char' will be ignored)\"]]\n\nThe old Tcl 8.5.9 on macOS does not have a string `cat` method, so\n`string cat` crashes:\n\n    can't set \"commit_type\": unknown or ambiguous subcommand \"cat\":\n        must be bytelength, compare, equal, first, index, is, last,\n        length, map, match, range, repeat, replace, reverse, tolower,\n        totitle, toupper, trim, trimleft, trimright, wordend, or\n        wordstart\n    unknown or ambiguous subcommand \"cat\": must be bytelength,\n        compare, equal, first, index, is, last, length, map, match,\n        range, repeat, replace, reverse, tolower, totitle, toupper,\n        trim, trimleft, trimright, wordend, or wordstart while\n        executing\n    \"string cat $txt [mc \" (Lines starting with '$comment_char' will\n        be ignored)\"]\"\n\n> diff --git a/lib/commit.tcl b/lib/commit.tcl\n> @@ -141,6 +141,20 @@ proc setup_commit_encoding {msg_wt {quiet 0}} {\n> +proc strip_msg {msg} {\n> +       set cmd [concat [list | ] [_git_cmd stripspace] --strip-comments]\n> +       _trace_exec $cmd\n> +       set fd [open $cmd r+]\n> +       fconfigure $fd -translation binary -encoding utf-8\n> +       puts -nonewline $fd $msg\n> +       close $fd w\n> +       set result [read $fd]\n> +       close $fd\n> +       return $result\n> +}\n\nThe old Tcl on macOS does not support closing one end of a\nbidirectional pipe, so `close $fd w` errors out:\n\n    wrong # args: should be \"close channelId\"\n    wrong # args: should be \"close channelId\"\n        while executing\n    \"close $fd w\"\n\nI'll send a patch which resolves both problems.\n"}]}