Skip to content

Commit

Permalink
gitk: Fix commit encoding support
Browse files Browse the repository at this point in the history
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 <angavrilov@gmail.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
  • Loading branch information
Alexander Gavrilov authored and Paul Mackerras committed Nov 13, 2008
1 parent e7d6400 commit 590915d
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions gitk
Original file line number Diff line number Diff line change
Expand Up @@ -1555,9 +1555,27 @@ proc chewcommits {} {
return 0
}

proc do_readcommit {id} {
global tclencoding

# Invoke git-log to handle automatic encoding conversion
set fd [open [concat | git log --no-color --pretty=raw -1 $id] r]
# Read the results using i18n.logoutputencoding
fconfigure $fd -translation lf -eofchar {}
if {$tclencoding != {}} {
fconfigure $fd -encoding $tclencoding
}
set contents [read $fd]
close $fd
# Remove the heading line
regsub {^commit [0-9a-f]+\n} $contents {} contents

return $contents
}

proc readcommit {id} {
if {[catch {set contents [exec git cat-file commit $id]}]} return
parsecommit $id $contents 0
if {[catch {set contents [do_readcommit $id]}]} return
parsecommit $id $contents 1
}

proc parsecommit {id contents listed} {
Expand Down Expand Up @@ -10558,6 +10576,9 @@ set gitencoding {}
catch {
set gitencoding [exec git config --get i18n.commitencoding]
}
catch {
set gitencoding [exec git config --get i18n.logoutputencoding]
}
if {$gitencoding == ""} {
set gitencoding "utf-8"
}
Expand Down

0 comments on commit 590915d

Please sign in to comment.