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