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 binmode STDOUT, ':utf8';
21 our $version = "++GIT_VERSION++";
22 our $my_url = $cgi->url();
23 our $my_uri = $cgi->url(-absolute => 1);
25 # core git executable to use
26 # this can just be "git" if your webserver has a sensible PATH
27 our $GIT = "++GIT_BINDIR++/git";
29 # absolute fs-path which will be prepended to the project path
30 #our $projectroot = "/pub/scm";
31 our $projectroot = "++GITWEB_PROJECTROOT++";
33 # location for temporary files needed for diffs
34 our $git_temp = "/tmp/gitweb";
36 # target of the home link on top of all pages
37 our $home_link = $my_uri;
39 # string of the home link on top of all pages
40 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
42 # name of your site or organization to appear in page titles
43 # replace this with something more descriptive for clearer bookmarks
44 our $site_name = "++GITWEB_SITENAME++" || $ENV{'SERVER_NAME'} || "Untitled";
46 # html text to include at home page
47 our $home_text = "++GITWEB_HOMETEXT++";
49 # URI of default stylesheet
50 our $stylesheet = "++GITWEB_CSS++";
52 our $logo = "++GITWEB_LOGO++";
54 # source of projects list
55 our $projects_list = "++GITWEB_LIST++";
57 # list of git base URLs used for URL to where fetch project from,
58 # i.e. full URL is "$git_base_url/$project"
59 our @git_base_url_list = ("++GITWEB_BASE_URL++");
61 # default blob_plain mimetype and default charset for text/plain blob
62 our $default_blob_plain_mimetype = 'text/plain';
63 our $default_text_plain_charset = undef;
65 # file to use for guessing MIME types before trying /etc/mime.types
66 # (relative to the current git repository)
67 our $mimetypes_file = undef;
69 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
70 require $GITWEB_CONFIG if -e $GITWEB_CONFIG;
72 # version of the core git binary
73 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
75 $projects_list ||= $projectroot;
77 mkdir($git_temp, 0700) || die_error(undef, "Couldn't mkdir $git_temp");
80 # ======================================================================
81 # input validation and dispatch
82 our $action = $cgi->param('a');
83 if (defined $action) {
84 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
85 die_error(undef, "Invalid action parameter");
87 # action which does not check rest of parameters
88 if ($action eq "opml") {
94 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
95 if (defined $project) {
99 if (defined $project && $project) {
100 if (!validate_input($project)) {
101 die_error(undef, "Invalid project parameter");
103 if (!(-d "$projectroot/$project")) {
104 die_error(undef, "No such directory");
106 if (!(-e "$projectroot/$project/HEAD")) {
107 die_error(undef, "No such project");
109 $ENV{'GIT_DIR'} = "$projectroot/$project";
115 our $file_name = $cgi->param('f');
116 if (defined $file_name) {
117 if (!validate_input($file_name)) {
118 die_error(undef, "Invalid file parameter");
122 our $hash = $cgi->param('h');
124 if (!validate_input($hash)) {
125 die_error(undef, "Invalid hash parameter");
129 our $hash_parent = $cgi->param('hp');
130 if (defined $hash_parent) {
131 if (!validate_input($hash_parent)) {
132 die_error(undef, "Invalid hash parent parameter");
136 our $hash_base = $cgi->param('hb');
137 if (defined $hash_base) {
138 if (!validate_input($hash_base)) {
139 die_error(undef, "Invalid hash base parameter");
143 our $page = $cgi->param('pg');
145 if ($page =~ m/[^0-9]$/) {
146 die_error(undef, "Invalid page parameter");
150 our $searchtext = $cgi->param('s');
151 if (defined $searchtext) {
152 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) {
153 die_error(undef, "Invalid search parameter");
155 $searchtext = quotemeta $searchtext;
160 "blame" => \&git_blame2,
161 "blobdiff" => \&git_blobdiff,
162 "blobdiff_plain" => \&git_blobdiff_plain,
163 "blob" => \&git_blob,
164 "blob_plain" => \&git_blob_plain,
165 "commitdiff" => \&git_commitdiff,
166 "commitdiff_plain" => \&git_commitdiff_plain,
167 "commit" => \&git_commit,
168 "heads" => \&git_heads,
169 "history" => \&git_history,
172 "search" => \&git_search,
173 "shortlog" => \&git_shortlog,
174 "summary" => \&git_summary,
176 "tags" => \&git_tags,
177 "tree" => \&git_tree,
180 $action = 'summary' if (!defined($action));
181 if (!defined($actions{$action})) {
182 die_error(undef, "Unknown action");
184 $actions{$action}->();
187 ## ======================================================================
203 $params{"project"} ||= $project;
205 my $href = "$my_uri?";
206 $href .= esc_param( join(";",
207 map { "$mapping{$_}=$params{$_}" } keys %params
214 ## ======================================================================
215 ## validation, quoting/unquoting and escaping
220 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
223 if ($input =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
226 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\-\+\#\~\%]/) {
232 # quote unsafe chars, but keep the slash, even when it's not
233 # correct, but quoted slashes look too horrible in bookmarks
236 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
242 # replace invalid utf8 character with SUBSTITUTION sequence
245 $str = decode("utf8", $str, Encode::FB_DEFAULT);
246 $str = escapeHTML($str);
247 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
251 # git may return quoted and escaped filenames
254 if ($str =~ m/^"(.*)"$/) {
256 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
261 # escape tabs (convert tabs to spaces)
265 while ((my $pos = index($line, "\t")) != -1) {
266 if (my $count = (8 - ($pos % 8))) {
267 my $spaces = ' ' x $count;
268 $line =~ s/\t/$spaces/;
275 ## ----------------------------------------------------------------------
276 ## HTML aware string manipulation
281 my $add_len = shift || 10;
283 # allow only $len chars, but don't cut a word if it would fit in $add_len
284 # if it doesn't fit, cut it if it's still longer than the dots we would add
285 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
288 if (length($tail) > 4) {
290 $body =~ s/&[^;]*$//; # remove chopped character entities
295 ## ----------------------------------------------------------------------
296 ## functions returning short strings
298 # CSS class for given age value (in seconds)
302 if ($age < 60*60*2) {
304 } elsif ($age < 60*60*24*2) {
311 # convert age in seconds to "nn units ago" string
316 if ($age > 60*60*24*365*2) {
317 $age_str = (int $age/60/60/24/365);
318 $age_str .= " years ago";
319 } elsif ($age > 60*60*24*(365/12)*2) {
320 $age_str = int $age/60/60/24/(365/12);
321 $age_str .= " months ago";
322 } elsif ($age > 60*60*24*7*2) {
323 $age_str = int $age/60/60/24/7;
324 $age_str .= " weeks ago";
325 } elsif ($age > 60*60*24*2) {
326 $age_str = int $age/60/60/24;
327 $age_str .= " days ago";
328 } elsif ($age > 60*60*2) {
329 $age_str = int $age/60/60;
330 $age_str .= " hours ago";
331 } elsif ($age > 60*2) {
332 $age_str = int $age/60;
333 $age_str .= " min ago";
336 $age_str .= " sec ago";
338 $age_str .= " right now";
343 # convert file mode in octal to symbolic file mode string
345 my $mode = oct shift;
347 if (S_ISDIR($mode & S_IFMT)) {
349 } elsif (S_ISLNK($mode)) {
351 } elsif (S_ISREG($mode)) {
352 # git cares only about the executable bit
353 if ($mode & S_IXUSR) {
363 # convert file mode in octal to file type string
365 my $mode = oct shift;
367 if (S_ISDIR($mode & S_IFMT)) {
369 } elsif (S_ISLNK($mode)) {
371 } elsif (S_ISREG($mode)) {
378 ## ----------------------------------------------------------------------
379 ## functions returning short HTML fragments, or transforming HTML fragments
380 ## which don't beling to other sections
382 # format line of commit message or tag comment
383 sub format_log_line_html {
386 $line = esc_html($line);
387 $line =~ s/ / /g;
388 if ($line =~ m/([0-9a-fA-F]{40})/) {
390 if (git_get_type($hash_text) eq "commit") {
391 my $link = $cgi->a({-class => "text", -href => href(action=>"commit", hash=>$hash_text)}, $hash_text);
392 $line =~ s/$hash_text/$link/;
398 # format marker of refs pointing to given object
399 sub format_ref_marker {
400 my ($refs, $id) = @_;
403 if (defined $refs->{$id}) {
404 foreach my $ref (@{$refs->{$id}}) {
405 my ($type, $name) = qw();
406 # e.g. tags/v2.6.11 or heads/next
407 if ($ref =~ m!^(.*?)s?/(.*)$!) {
415 $markers .= " <span class=\"$type\">" . esc_html($name) . "</span>";
420 return ' <span class="refs">'. $markers . '</span>';
426 # format, perhaps shortened and with markers, title line
427 sub format_subject_html {
428 my ($long, $short, $href, $extra) = @_;
429 $extra = '' unless defined($extra);
431 if (length($short) < length($long)) {
432 return $cgi->a({-href => $href, -class => "list",
434 esc_html($short) . $extra);
436 return $cgi->a({-href => $href, -class => "list"},
437 esc_html($long) . $extra);
441 ## ----------------------------------------------------------------------
442 ## git utility subroutines, invoking git commands
444 # get HEAD ref of given project as hash
445 sub git_get_head_hash {
447 my $oENV = $ENV{'GIT_DIR'};
449 $ENV{'GIT_DIR'} = "$projectroot/$project";
450 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
453 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
458 $ENV{'GIT_DIR'} = $oENV;
463 # get type of given object
467 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
474 sub git_get_project_config {
477 return unless ($key);
478 $key =~ s/^gitweb\.//;
479 return if ($key =~ m/\W/);
481 my $val = qx($GIT repo-config --get gitweb.$key);
485 sub git_get_project_config_bool {
486 my $val = git_get_project_config (@_);
487 if ($val and $val =~ m/true|yes|on/) {
490 return; # implicit false
493 # get hash of given path at given ref
494 sub git_get_hash_by_path {
496 my $path = shift || return undef;
500 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
501 or die_error(undef, "Open git-ls-tree failed");
503 close $fd or return undef;
505 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
506 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
510 ## ......................................................................
511 ## git utility functions, directly accessing git repository
513 # assumes that PATH is not symref
514 sub git_get_hash_by_ref {
517 open my $fd, "$projectroot/$path" or return undef;
521 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
526 sub git_get_project_description {
529 open my $fd, "$projectroot/$path/description" or return undef;
536 sub git_get_project_url_list {
539 open my $fd, "$projectroot/$path/cloneurl" or return undef;
540 my @git_project_url_list = map { chomp; $_ } <$fd>;
543 return wantarray ? @git_project_url_list : \@git_project_url_list;
546 sub git_get_projects_list {
549 if (-d $projects_list) {
550 # search in directory
551 my $dir = $projects_list;
552 opendir my ($dh), $dir or return undef;
553 while (my $dir = readdir($dh)) {
554 if (-e "$projectroot/$dir/HEAD") {
562 } elsif (-f $projects_list) {
563 # read from file(url-encoded):
564 # 'git%2Fgit.git Linus+Torvalds'
565 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
566 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
567 open my ($fd), $projects_list or return undef;
568 while (my $line = <$fd>) {
570 my ($path, $owner) = split ' ', $line;
571 $path = unescape($path);
572 $owner = unescape($owner);
573 if (!defined $path) {
576 if (-e "$projectroot/$path/HEAD") {
579 owner => decode("utf8", $owner, Encode::FB_DEFAULT),
586 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
590 sub git_get_project_owner {
594 return undef unless $project;
596 # read from file (url-encoded):
597 # 'git%2Fgit.git Linus+Torvalds'
598 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
599 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
600 if (-f $projects_list) {
601 open (my $fd , $projects_list);
602 while (my $line = <$fd>) {
604 my ($pr, $ow) = split ' ', $line;
607 if ($pr eq $project) {
608 $owner = decode("utf8", $ow, Encode::FB_DEFAULT);
614 if (!defined $owner) {
615 $owner = get_file_owner("$projectroot/$project");
621 sub git_get_references {
622 my $type = shift || "";
625 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
626 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
627 if (-f "$projectroot/$project/info/refs") {
628 open $fd, "$projectroot/$project/info/refs"
631 open $fd, "-|", $GIT, "ls-remote", "."
635 while (my $line = <$fd>) {
637 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?[^\^]+)/) {
638 if (defined $refs{$1}) {
639 push @{$refs{$1}}, $2;
649 ## ----------------------------------------------------------------------
650 ## parse to hash functions
654 my $tz = shift || "-0000";
657 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
658 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
659 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
660 $date{'hour'} = $hour;
661 $date{'minute'} = $min;
662 $date{'mday'} = $mday;
663 $date{'day'} = $days[$wday];
664 $date{'month'} = $months[$mon];
665 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
666 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
668 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
669 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
670 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
671 $date{'hour_local'} = $hour;
672 $date{'minute_local'} = $min;
673 $date{'tz_local'} = $tz;
682 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
683 $tag{'id'} = $tag_id;
684 while (my $line = <$fd>) {
686 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
688 } elsif ($line =~ m/^type (.+)$/) {
690 } elsif ($line =~ m/^tag (.+)$/) {
692 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
696 } elsif ($line =~ m/--BEGIN/) {
697 push @comment, $line;
699 } elsif ($line eq "") {
703 push @comment, <$fd>;
704 $tag{'comment'} = \@comment;
706 if (!defined $tag{'name'}) {
713 my $commit_id = shift;
714 my $commit_text = shift;
719 if (defined $commit_text) {
720 @commit_lines = @$commit_text;
723 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id or return;
724 @commit_lines = split '\n', <$fd>;
729 my $header = shift @commit_lines;
730 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
733 ($co{'id'}, my @parents) = split ' ', $header;
734 $co{'parents'} = \@parents;
735 $co{'parent'} = $parents[0];
736 while (my $line = shift @commit_lines) {
737 last if $line eq "\n";
738 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
740 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
742 $co{'author_epoch'} = $2;
743 $co{'author_tz'} = $3;
744 if ($co{'author'} =~ m/^([^<]+) </) {
745 $co{'author_name'} = $1;
747 $co{'author_name'} = $co{'author'};
749 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
750 $co{'committer'} = $1;
751 $co{'committer_epoch'} = $2;
752 $co{'committer_tz'} = $3;
753 $co{'committer_name'} = $co{'committer'};
754 $co{'committer_name'} =~ s/ <.*//;
757 if (!defined $co{'tree'}) {
761 foreach my $title (@commit_lines) {
764 $co{'title'} = chop_str($title, 80, 5);
765 # remove leading stuff of merges to make the interesting part visible
766 if (length($title) > 50) {
767 $title =~ s/^Automatic //;
768 $title =~ s/^merge (of|with) /Merge ... /i;
769 if (length($title) > 50) {
770 $title =~ s/(http|rsync):\/\///;
772 if (length($title) > 50) {
773 $title =~ s/(master|www|rsync)\.//;
775 if (length($title) > 50) {
776 $title =~ s/kernel.org:?//;
778 if (length($title) > 50) {
779 $title =~ s/\/pub\/scm//;
782 $co{'title_short'} = chop_str($title, 50, 5);
786 # remove added spaces
787 foreach my $line (@commit_lines) {
790 $co{'comment'} = \@commit_lines;
792 my $age = time - $co{'committer_epoch'};
794 $co{'age_string'} = age_string($age);
795 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
796 if ($age > 60*60*24*7*2) {
797 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
798 $co{'age_string_age'} = $co{'age_string'};
800 $co{'age_string_date'} = $co{'age_string'};
801 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
806 # parse ref from ref_file, given by ref_id, with given type
808 my $ref_file = shift;
810 my $type = shift || git_get_type($ref_id);
813 $ref_item{'type'} = $type;
814 $ref_item{'id'} = $ref_id;
815 $ref_item{'epoch'} = 0;
816 $ref_item{'age'} = "unknown";
817 if ($type eq "tag") {
818 my %tag = parse_tag($ref_id);
819 $ref_item{'comment'} = $tag{'comment'};
820 if ($tag{'type'} eq "commit") {
821 my %co = parse_commit($tag{'object'});
822 $ref_item{'epoch'} = $co{'committer_epoch'};
823 $ref_item{'age'} = $co{'age_string'};
824 } elsif (defined($tag{'epoch'})) {
825 my $age = time - $tag{'epoch'};
826 $ref_item{'epoch'} = $tag{'epoch'};
827 $ref_item{'age'} = age_string($age);
829 $ref_item{'reftype'} = $tag{'type'};
830 $ref_item{'name'} = $tag{'name'};
831 $ref_item{'refid'} = $tag{'object'};
832 } elsif ($type eq "commit"){
833 my %co = parse_commit($ref_id);
834 $ref_item{'reftype'} = "commit";
835 $ref_item{'name'} = $ref_file;
836 $ref_item{'title'} = $co{'title'};
837 $ref_item{'refid'} = $ref_id;
838 $ref_item{'epoch'} = $co{'committer_epoch'};
839 $ref_item{'age'} = $co{'age_string'};
841 $ref_item{'reftype'} = $type;
842 $ref_item{'name'} = $ref_file;
843 $ref_item{'refid'} = $ref_id;
849 ## ......................................................................
850 ## parse to array of hashes functions
852 sub git_get_refs_list {
857 my $pfxlen = length("$projectroot/$project/$ref_dir");
858 File::Find::find(sub {
861 push @refs, substr($File::Find::name, $pfxlen + 1);
863 }, "$projectroot/$project/$ref_dir");
865 foreach my $ref_file (@refs) {
866 my $ref_id = git_get_hash_by_ref("$project/$ref_dir/$ref_file");
867 my $type = git_get_type($ref_id) || next;
868 my %ref_item = parse_ref($ref_file, $ref_id, $type);
870 push @reflist, \%ref_item;
873 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
877 ## ----------------------------------------------------------------------
878 ## filesystem-related functions
883 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
884 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
885 if (!defined $gcos) {
889 $owner =~ s/[,;].*$//;
890 return decode("utf8", $owner, Encode::FB_DEFAULT);
893 ## ......................................................................
894 ## mimetype related functions
896 sub mimetype_guess_file {
897 my $filename = shift;
899 -r $mimemap or return undef;
902 open(MIME, $mimemap) or return undef;
904 next if m/^#/; # skip comments
905 my ($mime, $exts) = split(/\t+/);
907 my @exts = split(/\s+/, $exts);
908 foreach my $ext (@exts) {
909 $mimemap{$ext} = $mime;
915 $filename =~ /\.(.*?)$/;
920 my $filename = shift;
922 $filename =~ /\./ or return undef;
924 if ($mimetypes_file) {
925 my $file = $mimetypes_file;
926 if ($file !~ m!^/!) { # if it is relative path
927 # it is relative to project
928 $file = "$projectroot/$project/$file";
930 $mime = mimetype_guess_file($filename, $file);
932 $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
938 my $filename = shift;
941 my $mime = mimetype_guess($filename);
942 $mime and return $mime;
946 return $default_blob_plain_mimetype unless $fd;
949 return 'text/plain' .
950 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
951 } elsif (! $filename) {
952 return 'application/octet-stream';
953 } elsif ($filename =~ m/\.png$/i) {
955 } elsif ($filename =~ m/\.gif$/i) {
957 } elsif ($filename =~ m/\.jpe?g$/i) {
960 return 'application/octet-stream';
964 ## ======================================================================
965 ## functions printing HTML: header, footer, error page
967 sub git_header_html {
968 my $status = shift || "200 OK";
971 my $title = "$site_name git";
972 if (defined $project) {
973 $title .= " - $project";
974 if (defined $action) {
975 $title .= "/$action";
976 if (defined $file_name) {
977 $title .= " - $file_name";
978 if ($action eq "tree" && $file_name !~ m|/$|) {
985 # require explicit support from the UA if we are to send the page as
986 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
987 # we have to do this because MSIE sometimes globs '*/*', pretending to
988 # support xhtml+xml but choking when it gets what it asked for.
989 if (defined $cgi->http('HTTP_ACCEPT') && $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ && $cgi->Accept('application/xhtml+xml') != 0) {
990 $content_type = 'application/xhtml+xml';
992 $content_type = 'text/html';
994 print $cgi->header(-type=>$content_type, -charset => 'utf-8', -status=> $status, -expires => $expires);
996 <?xml version="1.0" encoding="utf-8"?>
997 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
998 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
999 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1000 <!-- git core binaries version $git_version -->
1002 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1003 <meta name="generator" content="gitweb/$version git/$git_version"/>
1004 <meta name="robots" content="index, nofollow"/>
1005 <title>$title</title>
1006 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1008 if (defined $project) {
1009 printf('<link rel="alternate" title="%s log" '.
1010 'href="%s" type="application/rss+xml"/>'."\n",
1011 esc_param($project), href(action=>"rss"));
1016 "<div class=\"page_header\">\n" .
1017 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1018 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1020 print $cgi->a({-href => esc_param($home_link)}, $home_link_str) . " / ";
1021 if (defined $project) {
1022 print $cgi->a({-href => href(action=>"summary")}, esc_html($project));
1023 if (defined $action) {
1027 if (!defined $searchtext) {
1031 if (defined $hash_base) {
1032 $search_hash = $hash_base;
1033 } elsif (defined $hash) {
1034 $search_hash = $hash;
1036 $search_hash = "HEAD";
1038 $cgi->param("a", "search");
1039 $cgi->param("h", $search_hash);
1040 print $cgi->startform(-method => "get", -action => $my_uri) .
1041 "<div class=\"search\">\n" .
1042 $cgi->hidden(-name => "p") . "\n" .
1043 $cgi->hidden(-name => "a") . "\n" .
1044 $cgi->hidden(-name => "h") . "\n" .
1045 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
1047 $cgi->end_form() . "\n";
1052 sub git_footer_html {
1053 print "<div class=\"page_footer\">\n";
1054 if (defined $project) {
1055 my $descr = git_get_project_description($project);
1056 if (defined $descr) {
1057 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
1059 print $cgi->a({-href => href(action=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1061 print $cgi->a({-href => "$my_uri?" . esc_param("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
1069 my $status = shift || "403 Forbidden";
1070 my $error = shift || "Malformed query, file missing or permission denied";
1072 git_header_html($status);
1073 print "<div class=\"page_body\">\n" .
1075 "$status - $error\n" .
1082 ## ----------------------------------------------------------------------
1083 ## functions printing or outputting HTML: navigation
1085 sub git_print_page_nav {
1086 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1087 $extra = '' if !defined $extra; # pager or formats
1089 my @navs = qw(summary shortlog log commit commitdiff tree);
1091 @navs = grep { $_ ne $suppress } @navs;
1094 my %arg = map { $_ => {action=>$_} } @navs;
1095 if (defined $head) {
1096 for (qw(commit commitdiff)) {
1097 $arg{$_}{hash} = $head;
1099 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1100 for (qw(shortlog log)) {
1101 $arg{$_}{hash} = $head;
1105 $arg{tree}{hash} = $treehead if defined $treehead;
1106 $arg{tree}{hash_base} = $treebase if defined $treebase;
1108 print "<div class=\"page_nav\">\n" .
1110 map { $_ eq $current ?
1111 $_ : $cgi->a({-href => href(%{$arg{$_}})}, "$_")
1113 print "<br/>\n$extra<br/>\n" .
1117 sub format_paging_nav {
1118 my ($action, $hash, $head, $page, $nrevs) = @_;
1122 if ($hash ne $head || $page) {
1123 $paging_nav .= $cgi->a({-href => href(action=>$action)}, "HEAD");
1125 $paging_nav .= "HEAD";
1129 $paging_nav .= " ⋅ " .
1130 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page-1),
1131 -accesskey => "p", -title => "Alt-p"}, "prev");
1133 $paging_nav .= " ⋅ prev";
1136 if ($nrevs >= (100 * ($page+1)-1)) {
1137 $paging_nav .= " ⋅ " .
1138 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page+1),
1139 -accesskey => "n", -title => "Alt-n"}, "next");
1141 $paging_nav .= " ⋅ next";
1147 ## ......................................................................
1148 ## functions printing or outputting HTML: div
1150 sub git_print_header_div {
1151 my ($action, $title, $hash, $hash_base) = @_;
1154 $args{action} = $action;
1155 $args{hash} = $hash if $hash;
1156 $args{hash_base} = $hash_base if $hash_base;
1158 print "<div class=\"header\">\n" .
1159 $cgi->a({-href => href(%args), -class => "title"},
1160 $title ? $title : $action) .
1164 sub git_print_page_path {
1168 if (!defined $name) {
1169 print "<div class=\"page_path\"><b>/</b></div>\n";
1170 } elsif (defined $type && $type eq 'blob') {
1171 print "<div class=\"page_path\"><b>" .
1172 $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name)}, esc_html($name)) . "</b><br/></div>\n";
1174 print "<div class=\"page_path\"><b>" . esc_html($name) . "</b><br/></div>\n";
1178 ## ......................................................................
1179 ## functions printing large fragments of HTML
1181 sub git_difftree_body {
1182 my ($difftree, $parent) = @_;
1184 print "<div class=\"list_head\">\n";
1185 if ($#{$difftree} > 10) {
1186 print(($#{$difftree} + 1) . " files changed:\n");
1190 print "<table class=\"diff_tree\">\n";
1192 foreach my $line (@{$difftree}) {
1193 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1194 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1195 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1203 my $similarity = $6; # score
1204 my $file = validate_input(unquote($7));
1207 print "<tr class=\"dark\">\n";
1209 print "<tr class=\"light\">\n";
1213 if ($status eq "A") { # created
1215 if (S_ISREG(oct $to_mode)) {
1216 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1219 $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$file),
1220 -class => "list"}, esc_html($file)) .
1222 "<td><span class=\"file_status new\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" .
1223 "<td class=\"link\">" .
1224 $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$file)}, "blob") .
1227 } elsif ($status eq "D") { # deleted
1229 $cgi->a({-href => href(action=>"blob", hash=>$from_id, hash_base=>$parent, file_name=>$file),
1230 -class => "list"}, esc_html($file)) . "</td>\n" .
1231 "<td><span class=\"file_status deleted\">[deleted " . file_type($from_mode). "]</span></td>\n" .
1232 "<td class=\"link\">" .
1233 $cgi->a({-href => href(action=>"blob", hash=>$from_id, hash_base=>$parent, file_name=>$file)}, "blob") . " | " .
1234 $cgi->a({-href => href(action=>"history", hash_base=>$parent, file_name=>$file)}, "history") .
1237 } elsif ($status eq "M" || $status eq "T") { # modified, or type changed
1238 my $mode_chnge = "";
1239 if ($from_mode != $to_mode) {
1240 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
1241 if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
1242 $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
1244 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1245 if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
1246 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1247 } elsif (S_ISREG($to_mode)) {
1248 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1251 $mode_chnge .= "]</span>\n";
1254 if ($to_id ne $from_id) { # modified
1255 print $cgi->a({-href => href(action=>"blobdiff", hash=>$to_id, hash_parent=>$from_id, hash_base=>$hash, file_name=>$file),
1256 -class => "list"}, esc_html($file));
1257 } else { # mode changed
1258 print $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$file),
1259 -class => "list"}, esc_html($file));
1262 "<td>$mode_chnge</td>\n" .
1263 "<td class=\"link\">" .
1264 $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$file)}, "blob");
1265 if ($to_id ne $from_id) { # modified
1266 print $cgi->a({-href => href(action=>"blobdiff", hash=>$to_id, hash_parent=>$from_id, hash_base=>$hash, file_name=>$file)}, "diff");
1268 print " | " . $cgi->a({-href => href(action=>"history", hash_base=>$hash, file_name=>$file)}, "history") . "\n";
1271 } elsif ($status eq "R") { # renamed
1272 my ($from_file, $to_file) = split "\t", $file;
1274 if ($from_mode != $to_mode) {
1275 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1278 $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$to_file),
1279 -class => "list"}, esc_html($to_file)) . "</td>\n" .
1280 "<td><span class=\"file_status moved\">[moved from " .
1281 $cgi->a({-href => href(action=>"blob", hash=>$from_id, hash_base=>$parent, file_name=>$from_file),
1282 -class => "list"}, esc_html($from_file)) .
1283 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1284 "<td class=\"link\">" .
1285 $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$to_file)}, "blob");
1286 if ($to_id ne $from_id) {
1288 $cgi->a({-href => "$my_uri?" .
1289 esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file;fp=$from_file")}, "diff");
1293 } elsif ($status eq "C") { # copied
1294 my ($from_file, $to_file) = split "\t", $file;
1296 if ($from_mode != $to_mode) {
1297 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1300 $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$to_file),
1301 -class => "list"}, esc_html($to_file)) . "</td>\n" .
1302 "<td><span class=\"file_status copied\">[copied from " .
1303 $cgi->a({-href => href(action=>"blob", hash=>$from_id, hash_base=>$parent, file_name=>$from_file),
1304 -class => "list"}, esc_html($from_file)) .
1305 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1306 "<td class=\"link\">" .
1307 $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$to_file)}, "blob");
1308 if ($to_id ne $from_id) {
1310 $cgi->a({-href => "$my_uri?" .
1311 esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file;fp=$from_file")}, "diff");
1314 } # we should not encounter Unmerged (U) or Unknown (X) status
1320 sub git_shortlog_body {
1321 # uses global variable $project
1322 my ($revlist, $from, $to, $refs, $extra) = @_;
1323 $from = 0 unless defined $from;
1324 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1326 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1328 for (my $i = $from; $i <= $to; $i++) {
1329 my $commit = $revlist->[$i];
1330 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1331 my $ref = format_ref_marker($refs, $commit);
1332 my %co = parse_commit($commit);
1334 print "<tr class=\"dark\">\n";
1336 print "<tr class=\"light\">\n";
1339 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1340 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1341 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1343 print format_subject_html($co{'title'}, $co{'title_short'}, href(action=>"commit", hash=>$commit), $ref);
1345 "<td class=\"link\">" .
1346 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
1347 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
1351 if (defined $extra) {
1353 "<td colspan=\"4\">$extra</td>\n" .
1359 sub git_history_body {
1360 # Warning: assumes constant type (blob or tree) during history
1361 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1363 print "<table class=\"history\" cellspacing=\"0\">\n";
1365 while (my $line = <$fd>) {
1366 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1371 my %co = parse_commit($commit);
1376 my $ref = format_ref_marker($refs, $commit);
1379 print "<tr class=\"dark\">\n";
1381 print "<tr class=\"light\">\n";
1384 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1385 # shortlog uses chop_str($co{'author_name'}, 10)
1386 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1388 # originally git_history used chop_str($co{'title'}, 50)
1389 print format_subject_html($co{'title'}, $co{'title_short'}, href(action=>"commit", hash=>$commit), $ref);
1391 "<td class=\"link\">" .
1392 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
1393 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
1394 $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype);
1396 if ($ftype eq 'blob') {
1397 my $blob_current = git_get_hash_by_path($hash_base, $file_name);
1398 my $blob_parent = git_get_hash_by_path($commit, $file_name);
1399 if (defined $blob_current && defined $blob_parent &&
1400 $blob_current ne $blob_parent) {
1402 $cgi->a({-href => href(action=>"blobdiff", hash=>$blob_current, hash_parent=>$blob_parent, hash_base=>$commit, file_name=>$file_name)},
1409 if (defined $extra) {
1411 "<td colspan=\"4\">$extra</td>\n" .
1418 # uses global variable $project
1419 my ($taglist, $from, $to, $extra) = @_;
1420 $from = 0 unless defined $from;
1421 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1423 print "<table class=\"tags\" cellspacing=\"0\">\n";
1425 for (my $i = $from; $i <= $to; $i++) {
1426 my $entry = $taglist->[$i];
1428 my $comment_lines = $tag{'comment'};
1429 my $comment = shift @$comment_lines;
1431 if (defined $comment) {
1432 $comment_short = chop_str($comment, 30, 5);
1435 print "<tr class=\"dark\">\n";
1437 print "<tr class=\"light\">\n";
1440 print "<td><i>$tag{'age'}</i></td>\n" .
1442 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),
1443 -class => "list"}, "<b>" . esc_html($tag{'name'}) . "</b>") .
1446 if (defined $comment) {
1447 print format_subject_html($comment, $comment_short, href(action=>"tag", hash=>$tag{'id'}));
1450 "<td class=\"selflink\">";
1451 if ($tag{'type'} eq "tag") {
1452 print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag");
1457 "<td class=\"link\">" . " | " .
1458 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'});
1459 if ($tag{'reftype'} eq "commit") {
1460 print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") .
1461 " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'refid'})}, "log");
1462 } elsif ($tag{'reftype'} eq "blob") {
1463 print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw");
1468 if (defined $extra) {
1470 "<td colspan=\"5\">$extra</td>\n" .
1476 sub git_heads_body {
1477 # uses global variable $project
1478 my ($taglist, $head, $from, $to, $extra) = @_;
1479 $from = 0 unless defined $from;
1480 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1482 print "<table class=\"heads\" cellspacing=\"0\">\n";
1484 for (my $i = $from; $i <= $to; $i++) {
1485 my $entry = $taglist->[$i];
1487 my $curr = $tag{'id'} eq $head;
1489 print "<tr class=\"dark\">\n";
1491 print "<tr class=\"light\">\n";
1494 print "<td><i>$tag{'age'}</i></td>\n" .
1495 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
1496 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'}),
1497 -class => "list"}, "<b>" . esc_html($tag{'name'}) . "</b>") .
1499 "<td class=\"link\">" .
1500 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") . " | " .
1501 $cgi->a({-href => href(action=>"log", hash=>$tag{'name'})}, "log") .
1505 if (defined $extra) {
1507 "<td colspan=\"3\">$extra</td>\n" .
1513 ## ----------------------------------------------------------------------
1514 ## functions printing large fragments, format as one of arguments
1516 sub git_diff_print {
1518 my $from_name = shift;
1520 my $to_name = shift;
1521 my $format = shift || "html";
1523 my $from_tmp = "/dev/null";
1524 my $to_tmp = "/dev/null";
1527 # create tmp from-file
1528 if (defined $from) {
1529 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1530 open my $fd2, "> $from_tmp";
1531 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1538 # create tmp to-file
1540 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1541 open my $fd2, "> $to_tmp";
1542 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1549 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1550 if ($format eq "plain") {
1555 while (my $line = <$fd>) {
1557 my $char = substr($line, 0, 1);
1558 my $diff_class = "";
1560 $diff_class = " add";
1561 } elsif ($char eq "-") {
1562 $diff_class = " rem";
1563 } elsif ($char eq "@") {
1564 $diff_class = " chunk_header";
1565 } elsif ($char eq "\\") {
1569 $line = untabify($line);
1570 print "<div class=\"diff$diff_class\">" . esc_html($line) . "</div>\n";
1575 if (defined $from) {
1584 ## ======================================================================
1585 ## ======================================================================
1588 sub git_project_list {
1589 my $order = $cgi->param('o');
1590 if (defined $order && $order !~ m/project|descr|owner|age/) {
1591 die_error(undef, "Unknown order parameter");
1594 my @list = git_get_projects_list();
1597 die_error(undef, "No projects found");
1599 foreach my $pr (@list) {
1600 my $head = git_get_head_hash($pr->{'path'});
1601 if (!defined $head) {
1604 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1605 my %co = parse_commit($head);
1609 $pr->{'commit'} = \%co;
1610 if (!defined $pr->{'descr'}) {
1611 my $descr = git_get_project_description($pr->{'path'}) || "";
1612 $pr->{'descr'} = chop_str($descr, 25, 5);
1614 if (!defined $pr->{'owner'}) {
1615 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
1617 push @projects, $pr;
1621 if (-f $home_text) {
1622 print "<div class=\"index_include\">\n";
1623 open (my $fd, $home_text);
1628 print "<table class=\"project_list\">\n" .
1630 $order ||= "project";
1631 if ($order eq "project") {
1632 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1633 print "<th>Project</th>\n";
1636 $cgi->a({-href => "$my_uri?" . esc_param("o=project"),
1637 -class => "header"}, "Project") .
1640 if ($order eq "descr") {
1641 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1642 print "<th>Description</th>\n";
1645 $cgi->a({-href => "$my_uri?" . esc_param("o=descr"),
1646 -class => "header"}, "Description") .
1649 if ($order eq "owner") {
1650 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1651 print "<th>Owner</th>\n";
1654 $cgi->a({-href => "$my_uri?" . esc_param("o=owner"),
1655 -class => "header"}, "Owner") .
1658 if ($order eq "age") {
1659 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1660 print "<th>Last Change</th>\n";
1663 $cgi->a({-href => "$my_uri?" . esc_param("o=age"),
1664 -class => "header"}, "Last Change") .
1667 print "<th></th>\n" .
1670 foreach my $pr (@projects) {
1672 print "<tr class=\"dark\">\n";
1674 print "<tr class=\"light\">\n";
1677 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary"),
1678 -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
1679 "<td>" . esc_html($pr->{'descr'}) . "</td>\n" .
1680 "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
1681 print "<td class=\"". age_class($pr->{'commit'}{'age'}) . "\">" .
1682 $pr->{'commit'}{'age_string'} . "</td>\n" .
1683 "<td class=\"link\">" .
1684 $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary")}, "summary") . " | " .
1685 $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=shortlog")}, "shortlog") . " | " .
1686 $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=log")}, "log") .
1695 my $descr = git_get_project_description($project) || "none";
1696 my $head = git_get_head_hash($project);
1697 my %co = parse_commit($head);
1698 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
1700 my $owner = git_get_project_owner($project);
1702 my $refs = git_get_references();
1704 git_print_page_nav('summary','', $head);
1706 print "<div class=\"title\"> </div>\n";
1707 print "<table cellspacing=\"0\">\n" .
1708 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
1709 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1710 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
1711 # use per project git URL list in $projectroot/$project/cloneurl
1712 # or make project git URL from git base URL and project name
1713 my $url_tag = "URL";
1714 my @url_list = git_get_project_url_list($project);
1715 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
1716 foreach my $git_url (@url_list) {
1717 next unless $git_url;
1718 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
1723 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash($project)
1724 or die_error(undef, "Open git-rev-list failed");
1725 my @revlist = map { chomp; $_ } <$fd>;
1727 git_print_header_div('shortlog');
1728 git_shortlog_body(\@revlist, 0, 15, $refs,
1729 $cgi->a({-href => href(action=>"shortlog")}, "..."));
1731 my $taglist = git_get_refs_list("refs/tags");
1732 if (defined @$taglist) {
1733 git_print_header_div('tags');
1734 git_tags_body($taglist, 0, 15,
1735 $cgi->a({-href => href(action=>"tags")}, "..."));
1738 my $headlist = git_get_refs_list("refs/heads");
1739 if (defined @$headlist) {
1740 git_print_header_div('heads');
1741 git_heads_body($headlist, $head, 0, 15,
1742 $cgi->a({-href => href(action=>"heads")}, "..."));
1749 my $head = git_get_head_hash($project);
1751 git_print_page_nav('','', $head,undef,$head);
1752 my %tag = parse_tag($hash);
1753 git_print_header_div('commit', esc_html($tag{'name'}), $hash);
1754 print "<div class=\"title_text\">\n" .
1755 "<table cellspacing=\"0\">\n" .
1757 "<td>object</td>\n" .
1758 "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})}, $tag{'object'}) . "</td>\n" .
1759 "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})}, $tag{'type'}) . "</td>\n" .
1761 if (defined($tag{'author'})) {
1762 my %ad = parse_date($tag{'epoch'}, $tag{'tz'});
1763 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
1764 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1766 print "</table>\n\n" .
1768 print "<div class=\"page_body\">";
1769 my $comment = $tag{'comment'};
1770 foreach my $line (@$comment) {
1771 print esc_html($line) . "<br/>\n";
1780 die_error(undef, "Permission denied") if (!git_get_project_config_bool ('blame'));
1781 die_error('404 Not Found', "File name not defined") if (!$file_name);
1782 $hash_base ||= git_get_head_hash($project);
1783 die_error(undef, "Couldn't find base commit") unless ($hash_base);
1784 my %co = parse_commit($hash_base)
1785 or die_error(undef, "Reading commit failed");
1786 if (!defined $hash) {
1787 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
1788 or die_error(undef, "Error looking up file");
1790 $ftype = git_get_type($hash);
1791 if ($ftype !~ "blob") {
1792 die_error("400 Bad Request", "Object is not a blob");
1794 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
1795 or die_error(undef, "Open git-blame failed");
1798 $cgi->a({-href => href(action=>"blobl", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)}, "blob") .
1799 " | " . $cgi->a({-href => href(action=>"blame", file_name=>$file_name)}, "head");
1800 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1801 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
1802 git_print_page_path($file_name, $ftype);
1803 my @rev_color = (qw(light2 dark2));
1804 my $num_colors = scalar(@rev_color);
1805 my $current_color = 0;
1807 print "<div class=\"page_body\">\n";
1808 print "<table class=\"blame\">\n";
1809 print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
1811 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
1813 my $rev = substr($full_rev, 0, 8);
1817 if (!defined $last_rev) {
1818 $last_rev = $full_rev;
1819 } elsif ($last_rev ne $full_rev) {
1820 $last_rev = $full_rev;
1821 $current_color = ++$current_color % $num_colors;
1823 print "<tr class=\"$rev_color[$current_color]\">\n";
1824 print "<td class=\"sha1\">" .
1825 $cgi->a({-href => href(action=>"commit", hash=>$full_rev, file_name=>$file_name)}, esc_html($rev)) . "</td>\n";
1826 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html($lineno) . "</a></td>\n";
1827 print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
1832 close $fd or print "Reading blob failed\n";
1838 die_error('403 Permission denied', "Permission denied") if (!git_get_project_config_bool ('blame'));
1839 die_error('404 Not Found', "File name not defined") if (!$file_name);
1840 $hash_base ||= git_get_head_hash($project);
1841 die_error(undef, "Couldn't find base commit") unless ($hash_base);
1842 my %co = parse_commit($hash_base)
1843 or die_error(undef, "Reading commit failed");
1844 if (!defined $hash) {
1845 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
1846 or die_error(undef, "Error lookup file");
1848 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
1849 or die_error(undef, "Open git-annotate failed");
1852 $cgi->a({-href => href(action=>"blobl", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)}, "blob") .
1853 " | " . $cgi->a({-href => href(action=>"blame", file_name=>$file_name)}, "head");
1854 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1855 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
1856 git_print_page_path($file_name, 'blob');
1857 print "<div class=\"page_body\">\n";
1859 <table class="blame">
1868 my @line_class = (qw(light dark));
1869 my $line_class_len = scalar (@line_class);
1870 my $line_class_num = $#line_class;
1871 while (my $line = <$fd>) {
1883 $line_class_num = ($line_class_num + 1) % $line_class_len;
1885 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1892 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
1895 $short_rev = substr ($long_rev, 0, 8);
1896 $age = time () - $time;
1897 $age_str = age_string ($age);
1898 $age_str =~ s/ / /g;
1899 $age_class = age_class($age);
1900 $author = esc_html ($author);
1901 $author =~ s/ / /g;
1903 $data = untabify($data);
1904 $data = esc_html ($data);
1907 <tr class="$line_class[$line_class_num]">
1908 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
1909 <td class="$age_class">$age_str</td>
1911 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1912 <td class="pre">$data</td>
1915 } # while (my $line = <$fd>)
1916 print "</table>\n\n";
1917 close $fd or print "Reading blob failed.\n";
1923 my $head = git_get_head_hash($project);
1925 git_print_page_nav('','', $head,undef,$head);
1926 git_print_header_div('summary', $project);
1928 my $taglist = git_get_refs_list("refs/tags");
1929 if (defined @$taglist) {
1930 git_tags_body($taglist);
1936 my $head = git_get_head_hash($project);
1938 git_print_page_nav('','', $head,undef,$head);
1939 git_print_header_div('summary', $project);
1941 my $taglist = git_get_refs_list("refs/heads");
1942 if (defined @$taglist) {
1943 git_heads_body($taglist, $head);
1948 sub git_blob_plain {
1949 if (!defined $hash) {
1950 if (defined $file_name) {
1951 my $base = $hash_base || git_get_head_hash($project);
1952 $hash = git_get_hash_by_path($base, $file_name, "blob")
1953 or die_error(undef, "Error lookup file");
1955 die_error(undef, "No file name defined");
1959 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1960 or die_error(undef, "Couldn't cat $file_name, $hash");
1962 $type ||= blob_mimetype($fd, $file_name);
1964 # save as filename, even when no $file_name is given
1965 my $save_as = "$hash";
1966 if (defined $file_name) {
1967 $save_as = $file_name;
1968 } elsif ($type =~ m/^text\//) {
1972 print $cgi->header(-type => "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1974 binmode STDOUT, ':raw';
1976 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
1982 if (!defined $hash) {
1983 if (defined $file_name) {
1984 my $base = $hash_base || git_get_head_hash($project);
1985 $hash = git_get_hash_by_path($base, $file_name, "blob")
1986 or die_error(undef, "Error lookup file");
1988 die_error(undef, "No file name defined");
1991 my $have_blame = git_get_project_config_bool ('blame');
1992 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1993 or die_error(undef, "Couldn't cat $file_name, $hash");
1994 my $mimetype = blob_mimetype($fd, $file_name);
1995 if ($mimetype !~ m/^text\//) {
1997 return git_blob_plain($mimetype);
2000 my $formats_nav = '';
2001 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2002 if (defined $file_name) {
2004 $formats_nav .= $cgi->a({-href => href(action=>"blame", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)}, "blame") . " | ";
2007 $cgi->a({-href => href(action=>"blob_plain", hash=>$hash, file_name=>$file_name)}, "plain") .
2008 " | " . $cgi->a({-href => href(action=>"blob", hash_base=>"HEAD", file_name=>$file_name)}, "head");
2010 $formats_nav .= $cgi->a({-href => href(action=>"blob_plain", hash=>$hash)}, "plain");
2012 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2013 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2015 print "<div class=\"page_nav\">\n" .
2016 "<br/><br/></div>\n" .
2017 "<div class=\"title\">$hash</div>\n";
2019 git_print_page_path($file_name, "blob");
2020 print "<div class=\"page_body\">\n";
2022 while (my $line = <$fd>) {
2025 $line = untabify($line);
2026 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html($line);
2028 close $fd or print "Reading blob failed.\n";
2034 if (!defined $hash) {
2035 $hash = git_get_head_hash($project);
2036 if (defined $file_name) {
2037 my $base = $hash_base || $hash;
2038 $hash = git_get_hash_by_path($base, $file_name, "tree");
2040 if (!defined $hash_base) {
2045 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
2046 or die_error(undef, "Open git-ls-tree failed");
2047 my @entries = map { chomp; $_ } <$fd>;
2048 close $fd or die_error(undef, "Reading tree failed");
2051 my $refs = git_get_references();
2052 my $ref = format_ref_marker($refs, $hash_base);
2056 my $have_blame = git_get_project_config_bool ('blame');
2057 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2058 $base_key = ";hb=$hash_base";
2059 git_print_page_nav('tree','', $hash_base);
2060 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
2062 print "<div class=\"page_nav\">\n";
2063 print "<br/><br/></div>\n";
2064 print "<div class=\"title\">$hash</div>\n";
2066 if (defined $file_name) {
2067 $base = esc_html("$file_name/");
2069 git_print_page_path($file_name, 'tree');
2070 print "<div class=\"page_body\">\n";
2071 print "<table cellspacing=\"0\">\n";
2073 foreach my $line (@entries) {
2074 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2075 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2079 my $t_name = validate_input($4);
2081 print "<tr class=\"dark\">\n";
2083 print "<tr class=\"light\">\n";
2086 print "<td class=\"mode\">" . mode_str($t_mode) . "</td>\n";
2087 if ($t_type eq "blob") {
2088 print "<td class=\"list\">" .
2089 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name"), -class => "list"}, esc_html($t_name)) .
2091 "<td class=\"link\">" .
2092 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob");
2094 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame");
2096 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$t_hash;hb=$hash_base;f=$base$t_name")}, "history") .
2097 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") .
2099 } elsif ($t_type eq "tree") {
2100 print "<td class=\"list\">" .
2101 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html($t_name)) .
2103 "<td class=\"link\">" .
2104 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
2105 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") .
2110 print "</table>\n" .
2116 my $head = git_get_head_hash($project);
2117 if (!defined $hash) {
2120 if (!defined $page) {
2123 my $refs = git_get_references();
2125 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2126 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2127 or die_error(undef, "Open git-rev-list failed");
2128 my @revlist = map { chomp; $_ } <$fd>;
2131 my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#revlist);
2134 git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
2137 my %co = parse_commit($hash);
2139 git_print_header_div('summary', $project);
2140 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2142 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2143 my $commit = $revlist[$i];
2144 my $ref = format_ref_marker($refs, $commit);
2145 my %co = parse_commit($commit);
2147 my %ad = parse_date($co{'author_epoch'});
2148 git_print_header_div('commit',
2149 "<span class=\"age\">$co{'age_string'}</span>" .
2150 esc_html($co{'title'}) . $ref,
2152 print "<div class=\"title_text\">\n" .
2153 "<div class=\"log_link\">\n" .
2154 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
2155 " | " . $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
2158 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2160 "<div class=\"log_body\">\n";
2161 my $comment = $co{'comment'};
2163 foreach my $line (@$comment) {
2164 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2175 print format_log_line_html($line) . "<br/>\n";
2186 my %co = parse_commit($hash);
2188 die_error(undef, "Unknown commit object");
2190 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
2191 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
2193 my $parent = $co{'parent'};
2194 if (!defined $parent) {
2197 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
2198 or die_error(undef, "Open git-diff-tree failed");
2199 my @difftree = map { chomp; $_ } <$fd>;
2200 close $fd or die_error(undef, "Reading git-diff-tree failed");
2202 # non-textual hash id's can be cached
2204 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2207 my $refs = git_get_references();
2208 my $ref = format_ref_marker($refs, $co{'id'});
2209 my $formats_nav = '';
2210 if (defined $file_name && defined $co{'parent'}) {
2211 my $parent = $co{'parent'};
2212 $formats_nav .= $cgi->a({-href => href(action=>"blame", hash_parent=>$parent, file_name=>$file_name)}, "blame");
2214 git_header_html(undef, $expires);
2215 git_print_page_nav('commit', defined $co{'parent'} ? '' : 'commitdiff',
2216 $hash, $co{'tree'}, $hash,
2219 if (defined $co{'parent'}) {
2220 git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash);
2222 git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash);
2224 print "<div class=\"title_text\">\n" .
2225 "<table cellspacing=\"0\">\n";
2226 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
2228 "<td></td><td> $ad{'rfc2822'}";
2229 if ($ad{'hour_local'} < 6) {
2230 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2232 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2236 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
2237 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
2238 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2241 "<td class=\"sha1\">" .
2242 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash), class => "list"}, $co{'tree'}) .
2244 "<td class=\"link\">" . $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)}, "tree") .
2247 my $parents = $co{'parents'};
2248 foreach my $par (@$parents) {
2251 "<td class=\"sha1\">" . $cgi->a({-href => href(action=>"commit", hash=>$par), class => "list"}, $par) . "</td>" .
2252 "<td class=\"link\">" .
2253 $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") .
2254 " | " . $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "commitdiff") .
2260 print "<div class=\"page_body\">\n";
2261 my $comment = $co{'comment'};
2264 foreach my $line (@$comment) {
2265 # print only one empty line
2267 if ($empty || $signed) {
2274 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2276 print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
2279 print format_log_line_html($line) . "<br/>\n";
2284 git_difftree_body(\@difftree, $parent);
2290 mkdir($git_temp, 0700);
2292 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2294 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2295 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2296 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2298 print "<div class=\"page_nav\">\n" .
2299 "<br/><br/></div>\n" .
2300 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2302 git_print_page_path($file_name, "blob");
2303 print "<div class=\"page_body\">\n" .
2304 "<div class=\"diff_info\">blob:" .
2305 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2307 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2309 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2314 sub git_blobdiff_plain {
2315 mkdir($git_temp, 0700);
2316 print $cgi->header(-type => "text/plain", -charset => 'utf-8');
2317 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2320 sub git_commitdiff {
2321 mkdir($git_temp, 0700);
2322 my %co = parse_commit($hash);
2324 die_error(undef, "Unknown commit object");
2326 if (!defined $hash_parent) {
2327 $hash_parent = $co{'parent'} || '--root';
2329 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2330 or die_error(undef, "Open git-diff-tree failed");
2331 my @difftree = map { chomp; $_ } <$fd>;
2332 close $fd or die_error(undef, "Reading git-diff-tree failed");
2334 # non-textual hash id's can be cached
2336 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2339 my $refs = git_get_references();
2340 my $ref = format_ref_marker($refs, $co{'id'});
2342 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2343 git_header_html(undef, $expires);
2344 git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2345 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
2346 print "<div class=\"page_body\">\n";
2347 my $comment = $co{'comment'};
2350 my @log = @$comment;
2351 # remove first and empty lines after that
2353 while (defined $log[0] && $log[0] eq "") {
2356 foreach my $line (@log) {
2357 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2368 print format_log_line_html($line) . "<br/>\n";
2371 foreach my $line (@difftree) {
2372 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2373 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2374 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2382 my $file = validate_input(unquote($6));
2383 if ($status eq "A") {
2384 print "<div class=\"diff_info\">" . file_type($to_mode) . ":" .
2385 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2387 git_diff_print(undef, "/dev/null", $to_id, "b/$file");
2388 } elsif ($status eq "D") {
2389 print "<div class=\"diff_info\">" . file_type($from_mode) . ":" .
2390 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash_parent;f=$file")}, $from_id) . "(deleted)" .
2392 git_diff_print($from_id, "a/$file", undef, "/dev/null");
2393 } elsif ($status eq "M") {
2394 if ($from_id ne $to_id) {
2395 print "<div class=\"diff_info\">" .
2396 file_type($from_mode) . ":" .
2397 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash_parent;f=$file")}, $from_id) .
2399 file_type($to_mode) . ":" .
2400 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2402 git_diff_print($from_id, "a/$file", $to_id, "b/$file");
2411 sub git_commitdiff_plain {
2412 mkdir($git_temp, 0700);
2413 my %co = parse_commit($hash);
2415 die_error(undef, "Unknown commit object");
2417 if (!defined $hash_parent) {
2418 $hash_parent = $co{'parent'} || '--root';
2420 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2421 or die_error(undef, "Open git-diff-tree failed");
2422 my @difftree = map { chomp; $_ } <$fd>;
2423 close $fd or die_error(undef, "Reading diff-tree failed");
2425 # try to figure out the next tag after this commit
2427 my $refs = git_get_references("tags");
2428 open $fd, "-|", $GIT, "rev-list", "HEAD";
2429 my @commits = map { chomp; $_ } <$fd>;
2431 foreach my $commit (@commits) {
2432 if (defined $refs->{$commit}) {
2433 $tagname = $refs->{$commit}
2435 if ($commit eq $hash) {
2440 print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2441 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
2442 my $comment = $co{'comment'};
2443 print "From: $co{'author'}\n" .
2444 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2445 "Subject: $co{'title'}\n";
2446 if (defined $tagname) {
2447 print "X-Git-Tag: $tagname\n";
2449 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2452 foreach my $line (@$comment) {;
2457 foreach my $line (@difftree) {
2458 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2465 if ($status eq "A") {
2466 git_diff_print(undef, "/dev/null", $to_id, "b/$file", "plain");
2467 } elsif ($status eq "D") {
2468 git_diff_print($from_id, "a/$file", undef, "/dev/null", "plain");
2469 } elsif ($status eq "M") {
2470 git_diff_print($from_id, "a/$file", $to_id, "b/$file", "plain");
2476 if (!defined $hash_base) {
2477 $hash_base = git_get_head_hash($project);
2480 my %co = parse_commit($hash_base);
2482 die_error(undef, "Unknown commit object");
2484 my $refs = git_get_references();
2486 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base);
2487 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2488 if (!defined $hash && defined $file_name) {
2489 $hash = git_get_hash_by_path($hash_base, $file_name);
2491 if (defined $hash) {
2492 $ftype = git_get_type($hash);
2494 git_print_page_path($file_name, $ftype);
2497 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2498 git_history_body($fd, $refs, $hash_base, $ftype);
2505 if (!defined $searchtext) {
2506 die_error(undef, "Text field empty");
2508 if (!defined $hash) {
2509 $hash = git_get_head_hash($project);
2511 my %co = parse_commit($hash);
2513 die_error(undef, "Unknown commit object");
2515 # pickaxe may take all resources of your box and run for several minutes
2516 # with every query - so decide by yourself how public you make this feature :)
2517 my $commit_search = 1;
2518 my $author_search = 0;
2519 my $committer_search = 0;
2520 my $pickaxe_search = 0;
2521 if ($searchtext =~ s/^author\\://i) {
2523 } elsif ($searchtext =~ s/^committer\\://i) {
2524 $committer_search = 1;
2525 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2527 $pickaxe_search = 1;
2530 git_print_page_nav('','', $hash,$co{'tree'},$hash);
2531 git_print_header_div('commit', esc_html($co{'title'}), $hash);
2533 print "<table cellspacing=\"0\">\n";
2535 if ($commit_search) {
2537 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2538 while (my $commit_text = <$fd>) {
2539 if (!grep m/$searchtext/i, $commit_text) {
2542 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2545 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2548 my @commit_lines = split "\n", $commit_text;
2549 my %co = parse_commit(undef, \@commit_lines);
2554 print "<tr class=\"dark\">\n";
2556 print "<tr class=\"light\">\n";
2559 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2560 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2562 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" . esc_html(chop_str($co{'title'}, 50)) . "</b><br/>");
2563 my $comment = $co{'comment'};
2564 foreach my $line (@$comment) {
2565 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2566 my $lead = esc_html($1) || "";
2567 $lead = chop_str($lead, 30, 10);
2568 my $match = esc_html($2) || "";
2569 my $trail = esc_html($3) || "";
2570 $trail = chop_str($trail, 30, 10);
2571 my $text = "$lead<span class=\"match\">$match</span>$trail";
2572 print chop_str($text, 80, 5) . "<br/>\n";
2576 "<td class=\"link\">" .
2577 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2578 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2585 if ($pickaxe_search) {
2587 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2590 while (my $line = <$fd>) {
2591 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2594 $set{'from_id'} = $3;
2596 $set{'id'} = $set{'to_id'};
2597 if ($set{'id'} =~ m/0{40}/) {
2598 $set{'id'} = $set{'from_id'};
2600 if ($set{'id'} =~ m/0{40}/) {
2604 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2607 print "<tr class=\"dark\">\n";
2609 print "<tr class=\"light\">\n";
2612 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2613 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2615 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2616 esc_html(chop_str($co{'title'}, 50)) . "</b><br/>");
2617 while (my $setref = shift @files) {
2619 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2620 "<span class=\"match\">" . esc_html($set{'file'}) . "</span>") .
2624 "<td class=\"link\">" .
2625 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2626 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2630 %co = parse_commit($1);
2640 my $head = git_get_head_hash($project);
2641 if (!defined $hash) {
2644 if (!defined $page) {
2647 my $refs = git_get_references();
2649 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2650 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2651 or die_error(undef, "Open git-rev-list failed");
2652 my @revlist = map { chomp; $_ } <$fd>;
2655 my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, $#revlist);
2657 if ($#revlist >= (100 * ($page+1)-1)) {
2659 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)),
2660 -title => "Alt-n"}, "next");
2665 git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);
2666 git_print_header_div('summary', $project);
2668 git_shortlog_body(\@revlist, ($page * 100), $#revlist, $refs, $next_link);
2673 ## ......................................................................
2674 ## feeds (RSS, OPML)
2677 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
2678 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash($project)
2679 or die_error(undef, "Open git-rev-list failed");
2680 my @revlist = map { chomp; $_ } <$fd>;
2681 close $fd or die_error(undef, "Reading git-rev-list failed");
2682 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
2683 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2684 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
2685 print "<channel>\n";
2686 print "<title>$project</title>\n".
2687 "<link>" . esc_html("$my_url?p=$project;a=summary") . "</link>\n".
2688 "<description>$project log</description>\n".
2689 "<language>en</language>\n";
2691 for (my $i = 0; $i <= $#revlist; $i++) {
2692 my $commit = $revlist[$i];
2693 my %co = parse_commit($commit);
2694 # we read 150, we always show 30 and the ones more recent than 48 hours
2695 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
2698 my %cd = parse_date($co{'committer_epoch'});
2699 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
2700 my @difftree = map { chomp; $_ } <$fd>;
2704 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) .
2706 "<author>" . esc_html($co{'author'}) . "</author>\n" .
2707 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
2708 "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
2709 "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
2710 "<description>" . esc_html($co{'title'}) . "</description>\n" .
2711 "<content:encoded>" .
2713 my $comment = $co{'comment'};
2714 foreach my $line (@$comment) {
2715 $line = decode("utf8", $line, Encode::FB_DEFAULT);
2716 print "$line<br/>\n";
2719 foreach my $line (@difftree) {
2720 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2723 my $file = validate_input(unquote($7));
2724 $file = decode("utf8", $file, Encode::FB_DEFAULT);
2725 print "$file<br/>\n";
2728 "</content:encoded>\n" .
2731 print "</channel></rss>";
2735 my @list = git_get_projects_list();
2737 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
2738 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2739 "<opml version=\"1.0\">\n".
2741 " <title>$site_name Git OPML Export</title>\n".
2744 "<outline text=\"git RSS feeds\">\n";
2746 foreach my $pr (@list) {
2748 my $head = git_get_head_hash($proj{'path'});
2749 if (!defined $head) {
2752 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
2753 my %co = parse_commit($head);
2758 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
2759 my $rss = "$my_url?p=$proj{'path'};a=rss";
2760 my $html = "$my_url?p=$proj{'path'};a=summary";
2761 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
2763 print "</outline>\n".