Guest User

Untitled

a guest
Jun 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. --- gitweb.cgi 2018-05-30 00:26:43.000000000 +0300
  2. +++ my_gitweb.cgi 2018-06-16 15:26:41.207212864 +0300
  3. @@ -24,6 +24,23 @@
  4.  
  5. binmode STDOUT, ':utf8';
  6.  
  7. +
  8. +use CGI::Fast (-utf8);
  9. +use FCGI ();
  10. +use Encode ();
  11. +
  12. +my $enc = Encode::find_encoding('UTF-8');
  13. +my $org = \&FCGI::Stream::PRINT;
  14. +no warnings 'redefine';
  15. +local *FCGI::Stream::PRINT = sub {
  16. + my @OUTPUT = @_;
  17. + for (my $i = 1; $i < @_; $i++) {
  18. + $OUTPUT[$i] = $enc->encode($_[$i], Encode::FB_CROAK|Encode::LEAVE_SRC);
  19. + }
  20. + @_ = @OUTPUT;
  21. + goto $org;
  22. +};
  23. +
  24. if (!defined($CGI::VERSION) || $CGI::VERSION < 4.08) {
  25. eval 'sub CGI::multi_param { CGI::param(@_) }'
  26. }
  27. @@ -5719,7 +5736,7 @@
  28. }
  29. print "</td>\n";
  30. }
  31. - print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
  32. + print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree"),
  33. -class => "list"},
  34. esc_html_match_hl($pr->{'path'}, $search_regexp)) .
  35. "</td>\n" .
  36. @@ -6527,6 +6544,46 @@
  37. }
  38. }
  39.  
  40. +sub git_readme_out {
  41. + my ($roothash) = @_;
  42. + if (!$prevent_xss) {
  43. + my $file_name = "README.md";
  44. + my $readme_md_blob_hash = git_get_hash_by_path($roothash, $file_name, "blob");
  45. + my $readme_blob_hash;
  46. + if (!$readme_md_blob_hash) {
  47. + $file_name = "README";
  48. + $readme_blob_hash = git_get_hash_by_path($roothash, $file_name, "blob");
  49. + if (!$readme_blob_hash) {
  50. + $file_name = "readme.txt";
  51. + $readme_blob_hash = git_get_hash_by_path($roothash, $file_name, "blob");
  52. + }
  53. + }
  54. + if ($readme_blob_hash || $readme_md_blob_hash) { # if a readme exists
  55. + print "<div class=\"page_header\">" . $file_name . "</div>\n";
  56. + print "<div class=\"readme page_body\">";
  57. + if ($readme_md_blob_hash) {
  58. + my $cmd_markdownify = $GIT . " " . git_cmd() . " cat-file blob " . $readme_md_blob_hash . " | cmark-gfm --safe |";
  59. + open FOO, $cmd_markdownify or die_error(500, "Open git-cat-file blob '$readme_md_blob_hash' failed");
  60. + while (<FOO>) {
  61. + print sanitize($_);
  62. + }
  63. + close(FOO);
  64. + } else {
  65. + open my $fd, "-|", git_cmd(), "cat-file", "blob", $readme_blob_hash
  66. + or die_error(500, "Couldn't cat $file_name, $readme_blob_hash");
  67. + while (my $line = <$fd>) {
  68. + chomp $line;
  69. + $line = untabify($line);
  70. + printf qq!<div class="pre"> %s</div>\n!, esc_html($line, -nbsp=>1);
  71. + }
  72. + close $fd
  73. + or print "Reading blob failed.\n";
  74. + }
  75. + print "</div>";
  76. + }
  77. + }
  78. +}
  79. +
  80. sub git_summary {
  81. my $descr = git_get_project_description($project) || "none";
  82. my %co = parse_commit("HEAD");
  83. @@ -6642,6 +6699,8 @@
  84. 'no_header');
  85. }
  86.  
  87. + git_readme_out($head);
  88. +
  89. git_footer_html();
  90. }
  91.  
  92. @@ -7245,6 +7304,11 @@
  93. }
  94. print "</table>\n" .
  95. "</div>";
  96. +
  97. + if (!defined $file_name) {
  98. + git_readme_out($hash_base);
  99. + }
  100. +
  101. git_footer_html();
  102. }
Add Comment
Please, Sign In to add comment