Skip to content

Commit 06569cd

Browse files
angavrilovspearce
authored andcommitted
git-gui: Fix post-commit status with subject in non-locale encoding
As pointed out in msysgit bug #181, when a non-locale encoding is used for commits, post-commit status messages display the subject incorrectly. It happens because the file handle is not properly configured before the subject is read back. This patch fixes it by factoring out the code that is used to setup the output handle into a separate function, and calling it from the reading code. Signed-off-by: Alexander Gavrilov <[email protected]> Acked-by: Robin Rosenberg <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent e612120 commit 06569cd

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

lib/commit.tcl

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,23 @@ proc create_new_commit {} {
115115
rescan ui_ready
116116
}
117117

118+
proc setup_commit_encoding {msg_wt {quiet 0}} {
119+
global repo_config
120+
121+
if {[catch {set enc $repo_config(i18n.commitencoding)}]} {
122+
set enc utf-8
123+
}
124+
set use_enc [tcl_encoding $enc]
125+
if {$use_enc ne {}} {
126+
fconfigure $msg_wt -encoding $use_enc
127+
} else {
128+
if {!$quiet} {
129+
error_popup [mc "warning: Tcl does not support encoding '%s'." $enc]
130+
}
131+
fconfigure $msg_wt -encoding utf-8
132+
}
133+
}
134+
118135
proc commit_tree {} {
119136
global HEAD commit_type file_states ui_comm repo_config
120137
global pch_error
@@ -200,16 +217,7 @@ A good commit message has the following format:
200217
set msg_p [gitdir GITGUI_EDITMSG]
201218
set msg_wt [open $msg_p w]
202219
fconfigure $msg_wt -translation lf
203-
if {[catch {set enc $repo_config(i18n.commitencoding)}]} {
204-
set enc utf-8
205-
}
206-
set use_enc [tcl_encoding $enc]
207-
if {$use_enc ne {}} {
208-
fconfigure $msg_wt -encoding $use_enc
209-
} else {
210-
error_popup [mc "warning: Tcl does not support encoding '%s'." $enc]
211-
fconfigure $msg_wt -encoding utf-8
212-
}
220+
setup_commit_encoding $msg_wt
213221
puts $msg_wt $msg
214222
close $msg_wt
215223

@@ -362,6 +370,7 @@ A rescan will be automatically started now.
362370
append reflogm " ($commit_type)"
363371
}
364372
set msg_fd [open $msg_p r]
373+
setup_commit_encoding $msg_fd 1
365374
gets $msg_fd subject
366375
close $msg_fd
367376
append reflogm {: } $subject

0 commit comments

Comments
 (0)