]>
Commit | Line | Data |
---|---|---|
161332a5 KS |
1 | #!/usr/bin/perl |
2 | ||
c994d620 | 3 | # gitweb - simple web interface to track changes in git repositories |
22fafb99 | 4 | # |
161332a5 KS |
5 | # (C) 2005, Kay Sievers <kay.sievers@vrfy.org> |
6 | # (C) 2005, Christian Gierke <ch@gierke.de> | |
823d5dc8 | 7 | # |
d8f1c5c2 | 8 | # This program is licensed under the GPLv2 |
161332a5 KS |
9 | |
10 | use strict; | |
11 | use warnings; | |
19806691 | 12 | use CGI qw(:standard :escapeHTML -nosticky); |
7403d50b | 13 | use CGI::Util qw(unescape); |
161332a5 | 14 | use CGI::Carp qw(fatalsToBrowser); |
40c13813 | 15 | use Encode; |
b87d78d6 | 16 | use Fcntl ':mode'; |
10bb9036 | 17 | binmode STDOUT, ':utf8'; |
161332a5 | 18 | |
3e029299 | 19 | my $cgi = new CGI; |
94140c7a | 20 | my $version = "257"; |
b87d78d6 KS |
21 | my $my_url = $cgi->url(); |
22 | my $my_uri = $cgi->url(-absolute => 1); | |
40c13813 | 23 | my $rss_link = ""; |
3e029299 | 24 | |
b87d78d6 | 25 | # absolute fs-path which will be prepended to the project path |
a48e11ca | 26 | #my $projectroot = "/pub/scm"; |
40c13813 | 27 | my $projectroot = "/home/kay/public_html/pub/scm"; |
b87d78d6 KS |
28 | |
29 | # location of the git-core binaries | |
b51103f3 | 30 | my $gitbin = "/usr/bin"; |
b87d78d6 KS |
31 | |
32 | # location for temporary files needed for diffs | |
19806691 | 33 | my $git_temp = "/tmp/gitweb"; |
034df39e | 34 | |
b87d78d6 | 35 | # target of the home link on top of all pages |
ede5e100 | 36 | my $home_link = $my_uri; |
b87d78d6 | 37 | |
8ab1da2c KS |
38 | # html text to include at home page |
39 | my $home_text = "indextext.html"; | |
40 | ||
09bd7898 | 41 | # source of projects list |
40c13813 KS |
42 | #my $projects_list = $projectroot; |
43 | my $projects_list = "index/index.aux"; | |
b87d78d6 | 44 | |
09bd7898 KS |
45 | # input validation and dispatch |
46 | my $action = $cgi->param('a'); | |
47 | if (defined $action) { | |
c91da262 | 48 | if ($action =~ m/[^0-9a-zA-Z\.\-_]/) { |
09bd7898 KS |
49 | undef $action; |
50 | die_error(undef, "Invalid action parameter."); | |
b87d78d6 | 51 | } |
09bd7898 KS |
52 | if ($action eq "git-logo.png") { |
53 | git_logo(); | |
54 | exit; | |
c994d620 KS |
55 | } elsif ($action eq "opml") { |
56 | git_opml(); | |
57 | exit; | |
09bd7898 | 58 | } |
b87d78d6 | 59 | } |
44ad2978 | 60 | |
f7ab660c KS |
61 | my $order = $cgi->param('o'); |
62 | if (defined $order) { | |
c91da262 | 63 | if ($order =~ m/[^0-9a-zA-Z_]/) { |
f7ab660c KS |
64 | undef $order; |
65 | die_error(undef, "Invalid order parameter."); | |
66 | } | |
67 | } | |
68 | ||
022be3d0 | 69 | my $project = $cgi->param('p'); |
b87d78d6 | 70 | if (defined $project) { |
c91da262 KS |
71 | $project = validate_input($project); |
72 | if (!defined($project)) { | |
73 | die_error(undef, "Invalid project parameter."); | |
9cd3d988 KS |
74 | } |
75 | if (!(-d "$projectroot/$project")) { | |
b87d78d6 | 76 | undef $project; |
09bd7898 | 77 | die_error(undef, "No such directory."); |
b87d78d6 KS |
78 | } |
79 | if (!(-e "$projectroot/$project/HEAD")) { | |
80 | undef $project; | |
09bd7898 | 81 | die_error(undef, "No such project."); |
9cd3d988 | 82 | } |
232ff553 KS |
83 | $rss_link = "<link rel=\"alternate\" title=\"" . esc_param($project) . " log\" href=\"" . |
84 | "$my_uri?" . esc_param("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>"; | |
4fac5294 | 85 | $ENV{'GIT_DIR'} = "$projectroot/$project"; |
09bd7898 | 86 | } else { |
ede5e100 | 87 | git_project_list(); |
09bd7898 | 88 | exit; |
a59d4afd | 89 | } |
6191f8e1 KS |
90 | |
91 | my $file_name = $cgi->param('f'); | |
b87d78d6 | 92 | if (defined $file_name) { |
c91da262 KS |
93 | $file_name = validate_input($file_name); |
94 | if (!defined($file_name)) { | |
95 | die_error(undef, "Invalid file parameter."); | |
b87d78d6 | 96 | } |
a59d4afd | 97 | } |
6191f8e1 KS |
98 | |
99 | my $hash = $cgi->param('h'); | |
4fac5294 | 100 | if (defined $hash) { |
c91da262 KS |
101 | $hash = validate_input($hash); |
102 | if (!defined($hash)) { | |
103 | die_error(undef, "Invalid hash parameter."); | |
4fac5294 | 104 | } |
a59d4afd | 105 | } |
6191f8e1 KS |
106 | |
107 | my $hash_parent = $cgi->param('hp'); | |
c91da262 KS |
108 | if (defined $hash_parent) { |
109 | $hash_parent = validate_input($hash_parent); | |
110 | if (!defined($hash_parent)) { | |
111 | die_error(undef, "Invalid hash parent parameter."); | |
112 | } | |
09bd7898 KS |
113 | } |
114 | ||
115 | my $hash_base = $cgi->param('hb'); | |
c91da262 KS |
116 | if (defined $hash_base) { |
117 | $hash_base = validate_input($hash_base); | |
118 | if (!defined($hash_base)) { | |
119 | die_error(undef, "Invalid hash base parameter."); | |
120 | } | |
a59d4afd | 121 | } |
6191f8e1 | 122 | |
ea4a6df4 KS |
123 | my $page = $cgi->param('pg'); |
124 | if (defined $page) { | |
c91da262 | 125 | if ($page =~ m/[^0-9]$/) { |
ea4a6df4 KS |
126 | undef $page; |
127 | die_error(undef, "Invalid page parameter."); | |
b87d78d6 | 128 | } |
2ad9331e | 129 | } |
823d5dc8 | 130 | |
19806691 KS |
131 | my $searchtext = $cgi->param('s'); |
132 | if (defined $searchtext) { | |
133 | if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) { | |
134 | undef $searchtext; | |
135 | die_error(undef, "Invalid search parameter."); | |
136 | } | |
137 | $searchtext = quotemeta $searchtext; | |
138 | } | |
139 | ||
c91da262 KS |
140 | sub validate_input { |
141 | my $input = shift; | |
142 | ||
143 | if ($input =~ m/^[0-9a-fA-F]{40}$/) { | |
144 | return $input; | |
145 | } | |
146 | if ($input =~ m/(^|\/)(|\.|\.\.)($|\/)/) { | |
147 | return undef; | |
148 | } | |
f5ac835a | 149 | if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\-\+\#\~\%]/) { |
c91da262 KS |
150 | return undef; |
151 | } | |
152 | return $input; | |
153 | } | |
154 | ||
4fac5294 | 155 | if (!defined $action || $action eq "summary") { |
ede5e100 KS |
156 | git_summary(); |
157 | exit; | |
d8f1c5c2 KS |
158 | } elsif ($action eq "heads") { |
159 | git_heads(); | |
0db37973 | 160 | exit; |
ede5e100 KS |
161 | } elsif ($action eq "tags") { |
162 | git_tags(); | |
163 | exit; | |
164 | } elsif ($action eq "blob") { | |
09bd7898 KS |
165 | git_blob(); |
166 | exit; | |
19806691 KS |
167 | } elsif ($action eq "blob_plain") { |
168 | git_blob_plain(); | |
169 | exit; | |
09bd7898 KS |
170 | } elsif ($action eq "tree") { |
171 | git_tree(); | |
172 | exit; | |
173 | } elsif ($action eq "rss") { | |
174 | git_rss(); | |
175 | exit; | |
176 | } elsif ($action eq "commit") { | |
177 | git_commit(); | |
178 | exit; | |
179 | } elsif ($action eq "log") { | |
180 | git_log(); | |
181 | exit; | |
182 | } elsif ($action eq "blobdiff") { | |
183 | git_blobdiff(); | |
184 | exit; | |
19806691 KS |
185 | } elsif ($action eq "blobdiff_plain") { |
186 | git_blobdiff_plain(); | |
187 | exit; | |
09bd7898 KS |
188 | } elsif ($action eq "commitdiff") { |
189 | git_commitdiff(); | |
190 | exit; | |
19806691 KS |
191 | } elsif ($action eq "commitdiff_plain") { |
192 | git_commitdiff_plain(); | |
193 | exit; | |
09bd7898 KS |
194 | } elsif ($action eq "history") { |
195 | git_history(); | |
196 | exit; | |
19806691 KS |
197 | } elsif ($action eq "search") { |
198 | git_search(); | |
199 | exit; | |
200 | } elsif ($action eq "shortlog") { | |
201 | git_shortlog(); | |
202 | exit; | |
d8a20ba9 KS |
203 | } elsif ($action eq "tag") { |
204 | git_tag(); | |
205 | exit; | |
09bd7898 KS |
206 | } else { |
207 | undef $action; | |
208 | die_error(undef, "Unknown action."); | |
209 | exit; | |
210 | } | |
211 | ||
232ff553 KS |
212 | # quote unsafe chars, but keep the slash, even when it's not |
213 | # correct, but quoted slashes look too horrible in bookmarks | |
214 | sub esc_param { | |
353347b0 | 215 | my $str = shift; |
232ff553 | 216 | $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg; |
18216710 | 217 | $str =~ s/\+/%2B/g; |
a9e60b7d | 218 | $str =~ s/ /\+/g; |
353347b0 KS |
219 | return $str; |
220 | } | |
221 | ||
232ff553 | 222 | # replace invalid utf8 character with SUBSTITUTION sequence |
40c13813 KS |
223 | sub esc_html { |
224 | my $str = shift; | |
40c13813 | 225 | $str = decode("utf8", $str, Encode::FB_DEFAULT); |
10bb9036 | 226 | $str = escapeHTML($str); |
40c13813 KS |
227 | return $str; |
228 | } | |
229 | ||
232ff553 KS |
230 | # git may return quoted and escaped filenames |
231 | sub unquote { | |
232 | my $str = shift; | |
233 | if ($str =~ m/^"(.*)"$/) { | |
234 | $str = $1; | |
235 | $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg; | |
236 | } | |
237 | return $str; | |
238 | } | |
239 | ||
12a88f2f | 240 | sub git_header_html { |
a59d4afd | 241 | my $status = shift || "200 OK"; |
11044297 | 242 | my $expires = shift; |
a59d4afd | 243 | |
b87d78d6 KS |
244 | my $title = "git"; |
245 | if (defined $project) { | |
246 | $title .= " - $project"; | |
247 | if (defined $action) { | |
248 | $title .= "/$action"; | |
249 | } | |
250 | } | |
11044297 | 251 | print $cgi->header(-type=>'text/html', -charset => 'utf-8', -status=> $status, -expires => $expires); |
a59d4afd | 252 | print <<EOF; |
6191f8e1 | 253 | <?xml version="1.0" encoding="utf-8"?> |
161332a5 | 254 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
034df39e | 255 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"> |
6191f8e1 | 256 | <!-- git web interface v$version, (C) 2005, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke <ch\@gierke.de> --> |
161332a5 | 257 | <head> |
c994d620 KS |
258 | <meta http-equiv="content-type" content="text/html; charset=utf-8"/> |
259 | <meta name="robots" content="index, nofollow"/> | |
b87d78d6 | 260 | <title>$title</title> |
6191f8e1 KS |
261 | $rss_link |
262 | <style type="text/css"> | |
c07ad4b9 | 263 | body { font-family: sans-serif; font-size: 12px; margin:0px; border:solid #d9d8d1; border-width:1px; margin:10px; } |
6191f8e1 | 264 | a { color:#0000cc; } |
c07ad4b9 KS |
265 | a:hover, a:visited, a:active { color:#880000; } |
266 | div.page_header { height:25px; padding:8px; font-size:18px; font-weight:bold; background-color:#d9d8d1; } | |
d8d17b5d | 267 | div.page_header a:visited, a.header { color:#0000cc; } |
6191f8e1 | 268 | div.page_header a:hover { color:#880000; } |
c07ad4b9 | 269 | div.page_nav { padding:8px; } |
6191f8e1 | 270 | div.page_nav a:visited { color:#0000cc; } |
19806691 | 271 | div.page_path { padding:8px; border:solid #d9d8d1; border-width:0px 0px 1px} |
c07ad4b9 | 272 | div.page_footer { height:17px; padding:4px 8px; background-color: #d9d8d1; } |
6191f8e1 | 273 | div.page_footer_text { float:left; color:#555555; font-style:italic; } |
c07ad4b9 | 274 | div.page_body { padding:8px; } |
6191f8e1 | 275 | div.title, a.title { |
c07ad4b9 | 276 | display:block; padding:6px 8px; |
6191f8e1 KS |
277 | font-weight:bold; background-color:#edece6; text-decoration:none; color:#000000; |
278 | } | |
279 | a.title:hover { background-color: #d9d8d1; } | |
bddec01d | 280 | div.title_text { padding:6px 0px; border: solid #d9d8d1; border-width:0px 0px 1px; } |
c07ad4b9 | 281 | div.log_body { padding:8px 8px 8px 150px; } |
440c6006 | 282 | span.age { position:relative; float:left; width:142px; font-style:italic; } |
c07ad4b9 | 283 | div.log_link { |
bddec01d | 284 | padding:0px 8px; |
c07ad4b9 | 285 | font-size:10px; font-family:sans-serif; font-style:normal; |
bddec01d | 286 | position:relative; float:left; width:136px; |
6191f8e1 | 287 | } |
bddec01d | 288 | div.list_head { padding:6px 8px 4px; border:solid #d9d8d1; border-width:1px 0px 0px; font-style:italic; } |
10dba28d | 289 | a.list { text-decoration:none; color:#000000; } |
c994d620 | 290 | a.list:hover { text-decoration:underline; color:#880000; } |
d8a20ba9 KS |
291 | a.text { text-decoration:none; color:#0000cc; } |
292 | a.text:visited { text-decoration:none; color:#880000; } | |
293 | a.text:hover { text-decoration:underline; color:#880000; } | |
bddec01d KS |
294 | table { padding:8px 4px; } |
295 | th { padding:2px 5px; font-size:12px; text-align:left; } | |
c994d620 KS |
296 | tr.light:hover { background-color:#edece6; } |
297 | tr.dark { background-color:#f6f6f0; } | |
298 | tr.dark:hover { background-color:#edece6; } | |
19806691 | 299 | td { padding:2px 5px; font-size:12px; vertical-align:top; } |
bddec01d | 300 | td.link { padding:2px 5px; font-family:sans-serif; font-size:10px; } |
c07ad4b9 KS |
301 | div.pre { font-family:monospace; font-size:12px; white-space:pre; } |
302 | div.diff_info { font-family:monospace; color:#000099; background-color:#edece6; font-style:italic; } | |
8ab1da2c | 303 | div.index_include { border:solid #d9d8d1; border-width:0px 0px 1px; padding:12px 8px; } |
c994d620 | 304 | div.search { margin:4px 8px; position:absolute; top:56px; right:12px } |
71be1e79 | 305 | a.linenr { color:#999999; text-decoration:none } |
c994d620 KS |
306 | a.rss_logo { |
307 | float:right; padding:3px 0px; width:35px; line-height:10px; | |
09bd7898 | 308 | border:1px solid; border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e; |
6191f8e1 | 309 | color:#ffffff; background-color:#ff6600; |
09bd7898 KS |
310 | font-weight:bold; font-family:sans-serif; font-size:10px; |
311 | text-align:center; text-decoration:none; | |
6191f8e1 | 312 | } |
2735983d | 313 | a.rss_logo:hover { background-color:#ee5500; } |
6191f8e1 | 314 | </style> |
161332a5 KS |
315 | </head> |
316 | <body> | |
317 | EOF | |
ff7669a5 | 318 | print "<div class=\"page_header\">\n" . |
c994d620 | 319 | "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" . |
232ff553 | 320 | "<img src=\"$my_uri?" . esc_param("a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" . |
19806691 | 321 | "</a>\n"; |
232ff553 | 322 | print $cgi->a({-href => esc_param($home_link)}, "projects") . " / "; |
b87d78d6 | 323 | if (defined $project) { |
232ff553 | 324 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, esc_html($project)); |
b87d78d6 KS |
325 | if (defined $action) { |
326 | print " / $action"; | |
327 | } | |
19806691 KS |
328 | print "\n"; |
329 | if (!defined $searchtext) { | |
330 | $searchtext = ""; | |
331 | } | |
c39e47d9 KS |
332 | my $search_hash; |
333 | if (defined $hash) { | |
334 | $search_hash = $hash; | |
335 | } else { | |
336 | $search_hash = "HEAD"; | |
337 | } | |
19806691 | 338 | $cgi->param("a", "search"); |
c39e47d9 | 339 | $cgi->param("h", $search_hash); |
353347b0 | 340 | print $cgi->startform(-method => "get", -action => $my_uri) . |
c994d620 KS |
341 | "<div class=\"search\">\n" . |
342 | $cgi->hidden(-name => "p") . "\n" . | |
343 | $cgi->hidden(-name => "a") . "\n" . | |
c39e47d9 | 344 | $cgi->hidden(-name => "h") . "\n" . |
c994d620 KS |
345 | $cgi->textfield(-name => "s", -value => $searchtext) . "\n" . |
346 | "</div>" . | |
347 | $cgi->end_form() . "\n"; | |
4c02e3c5 KS |
348 | } |
349 | print "</div>\n"; | |
161332a5 KS |
350 | } |
351 | ||
12a88f2f | 352 | sub git_footer_html { |
6191f8e1 | 353 | print "<div class=\"page_footer\">\n"; |
b87d78d6 | 354 | if (defined $project) { |
09bd7898 | 355 | my $descr = git_read_description($project); |
b87d78d6 | 356 | if (defined $descr) { |
40c13813 | 357 | print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n"; |
6191f8e1 | 358 | } |
232ff553 | 359 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n"; |
c994d620 | 360 | } else { |
232ff553 | 361 | print $cgi->a({-href => "$my_uri?" . esc_param("a=opml"), -class => "rss_logo"}, "OPML") . "\n"; |
ff7669a5 | 362 | } |
6191f8e1 KS |
363 | print "</div>\n" . |
364 | "</body>\n" . | |
9cd3d988 | 365 | "</html>"; |
161332a5 KS |
366 | } |
367 | ||
061cc7cd KS |
368 | sub die_error { |
369 | my $status = shift || "403 Forbidden"; | |
a59d4afd | 370 | my $error = shift || "Malformed query, file missing or permission denied"; |
664f4cc5 | 371 | |
a59d4afd KS |
372 | git_header_html($status); |
373 | print "<div class=\"page_body\">\n" . | |
7ab0d2b6 KS |
374 | "<br/><br/>\n" . |
375 | "$status - $error\n" . | |
376 | "<br/>\n" . | |
377 | "</div>\n"; | |
a59d4afd | 378 | git_footer_html(); |
09bd7898 | 379 | exit; |
a59d4afd KS |
380 | } |
381 | ||
42f7eb94 KS |
382 | sub git_get_type { |
383 | my $hash = shift; | |
384 | ||
19806691 | 385 | open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return; |
42f7eb94 | 386 | my $type = <$fd>; |
d8a20ba9 | 387 | close $fd or return; |
42f7eb94 KS |
388 | chomp $type; |
389 | return $type; | |
390 | } | |
391 | ||
ede5e100 | 392 | sub git_read_hash { |
54b0a43c | 393 | my $path = shift; |
09bd7898 | 394 | |
19806691 | 395 | open my $fd, "$projectroot/$path" or return undef; |
12a88f2f KS |
396 | my $head = <$fd>; |
397 | close $fd; | |
398 | chomp $head; | |
b87d78d6 KS |
399 | if ($head =~ m/^[0-9a-fA-F]{40}$/) { |
400 | return $head; | |
b87d78d6 KS |
401 | } |
402 | } | |
403 | ||
09bd7898 | 404 | sub git_read_description { |
b87d78d6 | 405 | my $path = shift; |
09bd7898 | 406 | |
19806691 | 407 | open my $fd, "$projectroot/$path/description" or return undef; |
b87d78d6 KS |
408 | my $descr = <$fd>; |
409 | close $fd; | |
410 | chomp $descr; | |
411 | return $descr; | |
12a88f2f KS |
412 | } |
413 | ||
ede5e100 KS |
414 | sub git_read_tag { |
415 | my $tag_id = shift; | |
416 | my %tag; | |
d8a20ba9 | 417 | my @comment; |
ede5e100 | 418 | |
19806691 | 419 | open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return; |
d8a20ba9 | 420 | $tag{'id'} = $tag_id; |
ede5e100 KS |
421 | while (my $line = <$fd>) { |
422 | chomp $line; | |
423 | if ($line =~ m/^object ([0-9a-fA-F]{40})$/) { | |
424 | $tag{'object'} = $1; | |
7ab0d2b6 | 425 | } elsif ($line =~ m/^type (.+)$/) { |
ede5e100 | 426 | $tag{'type'} = $1; |
7ab0d2b6 | 427 | } elsif ($line =~ m/^tag (.+)$/) { |
ede5e100 | 428 | $tag{'name'} = $1; |
d8a20ba9 KS |
429 | } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) { |
430 | $tag{'author'} = $1; | |
431 | $tag{'epoch'} = $2; | |
432 | $tag{'tz'} = $3; | |
433 | } elsif ($line =~ m/--BEGIN/) { | |
434 | push @comment, $line; | |
435 | last; | |
436 | } elsif ($line eq "") { | |
437 | last; | |
ede5e100 KS |
438 | } |
439 | } | |
d8a20ba9 KS |
440 | push @comment, <$fd>; |
441 | $tag{'comment'} = \@comment; | |
19806691 | 442 | close $fd or return; |
ede5e100 KS |
443 | if (!defined $tag{'name'}) { |
444 | return | |
445 | }; | |
446 | return %tag | |
447 | } | |
448 | ||
d263a6bd KS |
449 | sub age_string { |
450 | my $age = shift; | |
451 | my $age_str; | |
452 | ||
453 | if ($age > 60*60*24*365*2) { | |
454 | $age_str = (int $age/60/60/24/365); | |
455 | $age_str .= " years ago"; | |
456 | } elsif ($age > 60*60*24*(365/12)*2) { | |
457 | $age_str = int $age/60/60/24/(365/12); | |
458 | $age_str .= " months ago"; | |
459 | } elsif ($age > 60*60*24*7*2) { | |
460 | $age_str = int $age/60/60/24/7; | |
461 | $age_str .= " weeks ago"; | |
462 | } elsif ($age > 60*60*24*2) { | |
463 | $age_str = int $age/60/60/24; | |
464 | $age_str .= " days ago"; | |
465 | } elsif ($age > 60*60*2) { | |
466 | $age_str = int $age/60/60; | |
467 | $age_str .= " hours ago"; | |
468 | } elsif ($age > 60*2) { | |
469 | $age_str = int $age/60; | |
470 | $age_str .= " min ago"; | |
471 | } elsif ($age > 2) { | |
472 | $age_str = int $age; | |
473 | $age_str .= " sec ago"; | |
474 | } else { | |
475 | $age_str .= " right now"; | |
476 | } | |
477 | return $age_str; | |
478 | } | |
479 | ||
09bd7898 | 480 | sub git_read_commit { |
19806691 KS |
481 | my $commit_id = shift; |
482 | my $commit_text = shift; | |
483 | ||
484 | my @commit_lines; | |
703ac710 | 485 | my %co; |
703ac710 | 486 | |
19806691 KS |
487 | if (defined $commit_text) { |
488 | @commit_lines = @$commit_text; | |
489 | } else { | |
25f422fb KS |
490 | $/ = "\0"; |
491 | open my $fd, "-|", "$gitbin/git-rev-list --header --parents --max-count=1 $commit_id" or return; | |
492 | @commit_lines = split '\n', <$fd>; | |
19806691 | 493 | close $fd or return; |
25f422fb KS |
494 | $/ = "\n"; |
495 | pop @commit_lines; | |
19806691 | 496 | } |
25f422fb KS |
497 | my $header = shift @commit_lines; |
498 | if (!($header =~ m/^[0-9a-fA-F]{40}/)) { | |
499 | return; | |
500 | } | |
501 | ($co{'id'}, my @parents) = split ' ', $header; | |
502 | $co{'parents'} = \@parents; | |
503 | $co{'parent'} = $parents[0]; | |
19806691 | 504 | while (my $line = shift @commit_lines) { |
b87d78d6 | 505 | last if $line eq "\n"; |
7ab0d2b6 | 506 | if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) { |
703ac710 | 507 | $co{'tree'} = $1; |
022be3d0 | 508 | } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) { |
3f714537 | 509 | $co{'author'} = $1; |
185f09e5 KS |
510 | $co{'author_epoch'} = $2; |
511 | $co{'author_tz'} = $3; | |
2bf7a52c KS |
512 | if ($co{'author'} =~ m/^([^<]+) </) { |
513 | $co{'author_name'} = $1; | |
514 | } else { | |
515 | $co{'author_name'} = $co{'author'}; | |
516 | } | |
86eed32d KS |
517 | } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) { |
518 | $co{'committer'} = $1; | |
185f09e5 KS |
519 | $co{'committer_epoch'} = $2; |
520 | $co{'committer_tz'} = $3; | |
991910a9 KS |
521 | $co{'committer_name'} = $co{'committer'}; |
522 | $co{'committer_name'} =~ s/ <.*//; | |
703ac710 KS |
523 | } |
524 | } | |
ede5e100 | 525 | if (!defined $co{'tree'}) { |
25f422fb | 526 | return; |
ede5e100 | 527 | }; |
25f422fb | 528 | |
19806691 KS |
529 | foreach my $title (@commit_lines) { |
530 | if ($title ne "") { | |
48c771f4 | 531 | $co{'title'} = chop_str($title, 80, 5); |
19806691 KS |
532 | # remove leading stuff of merges to make the interesting part visible |
533 | if (length($title) > 50) { | |
534 | $title =~ s/^Automatic //; | |
535 | $title =~ s/^merge (of|with) /Merge ... /i; | |
536 | if (length($title) > 50) { | |
537 | $title =~ s/(http|rsync):\/\///; | |
538 | } | |
539 | if (length($title) > 50) { | |
540 | $title =~ s/(master|www|rsync)\.//; | |
541 | } | |
542 | if (length($title) > 50) { | |
543 | $title =~ s/kernel.org:?//; | |
544 | } | |
545 | if (length($title) > 50) { | |
546 | $title =~ s/\/pub\/scm//; | |
547 | } | |
548 | } | |
48c771f4 | 549 | $co{'title_short'} = chop_str($title, 50, 5); |
19806691 KS |
550 | last; |
551 | } | |
552 | } | |
25f422fb KS |
553 | # remove added spaces |
554 | foreach my $line (@commit_lines) { | |
555 | $line =~ s/^ //; | |
556 | } | |
557 | $co{'comment'} = \@commit_lines; | |
2ae100df KS |
558 | |
559 | my $age = time - $co{'committer_epoch'}; | |
560 | $co{'age'} = $age; | |
d263a6bd | 561 | $co{'age_string'} = age_string($age); |
71be1e79 KS |
562 | my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'}); |
563 | if ($age > 60*60*24*7*2) { | |
1b1cd421 | 564 | $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday; |
71be1e79 KS |
565 | $co{'age_string_age'} = $co{'age_string'}; |
566 | } else { | |
567 | $co{'age_string_date'} = $co{'age_string'}; | |
1b1cd421 | 568 | $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday; |
71be1e79 | 569 | } |
703ac710 KS |
570 | return %co; |
571 | } | |
572 | ||
19806691 | 573 | sub git_diff_print { |
8ed23e1b | 574 | my $from = shift; |
2735983d | 575 | my $from_name = shift; |
8ed23e1b | 576 | my $to = shift; |
2735983d | 577 | my $to_name = shift; |
19806691 | 578 | my $format = shift || "html"; |
4c02e3c5 | 579 | |
8ed23e1b KS |
580 | my $from_tmp = "/dev/null"; |
581 | my $to_tmp = "/dev/null"; | |
8ed23e1b | 582 | my $pid = $$; |
4c02e3c5 | 583 | |
ff7669a5 | 584 | # create tmp from-file |
b87d78d6 | 585 | if (defined $from) { |
19806691 | 586 | $from_tmp = "$git_temp/gitweb_" . $$ . "_from"; |
b87d78d6 | 587 | open my $fd2, "> $from_tmp"; |
034df39e | 588 | open my $fd, "-|", "$gitbin/git-cat-file blob $from"; |
8ed23e1b KS |
589 | my @file = <$fd>; |
590 | print $fd2 @file; | |
4c02e3c5 KS |
591 | close $fd2; |
592 | close $fd; | |
4c02e3c5 KS |
593 | } |
594 | ||
b531daf3 | 595 | # create tmp to-file |
b87d78d6 | 596 | if (defined $to) { |
19806691 | 597 | $to_tmp = "$git_temp/gitweb_" . $$ . "_to"; |
8ed23e1b | 598 | open my $fd2, "> $to_tmp"; |
034df39e | 599 | open my $fd, "-|", "$gitbin/git-cat-file blob $to"; |
8ed23e1b KS |
600 | my @file = <$fd>; |
601 | print $fd2 @file; | |
4c02e3c5 KS |
602 | close $fd2; |
603 | close $fd; | |
4c02e3c5 KS |
604 | } |
605 | ||
18216710 | 606 | open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp"; |
19806691 KS |
607 | if ($format eq "plain") { |
608 | undef $/; | |
609 | print <$fd>; | |
610 | $/ = "\n"; | |
611 | } else { | |
612 | while (my $line = <$fd>) { | |
613 | chomp($line); | |
614 | my $char = substr($line, 0, 1); | |
615 | my $color = ""; | |
616 | if ($char eq '+') { | |
617 | $color = " style=\"color:#008800;\""; | |
618 | } elsif ($char eq "-") { | |
619 | $color = " style=\"color:#cc0000;\""; | |
620 | } elsif ($char eq "@") { | |
621 | $color = " style=\"color:#990099;\""; | |
622 | } elsif ($char eq "\\") { | |
623 | # skip errors | |
624 | next; | |
625 | } | |
626 | while ((my $pos = index($line, "\t")) != -1) { | |
627 | if (my $count = (8 - (($pos-1) % 8))) { | |
628 | my $spaces = ' ' x $count; | |
629 | $line =~ s/\t/$spaces/; | |
630 | } | |
631 | } | |
40c13813 | 632 | print "<div class=\"pre\"$color>" . esc_html($line) . "</div>\n"; |
c07ad4b9 | 633 | } |
4c02e3c5 KS |
634 | } |
635 | close $fd; | |
8ed23e1b | 636 | |
b87d78d6 | 637 | if (defined $from) { |
2735983d | 638 | unlink($from_tmp); |
8ed23e1b | 639 | } |
b87d78d6 | 640 | if (defined $to) { |
2735983d | 641 | unlink($to_tmp); |
8ed23e1b | 642 | } |
4c02e3c5 KS |
643 | } |
644 | ||
d767d59c | 645 | sub mode_str { |
2735983d KS |
646 | my $mode = oct shift; |
647 | ||
b87d78d6 KS |
648 | if (S_ISDIR($mode & S_IFMT)) { |
649 | return 'drwxr-xr-x'; | |
650 | } elsif (S_ISLNK($mode)) { | |
651 | return 'lrwxrwxrwx'; | |
652 | } elsif (S_ISREG($mode)) { | |
991910a9 | 653 | # git cares only about the executable bit |
b87d78d6 KS |
654 | if ($mode & S_IXUSR) { |
655 | return '-rwxr-xr-x'; | |
54b0a43c | 656 | } else { |
b87d78d6 | 657 | return '-rw-r--r--'; |
54b0a43c | 658 | }; |
b87d78d6 KS |
659 | } else { |
660 | return '----------'; | |
d767d59c | 661 | } |
d767d59c KS |
662 | } |
663 | ||
2bf7a52c KS |
664 | sub chop_str { |
665 | my $str = shift; | |
666 | my $len = shift; | |
19806691 | 667 | my $add_len = shift || 10; |
2bf7a52c | 668 | |
a48e11ca KS |
669 | # allow only $len chars, but don't cut a word if it would fit in $add_len |
670 | # if it doesn't fit, cut it if it's still longer than the dots we would add | |
671 | $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/; | |
672 | my $body = $1; | |
673 | my $tail = $2; | |
674 | if (length($tail) > 4) { | |
675 | $tail = " ..."; | |
2bf7a52c | 676 | } |
a48e11ca | 677 | return "$body$tail"; |
2bf7a52c KS |
678 | } |
679 | ||
2735983d KS |
680 | sub file_type { |
681 | my $mode = oct shift; | |
682 | ||
b87d78d6 | 683 | if (S_ISDIR($mode & S_IFMT)) { |
2735983d | 684 | return "directory"; |
b87d78d6 | 685 | } elsif (S_ISLNK($mode)) { |
2735983d | 686 | return "symlink"; |
b87d78d6 KS |
687 | } elsif (S_ISREG($mode)) { |
688 | return "file"; | |
2735983d KS |
689 | } else { |
690 | return "unknown"; | |
691 | } | |
692 | } | |
693 | ||
f49201a9 KS |
694 | sub format_log_line_html { |
695 | my $line = shift; | |
696 | ||
40c13813 | 697 | $line = esc_html($line); |
f49201a9 KS |
698 | $line =~ s/ / /g; |
699 | if ($line =~ m/([0-9a-fA-F]{40})/) { | |
700 | my $hash_text = $1; | |
701 | if (git_get_type($hash_text) eq "commit") { | |
232ff553 | 702 | my $link = $cgi->a({-class => "text", -href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_text")}, $hash_text); |
f49201a9 KS |
703 | $line =~ s/$hash_text/$link/; |
704 | } | |
705 | } | |
706 | return $line; | |
707 | } | |
708 | ||
86eed32d | 709 | sub date_str { |
991910a9 KS |
710 | my $epoch = shift; |
711 | my $tz = shift || "-0000"; | |
86eed32d | 712 | |
991910a9 | 713 | my %date; |
86eed32d KS |
714 | my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); |
715 | my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); | |
991910a9 KS |
716 | my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch); |
717 | $date{'hour'} = $hour; | |
ff7669a5 KS |
718 | $date{'minute'} = $min; |
719 | $date{'mday'} = $mday; | |
720 | $date{'day'} = $days[$wday]; | |
721 | $date{'month'} = $months[$mon]; | |
991910a9 KS |
722 | $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec; |
723 | $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min; | |
724 | ||
034df39e KS |
725 | $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/; |
726 | my $local = $epoch + ((int $1 + ($2/60)) * 3600); | |
991910a9 | 727 | ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local); |
185f09e5 KS |
728 | $date{'hour_local'} = $hour; |
729 | $date{'minute_local'} = $min; | |
730 | $date{'tz_local'} = $tz; | |
991910a9 | 731 | return %date; |
86eed32d KS |
732 | } |
733 | ||
b87d78d6 | 734 | # git-logo (cached in browser for one day) |
eb28240b | 735 | sub git_logo { |
8f1deb5f | 736 | binmode STDOUT, ':raw'; |
022be3d0 | 737 | print $cgi->header(-type => 'image/png', -expires => '+1d'); |
b87d78d6 KS |
738 | # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g' |
739 | print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" . | |
740 | "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" . | |
741 | "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" . | |
742 | "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" . | |
743 | "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" . | |
744 | "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" . | |
745 | "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" . | |
746 | "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" . | |
747 | "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" . | |
748 | "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" . | |
749 | "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" . | |
750 | "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" . | |
751 | "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82"; | |
022be3d0 KS |
752 | } |
753 | ||
c07ad4b9 KS |
754 | sub get_file_owner { |
755 | my $path = shift; | |
756 | ||
757 | my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path); | |
758 | my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid); | |
759 | if (!defined $gcos) { | |
760 | return undef; | |
761 | } | |
762 | my $owner = $gcos; | |
763 | $owner =~ s/[,;].*$//; | |
764 | return $owner; | |
765 | } | |
766 | ||
c994d620 | 767 | sub git_read_projects { |
09bd7898 KS |
768 | my @list; |
769 | ||
ede5e100 | 770 | if (-d $projects_list) { |
09bd7898 | 771 | # search in directory |
ede5e100 | 772 | my $dir = $projects_list; |
19806691 | 773 | opendir my $dh, $dir or return undef; |
09bd7898 KS |
774 | while (my $dir = readdir($dh)) { |
775 | if (-e "$projectroot/$dir/HEAD") { | |
c07ad4b9 KS |
776 | my $pr = { |
777 | path => $dir, | |
778 | }; | |
779 | push @list, $pr | |
09bd7898 KS |
780 | } |
781 | } | |
782 | closedir($dh); | |
ede5e100 | 783 | } elsif (-f $projects_list) { |
7ab0d2b6 KS |
784 | # read from file(url-encoded): |
785 | # 'git%2Fgit.git Linus+Torvalds' | |
786 | # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin' | |
787 | # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman' | |
19806691 | 788 | open my $fd , $projects_list or return undef; |
09bd7898 KS |
789 | while (my $line = <$fd>) { |
790 | chomp $line; | |
7403d50b KS |
791 | my ($path, $owner) = split ' ', $line; |
792 | $path = unescape($path); | |
793 | $owner = unescape($owner); | |
c07ad4b9 KS |
794 | if (!defined $path) { |
795 | next; | |
796 | } | |
797 | if (-e "$projectroot/$path/HEAD") { | |
798 | my $pr = { | |
799 | path => $path, | |
800 | owner => $owner, | |
801 | }; | |
802 | push @list, $pr | |
09bd7898 KS |
803 | } |
804 | } | |
805 | close $fd; | |
806 | } | |
c994d620 KS |
807 | @list = sort {$a->{'path'} cmp $b->{'path'}} @list; |
808 | return @list; | |
809 | } | |
09bd7898 | 810 | |
c994d620 KS |
811 | sub git_project_list { |
812 | my @list = git_read_projects(); | |
f7ab660c | 813 | my @projects; |
09bd7898 KS |
814 | if (!@list) { |
815 | die_error(undef, "No project found."); | |
816 | } | |
f7ab660c KS |
817 | foreach my $pr (@list) { |
818 | my $head = git_read_hash("$pr->{'path'}/HEAD"); | |
819 | if (!defined $head) { | |
820 | next; | |
821 | } | |
822 | $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}"; | |
823 | my %co = git_read_commit($head); | |
824 | if (!%co) { | |
825 | next; | |
826 | } | |
827 | $pr->{'commit'} = \%co; | |
828 | if (!defined $pr->{'descr'}) { | |
829 | my $descr = git_read_description($pr->{'path'}) || ""; | |
830 | $pr->{'descr'} = chop_str($descr, 25, 5); | |
831 | } | |
832 | if (!defined $pr->{'owner'}) { | |
833 | $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || ""; | |
834 | } | |
835 | push @projects, $pr; | |
836 | } | |
b87d78d6 | 837 | git_header_html(); |
8ab1da2c KS |
838 | if (-f $home_text) { |
839 | print "<div class=\"index_include\">\n"; | |
ede5e100 | 840 | open (my $fd, $home_text); |
8ab1da2c KS |
841 | print <$fd>; |
842 | close $fd; | |
843 | print "</div>\n"; | |
844 | } | |
bddec01d | 845 | print "<table cellspacing=\"0\">\n" . |
f7ab660c | 846 | "<tr>\n"; |
d8d17b5d | 847 | if (!defined($order) || (defined($order) && ($order eq "project"))) { |
f7ab660c KS |
848 | @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects; |
849 | print "<th>Project</th>\n"; | |
850 | } else { | |
232ff553 | 851 | print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=project")}, "Project") . "</th>\n"; |
d8d17b5d KS |
852 | } |
853 | if (defined($order) && ($order eq "descr")) { | |
854 | @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects; | |
855 | print "<th>Description</th>\n"; | |
856 | } else { | |
232ff553 | 857 | print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=descr")}, "Description") . "</th>\n"; |
f7ab660c | 858 | } |
f7ab660c KS |
859 | if (defined($order) && ($order eq "owner")) { |
860 | @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects; | |
861 | print "<th>Owner</th>\n"; | |
862 | } else { | |
232ff553 | 863 | print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=owner")}, "Owner") . "</th>\n"; |
f7ab660c KS |
864 | } |
865 | if (defined($order) && ($order eq "age")) { | |
866 | @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects; | |
d8d17b5d | 867 | print "<th>Last Change</th>\n"; |
f7ab660c | 868 | } else { |
232ff553 | 869 | print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=age")}, "Last Change") . "</th>\n"; |
f7ab660c KS |
870 | } |
871 | print "<th></th>\n" . | |
eb28240b | 872 | "</tr>\n"; |
bddec01d | 873 | my $alternate = 0; |
f7ab660c | 874 | foreach my $pr (@projects) { |
bddec01d | 875 | if ($alternate) { |
c994d620 | 876 | print "<tr class=\"dark\">\n"; |
bddec01d | 877 | } else { |
c994d620 | 878 | print "<tr class=\"light\">\n"; |
bddec01d KS |
879 | } |
880 | $alternate ^= 1; | |
232ff553 | 881 | print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary"), -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" . |
f7ab660c KS |
882 | "<td>$pr->{'descr'}</td>\n" . |
883 | "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n"; | |
ede5e100 | 884 | my $colored_age; |
f7ab660c KS |
885 | if ($pr->{'commit'}{'age'} < 60*60*2) { |
886 | $colored_age = "<span style =\"color: #009900;\"><b><i>$pr->{'commit'}{'age_string'}</i></b></span>"; | |
887 | } elsif ($pr->{'commit'}{'age'} < 60*60*24*2) { | |
888 | $colored_age = "<span style =\"color: #009900;\"><i>$pr->{'commit'}{'age_string'}</i></span>"; | |
b87d78d6 | 889 | } else { |
f7ab660c | 890 | $colored_age = "<i>$pr->{'commit'}{'age_string'}</i>"; |
b87d78d6 | 891 | } |
ede5e100 KS |
892 | print "<td>$colored_age</td>\n" . |
893 | "<td class=\"link\">" . | |
232ff553 KS |
894 | $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary")}, "summary") . |
895 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=shortlog")}, "shortlog") . | |
896 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=log")}, "log") . | |
9ea82aa8 KS |
897 | "</td>\n" . |
898 | "</tr>\n"; | |
b87d78d6 | 899 | } |
7ab0d2b6 | 900 | print "</table>\n"; |
b87d78d6 | 901 | git_footer_html(); |
161332a5 KS |
902 | } |
903 | ||
0db37973 KS |
904 | sub git_read_refs { |
905 | my $ref_dir = shift; | |
fa378499 | 906 | my @reflist; |
ede5e100 | 907 | |
4fac5294 | 908 | my @refs; |
0db37973 | 909 | opendir my $dh, "$projectroot/$project/$ref_dir"; |
4fac5294 KS |
910 | while (my $dir = readdir($dh)) { |
911 | if ($dir =~ m/^\./) { | |
912 | next; | |
913 | } | |
914 | if (-d "$projectroot/$project/$ref_dir/$dir") { | |
915 | opendir my $dh2, "$projectroot/$project/$ref_dir/$dir"; | |
916 | my @subdirs = grep !m/^\./, readdir $dh2; | |
917 | closedir($dh2); | |
918 | foreach my $subdir (@subdirs) { | |
919 | push @refs, "$dir/$subdir" | |
920 | } | |
921 | next; | |
922 | } | |
923 | push @refs, $dir; | |
924 | } | |
ede5e100 | 925 | closedir($dh); |
fa378499 KS |
926 | foreach my $ref_file (@refs) { |
927 | my $ref_id = git_read_hash("$project/$ref_dir/$ref_file"); | |
928 | my $type = git_get_type($ref_id) || next; | |
929 | my %ref_item; | |
ede5e100 | 930 | my %co; |
d8a20ba9 KS |
931 | $ref_item{'type'} = $type; |
932 | $ref_item{'id'} = $ref_id; | |
d263a6bd KS |
933 | $ref_item{'epoch'} = 0; |
934 | $ref_item{'age'} = "unknown"; | |
ede5e100 | 935 | if ($type eq "tag") { |
fa378499 | 936 | my %tag = git_read_tag($ref_id); |
d8a20ba9 | 937 | $ref_item{'comment'} = $tag{'comment'}; |
ede5e100 KS |
938 | if ($tag{'type'} eq "commit") { |
939 | %co = git_read_commit($tag{'object'}); | |
d263a6bd KS |
940 | $ref_item{'epoch'} = $co{'committer_epoch'}; |
941 | $ref_item{'age'} = $co{'age_string'}; | |
942 | } elsif (defined($tag{'epoch'})) { | |
943 | my $age = time - $tag{'epoch'}; | |
944 | $ref_item{'epoch'} = $tag{'epoch'}; | |
945 | $ref_item{'age'} = age_string($age); | |
ede5e100 | 946 | } |
d8a20ba9 | 947 | $ref_item{'reftype'} = $tag{'type'}; |
fa378499 | 948 | $ref_item{'name'} = $tag{'name'}; |
d8a20ba9 | 949 | $ref_item{'refid'} = $tag{'object'}; |
ede5e100 | 950 | } elsif ($type eq "commit"){ |
fa378499 | 951 | %co = git_read_commit($ref_id); |
d8a20ba9 | 952 | $ref_item{'reftype'} = "commit"; |
fa378499 KS |
953 | $ref_item{'name'} = $ref_file; |
954 | $ref_item{'title'} = $co{'title'}; | |
d8a20ba9 | 955 | $ref_item{'refid'} = $ref_id; |
d263a6bd KS |
956 | $ref_item{'epoch'} = $co{'committer_epoch'}; |
957 | $ref_item{'age'} = $co{'age_string'}; | |
ede5e100 | 958 | } |
ede5e100 | 959 | |
fa378499 | 960 | push @reflist, \%ref_item; |
ede5e100 KS |
961 | } |
962 | # sort tags by age | |
fa378499 KS |
963 | @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist; |
964 | return \@reflist; | |
ede5e100 KS |
965 | } |
966 | ||
967 | sub git_summary { | |
968 | my $descr = git_read_description($project) || "none"; | |
969 | my $head = git_read_hash("$project/HEAD"); | |
ede5e100 KS |
970 | my %co = git_read_commit($head); |
971 | my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'}); | |
972 | ||
973 | my $owner; | |
974 | if (-f $projects_list) { | |
975 | open (my $fd , $projects_list); | |
976 | while (my $line = <$fd>) { | |
977 | chomp $line; | |
7403d50b KS |
978 | my ($pr, $ow) = split ' ', $line; |
979 | $pr = unescape($pr); | |
980 | $ow = unescape($ow); | |
ede5e100 KS |
981 | if ($pr eq $project) { |
982 | $owner = $ow; | |
983 | last; | |
984 | } | |
985 | } | |
986 | close $fd; | |
987 | } | |
988 | if (!defined $owner) { | |
989 | $owner = get_file_owner("$projectroot/$project"); | |
990 | } | |
991 | ||
992 | git_header_html(); | |
993 | print "<div class=\"page_nav\">\n" . | |
19806691 | 994 | "summary". |
232ff553 KS |
995 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") . |
996 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") . | |
997 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") . | |
998 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") . | |
999 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree")}, "tree") . | |
ede5e100 KS |
1000 | "<br/><br/>\n" . |
1001 | "</div>\n"; | |
19806691 | 1002 | print "<div class=\"title\"> </div>\n"; |
bddec01d | 1003 | print "<table cellspacing=\"0\">\n" . |
40c13813 | 1004 | "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" . |
ede5e100 KS |
1005 | "<tr><td>owner</td><td>$owner</td></tr>\n" . |
1006 | "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" . | |
bddec01d | 1007 | "</table>\n"; |
19806691 | 1008 | open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_hash("$project/HEAD") or die_error(undef, "Open failed."); |
ede5e100 KS |
1009 | my (@revlist) = map { chomp; $_ } <$fd>; |
1010 | close $fd; | |
1011 | print "<div>\n" . | |
232ff553 | 1012 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog"), -class => "title"}, "shortlog") . |
ede5e100 | 1013 | "</div>\n"; |
19806691 | 1014 | my $i = 16; |
bddec01d KS |
1015 | print "<table cellspacing=\"0\">\n"; |
1016 | my $alternate = 0; | |
ede5e100 KS |
1017 | foreach my $commit (@revlist) { |
1018 | my %co = git_read_commit($commit); | |
1019 | my %ad = date_str($co{'author_epoch'}); | |
bddec01d | 1020 | if ($alternate) { |
c994d620 | 1021 | print "<tr class=\"dark\">\n"; |
bddec01d | 1022 | } else { |
c994d620 | 1023 | print "<tr class=\"light\">\n"; |
bddec01d KS |
1024 | } |
1025 | $alternate ^= 1; | |
19806691 | 1026 | if ($i-- > 0) { |
10dba28d | 1027 | print "<td><i>$co{'age_string'}</i></td>\n" . |
40c13813 | 1028 | "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" . |
c24fd7b7 KS |
1029 | "<td>"; |
1030 | if (length($co{'title_short'}) < length($co{'title'})) { | |
232ff553 | 1031 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list", -title => "$co{'title'}"}, |
40c13813 | 1032 | "<b>" . esc_html($co{'title_short'}) . "</b>"); |
c24fd7b7 | 1033 | } else { |
232ff553 | 1034 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"}, |
40c13813 | 1035 | "<b>" . esc_html($co{'title'}) . "</b>"); |
c24fd7b7 | 1036 | } |
76a8323a | 1037 | print "</td>\n" . |
a4d26ef0 | 1038 | "<td class=\"link\">" . |
232ff553 KS |
1039 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") . |
1040 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") . | |
a4d26ef0 | 1041 | "</td>\n" . |
440c6006 KS |
1042 | "</tr>"; |
1043 | } else { | |
232ff553 | 1044 | print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "...") . "</td>\n" . |
440c6006 | 1045 | "</tr>"; |
ede5e100 KS |
1046 | last; |
1047 | } | |
1048 | } | |
bddec01d | 1049 | print "</table\n>"; |
ede5e100 | 1050 | |
0db37973 | 1051 | my $taglist = git_read_refs("refs/tags"); |
ede5e100 KS |
1052 | if (defined @$taglist) { |
1053 | print "<div>\n" . | |
232ff553 | 1054 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tags"), -class => "title"}, "tags") . |
ede5e100 | 1055 | "</div>\n"; |
19806691 | 1056 | my $i = 16; |
bddec01d KS |
1057 | print "<table cellspacing=\"0\">\n"; |
1058 | my $alternate = 0; | |
ede5e100 KS |
1059 | foreach my $entry (@$taglist) { |
1060 | my %tag = %$entry; | |
d8a20ba9 KS |
1061 | my $comment_lines = $tag{'comment'}; |
1062 | my $comment = shift @$comment_lines; | |
1063 | if (defined($comment)) { | |
1064 | $comment = chop_str($comment, 30, 5); | |
1065 | } | |
bddec01d | 1066 | if ($alternate) { |
c994d620 | 1067 | print "<tr class=\"dark\">\n"; |
bddec01d | 1068 | } else { |
c994d620 | 1069 | print "<tr class=\"light\">\n"; |
bddec01d KS |
1070 | } |
1071 | $alternate ^= 1; | |
19806691 | 1072 | if ($i-- > 0) { |
10dba28d | 1073 | print "<td><i>$tag{'age'}</i></td>\n" . |
19806691 | 1074 | "<td>" . |
232ff553 | 1075 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"}, |
40c13813 | 1076 | "<b>" . esc_html($tag{'name'}) . "</b>") . |
19806691 | 1077 | "</td>\n" . |
d8a20ba9 KS |
1078 | "<td>"; |
1079 | if (defined($comment)) { | |
232ff553 | 1080 | print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment); |
d8a20ba9 KS |
1081 | } |
1082 | print "</td>\n" . | |
1083 | "<td class=\"link\">"; | |
1084 | if ($tag{'type'} eq "tag") { | |
232ff553 | 1085 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | "; |
d8a20ba9 | 1086 | } |
232ff553 | 1087 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'}); |
d8a20ba9 | 1088 | if ($tag{'reftype'} eq "commit") { |
232ff553 KS |
1089 | print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") . |
1090 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log"); | |
19806691 KS |
1091 | } |
1092 | print "</td>\n" . | |
440c6006 KS |
1093 | "</tr>"; |
1094 | } else { | |
232ff553 | 1095 | print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tags")}, "...") . "</td>\n" . |
440c6006 | 1096 | "</tr>"; |
ede5e100 KS |
1097 | last; |
1098 | } | |
1099 | } | |
bddec01d | 1100 | print "</table\n>"; |
ede5e100 | 1101 | } |
0db37973 | 1102 | |
d8f1c5c2 KS |
1103 | my $headlist = git_read_refs("refs/heads"); |
1104 | if (defined @$headlist) { | |
0db37973 | 1105 | print "<div>\n" . |
232ff553 | 1106 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=heads"), -class => "title"}, "heads") . |
0db37973 | 1107 | "</div>\n"; |
19806691 | 1108 | my $i = 16; |
bddec01d KS |
1109 | print "<table cellspacing=\"0\">\n"; |
1110 | my $alternate = 0; | |
d8f1c5c2 | 1111 | foreach my $entry (@$headlist) { |
0db37973 | 1112 | my %tag = %$entry; |
bddec01d | 1113 | if ($alternate) { |
c994d620 | 1114 | print "<tr class=\"dark\">\n"; |
bddec01d | 1115 | } else { |
c994d620 | 1116 | print "<tr class=\"light\">\n"; |
bddec01d KS |
1117 | } |
1118 | $alternate ^= 1; | |
19806691 | 1119 | if ($i-- > 0) { |
10dba28d | 1120 | print "<td><i>$tag{'age'}</i></td>\n" . |
19806691 | 1121 | "<td>" . |
232ff553 | 1122 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"}, |
40c13813 | 1123 | "<b>" . esc_html($tag{'name'}) . "</b>") . |
19806691 KS |
1124 | "</td>\n" . |
1125 | "<td class=\"link\">" . | |
232ff553 KS |
1126 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") . |
1127 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'name'}")}, "log") . | |
19806691 | 1128 | "</td>\n" . |
0db37973 KS |
1129 | "</tr>"; |
1130 | } else { | |
232ff553 | 1131 | print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=heads")}, "...") . "</td>\n" . |
0db37973 KS |
1132 | "</tr>"; |
1133 | last; | |
1134 | } | |
1135 | } | |
bddec01d | 1136 | print "</table\n>"; |
0db37973 | 1137 | } |
ede5e100 KS |
1138 | git_footer_html(); |
1139 | } | |
1140 | ||
d8a20ba9 KS |
1141 | sub git_tag { |
1142 | my $head = git_read_hash("$project/HEAD"); | |
1143 | git_header_html(); | |
1144 | print "<div class=\"page_nav\">\n" . | |
232ff553 KS |
1145 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") . |
1146 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") . | |
1147 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") . | |
1148 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") . | |
1149 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") . | |
1150 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" . | |
d8a20ba9 KS |
1151 | "<br/>\n" . |
1152 | "</div>\n"; | |
1153 | my %tag = git_read_tag($hash); | |
1154 | print "<div>\n" . | |
232ff553 | 1155 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($tag{'name'})) . "\n" . |
d8a20ba9 KS |
1156 | "</div>\n"; |
1157 | print "<div class=\"title_text\">\n" . | |
1158 | "<table cellspacing=\"0\">\n" . | |
e4669df9 KS |
1159 | "<tr>\n" . |
1160 | "<td>object</td>\n" . | |
232ff553 KS |
1161 | "<td>" . $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" . |
1162 | "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" . | |
e4669df9 | 1163 | "</tr>\n"; |
d8a20ba9 KS |
1164 | if (defined($tag{'author'})) { |
1165 | my %ad = date_str($tag{'epoch'}, $tag{'tz'}); | |
40c13813 | 1166 | print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n"; |
d8a20ba9 KS |
1167 | print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n"; |
1168 | } | |
1169 | print "</table>\n\n" . | |
1170 | "</div>\n"; | |
1171 | print "<div class=\"page_body\">"; | |
1172 | my $comment = $tag{'comment'}; | |
1173 | foreach my $line (@$comment) { | |
40c13813 | 1174 | print esc_html($line) . "<br/>\n"; |
d8a20ba9 KS |
1175 | } |
1176 | print "</div>\n"; | |
1177 | git_footer_html(); | |
1178 | } | |
1179 | ||
ede5e100 KS |
1180 | sub git_tags { |
1181 | my $head = git_read_hash("$project/HEAD"); | |
1182 | git_header_html(); | |
1183 | print "<div class=\"page_nav\">\n" . | |
232ff553 KS |
1184 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") . |
1185 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") . | |
1186 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") . | |
1187 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") . | |
1188 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") . | |
1189 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" . | |
19806691 | 1190 | "<br/>\n" . |
ede5e100 | 1191 | "</div>\n"; |
0db37973 | 1192 | my $taglist = git_read_refs("refs/tags"); |
ede5e100 | 1193 | print "<div>\n" . |
232ff553 | 1194 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") . |
ede5e100 | 1195 | "</div>\n"; |
bddec01d KS |
1196 | print "<table cellspacing=\"0\">\n"; |
1197 | my $alternate = 0; | |
ede5e100 KS |
1198 | if (defined @$taglist) { |
1199 | foreach my $entry (@$taglist) { | |
1200 | my %tag = %$entry; | |
d8a20ba9 KS |
1201 | my $comment_lines = $tag{'comment'}; |
1202 | my $comment = shift @$comment_lines; | |
1203 | if (defined($comment)) { | |
1204 | $comment = chop_str($comment, 30, 5); | |
1205 | } | |
bddec01d | 1206 | if ($alternate) { |
c994d620 | 1207 | print "<tr class=\"dark\">\n"; |
bddec01d | 1208 | } else { |
c994d620 | 1209 | print "<tr class=\"light\">\n"; |
bddec01d KS |
1210 | } |
1211 | $alternate ^= 1; | |
1212 | print "<td><i>$tag{'age'}</i></td>\n" . | |
19806691 | 1213 | "<td>" . |
232ff553 | 1214 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"}, |
40c13813 | 1215 | "<b>" . esc_html($tag{'name'}) . "</b>") . |
19806691 | 1216 | "</td>\n" . |
d8a20ba9 KS |
1217 | "<td>"; |
1218 | if (defined($comment)) { | |
232ff553 | 1219 | print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment); |
d8a20ba9 KS |
1220 | } |
1221 | print "</td>\n" . | |
1222 | "<td class=\"link\">"; | |
1223 | if ($tag{'type'} eq "tag") { | |
232ff553 | 1224 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | "; |
d8a20ba9 | 1225 | } |
232ff553 | 1226 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'}); |
d8a20ba9 | 1227 | if ($tag{'reftype'} eq "commit") { |
232ff553 KS |
1228 | print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") . |
1229 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log"); | |
19806691 KS |
1230 | } |
1231 | print "</td>\n" . | |
10dba28d | 1232 | "</tr>"; |
ede5e100 KS |
1233 | } |
1234 | } | |
bddec01d | 1235 | print "</table\n>"; |
ede5e100 KS |
1236 | git_footer_html(); |
1237 | } | |
1238 | ||
d8f1c5c2 | 1239 | sub git_heads { |
0db37973 KS |
1240 | my $head = git_read_hash("$project/HEAD"); |
1241 | git_header_html(); | |
1242 | print "<div class=\"page_nav\">\n" . | |
232ff553 KS |
1243 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") . |
1244 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") . | |
1245 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") . | |
1246 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") . | |
1247 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") . | |
1248 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" . | |
19806691 | 1249 | "<br/>\n" . |
0db37973 KS |
1250 | "</div>\n"; |
1251 | my $taglist = git_read_refs("refs/heads"); | |
1252 | print "<div>\n" . | |
232ff553 | 1253 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") . |
0db37973 | 1254 | "</div>\n"; |
bddec01d KS |
1255 | print "<table cellspacing=\"0\">\n"; |
1256 | my $alternate = 0; | |
0db37973 KS |
1257 | if (defined @$taglist) { |
1258 | foreach my $entry (@$taglist) { | |
1259 | my %tag = %$entry; | |
bddec01d | 1260 | if ($alternate) { |
c994d620 | 1261 | print "<tr class=\"dark\">\n"; |
bddec01d | 1262 | } else { |
c994d620 | 1263 | print "<tr class=\"light\">\n"; |
bddec01d KS |
1264 | } |
1265 | $alternate ^= 1; | |
1266 | print "<td><i>$tag{'age'}</i></td>\n" . | |
19806691 | 1267 | "<td>" . |
232ff553 | 1268 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"}, "<b>" . esc_html($tag{'name'}) . "</b>") . |
19806691 KS |
1269 | "</td>\n" . |
1270 | "<td class=\"link\">" . | |
232ff553 KS |
1271 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") . |
1272 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'name'}")}, "log") . | |
19806691 | 1273 | "</td>\n" . |
10dba28d | 1274 | "</tr>"; |
0db37973 KS |
1275 | } |
1276 | } | |
bddec01d | 1277 | print "</table\n>"; |
0db37973 KS |
1278 | git_footer_html(); |
1279 | } | |
1280 | ||
09bd7898 KS |
1281 | sub git_get_hash_by_path { |
1282 | my $base = shift; | |
19806691 | 1283 | my $path = shift || return undef; |
09bd7898 KS |
1284 | |
1285 | my $tree = $base; | |
1286 | my @parts = split '/', $path; | |
1287 | while (my $part = shift @parts) { | |
19806691 | 1288 | open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error(undef, "Open git-ls-tree failed."); |
09bd7898 | 1289 | my (@entries) = map { chomp; $_ } <$fd>; |
19806691 | 1290 | close $fd or return undef; |
09bd7898 KS |
1291 | foreach my $line (@entries) { |
1292 | #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c' | |
19806691 | 1293 | $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/; |
09bd7898 KS |
1294 | my $t_mode = $1; |
1295 | my $t_type = $2; | |
1296 | my $t_hash = $3; | |
ae786205 | 1297 | my $t_name = validate_input(unquote($4)); |
09bd7898 KS |
1298 | if ($t_name eq $part) { |
1299 | if (!(@parts)) { | |
1300 | return $t_hash; | |
1301 | } | |
1302 | if ($t_type eq "tree") { | |
1303 | $tree = $t_hash; | |
1304 | } | |
1305 | last; | |
1306 | } | |
1307 | } | |
1308 | } | |
1309 | } | |
1310 | ||
1311 | sub git_blob { | |
1312 | if (!defined $hash && defined $file_name) { | |
ede5e100 | 1313 | my $base = $hash_base || git_read_hash("$project/HEAD"); |
ae786205 | 1314 | $hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file."); |
09bd7898 | 1315 | } |
19806691 | 1316 | open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error(undef, "Open failed."); |
12a88f2f | 1317 | git_header_html(); |
09bd7898 | 1318 | if (defined $hash_base && (my %co = git_read_commit($hash_base))) { |
42f7eb94 | 1319 | print "<div class=\"page_nav\">\n" . |
232ff553 KS |
1320 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") . |
1321 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") . | |
1322 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") . | |
1323 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") . | |
1324 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") . | |
1325 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n"; | |
9312944d | 1326 | if (defined $file_name) { |
232ff553 KS |
1327 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") . |
1328 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head") . "<br/>\n"; | |
9312944d | 1329 | } else { |
232ff553 | 1330 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash")}, "plain") . "<br/>\n"; |
9312944d KS |
1331 | } |
1332 | print "</div>\n". | |
1333 | "<div>" . | |
232ff553 | 1334 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . |
c07ad4b9 | 1335 | "</div>\n"; |
09bd7898 KS |
1336 | } else { |
1337 | print "<div class=\"page_nav\">\n" . | |
1338 | "<br/><br/></div>\n" . | |
1339 | "<div class=\"title\">$hash</div>\n"; | |
1340 | } | |
1341 | if (defined $file_name) { | |
232ff553 | 1342 | print "<div class=\"page_path\"><b>" . esc_html($file_name) . "</b></div>\n"; |
09bd7898 | 1343 | } |
c07ad4b9 | 1344 | print "<div class=\"page_body\">\n"; |
161332a5 KS |
1345 | my $nr; |
1346 | while (my $line = <$fd>) { | |
c07ad4b9 | 1347 | chomp $line; |
161332a5 | 1348 | $nr++; |
19806691 KS |
1349 | while ((my $pos = index($line, "\t")) != -1) { |
1350 | if (my $count = (8 - ($pos % 8))) { | |
1351 | my $spaces = ' ' x $count; | |
1352 | $line =~ s/\t/$spaces/; | |
1353 | } | |
1354 | } | |
40c13813 | 1355 | printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html($line); |
161332a5 | 1356 | } |
19806691 | 1357 | close $fd or print "Reading blob failed.\n"; |
fbb592a9 | 1358 | print "</div>"; |
12a88f2f | 1359 | git_footer_html(); |
09bd7898 KS |
1360 | } |
1361 | ||
19806691 | 1362 | sub git_blob_plain { |
9312944d KS |
1363 | my $save_as = "$hash.txt"; |
1364 | if (defined $file_name) { | |
1365 | $save_as = $file_name; | |
1366 | } | |
1367 | print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"$save_as\""); | |
19806691 KS |
1368 | open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return; |
1369 | undef $/; | |
1370 | print <$fd>; | |
1371 | $/ = "\n"; | |
1372 | close $fd; | |
1373 | } | |
1374 | ||
09bd7898 | 1375 | sub git_tree { |
b87d78d6 | 1376 | if (!defined $hash) { |
ede5e100 | 1377 | $hash = git_read_hash("$project/HEAD"); |
09bd7898 | 1378 | if (defined $file_name) { |
ede5e100 | 1379 | my $base = $hash_base || git_read_hash("$project/HEAD"); |
09bd7898 KS |
1380 | $hash = git_get_hash_by_path($base, $file_name, "tree"); |
1381 | } | |
10dba28d KS |
1382 | if (!defined $hash_base) { |
1383 | $hash_base = git_read_hash("$project/HEAD"); | |
1384 | } | |
e925f38c | 1385 | } |
232ff553 KS |
1386 | $/ = "\0"; |
1387 | open my $fd, "-|", "$gitbin/git-ls-tree -z $hash" or die_error(undef, "Open git-ls-tree failed."); | |
1388 | chomp (my (@entries) = <$fd>); | |
19806691 | 1389 | close $fd or die_error(undef, "Reading tree failed."); |
232ff553 | 1390 | $/ = "\n"; |
d63577da | 1391 | |
12a88f2f | 1392 | git_header_html(); |
09bd7898 | 1393 | my $base_key = ""; |
09bd7898 KS |
1394 | my $base = ""; |
1395 | if (defined $hash_base && (my %co = git_read_commit($hash_base))) { | |
1396 | $base_key = ";hb=$hash_base"; | |
42f7eb94 | 1397 | print "<div class=\"page_nav\">\n" . |
232ff553 KS |
1398 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") . |
1399 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash_base")}, "shortlog") . | |
1400 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash_base")}, "log") . | |
1401 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") . | |
1402 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") . | |
19806691 | 1403 | " | tree" . |
6191f8e1 KS |
1404 | "<br/><br/>\n" . |
1405 | "</div>\n"; | |
d63577da | 1406 | print "<div>\n" . |
232ff553 | 1407 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "\n" . |
d63577da KS |
1408 | "</div>\n"; |
1409 | } else { | |
1410 | print "<div class=\"page_nav\">\n"; | |
1411 | print "<br/><br/></div>\n"; | |
1412 | print "<div class=\"title\">$hash</div>\n"; | |
1413 | } | |
09bd7898 | 1414 | if (defined $file_name) { |
232ff553 KS |
1415 | $base = esc_html("$file_name/"); |
1416 | print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b></div>\n"; | |
09bd7898 | 1417 | } else { |
19806691 | 1418 | print "<div class=\"page_path\"><b>/</b></div>\n"; |
09bd7898 | 1419 | } |
fbb592a9 | 1420 | print "<div class=\"page_body\">\n"; |
42f7eb94 | 1421 | print "<table cellspacing=\"0\">\n"; |
bddec01d | 1422 | my $alternate = 0; |
161332a5 | 1423 | foreach my $line (@entries) { |
c068cff1 | 1424 | #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c' |
19806691 | 1425 | $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/; |
d767d59c | 1426 | my $t_mode = $1; |
161332a5 KS |
1427 | my $t_type = $2; |
1428 | my $t_hash = $3; | |
232ff553 | 1429 | my $t_name = validate_input($4); |
bddec01d | 1430 | if ($alternate) { |
c994d620 | 1431 | print "<tr class=\"dark\">\n"; |
bddec01d | 1432 | } else { |
c994d620 | 1433 | print "<tr class=\"light\">\n"; |
bddec01d KS |
1434 | } |
1435 | $alternate ^= 1; | |
1436 | print "<td style=\"font-family:monospace\">" . mode_str($t_mode) . "</td>\n"; | |
161332a5 | 1437 | if ($t_type eq "blob") { |
10dba28d | 1438 | print "<td class=\"list\">" . |
232ff553 | 1439 | $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)) . |
c994d620 KS |
1440 | "</td>\n" . |
1441 | "<td class=\"link\">" . | |
232ff553 KS |
1442 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") . |
1443 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") . | |
42f7eb94 | 1444 | "</td>\n"; |
161332a5 | 1445 | } elsif ($t_type eq "tree") { |
10dba28d | 1446 | print "<td class=\"list\">" . |
232ff553 | 1447 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html($t_name)) . |
19806691 | 1448 | "</td>\n" . |
c994d620 | 1449 | "<td class=\"link\">" . |
232ff553 | 1450 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") . |
c994d620 | 1451 | "</td>\n"; |
161332a5 | 1452 | } |
42f7eb94 | 1453 | print "</tr>\n"; |
161332a5 | 1454 | } |
42f7eb94 KS |
1455 | print "</table>\n" . |
1456 | "</div>"; | |
12a88f2f | 1457 | git_footer_html(); |
09bd7898 KS |
1458 | } |
1459 | ||
1460 | sub git_rss { | |
19806691 | 1461 | # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ |
d8d17b5d | 1462 | open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_hash("$project/HEAD") or die_error(undef, "Open failed."); |
d51e902a | 1463 | my (@revlist) = map { chomp; $_ } <$fd>; |
19806691 | 1464 | close $fd or die_error(undef, "Reading rev-list failed."); |
034df39e KS |
1465 | print $cgi->header(-type => 'text/xml', -charset => 'utf-8'); |
1466 | print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n". | |
19806691 | 1467 | "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n"; |
034df39e KS |
1468 | print "<channel>\n"; |
1469 | print "<title>$project</title>\n". | |
40c13813 | 1470 | "<link>" . esc_html("$my_url?p=$project;a=summary") . "</link>\n". |
034df39e KS |
1471 | "<description>$project log</description>\n". |
1472 | "<language>en</language>\n"; | |
1473 | ||
d8d17b5d KS |
1474 | for (my $i = 0; $i <= $#revlist; $i++) { |
1475 | my $commit = $revlist[$i]; | |
09bd7898 | 1476 | my %co = git_read_commit($commit); |
d8d17b5d KS |
1477 | # we read 150, we always show 30 and the ones more recent than 48 hours |
1478 | if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) { | |
1479 | last; | |
1480 | } | |
19806691 | 1481 | my %cd = date_str($co{'committer_epoch'}); |
d8d17b5d KS |
1482 | open $fd, "-|", "$gitbin/git-diff-tree -r $co{'parent'} $co{'id'}" or next; |
1483 | my @difftree = map { chomp; $_ } <$fd>; | |
1484 | close $fd or next; | |
034df39e | 1485 | print "<item>\n" . |
19806691 | 1486 | "<title>" . |
40c13813 | 1487 | sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) . |
19806691 | 1488 | "</title>\n" . |
40c13813 | 1489 | "<author>" . esc_html($co{'author'}) . "</author>\n" . |
19806691 | 1490 | "<pubDate>$cd{'rfc2822'}</pubDate>\n" . |
40c13813 KS |
1491 | "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" . |
1492 | "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" . | |
1493 | "<description>" . esc_html($co{'title'}) . "</description>\n" . | |
19806691 KS |
1494 | "<content:encoded>" . |
1495 | "<![CDATA[\n"; | |
034df39e KS |
1496 | my $comment = $co{'comment'}; |
1497 | foreach my $line (@$comment) { | |
40c13813 | 1498 | $line = decode("utf8", $line, Encode::FB_DEFAULT); |
19806691 | 1499 | print "$line<br/>\n"; |
161332a5 | 1500 | } |
d8d17b5d KS |
1501 | print "<br/>\n"; |
1502 | foreach my $line (@difftree) { | |
1503 | if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) { | |
1504 | next; | |
1505 | } | |
232ff553 KS |
1506 | my $file = validate_input(unquote($7)); |
1507 | $file = decode("utf8", $file, Encode::FB_DEFAULT); | |
d8d17b5d KS |
1508 | print "$file<br/>\n"; |
1509 | } | |
19806691 KS |
1510 | print "]]>\n" . |
1511 | "</content:encoded>\n" . | |
034df39e KS |
1512 | "</item>\n"; |
1513 | } | |
1514 | print "</channel></rss>"; | |
09bd7898 KS |
1515 | } |
1516 | ||
c994d620 KS |
1517 | sub git_opml { |
1518 | my @list = git_read_projects(); | |
1519 | ||
1520 | print $cgi->header(-type => 'text/xml', -charset => 'utf-8'); | |
1521 | print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n". | |
1522 | "<opml version=\"1.0\">\n". | |
1523 | "<head>". | |
1524 | " <title>Git OPML Export</title>\n". | |
1525 | "</head>\n". | |
1526 | "<body>\n". | |
1527 | "<outline text=\"git RSS feeds\">\n"; | |
1528 | ||
1529 | foreach my $pr (@list) { | |
1530 | my %proj = %$pr; | |
1531 | my $head = git_read_hash("$proj{'path'}/HEAD"); | |
1532 | if (!defined $head) { | |
1533 | next; | |
1534 | } | |
4fac5294 | 1535 | $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}"; |
c994d620 KS |
1536 | my %co = git_read_commit($head); |
1537 | if (!%co) { | |
1538 | next; | |
1539 | } | |
1540 | ||
40c13813 | 1541 | my $path = esc_html(chop_str($proj{'path'}, 25, 5)); |
c994d620 | 1542 | my $rss = "$my_url?p=$proj{'path'};a=rss"; |
71be1e79 | 1543 | my $html = "$my_url?p=$proj{'path'};a=summary"; |
c994d620 KS |
1544 | print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n"; |
1545 | } | |
1546 | print "</outline>\n". | |
1547 | "</body>\n". | |
1548 | "</opml>\n"; | |
1549 | } | |
1550 | ||
09bd7898 | 1551 | sub git_log { |
19806691 | 1552 | my $head = git_read_hash("$project/HEAD"); |
0db37973 | 1553 | if (!defined $hash) { |
19806691 | 1554 | $hash = $head; |
0db37973 | 1555 | } |
ea4a6df4 KS |
1556 | if (!defined $page) { |
1557 | $page = 0; | |
b87d78d6 | 1558 | } |
034df39e KS |
1559 | git_header_html(); |
1560 | print "<div class=\"page_nav\">\n"; | |
232ff553 KS |
1561 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") . |
1562 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash")}, "shortlog") . | |
19806691 | 1563 | " | log" . |
232ff553 KS |
1564 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") . |
1565 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") . | |
1566 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n"; | |
ea4a6df4 KS |
1567 | |
1568 | my $limit = sprintf("--max-count=%i", (100 * ($page+1))); | |
1569 | open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed."); | |
1570 | my (@revlist) = map { chomp; $_ } <$fd>; | |
1571 | close $fd; | |
1572 | ||
1573 | if ($hash ne $head || $page) { | |
232ff553 | 1574 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "HEAD"); |
ea4a6df4 KS |
1575 | } else { |
1576 | print "HEAD"; | |
1577 | } | |
1578 | if ($page > 0) { | |
c994d620 | 1579 | print " ⋅ " . |
232ff553 | 1580 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash;pg=" . ($page-1)), -accesskey => "p", -title => "Alt-p"}, "prev"); |
ea4a6df4 KS |
1581 | } else { |
1582 | print " ⋅ prev"; | |
1583 | } | |
1584 | if ($#revlist >= (100 * ($page+1)-1)) { | |
c994d620 | 1585 | print " ⋅ " . |
232ff553 | 1586 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash;pg=" . ($page+1)), -accesskey => "n", -title => "Alt-n"}, "next"); |
ea4a6df4 KS |
1587 | } else { |
1588 | print " ⋅ next"; | |
1589 | } | |
ede5e100 | 1590 | print "<br/>\n" . |
034df39e | 1591 | "</div>\n"; |
b87d78d6 | 1592 | if (!@revlist) { |
19806691 | 1593 | print "<div>\n" . |
232ff553 | 1594 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") . |
19806691 | 1595 | "</div>\n"; |
0db37973 | 1596 | my %co = git_read_commit($hash); |
e925f38c | 1597 | print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n"; |
161332a5 | 1598 | } |
c994d620 KS |
1599 | for (my $i = ($page * 100); $i <= $#revlist; $i++) { |
1600 | my $commit = $revlist[$i]; | |
09bd7898 | 1601 | my %co = git_read_commit($commit); |
b87d78d6 | 1602 | next if !%co; |
034df39e KS |
1603 | my %ad = date_str($co{'author_epoch'}); |
1604 | print "<div>\n" . | |
232ff553 | 1605 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "title"}, |
40c13813 | 1606 | "<span class=\"age\">$co{'age_string'}</span>" . esc_html($co{'title'})) . "\n" . |
034df39e KS |
1607 | "</div>\n"; |
1608 | print "<div class=\"title_text\">\n" . | |
1609 | "<div class=\"log_link\">\n" . | |
232ff553 KS |
1610 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") . |
1611 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") . | |
eb28240b | 1612 | "<br/>\n" . |
034df39e | 1613 | "</div>\n" . |
40c13813 | 1614 | "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" . |
034df39e KS |
1615 | "</div>\n" . |
1616 | "<div class=\"log_body\">\n"; | |
1617 | my $comment = $co{'comment'}; | |
09bd7898 | 1618 | my $empty = 0; |
034df39e | 1619 | foreach my $line (@$comment) { |
10dba28d | 1620 | if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) { |
09bd7898 KS |
1621 | next; |
1622 | } | |
1623 | if ($line eq "") { | |
1624 | if ($empty) { | |
1625 | next; | |
1626 | } | |
1627 | $empty = 1; | |
1628 | } else { | |
1629 | $empty = 0; | |
1630 | } | |
f49201a9 | 1631 | print format_log_line_html($line) . "<br/>\n"; |
034df39e | 1632 | } |
09bd7898 KS |
1633 | if (!$empty) { |
1634 | print "<br/>\n"; | |
1635 | } | |
1636 | print "</div>\n"; | |
e334d18c | 1637 | } |
034df39e | 1638 | git_footer_html(); |
09bd7898 KS |
1639 | } |
1640 | ||
1641 | sub git_commit { | |
1642 | my %co = git_read_commit($hash); | |
034df39e | 1643 | if (!%co) { |
09bd7898 | 1644 | die_error(undef, "Unknown commit object."); |
d63577da | 1645 | } |
185f09e5 KS |
1646 | my %ad = date_str($co{'author_epoch'}, $co{'author_tz'}); |
1647 | my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'}); | |
161332a5 | 1648 | |
6191f8e1 | 1649 | my @difftree; |
19806691 | 1650 | my $root = ""; |
d8a20ba9 KS |
1651 | my $parent = $co{'parent'}; |
1652 | if (!defined $parent) { | |
19806691 | 1653 | $root = " --root"; |
d8a20ba9 | 1654 | $parent = ""; |
6191f8e1 | 1655 | } |
d8a20ba9 | 1656 | open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $parent $hash" or die_error(undef, "Open failed."); |
19806691 KS |
1657 | @difftree = map { chomp; $_ } <$fd>; |
1658 | close $fd or die_error(undef, "Reading diff-tree failed."); | |
11044297 KS |
1659 | |
1660 | # non-textual hash id's can be cached | |
1661 | my $expires; | |
1662 | if ($hash =~ m/^[0-9a-fA-F]{40}$/) { | |
1663 | $expires = "+1d"; | |
1664 | } | |
1665 | git_header_html(undef, $expires); | |
42f7eb94 | 1666 | print "<div class=\"page_nav\">\n" . |
232ff553 KS |
1667 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") . |
1668 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash")}, "shortlog") . | |
1669 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") . | |
19806691 | 1670 | " | commit"; |
42f7eb94 | 1671 | if (defined $co{'parent'}) { |
232ff553 | 1672 | print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff"); |
42f7eb94 | 1673 | } |
232ff553 | 1674 | print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "\n" . |
ff7669a5 | 1675 | "<br/><br/></div>\n"; |
b87d78d6 KS |
1676 | if (defined $co{'parent'}) { |
1677 | print "<div>\n" . | |
232ff553 | 1678 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" . |
b87d78d6 KS |
1679 | "</div>\n"; |
1680 | } else { | |
1681 | print "<div>\n" . | |
232ff553 | 1682 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" . |
b87d78d6 KS |
1683 | "</div>\n"; |
1684 | } | |
6191f8e1 | 1685 | print "<div class=\"title_text\">\n" . |
b87d78d6 | 1686 | "<table cellspacing=\"0\">\n"; |
40c13813 | 1687 | print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n". |
bddec01d KS |
1688 | "<tr>" . |
1689 | "<td></td><td> $ad{'rfc2822'}"; | |
927dcec4 | 1690 | if ($ad{'hour_local'} < 6) { |
b87d78d6 KS |
1691 | printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}); |
1692 | } else { | |
1693 | printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}); | |
1694 | } | |
bddec01d KS |
1695 | print "</td>" . |
1696 | "</tr>\n"; | |
40c13813 | 1697 | print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n"; |
e925f38c | 1698 | print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n"; |
f9127561 | 1699 | print "<tr><td>commit</td><td style=\"font-family:monospace\">$co{'id'}</td></tr>\n"; |
bddec01d KS |
1700 | print "<tr>" . |
1701 | "<td>tree</td>" . | |
19806691 | 1702 | "<td style=\"font-family:monospace\">" . |
232ff553 | 1703 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) . |
19806691 | 1704 | "</td>" . |
232ff553 | 1705 | "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . |
bddec01d KS |
1706 | "</td>" . |
1707 | "</tr>\n"; | |
3e029299 KS |
1708 | my $parents = $co{'parents'}; |
1709 | foreach my $par (@$parents) { | |
bddec01d KS |
1710 | print "<tr>" . |
1711 | "<td>parent</td>" . | |
232ff553 | 1712 | "<td style=\"font-family:monospace\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" . |
bddec01d | 1713 | "<td class=\"link\">" . |
232ff553 KS |
1714 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$par")}, "commit") . |
1715 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") . | |
bddec01d KS |
1716 | "</td>" . |
1717 | "</tr>\n"; | |
3e029299 | 1718 | } |
b87d78d6 KS |
1719 | print "</table>". |
1720 | "</div>\n"; | |
fbb592a9 | 1721 | print "<div class=\"page_body\">\n"; |
3e029299 | 1722 | my $comment = $co{'comment'}; |
09bd7898 KS |
1723 | my $empty = 0; |
1724 | my $signed = 0; | |
3e029299 | 1725 | foreach my $line (@$comment) { |
09bd7898 KS |
1726 | # print only one empty line |
1727 | if ($line eq "") { | |
1728 | if ($empty || $signed) { | |
1729 | next; | |
1730 | } | |
1731 | $empty = 1; | |
1732 | } else { | |
1733 | $empty = 0; | |
1734 | } | |
10dba28d | 1735 | if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) { |
09bd7898 | 1736 | $signed = 1; |
40c13813 | 1737 | print "<span style=\"color: #888888\">" . esc_html($line) . "</span><br/>\n"; |
3e029299 | 1738 | } else { |
09bd7898 | 1739 | $signed = 0; |
f49201a9 | 1740 | print format_log_line_html($line) . "<br/>\n"; |
3e029299 KS |
1741 | } |
1742 | } | |
927dcec4 | 1743 | print "</div>\n"; |
09bd7898 | 1744 | print "<div class=\"list_head\">\n"; |
6191f8e1 | 1745 | if ($#difftree > 10) { |
09bd7898 | 1746 | print(($#difftree + 1) . " files changed:\n"); |
6191f8e1 | 1747 | } |
09bd7898 | 1748 | print "</div>\n"; |
bddec01d KS |
1749 | print "<table cellspacing=\"0\">\n"; |
1750 | my $alternate = 0; | |
161332a5 | 1751 | foreach my $line (@difftree) { |
19806691 KS |
1752 | # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c' |
1753 | # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c' | |
d8a20ba9 KS |
1754 | if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) { |
1755 | next; | |
1756 | } | |
19806691 KS |
1757 | my $from_mode = $1; |
1758 | my $to_mode = $2; | |
1759 | my $from_id = $3; | |
1760 | my $to_id = $4; | |
1761 | my $status = $5; | |
ea4a6df4 | 1762 | my $similarity = $6; |
232ff553 | 1763 | my $file = validate_input(unquote($7)); |
bddec01d | 1764 | if ($alternate) { |
c994d620 | 1765 | print "<tr class=\"dark\">\n"; |
bddec01d | 1766 | } else { |
c994d620 | 1767 | print "<tr class=\"light\">\n"; |
bddec01d KS |
1768 | } |
1769 | $alternate ^= 1; | |
f6375b24 | 1770 | if ($status eq "A") { |
10dba28d | 1771 | my $mode_chng = ""; |
19806691 KS |
1772 | if (S_ISREG(oct $to_mode)) { |
1773 | $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777); | |
10dba28d KS |
1774 | } |
1775 | print "<td>" . | |
232ff553 | 1776 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file)) . "</td>\n" . |
19806691 | 1777 | "<td><span style=\"color: #008000;\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" . |
232ff553 | 1778 | "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n"; |
19806691 | 1779 | } elsif ($status eq "D") { |
10dba28d | 1780 | print "<td>" . |
232ff553 | 1781 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file)) . "</td>\n" . |
19806691 | 1782 | "<td><span style=\"color: #c00000;\">[deleted " . file_type($from_mode). "]</span></td>\n" . |
10dba28d | 1783 | "<td class=\"link\">" . |
232ff553 KS |
1784 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") . |
1785 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash;f=$file")}, "history") . | |
10dba28d | 1786 | "</td>\n" |
19806691 | 1787 | } elsif ($status eq "M" || $status eq "T") { |
10dba28d KS |
1788 | my $mode_chnge = ""; |
1789 | if ($from_mode != $to_mode) { | |
1790 | $mode_chnge = " <span style=\"color: #777777;\">[changed"; | |
1791 | if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) { | |
1792 | $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode); | |
b87d78d6 | 1793 | } |
10dba28d KS |
1794 | if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) { |
1795 | if (S_ISREG($from_mode) && S_ISREG($to_mode)) { | |
1796 | $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777); | |
1797 | } elsif (S_ISREG($to_mode)) { | |
1798 | $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777); | |
b87d78d6 | 1799 | } |
9cd3d988 | 1800 | } |
10dba28d KS |
1801 | $mode_chnge .= "]</span>\n"; |
1802 | } | |
1803 | print "<td>"; | |
1804 | if ($to_id ne $from_id) { | |
232ff553 | 1805 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file)); |
10dba28d | 1806 | } else { |
232ff553 | 1807 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file)); |
161332a5 | 1808 | } |
10dba28d KS |
1809 | print "</td>\n" . |
1810 | "<td>$mode_chnge</td>\n" . | |
1811 | "<td class=\"link\">"; | |
232ff553 | 1812 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob"); |
10dba28d | 1813 | if ($to_id ne $from_id) { |
232ff553 | 1814 | print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff"); |
10dba28d | 1815 | } |
232ff553 | 1816 | print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash;f=$file")}, "history") . "\n"; |
10dba28d | 1817 | print "</td>\n"; |
dcea8d0b KS |
1818 | } elsif ($status eq "R") { |
1819 | my ($from_file, $to_file) = split "\t", $file; | |
1820 | my $mode_chng = ""; | |
1821 | if ($from_mode != $to_mode) { | |
1822 | $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777); | |
1823 | } | |
1824 | print "<td>" . | |
232ff553 | 1825 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file"), -class => "list"}, esc_html($to_file)) . "</td>\n" . |
dcea8d0b | 1826 | "<td><span style=\"color: #777777;\">[moved from " . |
232ff553 | 1827 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$from_file"), -class => "list"}, esc_html($from_file)) . |
ea4a6df4 | 1828 | " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" . |
dcea8d0b | 1829 | "<td class=\"link\">" . |
232ff553 | 1830 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob"); |
dcea8d0b | 1831 | if ($to_id ne $from_id) { |
232ff553 | 1832 | print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff"); |
dcea8d0b KS |
1833 | } |
1834 | print "</td>\n"; | |
161332a5 | 1835 | } |
10dba28d | 1836 | print "</tr>\n"; |
161332a5 | 1837 | } |
bddec01d | 1838 | print "</table>\n"; |
12a88f2f | 1839 | git_footer_html(); |
09bd7898 KS |
1840 | } |
1841 | ||
1842 | sub git_blobdiff { | |
19806691 | 1843 | mkdir($git_temp, 0700); |
12a88f2f | 1844 | git_header_html(); |
09bd7898 | 1845 | if (defined $hash_base && (my %co = git_read_commit($hash_base))) { |
42f7eb94 | 1846 | print "<div class=\"page_nav\">\n" . |
232ff553 KS |
1847 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") . |
1848 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") . | |
1849 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") . | |
1850 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") . | |
1851 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") . | |
1852 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . | |
19806691 | 1853 | "<br/>\n"; |
232ff553 | 1854 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain") . |
09bd7898 KS |
1855 | "</div>\n"; |
1856 | print "<div>\n" . | |
232ff553 | 1857 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "\n" . |
09bd7898 KS |
1858 | "</div>\n"; |
1859 | } else { | |
1860 | print "<div class=\"page_nav\">\n" . | |
1861 | "<br/><br/></div>\n" . | |
1862 | "<div class=\"title\">$hash vs $hash_parent</div>\n"; | |
1863 | } | |
1864 | if (defined $file_name) { | |
232ff553 | 1865 | print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b></div>\n"; |
09bd7898 | 1866 | } |
9cd3d988 | 1867 | print "<div class=\"page_body\">\n" . |
c07ad4b9 | 1868 | "<div class=\"diff_info\">blob:" . |
232ff553 | 1869 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) . |
2735983d | 1870 | " -> blob:" . |
232ff553 | 1871 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) . |
c07ad4b9 | 1872 | "</div>\n"; |
19806691 | 1873 | git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash); |
c07ad4b9 | 1874 | print "</div>"; |
12a88f2f | 1875 | git_footer_html(); |
09bd7898 KS |
1876 | } |
1877 | ||
19806691 KS |
1878 | sub git_blobdiff_plain { |
1879 | mkdir($git_temp, 0700); | |
1880 | print $cgi->header(-type => "text/plain", -charset => 'utf-8'); | |
1881 | git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain"); | |
1882 | } | |
1883 | ||
09bd7898 | 1884 | sub git_commitdiff { |
19806691 | 1885 | mkdir($git_temp, 0700); |
09bd7898 | 1886 | my %co = git_read_commit($hash); |
034df39e | 1887 | if (!%co) { |
09bd7898 | 1888 | die_error(undef, "Unknown commit object."); |
d63577da | 1889 | } |
bddec01d KS |
1890 | if (!defined $hash_parent) { |
1891 | $hash_parent = $co{'parent'}; | |
1892 | } | |
19806691 | 1893 | open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed."); |
4c02e3c5 | 1894 | my (@difftree) = map { chomp; $_ } <$fd>; |
19806691 | 1895 | close $fd or die_error(undef, "Reading diff-tree failed."); |
161332a5 | 1896 | |
11044297 KS |
1897 | # non-textual hash id's can be cached |
1898 | my $expires; | |
1899 | if ($hash =~ m/^[0-9a-fA-F]{40}$/) { | |
1900 | $expires = "+1d"; | |
1901 | } | |
1902 | git_header_html(undef, $expires); | |
42f7eb94 | 1903 | print "<div class=\"page_nav\">\n" . |
232ff553 KS |
1904 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") . |
1905 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash")}, "shortlog") . | |
1906 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") . | |
1907 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") . | |
19806691 | 1908 | " | commitdiff" . |
232ff553 KS |
1909 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "<br/>\n"; |
1910 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain") . "\n" . | |
19806691 | 1911 | "</div>\n"; |
9cd3d988 | 1912 | print "<div>\n" . |
232ff553 | 1913 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" . |
9cd3d988 | 1914 | "</div>\n"; |
c07ad4b9 | 1915 | print "<div class=\"page_body\">\n"; |
0db37973 KS |
1916 | my $comment = $co{'comment'}; |
1917 | my $empty = 0; | |
1918 | my $signed = 0; | |
fa378499 | 1919 | my @log = @$comment; |
a4d26ef0 | 1920 | # remove first and empty lines after that |
fa378499 | 1921 | shift @log; |
a4d26ef0 KS |
1922 | while (defined $log[0] && $log[0] eq "") { |
1923 | shift @log; | |
1924 | } | |
fa378499 | 1925 | foreach my $line (@log) { |
10dba28d | 1926 | if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) { |
0db37973 KS |
1927 | next; |
1928 | } | |
1929 | if ($line eq "") { | |
1930 | if ($empty) { | |
1931 | next; | |
1932 | } | |
1933 | $empty = 1; | |
1934 | } else { | |
1935 | $empty = 0; | |
1936 | } | |
f49201a9 | 1937 | print format_log_line_html($line) . "<br/>\n"; |
0db37973 KS |
1938 | } |
1939 | print "<br/>\n"; | |
4c02e3c5 | 1940 | foreach my $line (@difftree) { |
19806691 KS |
1941 | # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c' |
1942 | # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c' | |
1943 | $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/; | |
1944 | my $from_mode = $1; | |
1945 | my $to_mode = $2; | |
1946 | my $from_id = $3; | |
1947 | my $to_id = $4; | |
1948 | my $status = $5; | |
232ff553 | 1949 | my $file = validate_input(unquote($6)); |
f6375b24 | 1950 | if ($status eq "A") { |
19806691 | 1951 | print "<div class=\"diff_info\">" . file_type($to_mode) . ":" . |
232ff553 | 1952 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" . |
19806691 KS |
1953 | "</div>\n"; |
1954 | git_diff_print(undef, "/dev/null", $to_id, "b/$file"); | |
1955 | } elsif ($status eq "D") { | |
1956 | print "<div class=\"diff_info\">" . file_type($from_mode) . ":" . | |
232ff553 | 1957 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" . |
19806691 KS |
1958 | "</div>\n"; |
1959 | git_diff_print($from_id, "a/$file", undef, "/dev/null"); | |
1960 | } elsif ($status eq "M") { | |
1961 | if ($from_id ne $to_id) { | |
1962 | print "<div class=\"diff_info\">" . | |
232ff553 | 1963 | file_type($from_mode) . ":" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . |
19806691 | 1964 | " -> " . |
232ff553 | 1965 | file_type($to_mode) . ":" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id); |
19806691 KS |
1966 | print "</div>\n"; |
1967 | git_diff_print($from_id, "a/$file", $to_id, "b/$file"); | |
4c02e3c5 KS |
1968 | } |
1969 | } | |
161332a5 | 1970 | } |
c07ad4b9 KS |
1971 | print "<br/>\n" . |
1972 | "</div>"; | |
12a88f2f | 1973 | git_footer_html(); |
09bd7898 KS |
1974 | } |
1975 | ||
19806691 KS |
1976 | sub git_commitdiff_plain { |
1977 | mkdir($git_temp, 0700); | |
1978 | open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed."); | |
1979 | my (@difftree) = map { chomp; $_ } <$fd>; | |
1980 | close $fd or die_error(undef, "Reading diff-tree failed."); | |
1981 | ||
1b1cd421 KS |
1982 | # try to figure out the next tag after this commit |
1983 | my $tagname; | |
1984 | my %taghash; | |
1985 | my $tags = git_read_refs("refs/tags"); | |
1986 | foreach my $entry (@$tags) { | |
1987 | my %tag = %$entry; | |
d8a20ba9 | 1988 | $taghash{$tag{'refid'}} = $tag{'name'}; |
1b1cd421 KS |
1989 | } |
1990 | open $fd, "-|", "$gitbin/git-rev-list HEAD"; | |
1991 | while (my $commit = <$fd>) { | |
1992 | chomp $commit; | |
1993 | if ($taghash{$commit}) { | |
1994 | $tagname = $taghash{$commit}; | |
1995 | } | |
1996 | if ($commit eq $hash) { | |
1997 | last; | |
1998 | } | |
1999 | } | |
2000 | close $fd; | |
2001 | ||
9312944d | 2002 | print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\""); |
c994d620 KS |
2003 | my %co = git_read_commit($hash); |
2004 | my %ad = date_str($co{'author_epoch'}, $co{'author_tz'}); | |
c994d620 | 2005 | my $comment = $co{'comment'}; |
1b1cd421 | 2006 | print "From: $co{'author'}\n" . |
c994d620 | 2007 | "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n". |
1b1cd421 KS |
2008 | "Subject: $co{'title'}\n"; |
2009 | if (defined $tagname) { | |
2010 | print "X-Git-Tag: $tagname\n"; | |
2011 | } | |
2012 | print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" . | |
c994d620 | 2013 | "\n"; |
1b1cd421 | 2014 | |
c994d620 KS |
2015 | foreach my $line (@$comment) {; |
2016 | print " $line\n"; | |
2017 | } | |
1b1cd421 KS |
2018 | print "---\n\n"; |
2019 | ||
19806691 KS |
2020 | foreach my $line (@difftree) { |
2021 | $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/; | |
2022 | my $from_id = $3; | |
2023 | my $to_id = $4; | |
2024 | my $status = $5; | |
2025 | my $file = $6; | |
f6375b24 | 2026 | if ($status eq "A") { |
19806691 KS |
2027 | git_diff_print(undef, "/dev/null", $to_id, "b/$file", "plain"); |
2028 | } elsif ($status eq "D") { | |
2029 | git_diff_print($from_id, "a/$file", undef, "/dev/null", "plain"); | |
2030 | } elsif ($status eq "M") { | |
2031 | git_diff_print($from_id, "a/$file", $to_id, "b/$file", "plain"); | |
2032 | } | |
2033 | } | |
2034 | } | |
2035 | ||
09bd7898 | 2036 | sub git_history { |
b87d78d6 | 2037 | if (!defined $hash) { |
ede5e100 | 2038 | $hash = git_read_hash("$project/HEAD"); |
09bd7898 KS |
2039 | } |
2040 | my %co = git_read_commit($hash); | |
2041 | if (!%co) { | |
2042 | die_error(undef, "Unknown commit object."); | |
2ae100df | 2043 | } |
d51e902a | 2044 | git_header_html(); |
42f7eb94 | 2045 | print "<div class=\"page_nav\">\n" . |
232ff553 KS |
2046 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") . |
2047 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") . | |
2048 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") . | |
2049 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") . | |
2050 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") . | |
2051 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . | |
09bd7898 KS |
2052 | "<br/><br/>\n" . |
2053 | "</div>\n"; | |
d63577da | 2054 | print "<div>\n" . |
232ff553 | 2055 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" . |
820e4f6b | 2056 | "</div>\n"; |
232ff553 | 2057 | print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b><br/></div>\n"; |
10dba28d | 2058 | |
18216710 | 2059 | open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin \'$file_name\'"; |
b87d78d6 | 2060 | my $commit; |
bddec01d KS |
2061 | print "<table cellspacing=\"0\">\n"; |
2062 | my $alternate = 0; | |
b87d78d6 | 2063 | while (my $line = <$fd>) { |
d05c19ee | 2064 | if ($line =~ m/^([0-9a-fA-F]{40})/){ |
b87d78d6 KS |
2065 | $commit = $1; |
2066 | next; | |
d51e902a | 2067 | } |
19806691 | 2068 | if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) { |
09bd7898 | 2069 | my %co = git_read_commit($commit); |
b87d78d6 KS |
2070 | if (!%co) { |
2071 | next; | |
2072 | } | |
bddec01d | 2073 | if ($alternate) { |
c994d620 | 2074 | print "<tr class=\"dark\">\n"; |
bddec01d | 2075 | } else { |
c994d620 | 2076 | print "<tr class=\"light\">\n"; |
bddec01d KS |
2077 | } |
2078 | $alternate ^= 1; | |
71be1e79 | 2079 | print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . |
40c13813 | 2080 | "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" . |
232ff553 | 2081 | "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" . |
40c13813 | 2082 | esc_html(chop_str($co{'title'}, 50)) . "</b>") . "</td>\n" . |
10dba28d | 2083 | "<td class=\"link\">" . |
232ff553 KS |
2084 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") . |
2085 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") . | |
2086 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=$commit;f=$file_name")}, "blob"); | |
42f7eb94 KS |
2087 | my $blob = git_get_hash_by_path($hash, $file_name); |
2088 | my $blob_parent = git_get_hash_by_path($commit, $file_name); | |
2089 | if (defined $blob && defined $blob_parent && $blob ne $blob_parent) { | |
c994d620 | 2090 | print " | " . |
232ff553 | 2091 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")}, |
c994d620 | 2092 | "diff to current"); |
42f7eb94 | 2093 | } |
10dba28d KS |
2094 | print "</td>\n" . |
2095 | "</tr>\n"; | |
b87d78d6 | 2096 | undef $commit; |
2ae100df | 2097 | } |
d51e902a | 2098 | } |
bddec01d | 2099 | print "</table>\n"; |
b87d78d6 | 2100 | close $fd; |
d51e902a | 2101 | git_footer_html(); |
161332a5 | 2102 | } |
19806691 KS |
2103 | |
2104 | sub git_search { | |
2105 | if (!defined $searchtext) { | |
2106 | die_error("", "Text field empty."); | |
2107 | } | |
2108 | if (!defined $hash) { | |
2109 | $hash = git_read_hash("$project/HEAD"); | |
2110 | } | |
2111 | my %co = git_read_commit($hash); | |
2112 | if (!%co) { | |
2113 | die_error(undef, "Unknown commit object."); | |
2114 | } | |
c994d620 KS |
2115 | # pickaxe may take all resources of your box and run for several minutes |
2116 | # with every query - so decide by yourself how public you make this feature :) | |
2117 | my $commit_search = 1; | |
2118 | my $author_search = 0; | |
2119 | my $committer_search = 0; | |
2120 | my $pickaxe_search = 0; | |
2121 | if ($searchtext =~ s/^author\\://i) { | |
2122 | $author_search = 1; | |
2123 | } elsif ($searchtext =~ s/^committer\\://i) { | |
2124 | $committer_search = 1; | |
2125 | } elsif ($searchtext =~ s/^pickaxe\\://i) { | |
2126 | $commit_search = 0; | |
2127 | $pickaxe_search = 1; | |
2128 | } | |
19806691 KS |
2129 | git_header_html(); |
2130 | print "<div class=\"page_nav\">\n" . | |
232ff553 KS |
2131 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary;h=$hash")}, "summary") . |
2132 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") . | |
2133 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") . | |
2134 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") . | |
2135 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") . | |
2136 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . | |
19806691 KS |
2137 | "<br/><br/>\n" . |
2138 | "</div>\n"; | |
2139 | ||
2140 | print "<div>\n" . | |
232ff553 | 2141 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" . |
19806691 KS |
2142 | "</div>\n"; |
2143 | print "<table cellspacing=\"0\">\n"; | |
19806691 | 2144 | my $alternate = 0; |
c994d620 KS |
2145 | if ($commit_search) { |
2146 | $/ = "\0"; | |
25f422fb | 2147 | open my $fd, "-|", "$gitbin/git-rev-list --header --parents $hash" or next; |
c994d620 KS |
2148 | while (my $commit_text = <$fd>) { |
2149 | if (!grep m/$searchtext/i, $commit_text) { | |
2150 | next; | |
19806691 | 2151 | } |
c994d620 KS |
2152 | if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) { |
2153 | next; | |
19806691 | 2154 | } |
c994d620 | 2155 | if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) { |
19806691 KS |
2156 | next; |
2157 | } | |
c994d620 | 2158 | my @commit_lines = split "\n", $commit_text; |
25f422fb | 2159 | my %co = git_read_commit(undef, \@commit_lines); |
c994d620 KS |
2160 | if (!%co) { |
2161 | next; | |
2162 | } | |
2163 | if ($alternate) { | |
2164 | print "<tr class=\"dark\">\n"; | |
2165 | } else { | |
2166 | print "<tr class=\"light\">\n"; | |
2167 | } | |
2168 | $alternate ^= 1; | |
71be1e79 | 2169 | print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . |
40c13813 | 2170 | "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" . |
c994d620 | 2171 | "<td>" . |
232ff553 | 2172 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" . esc_html(chop_str($co{'title'}, 50)) . "</b><br/>"); |
c994d620 KS |
2173 | my $comment = $co{'comment'}; |
2174 | foreach my $line (@$comment) { | |
2175 | if ($line =~ m/^(.*)($searchtext)(.*)$/i) { | |
40c13813 | 2176 | my $lead = esc_html($1) || ""; |
c994d620 | 2177 | $lead = chop_str($lead, 30, 10); |
40c13813 KS |
2178 | my $match = esc_html($2) || ""; |
2179 | my $trail = esc_html($3) || ""; | |
c994d620 KS |
2180 | $trail = chop_str($trail, 30, 10); |
2181 | my $text = "$lead<span style=\"color:#e00000\">$match</span>$trail"; | |
2182 | print chop_str($text, 80, 5) . "<br/>\n"; | |
19806691 | 2183 | } |
c994d620 KS |
2184 | } |
2185 | print "</td>\n" . | |
2186 | "<td class=\"link\">" . | |
232ff553 KS |
2187 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}")}, "commit") . |
2188 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree"); | |
c994d620 KS |
2189 | print "</td>\n" . |
2190 | "</tr>\n"; | |
2191 | } | |
2192 | close $fd; | |
2193 | } | |
2194 | ||
2195 | if ($pickaxe_search) { | |
2196 | $/ = "\n"; | |
a9e60b7d | 2197 | open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S\'$searchtext\'"; |
c994d620 KS |
2198 | undef %co; |
2199 | my @files; | |
2200 | while (my $line = <$fd>) { | |
2201 | if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) { | |
2202 | my %set; | |
2203 | $set{'file'} = $6; | |
2204 | $set{'from_id'} = $3; | |
2205 | $set{'to_id'} = $4; | |
2206 | $set{'id'} = $set{'to_id'}; | |
2207 | if ($set{'id'} =~ m/0{40}/) { | |
2208 | $set{'id'} = $set{'from_id'}; | |
19806691 | 2209 | } |
c994d620 KS |
2210 | if ($set{'id'} =~ m/0{40}/) { |
2211 | next; | |
2212 | } | |
2213 | push @files, \%set; | |
53b89d8d | 2214 | } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){ |
c994d620 KS |
2215 | if (%co) { |
2216 | if ($alternate) { | |
2217 | print "<tr class=\"dark\">\n"; | |
2218 | } else { | |
2219 | print "<tr class=\"light\">\n"; | |
2220 | } | |
2221 | $alternate ^= 1; | |
71be1e79 | 2222 | print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . |
40c13813 | 2223 | "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" . |
c994d620 | 2224 | "<td>" . |
232ff553 | 2225 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" . |
40c13813 | 2226 | esc_html(chop_str($co{'title'}, 50)) . "</b><br/>"); |
c994d620 KS |
2227 | while (my $setref = shift @files) { |
2228 | my %set = %$setref; | |
232ff553 | 2229 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"}, |
40c13813 | 2230 | "<span style=\"color:#e00000\">" . esc_html($set{'file'}) . "</span>") . |
c994d620 KS |
2231 | "<br/>\n"; |
2232 | } | |
2233 | print "</td>\n" . | |
2234 | "<td class=\"link\">" . | |
232ff553 KS |
2235 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}")}, "commit") . |
2236 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree"); | |
c994d620 KS |
2237 | print "</td>\n" . |
2238 | "</tr>\n"; | |
2239 | } | |
2240 | %co = git_read_commit($1); | |
19806691 | 2241 | } |
19806691 | 2242 | } |
c994d620 | 2243 | close $fd; |
19806691 KS |
2244 | } |
2245 | print "</table>\n"; | |
19806691 KS |
2246 | git_footer_html(); |
2247 | } | |
2248 | ||
2249 | sub git_shortlog { | |
2250 | my $head = git_read_hash("$project/HEAD"); | |
2251 | if (!defined $hash) { | |
2252 | $hash = $head; | |
2253 | } | |
ea4a6df4 KS |
2254 | if (!defined $page) { |
2255 | $page = 0; | |
2256 | } | |
19806691 KS |
2257 | git_header_html(); |
2258 | print "<div class=\"page_nav\">\n" . | |
232ff553 | 2259 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") . |
19806691 | 2260 | " | shortlog" . |
232ff553 KS |
2261 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") . |
2262 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") . | |
2263 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") . | |
2264 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n"; | |
ea4a6df4 KS |
2265 | |
2266 | my $limit = sprintf("--max-count=%i", (100 * ($page+1))); | |
19806691 KS |
2267 | open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed."); |
2268 | my (@revlist) = map { chomp; $_ } <$fd>; | |
2269 | close $fd; | |
ea4a6df4 KS |
2270 | |
2271 | if ($hash ne $head || $page) { | |
232ff553 | 2272 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "HEAD"); |
ea4a6df4 KS |
2273 | } else { |
2274 | print "HEAD"; | |
2275 | } | |
2276 | if ($page > 0) { | |
c994d620 | 2277 | print " ⋅ " . |
232ff553 | 2278 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page-1)), -accesskey => "p", -title => "Alt-p"}, "prev"); |
ea4a6df4 KS |
2279 | } else { |
2280 | print " ⋅ prev"; | |
2281 | } | |
2282 | if ($#revlist >= (100 * ($page+1)-1)) { | |
c994d620 | 2283 | print " ⋅ " . |
232ff553 | 2284 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -accesskey => "n", -title => "Alt-n"}, "next"); |
ea4a6df4 KS |
2285 | } else { |
2286 | print " ⋅ next"; | |
2287 | } | |
2288 | print "<br/>\n" . | |
2289 | "</div>\n"; | |
19806691 | 2290 | print "<div>\n" . |
232ff553 | 2291 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") . |
19806691 KS |
2292 | "</div>\n"; |
2293 | print "<table cellspacing=\"0\">\n"; | |
19806691 | 2294 | my $alternate = 0; |
ea4a6df4 KS |
2295 | for (my $i = ($page * 100); $i <= $#revlist; $i++) { |
2296 | my $commit = $revlist[$i]; | |
19806691 KS |
2297 | my %co = git_read_commit($commit); |
2298 | my %ad = date_str($co{'author_epoch'}); | |
2299 | if ($alternate) { | |
c994d620 | 2300 | print "<tr class=\"dark\">\n"; |
19806691 | 2301 | } else { |
c994d620 | 2302 | print "<tr class=\"light\">\n"; |
19806691 KS |
2303 | } |
2304 | $alternate ^= 1; | |
71be1e79 | 2305 | print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . |
40c13813 | 2306 | "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" . |
c24fd7b7 KS |
2307 | "<td>"; |
2308 | if (length($co{'title_short'}) < length($co{'title'})) { | |
232ff553 | 2309 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list", -title => "$co{'title'}"}, |
40c13813 | 2310 | "<b>" . esc_html($co{'title_short'}) . "</b>"); |
c24fd7b7 | 2311 | } else { |
232ff553 | 2312 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"}, |
40c13813 | 2313 | "<b>" . esc_html($co{'title_short'}) . "</b>"); |
c24fd7b7 KS |
2314 | } |
2315 | print "</td>\n" . | |
19806691 | 2316 | "<td class=\"link\">" . |
232ff553 KS |
2317 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") . |
2318 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") . | |
19806691 KS |
2319 | "</td>\n" . |
2320 | "</tr>"; | |
2321 | } | |
c994d620 KS |
2322 | if ($#revlist >= (100 * ($page+1)-1)) { |
2323 | print "<tr>\n" . | |
2324 | "<td>" . | |
232ff553 | 2325 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -title => "Alt-n"}, "next") . |
c994d620 KS |
2326 | "</td>\n" . |
2327 | "</tr>\n"; | |
2328 | } | |
19806691 KS |
2329 | print "</table\n>"; |
2330 | git_footer_html(); | |
2331 | } |