summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 696235c)
raw | patch | inline | side by side (parent: 696235c)
author | Alexander Gavrilov <angavrilov@gmail.com> | |
Wed, 17 Sep 2008 21:07:32 +0000 (01:07 +0400) | ||
committer | Shawn O. Pearce <spearce@spearce.org> | |
Wed, 24 Sep 2008 19:48:32 +0000 (12:48 -0700) |
- 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>
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>
git-gui.sh | patch | blob | history | |
lib/blame.tcl | patch | blob | history | |
lib/diff.tcl | patch | blob | history | |
lib/encoding.tcl | patch | blob | history | |
lib/option.tcl | patch | blob | history |
diff --git a/git-gui.sh b/git-gui.sh
index 4a762355d64f41e89af3aa1ceab713ba16eae380..b37148b7b234f4c0b97ee0b955908272d83128e5 100755 (executable)
--- a/git-gui.sh
+++ b/git-gui.sh
set default_config(user.name) {}
set default_config(user.email) {}
+set default_config(gui.encoding) [encoding system]
set default_config(gui.matchtrackingbranch) false
set default_config(gui.pruneduringfetch) false
set default_config(gui.trustmtime) false
diff --git a/lib/blame.tcl b/lib/blame.tcl
index 7535adb97de1ab374034e95fe590380dd7c7a626..84d55b58287db4d62488c10b748424e1a896b8e4 100644 (file)
--- a/lib/blame.tcl
+++ b/lib/blame.tcl
fconfigure $fd \
-blocking 0 \
-translation lf \
- -encoding [tcl_encoding [gitattr $path encoding UTF-8]]
+ -encoding [get_path_encoding $path]
fileevent $fd readable [cb _read_file $fd $jump]
set current_fd $fd
}
diff --git a/lib/diff.tcl b/lib/diff.tcl
index b0ecfbcb5931ee160dbf24dee49940102029e8f5..8fefc5d9ae9cad3be93946b67f20bf82f09d0c89 100644 (file)
--- a/lib/diff.tcl
+++ b/lib/diff.tcl
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]
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]
}
}
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]} {
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]} {
diff --git a/lib/encoding.tcl b/lib/encoding.tcl
index 7f06b0d47f0fa214c98644757f99f8a036b9689e..e186b0c5695cf2f3b83b9e9ce7d4aa0fd81b975e 100644 (file)
--- a/lib/encoding.tcl
+++ b/lib/encoding.tcl
}
return {}
}
+
+proc get_path_encoding {path} {
+ set tcl_enc [tcl_encoding [get_config gui.encoding]]
+ if {$tcl_enc eq {}} {
+ set tcl_enc [encoding system]
+ }
+ if {$path ne {}} {
+ set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]]
+ if {$enc2 ne {}} {
+ set tcl_enc $enc2
+ }
+ }
+ return $tcl_enc
+}
diff --git a/lib/option.tcl b/lib/option.tcl
index 9b865f6a754aeb0933e1696ae1c9ffaee899e936..40af44e3bff8e328b29a0a5b3f7457233701f853 100644 (file)
--- a/lib/option.tcl
+++ b/lib/option.tcl
# git-gui options editor
# Copyright (C) 2006, 2007 Shawn Pearce
+proc config_check_encodings {} {
+ global repo_config_new global_config_new
+
+ set enc $global_config_new(gui.encoding)
+ if {$enc eq {}} {
+ set global_config_new(gui.encoding) [encoding system]
+ } elseif {[tcl_encoding $enc] eq {}} {
+ error_popup [mc "Invalid global encoding '%s'" $enc]
+ return 0
+ }
+
+ set enc $repo_config_new(gui.encoding)
+ if {$enc eq {}} {
+ set repo_config_new(gui.encoding) [encoding system]
+ } elseif {[tcl_encoding $enc] eq {}} {
+ error_popup [mc "Invalid repo encoding '%s'" $enc]
+ return 0
+ }
+
+ return 1
+}
+
proc save_config {} {
global default_config font_descs
global repo_config global_config
{i-1..99 gui.diffcontext {mc "Number of Diff Context Lines"}}
{i-0..99 gui.commitmsgwidth {mc "Commit Message Text Width"}}
{t gui.newbranchtemplate {mc "New Branch Name Template"}}
+ {t gui.encoding {mc "Default File Contents Encoding"}}
} {
set type [lindex $option 0]
set name [lindex $option 1]
}
proc do_save_config {w} {
+ if {![config_check_encodings]} return
if {[catch {save_config} err]} {
error_popup [strcat [mc "Failed to completely save options:"] "\n\n$err"]
}