Skip to contentSkip to conversation

git-gui: heed core.commentChar/commentString

PATCH In review Oswald Buddenhagen 2 participants 3 messages Mar 15, 2025 – Mar 16, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git-gui: heed core.commentChar/commentString

This amends 1ae85ff6d (git-gui: strip comments and consecutive empty lines from commit messages, 2024-08-13) to deal with custom comment characters/strings.

The magic commentString value "auto" is not handled, because the option makes no sense to me - it does not support comments in templates and hook output, and it seems far-fetched that someone would introduce comments during editing the message.

Change-Id Iafc0580e818cb5058cfacbafe6e5da40679a1b1c

--

Cc Johannes Sixt <[email protected]>

the textfield label munging is modeled after b9a43869c9 (without introducing the same compatibility problem with tcl 8.5), but i'm not positive it's actually a good idea to have it - it looks a bit messy, while providing info that the command line client assumes to be known.

---
 git-gui/git-gui.sh     | 11 ++++++++++-
 git-gui/lib/commit.tcl |  4 +++-
 2 files changed, 13 insertions(+), 2 deletions(-)
git-gui/git-gui.sh +10 -1
index 887d6d596c..ed14ba679b 100755
@@ -880,16 +880,24 @@ proc apply_config {} {
 			color::sync_with_theme
 		}
 	}
+
+	global comment_string
+	set comment_string [get_config core.commentstring]
+	if {$comment_string eq {}} {
+		set comment_string [get_config core.commentchar]
+	}
 }
 
 set default_config(branch.autosetupmerge) true
 set default_config(merge.tool) {}
 set default_config(mergetool.keepbackup) true
 set default_config(merge.diffstat) true
 set default_config(merge.summary) false
 set default_config(merge.verbosity) 2
 set default_config(user.name) {}
 set default_config(user.email) {}
+set default_config(core.commentchar) "#"
+set default_config(core.commentstring) {}
 
 set default_config(gui.encoding) [encoding system]
 set default_config(gui.matchtrackingbranch) false
@@ -3416,15 +3424,16 @@ ${NS}::label $ui_coml \
 	-anchor w \
 	-justify left
 proc trace_commit_type {varname args} {
-	global ui_coml commit_type
+	global ui_coml commit_type comment_string
 	switch -glob -- $commit_type {
 	initial       {set txt [mc "Initial Commit Message:"]}
 	amend         {set txt [mc "Amended Commit Message:"]}
 	amend-initial {set txt [mc "Amended Initial Commit Message:"]}
 	amend-merge   {set txt [mc "Amended Merge Commit Message:"]}
 	merge         {set txt [mc "Merge Commit Message:"]}
 	*             {set txt [mc "Commit Message:"]}
 	}
+	append txt [mc " (Lines starting with '%s' will be discarded)" $comment_string]
 	$ui_coml conf -text $txt
 }
 trace add variable commit_type write trace_commit_type
git-gui/lib/commit.tcl +3 -1
index 208dc2817c..a570f9cdc6 100644
@@ -211,7 +211,9 @@ You must stage at least 1 file before you can commit.
 	# Strip trailing whitespace
 	regsub -all -line {[ \t\r]+$} $msg {} msg
 	# Strip comment lines
