The gitweb author initials feature from a36817b doesn't work with i18n names
The @author_initials feature Jakub added in a36817b claims to use a i18n regexp (/\b([[:upper:]])\B/g), but in Perl this doesn't actually do anything unless the string being matched against has the UTF8 flag.
So as a result it abbreviates me to "AB" not "ÆAB". Here's something that demonstrates the issue:
$ cat author-initials.pl #!/usr/bin/env perl use strict; use warnings;
#binmode STDOUT, ':utf8';
open my $fd, "-|", "git", "blame", "--incremental", "--", "Makefile" or die "Can't open: $!";
#binmode $fd, ":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;
}With those two binmode commands commented out:
$ 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)And uncommented:
$ 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)Jakub, do you see a reason not to just apply this:
gitweb/gitweb.perl +1 -0
@@ -6631,6 +6631,7 @@ sub git_blame_common { $hash_base, '--', $file_name or die_error(500, "Open git-blame --porcelain failed"); } + binmode $fd, ":utf8"; # incremental blame data returns early if ($format eq 'data') {
I haven't gotten an env where I can test gitweb running, but that looks like it should work to me.
Simon Ruderich
Tested-byQuoted 2 lines · Ævar Arnfjörð Bjarmason
I haven't gotten an env where I can test gitweb running, but that looks like it should work to me.
I've tested the patch and it works fine.
Regards
Simon
Signature · 3 lines
+ privacy is necessary + using gnupg http://gnupg.org + public key id: 0x92FEFDB7E44C32F9
PATCH 1/1 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)--- gitweb/gitweb.perl | 1 + 1 file changed, 1 insertion(+)
gitweb/gitweb.perl +1 -0
@@ -6631,6 +6631,7 @@ sub git_blame_common { $hash_base, '--', $file_name or die_error(500, "Open git-blame --porcelain failed"); } + binmode $fh, ':utf8'; # incremental blame data returns early if ($format eq 'data') {
Signature · 1 line
1.8.4.rc2
Re: [PATCH] gitweb: Fix the author initials in blame for non-ASCII names
Quoted 12 lines · Ævar Arnfjörð Bjarmason
Acked-by Jakub Narębski <[email protected]>Tested-by Simon Ruderich <[email protected]>--- gitweb/gitweb.perl | 1 + 1 file changed, 1 insertion(+)gitweb/gitweb.perl +0
-0
gitweb/gitweb.perl sub git_blame_common { · line 6637
Quoted 7 lines
gitweb/gitweb.perl +1
-0@@ -6631,6 +6631,7 @@ sub git_blame_common { $hash_base, '--', $file_name or die_error(500, "Open git-blame --porcelain failed"); } + binmode $fh, ':utf8'; # incremental blame data returns early if ($format eq 'data') {
[Fri Aug 30 17:48:17 2013] gitweb.perl: Global symbol "$fh" requires explicit package name at /home/gitster/w/buildfarm/next/t/../gitweb/gitweb.perl line 6634. [Fri Aug 30 17:48:17 2013] gitweb.perl: Execution of /home/gitster/w/buildfarm/next/t/../gitweb/gitweb.perl aborted due to compilation errors.
Re: [PATCH] gitweb: Fix the author initials in blame for non-ASCII names
Quoted 9 lines · Junio C Hamano
Quoted 7 lines · Ævar Arnfjörð Bjarmason
Acked-by Jakub Narębski <[email protected]>Tested-by Simon Ruderich <[email protected]>--- gitweb/gitweb.perl | 1 + 1 file changed, 1 insertion(+)
Quoted 9 lines
gitweb/gitweb.perl sub git_blame_common { · line 6634
Quoted 9 lines
gitweb/gitweb.perl +1
-0@@ -6631,6 +6631,7 @@ sub git_blame_common { $hash_base, '--', $file_name or die_error(500, "Open git-blame --porcelain failed"); } + binmode $fh, ':utf8';
Should be $fd, not $fh.
Quoted 3 lines
[Fri Aug 30 17:48:17 2013] gitweb.perl: Global symbol "$fh" requires explicit package name at /home/gitster/w/buildfarm/next/t/../gitweb/gitweb.perl line 6634. [Fri Aug 30 17:48:17 2013] gitweb.perl: Execution of /home/gitster/w/buildfarm/next/t/../gitweb/gitweb.perl aborted due to compilation errors.
I wonder how it passed Ævar and Simon tests. Perhaps proposal had $fd?
Signature · 1 line
Jakub Narebski
Re: [PATCH] gitweb: Fix the author initials in blame for non-ASCII names
In reply to Junio C HamanoQuoted 15 lines · Junio C Hamano
gitweb/gitweb.perl sub git_blame_common { · line 6634
Quoted 8 lines · Ævar Arnfjörð Bjarmason
Acked-by Jakub Narębski <[email protected]>Tested-by Simon Ruderich <[email protected]>---
+++ b/gitweb/gitweb.perlgitweb/gitweb.perl +1
-0@@ -6631,6 +6631,7 @@ sub git_blame_common { + binmode $fh, ':utf8';[Fri Aug 30 17:48:17 2013] gitweb.perl: Global symbol "$fh" requires explicit package name at /home/gitster/w/buildfarm/next/t/../gitweb/gitweb.perl line 6634. [Fri Aug 30 17:48:17 2013] gitweb.perl: Execution of /home/gitster/w/buildfarm/next/t/../gitweb/gitweb.perl aborted due to compilation errors.
I think in this function the filehandle is called $fd, not $fh. Has any of you really tested this???
Re: [PATCH] gitweb: Fix the author initials in blame for non-ASCII names
Quoted 2 lines · Junio C Hamano
I think in this function the filehandle is called $fd, not $fh. Has any of you really tested this???
I did, but I applied the change by hand without applying the patch directly and didn't notice the difference. Sorry for that.
Regards
Simon
Signature · 3 lines
+ privacy is necessary + using gnupg http://gnupg.org + public key id: 0x92FEFDB7E44C32F9
Re: [PATCH] gitweb: Fix the author initials in blame for non-ASCII names
In reply to Junio C HamanoQuoted 21 lines · Junio C Hamano
Quoted 16 lines · Junio C Hamano
gitweb/gitweb.perl sub git_blame_common { · line 6634
Quoted 8 lines · Ævar Arnfjörð Bjarmason
Acked-by Jakub Narębski <[email protected]>Tested-by Simon Ruderich <[email protected]>---
+++ b/gitweb/gitweb.perlgitweb/gitweb.perl +1
-0@@ -6631,6 +6631,7 @@ sub git_blame_common { + binmode $fh, ':utf8';[Fri Aug 30 17:48:17 2013] gitweb.perl: Global symbol "$fh" requires explicit package name at /home/gitster/w/buildfarm/next/t/../gitweb/ gitweb.perl line 6634. [Fri Aug 30 17:48:17 2013] gitweb.perl: Execution of /home/gitster/Quoted 2 lines
w/buildfarm/next/t/../gitweb/gitweb.perl aborted due to compilation errors.
Quoted 2 lines
I think in this function the filehandle is called $fd, not $fh. Has any of you really tested this???
What happens if the author name is written in ISO-8859-1 instead of UTF-8 in the actual commit object itself?
I'm pretty sure I've seen this where older commits have a ISO-8859-1 author name and then newer commits have a UTF-8 version of the same author's name.
In fact, in the git repository itself, look at commit 0cb3f80d (UTF-8) and commit 7eb93c89 (ISO-8859-1) to see this in action.
Re: [PATCH] gitweb: Fix the author initials in blame for non-ASCII names
Quoted 6 lines · Kyle J. McKay
Quoted 4 lines · Junio C Hamano
Quoted 3 lines · Junio C Hamano
Quoted 1 line · Ævar Arnfjörð Bjarmason
+ binmode $fh, ':utf8';
Quoted 8 lines
What happens if the author name is written in ISO-8859-1 instead of UTF-8 in the actual commit object itself?
I'm pretty sure I've seen this where older commits have a ISO-8859-1 author name and then newer commits have a UTF-8 version of the same author's name.
In fact, in the git repository itself, look at commit
0cb3f80d(UTF-8) and commit7eb93c89(ISO-8859-1) to see this in action.
Well, then you have a problem, though it is only with old history (before introduction of "encoding" header in commit object).
Better and more complete solution would be to use to_utf8() function instead of 'utf8' layer, which when finding invalid UTF-8 sequence uses $fallback_encoding (by default "latin1", i.e. ISO-8859-1) instead.
In my TODO list is creating PerlIO layer ':utf8-with-fallback' which would replace all those to_utf8() calls...
Signature · 1 line
Jakub Narebski
Re: [PATCH] gitweb: Fix the author initials in blame for non-ASCII names
In reply to Junio C HamanoI did. I just clumsily sent out the wrong patch. I.e. tested it manually on another system, and then fat-fingered $fh instead of $fd.
Should I send another patch or do you want to just fix this one up?
Quoted 20 lines · Junio C Hamano
Quoted 15 lines · Junio C Hamano
gitweb/gitweb.perl sub git_blame_common { · line 6634
Quoted 8 lines · Ævar Arnfjörð Bjarmason
Acked-by Jakub Narębski <[email protected]>Tested-by Simon Ruderich <[email protected]>---
+++ b/gitweb/gitweb.perlgitweb/gitweb.perl +1
-0@@ -6631,6 +6631,7 @@ sub git_blame_common { + binmode $fh, ':utf8';[Fri Aug 30 17:48:17 2013] gitweb.perl: Global symbol "$fh" requires explicit package name at /home/gitster/w/buildfarm/next/t/../gitweb/gitweb.perl line 6634. [Fri Aug 30 17:48:17 2013] gitweb.perl: Execution of /home/gitster/w/buildfarm/next/t/../gitweb/gitweb.perl aborted due to compilation errors.I think in this function the filehandle is called $fd, not $fh. Has any of you really tested this???
[Ævar, sorry for duplication but I accidentally send HTML email; stupid Gmail]
Quoted 5 lines · Ævar Arnfjörð Bjarmason
The @author_initials feature Jakub added in a36817b claims to use a i18n regexp (/\b([[:upper:]])\B/g), but in Perl this doesn't actually do anything unless the string being matched against has the UTF8 flag.
So as a result it abbreviates me to "AB" not "ÆAB".
[...]
Thanks for catching this, and for an analysis.
Quoted 15 lines
Jakub, do you see a reason not to just apply this:
gitweb/gitweb.perl +1
-0@@ -6631,6 +6631,7 @@ sub git_blame_common { $hash_base, '--', $file_name or die_error(500, "Open git-blame --porcelain failed"); } + binmode $fd, ":utf8"; # incremental blame data returns early if ($format eq 'data') {
Quoted 2 lines
I haven't gotten an env where I can test gitweb running, but that looks like it should work to me.
Unfortunetly I cannot check this either, but it looks obviously correct. ACK.
Signature · 1 line
Jakub Narebski