gitweb: No periods for error messages
[gitweb.git] / gitweb / gitweb.perl
index 6e4261d5f23174cc771dad193ba522116d1ab498..62849014574861d0da899d31c49f401dcaa168f3 100755 (executable)
 binmode STDOUT, ':utf8';
 
 our $cgi = new CGI;
-our $version = "@@GIT_VERSION@@";
+our $version = "++GIT_VERSION++";
 our $my_url = $cgi->url();
 our $my_uri = $cgi->url(-absolute => 1);
 our $rss_link = "";
 
 # core git executable to use
 # this can just be "git" if your webserver has a sensible PATH
-our $GIT = "@@GIT_BINDIR@@/git";
+our $GIT = "++GIT_BINDIR++/git";
 
 # absolute fs-path which will be prepended to the project path
 #our $projectroot = "/pub/scm";
-our $projectroot = "@@GITWEB_PROJECTROOT@@";
-
-# version of the core git binary
-our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
+our $projectroot = "++GITWEB_PROJECTROOT++";
 
 # location for temporary files needed for diffs
 our $git_temp = "/tmp/gitweb";
-if (! -d $git_temp) {
-       mkdir($git_temp, 0700) || die_error("Couldn't mkdir $git_temp");
-}
 
 # target of the home link on top of all pages
 our $home_link = $my_uri;
 
 # name of your site or organization to appear in page titles
 # replace this with something more descriptive for clearer bookmarks
-our $site_name = "@@GITWEB_SITENAME@@" || $ENV{'SERVER_NAME'} || "Untitled";
+our $site_name = "++GITWEB_SITENAME++" || $ENV{'SERVER_NAME'} || "Untitled";
 
 # html text to include at home page
-our $home_text = "@@GITWEB_HOMETEXT@@";
+our $home_text = "++GITWEB_HOMETEXT++";
 
 # URI of default stylesheet
-our $stylesheet = "@@GITWEB_CSS@@";
+our $stylesheet = "++GITWEB_CSS++";
+# URI of GIT logo
+our $logo = "++GITWEB_LOGO++";
 
 # source of projects list
-our $projects_list = "@@GITWEB_LIST@@" || "$projectroot";
+our $projects_list = "++GITWEB_LIST++";
 
 # default blob_plain mimetype and default charset for text/plain blob
 our $default_blob_plain_mimetype = 'text/plain';
 # (relative to the current git repository)
 our $mimetypes_file = undef;
 
+our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
+require $GITWEB_CONFIG if -e $GITWEB_CONFIG;
+
+# version of the core git binary
+our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
+
+$projects_list ||= $projectroot;
+if (! -d $git_temp) {
+       mkdir($git_temp, 0700) || die_error(undef, "Couldn't mkdir $git_temp");
+}
+
+# ======================================================================
 # input validation and dispatch
 our $action = $cgi->param('a');
 if (defined $action) {
        if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
-               undef $action;
-               die_error(undef, "Invalid action parameter.");
+               die_error(undef, "Invalid action parameter");
        }
