@@ -6229,7 +6229,7 @@ proc gettree {id} {
6229
6229
set treepending $id
6230
6230
set treefilelist($id ) {}
6231
6231
set treeidlist($id ) {}
6232
- fconfigure $gtf -blocking 0
6232
+ fconfigure $gtf -blocking 0 -encoding binary
6233
6233
filerun $gtf [list gettreeline $gtf $id ]
6234
6234
}
6235
6235
} else {
@@ -6251,11 +6251,12 @@ proc gettreeline {gtf id} {
6251
6251
set line [string range $line 0 [expr {$i -1}]]
6252
6252
if {$diffids ne $nullid2 && [lindex $line 1] ne " blob" } continue
6253
6253
set sha1 [lindex $line 2]
6254
- if {[string index $fname 0] eq " \" " } {
6255
- set fname [lindex $fname 0]
6256
- }
6257
6254
lappend treeidlist($id ) $sha1
6258
6255
}
6256
+ if {[string index $fname 0] eq " \" " } {
6257
+ set fname [lindex $fname 0]
6258
+ }
6259
+ set fname [encoding convertfrom $fname ]
6259
6260
lappend treefilelist($id ) $fname
6260
6261
}
6261
6262
if {![eof $gtf ]} {
@@ -6296,7 +6297,7 @@ proc showfile {f} {
6296
6297
return
6297
6298
}
6298
6299
}
6299
- fconfigure $bf -blocking 0
6300
+ fconfigure $bf -blocking 0 -encoding [get_path_encoding $f ]
6300
6301
filerun $bf [list getblobline $bf $diffids ]
6301
6302
$ctext config -state normal
6302
6303
clear_ctext $commentend
@@ -6334,6 +6335,7 @@ proc mergediff {id} {
6334
6335
global diffids
6335
6336
global parents
6336
6337
global diffcontext
6338
+ global diffencoding
6337
6339
global limitdiffs vfilelimit curview
6338
6340
6339
6341
set diffmergeid $id
@@ -6347,16 +6349,18 @@ proc mergediff {id} {
6347
6349
error_popup " [ mc " Error getting merge diffs:" ] $err "
6348
6350
return
6349
6351
}
6350
- fconfigure $mdf -blocking 0
6352
+ fconfigure $mdf -blocking 0 -encoding binary
6351
6353
set mdifffd($id ) $mdf
6352
6354
set np [llength $parents($curview,$id) ]
6355
+ set diffencoding [get_path_encoding {}]
6353
6356
settabs $np
6354
6357
filerun $mdf [list getmergediffline $mdf $id $np ]
6355
6358
}
6356
6359
6357
6360
proc getmergediffline {mdf id np} {
6358
6361
global diffmergeid ctext cflist mergemax
6359
6362
global difffilestart mdifffd
6363
+ global diffencoding
6360
6364
6361
6365
$ctext conf -state normal
6362
6366
set nr 0
@@ -6368,18 +6372,22 @@ proc getmergediffline {mdf id np} {
6368
6372
}
6369
6373
if {[regexp {^diff --cc (.*)} $line match fname]} {
6370
6374
# start of a new file
6375
+ set fname [encoding convertfrom $fname ]
6371
6376
$ctext insert end " \n "
6372
6377
set here [$ctext index " end - 1c" ]
6373
6378
lappend difffilestart $here
6374
6379
add_flist [list $fname ]
6380
+ set diffencoding [get_path_encoding $fname ]
6375
6381
set l [expr {(78 - [string length $fname ]) / 2}]
6376
6382
set pad [string range " ----------------------------------------" 1 $l ]
6377
6383
$ctext insert end " $pad $fname $pad \n " filesep
6378
6384
} elseif {[regexp {^@@} $line ]} {
6385
+ set line [encoding convertfrom $diffencoding $line ]
6379
6386
$ctext insert end " $line \n " hunksep
6380
6387
} elseif {[regexp {^[0-9a-f]{40}$} $line ] || [regexp {^index} $line ]} {
6381
6388
# do nothing
6382
6389
} else {
6390
+ set line [encoding convertfrom $diffencoding $line ]
6383
6391
# parse the prefix - one ' ', '-' or '+' for each parent
6384
6392
set spaces {}
6385
6393
set minuses {}
@@ -6514,7 +6522,7 @@ proc gettreediffs {ids} {
6514
6522
6515
6523
set treepending $ids
6516
6524
set treediff {}
6517
- fconfigure $gdtf -blocking 0
6525
+ fconfigure $gdtf -blocking 0 -encoding binary
6518
6526
filerun $gdtf [list gettreediffline $gdtf $ids ]
6519
6527
}
6520
6528
@@ -6530,6 +6538,7 @@ proc gettreediffline {gdtf ids} {
6530
6538
if {[string index $file 0] eq " \" " } {
6531
6539
set file [lindex $file 0]
6532
6540
}
6541
+ set file [encoding convertfrom $file ]
6533
6542
lappend treediff $file
6534
6543
}
6535
6544
}
@@ -6587,6 +6596,7 @@ proc getblobdiffs {ids} {
6587
6596
global diffcontext
6588
6597
global ignorespace
6589
6598
global limitdiffs vfilelimit curview
6599
+ global diffencoding
6590
6600
6591
6601
set cmd [diffcmd $ids " -p -C --no-commit-id -U$diffcontext " ]
6592
6602
if {$ignorespace } {
@@ -6600,7 +6610,8 @@ proc getblobdiffs {ids} {
6600
6610
return
6601
6611
}
6602
6612
set diffinhdr 0
6603
- fconfigure $bdf -blocking 0
6613
+ set diffencoding [get_path_encoding {}]
6614
+ fconfigure $bdf -blocking 0 -encoding binary
6604
6615
set blobdifffd($ids ) $bdf
6605
6616
filerun $bdf [list getblobdiffline $bdf $diffids ]
6606
6617
}
@@ -6634,6 +6645,7 @@ proc getblobdiffline {bdf ids} {
6634
6645
global diffids blobdifffd ctext curdiffstart
6635
6646
global diffnexthead diffnextnote difffilestart
6636
6647
global diffinhdr treediffs
6648
+ global diffencoding
6637
6649
6638
6650
set nr 0
6639
6651
$ctext conf -state normal
@@ -6671,10 +6683,13 @@ proc getblobdiffline {bdf ids} {
6671
6683
} else {
6672
6684
set fname [string range $line 2 [expr {$i - 1}]]
6673
6685
}
6686
+ set fname [encoding convertfrom $fname ]
6687
+ set diffencoding [get_path_encoding $fname ]
6674
6688
makediffhdr $fname $ids
6675
6689
6676
6690
} elseif {[regexp {^@@ -([0-9]+)(,[0-9]+)? \+([0-9]+)(,[0-9]+)? @@(.*)} \
6677
6691
$line match f1l f1c f2l f2c rest]} {
6692
+ set line [encoding convertfrom $diffencoding $line ]
6678
6693
$ctext insert end " $line \n " hunksep
6679
6694
set diffinhdr 0
6680
6695
@@ -6684,6 +6699,7 @@ proc getblobdiffline {bdf ids} {
6684
6699
if {[string index $fname 0] eq " \" " } {
6685
6700
set fname [lindex $fname 0]
6686
6701
}
6702
+ set fname [encoding convertfrom $fname ]
6687
6703
set i [lsearch -exact $treediffs($ids) $fname ]
6688
6704
if {$i >= 0} {
6689
6705
setinlist difffilestart $i $curdiffstart
@@ -6694,6 +6710,8 @@ proc getblobdiffline {bdf ids} {
6694
6710
if {[string index $fname 0] eq " \" " } {
6695
6711
set fname [lindex $fname 0]
6696
6712
}
6713
+ set fname [encoding convertfrom $fname ]
6714
+ set diffencoding [get_path_encoding $fname ]
6697
6715
makediffhdr $fname $ids
6698
6716
} elseif {[string compare -length 3 $line " ---" ] == 0} {
6699
6717
# do nothing
@@ -6705,6 +6723,7 @@ proc getblobdiffline {bdf ids} {
6705
6723
$ctext insert end " $line \n " filesep
6706
6724
6707
6725
} else {
6726
+ set line [encoding convertfrom $diffencoding $line ]
6708
6727
set x [string range $line 0 0]
6709
6728
if {$x == " -" || $x == " +" } {
6710
6729
set tag [expr {$x == " +" }]
@@ -9727,7 +9746,7 @@ set encoding_aliases {
9727
9746
{ ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
9728
9747
{ GBK CP936 MS936 windows-936 }
9729
9748
{ JIS_Encoding csJISEncoding }
9730
- { Shift_JIS MS_Kanji csShiftJIS }
9749
+ { Shift_JIS MS_Kanji csShiftJIS ShiftJIS Shift-JIS }
9731
9750
{ Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
9732
9751
EUC-JP }
9733
9752
{ Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
@@ -9769,7 +9788,7 @@ proc tcl_encoding {enc} {
9769
9788
set i [lsearch -exact $lcnames $enc ]
9770
9789
if {$i < 0} {
9771
9790
# look for "isonnn" instead of "iso-nnn" or "iso_nnn"
9772
- if {[regsub {^iso[-_]} $enc iso encx]} {
9791
+ if {[regsub {^( iso|cp|ibm|jis) [-_]} $enc {\1} encx]} {
9773
9792
set i [lsearch -exact $lcnames $encx ]
9774
9793
}
9775
9794
}
@@ -9781,7 +9800,7 @@ proc tcl_encoding {enc} {
9781
9800
foreach e $ll {
9782
9801
set i [lsearch -exact $lcnames $e ]
9783
9802
if {$i < 0} {
9784
- if {[regsub {^iso[-_]} $e iso ex]} {
9803
+ if {[regsub {^( iso|cp|ibm|jis) [-_]} $e {\1} ex]} {
9785
9804
set i [lsearch -exact $lcnames $ex ]
9786
9805
}
9787
9806
}
@@ -9796,6 +9815,34 @@ proc tcl_encoding {enc} {
9796
9815
return {}
9797
9816
}
9798
9817
9818
+ proc gitattr {path attr default} {
9819
+ if {[catch {set r [exec git check-attr $attr -- $path ]}]} {
9820
+ set r unspecified
9821
+ } else {
9822
+ set r [join [lrange [split $r :] 2 end] :]
9823
+ regsub {^ } $r {} r
9824
+ }
9825
+ if {$r eq {unspecified}} {
9826
+ return $default
9827
+ }
9828
+ return $r
9829
+ }
9830
+
9831
+ proc get_path_encoding {path} {
9832
+ global gui_encoding
9833
+ set tcl_enc [tcl_encoding $gui_encoding ]
9834
+ if {$tcl_enc eq {}} {
9835
+ set tcl_enc [encoding system]
9836
+ }
9837
+ if {$path ne {}} {
9838
+ set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc ]]
9839
+ if {$enc2 ne {}} {
9840
+ set tcl_enc $enc2
9841
+ }
9842
+ }
9843
+ return $tcl_enc
9844
+ }
9845
+
9799
9846
# First check that Tcl/Tk is recent enough
9800
9847
if {[catch {package require Tk 8.4} err]} {
9801
9848
show_error {} . [mc " Sorry, gitk cannot run with this version of Tcl/Tk.\n\
@@ -9818,6 +9865,11 @@ if {$tclencoding == {}} {
9818
9865
puts stderr " Warning: encoding $gitencoding is not supported by Tcl/Tk"
9819
9866
}
9820
9867
9868
+ set gui_encoding [encoding system]
9869
+ catch {
9870
+ set gui_encoding [exec git config --get gui.encoding]
9871
+ }
9872
+
9821
9873
set mainfont {Helvetica 9}
9822
9874
set textfont {Courier 9}
9823
9875
set uifont {Helvetica 9 bold}
0 commit comments