1 Subject: [PATCH] gitweb: support automatic readme generation
3 If enabled by setting $git_automatic_readme_html to an executable
4 that takes a .git directory as its argument, then if README.html
5 insertion is enabled and README.html does not exist or is zero
6 length, then the output of the $git_automatic_readme_html utility
7 will be inserted instead if it is non-empty.
9 It's still possible to prevent display of any readme by creating
10 a README.html file that consists of only XML <!-- comments -->.
12 Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
14 gitweb/gitweb.perl | 52 +++++++++++++++++++++++++++++++++++++++++++-----
15 gitweb/static/gitweb.css | 48 ++++++++++++++++++++++++++++++++++++++------
16 2 files changed, 89 insertions(+), 11 deletions(-)
18 diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
19 index 1cca889c..08691a75 100755
20 --- a/gitweb/gitweb.perl
21 +++ b/gitweb/gitweb.perl
22 @@ -200,6 +200,13 @@ our $fallback_encoding = 'latin1';
23 # - one might want to include '-B' option, e.g. '-B', '-M'
24 our @diff_opts = ('-M'); # taken from git_commit
26 +# utility to automatically produce a default README.html if README.html is
27 +# enabled and it does not exist or is 0 bytes in length. If this is set to an
28 +# executable utility that takes an absolute path to a .git directory as its
29 +# first argument and outputs an HTML fragment to use for README.html, then
30 +# it will be called when README.html is enabled but empty or missing.
31 +our $git_automatic_readme_html = undef;
33 # Disables features that would allow repository owners to inject script into
36 @@ -4220,6 +4227,33 @@ sub insert_file {
40 +# return undef on failure
42 + defined(my $fd = cmd_pipe @_) or return undef;
47 + my $result = join('', map({ to_utf8($_) } <$fd>));
48 + close $fd or return undef;
52 +# return undef on failure
53 +# return '' if only comments
54 +sub collect_html_file {
55 + my $filename = shift;
57 + open my $fd, '<', $filename or return undef;
58 + my $result = join('', map({ to_utf8($_) } <$fd>));
59 + close $fd or return undef;
60 + return undef unless defined($result);
62 + $test =~ s/<!--(?:[^-]|(?:-(?!-)))*-->//gs;
64 + return $test eq '' ? '' : $result;
67 ## ......................................................................
68 ## mimetype related functions
70 @@ -7386,11 +7420,19 @@ sub git_summary {
72 # If XSS prevention is on, we don't include README.html.
73 # TODO: Allow a readme in some safe format.
74 - if (!$prevent_xss && -s "$projectroot/$project/README.html") {
75 - print "<div class=\"title\">readme</div>\n" .
76 - "<div class=\"readme\">\n";
77 - insert_file("$projectroot/$project/README.html");
78 - print "\n</div>\n"; # class="readme"
79 + if (!$prevent_xss) {
80 + my $readme = -s "$projectroot/$project/README.html"
81 + ? collect_html_file("$projectroot/$project/README.html")
82 + : collect_output($git_automatic_readme_html, "$projectroot/$project");
83 + if (defined($readme)) {
84 + $readme =~ s/^\s+//s;
85 + $readme =~ s/\s+$//s;
86 + print "<div class=\"title\">readme</div>\n",
87 + "<div class=\"readme\">\n",
94 # we need to request one more than 16 (0..15) to check if
95 diff --git a/gitweb/static/gitweb.css b/gitweb/static/gitweb.css
96 index 3e4c4a93..d4567df7 100644
97 --- a/gitweb/static/gitweb.css
98 +++ b/gitweb/static/gitweb.css
99 @@ -8,11 +8,15 @@ body {
104 +a, a:hover, a:visited, a:active {
112 -a:hover, a:visited, a:active {
113 +a[href]:hover, a[href]:visited, a[href]:active {
117 @@ -37,6 +41,10 @@ img.blob {
121 +div.header, div.title {
128 @@ -131,14 +139,42 @@ span.title {
137 background-color: #d9d8d1;
163 + background-color: #eee;
166 +div.readme pre.plaintext {
169 + background-color: inherit;
174 border: solid #d9d8d1;