git-gui: Handle commit encoding better.
Git prefers that all log messages are encoding in UTF-8. So now when git-gui generates the commit message it converts the commit message text from the internal Tcl Unicode representation into a UTF-8 file. The file is then fed as stdin to git-commit-tree. I had to start using a file here rather than feeding the message in with << as << uses the system encoding, which we may not want. When we reload a commit message via git-cat-file we are getting the raw byte stream, with no encoding performed by Git itself. So unless the new 'encoding' header appears in the message we should probably assume it is utf-8 encoded; but if the header is present we need to use whatever it claims. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Jan 23, 2007 at 04:40 UTC
59885273c337df937430b8731633c2e9020ce8e3
1 file changed
+22
-1
git-gui.sh
+22
-1
@@ -805,6 +805,7 @@ proc read_diff {fd} {
805
806
proc load_last_commit {} {
807
global HEAD PARENT MERGE_HEAD commit_type ui_comm
808
+ global repo_config
809
810
if {[llength $PARENT] == 0} {
811
error_popup {There is nothing to amend.
@@ -831,11 +832,18 @@ current merge activity.
832
set parents [list]
833
if {[catch {
834
set fd [open "| git cat-file commit $curHEAD" r]
835
+ fconfigure $fd -encoding binary -translation lf
836
+ if {[catch {set enc $repo_config(i18n.commitencoding)}]} {
837
+ set enc utf-8
838
+ }
839
while {[gets $fd line] > 0} {
840
if {[string match {parent *} $line]} {
841
lappend parents [string range $line 7 end]
842
+ } elseif {[string match {encoding *} $line]} {
843
+ set enc [string tolower [string range $line 9 end]]
844
}
845
}
846
+ fconfigure $fd -encoding $enc
847
set msg [string trim [read $fd]]
848
close $fd
849
} err]} {
@@ -1027,6 +1035,7 @@ proc commit_committree {fd_wt curHEAD msg} {
1035
global single_commit all_heads current_branch
1036
global ui_status_value ui_comm selected_commit_type
1037
global file_states selected_paths rescan_active
1038
+ global repo_config
1039
1040
gets $fd_wt tree_id
1041
if {$tree_id eq {} || [catch {close $fd_wt} err]} {
@@ -1036,6 +1045,17 @@ proc commit_committree {fd_wt curHEAD msg} {
1045
return
1046
}
1047
1048
+ # -- Build the message.
1049
+ #
1050
+ set msg_p [gitdir COMMIT_EDITMSG]
1051
+ set msg_wt [open $msg_p w]
1052
+ if {[catch {set enc $repo_config(i18n.commitencoding)}]} {
1053
+ set enc utf-8
1054
+ }
1055
+ fconfigure $msg_wt -encoding $enc -translation binary
1056
+ puts -nonewline $msg_wt $msg
1057
+ close $msg_wt
1058
+
1059
# -- Create the commit.
1060
#
1061
set cmd [list git commit-tree $tree_id]
@@ -1048,7 +1068,7 @@ proc commit_committree {fd_wt curHEAD msg} {
1068
# git commit-tree writes to stderr during initial commit.
1069
lappend cmd 2>/dev/null
1070
}
1051
- lappend cmd << $msg
1071
+ lappend cmd <$msg_p
1072
if {[catch {set cmt_id [eval exec $cmd]} err]} {
1073
error_popup "commit-tree failed:\n\n$err"
1074
set ui_status_value {Commit failed.}
@@ -1086,6 +1106,7 @@ proc commit_committree {fd_wt curHEAD msg} {
1106
1107
# -- Cleanup after ourselves.
1108
#
1109
+ catch {file delete $msg_p}
1110
catch {file delete [gitdir MERGE_HEAD]}
1111
catch {file delete [gitdir MERGE_MSG]}
1112
catch {file delete [gitdir SQUASH_MSG]}