-       if ($action eq "git-logo.png") {
-               git_logo();
-               exit;
-       } elsif ($action eq "opml") {
+       # action which does not check rest of parameters
+       if ($action eq "opml") {
                git_opml();
                exit;
        }
 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
 if (defined $project) {
        $project =~ s|^/||; $project =~ s|/$||;
-       $project = validate_input($project);
-       if (!defined($project)) {
-               die_error(undef, "Invalid project parameter.");
+       if (!validate_input($project)) {
+               die_error(undef, "Invalid project parameter");
        }
        if (!(-d "$projectroot/$project")) {
-               undef $project;
-               die_error(undef, "No such directory.");
+               die_error(undef, "No such directory");
        }
        if (!(-e "$projectroot/$project/HEAD")) {
-               undef $project;
-               die_error(undef, "No such project.");
+               die_error(undef, "No such project");
        }
        $rss_link = "<link rel=\"alternate\" title=\"" . esc_param($project) . " log\" href=\"" .
                    "$my_uri?" . esc_param("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
 
 our $file_name = $cgi->param('f');
 if (defined $file_name) {
-       $file_name = validate_input($file_name);
-       if (!defined($file_name)) {
-               die_error(undef, "Invalid file parameter.");
+       if (!validate_input($file_name)) {
+               die_error(undef, "Invalid file parameter");
        }
 }
 
 our $hash = $cgi->param('h');
 if (defined $hash) {
-       $hash = validate_input($hash);
-       if (!defined($hash)) {
-               die_error(undef, "Invalid hash parameter.");
+       if (!validate_input($hash)) {
+               die_error(undef, "Invalid hash parameter");
        }
 }
 
 our $hash_parent = $cgi->param('hp');
 if (defined $hash_parent) {
-       $hash_parent = validate_input($hash_parent);
-       if (!defined($hash_parent)) {
-               die_error(undef, "Invalid hash parent parameter.");
+       if (!validate_input($hash_parent)) {
+               die_error(undef, "Invalid hash parent parameter");
        }
 }
 
 our $hash_base = $cgi->param('hb');
 if (defined $hash_base) {
-       $hash_base = validate_input($hash_base);
-       if (!defined($hash_base)) {
-               die_error(undef, "Invalid hash base parameter.");
+       if (!validate_input($hash_base)) {
+               die_error(undef, "Invalid hash base parameter");
        }
 }
 
 our $page = $cgi->param('pg');
 if (defined $page) {
        if ($page =~ m/[^0-9]$/) {
-               undef $page;
-               die_error(undef, "Invalid page parameter.");
+               die_error(undef, "Invalid page parameter");
        }
 }
 
 our $searchtext = $cgi->param('s');
 if (defined $searchtext) {
        if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) {
-               undef $searchtext;
-               die_error(undef, "Invalid search parameter.");
+               die_error(undef, "Invalid search parameter");
        }
        $searchtext = quotemeta $searchtext;
 }
 
 $action = 'summary' if (!defined($action));
 if (!defined($actions{$action})) {
-       undef $action;
-       die_error(undef, "Unknown action.");
+       die_error(undef, "Unknown action");
 }
 $actions{$action}->();
 exit;
@@ -423,7 +418,7 @@ sub git_get_hash_by_path {
        my $tree = $base;
 
        open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
-               or die_error(undef, "Open git-ls-tree failed.");
+               or die_error(undef, "Open git-ls-tree failed");
        my $line = <$fd>;
        close $fd or return undef;
 
@@ -873,7 +868,7 @@ sub git_header_html {
 EOF
        print "<div class=\"page_header\">\n" .
              "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
-             "<img src=\"$my_uri?" . esc_param("a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
+             "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
              "</a>\n";
        print $cgi->a({-href => esc_param($home_link)}, "projects") . " / ";
        if (defined $project) {
@@ -1267,36 +1262,16 @@ sub git_diff_print {
 ## ======================================================================
 ## actions
 
-# git-logo (cached in browser for one day)
-sub git_logo {
-       binmode STDOUT, ':raw';
-       print $cgi->header(-type => 'image/png', -expires => '+1d');
-       # cat git-logo.png | hexdump -e '16/1 " %02x"  "\n"' | sed 's/ /\\x/g'
-       print   "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
-               "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
-               "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
-               "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
-               "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
-               "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
-               "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
-               "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
-               "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
-               "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
-               "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
-               "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
-               "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
-}
-
 sub git_project_list {
        my $order = $cgi->param('o');
        if (defined $order && $order !~ m/project|descr|owner|age/) {
-               die_error(undef, "Invalid order parameter '$order'.");
+               die_error(undef, "Invalid order parameter '$order'");
        }
 
        my @list = git_read_projects();
        my @projects;
        if (!@list) {
-               die_error(undef, "No projects found.");
+               die_error(undef, "No projects found");
        }
        foreach my $pr (@list) {
                my $head = git_read_head($pr->{'path'});
@@ -1430,7 +1405,7 @@ sub git_summary {
              "</table>\n";
 
        open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_read_head($project)
-               or die_error(undef, "Open git-rev-list failed.");
+               or die_error(undef, "Open git-rev-list failed");
        my @revlist = map { chomp; $_ } <$fd>;
        close $fd;
        git_header_div('shortlog');
@@ -1486,10 +1461,10 @@ sub git_tag {
 sub git_blame2 {
        my $fd;
        my $ftype;
-       die_error(undef, "Permission denied.") if (!git_get_project_config_bool ('blame'));
+       die_error(undef, "Permission denied") if (!git_get_project_config_bool ('blame'));
        die_error('404 Not Found', "File name not defined") if (!$file_name);
        $hash_base ||= git_read_head($project);
-       die_error(undef, "Reading commit failed") unless ($hash_base);
+       die_error(undef, "Couldn't find base commit") unless ($hash_base);
        my %co = git_read_commit($hash_base)
                or die_error(undef, "Reading commit failed");
        if (!defined $hash) {
@@ -1498,10 +1473,10 @@ sub git_blame2 {
        }
        $ftype = git_get_type($hash);
        if ($ftype !~ "blob") {
-               die_error("400 Bad Request", "object is not a blob");
+               die_error("400 Bad Request", "Object is not a blob");
        }
        open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
-               or die_error(undef, "Open git-blame failed.");
+               or die_error(undef, "Open git-blame failed");
        git_header_html();
        my $formats_nav =
                $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
@@ -1544,18 +1519,18 @@ sub git_blame2 {
 
 sub git_blame {
        my $fd;
-       die_error('403 Permission denied', "Permission denied.") if (!git_get_project_config_bool ('blame'));
-       die_error('404 Not Found', "What file will it be, master?") if (!$file_name);
+       die_error('403 Permission denied', "Permission denied") if (!git_get_project_config_bool ('blame'));
+       die_error('404 Not Found', "File name not defined") if (!$file_name);
        $hash_base ||= git_read_head($project);
-       die_error(undef, "Reading commit failed.") unless ($hash_base);
+       die_error(undef, "Couldn't find base commit") unless ($hash_base);
        my %co = git_read_commit($hash_base)
-               or die_error(undef, "Reading commit failed.");
+               or die_error(undef, "Reading commit failed");
        if (!defined $hash) {
                $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
-                       or die_error(undef, "Error lookup file.");
+                       or die_error(undef, "Error lookup file");
        }
        open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
-               or die_error(undef, "Open git-annotate failed.");
+               or die_error(undef, "Open git-annotate failed");
        git_header_html();
        my $formats_nav =
                $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
@@ -1665,14 +1640,14 @@ sub git_blob_plain {
                if (defined $file_name) {
                        my $base = $hash_base || git_read_head($project);
                        $hash = git_get_hash_by_path($base, $file_name, "blob")
-                               or die_error(undef, "Error lookup file.");
+                               or die_error(undef, "Error lookup file");
                } else {
-                       die_error(undef, "No file name defined.");
+                       die_error(undef, "No file name defined");
                }
        }
        my $type = shift;
        open my $fd, "-|", $GIT, "cat-file", "blob", $hash
-               or die_error("Couldn't cat $file_name, $hash");
+               or die_error(undef, "Couldn't cat $file_name, $hash");
 
        $type ||= git_blob_plain_mimetype($fd, $file_name);
 
@@ -1698,14 +1673,14 @@ sub git_blob {
                if (defined $file_name) {
                        my $base = $hash_base || git_read_head($project);
                        $hash = git_get_hash_by_path($base, $file_name, "blob")
-                               or die_error(undef, "Error lookup file.");
+                               or die_error(undef, "Error lookup file");
                } else {
-                       die_error(undef, "No file name defined.");
+                       die_error(undef, "No file name defined");
                }
        }
        my $have_blame = git_get_project_config_bool ('blame');
        open my $fd, "-|", $GIT, "cat-file", "blob", $hash
-               or die_error(undef, "Couldn't cat $file_name, $hash.");
+               or die_error(undef, "Couldn't cat $file_name, $hash");
        my $mimetype = git_blob_plain_mimetype($fd, $file_name);
        if ($mimetype !~ m/^text\//) {
                close $fd;
@@ -1763,9 +1738,9 @@ sub git_tree {
        }
        $/ = "\0";
        open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
-               or die_error(undef, "Open git-ls-tree failed.");
+               or die_error(undef, "Open git-ls-tree failed");
        my @entries = map { chomp; $_ } <$fd>;
-       close $fd or die_error(undef, "Reading tree failed.");
+       close $fd or die_error(undef, "Reading tree failed");
        $/ = "\n";
 
        my $refs = read_info_ref();
@@ -1773,6 +1748,7 @@ sub git_tree {
        git_header_html();
        my $base_key = "";
        my $base = "";
+       my $have_blame = git_get_project_config_bool ('blame');
        if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
                $base_key = ";hb=$hash_base";
                git_page_nav('tree','', $hash_base);
@@ -1808,9 +1784,11 @@ sub git_tree {
                              $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name"), -class => "list"}, esc_html($t_name)) .
                              "</td>\n" .
                              "<td class=\"link\">" .
-                             $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
-#                            " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") .
-                             " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$t_hash;hb=$hash_base;f=$base$t_name")}, "history") .
+                             $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob");
+                       if ($have_blame) {
+                               print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame");
+                       }
+                       print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$t_hash;hb=$hash_base;f=$base$t_name")}, "history") .
                              " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") .
                              "</td>\n";
                } elsif ($t_type eq "tree") {
@@ -1841,7 +1819,7 @@ sub git_log {
 
        my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
        open my $fd, "-|", $GIT, "rev-list", $limit, $hash
-               or die_error(undef, "Open git-rev-list failed.");
+               or die_error(undef, "Open git-rev-list failed");
        my @revlist = map { chomp; $_ } <$fd>;
        close $fd;
 
@@ -1902,7 +1880,7 @@ sub git_log {
 sub git_commit {
        my %co = git_read_commit($hash);
        if (!%co) {
-               die_error(undef, "Unknown commit object.");
+               die_error(undef, "Unknown commit object");
        }
        my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
        my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
@@ -1912,9 +1890,9 @@ sub git_commit {
                $parent = "--root";
        }
        open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
-               or die_error(undef, "Open git-diff-tree failed.");
+               or die_error(undef, "Open git-diff-tree failed");
        my @difftree = map { chomp; $_ } <$fd>;
-       close $fd or die_error(undef, "Reading git-diff-tree failed.");
+       close $fd or die_error(undef, "Reading git-diff-tree failed");
 
        # non-textual hash id's can be cached
        my $expires;
@@ -2130,15 +2108,15 @@ sub git_commitdiff {
        mkdir($git_temp, 0700);
        my %co = git_read_commit($hash);
        if (!%co) {
-               die_error(undef, "Unknown commit object.");
+               die_error(undef, "Unknown commit object");
        }
        if (!defined $hash_parent) {
                $hash_parent = $co{'parent'};
        }
        open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
-               or die_error(undef, "Open git-diff-tree failed.");
+               or die_error(undef, "Open git-diff-tree failed");
        my @difftree = map { chomp; $_ } <$fd>;
-       close $fd or die_error(undef, "Reading diff-tree failed.");
+       close $fd or die_error(undef, "Reading git-diff-tree failed");
 
        # non-textual hash id's can be cached
        my $expires;
@@ -2216,9 +2194,9 @@ sub git_commitdiff {
 sub git_commitdiff_plain {
        mkdir($git_temp, 0700);
        open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
-               or die_error(undef, "Open git-diff-tree failed.");
+               or die_error(undef, "Open git-diff-tree failed");
        my @difftree = map { chomp; $_ } <$fd>;
-       close $fd or die_error(undef, "Reading diff-tree failed.");
+       close $fd or die_error(undef, "Reading diff-tree failed");
 
        # try to figure out the next tag after this commit
        my $tagname;
@@ -2276,7 +2254,7 @@ sub git_history {
        my $ftype;
        my %co = git_read_commit($hash_base);
        if (!%co) {
-               die_error(undef, "Unknown commit object.");
+               die_error(undef, "Unknown commit object");
        }
        my $refs = read_info_ref();
        git_header_html();
@@ -2334,14 +2312,14 @@ sub git_history {
 
 sub git_search {
        if (!defined $searchtext) {
-               die_error("", "Text field empty.");
+               die_error(undef, "Text field empty");
        }
        if (!defined $hash) {
                $hash = git_read_head($project);
        }
        my %co = git_read_commit($hash);
        if (!%co) {
-               die_error(undef, "Unknown commit object.");
+               die_error(undef, "Unknown commit object");
        }
        # pickaxe may take all resources of your box and run for several minutes
        # with every query - so decide by yourself how public you make this feature :)
@@ -2479,7 +2457,7 @@ sub git_shortlog {
 
        my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
        open my $fd, "-|", $GIT, "rev-list", $limit, $hash
-               or die_error(undef, "Open git-rev-list failed.");
+               or die_error(undef, "Open git-rev-list failed");
        my @revlist = map { chomp; $_ } <$fd>;
        close $fd;
 
@@ -2507,9 +2485,9 @@ sub git_shortlog {
 sub git_rss {
        # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
        open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_read_head($project)
-               or die_error(undef, "Open git-rev-list failed.");
+               or die_error(undef, "Open git-rev-list failed");
        my @revlist = map { chomp; $_ } <$fd>;
-       close $fd or die_error(undef, "Reading rev-list failed.");
+       close $fd or die_error(undef, "Reading git-rev-list failed");
        print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
        print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
              "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";