]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/git.pm
git: Manually decode git output from utf-8, avoids warning messages on invalidly...
[git.ikiwiki.info.git] / IkiWiki / Plugin / git.pm
index 042c69f5a043699ff275f4acb7433a9482a366c8..b386ab71bfa6b0d0feffcb53fb167f17c1ac016d 100644 (file)
@@ -136,14 +136,16 @@ sub safe_git (&@) {
        }
        # In parent.
 
+       # git output is probably utf-8 encoded, but may contain
+       # other encodings or invalidly encoded stuff. So do not rely
+       # on the normal utf-8 IO layer, decode it by hand.
+       binmode($OUT);
+
        my @lines;
        while (<$OUT>) {
+               $_=decode_utf8($_, 0);
+
                chomp;
-               
-               # check for invalid utf-8, and toss it back to avoid crashes
-               if (! utf8::valid($_)) {
-                       $_=encode_utf8($_);
-               }
 
                push @lines, $_;
        }
@@ -447,7 +449,7 @@ sub rcs_commit_staged ($$$) {
        # Set the commit author and email to the web committer.
        my %env=%ENV;
        if (defined $user || defined $ipaddr) {
-               my $u=defined $user ? $user : $ipaddr;
+               my $u=encode_utf8(defined $user ? $user : $ipaddr);
                $ENV{GIT_AUTHOR_NAME}=$u;
                $ENV{GIT_AUTHOR_EMAIL}="$u\@web";
        }