Sort out to_utf8 usage.
Dan Brook [Fri, 20 Nov 2009 12:39:04 +0000 (12:39 +0000)]
lib/Gitalist/Git/Project.pm
lib/gitweb.pm

index f9f81b8..ae4ac0e 100644 (file)
@@ -27,7 +27,6 @@ class Gitalist::Git::Project with Gitalist::Git::HasUtils {
     use Moose::Autobox;
     use List::MoreUtils qw/any zip/;
     use DateTime;
-    use Gitalist::Util qw(to_utf8);
     use Gitalist::Git::Object::Blob;
     use Gitalist::Git::Object::Tree;
     use Gitalist::Git::Object::Commit;
@@ -259,11 +258,10 @@ method snapshot (NonEmptySimpleStr :$sha1,
     $format = $formats->{$format};
     my $name = $self->name;
     $name =~ s,([^/])/*\.git$,$1,;
-    my $filename = to_utf8($name);
+    my $filename = $name;
     $filename .= "-$sha1.$format";
     $name =~ s/\047/\047\\\047\047/g;
 
-
     my @cmd = ('archive', "--format=$format", "--prefix=$name/", $sha1);
     return ($filename, $self->run_cmd_fh(@cmd));
     # TODO - support compressed archives
index d110b76..9e689d1 100755 (executable)
@@ -20,8 +20,6 @@ use File::Basename qw(basename);
 use FindBin;
 binmode STDOUT, ':utf8';
 
-use Gitalist::Util qw(to_utf8);
-
 BEGIN {
        CGI->compile();
 }
@@ -1159,6 +1157,19 @@ sub project_in_list {
        return @list && scalar(grep { $_->{'path'} eq $project } @list);
 }
 
+# decode sequences of octets in utf8 into Perl's internal form,
+# which is utf-8 with utf8 flag set if needed.  gitweb writes out
+# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
+sub to_utf8 {
+       my $str = shift;
+       if (utf8::valid($str)) {
+               utf8::decode($str);
+               return $str;
+       } else {
+               return decode($fallback_encoding, $str, Encode::FB_DEFAULT);
+       }
+}
+
 ## ----------------------------------------------------------------------
 ## HTML aware string manipulation