Skip to content

Commit 590915d

Browse files
angavrilovpaulusmack
authored andcommitted
gitk: Fix commit encoding support
This commit fixes two problems with commit encodings: 1) git-log actually uses i18n.logoutputencoding to generate its output, and falls back to i18n.commitencoding only when that option is not set. Thus, gitk should use its value to read the results, if available. 2) The readcommit function did not process encodings at all. This led to randomly appearing misconverted commits if the commit encoding differed from the current locale. Now commit messages should be displayed correctly, except when logoutputencoding is set to an encoding that cannot represent charecters in the message. For example, it is impossible to convert Japanese characters from Shift-JIS to CP-1251 (although the reverse conversion works). The reason for using git log to read the commit and then getting Tcl to convert its output is that is essentially what happens in the normal path through getcommitlines, hence there is less chance for unintended differences in how commits are processed in getcommitlines and do_readcommit. Signed-off-by: Alexander Gavrilov <[email protected]> Signed-off-by: Paul Mackerras <[email protected]>
1 parent e7d6400 commit 590915d

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

gitk

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,9 +1555,27 @@ proc chewcommits {} {
15551555
return 0
15561556
}
15571557

1558+
proc do_readcommit {id} {
1559+
global tclencoding
1560+
1561+
# Invoke git-log to handle automatic encoding conversion
1562+
set fd [open [concat | git log --no-color --pretty=raw -1 $id] r]
1563+
# Read the results using i18n.logoutputencoding
1564+
fconfigure $fd -translation lf -eofchar {}
1565+
if {$tclencoding != {}} {
1566+
fconfigure $fd -encoding $tclencoding
1567+
}
1568+
set contents [read $fd]
1569+
close $fd
1570+
# Remove the heading line
1571+
regsub {^commit [0-9a-f]+\n} $contents {} contents
1572+
1573+
return $contents
1574+
}
1575+
15581576
proc readcommit {id} {
1559-
if {[catch {set contents [exec git cat-file commit $id]}]} return
1560-
parsecommit $id $contents 0
1577+
if {[catch {set contents [do_readcommit $id]}]} return
1578+
parsecommit $id $contents 1
15611579
}
15621580

15631581
proc parsecommit {id contents listed} {
@@ -10558,6 +10576,9 @@ set gitencoding {}
1055810576
catch {
1055910577
set gitencoding [exec git config --get i18n.commitencoding]
1056010578
}
10579+
catch {
10580+
set gitencoding [exec git config --get i18n.logoutputencoding]
10581+
}
1056110582
if {$gitencoding == ""} {
1056210583
set gitencoding "utf-8"
1056310584
}

0 commit comments

Comments
 (0)