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 # location for temporary files needed for diffs
35 our $git_temp = "/tmp/gitweb";
37 # target of the home link on top of all pages
38 our $home_link = $my_uri || "/";
40 # string of the home link on top of all pages
41 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
43 # name of your site or organization to appear in page titles
44 # replace this with something more descriptive for clearer bookmarks
45 our $site_name = "++GITWEB_SITENAME++" || $ENV{'SERVER_NAME'} || "Untitled";
47 # html text to include at home page
48 our $home_text = "++GITWEB_HOMETEXT++";
50 # URI of default stylesheet
51 our $stylesheet = "++GITWEB_CSS++";
53 our $logo = "++GITWEB_LOGO++";
55 # source of projects list
56 our $projects_list = "++GITWEB_LIST++";
58 # list of git base URLs used for URL to where fetch project from,
59 # i.e. full URL is "$git_base_url/$project"
60 our @git_base_url_list = ("++GITWEB_BASE_URL++");
62 # default blob_plain mimetype and default charset for text/plain blob
63 our $default_blob_plain_mimetype = 'text/plain';
64 our $default_text_plain_charset = undef;
66 # file to use for guessing MIME types before trying /etc/mime.types
67 # (relative to the current git repository)
68 our $mimetypes_file = undef;
70 # You define site-wide feature defaults here; override them with
71 # $GITWEB_CONFIG as necessary.
73 # feature => {'sub' => feature-sub, 'override' => allow-override, 'default' => [ default options...]
74 # if feature is overridable, feature-sub will be called with default options;
75 # return value indicates if to enable specified feature
78 'sub' => \&feature_blame,
83 'sub' => \&feature_snapshot,
85 # => [content-encoding, suffix, program]
86 'default' => ['x-gzip', 'gz', 'gzip']},
89 sub gitweb_check_feature {
91 return undef unless exists $feature{$name};
92 my ($sub, $override, @defaults) = (
93 $feature{$name}{'sub'},
94 $feature{$name}{'override'},
95 @{$feature{$name}{'default'}});
96 if (!$override) { return @defaults; }
97 return $sub->(@defaults);
100 # To enable system wide have in $GITWEB_CONFIG
101 # $feature{'blame'}{'default'} = [1];
102 # To have project specific config enable override in $GITWEB_CONFIG
103 # $feature{'blame'}{'override'} = 1;
104 # and in project config gitweb.blame = 0|1;
107 my ($val) = git_get_project_config('blame', '--bool');
109 if ($val eq 'true') {
111 } elsif ($val eq 'false') {
118 # To disable system wide have in $GITWEB_CONFIG
119 # $feature{'snapshot'}{'default'} = [undef];
120 # To have project specific config enable override in $GITWEB_CONFIG
121 # $feature{'blame'}{'override'} = 1;
122 # and in project config gitweb.snapshot = none|gzip|bzip2
124 sub feature_snapshot {
125 my ($ctype, $suffix, $command) = @_;
127 my ($val) = git_get_project_config('snapshot');
129 if ($val eq 'gzip') {
130 return ('x-gzip', 'gz', 'gzip');
131 } elsif ($val eq 'bzip2') {
132 return ('x-bzip2', 'bz2', 'bzip2');
133 } elsif ($val eq 'none') {
137 return ($ctype, $suffix, $command);
140 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
141 require $GITWEB_CONFIG if -e $GITWEB_CONFIG;
143 # version of the core git binary
144 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
146 $projects_list ||= $projectroot;
147 if (! -d $git_temp) {
148 mkdir($git_temp, 0700) || die_error(undef, "Couldn't mkdir $git_temp");
151 # ======================================================================
152 # input validation and dispatch
153 our $action = $cgi->param('a');
154 if (defined $action) {
155 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
156 die_error(undef, "Invalid action parameter");
160 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
161 if (defined $project) {
164 $project = undef unless $project;
166 if (defined $project) {
167 if (!validate_input($project)) {
168 die_error(undef, "Invalid project parameter");
170 if (!(-d "$projectroot/$project")) {
171 die_error(undef, "No such directory");
173 if (!(-e "$projectroot/$project/HEAD")) {
174 die_error(undef, "No such project");
176 $ENV{'GIT_DIR'} = "$projectroot/$project";
179 our $file_name = $cgi->param('f');
180 if (defined $file_name) {
181 if (!validate_input($file_name)) {
182 die_error(undef, "Invalid file parameter");
186 our $file_parent = $cgi->param('fp');
187 if (defined $file_parent) {
188 if (!validate_input($file_parent)) {
189 die_error(undef, "Invalid file parent parameter");
193 our $hash = $cgi->param('h');
195 if (!validate_input($hash)) {
196 die_error(undef, "Invalid hash parameter");
200 our $hash_parent = $cgi->param('hp');
201 if (defined $hash_parent) {
202 if (!validate_input($hash_parent)) {
203 die_error(undef, "Invalid hash parent parameter");
207 our $hash_base = $cgi->param('hb');
208 if (defined $hash_base) {
209 if (!validate_input($hash_base)) {
210 die_error(undef, "Invalid hash base parameter");
214 our $page = $cgi->param('pg');
216 if ($page =~ m/[^0-9]$/) {
217 die_error(undef, "Invalid page parameter");
221 our $searchtext = $cgi->param('s');
222 if (defined $searchtext) {
223 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) {
224 die_error(undef, "Invalid search parameter");
226 $searchtext = quotemeta $searchtext;
231 "blame" => \&git_blame2,
232 "blobdiff" => \&git_blobdiff,
233 "blobdiff_plain" => \&git_blobdiff_plain,
234 "blob" => \&git_blob,
235 "blob_plain" => \&git_blob_plain,
236 "commitdiff" => \&git_commitdiff,
237 "commitdiff_plain" => \&git_commitdiff_plain,
238 "commit" => \&git_commit,
239 "heads" => \&git_heads,
240 "history" => \&git_history,
243 "search" => \&git_search,
244 "shortlog" => \&git_shortlog,
245 "summary" => \&git_summary,
247 "tags" => \&git_tags,
248 "tree" => \&git_tree,
249 "snapshot" => \&git_snapshot,
250 # those below don't need $project
251 "opml" => \&git_opml,
252 "project_list" => \&git_project_list,
255 if (defined $project) {
256 $action ||= 'summary';
258 $action ||= 'project_list';
260 if (!defined($actions{$action})) {
261 die_error(undef, "Unknown action");
263 $actions{$action}->();
266 ## ======================================================================
283 my %mapping = @mapping;
285 $params{"project"} ||= $project;
288 for (my $i = 0; $i < @mapping; $i += 2) {
289 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
290 if (defined $params{$name}) {
291 push @result, $symbol . "=" . esc_param($params{$name});
294 return "$my_uri?" . join(';', @result);
298 ## ======================================================================
299 ## validation, quoting/unquoting and escaping
304 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
307 if ($input =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
310 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\-\+\#\~\%]/) {
316 # quote unsafe chars, but keep the slash, even when it's not
317 # correct, but quoted slashes look too horrible in bookmarks
320 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
326 # replace invalid utf8 character with SUBSTITUTION sequence
329 $str = decode("utf8", $str, Encode::FB_DEFAULT);
330 $str = escapeHTML($str);
331 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
335 # git may return quoted and escaped filenames
338 if ($str =~ m/^"(.*)"$/) {
340 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
345 # escape tabs (convert tabs to spaces)
349 while ((my $pos = index($line, "\t")) != -1) {
350 if (my $count = (8 - ($pos % 8))) {
351 my $spaces = ' ' x $count;
352 $line =~ s/\t/$spaces/;
359 ## ----------------------------------------------------------------------
360 ## HTML aware string manipulation
365 my $add_len = shift || 10;
367 # allow only $len chars, but don't cut a word if it would fit in $add_len
368 # if it doesn't fit, cut it if it's still longer than the dots we would add
369 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
372 if (length($tail) > 4) {
374 $body =~ s/&[^;]*$//; # remove chopped character entities
379 ## ----------------------------------------------------------------------
380 ## functions returning short strings
382 # CSS class for given age value (in seconds)
386 if ($age < 60*60*2) {
388 } elsif ($age < 60*60*24*2) {
395 # convert age in seconds to "nn units ago" string
400 if ($age > 60*60*24*365*2) {
401 $age_str = (int $age/60/60/24/365);
402 $age_str .= " years ago";
403 } elsif ($age > 60*60*24*(365/12)*2) {
404 $age_str = int $age/60/60/24/(365/12);
405 $age_str .= " months ago";
406 } elsif ($age > 60*60*24*7*2) {
407 $age_str = int $age/60/60/24/7;
408 $age_str .= " weeks ago";
409 } elsif ($age > 60*60*24*2) {
410 $age_str = int $age/60/60/24;
411 $age_str .= " days ago";
412 } elsif ($age > 60*60*2) {
413 $age_str = int $age/60/60;
414 $age_str .= " hours ago";
415 } elsif ($age > 60*2) {
416 $age_str = int $age/60;
417 $age_str .= " min ago";
420 $age_str .= " sec ago";
422 $age_str .= " right now";
427 # convert file mode in octal to symbolic file mode string
429 my $mode = oct shift;
431 if (S_ISDIR($mode & S_IFMT)) {
433 } elsif (S_ISLNK($mode)) {
435 } elsif (S_ISREG($mode)) {
436 # git cares only about the executable bit
437 if ($mode & S_IXUSR) {
447 # convert file mode in octal to file type string
449 my $mode = oct shift;
451 if (S_ISDIR($mode & S_IFMT)) {
453 } elsif (S_ISLNK($mode)) {
455 } elsif (S_ISREG($mode)) {
462 ## ----------------------------------------------------------------------
463 ## functions returning short HTML fragments, or transforming HTML fragments
464 ## which don't beling to other sections
466 # format line of commit message or tag comment
467 sub format_log_line_html {
470 $line = esc_html($line);
471 $line =~ s/ / /g;
472 if ($line =~ m/([0-9a-fA-F]{40})/) {
474 if (git_get_type($hash_text) eq "commit") {
476 $cgi->a({-href => href(action=>"commit", hash=>$hash_text),
477 -class => "text"}, $hash_text);
478 $line =~ s/$hash_text/$link/;
484 # format marker of refs pointing to given object
485 sub format_ref_marker {
486 my ($refs, $id) = @_;
489 if (defined $refs->{$id}) {
490 foreach my $ref (@{$refs->{$id}}) {
491 my ($type, $name) = qw();
492 # e.g. tags/v2.6.11 or heads/next
493 if ($ref =~ m!^(.*?)s?/(.*)$!) {
501 $markers .= " <span class=\"$type\">" . esc_html($name) . "</span>";
506 return ' <span class="refs">'. $markers . '</span>';
512 # format, perhaps shortened and with markers, title line
513 sub format_subject_html {
514 my ($long, $short, $href, $extra) = @_;
515 $extra = '' unless defined($extra);
517 if (length($short) < length($long)) {
518 return $cgi->a({-href => $href, -class => "list subject",
520 esc_html($short) . $extra);
522 return $cgi->a({-href => $href, -class => "list subject"},
523 esc_html($long) . $extra);
527 sub format_diff_line {
529 my $char = substr($line, 0, 1);
535 $diff_class = " add";
536 } elsif ($char eq "-") {
537 $diff_class = " rem";
538 } elsif ($char eq "@") {
539 $diff_class = " chunk_header";
540 } elsif ($char eq "\\") {
541 $diff_class = " incomplete";
543 $line = untabify($line);
544 return "<div class=\"diff$diff_class\">" . esc_html($line) . "</div>\n";
547 ## ----------------------------------------------------------------------
548 ## git utility subroutines, invoking git commands
550 # get HEAD ref of given project as hash
551 sub git_get_head_hash {
553 my $oENV = $ENV{'GIT_DIR'};
555 $ENV{'GIT_DIR'} = "$projectroot/$project";
556 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
559 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
564 $ENV{'GIT_DIR'} = $oENV;
569 # get type of given object
573 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
580 sub git_get_project_config {
581 my ($key, $type) = @_;
583 return unless ($key);
584 $key =~ s/^gitweb\.//;
585 return if ($key =~ m/\W/);
587 my @x = ($GIT, 'repo-config');
588 if (defined $type) { push @x, $type; }
590 push @x, "gitweb.$key";
596 # get hash of given path at given ref
597 sub git_get_hash_by_path {
599 my $path = shift || return undef;
603 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
604 or die_error(undef, "Open git-ls-tree failed");
606 close $fd or return undef;
608 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
609 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
613 ## ......................................................................
614 ## git utility functions, directly accessing git repository
616 # assumes that PATH is not symref
617 sub git_get_hash_by_ref {
620 open my $fd, "$projectroot/$path" or return undef;
624 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
629 sub git_get_project_description {
632 open my $fd, "$projectroot/$path/description" or return undef;
639 sub git_get_project_url_list {
642 open my $fd, "$projectroot/$path/cloneurl" or return undef;
643 my @git_project_url_list = map { chomp; $_ } <$fd>;
646 return wantarray ? @git_project_url_list : \@git_project_url_list;
649 sub git_get_projects_list {
652 if (-d $projects_list) {
653 # search in directory
654 my $dir = $projects_list;
655 opendir my ($dh), $dir or return undef;
656 while (my $dir = readdir($dh)) {
657 if (-e "$projectroot/$dir/HEAD") {
665 } elsif (-f $projects_list) {
666 # read from file(url-encoded):
667 # 'git%2Fgit.git Linus+Torvalds'
668 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
669 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
670 open my ($fd), $projects_list or return undef;
671 while (my $line = <$fd>) {
673 my ($path, $owner) = split ' ', $line;
674 $path = unescape($path);
675 $owner = unescape($owner);
676 if (!defined $path) {
679 if (-e "$projectroot/$path/HEAD") {
682 owner => decode("utf8", $owner, Encode::FB_DEFAULT),
689 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
693 sub git_get_project_owner {
697 return undef unless $project;
699 # read from file (url-encoded):
700 # 'git%2Fgit.git Linus+Torvalds'
701 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
702 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
703 if (-f $projects_list) {
704 open (my $fd , $projects_list);
705 while (my $line = <$fd>) {
707 my ($pr, $ow) = split ' ', $line;
710 if ($pr eq $project) {
711 $owner = decode("utf8", $ow, Encode::FB_DEFAULT);
717 if (!defined $owner) {
718 $owner = get_file_owner("$projectroot/$project");
724 sub git_get_references {
725 my $type = shift || "";
728 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
729 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
730 if (-f "$projectroot/$project/info/refs") {
731 open $fd, "$projectroot/$project/info/refs"
734 open $fd, "-|", $GIT, "ls-remote", "."
738 while (my $line = <$fd>) {
740 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?[^\^]+)/) {
741 if (defined $refs{$1}) {
742 push @{$refs{$1}}, $2;
752 sub git_get_following_references {
753 my $hash = shift || return undef;
755 my $base = shift || $hash_base || "HEAD";
757 my $refs = git_get_references($type);
758 open my $fd, "-|", $GIT, "rev-list", $base
760 my @commits = map { chomp; $_ } <$fd>;
767 foreach my $commit (@commits) {
768 foreach my $ref (@{$refs->{$commit}}) {
770 push @reflist, $lastref;
772 if ($commit eq $hash) {
777 return wantarray ? @reflist : $lastref;
780 sub git_get_preceding_references {
781 my $hash = shift || return undef;
784 my $refs = git_get_references($type);
785 open my $fd, "-|", $GIT, "rev-list", $hash
787 my @commits = map { chomp; $_ } <$fd>;
794 foreach my $commit (@commits) {
795 foreach my $ref (@{$refs->{$commit}}) {
796 $firstref = $ref unless $firstref;
801 return wantarray ? @reflist : $firstref;
804 ## ----------------------------------------------------------------------
805 ## parse to hash functions
809 my $tz = shift || "-0000";
812 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
813 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
814 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
815 $date{'hour'} = $hour;
816 $date{'minute'} = $min;
817 $date{'mday'} = $mday;
818 $date{'day'} = $days[$wday];
819 $date{'month'} = $months[$mon];
820 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
821 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
822 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
823 $mday, $months[$mon], $hour ,$min;
825 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
826 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
827 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
828 $date{'hour_local'} = $hour;
829 $date{'minute_local'} = $min;
830 $date{'tz_local'} = $tz;
839 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
840 $tag{'id'} = $tag_id;
841 while (my $line = <$fd>) {
843 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
845 } elsif ($line =~ m/^type (.+)$/) {
847 } elsif ($line =~ m/^tag (.+)$/) {
849 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
853 } elsif ($line =~ m/--BEGIN/) {
854 push @comment, $line;
856 } elsif ($line eq "") {
860 push @comment, <$fd>;
861 $tag{'comment'} = \@comment;
863 if (!defined $tag{'name'}) {
870 my $commit_id = shift;
871 my $commit_text = shift;
876 if (defined $commit_text) {
877 @commit_lines = @$commit_text;
880 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id
882 @commit_lines = split '\n', <$fd>;
887 my $header = shift @commit_lines;
888 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
891 ($co{'id'}, my @parents) = split ' ', $header;
892 $co{'parents'} = \@parents;
893 $co{'parent'} = $parents[0];
894 while (my $line = shift @commit_lines) {
895 last if $line eq "\n";
896 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
898 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
900 $co{'author_epoch'} = $2;
901 $co{'author_tz'} = $3;
902 if ($co{'author'} =~ m/^([^<]+) </) {
903 $co{'author_name'} = $1;
905 $co{'author_name'} = $co{'author'};
907 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
908 $co{'committer'} = $1;
909 $co{'committer_epoch'} = $2;
910 $co{'committer_tz'} = $3;
911 $co{'committer_name'} = $co{'committer'};
912 $co{'committer_name'} =~ s/ <.*//;
915 if (!defined $co{'tree'}) {
919 foreach my $title (@commit_lines) {
922 $co{'title'} = chop_str($title, 80, 5);
923 # remove leading stuff of merges to make the interesting part visible
924 if (length($title) > 50) {
925 $title =~ s/^Automatic //;
926 $title =~ s/^merge (of|with) /Merge ... /i;
927 if (length($title) > 50) {
928 $title =~ s/(http|rsync):\/\///;
930 if (length($title) > 50) {
931 $title =~ s/(master|www|rsync)\.//;
933 if (length($title) > 50) {
934 $title =~ s/kernel.org:?//;
936 if (length($title) > 50) {
937 $title =~ s/\/pub\/scm//;
940 $co{'title_short'} = chop_str($title, 50, 5);
944 # remove added spaces
945 foreach my $line (@commit_lines) {
948 $co{'comment'} = \@commit_lines;
950 my $age = time - $co{'committer_epoch'};
952 $co{'age_string'} = age_string($age);
953 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
954 if ($age > 60*60*24*7*2) {
955 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
956 $co{'age_string_age'} = $co{'age_string'};
958 $co{'age_string_date'} = $co{'age_string'};
959 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
964 # parse ref from ref_file, given by ref_id, with given type
966 my $ref_file = shift;
968 my $type = shift || git_get_type($ref_id);
971 $ref_item{'type'} = $type;
972 $ref_item{'id'} = $ref_id;
973 $ref_item{'epoch'} = 0;
974 $ref_item{'age'} = "unknown";
975 if ($type eq "tag") {
976 my %tag = parse_tag($ref_id);
977 $ref_item{'comment'} = $tag{'comment'};
978 if ($tag{'type'} eq "commit") {
979 my %co = parse_commit($tag{'object'});
980 $ref_item{'epoch'} = $co{'committer_epoch'};
981 $ref_item{'age'} = $co{'age_string'};
982 } elsif (defined($tag{'epoch'})) {
983 my $age = time - $tag{'epoch'};
984 $ref_item{'epoch'} = $tag{'epoch'};
985 $ref_item{'age'} = age_string($age);
987 $ref_item{'reftype'} = $tag{'type'};
988 $ref_item{'name'} = $tag{'name'};
989 $ref_item{'refid'} = $tag{'object'};
990 } elsif ($type eq "commit"){
991 my %co = parse_commit($ref_id);
992 $ref_item{'reftype'} = "commit";
993 $ref_item{'name'} = $ref_file;
994 $ref_item{'title'} = $co{'title'};
995 $ref_item{'refid'} = $ref_id;
996 $ref_item{'epoch'} = $co{'committer_epoch'};
997 $ref_item{'age'} = $co{'age_string'};
999 $ref_item{'reftype'} = $type;
1000 $ref_item{'name'} = $ref_file;
1001 $ref_item{'refid'} = $ref_id;
1007 # parse line of git-diff-tree "raw" output
1008 sub parse_difftree_raw_line {
1012 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1013 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1014 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1015 $res{'from_mode'} = $1;
1016 $res{'to_mode'} = $2;
1017 $res{'from_id'} = $3;
1019 $res{'status'} = $5;
1020 $res{'similarity'} = $6;
1021 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1022 ($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
1024 $res{'file'} = unquote($7);
1027 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1028 #elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1029 # $res{'commit'} = $1;
1032 return wantarray ? %res : \%res;
1035 ## ......................................................................
1036 ## parse to array of hashes functions
1038 sub git_get_refs_list {
1039 my $ref_dir = shift;
1043 my $pfxlen = length("$projectroot/$project/$ref_dir");
1044 File::Find::find(sub {
1047 push @refs, substr($File::Find::name, $pfxlen + 1);
1049 }, "$projectroot/$project/$ref_dir");
1051 foreach my $ref_file (@refs) {
1052 my $ref_id = git_get_hash_by_ref("$project/$ref_dir/$ref_file");
1053 my $type = git_get_type($ref_id) || next;
1054 my %ref_item = parse_ref($ref_file, $ref_id, $type);
1056 push @reflist, \%ref_item;
1059 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1063 ## ----------------------------------------------------------------------
1064 ## filesystem-related functions
1066 sub get_file_owner {
1069 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1070 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1071 if (!defined $gcos) {
1075 $owner =~ s/[,;].*$//;
1076 return decode("utf8", $owner, Encode::FB_DEFAULT);
1079 ## ......................................................................
1080 ## mimetype related functions
1082 sub mimetype_guess_file {
1083 my $filename = shift;
1084 my $mimemap = shift;
1085 -r $mimemap or return undef;
1088 open(MIME, $mimemap) or return undef;
1090 next if m/^#/; # skip comments
1091 my ($mime, $exts) = split(/\t+/);
1092 if (defined $exts) {
1093 my @exts = split(/\s+/, $exts);
1094 foreach my $ext (@exts) {
1095 $mimemap{$ext} = $mime;
1101 $filename =~ /\.(.*?)$/;
1102 return $mimemap{$1};
1105 sub mimetype_guess {
1106 my $filename = shift;
1108 $filename =~ /\./ or return undef;
1110 if ($mimetypes_file) {
1111 my $file = $mimetypes_file;
1112 if ($file !~ m!^/!) { # if it is relative path
1113 # it is relative to project
1114 $file = "$projectroot/$project/$file";
1116 $mime = mimetype_guess_file($filename, $file);
1118 $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
1124 my $filename = shift;
1127 my $mime = mimetype_guess($filename);
1128 $mime and return $mime;
1132 return $default_blob_plain_mimetype unless $fd;
1135 return 'text/plain' .
1136 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1137 } elsif (! $filename) {
1138 return 'application/octet-stream';
1139 } elsif ($filename =~ m/\.png$/i) {
1141 } elsif ($filename =~ m/\.gif$/i) {
1143 } elsif ($filename =~ m/\.jpe?g$/i) {
1144 return 'image/jpeg';
1146 return 'application/octet-stream';
1150 ## ======================================================================
1151 ## functions printing HTML: header, footer, error page
1153 sub git_header_html {
1154 my $status = shift || "200 OK";
1155 my $expires = shift;
1157 my $title = "$site_name git";
1158 if (defined $project) {
1159 $title .= " - $project";
1160 if (defined $action) {
1161 $title .= "/$action";
1162 if (defined $file_name) {
1163 $title .= " - $file_name";
1164 if ($action eq "tree" && $file_name !~ m|/$|) {
1171 # require explicit support from the UA if we are to send the page as
1172 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1173 # we have to do this because MSIE sometimes globs '*/*', pretending to
1174 # support xhtml+xml but choking when it gets what it asked for.
1175 if (defined $cgi->http('HTTP_ACCEPT') &&
1176 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&
1177 $cgi->Accept('application/xhtml+xml') != 0) {
1178 $content_type = 'application/xhtml+xml';
1180 $content_type = 'text/html';
1182 print $cgi->header(-type=>$content_type, -charset => 'utf-8',
1183 -status=> $status, -expires => $expires);
1185 <?xml version="1.0" encoding="utf-8"?>
1186 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1187 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1188 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1189 <!-- git core binaries version $git_version -->
1191 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1192 <meta name="generator" content="gitweb/$version git/$git_version"/>
1193 <meta name="robots" content="index, nofollow"/>
1194 <title>$title</title>
1195 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1197 if (defined $project) {
1198 printf('<link rel="alternate" title="%s log" '.
1199 'href="%s" type="application/rss+xml"/>'."\n",
1200 esc_param($project), href(action=>"rss"));
1205 "<div class=\"page_header\">\n" .
1206 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1207 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1209 print $cgi->a({-href => esc_param($home_link)}, $home_link_str) . " / ";
1210 if (defined $project) {
1211 print $cgi->a({-href => href(action=>"summary")}, esc_html($project));
1212 if (defined $action) {
1216 if (!defined $searchtext) {
1220 if (defined $hash_base) {
1221 $search_hash = $hash_base;
1222 } elsif (defined $hash) {
1223 $search_hash = $hash;
1225 $search_hash = "HEAD";
1227 $cgi->param("a", "search");
1228 $cgi->param("h", $search_hash);
1229 print $cgi->startform(-method => "get", -action => $my_uri) .
1230 "<div class=\"search\">\n" .
1231 $cgi->hidden(-name => "p") . "\n" .
1232 $cgi->hidden(-name => "a") . "\n" .
1233 $cgi->hidden(-name => "h") . "\n" .
1234 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
1236 $cgi->end_form() . "\n";
1241 sub git_footer_html {
1242 print "<div class=\"page_footer\">\n";
1243 if (defined $project) {
1244 my $descr = git_get_project_description($project);
1245 if (defined $descr) {
1246 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
1248 print $cgi->a({-href => href(action=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1250 print $cgi->a({-href => href(action=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1258 my $status = shift || "403 Forbidden";
1259 my $error = shift || "Malformed query, file missing or permission denied";
1261 git_header_html($status);
1263 <div class="page_body">
1273 ## ----------------------------------------------------------------------
1274 ## functions printing or outputting HTML: navigation
1276 sub git_print_page_nav {
1277 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1278 $extra = '' if !defined $extra; # pager or formats
1280 my @navs = qw(summary shortlog log commit commitdiff tree);
1282 @navs = grep { $_ ne $suppress } @navs;
1285 my %arg = map { $_ => {action=>$_} } @navs;
1286 if (defined $head) {
1287 for (qw(commit commitdiff)) {
1288 $arg{$_}{hash} = $head;
1290 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1291 for (qw(shortlog log)) {
1292 $arg{$_}{hash} = $head;
1296 $arg{tree}{hash} = $treehead if defined $treehead;
1297 $arg{tree}{hash_base} = $treebase if defined $treebase;
1299 print "<div class=\"page_nav\">\n" .
1301 map { $_ eq $current ?
1302 $_ : $cgi->a({-href => href(%{$arg{$_}})}, "$_")
1304 print "<br/>\n$extra<br/>\n" .
1308 sub format_paging_nav {
1309 my ($action, $hash, $head, $page, $nrevs) = @_;
1313 if ($hash ne $head || $page) {
1314 $paging_nav .= $cgi->a({-href => href(action=>$action)}, "HEAD");
1316 $paging_nav .= "HEAD";
1320 $paging_nav .= " ⋅ " .
1321 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page-1),
1322 -accesskey => "p", -title => "Alt-p"}, "prev");
1324 $paging_nav .= " ⋅ prev";
1327 if ($nrevs >= (100 * ($page+1)-1)) {
1328 $paging_nav .= " ⋅ " .
1329 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page+1),
1330 -accesskey => "n", -title => "Alt-n"}, "next");
1332 $paging_nav .= " ⋅ next";
1338 ## ......................................................................
1339 ## functions printing or outputting HTML: div
1341 sub git_print_header_div {
1342 my ($action, $title, $hash, $hash_base) = @_;
1345 $args{action} = $action;
1346 $args{hash} = $hash if $hash;
1347 $args{hash_base} = $hash_base if $hash_base;
1349 print "<div class=\"header\">\n" .
1350 $cgi->a({-href => href(%args), -class => "title"},
1351 $title ? $title : $action) .
1355 sub git_print_page_path {
1360 if (!defined $name) {
1361 print "<div class=\"page_path\">/</div>\n";
1362 } elsif (defined $type && $type eq 'blob') {
1363 print "<div class=\"page_path\">";
1365 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,
1369 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name)},
1372 print "<br/></div>\n";
1374 print "<div class=\"page_path\">" . esc_html($name) . "<br/></div>\n";
1381 # remove leading empty lines
1382 while (defined $log->[0] && $log->[0] eq "") {
1389 foreach my $line (@$log) {
1390 # print only one empty line
1391 # do not print empty line after signoff
1393 next if ($empty || $signoff);
1398 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1400 print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
1403 print format_log_line_html($line) . "<br/>\n";
1408 sub git_print_simplified_log {
1410 my $remove_title = shift;
1412 shift @$log if $remove_title;
1413 # remove leading empty lines
1414 while (defined $log->[0] && $log->[0] eq "") {
1418 # simplify and print log
1420 foreach my $line (@$log) {
1421 # remove signoff lines
1422 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1425 # print only one empty line
1432 print format_log_line_html($line) . "<br/>\n";
1434 # end with single empty line
1435 print "<br/>\n" unless $empty;
1438 ## ......................................................................
1439 ## functions printing large fragments of HTML
1441 sub git_difftree_body {
1442 my ($difftree, $hash, $parent) = @_;
1444 print "<div class=\"list_head\">\n";
1445 if ($#{$difftree} > 10) {
1446 print(($#{$difftree} + 1) . " files changed:\n");
1450 print "<table class=\"diff_tree\">\n";
1452 foreach my $line (@{$difftree}) {
1453 my %diff = parse_difftree_raw_line($line);
1456 print "<tr class=\"dark\">\n";
1458 print "<tr class=\"light\">\n";
1462 my ($to_mode_oct, $to_mode_str, $to_file_type);
1463 my ($from_mode_oct, $from_mode_str, $from_file_type);
1464 if ($diff{'to_mode'} ne ('0' x 6)) {
1465 $to_mode_oct = oct $diff{'to_mode'};
1466 if (S_ISREG($to_mode_oct)) { # only for regular file
1467 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1469 $to_file_type = file_type($diff{'to_mode'});
1471 if ($diff{'from_mode'} ne ('0' x 6)) {
1472 $from_mode_oct = oct $diff{'from_mode'};
1473 if (S_ISREG($to_mode_oct)) { # only for regular file
1474 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1476 $from_file_type = file_type($diff{'from_mode'});
1479 if ($diff{'status'} eq "A") { # created
1480 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1481 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1482 $mode_chng .= "]</span>";
1484 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1485 hash_base=>$hash, file_name=>$diff{'file'}),
1486 -class => "list"}, esc_html($diff{'file'})) .
1488 "<td>$mode_chng</td>\n" .
1489 "<td class=\"link\">" .
1490 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1491 hash_base=>$hash, file_name=>$diff{'file'})},
1495 } elsif ($diff{'status'} eq "D") { # deleted
1496 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1498 $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
1499 hash_base=>$parent, file_name=>$diff{'file'}),
1500 -class => "list"}, esc_html($diff{'file'})) .
1502 "<td>$mode_chng</td>\n" .
1503 "<td class=\"link\">" .
1504 $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
1505 hash_base=>$parent, file_name=>$diff{'file'})},
1508 $cgi->a({-href => href(action=>"history", hash_base=>$parent,
1509 file_name=>$diff{'file'})},\
1513 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1514 my $mode_chnge = "";
1515 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1516 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1517 if ($from_file_type != $to_file_type) {
1518 $mode_chnge .= " from $from_file_type to $to_file_type";
1520 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1521 if ($from_mode_str && $to_mode_str) {
1522 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1523 } elsif ($to_mode_str) {
1524 $mode_chnge .= " mode: $to_mode_str";
1527 $mode_chnge .= "]</span>\n";
1530 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1531 print $cgi->a({-href => href(action=>"blobdiff", hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1532 hash_base=>$hash, file_name=>$diff{'file'}),
1533 -class => "list"}, esc_html($diff{'file'}));
1534 } else { # only mode changed
1535 print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1536 hash_base=>$hash, file_name=>$diff{'file'}),
1537 -class => "list"}, esc_html($diff{'file'}));
1540 "<td>$mode_chnge</td>\n" .
1541 "<td class=\"link\">" .
1542 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1543 hash_base=>$hash, file_name=>$diff{'file'})},
1545 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1547 $cgi->a({-href => href(action=>"blobdiff", hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1548 hash_base=>$hash, file_name=>$diff{'file'})},
1552 $cgi->a({-href => href(action=>"history",
1553 hash_base=>$hash, file_name=>$diff{'file'})},
1557 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1558 my %status_name = ('R' => 'moved', 'C' => 'copied');
1559 my $nstatus = $status_name{$diff{'status'}};
1561 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1562 # mode also for directories, so we cannot use $to_mode_str
1563 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1566 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1567 hash=>$diff{'to_id'}, file_name=>$diff{'to_file'}),
1568 -class => "list"}, esc_html($diff{'to_file'})) . "</td>\n" .
1569 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1570 $cgi->a({-href => href(action=>"blob", hash_base=>$parent,
1571 hash=>$diff{'from_id'}, file_name=>$diff{'from_file'}),
1572 -class => "list"}, esc_html($diff{'from_file'})) .
1573 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1574 "<td class=\"link\">" .
1575 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1576 hash=>$diff{'to_id'}, file_name=>$diff{'to_file'})},
1578 if ($diff{'to_id'} ne $diff{'from_id'}) {
1580 $cgi->a({-href => href(action=>"blobdiff", hash_base=>$hash,
1581 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1582 file_name=>$diff{'to_file'}, file_parent=>$diff{'from_file'})},
1587 } # we should not encounter Unmerged (U) or Unknown (X) status
1593 sub git_patchset_body {
1594 my ($fd, $difftree, $hash, $hash_parent) = @_;
1598 my $patch_found = 0;
1601 print "<div class=\"patchset\">\n";
1604 while (my $patch_line @$fd>) {
1607 if ($patch_line =~ m/^diff /) { # "git diff" header
1608 # beginning of patch (in patchset)
1610 # close previous patch
1611 print "</div>\n"; # class="patch"
1613 # first patch in patchset
1616 print "<div class=\"patch\">\n";
1618 %diffinfo = parse_difftree_raw_line($difftree->[$patch_idx++]);
1620 # for now, no extended header, hence we skip empty patches
1621 # companion to next LINE if $in_header;
1622 if ($diffinfo{'from_id'} eq $diffinfo{'to_id'}) { # no change
1627 if ($diffinfo{'status'} eq "A") { # added
1628 print "<div class=\"diff_info\">" . file_type($diffinfo{'to_mode'}) . ":" .
1629 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1630 hash=>$diffinfo{'to_id'}, file_name=>$diffinfo{'file'})},
1631 $diffinfo{'to_id'}) . "(new)" .
1632 "</div>\n"; # class="diff_info"
1634 } elsif ($diffinfo{'status'} eq "D") { # deleted
1635 print "<div class=\"diff_info\">" . file_type($diffinfo{'from_mode'}) . ":" .
1636 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1637 hash=>$diffinfo{'from_id'}, file_name=>$diffinfo{'file'})},
1638 $diffinfo{'from_id'}) . "(deleted)" .
1639 "</div>\n"; # class="diff_info"
1641 } elsif ($diffinfo{'status'} eq "R" || # renamed
1642 $diffinfo{'status'} eq "C") { # copied
1643 print "<div class=\"diff_info\">" .
1644 file_type($diffinfo{'from_mode'}) . ":" .
1645 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1646 hash=>$diffinfo{'from_id'}, file_name=>$diffinfo{'from_file'})},
1647 $diffinfo{'from_id'}) .
1649 file_type($diffinfo{'to_mode'}) . ":" .
1650 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1651 hash=>$diffinfo{'to_id'}, file_name=>$diffinfo{'to_file'})},
1652 $diffinfo{'to_id'});
1653 print "</div>\n"; # class="diff_info"
1655 } else { # modified, mode changed, ...
1656 print "<div class=\"diff_info\">" .
1657 file_type($diffinfo{'from_mode'}) . ":" .
1658 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1659 hash=>$diffinfo{'from_id'}, file_name=>$diffinfo{'file'})},
1660 $diffinfo{'from_id'}) .
1662 file_type($diffinfo{'to_mode'}) . ":" .
1663 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1664 hash=>$diffinfo{'to_id'}, file_name=>$diffinfo{'file'})},
1665 $diffinfo{'to_id'});
1666 print "</div>\n"; # class="diff_info"
1669 #print "<div class=\"diff extended_header\">\n";
1672 } # start of patch in patchset
1675 if ($in_header && $patch_line =~ m/^---/) {
1679 next LINE if $in_header;
1681 print format_diff_line($patch_line);
1683 print "</div>\n" if $patch_found; # class="patch"
1685 print "</div>\n"; # class="patchset"
1688 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1690 sub git_shortlog_body {
1691 # uses global variable $project
1692 my ($revlist, $from, $to, $refs, $extra) = @_;
1694 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
1695 my $have_snapshot = (defined $ctype && defined $suffix);
1697 $from = 0 unless defined $from;
1698 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1700 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1702 for (my $i = $from; $i <= $to; $i++) {
1703 my $commit = $revlist->[$i];
1704 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1705 my $ref = format_ref_marker($refs, $commit);
1706 my %co = parse_commit($commit);
1708 print "<tr class=\"dark\">\n";
1710 print "<tr class=\"light\">\n";
1713 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1714 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1715 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1717 print format_subject_html($co{'title'}, $co{'title_short'},
1718 href(action=>"commit", hash=>$commit), $ref);
1720 "<td class=\"link\">" .
1721 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
1722 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff");
1723 if ($have_snapshot) {
1724 print " | " . $cgi->a({-href => href(action=>"snapshot", hash=>$commit)}, "snapshot");
1729 if (defined $extra) {
1731 "<td colspan=\"4\">$extra</td>\n" .
1737 sub git_history_body {
1738 # Warning: assumes constant type (blob or tree) during history
1739 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1741 print "<table class=\"history\" cellspacing=\"0\">\n";
1743 while (my $line = <$fd>) {
1744 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1749 my %co = parse_commit($commit);
1754 my $ref = format_ref_marker($refs, $commit);
1757 print "<tr class=\"dark\">\n";
1759 print "<tr class=\"light\">\n";
1762 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1763 # shortlog uses chop_str($co{'author_name'}, 10)
1764 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1766 # originally git_history used chop_str($co{'title'}, 50)
1767 print format_subject_html($co{'title'}, $co{'title_short'},
1768 href(action=>"commit", hash=>$commit), $ref);
1770 "<td class=\"link\">" .
1771 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
1772 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
1773 $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype);
1775 if ($ftype eq 'blob') {
1776 my $blob_current = git_get_hash_by_path($hash_base, $file_name);
1777 my $blob_parent = git_get_hash_by_path($commit, $file_name);
1778 if (defined $blob_current && defined $blob_parent &&
1779 $blob_current ne $blob_parent) {
1781 $cgi->a({-href => href(action=>"blobdiff", hash=>$blob_current, hash_parent=>$blob_parent,
1782 hash_base=>$commit, file_name=>$file_name)},
1789 if (defined $extra) {
1791 "<td colspan=\"4\">$extra</td>\n" .
1798 # uses global variable $project
1799 my ($taglist, $from, $to, $extra) = @_;
1800 $from = 0 unless defined $from;
1801 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1803 print "<table class=\"tags\" cellspacing=\"0\">\n";
1805 for (my $i = $from; $i <= $to; $i++) {
1806 my $entry = $taglist->[$i];
1808 my $comment_lines = $tag{'comment'};
1809 my $comment = shift @$comment_lines;
1811 if (defined $comment) {
1812 $comment_short = chop_str($comment, 30, 5);
1815 print "<tr class=\"dark\">\n";
1817 print "<tr class=\"light\">\n";
1820 print "<td><i>$tag{'age'}</i></td>\n" .
1822 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),
1823 -class => "list name"}, esc_html($tag{'name'})) .
1826 if (defined $comment) {
1827 print format_subject_html($comment, $comment_short,
1828 href(action=>"tag", hash=>$tag{'id'}));
1831 "<td class=\"selflink\">";
1832 if ($tag{'type'} eq "tag") {
1833 print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag");
1838 "<td class=\"link\">" . " | " .
1839 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'});
1840 if ($tag{'reftype'} eq "commit") {
1841 print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") .
1842 " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'refid'})}, "log");
1843 } elsif ($tag{'reftype'} eq "blob") {
1844 print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw");
1849 if (defined $extra) {
1851 "<td colspan=\"5\">$extra</td>\n" .
1857 sub git_heads_body {
1858 # uses global variable $project
1859 my ($taglist, $head, $from, $to, $extra) = @_;
1860 $from = 0 unless defined $from;
1861 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1863 print "<table class=\"heads\" cellspacing=\"0\">\n";
1865 for (my $i = $from; $i <= $to; $i++) {
1866 my $entry = $taglist->[$i];
1868 my $curr = $tag{'id'} eq $head;
1870 print "<tr class=\"dark\">\n";
1872 print "<tr class=\"light\">\n";
1875 print "<td><i>$tag{'age'}</i></td>\n" .
1876 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
1877 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'}),
1878 -class => "list name"},esc_html($tag{'name'})) .
1880 "<td class=\"link\">" .
1881 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") . " | " .
1882 $cgi->a({-href => href(action=>"log", hash=>$tag{'name'})}, "log") .
1886 if (defined $extra) {
1888 "<td colspan=\"3\">$extra</td>\n" .
1894 ## ----------------------------------------------------------------------
1895 ## functions printing large fragments, format as one of arguments
1897 sub git_diff_print {
1899 my $from_name = shift;
1901 my $to_name = shift;
1902 my $format = shift || "html";
1904 my $from_tmp = "/dev/null";
1905 my $to_tmp = "/dev/null";
1908 # create tmp from-file
1909 if (defined $from) {
1910 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1911 open my $fd2, "> $from_tmp";
1912 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1919 # create tmp to-file
1921 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1922 open my $fd2, "> $to_tmp";
1923 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1930 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1931 if ($format eq "plain") {
1936 while (my $line = <$fd>) {
1938 my $char = substr($line, 0, 1);
1939 my $diff_class = "";
1941 $diff_class = " add";
1942 } elsif ($char eq "-") {
1943 $diff_class = " rem";
1944 } elsif ($char eq "@") {
1945 $diff_class = " chunk_header";
1946 } elsif ($char eq "\\") {
1950 $line = untabify($line);
1951 print "<div class=\"diff$diff_class\">" . esc_html($line) . "</div>\n";
1956 if (defined $from) {
1965 ## ======================================================================
1966 ## ======================================================================
1969 sub git_project_list {
1970 my $order = $cgi->param('o');
1971 if (defined $order && $order !~ m/project|descr|owner|age/) {
1972 die_error(undef, "Unknown order parameter");
1975 my @list = git_get_projects_list();
1978 die_error(undef, "No projects found");
1980 foreach my $pr (@list) {
1981 my $head = git_get_head_hash($pr->{'path'});
1982 if (!defined $head) {
1985 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1986 my %co = parse_commit($head);
1990 $pr->{'commit'} = \%co;
1991 if (!defined $pr->{'descr'}) {
1992 my $descr = git_get_project_description($pr->{'path'}) || "";
1993 $pr->{'descr'} = chop_str($descr, 25, 5);
1995 if (!defined $pr->{'owner'}) {
1996 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
1998 push @projects, $pr;
2002 if (-f $home_text) {
2003 print "<div class=\"index_include\">\n";
2004 open (my $fd, $home_text);
2009 print "<table class=\"project_list\">\n" .
2011 $order ||= "project";
2012 if ($order eq "project") {
2013 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2014 print "<th>Project</th>\n";
2017 $cgi->a({-href => "$my_uri?" . esc_param("o=project"),
2018 -class => "header"}, "Project") .
2021 if ($order eq "descr") {
2022 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2023 print "<th>Description</th>\n";
2026 $cgi->a({-href => "$my_uri?" . esc_param("o=descr"),
2027 -class => "header"}, "Description") .
2030 if ($order eq "owner") {
2031 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2032 print "<th>Owner</th>\n";
2035 $cgi->a({-href => "$my_uri?" . esc_param("o=owner"),
2036 -class => "header"}, "Owner") .
2039 if ($order eq "age") {
2040 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2041 print "<th>Last Change</th>\n";
2044 $cgi->a({-href => "$my_uri?" . esc_param("o=age"),
2045 -class => "header"}, "Last Change") .
2048 print "<th></th>\n" .
2051 foreach my $pr (@projects) {
2053 print "<tr class=\"dark\">\n";
2055 print "<tr class=\"light\">\n";
2058 print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
2059 -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
2060 "<td>" . esc_html($pr->{'descr'}) . "</td>\n" .
2061 "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
2062 print "<td class=\"". age_class($pr->{'commit'}{'age'}) . "\">" .
2063 $pr->{'commit'}{'age_string'} . "</td>\n" .
2064 "<td class=\"link\">" .
2065 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
2066 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
2067 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") .
2076 my $descr = git_get_project_description($project) || "none";
2077 my $head = git_get_head_hash($project);
2078 my %co = parse_commit($head);
2079 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
2081 my $owner = git_get_project_owner($project);
2083 my $refs = git_get_references();
2085 git_print_page_nav('summary','', $head);
2087 print "<div class=\"title\"> </div>\n";
2088 print "<table cellspacing=\"0\">\n" .
2089 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
2090 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2091 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2092 # use per project git URL list in $projectroot/$project/cloneurl
2093 # or make project git URL from git base URL and project name
2094 my $url_tag = "URL";
2095 my @url_list = git_get_project_url_list($project);
2096 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2097 foreach my $git_url (@url_list) {
2098 next unless $git_url;
2099 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2104 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash($project)
2105 or die_error(undef, "Open git-rev-list failed");
2106 my @revlist = map { chomp; $_ } <$fd>;
2108 git_print_header_div('shortlog');
2109 git_shortlog_body(\@revlist, 0, 15, $refs,
2110 $cgi->a({-href => href(action=>"shortlog")}, "..."));
2112 my $taglist = git_get_refs_list("refs/tags");
2113 if (defined @$taglist) {
2114 git_print_header_div('tags');
2115 git_tags_body($taglist, 0, 15,
2116 $cgi->a({-href => href(action=>"tags")}, "..."));
2119 my $headlist = git_get_refs_list("refs/heads");
2120 if (defined @$headlist) {
2121 git_print_header_div('heads');
2122 git_heads_body($headlist, $head, 0, 15,
2123 $cgi->a({-href => href(action=>"heads")}, "..."));
2130 my $head = git_get_head_hash($project);
2132 git_print_page_nav('','', $head,undef,$head);
2133 my %tag = parse_tag($hash);
2134 git_print_header_div('commit', esc_html($tag{'name'}), $hash);
2135 print "<div class=\"title_text\">\n" .
2136 "<table cellspacing=\"0\">\n" .
2138 "<td>object</td>\n" .
2139 "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
2140 $tag{'object'}) . "</td>\n" .
2141 "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
2142 $tag{'type'}) . "</td>\n" .
2144 if (defined($tag{'author'})) {
2145 my %ad = parse_date($tag{'epoch'}, $tag{'tz'});
2146 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
2147 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2148 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2151 print "</table>\n\n" .
2153 print "<div class=\"page_body\">";
2154 my $comment = $tag{'comment'};
2155 foreach my $line (@$comment) {
2156 print esc_html($line) . "<br/>\n";
2166 if (!gitweb_check_feature('blame')) {
2167 die_error('403 Permission denied', "Permission denied");
2169 die_error('404 Not Found', "File name not defined") if (!$file_name);
2170 $hash_base ||= git_get_head_hash($project);
2171 die_error(undef, "Couldn't find base commit") unless ($hash_base);
2172 my %co = parse_commit($hash_base)
2173 or die_error(undef, "Reading commit failed");
2174 if (!defined $hash) {
2175 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
2176 or die_error(undef, "Error looking up file");
2178 $ftype = git_get_type($hash);
2179 if ($ftype !~ "blob") {
2180 die_error("400 Bad Request", "Object is not a blob");
2182 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
2183 or die_error(undef, "Open git-blame failed");
2186 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2189 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
2191 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2192 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2193 git_print_page_path($file_name, $ftype, $hash_base);
2194 my @rev_color = (qw(light2 dark2));
2195 my $num_colors = scalar(@rev_color);
2196 my $current_color = 0;
2199 <div class="page_body">
2200 <table class="blame">
2201 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2204 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2206 my $rev = substr($full_rev, 0, 8);
2210 if (!defined $last_rev) {
2211 $last_rev = $full_rev;
2212 } elsif ($last_rev ne $full_rev) {
2213 $last_rev = $full_rev;
2214 $current_color = ++$current_color % $num_colors;
2216 print "<tr class=\"$rev_color[$current_color]\">\n";
2217 print "<td class=\"sha1\">" .
2218 $cgi->a({-href => href(action=>"commit", hash=>$full_rev, file_name=>$file_name)},
2219 esc_html($rev)) . "</td>\n";
2220 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2221 esc_html($lineno) . "</a></td>\n";
2222 print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
2228 or print "Reading blob failed\n";
2235 if (!gitweb_check_feature('blame')) {
2236 die_error('403 Permission denied', "Permission denied");
2238 die_error('404 Not Found', "File name not defined") if (!$file_name);
2239 $hash_base ||= git_get_head_hash($project);
2240 die_error(undef, "Couldn't find base commit") unless ($hash_base);
2241 my %co = parse_commit($hash_base)
2242 or die_error(undef, "Reading commit failed");
2243 if (!defined $hash) {
2244 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
2245 or die_error(undef, "Error lookup file");
2247 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2248 or die_error(undef, "Open git-annotate failed");
2251 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2254 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
2256 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2257 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2258 git_print_page_path($file_name, 'blob', $hash_base);
2259 print "<div class=\"page_body\">\n";
2261 <table class="blame">
2270 my @line_class = (qw(light dark));
2271 my $line_class_len = scalar (@line_class);
2272 my $line_class_num = $#line_class;
2273 while (my $line = <$fd>) {
2285 $line_class_num = ($line_class_num + 1) % $line_class_len;
2287 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
2294 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
2297 $short_rev = substr ($long_rev, 0, 8);
2298 $age = time () - $time;
2299 $age_str = age_string ($age);
2300 $age_str =~ s/ / /g;
2301 $age_class = age_class($age);
2302 $author = esc_html ($author);
2303 $author =~ s/ / /g;
2305 $data = untabify($data);
2306 $data = esc_html ($data);
2309 <tr class="$line_class[$line_class_num]">
2310 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2311 <td class="$age_class">$age_str</td>
2313 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2314 <td class="pre">$data</td>
2317 } # while (my $line = <$fd>)
2318 print "</table>\n\n";
2320 or print "Reading blob failed.\n";
2326 my $head = git_get_head_hash($project);
2328 git_print_page_nav('','', $head,undef,$head);
2329 git_print_header_div('summary', $project);
2331 my $taglist = git_get_refs_list("refs/tags");
2332 if (defined @$taglist) {
2333 git_tags_body($taglist);
2339 my $head = git_get_head_hash($project);
2341 git_print_page_nav('','', $head,undef,$head);
2342 git_print_header_div('summary', $project);
2344 my $taglist = git_get_refs_list("refs/heads");
2345 if (defined @$taglist) {
2346 git_heads_body($taglist, $head);
2351 sub git_blob_plain {
2352 if (!defined $hash) {
2353 if (defined $file_name) {
2354 my $base = $hash_base || git_get_head_hash($project);
2355 $hash = git_get_hash_by_path($base, $file_name, "blob")
2356 or die_error(undef, "Error lookup file");
2358 die_error(undef, "No file name defined");
2362 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2363 or die_error(undef, "Couldn't cat $file_name, $hash");
2365 $type ||= blob_mimetype($fd, $file_name);
2367 # save as filename, even when no $file_name is given
2368 my $save_as = "$hash";
2369 if (defined $file_name) {
2370 $save_as = $file_name;
2371 } elsif ($type =~ m/^text\//) {
2375 print $cgi->header(-type => "$type",
2376 -content_disposition => "inline; filename=\"$save_as\"");
2378 binmode STDOUT, ':raw';
2380 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
2386 if (!defined $hash) {
2387 if (defined $file_name) {
2388 my $base = $hash_base || git_get_head_hash($project);
2389 $hash = git_get_hash_by_path($base, $file_name, "blob")
2390 or die_error(undef, "Error lookup file");
2392 die_error(undef, "No file name defined");
2395 my $have_blame = gitweb_check_feature('blame');
2396 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2397 or die_error(undef, "Couldn't cat $file_name, $hash");
2398 my $mimetype = blob_mimetype($fd, $file_name);
2399 if ($mimetype !~ m/^text\//) {
2401 return git_blob_plain($mimetype);
2404 my $formats_nav = '';
2405 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2406 if (defined $file_name) {
2409 $cgi->a({-href => href(action=>"blame", hash_base=>$hash_base,
2410 hash=>$hash, file_name=>$file_name)},
2415 $cgi->a({-href => href(action=>"blob_plain",
2416 hash=>$hash, file_name=>$file_name)},
2419 $cgi->a({-href => href(action=>"blob",
2420 hash_base=>"HEAD", file_name=>$file_name)},
2424 $cgi->a({-href => href(action=>"blob_plain", hash=>$hash)}, "plain");
2426 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2427 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2429 print "<div class=\"page_nav\">\n" .
2430 "<br/><br/></div>\n" .
2431 "<div class=\"title\">$hash</div>\n";
2433 git_print_page_path($file_name, "blob", $hash_base);
2434 print "<div class=\"page_body\">\n";
2436 while (my $line = <$fd>) {
2439 $line = untabify($line);
2440 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2441 $nr, $nr, $nr, esc_html($line);
2444 or print "Reading blob failed.\n";
2450 if (!defined $hash) {
2451 $hash = git_get_head_hash($project);
2452 if (defined $file_name) {
2453 my $base = $hash_base || $hash;
2454 $hash = git_get_hash_by_path($base, $file_name, "tree");
2456 if (!defined $hash_base) {
2461 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
2462 or die_error(undef, "Open git-ls-tree failed");
2463 my @entries = map { chomp; $_ } <$fd>;
2464 close $fd or die_error(undef, "Reading tree failed");
2467 my $refs = git_get_references();
2468 my $ref = format_ref_marker($refs, $hash_base);
2472 my $have_blame = gitweb_check_feature('blame');
2473 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2474 $base_key{hash_base} = $hash_base;
2475 git_print_page_nav('tree','', $hash_base);
2476 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
2478 print "<div class=\"page_nav\">\n";
2479 print "<br/><br/></div>\n";
2480 print "<div class=\"title\">$hash</div>\n";
2482 if (defined $file_name) {
2483 $base = esc_html("$file_name/");
2485 git_print_page_path($file_name, 'tree', $hash_base);
2486 print "<div class=\"page_body\">\n";
2487 print "<table cellspacing=\"0\">\n";
2489 foreach my $line (@entries) {
2490 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2491 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2495 my $t_name = validate_input($4);
2497 print "<tr class=\"dark\">\n";
2499 print "<tr class=\"light\">\n";
2502 print "<td class=\"mode\">" . mode_str($t_mode) . "</td>\n";
2503 if ($t_type eq "blob") {
2504 print "<td class=\"list\">" .
2505 $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key),
2506 -class => "list"}, esc_html($t_name)) .
2508 "<td class=\"link\">" .
2509 $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2513 $cgi->a({-href => href(action=>"blame", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2517 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
2518 hash=>$t_hash, file_name=>"$base$t_name")},
2521 $cgi->a({-href => href(action=>"blob_plain",
2522 hash=>$t_hash, file_name=>"$base$t_name")},
2525 } elsif ($t_type eq "tree") {
2526 print "<td class=\"list\">" .
2527 $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2528 esc_html($t_name)) .
2530 "<td class=\"link\">" .
2531 $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2534 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, file_name=>"$base$t_name")},
2540 print "</table>\n" .
2547 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
2548 my $have_snapshot = (defined $ctype && defined $suffix);
2549 if (!$have_snapshot) {
2550 die_error('403 Permission denied', "Permission denied");
2553 if (!defined $hash) {
2554 $hash = git_get_head_hash($project);
2557 my $filename = basename($project) . "-$hash.tar.$suffix";
2559 print $cgi->header(-type => 'application/x-tar',
2560 -content_encoding => $ctype,
2561 -content_disposition => "inline; filename=\"$filename\"",
2562 -status => '200 OK');
2564 open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | $command" or
2565 die_error(undef, "Execute git-tar-tree failed.");
2566 binmode STDOUT, ':raw';
2568 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
2574 my $head = git_get_head_hash($project);
2575 if (!defined $hash) {
2578 if (!defined $page) {
2581 my $refs = git_get_references();
2583 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2584 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2585 or die_error(undef, "Open git-rev-list failed");
2586 my @revlist = map { chomp; $_ } <$fd>;
2589 my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#revlist);
2592 git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
2595 my %co = parse_commit($hash);
2597 git_print_header_div('summary', $project);
2598 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2600 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2601 my $commit = $revlist[$i];
2602 my $ref = format_ref_marker($refs, $commit);
2603 my %co = parse_commit($commit);
2605 my %ad = parse_date($co{'author_epoch'});
2606 git_print_header_div('commit',
2607 "<span class=\"age\">$co{'age_string'}</span>" .
2608 esc_html($co{'title'}) . $ref,
2610 print "<div class=\"title_text\">\n" .
2611 "<div class=\"log_link\">\n" .
2612 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
2614 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
2617 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2620 print "<div class=\"log_body\">\n";
2621 git_print_simplified_log($co{'comment'});
2628 my %co = parse_commit($hash);
2630 die_error(undef, "Unknown commit object");
2632 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
2633 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
2635 my $parent = $co{'parent'};
2636 if (!defined $parent) {
2639 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
2640 or die_error(undef, "Open git-diff-tree failed");
2641 my @difftree = map { chomp; $_ } <$fd>;
2642 close $fd or die_error(undef, "Reading git-diff-tree failed");
2644 # non-textual hash id's can be cached
2646 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2649 my $refs = git_get_references();
2650 my $ref = format_ref_marker($refs, $co{'id'});
2652 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
2653 my $have_snapshot = (defined $ctype && defined $suffix);
2655 my $formats_nav = '';
2656 if (defined $file_name && defined $co{'parent'}) {
2657 my $parent = $co{'parent'};
2659 $cgi->a({-href => href(action=>"blame", hash_parent=>$parent, file_name=>$file_name)},
2662 git_header_html(undef, $expires);
2663 git_print_page_nav('commit', defined $co{'parent'} ? '' : 'commitdiff',
2664 $hash, $co{'tree'}, $hash,
2667 if (defined $co{'parent'}) {
2668 git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash);
2670 git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash);
2672 print "<div class=\"title_text\">\n" .
2673 "<table cellspacing=\"0\">\n";
2674 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
2676 "<td></td><td> $ad{'rfc2822'}";
2677 if ($ad{'hour_local'} < 6) {
2678 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2679 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2681 printf(" (%02d:%02d %s)",
2682 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2686 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
2687 print "<tr><td></td><td> $cd{'rfc2822'}" .
2688 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2690 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2693 "<td class=\"sha1\">" .
2694 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),
2695 class => "list"}, $co{'tree'}) .
2697 "<td class=\"link\">" .
2698 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},
2700 if ($have_snapshot) {
2702 $cgi->a({-href => href(action=>"snapshot", hash=>$hash)}, "snapshot");
2706 my $parents = $co{'parents'};
2707 foreach my $par (@$parents) {
2710 "<td class=\"sha1\">" .
2711 $cgi->a({-href => href(action=>"commit", hash=>$par),
2712 class => "list"}, $par) .
2714 "<td class=\"link\">" .
2715 $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") .
2717 $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "commitdiff") .
2724 print "<div class=\"page_body\">\n";
2725 git_print_log($co{'comment'});
2728 git_difftree_body(\@difftree, $hash, $parent);
2734 mkdir($git_temp, 0700);
2736 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2738 $cgi->a({-href => href(action=>"blobdiff_plain",
2739 hash=>$hash, hash_parent=>$hash_parent)},
2741 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2742 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2745 <div class="page_nav"><br/><br/></div>
2746 <div class="title">$hash vs $hash_parent</div>
2749 git_print_page_path($file_name, "blob", $hash_base);
2750 print "<div class=\"page_body\">\n" .
2751 "<div class=\"diff_info\">blob:" .
2752 $cgi->a({-href => href(action=>"blob", hash=>$hash_parent,
2753 hash_base=>$hash_base, file_name=>($file_parent || $file_name))},
2756 $cgi->a({-href => href(action=>"blob", hash=>$hash,
2757 hash_base=>$hash_base, file_name=>$file_name)},
2760 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2761 print "</div>"; # page_body
2765 sub git_blobdiff_plain {
2766 mkdir($git_temp, 0700);
2767 print $cgi->header(-type => "text/plain", -charset => 'utf-8');
2768 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2771 sub git_commitdiff {
2772 my $format = shift || 'html';
2773 my %co = parse_commit($hash);
2775 die_error(undef, "Unknown commit object");
2777 if (!defined $hash_parent) {
2778 $hash_parent = $co{'parent'} || '--root';
2784 if ($format eq 'html') {
2785 open $fd, "-|", $GIT, "diff-tree", '-r', '-M', '-C',
2786 "--patch-with-raw", "--full-index", $hash_parent, $hash
2787 or die_error(undef, "Open git-diff-tree failed");
2789 while (chomp(my $line = <$fd>)) {
2790 # empty line ends raw part of diff-tree output
2792 push @difftree, $line;
2795 } elsif ($format eq 'plain') {
2796 open $fd, "-|", $GIT, "diff-tree", '-r', '-p', '-B', $hash_parent, $hash
2797 or die_error(undef, "Open git-diff-tree failed");
2800 die_error(undef, "Unknown commitdiff format");
2803 # non-textual hash id's can be cached
2805 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2809 # write commit message
2810 if ($format eq 'html') {
2811 my $refs = git_get_references();
2812 my $ref = format_ref_marker($refs, $co{'id'});
2814 $cgi->a({-href => href(action=>"commitdiff_plain",
2815 hash=>$hash, hash_parent=>$hash_parent)},
2818 git_header_html(undef, $expires);
2819 git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2820 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
2821 print "<div class=\"page_body\">\n";
2822 print "<div class=\"log\">\n";
2823 git_print_simplified_log($co{'comment'}, 1); # skip title
2824 print "</div>\n"; # class="log"
2826 } elsif ($format eq 'plain') {
2827 my $refs = git_get_references("tags");
2829 if (exists $refs->{$hash}) {
2830 @tagnames = map { s|^tags/|| } $refs->{$hash};
2832 my $filename = basename($project) . "-$hash.patch";
2835 -type => 'text/plain',
2836 -charset => 'utf-8',
2837 -expires => $expires,
2838 -content_disposition => qq(inline; filename="$filename"));
2839 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
2842 Date: $ad{'rfc2822'} ($ad{'tz_local'})
2843 Subject: $co{'title'}
2845 foreach my $tag (@tagnames) {
2846 print "X-Git-Tag: $tag\n";
2848 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
2849 foreach my $line (@{$co{'comment'}}) {
2856 if ($format eq 'html') {
2857 #git_difftree_body(\@difftree, $hash, $hash_parent);
2860 git_patchset_body($fd, \@difftree, $hash, $hash_parent);
2862 print "</div>\n"; # class="page_body"
2865 } elsif ($format eq 'plain') {
2869 or print "Reading git-diff-tree failed\n";
2873 sub git_commitdiff_plain {
2874 git_commitdiff('plain');
2878 if (!defined $hash_base) {
2879 $hash_base = git_get_head_hash($project);
2882 my %co = parse_commit($hash_base);
2884 die_error(undef, "Unknown commit object");
2886 my $refs = git_get_references();
2888 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base);
2889 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2890 if (!defined $hash && defined $file_name) {
2891 $hash = git_get_hash_by_path($hash_base, $file_name);
2893 if (defined $hash) {
2894 $ftype = git_get_type($hash);
2896 git_print_page_path($file_name, $ftype, $hash_base);
2899 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2900 git_history_body($fd, $refs, $hash_base, $ftype);
2907 if (!defined $searchtext) {
2908 die_error(undef, "Text field empty");
2910 if (!defined $hash) {
2911 $hash = git_get_head_hash($project);
2913 my %co = parse_commit($hash);
2915 die_error(undef, "Unknown commit object");
2917 # pickaxe may take all resources of your box and run for several minutes
2918 # with every query - so decide by yourself how public you make this feature :)
2919 my $commit_search = 1;
2920 my $author_search = 0;
2921 my $committer_search = 0;
2922 my $pickaxe_search = 0;
2923 if ($searchtext =~ s/^author\\://i) {
2925 } elsif ($searchtext =~ s/^committer\\://i) {
2926 $committer_search = 1;
2927 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2929 $pickaxe_search = 1;
2932 git_print_page_nav('','', $hash,$co{'tree'},$hash);
2933 git_print_header_div('commit', esc_html($co{'title'}), $hash);
2935 print "<table cellspacing=\"0\">\n";
2937 if ($commit_search) {
2939 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2940 while (my $commit_text = <$fd>) {
2941 if (!grep m/$searchtext/i, $commit_text) {
2944 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2947 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2950 my @commit_lines = split "\n", $commit_text;
2951 my %co = parse_commit(undef, \@commit_lines);
2956 print "<tr class=\"dark\">\n";
2958 print "<tr class=\"light\">\n";
2961 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2962 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2964 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"},
2965 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
2966 my $comment = $co{'comment'};
2967 foreach my $line (@$comment) {
2968 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2969 my $lead = esc_html($1) || "";
2970 $lead = chop_str($lead, 30, 10);
2971 my $match = esc_html($2) || "";
2972 my $trail = esc_html($3) || "";
2973 $trail = chop_str($trail, 30, 10);
2974 my $text = "$lead<span class=\"match\">$match</span>$trail";
2975 print chop_str($text, 80, 5) . "<br/>\n";
2979 "<td class=\"link\">" .
2980 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
2982 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
2989 if ($pickaxe_search) {
2991 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2994 while (my $line = <$fd>) {
2995 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2998 $set{'from_id'} = $3;
3000 $set{'id'} = $set{'to_id'};
3001 if ($set{'id'} =~ m/0{40}/) {
3002 $set{'id'} = $set{'from_id'};
3004 if ($set{'id'} =~ m/0{40}/) {
3008 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3011 print "<tr class=\"dark\">\n";
3013 print "<tr class=\"light\">\n";
3016 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3017 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3019 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
3020 -class => "list subject"},
3021 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
3022 while (my $setref = shift @files) {
3024 print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},
3025 hash=>$set{'id'}, file_name=>$set{'file'}),
3027 "<span class=\"match\">" . esc_html($set{'file'}) . "</span>") .
3031 "<td class=\"link\">" .
3032 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
3034 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
3038 %co = parse_commit($1);
3048 my $head = git_get_head_hash($project);
3049 if (!defined $hash) {
3052 if (!defined $page) {
3055 my $refs = git_get_references();
3057 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3058 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
3059 or die_error(undef, "Open git-rev-list failed");
3060 my @revlist = map { chomp; $_ } <$fd>;
3063 my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, $#revlist);
3065 if ($#revlist >= (100 * ($page+1)-1)) {
3067 $cgi->a({-href => href(action=>"shortlog", hash=>$hash, page=>$page+1),
3068 -title => "Alt-n"}, "next");
3073 git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);
3074 git_print_header_div('summary', $project);
3076 git_shortlog_body(\@revlist, ($page * 100), $#revlist, $refs, $next_link);
3081 ## ......................................................................
3082 ## feeds (RSS, OPML)
3085 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3086 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash($project)
3087 or die_error(undef, "Open git-rev-list failed");
3088 my @revlist = map { chomp; $_ } <$fd>;
3089 close $fd or die_error(undef, "Reading git-rev-list failed");
3090 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
3092 <?xml version="1.0" encoding="utf-8"?>
3093 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3095 <title>$project $my_uri $my_url</title>
3096 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3097 <description>$project log</description>
3098 <language>en</language>
3101 for (my $i = 0; $i <= $#revlist; $i++) {
3102 my $commit = $revlist[$i];
3103 my %co = parse_commit($commit);
3104 # we read 150, we always show 30 and the ones more recent than 48 hours
3105 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3108 my %cd = parse_date($co{'committer_epoch'});
3109 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
3110 my @difftree = map { chomp; $_ } <$fd>;
3114 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) .
3116 "<author>" . esc_html($co{'author'}) . "</author>\n" .
3117 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3118 "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3119 "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3120 "<description>" . esc_html($co{'title'}) . "</description>\n" .
3121 "<content:encoded>" .
3123 my $comment = $co{'comment'};
3124 foreach my $line (@$comment) {
3125 $line = decode("utf8", $line, Encode::FB_DEFAULT);
3126 print "$line<br/>\n";
3129 foreach my $line (@difftree) {
3130 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3133 my $file = validate_input(unquote($7));
3134 $file = decode("utf8", $file, Encode::FB_DEFAULT);
3135 print "$file<br/>\n";
3138 "</content:encoded>\n" .
3141 print "</channel></rss>";
3145 my @list = git_get_projects_list();
3147 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
3149 <?xml version="1.0" encoding="utf-8"?>
3150 <opml version="1.0">
3152 <title>$site_name Git OPML Export</title>
3155 <outline text="git RSS feeds">
3158 foreach my $pr (@list) {
3160 my $head = git_get_head_hash($proj{'path'});
3161 if (!defined $head) {
3164 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
3165 my %co = parse_commit($head);
3170 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
3171 my $rss = "$my_url?p=$proj{'path'};a=rss";
3172 my $html = "$my_url?p=$proj{'path'};a=summary";
3173 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";