Skip to content

Commit fd87004

Browse files
avargitster
authored andcommitted
gitweb: Fix the author initials in blame for non-ASCII names
Change the @author_initials feature Jakub added in v1.6.4-rc2-14-ga36817b to match non-ASCII author initials as intended. The regexp Jakub added was intended to match non-ASCII (/\b([[:upper:]])\B/g). But in Perl this doesn't actually match non-ASCII upper-case characters unless the string being matched against has the UTF8 flag. So when we open a pipe to "git blame" we need to mark the file descriptor we're opening as utf8 explicitly. So as a result it abbreviates me to "AB" not "ÆAB", entirely because "Æ" isn't /[[:upper:]]/ unless the string being matched against has the UTF8 flag. Here's something that demonstrates the issue: #!/usr/bin/env perl use strict; use warnings; binmode STDOUT, ':utf8' if $ENV{UTF8}; open my $fd, "-|", "git", "blame", "--incremental", "--", "Makefile" or die "Can't open: $!"; binmode $fd, ":utf8" if $ENV{UTF8}; while (my $line = <$fd>) { next unless my ($author) = $line =~ /^author (.*)/; my @author_initials = ($author =~ /\b([[:upper:]])\B/g); printf "%s (%s)\n", join("", @author_initials), $author; } When that's run with and without UTF8 being true in the environment it gives, on git.git: $ UTF8=0 perl author-initials.pl | sort | uniq -c | sort -nr | head -n 5 99 JH (Junio C Hamano) 35 JN (Jonathan Nieder) 35 JK (Jeff King) 20 JS (Johannes Schindelin) 16 AB (Ævar Arnfjörð Bjarmason) $ UTF8=1 perl author-initials.pl | sort | uniq -c | sort -nr | head -n 5 99 JH (Junio C Hamano) 35 JN (Jonathan Nieder) 35 JK (Jeff King) 20 JS (Johannes Schindelin) 16 ÆAB (Ævar Arnfjörð Bjarmason) Acked-by: Jakub Narębski <[email protected]> Tested-by: Ævar Arnfjörð Bjarmason <[email protected]> Tested-by: Simon Ruderich <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a3bc3d0 commit fd87004

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

gitweb/gitweb.perl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6626,6 +6626,7 @@ sub git_blame_common {
66266626
$hash_base, '--', $file_name
66276627
or die_error(500, "Open git-blame --porcelain failed");
66286628
}
6629+
binmode $fd, ':utf8';
66296630

66306631
# incremental blame data returns early
66316632
if ($format eq 'data') {

0 commit comments

Comments
 (0)