@matheusbsbs / matheus-bagliano / commits / f20db5ff30
Fork 0

git-gui: Correctly handle UTF-8 encoded commit messages

Uwe Kleine-König discovered git-gui mangled his surname and did not send the proper UTF-8 byte sequence to git-commit-tree when his name appeared in the commit message (e.g. Signed-Off-By line). Turns out this was related to other trouble that I had in the past with trying to use "fconfigure $fd -encoding $enc" to select the stream encoding and let Tcl's IO engine do all of the encoding work for us. Other parts of git-gui were just always setting the file channels to "-encoding binary" and then performing the encoding work themselves using "encoding convertfrom" and "convertto", as that was the only way I could make UTF-8 filenames work properly. I found this same bug in the amend code path, and in the blame display. So its fixed in all three locations (commit creation, reloading message for amend, viewing message in blame). Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Apr 24, 2007 at 02:11 UTC f20db5ff30af2169a0fe8a0afe015c30cdbe0256
1 file changed +26 -20
git-gui.sh
+26 -20
@@ -1067,8 +1067,8 @@ You are currently in the middle of a merge that has not been fully completed. Y
1067 set enc [string tolower [string range $line 9 end]]
1068 }
1069 }
1070 - fconfigure $fd -encoding $enc
1071 - set msg [string trim [read $fd]]
1070 + set msg [encoding convertfrom $enc [read $fd]]
1071 + set msg [string trim $msg]
1072 close $fd
1073 } err]} {
1074 error_popup "Error loading commit data for amend:\n\n$err"
@@ -1291,8 +1291,8 @@ A rescan will be automatically started now.
1291 if {[catch {set enc $repo_config(i18n.commitencoding)}]} {
1292 set enc utf-8
1293 }
1294 - fconfigure $msg_wt -encoding $enc -translation binary
1295 - puts -nonewline $msg_wt $msg
1294 + fconfigure $msg_wt -encoding binary -translation binary
1295 + puts -nonewline $msg_wt [encoding convertto $enc $msg]
1296 close $msg_wt
1297
1298 # -- Create the commit.
@@ -3663,6 +3663,20 @@ proc blame_showcommit {w w_cmit w_line w_file lno} {
3663 incr i
3664 }
3665
3666 + set author_name {}
3667 + set author_email {}
3668 + set author_time {}
3669 + catch {set author_name $blame_data($w,$cmit,author)}
3670 + catch {set author_email $blame_data($w,$cmit,author-mail)}
3671 + catch {set author_time [clock format $blame_data($w,$cmit,author-time)]}
3672 +
3673 + set committer_name {}
3674 + set committer_email {}
3675 + set committer_time {}
3676 + catch {set committer_name $blame_data($w,$cmit,committer)}
3677 + catch {set committer_email $blame_data($w,$cmit,committer-mail)}
3678 + catch {set committer_time [clock format $blame_data($w,$cmit,committer-time)]}
3679 +
3680 if {[catch {set msg $blame_data($w,$cmit,message)}]} {
3681 set msg {}
3682 catch {
@@ -3676,27 +3690,19 @@ proc blame_showcommit {w w_cmit w_line w_file lno} {
3690 set enc [string tolower [string range $line 9 end]]
3691 }
3692 }
3679 - fconfigure $fd -encoding $enc
3680 - set msg [string trim [read $fd]]
3693 + set msg [encoding convertfrom $enc [read $fd]]
3694 + set msg [string trim $msg]
3695 close $fd
3696 +
3697 + set author_name [encoding convertfrom $enc $author_name]
3698 + set committer_name [encoding convertfrom $enc $committer_name]
3699 +
3700 + set blame_data($w,$cmit,author) $author_name
3701 + set blame_data($w,$cmit,committer) $committer_name
3702 }
3703 set blame_data($w,$cmit,message) $msg
3704 }
3705
3686 - set author_name {}
3687 - set author_email {}
3688 - set author_time {}
3689 - catch {set author_name $blame_data($w,$cmit,author)}
3690 - catch {set author_email $blame_data($w,$cmit,author-mail)}
3691 - catch {set author_time [clock format $blame_data($w,$cmit,author-time)]}
3692 -
3693 - set committer_name {}
3694 - set committer_email {}
3695 - set committer_time {}
3696 - catch {set committer_name $blame_data($w,$cmit,committer)}
3697 - catch {set committer_email $blame_data($w,$cmit,committer-mail)}
3698 - catch {set committer_time [clock format $blame_data($w,$cmit,committer-time)]}
3699 -
3706 $w_cmit insert end "commit $cmit\n"
3707 $w_cmit insert end "Author: $author_name $author_email $author_time\n"
3708 $w_cmit insert end "Committer: $committer_name $committer_email $committer_time\n"