From c3561b12139efbb17bf7dbc07b84e3debed1b017 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Tue, 2 May 2023 02:05:46 +0700 Subject: gitk-git: add option to remove indentation on the commit comment Indentation make us hard to copy-paste the content of commit comment from gitk to other medium, especially when creating change log. The "git log --pretty=raw" command does not have option to re-format the pretty output again, so the only way to remove indentation is by trimming left space line by line. This changes add option "Remove indentation on comment" under "General" option in Preference. If its checked the comment will rendered without left space; otherwise it will displayed as usual. --- gitk-git/gitk | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'gitk-git/gitk') diff --git a/gitk-git/gitk b/gitk-git/gitk index 91b16a3bb0..831e2e0178 100755 --- a/gitk-git/gitk +++ b/gitk-git/gitk @@ -1906,6 +1906,7 @@ proc readcommit {id} { proc parsecommit {id contents listed} { global commitinfo + global no_indent set inhdr 1 set comment {} @@ -1949,11 +1950,22 @@ proc parsecommit {id contents listed} { # if we got this via git cat-file, add the indentation set newcomment {} foreach line [split $comment "\n"] { - append newcomment " " + if {!$no_indent} { + append newcomment " " + } append newcomment $line append newcomment "\n" } set comment $newcomment + } else { + if {$no_indent} { + set newcomment {} + foreach line [split $comment "\n"] { + append newcomment [string range $line 4 end] + append newcomment "\n" + } + set comment $newcomment + } } set hasnote [string first "\nNotes:\n" $contents] set diff "" @@ -11794,6 +11806,10 @@ proc prefspage_general {notebook} { grid x $page.webbrowserl $page.webbrowser -sticky ew grid configure $page.webbrowser -padx {0 5} + ttk::checkbutton $page.no_indent -variable no_indent \ + -text [mc "Remove indentation on comment"] + grid x $page.no_indent -sticky w + grid columnconfigure $page 2 -weight 1 return $page @@ -12097,6 +12113,7 @@ proc prefsok {} { global oldprefs prefstop fontpref treediffs global {*}$::config_variables global ctext + global no_indent catch {destroy $prefstop} unset prefstop @@ -12151,6 +12168,9 @@ proc prefsok {} { if {$wrapdefault != $oldprefs(wrapdefault)} { $ctext configure -wrap $wrapdefault } + if {$no_indent != $oldprefs(no_indent)} { + reloadcommits + } } proc formatdate {d} { @@ -12658,6 +12678,7 @@ set autocopy 0 set autoselect 1 set autosellen $hashlength set perfile_attrs 0 +set no_indent 0 if {[tk windowingsystem] eq "aqua"} { set extdifftool "opendiff" @@ -12787,6 +12808,7 @@ set config_variables { maxrefs maxwidth mergecolors + no_indent perfile_attrs reflinecolor refstohide @@ -13033,3 +13055,4 @@ getcommits {} # indent-tabs-mode: t # tab-width: 8 # End: +# vim: ts=4 expandtab -- cgit v1.3