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>;
793 foreach my $commit (@commits) {
794 foreach my $ref (@{$refs->{$commit}}) {
795 return $ref unless wantarray;
803 ## ----------------------------------------------------------------------
804 ## parse to hash functions
808 my $tz = shift || "-0000";
811 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
812 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
813 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
814 $date{'hour'} = $hour;
815 $date{'minute'} = $min;
816 $date{'mday'} = $mday;
817 $date{'day'} = $days[$wday];
818 $date{'month'} = $months[$mon];
819 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
820 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
821 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
822 $mday, $months[$mon], $hour ,$min;
824 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
825 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
826 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
827 $date{'hour_local'} = $hour;
828 $date{'minute_local'} = $min;
829 $date{'tz_local'} = $tz;
838 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
839 $tag{'id'} = $tag_id;
840 while (my $line = <$fd>) {
842 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
844 } elsif ($line =~ m/^type (.+)$/) {
846 } elsif ($line =~ m/^tag (.+)$/) {
848 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
852 } elsif ($line =~ m/--BEGIN/) {
853 push @comment, $line;
855 } elsif ($line eq "") {
859 push @comment, <$fd>;
860 $tag{'comment'} = \@comment;
862 if (!defined $tag{'name'}) {
869 my $commit_id = shift;
870 my $commit_text = shift;
875 if (defined $commit_text) {
876 @commit_lines = @$commit_text;
879 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id
881 @commit_lines = split '\n', <$fd>;
886 my $header = shift @commit_lines;
887 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
890 ($co{'id'}, my @parents) = split ' ', $header;
891 $co{'parents'} = \@parents;
892 $co{'parent'} = $parents[0];
893 while (my $line = shift @commit_lines) {
894 last if $line eq "\n";
895 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
897 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
899 $co{'author_epoch'} = $2;
900 $co{'author_tz'} = $3;
901 if ($co{'author'} =~ m/^([^<]+) </) {
902 $co{'author_name'} = $1;
904 $co{'author_name'} = $co{'author'};
906 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
907 $co{'committer'} = $1;
908 $co{'committer_epoch'} = $2;
909 $co{'committer_tz'} = $3;
910 $co{'committer_name'} = $co{'committer'};
911 $co{'committer_name'} =~ s/ <.*//;
914 if (!defined $co{'tree'}) {
918 foreach my $title (@commit_lines) {
921 $co{'title'} = chop_str($title, 80, 5);
922 # remove leading stuff of merges to make the interesting part visible
923 if (length($title) > 50) {
924 $title =~ s/^Automatic //;
925 $title =~ s/^merge (of|with) /Merge ... /i;
926 if (length($title) > 50) {
927 $title =~ s/(http|rsync):\/\///;
929 if (length($title) > 50) {
930 $title =~ s/(master|www|rsync)\.//;
932 if (length($title) > 50) {
933 $title =~ s/kernel.org:?//;
935 if (length($title) > 50) {
936 $title =~ s/\/pub\/scm//;
939 $co{'title_short'} = chop_str($title, 50, 5);
943 # remove added spaces
944 foreach my $line (@commit_lines) {
947 $co{'comment'} = \@commit_lines;
949 my $age = time - $co{'committer_epoch'};
951 $co{'age_string'} = age_string($age);
952 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
953 if ($age > 60*60*24*7*2) {
954 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
955 $co{'age_string_age'} = $co{'age_string'};
957 $co{'age_string_date'} = $co{'age_string'};
958 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
963 # parse ref from ref_file, given by ref_id, with given type
965 my $ref_file = shift;
967 my $type = shift || git_get_type($ref_id);
970 $ref_item{'type'} = $type;
971 $ref_item{'id'} = $ref_id;
972 $ref_item{'epoch'} = 0;
973 $ref_item{'age'} = "unknown";
974 if ($type eq "tag") {
975 my %tag = parse_tag($ref_id);
976 $ref_item{'comment'} = $tag{'comment'};
977 if ($tag{'type'} eq "commit") {
978 my %co = parse_commit($tag{'object'});
979 $ref_item{'epoch'} = $co{'committer_epoch'};
980 $ref_item{'age'} = $co{'age_string'};
981 } elsif (defined($tag{'epoch'})) {
982 my $age = time - $tag{'epoch'};
983 $ref_item{'epoch'} = $tag{'epoch'};
984 $ref_item{'age'} = age_string($age);
986 $ref_item{'reftype'} = $tag{'type'};
987 $ref_item{'name'} = $tag{'name'};
988 $ref_item{'refid'} = $tag{'object'};
989 } elsif ($type eq "commit"){
990 my %co = parse_commit($ref_id);
991 $ref_item{'reftype'} = "commit";
992 $ref_item{'name'} = $ref_file;
993 $ref_item{'title'} = $co{'title'};
994 $ref_item{'refid'} = $ref_id;
995 $ref_item{'epoch'} = $co{'committer_epoch'};
996 $ref_item{'age'} = $co{'age_string'};
998 $ref_item{'reftype'} = $type;
999 $ref_item{'name'} = $ref_file;
1000 $ref_item{'refid'} = $ref_id;
1006 # parse line of git-diff-tree "raw" output
1007 sub parse_difftree_raw_line {
1011 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1012 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1013 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1014 $res{'from_mode'} = $1;
1015 $res{'to_mode'} = $2;
1016 $res{'from_id'} = $3;
1018 $res{'status'} = $5;
1019 $res{'similarity'} = $6;
1020 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1021 ($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
1023 $res{'file'} = unquote($7);
1026 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1027 #elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1028 # $res{'commit'} = $1;
1031 return wantarray ? %res : \%res;
1034 ## ......................................................................
1035 ## parse to array of hashes functions
1037 sub git_get_refs_list {
1038 my $ref_dir = shift;
1042 my $pfxlen = length("$projectroot/$project/$ref_dir");
1043 File::Find::find(sub {
1046 push @refs, substr($File::Find::name, $pfxlen + 1);
1048 }, "$projectroot/$project/$ref_dir");
1050 foreach my $ref_file (@refs) {
1051 my $ref_id = git_get_hash_by_ref("$project/$ref_dir/$ref_file");
1052 my $type = git_get_type($ref_id) || next;
1053 my %ref_item = parse_ref($ref_file, $ref_id, $type);
1055 push @reflist, \%ref_item;
1058 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1062 ## ----------------------------------------------------------------------
1063 ## filesystem-related functions
1065 sub get_file_owner {
1068 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1069 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1070 if (!defined $gcos) {
1074 $owner =~ s/[,;].*$//;
1075 return decode("utf8", $owner, Encode::FB_DEFAULT);
1078 ## ......................................................................
1079 ## mimetype related functions
1081 sub mimetype_guess_file {
1082 my $filename = shift;
1083 my $mimemap = shift;
1084 -r $mimemap or return undef;
1087 open(MIME, $mimemap) or return undef;
1089 next if m/^#/; # skip comments
1090 my ($mime, $exts) = split(/\t+/);
1091 if (defined $exts) {
1092 my @exts = split(/\s+/, $exts);
1093 foreach my $ext (@exts) {
1094 $mimemap{$ext} = $mime;
1100 $filename =~ /\.(.*?)$/;
1101 return $mimemap{$1};
1104 sub mimetype_guess {
1105 my $filename = shift;
1107 $filename =~ /\./ or return undef;
1109 if ($mimetypes_file) {
1110 my $file = $mimetypes_file;
1111 if ($file !~ m!^/!) { # if it is relative path
1112 # it is relative to project
1113 $file = "$projectroot/$project/$file";
1115 $mime = mimetype_guess_file($filename, $file);
1117 $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
1123 my $filename = shift;
1126 my $mime = mimetype_guess($filename);
1127 $mime and return $mime;
1131 return $default_blob_plain_mimetype unless $fd;
1134 return 'text/plain' .
1135 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1136 } elsif (! $filename) {
1137 return 'application/octet-stream';
1138 } elsif ($filename =~ m/\.png$/i) {
1140 } elsif ($filename =~ m/\.gif$/i) {
1142 } elsif ($filename =~ m/\.jpe?g$/i) {
1143 return 'image/jpeg';
1145 return 'application/octet-stream';
1149 ## ======================================================================
1150 ## functions printing HTML: header, footer, error page
1152 sub git_header_html {
1153 my $status = shift || "200 OK";
1154 my $expires = shift;
1156 my $title = "$site_name git";
1157 if (defined $project) {
1158 $title .= " - $project";
1159 if (defined $action) {
1160 $title .= "/$action";
1161 if (defined $file_name) {
1162 $title .= " - $file_name";
1163 if ($action eq "tree" && $file_name !~ m|/$|) {
1170 # require explicit support from the UA if we are to send the page as
1171 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1172 # we have to do this because MSIE sometimes globs '*/*', pretending to
1173 # support xhtml+xml but choking when it gets what it asked for.
1174 if (defined $cgi->http('HTTP_ACCEPT') &&
1175 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&
1176 $cgi->Accept('application/xhtml+xml') != 0) {
1177 $content_type = 'application/xhtml+xml';
1179 $content_type = 'text/html';
1181 print $cgi->header(-type=>$content_type, -charset => 'utf-8',
1182 -status=> $status, -expires => $expires);
1184 <?xml version="1.0" encoding="utf-8"?>
1185 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1186 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1187 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1188 <!-- git core binaries version $git_version -->
1190 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1191 <meta name="generator" content="gitweb/$version git/$git_version"/>
1192 <meta name="robots" content="index, nofollow"/>
1193 <title>$title</title>
1194 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1196 if (defined $project) {
1197 printf('<link rel="alternate" title="%s log" '.
1198 'href="%s" type="application/rss+xml"/>'."\n",
1199 esc_param($project), href(action=>"rss"));
1204 "<div class=\"page_header\">\n" .
1205 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1206 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1208 print $cgi->a({-href => esc_param($home_link)}, $home_link_str) . " / ";
1209 if (defined $project) {
1210 print $cgi->a({-href => href(action=>"summary")}, esc_html($project));
1211 if (defined $action) {
1215 if (!defined $searchtext) {
1219 if (defined $hash_base) {
1220 $search_hash = $hash_base;
1221 } elsif (defined $hash) {
1222 $search_hash = $hash;
1224 $search_hash = "HEAD";
1226 $cgi->param("a", "search");
1227 $cgi->param("h", $search_hash);
1228 print $cgi->startform(-method => "get", -action => $my_uri) .
1229 "<div class=\"search\">\n" .
1230 $cgi->hidden(-name => "p") . "\n" .
1231 $cgi->hidden(-name => "a") . "\n" .
1232 $cgi->hidden(-name => "h") . "\n" .
1233 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
1235 $cgi->end_form() . "\n";
1240 sub git_footer_html {
1241 print "<div class=\"page_footer\">\n";
1242 if (defined $project) {
1243 my $descr = git_get_project_description($project);
1244 if (defined $descr) {
1245 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
1247 print $cgi->a({-href => href(action=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1249 print $cgi->a({-href => href(action=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1257 my $status = shift || "403 Forbidden";
1258 my $error = shift || "Malformed query, file missing or permission denied";
1260 git_header_html($status);
1262 <div class="page_body">
1272 ## ----------------------------------------------------------------------
1273 ## functions printing or outputting HTML: navigation
1275 sub git_print_page_nav {
1276 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1277 $extra = '' if !defined $extra; # pager or formats
1279 my @navs = qw(summary shortlog log commit commitdiff tree);
1281 @navs = grep { $_ ne $suppress } @navs;
1284 my %arg = map { $_ => {action=>$_} } @navs;
1285 if (defined $head) {
1286 for (qw(commit commitdiff)) {
1287 $arg{$_}{hash} = $head;
1289 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1290 for (qw(shortlog log)) {
1291 $arg{$_}{hash} = $head;
1295 $arg{tree}{hash} = $treehead if defined $treehead;
1296 $arg{tree}{hash_base} = $treebase if defined $treebase;
1298 print "<div class=\"page_nav\">\n" .
1300 map { $_ eq $current ?
1301 $_ : $cgi->a({-href => href(%{$arg{$_}})}, "$_")
1303 print "<br/>\n$extra<br/>\n" .
1307 sub format_paging_nav {
1308 my ($action, $hash, $head, $page, $nrevs) = @_;
1312 if ($hash ne $head || $page) {
1313 $paging_nav .= $cgi->a({-href => href(action=>$action)}, "HEAD");
1315 $paging_nav .= "HEAD";
1319 $paging_nav .= " ⋅ " .
1320 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page-1),
1321 -accesskey => "p", -title => "Alt-p"}, "prev");
1323 $paging_nav .= " ⋅ prev";
1326 if ($nrevs >= (100 * ($page+1)-1)) {
1327 $paging_nav .= " ⋅ " .
1328 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page+1),
1329 -accesskey => "n", -title => "Alt-n"}, "next");
1331 $paging_nav .= " ⋅ next";
1337 ## ......................................................................
1338 ## functions printing or outputting HTML: div
1340 sub git_print_header_div {
1341 my ($action, $title, $hash, $hash_base) = @_;
1344 $args{action} = $action;
1345 $args{hash} = $hash if $hash;
1346 $args{hash_base} = $hash_base if $hash_base;
1348 print "<div class=\"header\">\n" .
1349 $cgi->a({-href => href(%args), -class => "title"},
1350 $title ? $title : $action) .
1354 sub git_print_page_path {
1359 if (!defined $name) {
1360 print "<div class=\"page_path\">/</div>\n";
1361 } elsif (defined $type && $type eq 'blob') {
1362 print "<div class=\"page_path\">";
1364 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,
1368 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name)},
1371 print "<br/></div>\n";
1373 print "<div class=\"page_path\">" . esc_html($name) . "<br/></div>\n";
1380 # remove leading empty lines
1381 while (defined $log->[0] && $log->[0] eq "") {
1388 foreach my $line (@$log) {
1389 # print only one empty line
1390 # do not print empty line after signoff
1392 next if ($empty || $signoff);
1397 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1399 print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
1402 print format_log_line_html($line) . "<br/>\n";
1407 sub git_print_simplified_log {
1409 my $remove_title = shift;
1411 shift @$log if $remove_title;
1412 # remove leading empty lines
1413 while (defined $log->[0] && $log->[0] eq "") {
1417 # simplify and print log
1419 foreach my $line (@$log) {
1420 # remove signoff lines
1421 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1424 # print only one empty line
1431 print format_log_line_html($line) . "<br/>\n";
1433 # end with single empty line
1434 print "<br/>\n" unless $empty;
1437 ## ......................................................................
1438 ## functions printing large fragments of HTML
1440 sub git_difftree_body {
1441 my ($difftree, $hash, $parent) = @_;
1443 print "<div class=\"list_head\">\n";
1444 if ($#{$difftree} > 10) {
1445 print(($#{$difftree} + 1) . " files changed:\n");
1449 print "<table class=\"diff_tree\">\n";
1451 foreach my $line (@{$difftree}) {
1452 my %diff = parse_difftree_raw_line($line);
1455 print "<tr class=\"dark\">\n";
1457 print "<tr class=\"light\">\n";
1461 my ($to_mode_oct, $to_mode_str, $to_file_type);
1462 my ($from_mode_oct, $from_mode_str, $from_file_type);
1463 if ($diff{'to_mode'} ne ('0' x 6)) {
1464 $to_mode_oct = oct $diff{'to_mode'};
1465 if (S_ISREG($to_mode_oct)) { # only for regular file
1466 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1468 $to_file_type = file_type($diff{'to_mode'});
1470 if ($diff{'from_mode'} ne ('0' x 6)) {
1471 $from_mode_oct = oct $diff{'from_mode'};
1472 if (S_ISREG($to_mode_oct)) { # only for regular file
1473 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1475 $from_file_type = file_type($diff{'from_mode'});
1478 if ($diff{'status'} eq "A") { # created
1479 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1480 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1481 $mode_chng .= "]</span>";
1483 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1484 hash_base=>$hash, file_name=>$diff{'file'}),
1485 -class => "list"}, esc_html($diff{'file'})) .
1487 "<td>$mode_chng</td>\n" .
1488 "<td class=\"link\">" .
1489 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1490 hash_base=>$hash, file_name=>$diff{'file'})},
1494 } elsif ($diff{'status'} eq "D") { # deleted
1495 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1497 $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
1498 hash_base=>$parent, file_name=>$diff{'file'}),
1499 -class => "list"}, esc_html($diff{'file'})) .
1501 "<td>$mode_chng</td>\n" .
1502 "<td class=\"link\">" .
1503 $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
1504 hash_base=>$parent, file_name=>$diff{'file'})},
1507 $cgi->a({-href => href(action=>"history", hash_base=>$parent,
1508 file_name=>$diff{'file'})},\
1512 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1513 my $mode_chnge = "";
1514 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1515 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1516 if ($from_file_type != $to_file_type) {
1517 $mode_chnge .= " from $from_file_type to $to_file_type";
1519 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1520 if ($from_mode_str && $to_mode_str) {
1521 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1522 } elsif ($to_mode_str) {
1523 $mode_chnge .= " mode: $to_mode_str";
1526 $mode_chnge .= "]</span>\n";
1529 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1530 print $cgi->a({-href => href(action=>"blobdiff", hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1531 hash_base=>$hash, file_name=>$diff{'file'}),
1532 -class => "list"}, esc_html($diff{'file'}));
1533 } else { # only mode changed
1534 print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1535 hash_base=>$hash, file_name=>$diff{'file'}),
1536 -class => "list"}, esc_html($diff{'file'}));
1539 "<td>$mode_chnge</td>\n" .
1540 "<td class=\"link\">" .
1541 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1542 hash_base=>$hash, file_name=>$diff{'file'})},
1544 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1546 $cgi->a({-href => href(action=>"blobdiff", hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1547 hash_base=>$hash, file_name=>$diff{'file'})},
1551 $cgi->a({-href => href(action=>"history",
1552 hash_base=>$hash, file_name=>$diff{'file'})},
1556 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1557 my %status_name = ('R' => 'moved', 'C' => 'copied');
1558 my $nstatus = $status_name{$diff{'status'}};
1560 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1561 # mode also for directories, so we cannot use $to_mode_str
1562 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1565 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1566 hash=>$diff{'to_id'}, file_name=>$diff{'to_file'}),
1567 -class => "list"}, esc_html($diff{'to_file'})) . "</td>\n" .
1568 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1569 $cgi->a({-href => href(action=>"blob", hash_base=>$parent,
1570 hash=>$diff{'from_id'}, file_name=>$diff{'from_file'}),
1571 -class => "list"}, esc_html($diff{'from_file'})) .
1572 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1573 "<td class=\"link\">" .
1574 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1575 hash=>$diff{'to_id'}, file_name=>$diff{'to_file'})},
1577 if ($diff{'to_id'} ne $diff{'from_id'}) {
1579 $cgi->a({-href => href(action=>"blobdiff", hash_base=>$hash,
1580 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1581 file_name=>$diff{'to_file'}, file_parent=>$diff{'from_file'})},
1586 } # we should not encounter Unmerged (U) or Unknown (X) status
1592 sub git_patchset_body {
1593 my ($fd, $difftree, $hash, $hash_parent) = @_;
1597 my $patch_found = 0;
1600 print "<div class=\"patchset\">\n";
1603 while (my $patch_line @$fd>) {
1606 if ($patch_line =~ m/^diff /) { # "git diff" header
1607 # beginning of patch (in patchset)
1609 # close previous patch
1610 print "</div>\n"; # class="patch"
1612 # first patch in patchset
1615 print "<div class=\"patch\">\n";
1617 %diffinfo = parse_difftree_raw_line($difftree->[$patch_idx++]);
1619 # for now, no extended header, hence we skip empty patches
1620 # companion to next LINE if $in_header;
1621 if ($diffinfo{'from_id'} eq $diffinfo{'to_id'}) { # no change
1626 if ($diffinfo{'status'} eq "A") { # added
1627 print "<div class=\"diff_info\">" . file_type($diffinfo{'to_mode'}) . ":" .
1628 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1629 hash=>$diffinfo{'to_id'}, file_name=>$diffinfo{'file'})},
1630 $diffinfo{'to_id'}) . "(new)" .
1631 "</div>\n"; # class="diff_info"
1633 } elsif ($diffinfo{'status'} eq "D") { # deleted
1634 print "<div class=\"diff_info\">" . file_type($diffinfo{'from_mode'}) . ":" .
1635 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1636 hash=>$diffinfo{'from_id'}, file_name=>$diffinfo{'file'})},
1637 $diffinfo{'from_id'}) . "(deleted)" .
1638 "</div>\n"; # class="diff_info"
1640 } elsif ($diffinfo{'status'} eq "R" || # renamed
1641 $diffinfo{'status'} eq "C") { # copied
1642 print "<div class=\"diff_info\">" .
1643 file_type($diffinfo{'from_mode'}) . ":" .
1644 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1645 hash=>$diffinfo{'from_id'}, file_name=>$diffinfo{'from_file'})},
1646 $diffinfo{'from_id'}) .
1648 file_type($diffinfo{'to_mode'}) . ":" .
1649 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1650 hash=>$diffinfo{'to_id'}, file_name=>$diffinfo{'to_file'})},
1651 $diffinfo{'to_id'});
1652 print "</div>\n"; # class="diff_info"
1654 } else { # modified, mode changed, ...
1655 print "<div class=\"diff_info\">" .
1656 file_type($diffinfo{'from_mode'}) . ":" .
1657 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1658 hash=>$diffinfo{'from_id'}, file_name=>$diffinfo{'file'})},
1659 $diffinfo{'from_id'}) .
1661 file_type($diffinfo{'to_mode'}) . ":" .
1662 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1663 hash=>$diffinfo{'to_id'}, file_name=>$diffinfo{'file'})},
1664 $diffinfo{'to_id'});
1665 print "</div>\n"; # class="diff_info"
1668 #print "<div class=\"diff extended_header\">\n";
1671 } # start of patch in patchset
1674 if ($in_header && $patch_line =~ m/^---/) {
1678 next LINE if $in_header;
1680 print format_diff_line($patch_line);
1682 print "</div>\n" if $patch_found; # class="patch"
1684 print "</div>\n"; # class="patchset"
1687 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1689 sub git_shortlog_body {
1690 # uses global variable $project
1691 my ($revlist, $from, $to, $refs, $extra) = @_;
1693 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
1694 my $have_snapshot = (defined $ctype && defined $suffix);
1696 $from = 0 unless defined $from;
1697 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1699 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1701 for (my $i = $from; $i <= $to; $i++) {
1702 my $commit = $revlist->[$i];
1703 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1704 my $ref = format_ref_marker($refs, $commit);
1705 my %co = parse_commit($commit);
1707 print "<tr class=\"dark\">\n";
1709 print "<tr class=\"light\">\n";
1712 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1713 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1714 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1716 print format_subject_html($co{'title'}, $co{'title_short'},
1717 href(action=>"commit", hash=>$commit), $ref);
1719 "<td class=\"link\">" .
1720 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
1721 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff");
1722 if ($have_snapshot) {
1723 print " | " . $cgi->a({-href => href(action=>"snapshot", hash=>$commit)}, "snapshot");
1728 if (defined $extra) {
1730 "<td colspan=\"4\">$extra</td>\n" .
1736 sub git_history_body {
1737 # Warning: assumes constant type (blob or tree) during history
1738 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1740 print "<table class=\"history\" cellspacing=\"0\">\n";
1742 while (my $line = <$fd>) {
1743 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1748 my %co = parse_commit($commit);
1753 my $ref = format_ref_marker($refs, $commit);
1756 print "<tr class=\"dark\">\n";
1758 print "<tr class=\"light\">\n";
1761 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1762 # shortlog uses chop_str($co{'author_name'}, 10)
1763 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1765 # originally git_history used chop_str($co{'title'}, 50)
1766 print format_subject_html($co{'title'}, $co{'title_short'},
1767 href(action=>"commit", hash=>$commit), $ref);
1769 "<td class=\"link\">" .
1770 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
1771 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
1772 $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype);
1774 if ($ftype eq 'blob') {
1775 my $blob_current = git_get_hash_by_path($hash_base, $file_name);
1776 my $blob_parent = git_get_hash_by_path($commit, $file_name);
1777 if (defined $blob_current && defined $blob_parent &&
1778 $blob_current ne $blob_parent) {
1780 $cgi->a({-href => href(action=>"blobdiff", hash=>$blob_current, hash_parent=>$blob_parent,
1781 hash_base=>$commit, file_name=>$file_name)},
1788 if (defined $extra) {
1790 "<td colspan=\"4\">$extra</td>\n" .
1797 # uses global variable $project
1798 my ($taglist, $from, $to, $extra) = @_;
1799 $from = 0 unless defined $from;
1800 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1802 print "<table class=\"tags\" cellspacing=\"0\">\n";
1804 for (my $i = $from; $i <= $to; $i++) {
1805 my $entry = $taglist->[$i];
1807 my $comment_lines = $tag{'comment'};
1808 my $comment = shift @$comment_lines;
1810 if (defined $comment) {
1811 $comment_short = chop_str($comment, 30, 5);
1814 print "<tr class=\"dark\">\n";
1816 print "<tr class=\"light\">\n";
1819 print "<td><i>$tag{'age'}</i></td>\n" .
1821 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),
1822 -class => "list name"}, esc_html($tag{'name'})) .
1825 if (defined $comment) {
1826 print format_subject_html($comment, $comment_short,
1827 href(action=>"tag", hash=>$tag{'id'}));
1830 "<td class=\"selflink\">";
1831 if ($tag{'type'} eq "tag") {
1832 print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag");
1837 "<td class=\"link\">" . " | " .
1838 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'});
1839 if ($tag{'reftype'} eq "commit") {
1840 print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") .
1841 " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'refid'})}, "log");
1842 } elsif ($tag{'reftype'} eq "blob") {
1843 print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw");
1848 if (defined $extra) {
1850 "<td colspan=\"5\">$extra</td>\n" .
1856 sub git_heads_body {
1857 # uses global variable $project
1858 my ($taglist, $head, $from, $to, $extra) = @_;
1859 $from = 0 unless defined $from;
1860 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1862 print "<table class=\"heads\" cellspacing=\"0\">\n";
1864 for (my $i = $from; $i <= $to; $i++) {
1865 my $entry = $taglist->[$i];
1867 my $curr = $tag{'id'} eq $head;
1869 print "<tr class=\"dark\">\n";
1871 print "<tr class=\"light\">\n";
1874 print "<td><i>$tag{'age'}</i></td>\n" .
1875 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
1876 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'}),
1877 -class => "list name"},esc_html($tag{'name'})) .
1879 "<td class=\"link\">" .
1880 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") . " | " .
1881 $cgi->a({-href => href(action=>"log", hash=>$tag{'name'})}, "log") .
1885 if (defined $extra) {
1887 "<td colspan=\"3\">$extra</td>\n" .
1893 ## ----------------------------------------------------------------------
1894 ## functions printing large fragments, format as one of arguments
1896 sub git_diff_print {
1898 my $from_name = shift;
1900 my $to_name = shift;
1901 my $format = shift || "html";
1903 my $from_tmp = "/dev/null";
1904 my $to_tmp = "/dev/null";
1907 # create tmp from-file
1908 if (defined $from) {
1909 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1910 open my $fd2, "> $from_tmp";
1911 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1918 # create tmp to-file
1920 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1921 open my $fd2, "> $to_tmp";
1922 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1929 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1930 if ($format eq "plain") {
1935 while (my $line = <$fd>) {
1937 my $char = substr($line, 0, 1);
1938 my $diff_class = "";
1940 $diff_class = " add";
1941 } elsif ($char eq "-") {
1942 $diff_class = " rem";
1943 } elsif ($char eq "@") {
1944 $diff_class = " chunk_header";
1945 } elsif ($char eq "\\") {
1949 $line = untabify($line);
1950 print "<div class=\"diff$diff_class\">" . esc_html($line) . "</div>\n";
1955 if (defined $from) {
1964 ## ======================================================================
1965 ## ======================================================================
1968 sub git_project_list {
1969 my $order = $cgi->param('o');
1970 if (defined $order && $order !~ m/project|descr|owner|age/) {
1971 die_error(undef, "Unknown order parameter");
1974 my @list = git_get_projects_list();
1977 die_error(undef, "No projects found");
1979 foreach my $pr (@list) {
1980 my $head = git_get_head_hash($pr->{'path'});
1981 if (!defined $head) {
1984 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1985 my %co = parse_commit($head);
1989 $pr->{'commit'} = \%co;
1990 if (!defined $pr->{'descr'}) {
1991 my $descr = git_get_project_description($pr->{'path'}) || "";
1992 $pr->{'descr'} = chop_str($descr, 25, 5);
1994 if (!defined $pr->{'owner'}) {
1995 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
1997 push @projects, $pr;
2001 if (-f $home_text) {
2002 print "<div class=\"index_include\">\n";
2003 open (my $fd, $home_text);
2008 print "<table class=\"project_list\">\n" .
2010 $order ||= "project";
2011 if ($order eq "project") {
2012 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2013 print "<th>Project</th>\n";
2016 $cgi->a({-href => "$my_uri?" . esc_param("o=project"),
2017 -class => "header"}, "Project") .
2020 if ($order eq "descr") {
2021 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2022 print "<th>Description</th>\n";
2025 $cgi->a({-href => "$my_uri?" . esc_param("o=descr"),
2026 -class => "header"}, "Description") .
2029 if ($order eq "owner") {
2030 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2031 print "<th>Owner</th>\n";
2034 $cgi->a({-href => "$my_uri?" . esc_param("o=owner"),
2035 -class => "header"}, "Owner") .
2038 if ($order eq "age") {
2039 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2040 print "<th>Last Change</th>\n";
2043 $cgi->a({-href => "$my_uri?" . esc_param("o=age"),
2044 -class => "header"}, "Last Change") .
2047 print "<th></th>\n" .
2050 foreach my $pr (@projects) {
2052 print "<tr class=\"dark\">\n";
2054 print "<tr class=\"light\">\n";
2057 print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
2058 -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
2059 "<td>" . esc_html($pr->{'descr'}) . "</td>\n" .
2060 "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
2061 print "<td class=\"". age_class($pr->{'commit'}{'age'}) . "\">" .
2062 $pr->{'commit'}{'age_string'} . "</td>\n" .
2063 "<td class=\"link\">" .
2064 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
2065 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
2066 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") .
2075 my $descr = git_get_project_description($project) || "none";
2076 my $head = git_get_head_hash($project);
2077 my %co = parse_commit($head);
2078 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
2080 my $owner = git_get_project_owner($project);
2082 my $refs = git_get_references();
2084 git_print_page_nav('summary','', $head);
2086 print "<div class=\"title\"> </div>\n";
2087 print "<table cellspacing=\"0\">\n" .
2088 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
2089 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2090 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2091 # use per project git URL list in $projectroot/$project/cloneurl
2092 # or make project git URL from git base URL and project name
2093 my $url_tag = "URL";
2094 my @url_list = git_get_project_url_list($project);
2095 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2096 foreach my $git_url (@url_list) {
2097 next unless $git_url;
2098 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2103 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash($project)
2104 or die_error(undef, "Open git-rev-list failed");
2105 my @revlist = map { chomp; $_ } <$fd>;
2107 git_print_header_div('shortlog');
2108 git_shortlog_body(\@revlist, 0, 15, $refs,
2109 $cgi->a({-href => href(action=>"shortlog")}, "..."));
2111 my $taglist = git_get_refs_list("refs/tags");
2112 if (defined @$taglist) {
2113 git_print_header_div('tags');
2114 git_tags_body($taglist, 0, 15,
2115 $cgi->a({-href => href(action=>"tags")}, "..."));
2118 my $headlist = git_get_refs_list("refs/heads");
2119 if (defined @$headlist) {
2120 git_print_header_div('heads');
2121 git_heads_body($headlist, $head, 0, 15,
2122 $cgi->a({-href => href(action=>"heads")}, "..."));
2129 my $head = git_get_head_hash($project);
2131 git_print_page_nav('','', $head,undef,$head);
2132 my %tag = parse_tag($hash);
2133 git_print_header_div('commit', esc_html($tag{'name'}), $hash);
2134 print "<div class=\"title_text\">\n" .
2135 "<table cellspacing=\"0\">\n" .
2137 "<td>object</td>\n" .
2138 "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
2139 $tag{'object'}) . "</td>\n" .
2140 "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
2141 $tag{'type'}) . "</td>\n" .
2143 if (defined($tag{'author'})) {
2144 my %ad = parse_date($tag{'epoch'}, $tag{'tz'});
2145 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
2146 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2147 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2150 print "</table>\n\n" .
2152 print "<div class=\"page_body\">";
2153 my $comment = $tag{'comment'};
2154 foreach my $line (@$comment) {
2155 print esc_html($line) . "<br/>\n";
2165 if (!gitweb_check_feature('blame')) {
2166 die_error('403 Permission denied', "Permission denied");
2168 die_error('404 Not Found', "File name not defined") if (!$file_name);
2169 $hash_base ||= git_get_head_hash($project);
2170 die_error(undef, "Couldn't find base commit") unless ($hash_base);
2171 my %co = parse_commit($hash_base)
2172 or die_error(undef, "Reading commit failed");
2173 if (!defined $hash) {
2174 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
2175 or die_error(undef, "Error looking up file");
2177 $ftype = git_get_type($hash);
2178 if ($ftype !~ "blob") {
2179 die_error("400 Bad Request", "Object is not a blob");
2181 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
2182 or die_error(undef, "Open git-blame failed");
2185 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2188 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
2190 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2191 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2192 git_print_page_path($file_name, $ftype, $hash_base);
2193 my @rev_color = (qw(light2 dark2));
2194 my $num_colors = scalar(@rev_color);
2195 my $current_color = 0;
2198 <div class="page_body">
2199 <table class="blame">
2200 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2203 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2205 my $rev = substr($full_rev, 0, 8);
2209 if (!defined $last_rev) {
2210 $last_rev = $full_rev;
2211 } elsif ($last_rev ne $full_rev) {
2212 $last_rev = $full_rev;
2213 $current_color = ++$current_color % $num_colors;
2215 print "<tr class=\"$rev_color[$current_color]\">\n";
2216 print "<td class=\"sha1\">" .
2217 $cgi->a({-href => href(action=>"commit", hash=>$full_rev, file_name=>$file_name)},
2218 esc_html($rev)) . "</td>\n";
2219 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2220 esc_html($lineno) . "</a></td>\n";
2221 print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
2227 or print "Reading blob failed\n";
2234 if (!gitweb_check_feature('blame')) {
2235 die_error('403 Permission denied', "Permission denied");
2237 die_error('404 Not Found', "File name not defined") if (!$file_name);
2238 $hash_base ||= git_get_head_hash($project);
2239 die_error(undef, "Couldn't find base commit") unless ($hash_base);
2240 my %co = parse_commit($hash_base)
2241 or die_error(undef, "Reading commit failed");
2242 if (!defined $hash) {
2243 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
2244 or die_error(undef, "Error lookup file");
2246 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2247 or die_error(undef, "Open git-annotate failed");
2250 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2253 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
2255 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2256 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2257 git_print_page_path($file_name, 'blob', $hash_base);
2258 print "<div class=\"page_body\">\n";
2260 <table class="blame">
2269 my @line_class = (qw(light dark));
2270 my $line_class_len = scalar (@line_class);
2271 my $line_class_num = $#line_class;
2272 while (my $line = <$fd>) {
2284 $line_class_num = ($line_class_num + 1) % $line_class_len;
2286 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
2293 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
2296 $short_rev = substr ($long_rev, 0, 8);
2297 $age = time () - $time;
2298 $age_str = age_string ($age);
2299 $age_str =~ s/ / /g;
2300 $age_class = age_class($age);
2301 $author = esc_html ($author);
2302 $author =~ s/ / /g;
2304 $data = untabify($data);
2305 $data = esc_html ($data);
2308 <tr class="$line_class[$line_class_num]">
2309 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2310 <td class="$age_class">$age_str</td>
2312 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2313 <td class="pre">$data</td>
2316 } # while (my $line = <$fd>)
2317 print "</table>\n\n";
2319 or print "Reading blob failed.\n";
2325 my $head = git_get_head_hash($project);
2327 git_print_page_nav('','', $head,undef,$head);
2328 git_print_header_div('summary', $project);
2330 my $taglist = git_get_refs_list("refs/tags");
2331 if (defined @$taglist) {
2332 git_tags_body($taglist);
2338 my $head = git_get_head_hash($project);
2340 git_print_page_nav('','', $head,undef,$head);
2341 git_print_header_div('summary', $project);
2343 my $taglist = git_get_refs_list("refs/heads");
2344 if (defined @$taglist) {
2345 git_heads_body($taglist, $head);
2350 sub git_blob_plain {
2351 if (!defined $hash) {
2352 if (defined $file_name) {
2353 my $base = $hash_base || git_get_head_hash($project);
2354 $hash = git_get_hash_by_path($base, $file_name, "blob")
2355 or die_error(undef, "Error lookup file");
2357 die_error(undef, "No file name defined");
2361 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2362 or die_error(undef, "Couldn't cat $file_name, $hash");
2364 $type ||= blob_mimetype($fd, $file_name);
2366 # save as filename, even when no $file_name is given
2367 my $save_as = "$hash";
2368 if (defined $file_name) {
2369 $save_as = $file_name;
2370 } elsif ($type =~ m/^text\//) {
2374 print $cgi->header(-type => "$type",
2375 -content_disposition => "inline; filename=\"$save_as\"");
2377 binmode STDOUT, ':raw';
2379 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
2385 if (!defined $hash) {
2386 if (defined $file_name) {
2387 my $base = $hash_base || git_get_head_hash($project);
2388 $hash = git_get_hash_by_path($base, $file_name, "blob")
2389 or die_error(undef, "Error lookup file");
2391 die_error(undef, "No file name defined");
2394 my $have_blame = gitweb_check_feature('blame');
2395 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2396 or die_error(undef, "Couldn't cat $file_name, $hash");
2397 my $mimetype = blob_mimetype($fd, $file_name);
2398 if ($mimetype !~ m/^text\//) {
2400 return git_blob_plain($mimetype);
2403 my $formats_nav = '';
2404 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2405 if (defined $file_name) {
2408 $cgi->a({-href => href(action=>"blame", hash_base=>$hash_base,
2409 hash=>$hash, file_name=>$file_name)},
2414 $cgi->a({-href => href(action=>"blob_plain",
2415 hash=>$hash, file_name=>$file_name)},
2418 $cgi->a({-href => href(action=>"blob",
2419 hash_base=>"HEAD", file_name=>$file_name)},
2423 $cgi->a({-href => href(action=>"blob_plain", hash=>$hash)}, "plain");
2425 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2426 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2428 print "<div class=\"page_nav\">\n" .
2429 "<br/><br/></div>\n" .
2430 "<div class=\"title\">$hash</div>\n";
2432 git_print_page_path($file_name, "blob", $hash_base);
2433 print "<div class=\"page_body\">\n";
2435 while (my $line = <$fd>) {
2438 $line = untabify($line);
2439 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2440 $nr, $nr, $nr, esc_html($line);
2443 or print "Reading blob failed.\n";
2449 if (!defined $hash) {
2450 $hash = git_get_head_hash($project);
2451 if (defined $file_name) {
2452 my $base = $hash_base || $hash;
2453 $hash = git_get_hash_by_path($base, $file_name, "tree");
2455 if (!defined $hash_base) {
2460 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
2461 or die_error(undef, "Open git-ls-tree failed");
2462 my @entries = map { chomp; $_ } <$fd>;
2463 close $fd or die_error(undef, "Reading tree failed");
2466 my $refs = git_get_references();
2467 my $ref = format_ref_marker($refs, $hash_base);
2471 my $have_blame = gitweb_check_feature('blame');
2472 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2473 $base_key{hash_base} = $hash_base;
2474 git_print_page_nav('tree','', $hash_base);
2475 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
2477 print "<div class=\"page_nav\">\n";
2478 print "<br/><br/></div>\n";
2479 print "<div class=\"title\">$hash</div>\n";
2481 if (defined $file_name) {
2482 $base = esc_html("$file_name/");
2484 git_print_page_path($file_name, 'tree', $hash_base);
2485 print "<div class=\"page_body\">\n";
2486 print "<table cellspacing=\"0\">\n";
2488 foreach my $line (@entries) {
2489 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2490 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2494 my $t_name = validate_input($4);
2496 print "<tr class=\"dark\">\n";
2498 print "<tr class=\"light\">\n";
2501 print "<td class=\"mode\">" . mode_str($t_mode) . "</td>\n";
2502 if ($t_type eq "blob") {
2503 print "<td class=\"list\">" .
2504 $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key),
2505 -class => "list"}, esc_html($t_name)) .
2507 "<td class=\"link\">" .
2508 $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2512 $cgi->a({-href => href(action=>"blame", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2516 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
2517 hash=>$t_hash, file_name=>"$base$t_name")},
2520 $cgi->a({-href => href(action=>"blob_plain",
2521 hash=>$t_hash, file_name=>"$base$t_name")},
2524 } elsif ($t_type eq "tree") {
2525 print "<td class=\"list\">" .
2526 $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2527 esc_html($t_name)) .
2529 "<td class=\"link\">" .
2530 $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2533 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, file_name=>"$base$t_name")},
2539 print "</table>\n" .
2546 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
2547 my $have_snapshot = (defined $ctype && defined $suffix);
2548 if (!$have_snapshot) {
2549 die_error('403 Permission denied', "Permission denied");
2552 if (!defined $hash) {
2553 $hash = git_get_head_hash($project);
2556 my $filename = basename($project) . "-$hash.tar.$suffix";
2558 print $cgi->header(-type => 'application/x-tar',
2559 -content_encoding => $ctype,
2560 -content_disposition => "inline; filename=\"$filename\"",
2561 -status => '200 OK');
2563 open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | $command" or
2564 die_error(undef, "Execute git-tar-tree failed.");
2565 binmode STDOUT, ':raw';
2567 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
2573 my $head = git_get_head_hash($project);
2574 if (!defined $hash) {
2577 if (!defined $page) {
2580 my $refs = git_get_references();
2582 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2583 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2584 or die_error(undef, "Open git-rev-list failed");
2585 my @revlist = map { chomp; $_ } <$fd>;
2588 my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#revlist);
2591 git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
2594 my %co = parse_commit($hash);
2596 git_print_header_div('summary', $project);
2597 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2599 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2600 my $commit = $revlist[$i];
2601 my $ref = format_ref_marker($refs, $commit);
2602 my %co = parse_commit($commit);
2604 my %ad = parse_date($co{'author_epoch'});
2605 git_print_header_div('commit',
2606 "<span class=\"age\">$co{'age_string'}</span>" .
2607 esc_html($co{'title'}) . $ref,
2609 print "<div class=\"title_text\">\n" .
2610 "<div class=\"log_link\">\n" .
2611 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
2613 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
2616 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2619 print "<div class=\"log_body\">\n";
2620 git_print_simplified_log($co{'comment'});
2627 my %co = parse_commit($hash);
2629 die_error(undef, "Unknown commit object");
2631 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
2632 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
2634 my $parent = $co{'parent'};
2635 if (!defined $parent) {
2638 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
2639 or die_error(undef, "Open git-diff-tree failed");
2640 my @difftree = map { chomp; $_ } <$fd>;
2641 close $fd or die_error(undef, "Reading git-diff-tree failed");
2643 # non-textual hash id's can be cached
2645 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2648 my $refs = git_get_references();
2649 my $ref = format_ref_marker($refs, $co{'id'});
2651 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
2652 my $have_snapshot = (defined $ctype && defined $suffix);
2654 my $formats_nav = '';
2655 if (defined $file_name && defined $co{'parent'}) {
2656 my $parent = $co{'parent'};
2658 $cgi->a({-href => href(action=>"blame", hash_parent=>$parent, file_name=>$file_name)},
2661 git_header_html(undef, $expires);
2662 git_print_page_nav('commit', defined $co{'parent'} ? '' : 'commitdiff',
2663 $hash, $co{'tree'}, $hash,
2666 if (defined $co{'parent'}) {
2667 git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash);
2669 git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash);
2671 print "<div class=\"title_text\">\n" .
2672 "<table cellspacing=\"0\">\n";
2673 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
2675 "<td></td><td> $ad{'rfc2822'}";
2676 if ($ad{'hour_local'} < 6) {
2677 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2678 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2680 printf(" (%02d:%02d %s)",
2681 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2685 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
2686 print "<tr><td></td><td> $cd{'rfc2822'}" .
2687 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2689 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2692 "<td class=\"sha1\">" .
2693 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),
2694 class => "list"}, $co{'tree'}) .
2696 "<td class=\"link\">" .
2697 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},
2699 if ($have_snapshot) {
2701 $cgi->a({-href => href(action=>"snapshot", hash=>$hash)}, "snapshot");
2705 my $parents = $co{'parents'};
2706 foreach my $par (@$parents) {
2709 "<td class=\"sha1\">" .
2710 $cgi->a({-href => href(action=>"commit", hash=>$par),
2711 class => "list"}, $par) .
2713 "<td class=\"link\">" .
2714 $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") .
2716 $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "commitdiff") .
2723 print "<div class=\"page_body\">\n";
2724 git_print_log($co{'comment'});
2727 git_difftree_body(\@difftree, $hash, $parent);
2733 mkdir($git_temp, 0700);
2735 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2737 $cgi->a({-href => href(action=>"blobdiff_plain",
2738 hash=>$hash, hash_parent=>$hash_parent)},
2740 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2741 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2744 <div class="page_nav"><br/><br/></div>
2745 <div class="title">$hash vs $hash_parent</div>
2748 git_print_page_path($file_name, "blob", $hash_base);
2749 print "<div class=\"page_body\">\n" .
2750 "<div class=\"diff_info\">blob:" .
2751 $cgi->a({-href => href(action=>"blob", hash=>$hash_parent,
2752 hash_base=>$hash_base, file_name=>($file_parent || $file_name))},
2755 $cgi->a({-href => href(action=>"blob", hash=>$hash,
2756 hash_base=>$hash_base, file_name=>$file_name)},
2759 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2760 print "</div>"; # page_body
2764 sub git_blobdiff_plain {
2765 mkdir($git_temp, 0700);
2766 print $cgi->header(-type => "text/plain", -charset => 'utf-8');
2767 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2770 sub git_commitdiff {
2771 my $format = shift || 'html';
2772 my %co = parse_commit($hash);
2774 die_error(undef, "Unknown commit object");
2776 if (!defined $hash_parent) {
2777 $hash_parent = $co{'parent'} || '--root';
2783 if ($format eq 'html') {
2784 open $fd, "-|", $GIT, "diff-tree", '-r', '-M', '-C',
2785 "--patch-with-raw", "--full-index", $hash_parent, $hash
2786 or die_error(undef, "Open git-diff-tree failed");
2788 while (chomp(my $line = <$fd>)) {
2789 # empty line ends raw part of diff-tree output
2791 push @difftree, $line;
2794 } elsif ($format eq 'plain') {
2795 open $fd, "-|", $GIT, "diff-tree", '-r', '-p', '-B', $hash_parent, $hash
2796 or die_error(undef, "Open git-diff-tree failed");
2799 die_error(undef, "Unknown commitdiff format");
2802 # non-textual hash id's can be cached
2804 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2808 # write commit message
2809 if ($format eq 'html') {
2810 my $refs = git_get_references();
2811 my $ref = format_ref_marker($refs, $co{'id'});
2813 $cgi->a({-href => href(action=>"commitdiff_plain",
2814 hash=>$hash, hash_parent=>$hash_parent)},
2817 git_header_html(undef, $expires);
2818 git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2819 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
2820 print "<div class=\"page_body\">\n";
2821 print "<div class=\"log\">\n";
2822 git_print_simplified_log($co{'comment'}, 1); # skip title
2823 print "</div>\n"; # class="log"
2825 } elsif ($format eq 'plain') {
2826 my $refs = git_get_references("tags");
2828 if (exists $refs->{$hash}) {
2829 @tagnames = map { s|^tags/|| } $refs->{$hash};
2831 my $filename = basename($project) . "-$hash.patch";
2834 -type => 'text/plain',
2835 -charset => 'utf-8',
2836 -expires => $expires,
2837 -content_disposition => qq(inline; filename="$filename"));
2838 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
2841 Date: $ad{'rfc2822'} ($ad{'tz_local'})
2842 Subject: $co{'title'}
2844 foreach my $tag (@tagnames) {
2845 print "X-Git-Tag: $tag\n";
2847 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
2848 foreach my $line (@{$co{'comment'}}) {
2855 if ($format eq 'html') {
2856 #git_difftree_body(\@difftree, $hash, $hash_parent);
2859 git_patchset_body($fd, \@difftree, $hash, $hash_parent);
2861 print "</div>\n"; # class="page_body"
2864 } elsif ($format eq 'plain') {
2868 or print "Reading git-diff-tree failed\n";
2872 sub git_commitdiff_plain {
2873 git_commitdiff('plain');
2877 if (!defined $hash_base) {
2878 $hash_base = git_get_head_hash($project);
2881 my %co = parse_commit($hash_base);
2883 die_error(undef, "Unknown commit object");
2885 my $refs = git_get_references();
2887 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base);
2888 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2889 if (!defined $hash && defined $file_name) {
2890 $hash = git_get_hash_by_path($hash_base, $file_name);
2892 if (defined $hash) {
2893 $ftype = git_get_type($hash);
2895 git_print_page_path($file_name, $ftype, $hash_base);
2898 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2899 git_history_body($fd, $refs, $hash_base, $ftype);
2906 if (!defined $searchtext) {
2907 die_error(undef, "Text field empty");
2909 if (!defined $hash) {
2910 $hash = git_get_head_hash($project);
2912 my %co = parse_commit($hash);
2914 die_error(undef, "Unknown commit object");
2916 # pickaxe may take all resources of your box and run for several minutes
2917 # with every query - so decide by yourself how public you make this feature :)
2918 my $commit_search = 1;
2919 my $author_search = 0;
2920 my $committer_search = 0;
2921 my $pickaxe_search = 0;
2922 if ($searchtext =~ s/^author\\://i) {
2924 } elsif ($searchtext =~ s/^committer\\://i) {
2925 $committer_search = 1;
2926 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2928 $pickaxe_search = 1;
2931 git_print_page_nav('','', $hash,$co{'tree'},$hash);
2932 git_print_header_div('commit', esc_html($co{'title'}), $hash);
2934 print "<table cellspacing=\"0\">\n";
2936 if ($commit_search) {
2938 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2939 while (my $commit_text = <$fd>) {
2940 if (!grep m/$searchtext/i, $commit_text) {
2943 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2946 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2949 my @commit_lines = split "\n", $commit_text;
2950 my %co = parse_commit(undef, \@commit_lines);
2955 print "<tr class=\"dark\">\n";
2957 print "<tr class=\"light\">\n";
2960 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2961 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2963 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"},
2964 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
2965 my $comment = $co{'comment'};
2966 foreach my $line (@$comment) {
2967 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2968 my $lead = esc_html($1) || "";
2969 $lead = chop_str($lead, 30, 10);
2970 my $match = esc_html($2) || "";
2971 my $trail = esc_html($3) || "";
2972 $trail = chop_str($trail, 30, 10);
2973 my $text = "$lead<span class=\"match\">$match</span>$trail";
2974 print chop_str($text, 80, 5) . "<br/>\n";
2978 "<td class=\"link\">" .
2979 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
2981 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
2988 if ($pickaxe_search) {
2990 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2993 while (my $line = <$fd>) {
2994 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2997 $set{'from_id'} = $3;
2999 $set{'id'} = $set{'to_id'};
3000 if ($set{'id'} =~ m/0{40}/) {
3001 $set{'id'} = $set{'from_id'};
3003 if ($set{'id'} =~ m/0{40}/) {
3007 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3010 print "<tr class=\"dark\">\n";
3012 print "<tr class=\"light\">\n";
3015 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3016 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3018 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
3019 -class => "list subject"},
3020 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
3021 while (my $setref = shift @files) {
3023 print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},
3024 hash=>$set{'id'}, file_name=>$set{'file'}),
3026 "<span class=\"match\">" . esc_html($set{'file'}) . "</span>") .
3030 "<td class=\"link\">" .
3031 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
3033 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
3037 %co = parse_commit($1);
3047 my $head = git_get_head_hash($project);
3048 if (!defined $hash) {
3051 if (!defined $page) {
3054 my $refs = git_get_references();
3056 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3057 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
3058 or die_error(undef, "Open git-rev-list failed");
3059 my @revlist = map { chomp; $_ } <$fd>;
3062 my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, $#revlist);
3064 if ($#revlist >= (100 * ($page+1)-1)) {
3066 $cgi->a({-href => href(action=>"shortlog", hash=>$hash, page=>$page+1),
3067 -title => "Alt-n"}, "next");
3072 git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);
3073 git_print_header_div('summary', $project);
3075 git_shortlog_body(\@revlist, ($page * 100), $#revlist, $refs, $next_link);
3080 ## ......................................................................
3081 ## feeds (RSS, OPML)
3084 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3085 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash($project)
3086 or die_error(undef, "Open git-rev-list failed");
3087 my @revlist = map { chomp; $_ } <$fd>;
3088 close $fd or die_error(undef, "Reading git-rev-list failed");
3089 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
3091 <?xml version="1.0" encoding="utf-8"?>
3092 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3094 <title>$project $my_uri $my_url</title>
3095 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3096 <description>$project log</description>
3097 <language>en</language>
3100 for (my $i = 0; $i <= $#revlist; $i++) {
3101 my $commit = $revlist[$i];
3102 my %co = parse_commit($commit);
3103 # we read 150, we always show 30 and the ones more recent than 48 hours
3104 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3107 my %cd = parse_date($co{'committer_epoch'});
3108 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
3109 my @difftree = map { chomp; $_ } <$fd>;
3113 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) .
3115 "<author>" . esc_html($co{'author'}) . "</author>\n" .
3116 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3117 "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3118 "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3119 "<description>" . esc_html($co{'title'}) . "</description>\n" .
3120 "<content:encoded>" .
3122 my $comment = $co{'comment'};
3123 foreach my $line (@$comment) {
3124 $line = decode("utf8", $line, Encode::FB_DEFAULT);
3125 print "$line<br/>\n";
3128 foreach my $line (@difftree) {
3129 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3132 my $file = validate_input(unquote($7));
3133 $file = decode("utf8", $file, Encode::FB_DEFAULT);
3134 print "$file<br/>\n";
3137 "</content:encoded>\n" .
3140 print "</channel></rss>";
3144 my @list = git_get_projects_list();
3146 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
3148 <?xml version="1.0" encoding="utf-8"?>
3149 <opml version="1.0">
3151 <title>$site_name Git OPML Export</title>
3154 <outline text="git RSS feeds">
3157 foreach my $pr (@list) {
3159 my $head = git_get_head_hash($proj{'path'});
3160 if (!defined $head) {
3163 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
3164 my %co = parse_commit($head);
3169 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
3170 my $rss = "$my_url?p=$proj{'path'};a=rss";
3171 my $html = "$my_url?p=$proj{'path'};a=summary";
3172 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";