{"thread":{"id":"63137","subject":"[PATCH] git-gui: heed core.commentChar/commentString","startedAt":"2025-03-15T14:09:15Z","lastAt":"2025-03-16T11:02:42Z","messageCount":3,"participants":["Oswald Buddenhagen","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"514352","messageId":"20250315140913.577422-1-oswald.buddenhagen@gmx.de","threadId":"63137","inReplyTo":null,"subject":"[PATCH] git-gui: heed core.commentChar/commentString","fromName":"Oswald Buddenhagen","fromEmail":"oswald.buddenhagen@gmx.de","sentAt":"2025-03-15T14:09:13Z","receivedAt":"2025-03-15T14:09:15Z","isPatch":true,"sender":{"key":"oswald.buddenhagen@gmx.de","avatar":"https://avatars.githubusercontent.com/u/812380?v=4"},"body":"This amends 1ae85ff6d (git-gui: strip comments and consecutive empty\nlines from commit messages, 2024-08-13) to deal with custom comment\ncharacters/strings.\n\nThe magic commentString value \"auto\" is not handled, because the option\nmakes no sense to me - it does not support comments in templates and\nhook output, and it seems far-fetched that someone would introduce\ncomments during editing the message.\n\nSigned-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>\nChange-Id: Iafc0580e818cb5058cfacbafe6e5da40679a1b1c\n\n--\n\nCc: Johannes Sixt <j6t@kdbg.org>\n\nthe textfield label munging is modeled after b9a43869c9 (without\nintroducing the same compatibility problem with tcl 8.5), but i'm not\npositive it's actually a good idea to have it - it looks a bit messy,\nwhile providing info that the command line client assumes to be known.\n---\n git-gui/git-gui.sh     | 11 ++++++++++-\n git-gui/lib/commit.tcl |  4 +++-\n 2 files changed, 13 insertions(+), 2 deletions(-)\n\ndiff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\nindex 887d6d596c..ed14ba679b 100755\n--- a/git-gui/git-gui.sh\n+++ b/git-gui/git-gui.sh\n@@ -880,16 +880,24 @@ proc apply_config {} {\n \t\t\tcolor::sync_with_theme\n \t\t}\n \t}\n+\n+\tglobal comment_string\n+\tset comment_string [get_config core.commentstring]\n+\tif {$comment_string eq {}} {\n+\t\tset comment_string [get_config core.commentchar]\n+\t}\n }\n \n set default_config(branch.autosetupmerge) true\n set default_config(merge.tool) {}\n set default_config(mergetool.keepbackup) true\n set default_config(merge.diffstat) true\n 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+set default_config(core.commentstring) {}\n \n set default_config(gui.encoding) [encoding system]\n set default_config(gui.matchtrackingbranch) false\n@@ -3416,15 +3424,16 @@ ${NS}::label $ui_coml \\\n \t-anchor w \\\n \t-justify left\n proc trace_commit_type {varname args} {\n-\tglobal ui_coml commit_type\n+\tglobal ui_coml commit_type comment_string\n \tswitch -glob -- $commit_type {\n \tinitial       {set txt [mc \"Initial Commit Message:\"]}\n \tamend         {set txt [mc \"Amended Commit Message:\"]}\n \tamend-initial {set txt [mc \"Amended Initial Commit Message:\"]}\n \tamend-merge   {set txt [mc \"Amended Merge Commit Message:\"]}\n \tmerge         {set txt [mc \"Merge Commit Message:\"]}\n \t*             {set txt [mc \"Commit Message:\"]}\n \t}\n+\tappend txt [mc \" (Lines starting with '%s' will be discarded)\" $comment_string]\n \t$ui_coml conf -text $txt\n }\n trace add variable commit_type write trace_commit_type\ndiff --git a/git-gui/lib/commit.tcl b/git-gui/lib/commit.tcl\nindex 208dc2817c..a570f9cdc6 100644\n--- a/git-gui/lib/commit.tcl\n+++ b/git-gui/lib/commit.tcl\n@@ -211,7 +211,9 @@ You must stage at least 1 file before you can commit.\n \t# Strip trailing whitespace\n \tregsub -all -line {[ \\t\\r]+$} $msg {} msg\n \t# Strip comment lines\n-\tregsub -all {(^|\\n)#[^\\n]*} $msg {\\1} msg\n+\tglobal comment_string\n+\tset cmt_rx [strcat {(^|\\n)} [regsub -all {\\W} $comment_string {\\\\&}] {[^\\n]*}]\n+\tregsub -all $cmt_rx $msg {\\1} msg\n \t# Strip leading empty lines\n \tregsub {^\\n*} $msg {} msg\n \t# Compress consecutive empty lines\n-- \n2.49.0.416.g2f302f2ef0.dirty\n\n"},{"id":"514393","messageId":"Z9anqjBmKFpPuTP9@ugly","threadId":"63137","inReplyTo":"a62035cf-b67e-4291-acf6-d2454a9459bb@kdbg.org","subject":"Re: [PATCH] git-gui: heed core.commentChar/commentString","fromName":"Oswald Buddenhagen","fromEmail":"oswald.buddenhagen@gmx.de","sentAt":"2025-03-16T10:27:54Z","receivedAt":"2025-03-16T10:27:56Z","isPatch":true,"sender":{"key":"oswald.buddenhagen@gmx.de","avatar":"https://avatars.githubusercontent.com/u/812380?v=4"},"body":"On Sun, Mar 16, 2025 at 11:22:12AM +0100, Johannes Sixt wrote:\n>Am 15.03.25 um 15:09 schrieb Oswald Buddenhagen:\n>> +\tappend txt [mc \" (Lines starting with '%s' will be discarded)\" $comment_string]\n>\n>Like you said in the introduction, this does look messy. Would you\n>approve that I remove this hunk while queuing?\n>\nyep, go ahead!\n\n"},{"id":"514394","messageId":"a62035cf-b67e-4291-acf6-d2454a9459bb@kdbg.org","threadId":"63137","inReplyTo":"20250315140913.577422-1-oswald.buddenhagen@gmx.de","subject":"Re: [PATCH] git-gui: heed core.commentChar/commentString","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2025-03-16T10:22:12Z","receivedAt":"2025-03-16T11:02:42Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 15.03.25 um 15:09 schrieb Oswald Buddenhagen:\n> This amends 1ae85ff6d (git-gui: strip comments and consecutive empty\n> lines from commit messages, 2024-08-13) to deal with custom comment\n> characters/strings.\n> \n> The magic commentString value \"auto\" is not handled, because the option\n> makes no sense to me - it does not support comments in templates and\n> hook output, and it seems far-fetched that someone would introduce\n> comments during editing the message.\n> \n> Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>\n> Change-Id: Iafc0580e818cb5058cfacbafe6e5da40679a1b1c\n> \n> --\n> \n> Cc: Johannes Sixt <j6t@kdbg.org>\n> \n> the textfield label munging is modeled after b9a43869c9 (without\n> introducing the same compatibility problem with tcl 8.5), but i'm not\n> positive it's actually a good idea to have it - it looks a bit messy,\n> while providing info that the command line client assumes to be known.\n\nSee below.\n\n> ---\n>  git-gui/git-gui.sh     | 11 ++++++++++-\n>  git-gui/lib/commit.tcl |  4 +++-\n>  2 files changed, 13 insertions(+), 2 deletions(-)\n> \n> diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\n> index 887d6d596c..ed14ba679b 100755\n> --- a/git-gui/git-gui.sh\n> +++ b/git-gui/git-gui.sh\n> @@ -880,16 +880,24 @@ proc apply_config {} {\n>  \t\t\tcolor::sync_with_theme\n>  \t\t}\n>  \t}\n> +\n> +\tglobal comment_string\n> +\tset comment_string [get_config core.commentstring]\n> +\tif {$comment_string eq {}} {\n> +\t\tset comment_string [get_config core.commentchar]\n> +\t}\n\nTaking care of both forms. Good!\n\n>  }\n>  \n>  set default_config(branch.autosetupmerge) true\n>  set default_config(merge.tool) {}\n>  set default_config(mergetool.keepbackup) true\n>  set default_config(merge.diffstat) true\n>  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> +set default_config(core.commentstring) {}\n>  \n>  set default_config(gui.encoding) [encoding system]\n>  set default_config(gui.matchtrackingbranch) false\n\n> @@ -3416,15 +3424,16 @@ ${NS}::label $ui_coml \\\n>  \t-anchor w \\\n>  \t-justify left\n>  proc trace_commit_type {varname args} {\n> -\tglobal ui_coml commit_type\n> +\tglobal ui_coml commit_type comment_string\n>  \tswitch -glob -- $commit_type {\n>  \tinitial       {set txt [mc \"Initial Commit Message:\"]}\n>  \tamend         {set txt [mc \"Amended Commit Message:\"]}\n>  \tamend-initial {set txt [mc \"Amended Initial Commit Message:\"]}\n>  \tamend-merge   {set txt [mc \"Amended Merge Commit Message:\"]}\n>  \tmerge         {set txt [mc \"Merge Commit Message:\"]}\n>  \t*             {set txt [mc \"Commit Message:\"]}\n>  \t}\n> +\tappend txt [mc \" (Lines starting with '%s' will be discarded)\" $comment_string]\n>  \t$ui_coml conf -text $txt\n>  }\n>  trace add variable commit_type write trace_commit_type\n\nLike you said in the introduction, this does look messy. Would you\napprove that I remove this hunk while queuing?\n\n> diff --git a/git-gui/lib/commit.tcl b/git-gui/lib/commit.tcl\n> index 208dc2817c..a570f9cdc6 100644\n> --- a/git-gui/lib/commit.tcl\n> +++ b/git-gui/lib/commit.tcl\n> @@ -211,7 +211,9 @@ You must stage at least 1 file before you can commit.\n>  \t# Strip trailing whitespace\n>  \tregsub -all -line {[ \\t\\r]+$} $msg {} msg\n>  \t# Strip comment lines\n> -\tregsub -all {(^|\\n)#[^\\n]*} $msg {\\1} msg\n> +\tglobal comment_string\n> +\tset cmt_rx [strcat {(^|\\n)} [regsub -all {\\W} $comment_string {\\\\&}] {[^\\n]*}]\n\nThis escapes all non-word characters so that they lose their special\nmeaning in a regular expression. Good.\n\n> +\tregsub -all $cmt_rx $msg {\\1} msg\n>  \t# Strip leading empty lines\n>  \tregsub {^\\n*} $msg {} msg\n>  \t# Compress consecutive empty lines\n\nThank you very much!\n\n-- Hannes\n\n"}]}