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 ## ----------------------------------------------------------------------
528 ## git utility subroutines, invoking git commands
530 # get HEAD ref of given project as hash
531 sub git_get_head_hash {
533 my $oENV = $ENV{'GIT_DIR'};
535 $ENV{'GIT_DIR'} = "$projectroot/$project";
536 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
539 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
544 $ENV{'GIT_DIR'} = $oENV;
549 # get type of given object
553 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
560 sub git_get_project_config {
561 my ($key, $type) = @_;
563 return unless ($key);
564 $key =~ s/^gitweb\.//;
565 return if ($key =~ m/\W/);
567 my @x = ($GIT, 'repo-config');
568 if (defined $type) { push @x, $type; }
570 push @x, "gitweb.$key";
576 # get hash of given path at given ref
577 sub git_get_hash_by_path {
579 my $path = shift || return undef;
583 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
584 or die_error(undef, "Open git-ls-tree failed");
586 close $fd or return undef;
588 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
589 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
593 ## ......................................................................
594 ## git utility functions, directly accessing git repository
596 # assumes that PATH is not symref
597 sub git_get_hash_by_ref {
600 open my $fd, "$projectroot/$path" or return undef;
604 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
609 sub git_get_project_description {
612 open my $fd, "$projectroot/$path/description" or return undef;
619 sub git_get_project_url_list {
622 open my $fd, "$projectroot/$path/cloneurl" or return undef;
623 my @git_project_url_list = map { chomp; $_ } <$fd>;
626 return wantarray ? @git_project_url_list : \@git_project_url_list;
629 sub git_get_projects_list {
632 if (-d $projects_list) {
633 # search in directory
634 my $dir = $projects_list;
635 opendir my ($dh), $dir or return undef;
636 while (my $dir = readdir($dh)) {
637 if (-e "$projectroot/$dir/HEAD") {
645 } elsif (-f $projects_list) {
646 # read from file(url-encoded):
647 # 'git%2Fgit.git Linus+Torvalds'
648 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
649 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
650 open my ($fd), $projects_list or return undef;
651 while (my $line = <$fd>) {
653 my ($path, $owner) = split ' ', $line;
654 $path = unescape($path);
655 $owner = unescape($owner);
656 if (!defined $path) {
659 if (-e "$projectroot/$path/HEAD") {
662 owner => decode("utf8", $owner, Encode::FB_DEFAULT),
669 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
673 sub git_get_project_owner {
677 return undef unless $project;
679 # read from file (url-encoded):
680 # 'git%2Fgit.git Linus+Torvalds'
681 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
682 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
683 if (-f $projects_list) {
684 open (my $fd , $projects_list);
685 while (my $line = <$fd>) {
687 my ($pr, $ow) = split ' ', $line;
690 if ($pr eq $project) {
691 $owner = decode("utf8", $ow, Encode::FB_DEFAULT);
697 if (!defined $owner) {
698 $owner = get_file_owner("$projectroot/$project");
704 sub git_get_references {
705 my $type = shift || "";
708 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
709 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
710 if (-f "$projectroot/$project/info/refs") {
711 open $fd, "$projectroot/$project/info/refs"
714 open $fd, "-|", $GIT, "ls-remote", "."
718 while (my $line = <$fd>) {
720 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?[^\^]+)/) {
721 if (defined $refs{$1}) {
722 push @{$refs{$1}}, $2;
732 ## ----------------------------------------------------------------------
733 ## parse to hash functions
737 my $tz = shift || "-0000";
740 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
741 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
742 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
743 $date{'hour'} = $hour;
744 $date{'minute'} = $min;
745 $date{'mday'} = $mday;
746 $date{'day'} = $days[$wday];
747 $date{'month'} = $months[$mon];
748 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
749 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
750 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
751 $mday, $months[$mon], $hour ,$min;
753 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
754 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
755 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
756 $date{'hour_local'} = $hour;
757 $date{'minute_local'} = $min;
758 $date{'tz_local'} = $tz;
767 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
768 $tag{'id'} = $tag_id;
769 while (my $line = <$fd>) {
771 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
773 } elsif ($line =~ m/^type (.+)$/) {
775 } elsif ($line =~ m/^tag (.+)$/) {
777 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
781 } elsif ($line =~ m/--BEGIN/) {
782 push @comment, $line;
784 } elsif ($line eq "") {
788 push @comment, <$fd>;
789 $tag{'comment'} = \@comment;
791 if (!defined $tag{'name'}) {
798 my $commit_id = shift;
799 my $commit_text = shift;
804 if (defined $commit_text) {
805 @commit_lines = @$commit_text;
808 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id
810 @commit_lines = split '\n', <$fd>;
815 my $header = shift @commit_lines;
816 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
819 ($co{'id'}, my @parents) = split ' ', $header;
820 $co{'parents'} = \@parents;
821 $co{'parent'} = $parents[0];
822 while (my $line = shift @commit_lines) {
823 last if $line eq "\n";
824 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
826 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
828 $co{'author_epoch'} = $2;
829 $co{'author_tz'} = $3;
830 if ($co{'author'} =~ m/^([^<]+) </) {
831 $co{'author_name'} = $1;
833 $co{'author_name'} = $co{'author'};
835 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
836 $co{'committer'} = $1;
837 $co{'committer_epoch'} = $2;
838 $co{'committer_tz'} = $3;
839 $co{'committer_name'} = $co{'committer'};
840 $co{'committer_name'} =~ s/ <.*//;
843 if (!defined $co{'tree'}) {
847 foreach my $title (@commit_lines) {
850 $co{'title'} = chop_str($title, 80, 5);
851 # remove leading stuff of merges to make the interesting part visible
852 if (length($title) > 50) {
853 $title =~ s/^Automatic //;
854 $title =~ s/^merge (of|with) /Merge ... /i;
855 if (length($title) > 50) {
856 $title =~ s/(http|rsync):\/\///;
858 if (length($title) > 50) {
859 $title =~ s/(master|www|rsync)\.//;
861 if (length($title) > 50) {
862 $title =~ s/kernel.org:?//;
864 if (length($title) > 50) {
865 $title =~ s/\/pub\/scm//;
868 $co{'title_short'} = chop_str($title, 50, 5);
872 # remove added spaces
873 foreach my $line (@commit_lines) {
876 $co{'comment'} = \@commit_lines;
878 my $age = time - $co{'committer_epoch'};
880 $co{'age_string'} = age_string($age);
881 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
882 if ($age > 60*60*24*7*2) {
883 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
884 $co{'age_string_age'} = $co{'age_string'};
886 $co{'age_string_date'} = $co{'age_string'};
887 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
892 # parse ref from ref_file, given by ref_id, with given type
894 my $ref_file = shift;
896 my $type = shift || git_get_type($ref_id);
899 $ref_item{'type'} = $type;
900 $ref_item{'id'} = $ref_id;
901 $ref_item{'epoch'} = 0;
902 $ref_item{'age'} = "unknown";
903 if ($type eq "tag") {
904 my %tag = parse_tag($ref_id);
905 $ref_item{'comment'} = $tag{'comment'};
906 if ($tag{'type'} eq "commit") {
907 my %co = parse_commit($tag{'object'});
908 $ref_item{'epoch'} = $co{'committer_epoch'};
909 $ref_item{'age'} = $co{'age_string'};
910 } elsif (defined($tag{'epoch'})) {
911 my $age = time - $tag{'epoch'};
912 $ref_item{'epoch'} = $tag{'epoch'};
913 $ref_item{'age'} = age_string($age);
915 $ref_item{'reftype'} = $tag{'type'};
916 $ref_item{'name'} = $tag{'name'};
917 $ref_item{'refid'} = $tag{'object'};
918 } elsif ($type eq "commit"){
919 my %co = parse_commit($ref_id);
920 $ref_item{'reftype'} = "commit";
921 $ref_item{'name'} = $ref_file;
922 $ref_item{'title'} = $co{'title'};
923 $ref_item{'refid'} = $ref_id;
924 $ref_item{'epoch'} = $co{'committer_epoch'};
925 $ref_item{'age'} = $co{'age_string'};
927 $ref_item{'reftype'} = $type;
928 $ref_item{'name'} = $ref_file;
929 $ref_item{'refid'} = $ref_id;
935 # parse line of git-diff-tree "raw" output
936 sub parse_difftree_raw_line {
940 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
941 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
942 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
943 $res{'from_mode'} = $1;
944 $res{'to_mode'} = $2;
945 $res{'from_id'} = $3;
948 $res{'similarity'} = $6;
949 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
950 ($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
952 $res{'file'} = unquote($7);
955 # 'c512b523472485aef4fff9e57b229d9d243c967f'
956 #elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
957 # $res{'commit'} = $1;
960 return wantarray ? %res : \%res;
963 ## ......................................................................
964 ## parse to array of hashes functions
966 sub git_get_refs_list {
971 my $pfxlen = length("$projectroot/$project/$ref_dir");
972 File::Find::find(sub {
975 push @refs, substr($File::Find::name, $pfxlen + 1);
977 }, "$projectroot/$project/$ref_dir");
979 foreach my $ref_file (@refs) {
980 my $ref_id = git_get_hash_by_ref("$project/$ref_dir/$ref_file");
981 my $type = git_get_type($ref_id) || next;
982 my %ref_item = parse_ref($ref_file, $ref_id, $type);
984 push @reflist, \%ref_item;
987 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
991 ## ----------------------------------------------------------------------
992 ## filesystem-related functions
997 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
998 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
999 if (!defined $gcos) {
1003 $owner =~ s/[,;].*$//;
1004 return decode("utf8", $owner, Encode::FB_DEFAULT);
1007 ## ......................................................................
1008 ## mimetype related functions
1010 sub mimetype_guess_file {
1011 my $filename = shift;
1012 my $mimemap = shift;
1013 -r $mimemap or return undef;
1016 open(MIME, $mimemap) or return undef;
1018 next if m/^#/; # skip comments
1019 my ($mime, $exts) = split(/\t+/);
1020 if (defined $exts) {
1021 my @exts = split(/\s+/, $exts);
1022 foreach my $ext (@exts) {
1023 $mimemap{$ext} = $mime;
1029 $filename =~ /\.(.*?)$/;
1030 return $mimemap{$1};
1033 sub mimetype_guess {
1034 my $filename = shift;
1036 $filename =~ /\./ or return undef;
1038 if ($mimetypes_file) {
1039 my $file = $mimetypes_file;
1040 if ($file !~ m!^/!) { # if it is relative path
1041 # it is relative to project
1042 $file = "$projectroot/$project/$file";
1044 $mime = mimetype_guess_file($filename, $file);
1046 $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
1052 my $filename = shift;
1055 my $mime = mimetype_guess($filename);
1056 $mime and return $mime;
1060 return $default_blob_plain_mimetype unless $fd;
1063 return 'text/plain' .
1064 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1065 } elsif (! $filename) {
1066 return 'application/octet-stream';
1067 } elsif ($filename =~ m/\.png$/i) {
1069 } elsif ($filename =~ m/\.gif$/i) {
1071 } elsif ($filename =~ m/\.jpe?g$/i) {
1072 return 'image/jpeg';
1074 return 'application/octet-stream';
1078 ## ======================================================================
1079 ## functions printing HTML: header, footer, error page
1081 sub git_header_html {
1082 my $status = shift || "200 OK";
1083 my $expires = shift;
1085 my $title = "$site_name git";
1086 if (defined $project) {
1087 $title .= " - $project";
1088 if (defined $action) {
1089 $title .= "/$action";
1090 if (defined $file_name) {
1091 $title .= " - $file_name";
1092 if ($action eq "tree" && $file_name !~ m|/$|) {
1099 # require explicit support from the UA if we are to send the page as
1100 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1101 # we have to do this because MSIE sometimes globs '*/*', pretending to
1102 # support xhtml+xml but choking when it gets what it asked for.
1103 if (defined $cgi->http('HTTP_ACCEPT') &&
1104 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&
1105 $cgi->Accept('application/xhtml+xml') != 0) {
1106 $content_type = 'application/xhtml+xml';
1108 $content_type = 'text/html';
1110 print $cgi->header(-type=>$content_type, -charset => 'utf-8',
1111 -status=> $status, -expires => $expires);
1113 <?xml version="1.0" encoding="utf-8"?>
1114 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1115 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1116 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1117 <!-- git core binaries version $git_version -->
1119 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1120 <meta name="generator" content="gitweb/$version git/$git_version"/>
1121 <meta name="robots" content="index, nofollow"/>
1122 <title>$title</title>
1123 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1125 if (defined $project) {
1126 printf('<link rel="alternate" title="%s log" '.
1127 'href="%s" type="application/rss+xml"/>'."\n",
1128 esc_param($project), href(action=>"rss"));
1133 "<div class=\"page_header\">\n" .
1134 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1135 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1137 print $cgi->a({-href => esc_param($home_link)}, $home_link_str) . " / ";
1138 if (defined $project) {
1139 print $cgi->a({-href => href(action=>"summary")}, esc_html($project));
1140 if (defined $action) {
1144 if (!defined $searchtext) {
1148 if (defined $hash_base) {
1149 $search_hash = $hash_base;
1150 } elsif (defined $hash) {
1151 $search_hash = $hash;
1153 $search_hash = "HEAD";
1155 $cgi->param("a", "search");
1156 $cgi->param("h", $search_hash);
1157 print $cgi->startform(-method => "get", -action => $my_uri) .
1158 "<div class=\"search\">\n" .
1159 $cgi->hidden(-name => "p") . "\n" .
1160 $cgi->hidden(-name => "a") . "\n" .
1161 $cgi->hidden(-name => "h") . "\n" .
1162 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
1164 $cgi->end_form() . "\n";
1169 sub git_footer_html {
1170 print "<div class=\"page_footer\">\n";
1171 if (defined $project) {
1172 my $descr = git_get_project_description($project);
1173 if (defined $descr) {
1174 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
1176 print $cgi->a({-href => href(action=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1178 print $cgi->a({-href => href(action=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1186 my $status = shift || "403 Forbidden";
1187 my $error = shift || "Malformed query, file missing or permission denied";
1189 git_header_html($status);
1191 <div class="page_body">
1201 ## ----------------------------------------------------------------------
1202 ## functions printing or outputting HTML: navigation
1204 sub git_print_page_nav {
1205 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1206 $extra = '' if !defined $extra; # pager or formats
1208 my @navs = qw(summary shortlog log commit commitdiff tree);
1210 @navs = grep { $_ ne $suppress } @navs;
1213 my %arg = map { $_ => {action=>$_} } @navs;
1214 if (defined $head) {
1215 for (qw(commit commitdiff)) {
1216 $arg{$_}{hash} = $head;
1218 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1219 for (qw(shortlog log)) {
1220 $arg{$_}{hash} = $head;
1224 $arg{tree}{hash} = $treehead if defined $treehead;
1225 $arg{tree}{hash_base} = $treebase if defined $treebase;
1227 print "<div class=\"page_nav\">\n" .
1229 map { $_ eq $current ?
1230 $_ : $cgi->a({-href => href(%{$arg{$_}})}, "$_")
1232 print "<br/>\n$extra<br/>\n" .
1236 sub format_paging_nav {
1237 my ($action, $hash, $head, $page, $nrevs) = @_;
1241 if ($hash ne $head || $page) {
1242 $paging_nav .= $cgi->a({-href => href(action=>$action)}, "HEAD");
1244 $paging_nav .= "HEAD";
1248 $paging_nav .= " ⋅ " .
1249 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page-1),
1250 -accesskey => "p", -title => "Alt-p"}, "prev");
1252 $paging_nav .= " ⋅ prev";
1255 if ($nrevs >= (100 * ($page+1)-1)) {
1256 $paging_nav .= " ⋅ " .
1257 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page+1),
1258 -accesskey => "n", -title => "Alt-n"}, "next");
1260 $paging_nav .= " ⋅ next";
1266 ## ......................................................................
1267 ## functions printing or outputting HTML: div
1269 sub git_print_header_div {
1270 my ($action, $title, $hash, $hash_base) = @_;
1273 $args{action} = $action;
1274 $args{hash} = $hash if $hash;
1275 $args{hash_base} = $hash_base if $hash_base;
1277 print "<div class=\"header\">\n" .
1278 $cgi->a({-href => href(%args), -class => "title"},
1279 $title ? $title : $action) .
1283 sub git_print_page_path {
1288 if (!defined $name) {
1289 print "<div class=\"page_path\">/</div>\n";
1290 } elsif (defined $type && $type eq 'blob') {
1291 print "<div class=\"page_path\">";
1293 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,
1297 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name)},
1300 print "<br/></div>\n";
1302 print "<div class=\"page_path\">" . esc_html($name) . "<br/></div>\n";
1309 # remove leading empty lines
1310 while (defined $log->[0] && $log->[0] eq "") {
1317 foreach my $line (@$log) {
1318 # print only one empty line
1319 # do not print empty line after signoff
1321 next if ($empty || $signoff);
1326 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1328 print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
1331 print format_log_line_html($line) . "<br/>\n";
1336 sub git_print_simplified_log {
1338 my $remove_title = shift;
1340 shift @$log if $remove_title;
1341 # remove leading empty lines
1342 while (defined $log->[0] && $log->[0] eq "") {
1346 # simplify and print log
1348 foreach my $line (@$log) {
1349 # remove signoff lines
1350 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1353 # print only one empty line
1360 print format_log_line_html($line) . "<br/>\n";
1362 # end with single empty line
1363 print "<br/>\n" unless $empty;
1366 ## ......................................................................
1367 ## functions printing large fragments of HTML
1369 sub git_difftree_body {
1370 my ($difftree, $parent) = @_;
1372 print "<div class=\"list_head\">\n";
1373 if ($#{$difftree} > 10) {
1374 print(($#{$difftree} + 1) . " files changed:\n");
1378 print "<table class=\"diff_tree\">\n";
1380 foreach my $line (@{$difftree}) {
1381 my %diff = parse_difftree_raw_line($line);
1384 print "<tr class=\"dark\">\n";
1386 print "<tr class=\"light\">\n";
1390 my ($to_mode_oct, $to_mode_str, $to_file_type);
1391 my ($from_mode_oct, $from_mode_str, $from_file_type);
1392 if ($diff{'to_mode'} ne ('0' x 6)) {
1393 $to_mode_oct = oct $diff{'to_mode'};
1394 if (S_ISREG($to_mode_oct)) { # only for regular file
1395 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1397 $to_file_type = file_type($diff{'to_mode'});
1399 if ($diff{'from_mode'} ne ('0' x 6)) {
1400 $from_mode_oct = oct $diff{'from_mode'};
1401 if (S_ISREG($to_mode_oct)) { # only for regular file
1402 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1404 $from_file_type = file_type($diff{'from_mode'});
1407 if ($diff{'status'} eq "A") { # created
1408 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1409 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1410 $mode_chng .= "]</span>";
1412 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1413 hash_base=>$hash, file_name=>$diff{'file'}),
1414 -class => "list"}, esc_html($diff{'file'})) .
1416 "<td>$mode_chng</td>\n" .
1417 "<td class=\"link\">" .
1418 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1419 hash_base=>$hash, file_name=>$diff{'file'})},
1423 } elsif ($diff{'status'} eq "D") { # deleted
1424 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1426 $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
1427 hash_base=>$parent, file_name=>$diff{'file'}),
1428 -class => "list"}, esc_html($diff{'file'})) .
1430 "<td>$mode_chng</td>\n" .
1431 "<td class=\"link\">" .
1432 $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
1433 hash_base=>$parent, file_name=>$diff{'file'})},
1436 $cgi->a({-href => href(action=>"history", hash_base=>$parent,
1437 file_name=>$diff{'file'})},\
1441 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1442 my $mode_chnge = "";
1443 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1444 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1445 if ($from_file_type != $to_file_type) {
1446 $mode_chnge .= " from $from_file_type to $to_file_type";
1448 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1449 if ($from_mode_str && $to_mode_str) {
1450 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1451 } elsif ($to_mode_str) {
1452 $mode_chnge .= " mode: $to_mode_str";
1455 $mode_chnge .= "]</span>\n";
1458 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1459 print $cgi->a({-href => href(action=>"blobdiff", hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1460 hash_base=>$hash, file_name=>$diff{'file'}),
1461 -class => "list"}, esc_html($diff{'file'}));
1462 } else { # only mode changed
1463 print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1464 hash_base=>$hash, file_name=>$diff{'file'}),
1465 -class => "list"}, esc_html($diff{'file'}));
1468 "<td>$mode_chnge</td>\n" .
1469 "<td class=\"link\">" .
1470 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1471 hash_base=>$hash, file_name=>$diff{'file'})},
1473 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1475 $cgi->a({-href => href(action=>"blobdiff", hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1476 hash_base=>$hash, file_name=>$diff{'file'})},
1480 $cgi->a({-href => href(action=>"history",
1481 hash_base=>$hash, file_name=>$diff{'file'})},
1485 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1486 my %status_name = ('R' => 'moved', 'C' => 'copied');
1487 my $nstatus = $status_name{$diff{'status'}};
1489 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1490 # mode also for directories, so we cannot use $to_mode_str
1491 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1494 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1495 hash=>$diff{'to_id'}, file_name=>$diff{'to_file'}),
1496 -class => "list"}, esc_html($diff{'to_file'})) . "</td>\n" .
1497 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1498 $cgi->a({-href => href(action=>"blob", hash_base=>$parent,
1499 hash=>$diff{'from_id'}, file_name=>$diff{'from_file'}),
1500 -class => "list"}, esc_html($diff{'from_file'})) .
1501 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1502 "<td class=\"link\">" .
1503 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1504 hash=>$diff{'to_id'}, file_name=>$diff{'to_file'})},
1506 if ($diff{'to_id'} ne $diff{'from_id'}) {
1508 $cgi->a({-href => href(action=>"blobdiff", hash_base=>$hash,
1509 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1510 file_name=>$diff{'to_file'}, file_parent=>$diff{'from_file'})},
1515 } # we should not encounter Unmerged (U) or Unknown (X) status
1521 sub git_shortlog_body {
1522 # uses global variable $project
1523 my ($revlist, $from, $to, $refs, $extra) = @_;
1525 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
1526 my $have_snapshot = (defined $ctype && defined $suffix);
1528 $from = 0 unless defined $from;
1529 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1531 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1533 for (my $i = $from; $i <= $to; $i++) {
1534 my $commit = $revlist->[$i];
1535 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1536 my $ref = format_ref_marker($refs, $commit);
1537 my %co = parse_commit($commit);
1539 print "<tr class=\"dark\">\n";
1541 print "<tr class=\"light\">\n";
1544 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1545 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1546 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1548 print format_subject_html($co{'title'}, $co{'title_short'},
1549 href(action=>"commit", hash=>$commit), $ref);
1551 "<td class=\"link\">" .
1552 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
1553 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff");
1554 if ($have_snapshot) {
1555 print " | " . $cgi->a({-href => href(action=>"snapshot", hash=>$commit)}, "snapshot");
1560 if (defined $extra) {
1562 "<td colspan=\"4\">$extra</td>\n" .
1568 sub git_history_body {
1569 # Warning: assumes constant type (blob or tree) during history
1570 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1572 print "<table class=\"history\" cellspacing=\"0\">\n";
1574 while (my $line = <$fd>) {
1575 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1580 my %co = parse_commit($commit);
1585 my $ref = format_ref_marker($refs, $commit);
1588 print "<tr class=\"dark\">\n";
1590 print "<tr class=\"light\">\n";
1593 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1594 # shortlog uses chop_str($co{'author_name'}, 10)
1595 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1597 # originally git_history used chop_str($co{'title'}, 50)
1598 print format_subject_html($co{'title'}, $co{'title_short'},
1599 href(action=>"commit", hash=>$commit), $ref);
1601 "<td class=\"link\">" .
1602 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
1603 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
1604 $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype);
1606 if ($ftype eq 'blob') {
1607 my $blob_current = git_get_hash_by_path($hash_base, $file_name);
1608 my $blob_parent = git_get_hash_by_path($commit, $file_name);
1609 if (defined $blob_current && defined $blob_parent &&
1610 $blob_current ne $blob_parent) {
1612 $cgi->a({-href => href(action=>"blobdiff", hash=>$blob_current, hash_parent=>$blob_parent,
1613 hash_base=>$commit, file_name=>$file_name)},
1620 if (defined $extra) {
1622 "<td colspan=\"4\">$extra</td>\n" .
1629 # uses global variable $project
1630 my ($taglist, $from, $to, $extra) = @_;
1631 $from = 0 unless defined $from;
1632 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1634 print "<table class=\"tags\" cellspacing=\"0\">\n";
1636 for (my $i = $from; $i <= $to; $i++) {
1637 my $entry = $taglist->[$i];
1639 my $comment_lines = $tag{'comment'};
1640 my $comment = shift @$comment_lines;
1642 if (defined $comment) {
1643 $comment_short = chop_str($comment, 30, 5);
1646 print "<tr class=\"dark\">\n";
1648 print "<tr class=\"light\">\n";
1651 print "<td><i>$tag{'age'}</i></td>\n" .
1653 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),
1654 -class => "list name"}, esc_html($tag{'name'})) .
1657 if (defined $comment) {
1658 print format_subject_html($comment, $comment_short,
1659 href(action=>"tag", hash=>$tag{'id'}));
1662 "<td class=\"selflink\">";
1663 if ($tag{'type'} eq "tag") {
1664 print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag");
1669 "<td class=\"link\">" . " | " .
1670 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'});
1671 if ($tag{'reftype'} eq "commit") {
1672 print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") .
1673 " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'refid'})}, "log");
1674 } elsif ($tag{'reftype'} eq "blob") {
1675 print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw");
1680 if (defined $extra) {
1682 "<td colspan=\"5\">$extra</td>\n" .
1688 sub git_heads_body {
1689 # uses global variable $project
1690 my ($taglist, $head, $from, $to, $extra) = @_;
1691 $from = 0 unless defined $from;
1692 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1694 print "<table class=\"heads\" cellspacing=\"0\">\n";
1696 for (my $i = $from; $i <= $to; $i++) {
1697 my $entry = $taglist->[$i];
1699 my $curr = $tag{'id'} eq $head;
1701 print "<tr class=\"dark\">\n";
1703 print "<tr class=\"light\">\n";
1706 print "<td><i>$tag{'age'}</i></td>\n" .
1707 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
1708 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'}),
1709 -class => "list name"},esc_html($tag{'name'})) .
1711 "<td class=\"link\">" .
1712 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") . " | " .
1713 $cgi->a({-href => href(action=>"log", hash=>$tag{'name'})}, "log") .
1717 if (defined $extra) {
1719 "<td colspan=\"3\">$extra</td>\n" .
1725 ## ----------------------------------------------------------------------
1726 ## functions printing large fragments, format as one of arguments
1728 sub git_diff_print {
1730 my $from_name = shift;
1732 my $to_name = shift;
1733 my $format = shift || "html";
1735 my $from_tmp = "/dev/null";
1736 my $to_tmp = "/dev/null";
1739 # create tmp from-file
1740 if (defined $from) {
1741 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1742 open my $fd2, "> $from_tmp";
1743 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1750 # create tmp to-file
1752 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1753 open my $fd2, "> $to_tmp";
1754 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1761 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1762 if ($format eq "plain") {
1767 while (my $line = <$fd>) {
1769 my $char = substr($line, 0, 1);
1770 my $diff_class = "";
1772 $diff_class = " add";
1773 } elsif ($char eq "-") {
1774 $diff_class = " rem";
1775 } elsif ($char eq "@") {
1776 $diff_class = " chunk_header";
1777 } elsif ($char eq "\\") {
1781 $line = untabify($line);
1782 print "<div class=\"diff$diff_class\">" . esc_html($line) . "</div>\n";
1787 if (defined $from) {
1796 ## ======================================================================
1797 ## ======================================================================
1800 sub git_project_list {
1801 my $order = $cgi->param('o');
1802 if (defined $order && $order !~ m/project|descr|owner|age/) {
1803 die_error(undef, "Unknown order parameter");
1806 my @list = git_get_projects_list();
1809 die_error(undef, "No projects found");
1811 foreach my $pr (@list) {
1812 my $head = git_get_head_hash($pr->{'path'});
1813 if (!defined $head) {
1816 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1817 my %co = parse_commit($head);
1821 $pr->{'commit'} = \%co;
1822 if (!defined $pr->{'descr'}) {
1823 my $descr = git_get_project_description($pr->{'path'}) || "";
1824 $pr->{'descr'} = chop_str($descr, 25, 5);
1826 if (!defined $pr->{'owner'}) {
1827 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
1829 push @projects, $pr;
1833 if (-f $home_text) {
1834 print "<div class=\"index_include\">\n";
1835 open (my $fd, $home_text);
1840 print "<table class=\"project_list\">\n" .
1842 $order ||= "project";
1843 if ($order eq "project") {
1844 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1845 print "<th>Project</th>\n";
1848 $cgi->a({-href => "$my_uri?" . esc_param("o=project"),
1849 -class => "header"}, "Project") .
1852 if ($order eq "descr") {
1853 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1854 print "<th>Description</th>\n";
1857 $cgi->a({-href => "$my_uri?" . esc_param("o=descr"),
1858 -class => "header"}, "Description") .
1861 if ($order eq "owner") {
1862 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1863 print "<th>Owner</th>\n";
1866 $cgi->a({-href => "$my_uri?" . esc_param("o=owner"),
1867 -class => "header"}, "Owner") .
1870 if ($order eq "age") {
1871 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1872 print "<th>Last Change</th>\n";
1875 $cgi->a({-href => "$my_uri?" . esc_param("o=age"),
1876 -class => "header"}, "Last Change") .
1879 print "<th></th>\n" .
1882 foreach my $pr (@projects) {
1884 print "<tr class=\"dark\">\n";
1886 print "<tr class=\"light\">\n";
1889 print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
1890 -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
1891 "<td>" . esc_html($pr->{'descr'}) . "</td>\n" .
1892 "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
1893 print "<td class=\"". age_class($pr->{'commit'}{'age'}) . "\">" .
1894 $pr->{'commit'}{'age_string'} . "</td>\n" .
1895 "<td class=\"link\">" .
1896 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
1897 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
1898 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") .
1907 my $descr = git_get_project_description($project) || "none";
1908 my $head = git_get_head_hash($project);
1909 my %co = parse_commit($head);
1910 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
1912 my $owner = git_get_project_owner($project);
1914 my $refs = git_get_references();
1916 git_print_page_nav('summary','', $head);
1918 print "<div class=\"title\"> </div>\n";
1919 print "<table cellspacing=\"0\">\n" .
1920 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
1921 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1922 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
1923 # use per project git URL list in $projectroot/$project/cloneurl
1924 # or make project git URL from git base URL and project name
1925 my $url_tag = "URL";
1926 my @url_list = git_get_project_url_list($project);
1927 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
1928 foreach my $git_url (@url_list) {
1929 next unless $git_url;
1930 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
1935 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash($project)
1936 or die_error(undef, "Open git-rev-list failed");
1937 my @revlist = map { chomp; $_ } <$fd>;
1939 git_print_header_div('shortlog');
1940 git_shortlog_body(\@revlist, 0, 15, $refs,
1941 $cgi->a({-href => href(action=>"shortlog")}, "..."));
1943 my $taglist = git_get_refs_list("refs/tags");
1944 if (defined @$taglist) {
1945 git_print_header_div('tags');
1946 git_tags_body($taglist, 0, 15,
1947 $cgi->a({-href => href(action=>"tags")}, "..."));
1950 my $headlist = git_get_refs_list("refs/heads");
1951 if (defined @$headlist) {
1952 git_print_header_div('heads');
1953 git_heads_body($headlist, $head, 0, 15,
1954 $cgi->a({-href => href(action=>"heads")}, "..."));
1961 my $head = git_get_head_hash($project);
1963 git_print_page_nav('','', $head,undef,$head);
1964 my %tag = parse_tag($hash);
1965 git_print_header_div('commit', esc_html($tag{'name'}), $hash);
1966 print "<div class=\"title_text\">\n" .
1967 "<table cellspacing=\"0\">\n" .
1969 "<td>object</td>\n" .
1970 "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
1971 $tag{'object'}) . "</td>\n" .
1972 "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
1973 $tag{'type'}) . "</td>\n" .
1975 if (defined($tag{'author'})) {
1976 my %ad = parse_date($tag{'epoch'}, $tag{'tz'});
1977 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
1978 print "<tr><td></td><td>" . $ad{'rfc2822'} .
1979 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
1982 print "</table>\n\n" .
1984 print "<div class=\"page_body\">";
1985 my $comment = $tag{'comment'};
1986 foreach my $line (@$comment) {
1987 print esc_html($line) . "<br/>\n";
1997 if (!gitweb_check_feature('blame')) {
1998 die_error('403 Permission denied', "Permission denied");
2000 die_error('404 Not Found', "File name not defined") if (!$file_name);
2001 $hash_base ||= git_get_head_hash($project);
2002 die_error(undef, "Couldn't find base commit") unless ($hash_base);
2003 my %co = parse_commit($hash_base)
2004 or die_error(undef, "Reading commit failed");
2005 if (!defined $hash) {
2006 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
2007 or die_error(undef, "Error looking up file");
2009 $ftype = git_get_type($hash);
2010 if ($ftype !~ "blob") {
2011 die_error("400 Bad Request", "Object is not a blob");
2013 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
2014 or die_error(undef, "Open git-blame failed");
2017 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2020 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
2022 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2023 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2024 git_print_page_path($file_name, $ftype, $hash_base);
2025 my @rev_color = (qw(light2 dark2));
2026 my $num_colors = scalar(@rev_color);
2027 my $current_color = 0;
2030 <div class="page_body">
2031 <table class="blame">
2032 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2035 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2037 my $rev = substr($full_rev, 0, 8);
2041 if (!defined $last_rev) {
2042 $last_rev = $full_rev;
2043 } elsif ($last_rev ne $full_rev) {
2044 $last_rev = $full_rev;
2045 $current_color = ++$current_color % $num_colors;
2047 print "<tr class=\"$rev_color[$current_color]\">\n";
2048 print "<td class=\"sha1\">" .
2049 $cgi->a({-href => href(action=>"commit", hash=>$full_rev, file_name=>$file_name)},
2050 esc_html($rev)) . "</td>\n";
2051 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2052 esc_html($lineno) . "</a></td>\n";
2053 print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
2059 or print "Reading blob failed\n";
2066 if (!gitweb_check_feature('blame')) {
2067 die_error('403 Permission denied', "Permission denied");
2069 die_error('404 Not Found', "File name not defined") if (!$file_name);
2070 $hash_base ||= git_get_head_hash($project);
2071 die_error(undef, "Couldn't find base commit") unless ($hash_base);
2072 my %co = parse_commit($hash_base)
2073 or die_error(undef, "Reading commit failed");
2074 if (!defined $hash) {
2075 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
2076 or die_error(undef, "Error lookup file");
2078 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2079 or die_error(undef, "Open git-annotate failed");
2082 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2085 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
2087 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2088 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2089 git_print_page_path($file_name, 'blob', $hash_base);
2090 print "<div class=\"page_body\">\n";
2092 <table class="blame">
2101 my @line_class = (qw(light dark));
2102 my $line_class_len = scalar (@line_class);
2103 my $line_class_num = $#line_class;
2104 while (my $line = <$fd>) {
2116 $line_class_num = ($line_class_num + 1) % $line_class_len;
2118 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
2125 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
2128 $short_rev = substr ($long_rev, 0, 8);
2129 $age = time () - $time;
2130 $age_str = age_string ($age);
2131 $age_str =~ s/ / /g;
2132 $age_class = age_class($age);
2133 $author = esc_html ($author);
2134 $author =~ s/ / /g;
2136 $data = untabify($data);
2137 $data = esc_html ($data);
2140 <tr class="$line_class[$line_class_num]">
2141 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2142 <td class="$age_class">$age_str</td>
2144 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2145 <td class="pre">$data</td>
2148 } # while (my $line = <$fd>)
2149 print "</table>\n\n";
2151 or print "Reading blob failed.\n";
2157 my $head = git_get_head_hash($project);
2159 git_print_page_nav('','', $head,undef,$head);
2160 git_print_header_div('summary', $project);
2162 my $taglist = git_get_refs_list("refs/tags");
2163 if (defined @$taglist) {
2164 git_tags_body($taglist);
2170 my $head = git_get_head_hash($project);
2172 git_print_page_nav('','', $head,undef,$head);
2173 git_print_header_div('summary', $project);
2175 my $taglist = git_get_refs_list("refs/heads");
2176 if (defined @$taglist) {
2177 git_heads_body($taglist, $head);
2182 sub git_blob_plain {
2183 if (!defined $hash) {
2184 if (defined $file_name) {
2185 my $base = $hash_base || git_get_head_hash($project);
2186 $hash = git_get_hash_by_path($base, $file_name, "blob")
2187 or die_error(undef, "Error lookup file");
2189 die_error(undef, "No file name defined");
2193 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2194 or die_error(undef, "Couldn't cat $file_name, $hash");
2196 $type ||= blob_mimetype($fd, $file_name);
2198 # save as filename, even when no $file_name is given
2199 my $save_as = "$hash";
2200 if (defined $file_name) {
2201 $save_as = $file_name;
2202 } elsif ($type =~ m/^text\//) {
2206 print $cgi->header(-type => "$type",
2207 -content_disposition => "inline; filename=\"$save_as\"");
2209 binmode STDOUT, ':raw';
2211 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
2217 if (!defined $hash) {
2218 if (defined $file_name) {
2219 my $base = $hash_base || git_get_head_hash($project);
2220 $hash = git_get_hash_by_path($base, $file_name, "blob")
2221 or die_error(undef, "Error lookup file");
2223 die_error(undef, "No file name defined");
2226 my $have_blame = gitweb_check_feature('blame');
2227 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2228 or die_error(undef, "Couldn't cat $file_name, $hash");
2229 my $mimetype = blob_mimetype($fd, $file_name);
2230 if ($mimetype !~ m/^text\//) {
2232 return git_blob_plain($mimetype);
2235 my $formats_nav = '';
2236 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2237 if (defined $file_name) {
2240 $cgi->a({-href => href(action=>"blame", hash_base=>$hash_base,
2241 hash=>$hash, file_name=>$file_name)},
2246 $cgi->a({-href => href(action=>"blob_plain",
2247 hash=>$hash, file_name=>$file_name)},
2250 $cgi->a({-href => href(action=>"blob",
2251 hash_base=>"HEAD", file_name=>$file_name)},
2255 $cgi->a({-href => href(action=>"blob_plain", hash=>$hash)}, "plain");
2257 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2258 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2260 print "<div class=\"page_nav\">\n" .
2261 "<br/><br/></div>\n" .
2262 "<div class=\"title\">$hash</div>\n";
2264 git_print_page_path($file_name, "blob", $hash_base);
2265 print "<div class=\"page_body\">\n";
2267 while (my $line = <$fd>) {
2270 $line = untabify($line);
2271 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2272 $nr, $nr, $nr, esc_html($line);
2275 or print "Reading blob failed.\n";
2281 if (!defined $hash) {
2282 $hash = git_get_head_hash($project);
2283 if (defined $file_name) {
2284 my $base = $hash_base || $hash;
2285 $hash = git_get_hash_by_path($base, $file_name, "tree");
2287 if (!defined $hash_base) {
2292 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
2293 or die_error(undef, "Open git-ls-tree failed");
2294 my @entries = map { chomp; $_ } <$fd>;
2295 close $fd or die_error(undef, "Reading tree failed");
2298 my $refs = git_get_references();
2299 my $ref = format_ref_marker($refs, $hash_base);
2303 my $have_blame = gitweb_check_feature('blame');
2304 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2305 $base_key{hash_base} = $hash_base;
2306 git_print_page_nav('tree','', $hash_base);
2307 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
2309 print "<div class=\"page_nav\">\n";
2310 print "<br/><br/></div>\n";
2311 print "<div class=\"title\">$hash</div>\n";
2313 if (defined $file_name) {
2314 $base = esc_html("$file_name/");
2316 git_print_page_path($file_name, 'tree', $hash_base);
2317 print "<div class=\"page_body\">\n";
2318 print "<table cellspacing=\"0\">\n";
2320 foreach my $line (@entries) {
2321 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2322 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2326 my $t_name = validate_input($4);
2328 print "<tr class=\"dark\">\n";
2330 print "<tr class=\"light\">\n";
2333 print "<td class=\"mode\">" . mode_str($t_mode) . "</td>\n";
2334 if ($t_type eq "blob") {
2335 print "<td class=\"list\">" .
2336 $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key),
2337 -class => "list"}, esc_html($t_name)) .
2339 "<td class=\"link\">" .
2340 $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2344 $cgi->a({-href => href(action=>"blame", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2348 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
2349 hash=>$t_hash, file_name=>"$base$t_name")},
2352 $cgi->a({-href => href(action=>"blob_plain",
2353 hash=>$t_hash, file_name=>"$base$t_name")},
2356 } elsif ($t_type eq "tree") {
2357 print "<td class=\"list\">" .
2358 $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2359 esc_html($t_name)) .
2361 "<td class=\"link\">" .
2362 $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2365 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, file_name=>"$base$t_name")},
2371 print "</table>\n" .
2378 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
2379 my $have_snapshot = (defined $ctype && defined $suffix);
2380 if (!$have_snapshot) {
2381 die_error('403 Permission denied', "Permission denied");
2384 if (!defined $hash) {
2385 $hash = git_get_head_hash($project);
2388 my $filename = basename($project) . "-$hash.tar.$suffix";
2390 print $cgi->header(-type => 'application/x-tar',
2391 -content_encoding => $ctype,
2392 -content_disposition => "inline; filename=\"$filename\"",
2393 -status => '200 OK');
2395 open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | $command" or
2396 die_error(undef, "Execute git-tar-tree failed.");
2397 binmode STDOUT, ':raw';
2399 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
2405 my $head = git_get_head_hash($project);
2406 if (!defined $hash) {
2409 if (!defined $page) {
2412 my $refs = git_get_references();
2414 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2415 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2416 or die_error(undef, "Open git-rev-list failed");
2417 my @revlist = map { chomp; $_ } <$fd>;
2420 my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#revlist);
2423 git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
2426 my %co = parse_commit($hash);
2428 git_print_header_div('summary', $project);
2429 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2431 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2432 my $commit = $revlist[$i];
2433 my $ref = format_ref_marker($refs, $commit);
2434 my %co = parse_commit($commit);
2436 my %ad = parse_date($co{'author_epoch'});
2437 git_print_header_div('commit',
2438 "<span class=\"age\">$co{'age_string'}</span>" .
2439 esc_html($co{'title'}) . $ref,
2441 print "<div class=\"title_text\">\n" .
2442 "<div class=\"log_link\">\n" .
2443 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
2445 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
2448 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2451 print "<div class=\"log_body\">\n";
2452 git_print_simplified_log($co{'comment'});
2459 my %co = parse_commit($hash);
2461 die_error(undef, "Unknown commit object");
2463 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
2464 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
2466 my $parent = $co{'parent'};
2467 if (!defined $parent) {
2470 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
2471 or die_error(undef, "Open git-diff-tree failed");
2472 my @difftree = map { chomp; $_ } <$fd>;
2473 close $fd or die_error(undef, "Reading git-diff-tree failed");
2475 # non-textual hash id's can be cached
2477 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2480 my $refs = git_get_references();
2481 my $ref = format_ref_marker($refs, $co{'id'});
2483 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
2484 my $have_snapshot = (defined $ctype && defined $suffix);
2486 my $formats_nav = '';
2487 if (defined $file_name && defined $co{'parent'}) {
2488 my $parent = $co{'parent'};
2490 $cgi->a({-href => href(action=>"blame", hash_parent=>$parent, file_name=>$file_name)},
2493 git_header_html(undef, $expires);
2494 git_print_page_nav('commit', defined $co{'parent'} ? '' : 'commitdiff',
2495 $hash, $co{'tree'}, $hash,
2498 if (defined $co{'parent'}) {
2499 git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash);
2501 git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash);
2503 print "<div class=\"title_text\">\n" .
2504 "<table cellspacing=\"0\">\n";
2505 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
2507 "<td></td><td> $ad{'rfc2822'}";
2508 if ($ad{'hour_local'} < 6) {
2509 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2510 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2512 printf(" (%02d:%02d %s)",
2513 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2517 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
2518 print "<tr><td></td><td> $cd{'rfc2822'}" .
2519 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2521 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2524 "<td class=\"sha1\">" .
2525 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),
2526 class => "list"}, $co{'tree'}) .
2528 "<td class=\"link\">" .
2529 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},
2531 if ($have_snapshot) {
2533 $cgi->a({-href => href(action=>"snapshot", hash=>$hash)}, "snapshot");
2537 my $parents = $co{'parents'};
2538 foreach my $par (@$parents) {
2541 "<td class=\"sha1\">" .
2542 $cgi->a({-href => href(action=>"commit", hash=>$par),
2543 class => "list"}, $par) .
2545 "<td class=\"link\">" .
2546 $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") .
2548 $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "commitdiff") .
2555 print "<div class=\"page_body\">\n";
2556 git_print_log($co{'comment'});
2559 git_difftree_body(\@difftree, $parent);
2565 mkdir($git_temp, 0700);
2567 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2569 $cgi->a({-href => href(action=>"blobdiff_plain",
2570 hash=>$hash, hash_parent=>$hash_parent)},
2572 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2573 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2576 <div class="page_nav"><br/><br/></div>
2577 <div class="title">$hash vs $hash_parent</div>
2580 git_print_page_path($file_name, "blob", $hash_base);
2581 print "<div class=\"page_body\">\n" .
2582 "<div class=\"diff_info\">blob:" .
2583 $cgi->a({-href => href(action=>"blob", hash=>$hash_parent,
2584 hash_base=>$hash_base, file_name=>($file_parent || $file_name))},
2587 $cgi->a({-href => href(action=>"blob", hash=>$hash,
2588 hash_base=>$hash_base, file_name=>$file_name)},
2591 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2592 print "</div>"; # page_body
2596 sub git_blobdiff_plain {
2597 mkdir($git_temp, 0700);
2598 print $cgi->header(-type => "text/plain", -charset => 'utf-8');
2599 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2602 sub git_commitdiff {
2603 mkdir($git_temp, 0700);
2604 my %co = parse_commit($hash);
2606 die_error(undef, "Unknown commit object");
2608 if (!defined $hash_parent) {
2609 $hash_parent = $co{'parent'} || '--root';
2611 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2612 or die_error(undef, "Open git-diff-tree failed");
2613 my @difftree = map { chomp; $_ } <$fd>;
2614 close $fd or die_error(undef, "Reading git-diff-tree failed");
2616 # non-textual hash id's can be cached
2618 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2621 my $refs = git_get_references();
2622 my $ref = format_ref_marker($refs, $co{'id'});
2624 $cgi->a({-href => href(action=>"commitdiff_plain", hash=>$hash, hash_parent=>$hash_parent)},
2626 git_header_html(undef, $expires);
2627 git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2628 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
2629 print "<div class=\"page_body\">\n";
2630 git_print_simplified_log($co{'comment'}, 1); # skip title
2632 foreach my $line (@difftree) {
2633 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2634 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2635 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2643 my $file = validate_input(unquote($6));
2644 if ($status eq "A") {
2645 print "<div class=\"diff_info\">" . file_type($to_mode) . ":" .
2646 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
2647 hash=>$to_id, file_name=>$file)},
2650 git_diff_print(undef, "/dev/null", $to_id, "b/$file");
2651 } elsif ($status eq "D") {
2652 print "<div class=\"diff_info\">" . file_type($from_mode) . ":" .
2653 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
2654 hash=>$from_id, file_name=>$file)},
2655 $from_id) . "(deleted)" .
2657 git_diff_print($from_id, "a/$file", undef, "/dev/null");
2658 } elsif ($status eq "M") {
2659 if ($from_id ne $to_id) {
2660 print "<div class=\"diff_info\">" .
2661 file_type($from_mode) . ":" .
2662 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
2663 hash=>$from_id, file_name=>$file)},
2666 file_type($to_mode) . ":" .
2667 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
2668 hash=>$to_id, file_name=>$file)},
2671 git_diff_print($from_id, "a/$file", $to_id, "b/$file");
2680 sub git_commitdiff_plain {
2681 mkdir($git_temp, 0700);
2682 my %co = parse_commit($hash);
2684 die_error(undef, "Unknown commit object");
2686 if (!defined $hash_parent) {
2687 $hash_parent = $co{'parent'} || '--root';
2689 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2690 or die_error(undef, "Open git-diff-tree failed");
2691 my @difftree = map { chomp; $_ } <$fd>;
2692 close $fd or die_error(undef, "Reading diff-tree failed");
2694 # try to figure out the next tag after this commit
2696 my $refs = git_get_references("tags");
2697 open $fd, "-|", $GIT, "rev-list", "HEAD";
2698 my @commits = map { chomp; $_ } <$fd>;
2700 foreach my $commit (@commits) {
2701 if (defined $refs->{$commit}) {
2702 $tagname = $refs->{$commit}
2704 if ($commit eq $hash) {
2709 print $cgi->header(-type => "text/plain",
2710 -charset => 'utf-8',
2711 -content_disposition => "inline; filename=\"git-$hash.patch\"");
2712 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
2713 my $comment = $co{'comment'};
2716 Date: $ad{'rfc2822'} ($ad{'tz_local'})
2717 Subject: $co{'title'}
2719 if (defined $tagname) {
2720 print "X-Git-Tag: $tagname\n";
2722 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2725 foreach my $line (@$comment) {;
2730 foreach my $line (@difftree) {
2731 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2738 if ($status eq "A") {
2739 git_diff_print(undef, "/dev/null", $to_id, "b/$file", "plain");
2740 } elsif ($status eq "D") {
2741 git_diff_print($from_id, "a/$file", undef, "/dev/null", "plain");
2742 } elsif ($status eq "M") {
2743 git_diff_print($from_id, "a/$file", $to_id, "b/$file", "plain");
2749 if (!defined $hash_base) {
2750 $hash_base = git_get_head_hash($project);
2753 my %co = parse_commit($hash_base);
2755 die_error(undef, "Unknown commit object");
2757 my $refs = git_get_references();
2759 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base);
2760 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2761 if (!defined $hash && defined $file_name) {
2762 $hash = git_get_hash_by_path($hash_base, $file_name);
2764 if (defined $hash) {
2765 $ftype = git_get_type($hash);
2767 git_print_page_path($file_name, $ftype, $hash_base);
2770 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2771 git_history_body($fd, $refs, $hash_base, $ftype);
2778 if (!defined $searchtext) {
2779 die_error(undef, "Text field empty");
2781 if (!defined $hash) {
2782 $hash = git_get_head_hash($project);
2784 my %co = parse_commit($hash);
2786 die_error(undef, "Unknown commit object");
2788 # pickaxe may take all resources of your box and run for several minutes
2789 # with every query - so decide by yourself how public you make this feature :)
2790 my $commit_search = 1;
2791 my $author_search = 0;
2792 my $committer_search = 0;
2793 my $pickaxe_search = 0;
2794 if ($searchtext =~ s/^author\\://i) {
2796 } elsif ($searchtext =~ s/^committer\\://i) {
2797 $committer_search = 1;
2798 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2800 $pickaxe_search = 1;
2803 git_print_page_nav('','', $hash,$co{'tree'},$hash);
2804 git_print_header_div('commit', esc_html($co{'title'}), $hash);
2806 print "<table cellspacing=\"0\">\n";
2808 if ($commit_search) {
2810 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2811 while (my $commit_text = <$fd>) {
2812 if (!grep m/$searchtext/i, $commit_text) {
2815 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2818 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2821 my @commit_lines = split "\n", $commit_text;
2822 my %co = parse_commit(undef, \@commit_lines);
2827 print "<tr class=\"dark\">\n";
2829 print "<tr class=\"light\">\n";
2832 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2833 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2835 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"},
2836 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
2837 my $comment = $co{'comment'};
2838 foreach my $line (@$comment) {
2839 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2840 my $lead = esc_html($1) || "";
2841 $lead = chop_str($lead, 30, 10);
2842 my $match = esc_html($2) || "";
2843 my $trail = esc_html($3) || "";
2844 $trail = chop_str($trail, 30, 10);
2845 my $text = "$lead<span class=\"match\">$match</span>$trail";
2846 print chop_str($text, 80, 5) . "<br/>\n";
2850 "<td class=\"link\">" .
2851 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
2853 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
2860 if ($pickaxe_search) {
2862 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2865 while (my $line = <$fd>) {
2866 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2869 $set{'from_id'} = $3;
2871 $set{'id'} = $set{'to_id'};
2872 if ($set{'id'} =~ m/0{40}/) {
2873 $set{'id'} = $set{'from_id'};
2875 if ($set{'id'} =~ m/0{40}/) {
2879 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2882 print "<tr class=\"dark\">\n";
2884 print "<tr class=\"light\">\n";
2887 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2888 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2890 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
2891 -class => "list subject"},
2892 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
2893 while (my $setref = shift @files) {
2895 print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},
2896 hash=>$set{'id'}, file_name=>$set{'file'}),
2898 "<span class=\"match\">" . esc_html($set{'file'}) . "</span>") .
2902 "<td class=\"link\">" .
2903 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
2905 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
2909 %co = parse_commit($1);
2919 my $head = git_get_head_hash($project);
2920 if (!defined $hash) {
2923 if (!defined $page) {
2926 my $refs = git_get_references();
2928 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2929 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2930 or die_error(undef, "Open git-rev-list failed");
2931 my @revlist = map { chomp; $_ } <$fd>;
2934 my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, $#revlist);
2936 if ($#revlist >= (100 * ($page+1)-1)) {
2938 $cgi->a({-href => href(action=>"shortlog", hash=>$hash, page=>$page+1),
2939 -title => "Alt-n"}, "next");
2944 git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);
2945 git_print_header_div('summary', $project);
2947 git_shortlog_body(\@revlist, ($page * 100), $#revlist, $refs, $next_link);
2952 ## ......................................................................
2953 ## feeds (RSS, OPML)
2956 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
2957 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash($project)
2958 or die_error(undef, "Open git-rev-list failed");
2959 my @revlist = map { chomp; $_ } <$fd>;
2960 close $fd or die_error(undef, "Reading git-rev-list failed");
2961 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
2963 <?xml version="1.0" encoding="utf-8"?>
2964 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
2966 <title>$project $my_uri $my_url</title>
2967 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
2968 <description>$project log</description>
2969 <language>en</language>
2972 for (my $i = 0; $i <= $#revlist; $i++) {
2973 my $commit = $revlist[$i];
2974 my %co = parse_commit($commit);
2975 # we read 150, we always show 30 and the ones more recent than 48 hours
2976 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
2979 my %cd = parse_date($co{'committer_epoch'});
2980 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
2981 my @difftree = map { chomp; $_ } <$fd>;
2985 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) .
2987 "<author>" . esc_html($co{'author'}) . "</author>\n" .
2988 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
2989 "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
2990 "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
2991 "<description>" . esc_html($co{'title'}) . "</description>\n" .
2992 "<content:encoded>" .
2994 my $comment = $co{'comment'};
2995 foreach my $line (@$comment) {
2996 $line = decode("utf8", $line, Encode::FB_DEFAULT);
2997 print "$line<br/>\n";
3000 foreach my $line (@difftree) {
3001 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3004 my $file = validate_input(unquote($7));
3005 $file = decode("utf8", $file, Encode::FB_DEFAULT);
3006 print "$file<br/>\n";
3009 "</content:encoded>\n" .
3012 print "</channel></rss>";
3016 my @list = git_get_projects_list();
3018 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
3020 <?xml version="1.0" encoding="utf-8"?>
3021 <opml version="1.0">
3023 <title>$site_name Git OPML Export</title>
3026 <outline text="git RSS feeds">
3029 foreach my $pr (@list) {
3031 my $head = git_get_head_hash($proj{'path'});
3032 if (!defined $head) {
3035 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
3036 my %co = parse_commit($head);
3041 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
3042 my $rss = "$my_url?p=$proj{'path'};a=rss";
3043 my $html = "$my_url?p=$proj{'path'};a=summary";
3044 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";