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
12 use CGI qw(:standard :escapeHTML -nosticky);
13 use CGI::Util qw(unescape);
14 use CGI::Carp qw(fatalsToBrowser);
18 use File::Basename qw(basename);
19 binmode STDOUT, ':utf8';
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++";
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.
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
82 'sub' => \&feature_blame,
87 'sub' => \&feature_snapshot,
89 # => [content-encoding, suffix, program]
90 'default' => ['x-gzip', 'gz', 'gzip']},
93 sub gitweb_check_feature {
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;
111 my ($val) = git_get_project_config('blame', '--bool');
113 if ($val eq 'true') {
115 } elsif ($val eq 'false') {
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') {
141 return ($ctype, $suffix, $command);
144 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
145 require $GITWEB_CONFIG if -e $GITWEB_CONFIG;
147 # version of the core git binary
148 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
150 $projects_list ||= $projectroot;
152 # ======================================================================
153 # input validation and dispatch
154 our $action = $cgi->param('a');
155 if (defined $action) {
156 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
157 die_error(undef, "Invalid action parameter");
161 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
162 if (defined $project) {
165 $project = undef unless $project;
167 if (defined $project) {
168 if (!validate_input($project)) {
169 die_error(undef, "Invalid project parameter");
171 if (!(-d "$projectroot/$project")) {
172 die_error(undef, "No such directory");
174 if (!(-e "$projectroot/$project/HEAD")) {
175 die_error(undef, "No such project");
177 $ENV{'GIT_DIR'} = "$projectroot/$project";
180 our $file_name = $cgi->param('f');
181 if (defined $file_name) {
182 if (!validate_input($file_name)) {
183 die_error(undef, "Invalid file parameter");
187 our $file_parent = $cgi->param('fp');
188 if (defined $file_parent) {
189 if (!validate_input($file_parent)) {
190 die_error(undef, "Invalid file parent parameter");
194 our $hash = $cgi->param('h');
196 if (!validate_input($hash)) {
197 die_error(undef, "Invalid hash parameter");
201 our $hash_parent = $cgi->param('hp');
202 if (defined $hash_parent) {
203 if (!validate_input($hash_parent)) {
204 die_error(undef, "Invalid hash parent parameter");
208 our $hash_base = $cgi->param('hb');
209 if (defined $hash_base) {
210 if (!validate_input($hash_base)) {
211 die_error(undef, "Invalid hash base parameter");
215 our $hash_parent_base = $cgi->param('hpb');
216 if (defined $hash_parent_base) {
217 if (!validate_input($hash_parent_base)) {
218 die_error(undef, "Invalid hash parent base parameter");
222 our $page = $cgi->param('pg');
224 if ($page =~ m/[^0-9]$/) {
225 die_error(undef, "Invalid page parameter");
229 our $searchtext = $cgi->param('s');
230 if (defined $searchtext) {
231 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) {
232 die_error(undef, "Invalid search parameter");
234 $searchtext = quotemeta $searchtext;
239 "blame" => \&git_blame2,
240 "blobdiff" => \&git_blobdiff,
241 "blobdiff_plain" => \&git_blobdiff_plain,
242 "blob" => \&git_blob,
243 "blob_plain" => \&git_blob_plain,
244 "commitdiff" => \&git_commitdiff,
245 "commitdiff_plain" => \&git_commitdiff_plain,
246 "commit" => \&git_commit,
247 "heads" => \&git_heads,
248 "history" => \&git_history,
251 "search" => \&git_search,
252 "shortlog" => \&git_shortlog,
253 "summary" => \&git_summary,
255 "tags" => \&git_tags,
256 "tree" => \&git_tree,
257 "snapshot" => \&git_snapshot,
258 # those below don't need $project
259 "opml" => \&git_opml,
260 "project_list" => \&git_project_list,
263 if (defined $project) {
264 $action ||= 'summary';
266 $action ||= 'project_list';
268 if (!defined($actions{$action})) {
269 die_error(undef, "Unknown action");
271 $actions{$action}->();
274 ## ======================================================================
288 hash_parent_base => "hpb",
292 my %mapping = @mapping;
294 $params{"project"} ||= $project;
297 for (my $i = 0; $i < @mapping; $i += 2) {
298 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
299 if (defined $params{$name}) {
300 push @result, $symbol . "=" . esc_param($params{$name});
303 return "$my_uri?" . join(';', @result);
307 ## ======================================================================
308 ## validation, quoting/unquoting and escaping
313 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
316 if ($input =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
319 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\-\+\#\~\%]/) {
325 # quote unsafe chars, but keep the slash, even when it's not
326 # correct, but quoted slashes look too horrible in bookmarks
329 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
335 # replace invalid utf8 character with SUBSTITUTION sequence
338 $str = decode("utf8", $str, Encode::FB_DEFAULT);
339 $str = escapeHTML($str);
340 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
344 # git may return quoted and escaped filenames
347 if ($str =~ m/^"(.*)"$/) {
349 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
354 # escape tabs (convert tabs to spaces)
358 while ((my $pos = index($line, "\t")) != -1) {
359 if (my $count = (8 - ($pos % 8))) {
360 my $spaces = ' ' x $count;
361 $line =~ s/\t/$spaces/;
368 ## ----------------------------------------------------------------------
369 ## HTML aware string manipulation
374 my $add_len = shift || 10;
376 # allow only $len chars, but don't cut a word if it would fit in $add_len
377 # if it doesn't fit, cut it if it's still longer than the dots we would add
378 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
381 if (length($tail) > 4) {
383 $body =~ s/&[^;]*$//; # remove chopped character entities
388 ## ----------------------------------------------------------------------
389 ## functions returning short strings
391 # CSS class for given age value (in seconds)
395 if ($age < 60*60*2) {
397 } elsif ($age < 60*60*24*2) {
404 # convert age in seconds to "nn units ago" string
409 if ($age > 60*60*24*365*2) {
410 $age_str = (int $age/60/60/24/365);
411 $age_str .= " years ago";
412 } elsif ($age > 60*60*24*(365/12)*2) {
413 $age_str = int $age/60/60/24/(365/12);
414 $age_str .= " months ago";
415 } elsif ($age > 60*60*24*7*2) {
416 $age_str = int $age/60/60/24/7;
417 $age_str .= " weeks ago";
418 } elsif ($age > 60*60*24*2) {
419 $age_str = int $age/60/60/24;
420 $age_str .= " days ago";
421 } elsif ($age > 60*60*2) {
422 $age_str = int $age/60/60;
423 $age_str .= " hours ago";
424 } elsif ($age > 60*2) {
425 $age_str = int $age/60;
426 $age_str .= " min ago";
429 $age_str .= " sec ago";
431 $age_str .= " right now";
436 # convert file mode in octal to symbolic file mode string
438 my $mode = oct shift;
440 if (S_ISDIR($mode & S_IFMT)) {
442 } elsif (S_ISLNK($mode)) {
444 } elsif (S_ISREG($mode)) {
445 # git cares only about the executable bit
446 if ($mode & S_IXUSR) {
456 # convert file mode in octal to file type string
460 if ($mode !~ m/^[0-7]+$/) {
466 if (S_ISDIR($mode & S_IFMT)) {
468 } elsif (S_ISLNK($mode)) {
470 } elsif (S_ISREG($mode)) {
477 ## ----------------------------------------------------------------------
478 ## functions returning short HTML fragments, or transforming HTML fragments
479 ## which don't beling to other sections
481 # format line of commit message or tag comment
482 sub format_log_line_html {
485 $line = esc_html($line);
486 $line =~ s/ / /g;
487 if ($line =~ m/([0-9a-fA-F]{40})/) {
489 if (git_get_type($hash_text) eq "commit") {
491 $cgi->a({-href => href(action=>"commit", hash=>$hash_text),
492 -class => "text"}, $hash_text);
493 $line =~ s/$hash_text/$link/;
499 # format marker of refs pointing to given object
500 sub format_ref_marker {
501 my ($refs, $id) = @_;
504 if (defined $refs->{$id}) {
505 foreach my $ref (@{$refs->{$id}}) {
506 my ($type, $name) = qw();
507 # e.g. tags/v2.6.11 or heads/next
508 if ($ref =~ m!^(.*?)s?/(.*)$!) {
516 $markers .= " <span class=\"$type\">" . esc_html($name) . "</span>";
521 return ' <span class="refs">'. $markers . '</span>';
527 # format, perhaps shortened and with markers, title line
528 sub format_subject_html {
529 my ($long, $short, $href, $extra) = @_;
530 $extra = '' unless defined($extra);
532 if (length($short) < length($long)) {
533 return $cgi->a({-href => $href, -class => "list subject",
535 esc_html($short) . $extra);
537 return $cgi->a({-href => $href, -class => "list subject"},
538 esc_html($long) . $extra);
542 sub format_diff_line {
544 my $char = substr($line, 0, 1);
550 $diff_class = " add";
551 } elsif ($char eq "-") {
552 $diff_class = " rem";
553 } elsif ($char eq "@") {
554 $diff_class = " chunk_header";
555 } elsif ($char eq "\\") {
556 $diff_class = " incomplete";
558 $line = untabify($line);
559 return "<div class=\"diff$diff_class\">" . esc_html($line) . "</div>\n";
562 ## ----------------------------------------------------------------------
563 ## git utility subroutines, invoking git commands
565 # get HEAD ref of given project as hash
566 sub git_get_head_hash {
568 my $oENV = $ENV{'GIT_DIR'};
570 $ENV{'GIT_DIR'} = "$projectroot/$project";
571 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
574 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
579 $ENV{'GIT_DIR'} = $oENV;
584 # get type of given object
588 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
595 sub git_get_project_config {
596 my ($key, $type) = @_;
598 return unless ($key);
599 $key =~ s/^gitweb\.//;
600 return if ($key =~ m/\W/);
602 my @x = ($GIT, 'repo-config');
603 if (defined $type) { push @x, $type; }
605 push @x, "gitweb.$key";
611 # get hash of given path at given ref
612 sub git_get_hash_by_path {
614 my $path = shift || return undef;
618 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
619 or die_error(undef, "Open git-ls-tree failed");
621 close $fd or return undef;
623 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
624 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
628 ## ......................................................................
629 ## git utility functions, directly accessing git repository
631 # assumes that PATH is not symref
632 sub git_get_hash_by_ref {
635 open my $fd, "$projectroot/$path" or return undef;
639 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
644 sub git_get_project_description {
647 open my $fd, "$projectroot/$path/description" or return undef;
654 sub git_get_project_url_list {
657 open my $fd, "$projectroot/$path/cloneurl" or return undef;
658 my @git_project_url_list = map { chomp; $_ } <$fd>;
661 return wantarray ? @git_project_url_list : \@git_project_url_list;
664 sub git_get_projects_list {
667 if (-d $projects_list) {
668 # search in directory
669 my $dir = $projects_list;
670 opendir my ($dh), $dir or return undef;
671 while (my $dir = readdir($dh)) {
672 if (-e "$projectroot/$dir/HEAD") {
680 } elsif (-f $projects_list) {
681 # read from file(url-encoded):
682 # 'git%2Fgit.git Linus+Torvalds'
683 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
684 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
685 open my ($fd), $projects_list or return undef;
686 while (my $line = <$fd>) {
688 my ($path, $owner) = split ' ', $line;
689 $path = unescape($path);
690 $owner = unescape($owner);
691 if (!defined $path) {
694 if (-e "$projectroot/$path/HEAD") {
697 owner => decode("utf8", $owner, Encode::FB_DEFAULT),
704 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
708 sub git_get_project_owner {
712 return undef unless $project;
714 # read from file (url-encoded):
715 # 'git%2Fgit.git Linus+Torvalds'
716 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
717 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
718 if (-f $projects_list) {
719 open (my $fd , $projects_list);
720 while (my $line = <$fd>) {
722 my ($pr, $ow) = split ' ', $line;
725 if ($pr eq $project) {
726 $owner = decode("utf8", $ow, Encode::FB_DEFAULT);
732 if (!defined $owner) {
733 $owner = get_file_owner("$projectroot/$project");
739 sub git_get_references {
740 my $type = shift || "";
743 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
744 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
745 if (-f "$projectroot/$project/info/refs") {
746 open $fd, "$projectroot/$project/info/refs"
749 open $fd, "-|", $GIT, "ls-remote", "."
753 while (my $line = <$fd>) {
755 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?[^\^]+)/) {
756 if (defined $refs{$1}) {
757 push @{$refs{$1}}, $2;
767 sub git_get_rev_name_tags {
768 my $hash = shift || return undef;
770 open my $fd, "-|", $GIT, "name-rev", "--tags", $hash
772 my $name_rev = <$fd>;
775 if ($name_rev =~ m|^$hash tags/(.*)$|) {
778 # catches also '$hash undefined' output
783 ## ----------------------------------------------------------------------
784 ## parse to hash functions
788 my $tz = shift || "-0000";
791 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
792 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
793 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
794 $date{'hour'} = $hour;
795 $date{'minute'} = $min;
796 $date{'mday'} = $mday;
797 $date{'day'} = $days[$wday];
798 $date{'month'} = $months[$mon];
799 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
800 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
801 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
802 $mday, $months[$mon], $hour ,$min;
804 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
805 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
806 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
807 $date{'hour_local'} = $hour;
808 $date{'minute_local'} = $min;
809 $date{'tz_local'} = $tz;
818 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
819 $tag{'id'} = $tag_id;
820 while (my $line = <$fd>) {
822 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
824 } elsif ($line =~ m/^type (.+)$/) {
826 } elsif ($line =~ m/^tag (.+)$/) {
828 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
832 } elsif ($line =~ m/--BEGIN/) {
833 push @comment, $line;
835 } elsif ($line eq "") {
839 push @comment, <$fd>;
840 $tag{'comment'} = \@comment;
842 if (!defined $tag{'name'}) {
849 my $commit_id = shift;
850 my $commit_text = shift;
855 if (defined $commit_text) {
856 @commit_lines = @$commit_text;
859 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id
861 @commit_lines = split '\n', <$fd>;
866 my $header = shift @commit_lines;
867 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
870 ($co{'id'}, my @parents) = split ' ', $header;
871 $co{'parents'} = \@parents;
872 $co{'parent'} = $parents[0];
873 while (my $line = shift @commit_lines) {
874 last if $line eq "\n";
875 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
877 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
879 $co{'author_epoch'} = $2;
880 $co{'author_tz'} = $3;
881 if ($co{'author'} =~ m/^([^<]+) </) {
882 $co{'author_name'} = $1;
884 $co{'author_name'} = $co{'author'};
886 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
887 $co{'committer'} = $1;
888 $co{'committer_epoch'} = $2;
889 $co{'committer_tz'} = $3;
890 $co{'committer_name'} = $co{'committer'};
891 $co{'committer_name'} =~ s/ <.*//;
894 if (!defined $co{'tree'}) {
898 foreach my $title (@commit_lines) {
901 $co{'title'} = chop_str($title, 80, 5);
902 # remove leading stuff of merges to make the interesting part visible
903 if (length($title) > 50) {
904 $title =~ s/^Automatic //;
905 $title =~ s/^merge (of|with) /Merge ... /i;
906 if (length($title) > 50) {
907 $title =~ s/(http|rsync):\/\///;
909 if (length($title) > 50) {
910 $title =~ s/(master|www|rsync)\.//;
912 if (length($title) > 50) {
913 $title =~ s/kernel.org:?//;
915 if (length($title) > 50) {
916 $title =~ s/\/pub\/scm//;
919 $co{'title_short'} = chop_str($title, 50, 5);
923 # remove added spaces
924 foreach my $line (@commit_lines) {
927 $co{'comment'} = \@commit_lines;
929 my $age = time - $co{'committer_epoch'};
931 $co{'age_string'} = age_string($age);
932 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
933 if ($age > 60*60*24*7*2) {
934 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
935 $co{'age_string_age'} = $co{'age_string'};
937 $co{'age_string_date'} = $co{'age_string'};
938 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
943 # parse ref from ref_file, given by ref_id, with given type
945 my $ref_file = shift;
947 my $type = shift || git_get_type($ref_id);
950 $ref_item{'type'} = $type;
951 $ref_item{'id'} = $ref_id;
952 $ref_item{'epoch'} = 0;
953 $ref_item{'age'} = "unknown";
954 if ($type eq "tag") {
955 my %tag = parse_tag($ref_id);
956 $ref_item{'comment'} = $tag{'comment'};
957 if ($tag{'type'} eq "commit") {
958 my %co = parse_commit($tag{'object'});
959 $ref_item{'epoch'} = $co{'committer_epoch'};
960 $ref_item{'age'} = $co{'age_string'};
961 } elsif (defined($tag{'epoch'})) {
962 my $age = time - $tag{'epoch'};
963 $ref_item{'epoch'} = $tag{'epoch'};
964 $ref_item{'age'} = age_string($age);
966 $ref_item{'reftype'} = $tag{'type'};
967 $ref_item{'name'} = $tag{'name'};
968 $ref_item{'refid'} = $tag{'object'};
969 } elsif ($type eq "commit"){
970 my %co = parse_commit($ref_id);
971 $ref_item{'reftype'} = "commit";
972 $ref_item{'name'} = $ref_file;
973 $ref_item{'title'} = $co{'title'};
974 $ref_item{'refid'} = $ref_id;
975 $ref_item{'epoch'} = $co{'committer_epoch'};
976 $ref_item{'age'} = $co{'age_string'};
978 $ref_item{'reftype'} = $type;
979 $ref_item{'name'} = $ref_file;
980 $ref_item{'refid'} = $ref_id;
986 # parse line of git-diff-tree "raw" output
987 sub parse_difftree_raw_line {
991 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
992 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
993 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
994 $res{'from_mode'} = $1;
995 $res{'to_mode'} = $2;
996 $res{'from_id'} = $3;
999 $res{'similarity'} = $6;
1000 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1001 ($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
1003 $res{'file'} = unquote($7);
1006 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1007 #elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1008 # $res{'commit'} = $1;
1011 return wantarray ? %res : \%res;
1014 ## ......................................................................
1015 ## parse to array of hashes functions
1017 sub git_get_refs_list {
1018 my $ref_dir = shift;
1022 my $pfxlen = length("$projectroot/$project/$ref_dir");
1023 File::Find::find(sub {
1026 push @refs, substr($File::Find::name, $pfxlen + 1);
1028 }, "$projectroot/$project/$ref_dir");
1030 foreach my $ref_file (@refs) {
1031 my $ref_id = git_get_hash_by_ref("$project/$ref_dir/$ref_file");
1032 my $type = git_get_type($ref_id) || next;
1033 my %ref_item = parse_ref($ref_file, $ref_id, $type);
1035 push @reflist, \%ref_item;
1038 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1042 ## ----------------------------------------------------------------------
1043 ## filesystem-related functions
1045 sub get_file_owner {
1048 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1049 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1050 if (!defined $gcos) {
1054 $owner =~ s/[,;].*$//;
1055 return decode("utf8", $owner, Encode::FB_DEFAULT);
1058 ## ......................................................................
1059 ## mimetype related functions
1061 sub mimetype_guess_file {
1062 my $filename = shift;
1063 my $mimemap = shift;
1064 -r $mimemap or return undef;
1067 open(MIME, $mimemap) or return undef;
1069 next if m/^#/; # skip comments
1070 my ($mime, $exts) = split(/\t+/);
1071 if (defined $exts) {
1072 my @exts = split(/\s+/, $exts);
1073 foreach my $ext (@exts) {
1074 $mimemap{$ext} = $mime;
1080 $filename =~ /\.(.*?)$/;
1081 return $mimemap{$1};
1084 sub mimetype_guess {
1085 my $filename = shift;
1087 $filename =~ /\./ or return undef;
1089 if ($mimetypes_file) {
1090 my $file = $mimetypes_file;
1091 if ($file !~ m!^/!) { # if it is relative path
1092 # it is relative to project
1093 $file = "$projectroot/$project/$file";
1095 $mime = mimetype_guess_file($filename, $file);
1097 $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
1103 my $filename = shift;
1106 my $mime = mimetype_guess($filename);
1107 $mime and return $mime;
1111 return $default_blob_plain_mimetype unless $fd;
1114 return 'text/plain' .
1115 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1116 } elsif (! $filename) {
1117 return 'application/octet-stream';
1118 } elsif ($filename =~ m/\.png$/i) {
1120 } elsif ($filename =~ m/\.gif$/i) {
1122 } elsif ($filename =~ m/\.jpe?g$/i) {
1123 return 'image/jpeg';
1125 return 'application/octet-stream';
1129 ## ======================================================================
1130 ## functions printing HTML: header, footer, error page
1132 sub git_header_html {
1133 my $status = shift || "200 OK";
1134 my $expires = shift;
1136 my $title = "$site_name git";
1137 if (defined $project) {
1138 $title .= " - $project";
1139 if (defined $action) {
1140 $title .= "/$action";
1141 if (defined $file_name) {
1142 $title .= " - $file_name";
1143 if ($action eq "tree" && $file_name !~ m|/$|) {
1150 # require explicit support from the UA if we are to send the page as
1151 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1152 # we have to do this because MSIE sometimes globs '*/*', pretending to
1153 # support xhtml+xml but choking when it gets what it asked for.
1154 if (defined $cgi->http('HTTP_ACCEPT') &&
1155 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&
1156 $cgi->Accept('application/xhtml+xml') != 0) {
1157 $content_type = 'application/xhtml+xml';
1159 $content_type = 'text/html';
1161 print $cgi->header(-type=>$content_type, -charset => 'utf-8',
1162 -status=> $status, -expires => $expires);
1164 <?xml version="1.0" encoding="utf-8"?>
1165 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1166 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1167 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1168 <!-- git core binaries version $git_version -->
1170 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1171 <meta name="generator" content="gitweb/$version git/$git_version"/>
1172 <meta name="robots" content="index, nofollow"/>
1173 <title>$title</title>
1174 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1176 if (defined $project) {
1177 printf('<link rel="alternate" title="%s log" '.
1178 'href="%s" type="application/rss+xml"/>'."\n",
1179 esc_param($project), href(action=>"rss"));
1184 "<div class=\"page_header\">\n" .
1185 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1186 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1188 print $cgi->a({-href => esc_param($home_link)}, $home_link_str) . " / ";
1189 if (defined $project) {
1190 print $cgi->a({-href => href(action=>"summary")}, esc_html($project));
1191 if (defined $action) {
1195 if (!defined $searchtext) {
1199 if (defined $hash_base) {
1200 $search_hash = $hash_base;
1201 } elsif (defined $hash) {
1202 $search_hash = $hash;
1204 $search_hash = "HEAD";
1206 $cgi->param("a", "search");
1207 $cgi->param("h", $search_hash);
1208 print $cgi->startform(-method => "get", -action => $my_uri) .
1209 "<div class=\"search\">\n" .
1210 $cgi->hidden(-name => "p") . "\n" .
1211 $cgi->hidden(-name => "a") . "\n" .
1212 $cgi->hidden(-name => "h") . "\n" .
1213 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
1215 $cgi->end_form() . "\n";
1220 sub git_footer_html {
1221 print "<div class=\"page_footer\">\n";
1222 if (defined $project) {
1223 my $descr = git_get_project_description($project);
1224 if (defined $descr) {
1225 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
1227 print $cgi->a({-href => href(action=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1229 print $cgi->a({-href => href(action=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1237 my $status = shift || "403 Forbidden";
1238 my $error = shift || "Malformed query, file missing or permission denied";
1240 git_header_html($status);
1242 <div class="page_body">
1252 ## ----------------------------------------------------------------------
1253 ## functions printing or outputting HTML: navigation
1255 sub git_print_page_nav {
1256 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1257 $extra = '' if !defined $extra; # pager or formats
1259 my @navs = qw(summary shortlog log commit commitdiff tree);
1261 @navs = grep { $_ ne $suppress } @navs;
1264 my %arg = map { $_ => {action=>$_} } @navs;
1265 if (defined $head) {
1266 for (qw(commit commitdiff)) {
1267 $arg{$_}{hash} = $head;
1269 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1270 for (qw(shortlog log)) {
1271 $arg{$_}{hash} = $head;
1275 $arg{tree}{hash} = $treehead if defined $treehead;
1276 $arg{tree}{hash_base} = $treebase if defined $treebase;
1278 print "<div class=\"page_nav\">\n" .
1280 map { $_ eq $current ?
1281 $_ : $cgi->a({-href => href(%{$arg{$_}})}, "$_")
1283 print "<br/>\n$extra<br/>\n" .
1287 sub format_paging_nav {
1288 my ($action, $hash, $head, $page, $nrevs) = @_;
1292 if ($hash ne $head || $page) {
1293 $paging_nav .= $cgi->a({-href => href(action=>$action)}, "HEAD");
1295 $paging_nav .= "HEAD";
1299 $paging_nav .= " ⋅ " .
1300 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page-1),
1301 -accesskey => "p", -title => "Alt-p"}, "prev");
1303 $paging_nav .= " ⋅ prev";
1306 if ($nrevs >= (100 * ($page+1)-1)) {
1307 $paging_nav .= " ⋅ " .
1308 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page+1),
1309 -accesskey => "n", -title => "Alt-n"}, "next");
1311 $paging_nav .= " ⋅ next";
1317 ## ......................................................................
1318 ## functions printing or outputting HTML: div
1320 sub git_print_header_div {
1321 my ($action, $title, $hash, $hash_base) = @_;
1324 $args{action} = $action;
1325 $args{hash} = $hash if $hash;
1326 $args{hash_base} = $hash_base if $hash_base;
1328 print "<div class=\"header\">\n" .
1329 $cgi->a({-href => href(%args), -class => "title"},
1330 $title ? $title : $action) .
1334 sub git_print_page_path {
1339 if (!defined $name) {
1340 print "<div class=\"page_path\">/</div>\n";
1341 } elsif (defined $type && $type eq 'blob') {
1342 print "<div class=\"page_path\">";
1344 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,
1348 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name)},
1351 print "<br/></div>\n";
1353 print "<div class=\"page_path\">" . esc_html($name) . "<br/></div>\n";
1360 # remove leading empty lines
1361 while (defined $log->[0] && $log->[0] eq "") {
1368 foreach my $line (@$log) {
1369 # print only one empty line
1370 # do not print empty line after signoff
1372 next if ($empty || $signoff);
1377 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1379 print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
1382 print format_log_line_html($line) . "<br/>\n";
1387 sub git_print_simplified_log {
1389 my $remove_title = shift;
1391 shift @$log if $remove_title;
1392 # remove leading empty lines
1393 while (defined $log->[0] && $log->[0] eq "") {
1397 # simplify and print log
1399 foreach my $line (@$log) {
1400 # remove signoff lines
1401 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1404 # print only one empty line
1411 print format_log_line_html($line) . "<br/>\n";
1413 # end with single empty line
1414 print "<br/>\n" unless $empty;
1417 ## ......................................................................
1418 ## functions printing large fragments of HTML
1420 sub git_difftree_body {
1421 my ($difftree, $hash, $parent) = @_;
1423 print "<div class=\"list_head\">\n";
1424 if ($#{$difftree} > 10) {
1425 print(($#{$difftree} + 1) . " files changed:\n");
1429 print "<table class=\"diff_tree\">\n";
1431 foreach my $line (@{$difftree}) {
1432 my %diff = parse_difftree_raw_line($line);
1435 print "<tr class=\"dark\">\n";
1437 print "<tr class=\"light\">\n";
1441 my ($to_mode_oct, $to_mode_str, $to_file_type);
1442 my ($from_mode_oct, $from_mode_str, $from_file_type);
1443 if ($diff{'to_mode'} ne ('0' x 6)) {
1444 $to_mode_oct = oct $diff{'to_mode'};
1445 if (S_ISREG($to_mode_oct)) { # only for regular file
1446 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1448 $to_file_type = file_type($diff{'to_mode'});
1450 if ($diff{'from_mode'} ne ('0' x 6)) {
1451 $from_mode_oct = oct $diff{'from_mode'};
1452 if (S_ISREG($to_mode_oct)) { # only for regular file
1453 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1455 $from_file_type = file_type($diff{'from_mode'});
1458 if ($diff{'status'} eq "A") { # created
1459 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1460 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1461 $mode_chng .= "]</span>";
1463 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1464 hash_base=>$hash, file_name=>$diff{'file'}),
1465 -class => "list"}, esc_html($diff{'file'})) .
1467 "<td>$mode_chng</td>\n" .
1468 "<td class=\"link\">" .
1469 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1470 hash_base=>$hash, file_name=>$diff{'file'})},
1474 } elsif ($diff{'status'} eq "D") { # deleted
1475 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1477 $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
1478 hash_base=>$parent, file_name=>$diff{'file'}),
1479 -class => "list"}, esc_html($diff{'file'})) .
1481 "<td>$mode_chng</td>\n" .
1482 "<td class=\"link\">" .
1483 $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
1484 hash_base=>$parent, file_name=>$diff{'file'})},
1487 $cgi->a({-href => href(action=>"history", hash_base=>$parent,
1488 file_name=>$diff{'file'})},
1492 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1493 my $mode_chnge = "";
1494 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1495 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1496 if ($from_file_type != $to_file_type) {
1497 $mode_chnge .= " from $from_file_type to $to_file_type";
1499 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1500 if ($from_mode_str && $to_mode_str) {
1501 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1502 } elsif ($to_mode_str) {
1503 $mode_chnge .= " mode: $to_mode_str";
1506 $mode_chnge .= "]</span>\n";
1509 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1510 print $cgi->a({-href => href(action=>"blobdiff",
1511 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1512 hash_base=>$hash, hash_parent_base=>$parent,
1513 file_name=>$diff{'file'}),
1514 -class => "list"}, esc_html($diff{'file'}));
1515 } else { # only mode changed
1516 print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1517 hash_base=>$hash, file_name=>$diff{'file'}),
1518 -class => "list"}, esc_html($diff{'file'}));
1521 "<td>$mode_chnge</td>\n" .
1522 "<td class=\"link\">" .
1523 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1524 hash_base=>$hash, file_name=>$diff{'file'})},
1526 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1528 $cgi->a({-href => href(action=>"blobdiff",
1529 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1530 hash_base=>$hash, hash_parent_base=>$parent,
1531 file_name=>$diff{'file'})},
1535 $cgi->a({-href => href(action=>"history",
1536 hash_base=>$hash, file_name=>$diff{'file'})},
1540 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1541 my %status_name = ('R' => 'moved', 'C' => 'copied');
1542 my $nstatus = $status_name{$diff{'status'}};
1544 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1545 # mode also for directories, so we cannot use $to_mode_str
1546 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1549 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1550 hash=>$diff{'to_id'}, file_name=>$diff{'to_file'}),
1551 -class => "list"}, esc_html($diff{'to_file'})) . "</td>\n" .
1552 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1553 $cgi->a({-href => href(action=>"blob", hash_base=>$parent,
1554 hash=>$diff{'from_id'}, file_name=>$diff{'from_file'}),
1555 -class => "list"}, esc_html($diff{'from_file'})) .
1556 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1557 "<td class=\"link\">" .
1558 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1559 hash=>$diff{'to_id'}, file_name=>$diff{'to_file'})},
1561 if ($diff{'to_id'} ne $diff{'from_id'}) {
1563 $cgi->a({-href => href(action=>"blobdiff",
1564 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1565 hash_base=>$hash, hash_parent_base=>$parent,
1566 file_name=>$diff{'to_file'}, file_parent=>$diff{'from_file'})},
1571 } # we should not encounter Unmerged (U) or Unknown (X) status
1577 sub git_patchset_body {
1578 my ($fd, $difftree, $hash, $hash_parent) = @_;
1582 my $patch_found = 0;
1585 print "<div class=\"patchset\">\n";
1588 while (my $patch_line = <$fd>) {
1591 if ($patch_line =~ m/^diff /) { # "git diff" header
1592 # beginning of patch (in patchset)
1594 # close previous patch
1595 print "</div>\n"; # class="patch"
1597 # first patch in patchset
1600 print "<div class=\"patch\">\n";
1602 if (ref($difftree->[$patch_idx]) eq "HASH") {
1603 $diffinfo = $difftree->[$patch_idx];
1605 $diffinfo = parse_difftree_raw_line($difftree->[$patch_idx]);
1609 # for now, no extended header, hence we skip empty patches
1610 # companion to next LINE if $in_header;
1611 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1616 if ($diffinfo->{'status'} eq "A") { # added
1617 print "<div class=\"diff_info\">" . file_type($diffinfo->{'to_mode'}) . ":" .
1618 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1619 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'file'})},
1620 $diffinfo->{'to_id'}) . "(new)" .
1621 "</div>\n"; # class="diff_info"
1623 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1624 print "<div class=\"diff_info\">" . file_type($diffinfo->{'from_mode'}) . ":" .
1625 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1626 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'file'})},
1627 $diffinfo->{'from_id'}) . "(deleted)" .
1628 "</div>\n"; # class="diff_info"
1630 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1631 $diffinfo->{'status'} eq "C" || # copied
1632 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1633 print "<div class=\"diff_info\">" .
1634 file_type($diffinfo->{'from_mode'}) . ":" .
1635 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1636 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'from_file'})},
1637 $diffinfo->{'from_id'}) .
1639 file_type($diffinfo->{'to_mode'}) . ":" .
1640 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1641 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'to_file'})},
1642 $diffinfo->{'to_id'});
1643 print "</div>\n"; # class="diff_info"
1645 } else { # modified, mode changed, ...
1646 print "<div class=\"diff_info\">" .
1647 file_type($diffinfo->{'from_mode'}) . ":" .
1648 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1649 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'file'})},
1650 $diffinfo->{'from_id'}) .
1652 file_type($diffinfo->{'to_mode'}) . ":" .
1653 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1654 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'file'})},
1655 $diffinfo->{'to_id'});
1656 print "</div>\n"; # class="diff_info"
1659 #print "<div class=\"diff extended_header\">\n";
1662 } # start of patch in patchset
1665 if ($in_header && $patch_line =~ m/^---/) {
1666 #print "</div>\n"; # class="diff extended_header"
1669 my $file = $diffinfo->{'from_file'};
1670 $file ||= $diffinfo->{'file'};
1671 $file = $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1672 hash=>$diffinfo->{'from_id'}, file_name=>$file),
1673 -class => "list"}, esc_html($file));
1674 $patch_line =~ s|a/.*$|a/$file|g;
1675 print "<div class=\"diff from_file\">$patch_line</div>\n";
1677 $patch_line = <$fd>;
1680 #$patch_line =~ m/^+++/;
1681 $file = $diffinfo->{'to_file'};
1682 $file ||= $diffinfo->{'file'};
1683 $file = $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1684 hash=>$diffinfo->{'to_id'}, file_name=>$file),
1685 -class => "list"}, esc_html($file));
1686 $patch_line =~ s|b/.*|b/$file|g;
1687 print "<div class=\"diff to_file\">$patch_line</div>\n";
1691 next LINE if $in_header;
1693 print format_diff_line($patch_line);
1695 print "</div>\n" if $patch_found; # class="patch"
1697 print "</div>\n"; # class="patchset"
1700 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1702 sub git_shortlog_body {
1703 # uses global variable $project
1704 my ($revlist, $from, $to, $refs, $extra) = @_;
1706 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
1707 my $have_snapshot = (defined $ctype && defined $suffix);
1709 $from = 0 unless defined $from;
1710 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1712 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1714 for (my $i = $from; $i <= $to; $i++) {
1715 my $commit = $revlist->[$i];
1716 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1717 my $ref = format_ref_marker($refs, $commit);
1718 my %co = parse_commit($commit);
1720 print "<tr class=\"dark\">\n";
1722 print "<tr class=\"light\">\n";
1725 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1726 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1727 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1729 print format_subject_html($co{'title'}, $co{'title_short'},
1730 href(action=>"commit", hash=>$commit), $ref);
1732 "<td class=\"link\">" .
1733 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
1734 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff");
1735 if ($have_snapshot) {
1736 print " | " . $cgi->a({-href => href(action=>"snapshot", hash=>$commit)}, "snapshot");
1741 if (defined $extra) {
1743 "<td colspan=\"4\">$extra</td>\n" .
1749 sub git_history_body {
1750 # Warning: assumes constant type (blob or tree) during history
1751 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1753 print "<table class=\"history\" cellspacing=\"0\">\n";
1755 while (my $line = <$fd>) {
1756 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1761 my %co = parse_commit($commit);
1766 my $ref = format_ref_marker($refs, $commit);
1769 print "<tr class=\"dark\">\n";
1771 print "<tr class=\"light\">\n";
1774 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1775 # shortlog uses chop_str($co{'author_name'}, 10)
1776 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1778 # originally git_history used chop_str($co{'title'}, 50)
1779 print format_subject_html($co{'title'}, $co{'title_short'},
1780 href(action=>"commit", hash=>$commit), $ref);
1782 "<td class=\"link\">" .
1783 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
1784 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
1785 $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype);
1787 if ($ftype eq 'blob') {
1788 my $blob_current = git_get_hash_by_path($hash_base, $file_name);
1789 my $blob_parent = git_get_hash_by_path($commit, $file_name);
1790 if (defined $blob_current && defined $blob_parent &&
1791 $blob_current ne $blob_parent) {
1793 $cgi->a({-href => href(action=>"blobdiff",
1794 hash=>$blob_current, hash_parent=>$blob_parent,
1795 hash_base=>$hash_base, hash_parent_base=>$commit,
1796 file_name=>$file_name)},
1803 if (defined $extra) {
1805 "<td colspan=\"4\">$extra</td>\n" .
1812 # uses global variable $project
1813 my ($taglist, $from, $to, $extra) = @_;
1814 $from = 0 unless defined $from;
1815 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1817 print "<table class=\"tags\" cellspacing=\"0\">\n";
1819 for (my $i = $from; $i <= $to; $i++) {
1820 my $entry = $taglist->[$i];
1822 my $comment_lines = $tag{'comment'};
1823 my $comment = shift @$comment_lines;
1825 if (defined $comment) {
1826 $comment_short = chop_str($comment, 30, 5);
1829 print "<tr class=\"dark\">\n";
1831 print "<tr class=\"light\">\n";
1834 print "<td><i>$tag{'age'}</i></td>\n" .
1836 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),
1837 -class => "list name"}, esc_html($tag{'name'})) .
1840 if (defined $comment) {
1841 print format_subject_html($comment, $comment_short,
1842 href(action=>"tag", hash=>$tag{'id'}));
1845 "<td class=\"selflink\">";
1846 if ($tag{'type'} eq "tag") {
1847 print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag");
1852 "<td class=\"link\">" . " | " .
1853 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'});
1854 if ($tag{'reftype'} eq "commit") {
1855 print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") .
1856 " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'refid'})}, "log");
1857 } elsif ($tag{'reftype'} eq "blob") {
1858 print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw");
1863 if (defined $extra) {
1865 "<td colspan=\"5\">$extra</td>\n" .
1871 sub git_heads_body {
1872 # uses global variable $project
1873 my ($taglist, $head, $from, $to, $extra) = @_;
1874 $from = 0 unless defined $from;
1875 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1877 print "<table class=\"heads\" cellspacing=\"0\">\n";
1879 for (my $i = $from; $i <= $to; $i++) {
1880 my $entry = $taglist->[$i];
1882 my $curr = $tag{'id'} eq $head;
1884 print "<tr class=\"dark\">\n";
1886 print "<tr class=\"light\">\n";
1889 print "<td><i>$tag{'age'}</i></td>\n" .
1890 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
1891 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'}),
1892 -class => "list name"},esc_html($tag{'name'})) .
1894 "<td class=\"link\">" .
1895 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") . " | " .
1896 $cgi->a({-href => href(action=>"log", hash=>$tag{'name'})}, "log") .
1900 if (defined $extra) {
1902 "<td colspan=\"3\">$extra</td>\n" .
1908 ## ======================================================================
1909 ## ======================================================================
1912 sub git_project_list {
1913 my $order = $cgi->param('o');
1914 if (defined $order && $order !~ m/project|descr|owner|age/) {
1915 die_error(undef, "Unknown order parameter");
1918 my @list = git_get_projects_list();
1921 die_error(undef, "No projects found");
1923 foreach my $pr (@list) {
1924 my $head = git_get_head_hash($pr->{'path'});
1925 if (!defined $head) {
1928 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1929 my %co = parse_commit($head);
1933 $pr->{'commit'} = \%co;
1934 if (!defined $pr->{'descr'}) {
1935 my $descr = git_get_project_description($pr->{'path'}) || "";
1936 $pr->{'descr'} = chop_str($descr, 25, 5);
1938 if (!defined $pr->{'owner'}) {
1939 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
1941 push @projects, $pr;
1945 if (-f $home_text) {
1946 print "<div class=\"index_include\">\n";
1947 open (my $fd, $home_text);
1952 print "<table class=\"project_list\">\n" .
1954 $order ||= "project";
1955 if ($order eq "project") {
1956 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1957 print "<th>Project</th>\n";
1960 $cgi->a({-href => "$my_uri?" . esc_param("o=project"),
1961 -class => "header"}, "Project") .
1964 if ($order eq "descr") {
1965 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1966 print "<th>Description</th>\n";
1969 $cgi->a({-href => "$my_uri?" . esc_param("o=descr"),
1970 -class => "header"}, "Description") .
1973 if ($order eq "owner") {
1974 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1975 print "<th>Owner</th>\n";
1978 $cgi->a({-href => "$my_uri?" . esc_param("o=owner"),
1979 -class => "header"}, "Owner") .
1982 if ($order eq "age") {
1983 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1984 print "<th>Last Change</th>\n";
1987 $cgi->a({-href => "$my_uri?" . esc_param("o=age"),
1988 -class => "header"}, "Last Change") .
1991 print "<th></th>\n" .
1994 foreach my $pr (@projects) {
1996 print "<tr class=\"dark\">\n";
1998 print "<tr class=\"light\">\n";
2001 print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
2002 -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
2003 "<td>" . esc_html($pr->{'descr'}) . "</td>\n" .
2004 "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
2005 print "<td class=\"". age_class($pr->{'commit'}{'age'}) . "\">" .
2006 $pr->{'commit'}{'age_string'} . "</td>\n" .
2007 "<td class=\"link\">" .
2008 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
2009 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
2010 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") .
2019 my $descr = git_get_project_description($project) || "none";
2020 my $head = git_get_head_hash($project);
2021 my %co = parse_commit($head);
2022 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
2024 my $owner = git_get_project_owner($project);
2026 my $refs = git_get_references();
2028 git_print_page_nav('summary','', $head);
2030 print "<div class=\"title\"> </div>\n";
2031 print "<table cellspacing=\"0\">\n" .
2032 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
2033 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2034 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2035 # use per project git URL list in $projectroot/$project/cloneurl
2036 # or make project git URL from git base URL and project name
2037 my $url_tag = "URL";
2038 my @url_list = git_get_project_url_list($project);
2039 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2040 foreach my $git_url (@url_list) {
2041 next unless $git_url;
2042 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2047 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash($project)
2048 or die_error(undef, "Open git-rev-list failed");
2049 my @revlist = map { chomp; $_ } <$fd>;
2051 git_print_header_div('shortlog');
2052 git_shortlog_body(\@revlist, 0, 15, $refs,
2053 $cgi->a({-href => href(action=>"shortlog")}, "..."));
2055 my $taglist = git_get_refs_list("refs/tags");
2056 if (defined @$taglist) {
2057 git_print_header_div('tags');
2058 git_tags_body($taglist, 0, 15,
2059 $cgi->a({-href => href(action=>"tags")}, "..."));
2062 my $headlist = git_get_refs_list("refs/heads");
2063 if (defined @$headlist) {
2064 git_print_header_div('heads');
2065 git_heads_body($headlist, $head, 0, 15,
2066 $cgi->a({-href => href(action=>"heads")}, "..."));
2073 my $head = git_get_head_hash($project);
2075 git_print_page_nav('','', $head,undef,$head);
2076 my %tag = parse_tag($hash);
2077 git_print_header_div('commit', esc_html($tag{'name'}), $hash);
2078 print "<div class=\"title_text\">\n" .
2079 "<table cellspacing=\"0\">\n" .
2081 "<td>object</td>\n" .
2082 "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
2083 $tag{'object'}) . "</td>\n" .
2084 "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
2085 $tag{'type'}) . "</td>\n" .
2087 if (defined($tag{'author'})) {
2088 my %ad = parse_date($tag{'epoch'}, $tag{'tz'});
2089 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
2090 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2091 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2094 print "</table>\n\n" .
2096 print "<div class=\"page_body\">";
2097 my $comment = $tag{'comment'};
2098 foreach my $line (@$comment) {
2099 print esc_html($line) . "<br/>\n";
2109 if (!gitweb_check_feature('blame')) {
2110 die_error('403 Permission denied', "Permission denied");
2112 die_error('404 Not Found', "File name not defined") if (!$file_name);
2113 $hash_base ||= git_get_head_hash($project);
2114 die_error(undef, "Couldn't find base commit") unless ($hash_base);
2115 my %co = parse_commit($hash_base)
2116 or die_error(undef, "Reading commit failed");
2117 if (!defined $hash) {
2118 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
2119 or die_error(undef, "Error looking up file");
2121 $ftype = git_get_type($hash);
2122 if ($ftype !~ "blob") {
2123 die_error("400 Bad Request", "Object is not a blob");
2125 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
2126 or die_error(undef, "Open git-blame failed");
2129 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2132 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
2134 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2135 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2136 git_print_page_path($file_name, $ftype, $hash_base);
2137 my @rev_color = (qw(light2 dark2));
2138 my $num_colors = scalar(@rev_color);
2139 my $current_color = 0;
2142 <div class="page_body">
2143 <table class="blame">
2144 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2147 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2149 my $rev = substr($full_rev, 0, 8);
2153 if (!defined $last_rev) {
2154 $last_rev = $full_rev;
2155 } elsif ($last_rev ne $full_rev) {
2156 $last_rev = $full_rev;
2157 $current_color = ++$current_color % $num_colors;
2159 print "<tr class=\"$rev_color[$current_color]\">\n";
2160 print "<td class=\"sha1\">" .
2161 $cgi->a({-href => href(action=>"commit", hash=>$full_rev, file_name=>$file_name)},
2162 esc_html($rev)) . "</td>\n";
2163 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2164 esc_html($lineno) . "</a></td>\n";
2165 print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
2171 or print "Reading blob failed\n";
2178 if (!gitweb_check_feature('blame')) {
2179 die_error('403 Permission denied', "Permission denied");
2181 die_error('404 Not Found', "File name not defined") if (!$file_name);
2182 $hash_base ||= git_get_head_hash($project);
2183 die_error(undef, "Couldn't find base commit") unless ($hash_base);
2184 my %co = parse_commit($hash_base)
2185 or die_error(undef, "Reading commit failed");
2186 if (!defined $hash) {
2187 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
2188 or die_error(undef, "Error lookup file");
2190 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2191 or die_error(undef, "Open git-annotate failed");
2194 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2197 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
2199 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2200 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2201 git_print_page_path($file_name, 'blob', $hash_base);
2202 print "<div class=\"page_body\">\n";
2204 <table class="blame">
2213 my @line_class = (qw(light dark));
2214 my $line_class_len = scalar (@line_class);
2215 my $line_class_num = $#line_class;
2216 while (my $line = <$fd>) {
2228 $line_class_num = ($line_class_num + 1) % $line_class_len;
2230 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2237 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
2240 $short_rev = substr ($long_rev, 0, 8);
2241 $age = time () - $time;
2242 $age_str = age_string ($age);
2243 $age_str =~ s/ / /g;
2244 $age_class = age_class($age);
2245 $author = esc_html ($author);
2246 $author =~ s/ / /g;
2248 $data = untabify($data);
2249 $data = esc_html ($data);
2252 <tr class="$line_class[$line_class_num]">
2253 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2254 <td class="$age_class">$age_str</td>
2256 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2257 <td class="pre">$data</td>
2260 } # while (my $line = <$fd>)
2261 print "</table>\n\n";
2263 or print "Reading blob failed.\n";
2269 my $head = git_get_head_hash($project);
2271 git_print_page_nav('','', $head,undef,$head);
2272 git_print_header_div('summary', $project);
2274 my $taglist = git_get_refs_list("refs/tags");
2275 if (defined @$taglist) {
2276 git_tags_body($taglist);
2282 my $head = git_get_head_hash($project);
2284 git_print_page_nav('','', $head,undef,$head);
2285 git_print_header_div('summary', $project);
2287 my $taglist = git_get_refs_list("refs/heads");
2288 if (defined @$taglist) {
2289 git_heads_body($taglist, $head);
2294 sub git_blob_plain {
2295 # blobs defined by non-textual hash id's can be cached
2297 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2301 if (!defined $hash) {
2302 if (defined $file_name) {
2303 my $base = $hash_base || git_get_head_hash($project);
2304 $hash = git_get_hash_by_path($base, $file_name, "blob")
2305 or die_error(undef, "Error lookup file");
2307 die_error(undef, "No file name defined");
2311 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2312 or die_error(undef, "Couldn't cat $file_name, $hash");
2314 $type ||= blob_mimetype($fd, $file_name);
2316 # save as filename, even when no $file_name is given
2317 my $save_as = "$hash";
2318 if (defined $file_name) {
2319 $save_as = $file_name;
2320 } elsif ($type =~ m/^text\//) {
2327 -content_disposition => "inline; filename=\"$save_as\"");
2329 binmode STDOUT, ':raw';
2331 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
2337 # blobs defined by non-textual hash id's can be cached
2339 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2343 if (!defined $hash) {
2344 if (defined $file_name) {
2345 my $base = $hash_base || git_get_head_hash($project);
2346 $hash = git_get_hash_by_path($base, $file_name, "blob")
2347 or die_error(undef, "Error lookup file");
2349 die_error(undef, "No file name defined");
2352 my $have_blame = gitweb_check_feature('blame');
2353 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2354 or die_error(undef, "Couldn't cat $file_name, $hash");
2355 my $mimetype = blob_mimetype($fd, $file_name);
2356 if ($mimetype !~ m/^text\//) {
2358 return git_blob_plain($mimetype);
2360 git_header_html(undef, $expires);
2361 my $formats_nav = '';
2362 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2363 if (defined $file_name) {
2366 $cgi->a({-href => href(action=>"blame", hash_base=>$hash_base,
2367 hash=>$hash, file_name=>$file_name)},
2372 $cgi->a({-href => href(action=>"blob_plain",
2373 hash=>$hash, file_name=>$file_name)},
2376 $cgi->a({-href => href(action=>"blob",
2377 hash_base=>"HEAD", file_name=>$file_name)},
2381 $cgi->a({-href => href(action=>"blob_plain", hash=>$hash)}, "plain");
2383 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2384 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2386 print "<div class=\"page_nav\">\n" .
2387 "<br/><br/></div>\n" .
2388 "<div class=\"title\">$hash</div>\n";
2390 git_print_page_path($file_name, "blob", $hash_base);
2391 print "<div class=\"page_body\">\n";
2393 while (my $line = <$fd>) {
2396 $line = untabify($line);
2397 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2398 $nr, $nr, $nr, esc_html($line);
2401 or print "Reading blob failed.\n";
2407 if (!defined $hash) {
2408 $hash = git_get_head_hash($project);
2409 if (defined $file_name) {
2410 my $base = $hash_base || $hash;
2411 $hash = git_get_hash_by_path($base, $file_name, "tree");
2413 if (!defined $hash_base) {
2418 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
2419 or die_error(undef, "Open git-ls-tree failed");
2420 my @entries = map { chomp; $_ } <$fd>;
2421 close $fd or die_error(undef, "Reading tree failed");
2424 my $refs = git_get_references();
2425 my $ref = format_ref_marker($refs, $hash_base);
2429 my $have_blame = gitweb_check_feature('blame');
2430 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2431 $base_key{hash_base} = $hash_base;
2432 git_print_page_nav('tree','', $hash_base);
2433 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
2435 print "<div class=\"page_nav\">\n";
2436 print "<br/><br/></div>\n";
2437 print "<div class=\"title\">$hash</div>\n";
2439 if (defined $file_name) {
2440 $base = esc_html("$file_name/");
2442 git_print_page_path($file_name, 'tree', $hash_base);
2443 print "<div class=\"page_body\">\n";
2444 print "<table cellspacing=\"0\">\n";
2446 foreach my $line (@entries) {
2447 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2448 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2452 my $t_name = validate_input($4);
2454 print "<tr class=\"dark\">\n";
2456 print "<tr class=\"light\">\n";
2459 print "<td class=\"mode\">" . mode_str($t_mode) . "</td>\n";
2460 if ($t_type eq "blob") {
2461 print "<td class=\"list\">" .
2462 $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key),
2463 -class => "list"}, esc_html($t_name)) .
2465 "<td class=\"link\">" .
2466 $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2470 $cgi->a({-href => href(action=>"blame", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2474 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
2475 hash=>$t_hash, file_name=>"$base$t_name")},
2478 $cgi->a({-href => href(action=>"blob_plain",
2479 hash=>$t_hash, file_name=>"$base$t_name")},
2482 } elsif ($t_type eq "tree") {
2483 print "<td class=\"list\">" .
2484 $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2485 esc_html($t_name)) .
2487 "<td class=\"link\">" .
2488 $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2491 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, file_name=>"$base$t_name")},
2497 print "</table>\n" .
2504 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
2505 my $have_snapshot = (defined $ctype && defined $suffix);
2506 if (!$have_snapshot) {
2507 die_error('403 Permission denied', "Permission denied");
2510 if (!defined $hash) {
2511 $hash = git_get_head_hash($project);
2514 my $filename = basename($project) . "-$hash.tar.$suffix";
2516 print $cgi->header(-type => 'application/x-tar',
2517 -content_encoding => $ctype,
2518 -content_disposition => "inline; filename=\"$filename\"",
2519 -status => '200 OK');
2521 open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | $command" or
2522 die_error(undef, "Execute git-tar-tree failed.");
2523 binmode STDOUT, ':raw';
2525 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
2531 my $head = git_get_head_hash($project);
2532 if (!defined $hash) {
2535 if (!defined $page) {
2538 my $refs = git_get_references();
2540 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2541 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2542 or die_error(undef, "Open git-rev-list failed");
2543 my @revlist = map { chomp; $_ } <$fd>;
2546 my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#revlist);
2549 git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
2552 my %co = parse_commit($hash);
2554 git_print_header_div('summary', $project);
2555 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2557 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2558 my $commit = $revlist[$i];
2559 my $ref = format_ref_marker($refs, $commit);
2560 my %co = parse_commit($commit);
2562 my %ad = parse_date($co{'author_epoch'});
2563 git_print_header_div('commit',
2564 "<span class=\"age\">$co{'age_string'}</span>" .
2565 esc_html($co{'title'}) . $ref,
2567 print "<div class=\"title_text\">\n" .
2568 "<div class=\"log_link\">\n" .
2569 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
2571 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
2574 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2577 print "<div class=\"log_body\">\n";
2578 git_print_simplified_log($co{'comment'});
2585 my %co = parse_commit($hash);
2587 die_error(undef, "Unknown commit object");
2589 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
2590 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
2592 my $parent = $co{'parent'};
2593 if (!defined $parent) {
2596 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
2597 or die_error(undef, "Open git-diff-tree failed");
2598 my @difftree = map { chomp; $_ } <$fd>;
2599 close $fd or die_error(undef, "Reading git-diff-tree failed");
2601 # non-textual hash id's can be cached
2603 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2606 my $refs = git_get_references();
2607 my $ref = format_ref_marker($refs, $co{'id'});
2609 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
2610 my $have_snapshot = (defined $ctype && defined $suffix);
2612 my $formats_nav = '';
2613 if (defined $file_name && defined $co{'parent'}) {
2614 my $parent = $co{'parent'};
2616 $cgi->a({-href => href(action=>"blame", hash_parent=>$parent, file_name=>$file_name)},
2619 git_header_html(undef, $expires);
2620 git_print_page_nav('commit', defined $co{'parent'} ? '' : 'commitdiff',
2621 $hash, $co{'tree'}, $hash,
2624 if (defined $co{'parent'}) {
2625 git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash);
2627 git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash);
2629 print "<div class=\"title_text\">\n" .
2630 "<table cellspacing=\"0\">\n";
2631 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
2633 "<td></td><td> $ad{'rfc2822'}";
2634 if ($ad{'hour_local'} < 6) {
2635 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2636 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2638 printf(" (%02d:%02d %s)",
2639 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2643 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
2644 print "<tr><td></td><td> $cd{'rfc2822'}" .
2645 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2647 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2650 "<td class=\"sha1\">" .
2651 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),
2652 class => "list"}, $co{'tree'}) .
2654 "<td class=\"link\">" .
2655 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},
2657 if ($have_snapshot) {
2659 $cgi->a({-href => href(action=>"snapshot", hash=>$hash)}, "snapshot");
2663 my $parents = $co{'parents'};
2664 foreach my $par (@$parents) {
2667 "<td class=\"sha1\">" .
2668 $cgi->a({-href => href(action=>"commit", hash=>$par),
2669 class => "list"}, $par) .
2671 "<td class=\"link\">" .
2672 $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") .
2674 $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "commitdiff") .
2681 print "<div class=\"page_body\">\n";
2682 git_print_log($co{'comment'});
2685 git_difftree_body(\@difftree, $hash, $parent);
2691 my $format = shift || 'html';
2698 # preparing $fd and %diffinfo for git_patchset_body
2700 if (defined $hash_base && defined $hash_parent_base) {
2701 if (defined $file_name) {
2703 open $fd, "-|", $GIT, "diff-tree", '-r', '-M', '-C', $hash_parent_base, $hash_base,
2705 or die_error(undef, "Open git-diff-tree failed");
2706 @difftree = map { chomp; $_ } <$fd>;
2708 or die_error(undef, "Reading git-diff-tree failed");
2710 or die_error('404 Not Found', "Blob diff not found");
2712 } elsif (defined $hash) { # try to find filename from $hash
2713 if ($hash !~ /[0-9a-fA-F]{40}/) {
2714 $hash = git_to_hash($hash);
2716 } elsif (defined $hash &&
2717 $hash =~ /[0-9a-fA-F]{40}/) {
2718 # try to find filename from $hash
2720 # read filtered raw output
2721 open $fd, "-|", $GIT, "diff-tree", '-r', '-M', '-C', $hash_parent_base, $hash_base
2722 or die_error(undef, "Open git-diff-tree failed");
2724 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
2726 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
2727 map { chomp; $_ } <$fd>;
2729 or die_error(undef, "Reading git-diff-tree failed");
2731 or die_error('404 Not Found', "Blob diff not found");
2734 die_error('404 Not Found', "Missing one of the blob diff parameters");
2737 if (@difftree > 1) {
2738 die_error('404 Not Found', "Ambiguous blob diff specification");
2741 %diffinfo = parse_difftree_raw_line($difftree[0]);
2742 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
2743 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
2745 $hash_parent ||= $diffinfo{'from_id'};
2746 $hash ||= $diffinfo{'to_id'};
2748 # non-textual hash id's can be cached
2749 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
2750 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
2755 open $fd, "-|", $GIT, "diff-tree", '-r', '-p', '-M', '-C', $hash_parent_base, $hash_base,
2757 or die_error(undef, "Open git-diff-tree failed");
2760 # old/legacy style URI
2761 if (!%diffinfo && # if new style URI failed
2762 defined $hash && defined $hash_parent) {
2763 # fake git-diff-tree raw output
2764 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
2765 $diffinfo{'from_id'} = $hash_parent;
2766 $diffinfo{'to_id'} = $hash;
2767 if (defined $file_name) {
2768 if (defined $file_parent) {
2769 $diffinfo{'status'} = '2';
2770 $diffinfo{'from_file'} = $file_parent;
2771 $diffinfo{'to_file'} = $file_name;
2772 } else { # assume not renamed
2773 $diffinfo{'status'} = '1';
2774 $diffinfo{'from_file'} = $file_name;
2775 $diffinfo{'to_file'} = $file_name;
2777 } else { # no filename given
2778 $diffinfo{'status'} = '2';
2779 $diffinfo{'from_file'} = $hash_parent;
2780 $diffinfo{'to_file'} = $hash;
2783 # non-textual hash id's can be cached
2784 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
2785 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
2790 open $fd, "-|", $GIT, "diff", '-p', $hash_parent, $hash
2791 or die_error(undef, "Open git-diff failed");
2793 die_error('404 Not Found', "Missing one of the blob diff parameters")
2798 if ($format eq 'html') {
2800 $cgi->a({-href => href(action=>"blobdiff_plain",
2801 hash=>$hash, hash_parent=>$hash_parent,
2802 hash_base=>$hash_base, hash_parent_base=>$hash_parent_base,
2803 file_name=>$file_name, file_parent=>$file_parent)},
2805 git_header_html(undef, $expires);
2806 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2807 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2808 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2810 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
2811 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
2813 if (defined $file_name) {
2814 git_print_page_path($file_name, "blob", $hash_base);
2816 print "<div class=\"page_path\"></div>\n";
2819 } elsif ($format eq 'plain') {
2821 -type => 'text/plain',
2822 -charset => 'utf-8',
2823 -expires => $expires,
2824 -content_disposition => qq(inline; filename="${file_name}.patch"));
2826 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
2829 die_error(undef, "Unknown blobdiff format");
2833 if ($format eq 'html') {
2834 print "<div class=\"page_body\">\n";
2836 git_patchset_body($fd, [ \%diffinfo ], $hash_base, $hash_parent_base);
2839 print "</div>\n"; # class="page_body"
2843 while (my $line = <$fd>) {
2844 $line =~ s!a/($hash|$hash_parent)!a/$diffinfo{'from_file'}!g;
2845 $line =~ s!b/($hash|$hash_parent)!b/$diffinfo{'to_file'}!g;
2849 last if $line =~ m!^\+\+\+!;
2857 sub git_blobdiff_plain {
2858 git_blobdiff('plain');
2861 sub git_commitdiff {
2862 my $format = shift || 'html';
2863 my %co = parse_commit($hash);
2865 die_error(undef, "Unknown commit object");
2867 if (!defined $hash_parent) {
2868 $hash_parent = $co{'parent'} || '--root';
2874 if ($format eq 'html') {
2875 open $fd, "-|", $GIT, "diff-tree", '-r', '-M', '-C',
2876 "--patch-with-raw", "--full-index", $hash_parent, $hash
2877 or die_error(undef, "Open git-diff-tree failed");
2879 while (chomp(my $line = <$fd>)) {
2880 # empty line ends raw part of diff-tree output
2882 push @difftree, $line;
2885 } elsif ($format eq 'plain') {
2886 open $fd, "-|", $GIT, "diff-tree", '-r', '-p', '-B', $hash_parent, $hash
2887 or die_error(undef, "Open git-diff-tree failed");
2890 die_error(undef, "Unknown commitdiff format");
2893 # non-textual hash id's can be cached
2895 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2899 # write commit message
2900 if ($format eq 'html') {
2901 my $refs = git_get_references();
2902 my $ref = format_ref_marker($refs, $co{'id'});
2904 $cgi->a({-href => href(action=>"commitdiff_plain",
2905 hash=>$hash, hash_parent=>$hash_parent)},
2908 git_header_html(undef, $expires);
2909 git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2910 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
2911 print "<div class=\"page_body\">\n";
2912 print "<div class=\"log\">\n";
2913 git_print_simplified_log($co{'comment'}, 1); # skip title
2914 print "</div>\n"; # class="log"
2916 } elsif ($format eq 'plain') {
2917 my $refs = git_get_references("tags");
2918 my $tagname = git_get_rev_name_tags($hash);
2919 my $filename = basename($project) . "-$hash.patch";
2922 -type => 'text/plain',
2923 -charset => 'utf-8',
2924 -expires => $expires,
2925 -content_disposition => qq(inline; filename="$filename"));
2926 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
2929 Date: $ad{'rfc2822'} ($ad{'tz_local'})
2930 Subject: $co{'title'}
2932 print "X-Git-Tag: $tagname\n" if $tagname;
2933 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
2935 foreach my $line (@{$co{'comment'}}) {
2942 if ($format eq 'html') {
2943 #git_difftree_body(\@difftree, $hash, $hash_parent);
2946 git_patchset_body($fd, \@difftree, $hash, $hash_parent);
2948 print "</div>\n"; # class="page_body"
2951 } elsif ($format eq 'plain') {
2955 or print "Reading git-diff-tree failed\n";
2959 sub git_commitdiff_plain {
2960 git_commitdiff('plain');
2964 if (!defined $hash_base) {
2965 $hash_base = git_get_head_hash($project);
2968 my %co = parse_commit($hash_base);
2970 die_error(undef, "Unknown commit object");
2972 my $refs = git_get_references();
2974 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base);
2975 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2976 if (!defined $hash && defined $file_name) {
2977 $hash = git_get_hash_by_path($hash_base, $file_name);
2979 if (defined $hash) {
2980 $ftype = git_get_type($hash);
2982 git_print_page_path($file_name, $ftype, $hash_base);
2985 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2986 git_history_body($fd, $refs, $hash_base, $ftype);
2993 if (!defined $searchtext) {
2994 die_error(undef, "Text field empty");
2996 if (!defined $hash) {
2997 $hash = git_get_head_hash($project);
2999 my %co = parse_commit($hash);
3001 die_error(undef, "Unknown commit object");
3003 # pickaxe may take all resources of your box and run for several minutes
3004 # with every query - so decide by yourself how public you make this feature :)
3005 my $commit_search = 1;
3006 my $author_search = 0;
3007 my $committer_search = 0;
3008 my $pickaxe_search = 0;
3009 if ($searchtext =~ s/^author\\://i) {
3011 } elsif ($searchtext =~ s/^committer\\://i) {
3012 $committer_search = 1;
3013 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3015 $pickaxe_search = 1;
3018 git_print_page_nav('','', $hash,$co{'tree'},$hash);
3019 git_print_header_div('commit', esc_html($co{'title'}), $hash);
3021 print "<table cellspacing=\"0\">\n";
3023 if ($commit_search) {
3025 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
3026 while (my $commit_text = <$fd>) {
3027 if (!grep m/$searchtext/i, $commit_text) {
3030 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3033 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3036 my @commit_lines = split "\n", $commit_text;
3037 my %co = parse_commit(undef, \@commit_lines);
3042 print "<tr class=\"dark\">\n";
3044 print "<tr class=\"light\">\n";
3047 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3048 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3050 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"},
3051 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
3052 my $comment = $co{'comment'};
3053 foreach my $line (@$comment) {
3054 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3055 my $lead = esc_html($1) || "";
3056 $lead = chop_str($lead, 30, 10);
3057 my $match = esc_html($2) || "";
3058 my $trail = esc_html($3) || "";
3059 $trail = chop_str($trail, 30, 10);
3060 my $text = "$lead<span class=\"match\">$match</span>$trail";
3061 print chop_str($text, 80, 5) . "<br/>\n";
3065 "<td class=\"link\">" .
3066 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
3068 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
3075 if ($pickaxe_search) {
3077 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
3080 while (my $line = <$fd>) {
3081 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3084 $set{'from_id'} = $3;
3086 $set{'id'} = $set{'to_id'};
3087 if ($set{'id'} =~ m/0{40}/) {
3088 $set{'id'} = $set{'from_id'};
3090 if ($set{'id'} =~ m/0{40}/) {
3094 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3097 print "<tr class=\"dark\">\n";
3099 print "<tr class=\"light\">\n";
3102 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3103 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3105 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
3106 -class => "list subject"},
3107 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
3108 while (my $setref = shift @files) {
3110 print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},
3111 hash=>$set{'id'}, file_name=>$set{'file'}),
3113 "<span class=\"match\">" . esc_html($set{'file'}) . "</span>") .
3117 "<td class=\"link\">" .
3118 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
3120 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
3124 %co = parse_commit($1);
3134 my $head = git_get_head_hash($project);
3135 if (!defined $hash) {
3138 if (!defined $page) {
3141 my $refs = git_get_references();
3143 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3144 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
3145 or die_error(undef, "Open git-rev-list failed");
3146 my @revlist = map { chomp; $_ } <$fd>;
3149 my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, $#revlist);
3151 if ($#revlist >= (100 * ($page+1)-1)) {
3153 $cgi->a({-href => href(action=>"shortlog", hash=>$hash, page=>$page+1),
3154 -title => "Alt-n"}, "next");
3159 git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);
3160 git_print_header_div('summary', $project);
3162 git_shortlog_body(\@revlist, ($page * 100), $#revlist, $refs, $next_link);
3167 ## ......................................................................
3168 ## feeds (RSS, OPML)
3171 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3172 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash($project)
3173 or die_error(undef, "Open git-rev-list failed");
3174 my @revlist = map { chomp; $_ } <$fd>;
3175 close $fd or die_error(undef, "Reading git-rev-list failed");
3176 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
3178 <?xml version="1.0" encoding="utf-8"?>
3179 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3181 <title>$project $my_uri $my_url</title>
3182 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3183 <description>$project log</description>
3184 <language>en</language>
3187 for (my $i = 0; $i <= $#revlist; $i++) {
3188 my $commit = $revlist[$i];
3189 my %co = parse_commit($commit);
3190 # we read 150, we always show 30 and the ones more recent than 48 hours
3191 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3194 my %cd = parse_date($co{'committer_epoch'});
3195 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
3196 my @difftree = map { chomp; $_ } <$fd>;
3200 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) .
3202 "<author>" . esc_html($co{'author'}) . "</author>\n" .
3203 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3204 "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3205 "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3206 "<description>" . esc_html($co{'title'}) . "</description>\n" .
3207 "<content:encoded>" .
3209 my $comment = $co{'comment'};
3210 foreach my $line (@$comment) {
3211 $line = decode("utf8", $line, Encode::FB_DEFAULT);
3212 print "$line<br/>\n";
3215 foreach my $line (@difftree) {
3216 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3219 my $file = validate_input(unquote($7));
3220 $file = decode("utf8", $file, Encode::FB_DEFAULT);
3221 print "$file<br/>\n";
3224 "</content:encoded>\n" .
3227 print "</channel></rss>";
3231 my @list = git_get_projects_list();
3233 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
3235 <?xml version="1.0" encoding="utf-8"?>
3236 <opml version="1.0">
3238 <title>$site_name Git OPML Export</title>
3241 <outline text="git RSS feeds">
3244 foreach my $pr (@list) {
3246 my $head = git_get_head_hash($proj{'path'});
3247 if (!defined $head) {
3250 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
3251 my %co = parse_commit($head);
3256 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
3257 my $rss = "$my_url?p=$proj{'path'};a=rss";
3258 my $html = "$my_url?p=$proj{'path'};a=summary";
3259 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";