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>
diff --git a/git-gui.sh b/git-gui.sh
index 7dddc7d..936b367 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -1464,7 +1464,7 @@
 		(![$ui_comm edit modified]
 		|| [string trim [$ui_comm get 0.0 end]] eq {})} {
 		if {[string match amend* $commit_type]} {
-		} elseif {[load_message GITGUI_MSG]} {
+		} elseif {[load_message GITGUI_MSG utf-8]} {
 		} elseif {[run_prepare_commit_msg_hook]} {
 		} elseif {[load_message MERGE_MSG]} {
 		} elseif {[load_message SQUASH_MSG]} {
@@ -1550,7 +1550,7 @@
 	fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
 }
 
-proc load_message {file} {
+proc load_message {file {encoding {}}} {
 	global ui_comm
 
 	set f [gitdir $file]
@@ -1559,6 +1559,9 @@
 			return 0
 		}
 		fconfigure $fd -eofchar {}
+		if {$encoding ne {}} {
+			fconfigure $fd -encoding $encoding
+		}
 		set content [string trim [read $fd]]
 		close $fd
 		regsub -all -line {[ \r\t]+$} $content {} content
@@ -2267,6 +2270,7 @@
 				&& $msg ne {}} {
 				catch {
 					set fd [open $save w]
+					fconfigure $fd -encoding utf-8
 					puts -nonewline $fd $msg
 					close $fd
 				}
@@ -3836,7 +3840,7 @@
 }
 
 if {[winfo exists $ui_comm]} {
-	set GITGUI_BCK_exists [load_message GITGUI_BCK]
+	set GITGUI_BCK_exists [load_message GITGUI_BCK utf-8]
 
 	# -- If both our backup and message files exist use the
 	#    newer of the two files to initialize the buffer.
@@ -3873,6 +3877,7 @@
 			} elseif {$m} {
 				catch {
 					set fd [open [gitdir GITGUI_BCK] w]
+					fconfigure $fd -encoding utf-8
 					puts -nonewline $fd $msg
 					close $fd
 					set GITGUI_BCK_exists 1