]>
Commit | Line | Data |
---|---|---|
161332a5 KS |
1 | #!/usr/bin/perl |
2 | ||
c994d620 | 3 | # gitweb - simple web interface to track changes in git repositories |
22fafb99 | 4 | # |
00cd0794 KS |
5 | # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org> |
6 | # (C) 2005, Christian Gierke | |
823d5dc8 | 7 | # |
d8f1c5c2 | 8 | # This program is licensed under the GPLv2 |
161332a5 KS |
9 | |
10 | use strict; | |
11 | use warnings; | |
19806691 | 12 | use CGI qw(:standard :escapeHTML -nosticky); |
7403d50b | 13 | use CGI::Util qw(unescape); |
161332a5 | 14 | use CGI::Carp qw(fatalsToBrowser); |
40c13813 | 15 | use Encode; |
b87d78d6 | 16 | use Fcntl ':mode'; |
7a13b999 | 17 | use File::Find qw(); |
10bb9036 | 18 | binmode STDOUT, ':utf8'; |
161332a5 | 19 | |
4a87b43e | 20 | our $cgi = new CGI; |
06c084d2 | 21 | our $version = "++GIT_VERSION++"; |
4a87b43e DS |
22 | our $my_url = $cgi->url(); |
23 | our $my_uri = $cgi->url(-absolute => 1); | |
3e029299 | 24 | |
e130ddaa AT |
25 | # core git executable to use |
26 | # this can just be "git" if your webserver has a sensible PATH | |
06c084d2 | 27 | our $GIT = "++GIT_BINDIR++/git"; |
3f7f2710 | 28 | |
b87d78d6 | 29 | # absolute fs-path which will be prepended to the project path |
4a87b43e | 30 | #our $projectroot = "/pub/scm"; |
06c084d2 | 31 | our $projectroot = "++GITWEB_PROJECTROOT++"; |
b87d78d6 | 32 | |
b87d78d6 | 33 | # location for temporary files needed for diffs |
4a87b43e | 34 | our $git_temp = "/tmp/gitweb"; |
034df39e | 35 | |
b87d78d6 | 36 | # target of the home link on top of all pages |
4a87b43e | 37 | our $home_link = $my_uri; |
b87d78d6 | 38 | |
2de21fac YS |
39 | # string of the home link on top of all pages |
40 | our $home_link_str = "++GITWEB_HOME_LINK_STR++"; | |
41 | ||
49da1daf AT |
42 | # name of your site or organization to appear in page titles |
43 | # replace this with something more descriptive for clearer bookmarks | |
06c084d2 | 44 | our $site_name = "++GITWEB_SITENAME++" || $ENV{'SERVER_NAME'} || "Untitled"; |
49da1daf | 45 | |
8ab1da2c | 46 | # html text to include at home page |
06c084d2 | 47 | our $home_text = "++GITWEB_HOMETEXT++"; |
8ab1da2c | 48 | |
aedd9425 | 49 | # URI of default stylesheet |
06c084d2 | 50 | our $stylesheet = "++GITWEB_CSS++"; |
281f2f6b | 51 | # URI of GIT logo |
06c084d2 | 52 | our $logo = "++GITWEB_LOGO++"; |
aedd9425 | 53 | |
09bd7898 | 54 | # source of projects list |
06c084d2 | 55 | our $projects_list = "++GITWEB_LIST++"; |
b87d78d6 | 56 | |
f5aa79d9 | 57 | # default blob_plain mimetype and default charset for text/plain blob |
4a87b43e DS |
58 | our $default_blob_plain_mimetype = 'text/plain'; |
59 | our $default_text_plain_charset = undef; | |
f5aa79d9 | 60 | |
2d007374 PB |
61 | # file to use for guessing MIME types before trying /etc/mime.types |
62 | # (relative to the current git repository) | |
4a87b43e | 63 | our $mimetypes_file = undef; |
2d007374 | 64 | |
06c084d2 | 65 | our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++"; |
c8d138a8 JK |
66 | require $GITWEB_CONFIG if -e $GITWEB_CONFIG; |
67 | ||
68 | # version of the core git binary | |
69 | our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown"; | |
70 | ||
71 | $projects_list ||= $projectroot; | |
72 | if (! -d $git_temp) { | |
cfd82669 | 73 | mkdir($git_temp, 0700) || die_error(undef, "Couldn't mkdir $git_temp"); |
c8d138a8 JK |
74 | } |
75 | ||
154b4d78 | 76 | # ====================================================================== |
09bd7898 | 77 | # input validation and dispatch |
4a87b43e | 78 | our $action = $cgi->param('a'); |
09bd7898 | 79 | if (defined $action) { |
c91da262 | 80 | if ($action =~ m/[^0-9a-zA-Z\.\-_]/) { |
cac4bd94 | 81 | die_error(undef, "Invalid action parameter"); |
b87d78d6 | 82 | } |
154b4d78 | 83 | # action which does not check rest of parameters |
281f2f6b | 84 | if ($action eq "opml") { |
c994d620 KS |
85 | git_opml(); |
86 | exit; | |
09bd7898 | 87 | } |
b87d78d6 | 88 | } |
44ad2978 | 89 | |
4a87b43e | 90 | our $project = ($cgi->param('p') || $ENV{'PATH_INFO'}); |
dd04c428 ML |
91 | if (defined $project) { |
92 | $project =~ s|^/||; | |
93 | $project =~ s|/$||; | |
94 | } | |
668e34d7 | 95 | if (defined $project && $project) { |
dbd954a8 | 96 | if (!validate_input($project)) { |
cac4bd94 | 97 | die_error(undef, "Invalid project parameter"); |
9cd3d988 KS |
98 | } |
99 | if (!(-d "$projectroot/$project")) { | |
cac4bd94 | 100 | die_error(undef, "No such directory"); |
b87d78d6 KS |
101 | } |
102 | if (!(-e "$projectroot/$project/HEAD")) { | |
cac4bd94 | 103 | die_error(undef, "No such project"); |
9cd3d988 | 104 | } |
4fac5294 | 105 | $ENV{'GIT_DIR'} = "$projectroot/$project"; |
09bd7898 | 106 | } else { |
ede5e100 | 107 | git_project_list(); |
09bd7898 | 108 | exit; |
a59d4afd | 109 | } |
6191f8e1 | 110 | |
4a87b43e | 111 | our $file_name = $cgi->param('f'); |
b87d78d6 | 112 | if (defined $file_name) { |
dbd954a8 | 113 | if (!validate_input($file_name)) { |
cac4bd94 | 114 | die_error(undef, "Invalid file parameter"); |
b87d78d6 | 115 | } |
a59d4afd | 116 | } |
6191f8e1 | 117 | |
4a87b43e | 118 | our $hash = $cgi->param('h'); |
4fac5294 | 119 | if (defined $hash) { |
dbd954a8 | 120 | if (!validate_input($hash)) { |
cac4bd94 | 121 | die_error(undef, "Invalid hash parameter"); |
4fac5294 | 122 | } |
a59d4afd | 123 | } |
6191f8e1 | 124 | |
4a87b43e | 125 | our $hash_parent = $cgi->param('hp'); |
c91da262 | 126 | if (defined $hash_parent) { |
dbd954a8 | 127 | if (!validate_input($hash_parent)) { |
cac4bd94 | 128 | die_error(undef, "Invalid hash parent parameter"); |
c91da262 | 129 | } |
09bd7898 KS |
130 | } |
131 | ||
4a87b43e | 132 | our $hash_base = $cgi->param('hb'); |
c91da262 | 133 | if (defined $hash_base) { |
dbd954a8 | 134 | if (!validate_input($hash_base)) { |
cac4bd94 | 135 | die_error(undef, "Invalid hash base parameter"); |
c91da262 | 136 | } |
a59d4afd | 137 | } |
6191f8e1 | 138 | |
4a87b43e | 139 | our $page = $cgi->param('pg'); |
ea4a6df4 | 140 | if (defined $page) { |
c91da262 | 141 | if ($page =~ m/[^0-9]$/) { |
cac4bd94 | 142 | die_error(undef, "Invalid page parameter"); |
b87d78d6 | 143 | } |
2ad9331e | 144 | } |
823d5dc8 | 145 | |
4a87b43e | 146 | our $searchtext = $cgi->param('s'); |
19806691 KS |
147 | if (defined $searchtext) { |
148 | if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) { | |
cac4bd94 | 149 | die_error(undef, "Invalid search parameter"); |
19806691 KS |
150 | } |
151 | $searchtext = quotemeta $searchtext; | |
152 | } | |
153 | ||
717b8311 | 154 | # dispatch |
8e85cdc4 ML |
155 | my %actions = ( |
156 | "blame" => \&git_blame2, | |
157 | "blobdiff" => \&git_blobdiff, | |
158 | "blobdiff_plain" => \&git_blobdiff_plain, | |
159 | "blob" => \&git_blob, | |
160 | "blob_plain" => \&git_blob_plain, | |
161 | "commitdiff" => \&git_commitdiff, | |
162 | "commitdiff_plain" => \&git_commitdiff_plain, | |
163 | "commit" => \&git_commit, | |
164 | "heads" => \&git_heads, | |
165 | "history" => \&git_history, | |
166 | "log" => \&git_log, | |
167 | "rss" => \&git_rss, | |
168 | "search" => \&git_search, | |
169 | "shortlog" => \&git_shortlog, | |
170 | "summary" => \&git_summary, | |
171 | "tag" => \&git_tag, | |
172 | "tags" => \&git_tags, | |
173 | "tree" => \&git_tree, | |
174 | ); | |
175 | ||
176 | $action = 'summary' if (!defined($action)); | |
177 | if (!defined($actions{$action})) { | |
cac4bd94 | 178 | die_error(undef, "Unknown action"); |
09bd7898 | 179 | } |
8e85cdc4 ML |
180 | $actions{$action}->(); |
181 | exit; | |
09bd7898 | 182 | |
717b8311 JN |
183 | ## ====================================================================== |
184 | ## validation, quoting/unquoting and escaping | |
185 | ||
186 | sub validate_input { | |
187 | my $input = shift; | |
188 | ||
189 | if ($input =~ m/^[0-9a-fA-F]{40}$/) { | |
190 | return $input; | |
191 | } | |
192 | if ($input =~ m/(^|\/)(|\.|\.\.)($|\/)/) { | |
193 | return undef; | |
194 | } | |
195 | if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\-\+\#\~\%]/) { | |
196 | return undef; | |
197 | } | |
198 | return $input; | |
199 | } | |
200 | ||
232ff553 KS |
201 | # quote unsafe chars, but keep the slash, even when it's not |
202 | # correct, but quoted slashes look too horrible in bookmarks | |
203 | sub esc_param { | |
353347b0 | 204 | my $str = shift; |
232ff553 | 205 | $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg; |
18216710 | 206 | $str =~ s/\+/%2B/g; |
a9e60b7d | 207 | $str =~ s/ /\+/g; |
353347b0 KS |
208 | return $str; |
209 | } | |
210 | ||
232ff553 | 211 | # replace invalid utf8 character with SUBSTITUTION sequence |
40c13813 KS |
212 | sub esc_html { |
213 | my $str = shift; | |
40c13813 | 214 | $str = decode("utf8", $str, Encode::FB_DEFAULT); |
10bb9036 | 215 | $str = escapeHTML($str); |
3dc13832 | 216 | $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file) |
40c13813 KS |
217 | return $str; |
218 | } | |
219 | ||
232ff553 KS |
220 | # git may return quoted and escaped filenames |
221 | sub unquote { | |
222 | my $str = shift; | |
223 | if ($str =~ m/^"(.*)"$/) { | |
224 | $str = $1; | |
225 | $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg; | |
226 | } | |
227 | return $str; | |
228 | } | |
229 | ||
f16db173 JN |
230 | # escape tabs (convert tabs to spaces) |
231 | sub untabify { | |
232 | my $line = shift; | |
233 | ||
234 | while ((my $pos = index($line, "\t")) != -1) { | |
235 | if (my $count = (8 - ($pos % 8))) { | |
236 | my $spaces = ' ' x $count; | |
237 | $line =~ s/\t/$spaces/; | |
238 | } | |
239 | } | |
240 | ||
241 | return $line; | |
242 | } | |
243 | ||
717b8311 JN |
244 | ## ---------------------------------------------------------------------- |
245 | ## HTML aware string manipulation | |
246 | ||
247 | sub chop_str { | |
248 | my $str = shift; | |
249 | my $len = shift; | |
250 | my $add_len = shift || 10; | |
251 | ||
252 | # allow only $len chars, but don't cut a word if it would fit in $add_len | |
253 | # if it doesn't fit, cut it if it's still longer than the dots we would add | |
254 | $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/; | |
255 | my $body = $1; | |
256 | my $tail = $2; | |
257 | if (length($tail) > 4) { | |
258 | $tail = " ..."; | |
259 | $body =~ s/&[^;]*$//; # remove chopped character entities | |
260 | } | |
261 | return "$body$tail"; | |
262 | } | |
263 | ||
264 | ## ---------------------------------------------------------------------- | |
265 | ## functions returning short strings | |
266 | ||
1f1ab5f0 JN |
267 | # CSS class for given age value (in seconds) |
268 | sub age_class { | |
269 | my $age = shift; | |
270 | ||
271 | if ($age < 60*60*2) { | |
272 | return "age0"; | |
273 | } elsif ($age < 60*60*24*2) { | |
274 | return "age1"; | |
275 | } else { | |
276 | return "age2"; | |
277 | } | |
278 | } | |
279 | ||
717b8311 JN |
280 | # convert age in seconds to "nn units ago" string |
281 | sub age_string { | |
282 | my $age = shift; | |
283 | my $age_str; | |
a59d4afd | 284 | |
717b8311 JN |
285 | if ($age > 60*60*24*365*2) { |
286 | $age_str = (int $age/60/60/24/365); | |
287 | $age_str .= " years ago"; | |
288 | } elsif ($age > 60*60*24*(365/12)*2) { | |
289 | $age_str = int $age/60/60/24/(365/12); | |
290 | $age_str .= " months ago"; | |
291 | } elsif ($age > 60*60*24*7*2) { | |
292 | $age_str = int $age/60/60/24/7; | |
293 | $age_str .= " weeks ago"; | |
294 | } elsif ($age > 60*60*24*2) { | |
295 | $age_str = int $age/60/60/24; | |
296 | $age_str .= " days ago"; | |
297 | } elsif ($age > 60*60*2) { | |
298 | $age_str = int $age/60/60; | |
299 | $age_str .= " hours ago"; | |
300 | } elsif ($age > 60*2) { | |
301 | $age_str = int $age/60; | |
302 | $age_str .= " min ago"; | |
303 | } elsif ($age > 2) { | |
304 | $age_str = int $age; | |
305 | $age_str .= " sec ago"; | |
f6801d66 | 306 | } else { |
717b8311 | 307 | $age_str .= " right now"; |
4c02e3c5 | 308 | } |
717b8311 | 309 | return $age_str; |
161332a5 KS |
310 | } |
311 | ||
717b8311 JN |
312 | # convert file mode in octal to symbolic file mode string |
313 | sub mode_str { | |
314 | my $mode = oct shift; | |
315 | ||
316 | if (S_ISDIR($mode & S_IFMT)) { | |
317 | return 'drwxr-xr-x'; | |
318 | } elsif (S_ISLNK($mode)) { | |
319 | return 'lrwxrwxrwx'; | |
320 | } elsif (S_ISREG($mode)) { | |
321 | # git cares only about the executable bit | |
322 | if ($mode & S_IXUSR) { | |
323 | return '-rwxr-xr-x'; | |
324 | } else { | |
325 | return '-rw-r--r--'; | |
326 | }; | |
c994d620 | 327 | } else { |
717b8311 | 328 | return '----------'; |
ff7669a5 | 329 | } |
161332a5 KS |
330 | } |
331 | ||
717b8311 JN |
332 | # convert file mode in octal to file type string |
333 | sub file_type { | |
334 | my $mode = oct shift; | |
664f4cc5 | 335 | |
717b8311 JN |
336 | if (S_ISDIR($mode & S_IFMT)) { |
337 | return "directory"; | |
338 | } elsif (S_ISLNK($mode)) { | |
339 | return "symlink"; | |
340 | } elsif (S_ISREG($mode)) { | |
341 | return "file"; | |
342 | } else { | |
343 | return "unknown"; | |
344 | } | |
a59d4afd KS |
345 | } |
346 | ||
717b8311 JN |
347 | ## ---------------------------------------------------------------------- |
348 | ## functions returning short HTML fragments, or transforming HTML fragments | |
349 | ## which don't beling to other sections | |
b18f9bf4 | 350 | |
717b8311 JN |
351 | # format line of commit message or tag comment |
352 | sub format_log_line_html { | |
353 | my $line = shift; | |
b18f9bf4 | 354 | |
717b8311 JN |
355 | $line = esc_html($line); |
356 | $line =~ s/ / /g; | |
357 | if ($line =~ m/([0-9a-fA-F]{40})/) { | |
358 | my $hash_text = $1; | |
359 | if (git_get_type($hash_text) eq "commit") { | |
360 | my $link = $cgi->a({-class => "text", -href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_text")}, $hash_text); | |
361 | $line =~ s/$hash_text/$link/; | |
b18f9bf4 JN |
362 | } |
363 | } | |
717b8311 | 364 | return $line; |
b18f9bf4 JN |
365 | } |
366 | ||
717b8311 | 367 | # format marker of refs pointing to given object |
847e01fb | 368 | sub format_ref_marker { |
717b8311 | 369 | my ($refs, $id) = @_; |
d294e1ca | 370 | my $markers = ''; |
27fb8c40 | 371 | |
717b8311 | 372 | if (defined $refs->{$id}) { |
d294e1ca JN |
373 | foreach my $ref (@{$refs->{$id}}) { |
374 | my ($type, $name) = qw(); | |
375 | # e.g. tags/v2.6.11 or heads/next | |
376 | if ($ref =~ m!^(.*?)s?/(.*)$!) { | |
377 | $type = $1; | |
378 | $name = $2; | |
379 | } else { | |
380 | $type = "ref"; | |
381 | $name = $ref; | |
382 | } | |
383 | ||
384 | $markers .= " <span class=\"$type\">" . esc_html($name) . "</span>"; | |
385 | } | |
386 | } | |
387 | ||
388 | if ($markers) { | |
389 | return ' <span class="refs">'. $markers . '</span>'; | |
717b8311 JN |
390 | } else { |
391 | return ""; | |
392 | } | |
27fb8c40 JN |
393 | } |
394 | ||
17d07443 JN |
395 | # format, perhaps shortened and with markers, title line |
396 | sub format_subject_html { | |
397 | my ($long, $short, $query, $extra) = @_; | |
398 | $extra = '' unless defined($extra); | |
399 | ||
400 | if (length($short) < length($long)) { | |
401 | return $cgi->a({-href => "$my_uri?" . esc_param($query), | |
402 | -class => "list", -title => $long}, | |
403 | esc_html($short) . $extra); | |
404 | } else { | |
405 | return $cgi->a({-href => "$my_uri?" . esc_param($query), | |
406 | -class => "list"}, | |
407 | esc_html($long) . $extra); | |
408 | } | |
409 | } | |
410 | ||
717b8311 JN |
411 | ## ---------------------------------------------------------------------- |
412 | ## git utility subroutines, invoking git commands | |
42f7eb94 | 413 | |
717b8311 | 414 | # get HEAD ref of given project as hash |
847e01fb | 415 | sub git_get_head_hash { |
df2c37a5 JH |
416 | my $project = shift; |
417 | my $oENV = $ENV{'GIT_DIR'}; | |
418 | my $retval = undef; | |
419 | $ENV{'GIT_DIR'} = "$projectroot/$project"; | |
e130ddaa | 420 | if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") { |
df2c37a5 JH |
421 | my $head = <$fd>; |
422 | close $fd; | |
2c5c008b KS |
423 | if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) { |
424 | $retval = $1; | |
df2c37a5 JH |
425 | } |
426 | } | |
2c5c008b KS |
427 | if (defined $oENV) { |
428 | $ENV{'GIT_DIR'} = $oENV; | |
429 | } | |
df2c37a5 JH |
430 | return $retval; |
431 | } | |
432 | ||
717b8311 JN |
433 | # get type of given object |
434 | sub git_get_type { | |
435 | my $hash = shift; | |
436 | ||
437 | open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return; | |
438 | my $type = <$fd>; | |
439 | close $fd or return; | |
440 | chomp $type; | |
441 | return $type; | |
442 | } | |
443 | ||
444 | sub git_get_project_config { | |
445 | my $key = shift; | |
446 | ||
447 | return unless ($key); | |
448 | $key =~ s/^gitweb\.//; | |
449 | return if ($key =~ m/\W/); | |
450 | ||
451 | my $val = qx($GIT repo-config --get gitweb.$key); | |
452 | return ($val); | |
453 | } | |
454 | ||
455 | sub git_get_project_config_bool { | |
456 | my $val = git_get_project_config (@_); | |
457 | if ($val and $val =~ m/true|yes|on/) { | |
458 | return (1); | |
459 | } | |
460 | return; # implicit false | |
461 | } | |
462 | ||
463 | # get hash of given path at given ref | |
464 | sub git_get_hash_by_path { | |
465 | my $base = shift; | |
466 | my $path = shift || return undef; | |
467 | ||
468 | my $tree = $base; | |
469 | ||
470 | open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path | |
cac4bd94 | 471 | or die_error(undef, "Open git-ls-tree failed"); |
717b8311 JN |
472 | my $line = <$fd>; |
473 | close $fd or return undef; | |
474 | ||
475 | #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c' | |
476 | $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/; | |
477 | return $3; | |
478 | } | |
479 | ||
480 | ## ...................................................................... | |
481 | ## git utility functions, directly accessing git repository | |
482 | ||
483 | # assumes that PATH is not symref | |
847e01fb | 484 | sub git_get_hash_by_ref { |
54b0a43c | 485 | my $path = shift; |
09bd7898 | 486 | |
19806691 | 487 | open my $fd, "$projectroot/$path" or return undef; |
12a88f2f KS |
488 | my $head = <$fd>; |
489 | close $fd; | |
490 | chomp $head; | |
b87d78d6 KS |
491 | if ($head =~ m/^[0-9a-fA-F]{40}$/) { |
492 | return $head; | |
b87d78d6 KS |
493 | } |
494 | } | |
495 | ||
847e01fb | 496 | sub git_get_project_description { |
b87d78d6 | 497 | my $path = shift; |
09bd7898 | 498 | |
19806691 | 499 | open my $fd, "$projectroot/$path/description" or return undef; |
b87d78d6 KS |
500 | my $descr = <$fd>; |
501 | close $fd; | |
502 | chomp $descr; | |
503 | return $descr; | |
12a88f2f KS |
504 | } |
505 | ||
847e01fb | 506 | sub git_get_projects_list { |
717b8311 JN |
507 | my @list; |
508 | ||
509 | if (-d $projects_list) { | |
510 | # search in directory | |
511 | my $dir = $projects_list; | |
512 | opendir my ($dh), $dir or return undef; | |
513 | while (my $dir = readdir($dh)) { | |
514 | if (-e "$projectroot/$dir/HEAD") { | |
515 | my $pr = { | |
516 | path => $dir, | |
517 | }; | |
518 | push @list, $pr | |
519 | } | |
520 | } | |
521 | closedir($dh); | |
522 | } elsif (-f $projects_list) { | |
523 | # read from file(url-encoded): | |
524 | # 'git%2Fgit.git Linus+Torvalds' | |
525 | # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin' | |
526 | # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman' | |
527 | open my ($fd), $projects_list or return undef; | |
528 | while (my $line = <$fd>) { | |
529 | chomp $line; | |
530 | my ($path, $owner) = split ' ', $line; | |
531 | $path = unescape($path); | |
532 | $owner = unescape($owner); | |
533 | if (!defined $path) { | |
534 | next; | |
535 | } | |
536 | if (-e "$projectroot/$path/HEAD") { | |
537 | my $pr = { | |
538 | path => $path, | |
539 | owner => decode("utf8", $owner, Encode::FB_DEFAULT), | |
540 | }; | |
541 | push @list, $pr | |
542 | } | |
543 | } | |
544 | close $fd; | |
545 | } | |
546 | @list = sort {$a->{'path'} cmp $b->{'path'}} @list; | |
547 | return @list; | |
548 | } | |
549 | ||
1e0cf030 JN |
550 | sub git_get_project_owner { |
551 | my $project = shift; | |
552 | my $owner; | |
553 | ||
554 | return undef unless $project; | |
555 | ||
556 | # read from file (url-encoded): | |
557 | # 'git%2Fgit.git Linus+Torvalds' | |
558 | # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin' | |
559 | # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman' | |
560 | if (-f $projects_list) { | |
561 | open (my $fd , $projects_list); | |
562 | while (my $line = <$fd>) { | |
563 | chomp $line; | |
564 | my ($pr, $ow) = split ' ', $line; | |
565 | $pr = unescape($pr); | |
566 | $ow = unescape($ow); | |
567 | if ($pr eq $project) { | |
568 | $owner = decode("utf8", $ow, Encode::FB_DEFAULT); | |
569 | last; | |
570 | } | |
571 | } | |
572 | close $fd; | |
573 | } | |
574 | if (!defined $owner) { | |
575 | $owner = get_file_owner("$projectroot/$project"); | |
576 | } | |
577 | ||
578 | return $owner; | |
579 | } | |
580 | ||
847e01fb | 581 | sub git_get_references { |
717b8311 JN |
582 | my $type = shift || ""; |
583 | my %refs; | |
d294e1ca | 584 | my $fd; |
717b8311 JN |
585 | # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11 |
586 | # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{} | |
d294e1ca JN |
587 | if (-f "$projectroot/$project/info/refs") { |
588 | open $fd, "$projectroot/$project/info/refs" | |
589 | or return; | |
590 | } else { | |
591 | open $fd, "-|", $GIT, "ls-remote", "." | |
592 | or return; | |
593 | } | |
594 | ||
717b8311 JN |
595 | while (my $line = <$fd>) { |
596 | chomp $line; | |
d294e1ca | 597 | if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?[^\^]+)/) { |
717b8311 | 598 | if (defined $refs{$1}) { |
d294e1ca | 599 | push @{$refs{$1}}, $2; |
717b8311 | 600 | } else { |
d294e1ca | 601 | $refs{$1} = [ $2 ]; |
717b8311 JN |
602 | } |
603 | } | |
604 | } | |
605 | close $fd or return; | |
606 | return \%refs; | |
607 | } | |
608 | ||
609 | ## ---------------------------------------------------------------------- | |
610 | ## parse to hash functions | |
611 | ||
847e01fb | 612 | sub parse_date { |
717b8311 JN |
613 | my $epoch = shift; |
614 | my $tz = shift || "-0000"; | |
615 | ||
616 | my %date; | |
617 | my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); | |
618 | my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); | |
619 | my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch); | |
620 | $date{'hour'} = $hour; | |
621 | $date{'minute'} = $min; | |
622 | $date{'mday'} = $mday; | |
623 | $date{'day'} = $days[$wday]; | |
624 | $date{'month'} = $months[$mon]; | |
625 | $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec; | |
626 | $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min; | |
627 | ||
628 | $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/; | |
629 | my $local = $epoch + ((int $1 + ($2/60)) * 3600); | |
630 | ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local); | |
631 | $date{'hour_local'} = $hour; | |
632 | $date{'minute_local'} = $min; | |
633 | $date{'tz_local'} = $tz; | |
634 | return %date; | |
635 | } | |
636 | ||
847e01fb | 637 | sub parse_tag { |
ede5e100 KS |
638 | my $tag_id = shift; |
639 | my %tag; | |
d8a20ba9 | 640 | my @comment; |
ede5e100 | 641 | |
b9182987 | 642 | open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return; |
d8a20ba9 | 643 | $tag{'id'} = $tag_id; |
ede5e100 KS |
644 | while (my $line = <$fd>) { |
645 | chomp $line; | |
646 | if ($line =~ m/^object ([0-9a-fA-F]{40})$/) { | |
647 | $tag{'object'} = $1; | |
7ab0d2b6 | 648 | } elsif ($line =~ m/^type (.+)$/) { |
ede5e100 | 649 | $tag{'type'} = $1; |
7ab0d2b6 | 650 | } elsif ($line =~ m/^tag (.+)$/) { |
ede5e100 | 651 | $tag{'name'} = $1; |
d8a20ba9 KS |
652 | } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) { |
653 | $tag{'author'} = $1; | |
654 | $tag{'epoch'} = $2; | |
655 | $tag{'tz'} = $3; | |
656 | } elsif ($line =~ m/--BEGIN/) { | |
657 | push @comment, $line; | |
658 | last; | |
659 | } elsif ($line eq "") { | |
660 | last; | |
ede5e100 KS |
661 | } |
662 | } | |
d8a20ba9 KS |
663 | push @comment, <$fd>; |
664 | $tag{'comment'} = \@comment; | |
19806691 | 665 | close $fd or return; |
ede5e100 KS |
666 | if (!defined $tag{'name'}) { |
667 | return | |
668 | }; | |
669 | return %tag | |
670 | } | |
671 | ||
847e01fb | 672 | sub parse_commit { |
19806691 KS |
673 | my $commit_id = shift; |
674 | my $commit_text = shift; | |
675 | ||
676 | my @commit_lines; | |
703ac710 | 677 | my %co; |
703ac710 | 678 | |
19806691 KS |
679 | if (defined $commit_text) { |
680 | @commit_lines = @$commit_text; | |
681 | } else { | |
25f422fb | 682 | $/ = "\0"; |
b9182987 | 683 | open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id or return; |
25f422fb | 684 | @commit_lines = split '\n', <$fd>; |
19806691 | 685 | close $fd or return; |
25f422fb KS |
686 | $/ = "\n"; |
687 | pop @commit_lines; | |
19806691 | 688 | } |
25f422fb KS |
689 | my $header = shift @commit_lines; |
690 | if (!($header =~ m/^[0-9a-fA-F]{40}/)) { | |
691 | return; | |
692 | } | |
693 | ($co{'id'}, my @parents) = split ' ', $header; | |
694 | $co{'parents'} = \@parents; | |
695 | $co{'parent'} = $parents[0]; | |
19806691 | 696 | while (my $line = shift @commit_lines) { |
b87d78d6 | 697 | last if $line eq "\n"; |
7ab0d2b6 | 698 | if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) { |
703ac710 | 699 | $co{'tree'} = $1; |
022be3d0 | 700 | } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) { |
3f714537 | 701 | $co{'author'} = $1; |
185f09e5 KS |
702 | $co{'author_epoch'} = $2; |
703 | $co{'author_tz'} = $3; | |
2bf7a52c KS |
704 | if ($co{'author'} =~ m/^([^<]+) </) { |
705 | $co{'author_name'} = $1; | |
706 | } else { | |
707 | $co{'author_name'} = $co{'author'}; | |
708 | } | |
86eed32d KS |
709 | } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) { |
710 | $co{'committer'} = $1; | |
185f09e5 KS |
711 | $co{'committer_epoch'} = $2; |
712 | $co{'committer_tz'} = $3; | |
991910a9 KS |
713 | $co{'committer_name'} = $co{'committer'}; |
714 | $co{'committer_name'} =~ s/ <.*//; | |
703ac710 KS |
715 | } |
716 | } | |
ede5e100 | 717 | if (!defined $co{'tree'}) { |
25f422fb | 718 | return; |
ede5e100 | 719 | }; |
25f422fb | 720 | |
19806691 | 721 | foreach my $title (@commit_lines) { |
c2488d06 | 722 | $title =~ s/^ //; |
19806691 | 723 | if ($title ne "") { |
48c771f4 | 724 | $co{'title'} = chop_str($title, 80, 5); |
19806691 KS |
725 | # remove leading stuff of merges to make the interesting part visible |
726 | if (length($title) > 50) { | |
727 | $title =~ s/^Automatic //; | |
728 | $title =~ s/^merge (of|with) /Merge ... /i; | |
729 | if (length($title) > 50) { | |
730 | $title =~ s/(http|rsync):\/\///; | |
731 | } | |
732 | if (length($title) > 50) { | |
733 | $title =~ s/(master|www|rsync)\.//; | |
734 | } | |
735 | if (length($title) > 50) { | |
736 | $title =~ s/kernel.org:?//; | |
737 | } | |
738 | if (length($title) > 50) { | |
739 | $title =~ s/\/pub\/scm//; | |
740 | } | |
741 | } | |
48c771f4 | 742 | $co{'title_short'} = chop_str($title, 50, 5); |
19806691 KS |
743 | last; |
744 | } | |
745 | } | |
25f422fb KS |
746 | # remove added spaces |
747 | foreach my $line (@commit_lines) { | |
748 | $line =~ s/^ //; | |
749 | } | |
750 | $co{'comment'} = \@commit_lines; | |
2ae100df KS |
751 | |
752 | my $age = time - $co{'committer_epoch'}; | |
753 | $co{'age'} = $age; | |
d263a6bd | 754 | $co{'age_string'} = age_string($age); |
71be1e79 KS |
755 | my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'}); |
756 | if ($age > 60*60*24*7*2) { | |
1b1cd421 | 757 | $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday; |
71be1e79 KS |
758 | $co{'age_string_age'} = $co{'age_string'}; |
759 | } else { | |
760 | $co{'age_string_date'} = $co{'age_string'}; | |
1b1cd421 | 761 | $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday; |
71be1e79 | 762 | } |
703ac710 KS |
763 | return %co; |
764 | } | |
765 | ||
a446d6bb JN |
766 | # parse ref from ref_file, given by ref_id, with given type |
767 | sub parse_ref { | |
768 | my $ref_file = shift; | |
769 | my $ref_id = shift; | |
770 | my $type = shift || git_get_type($ref_id); | |
771 | my %ref_item; | |
772 | ||
773 | $ref_item{'type'} = $type; | |
774 | $ref_item{'id'} = $ref_id; | |
775 | $ref_item{'epoch'} = 0; | |
776 | $ref_item{'age'} = "unknown"; | |
777 | if ($type eq "tag") { | |
778 | my %tag = parse_tag($ref_id); | |
779 | $ref_item{'comment'} = $tag{'comment'}; | |
780 | if ($tag{'type'} eq "commit") { | |
781 | my %co = parse_commit($tag{'object'}); | |
782 | $ref_item{'epoch'} = $co{'committer_epoch'}; | |
783 | $ref_item{'age'} = $co{'age_string'}; | |
784 | } elsif (defined($tag{'epoch'})) { | |
785 | my $age = time - $tag{'epoch'}; | |
786 | $ref_item{'epoch'} = $tag{'epoch'}; | |
787 | $ref_item{'age'} = age_string($age); | |
788 | } | |
789 | $ref_item{'reftype'} = $tag{'type'}; | |
790 | $ref_item{'name'} = $tag{'name'}; | |
791 | $ref_item{'refid'} = $tag{'object'}; | |
792 | } elsif ($type eq "commit"){ | |
793 | my %co = parse_commit($ref_id); | |
794 | $ref_item{'reftype'} = "commit"; | |
795 | $ref_item{'name'} = $ref_file; | |
796 | $ref_item{'title'} = $co{'title'}; | |
797 | $ref_item{'refid'} = $ref_id; | |
798 | $ref_item{'epoch'} = $co{'committer_epoch'}; | |
799 | $ref_item{'age'} = $co{'age_string'}; | |
800 | } else { | |
801 | $ref_item{'reftype'} = $type; | |
802 | $ref_item{'name'} = $ref_file; | |
803 | $ref_item{'refid'} = $ref_id; | |
804 | } | |
805 | ||
806 | return %ref_item; | |
807 | } | |
808 | ||
717b8311 JN |
809 | ## ...................................................................... |
810 | ## parse to array of hashes functions | |
4c02e3c5 | 811 | |
847e01fb | 812 | sub git_get_refs_list { |
717b8311 JN |
813 | my $ref_dir = shift; |
814 | my @reflist; | |
4c02e3c5 | 815 | |
717b8311 | 816 | my @refs; |
7a13b999 JH |
817 | my $pfxlen = length("$projectroot/$project/$ref_dir"); |
818 | File::Find::find(sub { | |
819 | return if (/^\./); | |
820 | if (-f $_) { | |
821 | push @refs, substr($File::Find::name, $pfxlen + 1); | |
717b8311 | 822 | } |
7a13b999 JH |
823 | }, "$projectroot/$project/$ref_dir"); |
824 | ||
717b8311 | 825 | foreach my $ref_file (@refs) { |
847e01fb | 826 | my $ref_id = git_get_hash_by_ref("$project/$ref_dir/$ref_file"); |
717b8311 | 827 | my $type = git_get_type($ref_id) || next; |
a446d6bb | 828 | my %ref_item = parse_ref($ref_file, $ref_id, $type); |
991910a9 | 829 | |
717b8311 JN |
830 | push @reflist, \%ref_item; |
831 | } | |
a446d6bb | 832 | # sort refs by age |
717b8311 JN |
833 | @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist; |
834 | return \@reflist; | |
86eed32d KS |
835 | } |
836 | ||
717b8311 JN |
837 | ## ---------------------------------------------------------------------- |
838 | ## filesystem-related functions | |
022be3d0 | 839 | |
c07ad4b9 KS |
840 | sub get_file_owner { |
841 | my $path = shift; | |
842 | ||
843 | my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path); | |
844 | my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid); | |
845 | if (!defined $gcos) { | |
846 | return undef; | |
847 | } | |
848 | my $owner = $gcos; | |
849 | $owner =~ s/[,;].*$//; | |
281bf0cf | 850 | return decode("utf8", $owner, Encode::FB_DEFAULT); |
c07ad4b9 KS |
851 | } |
852 | ||
717b8311 JN |
853 | ## ...................................................................... |
854 | ## mimetype related functions | |
09bd7898 | 855 | |
717b8311 JN |
856 | sub mimetype_guess_file { |
857 | my $filename = shift; | |
858 | my $mimemap = shift; | |
859 | -r $mimemap or return undef; | |
860 | ||
861 | my %mimemap; | |
862 | open(MIME, $mimemap) or return undef; | |
863 | while (<MIME>) { | |
618918e5 | 864 | next if m/^#/; # skip comments |
717b8311 | 865 | my ($mime, $exts) = split(/\t+/); |
46b059d7 JH |
866 | if (defined $exts) { |
867 | my @exts = split(/\s+/, $exts); | |
868 | foreach my $ext (@exts) { | |
869 | $mimemap{$ext} = $mime; | |
870 | } | |
09bd7898 | 871 | } |
09bd7898 | 872 | } |
717b8311 | 873 | close(MIME); |
09bd7898 | 874 | |
717b8311 JN |
875 | $filename =~ /\.(.*?)$/; |
876 | return $mimemap{$1}; | |
877 | } | |
5996ca08 | 878 | |
717b8311 JN |
879 | sub mimetype_guess { |
880 | my $filename = shift; | |
881 | my $mime; | |
882 | $filename =~ /\./ or return undef; | |
5996ca08 | 883 | |
717b8311 JN |
884 | if ($mimetypes_file) { |
885 | my $file = $mimetypes_file; | |
d5aa50de JN |
886 | if ($file !~ m!^/!) { # if it is relative path |
887 | # it is relative to project | |
888 | $file = "$projectroot/$project/$file"; | |
889 | } | |
717b8311 JN |
890 | $mime = mimetype_guess_file($filename, $file); |
891 | } | |
892 | $mime ||= mimetype_guess_file($filename, '/etc/mime.types'); | |
893 | return $mime; | |
5996ca08 FF |
894 | } |
895 | ||
847e01fb | 896 | sub blob_mimetype { |
717b8311 JN |
897 | my $fd = shift; |
898 | my $filename = shift; | |
5996ca08 | 899 | |
717b8311 JN |
900 | if ($filename) { |
901 | my $mime = mimetype_guess($filename); | |
902 | $mime and return $mime; | |
d8d17b5d | 903 | } |
717b8311 JN |
904 | |
905 | # just in case | |
906 | return $default_blob_plain_mimetype unless $fd; | |
907 | ||
908 | if (-T $fd) { | |
909 | return 'text/plain' . | |
910 | ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : ''); | |
911 | } elsif (! $filename) { | |
912 | return 'application/octet-stream'; | |
913 | } elsif ($filename =~ m/\.png$/i) { | |
914 | return 'image/png'; | |
915 | } elsif ($filename =~ m/\.gif$/i) { | |
916 | return 'image/gif'; | |
917 | } elsif ($filename =~ m/\.jpe?g$/i) { | |
918 | return 'image/jpeg'; | |
d8d17b5d | 919 | } else { |
717b8311 | 920 | return 'application/octet-stream'; |
f7ab660c | 921 | } |
717b8311 JN |
922 | } |
923 | ||
924 | ## ====================================================================== | |
925 | ## functions printing HTML: header, footer, error page | |
926 | ||
927 | sub git_header_html { | |
928 | my $status = shift || "200 OK"; | |
929 | my $expires = shift; | |
930 | ||
931 | my $title = "$site_name git"; | |
932 | if (defined $project) { | |
933 | $title .= " - $project"; | |
934 | if (defined $action) { | |
935 | $title .= "/$action"; | |
936 | if (defined $file_name) { | |
937 | $title .= " - $file_name"; | |
938 | if ($action eq "tree" && $file_name !~ m|/$|) { | |
939 | $title .= "/"; | |
940 | } | |
941 | } | |
942 | } | |
f7ab660c | 943 | } |
717b8311 JN |
944 | my $content_type; |
945 | # require explicit support from the UA if we are to send the page as | |
946 | # 'application/xhtml+xml', otherwise send it as plain old 'text/html'. | |
947 | # we have to do this because MSIE sometimes globs '*/*', pretending to | |
948 | # support xhtml+xml but choking when it gets what it asked for. | |
bd943f47 | 949 | if (defined $cgi->http('HTTP_ACCEPT') && $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ && $cgi->Accept('application/xhtml+xml') != 0) { |
717b8311 | 950 | $content_type = 'application/xhtml+xml'; |
f7ab660c | 951 | } else { |
717b8311 | 952 | $content_type = 'text/html'; |
f7ab660c | 953 | } |
717b8311 JN |
954 | print $cgi->header(-type=>$content_type, -charset => 'utf-8', -status=> $status, -expires => $expires); |
955 | print <<EOF; | |
956 | <?xml version="1.0" encoding="utf-8"?> | |
957 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
958 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"> | |
959 | <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke --> | |
960 | <!-- git core binaries version $git_version --> | |
961 | <head> | |
962 | <meta http-equiv="content-type" content="$content_type; charset=utf-8"/> | |
963 | <meta name="robots" content="index, nofollow"/> | |
964 | <title>$title</title> | |
965 | <link rel="stylesheet" type="text/css" href="$stylesheet"/> | |
717b8311 | 966 | EOF |
dd04c428 ML |
967 | if (defined $project) { |
968 | printf('<link rel="alternate" title="%s log" '. | |
969 | 'href="%s" type="application/rss+xml"/>'."\n", | |
970 | esc_param($project), | |
971 | esc_param("$my_uri?p=$project;a=rss")); | |
972 | } | |
10161355 | 973 | |
dd04c428 ML |
974 | print "</head>\n" . |
975 | "<body>\n" . | |
10161355 | 976 | "<div class=\"page_header\">\n" . |
717b8311 | 977 | "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" . |
281f2f6b | 978 | "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" . |
717b8311 | 979 | "</a>\n"; |
2de21fac | 980 | print $cgi->a({-href => esc_param($home_link)}, $home_link_str) . " / "; |
717b8311 JN |
981 | if (defined $project) { |
982 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, esc_html($project)); | |
983 | if (defined $action) { | |
984 | print " / $action"; | |
985 | } | |
986 | print "\n"; | |
987 | if (!defined $searchtext) { | |
988 | $searchtext = ""; | |
989 | } | |
990 | my $search_hash; | |
991 | if (defined $hash_base) { | |
992 | $search_hash = $hash_base; | |
993 | } elsif (defined $hash) { | |
994 | $search_hash = $hash; | |
bddec01d | 995 | } else { |
717b8311 | 996 | $search_hash = "HEAD"; |
bddec01d | 997 | } |
717b8311 JN |
998 | $cgi->param("a", "search"); |
999 | $cgi->param("h", $search_hash); | |
1000 | print $cgi->startform(-method => "get", -action => $my_uri) . | |
1001 | "<div class=\"search\">\n" . | |
1002 | $cgi->hidden(-name => "p") . "\n" . | |
1003 | $cgi->hidden(-name => "a") . "\n" . | |
1004 | $cgi->hidden(-name => "h") . "\n" . | |
1005 | $cgi->textfield(-name => "s", -value => $searchtext) . "\n" . | |
1006 | "</div>" . | |
1007 | $cgi->end_form() . "\n"; | |
b87d78d6 | 1008 | } |
717b8311 JN |
1009 | print "</div>\n"; |
1010 | } | |
1011 | ||
1012 | sub git_footer_html { | |
1013 | print "<div class=\"page_footer\">\n"; | |
1014 | if (defined $project) { | |
847e01fb | 1015 | my $descr = git_get_project_description($project); |
717b8311 JN |
1016 | if (defined $descr) { |
1017 | print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n"; | |
1018 | } | |
1019 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n"; | |
1020 | } else { | |
1021 | print $cgi->a({-href => "$my_uri?" . esc_param("a=opml"), -class => "rss_logo"}, "OPML") . "\n"; | |
1022 | } | |
1023 | print "</div>\n" . | |
1024 | "</body>\n" . | |
1025 | "</html>"; | |
1026 | } | |
1027 | ||
1028 | sub die_error { | |
1029 | my $status = shift || "403 Forbidden"; | |
1030 | my $error = shift || "Malformed query, file missing or permission denied"; | |
1031 | ||
1032 | git_header_html($status); | |
1033 | print "<div class=\"page_body\">\n" . | |
1034 | "<br/><br/>\n" . | |
1035 | "$status - $error\n" . | |
1036 | "<br/>\n" . | |
1037 | "</div>\n"; | |
b87d78d6 | 1038 | git_footer_html(); |
717b8311 | 1039 | exit; |
161332a5 KS |
1040 | } |
1041 | ||
717b8311 JN |
1042 | ## ---------------------------------------------------------------------- |
1043 | ## functions printing or outputting HTML: navigation | |
1044 | ||
847e01fb | 1045 | sub git_print_page_nav { |
717b8311 JN |
1046 | my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_; |
1047 | $extra = '' if !defined $extra; # pager or formats | |
1048 | ||
1049 | my @navs = qw(summary shortlog log commit commitdiff tree); | |
1050 | if ($suppress) { | |
1051 | @navs = grep { $_ ne $suppress } @navs; | |
1052 | } | |
1053 | ||
1054 | my %arg = map { $_, ''} @navs; | |
1055 | if (defined $head) { | |
1056 | for (qw(commit commitdiff)) { | |
1057 | $arg{$_} = ";h=$head"; | |
1058 | } | |
1059 | if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) { | |
1060 | for (qw(shortlog log)) { | |
1061 | $arg{$_} = ";h=$head"; | |
045e531a | 1062 | } |
6a928415 KS |
1063 | } |
1064 | } | |
717b8311 JN |
1065 | $arg{tree} .= ";h=$treehead" if defined $treehead; |
1066 | $arg{tree} .= ";hb=$treebase" if defined $treebase; | |
1067 | ||
1068 | print "<div class=\"page_nav\">\n" . | |
1069 | (join " | ", | |
1070 | map { $_ eq $current | |
1071 | ? $_ | |
1072 | : $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$_$arg{$_}")}, "$_") | |
1073 | } | |
1074 | @navs); | |
1075 | print "<br/>\n$extra<br/>\n" . | |
1076 | "</div>\n"; | |
6a928415 KS |
1077 | } |
1078 | ||
847e01fb | 1079 | sub format_paging_nav { |
717b8311 JN |
1080 | my ($action, $hash, $head, $page, $nrevs) = @_; |
1081 | my $paging_nav; | |
594e212b | 1082 | |
717b8311 JN |
1083 | |
1084 | if ($hash ne $head || $page) { | |
1085 | $paging_nav .= $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$action")}, "HEAD"); | |
594e212b | 1086 | } else { |
717b8311 JN |
1087 | $paging_nav .= "HEAD"; |
1088 | } | |
1089 | ||
1090 | if ($page > 0) { | |
1091 | $paging_nav .= " ⋅ " . | |
1092 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$action;h=$hash;pg=" . ($page-1)), | |
26298b5f | 1093 | -accesskey => "p", -title => "Alt-p"}, "prev"); |
717b8311 JN |
1094 | } else { |
1095 | $paging_nav .= " ⋅ prev"; | |
1096 | } | |
1097 | ||
1098 | if ($nrevs >= (100 * ($page+1)-1)) { | |
1099 | $paging_nav .= " ⋅ " . | |
1100 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$action;h=$hash;pg=" . ($page+1)), | |
26298b5f | 1101 | -accesskey => "n", -title => "Alt-n"}, "next"); |
717b8311 JN |
1102 | } else { |
1103 | $paging_nav .= " ⋅ next"; | |
594e212b | 1104 | } |
717b8311 JN |
1105 | |
1106 | return $paging_nav; | |
594e212b JN |
1107 | } |
1108 | ||
717b8311 JN |
1109 | ## ...................................................................... |
1110 | ## functions printing or outputting HTML: div | |
1111 | ||
847e01fb | 1112 | sub git_print_header_div { |
717b8311 JN |
1113 | my ($action, $title, $hash, $hash_base) = @_; |
1114 | my $rest = ''; | |
1115 | ||
1116 | $rest .= ";h=$hash" if $hash; | |
1117 | $rest .= ";hb=$hash_base" if $hash_base; | |
1118 | ||
1119 | print "<div class=\"header\">\n" . | |
1120 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$action$rest"), | |
1121 | -class => "title"}, $title ? $title : $action) . "\n" . | |
1122 | "</div>\n"; | |
1123 | } | |
ede5e100 | 1124 | |
717b8311 JN |
1125 | sub git_print_page_path { |
1126 | my $name = shift; | |
1127 | my $type = shift; | |
ede5e100 | 1128 | |
717b8311 JN |
1129 | if (!defined $name) { |
1130 | print "<div class=\"page_path\"><b>/</b></div>\n"; | |
5d1acf4d | 1131 | } elsif (defined $type && $type eq 'blob') { |
717b8311 JN |
1132 | print "<div class=\"page_path\"><b>" . |
1133 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;f=$file_name")}, esc_html($name)) . "</b><br/></div>\n"; | |
1134 | } else { | |
1135 | print "<div class=\"page_path\"><b>" . esc_html($name) . "</b><br/></div>\n"; | |
ede5e100 | 1136 | } |
ede5e100 KS |
1137 | } |
1138 | ||
717b8311 JN |
1139 | ## ...................................................................... |
1140 | ## functions printing large fragments of HTML | |
1141 | ||
4a4a1a53 JN |
1142 | sub git_difftree_body { |
1143 | my ($difftree, $parent) = @_; | |
1144 | ||
1145 | print "<div class=\"list_head\">\n"; | |
1146 | if ($#{$difftree} > 10) { | |
1147 | print(($#{$difftree} + 1) . " files changed:\n"); | |
1148 | } | |
1149 | print "</div>\n"; | |
1150 | ||
1151 | print "<table class=\"diff_tree\">\n"; | |
1152 | my $alternate = 0; | |
1153 | foreach my $line (@{$difftree}) { | |
1154 | # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c' | |
1155 | # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c' | |
1156 | if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) { | |
1157 | next; | |
1158 | } | |
1159 | my $from_mode = $1; | |
1160 | my $to_mode = $2; | |
1161 | my $from_id = $3; | |
1162 | my $to_id = $4; | |
1163 | my $status = $5; | |
1164 | my $similarity = $6; # score | |
1165 | my $file = validate_input(unquote($7)); | |
1166 | ||
1167 | if ($alternate) { | |
1168 | print "<tr class=\"dark\">\n"; | |
1169 | } else { | |
1170 | print "<tr class=\"light\">\n"; | |
1171 | } | |
1172 | $alternate ^= 1; | |
1173 | ||
1174 | if ($status eq "A") { # created | |
1175 | my $mode_chng = ""; | |
1176 | if (S_ISREG(oct $to_mode)) { | |
1177 | $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777); | |
1178 | } | |
1179 | print "<td>" . | |
1180 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), | |
1181 | -class => "list"}, esc_html($file)) . | |
1182 | "</td>\n" . | |
1183 | "<td><span class=\"file_status new\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" . | |
1184 | "<td class=\"link\">" . | |
1185 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . | |
1186 | "</td>\n"; | |
1187 | ||
1188 | } elsif ($status eq "D") { # deleted | |
1189 | print "<td>" . | |
1190 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$parent;f=$file"), | |
1191 | -class => "list"}, esc_html($file)) . "</td>\n" . | |
1192 | "<td><span class=\"file_status deleted\">[deleted " . file_type($from_mode). "]</span></td>\n" . | |
1193 | "<td class=\"link\">" . | |
1194 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$parent;f=$file")}, "blob") . " | " . | |
1195 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$parent;f=$file")}, "history") . | |
1196 | "</td>\n" | |
1197 | ||
1198 | } elsif ($status eq "M" || $status eq "T") { # modified, or type changed | |
1199 | my $mode_chnge = ""; | |
1200 | if ($from_mode != $to_mode) { | |
1201 | $mode_chnge = " <span class=\"file_status mode_chnge\">[changed"; | |
1202 | if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) { | |
1203 | $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode); | |
1204 | } | |
1205 | if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) { | |
1206 | if (S_ISREG($from_mode) && S_ISREG($to_mode)) { | |
1207 | $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777); | |
1208 | } elsif (S_ISREG($to_mode)) { | |
1209 | $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777); | |
1210 | } | |
1211 | } | |
1212 | $mode_chnge .= "]</span>\n"; | |
1213 | } | |
1214 | print "<td>"; | |
1215 | if ($to_id ne $from_id) { # modified | |
1216 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"), | |
1217 | -class => "list"}, esc_html($file)); | |
1218 | } else { # mode changed | |
1219 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), | |
1220 | -class => "list"}, esc_html($file)); | |
1221 | } | |
1222 | print "</td>\n" . | |
1223 | "<td>$mode_chnge</td>\n" . | |
1224 | "<td class=\"link\">" . | |
1225 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob"); | |
1226 | if ($to_id ne $from_id) { # modified | |
1227 | print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff"); | |
1228 | } | |
1229 | print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$hash;f=$file")}, "history") . "\n"; | |
1230 | print "</td>\n"; | |
1231 | ||
1232 | } elsif ($status eq "R") { # renamed | |
1233 | my ($from_file, $to_file) = split "\t", $file; | |
1234 | my $mode_chng = ""; | |
1235 | if ($from_mode != $to_mode) { | |
1236 | $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777); | |
1237 | } | |
1238 | print "<td>" . | |
1239 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file"), | |
1240 | -class => "list"}, esc_html($to_file)) . "</td>\n" . | |
1241 | "<td><span class=\"file_status moved\">[moved from " . | |
1242 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$parent;f=$from_file"), | |
1243 | -class => "list"}, esc_html($from_file)) . | |
1244 | " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" . | |
1245 | "<td class=\"link\">" . | |
1246 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob"); | |
1247 | if ($to_id ne $from_id) { | |
1248 | print " | " . | |
1249 | $cgi->a({-href => "$my_uri?" . | |
1250 | esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file;fp=$from_file")}, "diff"); | |
1251 | } | |
1252 | print "</td>\n"; | |
1253 | ||
1254 | } elsif ($status eq "C") { # copied | |
1255 | my ($from_file, $to_file) = split "\t", $file; | |
1256 | my $mode_chng = ""; | |
1257 | if ($from_mode != $to_mode) { | |
1258 | $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777); | |
1259 | } | |
1260 | print "<td>" . | |
1261 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file"), | |
1262 | -class => "list"}, esc_html($to_file)) . "</td>\n" . | |
1263 | "<td><span class=\"file_status copied\">[copied from " . | |
1264 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$parent;f=$from_file"), | |
1265 | -class => "list"}, esc_html($from_file)) . | |
1266 | " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" . | |
1267 | "<td class=\"link\">" . | |
1268 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob"); | |
1269 | if ($to_id ne $from_id) { | |
1270 | print " | " . | |
1271 | $cgi->a({-href => "$my_uri?" . | |
1272 | esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file;fp=$from_file")}, "diff"); | |
1273 | } | |
1274 | print "</td>\n"; | |
1275 | } # we should not encounter Unmerged (U) or Unknown (X) status | |
1276 | print "</tr>\n"; | |
1277 | } | |
1278 | print "</table>\n"; | |
1279 | } | |
1280 | ||
9f5dcb81 JN |
1281 | sub git_shortlog_body { |
1282 | # uses global variable $project | |
1283 | my ($revlist, $from, $to, $refs, $extra) = @_; | |
1284 | $from = 0 unless defined $from; | |
1285 | $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to); | |
1286 | ||
1287 | print "<table class=\"shortlog\" cellspacing=\"0\">\n"; | |
1288 | my $alternate = 0; | |
1289 | for (my $i = $from; $i <= $to; $i++) { | |
1290 | my $commit = $revlist->[$i]; | |
847e01fb JN |
1291 | #my $ref = defined $refs ? format_ref_marker($refs, $commit) : ''; |
1292 | my $ref = format_ref_marker($refs, $commit); | |
1293 | my %co = parse_commit($commit); | |
9f5dcb81 JN |
1294 | if ($alternate) { |
1295 | print "<tr class=\"dark\">\n"; | |
1296 | } else { | |
1297 | print "<tr class=\"light\">\n"; | |
1298 | } | |
1299 | $alternate ^= 1; | |
1300 | # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" . | |
1301 | print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . | |
1302 | "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" . | |
1303 | "<td>"; | |
17d07443 | 1304 | print format_subject_html($co{'title'}, $co{'title_short'}, "p=$project;a=commit;h=$commit", $ref); |
9f5dcb81 JN |
1305 | print "</td>\n" . |
1306 | "<td class=\"link\">" . | |
1307 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") . " | " . | |
1308 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") . | |
1309 | "</td>\n" . | |
1310 | "</tr>\n"; | |
1311 | } | |
1312 | if (defined $extra) { | |
1313 | print "<tr>\n" . | |
1314 | "<td colspan=\"4\">$extra</td>\n" . | |
1315 | "</tr>\n"; | |
1316 | } | |
1317 | print "</table>\n"; | |
1318 | } | |
1319 | ||
581860e1 JN |
1320 | sub git_history_body { |
1321 | # Warning: assumes constant type (blob or tree) during history | |
1322 | my ($fd, $refs, $hash_base, $ftype, $extra) = @_; | |
1323 | ||
1324 | print "<table class=\"history\" cellspacing=\"0\">\n"; | |
1325 | my $alternate = 0; | |
1326 | while (my $line = <$fd>) { | |
1327 | if ($line !~ m/^([0-9a-fA-F]{40})/) { | |
1328 | next; | |
1329 | } | |
1330 | ||
1331 | my $commit = $1; | |
1332 | my %co = parse_commit($commit); | |
1333 | if (!%co) { | |
1334 | next; | |
1335 | } | |
1336 | ||
1337 | my $ref = format_ref_marker($refs, $commit); | |
1338 | ||
1339 | if ($alternate) { | |
1340 | print "<tr class=\"dark\">\n"; | |
1341 | } else { | |
1342 | print "<tr class=\"light\">\n"; | |
1343 | } | |
1344 | $alternate ^= 1; | |
1345 | print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . | |
1346 | # shortlog uses chop_str($co{'author_name'}, 10) | |
1347 | "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" . | |
1348 | "<td>"; | |
1349 | # originally git_history used chop_str($co{'title'}, 50) | |
1350 | print format_subject_html($co{'title'}, $co{'title_short'}, "p=$project;a=commit;h=$commit", $ref); | |
1351 | print "</td>\n" . | |
1352 | "<td class=\"link\">" . | |
1353 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") . " | " . | |
1354 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") . " | " . | |
1355 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$ftype;hb=$commit;f=$file_name")}, $ftype); | |
1356 | ||
1357 | if ($ftype eq 'blob') { | |
1358 | my $blob_current = git_get_hash_by_path($hash_base, $file_name); | |
1359 | my $blob_parent = git_get_hash_by_path($commit, $file_name); | |
1360 | if (defined $blob_current && defined $blob_parent && | |
1361 | $blob_current ne $blob_parent) { | |
1362 | print " | " . | |
1363 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$blob_current;hp=$blob_parent;hb=$commit;f=$file_name")}, | |
1364 | "diff to current"); | |
1365 | } | |
1366 | } | |
1367 | print "</td>\n" . | |
1368 | "</tr>\n"; | |
1369 | } | |
1370 | if (defined $extra) { | |
1371 | print "<tr>\n" . | |
1372 | "<td colspan=\"4\">$extra</td>\n" . | |
1373 | "</tr>\n"; | |
1374 | } | |
1375 | print "</table>\n"; | |
1376 | } | |
1377 | ||
717b8311 JN |
1378 | sub git_tags_body { |
1379 | # uses global variable $project | |
1380 | my ($taglist, $from, $to, $extra) = @_; | |
1381 | $from = 0 unless defined $from; | |
1382 | $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to); | |
1383 | ||
1384 | print "<table class=\"tags\" cellspacing=\"0\">\n"; | |
1385 | my $alternate = 0; | |
1386 | for (my $i = $from; $i <= $to; $i++) { | |
1387 | my $entry = $taglist->[$i]; | |
1388 | my %tag = %$entry; | |
1389 | my $comment_lines = $tag{'comment'}; | |
1390 | my $comment = shift @$comment_lines; | |
1391 | my $comment_short; | |
1392 | if (defined $comment) { | |
1393 | $comment_short = chop_str($comment, 30, 5); | |
1394 | } | |
1395 | if ($alternate) { | |
1396 | print "<tr class=\"dark\">\n"; | |
1397 | } else { | |
1398 | print "<tr class=\"light\">\n"; | |
1399 | } | |
1400 | $alternate ^= 1; | |
1401 | print "<td><i>$tag{'age'}</i></td>\n" . | |
1402 | "<td>" . | |
1403 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), | |
1404 | -class => "list"}, "<b>" . esc_html($tag{'name'}) . "</b>") . | |
1405 | "</td>\n" . | |
1406 | "<td>"; | |
1407 | if (defined $comment) { | |
17d07443 | 1408 | print format_subject_html($comment, $comment_short, "p=$project;a=tag;h=$tag{'id'}"); |
717b8311 JN |
1409 | } |
1410 | print "</td>\n" . | |
1411 | "<td class=\"selflink\">"; | |
1412 | if ($tag{'type'} eq "tag") { | |
1413 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag"); | |
1414 | } else { | |
1415 | print " "; | |
1416 | } | |
1417 | print "</td>\n" . | |
1418 | "<td class=\"link\">" . " | " . | |
1419 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'}); | |
1420 | if ($tag{'reftype'} eq "commit") { | |
1421 | print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") . | |
1422 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log"); | |
1423 | } elsif ($tag{'reftype'} eq "blob") { | |
1424 | print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$tag{'refid'}")}, "raw"); | |
1425 | } | |
1426 | print "</td>\n" . | |
1427 | "</tr>"; | |
1428 | } | |
1429 | if (defined $extra) { | |
1430 | print "<tr>\n" . | |
1431 | "<td colspan=\"5\">$extra</td>\n" . | |
1432 | "</tr>\n"; | |
1433 | } | |
1434 | print "</table>\n"; | |
1435 | } | |
1436 | ||
1437 | sub git_heads_body { | |
1438 | # uses global variable $project | |
1439 | my ($taglist, $head, $from, $to, $extra) = @_; | |
1440 | $from = 0 unless defined $from; | |
1441 | $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to); | |
1442 | ||
1443 | print "<table class=\"heads\" cellspacing=\"0\">\n"; | |
1444 | my $alternate = 0; | |
1445 | for (my $i = $from; $i <= $to; $i++) { | |
1446 | my $entry = $taglist->[$i]; | |
1447 | my %tag = %$entry; | |
1448 | my $curr = $tag{'id'} eq $head; | |
1449 | if ($alternate) { | |
1450 | print "<tr class=\"dark\">\n"; | |
1451 | } else { | |
1452 | print "<tr class=\"light\">\n"; | |
1453 | } | |
1454 | $alternate ^= 1; | |
1455 | print "<td><i>$tag{'age'}</i></td>\n" . | |
1456 | ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") . | |
1457 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}"), | |
1458 | -class => "list"}, "<b>" . esc_html($tag{'name'}) . "</b>") . | |
1459 | "</td>\n" . | |
1460 | "<td class=\"link\">" . | |
1461 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") . " | " . | |
1462 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'name'}")}, "log") . | |
1463 | "</td>\n" . | |
1464 | "</tr>"; | |
1465 | } | |
1466 | if (defined $extra) { | |
1467 | print "<tr>\n" . | |
1468 | "<td colspan=\"3\">$extra</td>\n" . | |
1469 | "</tr>\n"; | |
1470 | } | |
1471 | print "</table>\n"; | |
1472 | } | |
1473 | ||
1474 | ## ---------------------------------------------------------------------- | |
1475 | ## functions printing large fragments, format as one of arguments | |
1476 | ||
1477 | sub git_diff_print { | |
1478 | my $from = shift; | |
1479 | my $from_name = shift; | |
1480 | my $to = shift; | |
1481 | my $to_name = shift; | |
1482 | my $format = shift || "html"; | |
1483 | ||
1484 | my $from_tmp = "/dev/null"; | |
1485 | my $to_tmp = "/dev/null"; | |
1486 | my $pid = $$; | |
1487 | ||
1488 | # create tmp from-file | |
1489 | if (defined $from) { | |
1490 | $from_tmp = "$git_temp/gitweb_" . $$ . "_from"; | |
1491 | open my $fd2, "> $from_tmp"; | |
1492 | open my $fd, "-|", $GIT, "cat-file", "blob", $from; | |
1493 | my @file = <$fd>; | |
1494 | print $fd2 @file; | |
1495 | close $fd2; | |
1496 | close $fd; | |
1497 | } | |
1498 | ||
1499 | # create tmp to-file | |
1500 | if (defined $to) { | |
1501 | $to_tmp = "$git_temp/gitweb_" . $$ . "_to"; | |
1502 | open my $fd2, "> $to_tmp"; | |
1503 | open my $fd, "-|", $GIT, "cat-file", "blob", $to; | |
1504 | my @file = <$fd>; | |
1505 | print $fd2 @file; | |
1506 | close $fd2; | |
1507 | close $fd; | |
1508 | } | |
1509 | ||
1510 | open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp"; | |
1511 | if ($format eq "plain") { | |
1512 | undef $/; | |
1513 | print <$fd>; | |
1514 | $/ = "\n"; | |
1515 | } else { | |
1516 | while (my $line = <$fd>) { | |
1517 | chomp $line; | |
1518 | my $char = substr($line, 0, 1); | |
1519 | my $diff_class = ""; | |
1520 | if ($char eq '+') { | |
1521 | $diff_class = " add"; | |
1522 | } elsif ($char eq "-") { | |
1523 | $diff_class = " rem"; | |
1524 | } elsif ($char eq "@") { | |
1525 | $diff_class = " chunk_header"; | |
1526 | } elsif ($char eq "\\") { | |
1527 | # skip errors | |
1528 | next; | |
1529 | } | |
f16db173 | 1530 | $line = untabify($line); |
717b8311 JN |
1531 | print "<div class=\"diff$diff_class\">" . esc_html($line) . "</div>\n"; |
1532 | } | |
1533 | } | |
1534 | close $fd; | |
1535 | ||
1536 | if (defined $from) { | |
1537 | unlink($from_tmp); | |
1538 | } | |
1539 | if (defined $to) { | |
1540 | unlink($to_tmp); | |
1541 | } | |
1542 | } | |
1543 | ||
1544 | ||
1545 | ## ====================================================================== | |
1546 | ## ====================================================================== | |
1547 | ## actions | |
1548 | ||
717b8311 | 1549 | sub git_project_list { |
6326b60c JN |
1550 | my $order = $cgi->param('o'); |
1551 | if (defined $order && $order !~ m/project|descr|owner|age/) { | |
e2860ead | 1552 | die_error(undef, "Unknown order parameter"); |
6326b60c JN |
1553 | } |
1554 | ||
847e01fb | 1555 | my @list = git_get_projects_list(); |
717b8311 JN |
1556 | my @projects; |
1557 | if (!@list) { | |
cac4bd94 | 1558 | die_error(undef, "No projects found"); |
717b8311 JN |
1559 | } |
1560 | foreach my $pr (@list) { | |
847e01fb | 1561 | my $head = git_get_head_hash($pr->{'path'}); |
717b8311 JN |
1562 | if (!defined $head) { |
1563 | next; | |
9f5dcb81 | 1564 | } |
717b8311 | 1565 | $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}"; |
847e01fb | 1566 | my %co = parse_commit($head); |
717b8311 JN |
1567 | if (!%co) { |
1568 | next; | |
9f5dcb81 | 1569 | } |
717b8311 JN |
1570 | $pr->{'commit'} = \%co; |
1571 | if (!defined $pr->{'descr'}) { | |
847e01fb | 1572 | my $descr = git_get_project_description($pr->{'path'}) || ""; |
717b8311 | 1573 | $pr->{'descr'} = chop_str($descr, 25, 5); |
9f5dcb81 | 1574 | } |
717b8311 JN |
1575 | if (!defined $pr->{'owner'}) { |
1576 | $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || ""; | |
9f5dcb81 | 1577 | } |
717b8311 | 1578 | push @projects, $pr; |
9f5dcb81 | 1579 | } |
6326b60c | 1580 | |
717b8311 JN |
1581 | git_header_html(); |
1582 | if (-f $home_text) { | |
1583 | print "<div class=\"index_include\">\n"; | |
1584 | open (my $fd, $home_text); | |
1585 | print <$fd>; | |
1586 | close $fd; | |
1587 | print "</div>\n"; | |
9f5dcb81 | 1588 | } |
717b8311 JN |
1589 | print "<table class=\"project_list\">\n" . |
1590 | "<tr>\n"; | |
6326b60c JN |
1591 | $order ||= "project"; |
1592 | if ($order eq "project") { | |
717b8311 JN |
1593 | @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects; |
1594 | print "<th>Project</th>\n"; | |
1595 | } else { | |
6326b60c JN |
1596 | print "<th>" . |
1597 | $cgi->a({-href => "$my_uri?" . esc_param("o=project"), | |
1598 | -class => "header"}, "Project") . | |
1599 | "</th>\n"; | |
717b8311 | 1600 | } |
6326b60c | 1601 | if ($order eq "descr") { |
717b8311 JN |
1602 | @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects; |
1603 | print "<th>Description</th>\n"; | |
1604 | } else { | |
6326b60c JN |
1605 | print "<th>" . |
1606 | $cgi->a({-href => "$my_uri?" . esc_param("o=descr"), | |
1607 | -class => "header"}, "Description") . | |
1608 | "</th>\n"; | |
717b8311 | 1609 | } |
6326b60c | 1610 | if ($order eq "owner") { |
717b8311 JN |
1611 | @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects; |
1612 | print "<th>Owner</th>\n"; | |
1613 | } else { | |
6326b60c JN |
1614 | print "<th>" . |
1615 | $cgi->a({-href => "$my_uri?" . esc_param("o=owner"), | |
1616 | -class => "header"}, "Owner") . | |
1617 | "</th>\n"; | |
717b8311 | 1618 | } |
6326b60c | 1619 | if ($order eq "age") { |
717b8311 JN |
1620 | @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects; |
1621 | print "<th>Last Change</th>\n"; | |
1622 | } else { | |
6326b60c JN |
1623 | print "<th>" . |
1624 | $cgi->a({-href => "$my_uri?" . esc_param("o=age"), | |
1625 | -class => "header"}, "Last Change") . | |
1626 | "</th>\n"; | |
717b8311 JN |
1627 | } |
1628 | print "<th></th>\n" . | |
1629 | "</tr>\n"; | |
9f5dcb81 | 1630 | my $alternate = 0; |
717b8311 | 1631 | foreach my $pr (@projects) { |
9f5dcb81 JN |
1632 | if ($alternate) { |
1633 | print "<tr class=\"dark\">\n"; | |
1634 | } else { | |
1635 | print "<tr class=\"light\">\n"; | |
1636 | } | |
1637 | $alternate ^= 1; | |
6326b60c JN |
1638 | print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary"), |
1639 | -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" . | |
717b8311 JN |
1640 | "<td>" . esc_html($pr->{'descr'}) . "</td>\n" . |
1641 | "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n"; | |
6326b60c JN |
1642 | print "<td class=\"". age_class($pr->{'commit'}{'age'}) . "\">" . |
1643 | $pr->{'commit'}{'age_string'} . "</td>\n" . | |
9f5dcb81 | 1644 | "<td class=\"link\">" . |
6326b60c JN |
1645 | $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary")}, "summary") . " | " . |
1646 | $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=shortlog")}, "shortlog") . " | " . | |
1647 | $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=log")}, "log") . | |
9f5dcb81 | 1648 | "</td>\n" . |
9f5dcb81 JN |
1649 | "</tr>\n"; |
1650 | } | |
1651 | print "</table>\n"; | |
717b8311 | 1652 | git_footer_html(); |
9f5dcb81 JN |
1653 | } |
1654 | ||
ede5e100 | 1655 | sub git_summary { |
847e01fb JN |
1656 | my $descr = git_get_project_description($project) || "none"; |
1657 | my $head = git_get_head_hash($project); | |
1658 | my %co = parse_commit($head); | |
1659 | my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'}); | |
ede5e100 | 1660 | |
1e0cf030 | 1661 | my $owner = git_get_project_owner($project); |
ede5e100 | 1662 | |
847e01fb | 1663 | my $refs = git_get_references(); |
ede5e100 | 1664 | git_header_html(); |
847e01fb | 1665 | git_print_page_nav('summary','', $head); |
9f5dcb81 | 1666 | |
19806691 | 1667 | print "<div class=\"title\"> </div>\n"; |
bddec01d | 1668 | print "<table cellspacing=\"0\">\n" . |
40c13813 | 1669 | "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" . |
ede5e100 KS |
1670 | "<tr><td>owner</td><td>$owner</td></tr>\n" . |
1671 | "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" . | |
bddec01d | 1672 | "</table>\n"; |
9f5dcb81 | 1673 | |
847e01fb | 1674 | open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash($project) |
cac4bd94 | 1675 | or die_error(undef, "Open git-rev-list failed"); |
0881d2d1 | 1676 | my @revlist = map { chomp; $_ } <$fd>; |
ede5e100 | 1677 | close $fd; |
847e01fb | 1678 | git_print_header_div('shortlog'); |
9f5dcb81 JN |
1679 | git_shortlog_body(\@revlist, 0, 15, $refs, |
1680 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "...")); | |
ede5e100 | 1681 | |
847e01fb | 1682 | my $taglist = git_get_refs_list("refs/tags"); |
ede5e100 | 1683 | if (defined @$taglist) { |
847e01fb | 1684 | git_print_header_div('tags'); |
9f5dcb81 JN |
1685 | git_tags_body($taglist, 0, 15, |
1686 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tags")}, "...")); | |
ede5e100 | 1687 | } |
0db37973 | 1688 | |
847e01fb | 1689 | my $headlist = git_get_refs_list("refs/heads"); |
d8f1c5c2 | 1690 | if (defined @$headlist) { |
847e01fb | 1691 | git_print_header_div('heads'); |
b77aeb24 | 1692 | git_heads_body($headlist, $head, 0, 15, |
9f5dcb81 | 1693 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=heads")}, "...")); |
0db37973 | 1694 | } |
9f5dcb81 | 1695 | |
ede5e100 KS |
1696 | git_footer_html(); |
1697 | } | |
1698 | ||
d8a20ba9 | 1699 | sub git_tag { |
847e01fb | 1700 | my $head = git_get_head_hash($project); |
d8a20ba9 | 1701 | git_header_html(); |
847e01fb JN |
1702 | git_print_page_nav('','', $head,undef,$head); |
1703 | my %tag = parse_tag($hash); | |
1704 | git_print_header_div('commit', esc_html($tag{'name'}), $hash); | |
d8a20ba9 KS |
1705 | print "<div class=\"title_text\">\n" . |
1706 | "<table cellspacing=\"0\">\n" . | |
e4669df9 KS |
1707 | "<tr>\n" . |
1708 | "<td>object</td>\n" . | |
232ff553 KS |
1709 | "<td>" . $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" . |
1710 | "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" . | |
e4669df9 | 1711 | "</tr>\n"; |
d8a20ba9 | 1712 | if (defined($tag{'author'})) { |
847e01fb | 1713 | my %ad = parse_date($tag{'epoch'}, $tag{'tz'}); |
40c13813 | 1714 | print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n"; |
d8a20ba9 KS |
1715 | print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n"; |
1716 | } | |
1717 | print "</table>\n\n" . | |
1718 | "</div>\n"; | |
1719 | print "<div class=\"page_body\">"; | |
1720 | my $comment = $tag{'comment'}; | |
1721 | foreach my $line (@$comment) { | |
40c13813 | 1722 | print esc_html($line) . "<br/>\n"; |
d8a20ba9 KS |
1723 | } |
1724 | print "</div>\n"; | |
1725 | git_footer_html(); | |
1726 | } | |
1727 | ||
1f2857ea LT |
1728 | sub git_blame2 { |
1729 | my $fd; | |
1730 | my $ftype; | |
cac4bd94 | 1731 | die_error(undef, "Permission denied") if (!git_get_project_config_bool ('blame')); |
1f2857ea | 1732 | die_error('404 Not Found', "File name not defined") if (!$file_name); |
847e01fb | 1733 | $hash_base ||= git_get_head_hash($project); |
cac4bd94 | 1734 | die_error(undef, "Couldn't find base commit") unless ($hash_base); |
847e01fb | 1735 | my %co = parse_commit($hash_base) |
1f2857ea LT |
1736 | or die_error(undef, "Reading commit failed"); |
1737 | if (!defined $hash) { | |
1738 | $hash = git_get_hash_by_path($hash_base, $file_name, "blob") | |
1739 | or die_error(undef, "Error looking up file"); | |
1740 | } | |
1741 | $ftype = git_get_type($hash); | |
1742 | if ($ftype !~ "blob") { | |
e484a2d6 | 1743 | die_error("400 Bad Request", "Object is not a blob"); |
1f2857ea LT |
1744 | } |
1745 | open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base) | |
cac4bd94 | 1746 | or die_error(undef, "Open git-blame failed"); |
1f2857ea | 1747 | git_header_html(); |
0d83ddc4 JN |
1748 | my $formats_nav = |
1749 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") . | |
1750 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;f=$file_name")}, "head"); | |
847e01fb JN |
1751 | git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav); |
1752 | git_print_header_div('commit', esc_html($co{'title'}), $hash_base); | |
1f2857ea | 1753 | git_print_page_path($file_name, $ftype); |
82f930de | 1754 | my @rev_color = (qw(light2 dark2)); |
cc1bf97e LT |
1755 | my $num_colors = scalar(@rev_color); |
1756 | my $current_color = 0; | |
1757 | my $last_rev; | |
1f2857ea | 1758 | print "<div class=\"page_body\">\n"; |
1f2857ea LT |
1759 | print "<table class=\"blame\">\n"; |
1760 | print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n"; | |
acb0f6f3 LT |
1761 | while (<$fd>) { |
1762 | /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/; | |
1763 | my $full_rev = $1; | |
1f2857ea | 1764 | my $rev = substr($full_rev, 0, 8); |
acb0f6f3 LT |
1765 | my $lineno = $2; |
1766 | my $data = $3; | |
1f2857ea | 1767 | |
cc1bf97e LT |
1768 | if (!defined $last_rev) { |
1769 | $last_rev = $full_rev; | |
1770 | } elsif ($last_rev ne $full_rev) { | |
1771 | $last_rev = $full_rev; | |
1772 | $current_color = ++$current_color % $num_colors; | |
1773 | } | |
1774 | print "<tr class=\"$rev_color[$current_color]\">\n"; | |
1f2857ea LT |
1775 | print "<td class=\"sha1\">" . |
1776 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html($rev)) . "</td>\n"; | |
1777 | print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html($lineno) . "</a></td>\n"; | |
1778 | print "<td class=\"pre\">" . esc_html($data) . "</td>\n"; | |
1779 | print "</tr>\n"; | |
1780 | } | |
1781 | print "</table>\n"; | |
1782 | print "</div>"; | |
1f2857ea LT |
1783 | close $fd or print "Reading blob failed\n"; |
1784 | git_footer_html(); | |
1785 | } | |
1786 | ||
e34ef621 FF |
1787 | sub git_blame { |
1788 | my $fd; | |
cac4bd94 JN |
1789 | die_error('403 Permission denied', "Permission denied") if (!git_get_project_config_bool ('blame')); |
1790 | die_error('404 Not Found', "File name not defined") if (!$file_name); | |
847e01fb | 1791 | $hash_base ||= git_get_head_hash($project); |
cac4bd94 | 1792 | die_error(undef, "Couldn't find base commit") unless ($hash_base); |
847e01fb | 1793 | my %co = parse_commit($hash_base) |
cac4bd94 | 1794 | or die_error(undef, "Reading commit failed"); |
e34ef621 FF |
1795 | if (!defined $hash) { |
1796 | $hash = git_get_hash_by_path($hash_base, $file_name, "blob") | |
cac4bd94 | 1797 | or die_error(undef, "Error lookup file"); |
e34ef621 | 1798 | } |
e130ddaa | 1799 | open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base) |
cac4bd94 | 1800 | or die_error(undef, "Open git-annotate failed"); |
e34ef621 | 1801 | git_header_html(); |
0d83ddc4 JN |
1802 | my $formats_nav = |
1803 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") . | |
1804 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;f=$file_name")}, "head"); | |
847e01fb JN |
1805 | git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav); |
1806 | git_print_header_div('commit', esc_html($co{'title'}), $hash_base); | |
5d1acf4d | 1807 | git_print_page_path($file_name, 'blob'); |
e34ef621 FF |
1808 | print "<div class=\"page_body\">\n"; |
1809 | print <<HTML; | |
1f1ab5f0 | 1810 | <table class="blame"> |
e34ef621 FF |
1811 | <tr> |
1812 | <th>Commit</th> | |
1813 | <th>Age</th> | |
1814 | <th>Author</th> | |
1815 | <th>Line</th> | |
1816 | <th>Data</th> | |
1817 | </tr> | |
1818 | HTML | |
1819 | my @line_class = (qw(light dark)); | |
1820 | my $line_class_len = scalar (@line_class); | |
1821 | my $line_class_num = $#line_class; | |
1822 | while (my $line = <$fd>) { | |
1823 | my $long_rev; | |
1824 | my $short_rev; | |
1825 | my $author; | |
1826 | my $time; | |
1827 | my $lineno; | |
1828 | my $data; | |
1829 | my $age; | |
1830 | my $age_str; | |
1f1ab5f0 | 1831 | my $age_class; |
e34ef621 FF |
1832 | |
1833 | chomp $line; | |
1834 | $line_class_num = ($line_class_num + 1) % $line_class_len; | |
1835 | ||
1836 | if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) { | |
1837 | $long_rev = $1; | |
1838 | $author = $2; | |
1839 | $time = $3; | |
1840 | $lineno = $4; | |
1841 | $data = $5; | |
1842 | } else { | |
1f1ab5f0 | 1843 | print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n); |
e34ef621 FF |
1844 | next; |
1845 | } | |
1846 | $short_rev = substr ($long_rev, 0, 8); | |
1847 | $age = time () - $time; | |
1848 | $age_str = age_string ($age); | |
1849 | $age_str =~ s/ / /g; | |
1f1ab5f0 | 1850 | $age_class = age_class($age); |
e34ef621 FF |
1851 | $author = esc_html ($author); |
1852 | $author =~ s/ / /g; | |
f16db173 JN |
1853 | |
1854 | $data = untabify($data); | |
717b8311 | 1855 | $data = esc_html ($data); |
2d007374 | 1856 | |
717b8311 JN |
1857 | print <<HTML; |
1858 | <tr class="$line_class[$line_class_num]"> | |
1859 | <td class="sha1"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td> | |
1860 | <td class="$age_class">$age_str</td> | |
1861 | <td>$author</td> | |
1862 | <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td> | |
1863 | <td class="pre">$data</td> | |
1864 | </tr> | |
1865 | HTML | |
1866 | } # while (my $line = <$fd>) | |
1867 | print "</table>\n\n"; | |
1868 | close $fd or print "Reading blob failed.\n"; | |
1869 | print "</div>"; | |
1870 | git_footer_html(); | |
2d007374 PB |
1871 | } |
1872 | ||
717b8311 | 1873 | sub git_tags { |
847e01fb | 1874 | my $head = git_get_head_hash($project); |
717b8311 | 1875 | git_header_html(); |
847e01fb JN |
1876 | git_print_page_nav('','', $head,undef,$head); |
1877 | git_print_header_div('summary', $project); | |
2d007374 | 1878 | |
847e01fb | 1879 | my $taglist = git_get_refs_list("refs/tags"); |
717b8311 JN |
1880 | if (defined @$taglist) { |
1881 | git_tags_body($taglist); | |
2d007374 | 1882 | } |
717b8311 | 1883 | git_footer_html(); |
2d007374 PB |
1884 | } |
1885 | ||
717b8311 | 1886 | sub git_heads { |
847e01fb | 1887 | my $head = git_get_head_hash($project); |
717b8311 | 1888 | git_header_html(); |
847e01fb JN |
1889 | git_print_page_nav('','', $head,undef,$head); |
1890 | git_print_header_div('summary', $project); | |
930cf7dd | 1891 | |
847e01fb | 1892 | my $taglist = git_get_refs_list("refs/heads"); |
717b8311 JN |
1893 | if (defined @$taglist) { |
1894 | git_heads_body($taglist, $head); | |
f5aa79d9 | 1895 | } |
717b8311 | 1896 | git_footer_html(); |
f5aa79d9 JN |
1897 | } |
1898 | ||
19806691 | 1899 | sub git_blob_plain { |
cff0771b | 1900 | if (!defined $hash) { |
5be01bc8 | 1901 | if (defined $file_name) { |
847e01fb | 1902 | my $base = $hash_base || git_get_head_hash($project); |
5be01bc8 | 1903 | $hash = git_get_hash_by_path($base, $file_name, "blob") |
cac4bd94 | 1904 | or die_error(undef, "Error lookup file"); |
5be01bc8 | 1905 | } else { |
cac4bd94 | 1906 | die_error(undef, "No file name defined"); |
5be01bc8 JN |
1907 | } |
1908 | } | |
930cf7dd | 1909 | my $type = shift; |
044bfdc8 | 1910 | open my $fd, "-|", $GIT, "cat-file", "blob", $hash |
cfd82669 | 1911 | or die_error(undef, "Couldn't cat $file_name, $hash"); |
930cf7dd | 1912 | |
847e01fb | 1913 | $type ||= blob_mimetype($fd, $file_name); |
f5aa79d9 JN |
1914 | |
1915 | # save as filename, even when no $file_name is given | |
1916 | my $save_as = "$hash"; | |
9312944d KS |
1917 | if (defined $file_name) { |
1918 | $save_as = $file_name; | |
f5aa79d9 JN |
1919 | } elsif ($type =~ m/^text\//) { |
1920 | $save_as .= '.txt'; | |
9312944d | 1921 | } |
f5aa79d9 JN |
1922 | |
1923 | print $cgi->header(-type => "$type", '-content-disposition' => "inline; filename=\"$save_as\""); | |
19806691 | 1924 | undef $/; |
ad14e931 | 1925 | binmode STDOUT, ':raw'; |
19806691 | 1926 | print <$fd>; |
ad14e931 | 1927 | binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi |
19806691 KS |
1928 | $/ = "\n"; |
1929 | close $fd; | |
1930 | } | |
1931 | ||
930cf7dd | 1932 | sub git_blob { |
cff0771b | 1933 | if (!defined $hash) { |
5be01bc8 | 1934 | if (defined $file_name) { |
847e01fb | 1935 | my $base = $hash_base || git_get_head_hash($project); |
5be01bc8 | 1936 | $hash = git_get_hash_by_path($base, $file_name, "blob") |
cac4bd94 | 1937 | or die_error(undef, "Error lookup file"); |
5be01bc8 | 1938 | } else { |
cac4bd94 | 1939 | die_error(undef, "No file name defined"); |
5be01bc8 JN |
1940 | } |
1941 | } | |
930cf7dd | 1942 | my $have_blame = git_get_project_config_bool ('blame'); |
044bfdc8 | 1943 | open my $fd, "-|", $GIT, "cat-file", "blob", $hash |
cac4bd94 | 1944 | or die_error(undef, "Couldn't cat $file_name, $hash"); |
847e01fb | 1945 | my $mimetype = blob_mimetype($fd, $file_name); |
930cf7dd LT |
1946 | if ($mimetype !~ m/^text\//) { |
1947 | close $fd; | |
1948 | return git_blob_plain($mimetype); | |
1949 | } | |
1950 | git_header_html(); | |
0d83ddc4 | 1951 | my $formats_nav = ''; |
847e01fb | 1952 | if (defined $hash_base && (my %co = parse_commit($hash_base))) { |
930cf7dd LT |
1953 | if (defined $file_name) { |
1954 | if ($have_blame) { | |
0d83ddc4 | 1955 | $formats_nav .= $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | "; |
930cf7dd | 1956 | } |
0d83ddc4 JN |
1957 | $formats_nav .= |
1958 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") . | |
1959 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head"); | |
930cf7dd | 1960 | } else { |
0d83ddc4 | 1961 | $formats_nav .= $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash")}, "plain"); |
930cf7dd | 1962 | } |
847e01fb JN |
1963 | git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav); |
1964 | git_print_header_div('commit', esc_html($co{'title'}), $hash_base); | |
930cf7dd LT |
1965 | } else { |
1966 | print "<div class=\"page_nav\">\n" . | |
1967 | "<br/><br/></div>\n" . | |
1968 | "<div class=\"title\">$hash</div>\n"; | |
1969 | } | |
63433106 | 1970 | git_print_page_path($file_name, "blob"); |
930cf7dd LT |
1971 | print "<div class=\"page_body\">\n"; |
1972 | my $nr; | |
1973 | while (my $line = <$fd>) { | |
1974 | chomp $line; | |
1975 | $nr++; | |
f16db173 | 1976 | $line = untabify($line); |
930cf7dd LT |
1977 | printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html($line); |
1978 | } | |
1979 | close $fd or print "Reading blob failed.\n"; | |
1980 | print "</div>"; | |
1981 | git_footer_html(); | |
1982 | } | |
1983 | ||
09bd7898 | 1984 | sub git_tree { |
b87d78d6 | 1985 | if (!defined $hash) { |
847e01fb | 1986 | $hash = git_get_head_hash($project); |
09bd7898 | 1987 | if (defined $file_name) { |
df2c37a5 | 1988 | my $base = $hash_base || $hash; |
09bd7898 KS |
1989 | $hash = git_get_hash_by_path($base, $file_name, "tree"); |
1990 | } | |
10dba28d | 1991 | if (!defined $hash_base) { |
df2c37a5 | 1992 | $hash_base = $hash; |
10dba28d | 1993 | } |
e925f38c | 1994 | } |
232ff553 | 1995 | $/ = "\0"; |
044bfdc8 | 1996 | open my $fd, "-|", $GIT, "ls-tree", '-z', $hash |
cac4bd94 | 1997 | or die_error(undef, "Open git-ls-tree failed"); |
0881d2d1 | 1998 | my @entries = map { chomp; $_ } <$fd>; |
cac4bd94 | 1999 | close $fd or die_error(undef, "Reading tree failed"); |
232ff553 | 2000 | $/ = "\n"; |
d63577da | 2001 | |
847e01fb JN |
2002 | my $refs = git_get_references(); |
2003 | my $ref = format_ref_marker($refs, $hash_base); | |
12a88f2f | 2004 | git_header_html(); |
09bd7898 | 2005 | my $base_key = ""; |
09bd7898 | 2006 | my $base = ""; |
f9f02d01 | 2007 | my $have_blame = git_get_project_config_bool ('blame'); |
847e01fb | 2008 | if (defined $hash_base && (my %co = parse_commit($hash_base))) { |
09bd7898 | 2009 | $base_key = ";hb=$hash_base"; |
847e01fb JN |
2010 | git_print_page_nav('tree','', $hash_base); |
2011 | git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base); | |
d63577da KS |
2012 | } else { |
2013 | print "<div class=\"page_nav\">\n"; | |
2014 | print "<br/><br/></div>\n"; | |
2015 | print "<div class=\"title\">$hash</div>\n"; | |
2016 | } | |
09bd7898 | 2017 | if (defined $file_name) { |
232ff553 | 2018 | $base = esc_html("$file_name/"); |
09bd7898 | 2019 | } |
5d1acf4d | 2020 | git_print_page_path($file_name, 'tree'); |
fbb592a9 | 2021 | print "<div class=\"page_body\">\n"; |
42f7eb94 | 2022 | print "<table cellspacing=\"0\">\n"; |
bddec01d | 2023 | my $alternate = 0; |
161332a5 | 2024 | foreach my $line (@entries) { |
c068cff1 | 2025 | #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c' |
19806691 | 2026 | $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/; |
d767d59c | 2027 | my $t_mode = $1; |
161332a5 KS |
2028 | my $t_type = $2; |
2029 | my $t_hash = $3; | |
232ff553 | 2030 | my $t_name = validate_input($4); |
bddec01d | 2031 | if ($alternate) { |
c994d620 | 2032 | print "<tr class=\"dark\">\n"; |
bddec01d | 2033 | } else { |
c994d620 | 2034 | print "<tr class=\"light\">\n"; |
bddec01d KS |
2035 | } |
2036 | $alternate ^= 1; | |
1f1ab5f0 | 2037 | print "<td class=\"mode\">" . mode_str($t_mode) . "</td>\n"; |
161332a5 | 2038 | if ($t_type eq "blob") { |
10dba28d | 2039 | print "<td class=\"list\">" . |
232ff553 | 2040 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name"), -class => "list"}, esc_html($t_name)) . |
c994d620 KS |
2041 | "</td>\n" . |
2042 | "<td class=\"link\">" . | |
f9f02d01 LT |
2043 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob"); |
2044 | if ($have_blame) { | |
2045 | print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame"); | |
2046 | } | |
2047 | print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$t_hash;hb=$hash_base;f=$base$t_name")}, "history") . | |
25b7c18e | 2048 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") . |
42f7eb94 | 2049 | "</td>\n"; |
161332a5 | 2050 | } elsif ($t_type eq "tree") { |
10dba28d | 2051 | print "<td class=\"list\">" . |
232ff553 | 2052 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html($t_name)) . |
19806691 | 2053 | "</td>\n" . |
c994d620 | 2054 | "<td class=\"link\">" . |
232ff553 | 2055 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") . |
c6e1d9ed | 2056 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") . |
c994d620 | 2057 | "</td>\n"; |
161332a5 | 2058 | } |
42f7eb94 | 2059 | print "</tr>\n"; |
161332a5 | 2060 | } |
42f7eb94 KS |
2061 | print "</table>\n" . |
2062 | "</div>"; | |
12a88f2f | 2063 | git_footer_html(); |
09bd7898 KS |
2064 | } |
2065 | ||
09bd7898 | 2066 | sub git_log { |
847e01fb | 2067 | my $head = git_get_head_hash($project); |
0db37973 | 2068 | if (!defined $hash) { |
19806691 | 2069 | $hash = $head; |
0db37973 | 2070 | } |
ea4a6df4 KS |
2071 | if (!defined $page) { |
2072 | $page = 0; | |
b87d78d6 | 2073 | } |
847e01fb | 2074 | my $refs = git_get_references(); |
ea4a6df4 KS |
2075 | |
2076 | my $limit = sprintf("--max-count=%i", (100 * ($page+1))); | |
044bfdc8 | 2077 | open my $fd, "-|", $GIT, "rev-list", $limit, $hash |
cac4bd94 | 2078 | or die_error(undef, "Open git-rev-list failed"); |
0881d2d1 | 2079 | my @revlist = map { chomp; $_ } <$fd>; |
ea4a6df4 KS |
2080 | close $fd; |
2081 | ||
847e01fb | 2082 | my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#revlist); |
0d83ddc4 JN |
2083 | |
2084 | git_header_html(); | |
847e01fb | 2085 | git_print_page_nav('log','', $hash,undef,undef, $paging_nav); |
0d83ddc4 | 2086 | |
b87d78d6 | 2087 | if (!@revlist) { |
847e01fb | 2088 | my %co = parse_commit($hash); |
27fb8c40 | 2089 | |
847e01fb | 2090 | git_print_header_div('summary', $project); |
e925f38c | 2091 | print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n"; |
161332a5 | 2092 | } |
c994d620 KS |
2093 | for (my $i = ($page * 100); $i <= $#revlist; $i++) { |
2094 | my $commit = $revlist[$i]; | |
847e01fb JN |
2095 | my $ref = format_ref_marker($refs, $commit); |
2096 | my %co = parse_commit($commit); | |
b87d78d6 | 2097 | next if !%co; |
847e01fb JN |
2098 | my %ad = parse_date($co{'author_epoch'}); |
2099 | git_print_header_div('commit', | |
26298b5f JN |
2100 | "<span class=\"age\">$co{'age_string'}</span>" . |
2101 | esc_html($co{'title'}) . $ref, | |
2102 | $commit); | |
034df39e KS |
2103 | print "<div class=\"title_text\">\n" . |
2104 | "<div class=\"log_link\">\n" . | |
232ff553 KS |
2105 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") . |
2106 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") . | |
eb28240b | 2107 | "<br/>\n" . |
034df39e | 2108 | "</div>\n" . |
40c13813 | 2109 | "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" . |
034df39e KS |
2110 | "</div>\n" . |
2111 | "<div class=\"log_body\">\n"; | |
2112 | my $comment = $co{'comment'}; | |
09bd7898 | 2113 | my $empty = 0; |
034df39e | 2114 | foreach my $line (@$comment) { |
10dba28d | 2115 | if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) { |
09bd7898 KS |
2116 | next; |
2117 | } | |
2118 | if ($line eq "") { | |
2119 | if ($empty) { | |
2120 | next; | |
2121 | } | |
2122 | $empty = 1; | |
2123 | } else { | |
2124 | $empty = 0; | |
2125 | } | |
f49201a9 | 2126 | print format_log_line_html($line) . "<br/>\n"; |
034df39e | 2127 | } |
09bd7898 KS |
2128 | if (!$empty) { |
2129 | print "<br/>\n"; | |
2130 | } | |
2131 | print "</div>\n"; | |
e334d18c | 2132 | } |
034df39e | 2133 | git_footer_html(); |
09bd7898 KS |
2134 | } |
2135 | ||
2136 | sub git_commit { | |
847e01fb | 2137 | my %co = parse_commit($hash); |
034df39e | 2138 | if (!%co) { |
cac4bd94 | 2139 | die_error(undef, "Unknown commit object"); |
d63577da | 2140 | } |
847e01fb JN |
2141 | my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'}); |
2142 | my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'}); | |
161332a5 | 2143 | |
d8a20ba9 KS |
2144 | my $parent = $co{'parent'}; |
2145 | if (!defined $parent) { | |
b9182987 | 2146 | $parent = "--root"; |
6191f8e1 | 2147 | } |
b9182987 | 2148 | open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash |
cac4bd94 | 2149 | or die_error(undef, "Open git-diff-tree failed"); |
0881d2d1 | 2150 | my @difftree = map { chomp; $_ } <$fd>; |
cac4bd94 | 2151 | close $fd or die_error(undef, "Reading git-diff-tree failed"); |
11044297 KS |
2152 | |
2153 | # non-textual hash id's can be cached | |
2154 | my $expires; | |
2155 | if ($hash =~ m/^[0-9a-fA-F]{40}$/) { | |
2156 | $expires = "+1d"; | |
2157 | } | |
847e01fb JN |
2158 | my $refs = git_get_references(); |
2159 | my $ref = format_ref_marker($refs, $co{'id'}); | |
0d83ddc4 | 2160 | my $formats_nav = ''; |
4f7b34c9 LT |
2161 | if (defined $file_name && defined $co{'parent'}) { |
2162 | my $parent = $co{'parent'}; | |
0d83ddc4 | 2163 | $formats_nav .= $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;hb=$parent;f=$file_name")}, "blame"); |
4f7b34c9 | 2164 | } |
594e212b | 2165 | git_header_html(undef, $expires); |
847e01fb | 2166 | git_print_page_nav('commit', defined $co{'parent'} ? '' : 'commitdiff', |
26298b5f JN |
2167 | $hash, $co{'tree'}, $hash, |
2168 | $formats_nav); | |
4f7b34c9 | 2169 | |
b87d78d6 | 2170 | if (defined $co{'parent'}) { |
847e01fb | 2171 | git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash); |
b87d78d6 | 2172 | } else { |
847e01fb | 2173 | git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash); |
b87d78d6 | 2174 | } |
6191f8e1 | 2175 | print "<div class=\"title_text\">\n" . |
b87d78d6 | 2176 | "<table cellspacing=\"0\">\n"; |
40c13813 | 2177 | print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n". |
bddec01d KS |
2178 | "<tr>" . |
2179 | "<td></td><td> $ad{'rfc2822'}"; | |
927dcec4 | 2180 | if ($ad{'hour_local'} < 6) { |
1f1ab5f0 | 2181 | printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}); |
b87d78d6 KS |
2182 | } else { |
2183 | printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}); | |
2184 | } | |
bddec01d KS |
2185 | print "</td>" . |
2186 | "</tr>\n"; | |
40c13813 | 2187 | print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n"; |
e925f38c | 2188 | print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n"; |
1f1ab5f0 | 2189 | print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n"; |
bddec01d KS |
2190 | print "<tr>" . |
2191 | "<td>tree</td>" . | |
1f1ab5f0 | 2192 | "<td class=\"sha1\">" . |
232ff553 | 2193 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) . |
19806691 | 2194 | "</td>" . |
232ff553 | 2195 | "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . |
bddec01d KS |
2196 | "</td>" . |
2197 | "</tr>\n"; | |
8adc4bd4 | 2198 | my $parents = $co{'parents'}; |
3e029299 | 2199 | foreach my $par (@$parents) { |
bddec01d KS |
2200 | print "<tr>" . |
2201 | "<td>parent</td>" . | |
1f1ab5f0 | 2202 | "<td class=\"sha1\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" . |
bddec01d | 2203 | "<td class=\"link\">" . |
232ff553 KS |
2204 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$par")}, "commit") . |
2205 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") . | |
bddec01d KS |
2206 | "</td>" . |
2207 | "</tr>\n"; | |
3e029299 | 2208 | } |
7a9b4c5f | 2209 | print "</table>". |
b87d78d6 | 2210 | "</div>\n"; |
fbb592a9 | 2211 | print "<div class=\"page_body\">\n"; |
3e029299 | 2212 | my $comment = $co{'comment'}; |
09bd7898 KS |
2213 | my $empty = 0; |
2214 | my $signed = 0; | |
3e029299 | 2215 | foreach my $line (@$comment) { |
09bd7898 KS |
2216 | # print only one empty line |
2217 | if ($line eq "") { | |
2218 | if ($empty || $signed) { | |
2219 | next; | |
2220 | } | |
2221 | $empty = 1; | |
2222 | } else { | |
2223 | $empty = 0; | |
2224 | } | |
10dba28d | 2225 | if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) { |
09bd7898 | 2226 | $signed = 1; |
1f1ab5f0 | 2227 | print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n"; |
3e029299 | 2228 | } else { |
09bd7898 | 2229 | $signed = 0; |
f49201a9 | 2230 | print format_log_line_html($line) . "<br/>\n"; |
3e029299 KS |
2231 | } |
2232 | } | |
927dcec4 | 2233 | print "</div>\n"; |
4a4a1a53 JN |
2234 | |
2235 | git_difftree_body(\@difftree, $parent); | |
2236 | ||
12a88f2f | 2237 | git_footer_html(); |
09bd7898 KS |
2238 | } |
2239 | ||
2240 | sub git_blobdiff { | |
19806691 | 2241 | mkdir($git_temp, 0700); |
12a88f2f | 2242 | git_header_html(); |
847e01fb | 2243 | if (defined $hash_base && (my %co = parse_commit($hash_base))) { |
0d83ddc4 JN |
2244 | my $formats_nav = |
2245 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain"); | |
847e01fb JN |
2246 | git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav); |
2247 | git_print_header_div('commit', esc_html($co{'title'}), $hash_base); | |
09bd7898 KS |
2248 | } else { |
2249 | print "<div class=\"page_nav\">\n" . | |
2250 | "<br/><br/></div>\n" . | |
2251 | "<div class=\"title\">$hash vs $hash_parent</div>\n"; | |
2252 | } | |
63433106 | 2253 | git_print_page_path($file_name, "blob"); |
9cd3d988 | 2254 | print "<div class=\"page_body\">\n" . |
c07ad4b9 | 2255 | "<div class=\"diff_info\">blob:" . |
232ff553 | 2256 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) . |
2735983d | 2257 | " -> blob:" . |
232ff553 | 2258 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) . |
c07ad4b9 | 2259 | "</div>\n"; |
19806691 | 2260 | git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash); |
c07ad4b9 | 2261 | print "</div>"; |
12a88f2f | 2262 | git_footer_html(); |
09bd7898 KS |
2263 | } |
2264 | ||
19806691 KS |
2265 | sub git_blobdiff_plain { |
2266 | mkdir($git_temp, 0700); | |
2267 | print $cgi->header(-type => "text/plain", -charset => 'utf-8'); | |
2268 | git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain"); | |
2269 | } | |
2270 | ||
09bd7898 | 2271 | sub git_commitdiff { |
19806691 | 2272 | mkdir($git_temp, 0700); |
847e01fb | 2273 | my %co = parse_commit($hash); |
034df39e | 2274 | if (!%co) { |
cac4bd94 | 2275 | die_error(undef, "Unknown commit object"); |
d63577da | 2276 | } |
bddec01d | 2277 | if (!defined $hash_parent) { |
b5ff2cf9 | 2278 | $hash_parent = $co{'parent'} || '--root'; |
bddec01d | 2279 | } |
b9182987 | 2280 | open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash |
cac4bd94 | 2281 | or die_error(undef, "Open git-diff-tree failed"); |
0881d2d1 | 2282 | my @difftree = map { chomp; $_ } <$fd>; |
cac4bd94 | 2283 | close $fd or die_error(undef, "Reading git-diff-tree failed"); |
161332a5 | 2284 | |
11044297 KS |
2285 | # non-textual hash id's can be cached |
2286 | my $expires; | |
2287 | if ($hash =~ m/^[0-9a-fA-F]{40}$/) { | |
2288 | $expires = "+1d"; | |
2289 | } | |
847e01fb JN |
2290 | my $refs = git_get_references(); |
2291 | my $ref = format_ref_marker($refs, $co{'id'}); | |
0d83ddc4 JN |
2292 | my $formats_nav = |
2293 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain"); | |
594e212b | 2294 | git_header_html(undef, $expires); |
847e01fb JN |
2295 | git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav); |
2296 | git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash); | |
c07ad4b9 | 2297 | print "<div class=\"page_body\">\n"; |
0db37973 KS |
2298 | my $comment = $co{'comment'}; |
2299 | my $empty = 0; | |
2300 | my $signed = 0; | |
fa378499 | 2301 | my @log = @$comment; |
a4d26ef0 | 2302 | # remove first and empty lines after that |
fa378499 | 2303 | shift @log; |
a4d26ef0 KS |
2304 | while (defined $log[0] && $log[0] eq "") { |
2305 | shift @log; | |
2306 | } | |
fa378499 | 2307 | foreach my $line (@log) { |
10dba28d | 2308 | if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) { |
0db37973 KS |
2309 | next; |
2310 | } | |
2311 | if ($line eq "") { | |
2312 | if ($empty) { | |
2313 | next; | |
2314 | } | |
2315 | $empty = 1; | |
2316 | } else { | |
2317 | $empty = 0; | |
2318 | } | |
f49201a9 | 2319 | print format_log_line_html($line) . "<br/>\n"; |
0db37973 KS |
2320 | } |
2321 | print "<br/>\n"; | |
4c02e3c5 | 2322 | foreach my $line (@difftree) { |
19806691 KS |
2323 | # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c' |
2324 | # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c' | |
e349d21a JN |
2325 | if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) { |
2326 | next; | |
2327 | } | |
19806691 KS |
2328 | my $from_mode = $1; |
2329 | my $to_mode = $2; | |
2330 | my $from_id = $3; | |
2331 | my $to_id = $4; | |
2332 | my $status = $5; | |
232ff553 | 2333 | my $file = validate_input(unquote($6)); |
f6375b24 | 2334 | if ($status eq "A") { |
5be01bc8 | 2335 | print "<div class=\"diff_info\">" . file_type($to_mode) . ":" . |
232ff553 | 2336 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" . |
19806691 KS |
2337 | "</div>\n"; |
2338 | git_diff_print(undef, "/dev/null", $to_id, "b/$file"); | |
2339 | } elsif ($status eq "D") { | |
2340 | print "<div class=\"diff_info\">" . file_type($from_mode) . ":" . | |
d636ad97 | 2341 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash_parent;f=$file")}, $from_id) . "(deleted)" . |
19806691 KS |
2342 | "</div>\n"; |
2343 | git_diff_print($from_id, "a/$file", undef, "/dev/null"); | |
2344 | } elsif ($status eq "M") { | |
2345 | if ($from_id ne $to_id) { | |
2346 | print "<div class=\"diff_info\">" . | |
d636ad97 LT |
2347 | file_type($from_mode) . ":" . |
2348 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash_parent;f=$file")}, $from_id) . | |
19806691 | 2349 | " -> " . |
d636ad97 LT |
2350 | file_type($to_mode) . ":" . |
2351 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id); | |
19806691 KS |
2352 | print "</div>\n"; |
2353 | git_diff_print($from_id, "a/$file", $to_id, "b/$file"); | |
4c02e3c5 KS |
2354 | } |
2355 | } | |
161332a5 | 2356 | } |
c07ad4b9 KS |
2357 | print "<br/>\n" . |
2358 | "</div>"; | |
12a88f2f | 2359 | git_footer_html(); |
09bd7898 KS |
2360 | } |
2361 | ||
19806691 KS |
2362 | sub git_commitdiff_plain { |
2363 | mkdir($git_temp, 0700); | |
847e01fb | 2364 | my %co = parse_commit($hash); |
1568515d ML |
2365 | if (!%co) { |
2366 | die_error(undef, "Unknown commit object"); | |
2367 | } | |
2368 | if (!defined $hash_parent) { | |
2369 | $hash_parent = $co{'parent'} || '--root'; | |
2370 | } | |
b9182987 | 2371 | open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash |
cac4bd94 | 2372 | or die_error(undef, "Open git-diff-tree failed"); |
0881d2d1 | 2373 | my @difftree = map { chomp; $_ } <$fd>; |
cac4bd94 | 2374 | close $fd or die_error(undef, "Reading diff-tree failed"); |
19806691 | 2375 | |
1b1cd421 KS |
2376 | # try to figure out the next tag after this commit |
2377 | my $tagname; | |
847e01fb | 2378 | my $refs = git_get_references("tags"); |
b9182987 | 2379 | open $fd, "-|", $GIT, "rev-list", "HEAD"; |
0881d2d1 | 2380 | my @commits = map { chomp; $_ } <$fd>; |
6a928415 KS |
2381 | close $fd; |
2382 | foreach my $commit (@commits) { | |
2383 | if (defined $refs->{$commit}) { | |
2384 | $tagname = $refs->{$commit} | |
1b1cd421 KS |
2385 | } |
2386 | if ($commit eq $hash) { | |
2387 | last; | |
2388 | } | |
2389 | } | |
1b1cd421 | 2390 | |
9312944d | 2391 | print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\""); |
847e01fb | 2392 | my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'}); |
c994d620 | 2393 | my $comment = $co{'comment'}; |
1b1cd421 | 2394 | print "From: $co{'author'}\n" . |
c994d620 | 2395 | "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n". |
1b1cd421 KS |
2396 | "Subject: $co{'title'}\n"; |
2397 | if (defined $tagname) { | |
5be01bc8 | 2398 | print "X-Git-Tag: $tagname\n"; |
1b1cd421 KS |
2399 | } |
2400 | print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" . | |
c994d620 | 2401 | "\n"; |
1b1cd421 | 2402 | |
c994d620 | 2403 | foreach my $line (@$comment) {; |
c2488d06 | 2404 | print "$line\n"; |
c994d620 | 2405 | } |
1b1cd421 KS |
2406 | print "---\n\n"; |
2407 | ||
19806691 | 2408 | foreach my $line (@difftree) { |
e349d21a JN |
2409 | if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) { |
2410 | next; | |
2411 | } | |
19806691 KS |
2412 | my $from_id = $3; |
2413 | my $to_id = $4; | |
2414 | my $status = $5; | |
2415 | my $file = $6; | |
f6375b24 | 2416 | if ($status eq "A") { |
19806691 KS |
2417 | git_diff_print(undef, "/dev/null", $to_id, "b/$file", "plain"); |
2418 | } elsif ($status eq "D") { | |
2419 | git_diff_print($from_id, "a/$file", undef, "/dev/null", "plain"); | |
2420 | } elsif ($status eq "M") { | |
2421 | git_diff_print($from_id, "a/$file", $to_id, "b/$file", "plain"); | |
2422 | } | |
2423 | } | |
2424 | } | |
2425 | ||
09bd7898 | 2426 | sub git_history { |
c6e1d9ed | 2427 | if (!defined $hash_base) { |
847e01fb | 2428 | $hash_base = git_get_head_hash($project); |
09bd7898 | 2429 | } |
63433106 | 2430 | my $ftype; |
847e01fb | 2431 | my %co = parse_commit($hash_base); |
09bd7898 | 2432 | if (!%co) { |
cac4bd94 | 2433 | die_error(undef, "Unknown commit object"); |
2ae100df | 2434 | } |
847e01fb | 2435 | my $refs = git_get_references(); |
d51e902a | 2436 | git_header_html(); |
847e01fb JN |
2437 | git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base); |
2438 | git_print_header_div('commit', esc_html($co{'title'}), $hash_base); | |
93d5f061 LT |
2439 | if (!defined $hash && defined $file_name) { |
2440 | $hash = git_get_hash_by_path($hash_base, $file_name); | |
2441 | } | |
cff0771b | 2442 | if (defined $hash) { |
63433106 | 2443 | $ftype = git_get_type($hash); |
cff0771b | 2444 | } |
63433106 | 2445 | git_print_page_path($file_name, $ftype); |
10dba28d | 2446 | |
cdd4037d | 2447 | open my $fd, "-|", |
822c1859 | 2448 | $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name; |
581860e1 JN |
2449 | git_history_body($fd, $refs, $hash_base, $ftype); |
2450 | ||
b87d78d6 | 2451 | close $fd; |
d51e902a | 2452 | git_footer_html(); |
161332a5 | 2453 | } |
19806691 KS |
2454 | |
2455 | sub git_search { | |
2456 | if (!defined $searchtext) { | |
cac4bd94 | 2457 | die_error(undef, "Text field empty"); |
19806691 KS |
2458 | } |
2459 | if (!defined $hash) { | |
847e01fb | 2460 | $hash = git_get_head_hash($project); |
19806691 | 2461 | } |
847e01fb | 2462 | my %co = parse_commit($hash); |
19806691 | 2463 | if (!%co) { |
cac4bd94 | 2464 | die_error(undef, "Unknown commit object"); |
19806691 | 2465 | } |
c994d620 KS |
2466 | # pickaxe may take all resources of your box and run for several minutes |
2467 | # with every query - so decide by yourself how public you make this feature :) | |
2468 | my $commit_search = 1; | |
2469 | my $author_search = 0; | |
2470 | my $committer_search = 0; | |
2471 | my $pickaxe_search = 0; | |
2472 | if ($searchtext =~ s/^author\\://i) { | |
2473 | $author_search = 1; | |
2474 | } elsif ($searchtext =~ s/^committer\\://i) { | |
2475 | $committer_search = 1; | |
2476 | } elsif ($searchtext =~ s/^pickaxe\\://i) { | |
2477 | $commit_search = 0; | |
2478 | $pickaxe_search = 1; | |
2479 | } | |
19806691 | 2480 | git_header_html(); |
847e01fb JN |
2481 | git_print_page_nav('','', $hash,$co{'tree'},$hash); |
2482 | git_print_header_div('commit', esc_html($co{'title'}), $hash); | |
19806691 | 2483 | |
19806691 | 2484 | print "<table cellspacing=\"0\">\n"; |
19806691 | 2485 | my $alternate = 0; |
c994d620 KS |
2486 | if ($commit_search) { |
2487 | $/ = "\0"; | |
b9182987 | 2488 | open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next; |
c994d620 KS |
2489 | while (my $commit_text = <$fd>) { |
2490 | if (!grep m/$searchtext/i, $commit_text) { | |
2491 | next; | |
19806691 | 2492 | } |
c994d620 KS |
2493 | if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) { |
2494 | next; | |
19806691 | 2495 | } |
c994d620 | 2496 | if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) { |
19806691 KS |
2497 | next; |
2498 | } | |
c994d620 | 2499 | my @commit_lines = split "\n", $commit_text; |
847e01fb | 2500 | my %co = parse_commit(undef, \@commit_lines); |
c994d620 KS |
2501 | if (!%co) { |
2502 | next; | |
2503 | } | |
2504 | if ($alternate) { | |
2505 | print "<tr class=\"dark\">\n"; | |
2506 | } else { | |
2507 | print "<tr class=\"light\">\n"; | |
2508 | } | |
2509 | $alternate ^= 1; | |
71be1e79 | 2510 | print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . |
40c13813 | 2511 | "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" . |
c994d620 | 2512 | "<td>" . |
232ff553 | 2513 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" . esc_html(chop_str($co{'title'}, 50)) . "</b><br/>"); |
c994d620 KS |
2514 | my $comment = $co{'comment'}; |
2515 | foreach my $line (@$comment) { | |
2516 | if ($line =~ m/^(.*)($searchtext)(.*)$/i) { | |
40c13813 | 2517 | my $lead = esc_html($1) || ""; |
c994d620 | 2518 | $lead = chop_str($lead, 30, 10); |
40c13813 KS |
2519 | my $match = esc_html($2) || ""; |
2520 | my $trail = esc_html($3) || ""; | |
c994d620 | 2521 | $trail = chop_str($trail, 30, 10); |
1f1ab5f0 | 2522 | my $text = "$lead<span class=\"match\">$match</span>$trail"; |
c994d620 | 2523 | print chop_str($text, 80, 5) . "<br/>\n"; |
19806691 | 2524 | } |
c994d620 KS |
2525 | } |
2526 | print "</td>\n" . | |
2527 | "<td class=\"link\">" . | |
232ff553 KS |
2528 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}")}, "commit") . |
2529 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree"); | |
c994d620 KS |
2530 | print "</td>\n" . |
2531 | "</tr>\n"; | |
2532 | } | |
2533 | close $fd; | |
2534 | } | |
2535 | ||
2536 | if ($pickaxe_search) { | |
2537 | $/ = "\n"; | |
e130ddaa | 2538 | open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'"; |
c994d620 KS |
2539 | undef %co; |
2540 | my @files; | |
2541 | while (my $line = <$fd>) { | |
2542 | if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) { | |
2543 | my %set; | |
2544 | $set{'file'} = $6; | |
2545 | $set{'from_id'} = $3; | |
2546 | $set{'to_id'} = $4; | |
2547 | $set{'id'} = $set{'to_id'}; | |
2548 | if ($set{'id'} =~ m/0{40}/) { | |
2549 | $set{'id'} = $set{'from_id'}; | |
19806691 | 2550 | } |
c994d620 KS |
2551 | if ($set{'id'} =~ m/0{40}/) { |
2552 | next; | |
2553 | } | |
2554 | push @files, \%set; | |
53b89d8d | 2555 | } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){ |
c994d620 KS |
2556 | if (%co) { |
2557 | if ($alternate) { | |
2558 | print "<tr class=\"dark\">\n"; | |
2559 | } else { | |
2560 | print "<tr class=\"light\">\n"; | |
2561 | } | |
2562 | $alternate ^= 1; | |
71be1e79 | 2563 | print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . |
40c13813 | 2564 | "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" . |
c994d620 | 2565 | "<td>" . |
232ff553 | 2566 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" . |
40c13813 | 2567 | esc_html(chop_str($co{'title'}, 50)) . "</b><br/>"); |
c994d620 KS |
2568 | while (my $setref = shift @files) { |
2569 | my %set = %$setref; | |
232ff553 | 2570 | print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"}, |
1f1ab5f0 | 2571 | "<span class=\"match\">" . esc_html($set{'file'}) . "</span>") . |
c994d620 KS |
2572 | "<br/>\n"; |
2573 | } | |
2574 | print "</td>\n" . | |
2575 | "<td class=\"link\">" . | |
232ff553 KS |
2576 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}")}, "commit") . |
2577 | " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree"); | |
c994d620 KS |
2578 | print "</td>\n" . |
2579 | "</tr>\n"; | |
2580 | } | |
847e01fb | 2581 | %co = parse_commit($1); |
19806691 | 2582 | } |
19806691 | 2583 | } |
c994d620 | 2584 | close $fd; |
19806691 KS |
2585 | } |
2586 | print "</table>\n"; | |
19806691 KS |
2587 | git_footer_html(); |
2588 | } | |
2589 | ||
2590 | sub git_shortlog { | |
847e01fb | 2591 | my $head = git_get_head_hash($project); |
19806691 KS |
2592 | if (!defined $hash) { |
2593 | $hash = $head; | |
2594 | } | |
ea4a6df4 KS |
2595 | if (!defined $page) { |
2596 | $page = 0; | |
2597 | } | |
847e01fb | 2598 | my $refs = git_get_references(); |
ea4a6df4 KS |
2599 | |
2600 | my $limit = sprintf("--max-count=%i", (100 * ($page+1))); | |
044bfdc8 | 2601 | open my $fd, "-|", $GIT, "rev-list", $limit, $hash |
cac4bd94 | 2602 | or die_error(undef, "Open git-rev-list failed"); |
0881d2d1 | 2603 | my @revlist = map { chomp; $_ } <$fd>; |
19806691 | 2604 | close $fd; |
ea4a6df4 | 2605 | |
847e01fb | 2606 | my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, $#revlist); |
9f5dcb81 JN |
2607 | my $next_link = ''; |
2608 | if ($#revlist >= (100 * ($page+1)-1)) { | |
2609 | $next_link = | |
2610 | $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), | |
2611 | -title => "Alt-n"}, "next"); | |
2612 | } | |
2613 | ||
0d83ddc4 JN |
2614 | |
2615 | git_header_html(); | |
847e01fb JN |
2616 | git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav); |
2617 | git_print_header_div('summary', $project); | |
0d83ddc4 | 2618 | |
9f5dcb81 JN |
2619 | git_shortlog_body(\@revlist, ($page * 100), $#revlist, $refs, $next_link); |
2620 | ||
19806691 KS |
2621 | git_footer_html(); |
2622 | } | |
717b8311 JN |
2623 | |
2624 | ## ...................................................................... | |
2625 | ## feeds (RSS, OPML) | |
2626 | ||
2627 | sub git_rss { | |
2628 | # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ | |
847e01fb | 2629 | open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash($project) |
cac4bd94 | 2630 | or die_error(undef, "Open git-rev-list failed"); |
717b8311 | 2631 | my @revlist = map { chomp; $_ } <$fd>; |
cac4bd94 | 2632 | close $fd or die_error(undef, "Reading git-rev-list failed"); |
717b8311 JN |
2633 | print $cgi->header(-type => 'text/xml', -charset => 'utf-8'); |
2634 | print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n". | |
2635 | "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n"; | |
2636 | print "<channel>\n"; | |
2637 | print "<title>$project</title>\n". | |
2638 | "<link>" . esc_html("$my_url?p=$project;a=summary") . "</link>\n". | |
2639 | "<description>$project log</description>\n". | |
2640 | "<language>en</language>\n"; | |
2641 | ||
2642 | for (my $i = 0; $i <= $#revlist; $i++) { | |
2643 | my $commit = $revlist[$i]; | |
847e01fb | 2644 | my %co = parse_commit($commit); |
717b8311 JN |
2645 | # we read 150, we always show 30 and the ones more recent than 48 hours |
2646 | if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) { | |
2647 | last; | |
2648 | } | |
847e01fb | 2649 | my %cd = parse_date($co{'committer_epoch'}); |
717b8311 JN |
2650 | open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next; |
2651 | my @difftree = map { chomp; $_ } <$fd>; | |
2652 | close $fd or next; | |
2653 | print "<item>\n" . | |
2654 | "<title>" . | |
2655 | sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) . | |
2656 | "</title>\n" . | |
2657 | "<author>" . esc_html($co{'author'}) . "</author>\n" . | |
2658 | "<pubDate>$cd{'rfc2822'}</pubDate>\n" . | |
2659 | "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" . | |
2660 | "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" . | |
2661 | "<description>" . esc_html($co{'title'}) . "</description>\n" . | |
2662 | "<content:encoded>" . | |
2663 | "<![CDATA[\n"; | |
2664 | my $comment = $co{'comment'}; | |
2665 | foreach my $line (@$comment) { | |
2666 | $line = decode("utf8", $line, Encode::FB_DEFAULT); | |
2667 | print "$line<br/>\n"; | |
2668 | } | |
2669 | print "<br/>\n"; | |
2670 | foreach my $line (@difftree) { | |
2671 | if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) { | |
2672 | next; | |
2673 | } | |
2674 | my $file = validate_input(unquote($7)); | |
2675 | $file = decode("utf8", $file, Encode::FB_DEFAULT); | |
2676 | print "$file<br/>\n"; | |
2677 | } | |
2678 | print "]]>\n" . | |
2679 | "</content:encoded>\n" . | |
2680 | "</item>\n"; | |
2681 | } | |
2682 | print "</channel></rss>"; | |
2683 | } | |
2684 | ||
2685 | sub git_opml { | |
847e01fb | 2686 | my @list = git_get_projects_list(); |
717b8311 JN |
2687 | |
2688 | print $cgi->header(-type => 'text/xml', -charset => 'utf-8'); | |
2689 | print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n". | |
2690 | "<opml version=\"1.0\">\n". | |
2691 | "<head>". | |
2692 | " <title>$site_name Git OPML Export</title>\n". | |
2693 | "</head>\n". | |
2694 | "<body>\n". | |
2695 | "<outline text=\"git RSS feeds\">\n"; | |
2696 | ||
2697 | foreach my $pr (@list) { | |
2698 | my %proj = %$pr; | |
847e01fb | 2699 | my $head = git_get_head_hash($proj{'path'}); |
717b8311 JN |
2700 | if (!defined $head) { |
2701 | next; | |
2702 | } | |
2703 | $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}"; | |
847e01fb | 2704 | my %co = parse_commit($head); |
717b8311 JN |
2705 | if (!%co) { |
2706 | next; | |
2707 | } | |
2708 | ||
2709 | my $path = esc_html(chop_str($proj{'path'}, 25, 5)); | |
2710 | my $rss = "$my_url?p=$proj{'path'};a=rss"; | |
2711 | my $html = "$my_url?p=$proj{'path'};a=summary"; | |
2712 | print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n"; | |
2713 | } | |
2714 | print "</outline>\n". | |
2715 | "</body>\n". | |
2716 | "</opml>\n"; | |
2717 | } |