my @forklist;
my $check_forks = gitweb_check_feature('forks');
- if ($check_forks) {
- # find forks of a project
- my $filter = $project;
- $filter =~ s/\.git$//;
- @forklist = git_get_projects_list($filter);
- # filter out forks of forks
- @forklist = filter_forks_from_projects_list(\@forklist)
- if (@forklist);
+
+ if (!defined $hash_base) {
+ $hash_base = "HEAD";
+ }
+ if (!defined $hash) {
+ if (defined $file_name) {
+ $hash = git_get_hash_by_path($hash_base, $file_name, "tree");
+ } else {
+ $hash = $hash_base;
+ }
+ }
+ die_error(404, "No such tree") unless defined($hash);
+
+ my $show_sizes = gitweb_check_feature('show-sizes');
+ my $have_blame = gitweb_check_feature('blame');
+
+ my @entries = ();
+ {
+ local $/ = "\0";
+ open my $fd, "-|", git_cmd(), "ls-tree", '-z',
+ ($show_sizes ? '-l' : ()), @extra_options, $hash
+ or die_error(500, "Open git-ls-tree failed");
+ @entries = map { chomp; $_ } <$fd>;
+ close $fd
+ or die_error(404, "Reading tree failed");
}
+ my $refs = git_get_references();
+ my $ref = format_ref_marker($refs, $hash_base);
git_header_html();
git_print_page_nav('summary','', $head);
+ my $basedir = '';
- print "<div class=\"title\"> </div>\n";
print "<table class=\"projects_list\">\n" .
"<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html($descr) . "</td></tr>\n";
if ($owner and not $omit_owner) {
print "</table>\n";
- # If XSS prevention is on, we don't include README.html.
- # TODO: Allow a readme in some safe format.
- if (!$prevent_xss && -s "$projectroot/$project/README.html") {
- print "<div class=\"title\">readme</div>\n" .
- "<div class=\"readme\">\n";
- insert_file("$projectroot/$project/README.html");
- print "\n</div>\n"; # class="readme"
- }
+ print "<div class=\"page_body\">\n";
+ print "<table class=\"tree\">\n";
+ my $alternate = 1;
+ # '..' (top directory) link if possible
+ if (defined $hash_base &&
+ defined $file_name && $file_name =~ m![^/]+$!) {
+ if ($alternate) {
+ print "<tr class=\"dark\">\n";
+ } else {
+ print "<tr class=\"light\">\n";
+ }
+ $alternate ^= 1;
- # we need to request one more than 16 (0..15) to check if
- # those 16 are all
- my @commitlist = $head ? parse_commits($head, 17) : ();
- if (@commitlist) {
- git_print_header_div('shortlog');
- git_shortlog_body(\@commitlist, 0, 15, $refs,
- $#commitlist <= 15 ? undef :
- $cgi->a({-href => href(action=>"shortlog")}, "..."));
- }
+ my $up = $file_name;
+ $up =~ s!/?[^/]+$!!;
+ undef $up unless $up;
+ # based on git_print_tree_entry
+ print '<td class="mode">' . mode_str('040000') . "</td>\n";
+ print '<td class="size"> </td>'."\n" if $show_sizes;
+ print '<td class="list">';
+ print $cgi->a({-href => href(action=>"tree",
+ hash_base=>$hash_base,
+ file_name=>$up)},
+ "..");
+ print "</td>\n";
+ print "<td class=\"link\"></td>\n";
- if (@taglist) {
- git_print_header_div('tags');
- git_tags_body(\@taglist, 0, 15,
- $#taglist <= 15 ? undef :
- $cgi->a({-href => href(action=>"tags")}, "..."));
+ print "</tr>\n";
}
+ foreach my $line (@entries) {
+ my %t = parse_ls_tree_line($line, -z => 1, -l => $show_sizes);
- if (@headlist) {
- git_print_header_div('heads');
- git_heads_body(\@headlist, $head, 0, 15,
- $#headlist <= 15 ? undef :
- $cgi->a({-href => href(action=>"heads")}, "..."));
- }
+ if ($alternate) {
+ print "<tr class=\"dark\">\n";
+ } else {
+ print "<tr class=\"light\">\n";
+ }
+ $alternate ^= 1;
- if (%remotedata) {
- git_print_header_div('remotes');
- git_remotes_body(\%remotedata, 15, $head);
+ git_print_tree_entry(\%t, $basedir, $hash_base, $have_blame);
+
+ print "</tr>\n";
}
+ print "</table>\n" .
+ "</div>";
- if (@forklist) {
- git_print_header_div('forks');
- git_project_list_body(\@forklist, 'age', 0, 15,
- $#forklist <= 15 ? undef :
- $cgi->a({-href => href(action=>"forks")}, "..."),
- 'no_header');
+ # 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();