3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI qw(:standard :escapeHTML -nosticky);
13 use CGI::Util qw(unescape);
14 use CGI::Carp qw(fatalsToBrowser);
18 use File::Basename qw(basename);
19 binmode STDOUT, ':utf8';
22 our $version = "++GIT_VERSION++";
23 our $my_url = $cgi->url();
24 our $my_uri = $cgi->url(-absolute => 1);
26 # core git executable to use
27 # this can just be "git" if your webserver has a sensible PATH
28 our $GIT = "++GIT_BINDIR++/git";
30 # absolute fs-path which will be prepended to the project path
31 #our $projectroot = "/pub/scm";
32 our $projectroot = "++GITWEB_PROJECTROOT++";
34 # target of the home link on top of all pages
35 our $home_link = $my_uri || "/";
37 # string of the home link on top of all pages
38 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
40 # name of your site or organization to appear in page titles
41 # replace this with something more descriptive for clearer bookmarks
42 our $site_name = "++GITWEB_SITENAME++" || $ENV{'SERVER_NAME'} || "Untitled";
44 # html text to include at home page
45 our $home_text = "++GITWEB_HOMETEXT++";
47 # URI of default stylesheet
48 our $stylesheet = "++GITWEB_CSS++";
50 our $logo = "++GITWEB_LOGO++";
51 # URI of GIT favicon, assumed to be image/png type
52 our $favicon = "++GITWEB_FAVICON++";
54 # source of projects list
55 our $projects_list = "++GITWEB_LIST++";
57 # list of git base URLs used for URL to where fetch project from,
58 # i.e. full URL is "$git_base_url/$project"
59 our @git_base_url_list = ("++GITWEB_BASE_URL++");
61 # default blob_plain mimetype and default charset for text/plain blob
62 our $default_blob_plain_mimetype = 'text/plain';
63 our $default_text_plain_charset = undef;
65 # file to use for guessing MIME types before trying /etc/mime.types
66 # (relative to the current git repository)
67 our $mimetypes_file = undef;
69 # You define site-wide feature defaults here; override them with
70 # $GITWEB_CONFIG as necessary.
73 # 'sub' => feature-sub (subroutine),
74 # 'override' => allow-override (boolean),
75 # 'default' => [ default options...] (array reference)}
77 # if feature is overridable (it means that allow-override has true value,
78 # then feature-sub will be called with default options as parameters;
79 # return value of feature-sub indicates if to enable specified feature
81 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
84 'sub' => \&feature_blame,
89 'sub' => \&feature_snapshot,
91 # => [content-encoding, suffix, program]
92 'default' => ['x-gzip', 'gz', 'gzip']},
95 'sub' => \&feature_pickaxe,
100 sub gitweb_check_feature {
102 return undef unless exists $feature{$name};
103 my ($sub, $override, @defaults) = (
104 $feature{$name}{'sub'},
105 $feature{$name}{'override'},
106 @{$feature{$name}{'default'}});
107 if (!$override) { return @defaults; }
108 return $sub->(@defaults);
111 # To enable system wide have in $GITWEB_CONFIG
112 # $feature{'blame'}{'default'} = [1];
113 # To have project specific config enable override in $GITWEB_CONFIG
114 # $feature{'blame'}{'override'} = 1;
115 # and in project config gitweb.blame = 0|1;
118 my ($val) = git_get_project_config('blame', '--bool');
120 if ($val eq 'true') {
122 } elsif ($val eq 'false') {
129 # To disable system wide have in $GITWEB_CONFIG
130 # $feature{'snapshot'}{'default'} = [undef];
131 # To have project specific config enable override in $GITWEB_CONFIG
132 # $feature{'blame'}{'override'} = 1;
133 # and in project config gitweb.snapshot = none|gzip|bzip2
135 sub feature_snapshot {
136 my ($ctype, $suffix, $command) = @_;
138 my ($val) = git_get_project_config('snapshot');
140 if ($val eq 'gzip') {
141 return ('x-gzip', 'gz', 'gzip');
142 } elsif ($val eq 'bzip2') {
143 return ('x-bzip2', 'bz2', 'bzip2');
144 } elsif ($val eq 'none') {
148 return ($ctype, $suffix, $command);
151 # To enable system wide have in $GITWEB_CONFIG
152 # $feature{'pickaxe'}{'default'} = [1];
153 # To have project specific config enable override in $GITWEB_CONFIG
154 # $feature{'pickaxe'}{'override'} = 1;
155 # and in project config gitweb.pickaxe = 0|1;
157 sub feature_pickaxe {
158 my ($val) = git_get_project_config('pickaxe', '--bool');
160 if ($val eq 'true') {
162 } elsif ($val eq 'false') {
169 # rename detection options for git-diff and git-diff-tree
170 # - default is '-M', with the cost proportional to
171 # (number of removed files) * (number of new files).
172 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
173 # (number of changed files + number of removed files) * (number of new files)
174 # - even more costly is '-C', '--find-copies-harder' with cost
175 # (number of files in the original tree) * (number of new files)
176 # - one might want to include '-B' option, e.g. '-B', '-M'
177 our @diff_opts = ('-M'); # taken from git_commit
179 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
180 do $GITWEB_CONFIG if -e $GITWEB_CONFIG;
182 # version of the core git binary
183 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
185 # path to the current git repository
188 $projects_list ||= $projectroot;
190 # ======================================================================
191 # input validation and dispatch
192 our $action = $cgi->param('a');
193 if (defined $action) {
194 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
195 die_error(undef, "Invalid action parameter");
199 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
200 if (defined $project) {
203 $project = undef unless $project;
205 if (defined $project) {
206 if (!validate_input($project)) {
207 die_error(undef, "Invalid project parameter");
209 if (!(-d "$projectroot/$project")) {
210 die_error(undef, "No such directory");
212 if (!(-e "$projectroot/$project/HEAD")) {
213 die_error(undef, "No such project");
215 $git_dir = "$projectroot/$project";
218 our $file_name = $cgi->param('f');
219 if (defined $file_name) {
220 if (!validate_input($file_name)) {
221 die_error(undef, "Invalid file parameter");
225 our $file_parent = $cgi->param('fp');
226 if (defined $file_parent) {
227 if (!validate_input($file_parent)) {
228 die_error(undef, "Invalid file parent parameter");
232 our $hash = $cgi->param('h');
234 if (!validate_input($hash)) {
235 die_error(undef, "Invalid hash parameter");
239 our $hash_parent = $cgi->param('hp');
240 if (defined $hash_parent) {
241 if (!validate_input($hash_parent)) {
242 die_error(undef, "Invalid hash parent parameter");
246 our $hash_base = $cgi->param('hb');
247 if (defined $hash_base) {
248 if (!validate_input($hash_base)) {
249 die_error(undef, "Invalid hash base parameter");
253 our $hash_parent_base = $cgi->param('hpb');
254 if (defined $hash_parent_base) {
255 if (!validate_input($hash_parent_base)) {
256 die_error(undef, "Invalid hash parent base parameter");
260 our $page = $cgi->param('pg');
262 if ($page =~ m/[^0-9]$/) {
263 die_error(undef, "Invalid page parameter");
267 our $searchtext = $cgi->param('s');
268 if (defined $searchtext) {
269 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) {
270 die_error(undef, "Invalid search parameter");
272 $searchtext = quotemeta $searchtext;
277 "blame" => \&git_blame2,
278 "blobdiff" => \&git_blobdiff,
279 "blobdiff_plain" => \&git_blobdiff_plain,
280 "blob" => \&git_blob,
281 "blob_plain" => \&git_blob_plain,
282 "commitdiff" => \&git_commitdiff,
283 "commitdiff_plain" => \&git_commitdiff_plain,
284 "commit" => \&git_commit,
285 "heads" => \&git_heads,
286 "history" => \&git_history,
289 "search" => \&git_search,
290 "shortlog" => \&git_shortlog,
291 "summary" => \&git_summary,
293 "tags" => \&git_tags,
294 "tree" => \&git_tree,
295 "snapshot" => \&git_snapshot,
296 # those below don't need $project
297 "opml" => \&git_opml,
298 "project_list" => \&git_project_list,
299 "project_index" => \&git_project_index,
302 if (defined $project) {
303 $action ||= 'summary';
305 $action ||= 'project_list';
307 if (!defined($actions{$action})) {
308 die_error(undef, "Unknown action");
310 $actions{$action}->();
313 ## ======================================================================
327 hash_parent_base => "hpb",
331 my %mapping = @mapping;
333 $params{"project"} ||= $project;
336 for (my $i = 0; $i < @mapping; $i += 2) {
337 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
338 if (defined $params{$name}) {
339 push @result, $symbol . "=" . esc_param($params{$name});
342 return "$my_uri?" . join(';', @result);
346 ## ======================================================================
347 ## validation, quoting/unquoting and escaping
352 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
355 if ($input =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
358 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\-\+\#\~\%]/) {
364 # quote unsafe chars, but keep the slash, even when it's not
365 # correct, but quoted slashes look too horrible in bookmarks
368 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
374 # replace invalid utf8 character with SUBSTITUTION sequence
377 $str = decode("utf8", $str, Encode::FB_DEFAULT);
378 $str = escapeHTML($str);
379 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
383 # git may return quoted and escaped filenames
386 if ($str =~ m/^"(.*)"$/) {
388 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
393 # escape tabs (convert tabs to spaces)
397 while ((my $pos = index($line, "\t")) != -1) {
398 if (my $count = (8 - ($pos % 8))) {
399 my $spaces = ' ' x $count;
400 $line =~ s/\t/$spaces/;
407 ## ----------------------------------------------------------------------
408 ## HTML aware string manipulation
413 my $add_len = shift || 10;
415 # allow only $len chars, but don't cut a word if it would fit in $add_len
416 # if it doesn't fit, cut it if it's still longer than the dots we would add
417 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
420 if (length($tail) > 4) {
422 $body =~ s/&[^;]*$//; # remove chopped character entities
427 ## ----------------------------------------------------------------------
428 ## functions returning short strings
430 # CSS class for given age value (in seconds)
434 if ($age < 60*60*2) {
436 } elsif ($age < 60*60*24*2) {
443 # convert age in seconds to "nn units ago" string
448 if ($age > 60*60*24*365*2) {
449 $age_str = (int $age/60/60/24/365);
450 $age_str .= " years ago";
451 } elsif ($age > 60*60*24*(365/12)*2) {
452 $age_str = int $age/60/60/24/(365/12);
453 $age_str .= " months ago";
454 } elsif ($age > 60*60*24*7*2) {
455 $age_str = int $age/60/60/24/7;
456 $age_str .= " weeks ago";
457 } elsif ($age > 60*60*24*2) {
458 $age_str = int $age/60/60/24;
459 $age_str .= " days ago";
460 } elsif ($age > 60*60*2) {
461 $age_str = int $age/60/60;
462 $age_str .= " hours ago";
463 } elsif ($age > 60*2) {
464 $age_str = int $age/60;
465 $age_str .= " min ago";
468 $age_str .= " sec ago";
470 $age_str .= " right now";
475 # convert file mode in octal to symbolic file mode string
477 my $mode = oct shift;
479 if (S_ISDIR($mode & S_IFMT)) {
481 } elsif (S_ISLNK($mode)) {
483 } elsif (S_ISREG($mode)) {
484 # git cares only about the executable bit
485 if ($mode & S_IXUSR) {
495 # convert file mode in octal to file type string
499 if ($mode !~ m/^[0-7]+$/) {
505 if (S_ISDIR($mode & S_IFMT)) {
507 } elsif (S_ISLNK($mode)) {
509 } elsif (S_ISREG($mode)) {
516 ## ----------------------------------------------------------------------
517 ## functions returning short HTML fragments, or transforming HTML fragments
518 ## which don't beling to other sections
520 # format line of commit message or tag comment
521 sub format_log_line_html {
524 $line = esc_html($line);
525 $line =~ s/ / /g;
526 if ($line =~ m/([0-9a-fA-F]{40})/) {
528 if (git_get_type($hash_text) eq "commit") {
530 $cgi->a({-href => href(action=>"commit", hash=>$hash_text),
531 -class => "text"}, $hash_text);
532 $line =~ s/$hash_text/$link/;
538 # format marker of refs pointing to given object
539 sub format_ref_marker {
540 my ($refs, $id) = @_;
543 if (defined $refs->{$id}) {
544 foreach my $ref (@{$refs->{$id}}) {
545 my ($type, $name) = qw();
546 # e.g. tags/v2.6.11 or heads/next
547 if ($ref =~ m!^(.*?)s?/(.*)$!) {
555 $markers .= " <span class=\"$type\">" . esc_html($name) . "</span>";
560 return ' <span class="refs">'. $markers . '</span>';
566 # format, perhaps shortened and with markers, title line
567 sub format_subject_html {
568 my ($long, $short, $href, $extra) = @_;
569 $extra = '' unless defined($extra);
571 if (length($short) < length($long)) {
572 return $cgi->a({-href => $href, -class => "list subject",
574 esc_html($short) . $extra);
576 return $cgi->a({-href => $href, -class => "list subject"},
577 esc_html($long) . $extra);
581 sub format_diff_line {
583 my $char = substr($line, 0, 1);
589 $diff_class = " add";
590 } elsif ($char eq "-") {
591 $diff_class = " rem";
592 } elsif ($char eq "@") {
593 $diff_class = " chunk_header";
594 } elsif ($char eq "\\") {
595 $diff_class = " incomplete";
597 $line = untabify($line);
598 return "<div class=\"diff$diff_class\">" . esc_html($line) . "</div>\n";
601 ## ----------------------------------------------------------------------
602 ## git utility subroutines, invoking git commands
604 # returns path to the core git executable and the --git-dir parameter as list
606 return $GIT, '--git-dir='.$git_dir;
609 # returns path to the core git executable and the --git-dir parameter as string
611 return join(' ', git_cmd());
614 # get HEAD ref of given project as hash
615 sub git_get_head_hash {
617 my $o_git_dir = $git_dir;
619 $git_dir = "$projectroot/$project";
620 if (open my $fd, "-|", git_cmd(), "rev-parse", "--verify", "HEAD") {
623 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
627 if (defined $o_git_dir) {
628 $git_dir = $o_git_dir;
633 # get type of given object
637 open my $fd, "-|", git_cmd(), "cat-file", '-t', $hash or return;
644 sub git_get_project_config {
645 my ($key, $type) = @_;
647 return unless ($key);
648 $key =~ s/^gitweb\.//;
649 return if ($key =~ m/\W/);
651 my @x = (git_cmd(), 'repo-config');
652 if (defined $type) { push @x, $type; }
654 push @x, "gitweb.$key";
660 # get hash of given path at given ref
661 sub git_get_hash_by_path {
663 my $path = shift || return undef;
667 open my $fd, "-|", git_cmd(), "ls-tree", $base, "--", $path
668 or die_error(undef, "Open git-ls-tree failed");
670 close $fd or return undef;
672 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
673 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
677 ## ......................................................................
678 ## git utility functions, directly accessing git repository
680 sub git_get_project_description {
683 open my $fd, "$projectroot/$path/description" or return undef;
690 sub git_get_project_url_list {
693 open my $fd, "$projectroot/$path/cloneurl" or return undef;
694 my @git_project_url_list = map { chomp; $_ } <$fd>;
697 return wantarray ? @git_project_url_list : \@git_project_url_list;
700 sub git_get_projects_list {
703 if (-d $projects_list) {
704 # search in directory
705 my $dir = $projects_list;
706 my $pfxlen = length("$dir");
709 follow_fast => 1, # follow symbolic links
710 dangling_symlinks => 0, # ignore dangling symlinks, silently
712 # skip project-list toplevel, if we get it.
713 return if (m!^[/.]$!);
714 # only directories can be git repositories
715 return unless (-d $_);
717 my $subdir = substr($File::Find::name, $pfxlen + 1);
718 # we check related file in $projectroot
719 if (-e "$projectroot/$subdir/HEAD") {
720 push @list, { path => $subdir };
721 $File::Find::prune = 1;
726 } elsif (-f $projects_list) {
727 # read from file(url-encoded):
728 # 'git%2Fgit.git Linus+Torvalds'
729 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
730 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
731 open my ($fd), $projects_list or return undef;
732 while (my $line = <$fd>) {
734 my ($path, $owner) = split ' ', $line;
735 $path = unescape($path);
736 $owner = unescape($owner);
737 if (!defined $path) {
740 if (-e "$projectroot/$path/HEAD") {
743 owner => decode("utf8", $owner, Encode::FB_DEFAULT),
750 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
754 sub git_get_project_owner {
758 return undef unless $project;
760 # read from file (url-encoded):
761 # 'git%2Fgit.git Linus+Torvalds'
762 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
763 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
764 if (-f $projects_list) {
765 open (my $fd , $projects_list);
766 while (my $line = <$fd>) {
768 my ($pr, $ow) = split ' ', $line;
771 if ($pr eq $project) {
772 $owner = decode("utf8", $ow, Encode::FB_DEFAULT);
778 if (!defined $owner) {
779 $owner = get_file_owner("$projectroot/$project");
785 sub git_get_references {
786 my $type = shift || "";
789 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
790 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
791 if (-f "$projectroot/$project/info/refs") {
792 open $fd, "$projectroot/$project/info/refs"
795 open $fd, "-|", git_cmd(), "ls-remote", "."
799 while (my $line = <$fd>) {
801 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?[^\^]+)/) {
802 if (defined $refs{$1}) {
803 push @{$refs{$1}}, $2;
813 sub git_get_rev_name_tags {
814 my $hash = shift || return undef;
816 open my $fd, "-|", git_cmd(), "name-rev", "--tags", $hash
818 my $name_rev = <$fd>;
821 if ($name_rev =~ m|^$hash tags/(.*)$|) {
824 # catches also '$hash undefined' output
829 ## ----------------------------------------------------------------------
830 ## parse to hash functions
834 my $tz = shift || "-0000";
837 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
838 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
839 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
840 $date{'hour'} = $hour;
841 $date{'minute'} = $min;
842 $date{'mday'} = $mday;
843 $date{'day'} = $days[$wday];
844 $date{'month'} = $months[$mon];
845 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
846 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
847 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
848 $mday, $months[$mon], $hour ,$min;
850 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
851 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
852 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
853 $date{'hour_local'} = $hour;
854 $date{'minute_local'} = $min;
855 $date{'tz_local'} = $tz;
864 open my $fd, "-|", git_cmd(), "cat-file", "tag", $tag_id or return;
865 $tag{'id'} = $tag_id;
866 while (my $line = <$fd>) {
868 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
870 } elsif ($line =~ m/^type (.+)$/) {
872 } elsif ($line =~ m/^tag (.+)$/) {
874 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
878 } elsif ($line =~ m/--BEGIN/) {
879 push @comment, $line;
881 } elsif ($line eq "") {
885 push @comment, <$fd>;
886 $tag{'comment'} = \@comment;
888 if (!defined $tag{'name'}) {
895 my $commit_id = shift;
896 my $commit_text = shift;
901 if (defined $commit_text) {
902 @commit_lines = @$commit_text;
905 open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
907 @commit_lines = split '\n', <$fd>;
912 my $header = shift @commit_lines;
913 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
916 ($co{'id'}, my @parents) = split ' ', $header;
917 $co{'parents'} = \@parents;
918 $co{'parent'} = $parents[0];
919 while (my $line = shift @commit_lines) {
920 last if $line eq "\n";
921 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
923 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
925 $co{'author_epoch'} = $2;
926 $co{'author_tz'} = $3;
927 if ($co{'author'} =~ m/^([^<]+) </) {
928 $co{'author_name'} = $1;
930 $co{'author_name'} = $co{'author'};
932 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
933 $co{'committer'} = $1;
934 $co{'committer_epoch'} = $2;
935 $co{'committer_tz'} = $3;
936 $co{'committer_name'} = $co{'committer'};
937 $co{'committer_name'} =~ s/ <.*//;
940 if (!defined $co{'tree'}) {
944 foreach my $title (@commit_lines) {
947 $co{'title'} = chop_str($title, 80, 5);
948 # remove leading stuff of merges to make the interesting part visible
949 if (length($title) > 50) {
950 $title =~ s/^Automatic //;
951 $title =~ s/^merge (of|with) /Merge ... /i;
952 if (length($title) > 50) {
953 $title =~ s/(http|rsync):\/\///;
955 if (length($title) > 50) {
956 $title =~ s/(master|www|rsync)\.//;
958 if (length($title) > 50) {
959 $title =~ s/kernel.org:?//;
961 if (length($title) > 50) {
962 $title =~ s/\/pub\/scm//;
965 $co{'title_short'} = chop_str($title, 50, 5);
969 # remove added spaces
970 foreach my $line (@commit_lines) {
973 $co{'comment'} = \@commit_lines;
975 my $age = time - $co{'committer_epoch'};
977 $co{'age_string'} = age_string($age);
978 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
979 if ($age > 60*60*24*7*2) {
980 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
981 $co{'age_string_age'} = $co{'age_string'};
983 $co{'age_string_date'} = $co{'age_string'};
984 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
989 # parse ref from ref_file, given by ref_id, with given type
991 my $ref_file = shift;
993 my $type = shift || git_get_type($ref_id);
996 $ref_item{'type'} = $type;
997 $ref_item{'id'} = $ref_id;
998 $ref_item{'epoch'} = 0;
999 $ref_item{'age'} = "unknown";
1000 if ($type eq "tag") {
1001 my %tag = parse_tag($ref_id);
1002 $ref_item{'comment'} = $tag{'comment'};
1003 if ($tag{'type'} eq "commit") {
1004 my %co = parse_commit($tag{'object'});
1005 $ref_item{'epoch'} = $co{'committer_epoch'};
1006 $ref_item{'age'} = $co{'age_string'};
1007 } elsif (defined($tag{'epoch'})) {
1008 my $age = time - $tag{'epoch'};
1009 $ref_item{'epoch'} = $tag{'epoch'};
1010 $ref_item{'age'} = age_string($age);
1012 $ref_item{'reftype'} = $tag{'type'};
1013 $ref_item{'name'} = $tag{'name'};
1014 $ref_item{'refid'} = $tag{'object'};
1015 } elsif ($type eq "commit"){
1016 my %co = parse_commit($ref_id);
1017 $ref_item{'reftype'} = "commit";
1018 $ref_item{'name'} = $ref_file;
1019 $ref_item{'title'} = $co{'title'};
1020 $ref_item{'refid'} = $ref_id;
1021 $ref_item{'epoch'} = $co{'committer_epoch'};
1022 $ref_item{'age'} = $co{'age_string'};
1024 $ref_item{'reftype'} = $type;
1025 $ref_item{'name'} = $ref_file;
1026 $ref_item{'refid'} = $ref_id;
1032 # parse line of git-diff-tree "raw" output
1033 sub parse_difftree_raw_line {
1037 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1038 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1039 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1040 $res{'from_mode'} = $1;
1041 $res{'to_mode'} = $2;
1042 $res{'from_id'} = $3;
1044 $res{'status'} = $5;
1045 $res{'similarity'} = $6;
1046 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1047 ($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
1049 $res{'file'} = unquote($7);
1052 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1053 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1054 $res{'commit'} = $1;
1057 return wantarray ? %res : \%res;
1060 # parse line of git-ls-tree output
1061 sub parse_ls_tree_line ($;%) {
1066 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1067 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1075 $res{'name'} = unquote($4);
1078 return wantarray ? %res : \%res;
1081 ## ......................................................................
1082 ## parse to array of hashes functions
1084 sub git_get_refs_list {
1085 my $ref_dir = shift;
1089 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1091 while (my $line = <$fd>) {
1093 if ($line =~ m/^([0-9a-fA-F]{40})\t$ref_dir\/?([^\^]+)$/) {
1094 push @refs, { hash => $1, name => $2 };
1095 } elsif ($line =~ m/^[0-9a-fA-F]{40}\t$ref_dir\/?(.*)\^\{\}$/ &&
1096 $1 eq $refs[-1]{'name'}) {
1097 # most likely a tag is followed by its peeled
1098 # (deref) one, and when that happens we know the
1099 # previous one was of type 'tag'.
1100 $refs[-1]{'type'} = "tag";
1105 foreach my $ref (@refs) {
1106 my $ref_file = $ref->{'name'};
1107 my $ref_id = $ref->{'hash'};
1109 my $type = $ref->{'type'} || git_get_type($ref_id) || next;
1110 my %ref_item = parse_ref($ref_file, $ref_id, $type);
1112 push @reflist, \%ref_item;
1115 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1119 ## ----------------------------------------------------------------------
1120 ## filesystem-related functions
1122 sub get_file_owner {
1125 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1126 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1127 if (!defined $gcos) {
1131 $owner =~ s/[,;].*$//;
1132 return decode("utf8", $owner, Encode::FB_DEFAULT);
1135 ## ......................................................................
1136 ## mimetype related functions
1138 sub mimetype_guess_file {
1139 my $filename = shift;
1140 my $mimemap = shift;
1141 -r $mimemap or return undef;
1144 open(MIME, $mimemap) or return undef;
1146 next if m/^#/; # skip comments
1147 my ($mime, $exts) = split(/\t+/);
1148 if (defined $exts) {
1149 my @exts = split(/\s+/, $exts);
1150 foreach my $ext (@exts) {
1151 $mimemap{$ext} = $mime;
1157 $filename =~ /\.(.*?)$/;
1158 return $mimemap{$1};
1161 sub mimetype_guess {
1162 my $filename = shift;
1164 $filename =~ /\./ or return undef;
1166 if ($mimetypes_file) {
1167 my $file = $mimetypes_file;
1168 if ($file !~ m!^/!) { # if it is relative path
1169 # it is relative to project
1170 $file = "$projectroot/$project/$file";
1172 $mime = mimetype_guess_file($filename, $file);
1174 $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
1180 my $filename = shift;
1183 my $mime = mimetype_guess($filename);
1184 $mime and return $mime;
1188 return $default_blob_plain_mimetype unless $fd;
1191 return 'text/plain' .
1192 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1193 } elsif (! $filename) {
1194 return 'application/octet-stream';
1195 } elsif ($filename =~ m/\.png$/i) {
1197 } elsif ($filename =~ m/\.gif$/i) {
1199 } elsif ($filename =~ m/\.jpe?g$/i) {
1200 return 'image/jpeg';
1202 return 'application/octet-stream';
1206 ## ======================================================================
1207 ## functions printing HTML: header, footer, error page
1209 sub git_header_html {
1210 my $status = shift || "200 OK";
1211 my $expires = shift;
1213 my $title = "$site_name git";
1214 if (defined $project) {
1215 $title .= " - $project";
1216 if (defined $action) {
1217 $title .= "/$action";
1218 if (defined $file_name) {
1219 $title .= " - $file_name";
1220 if ($action eq "tree" && $file_name !~ m|/$|) {
1227 # require explicit support from the UA if we are to send the page as
1228 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1229 # we have to do this because MSIE sometimes globs '*/*', pretending to
1230 # support xhtml+xml but choking when it gets what it asked for.
1231 if (defined $cgi->http('HTTP_ACCEPT') &&
1232 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&
1233 $cgi->Accept('application/xhtml+xml') != 0) {
1234 $content_type = 'application/xhtml+xml';
1236 $content_type = 'text/html';
1238 print $cgi->header(-type=>$content_type, -charset => 'utf-8',
1239 -status=> $status, -expires => $expires);
1241 <?xml version="1.0" encoding="utf-8"?>
1242 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1243 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1244 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1245 <!-- git core binaries version $git_version -->
1247 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1248 <meta name="generator" content="gitweb/$version git/$git_version"/>
1249 <meta name="robots" content="index, nofollow"/>
1250 <title>$title</title>
1251 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1253 if (defined $project) {
1254 printf('<link rel="alternate" title="%s log" '.
1255 'href="%s" type="application/rss+xml"/>'."\n",
1256 esc_param($project), href(action=>"rss"));
1258 if (defined $favicon) {
1259 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1264 "<div class=\"page_header\">\n" .
1265 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1266 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1268 print $cgi->a({-href => esc_param($home_link)}, $home_link_str) . " / ";
1269 if (defined $project) {
1270 print $cgi->a({-href => href(action=>"summary")}, esc_html($project));
1271 if (defined $action) {
1275 if (!defined $searchtext) {
1279 if (defined $hash_base) {
1280 $search_hash = $hash_base;
1281 } elsif (defined $hash) {
1282 $search_hash = $hash;
1284 $search_hash = "HEAD";
1286 $cgi->param("a", "search");
1287 $cgi->param("h", $search_hash);
1288 print $cgi->startform(-method => "get", -action => $my_uri) .
1289 "<div class=\"search\">\n" .
1290 $cgi->hidden(-name => "p") . "\n" .
1291 $cgi->hidden(-name => "a") . "\n" .
1292 $cgi->hidden(-name => "h") . "\n" .
1293 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
1295 $cgi->end_form() . "\n";
1300 sub git_footer_html {
1301 print "<div class=\"page_footer\">\n";
1302 if (defined $project) {
1303 my $descr = git_get_project_description($project);
1304 if (defined $descr) {
1305 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
1307 print $cgi->a({-href => href(action=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1309 print $cgi->a({-href => href(action=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1317 my $status = shift || "403 Forbidden";
1318 my $error = shift || "Malformed query, file missing or permission denied";
1320 git_header_html($status);
1322 <div class="page_body">
1332 ## ----------------------------------------------------------------------
1333 ## functions printing or outputting HTML: navigation
1335 sub git_print_page_nav {
1336 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1337 $extra = '' if !defined $extra; # pager or formats
1339 my @navs = qw(summary shortlog log commit commitdiff tree);
1341 @navs = grep { $_ ne $suppress } @navs;
1344 my %arg = map { $_ => {action=>$_} } @navs;
1345 if (defined $head) {
1346 for (qw(commit commitdiff)) {
1347 $arg{$_}{hash} = $head;
1349 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1350 for (qw(shortlog log)) {
1351 $arg{$_}{hash} = $head;
1355 $arg{tree}{hash} = $treehead if defined $treehead;
1356 $arg{tree}{hash_base} = $treebase if defined $treebase;
1358 print "<div class=\"page_nav\">\n" .
1360 map { $_ eq $current ?
1361 $_ : $cgi->a({-href => href(%{$arg{$_}})}, "$_")
1363 print "<br/>\n$extra<br/>\n" .
1367 sub format_paging_nav {
1368 my ($action, $hash, $head, $page, $nrevs) = @_;
1372 if ($hash ne $head || $page) {
1373 $paging_nav .= $cgi->a({-href => href(action=>$action)}, "HEAD");
1375 $paging_nav .= "HEAD";
1379 $paging_nav .= " ⋅ " .
1380 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page-1),
1381 -accesskey => "p", -title => "Alt-p"}, "prev");
1383 $paging_nav .= " ⋅ prev";
1386 if ($nrevs >= (100 * ($page+1)-1)) {
1387 $paging_nav .= " ⋅ " .
1388 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page+1),
1389 -accesskey => "n", -title => "Alt-n"}, "next");
1391 $paging_nav .= " ⋅ next";
1397 ## ......................................................................
1398 ## functions printing or outputting HTML: div
1400 sub git_print_header_div {
1401 my ($action, $title, $hash, $hash_base) = @_;
1404 $args{action} = $action;
1405 $args{hash} = $hash if $hash;
1406 $args{hash_base} = $hash_base if $hash_base;
1408 print "<div class=\"header\">\n" .
1409 $cgi->a({-href => href(%args), -class => "title"},
1410 $title ? $title : $action) .
1414 #sub git_print_authorship (\%) {
1415 sub git_print_authorship {
1418 my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
1419 print "<div class=\"author_date\">" .
1420 esc_html($co->{'author_name'}) .
1422 if ($ad{'hour_local'} < 6) {
1423 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1424 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1426 printf(" (%02d:%02d %s)",
1427 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1432 sub git_print_page_path {
1437 if (!defined $name) {
1438 print "<div class=\"page_path\">/</div>\n";
1440 my @dirname = split '/', $name;
1441 my $basename = pop @dirname;
1444 print "<div class=\"page_path\">";
1445 foreach my $dir (@dirname) {
1446 $fullname .= $dir . '/';
1447 print $cgi->a({-href => href(action=>"tree", file_name=>$fullname,
1449 -title => $fullname}, esc_html($dir));
1452 if (defined $type && $type eq 'blob') {
1453 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,
1455 -title => $name}, esc_html($basename));
1456 } elsif (defined $type && $type eq 'tree') {
1457 print $cgi->a({-href => href(action=>"tree", file_name=>$file_name,
1459 -title => $name}, esc_html($basename));
1462 print esc_html($basename);
1464 print "<br/></div>\n";
1468 # sub git_print_log (\@;%) {
1469 sub git_print_log ($;%) {
1473 if ($opts{'-remove_title'}) {
1474 # remove title, i.e. first line of log
1477 # remove leading empty lines
1478 while (defined $log->[0] && $log->[0] eq "") {
1485 foreach my $line (@$log) {
1486 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1489 if (! $opts{'-remove_signoff'}) {
1490 print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
1493 # remove signoff lines
1500 # print only one empty line
1501 # do not print empty line after signoff
1503 next if ($empty || $signoff);
1509 print format_log_line_html($line) . "<br/>\n";
1512 if ($opts{'-final_empty_line'}) {
1513 # end with single empty line
1514 print "<br/>\n" unless $empty;
1518 sub git_print_simplified_log {
1520 my $remove_title = shift;
1523 -final_empty_line=> 1,
1524 -remove_title => $remove_title);
1527 # print tree entry (row of git_tree), but without encompassing <tr> element
1528 sub git_print_tree_entry {
1529 my ($t, $basedir, $hash_base, $have_blame) = @_;
1532 $base_key{hash_base} = $hash_base if defined $hash_base;
1534 print "<td class=\"mode\">" . mode_str($t->{'mode'}) . "</td>\n";
1535 if ($t->{'type'} eq "blob") {
1536 print "<td class=\"list\">" .
1537 $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
1538 file_name=>"$basedir$t->{'name'}", %base_key),
1539 -class => "list"}, esc_html($t->{'name'})) .
1541 "<td class=\"link\">" .
1542 $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
1543 file_name=>"$basedir$t->{'name'}", %base_key)},
1547 $cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},
1548 file_name=>"$basedir$t->{'name'}", %base_key)},
1551 if (defined $hash_base) {
1553 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
1554 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},
1558 $cgi->a({-href => href(action=>"blob_plain",
1559 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},
1563 } elsif ($t->{'type'} eq "tree") {
1564 print "<td class=\"list\">" .
1565 $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
1566 file_name=>"$basedir$t->{'name'}", %base_key)},
1567 esc_html($t->{'name'})) .
1569 "<td class=\"link\">" .
1570 $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
1571 file_name=>"$basedir$t->{'name'}", %base_key)},
1573 if (defined $hash_base) {
1575 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
1576 file_name=>"$basedir$t->{'name'}")},
1583 ## ......................................................................
1584 ## functions printing large fragments of HTML
1586 sub git_difftree_body {
1587 my ($difftree, $hash, $parent) = @_;
1589 print "<div class=\"list_head\">\n";
1590 if ($#{$difftree} > 10) {
1591 print(($#{$difftree} + 1) . " files changed:\n");
1595 print "<table class=\"diff_tree\">\n";
1598 foreach my $line (@{$difftree}) {
1599 my %diff = parse_difftree_raw_line($line);
1602 print "<tr class=\"dark\">\n";
1604 print "<tr class=\"light\">\n";
1608 my ($to_mode_oct, $to_mode_str, $to_file_type);
1609 my ($from_mode_oct, $from_mode_str, $from_file_type);
1610 if ($diff{'to_mode'} ne ('0' x 6)) {
1611 $to_mode_oct = oct $diff{'to_mode'};
1612 if (S_ISREG($to_mode_oct)) { # only for regular file
1613 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1615 $to_file_type = file_type($diff{'to_mode'});
1617 if ($diff{'from_mode'} ne ('0' x 6)) {
1618 $from_mode_oct = oct $diff{'from_mode'};
1619 if (S_ISREG($to_mode_oct)) { # only for regular file
1620 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1622 $from_file_type = file_type($diff{'from_mode'});
1625 if ($diff{'status'} eq "A") { # created
1626 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1627 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1628 $mode_chng .= "]</span>";
1630 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1631 hash_base=>$hash, file_name=>$diff{'file'}),
1632 -class => "list"}, esc_html($diff{'file'})) .
1634 "<td>$mode_chng</td>\n" .
1635 "<td class=\"link\">" .
1636 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1637 hash_base=>$hash, file_name=>$diff{'file'})},
1639 if ($action eq 'commitdiff') {
1643 $cgi->a({-href => "#patch$patchno"}, "patch");
1647 } elsif ($diff{'status'} eq "D") { # deleted
1648 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1650 $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
1651 hash_base=>$parent, file_name=>$diff{'file'}),
1652 -class => "list"}, esc_html($diff{'file'})) .
1654 "<td>$mode_chng</td>\n" .
1655 "<td class=\"link\">" .
1656 $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
1657 hash_base=>$parent, file_name=>$diff{'file'})},
1660 if ($action eq 'commitdiff') {
1664 $cgi->a({-href => "#patch$patchno"}, "patch");
1666 print $cgi->a({-href => href(action=>"history", hash_base=>$parent,
1667 file_name=>$diff{'file'})},
1671 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1672 my $mode_chnge = "";
1673 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1674 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1675 if ($from_file_type != $to_file_type) {
1676 $mode_chnge .= " from $from_file_type to $to_file_type";
1678 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1679 if ($from_mode_str && $to_mode_str) {
1680 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1681 } elsif ($to_mode_str) {
1682 $mode_chnge .= " mode: $to_mode_str";
1685 $mode_chnge .= "]</span>\n";
1688 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1689 print $cgi->a({-href => href(action=>"blobdiff",
1690 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1691 hash_base=>$hash, hash_parent_base=>$parent,
1692 file_name=>$diff{'file'}),
1693 -class => "list"}, esc_html($diff{'file'}));
1694 } else { # only mode changed
1695 print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1696 hash_base=>$hash, file_name=>$diff{'file'}),
1697 -class => "list"}, esc_html($diff{'file'}));
1700 "<td>$mode_chnge</td>\n" .
1701 "<td class=\"link\">" .
1702 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1703 hash_base=>$hash, file_name=>$diff{'file'})},
1705 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1706 if ($action eq 'commitdiff') {
1710 $cgi->a({-href => "#patch$patchno"}, "patch");
1713 $cgi->a({-href => href(action=>"blobdiff",
1714 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1715 hash_base=>$hash, hash_parent_base=>$parent,
1716 file_name=>$diff{'file'})},
1721 $cgi->a({-href => href(action=>"history",
1722 hash_base=>$hash, file_name=>$diff{'file'})},
1726 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1727 my %status_name = ('R' => 'moved', 'C' => 'copied');
1728 my $nstatus = $status_name{$diff{'status'}};
1730 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1731 # mode also for directories, so we cannot use $to_mode_str
1732 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1735 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1736 hash=>$diff{'to_id'}, file_name=>$diff{'to_file'}),
1737 -class => "list"}, esc_html($diff{'to_file'})) . "</td>\n" .
1738 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1739 $cgi->a({-href => href(action=>"blob", hash_base=>$parent,
1740 hash=>$diff{'from_id'}, file_name=>$diff{'from_file'}),
1741 -class => "list"}, esc_html($diff{'from_file'})) .
1742 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1743 "<td class=\"link\">" .
1744 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1745 hash=>$diff{'to_id'}, file_name=>$diff{'to_file'})},
1747 if ($diff{'to_id'} ne $diff{'from_id'}) {
1748 if ($action eq 'commitdiff') {
1752 $cgi->a({-href => "#patch$patchno"}, "patch");
1755 $cgi->a({-href => href(action=>"blobdiff",
1756 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1757 hash_base=>$hash, hash_parent_base=>$parent,
1758 file_name=>$diff{'to_file'}, file_parent=>$diff{'from_file'})},
1764 } # we should not encounter Unmerged (U) or Unknown (X) status
1770 sub git_patchset_body {
1771 my ($fd, $difftree, $hash, $hash_parent) = @_;
1775 my $patch_found = 0;
1778 print "<div class=\"patchset\">\n";
1781 while (my $patch_line = <$fd>) {
1784 if ($patch_line =~ m/^diff /) { # "git diff" header
1785 # beginning of patch (in patchset)
1787 # close previous patch
1788 print "</div>\n"; # class="patch"
1790 # first patch in patchset
1793 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1795 if (ref($difftree->[$patch_idx]) eq "HASH") {
1796 $diffinfo = $difftree->[$patch_idx];
1798 $diffinfo = parse_difftree_raw_line($difftree->[$patch_idx]);
1802 # for now, no extended header, hence we skip empty patches
1803 # companion to next LINE if $in_header;
1804 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1809 if ($diffinfo->{'status'} eq "A") { # added
1810 print "<div class=\"diff_info\">" . file_type($diffinfo->{'to_mode'}) . ":" .
1811 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1812 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'file'})},
1813 $diffinfo->{'to_id'}) . "(new)" .
1814 "</div>\n"; # class="diff_info"
1816 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1817 print "<div class=\"diff_info\">" . file_type($diffinfo->{'from_mode'}) . ":" .
1818 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1819 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'file'})},
1820 $diffinfo->{'from_id'}) . "(deleted)" .
1821 "</div>\n"; # class="diff_info"
1823 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1824 $diffinfo->{'status'} eq "C" || # copied
1825 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1826 print "<div class=\"diff_info\">" .
1827 file_type($diffinfo->{'from_mode'}) . ":" .
1828 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1829 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'from_file'})},
1830 $diffinfo->{'from_id'}) .
1832 file_type($diffinfo->{'to_mode'}) . ":" .
1833 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1834 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'to_file'})},
1835 $diffinfo->{'to_id'});
1836 print "</div>\n"; # class="diff_info"
1838 } else { # modified, mode changed, ...
1839 print "<div class=\"diff_info\">" .
1840 file_type($diffinfo->{'from_mode'}) . ":" .
1841 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1842 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'file'})},
1843 $diffinfo->{'from_id'}) .
1845 file_type($diffinfo->{'to_mode'}) . ":" .
1846 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1847 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'file'})},
1848 $diffinfo->{'to_id'});
1849 print "</div>\n"; # class="diff_info"
1852 #print "<div class=\"diff extended_header\">\n";
1855 } # start of patch in patchset
1858 if ($in_header && $patch_line =~ m/^---/) {
1859 #print "</div>\n"; # class="diff extended_header"
1862 my $file = $diffinfo->{'from_file'};
1863 $file ||= $diffinfo->{'file'};
1864 $file = $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1865 hash=>$diffinfo->{'from_id'}, file_name=>$file),
1866 -class => "list"}, esc_html($file));
1867 $patch_line =~ s|a/.*$|a/$file|g;
1868 print "<div class=\"diff from_file\">$patch_line</div>\n";
1870 $patch_line = <$fd>;
1873 #$patch_line =~ m/^+++/;
1874 $file = $diffinfo->{'to_file'};
1875 $file ||= $diffinfo->{'file'};
1876 $file = $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1877 hash=>$diffinfo->{'to_id'}, file_name=>$file),
1878 -class => "list"}, esc_html($file));
1879 $patch_line =~ s|b/.*|b/$file|g;
1880 print "<div class=\"diff to_file\">$patch_line</div>\n";
1884 next LINE if $in_header;
1886 print format_diff_line($patch_line);
1888 print "</div>\n" if $patch_found; # class="patch"
1890 print "</div>\n"; # class="patchset"
1893 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1895 sub git_shortlog_body {
1896 # uses global variable $project
1897 my ($revlist, $from, $to, $refs, $extra) = @_;
1899 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
1900 my $have_snapshot = (defined $ctype && defined $suffix);
1902 $from = 0 unless defined $from;
1903 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1905 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1907 for (my $i = $from; $i <= $to; $i++) {
1908 my $commit = $revlist->[$i];
1909 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1910 my $ref = format_ref_marker($refs, $commit);
1911 my %co = parse_commit($commit);
1913 print "<tr class=\"dark\">\n";
1915 print "<tr class=\"light\">\n";
1918 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1919 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1920 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1922 print format_subject_html($co{'title'}, $co{'title_short'},
1923 href(action=>"commit", hash=>$commit), $ref);
1925 "<td class=\"link\">" .
1926 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
1927 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff");
1928 if ($have_snapshot) {
1929 print " | " . $cgi->a({-href => href(action=>"snapshot", hash=>$commit)}, "snapshot");
1934 if (defined $extra) {
1936 "<td colspan=\"4\">$extra</td>\n" .
1942 sub git_history_body {
1943 # Warning: assumes constant type (blob or tree) during history
1944 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
1946 $from = 0 unless defined $from;
1947 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
1949 print "<table class=\"history\" cellspacing=\"0\">\n";
1951 for (my $i = $from; $i <= $to; $i++) {
1952 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
1957 my %co = parse_commit($commit);
1962 my $ref = format_ref_marker($refs, $commit);
1965 print "<tr class=\"dark\">\n";
1967 print "<tr class=\"light\">\n";
1970 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1971 # shortlog uses chop_str($co{'author_name'}, 10)
1972 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1974 # originally git_history used chop_str($co{'title'}, 50)
1975 print format_subject_html($co{'title'}, $co{'title_short'},
1976 href(action=>"commit", hash=>$commit), $ref);
1978 "<td class=\"link\">" .
1979 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
1980 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
1981 $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype);
1983 if ($ftype eq 'blob') {
1984 my $blob_current = git_get_hash_by_path($hash_base, $file_name);
1985 my $blob_parent = git_get_hash_by_path($commit, $file_name);
1986 if (defined $blob_current && defined $blob_parent &&
1987 $blob_current ne $blob_parent) {
1989 $cgi->a({-href => href(action=>"blobdiff",
1990 hash=>$blob_current, hash_parent=>$blob_parent,
1991 hash_base=>$hash_base, hash_parent_base=>$commit,
1992 file_name=>$file_name)},
1999 if (defined $extra) {
2001 "<td colspan=\"4\">$extra</td>\n" .
2008 # uses global variable $project
2009 my ($taglist, $from, $to, $extra) = @_;
2010 $from = 0 unless defined $from;
2011 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2013 print "<table class=\"tags\" cellspacing=\"0\">\n";
2015 for (my $i = $from; $i <= $to; $i++) {
2016 my $entry = $taglist->[$i];
2018 my $comment_lines = $tag{'comment'};
2019 my $comment = shift @$comment_lines;
2021 if (defined $comment) {
2022 $comment_short = chop_str($comment, 30, 5);
2025 print "<tr class=\"dark\">\n";
2027 print "<tr class=\"light\">\n";
2030 print "<td><i>$tag{'age'}</i></td>\n" .
2032 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),
2033 -class => "list name"}, esc_html($tag{'name'})) .
2036 if (defined $comment) {
2037 print format_subject_html($comment, $comment_short,
2038 href(action=>"tag", hash=>$tag{'id'}));
2041 "<td class=\"selflink\">";
2042 if ($tag{'type'} eq "tag") {
2043 print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag");
2048 "<td class=\"link\">" . " | " .
2049 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'});
2050 if ($tag{'reftype'} eq "commit") {
2051 print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") .
2052 " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'refid'})}, "log");
2053 } elsif ($tag{'reftype'} eq "blob") {
2054 print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw");
2059 if (defined $extra) {
2061 "<td colspan=\"5\">$extra</td>\n" .
2067 sub git_heads_body {
2068 # uses global variable $project
2069 my ($taglist, $head, $from, $to, $extra) = @_;
2070 $from = 0 unless defined $from;
2071 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2073 print "<table class=\"heads\" cellspacing=\"0\">\n";
2075 for (my $i = $from; $i <= $to; $i++) {
2076 my $entry = $taglist->[$i];
2078 my $curr = $tag{'id'} eq $head;
2080 print "<tr class=\"dark\">\n";
2082 print "<tr class=\"light\">\n";
2085 print "<td><i>$tag{'age'}</i></td>\n" .
2086 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
2087 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'}),
2088 -class => "list name"},esc_html($tag{'name'})) .
2090 "<td class=\"link\">" .
2091 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") . " | " .
2092 $cgi->a({-href => href(action=>"log", hash=>$tag{'name'})}, "log") .
2096 if (defined $extra) {
2098 "<td colspan=\"3\">$extra</td>\n" .
2104 ## ======================================================================
2105 ## ======================================================================
2108 sub git_project_list {
2109 my $order = $cgi->param('o');
2110 if (defined $order && $order !~ m/project|descr|owner|age/) {
2111 die_error(undef, "Unknown order parameter");
2114 my @list = git_get_projects_list();
2117 die_error(undef, "No projects found");
2119 foreach my $pr (@list) {
2120 my $head = git_get_head_hash($pr->{'path'});
2121 if (!defined $head) {
2124 $git_dir = "$projectroot/$pr->{'path'}";
2125 my %co = parse_commit($head);
2129 $pr->{'commit'} = \%co;
2130 if (!defined $pr->{'descr'}) {
2131 my $descr = git_get_project_description($pr->{'path'}) || "";
2132 $pr->{'descr'} = chop_str($descr, 25, 5);
2134 if (!defined $pr->{'owner'}) {
2135 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
2137 push @projects, $pr;
2141 if (-f $home_text) {
2142 print "<div class=\"index_include\">\n";
2143 open (my $fd, $home_text);
2148 print "<table class=\"project_list\">\n" .
2150 $order ||= "project";
2151 if ($order eq "project") {
2152 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2153 print "<th>Project</th>\n";
2156 $cgi->a({-href => "$my_uri?" . esc_param("o=project"),
2157 -class => "header"}, "Project") .
2160 if ($order eq "descr") {
2161 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2162 print "<th>Description</th>\n";
2165 $cgi->a({-href => "$my_uri?" . esc_param("o=descr"),
2166 -class => "header"}, "Description") .
2169 if ($order eq "owner") {
2170 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2171 print "<th>Owner</th>\n";
2174 $cgi->a({-href => "$my_uri?" . esc_param("o=owner"),
2175 -class => "header"}, "Owner") .
2178 if ($order eq "age") {
2179 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2180 print "<th>Last Change</th>\n";
2183 $cgi->a({-href => "$my_uri?" . esc_param("o=age"),
2184 -class => "header"}, "Last Change") .
2187 print "<th></th>\n" .
2190 foreach my $pr (@projects) {
2192 print "<tr class=\"dark\">\n";
2194 print "<tr class=\"light\">\n";
2197 print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
2198 -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
2199 "<td>" . esc_html($pr->{'descr'}) . "</td>\n" .
2200 "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
2201 print "<td class=\"". age_class($pr->{'commit'}{'age'}) . "\">" .
2202 $pr->{'commit'}{'age_string'} . "</td>\n" .
2203 "<td class=\"link\">" .
2204 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
2205 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
2206 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") .
2214 sub git_project_index {
2215 my @projects = git_get_projects_list();
2218 -type => 'text/plain',
2219 -charset => 'utf-8',
2220 -content_disposition => qq(inline; filename="index.aux"));
2222 foreach my $pr (@projects) {
2223 if (!exists $pr->{'owner'}) {
2224 $pr->{'owner'} = get_file_owner("$projectroot/$project");
2227 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2228 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2229 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
2230 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
2234 print "$path $owner\n";
2239 my $descr = git_get_project_description($project) || "none";
2240 my $head = git_get_head_hash($project);
2241 my %co = parse_commit($head);
2242 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
2244 my $owner = git_get_project_owner($project);
2246 my $refs = git_get_references();
2248 git_print_page_nav('summary','', $head);
2250 print "<div class=\"title\"> </div>\n";
2251 print "<table cellspacing=\"0\">\n" .
2252 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
2253 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2254 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2255 # use per project git URL list in $projectroot/$project/cloneurl
2256 # or make project git URL from git base URL and project name
2257 my $url_tag = "URL";
2258 my @url_list = git_get_project_url_list($project);
2259 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2260 foreach my $git_url (@url_list) {
2261 next unless $git_url;
2262 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2267 open my $fd, "-|", git_cmd(), "rev-list", "--max-count=17",
2268 git_get_head_hash($project)
2269 or die_error(undef, "Open git-rev-list failed");
2270 my @revlist = map { chomp; $_ } <$fd>;
2272 git_print_header_div('shortlog');
2273 git_shortlog_body(\@revlist, 0, 15, $refs,
2274 $cgi->a({-href => href(action=>"shortlog")}, "..."));
2276 my $taglist = git_get_refs_list("refs/tags");
2277 if (defined @$taglist) {
2278 git_print_header_div('tags');
2279 git_tags_body($taglist, 0, 15,
2280 $cgi->a({-href => href(action=>"tags")}, "..."));
2283 my $headlist = git_get_refs_list("refs/heads");
2284 if (defined @$headlist) {
2285 git_print_header_div('heads');
2286 git_heads_body($headlist, $head, 0, 15,
2287 $cgi->a({-href => href(action=>"heads")}, "..."));
2294 my $head = git_get_head_hash($project);
2296 git_print_page_nav('','', $head,undef,$head);
2297 my %tag = parse_tag($hash);
2298 git_print_header_div('commit', esc_html($tag{'name'}), $hash);
2299 print "<div class=\"title_text\">\n" .
2300 "<table cellspacing=\"0\">\n" .
2302 "<td>object</td>\n" .
2303 "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
2304 $tag{'object'}) . "</td>\n" .
2305 "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
2306 $tag{'type'}) . "</td>\n" .
2308 if (defined($tag{'author'})) {
2309 my %ad = parse_date($tag{'epoch'}, $tag{'tz'});
2310 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
2311 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2312 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2315 print "</table>\n\n" .
2317 print "<div class=\"page_body\">";
2318 my $comment = $tag{'comment'};
2319 foreach my $line (@$comment) {
2320 print esc_html($line) . "<br/>\n";
2330 my ($have_blame) = gitweb_check_feature('blame');
2332 die_error('403 Permission denied', "Permission denied");
2334 die_error('404 Not Found', "File name not defined") if (!$file_name);
2335 $hash_base ||= git_get_head_hash($project);
2336 die_error(undef, "Couldn't find base commit") unless ($hash_base);
2337 my %co = parse_commit($hash_base)
2338 or die_error(undef, "Reading commit failed");
2339 if (!defined $hash) {
2340 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
2341 or die_error(undef, "Error looking up file");
2343 $ftype = git_get_type($hash);
2344 if ($ftype !~ "blob") {
2345 die_error("400 Bad Request", "Object is not a blob");
2347 open ($fd, "-|", git_cmd(), "blame", '-l', $file_name, $hash_base)
2348 or die_error(undef, "Open git-blame failed");
2351 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2354 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
2356 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2357 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2358 git_print_page_path($file_name, $ftype, $hash_base);
2359 my @rev_color = (qw(light2 dark2));
2360 my $num_colors = scalar(@rev_color);
2361 my $current_color = 0;
2364 <div class="page_body">
2365 <table class="blame">
2366 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2369 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2371 my $rev = substr($full_rev, 0, 8);
2375 if (!defined $last_rev) {
2376 $last_rev = $full_rev;
2377 } elsif ($last_rev ne $full_rev) {
2378 $last_rev = $full_rev;
2379 $current_color = ++$current_color % $num_colors;
2381 print "<tr class=\"$rev_color[$current_color]\">\n";
2382 print "<td class=\"sha1\">" .
2383 $cgi->a({-href => href(action=>"commit", hash=>$full_rev, file_name=>$file_name)},
2384 esc_html($rev)) . "</td>\n";
2385 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2386 esc_html($lineno) . "</a></td>\n";
2387 print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
2393 or print "Reading blob failed\n";
2400 my ($have_blame) = gitweb_check_feature('blame');
2402 die_error('403 Permission denied', "Permission denied");
2404 die_error('404 Not Found', "File name not defined") if (!$file_name);
2405 $hash_base ||= git_get_head_hash($project);
2406 die_error(undef, "Couldn't find base commit") unless ($hash_base);
2407 my %co = parse_commit($hash_base)
2408 or die_error(undef, "Reading commit failed");
2409 if (!defined $hash) {
2410 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
2411 or die_error(undef, "Error lookup file");
2413 open ($fd, "-|", git_cmd(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2414 or die_error(undef, "Open git-annotate failed");
2417 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2420 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
2422 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2423 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2424 git_print_page_path($file_name, 'blob', $hash_base);
2425 print "<div class=\"page_body\">\n";
2427 <table class="blame">
2436 my @line_class = (qw(light dark));
2437 my $line_class_len = scalar (@line_class);
2438 my $line_class_num = $#line_class;
2439 while (my $line = <$fd>) {
2451 $line_class_num = ($line_class_num + 1) % $line_class_len;
2453 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2460 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
2463 $short_rev = substr ($long_rev, 0, 8);
2464 $age = time () - $time;
2465 $age_str = age_string ($age);
2466 $age_str =~ s/ / /g;
2467 $age_class = age_class($age);
2468 $author = esc_html ($author);
2469 $author =~ s/ / /g;
2471 $data = untabify($data);
2472 $data = esc_html ($data);
2475 <tr class="$line_class[$line_class_num]">
2476 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2477 <td class="$age_class">$age_str</td>
2479 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2480 <td class="pre">$data</td>
2483 } # while (my $line = <$fd>)
2484 print "</table>\n\n";
2486 or print "Reading blob failed.\n";
2492 my $head = git_get_head_hash($project);
2494 git_print_page_nav('','', $head,undef,$head);
2495 git_print_header_div('summary', $project);
2497 my $taglist = git_get_refs_list("refs/tags");
2498 if (defined @$taglist) {
2499 git_tags_body($taglist);
2505 my $head = git_get_head_hash($project);
2507 git_print_page_nav('','', $head,undef,$head);
2508 git_print_header_div('summary', $project);
2510 my $taglist = git_get_refs_list("refs/heads");
2511 if (defined @$taglist) {
2512 git_heads_body($taglist, $head);
2517 sub git_blob_plain {
2518 # blobs defined by non-textual hash id's can be cached
2520 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2524 if (!defined $hash) {
2525 if (defined $file_name) {
2526 my $base = $hash_base || git_get_head_hash($project);
2527 $hash = git_get_hash_by_path($base, $file_name, "blob")
2528 or die_error(undef, "Error lookup file");
2530 die_error(undef, "No file name defined");
2534 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
2535 or die_error(undef, "Couldn't cat $file_name, $hash");
2537 $type ||= blob_mimetype($fd, $file_name);
2539 # save as filename, even when no $file_name is given
2540 my $save_as = "$hash";
2541 if (defined $file_name) {
2542 $save_as = $file_name;
2543 } elsif ($type =~ m/^text\//) {
2550 -content_disposition => "inline; filename=\"$save_as\"");
2552 binmode STDOUT, ':raw';
2554 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
2560 # blobs defined by non-textual hash id's can be cached
2562 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2566 if (!defined $hash) {
2567 if (defined $file_name) {
2568 my $base = $hash_base || git_get_head_hash($project);
2569 $hash = git_get_hash_by_path($base, $file_name, "blob")
2570 or die_error(undef, "Error lookup file");
2572 die_error(undef, "No file name defined");
2575 my ($have_blame) = gitweb_check_feature('blame');
2576 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
2577 or die_error(undef, "Couldn't cat $file_name, $hash");
2578 my $mimetype = blob_mimetype($fd, $file_name);
2579 if ($mimetype !~ m/^text\//) {
2581 return git_blob_plain($mimetype);
2583 git_header_html(undef, $expires);
2584 my $formats_nav = '';
2585 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2586 if (defined $file_name) {
2589 $cgi->a({-href => href(action=>"blame", hash_base=>$hash_base,
2590 hash=>$hash, file_name=>$file_name)},
2595 $cgi->a({-href => href(action=>"blob_plain",
2596 hash=>$hash, file_name=>$file_name)},
2599 $cgi->a({-href => href(action=>"blob",
2600 hash_base=>"HEAD", file_name=>$file_name)},
2604 $cgi->a({-href => href(action=>"blob_plain", hash=>$hash)}, "plain");
2606 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2607 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2609 print "<div class=\"page_nav\">\n" .
2610 "<br/><br/></div>\n" .
2611 "<div class=\"title\">$hash</div>\n";
2613 git_print_page_path($file_name, "blob", $hash_base);
2614 print "<div class=\"page_body\">\n";
2616 while (my $line = <$fd>) {
2619 $line = untabify($line);
2620 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2621 $nr, $nr, $nr, esc_html($line);
2624 or print "Reading blob failed.\n";
2630 if (!defined $hash) {
2631 $hash = git_get_head_hash($project);
2632 if (defined $file_name) {
2633 my $base = $hash_base || $hash;
2634 $hash = git_get_hash_by_path($base, $file_name, "tree");
2636 if (!defined $hash_base) {
2641 open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
2642 or die_error(undef, "Open git-ls-tree failed");
2643 my @entries = map { chomp; $_ } <$fd>;
2644 close $fd or die_error(undef, "Reading tree failed");
2647 my $refs = git_get_references();
2648 my $ref = format_ref_marker($refs, $hash_base);
2651 my ($have_blame) = gitweb_check_feature('blame');
2652 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2653 git_print_page_nav('tree','', $hash_base);
2654 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
2657 print "<div class=\"page_nav\">\n";
2658 print "<br/><br/></div>\n";
2659 print "<div class=\"title\">$hash</div>\n";
2661 if (defined $file_name) {
2662 $base = esc_html("$file_name/");
2664 git_print_page_path($file_name, 'tree', $hash_base);
2665 print "<div class=\"page_body\">\n";
2666 print "<table cellspacing=\"0\">\n";
2668 foreach my $line (@entries) {
2669 my %t = parse_ls_tree_line($line, -z => 1);
2672 print "<tr class=\"dark\">\n";
2674 print "<tr class=\"light\">\n";
2678 git_print_tree_entry(\%t, $base, $hash_base, $have_blame);
2682 print "</table>\n" .
2689 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
2690 my $have_snapshot = (defined $ctype && defined $suffix);
2691 if (!$have_snapshot) {
2692 die_error('403 Permission denied', "Permission denied");
2695 if (!defined $hash) {
2696 $hash = git_get_head_hash($project);
2699 my $filename = basename($project) . "-$hash.tar.$suffix";
2701 print $cgi->header(-type => 'application/x-tar',
2702 -content_encoding => $ctype,
2703 -content_disposition => "inline; filename=\"$filename\"",
2704 -status => '200 OK');
2706 my $git_command = git_cmd_str();
2707 open my $fd, "-|", "$git_command tar-tree $hash \'$project\' | $command" or
2708 die_error(undef, "Execute git-tar-tree failed.");
2709 binmode STDOUT, ':raw';
2711 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
2717 my $head = git_get_head_hash($project);
2718 if (!defined $hash) {
2721 if (!defined $page) {
2724 my $refs = git_get_references();
2726 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2727 open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash
2728 or die_error(undef, "Open git-rev-list failed");
2729 my @revlist = map { chomp; $_ } <$fd>;
2732 my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#revlist);
2735 git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
2738 my %co = parse_commit($hash);
2740 git_print_header_div('summary', $project);
2741 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2743 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2744 my $commit = $revlist[$i];
2745 my $ref = format_ref_marker($refs, $commit);
2746 my %co = parse_commit($commit);
2748 my %ad = parse_date($co{'author_epoch'});
2749 git_print_header_div('commit',
2750 "<span class=\"age\">$co{'age_string'}</span>" .
2751 esc_html($co{'title'}) . $ref,
2753 print "<div class=\"title_text\">\n" .
2754 "<div class=\"log_link\">\n" .
2755 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
2757 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
2760 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2763 print "<div class=\"log_body\">\n";
2764 git_print_simplified_log($co{'comment'});
2771 my %co = parse_commit($hash);
2773 die_error(undef, "Unknown commit object");
2775 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
2776 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
2778 my $parent = $co{'parent'};
2779 if (!defined $parent) {
2782 open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $parent, $hash
2783 or die_error(undef, "Open git-diff-tree failed");
2784 my @difftree = map { chomp; $_ } <$fd>;
2785 close $fd or die_error(undef, "Reading git-diff-tree failed");
2787 # non-textual hash id's can be cached
2789 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2792 my $refs = git_get_references();
2793 my $ref = format_ref_marker($refs, $co{'id'});
2795 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
2796 my $have_snapshot = (defined $ctype && defined $suffix);
2798 my $formats_nav = '';
2799 if (defined $file_name && defined $co{'parent'}) {
2800 my $parent = $co{'parent'};
2802 $cgi->a({-href => href(action=>"blame", hash_parent=>$parent, file_name=>$file_name)},
2805 git_header_html(undef, $expires);
2806 git_print_page_nav('commit', defined $co{'parent'} ? '' : 'commitdiff',
2807 $hash, $co{'tree'}, $hash,
2810 if (defined $co{'parent'}) {
2811 git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash);
2813 git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash);
2815 print "<div class=\"title_text\">\n" .
2816 "<table cellspacing=\"0\">\n";
2817 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
2819 "<td></td><td> $ad{'rfc2822'}";
2820 if ($ad{'hour_local'} < 6) {
2821 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2822 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2824 printf(" (%02d:%02d %s)",
2825 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2829 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
2830 print "<tr><td></td><td> $cd{'rfc2822'}" .
2831 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2833 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2836 "<td class=\"sha1\">" .
2837 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),
2838 class => "list"}, $co{'tree'}) .
2840 "<td class=\"link\">" .
2841 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},
2843 if ($have_snapshot) {
2845 $cgi->a({-href => href(action=>"snapshot", hash=>$hash)}, "snapshot");
2849 my $parents = $co{'parents'};
2850 foreach my $par (@$parents) {
2853 "<td class=\"sha1\">" .
2854 $cgi->a({-href => href(action=>"commit", hash=>$par),
2855 class => "list"}, $par) .
2857 "<td class=\"link\">" .
2858 $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") .
2860 $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "diff") .
2867 print "<div class=\"page_body\">\n";
2868 git_print_log($co{'comment'});
2871 git_difftree_body(\@difftree, $hash, $parent);
2877 my $format = shift || 'html';
2884 # preparing $fd and %diffinfo for git_patchset_body
2886 if (defined $hash_base && defined $hash_parent_base) {
2887 if (defined $file_name) {
2889 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
2891 or die_error(undef, "Open git-diff-tree failed");
2892 @difftree = map { chomp; $_ } <$fd>;
2894 or die_error(undef, "Reading git-diff-tree failed");
2896 or die_error('404 Not Found', "Blob diff not found");
2898 } elsif (defined $hash &&
2899 $hash =~ /[0-9a-fA-F]{40}/) {
2900 # try to find filename from $hash
2902 # read filtered raw output
2903 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
2904 or die_error(undef, "Open git-diff-tree failed");
2906 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
2908 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
2909 map { chomp; $_ } <$fd>;
2911 or die_error(undef, "Reading git-diff-tree failed");
2913 or die_error('404 Not Found', "Blob diff not found");
2916 die_error('404 Not Found', "Missing one of the blob diff parameters");
2919 if (@difftree > 1) {
2920 die_error('404 Not Found', "Ambiguous blob diff specification");
2923 %diffinfo = parse_difftree_raw_line($difftree[0]);
2924 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
2925 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
2927 $hash_parent ||= $diffinfo{'from_id'};
2928 $hash ||= $diffinfo{'to_id'};
2930 # non-textual hash id's can be cached
2931 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
2932 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
2937 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
2938 '-p', $hash_parent_base, $hash_base,
2940 or die_error(undef, "Open git-diff-tree failed");
2943 # old/legacy style URI
2944 if (!%diffinfo && # if new style URI failed
2945 defined $hash && defined $hash_parent) {
2946 # fake git-diff-tree raw output
2947 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
2948 $diffinfo{'from_id'} = $hash_parent;
2949 $diffinfo{'to_id'} = $hash;
2950 if (defined $file_name) {
2951 if (defined $file_parent) {
2952 $diffinfo{'status'} = '2';
2953 $diffinfo{'from_file'} = $file_parent;
2954 $diffinfo{'to_file'} = $file_name;
2955 } else { # assume not renamed
2956 $diffinfo{'status'} = '1';
2957 $diffinfo{'from_file'} = $file_name;
2958 $diffinfo{'to_file'} = $file_name;
2960 } else { # no filename given
2961 $diffinfo{'status'} = '2';
2962 $diffinfo{'from_file'} = $hash_parent;
2963 $diffinfo{'to_file'} = $hash;
2966 # non-textual hash id's can be cached
2967 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
2968 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
2973 open $fd, "-|", git_cmd(), "diff", '-p', @diff_opts, $hash_parent, $hash
2974 or die_error(undef, "Open git-diff failed");
2976 die_error('404 Not Found', "Missing one of the blob diff parameters")
2981 if ($format eq 'html') {
2983 $cgi->a({-href => href(action=>"blobdiff_plain",
2984 hash=>$hash, hash_parent=>$hash_parent,
2985 hash_base=>$hash_base, hash_parent_base=>$hash_parent_base,
2986 file_name=>$file_name, file_parent=>$file_parent)},
2988 git_header_html(undef, $expires);
2989 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2990 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2991 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2993 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
2994 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
2996 if (defined $file_name) {
2997 git_print_page_path($file_name, "blob", $hash_base);
2999 print "<div class=\"page_path\"></div>\n";
3002 } elsif ($format eq 'plain') {
3004 -type => 'text/plain',
3005 -charset => 'utf-8',
3006 -expires => $expires,
3007 -content_disposition => qq(inline; filename="${file_name}.patch"));
3009 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3012 die_error(undef, "Unknown blobdiff format");
3016 if ($format eq 'html') {
3017 print "<div class=\"page_body\">\n";
3019 git_patchset_body($fd, [ \%diffinfo ], $hash_base, $hash_parent_base);
3022 print "</div>\n"; # class="page_body"
3026 while (my $line = <$fd>) {
3027 $line =~ s!a/($hash|$hash_parent)!a/$diffinfo{'from_file'}!g;
3028 $line =~ s!b/($hash|$hash_parent)!b/$diffinfo{'to_file'}!g;
3032 last if $line =~ m!^\+\+\+!;
3040 sub git_blobdiff_plain {
3041 git_blobdiff('plain');
3044 sub git_commitdiff {
3045 my $format = shift || 'html';
3046 my %co = parse_commit($hash);
3048 die_error(undef, "Unknown commit object");
3050 if (!defined $hash_parent) {
3051 $hash_parent = $co{'parent'} || '--root';
3057 if ($format eq 'html') {
3058 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
3059 "--patch-with-raw", "--full-index", $hash_parent, $hash
3060 or die_error(undef, "Open git-diff-tree failed");
3062 while (chomp(my $line = <$fd>)) {
3063 # empty line ends raw part of diff-tree output
3065 push @difftree, $line;
3068 } elsif ($format eq 'plain') {
3069 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
3070 '-p', $hash_parent, $hash
3071 or die_error(undef, "Open git-diff-tree failed");
3074 die_error(undef, "Unknown commitdiff format");
3077 # non-textual hash id's can be cached
3079 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3083 # write commit message
3084 if ($format eq 'html') {
3085 my $refs = git_get_references();
3086 my $ref = format_ref_marker($refs, $co{'id'});
3088 $cgi->a({-href => href(action=>"commitdiff_plain",
3089 hash=>$hash, hash_parent=>$hash_parent)},
3092 git_header_html(undef, $expires);
3093 git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3094 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
3095 git_print_authorship(\%co);
3096 print "<div class=\"page_body\">\n";
3097 print "<div class=\"log\">\n";
3098 git_print_simplified_log($co{'comment'}, 1); # skip title
3099 print "</div>\n"; # class="log"
3101 } elsif ($format eq 'plain') {
3102 my $refs = git_get_references("tags");
3103 my $tagname = git_get_rev_name_tags($hash);
3104 my $filename = basename($project) . "-$hash.patch";
3107 -type => 'text/plain',
3108 -charset => 'utf-8',
3109 -expires => $expires,
3110 -content_disposition => qq(inline; filename="$filename"));
3111 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
3114 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3115 Subject: $co{'title'}
3117 print "X-Git-Tag: $tagname\n" if $tagname;
3118 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3120 foreach my $line (@{$co{'comment'}}) {
3127 if ($format eq 'html') {
3128 git_difftree_body(\@difftree, $hash, $hash_parent);
3131 git_patchset_body($fd, \@difftree, $hash, $hash_parent);
3133 print "</div>\n"; # class="page_body"
3136 } elsif ($format eq 'plain') {
3140 or print "Reading git-diff-tree failed\n";
3144 sub git_commitdiff_plain {
3145 git_commitdiff('plain');
3149 if (!defined $hash_base) {
3150 $hash_base = git_get_head_hash($project);
3152 if (!defined $page) {
3156 my %co = parse_commit($hash_base);
3158 die_error(undef, "Unknown commit object");
3161 my $refs = git_get_references();
3162 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3164 if (!defined $hash && defined $file_name) {
3165 $hash = git_get_hash_by_path($hash_base, $file_name);
3167 if (defined $hash) {
3168 $ftype = git_get_type($hash);
3172 git_cmd(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3173 or die_error(undef, "Open git-rev-list-failed");
3174 my @revlist = map { chomp; $_ } <$fd>;
3176 or die_error(undef, "Reading git-rev-list failed");
3178 my $paging_nav = '';
3181 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3182 file_name=>$file_name)},
3184 $paging_nav .= " ⋅ " .
3185 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3186 file_name=>$file_name, page=>$page-1),
3187 -accesskey => "p", -title => "Alt-p"}, "prev");
3189 $paging_nav .= "first";
3190 $paging_nav .= " ⋅ prev";
3192 if ($#revlist >= (100 * ($page+1)-1)) {
3193 $paging_nav .= " ⋅ " .
3194 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3195 file_name=>$file_name, page=>$page+1),
3196 -accesskey => "n", -title => "Alt-n"}, "next");
3198 $paging_nav .= " ⋅ next";
3201 if ($#revlist >= (100 * ($page+1)-1)) {
3203 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3204 file_name=>$file_name, page=>$page+1),
3205 -title => "Alt-n"}, "next");
3209 git_print_page_nav('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3210 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
3211 git_print_page_path($file_name, $ftype, $hash_base);
3213 git_history_body(\@revlist, ($page * 100), $#revlist,
3214 $refs, $hash_base, $ftype, $next_link);
3220 if (!defined $searchtext) {
3221 die_error(undef, "Text field empty");
3223 if (!defined $hash) {
3224 $hash = git_get_head_hash($project);
3226 my %co = parse_commit($hash);
3228 die_error(undef, "Unknown commit object");
3231 my $commit_search = 1;
3232 my $author_search = 0;
3233 my $committer_search = 0;
3234 my $pickaxe_search = 0;
3235 if ($searchtext =~ s/^author\\://i) {
3237 } elsif ($searchtext =~ s/^committer\\://i) {
3238 $committer_search = 1;
3239 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3241 $pickaxe_search = 1;
3243 # pickaxe may take all resources of your box and run for several minutes
3244 # with every query - so decide by yourself how public you make this feature
3245 my ($have_pickaxe) = gitweb_check_feature('pickaxe');
3246 if (!$have_pickaxe) {
3247 die_error('403 Permission denied', "Permission denied");
3251 git_print_page_nav('','', $hash,$co{'tree'},$hash);
3252 git_print_header_div('commit', esc_html($co{'title'}), $hash);
3254 print "<table cellspacing=\"0\">\n";
3256 if ($commit_search) {
3258 open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", $hash or next;
3259 while (my $commit_text = <$fd>) {
3260 if (!grep m/$searchtext/i, $commit_text) {
3263 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3266 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3269 my @commit_lines = split "\n", $commit_text;
3270 my %co = parse_commit(undef, \@commit_lines);
3275 print "<tr class=\"dark\">\n";
3277 print "<tr class=\"light\">\n";
3280 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3281 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3283 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"},
3284 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
3285 my $comment = $co{'comment'};
3286 foreach my $line (@$comment) {
3287 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3288 my $lead = esc_html($1) || "";
3289 $lead = chop_str($lead, 30, 10);
3290 my $match = esc_html($2) || "";
3291 my $trail = esc_html($3) || "";
3292 $trail = chop_str($trail, 30, 10);
3293 my $text = "$lead<span class=\"match\">$match</span>$trail";
3294 print chop_str($text, 80, 5) . "<br/>\n";
3298 "<td class=\"link\">" .
3299 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
3301 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
3308 if ($pickaxe_search) {
3310 my $git_command = git_cmd_str();
3311 open my $fd, "-|", "$git_command rev-list $hash | " .
3312 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3315 while (my $line = <$fd>) {
3316 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3319 $set{'from_id'} = $3;
3321 $set{'id'} = $set{'to_id'};
3322 if ($set{'id'} =~ m/0{40}/) {
3323 $set{'id'} = $set{'from_id'};
3325 if ($set{'id'} =~ m/0{40}/) {
3329 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3332 print "<tr class=\"dark\">\n";
3334 print "<tr class=\"light\">\n";
3337 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3338 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3340 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
3341 -class => "list subject"},
3342 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
3343 while (my $setref = shift @files) {
3345 print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},
3346 hash=>$set{'id'}, file_name=>$set{'file'}),
3348 "<span class=\"match\">" . esc_html($set{'file'}) . "</span>") .
3352 "<td class=\"link\">" .
3353 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
3355 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
3359 %co = parse_commit($1);
3369 my $head = git_get_head_hash($project);
3370 if (!defined $hash) {
3373 if (!defined $page) {
3376 my $refs = git_get_references();
3378 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3379 open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash
3380 or die_error(undef, "Open git-rev-list failed");
3381 my @revlist = map { chomp; $_ } <$fd>;
3384 my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, $#revlist);
3386 if ($#revlist >= (100 * ($page+1)-1)) {
3388 $cgi->a({-href => href(action=>"shortlog", hash=>$hash, page=>$page+1),
3389 -title => "Alt-n"}, "next");
3394 git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);
3395 git_print_header_div('summary', $project);
3397 git_shortlog_body(\@revlist, ($page * 100), $#revlist, $refs, $next_link);
3402 ## ......................................................................
3403 ## feeds (RSS, OPML)
3406 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3407 open my $fd, "-|", git_cmd(), "rev-list", "--max-count=150", git_get_head_hash($project)
3408 or die_error(undef, "Open git-rev-list failed");
3409 my @revlist = map { chomp; $_ } <$fd>;
3410 close $fd or die_error(undef, "Reading git-rev-list failed");
3411 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
3413 <?xml version="1.0" encoding="utf-8"?>
3414 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3416 <title>$project $my_uri $my_url</title>
3417 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3418 <description>$project log</description>
3419 <language>en</language>
3422 for (my $i = 0; $i <= $#revlist; $i++) {
3423 my $commit = $revlist[$i];
3424 my %co = parse_commit($commit);
3425 # we read 150, we always show 30 and the ones more recent than 48 hours
3426 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3429 my %cd = parse_date($co{'committer_epoch'});
3430 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
3431 $co{'parent'}, $co{'id'}
3433 my @difftree = map { chomp; $_ } <$fd>;
3438 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) .
3440 "<author>" . esc_html($co{'author'}) . "</author>\n" .
3441 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3442 "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3443 "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3444 "<description>" . esc_html($co{'title'}) . "</description>\n" .
3445 "<content:encoded>" .
3447 my $comment = $co{'comment'};
3448 foreach my $line (@$comment) {
3449 $line = decode("utf8", $line, Encode::FB_DEFAULT);
3450 print "$line<br/>\n";
3453 foreach my $line (@difftree) {
3454 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3457 my $file = validate_input(unquote($7));
3458 $file = decode("utf8", $file, Encode::FB_DEFAULT);
3459 print "$file<br/>\n";
3462 "</content:encoded>\n" .
3465 print "</channel></rss>";
3469 my @list = git_get_projects_list();
3471 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
3473 <?xml version="1.0" encoding="utf-8"?>
3474 <opml version="1.0">
3476 <title>$site_name Git OPML Export</title>
3479 <outline text="git RSS feeds">
3482 foreach my $pr (@list) {
3484 my $head = git_get_head_hash($proj{'path'});
3485 if (!defined $head) {
3488 $git_dir = "$projectroot/$proj{'path'}";
3489 my %co = parse_commit($head);
3494 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
3495 my $rss = "$my_url?p=$proj{'path'};a=rss";
3496 my $html = "$my_url?p=$proj{'path'};a=summary";
3497 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";