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