Skip to content

Commit

Permalink
git-gui: Fix post-commit status with subject in non-locale encoding
Browse files Browse the repository at this point in the history
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 <angavrilov@gmail.com>
Acked-by: Robin Rosenberg <robin.rosenberg@gmail.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
  • Loading branch information
Alexander Gavrilov authored and Shawn O. Pearce committed Feb 1, 2009
1 parent e612120 commit 06569cd
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions lib/commit.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,23 @@ proc create_new_commit {} {
rescan ui_ready
}

proc setup_commit_encoding {msg_wt {quiet 0}} {
global repo_config

if {[catch {set enc $repo_config(i18n.commitencoding)}]} {
set enc utf-8
}
set use_enc [tcl_encoding $enc]
if {$use_enc ne {}} {
fconfigure $msg_wt -encoding $use_enc
} else {
if {!$quiet} {
error_popup [mc "warning: Tcl does not support encoding '%s'." $enc]
}
fconfigure $msg_wt -encoding utf-8
}
}

proc commit_tree {} {
global HEAD commit_type file_states ui_comm repo_config
global pch_error
Expand Down Expand Up @@ -200,16 +217,7 @@ A good commit message has the following format:
set msg_p [gitdir GITGUI_EDITMSG]
set msg_wt [open $msg_p w]
fconfigure $msg_wt -translation lf
if {[catch {set enc $repo_config(i18n.commitencoding)}]} {
set enc utf-8
}
set use_enc [tcl_encoding $enc]
if {$use_enc ne {}} {
fconfigure $msg_wt -encoding $use_enc
} else {
error_popup [mc "warning: Tcl does not support encoding '%s'." $enc]
fconfigure $msg_wt -encoding utf-8
}
setup_commit_encoding $msg_wt
puts $msg_wt $msg
close $msg_wt

Expand Down Expand Up @@ -362,6 +370,7 @@ A rescan will be automatically started now.
append reflogm " ($commit_type)"
}
set msg_fd [open $msg_p r]
setup_commit_encoding $msg_fd 1
gets $msg_fd subject
close $msg_fd
append reflogm {: } $subject
Expand Down

0 comments on commit 06569cd

Please sign in to comment.