git-gui: preserve commit messages in utf-8

The commit message buffer is automatically preserved to a local file but this uses the system encoding which may fail to properly encode unicode text. Forcing this file to use utf-8 preserves the message correctly. Reported-by: Ángel José Riesgo <ajriesgo@gmail.com> Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>

Pat Thoyts committed Apr 19, 2012 at 11:19 UTC fda1ba02f3015310c3ac505292640c90bc97b172
1 file changed +8 -3
git-gui.sh
+8 -3
@@ -1464,7 +1464,7 @@ proc rescan {after {honor_trustmtime 1}} {
1464 (![$ui_comm edit modified]
1465 || [string trim [$ui_comm get 0.0 end]] eq {})} {
1466 if {[string match amend* $commit_type]} {
1467 - } elseif {[load_message GITGUI_MSG]} {
1467 + } elseif {[load_message GITGUI_MSG utf-8]} {
1468 } elseif {[run_prepare_commit_msg_hook]} {
1469 } elseif {[load_message MERGE_MSG]} {
1470 } elseif {[load_message SQUASH_MSG]} {
@@ -1550,7 +1550,7 @@ proc rescan_stage2 {fd after} {
1550 fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
1551 }
1552
1553 -proc load_message {file} {
1553 +proc load_message {file {encoding {}}} {
1554 global ui_comm
1555
1556 set f [gitdir $file]
@@ -1559,6 +1559,9 @@ proc load_message {file} {
1559 return 0
1560 }
1561 fconfigure $fd -eofchar {}
1562 + if {$encoding ne {}} {
1563 + fconfigure $fd -encoding $encoding
1564 + }
1565 set content [string trim [read $fd]]
1566 close $fd
1567 regsub -all -line {[ \r\t]+$} $content {} content
@@ -2267,6 +2270,7 @@ proc do_quit {{rc {1}}} {
2270 && $msg ne {}} {
2271 catch {
2272 set fd [open $save w]
2273 + fconfigure $fd -encoding utf-8
2274 puts -nonewline $fd $msg
2275 close $fd
2276 }
@@ -3836,7 +3840,7 @@ if {[is_enabled transport]} {
3840 }
3841
3842 if {[winfo exists $ui_comm]} {
3839 - set GITGUI_BCK_exists [load_message GITGUI_BCK]
3843 + set GITGUI_BCK_exists [load_message GITGUI_BCK utf-8]
3844
3845 # -- If both our backup and message files exist use the
3846 # newer of the two files to initialize the buffer.
@@ -3873,6 +3877,7 @@ if {[winfo exists $ui_comm]} {
3877 } elseif {$m} {
3878 catch {
3879 set fd [open [gitdir GITGUI_BCK] w]
3880 + fconfigure $fd -encoding utf-8
3881 puts -nonewline $fd $msg
3882 close $fd
3883 set GITGUI_BCK_exists 1