-	regsub -all {(^|\n)#[^\n]*} $msg {\1} msg
+	global comment_string
+	set cmt_rx [strcat {(^|\n)} [regsub -all {\W} $comment_string {\\&}] {[^\n]*}]
+	regsub -all $cmt_rx $msg {\1} msg
 	# Strip leading empty lines
 	regsub {^\n*} $msg {} msg
 	# Compress consecutive empty lines
Signature · 1 line
2.49.0.416.g2f302f2ef0.dirty
#1 lore raw

Am 15.03.25 um 15:09 schrieb Oswald Buddenhagen:

Quoted 12 lines

This amends 1ae85ff6d (git-gui: strip comments and consecutive empty lines from commit messages, 2024-08-13) to deal with custom comment characters/strings.

The magic commentString value "auto" is not handled, because the option makes no sense to me - it does not support comments in templates and hook output, and it seems far-fetched that someone would introduce comments during editing the message.

Change-Id Iafc0580e818cb5058cfacbafe6e5da40679a1b1c
Quoted 8 lines

--

Cc Johannes Sixt <[email protected]>

the textfield label munging is modeled after b9a43869c9 (without introducing the same compatibility problem with tcl 8.5), but i'm not positive it's actually a good idea to have it - it looks a bit messy, while providing info that the command line client assumes to be known.

See below.

Quoted 10 lines
---
 git-gui/git-gui.sh     | 11 ++++++++++-
 git-gui/lib/commit.tcl |  4 +++-
 2 files changed, 13 insertions(+), 2 deletions(-)
git-gui/git-gui.sh +0 -0
index 887d6d596c..ed14ba679b 100755

git-gui/git-gui.sh proc apply_config {} { · line 888

Quoted 9 lines
git-gui/git-gui.sh +6 -0
@@ -880,16 +880,24 @@ proc apply_config {} {
 			color::sync_with_theme
 		}
 	}
+
+	global comment_string
+	set comment_string [get_config core.commentstring]
+	if {$comment_string eq {}} {
+		set comment_string [get_config core.commentchar]
+	}

Taking care of both forms. Good!

Quoted 24 lines
git-gui/git-gui.sh +3 -1
 }
 
 set default_config(branch.autosetupmerge) true
 set default_config(merge.tool) {}
 set default_config(mergetool.keepbackup) true
 set default_config(merge.diffstat) true
 set default_config(merge.summary) false
 set default_config(merge.verbosity) 2
 set default_config(user.name) {}
 set default_config(user.email) {}
+set default_config(core.commentchar) "#"
+set default_config(core.commentstring) {}
 
 set default_config(gui.encoding) [encoding system]
 set default_config(gui.matchtrackingbranch) false
@@ -3416,15 +3424,16 @@ ${NS}::label $ui_coml \
 	-anchor w \
 	-justify left
 proc trace_commit_type {varname args} {
-	global ui_coml commit_type
+	global ui_coml commit_type comment_string
 	switch -glob -- $commit_type {
 	initial       {set txt [mc "Initial Commit Message:"]}

git-gui/git-gui.sh ${NS}::label $ui_coml \ · line 3439

Quoted 10 lines
git-gui/git-gui.sh +1 -0
 	amend         {set txt [mc "Amended Commit Message:"]}
 	amend-initial {set txt [mc "Amended Initial Commit Message:"]}
 	amend-merge   {set txt [mc "Amended Merge Commit Message:"]}
 	merge         {set txt [mc "Merge Commit Message:"]}
 	*             {set txt [mc "Commit Message:"]}
 	}
+	append txt [mc " (Lines starting with '%s' will be discarded)" $comment_string]
 	$ui_coml conf -text $txt
 }
 trace add variable commit_type write trace_commit_type

Like you said in the introduction, this does look messy. Would you approve that I remove this hunk while queuing?

git-gui/lib/commit.tcl You must stage at least 1 file before you can commit. · line 215

Quoted 11 lines
git-gui/lib/commit.tcl +2 -1
index 208dc2817c..a570f9cdc6 100644
@@ -211,7 +211,9 @@ You must stage at least 1 file before you can commit.
 	# Strip trailing whitespace
 	regsub -all -line {[ \t\r]+$} $msg {} msg
 	# Strip comment lines
-	regsub -all {(^|\n)#[^\n]*} $msg {\1} msg
+	global comment_string
+	set cmt_rx [strcat {(^|\n)} [regsub -all {\W} $comment_string {\\&}] {[^\n]*}]

This escapes all non-word characters so that they lose their special meaning in a regular expression. Good.

git-gui/lib/commit.tcl You must stage at least 1 file before you can commit. · line 219

Quoted 4 lines
git-gui/lib/commit.tcl +1 -0
+	regsub -all $cmt_rx $msg {\1} msg
 	# Strip leading empty lines
 	regsub {^\n*} $msg {} msg
 	# Compress consecutive empty lines

Thank you very much!

-- Hannes

#2 lore raw
Quoted 6 lines · Johannes Sixt

Am 15.03.25 um 15:09 schrieb Oswald Buddenhagen:

git-gui/git-gui.sh ${NS}::label $ui_coml \ · line 3436

Quoted 1 line
git-gui/git-gui.sh +1 -0
+	append txt [mc " (Lines starting with '%s' will be discarded)" $comment_string]

Like you said in the introduction, this does look messy. Would you approve that I remove this hunk while queuing?

yep, go ahead!