-
-
Save a2ikm/2dbfb89114dfa5c543ed to your computer and use it in GitHub Desktop.
patch for git's diff-highlight to show utf8 strings properly. originally from https://gist.github.com/kaosf/d361cd5169fb36297d9c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- diff-highlight.org 2014-06-02 11:39:23.000000000 +0900 | |
+++ diff-highlight 2014-06-02 11:50:13.000000000 +0900 | |
@@ -3,6 +3,8 @@ | |
use warnings FATAL => 'all'; | |
use strict; | |
+use Encode qw(decode_utf8 encode_utf8); | |
+ | |
# Highlight by reversing foreground and background. You could do | |
# other things like bold or underline if you prefer. | |
my $HIGHLIGHT = "\x1b[7m"; | |
@@ -20,10 +22,10 @@ | |
$in_hunk = /^$COLOR*\@/; | |
} | |
elsif (/^$COLOR*-/) { | |
- push @removed, $_; | |
+ push @removed, decode_utf8($_); | |
} | |
elsif (/^$COLOR*\+/) { | |
- push @added, $_; | |
+ push @added, decode_utf8($_); | |
} | |
else { | |
show_hunk(\@removed, \@added); | |
@@ -58,7 +60,7 @@ | |
# If one side is empty, then there is nothing to compare or highlight. | |
if (!@$a || !@$b) { | |
- print @$a, @$b; | |
+ print encode_utf8($_) for @$a, @$b; | |
return; | |
} | |
@@ -67,17 +69,17 @@ | |
# stupid, and only handle multi-line hunks that remove and add the same | |
# number of lines. | |
if (@$a != @$b) { | |
- print @$a, @$b; | |
+ print encode_utf8($_) for @$a, @$b; | |
return; | |
} | |
my @queue; | |
for (my $i = 0; $i < @$a; $i++) { | |
my ($rm, $add) = highlight_pair($a->[$i], $b->[$i]); | |
- print $rm; | |
+ print encode_utf8($rm); | |
push @queue, $add; | |
} | |
- print @queue; | |
+ print encode_utf8($_) for @queue; | |
} | |
sub highlight_pair { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ wget https://raw.githubusercontent.com/git/git/34d9819e0a387be6d49cffe67458036450d6d0d5/contrib/diff-highlight/diff-highlight | |
$ wget https://gist.githubusercontent.com/a2ikm/2dbfb89114dfa5c543ed/raw/e2d8d550ef601c9310712f4187b803658427dd42/diff-highlight.utf8.patch | |
$ patch -u diff-highlight < diff-highlight.utf8.patch | |
$ chmod +x diff-highlight |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment