Added feature to gitweb tree mode: In current directory, display README if available.
[gitweb-sgk] / gitweb.cgi
index 16021cc..a3b31ce 100755 (executable)
@@ -3846,6 +3846,37 @@ sub insert_file {
        close $fd;
 }
 
        close $fd;
 }
 
+sub insert_html_file {
+       my $file_name = shift;
+       insert_file($file_name);
+}
+
+sub insert_text_file {
+       my $file_name = shift;
+
+       open my $fd, $file_name or die_error(500, "Couldn't open $file_name");
+
+       print "<pre>";
+       while (my $line = <$fd>) {
+               print to_utf8($line);
+       }
+       print "</pre>";
+}
+
+sub insert_markdown_file {
+       my $file_name = shift;
+
+       # TODO: Make this a config option?
+       my $markdown_cmd = "/usr/bin/markdown";
+
+       open my $fd, quote_command($markdown_cmd, $file_name)." |"
+               or die_error(500, "Couldn't open $file_name");
+
+       while (my $line = <$fd>) {
+               print to_utf8($line);
+       }
+}
+
 ## ......................................................................
 ## mimetype related functions
 
 ## ......................................................................
 ## mimetype related functions
 
@@ -4070,10 +4101,11 @@ sub print_nav_breadcrumbs_path {
        while (my $part = shift) {
                $dirprefix .= "/" if defined $dirprefix;
                $dirprefix .= $part;
        while (my $part = shift) {
                $dirprefix .= "/" if defined $dirprefix;
                $dirprefix .= $part;
-               print $cgi->a({-href => href(project => undef,
-                                            project_filter => $dirprefix,
-                                            action => "project_list")},
-                             esc_html($part)) . " / ";
+               if (scalar @_ != 0) {
+                       print $cgi->a({-href => href(action => "summary")}, esc_html($part)) . " / ";
+               } else {
+                       print $cgi->a({-href => href(action => "summary")}, esc_html($part));
+               }
        }
 }
 
        }
 }
 
@@ -4087,7 +4119,9 @@ sub print_nav_breadcrumbs {
                my @dirname = split '/', $project;
                my $projectbasename = pop @dirname;
                print_nav_breadcrumbs_path(@dirname);
                my @dirname = split '/', $project;
                my $projectbasename = pop @dirname;
                print_nav_breadcrumbs_path(@dirname);
-               print $cgi->a({-href => href(action=>"summary")}, esc_html($projectbasename));
+               if ($projectbasename != ".git") {
+                       print $cgi->a({-href => href(action=>"summary")}, esc_html($projectbasename));
+               }
                if (defined $action) {
                        my $action_print = $action ;
                        if (defined $opts{-action_extra}) {
                if (defined $action) {
                        my $action_print = $action ;
                        if (defined $opts{-action_extra}) {
@@ -4434,7 +4468,7 @@ sub git_print_header_div {
 
 sub format_repo_url {
        my ($name, $url) = @_;
 
 sub format_repo_url {
        my ($name, $url) = @_;
-       return "<tr class=\"metadata_url\"><td>$name</td><td>$url</td></tr>\n";
+       return "<tr class=\"metadata_url\"><td>$name</td><td><a href=\"$url\">$url</a></td></tr>\n";
 }
 
 # Group output by placing it in a DIV element and adding a header.
 }
 
 # Group output by placing it in a DIV element and adding a header.
@@ -4546,8 +4580,10 @@ sub git_print_page_path {
 
 
        print "<div class=\"page_path\">";
 
 
        print "<div class=\"page_path\">";
+       my $pretty_project = $project;
+       $pretty_project =~ s/\/\.git$//;
        print $cgi->a({-href => href(action=>"tree", hash_base=>$hb),
        print $cgi->a({-href => href(action=>"tree", hash_base=>$hb),
-                     -title => 'tree root'}, to_utf8("[$project]"));
+                     -title => 'tree root'}, to_utf8("[$pretty_project]"));
        print " / ";
        if (defined $name) {
                my @dirname = split '/', $name;
        print " / ";
        if (defined $name) {
                my @dirname = split '/', $name;
@@ -5724,9 +5760,11 @@ sub git_project_list_rows {
                        }
                        print "</td>\n";
                }
                        }
                        print "</td>\n";
                }
+               my $pretty_path = $pr->{'path'};
+               $pretty_path =~ s/\/\.git$//;
                print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
                                        -class => "list"},
                print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
                                        -class => "list"},
-                                      esc_html_match_hl($pr->{'path'}, $search_regexp)) .
+                                      esc_html_match_hl($pretty_path, $search_regexp)) .
                      "</td>\n" .
                      "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
                                        -class => "list",
                      "</td>\n" .
                      "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
                                        -class => "list",
@@ -6573,11 +6611,12 @@ sub git_summary {
 
        # use per project git URL list in $projectroot/$project/cloneurl
        # or make project git URL from git base URL and project name
 
        # use per project git URL list in $projectroot/$project/cloneurl
        # or make project git URL from git base URL and project name
-       my $url_tag = "URL";
+       my $url_tag = "clone URL";
        my @url_list = git_get_project_url_list($project);
        @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
        foreach my $git_url (@url_list) {
                next unless $git_url;
        my @url_list = git_get_project_url_list($project);
        @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
        foreach my $git_url (@url_list) {
                next unless $git_url;
+               $git_url =~ s/\.git$//;
                print format_repo_url($url_tag, $git_url);
                $url_tag = "";
        }
                print format_repo_url($url_tag, $git_url);
                $url_tag = "";
        }
@@ -7188,7 +7227,7 @@ sub git_tree {
                }
                git_print_page_nav('tree','', $hash_base, undef, undef,
                                   join(' | ', @views_nav));
                }
                git_print_page_nav('tree','', $hash_base, undef, undef,
                                   join(' | ', @views_nav));
-               git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
+               #git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
        } else {
                undef $hash_base;
                print "<div class=\"page_nav\">\n";
        } else {
                undef $hash_base;
                print "<div class=\"page_nav\">\n";
@@ -7247,6 +7286,30 @@ sub git_tree {
        }
        print "</table>\n" .
              "</div>";
        }
        print "</table>\n" .
              "</div>";
+
+       # If present, print one of the following, in order:
+       #       README.md, README.txt, README, README.html.
+       my $cwd_path = "$projectroot/$project";
+       $cwd_path =~ s/\.git$//;
+       $cwd_path = $cwd_path . $basedir;
+       if (!$prevent_xss && -s $cwd_path . "README.md") {
+               print "<div class=\"readme\">\n";
+               insert_markdown_file($cwd_path . "README.md");
+               print "\n</div>\n"; # class="readme"
+       } elsif (!$prevent_xss && -s $cwd_path . "README.txt") {
+               print "<div class=\"readme\">\n";
+               insert_text_file($cwd_path . "README.txt");
+               print "\n</div>\n"; # class="readme"
+       } elsif (!$prevent_xss && -s $cwd_path . "README") {
+               print "<div class=\"readme\">\n";
+               insert_text_file($cwd_path . "README");
+               print "\n</div>\n"; # class="readme"
+       } elsif (!$prevent_xss && -s $cwd_path . "README.html") {
+               print "<div class=\"readme\">\n";
+               insert_html_file($cwd_path . "README.html");
+               print "\n</div>\n"; # class="readme"
+       }
+
        git_footer_html();
 }
 
        git_footer_html();
 }