]> Lady’s Gitweb - Gitweb/blob - gitweb.perl
gitweb: Whitespace cleanup - tabs are for indent, spaces are for align (2)
[Gitweb] / gitweb.perl
1 #!/usr/bin/perl
2
3 # gitweb - simple web interface to track changes in git repositories
4 #
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
7 #
8 # This program is licensed under the GPLv2
9
10 use strict;
11 use warnings;
12 use CGI qw(:standard :escapeHTML -nosticky);
13 use CGI::Util qw(unescape);
14 use CGI::Carp qw(fatalsToBrowser);
15 use Encode;
16 use Fcntl ':mode';
17 use File::Find qw();
18 use File::Basename qw(basename);
19 binmode STDOUT, ':utf8';
20
21 our $cgi = new CGI;
22 our $version = "++GIT_VERSION++";
23 our $my_url = $cgi->url();
24 our $my_uri = $cgi->url(-absolute => 1);
25
26 # core git executable to use
27 # this can just be "git" if your webserver has a sensible PATH
28 our $GIT = "++GIT_BINDIR++/git";
29
30 # absolute fs-path which will be prepended to the project path
31 #our $projectroot = "/pub/scm";
32 our $projectroot = "++GITWEB_PROJECTROOT++";
33
34 # target of the home link on top of all pages
35 our $home_link = $my_uri || "/";
36
37 # string of the home link on top of all pages
38 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
39
40 # name of your site or organization to appear in page titles
41 # replace this with something more descriptive for clearer bookmarks
42 our $site_name = "++GITWEB_SITENAME++" || $ENV{'SERVER_NAME'} || "Untitled";
43
44 # filename of html text to include at top of each page
45 our $site_header = "++GITWEB_SITE_HEADER++";
46 # html text to include at home page
47 our $home_text = "++GITWEB_HOMETEXT++";
48 # filename of html text to include at bottom of each page
49 our $site_footer = "++GITWEB_SITE_FOOTER++";
50
51 # URI of stylesheets
52 our @stylesheets = ("++GITWEB_CSS++");
53 our $stylesheet;
54 # default is not to define style sheet, but it can be overwritten later
55 undef $stylesheet;
56
57 # URI of GIT logo (72x27 size)
58 our $logo = "++GITWEB_LOGO++";
59 # URI of GIT favicon, assumed to be image/png type
60 our $favicon = "++GITWEB_FAVICON++";
61
62 # URI and label (title) of GIT logo link
63 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
64 #our $logo_label = "git documentation";
65 our $logo_url = "http://git.or.cz/";
66 our $logo_label = "git homepage";
67
68 # source of projects list
69 our $projects_list = "++GITWEB_LIST++";
70
71 # show repository only if this file exists
72 # (only effective if this variable evaluates to true)
73 our $export_ok = "++GITWEB_EXPORT_OK++";
74
75 # only allow viewing of repositories also shown on the overview page
76 our $strict_export = "++GITWEB_STRICT_EXPORT++";
77
78 # list of git base URLs used for URL to where fetch project from,
79 # i.e. full URL is "$git_base_url/$project"
80 our @git_base_url_list = ("++GITWEB_BASE_URL++");
81
82 # default blob_plain mimetype and default charset for text/plain blob
83 our $default_blob_plain_mimetype = 'text/plain';
84 our $default_text_plain_charset = undef;
85
86 # file to use for guessing MIME types before trying /etc/mime.types
87 # (relative to the current git repository)
88 our $mimetypes_file = undef;
89
90 # You define site-wide feature defaults here; override them with
91 # $GITWEB_CONFIG as necessary.
92 our %feature = (
93 # feature => {
94 # 'sub' => feature-sub (subroutine),
95 # 'override' => allow-override (boolean),
96 # 'default' => [ default options...] (array reference)}
97 #
98 # if feature is overridable (it means that allow-override has true value,
99 # then feature-sub will be called with default options as parameters;
100 # return value of feature-sub indicates if to enable specified feature
101 #
102 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
103
104 # Enable the 'blame' blob view, showing the last commit that modified
105 # each line in the file. This can be very CPU-intensive.
106
107 # To enable system wide have in $GITWEB_CONFIG
108 # $feature{'blame'}{'default'} = [1];
109 # To have project specific config enable override in $GITWEB_CONFIG
110 # $feature{'blame'}{'override'} = 1;
111 # and in project config gitweb.blame = 0|1;
112 'blame' => {
113 'sub' => \&feature_blame,
114 'override' => 0,
115 'default' => [0]},
116
117 # Enable the 'snapshot' link, providing a compressed tarball of any
118 # tree. This can potentially generate high traffic if you have large
119 # project.
120
121 # To disable system wide have in $GITWEB_CONFIG
122 # $feature{'snapshot'}{'default'} = [undef];
123 # To have project specific config enable override in $GITWEB_CONFIG
124 # $feature{'blame'}{'override'} = 1;
125 # and in project config gitweb.snapshot = none|gzip|bzip2;
126 'snapshot' => {
127 'sub' => \&feature_snapshot,
128 'override' => 0,
129 # => [content-encoding, suffix, program]
130 'default' => ['x-gzip', 'gz', 'gzip']},
131
132 # Enable the pickaxe search, which will list the commits that modified
133 # a given string in a file. This can be practical and quite faster
134 # alternative to 'blame', but still potentially CPU-intensive.
135
136 # To enable system wide have in $GITWEB_CONFIG
137 # $feature{'pickaxe'}{'default'} = [1];
138 # To have project specific config enable override in $GITWEB_CONFIG
139 # $feature{'pickaxe'}{'override'} = 1;
140 # and in project config gitweb.pickaxe = 0|1;
141 'pickaxe' => {
142 'sub' => \&feature_pickaxe,
143 'override' => 0,
144 'default' => [1]},
145
146 # Make gitweb use an alternative format of the URLs which can be
147 # more readable and natural-looking: project name is embedded
148 # directly in the path and the query string contains other
149 # auxiliary information. All gitweb installations recognize
150 # URL in either format; this configures in which formats gitweb
151 # generates links.
152
153 # To enable system wide have in $GITWEB_CONFIG
154 # $feature{'pathinfo'}{'default'} = [1];
155 # Project specific override is not supported.
156
157 # Note that you will need to change the default location of CSS,
158 # favicon, logo and possibly other files to an absolute URL. Also,
159 # if gitweb.cgi serves as your indexfile, you will need to force
160 # $my_uri to contain the script name in your $GITWEB_CONFIG.
161 'pathinfo' => {
162 'override' => 0,
163 'default' => [0]},
164 );
165
166 sub gitweb_check_feature {
167 my ($name) = @_;
168 return unless exists $feature{$name};
169 my ($sub, $override, @defaults) = (
170 $feature{$name}{'sub'},
171 $feature{$name}{'override'},
172 @{$feature{$name}{'default'}});
173 if (!$override) { return @defaults; }
174 if (!defined $sub) {
175 warn "feature $name is not overrideable";
176 return @defaults;
177 }
178 return $sub->(@defaults);
179 }
180
181 sub feature_blame {
182 my ($val) = git_get_project_config('blame', '--bool');
183
184 if ($val eq 'true') {
185 return 1;
186 } elsif ($val eq 'false') {
187 return 0;
188 }
189
190 return $_[0];
191 }
192
193 sub feature_snapshot {
194 my ($ctype, $suffix, $command) = @_;
195
196 my ($val) = git_get_project_config('snapshot');
197
198 if ($val eq 'gzip') {
199 return ('x-gzip', 'gz', 'gzip');
200 } elsif ($val eq 'bzip2') {
201 return ('x-bzip2', 'bz2', 'bzip2');
202 } elsif ($val eq 'none') {
203 return ();
204 }
205
206 return ($ctype, $suffix, $command);
207 }
208
209 sub gitweb_have_snapshot {
210 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
211 my $have_snapshot = (defined $ctype && defined $suffix);
212
213 return $have_snapshot;
214 }
215
216 sub feature_pickaxe {
217 my ($val) = git_get_project_config('pickaxe', '--bool');
218
219 if ($val eq 'true') {
220 return (1);
221 } elsif ($val eq 'false') {
222 return (0);
223 }
224
225 return ($_[0]);
226 }
227
228 # checking HEAD file with -e is fragile if the repository was
229 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
230 # and then pruned.
231 sub check_head_link {
232 my ($dir) = @_;
233 my $headfile = "$dir/HEAD";
234 return ((-e $headfile) ||
235 (-l $headfile && readlink($headfile) =~ /^refs\/heads\//));
236 }
237
238 sub check_export_ok {
239 my ($dir) = @_;
240 return (check_head_link($dir) &&
241 (!$export_ok || -e "$dir/$export_ok"));
242 }
243
244 # rename detection options for git-diff and git-diff-tree
245 # - default is '-M', with the cost proportional to
246 # (number of removed files) * (number of new files).
247 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
248 # (number of changed files + number of removed files) * (number of new files)
249 # - even more costly is '-C', '--find-copies-harder' with cost
250 # (number of files in the original tree) * (number of new files)
251 # - one might want to include '-B' option, e.g. '-B', '-M'
252 our @diff_opts = ('-M'); # taken from git_commit
253
254 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
255 do $GITWEB_CONFIG if -e $GITWEB_CONFIG;
256
257 # version of the core git binary
258 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
259
260 $projects_list ||= $projectroot;
261
262 # ======================================================================
263 # input validation and dispatch
264 our $action = $cgi->param('a');
265 if (defined $action) {
266 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
267 die_error(undef, "Invalid action parameter");
268 }
269 }
270
271 # parameters which are pathnames
272 our $project = $cgi->param('p');
273 if (defined $project) {
274 if (!validate_pathname($project) ||
275 !(-d "$projectroot/$project") ||
276 !check_head_link("$projectroot/$project") ||
277 ($export_ok && !(-e "$projectroot/$project/$export_ok")) ||
278 ($strict_export && !project_in_list($project))) {
279 undef $project;
280 die_error(undef, "No such project");
281 }
282 }
283
284 our $file_name = $cgi->param('f');
285 if (defined $file_name) {
286 if (!validate_pathname($file_name)) {
287 die_error(undef, "Invalid file parameter");
288 }
289 }
290
291 our $file_parent = $cgi->param('fp');
292 if (defined $file_parent) {
293 if (!validate_pathname($file_parent)) {
294 die_error(undef, "Invalid file parent parameter");
295 }
296 }
297
298 # parameters which are refnames
299 our $hash = $cgi->param('h');
300 if (defined $hash) {
301 if (!validate_refname($hash)) {
302 die_error(undef, "Invalid hash parameter");
303 }
304 }
305
306 our $hash_parent = $cgi->param('hp');
307 if (defined $hash_parent) {
308 if (!validate_refname($hash_parent)) {
309 die_error(undef, "Invalid hash parent parameter");
310 }
311 }
312
313 our $hash_base = $cgi->param('hb');
314 if (defined $hash_base) {
315 if (!validate_refname($hash_base)) {
316 die_error(undef, "Invalid hash base parameter");
317 }
318 }
319
320 our $hash_parent_base = $cgi->param('hpb');
321 if (defined $hash_parent_base) {
322 if (!validate_refname($hash_parent_base)) {
323 die_error(undef, "Invalid hash parent base parameter");
324 }
325 }
326
327 # other parameters
328 our $page = $cgi->param('pg');
329 if (defined $page) {
330 if ($page =~ m/[^0-9]/) {
331 die_error(undef, "Invalid page parameter");
332 }
333 }
334
335 our $searchtext = $cgi->param('s');
336 if (defined $searchtext) {
337 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) {
338 die_error(undef, "Invalid search parameter");
339 }
340 $searchtext = quotemeta $searchtext;
341 }
342
343 # now read PATH_INFO and use it as alternative to parameters
344 sub evaluate_path_info {
345 return if defined $project;
346 my $path_info = $ENV{"PATH_INFO"};
347 return if !$path_info;
348 $path_info =~ s,^/+,,;
349 return if !$path_info;
350 # find which part of PATH_INFO is project
351 $project = $path_info;
352 $project =~ s,/+$,,;
353 while ($project && !check_head_link("$projectroot/$project")) {
354 $project =~ s,/*[^/]*$,,;
355 }
356 # validate project
357 $project = validate_pathname($project);
358 if (!$project ||
359 ($export_ok && !-e "$projectroot/$project/$export_ok") ||
360 ($strict_export && !project_in_list($project))) {
361 undef $project;
362 return;
363 }
364 # do not change any parameters if an action is given using the query string
365 return if $action;
366 $path_info =~ s,^$project/*,,;
367 my ($refname, $pathname) = split(/:/, $path_info, 2);
368 if (defined $pathname) {
369 # we got "project.git/branch:filename" or "project.git/branch:dir/"
370 # we could use git_get_type(branch:pathname), but it needs $git_dir
371 $pathname =~ s,^/+,,;
372 if (!$pathname || substr($pathname, -1) eq "/") {
373 $action ||= "tree";
374 $pathname =~ s,/$,,;
375 } else {
376 $action ||= "blob_plain";
377 }
378 $hash_base ||= validate_refname($refname);
379 $file_name ||= validate_pathname($pathname);
380 } elsif (defined $refname) {
381 # we got "project.git/branch"
382 $action ||= "shortlog";
383 $hash ||= validate_refname($refname);
384 }
385 }
386 evaluate_path_info();
387
388 # path to the current git repository
389 our $git_dir;
390 $git_dir = "$projectroot/$project" if $project;
391
392 # dispatch
393 my %actions = (
394 "blame" => \&git_blame2,
395 "blobdiff" => \&git_blobdiff,
396 "blobdiff_plain" => \&git_blobdiff_plain,
397 "blob" => \&git_blob,
398 "blob_plain" => \&git_blob_plain,
399 "commitdiff" => \&git_commitdiff,
400 "commitdiff_plain" => \&git_commitdiff_plain,
401 "commit" => \&git_commit,
402 "heads" => \&git_heads,
403 "history" => \&git_history,
404 "log" => \&git_log,
405 "rss" => \&git_rss,
406 "search" => \&git_search,
407 "shortlog" => \&git_shortlog,
408 "summary" => \&git_summary,
409 "tag" => \&git_tag,
410 "tags" => \&git_tags,
411 "tree" => \&git_tree,
412 "snapshot" => \&git_snapshot,
413 # those below don't need $project
414 "opml" => \&git_opml,
415 "project_list" => \&git_project_list,
416 "project_index" => \&git_project_index,
417 );
418
419 if (defined $project) {
420 $action ||= 'summary';
421 } else {
422 $action ||= 'project_list';
423 }
424 if (!defined($actions{$action})) {
425 die_error(undef, "Unknown action");
426 }
427 if ($action !~ m/^(opml|project_list|project_index)$/ &&
428 !$project) {
429 die_error(undef, "Project needed");
430 }
431 $actions{$action}->();
432 exit;
433
434 ## ======================================================================
435 ## action links
436
437 sub href(%) {
438 my %params = @_;
439 my $href = $my_uri;
440
441 # XXX: Warning: If you touch this, check the search form for updating,
442 # too.
443
444 my @mapping = (
445 project => "p",
446 action => "a",
447 file_name => "f",
448 file_parent => "fp",
449 hash => "h",
450 hash_parent => "hp",
451 hash_base => "hb",
452 hash_parent_base => "hpb",
453 page => "pg",
454 order => "o",
455 searchtext => "s",
456 );
457 my %mapping = @mapping;
458
459 $params{'project'} = $project unless exists $params{'project'};
460
461 my ($use_pathinfo) = gitweb_check_feature('pathinfo');
462 if ($use_pathinfo) {
463 # use PATH_INFO for project name
464 $href .= "/$params{'project'}" if defined $params{'project'};
465 delete $params{'project'};
466
467 # Summary just uses the project path URL
468 if (defined $params{'action'} && $params{'action'} eq 'summary') {
469 delete $params{'action'};
470 }
471 }
472
473 # now encode the parameters explicitly
474 my @result = ();
475 for (my $i = 0; $i < @mapping; $i += 2) {
476 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
477 if (defined $params{$name}) {
478 push @result, $symbol . "=" . esc_param($params{$name});
479 }
480 }
481 $href .= "?" . join(';', @result) if scalar @result;
482
483 return $href;
484 }
485
486
487 ## ======================================================================
488 ## validation, quoting/unquoting and escaping
489
490 sub validate_pathname {
491 my $input = shift || return undef;
492
493 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
494 # at the beginning, at the end, and between slashes.
495 # also this catches doubled slashes
496 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
497 return undef;
498 }
499 # no null characters
500 if ($input =~ m!\0!) {
501 return undef;
502 }
503 return $input;
504 }
505
506 sub validate_refname {
507 my $input = shift || return undef;
508
509 # textual hashes are O.K.
510 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
511 return $input;
512 }
513 # it must be correct pathname
514 $input = validate_pathname($input)
515 or return undef;
516 # restrictions on ref name according to git-check-ref-format
517 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
518 return undef;
519 }
520 return $input;
521 }
522
523 # very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT);
524 sub to_utf8 {
525 my $str = shift;
526 return decode("utf8", $str, Encode::FB_DEFAULT);
527 }
528
529 # quote unsafe chars, but keep the slash, even when it's not
530 # correct, but quoted slashes look too horrible in bookmarks
531 sub esc_param {
532 my $str = shift;
533 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf("%%%02X", ord($1))/eg;
534 $str =~ s/\+/%2B/g;
535 $str =~ s/ /\+/g;
536 return $str;
537 }
538
539 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
540 sub esc_url {
541 my $str = shift;
542 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
543 $str =~ s/\+/%2B/g;
544 $str =~ s/ /\+/g;
545 return $str;
546 }
547
548 # replace invalid utf8 character with SUBSTITUTION sequence
549 sub esc_html {
550 my $str = shift;
551 $str = to_utf8($str);
552 $str = escapeHTML($str);
553 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
554 $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1)
555 return $str;
556 }
557
558 # git may return quoted and escaped filenames
559 sub unquote {
560 my $str = shift;
561 if ($str =~ m/^"(.*)"$/) {
562 $str = $1;
563 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
564 }
565 return $str;
566 }
567
568 # escape tabs (convert tabs to spaces)
569 sub untabify {
570 my $line = shift;
571
572 while ((my $pos = index($line, "\t")) != -1) {
573 if (my $count = (8 - ($pos % 8))) {
574 my $spaces = ' ' x $count;
575 $line =~ s/\t/$spaces/;
576 }
577 }
578
579 return $line;
580 }
581
582 sub project_in_list {
583 my $project = shift;
584 my @list = git_get_projects_list();
585 return @list && scalar(grep { $_->{'path'} eq $project } @list);
586 }
587
588 ## ----------------------------------------------------------------------
589 ## HTML aware string manipulation
590
591 sub chop_str {
592 my $str = shift;
593 my $len = shift;
594 my $add_len = shift || 10;
595
596 # allow only $len chars, but don't cut a word if it would fit in $add_len
597 # if it doesn't fit, cut it if it's still longer than the dots we would add
598 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
599 my $body = $1;
600 my $tail = $2;
601 if (length($tail) > 4) {
602 $tail = " ...";
603 $body =~ s/&[^;]*$//; # remove chopped character entities
604 }
605 return "$body$tail";
606 }
607
608 ## ----------------------------------------------------------------------
609 ## functions returning short strings
610
611 # CSS class for given age value (in seconds)
612 sub age_class {
613 my $age = shift;
614
615 if ($age < 60*60*2) {
616 return "age0";
617 } elsif ($age < 60*60*24*2) {
618 return "age1";
619 } else {
620 return "age2";
621 }
622 }
623
624 # convert age in seconds to "nn units ago" string
625 sub age_string {
626 my $age = shift;
627 my $age_str;
628
629 if ($age > 60*60*24*365*2) {
630 $age_str = (int $age/60/60/24/365);
631 $age_str .= " years ago";
632 } elsif ($age > 60*60*24*(365/12)*2) {
633 $age_str = int $age/60/60/24/(365/12);
634 $age_str .= " months ago";
635 } elsif ($age > 60*60*24*7*2) {
636 $age_str = int $age/60/60/24/7;
637 $age_str .= " weeks ago";
638 } elsif ($age > 60*60*24*2) {
639 $age_str = int $age/60/60/24;
640 $age_str .= " days ago";
641 } elsif ($age > 60*60*2) {
642 $age_str = int $age/60/60;
643 $age_str .= " hours ago";
644 } elsif ($age > 60*2) {
645 $age_str = int $age/60;
646 $age_str .= " min ago";
647 } elsif ($age > 2) {
648 $age_str = int $age;
649 $age_str .= " sec ago";
650 } else {
651 $age_str .= " right now";
652 }
653 return $age_str;
654 }
655
656 # convert file mode in octal to symbolic file mode string
657 sub mode_str {
658 my $mode = oct shift;
659
660 if (S_ISDIR($mode & S_IFMT)) {
661 return 'drwxr-xr-x';
662 } elsif (S_ISLNK($mode)) {
663 return 'lrwxrwxrwx';
664 } elsif (S_ISREG($mode)) {
665 # git cares only about the executable bit
666 if ($mode & S_IXUSR) {
667 return '-rwxr-xr-x';
668 } else {
669 return '-rw-r--r--';
670 };
671 } else {
672 return '----------';
673 }
674 }
675
676 # convert file mode in octal to file type string
677 sub file_type {
678 my $mode = shift;
679
680 if ($mode !~ m/^[0-7]+$/) {
681 return $mode;
682 } else {
683 $mode = oct $mode;
684 }
685
686 if (S_ISDIR($mode & S_IFMT)) {
687 return "directory";
688 } elsif (S_ISLNK($mode)) {
689 return "symlink";
690 } elsif (S_ISREG($mode)) {
691 return "file";
692 } else {
693 return "unknown";
694 }
695 }
696
697 ## ----------------------------------------------------------------------
698 ## functions returning short HTML fragments, or transforming HTML fragments
699 ## which don't beling to other sections
700
701 # format line of commit message or tag comment
702 sub format_log_line_html {
703 my $line = shift;
704
705 $line = esc_html($line);
706 $line =~ s/ /&nbsp;/g;
707 if ($line =~ m/([0-9a-fA-F]{40})/) {
708 my $hash_text = $1;
709 if (git_get_type($hash_text) eq "commit") {
710 my $link =
711 $cgi->a({-href => href(action=>"commit", hash=>$hash_text),
712 -class => "text"}, $hash_text);
713 $line =~ s/$hash_text/$link/;
714 }
715 }
716 return $line;
717 }
718
719 # format marker of refs pointing to given object
720 sub format_ref_marker {
721 my ($refs, $id) = @_;
722 my $markers = '';
723
724 if (defined $refs->{$id}) {
725 foreach my $ref (@{$refs->{$id}}) {
726 my ($type, $name) = qw();
727 # e.g. tags/v2.6.11 or heads/next
728 if ($ref =~ m!^(.*?)s?/(.*)$!) {
729 $type = $1;
730 $name = $2;
731 } else {
732 $type = "ref";
733 $name = $ref;
734 }
735
736 $markers .= " <span class=\"$type\">" . esc_html($name) . "</span>";
737 }
738 }
739
740 if ($markers) {
741 return ' <span class="refs">'. $markers . '</span>';
742 } else {
743 return "";
744 }
745 }
746
747 # format, perhaps shortened and with markers, title line
748 sub format_subject_html {
749 my ($long, $short, $href, $extra) = @_;
750 $extra = '' unless defined($extra);
751
752 if (length($short) < length($long)) {
753 return $cgi->a({-href => $href, -class => "list subject",
754 -title => to_utf8($long)},
755 esc_html($short) . $extra);
756 } else {
757 return $cgi->a({-href => $href, -class => "list subject"},
758 esc_html($long) . $extra);
759 }
760 }
761
762 sub format_diff_line {
763 my $line = shift;
764 my $char = substr($line, 0, 1);
765 my $diff_class = "";
766
767 chomp $line;
768
769 if ($char eq '+') {
770 $diff_class = " add";
771 } elsif ($char eq "-") {
772 $diff_class = " rem";
773 } elsif ($char eq "@") {
774 $diff_class = " chunk_header";
775 } elsif ($char eq "\\") {
776 $diff_class = " incomplete";
777 }
778 $line = untabify($line);
779 return "<div class=\"diff$diff_class\">" . esc_html($line) . "</div>\n";
780 }
781
782 ## ----------------------------------------------------------------------
783 ## git utility subroutines, invoking git commands
784
785 # returns path to the core git executable and the --git-dir parameter as list
786 sub git_cmd {
787 return $GIT, '--git-dir='.$git_dir;
788 }
789
790 # returns path to the core git executable and the --git-dir parameter as string
791 sub git_cmd_str {
792 return join(' ', git_cmd());
793 }
794
795 # get HEAD ref of given project as hash
796 sub git_get_head_hash {
797 my $project = shift;
798 my $o_git_dir = $git_dir;
799 my $retval = undef;
800 $git_dir = "$projectroot/$project";
801 if (open my $fd, "-|", git_cmd(), "rev-parse", "--verify", "HEAD") {
802 my $head = <$fd>;
803 close $fd;
804 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
805 $retval = $1;
806 }
807 }
808 if (defined $o_git_dir) {
809 $git_dir = $o_git_dir;
810 }
811 return $retval;
812 }
813
814 # get type of given object
815 sub git_get_type {
816 my $hash = shift;
817
818 open my $fd, "-|", git_cmd(), "cat-file", '-t', $hash or return;
819 my $type = <$fd>;
820 close $fd or return;
821 chomp $type;
822 return $type;
823 }
824
825 sub git_get_project_config {
826 my ($key, $type) = @_;
827
828 return unless ($key);
829 $key =~ s/^gitweb\.//;
830 return if ($key =~ m/\W/);
831
832 my @x = (git_cmd(), 'repo-config');
833 if (defined $type) { push @x, $type; }
834 push @x, "--get";
835 push @x, "gitweb.$key";
836 my $val = qx(@x);
837 chomp $val;
838 return ($val);
839 }
840
841 # get hash of given path at given ref
842 sub git_get_hash_by_path {
843 my $base = shift;
844 my $path = shift || return undef;
845 my $type = shift;
846
847 $path =~ s,/+$,,;
848
849 open my $fd, "-|", git_cmd(), "ls-tree", $base, "--", $path
850 or die_error(undef, "Open git-ls-tree failed");
851 my $line = <$fd>;
852 close $fd or return undef;
853
854 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
855 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
856 if (defined $type && $type ne $2) {
857 # type doesn't match
858 return undef;
859 }
860 return $3;
861 }
862
863 ## ......................................................................
864 ## git utility functions, directly accessing git repository
865
866 sub git_get_project_description {
867 my $path = shift;
868
869 open my $fd, "$projectroot/$path/description" or return undef;
870 my $descr = <$fd>;
871 close $fd;
872 chomp $descr;
873 return $descr;
874 }
875
876 sub git_get_project_url_list {
877 my $path = shift;
878
879 open my $fd, "$projectroot/$path/cloneurl" or return;
880 my @git_project_url_list = map { chomp; $_ } <$fd>;
881 close $fd;
882
883 return wantarray ? @git_project_url_list : \@git_project_url_list;
884 }
885
886 sub git_get_projects_list {
887 my @list;
888
889 if (-d $projects_list) {
890 # search in directory
891 my $dir = $projects_list;
892 my $pfxlen = length("$dir");
893
894 File::Find::find({
895 follow_fast => 1, # follow symbolic links
896 dangling_symlinks => 0, # ignore dangling symlinks, silently
897 wanted => sub {
898 # skip project-list toplevel, if we get it.
899 return if (m!^[/.]$!);
900 # only directories can be git repositories
901 return unless (-d $_);
902
903 my $subdir = substr($File::Find::name, $pfxlen + 1);
904 # we check related file in $projectroot
905 if (check_export_ok("$projectroot/$subdir")) {
906 push @list, { path => $subdir };
907 $File::Find::prune = 1;
908 }
909 },
910 }, "$dir");
911
912 } elsif (-f $projects_list) {
913 # read from file(url-encoded):
914 # 'git%2Fgit.git Linus+Torvalds'
915 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
916 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
917 open my ($fd), $projects_list or return;
918 while (my $line = <$fd>) {
919 chomp $line;
920 my ($path, $owner) = split ' ', $line;
921 $path = unescape($path);
922 $owner = unescape($owner);
923 if (!defined $path) {
924 next;
925 }
926 if (check_export_ok("$projectroot/$path")) {
927 my $pr = {
928 path => $path,
929 owner => to_utf8($owner),
930 };
931 push @list, $pr
932 }
933 }
934 close $fd;
935 }
936 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
937 return @list;
938 }
939
940 sub git_get_project_owner {
941 my $project = shift;
942 my $owner;
943
944 return undef unless $project;
945
946 # read from file (url-encoded):
947 # 'git%2Fgit.git Linus+Torvalds'
948 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
949 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
950 if (-f $projects_list) {
951 open (my $fd , $projects_list);
952 while (my $line = <$fd>) {
953 chomp $line;
954 my ($pr, $ow) = split ' ', $line;
955 $pr = unescape($pr);
956 $ow = unescape($ow);
957 if ($pr eq $project) {
958 $owner = to_utf8($ow);
959 last;
960 }
961 }
962 close $fd;
963 }
964 if (!defined $owner) {
965 $owner = get_file_owner("$projectroot/$project");
966 }
967
968 return $owner;
969 }
970
971 sub git_get_references {
972 my $type = shift || "";
973 my %refs;
974 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
975 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
976 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
977 or return;
978
979 while (my $line = <$fd>) {
980 chomp $line;
981 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?[^\^]+)/) {
982 if (defined $refs{$1}) {
983 push @{$refs{$1}}, $2;
984 } else {
985 $refs{$1} = [ $2 ];
986 }
987 }
988 }
989 close $fd or return;
990 return \%refs;
991 }
992
993 sub git_get_rev_name_tags {
994 my $hash = shift || return undef;
995
996 open my $fd, "-|", git_cmd(), "name-rev", "--tags", $hash
997 or return;
998 my $name_rev = <$fd>;
999 close $fd;
1000
1001 if ($name_rev =~ m|^$hash tags/(.*)$|) {
1002 return $1;
1003 } else {
1004 # catches also '$hash undefined' output
1005 return undef;
1006 }
1007 }
1008
1009 ## ----------------------------------------------------------------------
1010 ## parse to hash functions
1011
1012 sub parse_date {
1013 my $epoch = shift;
1014 my $tz = shift || "-0000";
1015
1016 my %date;
1017 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1018 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1019 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1020 $date{'hour'} = $hour;
1021 $date{'minute'} = $min;
1022 $date{'mday'} = $mday;
1023 $date{'day'} = $days[$wday];
1024 $date{'month'} = $months[$mon];
1025 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1026 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1027 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1028 $mday, $months[$mon], $hour ,$min;
1029
1030 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1031 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1032 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1033 $date{'hour_local'} = $hour;
1034 $date{'minute_local'} = $min;
1035 $date{'tz_local'} = $tz;
1036 $date{'iso-tz'} = sprintf ("%04d-%02d-%02d %02d:%02d:%02d %s",
1037 1900+$year, $mon+1, $mday,
1038 $hour, $min, $sec, $tz);
1039 return %date;
1040 }
1041
1042 sub parse_tag {
1043 my $tag_id = shift;
1044 my %tag;
1045 my @comment;
1046
1047 open my $fd, "-|", git_cmd(), "cat-file", "tag", $tag_id or return;
1048 $tag{'id'} = $tag_id;
1049 while (my $line = <$fd>) {
1050 chomp $line;
1051 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1052 $tag{'object'} = $1;
1053 } elsif ($line =~ m/^type (.+)$/) {
1054 $tag{'type'} = $1;
1055 } elsif ($line =~ m/^tag (.+)$/) {
1056 $tag{'name'} = $1;
1057 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1058 $tag{'author'} = $1;
1059 $tag{'epoch'} = $2;
1060 $tag{'tz'} = $3;
1061 } elsif ($line =~ m/--BEGIN/) {
1062 push @comment, $line;
1063 last;
1064 } elsif ($line eq "") {
1065 last;
1066 }
1067 }
1068 push @comment, <$fd>;
1069 $tag{'comment'} = \@comment;
1070 close $fd or return;
1071 if (!defined $tag{'name'}) {
1072 return
1073 };
1074 return %tag
1075 }
1076
1077 sub git_get_last_activity {
1078 my ($path) = @_;
1079 my $fd;
1080
1081 $git_dir = "$projectroot/$path";
1082 open($fd, "-|", git_cmd(), 'for-each-ref',
1083 '--format=%(refname) %(committer)',
1084 '--sort=-committerdate',
1085 'refs/heads') or return;
1086 my $most_recent = <$fd>;
1087 close $fd or return;
1088 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1089 my $timestamp = $1;
1090 my $age = time - $timestamp;
1091 return ($age, age_string($age));
1092 }
1093 }
1094
1095 sub parse_commit {
1096 my $commit_id = shift;
1097 my $commit_text = shift;
1098
1099 my @commit_lines;
1100 my %co;
1101
1102 if (defined $commit_text) {
1103 @commit_lines = @$commit_text;
1104 } else {
1105 $/ = "\0";
1106 open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
1107 or return;
1108 @commit_lines = split '\n', <$fd>;
1109 close $fd or return;
1110 $/ = "\n";
1111 pop @commit_lines;
1112 }
1113 my $header = shift @commit_lines;
1114 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1115 return;
1116 }
1117 ($co{'id'}, my @parents) = split ' ', $header;
1118 $co{'parents'} = \@parents;
1119 $co{'parent'} = $parents[0];
1120 while (my $line = shift @commit_lines) {
1121 last if $line eq "\n";
1122 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1123 $co{'tree'} = $1;
1124 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1125 $co{'author'} = $1;
1126 $co{'author_epoch'} = $2;
1127 $co{'author_tz'} = $3;
1128 if ($co{'author'} =~ m/^([^<]+) </) {
1129 $co{'author_name'} = $1;
1130 } else {
1131 $co{'author_name'} = $co{'author'};
1132 }
1133 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1134 $co{'committer'} = $1;
1135 $co{'committer_epoch'} = $2;
1136 $co{'committer_tz'} = $3;
1137 $co{'committer_name'} = $co{'committer'};
1138 $co{'committer_name'} =~ s/ <.*//;
1139 }
1140 }
1141 if (!defined $co{'tree'}) {
1142 return;
1143 };
1144
1145 foreach my $title (@commit_lines) {
1146 $title =~ s/^ //;
1147 if ($title ne "") {
1148 $co{'title'} = chop_str($title, 80, 5);
1149 # remove leading stuff of merges to make the interesting part visible
1150 if (length($title) > 50) {
1151 $title =~ s/^Automatic //;
1152 $title =~ s/^merge (of|with) /Merge ... /i;
1153 if (length($title) > 50) {
1154 $title =~ s/(http|rsync):\/\///;
1155 }
1156 if (length($title) > 50) {
1157 $title =~ s/(master|www|rsync)\.//;
1158 }
1159 if (length($title) > 50) {
1160 $title =~ s/kernel.org:?//;
1161 }
1162 if (length($title) > 50) {
1163 $title =~ s/\/pub\/scm//;
1164 }
1165 }
1166 $co{'title_short'} = chop_str($title, 50, 5);
1167 last;
1168 }
1169 }
1170 if ($co{'title'} eq "") {
1171 $co{'title'} = $co{'title_short'} = '(no commit message)';
1172 }
1173 # remove added spaces
1174 foreach my $line (@commit_lines) {
1175 $line =~ s/^ //;
1176 }
1177 $co{'comment'} = \@commit_lines;
1178
1179 my $age = time - $co{'committer_epoch'};
1180 $co{'age'} = $age;
1181 $co{'age_string'} = age_string($age);
1182 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1183 if ($age > 60*60*24*7*2) {
1184 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1185 $co{'age_string_age'} = $co{'age_string'};
1186 } else {
1187 $co{'age_string_date'} = $co{'age_string'};
1188 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1189 }
1190 return %co;
1191 }
1192
1193 # parse ref from ref_file, given by ref_id, with given type
1194 sub parse_ref {
1195 my $ref_file = shift;
1196 my $ref_id = shift;
1197 my $type = shift || git_get_type($ref_id);
1198 my %ref_item;
1199
1200 $ref_item{'type'} = $type;
1201 $ref_item{'id'} = $ref_id;
1202 $ref_item{'epoch'} = 0;
1203 $ref_item{'age'} = "unknown";
1204 if ($type eq "tag") {
1205 my %tag = parse_tag($ref_id);
1206 $ref_item{'comment'} = $tag{'comment'};
1207 if ($tag{'type'} eq "commit") {
1208 my %co = parse_commit($tag{'object'});
1209 $ref_item{'epoch'} = $co{'committer_epoch'};
1210 $ref_item{'age'} = $co{'age_string'};
1211 } elsif (defined($tag{'epoch'})) {
1212 my $age = time - $tag{'epoch'};
1213 $ref_item{'epoch'} = $tag{'epoch'};
1214 $ref_item{'age'} = age_string($age);
1215 }
1216 $ref_item{'reftype'} = $tag{'type'};
1217 $ref_item{'name'} = $tag{'name'};
1218 $ref_item{'refid'} = $tag{'object'};
1219 } elsif ($type eq "commit"){
1220 my %co = parse_commit($ref_id);
1221 $ref_item{'reftype'} = "commit";
1222 $ref_item{'name'} = $ref_file;
1223 $ref_item{'title'} = $co{'title'};
1224 $ref_item{'refid'} = $ref_id;
1225 $ref_item{'epoch'} = $co{'committer_epoch'};
1226 $ref_item{'age'} = $co{'age_string'};
1227 } else {
1228 $ref_item{'reftype'} = $type;
1229 $ref_item{'name'} = $ref_file;
1230 $ref_item{'refid'} = $ref_id;
1231 }
1232
1233 return %ref_item;
1234 }
1235
1236 # parse line of git-diff-tree "raw" output
1237 sub parse_difftree_raw_line {
1238 my $line = shift;
1239 my %res;
1240
1241 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1242 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1243 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1244 $res{'from_mode'} = $1;
1245 $res{'to_mode'} = $2;
1246 $res{'from_id'} = $3;
1247 $res{'to_id'} = $4;
1248 $res{'status'} = $5;
1249 $res{'similarity'} = $6;
1250 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1251 ($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
1252 } else {
1253 $res{'file'} = unquote($7);
1254 }
1255 }
1256 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1257 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1258 $res{'commit'} = $1;
1259 }
1260
1261 return wantarray ? %res : \%res;
1262 }
1263
1264 # parse line of git-ls-tree output
1265 sub parse_ls_tree_line ($;%) {
1266 my $line = shift;
1267 my %opts = @_;
1268 my %res;
1269
1270 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1271 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1272
1273 $res{'mode'} = $1;
1274 $res{'type'} = $2;
1275 $res{'hash'} = $3;
1276 if ($opts{'-z'}) {
1277 $res{'name'} = $4;
1278 } else {
1279 $res{'name'} = unquote($4);
1280 }
1281
1282 return wantarray ? %res : \%res;
1283 }
1284
1285 ## ......................................................................
1286 ## parse to array of hashes functions
1287
1288 sub git_get_refs_list {
1289 my $type = shift || "";
1290 my %refs;
1291 my @reflist;
1292
1293 my @refs;
1294 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1295 or return;
1296 while (my $line = <$fd>) {
1297 chomp $line;
1298 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?([^\^]+))(\^\{\})?$/) {
1299 if (defined $refs{$1}) {
1300 push @{$refs{$1}}, $2;
1301 } else {
1302 $refs{$1} = [ $2 ];
1303 }
1304
1305 if (! $4) { # unpeeled, direct reference
1306 push @refs, { hash => $1, name => $3 }; # without type
1307 } elsif ($3 eq $refs[-1]{'name'}) {
1308 # most likely a tag is followed by its peeled
1309 # (deref) one, and when that happens we know the
1310 # previous one was of type 'tag'.
1311 $refs[-1]{'type'} = "tag";
1312 }
1313 }
1314 }
1315 close $fd;
1316
1317 foreach my $ref (@refs) {
1318 my $ref_file = $ref->{'name'};
1319 my $ref_id = $ref->{'hash'};
1320
1321 my $type = $ref->{'type'} || git_get_type($ref_id) || next;
1322 my %ref_item = parse_ref($ref_file, $ref_id, $type);
1323
1324 push @reflist, \%ref_item;
1325 }
1326 # sort refs by age
1327 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1328 return (\@reflist, \%refs);
1329 }
1330
1331 ## ----------------------------------------------------------------------
1332 ## filesystem-related functions
1333
1334 sub get_file_owner {
1335 my $path = shift;
1336
1337 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1338 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1339 if (!defined $gcos) {
1340 return undef;
1341 }
1342 my $owner = $gcos;
1343 $owner =~ s/[,;].*$//;
1344 return to_utf8($owner);
1345 }
1346
1347 ## ......................................................................
1348 ## mimetype related functions
1349
1350 sub mimetype_guess_file {
1351 my $filename = shift;
1352 my $mimemap = shift;
1353 -r $mimemap or return undef;
1354
1355 my %mimemap;
1356 open(MIME, $mimemap) or return undef;
1357 while (<MIME>) {
1358 next if m/^#/; # skip comments
1359 my ($mime, $exts) = split(/\t+/);
1360 if (defined $exts) {
1361 my @exts = split(/\s+/, $exts);
1362 foreach my $ext (@exts) {
1363 $mimemap{$ext} = $mime;
1364 }
1365 }
1366 }
1367 close(MIME);
1368
1369 $filename =~ /\.([^.]*)$/;
1370 return $mimemap{$1};
1371 }
1372
1373 sub mimetype_guess {
1374 my $filename = shift;
1375 my $mime;
1376 $filename =~ /\./ or return undef;
1377
1378 if ($mimetypes_file) {
1379 my $file = $mimetypes_file;
1380 if ($file !~ m!^/!) { # if it is relative path
1381 # it is relative to project
1382 $file = "$projectroot/$project/$file";
1383 }
1384 $mime = mimetype_guess_file($filename, $file);
1385 }
1386 $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
1387 return $mime;
1388 }
1389
1390 sub blob_mimetype {
1391 my $fd = shift;
1392 my $filename = shift;
1393
1394 if ($filename) {
1395 my $mime = mimetype_guess($filename);
1396 $mime and return $mime;
1397 }
1398
1399 # just in case
1400 return $default_blob_plain_mimetype unless $fd;
1401
1402 if (-T $fd) {
1403 return 'text/plain' .
1404 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1405 } elsif (! $filename) {
1406 return 'application/octet-stream';
1407 } elsif ($filename =~ m/\.png$/i) {
1408 return 'image/png';
1409 } elsif ($filename =~ m/\.gif$/i) {
1410 return 'image/gif';
1411 } elsif ($filename =~ m/\.jpe?g$/i) {
1412 return 'image/jpeg';
1413 } else {
1414 return 'application/octet-stream';
1415 }
1416 }
1417
1418 ## ======================================================================
1419 ## functions printing HTML: header, footer, error page
1420
1421 sub git_header_html {
1422 my $status = shift || "200 OK";
1423 my $expires = shift;
1424
1425 my $title = "$site_name git";
1426 if (defined $project) {
1427 $title .= " - $project";
1428 if (defined $action) {
1429 $title .= "/$action";
1430 if (defined $file_name) {
1431 $title .= " - " . esc_html($file_name);
1432 if ($action eq "tree" && $file_name !~ m|/$|) {
1433 $title .= "/";
1434 }
1435 }
1436 }
1437 }
1438 my $content_type;
1439 # require explicit support from the UA if we are to send the page as
1440 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1441 # we have to do this because MSIE sometimes globs '*/*', pretending to
1442 # support xhtml+xml but choking when it gets what it asked for.
1443 if (defined $cgi->http('HTTP_ACCEPT') &&
1444 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&
1445 $cgi->Accept('application/xhtml+xml') != 0) {
1446 $content_type = 'application/xhtml+xml';
1447 } else {
1448 $content_type = 'text/html';
1449 }
1450 print $cgi->header(-type=>$content_type, -charset => 'utf-8',
1451 -status=> $status, -expires => $expires);
1452 print <<EOF;
1453 <?xml version="1.0" encoding="utf-8"?>
1454 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1455 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1456 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1457 <!-- git core binaries version $git_version -->
1458 <head>
1459 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1460 <meta name="generator" content="gitweb/$version git/$git_version"/>
1461 <meta name="robots" content="index, nofollow"/>
1462 <title>$title</title>
1463 EOF
1464 # print out each stylesheet that exist
1465 if (defined $stylesheet) {
1466 #provides backwards capability for those people who define style sheet in a config file
1467 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1468 } else {
1469 foreach my $stylesheet (@stylesheets) {
1470 next unless $stylesheet;
1471 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1472 }
1473 }
1474 if (defined $project) {
1475 printf('<link rel="alternate" title="%s log" '.
1476 'href="%s" type="application/rss+xml"/>'."\n",
1477 esc_param($project), href(action=>"rss"));
1478 } else {
1479 printf('<link rel="alternate" title="%s projects list" '.
1480 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1481 $site_name, href(project=>undef, action=>"project_index"));
1482 printf('<link rel="alternate" title="%s projects logs" '.
1483 'href="%s" type="text/x-opml"/>'."\n",
1484 $site_name, href(project=>undef, action=>"opml"));
1485 }
1486 if (defined $favicon) {
1487 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1488 }
1489
1490 print "</head>\n" .
1491 "<body>\n";
1492
1493 if (-f $site_header) {
1494 open (my $fd, $site_header);
1495 print <$fd>;
1496 close $fd;
1497 }
1498
1499 print "<div class=\"page_header\">\n" .
1500 $cgi->a({-href => esc_url($logo_url),
1501 -title => $logo_label},
1502 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1503 print $cgi->a({-href => esc_url($home_link)}, $home_link_str) . " / ";
1504 if (defined $project) {
1505 print $cgi->a({-href => href(action=>"summary")}, esc_html($project));
1506 if (defined $action) {
1507 print " / $action";
1508 }
1509 print "\n";
1510 if (!defined $searchtext) {
1511 $searchtext = "";
1512 }
1513 my $search_hash;
1514 if (defined $hash_base) {
1515 $search_hash = $hash_base;
1516 } elsif (defined $hash) {
1517 $search_hash = $hash;
1518 } else {
1519 $search_hash = "HEAD";
1520 }
1521 $cgi->param("a", "search");
1522 $cgi->param("h", $search_hash);
1523 $cgi->param("p", $project);
1524 print $cgi->startform(-method => "get", -action => $my_uri) .
1525 "<div class=\"search\">\n" .
1526 $cgi->hidden(-name => "p") . "\n" .
1527 $cgi->hidden(-name => "a") . "\n" .
1528 $cgi->hidden(-name => "h") . "\n" .
1529 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
1530 "</div>" .
1531 $cgi->end_form() . "\n";
1532 }
1533 print "</div>\n";
1534 }
1535
1536 sub git_footer_html {
1537 print "<div class=\"page_footer\">\n";
1538 if (defined $project) {
1539 my $descr = git_get_project_description($project);
1540 if (defined $descr) {
1541 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
1542 }
1543 print $cgi->a({-href => href(action=>"rss"),
1544 -class => "rss_logo"}, "RSS") . "\n";
1545 } else {
1546 print $cgi->a({-href => href(project=>undef, action=>"opml"),
1547 -class => "rss_logo"}, "OPML") . " ";
1548 print $cgi->a({-href => href(project=>undef, action=>"project_index"),
1549 -class => "rss_logo"}, "TXT") . "\n";
1550 }
1551 print "</div>\n" ;
1552
1553 if (-f $site_footer) {
1554 open (my $fd, $site_footer);
1555 print <$fd>;
1556 close $fd;
1557 }
1558
1559 print "</body>\n" .
1560 "</html>";
1561 }
1562
1563 sub die_error {
1564 my $status = shift || "403 Forbidden";
1565 my $error = shift || "Malformed query, file missing or permission denied";
1566
1567 git_header_html($status);
1568 print <<EOF;
1569 <div class="page_body">
1570 <br /><br />
1571 $status - $error
1572 <br />
1573 </div>
1574 EOF
1575 git_footer_html();
1576 exit;
1577 }
1578
1579 ## ----------------------------------------------------------------------
1580 ## functions printing or outputting HTML: navigation
1581
1582 sub git_print_page_nav {
1583 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1584 $extra = '' if !defined $extra; # pager or formats
1585
1586 my @navs = qw(summary shortlog log commit commitdiff tree);
1587 if ($suppress) {
1588 @navs = grep { $_ ne $suppress } @navs;
1589 }
1590
1591 my %arg = map { $_ => {action=>$_} } @navs;
1592 if (defined $head) {
1593 for (qw(commit commitdiff)) {
1594 $arg{$_}{hash} = $head;
1595 }
1596 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1597 for (qw(shortlog log)) {
1598 $arg{$_}{hash} = $head;
1599 }
1600 }
1601 }
1602 $arg{tree}{hash} = $treehead if defined $treehead;
1603 $arg{tree}{hash_base} = $treebase if defined $treebase;
1604
1605 print "<div class=\"page_nav\">\n" .
1606 (join " | ",
1607 map { $_ eq $current ?
1608 $_ : $cgi->a({-href => href(%{$arg{$_}})}, "$_")
1609 } @navs);
1610 print "<br/>\n$extra<br/>\n" .
1611 "</div>\n";
1612 }
1613
1614 sub format_paging_nav {
1615 my ($action, $hash, $head, $page, $nrevs) = @_;
1616 my $paging_nav;
1617
1618
1619 if ($hash ne $head || $page) {
1620 $paging_nav .= $cgi->a({-href => href(action=>$action)}, "HEAD");
1621 } else {
1622 $paging_nav .= "HEAD";
1623 }
1624
1625 if ($page > 0) {
1626 $paging_nav .= " &sdot; " .
1627 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page-1),
1628 -accesskey => "p", -title => "Alt-p"}, "prev");
1629 } else {
1630 $paging_nav .= " &sdot; prev";
1631 }
1632
1633 if ($nrevs >= (100 * ($page+1)-1)) {
1634 $paging_nav .= " &sdot; " .
1635 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page+1),
1636 -accesskey => "n", -title => "Alt-n"}, "next");
1637 } else {
1638 $paging_nav .= " &sdot; next";
1639 }
1640
1641 return $paging_nav;
1642 }
1643
1644 ## ......................................................................
1645 ## functions printing or outputting HTML: div
1646
1647 sub git_print_header_div {
1648 my ($action, $title, $hash, $hash_base) = @_;
1649 my %args = ();
1650
1651 $args{action} = $action;
1652 $args{hash} = $hash if $hash;
1653 $args{hash_base} = $hash_base if $hash_base;
1654
1655 print "<div class=\"header\">\n" .
1656 $cgi->a({-href => href(%args), -class => "title"},
1657 $title ? $title : $action) .
1658 "\n</div>\n";
1659 }
1660
1661 #sub git_print_authorship (\%) {
1662 sub git_print_authorship {
1663 my $co = shift;
1664
1665 my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
1666 print "<div class=\"author_date\">" .
1667 esc_html($co->{'author_name'}) .
1668 " [$ad{'rfc2822'}";
1669 if ($ad{'hour_local'} < 6) {
1670 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1671 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1672 } else {
1673 printf(" (%02d:%02d %s)",
1674 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1675 }
1676 print "]</div>\n";
1677 }
1678
1679 sub git_print_page_path {
1680 my $name = shift;
1681 my $type = shift;
1682 my $hb = shift;
1683
1684 if (!defined $name) {
1685 print "<div class=\"page_path\">/</div>\n";
1686 } else {
1687 my @dirname = split '/', $name;
1688 my $basename = pop @dirname;
1689 my $fullname = '';
1690
1691 print "<div class=\"page_path\">";
1692 print $cgi->a({-href => href(action=>"tree", hash_base=>$hb),
1693 -title => 'tree root'}, "[$project]");
1694 print " / ";
1695 foreach my $dir (@dirname) {
1696 $fullname .= ($fullname ? '/' : '') . $dir;
1697 print $cgi->a({-href => href(action=>"tree", file_name=>$fullname,
1698 hash_base=>$hb),
1699 -title => $fullname}, esc_html($dir));
1700 print " / ";
1701 }
1702 if (defined $type && $type eq 'blob') {
1703 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,
1704 hash_base=>$hb),
1705 -title => $name}, esc_html($basename));
1706 } elsif (defined $type && $type eq 'tree') {
1707 print $cgi->a({-href => href(action=>"tree", file_name=>$file_name,
1708 hash_base=>$hb),
1709 -title => $name}, esc_html($basename));
1710 } else {
1711 print esc_html($basename);
1712 }
1713 print "<br/></div>\n";
1714 }
1715 }
1716
1717 # sub git_print_log (\@;%) {
1718 sub git_print_log ($;%) {
1719 my $log = shift;
1720 my %opts = @_;
1721
1722 if ($opts{'-remove_title'}) {
1723 # remove title, i.e. first line of log
1724 shift @$log;
1725 }
1726 # remove leading empty lines
1727 while (defined $log->[0] && $log->[0] eq "") {
1728 shift @$log;
1729 }
1730
1731 # print log
1732 my $signoff = 0;
1733 my $empty = 0;
1734 foreach my $line (@$log) {
1735 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1736 $signoff = 1;
1737 $empty = 0;
1738 if (! $opts{'-remove_signoff'}) {
1739 print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
1740 next;
1741 } else {
1742 # remove signoff lines
1743 next;
1744 }
1745 } else {
1746 $signoff = 0;
1747 }
1748
1749 # print only one empty line
1750 # do not print empty line after signoff
1751 if ($line eq "") {
1752 next if ($empty || $signoff);
1753 $empty = 1;
1754 } else {
1755 $empty = 0;
1756 }
1757
1758 print format_log_line_html($line) . "<br/>\n";
1759 }
1760
1761 if ($opts{'-final_empty_line'}) {
1762 # end with single empty line
1763 print "<br/>\n" unless $empty;
1764 }
1765 }
1766
1767 sub git_print_simplified_log {
1768 my $log = shift;
1769 my $remove_title = shift;
1770
1771 git_print_log($log,
1772 -final_empty_line=> 1,
1773 -remove_title => $remove_title);
1774 }
1775
1776 # print tree entry (row of git_tree), but without encompassing <tr> element
1777 sub git_print_tree_entry {
1778 my ($t, $basedir, $hash_base, $have_blame) = @_;
1779
1780 my %base_key = ();
1781 $base_key{hash_base} = $hash_base if defined $hash_base;
1782
1783 # The format of a table row is: mode list link. Where mode is
1784 # the mode of the entry, list is the name of the entry, an href,
1785 # and link is the action links of the entry.
1786
1787 print "<td class=\"mode\">" . mode_str($t->{'mode'}) . "</td>\n";
1788 if ($t->{'type'} eq "blob") {
1789 print "<td class=\"list\">" .
1790 $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
1791 file_name=>"$basedir$t->{'name'}", %base_key),
1792 -class => "list"}, esc_html($t->{'name'})) . "</td>\n";
1793 print "<td class=\"link\">";
1794 if ($have_blame) {
1795 print $cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},
1796 file_name=>"$basedir$t->{'name'}", %base_key)},
1797 "blame");
1798 }
1799 if (defined $hash_base) {
1800 if ($have_blame) {
1801 print " | ";
1802 }
1803 print $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
1804 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},
1805 "history");
1806 }
1807 print " | " .
1808 $cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,
1809 file_name=>"$basedir$t->{'name'}")},
1810 "raw");
1811 print "</td>\n";
1812
1813 } elsif ($t->{'type'} eq "tree") {
1814 print "<td class=\"list\">";
1815 print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
1816 file_name=>"$basedir$t->{'name'}", %base_key)},
1817 esc_html($t->{'name'}));
1818 print "</td>\n";
1819 print "<td class=\"link\">";
1820 if (defined $hash_base) {
1821 print $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
1822 file_name=>"$basedir$t->{'name'}")},
1823 "history");
1824 }
1825 print "</td>\n";
1826 }
1827 }
1828
1829 ## ......................................................................
1830 ## functions printing large fragments of HTML
1831
1832 sub git_difftree_body {
1833 my ($difftree, $hash, $parent) = @_;
1834
1835 print "<div class=\"list_head\">\n";
1836 if ($#{$difftree} > 10) {
1837 print(($#{$difftree} + 1) . " files changed:\n");
1838 }
1839 print "</div>\n";
1840
1841 print "<table class=\"diff_tree\">\n";
1842 my $alternate = 1;
1843 my $patchno = 0;
1844 foreach my $line (@{$difftree}) {
1845 my %diff = parse_difftree_raw_line($line);
1846
1847 if ($alternate) {
1848 print "<tr class=\"dark\">\n";
1849 } else {
1850 print "<tr class=\"light\">\n";
1851 }
1852 $alternate ^= 1;
1853
1854 my ($to_mode_oct, $to_mode_str, $to_file_type);
1855 my ($from_mode_oct, $from_mode_str, $from_file_type);
1856 if ($diff{'to_mode'} ne ('0' x 6)) {
1857 $to_mode_oct = oct $diff{'to_mode'};
1858 if (S_ISREG($to_mode_oct)) { # only for regular file
1859 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1860 }
1861 $to_file_type = file_type($diff{'to_mode'});
1862 }
1863 if ($diff{'from_mode'} ne ('0' x 6)) {
1864 $from_mode_oct = oct $diff{'from_mode'};
1865 if (S_ISREG($to_mode_oct)) { # only for regular file
1866 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1867 }
1868 $from_file_type = file_type($diff{'from_mode'});
1869 }
1870
1871 if ($diff{'status'} eq "A") { # created
1872 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1873 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1874 $mode_chng .= "]</span>";
1875 print "<td>";
1876 print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1877 hash_base=>$hash, file_name=>$diff{'file'}),
1878 -class => "list"}, esc_html($diff{'file'}));
1879 print "</td>\n";
1880 print "<td>$mode_chng</td>\n";
1881 print "<td class=\"link\">";
1882 if ($action eq 'commitdiff') {
1883 # link to patch
1884 $patchno++;
1885 print $cgi->a({-href => "#patch$patchno"}, "patch");
1886 }
1887 print "</td>\n";
1888
1889 } elsif ($diff{'status'} eq "D") { # deleted
1890 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1891 print "<td>";
1892 print $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
1893 hash_base=>$parent, file_name=>$diff{'file'}),
1894 -class => "list"}, esc_html($diff{'file'}));
1895 print "</td>\n";
1896 print "<td>$mode_chng</td>\n";
1897 print "<td class=\"link\">";
1898 if ($action eq 'commitdiff') {
1899 # link to patch
1900 $patchno++;
1901 print $cgi->a({-href => "#patch$patchno"}, "patch");
1902 print " | ";
1903 }
1904 print $cgi->a({-href => href(action=>"blame", hash_base=>$parent,
1905 file_name=>$diff{'file'})},
1906 "blame") . " | ";
1907 print $cgi->a({-href => href(action=>"history", hash_base=>$parent,
1908 file_name=>$diff{'file'})},
1909 "history");
1910 print "</td>\n";
1911
1912 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1913 my $mode_chnge = "";
1914 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1915 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1916 if ($from_file_type != $to_file_type) {
1917 $mode_chnge .= " from $from_file_type to $to_file_type";
1918 }
1919 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1920 if ($from_mode_str && $to_mode_str) {
1921 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1922 } elsif ($to_mode_str) {
1923 $mode_chnge .= " mode: $to_mode_str";
1924 }
1925 }
1926 $mode_chnge .= "]</span>\n";
1927 }
1928 print "<td>";
1929 print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1930 hash_base=>$hash, file_name=>$diff{'file'}),
1931 -class => "list"}, esc_html($diff{'file'}));
1932 print "</td>\n";
1933 print "<td>$mode_chnge</td>\n";
1934 print "<td class=\"link\">";
1935 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1936 if ($action eq 'commitdiff') {
1937 # link to patch
1938 $patchno++;
1939 print $cgi->a({-href => "#patch$patchno"}, "patch");
1940 } else {
1941 print $cgi->a({-href => href(action=>"blobdiff",
1942 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1943 hash_base=>$hash, hash_parent_base=>$parent,
1944 file_name=>$diff{'file'})},
1945 "diff");
1946 }
1947 print " | ";
1948 }
1949 print $cgi->a({-href => href(action=>"blame", hash_base=>$hash,
1950 file_name=>$diff{'file'})},
1951 "blame") . " | ";
1952 print $cgi->a({-href => href(action=>"history", hash_base=>$hash,
1953 file_name=>$diff{'file'})},
1954 "history");
1955 print "</td>\n";
1956
1957 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1958 my %status_name = ('R' => 'moved', 'C' => 'copied');
1959 my $nstatus = $status_name{$diff{'status'}};
1960 my $mode_chng = "";
1961 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1962 # mode also for directories, so we cannot use $to_mode_str
1963 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1964 }
1965 print "<td>" .
1966 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1967 hash=>$diff{'to_id'}, file_name=>$diff{'to_file'}),
1968 -class => "list"}, esc_html($diff{'to_file'})) . "</td>\n" .
1969 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1970 $cgi->a({-href => href(action=>"blob", hash_base=>$parent,
1971 hash=>$diff{'from_id'}, file_name=>$diff{'from_file'}),
1972 -class => "list"}, esc_html($diff{'from_file'})) .
1973 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1974 "<td class=\"link\">";
1975 if ($diff{'to_id'} ne $diff{'from_id'}) {
1976 if ($action eq 'commitdiff') {
1977 # link to patch
1978 $patchno++;
1979 print $cgi->a({-href => "#patch$patchno"}, "patch");
1980 } else {
1981 print $cgi->a({-href => href(action=>"blobdiff",
1982 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1983 hash_base=>$hash, hash_parent_base=>$parent,
1984 file_name=>$diff{'to_file'}, file_parent=>$diff{'from_file'})},
1985 "diff");
1986 }
1987 print " | ";
1988 }
1989 print $cgi->a({-href => href(action=>"blame", hash_base=>$parent,
1990 file_name=>$diff{'from_file'})},
1991 "blame") . " | ";
1992 print $cgi->a({-href => href(action=>"history", hash_base=>$parent,
1993 file_name=>$diff{'from_file'})},
1994 "history");
1995 print "</td>\n";
1996
1997 } # we should not encounter Unmerged (U) or Unknown (X) status
1998 print "</tr>\n";
1999 }
2000 print "</table>\n";
2001 }
2002
2003 sub git_patchset_body {
2004 my ($fd, $difftree, $hash, $hash_parent) = @_;
2005
2006 my $patch_idx = 0;
2007 my $in_header = 0;
2008 my $patch_found = 0;
2009 my $diffinfo;
2010
2011 print "<div class=\"patchset\">\n";
2012
2013 LINE:
2014 while (my $patch_line = <$fd>) {
2015 chomp $patch_line;
2016
2017 if ($patch_line =~ m/^diff /) { # "git diff" header
2018 # beginning of patch (in patchset)
2019 if ($patch_found) {
2020 # close previous patch
2021 print "</div>\n"; # class="patch"
2022 } else {
2023 # first patch in patchset
2024 $patch_found = 1;
2025 }
2026 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2027
2028 if (ref($difftree->[$patch_idx]) eq "HASH") {
2029 $diffinfo = $difftree->[$patch_idx];
2030 } else {
2031 $diffinfo = parse_difftree_raw_line($difftree->[$patch_idx]);
2032 }
2033 $patch_idx++;
2034
2035 # for now, no extended header, hence we skip empty patches
2036 # companion to next LINE if $in_header;
2037 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
2038 $in_header = 1;
2039 next LINE;
2040 }
2041
2042 if ($diffinfo->{'status'} eq "A") { # added
2043 print "<div class=\"diff_info\">" . file_type($diffinfo->{'to_mode'}) . ":" .
2044 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
2045 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'file'})},
2046 $diffinfo->{'to_id'}) . " (new)" .
2047 "</div>\n"; # class="diff_info"
2048
2049 } elsif ($diffinfo->{'status'} eq "D") { # deleted
2050 print "<div class=\"diff_info\">" . file_type($diffinfo->{'from_mode'}) . ":" .
2051 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
2052 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'file'})},
2053 $diffinfo->{'from_id'}) . " (deleted)" .
2054 "</div>\n"; # class="diff_info"
2055
2056 } elsif ($diffinfo->{'status'} eq "R" || # renamed
2057 $diffinfo->{'status'} eq "C" || # copied
2058 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
2059 print "<div class=\"diff_info\">" .
2060 file_type($diffinfo->{'from_mode'}) . ":" .
2061 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
2062 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'from_file'})},
2063 $diffinfo->{'from_id'}) .
2064 " -> " .
2065 file_type($diffinfo->{'to_mode'}) . ":" .
2066 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
2067 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'to_file'})},
2068 $diffinfo->{'to_id'});
2069 print "</div>\n"; # class="diff_info"
2070
2071 } else { # modified, mode changed, ...
2072 print "<div class=\"diff_info\">" .
2073 file_type($diffinfo->{'from_mode'}) . ":" .
2074 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
2075 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'file'})},
2076 $diffinfo->{'from_id'}) .
2077 " -> " .
2078 file_type($diffinfo->{'to_mode'}) . ":" .
2079 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
2080 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'file'})},
2081 $diffinfo->{'to_id'});
2082 print "</div>\n"; # class="diff_info"
2083 }
2084
2085 #print "<div class=\"diff extended_header\">\n";
2086 $in_header = 1;
2087 next LINE;
2088 } # start of patch in patchset
2089
2090
2091 if ($in_header && $patch_line =~ m/^---/) {
2092 #print "</div>\n"; # class="diff extended_header"
2093 $in_header = 0;
2094
2095 my $file = $diffinfo->{'from_file'};
2096 $file ||= $diffinfo->{'file'};
2097 $file = $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
2098 hash=>$diffinfo->{'from_id'}, file_name=>$file),
2099 -class => "list"}, esc_html($file));
2100 $patch_line =~ s|a/.*$|a/$file|g;
2101 print "<div class=\"diff from_file\">$patch_line</div>\n";
2102
2103 $patch_line = <$fd>;
2104 chomp $patch_line;
2105
2106 #$patch_line =~ m/^+++/;
2107 $file = $diffinfo->{'to_file'};
2108 $file ||= $diffinfo->{'file'};
2109 $file = $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
2110 hash=>$diffinfo->{'to_id'}, file_name=>$file),
2111 -class => "list"}, esc_html($file));
2112 $patch_line =~ s|b/.*|b/$file|g;
2113 print "<div class=\"diff to_file\">$patch_line</div>\n";
2114
2115 next LINE;
2116 }
2117 next LINE if $in_header;
2118
2119 print format_diff_line($patch_line);
2120 }
2121 print "</div>\n" if $patch_found; # class="patch"
2122
2123 print "</div>\n"; # class="patchset"
2124 }
2125
2126 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2127
2128 sub git_shortlog_body {
2129 # uses global variable $project
2130 my ($revlist, $from, $to, $refs, $extra) = @_;
2131
2132 $from = 0 unless defined $from;
2133 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2134
2135 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2136 my $alternate = 1;
2137 for (my $i = $from; $i <= $to; $i++) {
2138 my $commit = $revlist->[$i];
2139 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2140 my $ref = format_ref_marker($refs, $commit);
2141 my %co = parse_commit($commit);
2142 if ($alternate) {
2143 print "<tr class=\"dark\">\n";
2144 } else {
2145 print "<tr class=\"light\">\n";
2146 }
2147 $alternate ^= 1;
2148 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2149 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2150 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
2151 "<td>";
2152 print format_subject_html($co{'title'}, $co{'title_short'},
2153 href(action=>"commit", hash=>$commit), $ref);
2154 print "</td>\n" .
2155 "<td class=\"link\">" .
2156 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
2157 $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree");
2158 if (gitweb_have_snapshot()) {
2159 print " | " . $cgi->a({-href => href(action=>"snapshot", hash=>$commit)}, "snapshot");
2160 }
2161 print "</td>\n" .
2162 "</tr>\n";
2163 }
2164 if (defined $extra) {
2165 print "<tr>\n" .
2166 "<td colspan=\"4\">$extra</td>\n" .
2167 "</tr>\n";
2168 }
2169 print "</table>\n";
2170 }
2171
2172 sub git_history_body {
2173 # Warning: assumes constant type (blob or tree) during history
2174 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2175
2176 $from = 0 unless defined $from;
2177 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2178
2179 print "<table class=\"history\" cellspacing=\"0\">\n";
2180 my $alternate = 1;
2181 for (my $i = $from; $i <= $to; $i++) {
2182 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2183 next;
2184 }
2185
2186 my $commit = $1;
2187 my %co = parse_commit($commit);
2188 if (!%co) {
2189 next;
2190 }
2191
2192 my $ref = format_ref_marker($refs, $commit);
2193
2194 if ($alternate) {
2195 print "<tr class=\"dark\">\n";
2196 } else {
2197 print "<tr class=\"light\">\n";
2198 }
2199 $alternate ^= 1;
2200 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2201 # shortlog uses chop_str($co{'author_name'}, 10)
2202 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2203 "<td>";
2204 # originally git_history used chop_str($co{'title'}, 50)
2205 print format_subject_html($co{'title'}, $co{'title_short'},
2206 href(action=>"commit", hash=>$commit), $ref);
2207 print "</td>\n" .
2208 "<td class=\"link\">" .
2209 $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype) . " | " .
2210 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff");
2211
2212 if ($ftype eq 'blob') {
2213 my $blob_current = git_get_hash_by_path($hash_base, $file_name);
2214 my $blob_parent = git_get_hash_by_path($commit, $file_name);
2215 if (defined $blob_current && defined $blob_parent &&
2216 $blob_current ne $blob_parent) {
2217 print " | " .
2218 $cgi->a({-href => href(action=>"blobdiff",
2219 hash=>$blob_current, hash_parent=>$blob_parent,
2220 hash_base=>$hash_base, hash_parent_base=>$commit,
2221 file_name=>$file_name)},
2222 "diff to current");
2223 }
2224 }
2225 print "</td>\n" .
2226 "</tr>\n";
2227 }
2228 if (defined $extra) {
2229 print "<tr>\n" .
2230 "<td colspan=\"4\">$extra</td>\n" .
2231 "</tr>\n";
2232 }
2233 print "</table>\n";
2234 }
2235
2236 sub git_tags_body {
2237 # uses global variable $project
2238 my ($taglist, $from, $to, $extra) = @_;
2239 $from = 0 unless defined $from;
2240 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2241
2242 print "<table class=\"tags\" cellspacing=\"0\">\n";
2243 my $alternate = 1;
2244 for (my $i = $from; $i <= $to; $i++) {
2245 my $entry = $taglist->[$i];
2246 my %tag = %$entry;
2247 my $comment_lines = $tag{'comment'};
2248 my $comment = shift @$comment_lines;
2249 my $comment_short;
2250 if (defined $comment) {
2251 $comment_short = chop_str($comment, 30, 5);
2252 }
2253 if ($alternate) {
2254 print "<tr class=\"dark\">\n";
2255 } else {
2256 print "<tr class=\"light\">\n";
2257 }
2258 $alternate ^= 1;
2259 print "<td><i>$tag{'age'}</i></td>\n" .
2260 "<td>" .
2261 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),
2262 -class => "list name"}, esc_html($tag{'name'})) .
2263 "</td>\n" .
2264 "<td>";
2265 if (defined $comment) {
2266 print format_subject_html($comment, $comment_short,
2267 href(action=>"tag", hash=>$tag{'id'}));
2268 }
2269 print "</td>\n" .
2270 "<td class=\"selflink\">";
2271 if ($tag{'type'} eq "tag") {
2272 print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag");
2273 } else {
2274 print "&nbsp;";
2275 }
2276 print "</td>\n" .
2277 "<td class=\"link\">" . " | " .
2278 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'});
2279 if ($tag{'reftype'} eq "commit") {
2280 print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") .
2281 " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'refid'})}, "log");
2282 } elsif ($tag{'reftype'} eq "blob") {
2283 print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw");
2284 }
2285 print "</td>\n" .
2286 "</tr>";
2287 }
2288 if (defined $extra) {
2289 print "<tr>\n" .
2290 "<td colspan=\"5\">$extra</td>\n" .
2291 "</tr>\n";
2292 }
2293 print "</table>\n";
2294 }
2295
2296 sub git_heads_body {
2297 # uses global variable $project
2298 my ($headlist, $head, $from, $to, $extra) = @_;
2299 $from = 0 unless defined $from;
2300 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2301
2302 print "<table class=\"heads\" cellspacing=\"0\">\n";
2303 my $alternate = 1;
2304 for (my $i = $from; $i <= $to; $i++) {
2305 my $entry = $headlist->[$i];
2306 my %tag = %$entry;
2307 my $curr = $tag{'id'} eq $head;
2308 if ($alternate) {
2309 print "<tr class=\"dark\">\n";
2310 } else {
2311 print "<tr class=\"light\">\n";
2312 }
2313 $alternate ^= 1;
2314 print "<td><i>$tag{'age'}</i></td>\n" .
2315 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
2316 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'}),
2317 -class => "list name"},esc_html($tag{'name'})) .
2318 "</td>\n" .
2319 "<td class=\"link\">" .
2320 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") . " | " .
2321 $cgi->a({-href => href(action=>"log", hash=>$tag{'name'})}, "log") . " | " .
2322 $cgi->a({-href => href(action=>"tree", hash=>$tag{'name'}, hash_base=>$tag{'name'})}, "tree") .
2323 "</td>\n" .
2324 "</tr>";
2325 }
2326 if (defined $extra) {
2327 print "<tr>\n" .
2328 "<td colspan=\"3\">$extra</td>\n" .
2329 "</tr>\n";
2330 }
2331 print "</table>\n";
2332 }
2333
2334 ## ======================================================================
2335 ## ======================================================================
2336 ## actions
2337
2338 sub git_project_list {
2339 my $order = $cgi->param('o');
2340 if (defined $order && $order !~ m/project|descr|owner|age/) {
2341 die_error(undef, "Unknown order parameter");
2342 }
2343
2344 my @list = git_get_projects_list();
2345 my @projects;
2346 if (!@list) {
2347 die_error(undef, "No projects found");
2348 }
2349 foreach my $pr (@list) {
2350 my (@aa) = git_get_last_activity($pr->{'path'});
2351 unless (@aa) {
2352 next;
2353 }
2354 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2355 if (!defined $pr->{'descr'}) {
2356 my $descr = git_get_project_description($pr->{'path'}) || "";
2357 $pr->{'descr'} = chop_str($descr, 25, 5);
2358 }
2359 if (!defined $pr->{'owner'}) {
2360 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
2361 }
2362 push @projects, $pr;
2363 }
2364
2365 git_header_html();
2366 if (-f $home_text) {
2367 print "<div class=\"index_include\">\n";
2368 open (my $fd, $home_text);
2369 print <$fd>;
2370 close $fd;
2371 print "</div>\n";
2372 }
2373 print "<table class=\"project_list\">\n" .
2374 "<tr>\n";
2375 $order ||= "project";
2376 if ($order eq "project") {
2377 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2378 print "<th>Project</th>\n";
2379 } else {
2380 print "<th>" .
2381 $cgi->a({-href => href(project=>undef, order=>'project'),
2382 -class => "header"}, "Project") .
2383 "</th>\n";
2384 }
2385 if ($order eq "descr") {
2386 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2387 print "<th>Description</th>\n";
2388 } else {
2389 print "<th>" .
2390 $cgi->a({-href => href(project=>undef, order=>'descr'),
2391 -class => "header"}, "Description") .
2392 "</th>\n";
2393 }
2394 if ($order eq "owner") {
2395 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2396 print "<th>Owner</th>\n";
2397 } else {
2398 print "<th>" .
2399 $cgi->a({-href => href(project=>undef, order=>'owner'),
2400 -class => "header"}, "Owner") .
2401 "</th>\n";
2402 }
2403 if ($order eq "age") {
2404 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2405 print "<th>Last Change</th>\n";
2406 } else {
2407 print "<th>" .
2408 $cgi->a({-href => href(project=>undef, order=>'age'),
2409 -class => "header"}, "Last Change") .
2410 "</th>\n";
2411 }
2412 print "<th></th>\n" .
2413 "</tr>\n";
2414 my $alternate = 1;
2415 foreach my $pr (@projects) {
2416 if ($alternate) {
2417 print "<tr class=\"dark\">\n";
2418 } else {
2419 print "<tr class=\"light\">\n";
2420 }
2421 $alternate ^= 1;
2422 print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
2423 -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
2424 "<td>" . esc_html($pr->{'descr'}) . "</td>\n" .
2425 "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
2426 print "<td class=\"". age_class($pr->{'age'}) . "\">" .
2427 $pr->{'age_string'} . "</td>\n" .
2428 "<td class=\"link\">" .
2429 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
2430 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
2431 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") . " | " .
2432 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")}, "tree") .
2433 "</td>\n" .
2434 "</tr>\n";
2435 }
2436 print "</table>\n";
2437 git_footer_html();
2438 }
2439
2440 sub git_project_index {
2441 my @projects = git_get_projects_list();
2442
2443 print $cgi->header(
2444 -type => 'text/plain',
2445 -charset => 'utf-8',
2446 -content_disposition => 'inline; filename="index.aux"');
2447
2448 foreach my $pr (@projects) {
2449 if (!exists $pr->{'owner'}) {
2450 $pr->{'owner'} = get_file_owner("$projectroot/$project");
2451 }
2452
2453 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2454 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2455 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
2456 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
2457 $path =~ s/ /\+/g;
2458 $owner =~ s/ /\+/g;
2459
2460 print "$path $owner\n";
2461 }
2462 }
2463
2464 sub git_summary {
2465 my $descr = git_get_project_description($project) || "none";
2466 my $head = git_get_head_hash($project);
2467 my %co = parse_commit($head);
2468 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
2469
2470 my $owner = git_get_project_owner($project);
2471
2472 my ($reflist, $refs) = git_get_refs_list();
2473
2474 my @taglist;
2475 my @headlist;
2476 foreach my $ref (@$reflist) {
2477 if ($ref->{'name'} =~ s!^heads/!!) {
2478 push @headlist, $ref;
2479 } else {
2480 $ref->{'name'} =~ s!^tags/!!;
2481 push @taglist, $ref;
2482 }
2483 }
2484
2485 git_header_html();
2486 git_print_page_nav('summary','', $head);
2487
2488 print "<div class=\"title\">&nbsp;</div>\n";
2489 print "<table cellspacing=\"0\">\n" .
2490 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
2491 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2492 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2493 # use per project git URL list in $projectroot/$project/cloneurl
2494 # or make project git URL from git base URL and project name
2495 my $url_tag = "URL";
2496 my @url_list = git_get_project_url_list($project);
2497 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2498 foreach my $git_url (@url_list) {
2499 next unless $git_url;
2500 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2501 $url_tag = "";
2502 }
2503 print "</table>\n";
2504
2505 open my $fd, "-|", git_cmd(), "rev-list", "--max-count=17",
2506 git_get_head_hash($project)
2507 or die_error(undef, "Open git-rev-list failed");
2508 my @revlist = map { chomp; $_ } <$fd>;
2509 close $fd;
2510 git_print_header_div('shortlog');
2511 git_shortlog_body(\@revlist, 0, 15, $refs,
2512 $cgi->a({-href => href(action=>"shortlog")}, "..."));
2513
2514 if (@taglist) {
2515 git_print_header_div('tags');
2516 git_tags_body(\@taglist, 0, 15,
2517 $cgi->a({-href => href(action=>"tags")}, "..."));
2518 }
2519
2520 if (@headlist) {
2521 git_print_header_div('heads');
2522 git_heads_body(\@headlist, $head, 0, 15,
2523 $cgi->a({-href => href(action=>"heads")}, "..."));
2524 }
2525
2526 git_footer_html();
2527 }
2528
2529 sub git_tag {
2530 my $head = git_get_head_hash($project);
2531 git_header_html();
2532 git_print_page_nav('','', $head,undef,$head);
2533 my %tag = parse_tag($hash);
2534 git_print_header_div('commit', esc_html($tag{'name'}), $hash);
2535 print "<div class=\"title_text\">\n" .
2536 "<table cellspacing=\"0\">\n" .
2537 "<tr>\n" .
2538 "<td>object</td>\n" .
2539 "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
2540 $tag{'object'}) . "</td>\n" .
2541 "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
2542 $tag{'type'}) . "</td>\n" .
2543 "</tr>\n";
2544 if (defined($tag{'author'})) {
2545 my %ad = parse_date($tag{'epoch'}, $tag{'tz'});
2546 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
2547 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2548 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2549 "</td></tr>\n";
2550 }
2551 print "</table>\n\n" .
2552 "</div>\n";
2553 print "<div class=\"page_body\">";
2554 my $comment = $tag{'comment'};
2555 foreach my $line (@$comment) {
2556 print esc_html($line) . "<br/>\n";
2557 }
2558 print "</div>\n";
2559 git_footer_html();
2560 }
2561
2562 sub git_blame2 {
2563 my $fd;
2564 my $ftype;
2565
2566 my ($have_blame) = gitweb_check_feature('blame');
2567 if (!$have_blame) {
2568 die_error('403 Permission denied', "Permission denied");
2569 }
2570 die_error('404 Not Found', "File name not defined") if (!$file_name);
2571 $hash_base ||= git_get_head_hash($project);
2572 die_error(undef, "Couldn't find base commit") unless ($hash_base);
2573 my %co = parse_commit($hash_base)
2574 or die_error(undef, "Reading commit failed");
2575 if (!defined $hash) {
2576 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
2577 or die_error(undef, "Error looking up file");
2578 }
2579 $ftype = git_get_type($hash);
2580 if ($ftype !~ "blob") {
2581 die_error("400 Bad Request", "Object is not a blob");
2582 }
2583 open ($fd, "-|", git_cmd(), "blame", '-p', '--',
2584 $file_name, $hash_base)
2585 or die_error(undef, "Open git-blame failed");
2586 git_header_html();
2587 my $formats_nav =
2588 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2589 "blob") .
2590 " | " .
2591 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2592 "history") .
2593 " | " .
2594 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
2595 "HEAD");
2596 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2597 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2598 git_print_page_path($file_name, $ftype, $hash_base);
2599 my @rev_color = (qw(light2 dark2));
2600 my $num_colors = scalar(@rev_color);
2601 my $current_color = 0;
2602 my $last_rev;
2603 print <<HTML;
2604 <div class="page_body">
2605 <table class="blame">
2606 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2607 HTML
2608 my %metainfo = ();
2609 while (1) {
2610 $_ = <$fd>;
2611 last unless defined $_;
2612 my ($full_rev, $orig_lineno, $lineno, $group_size) =
2613 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
2614 if (!exists $metainfo{$full_rev}) {
2615 $metainfo{$full_rev} = {};
2616 }
2617 my $meta = $metainfo{$full_rev};
2618 while (<$fd>) {
2619 last if (s/^\t//);
2620 if (/^(\S+) (.*)$/) {
2621 $meta->{$1} = $2;
2622 }
2623 }
2624 my $data = $_;
2625 my $rev = substr($full_rev, 0, 8);
2626 my $author = $meta->{'author'};
2627 my %date = parse_date($meta->{'author-time'},
2628 $meta->{'author-tz'});
2629 my $date = $date{'iso-tz'};
2630 if ($group_size) {
2631 $current_color = ++$current_color % $num_colors;
2632 }
2633 print "<tr class=\"$rev_color[$current_color]\">\n";
2634 if ($group_size) {
2635 print "<td class=\"sha1\"";
2636 print " title=\"$author, $date\"";
2637 print " rowspan=\"$group_size\"" if ($group_size > 1);
2638 print ">";
2639 print $cgi->a({-href => href(action=>"commit",
2640 hash=>$full_rev,
2641 file_name=>$file_name)},
2642 esc_html($rev));
2643 print "</td>\n";
2644 }
2645 my $blamed = href(action => 'blame',
2646 file_name => $meta->{'filename'},
2647 hash_base => $full_rev);
2648 print "<td class=\"linenr\">";
2649 print $cgi->a({ -href => "$blamed#l$orig_lineno",
2650 -id => "l$lineno",
2651 -class => "linenr" },
2652 esc_html($lineno));
2653 print "</td>";
2654 print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
2655 print "</tr>\n";
2656 }
2657 print "</table>\n";
2658 print "</div>";
2659 close $fd
2660 or print "Reading blob failed\n";
2661 git_footer_html();
2662 }
2663
2664 sub git_blame {
2665 my $fd;
2666
2667 my ($have_blame) = gitweb_check_feature('blame');
2668 if (!$have_blame) {
2669 die_error('403 Permission denied', "Permission denied");
2670 }
2671 die_error('404 Not Found', "File name not defined") if (!$file_name);
2672 $hash_base ||= git_get_head_hash($project);
2673 die_error(undef, "Couldn't find base commit") unless ($hash_base);
2674 my %co = parse_commit($hash_base)
2675 or die_error(undef, "Reading commit failed");
2676 if (!defined $hash) {
2677 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
2678 or die_error(undef, "Error lookup file");
2679 }
2680 open ($fd, "-|", git_cmd(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2681 or die_error(undef, "Open git-annotate failed");
2682 git_header_html();
2683 my $formats_nav =
2684 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2685 "blob") .
2686 " | " .
2687 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2688 "history") .
2689 " | " .
2690 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
2691 "HEAD");
2692 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2693 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2694 git_print_page_path($file_name, 'blob', $hash_base);
2695 print "<div class=\"page_body\">\n";
2696 print <<HTML;
2697 <table class="blame">
2698 <tr>
2699 <th>Commit</th>
2700 <th>Age</th>
2701 <th>Author</th>
2702 <th>Line</th>
2703 <th>Data</th>
2704 </tr>
2705 HTML
2706 my @line_class = (qw(light dark));
2707 my $line_class_len = scalar (@line_class);
2708 my $line_class_num = $#line_class;
2709 while (my $line = <$fd>) {
2710 my $long_rev;
2711 my $short_rev;
2712 my $author;
2713 my $time;
2714 my $lineno;
2715 my $data;
2716 my $age;
2717 my $age_str;
2718 my $age_class;
2719
2720 chomp $line;
2721 $line_class_num = ($line_class_num + 1) % $line_class_len;
2722
2723 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2724 $long_rev = $1;
2725 $author = $2;
2726 $time = $3;
2727 $lineno = $4;
2728 $data = $5;
2729 } else {
2730 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
2731 next;
2732 }
2733 $short_rev = substr ($long_rev, 0, 8);
2734 $age = time () - $time;
2735 $age_str = age_string ($age);
2736 $age_str =~ s/ /&nbsp;/g;
2737 $age_class = age_class($age);
2738 $author = esc_html ($author);
2739 $author =~ s/ /&nbsp;/g;
2740
2741 $data = untabify($data);
2742 $data = esc_html ($data);
2743
2744 print <<HTML;
2745 <tr class="$line_class[$line_class_num]">
2746 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2747 <td class="$age_class">$age_str</td>
2748 <td>$author</td>
2749 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2750 <td class="pre">$data</td>
2751 </tr>
2752 HTML
2753 } # while (my $line = <$fd>)
2754 print "</table>\n\n";
2755 close $fd
2756 or print "Reading blob failed.\n";
2757 print "</div>";
2758 git_footer_html();
2759 }
2760
2761 sub git_tags {
2762 my $head = git_get_head_hash($project);
2763 git_header_html();
2764 git_print_page_nav('','', $head,undef,$head);
2765 git_print_header_div('summary', $project);
2766
2767 my ($taglist) = git_get_refs_list("tags");
2768 if (@$taglist) {
2769 git_tags_body($taglist);
2770 }
2771 git_footer_html();
2772 }
2773
2774 sub git_heads {
2775 my $head = git_get_head_hash($project);
2776 git_header_html();
2777 git_print_page_nav('','', $head,undef,$head);
2778 git_print_header_div('summary', $project);
2779
2780 my ($headlist) = git_get_refs_list("heads");
2781 if (@$headlist) {
2782 git_heads_body($headlist, $head);
2783 }
2784 git_footer_html();
2785 }
2786
2787 sub git_blob_plain {
2788 my $expires;
2789
2790 if (!defined $hash) {
2791 if (defined $file_name) {
2792 my $base = $hash_base || git_get_head_hash($project);
2793 $hash = git_get_hash_by_path($base, $file_name, "blob")
2794 or die_error(undef, "Error lookup file");
2795 } else {
2796 die_error(undef, "No file name defined");
2797 }
2798 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2799 # blobs defined by non-textual hash id's can be cached
2800 $expires = "+1d";
2801 }
2802
2803 my $type = shift;
2804 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
2805 or die_error(undef, "Couldn't cat $file_name, $hash");
2806
2807 $type ||= blob_mimetype($fd, $file_name);
2808
2809 # save as filename, even when no $file_name is given
2810 my $save_as = "$hash";
2811 if (defined $file_name) {
2812 $save_as = $file_name;
2813 } elsif ($type =~ m/^text\//) {
2814 $save_as .= '.txt';
2815 }
2816
2817 print $cgi->header(
2818 -type => "$type",
2819 -expires=>$expires,
2820 -content_disposition => 'inline; filename="' . "$save_as" . '"');
2821 undef $/;
2822 binmode STDOUT, ':raw';
2823 print <$fd>;
2824 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
2825 $/ = "\n";
2826 close $fd;
2827 }
2828
2829 sub git_blob {
2830 my $expires;
2831
2832 if (!defined $hash) {
2833 if (defined $file_name) {
2834 my $base = $hash_base || git_get_head_hash($project);
2835 $hash = git_get_hash_by_path($base, $file_name, "blob")
2836 or die_error(undef, "Error lookup file");
2837 } else {
2838 die_error(undef, "No file name defined");
2839 }
2840 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2841 # blobs defined by non-textual hash id's can be cached
2842 $expires = "+1d";
2843 }
2844
2845 my ($have_blame) = gitweb_check_feature('blame');
2846 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
2847 or die_error(undef, "Couldn't cat $file_name, $hash");
2848 my $mimetype = blob_mimetype($fd, $file_name);
2849 if ($mimetype !~ m/^text\//) {
2850 close $fd;
2851 return git_blob_plain($mimetype);
2852 }
2853 git_header_html(undef, $expires);
2854 my $formats_nav = '';
2855 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2856 if (defined $file_name) {
2857 if ($have_blame) {
2858 $formats_nav .=
2859 $cgi->a({-href => href(action=>"blame", hash_base=>$hash_base,
2860 hash=>$hash, file_name=>$file_name)},
2861 "blame") .
2862 " | ";
2863 }
2864 $formats_nav .=
2865 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
2866 hash=>$hash, file_name=>$file_name)},
2867 "history") .
2868 " | " .
2869 $cgi->a({-href => href(action=>"blob_plain",
2870 hash=>$hash, file_name=>$file_name)},
2871 "raw") .
2872 " | " .
2873 $cgi->a({-href => href(action=>"blob",
2874 hash_base=>"HEAD", file_name=>$file_name)},
2875 "HEAD");
2876 } else {
2877 $formats_nav .=
2878 $cgi->a({-href => href(action=>"blob_plain", hash=>$hash)}, "raw");
2879 }
2880 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2881 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2882 } else {
2883 print "<div class=\"page_nav\">\n" .
2884 "<br/><br/></div>\n" .
2885 "<div class=\"title\">$hash</div>\n";
2886 }
2887 git_print_page_path($file_name, "blob", $hash_base);
2888 print "<div class=\"page_body\">\n";
2889 my $nr;
2890 while (my $line = <$fd>) {
2891 chomp $line;
2892 $nr++;
2893 $line = untabify($line);
2894 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2895 $nr, $nr, $nr, esc_html($line);
2896 }
2897 close $fd
2898 or print "Reading blob failed.\n";
2899 print "</div>";
2900 git_footer_html();
2901 }
2902
2903 sub git_tree {
2904 my $have_snapshot = gitweb_have_snapshot();
2905
2906 if (!defined $hash_base) {
2907 $hash_base = "HEAD";
2908 }
2909 if (!defined $hash) {
2910 if (defined $file_name) {
2911 $hash = git_get_hash_by_path($hash_base, $file_name, "tree");
2912 } else {
2913 $hash = $hash_base;
2914 }
2915 }
2916 $/ = "\0";
2917 open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
2918 or die_error(undef, "Open git-ls-tree failed");
2919 my @entries = map { chomp; $_ } <$fd>;
2920 close $fd or die_error(undef, "Reading tree failed");
2921 $/ = "\n";
2922
2923 my $refs = git_get_references();
2924 my $ref = format_ref_marker($refs, $hash_base);
2925 git_header_html();
2926 my $base = "";
2927 my ($have_blame) = gitweb_check_feature('blame');
2928 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2929 my @views_nav = ();
2930 if (defined $file_name) {
2931 push @views_nav,
2932 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
2933 hash=>$hash, file_name=>$file_name)},
2934 "history"),
2935 $cgi->a({-href => href(action=>"tree",
2936 hash_base=>"HEAD", file_name=>$file_name)},
2937 "HEAD"),
2938 }
2939 if ($have_snapshot) {
2940 # FIXME: Should be available when we have no hash base as well.
2941 push @views_nav,
2942 $cgi->a({-href => href(action=>"snapshot", hash=>$hash)},
2943 "snapshot");
2944 }
2945 git_print_page_nav('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
2946 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
2947 } else {
2948 undef $hash_base;
2949 print "<div class=\"page_nav\">\n";
2950 print "<br/><br/></div>\n";
2951 print "<div class=\"title\">$hash</div>\n";
2952 }
2953 if (defined $file_name) {
2954 $base = esc_html("$file_name/");
2955 }
2956 git_print_page_path($file_name, 'tree', $hash_base);
2957 print "<div class=\"page_body\">\n";
2958 print "<table cellspacing=\"0\">\n";
2959 my $alternate = 1;
2960 foreach my $line (@entries) {
2961 my %t = parse_ls_tree_line($line, -z => 1);
2962
2963 if ($alternate) {
2964 print "<tr class=\"dark\">\n";
2965 } else {
2966 print "<tr class=\"light\">\n";
2967 }
2968 $alternate ^= 1;
2969
2970 git_print_tree_entry(\%t, $base, $hash_base, $have_blame);
2971
2972 print "</tr>\n";
2973 }
2974 print "</table>\n" .
2975 "</div>";
2976 git_footer_html();
2977 }
2978
2979 sub git_snapshot {
2980 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
2981 my $have_snapshot = (defined $ctype && defined $suffix);
2982 if (!$have_snapshot) {
2983 die_error('403 Permission denied', "Permission denied");
2984 }
2985
2986 if (!defined $hash) {
2987 $hash = git_get_head_hash($project);
2988 }
2989
2990 my $filename = basename($project) . "-$hash.tar.$suffix";
2991
2992 print $cgi->header(
2993 -type => 'application/x-tar',
2994 -content_encoding => $ctype,
2995 -content_disposition => 'inline; filename="' . "$filename" . '"',
2996 -status => '200 OK');
2997
2998 my $git = git_cmd_str();
2999 my $name = $project;
3000 $name =~ s/\047/\047\\\047\047/g;
3001 open my $fd, "-|",
3002 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3003 or die_error(undef, "Execute git-tar-tree failed.");
3004 binmode STDOUT, ':raw';
3005 print <$fd>;
3006 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
3007 close $fd;
3008
3009 }
3010
3011 sub git_log {
3012 my $head = git_get_head_hash($project);
3013 if (!defined $hash) {
3014 $hash = $head;
3015 }
3016 if (!defined $page) {
3017 $page = 0;
3018 }
3019 my $refs = git_get_references();
3020
3021 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3022 open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash
3023 or die_error(undef, "Open git-rev-list failed");
3024 my @revlist = map { chomp; $_ } <$fd>;
3025 close $fd;
3026
3027 my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#revlist);
3028
3029 git_header_html();
3030 git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
3031
3032 if (!@revlist) {
3033 my %co = parse_commit($hash);
3034
3035 git_print_header_div('summary', $project);
3036 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3037 }
3038 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
3039 my $commit = $revlist[$i];
3040 my $ref = format_ref_marker($refs, $commit);
3041 my %co = parse_commit($commit);
3042 next if !%co;
3043 my %ad = parse_date($co{'author_epoch'});
3044 git_print_header_div('commit',
3045 "<span class=\"age\">$co{'age_string'}</span>" .
3046 esc_html($co{'title'}) . $ref,
3047 $commit);
3048 print "<div class=\"title_text\">\n" .
3049 "<div class=\"log_link\">\n" .
3050 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
3051 " | " .
3052 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
3053 " | " .
3054 $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree") .
3055 "<br/>\n" .
3056 "</div>\n" .
3057 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3058 "</div>\n";
3059
3060 print "<div class=\"log_body\">\n";
3061 git_print_simplified_log($co{'comment'});
3062 print "</div>\n";
3063 }
3064 git_footer_html();
3065 }
3066
3067 sub git_commit {
3068 my %co = parse_commit($hash);
3069 if (!%co) {
3070 die_error(undef, "Unknown commit object");
3071 }
3072 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
3073 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
3074
3075 my $parent = $co{'parent'};
3076 if (!defined $parent) {
3077 $parent = "--root";
3078 }
3079 open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $parent, $hash
3080 or die_error(undef, "Open git-diff-tree failed");
3081 my @difftree = map { chomp; $_ } <$fd>;
3082 close $fd or die_error(undef, "Reading git-diff-tree failed");
3083
3084 # non-textual hash id's can be cached
3085 my $expires;
3086 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3087 $expires = "+1d";
3088 }
3089 my $refs = git_get_references();
3090 my $ref = format_ref_marker($refs, $co{'id'});
3091
3092 my $have_snapshot = gitweb_have_snapshot();
3093
3094 my @views_nav = ();
3095 if (defined $file_name && defined $co{'parent'}) {
3096 push @views_nav,
3097 $cgi->a({-href => href(action=>"blame", hash_parent=>$parent, file_name=>$file_name)},
3098 "blame");
3099 }
3100 git_header_html(undef, $expires);
3101 git_print_page_nav('commit', '',
3102 $hash, $co{'tree'}, $hash,
3103 join (' | ', @views_nav));
3104
3105 if (defined $co{'parent'}) {
3106 git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash);
3107 } else {
3108 git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash);
3109 }
3110 print "<div class=\"title_text\">\n" .
3111 "<table cellspacing=\"0\">\n";
3112 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
3113 "<tr>" .
3114 "<td></td><td> $ad{'rfc2822'}";
3115 if ($ad{'hour_local'} < 6) {
3116 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3117 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3118 } else {
3119 printf(" (%02d:%02d %s)",
3120 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3121 }
3122 print "</td>" .
3123 "</tr>\n";
3124 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
3125 print "<tr><td></td><td> $cd{'rfc2822'}" .
3126 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3127 "</td></tr>\n";
3128 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3129 print "<tr>" .
3130 "<td>tree</td>" .
3131 "<td class=\"sha1\">" .
3132 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),
3133 class => "list"}, $co{'tree'}) .
3134 "</td>" .
3135 "<td class=\"link\">" .
3136 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},
3137 "tree");
3138 if ($have_snapshot) {
3139 print " | " .
3140 $cgi->a({-href => href(action=>"snapshot", hash=>$hash)}, "snapshot");
3141 }
3142 print "</td>" .
3143 "</tr>\n";
3144 my $parents = $co{'parents'};
3145 foreach my $par (@$parents) {
3146 print "<tr>" .
3147 "<td>parent</td>" .
3148 "<td class=\"sha1\">" .
3149 $cgi->a({-href => href(action=>"commit", hash=>$par),
3150 class => "list"}, $par) .
3151 "</td>" .
3152 "<td class=\"link\">" .
3153 $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") .
3154 " | " .
3155 $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "diff") .
3156 "</td>" .
3157 "</tr>\n";
3158 }
3159 print "</table>".
3160 "</div>\n";
3161
3162 print "<div class=\"page_body\">\n";
3163 git_print_log($co{'comment'});
3164 print "</div>\n";
3165
3166 git_difftree_body(\@difftree, $hash, $parent);
3167
3168 git_footer_html();
3169 }
3170
3171 sub git_blobdiff {
3172 my $format = shift || 'html';
3173
3174 my $fd;
3175 my @difftree;
3176 my %diffinfo;
3177 my $expires;
3178
3179 # preparing $fd and %diffinfo for git_patchset_body
3180 # new style URI
3181 if (defined $hash_base && defined $hash_parent_base) {
3182 if (defined $file_name) {
3183 # read raw output
3184 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
3185 "--", $file_name
3186 or die_error(undef, "Open git-diff-tree failed");
3187 @difftree = map { chomp; $_ } <$fd>;
3188 close $fd
3189 or die_error(undef, "Reading git-diff-tree failed");
3190 @difftree
3191 or die_error('404 Not Found', "Blob diff not found");
3192
3193 } elsif (defined $hash &&
3194 $hash =~ /[0-9a-fA-F]{40}/) {
3195 # try to find filename from $hash
3196
3197 # read filtered raw output
3198 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
3199 or die_error(undef, "Open git-diff-tree failed");
3200 @difftree =
3201 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3202 # $hash == to_id
3203 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3204 map { chomp; $_ } <$fd>;
3205 close $fd
3206 or die_error(undef, "Reading git-diff-tree failed");
3207 @difftree
3208 or die_error('404 Not Found', "Blob diff not found");
3209
3210 } else {
3211 die_error('404 Not Found', "Missing one of the blob diff parameters");
3212 }
3213
3214 if (@difftree > 1) {
3215 die_error('404 Not Found', "Ambiguous blob diff specification");
3216 }
3217
3218 %diffinfo = parse_difftree_raw_line($difftree[0]);
3219 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3220 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3221
3222 $hash_parent ||= $diffinfo{'from_id'};
3223 $hash ||= $diffinfo{'to_id'};
3224
3225 # non-textual hash id's can be cached
3226 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3227 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3228 $expires = '+1d';
3229 }
3230
3231 # open patch output
3232 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
3233 '-p', $hash_parent_base, $hash_base,
3234 "--", $file_name
3235 or die_error(undef, "Open git-diff-tree failed");
3236 }
3237
3238 # old/legacy style URI
3239 if (!%diffinfo && # if new style URI failed
3240 defined $hash && defined $hash_parent) {
3241 # fake git-diff-tree raw output
3242 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3243 $diffinfo{'from_id'} = $hash_parent;
3244 $diffinfo{'to_id'} = $hash;
3245 if (defined $file_name) {
3246 if (defined $file_parent) {
3247 $diffinfo{'status'} = '2';
3248 $diffinfo{'from_file'} = $file_parent;
3249 $diffinfo{'to_file'} = $file_name;
3250 } else { # assume not renamed
3251 $diffinfo{'status'} = '1';
3252 $diffinfo{'from_file'} = $file_name;
3253 $diffinfo{'to_file'} = $file_name;
3254 }
3255 } else { # no filename given
3256 $diffinfo{'status'} = '2';
3257 $diffinfo{'from_file'} = $hash_parent;
3258 $diffinfo{'to_file'} = $hash;
3259 }
3260
3261 # non-textual hash id's can be cached
3262 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3263 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3264 $expires = '+1d';
3265 }
3266
3267 # open patch output
3268 open $fd, "-|", git_cmd(), "diff", '-p', @diff_opts, $hash_parent, $hash
3269 or die_error(undef, "Open git-diff failed");
3270 } else {
3271 die_error('404 Not Found', "Missing one of the blob diff parameters")
3272 unless %diffinfo;
3273 }
3274
3275 # header
3276 if ($format eq 'html') {
3277 my $formats_nav =
3278 $cgi->a({-href => href(action=>"blobdiff_plain",
3279 hash=>$hash, hash_parent=>$hash_parent,
3280 hash_base=>$hash_base, hash_parent_base=>$hash_parent_base,
3281 file_name=>$file_name, file_parent=>$file_parent)},
3282 "raw");
3283 git_header_html(undef, $expires);
3284 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
3285 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3286 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
3287 } else {
3288 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3289 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3290 }
3291 if (defined $file_name) {
3292 git_print_page_path($file_name, "blob", $hash_base);
3293 } else {
3294 print "<div class=\"page_path\"></div>\n";
3295 }
3296
3297 } elsif ($format eq 'plain') {
3298 print $cgi->header(
3299 -type => 'text/plain',
3300 -charset => 'utf-8',
3301 -expires => $expires,
3302 -content_disposition => 'inline; filename="' . "$file_name" . '.patch"');
3303
3304 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3305
3306 } else {
3307 die_error(undef, "Unknown blobdiff format");
3308 }
3309
3310 # patch
3311 if ($format eq 'html') {
3312 print "<div class=\"page_body\">\n";
3313
3314 git_patchset_body($fd, [ \%diffinfo ], $hash_base, $hash_parent_base);
3315 close $fd;
3316
3317 print "</div>\n"; # class="page_body"
3318 git_footer_html();
3319
3320 } else {
3321 while (my $line = <$fd>) {
3322 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_html($diffinfo{'from_file'})!eg;
3323 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_html($diffinfo{'to_file'})!eg;
3324
3325 print $line;
3326
3327 last if $line =~ m!^\+\+\+!;
3328 }
3329 local $/ = undef;
3330 print <$fd>;
3331 close $fd;
3332 }
3333 }
3334
3335 sub git_blobdiff_plain {
3336 git_blobdiff('plain');
3337 }
3338
3339 sub git_commitdiff {
3340 my $format = shift || 'html';
3341 my %co = parse_commit($hash);
3342 if (!%co) {
3343 die_error(undef, "Unknown commit object");
3344 }
3345 if (!defined $hash_parent) {
3346 $hash_parent = $co{'parent'} || '--root';
3347 }
3348
3349 # read commitdiff
3350 my $fd;
3351 my @difftree;
3352 if ($format eq 'html') {
3353 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
3354 "--patch-with-raw", "--full-index", $hash_parent, $hash
3355 or die_error(undef, "Open git-diff-tree failed");
3356
3357 while (chomp(my $line = <$fd>)) {
3358 # empty line ends raw part of diff-tree output
3359 last unless $line;
3360 push @difftree, $line;
3361 }
3362
3363 } elsif ($format eq 'plain') {
3364 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
3365 '-p', $hash_parent, $hash
3366 or die_error(undef, "Open git-diff-tree failed");
3367
3368 } else {
3369 die_error(undef, "Unknown commitdiff format");
3370 }
3371
3372 # non-textual hash id's can be cached
3373 my $expires;
3374 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3375 $expires = "+1d";
3376 }
3377
3378 # write commit message
3379 if ($format eq 'html') {
3380 my $refs = git_get_references();
3381 my $ref = format_ref_marker($refs, $co{'id'});
3382 my $formats_nav =
3383 $cgi->a({-href => href(action=>"commitdiff_plain",
3384 hash=>$hash, hash_parent=>$hash_parent)},
3385 "raw");
3386
3387 git_header_html(undef, $expires);
3388 git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3389 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
3390 git_print_authorship(\%co);
3391 print "<div class=\"page_body\">\n";
3392 print "<div class=\"log\">\n";
3393 git_print_simplified_log($co{'comment'}, 1); # skip title
3394 print "</div>\n"; # class="log"
3395
3396 } elsif ($format eq 'plain') {
3397 my $refs = git_get_references("tags");
3398 my $tagname = git_get_rev_name_tags($hash);
3399 my $filename = basename($project) . "-$hash.patch";
3400
3401 print $cgi->header(
3402 -type => 'text/plain',
3403 -charset => 'utf-8',
3404 -expires => $expires,
3405 -content_disposition => 'inline; filename="' . "$filename" . '"');
3406 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
3407 print <<TEXT;
3408 From: $co{'author'}
3409 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3410 Subject: $co{'title'}
3411 TEXT
3412 print "X-Git-Tag: $tagname\n" if $tagname;
3413 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3414
3415 foreach my $line (@{$co{'comment'}}) {
3416 print "$line\n";
3417 }
3418 print "---\n\n";
3419 }
3420
3421 # write patch
3422 if ($format eq 'html') {
3423 git_difftree_body(\@difftree, $hash, $hash_parent);
3424 print "<br/>\n";
3425
3426 git_patchset_body($fd, \@difftree, $hash, $hash_parent);
3427 close $fd;
3428 print "</div>\n"; # class="page_body"
3429 git_footer_html();
3430
3431 } elsif ($format eq 'plain') {
3432 local $/ = undef;
3433 print <$fd>;
3434 close $fd
3435 or print "Reading git-diff-tree failed\n";
3436 }
3437 }
3438
3439 sub git_commitdiff_plain {
3440 git_commitdiff('plain');
3441 }
3442
3443 sub git_history {
3444 if (!defined $hash_base) {
3445 $hash_base = git_get_head_hash($project);
3446 }
3447 if (!defined $page) {
3448 $page = 0;
3449 }
3450 my $ftype;
3451 my %co = parse_commit($hash_base);
3452 if (!%co) {
3453 die_error(undef, "Unknown commit object");
3454 }
3455
3456 my $refs = git_get_references();
3457 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3458
3459 if (!defined $hash && defined $file_name) {
3460 $hash = git_get_hash_by_path($hash_base, $file_name);
3461 }
3462 if (defined $hash) {
3463 $ftype = git_get_type($hash);
3464 }
3465
3466 open my $fd, "-|",
3467 git_cmd(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3468 or die_error(undef, "Open git-rev-list-failed");
3469 my @revlist = map { chomp; $_ } <$fd>;
3470 close $fd
3471 or die_error(undef, "Reading git-rev-list failed");
3472
3473 my $paging_nav = '';
3474 if ($page > 0) {
3475 $paging_nav .=
3476 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3477 file_name=>$file_name)},
3478 "first");
3479 $paging_nav .= " &sdot; " .
3480 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3481 file_name=>$file_name, page=>$page-1),
3482 -accesskey => "p", -title => "Alt-p"}, "prev");
3483 } else {
3484 $paging_nav .= "first";
3485 $paging_nav .= " &sdot; prev";
3486 }
3487 if ($#revlist >= (100 * ($page+1)-1)) {
3488 $paging_nav .= " &sdot; " .
3489 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3490 file_name=>$file_name, page=>$page+1),
3491 -accesskey => "n", -title => "Alt-n"}, "next");
3492 } else {
3493 $paging_nav .= " &sdot; next";
3494 }
3495 my $next_link = '';
3496 if ($#revlist >= (100 * ($page+1)-1)) {
3497 $next_link =
3498 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3499 file_name=>$file_name, page=>$page+1),
3500 -title => "Alt-n"}, "next");
3501 }
3502
3503 git_header_html();
3504 git_print_page_nav('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3505 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
3506 git_print_page_path($file_name, $ftype, $hash_base);
3507
3508 git_history_body(\@revlist, ($page * 100), $#revlist,
3509 $refs, $hash_base, $ftype, $next_link);
3510
3511 git_footer_html();
3512 }
3513
3514 sub git_search {
3515 if (!defined $searchtext) {
3516 die_error(undef, "Text field empty");
3517 }
3518 if (!defined $hash) {
3519 $hash = git_get_head_hash($project);
3520 }
3521 my %co = parse_commit($hash);
3522 if (!%co) {
3523 die_error(undef, "Unknown commit object");
3524 }
3525
3526 my $commit_search = 1;
3527 my $author_search = 0;
3528 my $committer_search = 0;
3529 my $pickaxe_search = 0;
3530 if ($searchtext =~ s/^author\\://i) {
3531 $author_search = 1;
3532 } elsif ($searchtext =~ s/^committer\\://i) {
3533 $committer_search = 1;
3534 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3535 $commit_search = 0;
3536 $pickaxe_search = 1;
3537
3538 # pickaxe may take all resources of your box and run for several minutes
3539 # with every query - so decide by yourself how public you make this feature
3540 my ($have_pickaxe) = gitweb_check_feature('pickaxe');
3541 if (!$have_pickaxe) {
3542 die_error('403 Permission denied', "Permission denied");
3543 }
3544 }
3545 git_header_html();
3546 git_print_page_nav('','', $hash,$co{'tree'},$hash);
3547 git_print_header_div('commit', esc_html($co{'title'}), $hash);
3548
3549 print "<table cellspacing=\"0\">\n";
3550 my $alternate = 1;
3551 if ($commit_search) {
3552 $/ = "\0";
3553 open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", $hash or next;
3554 while (my $commit_text = <$fd>) {
3555 if (!grep m/$searchtext/i, $commit_text) {
3556 next;
3557 }
3558 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3559 next;
3560 }
3561 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3562 next;
3563 }
3564 my @commit_lines = split "\n", $commit_text;
3565 my %co = parse_commit(undef, \@commit_lines);
3566 if (!%co) {
3567 next;
3568 }
3569 if ($alternate) {
3570 print "<tr class=\"dark\">\n";
3571 } else {
3572 print "<tr class=\"light\">\n";
3573 }
3574 $alternate ^= 1;
3575 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3576 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3577 "<td>" .
3578 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"},
3579 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
3580 my $comment = $co{'comment'};
3581 foreach my $line (@$comment) {
3582 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3583 my $lead = esc_html($1) || "";
3584 $lead = chop_str($lead, 30, 10);
3585 my $match = esc_html($2) || "";
3586 my $trail = esc_html($3) || "";
3587 $trail = chop_str($trail, 30, 10);
3588 my $text = "$lead<span class=\"match\">$match</span>$trail";
3589 print chop_str($text, 80, 5) . "<br/>\n";
3590 }
3591 }
3592 print "</td>\n" .
3593 "<td class=\"link\">" .
3594 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
3595 " | " .
3596 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
3597 print "</td>\n" .
3598 "</tr>\n";
3599 }
3600 close $fd;
3601 }
3602
3603 if ($pickaxe_search) {
3604 $/ = "\n";
3605 my $git_command = git_cmd_str();
3606 open my $fd, "-|", "$git_command rev-list $hash | " .
3607 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3608 undef %co;
3609 my @files;
3610 while (my $line = <$fd>) {
3611 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3612 my %set;
3613 $set{'file'} = $6;
3614 $set{'from_id'} = $3;
3615 $set{'to_id'} = $4;
3616 $set{'id'} = $set{'to_id'};
3617 if ($set{'id'} =~ m/0{40}/) {
3618 $set{'id'} = $set{'from_id'};
3619 }
3620 if ($set{'id'} =~ m/0{40}/) {
3621 next;
3622 }
3623 push @files, \%set;
3624 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3625 if (%co) {
3626 if ($alternate) {
3627 print "<tr class=\"dark\">\n";
3628 } else {
3629 print "<tr class=\"light\">\n";
3630 }
3631 $alternate ^= 1;
3632 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3633 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3634 "<td>" .
3635 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
3636 -class => "list subject"},
3637 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
3638 while (my $setref = shift @files) {
3639 my %set = %$setref;
3640 print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},
3641 hash=>$set{'id'}, file_name=>$set{'file'}),
3642 -class => "list"},
3643 "<span class=\"match\">" . esc_html($set{'file'}) . "</span>") .
3644 "<br/>\n";
3645 }
3646 print "</td>\n" .
3647 "<td class=\"link\">" .
3648 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
3649 " | " .
3650 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
3651 print "</td>\n" .
3652 "</tr>\n";
3653 }
3654 %co = parse_commit($1);
3655 }
3656 }
3657 close $fd;
3658 }
3659 print "</table>\n";
3660 git_footer_html();
3661 }
3662
3663 sub git_shortlog {
3664 my $head = git_get_head_hash($project);
3665 if (!defined $hash) {
3666 $hash = $head;
3667 }
3668 if (!defined $page) {
3669 $page = 0;
3670 }
3671 my $refs = git_get_references();
3672
3673 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3674 open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash
3675 or die_error(undef, "Open git-rev-list failed");
3676 my @revlist = map { chomp; $_ } <$fd>;
3677 close $fd;
3678
3679 my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, $#revlist);
3680 my $next_link = '';
3681 if ($#revlist >= (100 * ($page+1)-1)) {
3682 $next_link =
3683 $cgi->a({-href => href(action=>"shortlog", hash=>$hash, page=>$page+1),
3684 -title => "Alt-n"}, "next");
3685 }
3686
3687
3688 git_header_html();
3689 git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);
3690 git_print_header_div('summary', $project);
3691
3692 git_shortlog_body(\@revlist, ($page * 100), $#revlist, $refs, $next_link);
3693
3694 git_footer_html();
3695 }
3696
3697 ## ......................................................................
3698 ## feeds (RSS, OPML)
3699
3700 sub git_rss {
3701 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3702 open my $fd, "-|", git_cmd(), "rev-list", "--max-count=150", git_get_head_hash($project)
3703 or die_error(undef, "Open git-rev-list failed");
3704 my @revlist = map { chomp; $_ } <$fd>;
3705 close $fd or die_error(undef, "Reading git-rev-list failed");
3706 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
3707 print <<XML;
3708 <?xml version="1.0" encoding="utf-8"?>
3709 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3710 <channel>
3711 <title>$project $my_uri $my_url</title>
3712 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3713 <description>$project log</description>
3714 <language>en</language>
3715 XML
3716
3717 for (my $i = 0; $i <= $#revlist; $i++) {
3718 my $commit = $revlist[$i];
3719 my %co = parse_commit($commit);
3720 # we read 150, we always show 30 and the ones more recent than 48 hours
3721 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3722 last;
3723 }
3724 my %cd = parse_date($co{'committer_epoch'});
3725 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
3726 $co{'parent'}, $co{'id'}
3727 or next;
3728 my @difftree = map { chomp; $_ } <$fd>;
3729 close $fd
3730 or next;
3731 print "<item>\n" .
3732 "<title>" .
3733 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) .
3734 "</title>\n" .
3735 "<author>" . esc_html($co{'author'}) . "</author>\n" .
3736 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3737 "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3738 "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3739 "<description>" . esc_html($co{'title'}) . "</description>\n" .
3740 "<content:encoded>" .
3741 "<![CDATA[\n";
3742 my $comment = $co{'comment'};
3743 foreach my $line (@$comment) {
3744 $line = to_utf8($line);
3745 print "$line<br/>\n";
3746 }
3747 print "<br/>\n";
3748 foreach my $line (@difftree) {
3749 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3750 next;
3751 }
3752 my $file = esc_html(unquote($7));
3753 $file = to_utf8($file);
3754 print "$file<br/>\n";
3755 }
3756 print "]]>\n" .
3757 "</content:encoded>\n" .
3758 "</item>\n";
3759 }
3760 print "</channel></rss>";
3761 }
3762
3763 sub git_opml {
3764 my @list = git_get_projects_list();
3765
3766 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
3767 print <<XML;
3768 <?xml version="1.0" encoding="utf-8"?>
3769 <opml version="1.0">
3770 <head>
3771 <title>$site_name Git OPML Export</title>
3772 </head>
3773 <body>
3774 <outline text="git RSS feeds">
3775 XML
3776
3777 foreach my $pr (@list) {
3778 my %proj = %$pr;
3779 my $head = git_get_head_hash($proj{'path'});
3780 if (!defined $head) {
3781 next;
3782 }
3783 $git_dir = "$projectroot/$proj{'path'}";
3784 my %co = parse_commit($head);
3785 if (!%co) {
3786 next;
3787 }
3788
3789 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
3790 my $rss = "$my_url?p=$proj{'path'};a=rss";
3791 my $html = "$my_url?p=$proj{'path'};a=summary";
3792 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
3793 }
3794 print <<XML;
3795 </outline>
3796 </body>
3797 </opml>
3798 XML
3799 }
This page took 3.310691 seconds and 5 git commands to generate.