gitweb: Add git_project_index for generating index.aux
[git/jnareb-git.git] / gitweb / gitweb.perl
blob98193bec0ee1d1b30075ed9a8d1d6193a1290966
1 #!/usr/bin/perl
3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
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';
21 our $cgi = new CGI;
22 our $version = "++GIT_VERSION++";
23 our $my_url = $cgi->url();
24 our $my_uri = $cgi->url(-absolute => 1);
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";
30 # absolute fs-path which will be prepended to the project path
31 #our $projectroot = "/pub/scm";
32 our $projectroot = "++GITWEB_PROJECTROOT++";
34 # target of the home link on top of all pages
35 our $home_link = $my_uri || "/";
37 # string of the home link on top of all pages
38 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
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";
44 # html text to include at home page
45 our $home_text = "++GITWEB_HOMETEXT++";
47 # URI of default stylesheet
48 our $stylesheet = "++GITWEB_CSS++";
49 # URI of GIT logo
50 our $logo = "++GITWEB_LOGO++";
52 # source of projects list
53 our $projects_list = "++GITWEB_LIST++";
55 # list of git base URLs used for URL to where fetch project from,
56 # i.e. full URL is "$git_base_url/$project"
57 our @git_base_url_list = ("++GITWEB_BASE_URL++");
59 # default blob_plain mimetype and default charset for text/plain blob
60 our $default_blob_plain_mimetype = 'text/plain';
61 our $default_text_plain_charset = undef;
63 # file to use for guessing MIME types before trying /etc/mime.types
64 # (relative to the current git repository)
65 our $mimetypes_file = undef;
67 # You define site-wide feature defaults here; override them with
68 # $GITWEB_CONFIG as necessary.
69 our %feature = (
70 # feature => {
71 # 'sub' => feature-sub (subroutine),
72 # 'override' => allow-override (boolean),
73 # 'default' => [ default options...] (array reference)}
75 # if feature is overridable (it means that allow-override has true value,
76 # then feature-sub will be called with default options as parameters;
77 # return value of feature-sub indicates if to enable specified feature
79 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
81 'blame' => {
82 'sub' => \&feature_blame,
83 'override' => 0,
84 'default' => [0]},
86 'snapshot' => {
87 'sub' => \&feature_snapshot,
88 'override' => 0,
89 # => [content-encoding, suffix, program]
90 'default' => ['x-gzip', 'gz', 'gzip']},
93 sub gitweb_check_feature {
94 my ($name) = @_;
95 return undef unless exists $feature{$name};
96 my ($sub, $override, @defaults) = (
97 $feature{$name}{'sub'},
98 $feature{$name}{'override'},
99 @{$feature{$name}{'default'}});
100 if (!$override) { return @defaults; }
101 return $sub->(@defaults);
104 # To enable system wide have in $GITWEB_CONFIG
105 # $feature{'blame'}{'default'} = [1];
106 # To have project specific config enable override in $GITWEB_CONFIG
107 # $feature{'blame'}{'override'} = 1;
108 # and in project config gitweb.blame = 0|1;
110 sub feature_blame {
111 my ($val) = git_get_project_config('blame', '--bool');
113 if ($val eq 'true') {
114 return 1;
115 } elsif ($val eq 'false') {
116 return 0;
119 return $_[0];
122 # To disable system wide have in $GITWEB_CONFIG
123 # $feature{'snapshot'}{'default'} = [undef];
124 # To have project specific config enable override in $GITWEB_CONFIG
125 # $feature{'blame'}{'override'} = 1;
126 # and in project config gitweb.snapshot = none|gzip|bzip2
128 sub feature_snapshot {
129 my ($ctype, $suffix, $command) = @_;
131 my ($val) = git_get_project_config('snapshot');
133 if ($val eq 'gzip') {
134 return ('x-gzip', 'gz', 'gzip');
135 } elsif ($val eq 'bzip2') {
136 return ('x-bzip2', 'bz2', 'bzip2');
137 } elsif ($val eq 'none') {
138 return ();
141 return ($ctype, $suffix, $command);
144 # rename detection options for git-diff and git-diff-tree
145 # - default is '-M', with the cost proportional to
146 # (number of removed files) * (number of new files).
147 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
148 # (number of changed files + number of removed files) * (number of new files)
149 # - even more costly is '-C', '--find-copies-harder' with cost
150 # (number of files in the original tree) * (number of new files)
151 # - one might want to include '-B' option, e.g. '-B', '-M'
152 our @diff_opts = ('-M'); # taken from git_commit
154 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
155 require $GITWEB_CONFIG if -e $GITWEB_CONFIG;
157 # version of the core git binary
158 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
160 $projects_list ||= $projectroot;
162 # ======================================================================
163 # input validation and dispatch
164 our $action = $cgi->param('a');
165 if (defined $action) {
166 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
167 die_error(undef, "Invalid action parameter");
171 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
172 if (defined $project) {
173 $project =~ s|^/||;
174 $project =~ s|/$||;
175 $project = undef unless $project;
177 if (defined $project) {
178 if (!validate_input($project)) {
179 die_error(undef, "Invalid project parameter");
181 if (!(-d "$projectroot/$project")) {
182 die_error(undef, "No such directory");
184 if (!(-e "$projectroot/$project/HEAD")) {
185 die_error(undef, "No such project");
187 $ENV{'GIT_DIR'} = "$projectroot/$project";
190 our $file_name = $cgi->param('f');
191 if (defined $file_name) {
192 if (!validate_input($file_name)) {
193 die_error(undef, "Invalid file parameter");
197 our $file_parent = $cgi->param('fp');
198 if (defined $file_parent) {
199 if (!validate_input($file_parent)) {
200 die_error(undef, "Invalid file parent parameter");
204 our $hash = $cgi->param('h');
205 if (defined $hash) {
206 if (!validate_input($hash)) {
207 die_error(undef, "Invalid hash parameter");
211 our $hash_parent = $cgi->param('hp');
212 if (defined $hash_parent) {
213 if (!validate_input($hash_parent)) {
214 die_error(undef, "Invalid hash parent parameter");
218 our $hash_base = $cgi->param('hb');
219 if (defined $hash_base) {
220 if (!validate_input($hash_base)) {
221 die_error(undef, "Invalid hash base parameter");
225 our $hash_parent_base = $cgi->param('hpb');
226 if (defined $hash_parent_base) {
227 if (!validate_input($hash_parent_base)) {
228 die_error(undef, "Invalid hash parent base parameter");
232 our $page = $cgi->param('pg');
233 if (defined $page) {
234 if ($page =~ m/[^0-9]$/) {
235 die_error(undef, "Invalid page parameter");
239 our $searchtext = $cgi->param('s');
240 if (defined $searchtext) {
241 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) {
242 die_error(undef, "Invalid search parameter");
244 $searchtext = quotemeta $searchtext;
247 # dispatch
248 my %actions = (
249 "blame" => \&git_blame2,
250 "blobdiff" => \&git_blobdiff,
251 "blobdiff_plain" => \&git_blobdiff_plain,
252 "blob" => \&git_blob,
253 "blob_plain" => \&git_blob_plain,
254 "commitdiff" => \&git_commitdiff,
255 "commitdiff_plain" => \&git_commitdiff_plain,
256 "commit" => \&git_commit,
257 "heads" => \&git_heads,
258 "history" => \&git_history,
259 "log" => \&git_log,
260 "rss" => \&git_rss,
261 "search" => \&git_search,
262 "shortlog" => \&git_shortlog,
263 "summary" => \&git_summary,
264 "tag" => \&git_tag,
265 "tags" => \&git_tags,
266 "tree" => \&git_tree,
267 "snapshot" => \&git_snapshot,
268 # those below don't need $project
269 "opml" => \&git_opml,
270 "project_list" => \&git_project_list,
271 "project_index" => \&git_project_index,
274 if (defined $project) {
275 $action ||= 'summary';
276 } else {
277 $action ||= 'project_list';
279 if (!defined($actions{$action})) {
280 die_error(undef, "Unknown action");
282 $actions{$action}->();
283 exit;
285 ## ======================================================================
286 ## action links
288 sub href(%) {
289 my %params = @_;
291 my @mapping = (
292 project => "p",
293 action => "a",
294 file_name => "f",
295 file_parent => "fp",
296 hash => "h",
297 hash_parent => "hp",
298 hash_base => "hb",
299 hash_parent_base => "hpb",
300 page => "pg",
301 searchtext => "s",
303 my %mapping = @mapping;
305 $params{"project"} ||= $project;
307 my @result = ();
308 for (my $i = 0; $i < @mapping; $i += 2) {
309 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
310 if (defined $params{$name}) {
311 push @result, $symbol . "=" . esc_param($params{$name});
314 return "$my_uri?" . join(';', @result);
318 ## ======================================================================
319 ## validation, quoting/unquoting and escaping
321 sub validate_input {
322 my $input = shift;
324 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
325 return $input;
327 if ($input =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
328 return undef;
330 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\-\+\#\~\%]/) {
331 return undef;
333 return $input;
336 # quote unsafe chars, but keep the slash, even when it's not
337 # correct, but quoted slashes look too horrible in bookmarks
338 sub esc_param {
339 my $str = shift;
340 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
341 $str =~ s/\+/%2B/g;
342 $str =~ s/ /\+/g;
343 return $str;
346 # replace invalid utf8 character with SUBSTITUTION sequence
347 sub esc_html {
348 my $str = shift;
349 $str = decode("utf8", $str, Encode::FB_DEFAULT);
350 $str = escapeHTML($str);
351 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
352 return $str;
355 # git may return quoted and escaped filenames
356 sub unquote {
357 my $str = shift;
358 if ($str =~ m/^"(.*)"$/) {
359 $str = $1;
360 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
362 return $str;
365 # escape tabs (convert tabs to spaces)
366 sub untabify {
367 my $line = shift;
369 while ((my $pos = index($line, "\t")) != -1) {
370 if (my $count = (8 - ($pos % 8))) {
371 my $spaces = ' ' x $count;
372 $line =~ s/\t/$spaces/;
376 return $line;
379 ## ----------------------------------------------------------------------
380 ## HTML aware string manipulation
382 sub chop_str {
383 my $str = shift;
384 my $len = shift;
385 my $add_len = shift || 10;
387 # allow only $len chars, but don't cut a word if it would fit in $add_len
388 # if it doesn't fit, cut it if it's still longer than the dots we would add
389 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
390 my $body = $1;
391 my $tail = $2;
392 if (length($tail) > 4) {
393 $tail = " ...";
394 $body =~ s/&[^;]*$//; # remove chopped character entities
396 return "$body$tail";
399 ## ----------------------------------------------------------------------
400 ## functions returning short strings
402 # CSS class for given age value (in seconds)
403 sub age_class {
404 my $age = shift;
406 if ($age < 60*60*2) {
407 return "age0";
408 } elsif ($age < 60*60*24*2) {
409 return "age1";
410 } else {
411 return "age2";
415 # convert age in seconds to "nn units ago" string
416 sub age_string {
417 my $age = shift;
418 my $age_str;
420 if ($age > 60*60*24*365*2) {
421 $age_str = (int $age/60/60/24/365);
422 $age_str .= " years ago";
423 } elsif ($age > 60*60*24*(365/12)*2) {
424 $age_str = int $age/60/60/24/(365/12);
425 $age_str .= " months ago";
426 } elsif ($age > 60*60*24*7*2) {
427 $age_str = int $age/60/60/24/7;
428 $age_str .= " weeks ago";
429 } elsif ($age > 60*60*24*2) {
430 $age_str = int $age/60/60/24;
431 $age_str .= " days ago";
432 } elsif ($age > 60*60*2) {
433 $age_str = int $age/60/60;
434 $age_str .= " hours ago";
435 } elsif ($age > 60*2) {
436 $age_str = int $age/60;
437 $age_str .= " min ago";
438 } elsif ($age > 2) {
439 $age_str = int $age;
440 $age_str .= " sec ago";
441 } else {
442 $age_str .= " right now";
444 return $age_str;
447 # convert file mode in octal to symbolic file mode string
448 sub mode_str {
449 my $mode = oct shift;
451 if (S_ISDIR($mode & S_IFMT)) {
452 return 'drwxr-xr-x';
453 } elsif (S_ISLNK($mode)) {
454 return 'lrwxrwxrwx';
455 } elsif (S_ISREG($mode)) {
456 # git cares only about the executable bit
457 if ($mode & S_IXUSR) {
458 return '-rwxr-xr-x';
459 } else {
460 return '-rw-r--r--';
462 } else {
463 return '----------';
467 # convert file mode in octal to file type string
468 sub file_type {
469 my $mode = shift;
471 if ($mode !~ m/^[0-7]+$/) {
472 return $mode;
473 } else {
474 $mode = oct $mode;
477 if (S_ISDIR($mode & S_IFMT)) {
478 return "directory";
479 } elsif (S_ISLNK($mode)) {
480 return "symlink";
481 } elsif (S_ISREG($mode)) {
482 return "file";
483 } else {
484 return "unknown";
488 ## ----------------------------------------------------------------------
489 ## functions returning short HTML fragments, or transforming HTML fragments
490 ## which don't beling to other sections
492 # format line of commit message or tag comment
493 sub format_log_line_html {
494 my $line = shift;
496 $line = esc_html($line);
497 $line =~ s/ /&nbsp;/g;
498 if ($line =~ m/([0-9a-fA-F]{40})/) {
499 my $hash_text = $1;
500 if (git_get_type($hash_text) eq "commit") {
501 my $link =
502 $cgi->a({-href => href(action=>"commit", hash=>$hash_text),
503 -class => "text"}, $hash_text);
504 $line =~ s/$hash_text/$link/;
507 return $line;
510 # format marker of refs pointing to given object
511 sub format_ref_marker {
512 my ($refs, $id) = @_;
513 my $markers = '';
515 if (defined $refs->{$id}) {
516 foreach my $ref (@{$refs->{$id}}) {
517 my ($type, $name) = qw();
518 # e.g. tags/v2.6.11 or heads/next
519 if ($ref =~ m!^(.*?)s?/(.*)$!) {
520 $type = $1;
521 $name = $2;
522 } else {
523 $type = "ref";
524 $name = $ref;
527 $markers .= " <span class=\"$type\">" . esc_html($name) . "</span>";
531 if ($markers) {
532 return ' <span class="refs">'. $markers . '</span>';
533 } else {
534 return "";
538 # format, perhaps shortened and with markers, title line
539 sub format_subject_html {
540 my ($long, $short, $href, $extra) = @_;
541 $extra = '' unless defined($extra);
543 if (length($short) < length($long)) {
544 return $cgi->a({-href => $href, -class => "list subject",
545 -title => $long},
546 esc_html($short) . $extra);
547 } else {
548 return $cgi->a({-href => $href, -class => "list subject"},
549 esc_html($long) . $extra);
553 sub format_diff_line {
554 my $line = shift;
555 my $char = substr($line, 0, 1);
556 my $diff_class = "";
558 chomp $line;
560 if ($char eq '+') {
561 $diff_class = " add";
562 } elsif ($char eq "-") {
563 $diff_class = " rem";
564 } elsif ($char eq "@") {
565 $diff_class = " chunk_header";
566 } elsif ($char eq "\\") {
567 $diff_class = " incomplete";
569 $line = untabify($line);
570 return "<div class=\"diff$diff_class\">" . esc_html($line) . "</div>\n";
573 ## ----------------------------------------------------------------------
574 ## git utility subroutines, invoking git commands
576 # get HEAD ref of given project as hash
577 sub git_get_head_hash {
578 my $project = shift;
579 my $oENV = $ENV{'GIT_DIR'};
580 my $retval = undef;
581 $ENV{'GIT_DIR'} = "$projectroot/$project";
582 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
583 my $head = <$fd>;
584 close $fd;
585 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
586 $retval = $1;
589 if (defined $oENV) {
590 $ENV{'GIT_DIR'} = $oENV;
592 return $retval;
595 # get type of given object
596 sub git_get_type {
597 my $hash = shift;
599 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
600 my $type = <$fd>;
601 close $fd or return;
602 chomp $type;
603 return $type;
606 sub git_get_project_config {
607 my ($key, $type) = @_;
609 return unless ($key);
610 $key =~ s/^gitweb\.//;
611 return if ($key =~ m/\W/);
613 my @x = ($GIT, 'repo-config');
614 if (defined $type) { push @x, $type; }
615 push @x, "--get";
616 push @x, "gitweb.$key";
617 my $val = qx(@x);
618 chomp $val;
619 return ($val);
622 # get hash of given path at given ref
623 sub git_get_hash_by_path {
624 my $base = shift;
625 my $path = shift || return undef;
627 my $tree = $base;
629 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
630 or die_error(undef, "Open git-ls-tree failed");
631 my $line = <$fd>;
632 close $fd or return undef;
634 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
635 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
636 return $3;
639 ## ......................................................................
640 ## git utility functions, directly accessing git repository
642 # assumes that PATH is not symref
643 sub git_get_hash_by_ref {
644 my $path = shift;
646 open my $fd, "$projectroot/$path" or return undef;
647 my $head = <$fd>;
648 close $fd;
649 chomp $head;
650 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
651 return $head;
655 sub git_get_project_description {
656 my $path = shift;
658 open my $fd, "$projectroot/$path/description" or return undef;
659 my $descr = <$fd>;
660 close $fd;
661 chomp $descr;
662 return $descr;
665 sub git_get_project_url_list {
666 my $path = shift;
668 open my $fd, "$projectroot/$path/cloneurl" or return undef;
669 my @git_project_url_list = map { chomp; $_ } <$fd>;
670 close $fd;
672 return wantarray ? @git_project_url_list : \@git_project_url_list;
675 sub git_get_projects_list {
676 my @list;
678 if (-d $projects_list) {
679 # search in directory
680 my $dir = $projects_list;
681 opendir my ($dh), $dir or return undef;
682 while (my $dir = readdir($dh)) {
683 if (-e "$projectroot/$dir/HEAD") {
684 my $pr = {
685 path => $dir,
687 push @list, $pr
690 closedir($dh);
691 } elsif (-f $projects_list) {
692 # read from file(url-encoded):
693 # 'git%2Fgit.git Linus+Torvalds'
694 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
695 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
696 open my ($fd), $projects_list or return undef;
697 while (my $line = <$fd>) {
698 chomp $line;
699 my ($path, $owner) = split ' ', $line;
700 $path = unescape($path);
701 $owner = unescape($owner);
702 if (!defined $path) {
703 next;
705 if (-e "$projectroot/$path/HEAD") {
706 my $pr = {
707 path => $path,
708 owner => decode("utf8", $owner, Encode::FB_DEFAULT),
710 push @list, $pr
713 close $fd;
715 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
716 return @list;
719 sub git_get_project_owner {
720 my $project = shift;
721 my $owner;
723 return undef unless $project;
725 # read from file (url-encoded):
726 # 'git%2Fgit.git Linus+Torvalds'
727 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
728 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
729 if (-f $projects_list) {
730 open (my $fd , $projects_list);
731 while (my $line = <$fd>) {
732 chomp $line;
733 my ($pr, $ow) = split ' ', $line;
734 $pr = unescape($pr);
735 $ow = unescape($ow);
736 if ($pr eq $project) {
737 $owner = decode("utf8", $ow, Encode::FB_DEFAULT);
738 last;
741 close $fd;
743 if (!defined $owner) {
744 $owner = get_file_owner("$projectroot/$project");
747 return $owner;
750 sub git_get_references {
751 my $type = shift || "";
752 my %refs;
753 my $fd;
754 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
755 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
756 if (-f "$projectroot/$project/info/refs") {
757 open $fd, "$projectroot/$project/info/refs"
758 or return;
759 } else {
760 open $fd, "-|", $GIT, "ls-remote", "."
761 or return;
764 while (my $line = <$fd>) {
765 chomp $line;
766 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?[^\^]+)/) {
767 if (defined $refs{$1}) {
768 push @{$refs{$1}}, $2;
769 } else {
770 $refs{$1} = [ $2 ];
774 close $fd or return;
775 return \%refs;
778 sub git_get_rev_name_tags {
779 my $hash = shift || return undef;
781 open my $fd, "-|", $GIT, "name-rev", "--tags", $hash
782 or return;
783 my $name_rev = <$fd>;
784 close $fd;
786 if ($name_rev =~ m|^$hash tags/(.*)$|) {
787 return $1;
788 } else {
789 # catches also '$hash undefined' output
790 return undef;
794 ## ----------------------------------------------------------------------
795 ## parse to hash functions
797 sub parse_date {
798 my $epoch = shift;
799 my $tz = shift || "-0000";
801 my %date;
802 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
803 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
804 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
805 $date{'hour'} = $hour;
806 $date{'minute'} = $min;
807 $date{'mday'} = $mday;
808 $date{'day'} = $days[$wday];
809 $date{'month'} = $months[$mon];
810 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
811 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
812 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
813 $mday, $months[$mon], $hour ,$min;
815 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
816 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
817 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
818 $date{'hour_local'} = $hour;
819 $date{'minute_local'} = $min;
820 $date{'tz_local'} = $tz;
821 return %date;
824 sub parse_tag {
825 my $tag_id = shift;
826 my %tag;
827 my @comment;
829 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
830 $tag{'id'} = $tag_id;
831 while (my $line = <$fd>) {
832 chomp $line;
833 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
834 $tag{'object'} = $1;
835 } elsif ($line =~ m/^type (.+)$/) {
836 $tag{'type'} = $1;
837 } elsif ($line =~ m/^tag (.+)$/) {
838 $tag{'name'} = $1;
839 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
840 $tag{'author'} = $1;
841 $tag{'epoch'} = $2;
842 $tag{'tz'} = $3;
843 } elsif ($line =~ m/--BEGIN/) {
844 push @comment, $line;
845 last;
846 } elsif ($line eq "") {
847 last;
850 push @comment, <$fd>;
851 $tag{'comment'} = \@comment;
852 close $fd or return;
853 if (!defined $tag{'name'}) {
854 return
856 return %tag
859 sub parse_commit {
860 my $commit_id = shift;
861 my $commit_text = shift;
863 my @commit_lines;
864 my %co;
866 if (defined $commit_text) {
867 @commit_lines = @$commit_text;
868 } else {
869 $/ = "\0";
870 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id
871 or return;
872 @commit_lines = split '\n', <$fd>;
873 close $fd or return;
874 $/ = "\n";
875 pop @commit_lines;
877 my $header = shift @commit_lines;
878 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
879 return;
881 ($co{'id'}, my @parents) = split ' ', $header;
882 $co{'parents'} = \@parents;
883 $co{'parent'} = $parents[0];
884 while (my $line = shift @commit_lines) {
885 last if $line eq "\n";
886 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
887 $co{'tree'} = $1;
888 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
889 $co{'author'} = $1;
890 $co{'author_epoch'} = $2;
891 $co{'author_tz'} = $3;
892 if ($co{'author'} =~ m/^([^<]+) </) {
893 $co{'author_name'} = $1;
894 } else {
895 $co{'author_name'} = $co{'author'};
897 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
898 $co{'committer'} = $1;
899 $co{'committer_epoch'} = $2;
900 $co{'committer_tz'} = $3;
901 $co{'committer_name'} = $co{'committer'};
902 $co{'committer_name'} =~ s/ <.*//;
905 if (!defined $co{'tree'}) {
906 return;
909 foreach my $title (@commit_lines) {
910 $title =~ s/^ //;
911 if ($title ne "") {
912 $co{'title'} = chop_str($title, 80, 5);
913 # remove leading stuff of merges to make the interesting part visible
914 if (length($title) > 50) {
915 $title =~ s/^Automatic //;
916 $title =~ s/^merge (of|with) /Merge ... /i;
917 if (length($title) > 50) {
918 $title =~ s/(http|rsync):\/\///;
920 if (length($title) > 50) {
921 $title =~ s/(master|www|rsync)\.//;
923 if (length($title) > 50) {
924 $title =~ s/kernel.org:?//;
926 if (length($title) > 50) {
927 $title =~ s/\/pub\/scm//;
930 $co{'title_short'} = chop_str($title, 50, 5);
931 last;
934 # remove added spaces
935 foreach my $line (@commit_lines) {
936 $line =~ s/^ //;
938 $co{'comment'} = \@commit_lines;
940 my $age = time - $co{'committer_epoch'};
941 $co{'age'} = $age;
942 $co{'age_string'} = age_string($age);
943 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
944 if ($age > 60*60*24*7*2) {
945 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
946 $co{'age_string_age'} = $co{'age_string'};
947 } else {
948 $co{'age_string_date'} = $co{'age_string'};
949 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
951 return %co;
954 # parse ref from ref_file, given by ref_id, with given type
955 sub parse_ref {
956 my $ref_file = shift;
957 my $ref_id = shift;
958 my $type = shift || git_get_type($ref_id);
959 my %ref_item;
961 $ref_item{'type'} = $type;
962 $ref_item{'id'} = $ref_id;
963 $ref_item{'epoch'} = 0;
964 $ref_item{'age'} = "unknown";
965 if ($type eq "tag") {
966 my %tag = parse_tag($ref_id);
967 $ref_item{'comment'} = $tag{'comment'};
968 if ($tag{'type'} eq "commit") {
969 my %co = parse_commit($tag{'object'});
970 $ref_item{'epoch'} = $co{'committer_epoch'};
971 $ref_item{'age'} = $co{'age_string'};
972 } elsif (defined($tag{'epoch'})) {
973 my $age = time - $tag{'epoch'};
974 $ref_item{'epoch'} = $tag{'epoch'};
975 $ref_item{'age'} = age_string($age);
977 $ref_item{'reftype'} = $tag{'type'};
978 $ref_item{'name'} = $tag{'name'};
979 $ref_item{'refid'} = $tag{'object'};
980 } elsif ($type eq "commit"){
981 my %co = parse_commit($ref_id);
982 $ref_item{'reftype'} = "commit";
983 $ref_item{'name'} = $ref_file;
984 $ref_item{'title'} = $co{'title'};
985 $ref_item{'refid'} = $ref_id;
986 $ref_item{'epoch'} = $co{'committer_epoch'};
987 $ref_item{'age'} = $co{'age_string'};
988 } else {
989 $ref_item{'reftype'} = $type;
990 $ref_item{'name'} = $ref_file;
991 $ref_item{'refid'} = $ref_id;
994 return %ref_item;
997 # parse line of git-diff-tree "raw" output
998 sub parse_difftree_raw_line {
999 my $line = shift;
1000 my %res;
1002 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1003 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1004 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1005 $res{'from_mode'} = $1;
1006 $res{'to_mode'} = $2;
1007 $res{'from_id'} = $3;
1008 $res{'to_id'} = $4;
1009 $res{'status'} = $5;
1010 $res{'similarity'} = $6;
1011 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1012 ($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
1013 } else {
1014 $res{'file'} = unquote($7);
1017 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1018 #elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1019 # $res{'commit'} = $1;
1022 return wantarray ? %res : \%res;
1025 ## ......................................................................
1026 ## parse to array of hashes functions
1028 sub git_get_refs_list {
1029 my $ref_dir = shift;
1030 my @reflist;
1032 my @refs;
1033 my $pfxlen = length("$projectroot/$project/$ref_dir");
1034 File::Find::find(sub {
1035 return if (/^\./);
1036 if (-f $_) {
1037 push @refs, substr($File::Find::name, $pfxlen + 1);
1039 }, "$projectroot/$project/$ref_dir");
1041 foreach my $ref_file (@refs) {
1042 my $ref_id = git_get_hash_by_ref("$project/$ref_dir/$ref_file");
1043 my $type = git_get_type($ref_id) || next;
1044 my %ref_item = parse_ref($ref_file, $ref_id, $type);
1046 push @reflist, \%ref_item;
1048 # sort refs by age
1049 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1050 return \@reflist;
1053 ## ----------------------------------------------------------------------
1054 ## filesystem-related functions
1056 sub get_file_owner {
1057 my $path = shift;
1059 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1060 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1061 if (!defined $gcos) {
1062 return undef;
1064 my $owner = $gcos;
1065 $owner =~ s/[,;].*$//;
1066 return decode("utf8", $owner, Encode::FB_DEFAULT);
1069 ## ......................................................................
1070 ## mimetype related functions
1072 sub mimetype_guess_file {
1073 my $filename = shift;
1074 my $mimemap = shift;
1075 -r $mimemap or return undef;
1077 my %mimemap;
1078 open(MIME, $mimemap) or return undef;
1079 while (<MIME>) {
1080 next if m/^#/; # skip comments
1081 my ($mime, $exts) = split(/\t+/);
1082 if (defined $exts) {
1083 my @exts = split(/\s+/, $exts);
1084 foreach my $ext (@exts) {
1085 $mimemap{$ext} = $mime;
1089 close(MIME);
1091 $filename =~ /\.(.*?)$/;
1092 return $mimemap{$1};
1095 sub mimetype_guess {
1096 my $filename = shift;
1097 my $mime;
1098 $filename =~ /\./ or return undef;
1100 if ($mimetypes_file) {
1101 my $file = $mimetypes_file;
1102 if ($file !~ m!^/!) { # if it is relative path
1103 # it is relative to project
1104 $file = "$projectroot/$project/$file";
1106 $mime = mimetype_guess_file($filename, $file);
1108 $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
1109 return $mime;
1112 sub blob_mimetype {
1113 my $fd = shift;
1114 my $filename = shift;
1116 if ($filename) {
1117 my $mime = mimetype_guess($filename);
1118 $mime and return $mime;
1121 # just in case
1122 return $default_blob_plain_mimetype unless $fd;
1124 if (-T $fd) {
1125 return 'text/plain' .
1126 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1127 } elsif (! $filename) {
1128 return 'application/octet-stream';
1129 } elsif ($filename =~ m/\.png$/i) {
1130 return 'image/png';
1131 } elsif ($filename =~ m/\.gif$/i) {
1132 return 'image/gif';
1133 } elsif ($filename =~ m/\.jpe?g$/i) {
1134 return 'image/jpeg';
1135 } else {
1136 return 'application/octet-stream';
1140 ## ======================================================================
1141 ## functions printing HTML: header, footer, error page
1143 sub git_header_html {
1144 my $status = shift || "200 OK";
1145 my $expires = shift;
1147 my $title = "$site_name git";
1148 if (defined $project) {
1149 $title .= " - $project";
1150 if (defined $action) {
1151 $title .= "/$action";
1152 if (defined $file_name) {
1153 $title .= " - $file_name";
1154 if ($action eq "tree" && $file_name !~ m|/$|) {
1155 $title .= "/";
1160 my $content_type;
1161 # require explicit support from the UA if we are to send the page as
1162 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1163 # we have to do this because MSIE sometimes globs '*/*', pretending to
1164 # support xhtml+xml but choking when it gets what it asked for.
1165 if (defined $cgi->http('HTTP_ACCEPT') &&
1166 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&
1167 $cgi->Accept('application/xhtml+xml') != 0) {
1168 $content_type = 'application/xhtml+xml';
1169 } else {
1170 $content_type = 'text/html';
1172 print $cgi->header(-type=>$content_type, -charset => 'utf-8',
1173 -status=> $status, -expires => $expires);
1174 print <<EOF;
1175 <?xml version="1.0" encoding="utf-8"?>
1176 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1177 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1178 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1179 <!-- git core binaries version $git_version -->
1180 <head>
1181 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1182 <meta name="generator" content="gitweb/$version git/$git_version"/>
1183 <meta name="robots" content="index, nofollow"/>
1184 <title>$title</title>
1185 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1187 if (defined $project) {
1188 printf('<link rel="alternate" title="%s log" '.
1189 'href="%s" type="application/rss+xml"/>'."\n",
1190 esc_param($project), href(action=>"rss"));
1193 print "</head>\n" .
1194 "<body>\n" .
1195 "<div class=\"page_header\">\n" .
1196 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1197 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1198 "</a>\n";
1199 print $cgi->a({-href => esc_param($home_link)}, $home_link_str) . " / ";
1200 if (defined $project) {
1201 print $cgi->a({-href => href(action=>"summary")}, esc_html($project));
1202 if (defined $action) {
1203 print " / $action";
1205 print "\n";
1206 if (!defined $searchtext) {
1207 $searchtext = "";
1209 my $search_hash;
1210 if (defined $hash_base) {
1211 $search_hash = $hash_base;
1212 } elsif (defined $hash) {
1213 $search_hash = $hash;
1214 } else {
1215 $search_hash = "HEAD";
1217 $cgi->param("a", "search");
1218 $cgi->param("h", $search_hash);
1219 print $cgi->startform(-method => "get", -action => $my_uri) .
1220 "<div class=\"search\">\n" .
1221 $cgi->hidden(-name => "p") . "\n" .
1222 $cgi->hidden(-name => "a") . "\n" .
1223 $cgi->hidden(-name => "h") . "\n" .
1224 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
1225 "</div>" .
1226 $cgi->end_form() . "\n";
1228 print "</div>\n";
1231 sub git_footer_html {
1232 print "<div class=\"page_footer\">\n";
1233 if (defined $project) {
1234 my $descr = git_get_project_description($project);
1235 if (defined $descr) {
1236 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
1238 print $cgi->a({-href => href(action=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1239 } else {
1240 print $cgi->a({-href => href(action=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1242 print "</div>\n" .
1243 "</body>\n" .
1244 "</html>";
1247 sub die_error {
1248 my $status = shift || "403 Forbidden";
1249 my $error = shift || "Malformed query, file missing or permission denied";
1251 git_header_html($status);
1252 print <<EOF;
1253 <div class="page_body">
1254 <br /><br />
1255 $status - $error
1256 <br />
1257 </div>
1259 git_footer_html();
1260 exit;
1263 ## ----------------------------------------------------------------------
1264 ## functions printing or outputting HTML: navigation
1266 sub git_print_page_nav {
1267 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1268 $extra = '' if !defined $extra; # pager or formats
1270 my @navs = qw(summary shortlog log commit commitdiff tree);
1271 if ($suppress) {
1272 @navs = grep { $_ ne $suppress } @navs;
1275 my %arg = map { $_ => {action=>$_} } @navs;
1276 if (defined $head) {
1277 for (qw(commit commitdiff)) {
1278 $arg{$_}{hash} = $head;
1280 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1281 for (qw(shortlog log)) {
1282 $arg{$_}{hash} = $head;
1286 $arg{tree}{hash} = $treehead if defined $treehead;
1287 $arg{tree}{hash_base} = $treebase if defined $treebase;
1289 print "<div class=\"page_nav\">\n" .
1290 (join " | ",
1291 map { $_ eq $current ?
1292 $_ : $cgi->a({-href => href(%{$arg{$_}})}, "$_")
1293 } @navs);
1294 print "<br/>\n$extra<br/>\n" .
1295 "</div>\n";
1298 sub format_paging_nav {
1299 my ($action, $hash, $head, $page, $nrevs) = @_;
1300 my $paging_nav;
1303 if ($hash ne $head || $page) {
1304 $paging_nav .= $cgi->a({-href => href(action=>$action)}, "HEAD");
1305 } else {
1306 $paging_nav .= "HEAD";
1309 if ($page > 0) {
1310 $paging_nav .= " &sdot; " .
1311 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page-1),
1312 -accesskey => "p", -title => "Alt-p"}, "prev");
1313 } else {
1314 $paging_nav .= " &sdot; prev";
1317 if ($nrevs >= (100 * ($page+1)-1)) {
1318 $paging_nav .= " &sdot; " .
1319 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page+1),
1320 -accesskey => "n", -title => "Alt-n"}, "next");
1321 } else {
1322 $paging_nav .= " &sdot; next";
1325 return $paging_nav;
1328 ## ......................................................................
1329 ## functions printing or outputting HTML: div
1331 sub git_print_header_div {
1332 my ($action, $title, $hash, $hash_base) = @_;
1333 my %args = ();
1335 $args{action} = $action;
1336 $args{hash} = $hash if $hash;
1337 $args{hash_base} = $hash_base if $hash_base;
1339 print "<div class=\"header\">\n" .
1340 $cgi->a({-href => href(%args), -class => "title"},
1341 $title ? $title : $action) .
1342 "\n</div>\n";
1345 #sub git_print_authorship (\%) {
1346 sub git_print_authorship {
1347 my $co = shift;
1349 my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
1350 print "<div class=\"author_date\">" .
1351 esc_html($co->{'author_name'}) .
1352 " [$ad{'rfc2822'}";
1353 if ($ad{'hour_local'} < 6) {
1354 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1355 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1356 } else {
1357 printf(" (%02d:%02d %s)",
1358 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1360 print "]</div>\n";
1363 sub git_print_page_path {
1364 my $name = shift;
1365 my $type = shift;
1366 my $hb = shift;
1368 if (!defined $name) {
1369 print "<div class=\"page_path\">/</div>\n";
1370 } elsif (defined $type && $type eq 'blob') {
1371 print "<div class=\"page_path\">";
1372 if (defined $hb) {
1373 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,
1374 hash_base=>$hb)},
1375 esc_html($name));
1376 } else {
1377 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name)},
1378 esc_html($name));
1380 print "<br/></div>\n";
1381 } else {
1382 print "<div class=\"page_path\">" . esc_html($name) . "<br/></div>\n";
1386 # sub git_print_log (\@;%) {
1387 sub git_print_log ($;%) {
1388 my $log = shift;
1389 my %opts = @_;
1391 if ($opts{'-remove_title'}) {
1392 # remove title, i.e. first line of log
1393 shift @$log;
1395 # remove leading empty lines
1396 while (defined $log->[0] && $log->[0] eq "") {
1397 shift @$log;
1400 # print log
1401 my $signoff = 0;
1402 my $empty = 0;
1403 foreach my $line (@$log) {
1404 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1405 $signoff = 1;
1406 $empty = 0;
1407 if (! $opts{'-remove_signoff'}) {
1408 print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
1409 next;
1410 } else {
1411 # remove signoff lines
1412 next;
1414 } else {
1415 $signoff = 0;
1418 # print only one empty line
1419 # do not print empty line after signoff
1420 if ($line eq "") {
1421 next if ($empty || $signoff);
1422 $empty = 1;
1423 } else {
1424 $empty = 0;
1427 print format_log_line_html($line) . "<br/>\n";
1430 if ($opts{'-final_empty_line'}) {
1431 # end with single empty line
1432 print "<br/>\n" unless $empty;
1436 sub git_print_simplified_log {
1437 my $log = shift;
1438 my $remove_title = shift;
1440 git_print_log($log,
1441 -final_empty_line=> 1,
1442 -remove_title => $remove_title);
1445 ## ......................................................................
1446 ## functions printing large fragments of HTML
1448 sub git_difftree_body {
1449 my ($difftree, $hash, $parent) = @_;
1451 print "<div class=\"list_head\">\n";
1452 if ($#{$difftree} > 10) {
1453 print(($#{$difftree} + 1) . " files changed:\n");
1455 print "</div>\n";
1457 print "<table class=\"diff_tree\">\n";
1458 my $alternate = 0;
1459 my $patchno = 0;
1460 foreach my $line (@{$difftree}) {
1461 my %diff = parse_difftree_raw_line($line);
1463 if ($alternate) {
1464 print "<tr class=\"dark\">\n";
1465 } else {
1466 print "<tr class=\"light\">\n";
1468 $alternate ^= 1;
1470 my ($to_mode_oct, $to_mode_str, $to_file_type);
1471 my ($from_mode_oct, $from_mode_str, $from_file_type);
1472 if ($diff{'to_mode'} ne ('0' x 6)) {
1473 $to_mode_oct = oct $diff{'to_mode'};
1474 if (S_ISREG($to_mode_oct)) { # only for regular file
1475 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1477 $to_file_type = file_type($diff{'to_mode'});
1479 if ($diff{'from_mode'} ne ('0' x 6)) {
1480 $from_mode_oct = oct $diff{'from_mode'};
1481 if (S_ISREG($to_mode_oct)) { # only for regular file
1482 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1484 $from_file_type = file_type($diff{'from_mode'});
1487 if ($diff{'status'} eq "A") { # created
1488 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1489 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1490 $mode_chng .= "]</span>";
1491 print "<td>" .
1492 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1493 hash_base=>$hash, file_name=>$diff{'file'}),
1494 -class => "list"}, esc_html($diff{'file'})) .
1495 "</td>\n" .
1496 "<td>$mode_chng</td>\n" .
1497 "<td class=\"link\">" .
1498 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1499 hash_base=>$hash, file_name=>$diff{'file'})},
1500 "blob");
1501 if ($action == "commitdiff") {
1502 # link to patch
1503 $patchno++;
1504 print " | " .
1505 $cgi->a({-href => "#patch$patchno"}, "patch");
1507 print "</td>\n";
1509 } elsif ($diff{'status'} eq "D") { # deleted
1510 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1511 print "<td>" .
1512 $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
1513 hash_base=>$parent, file_name=>$diff{'file'}),
1514 -class => "list"}, esc_html($diff{'file'})) .
1515 "</td>\n" .
1516 "<td>$mode_chng</td>\n" .
1517 "<td class=\"link\">" .
1518 $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
1519 hash_base=>$parent, file_name=>$diff{'file'})},
1520 "blob") .
1521 " | ";
1522 if ($action == "commitdiff") {
1523 # link to patch
1524 $patchno++;
1525 print " | " .
1526 $cgi->a({-href => "#patch$patchno"}, "patch");
1528 print $cgi->a({-href => href(action=>"history", hash_base=>$parent,
1529 file_name=>$diff{'file'})},
1530 "history") .
1531 "</td>\n";
1533 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1534 my $mode_chnge = "";
1535 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1536 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1537 if ($from_file_type != $to_file_type) {
1538 $mode_chnge .= " from $from_file_type to $to_file_type";
1540 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1541 if ($from_mode_str && $to_mode_str) {
1542 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1543 } elsif ($to_mode_str) {
1544 $mode_chnge .= " mode: $to_mode_str";
1547 $mode_chnge .= "]</span>\n";
1549 print "<td>";
1550 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1551 print $cgi->a({-href => href(action=>"blobdiff",
1552 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1553 hash_base=>$hash, hash_parent_base=>$parent,
1554 file_name=>$diff{'file'}),
1555 -class => "list"}, esc_html($diff{'file'}));
1556 } else { # only mode changed
1557 print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1558 hash_base=>$hash, file_name=>$diff{'file'}),
1559 -class => "list"}, esc_html($diff{'file'}));
1561 print "</td>\n" .
1562 "<td>$mode_chnge</td>\n" .
1563 "<td class=\"link\">" .
1564 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1565 hash_base=>$hash, file_name=>$diff{'file'})},
1566 "blob");
1567 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1568 if ($action == "commitdiff") {
1569 # link to patch
1570 $patchno++;
1571 print " | " .
1572 $cgi->a({-href => "#patch$patchno"}, "patch");
1573 } else {
1574 print " | " .
1575 $cgi->a({-href => href(action=>"blobdiff",
1576 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1577 hash_base=>$hash, hash_parent_base=>$parent,
1578 file_name=>$diff{'file'})},
1579 "diff");
1582 print " | " .
1583 $cgi->a({-href => href(action=>"history",
1584 hash_base=>$hash, file_name=>$diff{'file'})},
1585 "history");
1586 print "</td>\n";
1588 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1589 my %status_name = ('R' => 'moved', 'C' => 'copied');
1590 my $nstatus = $status_name{$diff{'status'}};
1591 my $mode_chng = "";
1592 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1593 # mode also for directories, so we cannot use $to_mode_str
1594 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1596 print "<td>" .
1597 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1598 hash=>$diff{'to_id'}, file_name=>$diff{'to_file'}),
1599 -class => "list"}, esc_html($diff{'to_file'})) . "</td>\n" .
1600 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1601 $cgi->a({-href => href(action=>"blob", hash_base=>$parent,
1602 hash=>$diff{'from_id'}, file_name=>$diff{'from_file'}),
1603 -class => "list"}, esc_html($diff{'from_file'})) .
1604 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1605 "<td class=\"link\">" .
1606 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1607 hash=>$diff{'to_id'}, file_name=>$diff{'to_file'})},
1608 "blob");
1609 if ($diff{'to_id'} ne $diff{'from_id'}) {
1610 if ($action == "commitdiff") {
1611 # link to patch
1612 $patchno++;
1613 print " | " .
1614 $cgi->a({-href => "#patch$patchno"}, "patch");
1615 } else {
1616 print " | " .
1617 $cgi->a({-href => href(action=>"blobdiff",
1618 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1619 hash_base=>$hash, hash_parent_base=>$parent,
1620 file_name=>$diff{'to_file'}, file_parent=>$diff{'from_file'})},
1621 "diff");
1624 print "</td>\n";
1626 } # we should not encounter Unmerged (U) or Unknown (X) status
1627 print "</tr>\n";
1629 print "</table>\n";
1632 sub git_patchset_body {
1633 my ($fd, $difftree, $hash, $hash_parent) = @_;
1635 my $patch_idx = 0;
1636 my $in_header = 0;
1637 my $patch_found = 0;
1638 my $diffinfo;
1640 print "<div class=\"patchset\">\n";
1642 LINE:
1643 while (my $patch_line = <$fd>) {
1644 chomp $patch_line;
1646 if ($patch_line =~ m/^diff /) { # "git diff" header
1647 # beginning of patch (in patchset)
1648 if ($patch_found) {
1649 # close previous patch
1650 print "</div>\n"; # class="patch"
1651 } else {
1652 # first patch in patchset
1653 $patch_found = 1;
1655 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1657 if (ref($difftree->[$patch_idx]) eq "HASH") {
1658 $diffinfo = $difftree->[$patch_idx];
1659 } else {
1660 $diffinfo = parse_difftree_raw_line($difftree->[$patch_idx]);
1662 $patch_idx++;
1664 # for now, no extended header, hence we skip empty patches
1665 # companion to next LINE if $in_header;
1666 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1667 $in_header = 1;
1668 next LINE;
1671 if ($diffinfo->{'status'} eq "A") { # added
1672 print "<div class=\"diff_info\">" . file_type($diffinfo->{'to_mode'}) . ":" .
1673 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1674 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'file'})},
1675 $diffinfo->{'to_id'}) . "(new)" .
1676 "</div>\n"; # class="diff_info"
1678 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1679 print "<div class=\"diff_info\">" . file_type($diffinfo->{'from_mode'}) . ":" .
1680 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1681 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'file'})},
1682 $diffinfo->{'from_id'}) . "(deleted)" .
1683 "</div>\n"; # class="diff_info"
1685 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1686 $diffinfo->{'status'} eq "C" || # copied
1687 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1688 print "<div class=\"diff_info\">" .
1689 file_type($diffinfo->{'from_mode'}) . ":" .
1690 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1691 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'from_file'})},
1692 $diffinfo->{'from_id'}) .
1693 " -> " .
1694 file_type($diffinfo->{'to_mode'}) . ":" .
1695 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1696 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'to_file'})},
1697 $diffinfo->{'to_id'});
1698 print "</div>\n"; # class="diff_info"
1700 } else { # modified, mode changed, ...
1701 print "<div class=\"diff_info\">" .
1702 file_type($diffinfo->{'from_mode'}) . ":" .
1703 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1704 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'file'})},
1705 $diffinfo->{'from_id'}) .
1706 " -> " .
1707 file_type($diffinfo->{'to_mode'}) . ":" .
1708 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1709 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'file'})},
1710 $diffinfo->{'to_id'});
1711 print "</div>\n"; # class="diff_info"
1714 #print "<div class=\"diff extended_header\">\n";
1715 $in_header = 1;
1716 next LINE;
1717 } # start of patch in patchset
1720 if ($in_header && $patch_line =~ m/^---/) {
1721 #print "</div>\n"; # class="diff extended_header"
1722 $in_header = 0;
1724 my $file = $diffinfo->{'from_file'};
1725 $file ||= $diffinfo->{'file'};
1726 $file = $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1727 hash=>$diffinfo->{'from_id'}, file_name=>$file),
1728 -class => "list"}, esc_html($file));
1729 $patch_line =~ s|a/.*$|a/$file|g;
1730 print "<div class=\"diff from_file\">$patch_line</div>\n";
1732 $patch_line = <$fd>;
1733 chomp $patch_line;
1735 #$patch_line =~ m/^+++/;
1736 $file = $diffinfo->{'to_file'};
1737 $file ||= $diffinfo->{'file'};
1738 $file = $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1739 hash=>$diffinfo->{'to_id'}, file_name=>$file),
1740 -class => "list"}, esc_html($file));
1741 $patch_line =~ s|b/.*|b/$file|g;
1742 print "<div class=\"diff to_file\">$patch_line</div>\n";
1744 next LINE;
1746 next LINE if $in_header;
1748 print format_diff_line($patch_line);
1750 print "</div>\n" if $patch_found; # class="patch"
1752 print "</div>\n"; # class="patchset"
1755 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1757 sub git_shortlog_body {
1758 # uses global variable $project
1759 my ($revlist, $from, $to, $refs, $extra) = @_;
1761 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
1762 my $have_snapshot = (defined $ctype && defined $suffix);
1764 $from = 0 unless defined $from;
1765 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1767 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1768 my $alternate = 0;
1769 for (my $i = $from; $i <= $to; $i++) {
1770 my $commit = $revlist->[$i];
1771 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1772 my $ref = format_ref_marker($refs, $commit);
1773 my %co = parse_commit($commit);
1774 if ($alternate) {
1775 print "<tr class=\"dark\">\n";
1776 } else {
1777 print "<tr class=\"light\">\n";
1779 $alternate ^= 1;
1780 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1781 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1782 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1783 "<td>";
1784 print format_subject_html($co{'title'}, $co{'title_short'},
1785 href(action=>"commit", hash=>$commit), $ref);
1786 print "</td>\n" .
1787 "<td class=\"link\">" .
1788 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
1789 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff");
1790 if ($have_snapshot) {
1791 print " | " . $cgi->a({-href => href(action=>"snapshot", hash=>$commit)}, "snapshot");
1793 print "</td>\n" .
1794 "</tr>\n";
1796 if (defined $extra) {
1797 print "<tr>\n" .
1798 "<td colspan=\"4\">$extra</td>\n" .
1799 "</tr>\n";
1801 print "</table>\n";
1804 sub git_history_body {
1805 # Warning: assumes constant type (blob or tree) during history
1806 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1808 print "<table class=\"history\" cellspacing=\"0\">\n";
1809 my $alternate = 0;
1810 while (my $line = <$fd>) {
1811 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1812 next;
1815 my $commit = $1;
1816 my %co = parse_commit($commit);
1817 if (!%co) {
1818 next;
1821 my $ref = format_ref_marker($refs, $commit);
1823 if ($alternate) {
1824 print "<tr class=\"dark\">\n";
1825 } else {
1826 print "<tr class=\"light\">\n";
1828 $alternate ^= 1;
1829 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1830 # shortlog uses chop_str($co{'author_name'}, 10)
1831 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1832 "<td>";
1833 # originally git_history used chop_str($co{'title'}, 50)
1834 print format_subject_html($co{'title'}, $co{'title_short'},
1835 href(action=>"commit", hash=>$commit), $ref);
1836 print "</td>\n" .
1837 "<td class=\"link\">" .
1838 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
1839 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
1840 $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype);
1842 if ($ftype eq 'blob') {
1843 my $blob_current = git_get_hash_by_path($hash_base, $file_name);
1844 my $blob_parent = git_get_hash_by_path($commit, $file_name);
1845 if (defined $blob_current && defined $blob_parent &&
1846 $blob_current ne $blob_parent) {
1847 print " | " .
1848 $cgi->a({-href => href(action=>"blobdiff",
1849 hash=>$blob_current, hash_parent=>$blob_parent,
1850 hash_base=>$hash_base, hash_parent_base=>$commit,
1851 file_name=>$file_name)},
1852 "diff to current");
1855 print "</td>\n" .
1856 "</tr>\n";
1858 if (defined $extra) {
1859 print "<tr>\n" .
1860 "<td colspan=\"4\">$extra</td>\n" .
1861 "</tr>\n";
1863 print "</table>\n";
1866 sub git_tags_body {
1867 # uses global variable $project
1868 my ($taglist, $from, $to, $extra) = @_;
1869 $from = 0 unless defined $from;
1870 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1872 print "<table class=\"tags\" cellspacing=\"0\">\n";
1873 my $alternate = 0;
1874 for (my $i = $from; $i <= $to; $i++) {
1875 my $entry = $taglist->[$i];
1876 my %tag = %$entry;
1877 my $comment_lines = $tag{'comment'};
1878 my $comment = shift @$comment_lines;
1879 my $comment_short;
1880 if (defined $comment) {
1881 $comment_short = chop_str($comment, 30, 5);
1883 if ($alternate) {
1884 print "<tr class=\"dark\">\n";
1885 } else {
1886 print "<tr class=\"light\">\n";
1888 $alternate ^= 1;
1889 print "<td><i>$tag{'age'}</i></td>\n" .
1890 "<td>" .
1891 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),
1892 -class => "list name"}, esc_html($tag{'name'})) .
1893 "</td>\n" .
1894 "<td>";
1895 if (defined $comment) {
1896 print format_subject_html($comment, $comment_short,
1897 href(action=>"tag", hash=>$tag{'id'}));
1899 print "</td>\n" .
1900 "<td class=\"selflink\">";
1901 if ($tag{'type'} eq "tag") {
1902 print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag");
1903 } else {
1904 print "&nbsp;";
1906 print "</td>\n" .
1907 "<td class=\"link\">" . " | " .
1908 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'});
1909 if ($tag{'reftype'} eq "commit") {
1910 print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") .
1911 " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'refid'})}, "log");
1912 } elsif ($tag{'reftype'} eq "blob") {
1913 print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw");
1915 print "</td>\n" .
1916 "</tr>";
1918 if (defined $extra) {
1919 print "<tr>\n" .
1920 "<td colspan=\"5\">$extra</td>\n" .
1921 "</tr>\n";
1923 print "</table>\n";
1926 sub git_heads_body {
1927 # uses global variable $project
1928 my ($taglist, $head, $from, $to, $extra) = @_;
1929 $from = 0 unless defined $from;
1930 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1932 print "<table class=\"heads\" cellspacing=\"0\">\n";
1933 my $alternate = 0;
1934 for (my $i = $from; $i <= $to; $i++) {
1935 my $entry = $taglist->[$i];
1936 my %tag = %$entry;
1937 my $curr = $tag{'id'} eq $head;
1938 if ($alternate) {
1939 print "<tr class=\"dark\">\n";
1940 } else {
1941 print "<tr class=\"light\">\n";
1943 $alternate ^= 1;
1944 print "<td><i>$tag{'age'}</i></td>\n" .
1945 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
1946 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'}),
1947 -class => "list name"},esc_html($tag{'name'})) .
1948 "</td>\n" .
1949 "<td class=\"link\">" .
1950 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") . " | " .
1951 $cgi->a({-href => href(action=>"log", hash=>$tag{'name'})}, "log") .
1952 "</td>\n" .
1953 "</tr>";
1955 if (defined $extra) {
1956 print "<tr>\n" .
1957 "<td colspan=\"3\">$extra</td>\n" .
1958 "</tr>\n";
1960 print "</table>\n";
1963 ## ======================================================================
1964 ## ======================================================================
1965 ## actions
1967 sub git_project_list {
1968 my $order = $cgi->param('o');
1969 if (defined $order && $order !~ m/project|descr|owner|age/) {
1970 die_error(undef, "Unknown order parameter");
1973 my @list = git_get_projects_list();
1974 my @projects;
1975 if (!@list) {
1976 die_error(undef, "No projects found");
1978 foreach my $pr (@list) {
1979 my $head = git_get_head_hash($pr->{'path'});
1980 if (!defined $head) {
1981 next;
1983 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1984 my %co = parse_commit($head);
1985 if (!%co) {
1986 next;
1988 $pr->{'commit'} = \%co;
1989 if (!defined $pr->{'descr'}) {
1990 my $descr = git_get_project_description($pr->{'path'}) || "";
1991 $pr->{'descr'} = chop_str($descr, 25, 5);
1993 if (!defined $pr->{'owner'}) {
1994 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
1996 push @projects, $pr;
1999 git_header_html();
2000 if (-f $home_text) {
2001 print "<div class=\"index_include\">\n";
2002 open (my $fd, $home_text);
2003 print <$fd>;
2004 close $fd;
2005 print "</div>\n";
2007 print "<table class=\"project_list\">\n" .
2008 "<tr>\n";
2009 $order ||= "project";
2010 if ($order eq "project") {
2011 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2012 print "<th>Project</th>\n";
2013 } else {
2014 print "<th>" .
2015 $cgi->a({-href => "$my_uri?" . esc_param("o=project"),
2016 -class => "header"}, "Project") .
2017 "</th>\n";
2019 if ($order eq "descr") {
2020 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2021 print "<th>Description</th>\n";
2022 } else {
2023 print "<th>" .
2024 $cgi->a({-href => "$my_uri?" . esc_param("o=descr"),
2025 -class => "header"}, "Description") .
2026 "</th>\n";
2028 if ($order eq "owner") {
2029 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2030 print "<th>Owner</th>\n";
2031 } else {
2032 print "<th>" .
2033 $cgi->a({-href => "$my_uri?" . esc_param("o=owner"),
2034 -class => "header"}, "Owner") .
2035 "</th>\n";
2037 if ($order eq "age") {
2038 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2039 print "<th>Last Change</th>\n";
2040 } else {
2041 print "<th>" .
2042 $cgi->a({-href => "$my_uri?" . esc_param("o=age"),
2043 -class => "header"}, "Last Change") .
2044 "</th>\n";
2046 print "<th></th>\n" .
2047 "</tr>\n";
2048 my $alternate = 0;
2049 foreach my $pr (@projects) {
2050 if ($alternate) {
2051 print "<tr class=\"dark\">\n";
2052 } else {
2053 print "<tr class=\"light\">\n";
2055 $alternate ^= 1;
2056 print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
2057 -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
2058 "<td>" . esc_html($pr->{'descr'}) . "</td>\n" .
2059 "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
2060 print "<td class=\"". age_class($pr->{'commit'}{'age'}) . "\">" .
2061 $pr->{'commit'}{'age_string'} . "</td>\n" .
2062 "<td class=\"link\">" .
2063 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
2064 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
2065 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") .
2066 "</td>\n" .
2067 "</tr>\n";
2069 print "</table>\n";
2070 git_footer_html();
2073 sub git_project_index {
2074 my @projects = git_get_projects_list();
2076 print $cgi->header(
2077 -type => 'text/plain',
2078 -charset => 'utf-8',
2079 -content_disposition => qq(inline; filename="index.aux"));
2081 foreach my $pr (@projects) {
2082 if (!exists $pr->{'owner'}) {
2083 $pr->{'owner'} = get_file_owner("$projectroot/$project");
2086 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2087 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2088 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
2089 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
2090 $path =~ s/ /\+/g;
2091 $owner =~ s/ /\+/g;
2093 print "$path $owner\n";
2097 sub git_summary {
2098 my $descr = git_get_project_description($project) || "none";
2099 my $head = git_get_head_hash($project);
2100 my %co = parse_commit($head);
2101 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
2103 my $owner = git_get_project_owner($project);
2105 my $refs = git_get_references();
2106 git_header_html();
2107 git_print_page_nav('summary','', $head);
2109 print "<div class=\"title\">&nbsp;</div>\n";
2110 print "<table cellspacing=\"0\">\n" .
2111 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
2112 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2113 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2114 # use per project git URL list in $projectroot/$project/cloneurl
2115 # or make project git URL from git base URL and project name
2116 my $url_tag = "URL";
2117 my @url_list = git_get_project_url_list($project);
2118 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2119 foreach my $git_url (@url_list) {
2120 next unless $git_url;
2121 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2122 $url_tag = "";
2124 print "</table>\n";
2126 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash($project)
2127 or die_error(undef, "Open git-rev-list failed");
2128 my @revlist = map { chomp; $_ } <$fd>;
2129 close $fd;
2130 git_print_header_div('shortlog');
2131 git_shortlog_body(\@revlist, 0, 15, $refs,
2132 $cgi->a({-href => href(action=>"shortlog")}, "..."));
2134 my $taglist = git_get_refs_list("refs/tags");
2135 if (defined @$taglist) {
2136 git_print_header_div('tags');
2137 git_tags_body($taglist, 0, 15,
2138 $cgi->a({-href => href(action=>"tags")}, "..."));
2141 my $headlist = git_get_refs_list("refs/heads");
2142 if (defined @$headlist) {
2143 git_print_header_div('heads');
2144 git_heads_body($headlist, $head, 0, 15,
2145 $cgi->a({-href => href(action=>"heads")}, "..."));
2148 git_footer_html();
2151 sub git_tag {
2152 my $head = git_get_head_hash($project);
2153 git_header_html();
2154 git_print_page_nav('','', $head,undef,$head);
2155 my %tag = parse_tag($hash);
2156 git_print_header_div('commit', esc_html($tag{'name'}), $hash);
2157 print "<div class=\"title_text\">\n" .
2158 "<table cellspacing=\"0\">\n" .
2159 "<tr>\n" .
2160 "<td>object</td>\n" .
2161 "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
2162 $tag{'object'}) . "</td>\n" .
2163 "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
2164 $tag{'type'}) . "</td>\n" .
2165 "</tr>\n";
2166 if (defined($tag{'author'})) {
2167 my %ad = parse_date($tag{'epoch'}, $tag{'tz'});
2168 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
2169 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2170 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2171 "</td></tr>\n";
2173 print "</table>\n\n" .
2174 "</div>\n";
2175 print "<div class=\"page_body\">";
2176 my $comment = $tag{'comment'};
2177 foreach my $line (@$comment) {
2178 print esc_html($line) . "<br/>\n";
2180 print "</div>\n";
2181 git_footer_html();
2184 sub git_blame2 {
2185 my $fd;
2186 my $ftype;
2188 if (!gitweb_check_feature('blame')) {
2189 die_error('403 Permission denied', "Permission denied");
2191 die_error('404 Not Found', "File name not defined") if (!$file_name);
2192 $hash_base ||= git_get_head_hash($project);
2193 die_error(undef, "Couldn't find base commit") unless ($hash_base);
2194 my %co = parse_commit($hash_base)
2195 or die_error(undef, "Reading commit failed");
2196 if (!defined $hash) {
2197 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
2198 or die_error(undef, "Error looking up file");
2200 $ftype = git_get_type($hash);
2201 if ($ftype !~ "blob") {
2202 die_error("400 Bad Request", "Object is not a blob");
2204 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
2205 or die_error(undef, "Open git-blame failed");
2206 git_header_html();
2207 my $formats_nav =
2208 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2209 "blob") .
2210 " | " .
2211 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
2212 "head");
2213 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2214 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2215 git_print_page_path($file_name, $ftype, $hash_base);
2216 my @rev_color = (qw(light2 dark2));
2217 my $num_colors = scalar(@rev_color);
2218 my $current_color = 0;
2219 my $last_rev;
2220 print <<HTML;
2221 <div class="page_body">
2222 <table class="blame">
2223 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2224 HTML
2225 while (<$fd>) {
2226 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2227 my $full_rev = $1;
2228 my $rev = substr($full_rev, 0, 8);
2229 my $lineno = $2;
2230 my $data = $3;
2232 if (!defined $last_rev) {
2233 $last_rev = $full_rev;
2234 } elsif ($last_rev ne $full_rev) {
2235 $last_rev = $full_rev;
2236 $current_color = ++$current_color % $num_colors;
2238 print "<tr class=\"$rev_color[$current_color]\">\n";
2239 print "<td class=\"sha1\">" .
2240 $cgi->a({-href => href(action=>"commit", hash=>$full_rev, file_name=>$file_name)},
2241 esc_html($rev)) . "</td>\n";
2242 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2243 esc_html($lineno) . "</a></td>\n";
2244 print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
2245 print "</tr>\n";
2247 print "</table>\n";
2248 print "</div>";
2249 close $fd
2250 or print "Reading blob failed\n";
2251 git_footer_html();
2254 sub git_blame {
2255 my $fd;
2257 if (!gitweb_check_feature('blame')) {
2258 die_error('403 Permission denied', "Permission denied");
2260 die_error('404 Not Found', "File name not defined") if (!$file_name);
2261 $hash_base ||= git_get_head_hash($project);
2262 die_error(undef, "Couldn't find base commit") unless ($hash_base);
2263 my %co = parse_commit($hash_base)
2264 or die_error(undef, "Reading commit failed");
2265 if (!defined $hash) {
2266 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
2267 or die_error(undef, "Error lookup file");
2269 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2270 or die_error(undef, "Open git-annotate failed");
2271 git_header_html();
2272 my $formats_nav =
2273 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2274 "blob") .
2275 " | " .
2276 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
2277 "head");
2278 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2279 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2280 git_print_page_path($file_name, 'blob', $hash_base);
2281 print "<div class=\"page_body\">\n";
2282 print <<HTML;
2283 <table class="blame">
2284 <tr>
2285 <th>Commit</th>
2286 <th>Age</th>
2287 <th>Author</th>
2288 <th>Line</th>
2289 <th>Data</th>
2290 </tr>
2291 HTML
2292 my @line_class = (qw(light dark));
2293 my $line_class_len = scalar (@line_class);
2294 my $line_class_num = $#line_class;
2295 while (my $line = <$fd>) {
2296 my $long_rev;
2297 my $short_rev;
2298 my $author;
2299 my $time;
2300 my $lineno;
2301 my $data;
2302 my $age;
2303 my $age_str;
2304 my $age_class;
2306 chomp $line;
2307 $line_class_num = ($line_class_num + 1) % $line_class_len;
2309 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2310 $long_rev = $1;
2311 $author = $2;
2312 $time = $3;
2313 $lineno = $4;
2314 $data = $5;
2315 } else {
2316 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
2317 next;
2319 $short_rev = substr ($long_rev, 0, 8);
2320 $age = time () - $time;
2321 $age_str = age_string ($age);
2322 $age_str =~ s/ /&nbsp;/g;
2323 $age_class = age_class($age);
2324 $author = esc_html ($author);
2325 $author =~ s/ /&nbsp;/g;
2327 $data = untabify($data);
2328 $data = esc_html ($data);
2330 print <<HTML;
2331 <tr class="$line_class[$line_class_num]">
2332 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2333 <td class="$age_class">$age_str</td>
2334 <td>$author</td>
2335 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2336 <td class="pre">$data</td>
2337 </tr>
2338 HTML
2339 } # while (my $line = <$fd>)
2340 print "</table>\n\n";
2341 close $fd
2342 or print "Reading blob failed.\n";
2343 print "</div>";
2344 git_footer_html();
2347 sub git_tags {
2348 my $head = git_get_head_hash($project);
2349 git_header_html();
2350 git_print_page_nav('','', $head,undef,$head);
2351 git_print_header_div('summary', $project);
2353 my $taglist = git_get_refs_list("refs/tags");
2354 if (defined @$taglist) {
2355 git_tags_body($taglist);
2357 git_footer_html();
2360 sub git_heads {
2361 my $head = git_get_head_hash($project);
2362 git_header_html();
2363 git_print_page_nav('','', $head,undef,$head);
2364 git_print_header_div('summary', $project);
2366 my $taglist = git_get_refs_list("refs/heads");
2367 if (defined @$taglist) {
2368 git_heads_body($taglist, $head);
2370 git_footer_html();
2373 sub git_blob_plain {
2374 # blobs defined by non-textual hash id's can be cached
2375 my $expires;
2376 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2377 $expires = "+1d";
2380 if (!defined $hash) {
2381 if (defined $file_name) {
2382 my $base = $hash_base || git_get_head_hash($project);
2383 $hash = git_get_hash_by_path($base, $file_name, "blob")
2384 or die_error(undef, "Error lookup file");
2385 } else {
2386 die_error(undef, "No file name defined");
2389 my $type = shift;
2390 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2391 or die_error(undef, "Couldn't cat $file_name, $hash");
2393 $type ||= blob_mimetype($fd, $file_name);
2395 # save as filename, even when no $file_name is given
2396 my $save_as = "$hash";
2397 if (defined $file_name) {
2398 $save_as = $file_name;
2399 } elsif ($type =~ m/^text\//) {
2400 $save_as .= '.txt';
2403 print $cgi->header(
2404 -type => "$type",
2405 -expires=>$expires,
2406 -content_disposition => "inline; filename=\"$save_as\"");
2407 undef $/;
2408 binmode STDOUT, ':raw';
2409 print <$fd>;
2410 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
2411 $/ = "\n";
2412 close $fd;
2415 sub git_blob {
2416 # blobs defined by non-textual hash id's can be cached
2417 my $expires;
2418 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2419 $expires = "+1d";
2422 if (!defined $hash) {
2423 if (defined $file_name) {
2424 my $base = $hash_base || git_get_head_hash($project);
2425 $hash = git_get_hash_by_path($base, $file_name, "blob")
2426 or die_error(undef, "Error lookup file");
2427 } else {
2428 die_error(undef, "No file name defined");
2431 my $have_blame = gitweb_check_feature('blame');
2432 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2433 or die_error(undef, "Couldn't cat $file_name, $hash");
2434 my $mimetype = blob_mimetype($fd, $file_name);
2435 if ($mimetype !~ m/^text\//) {
2436 close $fd;
2437 return git_blob_plain($mimetype);
2439 git_header_html(undef, $expires);
2440 my $formats_nav = '';
2441 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2442 if (defined $file_name) {
2443 if ($have_blame) {
2444 $formats_nav .=
2445 $cgi->a({-href => href(action=>"blame", hash_base=>$hash_base,
2446 hash=>$hash, file_name=>$file_name)},
2447 "blame") .
2448 " | ";
2450 $formats_nav .=
2451 $cgi->a({-href => href(action=>"blob_plain",
2452 hash=>$hash, file_name=>$file_name)},
2453 "plain") .
2454 " | " .
2455 $cgi->a({-href => href(action=>"blob",
2456 hash_base=>"HEAD", file_name=>$file_name)},
2457 "head");
2458 } else {
2459 $formats_nav .=
2460 $cgi->a({-href => href(action=>"blob_plain", hash=>$hash)}, "plain");
2462 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2463 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2464 } else {
2465 print "<div class=\"page_nav\">\n" .
2466 "<br/><br/></div>\n" .
2467 "<div class=\"title\">$hash</div>\n";
2469 git_print_page_path($file_name, "blob", $hash_base);
2470 print "<div class=\"page_body\">\n";
2471 my $nr;
2472 while (my $line = <$fd>) {
2473 chomp $line;
2474 $nr++;
2475 $line = untabify($line);
2476 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2477 $nr, $nr, $nr, esc_html($line);
2479 close $fd
2480 or print "Reading blob failed.\n";
2481 print "</div>";
2482 git_footer_html();
2485 sub git_tree {
2486 if (!defined $hash) {
2487 $hash = git_get_head_hash($project);
2488 if (defined $file_name) {
2489 my $base = $hash_base || $hash;
2490 $hash = git_get_hash_by_path($base, $file_name, "tree");
2492 if (!defined $hash_base) {
2493 $hash_base = $hash;
2496 $/ = "\0";
2497 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
2498 or die_error(undef, "Open git-ls-tree failed");
2499 my @entries = map { chomp; $_ } <$fd>;
2500 close $fd or die_error(undef, "Reading tree failed");
2501 $/ = "\n";
2503 my $refs = git_get_references();
2504 my $ref = format_ref_marker($refs, $hash_base);
2505 git_header_html();
2506 my %base_key = ();
2507 my $base = "";
2508 my $have_blame = gitweb_check_feature('blame');
2509 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2510 $base_key{hash_base} = $hash_base;
2511 git_print_page_nav('tree','', $hash_base);
2512 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
2513 } else {
2514 print "<div class=\"page_nav\">\n";
2515 print "<br/><br/></div>\n";
2516 print "<div class=\"title\">$hash</div>\n";
2518 if (defined $file_name) {
2519 $base = esc_html("$file_name/");
2521 git_print_page_path($file_name, 'tree', $hash_base);
2522 print "<div class=\"page_body\">\n";
2523 print "<table cellspacing=\"0\">\n";
2524 my $alternate = 0;
2525 foreach my $line (@entries) {
2526 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2527 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2528 my $t_mode = $1;
2529 my $t_type = $2;
2530 my $t_hash = $3;
2531 my $t_name = validate_input($4);
2532 if ($alternate) {
2533 print "<tr class=\"dark\">\n";
2534 } else {
2535 print "<tr class=\"light\">\n";
2537 $alternate ^= 1;
2538 print "<td class=\"mode\">" . mode_str($t_mode) . "</td>\n";
2539 if ($t_type eq "blob") {
2540 print "<td class=\"list\">" .
2541 $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key),
2542 -class => "list"}, esc_html($t_name)) .
2543 "</td>\n" .
2544 "<td class=\"link\">" .
2545 $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2546 "blob");
2547 if ($have_blame) {
2548 print " | " .
2549 $cgi->a({-href => href(action=>"blame", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2550 "blame");
2552 print " | " .
2553 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
2554 hash=>$t_hash, file_name=>"$base$t_name")},
2555 "history") .
2556 " | " .
2557 $cgi->a({-href => href(action=>"blob_plain",
2558 hash=>$t_hash, file_name=>"$base$t_name")},
2559 "raw") .
2560 "</td>\n";
2561 } elsif ($t_type eq "tree") {
2562 print "<td class=\"list\">" .
2563 $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2564 esc_html($t_name)) .
2565 "</td>\n" .
2566 "<td class=\"link\">" .
2567 $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2568 "tree") .
2569 " | " .
2570 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, file_name=>"$base$t_name")},
2571 "history") .
2572 "</td>\n";
2574 print "</tr>\n";
2576 print "</table>\n" .
2577 "</div>";
2578 git_footer_html();
2581 sub git_snapshot {
2583 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
2584 my $have_snapshot = (defined $ctype && defined $suffix);
2585 if (!$have_snapshot) {
2586 die_error('403 Permission denied', "Permission denied");
2589 if (!defined $hash) {
2590 $hash = git_get_head_hash($project);
2593 my $filename = basename($project) . "-$hash.tar.$suffix";
2595 print $cgi->header(-type => 'application/x-tar',
2596 -content_encoding => $ctype,
2597 -content_disposition => "inline; filename=\"$filename\"",
2598 -status => '200 OK');
2600 open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | $command" or
2601 die_error(undef, "Execute git-tar-tree failed.");
2602 binmode STDOUT, ':raw';
2603 print <$fd>;
2604 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
2605 close $fd;
2609 sub git_log {
2610 my $head = git_get_head_hash($project);
2611 if (!defined $hash) {
2612 $hash = $head;
2614 if (!defined $page) {
2615 $page = 0;
2617 my $refs = git_get_references();
2619 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2620 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2621 or die_error(undef, "Open git-rev-list failed");
2622 my @revlist = map { chomp; $_ } <$fd>;
2623 close $fd;
2625 my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#revlist);
2627 git_header_html();
2628 git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
2630 if (!@revlist) {
2631 my %co = parse_commit($hash);
2633 git_print_header_div('summary', $project);
2634 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2636 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2637 my $commit = $revlist[$i];
2638 my $ref = format_ref_marker($refs, $commit);
2639 my %co = parse_commit($commit);
2640 next if !%co;
2641 my %ad = parse_date($co{'author_epoch'});
2642 git_print_header_div('commit',
2643 "<span class=\"age\">$co{'age_string'}</span>" .
2644 esc_html($co{'title'}) . $ref,
2645 $commit);
2646 print "<div class=\"title_text\">\n" .
2647 "<div class=\"log_link\">\n" .
2648 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
2649 " | " .
2650 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
2651 "<br/>\n" .
2652 "</div>\n" .
2653 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2654 "</div>\n";
2656 print "<div class=\"log_body\">\n";
2657 git_print_simplified_log($co{'comment'});
2658 print "</div>\n";
2660 git_footer_html();
2663 sub git_commit {
2664 my %co = parse_commit($hash);
2665 if (!%co) {
2666 die_error(undef, "Unknown commit object");
2668 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
2669 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
2671 my $parent = $co{'parent'};
2672 if (!defined $parent) {
2673 $parent = "--root";
2675 open my $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts, $parent, $hash
2676 or die_error(undef, "Open git-diff-tree failed");
2677 my @difftree = map { chomp; $_ } <$fd>;
2678 close $fd or die_error(undef, "Reading git-diff-tree failed");
2680 # non-textual hash id's can be cached
2681 my $expires;
2682 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2683 $expires = "+1d";
2685 my $refs = git_get_references();
2686 my $ref = format_ref_marker($refs, $co{'id'});
2688 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
2689 my $have_snapshot = (defined $ctype && defined $suffix);
2691 my $formats_nav = '';
2692 if (defined $file_name && defined $co{'parent'}) {
2693 my $parent = $co{'parent'};
2694 $formats_nav .=
2695 $cgi->a({-href => href(action=>"blame", hash_parent=>$parent, file_name=>$file_name)},
2696 "blame");
2698 git_header_html(undef, $expires);
2699 git_print_page_nav('commit', defined $co{'parent'} ? '' : 'commitdiff',
2700 $hash, $co{'tree'}, $hash,
2701 $formats_nav);
2703 if (defined $co{'parent'}) {
2704 git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash);
2705 } else {
2706 git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash);
2708 print "<div class=\"title_text\">\n" .
2709 "<table cellspacing=\"0\">\n";
2710 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
2711 "<tr>" .
2712 "<td></td><td> $ad{'rfc2822'}";
2713 if ($ad{'hour_local'} < 6) {
2714 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2715 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2716 } else {
2717 printf(" (%02d:%02d %s)",
2718 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2720 print "</td>" .
2721 "</tr>\n";
2722 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
2723 print "<tr><td></td><td> $cd{'rfc2822'}" .
2724 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2725 "</td></tr>\n";
2726 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2727 print "<tr>" .
2728 "<td>tree</td>" .
2729 "<td class=\"sha1\">" .
2730 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),
2731 class => "list"}, $co{'tree'}) .
2732 "</td>" .
2733 "<td class=\"link\">" .
2734 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},
2735 "tree");
2736 if ($have_snapshot) {
2737 print " | " .
2738 $cgi->a({-href => href(action=>"snapshot", hash=>$hash)}, "snapshot");
2740 print "</td>" .
2741 "</tr>\n";
2742 my $parents = $co{'parents'};
2743 foreach my $par (@$parents) {
2744 print "<tr>" .
2745 "<td>parent</td>" .
2746 "<td class=\"sha1\">" .
2747 $cgi->a({-href => href(action=>"commit", hash=>$par),
2748 class => "list"}, $par) .
2749 "</td>" .
2750 "<td class=\"link\">" .
2751 $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") .
2752 " | " .
2753 $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "commitdiff") .
2754 "</td>" .
2755 "</tr>\n";
2757 print "</table>".
2758 "</div>\n";
2760 print "<div class=\"page_body\">\n";
2761 git_print_log($co{'comment'});
2762 print "</div>\n";
2764 git_difftree_body(\@difftree, $hash, $parent);
2766 git_footer_html();
2769 sub git_blobdiff {
2770 my $format = shift || 'html';
2772 my $fd;
2773 my @difftree;
2774 my %diffinfo;
2775 my $expires;
2777 # preparing $fd and %diffinfo for git_patchset_body
2778 # new style URI
2779 if (defined $hash_base && defined $hash_parent_base) {
2780 if (defined $file_name) {
2781 # read raw output
2782 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
2783 "--", $file_name
2784 or die_error(undef, "Open git-diff-tree failed");
2785 @difftree = map { chomp; $_ } <$fd>;
2786 close $fd
2787 or die_error(undef, "Reading git-diff-tree failed");
2788 @difftree
2789 or die_error('404 Not Found', "Blob diff not found");
2791 } elsif (defined $hash &&
2792 $hash =~ /[0-9a-fA-F]{40}/) {
2793 # try to find filename from $hash
2795 # read filtered raw output
2796 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
2797 or die_error(undef, "Open git-diff-tree failed");
2798 @difftree =
2799 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
2800 # $hash == to_id
2801 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
2802 map { chomp; $_ } <$fd>;
2803 close $fd
2804 or die_error(undef, "Reading git-diff-tree failed");
2805 @difftree
2806 or die_error('404 Not Found', "Blob diff not found");
2808 } else {
2809 die_error('404 Not Found', "Missing one of the blob diff parameters");
2812 if (@difftree > 1) {
2813 die_error('404 Not Found', "Ambiguous blob diff specification");
2816 %diffinfo = parse_difftree_raw_line($difftree[0]);
2817 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
2818 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
2820 $hash_parent ||= $diffinfo{'from_id'};
2821 $hash ||= $diffinfo{'to_id'};
2823 # non-textual hash id's can be cached
2824 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
2825 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
2826 $expires = '+1d';
2829 # open patch output
2830 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts,
2831 '-p', $hash_parent_base, $hash_base,
2832 "--", $file_name
2833 or die_error(undef, "Open git-diff-tree failed");
2836 # old/legacy style URI
2837 if (!%diffinfo && # if new style URI failed
2838 defined $hash && defined $hash_parent) {
2839 # fake git-diff-tree raw output
2840 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
2841 $diffinfo{'from_id'} = $hash_parent;
2842 $diffinfo{'to_id'} = $hash;
2843 if (defined $file_name) {
2844 if (defined $file_parent) {
2845 $diffinfo{'status'} = '2';
2846 $diffinfo{'from_file'} = $file_parent;
2847 $diffinfo{'to_file'} = $file_name;
2848 } else { # assume not renamed
2849 $diffinfo{'status'} = '1';
2850 $diffinfo{'from_file'} = $file_name;
2851 $diffinfo{'to_file'} = $file_name;
2853 } else { # no filename given
2854 $diffinfo{'status'} = '2';
2855 $diffinfo{'from_file'} = $hash_parent;
2856 $diffinfo{'to_file'} = $hash;
2859 # non-textual hash id's can be cached
2860 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
2861 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
2862 $expires = '+1d';
2865 # open patch output
2866 open $fd, "-|", $GIT, "diff", '-p', @diff_opts, $hash_parent, $hash
2867 or die_error(undef, "Open git-diff failed");
2868 } else {
2869 die_error('404 Not Found', "Missing one of the blob diff parameters")
2870 unless %diffinfo;
2873 # header
2874 if ($format eq 'html') {
2875 my $formats_nav =
2876 $cgi->a({-href => href(action=>"blobdiff_plain",
2877 hash=>$hash, hash_parent=>$hash_parent,
2878 hash_base=>$hash_base, hash_parent_base=>$hash_parent_base,
2879 file_name=>$file_name, file_parent=>$file_parent)},
2880 "plain");
2881 git_header_html(undef, $expires);
2882 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2883 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2884 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2885 } else {
2886 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
2887 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
2889 if (defined $file_name) {
2890 git_print_page_path($file_name, "blob", $hash_base);
2891 } else {
2892 print "<div class=\"page_path\"></div>\n";
2895 } elsif ($format eq 'plain') {
2896 print $cgi->header(
2897 -type => 'text/plain',
2898 -charset => 'utf-8',
2899 -expires => $expires,
2900 -content_disposition => qq(inline; filename="${file_name}.patch"));
2902 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
2904 } else {
2905 die_error(undef, "Unknown blobdiff format");
2908 # patch
2909 if ($format eq 'html') {
2910 print "<div class=\"page_body\">\n";
2912 git_patchset_body($fd, [ \%diffinfo ], $hash_base, $hash_parent_base);
2913 close $fd;
2915 print "</div>\n"; # class="page_body"
2916 git_footer_html();
2918 } else {
2919 while (my $line = <$fd>) {
2920 $line =~ s!a/($hash|$hash_parent)!a/$diffinfo{'from_file'}!g;
2921 $line =~ s!b/($hash|$hash_parent)!b/$diffinfo{'to_file'}!g;
2923 print $line;
2925 last if $line =~ m!^\+\+\+!;
2927 local $/ = undef;
2928 print <$fd>;
2929 close $fd;
2933 sub git_blobdiff_plain {
2934 git_blobdiff('plain');
2937 sub git_commitdiff {
2938 my $format = shift || 'html';
2939 my %co = parse_commit($hash);
2940 if (!%co) {
2941 die_error(undef, "Unknown commit object");
2943 if (!defined $hash_parent) {
2944 $hash_parent = $co{'parent'} || '--root';
2947 # read commitdiff
2948 my $fd;
2949 my @difftree;
2950 if ($format eq 'html') {
2951 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts,
2952 "--patch-with-raw", "--full-index", $hash_parent, $hash
2953 or die_error(undef, "Open git-diff-tree failed");
2955 while (chomp(my $line = <$fd>)) {
2956 # empty line ends raw part of diff-tree output
2957 last unless $line;
2958 push @difftree, $line;
2961 } elsif ($format eq 'plain') {
2962 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts,
2963 '-p', $hash_parent, $hash
2964 or die_error(undef, "Open git-diff-tree failed");
2966 } else {
2967 die_error(undef, "Unknown commitdiff format");
2970 # non-textual hash id's can be cached
2971 my $expires;
2972 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2973 $expires = "+1d";
2976 # write commit message
2977 if ($format eq 'html') {
2978 my $refs = git_get_references();
2979 my $ref = format_ref_marker($refs, $co{'id'});
2980 my $formats_nav =
2981 $cgi->a({-href => href(action=>"commitdiff_plain",
2982 hash=>$hash, hash_parent=>$hash_parent)},
2983 "plain");
2985 git_header_html(undef, $expires);
2986 git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2987 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
2988 git_print_authorship(\%co);
2989 print "<div class=\"page_body\">\n";
2990 print "<div class=\"log\">\n";
2991 git_print_simplified_log($co{'comment'}, 1); # skip title
2992 print "</div>\n"; # class="log"
2994 } elsif ($format eq 'plain') {
2995 my $refs = git_get_references("tags");
2996 my $tagname = git_get_rev_name_tags($hash);
2997 my $filename = basename($project) . "-$hash.patch";
2999 print $cgi->header(
3000 -type => 'text/plain',
3001 -charset => 'utf-8',
3002 -expires => $expires,
3003 -content_disposition => qq(inline; filename="$filename"));
3004 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
3005 print <<TEXT;
3006 From: $co{'author'}
3007 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3008 Subject: $co{'title'}
3009 TEXT
3010 print "X-Git-Tag: $tagname\n" if $tagname;
3011 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3013 foreach my $line (@{$co{'comment'}}) {
3014 print "$line\n";
3016 print "---\n\n";
3019 # write patch
3020 if ($format eq 'html') {
3021 git_difftree_body(\@difftree, $hash, $hash_parent);
3022 print "<br/>\n";
3024 git_patchset_body($fd, \@difftree, $hash, $hash_parent);
3025 close $fd;
3026 print "</div>\n"; # class="page_body"
3027 git_footer_html();
3029 } elsif ($format eq 'plain') {
3030 local $/ = undef;
3031 print <$fd>;
3032 close $fd
3033 or print "Reading git-diff-tree failed\n";
3037 sub git_commitdiff_plain {
3038 git_commitdiff('plain');
3041 sub git_history {
3042 if (!defined $hash_base) {
3043 $hash_base = git_get_head_hash($project);
3045 my $ftype;
3046 my %co = parse_commit($hash_base);
3047 if (!%co) {
3048 die_error(undef, "Unknown commit object");
3050 my $refs = git_get_references();
3051 git_header_html();
3052 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base);
3053 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
3054 if (!defined $hash && defined $file_name) {
3055 $hash = git_get_hash_by_path($hash_base, $file_name);
3057 if (defined $hash) {
3058 $ftype = git_get_type($hash);
3060 git_print_page_path($file_name, $ftype, $hash_base);
3062 open my $fd, "-|",
3063 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
3064 git_history_body($fd, $refs, $hash_base, $ftype);
3066 close $fd;
3067 git_footer_html();
3070 sub git_search {
3071 if (!defined $searchtext) {
3072 die_error(undef, "Text field empty");
3074 if (!defined $hash) {
3075 $hash = git_get_head_hash($project);
3077 my %co = parse_commit($hash);
3078 if (!%co) {
3079 die_error(undef, "Unknown commit object");
3081 # pickaxe may take all resources of your box and run for several minutes
3082 # with every query - so decide by yourself how public you make this feature :)
3083 my $commit_search = 1;
3084 my $author_search = 0;
3085 my $committer_search = 0;
3086 my $pickaxe_search = 0;
3087 if ($searchtext =~ s/^author\\://i) {
3088 $author_search = 1;
3089 } elsif ($searchtext =~ s/^committer\\://i) {
3090 $committer_search = 1;
3091 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3092 $commit_search = 0;
3093 $pickaxe_search = 1;
3095 git_header_html();
3096 git_print_page_nav('','', $hash,$co{'tree'},$hash);
3097 git_print_header_div('commit', esc_html($co{'title'}), $hash);
3099 print "<table cellspacing=\"0\">\n";
3100 my $alternate = 0;
3101 if ($commit_search) {
3102 $/ = "\0";
3103 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
3104 while (my $commit_text = <$fd>) {
3105 if (!grep m/$searchtext/i, $commit_text) {
3106 next;
3108 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3109 next;
3111 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3112 next;
3114 my @commit_lines = split "\n", $commit_text;
3115 my %co = parse_commit(undef, \@commit_lines);
3116 if (!%co) {
3117 next;
3119 if ($alternate) {
3120 print "<tr class=\"dark\">\n";
3121 } else {
3122 print "<tr class=\"light\">\n";
3124 $alternate ^= 1;
3125 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3126 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3127 "<td>" .
3128 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"},
3129 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
3130 my $comment = $co{'comment'};
3131 foreach my $line (@$comment) {
3132 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3133 my $lead = esc_html($1) || "";
3134 $lead = chop_str($lead, 30, 10);
3135 my $match = esc_html($2) || "";
3136 my $trail = esc_html($3) || "";
3137 $trail = chop_str($trail, 30, 10);
3138 my $text = "$lead<span class=\"match\">$match</span>$trail";
3139 print chop_str($text, 80, 5) . "<br/>\n";
3142 print "</td>\n" .
3143 "<td class=\"link\">" .
3144 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
3145 " | " .
3146 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
3147 print "</td>\n" .
3148 "</tr>\n";
3150 close $fd;
3153 if ($pickaxe_search) {
3154 $/ = "\n";
3155 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
3156 undef %co;
3157 my @files;
3158 while (my $line = <$fd>) {
3159 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3160 my %set;
3161 $set{'file'} = $6;
3162 $set{'from_id'} = $3;
3163 $set{'to_id'} = $4;
3164 $set{'id'} = $set{'to_id'};
3165 if ($set{'id'} =~ m/0{40}/) {
3166 $set{'id'} = $set{'from_id'};
3168 if ($set{'id'} =~ m/0{40}/) {
3169 next;
3171 push @files, \%set;
3172 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3173 if (%co) {
3174 if ($alternate) {
3175 print "<tr class=\"dark\">\n";
3176 } else {
3177 print "<tr class=\"light\">\n";
3179 $alternate ^= 1;
3180 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3181 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3182 "<td>" .
3183 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
3184 -class => "list subject"},
3185 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
3186 while (my $setref = shift @files) {
3187 my %set = %$setref;
3188 print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},
3189 hash=>$set{'id'}, file_name=>$set{'file'}),
3190 -class => "list"},
3191 "<span class=\"match\">" . esc_html($set{'file'}) . "</span>") .
3192 "<br/>\n";
3194 print "</td>\n" .
3195 "<td class=\"link\">" .
3196 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
3197 " | " .
3198 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
3199 print "</td>\n" .
3200 "</tr>\n";
3202 %co = parse_commit($1);
3205 close $fd;
3207 print "</table>\n";
3208 git_footer_html();
3211 sub git_shortlog {
3212 my $head = git_get_head_hash($project);
3213 if (!defined $hash) {
3214 $hash = $head;
3216 if (!defined $page) {
3217 $page = 0;
3219 my $refs = git_get_references();
3221 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3222 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
3223 or die_error(undef, "Open git-rev-list failed");
3224 my @revlist = map { chomp; $_ } <$fd>;
3225 close $fd;
3227 my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, $#revlist);
3228 my $next_link = '';
3229 if ($#revlist >= (100 * ($page+1)-1)) {
3230 $next_link =
3231 $cgi->a({-href => href(action=>"shortlog", hash=>$hash, page=>$page+1),
3232 -title => "Alt-n"}, "next");
3236 git_header_html();
3237 git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);
3238 git_print_header_div('summary', $project);
3240 git_shortlog_body(\@revlist, ($page * 100), $#revlist, $refs, $next_link);
3242 git_footer_html();
3245 ## ......................................................................
3246 ## feeds (RSS, OPML)
3248 sub git_rss {
3249 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3250 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash($project)
3251 or die_error(undef, "Open git-rev-list failed");
3252 my @revlist = map { chomp; $_ } <$fd>;
3253 close $fd or die_error(undef, "Reading git-rev-list failed");
3254 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
3255 print <<XML;
3256 <?xml version="1.0" encoding="utf-8"?>
3257 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3258 <channel>
3259 <title>$project $my_uri $my_url</title>
3260 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3261 <description>$project log</description>
3262 <language>en</language>
3265 for (my $i = 0; $i <= $#revlist; $i++) {
3266 my $commit = $revlist[$i];
3267 my %co = parse_commit($commit);
3268 # we read 150, we always show 30 and the ones more recent than 48 hours
3269 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3270 last;
3272 my %cd = parse_date($co{'committer_epoch'});
3273 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts,
3274 $co{'parent'}, $co{'id'}
3275 or next;
3276 my @difftree = map { chomp; $_ } <$fd>;
3277 close $fd
3278 or next;
3279 print "<item>\n" .
3280 "<title>" .
3281 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) .
3282 "</title>\n" .
3283 "<author>" . esc_html($co{'author'}) . "</author>\n" .
3284 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3285 "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3286 "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3287 "<description>" . esc_html($co{'title'}) . "</description>\n" .
3288 "<content:encoded>" .
3289 "<![CDATA[\n";
3290 my $comment = $co{'comment'};
3291 foreach my $line (@$comment) {
3292 $line = decode("utf8", $line, Encode::FB_DEFAULT);
3293 print "$line<br/>\n";
3295 print "<br/>\n";
3296 foreach my $line (@difftree) {
3297 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3298 next;
3300 my $file = validate_input(unquote($7));
3301 $file = decode("utf8", $file, Encode::FB_DEFAULT);
3302 print "$file<br/>\n";
3304 print "]]>\n" .
3305 "</content:encoded>\n" .
3306 "</item>\n";
3308 print "</channel></rss>";
3311 sub git_opml {
3312 my @list = git_get_projects_list();
3314 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
3315 print <<XML;
3316 <?xml version="1.0" encoding="utf-8"?>
3317 <opml version="1.0">
3318 <head>
3319 <title>$site_name Git OPML Export</title>
3320 </head>
3321 <body>
3322 <outline text="git RSS feeds">
3325 foreach my $pr (@list) {
3326 my %proj = %$pr;
3327 my $head = git_get_head_hash($proj{'path'});
3328 if (!defined $head) {
3329 next;
3331 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
3332 my %co = parse_commit($head);
3333 if (!%co) {
3334 next;
3337 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
3338 my $rss = "$my_url?p=$proj{'path'};a=rss";
3339 my $html = "$my_url?p=$proj{'path'};a=summary";
3340 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
3342 print <<XML;
3343 </outline>
3344 </body>
3345 </opml>