Merge branch 'master' of git://github.com/broquaint/Gitalist
[catagits/Gitalist.git] / lib / gitweb.pm
index 46e535d..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();
 }
@@ -85,7 +83,7 @@ sub main {
        chomp($GIT);
 
        # absolute fs-path which will be prepended to the project path
-       our $projectroot = "/pub/scm";
+       #our $projectroot = "/pub/scm";
 
        # target of the home link on top of all pages
        our $home_link = $my_uri || "/";
@@ -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