git-gui: Cleanup handling of the default encoding.

- Make diffs and blame default to the system (locale)
  encoding instead of hard-coding UTF-8.
- Add a gui.encoding option to allow overriding it.
- gitattributes still have the final word.

The rationale for this is Windows support:

1) Windows people are accustomed to using legacy encodings
   for text files. For many of them defaulting to utf-8
   will be counter-intuitive.
2) Windows doesn't support utf-8 locales, and switching
   the system encoding is a real pain. Thus the option.

This patch also adds proper encoding conversion to Apply Hunk/Line.

Signed-off-by: Alexander Gavrilov <angavrilov@gmail.com>
Tested-by: Johannes Sixt <johannes.sixt@telecom.at>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
Alexander Gavrilov
2008-09-18 01:07:32 +04:00
committed by Shawn O. Pearce
parent 696235c6c1
commit 72e6b00202
5 changed files with 46 additions and 6 deletions

View File

@ -164,11 +164,10 @@ proc show_other_diff {path w m scroll_pos} {
set sz [string length $content]
}
file {
set enc [gitattr $path encoding UTF-8]
set fd [open $path r]
fconfigure $fd \
-eofchar {} \
-encoding [tcl_encoding $enc]
-encoding [get_path_encoding $path]
set content [read $fd $max_sz]
close $fd
set sz [file size $path]
@ -282,7 +281,7 @@ proc start_show_diff {scroll_pos {add_opts {}}} {
set ::current_diff_inheader 1
fconfigure $fd \
-blocking 0 \
-encoding [tcl_encoding [gitattr $path encoding UTF-8]] \
-encoding [get_path_encoding $path] \
-translation lf
fileevent $fd readable [list read_diff $fd $scroll_pos]
}
@ -435,8 +434,9 @@ proc apply_hunk {x y} {
}
if {[catch {
set enc [get_path_encoding $current_diff_path]
set p [eval git_write $apply_cmd]
fconfigure $p -translation binary -encoding binary
fconfigure $p -translation binary -encoding $enc
puts -nonewline $p $current_diff_header
puts -nonewline $p [$ui_diff get $s_lno $e_lno]
close $p} err]} {
@ -604,8 +604,9 @@ proc apply_line {x y} {
set patch "@@ -$hln,$n +$hln,[eval expr $n $sign 1] @@\n$patch"
if {[catch {
set enc [get_path_encoding $current_diff_path]
set p [eval git_write $apply_cmd]
fconfigure $p -translation binary -encoding binary
fconfigure $p -translation binary -encoding $enc
puts -nonewline $p $current_diff_header
puts -nonewline $p $patch
close $p} err]} {