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.
75 # feature => {'sub' => feature-sub, 'override' => allow-override, 'default' => [ default options...]
77 'blame' => {'sub' => \
&feature_blame
, 'override' => 0, 'default' => [0]},
78 'snapshot' => {'sub' => \
&feature_snapshot
, 'override' => 0, 'default' => ['x-gzip', 'gz', 'gzip']},
82 sub gitweb_check_feature
{
84 return undef unless exists $feature{$name};
85 my ($sub, $override, @defaults) = ($feature{$name}{'sub'},
86 $feature{$name}{'override'},
87 @
{$feature{$name}{'default'}});
88 if (!$override) { return @defaults; }
89 return $sub->(@defaults);
92 # To enable system wide have in $GITWEB_CONFIG
93 # $feature{'blame'}{'default'} = [1];
94 # To have project specific config enable override in $GITWEB_CONFIG
95 # $feature{'blame'}{'override'} = 1;
96 # and in project config gitweb.blame = 0|1;
99 my ($val) = git_get_project_config
('blame', '--bool');
101 if ($val eq 'true') {
103 } elsif ($val eq 'false') {
110 # To disable system wide have in $GITWEB_CONFIG
111 # $feature{'snapshot'}{'default'} = [undef];
112 # To have project specific config enable override in $GITWEB_CONFIG
113 # $feature{'blame'}{'override'} = 1;
114 # and in project config gitweb.snapshot = none|gzip|bzip2
116 sub feature_snapshot
{
117 my ($ctype, $suffix, $command) = @_;
119 my ($val) = git_get_project_config
('snapshot');
121 if ($val eq 'gzip') {
122 return ('x-gzip', 'gz', 'gzip');
123 } elsif ($val eq 'bzip2') {
124 return ('x-bzip2', 'bz2', 'bzip2');
125 } elsif ($val eq 'none') {
129 return ($ctype, $suffix, $command);
132 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
133 require $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
135 # version of the core git binary
136 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
138 $projects_list ||= $projectroot;
139 if (! -d
$git_temp) {
140 mkdir($git_temp, 0700) || die_error
(undef, "Couldn't mkdir $git_temp");
143 # ======================================================================
144 # input validation and dispatch
145 our $action = $cgi->param('a');
146 if (defined $action) {
147 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
148 die_error
(undef, "Invalid action parameter");
150 # action which does not check rest of parameters
151 if ($action eq "opml") {
157 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
158 if (defined $project) {
161 $project = undef unless $project;
163 if (defined $project) {
164 if (!validate_input
($project)) {
165 die_error
(undef, "Invalid project parameter");
167 if (!(-d
"$projectroot/$project")) {
168 die_error
(undef, "No such directory");
170 if (!(-e
"$projectroot/$project/HEAD")) {
171 die_error
(undef, "No such project");
173 $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
,
252 $action = 'summary' if (!defined($action));
253 if (!defined($actions{$action})) {
254 die_error
(undef, "Unknown action");
256 $actions{$action}->();
259 ## ======================================================================
276 $params{"project"} ||= $project;
278 my $href = "$my_uri?";
279 $href .= esc_param
( join(";",
281 "$mapping{$_}=$params{$_}" if defined $params{$_}
289 ## ======================================================================
290 ## validation, quoting/unquoting and escaping
295 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
298 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
301 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
307 # quote unsafe chars, but keep the slash, even when it's not
308 # correct, but quoted slashes look too horrible in bookmarks
311 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
317 # replace invalid utf8 character with SUBSTITUTION sequence
320 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
321 $str = escapeHTML
($str);
322 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
326 # git may return quoted and escaped filenames
329 if ($str =~ m/^"(.*)"$/) {
331 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
336 # escape tabs (convert tabs to spaces)
340 while ((my $pos = index($line, "\t")) != -1) {
341 if (my $count = (8 - ($pos % 8))) {
342 my $spaces = ' ' x
$count;
343 $line =~ s/\t/$spaces/;
350 ## ----------------------------------------------------------------------
351 ## HTML aware string manipulation
356 my $add_len = shift || 10;
358 # allow only $len chars, but don't cut a word if it would fit in $add_len
359 # if it doesn't fit, cut it if it's still longer than the dots we would add
360 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
363 if (length($tail) > 4) {
365 $body =~ s/&[^;]*$//; # remove chopped character entities
370 ## ----------------------------------------------------------------------
371 ## functions returning short strings
373 # CSS class for given age value (in seconds)
377 if ($age < 60*60*2) {
379 } elsif ($age < 60*60*24*2) {
386 # convert age in seconds to "nn units ago" string
391 if ($age > 60*60*24*365*2) {
392 $age_str = (int $age/60/60/24/365);
393 $age_str .= " years ago";
394 } elsif ($age > 60*60*24*(365/12)*2) {
395 $age_str = int $age/60/60/24/(365/12);
396 $age_str .= " months ago";
397 } elsif ($age > 60*60*24*7*2) {
398 $age_str = int $age/60/60/24/7;
399 $age_str .= " weeks ago";
400 } elsif ($age > 60*60*24*2) {
401 $age_str = int $age/60/60/24;
402 $age_str .= " days ago";
403 } elsif ($age > 60*60*2) {
404 $age_str = int $age/60/60;
405 $age_str .= " hours ago";
406 } elsif ($age > 60*2) {
407 $age_str = int $age/60;
408 $age_str .= " min ago";
411 $age_str .= " sec ago";
413 $age_str .= " right now";
418 # convert file mode in octal to symbolic file mode string
420 my $mode = oct shift;
422 if (S_ISDIR
($mode & S_IFMT
)) {
424 } elsif (S_ISLNK
($mode)) {
426 } elsif (S_ISREG
($mode)) {
427 # git cares only about the executable bit
428 if ($mode & S_IXUSR
) {
438 # convert file mode in octal to file type string
440 my $mode = oct shift;
442 if (S_ISDIR
($mode & S_IFMT
)) {
444 } elsif (S_ISLNK
($mode)) {
446 } elsif (S_ISREG
($mode)) {
453 ## ----------------------------------------------------------------------
454 ## functions returning short HTML fragments, or transforming HTML fragments
455 ## which don't beling to other sections
457 # format line of commit message or tag comment
458 sub format_log_line_html
{
461 $line = esc_html
($line);
462 $line =~ s/ / /g;
463 if ($line =~ m/([0-9a-fA-F]{40})/) {
465 if (git_get_type
($hash_text) eq "commit") {
466 my $link = $cgi->a({-class => "text", -href
=> href
(action
=>"commit", hash
=>$hash_text)}, $hash_text);
467 $line =~ s/$hash_text/$link/;
473 # format marker of refs pointing to given object
474 sub format_ref_marker
{
475 my ($refs, $id) = @_;
478 if (defined $refs->{$id}) {
479 foreach my $ref (@
{$refs->{$id}}) {
480 my ($type, $name) = qw();
481 # e.g. tags/v2.6.11 or heads/next
482 if ($ref =~ m!^(.*?)s?/(.*)$!) {
490 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
495 return ' <span class="refs">'. $markers . '</span>';
501 # format, perhaps shortened and with markers, title line
502 sub format_subject_html
{
503 my ($long, $short, $href, $extra) = @_;
504 $extra = '' unless defined($extra);
506 if (length($short) < length($long)) {
507 return $cgi->a({-href
=> $href, -class => "list",
509 esc_html
($short) . $extra);
511 return $cgi->a({-href
=> $href, -class => "list"},
512 esc_html
($long) . $extra);
516 ## ----------------------------------------------------------------------
517 ## git utility subroutines, invoking git commands
519 # get HEAD ref of given project as hash
520 sub git_get_head_hash
{
522 my $oENV = $ENV{'GIT_DIR'};
524 $ENV{'GIT_DIR'} = "$projectroot/$project";
525 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
528 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
533 $ENV{'GIT_DIR'} = $oENV;
538 # get type of given object
542 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
549 sub git_get_project_config
{
550 my ($key, $type) = @_;
552 return unless ($key);
553 $key =~ s/^gitweb\.//;
554 return if ($key =~ m/\W/);
556 my @x = ($GIT, 'repo-config');
557 if (defined $type) { push @x, $type; }
559 push @x, "gitweb.$key";
565 # get hash of given path at given ref
566 sub git_get_hash_by_path
{
568 my $path = shift || return undef;
572 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
573 or die_error
(undef, "Open git-ls-tree failed");
575 close $fd or return undef;
577 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
578 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
582 ## ......................................................................
583 ## git utility functions, directly accessing git repository
585 # assumes that PATH is not symref
586 sub git_get_hash_by_ref
{
589 open my $fd, "$projectroot/$path" or return undef;
593 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
598 sub git_get_project_description
{
601 open my $fd, "$projectroot/$path/description" or return undef;
608 sub git_get_project_url_list
{
611 open my $fd, "$projectroot/$path/cloneurl" or return undef;
612 my @git_project_url_list = map { chomp; $_ } <$fd>;
615 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
618 sub git_get_projects_list
{
621 if (-d
$projects_list) {
622 # search in directory
623 my $dir = $projects_list;
624 opendir my ($dh), $dir or return undef;
625 while (my $dir = readdir($dh)) {
626 if (-e
"$projectroot/$dir/HEAD") {
634 } elsif (-f
$projects_list) {
635 # read from file(url-encoded):
636 # 'git%2Fgit.git Linus+Torvalds'
637 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
638 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
639 open my ($fd), $projects_list or return undef;
640 while (my $line = <$fd>) {
642 my ($path, $owner) = split ' ', $line;
643 $path = unescape
($path);
644 $owner = unescape
($owner);
645 if (!defined $path) {
648 if (-e
"$projectroot/$path/HEAD") {
651 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
658 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
662 sub git_get_project_owner
{
666 return undef unless $project;
668 # read from file (url-encoded):
669 # 'git%2Fgit.git Linus+Torvalds'
670 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
671 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
672 if (-f
$projects_list) {
673 open (my $fd , $projects_list);
674 while (my $line = <$fd>) {
676 my ($pr, $ow) = split ' ', $line;
679 if ($pr eq $project) {
680 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
686 if (!defined $owner) {
687 $owner = get_file_owner
("$projectroot/$project");
693 sub git_get_references
{
694 my $type = shift || "";
697 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
698 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
699 if (-f
"$projectroot/$project/info/refs") {
700 open $fd, "$projectroot/$project/info/refs"
703 open $fd, "-|", $GIT, "ls-remote", "."
707 while (my $line = <$fd>) {
709 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
710 if (defined $refs{$1}) {
711 push @
{$refs{$1}}, $2;
721 ## ----------------------------------------------------------------------
722 ## parse to hash functions
726 my $tz = shift || "-0000";
729 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
730 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
731 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
732 $date{'hour'} = $hour;
733 $date{'minute'} = $min;
734 $date{'mday'} = $mday;
735 $date{'day'} = $days[$wday];
736 $date{'month'} = $months[$mon];
737 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
738 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
740 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
741 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
742 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
743 $date{'hour_local'} = $hour;
744 $date{'minute_local'} = $min;
745 $date{'tz_local'} = $tz;
754 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
755 $tag{'id'} = $tag_id;
756 while (my $line = <$fd>) {
758 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
760 } elsif ($line =~ m/^type (.+)$/) {
762 } elsif ($line =~ m/^tag (.+)$/) {
764 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
768 } elsif ($line =~ m/--BEGIN/) {
769 push @comment, $line;
771 } elsif ($line eq "") {
775 push @comment, <$fd>;
776 $tag{'comment'} = \
@comment;
778 if (!defined $tag{'name'}) {
785 my $commit_id = shift;
786 my $commit_text = shift;
791 if (defined $commit_text) {
792 @commit_lines = @
$commit_text;
795 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id or return;
796 @commit_lines = split '\n', <$fd>;
801 my $header = shift @commit_lines;
802 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
805 ($co{'id'}, my @parents) = split ' ', $header;
806 $co{'parents'} = \
@parents;
807 $co{'parent'} = $parents[0];
808 while (my $line = shift @commit_lines) {
809 last if $line eq "\n";
810 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
812 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
814 $co{'author_epoch'} = $2;
815 $co{'author_tz'} = $3;
816 if ($co{'author'} =~ m/^([^<]+) </) {
817 $co{'author_name'} = $1;
819 $co{'author_name'} = $co{'author'};
821 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
822 $co{'committer'} = $1;
823 $co{'committer_epoch'} = $2;
824 $co{'committer_tz'} = $3;
825 $co{'committer_name'} = $co{'committer'};
826 $co{'committer_name'} =~ s/ <.*//;
829 if (!defined $co{'tree'}) {
833 foreach my $title (@commit_lines) {
836 $co{'title'} = chop_str
($title, 80, 5);
837 # remove leading stuff of merges to make the interesting part visible
838 if (length($title) > 50) {
839 $title =~ s/^Automatic //;
840 $title =~ s/^merge (of|with) /Merge ... /i;
841 if (length($title) > 50) {
842 $title =~ s/(http|rsync):\/\///;
844 if (length($title) > 50) {
845 $title =~ s/(master|www|rsync)\.//;
847 if (length($title) > 50) {
848 $title =~ s/kernel.org:?//;
850 if (length($title) > 50) {
851 $title =~ s/\/pub\/scm//;
854 $co{'title_short'} = chop_str
($title, 50, 5);
858 # remove added spaces
859 foreach my $line (@commit_lines) {
862 $co{'comment'} = \
@commit_lines;
864 my $age = time - $co{'committer_epoch'};
866 $co{'age_string'} = age_string
($age);
867 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
868 if ($age > 60*60*24*7*2) {
869 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
870 $co{'age_string_age'} = $co{'age_string'};
872 $co{'age_string_date'} = $co{'age_string'};
873 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
878 # parse ref from ref_file, given by ref_id, with given type
880 my $ref_file = shift;
882 my $type = shift || git_get_type
($ref_id);
885 $ref_item{'type'} = $type;
886 $ref_item{'id'} = $ref_id;
887 $ref_item{'epoch'} = 0;
888 $ref_item{'age'} = "unknown";
889 if ($type eq "tag") {
890 my %tag = parse_tag
($ref_id);
891 $ref_item{'comment'} = $tag{'comment'};
892 if ($tag{'type'} eq "commit") {
893 my %co = parse_commit
($tag{'object'});
894 $ref_item{'epoch'} = $co{'committer_epoch'};
895 $ref_item{'age'} = $co{'age_string'};
896 } elsif (defined($tag{'epoch'})) {
897 my $age = time - $tag{'epoch'};
898 $ref_item{'epoch'} = $tag{'epoch'};
899 $ref_item{'age'} = age_string
($age);
901 $ref_item{'reftype'} = $tag{'type'};
902 $ref_item{'name'} = $tag{'name'};
903 $ref_item{'refid'} = $tag{'object'};
904 } elsif ($type eq "commit"){
905 my %co = parse_commit
($ref_id);
906 $ref_item{'reftype'} = "commit";
907 $ref_item{'name'} = $ref_file;
908 $ref_item{'title'} = $co{'title'};
909 $ref_item{'refid'} = $ref_id;
910 $ref_item{'epoch'} = $co{'committer_epoch'};
911 $ref_item{'age'} = $co{'age_string'};
913 $ref_item{'reftype'} = $type;
914 $ref_item{'name'} = $ref_file;
915 $ref_item{'refid'} = $ref_id;
921 ## ......................................................................
922 ## parse to array of hashes functions
924 sub git_get_refs_list
{
929 my $pfxlen = length("$projectroot/$project/$ref_dir");
930 File
::Find
::find
(sub {
933 push @refs, substr($File::Find
::name
, $pfxlen + 1);
935 }, "$projectroot/$project/$ref_dir");
937 foreach my $ref_file (@refs) {
938 my $ref_id = git_get_hash_by_ref
("$project/$ref_dir/$ref_file");
939 my $type = git_get_type
($ref_id) || next;
940 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
942 push @reflist, \
%ref_item;
945 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
949 ## ----------------------------------------------------------------------
950 ## filesystem-related functions
955 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
956 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
957 if (!defined $gcos) {
961 $owner =~ s/[,;].*$//;
962 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
965 ## ......................................................................
966 ## mimetype related functions
968 sub mimetype_guess_file
{
969 my $filename = shift;
971 -r
$mimemap or return undef;
974 open(MIME
, $mimemap) or return undef;
976 next if m/^#/; # skip comments
977 my ($mime, $exts) = split(/\t+/);
979 my @exts = split(/\s+/, $exts);
980 foreach my $ext (@exts) {
981 $mimemap{$ext} = $mime;
987 $filename =~ /\.(.*?)$/;
992 my $filename = shift;
994 $filename =~ /\./ or return undef;
996 if ($mimetypes_file) {
997 my $file = $mimetypes_file;
998 if ($file !~ m!^/!) { # if it is relative path
999 # it is relative to project
1000 $file = "$projectroot/$project/$file";
1002 $mime = mimetype_guess_file
($filename, $file);
1004 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1010 my $filename = shift;
1013 my $mime = mimetype_guess
($filename);
1014 $mime and return $mime;
1018 return $default_blob_plain_mimetype unless $fd;
1021 return 'text/plain' .
1022 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1023 } elsif (! $filename) {
1024 return 'application/octet-stream';
1025 } elsif ($filename =~ m/\.png$/i) {
1027 } elsif ($filename =~ m/\.gif$/i) {
1029 } elsif ($filename =~ m/\.jpe?g$/i) {
1030 return 'image/jpeg';
1032 return 'application/octet-stream';
1036 ## ======================================================================
1037 ## functions printing HTML: header, footer, error page
1039 sub git_header_html
{
1040 my $status = shift || "200 OK";
1041 my $expires = shift;
1043 my $title = "$site_name git";
1044 if (defined $project) {
1045 $title .= " - $project";
1046 if (defined $action) {
1047 $title .= "/$action";
1048 if (defined $file_name) {
1049 $title .= " - $file_name";
1050 if ($action eq "tree" && $file_name !~ m
|/$|) {
1057 # require explicit support from the UA if we are to send the page as
1058 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1059 # we have to do this because MSIE sometimes globs '*/*', pretending to
1060 # support xhtml+xml but choking when it gets what it asked for.
1061 if (defined $cgi->http('HTTP_ACCEPT') && $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ && $cgi->Accept('application/xhtml
+xml
') != 0) {
1062 $content_type = 'application
/xhtml
+xml
';
1064 $content_type = 'text
/html
';
1066 print $cgi->header(-type=>$content_type, -charset => 'utf
-8', -status=> $status, -expires => $expires);
1068 <?xml version="1.0" encoding="utf-8"?>
1069 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1070 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1071 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1072 <!-- git core binaries version $git_version -->
1074 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1075 <meta name="generator" content="gitweb/$version git/$git_version"/>
1076 <meta name="robots" content="index, nofollow"/>
1077 <title>$title</title>
1078 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1080 if (defined $project) {
1081 printf('<link rel="alternate" title="%s log" '.
1082 'href="%s" type="application/rss+xml"/>'."\n",
1083 esc_param
($project), href
(action
=>"rss"));
1088 "<div class=\"page_header\">\n" .
1089 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1090 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1092 print $cgi->a({-href
=> esc_param
($home_link)}, $home_link_str) . " / ";
1093 if (defined $project) {
1094 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1095 if (defined $action) {
1099 if (!defined $searchtext) {
1103 if (defined $hash_base) {
1104 $search_hash = $hash_base;
1105 } elsif (defined $hash) {
1106 $search_hash = $hash;
1108 $search_hash = "HEAD";
1110 $cgi->param("a", "search");
1111 $cgi->param("h", $search_hash);
1112 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1113 "<div class=\"search\">\n" .
1114 $cgi->hidden(-name
=> "p") . "\n" .
1115 $cgi->hidden(-name
=> "a") . "\n" .
1116 $cgi->hidden(-name
=> "h") . "\n" .
1117 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1119 $cgi->end_form() . "\n";
1124 sub git_footer_html
{
1125 print "<div class=\"page_footer\">\n";
1126 if (defined $project) {
1127 my $descr = git_get_project_description
($project);
1128 if (defined $descr) {
1129 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1131 print $cgi->a({-href
=> href
(action
=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1133 print $cgi->a({-href
=> href
(action
=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1141 my $status = shift || "403 Forbidden";
1142 my $error = shift || "Malformed query, file missing or permission denied";
1144 git_header_html
($status);
1145 print "<div class=\"page_body\">\n" .
1147 "$status - $error\n" .
1154 ## ----------------------------------------------------------------------
1155 ## functions printing or outputting HTML: navigation
1157 sub git_print_page_nav
{
1158 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1159 $extra = '' if !defined $extra; # pager or formats
1161 my @navs = qw(summary shortlog log commit commitdiff tree);
1163 @navs = grep { $_ ne $suppress } @navs;
1166 my %arg = map { $_ => {action
=>$_} } @navs;
1167 if (defined $head) {
1168 for (qw(commit commitdiff)) {
1169 $arg{$_}{hash
} = $head;
1171 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1172 for (qw(shortlog log)) {
1173 $arg{$_}{hash
} = $head;
1177 $arg{tree
}{hash
} = $treehead if defined $treehead;
1178 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1180 print "<div class=\"page_nav\">\n" .
1182 map { $_ eq $current ?
1183 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1185 print "<br/>\n$extra<br/>\n" .
1189 sub format_paging_nav
{
1190 my ($action, $hash, $head, $page, $nrevs) = @_;
1194 if ($hash ne $head || $page) {
1195 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1197 $paging_nav .= "HEAD";
1201 $paging_nav .= " ⋅ " .
1202 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1203 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1205 $paging_nav .= " ⋅ prev";
1208 if ($nrevs >= (100 * ($page+1)-1)) {
1209 $paging_nav .= " ⋅ " .
1210 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1211 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1213 $paging_nav .= " ⋅ next";
1219 ## ......................................................................
1220 ## functions printing or outputting HTML: div
1222 sub git_print_header_div
{
1223 my ($action, $title, $hash, $hash_base) = @_;
1226 $args{action
} = $action;
1227 $args{hash
} = $hash if $hash;
1228 $args{hash_base
} = $hash_base if $hash_base;
1230 print "<div class=\"header\">\n" .
1231 $cgi->a({-href
=> href
(%args), -class => "title"},
1232 $title ?
$title : $action) .
1236 sub git_print_page_path
{
1241 if (!defined $name) {
1242 print "<div class=\"page_path\"><b>/</b></div>\n";
1243 } elsif (defined $type && $type eq 'blob') {
1244 print "<div class=\"page_path\"><b>";
1246 print $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hb, file_name
=>$file_name)}, esc_html
($name));
1248 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name)}, esc_html
($name));
1250 print "</b><br/></div>\n";
1252 print "<div class=\"page_path\"><b>" . esc_html
($name) . "</b><br/></div>\n";
1259 # remove leading empty lines
1260 while (defined $log->[0] && $log->[0] eq "") {
1267 foreach my $line (@
$log) {
1268 # print only one empty line
1269 # do not print empty line after signoff
1271 next if ($empty || $signoff);
1276 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1278 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1281 print format_log_line_html
($line) . "<br/>\n";
1286 sub git_print_simplified_log
{
1288 my $remove_title = shift;
1290 shift @
$log if $remove_title;
1291 # remove leading empty lines
1292 while (defined $log->[0] && $log->[0] eq "") {
1296 # simplify and print log
1298 foreach my $line (@
$log) {
1299 # remove signoff lines
1300 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1303 # print only one empty line
1310 print format_log_line_html
($line) . "<br/>\n";
1312 # end with single empty line
1313 print "<br/>\n" unless $empty;
1316 ## ......................................................................
1317 ## functions printing large fragments of HTML
1319 sub git_difftree_body
{
1320 my ($difftree, $parent) = @_;
1322 print "<div class=\"list_head\">\n";
1323 if ($#{$difftree} > 10) {
1324 print(($#{$difftree} + 1) . " files changed:\n");
1328 print "<table class=\"diff_tree\">\n";
1330 foreach my $line (@
{$difftree}) {
1331 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1332 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1333 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1341 my $similarity = $6; # score
1342 my $file = validate_input
(unquote
($7));
1345 print "<tr class=\"dark\">\n";
1347 print "<tr class=\"light\">\n";
1351 if ($status eq "A") { # created
1353 if (S_ISREG
(oct $to_mode)) {
1354 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1357 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file),
1358 -class => "list"}, esc_html
($file)) .
1360 "<td><span class=\"file_status new\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
1361 "<td class=\"link\">" .
1362 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file)}, "blob") .
1365 } elsif ($status eq "D") { # deleted
1367 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$file),
1368 -class => "list"}, esc_html
($file)) . "</td>\n" .
1369 "<td><span class=\"file_status deleted\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
1370 "<td class=\"link\">" .
1371 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$file)}, "blob") . " | " .
1372 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent, file_name
=>$file)}, "history") .
1375 } elsif ($status eq "M" || $status eq "T") { # modified, or type changed
1376 my $mode_chnge = "";
1377 if ($from_mode != $to_mode) {
1378 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
1379 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
1380 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
1382 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1383 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
1384 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1385 } elsif (S_ISREG
($to_mode)) {
1386 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1389 $mode_chnge .= "]</span>\n";
1392 if ($to_id ne $from_id) { # modified
1393 print $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$to_id, hash_parent
=>$from_id, hash_base
=>$hash, file_name
=>$file),
1394 -class => "list"}, esc_html
($file));
1395 } else { # mode changed
1396 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file),
1397 -class => "list"}, esc_html
($file));
1400 "<td>$mode_chnge</td>\n" .
1401 "<td class=\"link\">" .
1402 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file)}, "blob");
1403 if ($to_id ne $from_id) { # modified
1404 print " | " . $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$to_id, hash_parent
=>$from_id, hash_base
=>$hash, file_name
=>$file)}, "diff");
1406 print " | " . $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash, file_name
=>$file)}, "history") . "\n";
1409 } elsif ($status eq "R") { # renamed
1410 my ($from_file, $to_file) = split "\t", $file;
1412 if ($from_mode != $to_mode) {
1413 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1416 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file),
1417 -class => "list"}, esc_html
($to_file)) . "</td>\n" .
1418 "<td><span class=\"file_status moved\">[moved from " .
1419 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$from_file),
1420 -class => "list"}, esc_html
($from_file)) .
1421 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1422 "<td class=\"link\">" .
1423 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file)}, "blob");
1424 if ($to_id ne $from_id) {
1426 $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$to_id, hash_parent
=>$from_id, hash_base
=>$hash, file_name
=>$to_file, file_parent
=>$from_file)}, "diff");
1430 } elsif ($status eq "C") { # copied
1431 my ($from_file, $to_file) = split "\t", $file;
1433 if ($from_mode != $to_mode) {
1434 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1437 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file),
1438 -class => "list"}, esc_html
($to_file)) . "</td>\n" .
1439 "<td><span class=\"file_status copied\">[copied from " .
1440 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$from_file),
1441 -class => "list"}, esc_html
($from_file)) .
1442 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1443 "<td class=\"link\">" .
1444 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file)}, "blob");
1445 if ($to_id ne $from_id) {
1447 $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$to_id, hash_parent
=>$from_id, hash_base
=>$hash, file_name
=>$to_file, file_parent
=>$from_file)}, "diff");
1450 } # we should not encounter Unmerged (U) or Unknown (X) status
1456 sub git_shortlog_body
{
1457 # uses global variable $project
1458 my ($revlist, $from, $to, $refs, $extra) = @_;
1460 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
1461 my $have_snapshot = (defined $ctype && defined $suffix);
1463 $from = 0 unless defined $from;
1464 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1466 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1468 for (my $i = $from; $i <= $to; $i++) {
1469 my $commit = $revlist->[$i];
1470 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1471 my $ref = format_ref_marker
($refs, $commit);
1472 my %co = parse_commit
($commit);
1474 print "<tr class=\"dark\">\n";
1476 print "<tr class=\"light\">\n";
1479 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1480 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1481 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1483 print format_subject_html
($co{'title'}, $co{'title_short'}, href
(action
=>"commit", hash
=>$commit), $ref);
1485 "<td class=\"link\">" .
1486 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1487 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
1488 if ($have_snapshot) {
1489 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
1494 if (defined $extra) {
1496 "<td colspan=\"4\">$extra</td>\n" .
1502 sub git_history_body
{
1503 # Warning: assumes constant type (blob or tree) during history
1504 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1506 print "<table class=\"history\" cellspacing=\"0\">\n";
1508 while (my $line = <$fd>) {
1509 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1514 my %co = parse_commit
($commit);
1519 my $ref = format_ref_marker
($refs, $commit);
1522 print "<tr class=\"dark\">\n";
1524 print "<tr class=\"light\">\n";
1527 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1528 # shortlog uses chop_str($co{'author_name'}, 10)
1529 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1531 # originally git_history used chop_str($co{'title'}, 50)
1532 print format_subject_html
($co{'title'}, $co{'title_short'}, href
(action
=>"commit", hash
=>$commit), $ref);
1534 "<td class=\"link\">" .
1535 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1536 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
1537 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype);
1539 if ($ftype eq 'blob') {
1540 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
1541 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
1542 if (defined $blob_current && defined $blob_parent &&
1543 $blob_current ne $blob_parent) {
1545 $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$blob_current, hash_parent
=>$blob_parent, hash_base
=>$commit, file_name
=>$file_name)},
1552 if (defined $extra) {
1554 "<td colspan=\"4\">$extra</td>\n" .
1561 # uses global variable $project
1562 my ($taglist, $from, $to, $extra) = @_;
1563 $from = 0 unless defined $from;
1564 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1566 print "<table class=\"tags\" cellspacing=\"0\">\n";
1568 for (my $i = $from; $i <= $to; $i++) {
1569 my $entry = $taglist->[$i];
1571 my $comment_lines = $tag{'comment'};
1572 my $comment = shift @
$comment_lines;
1574 if (defined $comment) {
1575 $comment_short = chop_str
($comment, 30, 5);
1578 print "<tr class=\"dark\">\n";
1580 print "<tr class=\"light\">\n";
1583 print "<td><i>$tag{'age'}</i></td>\n" .
1585 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
1586 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1589 if (defined $comment) {
1590 print format_subject_html
($comment, $comment_short, href
(action
=>"tag", hash
=>$tag{'id'}));
1593 "<td class=\"selflink\">";
1594 if ($tag{'type'} eq "tag") {
1595 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
1600 "<td class=\"link\">" . " | " .
1601 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
1602 if ($tag{'reftype'} eq "commit") {
1603 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
1604 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
1605 } elsif ($tag{'reftype'} eq "blob") {
1606 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
1611 if (defined $extra) {
1613 "<td colspan=\"5\">$extra</td>\n" .
1619 sub git_heads_body
{
1620 # uses global variable $project
1621 my ($taglist, $head, $from, $to, $extra) = @_;
1622 $from = 0 unless defined $from;
1623 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1625 print "<table class=\"heads\" cellspacing=\"0\">\n";
1627 for (my $i = $from; $i <= $to; $i++) {
1628 my $entry = $taglist->[$i];
1630 my $curr = $tag{'id'} eq $head;
1632 print "<tr class=\"dark\">\n";
1634 print "<tr class=\"light\">\n";
1637 print "<td><i>$tag{'age'}</i></td>\n" .
1638 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1639 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
1640 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1642 "<td class=\"link\">" .
1643 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
1644 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") .
1648 if (defined $extra) {
1650 "<td colspan=\"3\">$extra</td>\n" .
1656 ## ----------------------------------------------------------------------
1657 ## functions printing large fragments, format as one of arguments
1659 sub git_diff_print
{
1661 my $from_name = shift;
1663 my $to_name = shift;
1664 my $format = shift || "html";
1666 my $from_tmp = "/dev/null";
1667 my $to_tmp = "/dev/null";
1670 # create tmp from-file
1671 if (defined $from) {
1672 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1673 open my $fd2, "> $from_tmp";
1674 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1681 # create tmp to-file
1683 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1684 open my $fd2, "> $to_tmp";
1685 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1692 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1693 if ($format eq "plain") {
1698 while (my $line = <$fd>) {
1700 my $char = substr($line, 0, 1);
1701 my $diff_class = "";
1703 $diff_class = " add";
1704 } elsif ($char eq "-") {
1705 $diff_class = " rem";
1706 } elsif ($char eq "@") {
1707 $diff_class = " chunk_header";
1708 } elsif ($char eq "\\") {
1712 $line = untabify
($line);
1713 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
1718 if (defined $from) {
1727 ## ======================================================================
1728 ## ======================================================================
1731 sub git_project_list
{
1732 my $order = $cgi->param('o');
1733 if (defined $order && $order !~ m/project|descr|owner|age/) {
1734 die_error
(undef, "Unknown order parameter");
1737 my @list = git_get_projects_list
();
1740 die_error
(undef, "No projects found");
1742 foreach my $pr (@list) {
1743 my $head = git_get_head_hash
($pr->{'path'});
1744 if (!defined $head) {
1747 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1748 my %co = parse_commit
($head);
1752 $pr->{'commit'} = \
%co;
1753 if (!defined $pr->{'descr'}) {
1754 my $descr = git_get_project_description
($pr->{'path'}) || "";
1755 $pr->{'descr'} = chop_str
($descr, 25, 5);
1757 if (!defined $pr->{'owner'}) {
1758 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
1760 push @projects, $pr;
1764 if (-f
$home_text) {
1765 print "<div class=\"index_include\">\n";
1766 open (my $fd, $home_text);
1771 print "<table class=\"project_list\">\n" .
1773 $order ||= "project";
1774 if ($order eq "project") {
1775 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1776 print "<th>Project</th>\n";
1779 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
1780 -class => "header"}, "Project") .
1783 if ($order eq "descr") {
1784 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1785 print "<th>Description</th>\n";
1788 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
1789 -class => "header"}, "Description") .
1792 if ($order eq "owner") {
1793 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1794 print "<th>Owner</th>\n";
1797 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
1798 -class => "header"}, "Owner") .
1801 if ($order eq "age") {
1802 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1803 print "<th>Last Change</th>\n";
1806 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
1807 -class => "header"}, "Last Change") .
1810 print "<th></th>\n" .
1813 foreach my $pr (@projects) {
1815 print "<tr class=\"dark\">\n";
1817 print "<tr class=\"light\">\n";
1820 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
1821 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
1822 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
1823 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
1824 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
1825 $pr->{'commit'}{'age_string'} . "</td>\n" .
1826 "<td class=\"link\">" .
1827 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
1828 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
1829 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") .
1838 my $descr = git_get_project_description
($project) || "none";
1839 my $head = git_get_head_hash
($project);
1840 my %co = parse_commit
($head);
1841 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
1843 my $owner = git_get_project_owner
($project);
1845 my $refs = git_get_references
();
1847 git_print_page_nav
('summary','', $head);
1849 print "<div class=\"title\"> </div>\n";
1850 print "<table cellspacing=\"0\">\n" .
1851 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1852 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1853 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
1854 # use per project git URL list in $projectroot/$project/cloneurl
1855 # or make project git URL from git base URL and project name
1856 my $url_tag = "URL";
1857 my @url_list = git_get_project_url_list
($project);
1858 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
1859 foreach my $git_url (@url_list) {
1860 next unless $git_url;
1861 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
1866 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash
($project)
1867 or die_error
(undef, "Open git-rev-list failed");
1868 my @revlist = map { chomp; $_ } <$fd>;
1870 git_print_header_div
('shortlog');
1871 git_shortlog_body
(\
@revlist, 0, 15, $refs,
1872 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
1874 my $taglist = git_get_refs_list
("refs/tags");
1875 if (defined @
$taglist) {
1876 git_print_header_div
('tags');
1877 git_tags_body
($taglist, 0, 15,
1878 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
1881 my $headlist = git_get_refs_list
("refs/heads");
1882 if (defined @
$headlist) {
1883 git_print_header_div
('heads');
1884 git_heads_body
($headlist, $head, 0, 15,
1885 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
1892 my $head = git_get_head_hash
($project);
1894 git_print_page_nav
('','', $head,undef,$head);
1895 my %tag = parse_tag
($hash);
1896 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
1897 print "<div class=\"title_text\">\n" .
1898 "<table cellspacing=\"0\">\n" .
1900 "<td>object</td>\n" .
1901 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})}, $tag{'object'}) . "</td>\n" .
1902 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})}, $tag{'type'}) . "</td>\n" .
1904 if (defined($tag{'author'})) {
1905 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
1906 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1907 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1909 print "</table>\n\n" .
1911 print "<div class=\"page_body\">";
1912 my $comment = $tag{'comment'};
1913 foreach my $line (@
$comment) {
1914 print esc_html
($line) . "<br/>\n";
1924 if (!gitweb_check_feature
('blame')) {
1925 die_error
('403 Permission denied', "Permission denied");
1927 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1928 $hash_base ||= git_get_head_hash
($project);
1929 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
1930 my %co = parse_commit
($hash_base)
1931 or die_error
(undef, "Reading commit failed");
1932 if (!defined $hash) {
1933 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1934 or die_error
(undef, "Error looking up file");
1936 $ftype = git_get_type
($hash);
1937 if ($ftype !~ "blob") {
1938 die_error
("400 Bad Request", "Object is not a blob");
1940 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
1941 or die_error
(undef, "Open git-blame failed");
1944 $cgi->a({-href
=> href
(action
=>"blobl", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, "blob") .
1945 " | " . $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)}, "head");
1946 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1947 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1948 git_print_page_path
($file_name, $ftype, $hash_base);
1949 my @rev_color = (qw(light2 dark2));
1950 my $num_colors = scalar(@rev_color);
1951 my $current_color = 0;
1953 print "<div class=\"page_body\">\n";
1954 print "<table class=\"blame\">\n";
1955 print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
1957 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
1959 my $rev = substr($full_rev, 0, 8);
1963 if (!defined $last_rev) {
1964 $last_rev = $full_rev;
1965 } elsif ($last_rev ne $full_rev) {
1966 $last_rev = $full_rev;
1967 $current_color = ++$current_color % $num_colors;
1969 print "<tr class=\"$rev_color[$current_color]\">\n";
1970 print "<td class=\"sha1\">" .
1971 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)}, esc_html
($rev)) . "</td>\n";
1972 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html
($lineno) . "</a></td>\n";
1973 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
1978 close $fd or print "Reading blob failed\n";
1985 if (!gitweb_check_feature
('blame')) {
1986 die_error
('403 Permission denied', "Permission denied");
1988 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1989 $hash_base ||= git_get_head_hash
($project);
1990 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
1991 my %co = parse_commit
($hash_base)
1992 or die_error
(undef, "Reading commit failed");
1993 if (!defined $hash) {
1994 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1995 or die_error
(undef, "Error lookup file");
1997 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
1998 or die_error
(undef, "Open git-annotate failed");
2001 $cgi->a({-href
=> href
(action
=>"blobl", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, "blob") .
2002 " | " . $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)}, "head");
2003 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2004 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2005 git_print_page_path
($file_name, 'blob', $hash_base);
2006 print "<div class=\"page_body\">\n";
2008 <table class="blame">
2017 my @line_class = (qw(light dark));
2018 my $line_class_len = scalar (@line_class);
2019 my $line_class_num = $#line_class;
2020 while (my $line = <$fd>) {
2032 $line_class_num = ($line_class_num + 1) % $line_class_len;
2034 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
2041 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2044 $short_rev = substr ($long_rev, 0, 8);
2045 $age = time () - $time;
2046 $age_str = age_string
($age);
2047 $age_str =~ s/ / /g;
2048 $age_class = age_class
($age);
2049 $author = esc_html
($author);
2050 $author =~ s/ / /g;
2052 $data = untabify
($data);
2053 $data = esc_html
($data);
2056 <tr class="$line_class[$line_class_num]">
2057 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2058 <td class="$age_class">$age_str</td>
2060 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2061 <td class="pre">$data</td>
2064 } # while (my $line = <$fd>)
2065 print "</table>\n\n";
2066 close $fd or print "Reading blob failed.\n";
2072 my $head = git_get_head_hash
($project);
2074 git_print_page_nav
('','', $head,undef,$head);
2075 git_print_header_div
('summary', $project);
2077 my $taglist = git_get_refs_list
("refs/tags");
2078 if (defined @
$taglist) {
2079 git_tags_body
($taglist);
2085 my $head = git_get_head_hash
($project);
2087 git_print_page_nav
('','', $head,undef,$head);
2088 git_print_header_div
('summary', $project);
2090 my $taglist = git_get_refs_list
("refs/heads");
2091 if (defined @
$taglist) {
2092 git_heads_body
($taglist, $head);
2097 sub git_blob_plain
{
2098 if (!defined $hash) {
2099 if (defined $file_name) {
2100 my $base = $hash_base || git_get_head_hash
($project);
2101 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2102 or die_error
(undef, "Error lookup file");
2104 die_error
(undef, "No file name defined");
2108 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2109 or die_error
(undef, "Couldn't cat $file_name, $hash");
2111 $type ||= blob_mimetype
($fd, $file_name);
2113 # save as filename, even when no $file_name is given
2114 my $save_as = "$hash";
2115 if (defined $file_name) {
2116 $save_as = $file_name;
2117 } elsif ($type =~ m/^text\//) {
2121 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
2123 binmode STDOUT
, ':raw';
2125 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2131 if (!defined $hash) {
2132 if (defined $file_name) {
2133 my $base = $hash_base || git_get_head_hash
($project);
2134 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2135 or die_error
(undef, "Error lookup file");
2137 die_error
(undef, "No file name defined");
2140 my $have_blame = gitweb_check_feature
('blame');
2141 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2142 or die_error
(undef, "Couldn't cat $file_name, $hash");
2143 my $mimetype = blob_mimetype
($fd, $file_name);
2144 if ($mimetype !~ m/^text\//) {
2146 return git_blob_plain
($mimetype);
2149 my $formats_nav = '';
2150 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2151 if (defined $file_name) {
2153 $formats_nav .= $cgi->a({-href
=> href
(action
=>"blame", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, "blame") . " | ";
2156 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash, file_name
=>$file_name)}, "plain") .
2157 " | " . $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>"HEAD", file_name
=>$file_name)}, "head");
2159 $formats_nav .= $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "plain");
2161 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2162 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2164 print "<div class=\"page_nav\">\n" .
2165 "<br/><br/></div>\n" .
2166 "<div class=\"title\">$hash</div>\n";
2168 git_print_page_path
($file_name, "blob", $hash_base);
2169 print "<div class=\"page_body\">\n";
2171 while (my $line = <$fd>) {
2174 $line = untabify
($line);
2175 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
2177 close $fd or print "Reading blob failed.\n";
2183 if (!defined $hash) {
2184 $hash = git_get_head_hash
($project);
2185 if (defined $file_name) {
2186 my $base = $hash_base || $hash;
2187 $hash = git_get_hash_by_path
($base, $file_name, "tree");
2189 if (!defined $hash_base) {
2194 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
2195 or die_error
(undef, "Open git-ls-tree failed");
2196 my @entries = map { chomp; $_ } <$fd>;
2197 close $fd or die_error
(undef, "Reading tree failed");
2200 my $refs = git_get_references
();
2201 my $ref = format_ref_marker
($refs, $hash_base);
2205 my $have_blame = gitweb_check_feature
('blame');
2206 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2207 $base_key{hash_base
} = $hash_base;
2208 git_print_page_nav
('tree','', $hash_base);
2209 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2211 print "<div class=\"page_nav\">\n";
2212 print "<br/><br/></div>\n";
2213 print "<div class=\"title\">$hash</div>\n";
2215 if (defined $file_name) {
2216 $base = esc_html
("$file_name/");
2218 git_print_page_path
($file_name, 'tree', $hash_base);
2219 print "<div class=\"page_body\">\n";
2220 print "<table cellspacing=\"0\">\n";
2222 foreach my $line (@entries) {
2223 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2224 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2228 my $t_name = validate_input
($4);
2230 print "<tr class=\"dark\">\n";
2232 print "<tr class=\"light\">\n";
2235 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
2236 if ($t_type eq "blob") {
2237 print "<td class=\"list\">" .
2238 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key), -class => "list"}, esc_html
($t_name)) .
2240 "<td class=\"link\">" .
2241 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)}, "blob");
2243 print " | " . $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)}, "blame");
2245 print " | " . $cgi->a({-href
=> href
(action
=>"history", hash
=>$t_hash, hash_base
=>$hash_base, file_name
=>"$base$t_name")}, "history") .
2246 " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$t_hash, file_name
=>"$base$t_name")}, "raw") .
2248 } elsif ($t_type eq "tree") {
2249 print "<td class=\"list\">" .
2250 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)}, esc_html
($t_name)) .
2252 "<td class=\"link\">" .
2253 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)}, "tree") .
2254 " | " . $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base, file_name
=>"$base$t_name")}, "history") .
2259 print "</table>\n" .
2266 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2267 my $have_snapshot = (defined $ctype && defined $suffix);
2268 if (!$have_snapshot) {
2269 die_error
('403 Permission denied', "Permission denied");
2272 if (!defined $hash) {
2273 $hash = git_get_head_hash
($project);
2276 my $filename = basename
($project) . "-$hash.tar.$suffix";
2278 print $cgi->header(-type
=> 'application/x-tar',
2279 -content
-encoding
=> $ctype,
2280 '-content-disposition' =>
2281 "inline; filename=\"$filename\"",
2282 -status
=> '200 OK');
2284 open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | $command" or
2285 die_error
(undef, "Execute git-tar-tree failed.");
2286 binmode STDOUT
, ':raw';
2288 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2294 my $head = git_get_head_hash
($project);
2295 if (!defined $hash) {
2298 if (!defined $page) {
2301 my $refs = git_get_references
();
2303 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2304 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2305 or die_error
(undef, "Open git-rev-list failed");
2306 my @revlist = map { chomp; $_ } <$fd>;
2309 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2312 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2315 my %co = parse_commit
($hash);
2317 git_print_header_div
('summary', $project);
2318 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2320 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2321 my $commit = $revlist[$i];
2322 my $ref = format_ref_marker
($refs, $commit);
2323 my %co = parse_commit
($commit);
2325 my %ad = parse_date
($co{'author_epoch'});
2326 git_print_header_div
('commit',
2327 "<span class=\"age\">$co{'age_string'}</span>" .
2328 esc_html
($co{'title'}) . $ref,
2330 print "<div class=\"title_text\">\n" .
2331 "<div class=\"log_link\">\n" .
2332 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2333 " | " . $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2336 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2339 print "<div class=\"log_body\">\n";
2340 git_print_simplified_log
($co{'comment'});
2347 my %co = parse_commit
($hash);
2349 die_error
(undef, "Unknown commit object");
2351 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2352 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2354 my $parent = $co{'parent'};
2355 if (!defined $parent) {
2358 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
2359 or die_error
(undef, "Open git-diff-tree failed");
2360 my @difftree = map { chomp; $_ } <$fd>;
2361 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2363 # non-textual hash id's can be cached
2365 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2368 my $refs = git_get_references
();
2369 my $ref = format_ref_marker
($refs, $co{'id'});
2371 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2372 my $have_snapshot = (defined $ctype && defined $suffix);
2374 my $formats_nav = '';
2375 if (defined $file_name && defined $co{'parent'}) {
2376 my $parent = $co{'parent'};
2377 $formats_nav .= $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)}, "blame");
2379 git_header_html
(undef, $expires);
2380 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
2381 $hash, $co{'tree'}, $hash,
2384 if (defined $co{'parent'}) {
2385 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2387 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
2389 print "<div class=\"title_text\">\n" .
2390 "<table cellspacing=\"0\">\n";
2391 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2393 "<td></td><td> $ad{'rfc2822'}";
2394 if ($ad{'hour_local'} < 6) {
2395 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2397 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2401 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2402 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
2403 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2406 "<td class=\"sha1\">" .
2407 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash), class => "list"}, $co{'tree'}) .
2409 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)}, "tree");
2410 if ($have_snapshot) {
2411 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
2415 my $parents = $co{'parents'};
2416 foreach my $par (@
$parents) {
2419 "<td class=\"sha1\">" . $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par), class => "list"}, $par) . "</td>" .
2420 "<td class=\"link\">" .
2421 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
2422 " | " . $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "commitdiff") .
2429 print "<div class=\"page_body\">\n";
2430 git_print_log
($co{'comment'});
2433 git_difftree_body
(\
@difftree, $parent);
2439 mkdir($git_temp, 0700);
2441 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2443 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", hash
=>$hash, hash_parent
=>$hash_parent)}, "plain");
2444 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2445 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2447 print "<div class=\"page_nav\">\n" .
2448 "<br/><br/></div>\n" .
2449 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2451 git_print_page_path
($file_name, "blob", $hash_base);
2452 print "<div class=\"page_body\">\n" .
2453 "<div class=\"diff_info\">blob:" .
2454 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash_parent, hash_base
=>$hash_base, file_name
=>($file_parent || $file_name))}, $hash_parent) .
2456 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, $hash) .
2458 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2463 sub git_blobdiff_plain
{
2464 mkdir($git_temp, 0700);
2465 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2466 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2469 sub git_commitdiff
{
2470 mkdir($git_temp, 0700);
2471 my %co = parse_commit
($hash);
2473 die_error
(undef, "Unknown commit object");
2475 if (!defined $hash_parent) {
2476 $hash_parent = $co{'parent'} || '--root';
2478 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2479 or die_error
(undef, "Open git-diff-tree failed");
2480 my @difftree = map { chomp; $_ } <$fd>;
2481 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2483 # non-textual hash id's can be cached
2485 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2488 my $refs = git_get_references
();
2489 my $ref = format_ref_marker
($refs, $co{'id'});
2491 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", hash
=>$hash, hash_parent
=>$hash_parent)}, "plain");
2492 git_header_html
(undef, $expires);
2493 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2494 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2495 print "<div class=\"page_body\">\n";
2496 git_print_simplified_log
($co{'comment'}, 1); # skip title
2498 foreach my $line (@difftree) {
2499 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2500 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2501 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2509 my $file = validate_input
(unquote
($6));
2510 if ($status eq "A") {
2511 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2512 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file)}, $to_id) . "(new)" .
2514 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2515 } elsif ($status eq "D") {
2516 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2517 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$hash_parent, file_name
=>$file)}, $from_id) . "(deleted)" .
2519 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2520 } elsif ($status eq "M") {
2521 if ($from_id ne $to_id) {
2522 print "<div class=\"diff_info\">" .
2523 file_type
($from_mode) . ":" .
2524 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$hash_parent, file_name
=>$file)}, $from_id) .
2526 file_type
($to_mode) . ":" .
2527 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file)}, $to_id);
2529 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2538 sub git_commitdiff_plain
{
2539 mkdir($git_temp, 0700);
2540 my %co = parse_commit
($hash);
2542 die_error
(undef, "Unknown commit object");
2544 if (!defined $hash_parent) {
2545 $hash_parent = $co{'parent'} || '--root';
2547 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2548 or die_error
(undef, "Open git-diff-tree failed");
2549 my @difftree = map { chomp; $_ } <$fd>;
2550 close $fd or die_error
(undef, "Reading diff-tree failed");
2552 # try to figure out the next tag after this commit
2554 my $refs = git_get_references
("tags");
2555 open $fd, "-|", $GIT, "rev-list", "HEAD";
2556 my @commits = map { chomp; $_ } <$fd>;
2558 foreach my $commit (@commits) {
2559 if (defined $refs->{$commit}) {
2560 $tagname = $refs->{$commit}
2562 if ($commit eq $hash) {
2567 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2568 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2569 my $comment = $co{'comment'};
2570 print "From: $co{'author'}\n" .
2571 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2572 "Subject: $co{'title'}\n";
2573 if (defined $tagname) {
2574 print "X-Git-Tag: $tagname\n";
2576 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2579 foreach my $line (@
$comment) {;
2584 foreach my $line (@difftree) {
2585 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2592 if ($status eq "A") {
2593 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2594 } elsif ($status eq "D") {
2595 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2596 } elsif ($status eq "M") {
2597 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2603 if (!defined $hash_base) {
2604 $hash_base = git_get_head_hash
($project);
2607 my %co = parse_commit
($hash_base);
2609 die_error
(undef, "Unknown commit object");
2611 my $refs = git_get_references
();
2613 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2614 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2615 if (!defined $hash && defined $file_name) {
2616 $hash = git_get_hash_by_path
($hash_base, $file_name);
2618 if (defined $hash) {
2619 $ftype = git_get_type
($hash);
2621 git_print_page_path
($file_name, $ftype, $hash_base);
2624 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2625 git_history_body
($fd, $refs, $hash_base, $ftype);
2632 if (!defined $searchtext) {
2633 die_error
(undef, "Text field empty");
2635 if (!defined $hash) {
2636 $hash = git_get_head_hash
($project);
2638 my %co = parse_commit
($hash);
2640 die_error
(undef, "Unknown commit object");
2642 # pickaxe may take all resources of your box and run for several minutes
2643 # with every query - so decide by yourself how public you make this feature :)
2644 my $commit_search = 1;
2645 my $author_search = 0;
2646 my $committer_search = 0;
2647 my $pickaxe_search = 0;
2648 if ($searchtext =~ s/^author\\://i) {
2650 } elsif ($searchtext =~ s/^committer\\://i) {
2651 $committer_search = 1;
2652 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2654 $pickaxe_search = 1;
2657 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
2658 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
2660 print "<table cellspacing=\"0\">\n";
2662 if ($commit_search) {
2664 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2665 while (my $commit_text = <$fd>) {
2666 if (!grep m/$searchtext/i, $commit_text) {
2669 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2672 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2675 my @commit_lines = split "\n", $commit_text;
2676 my %co = parse_commit
(undef, \
@commit_lines);
2681 print "<tr class=\"dark\">\n";
2683 print "<tr class=\"light\">\n";
2686 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2687 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2689 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}) -class => "list"}, "<b>" . esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2690 my $comment = $co{'comment'};
2691 foreach my $line (@
$comment) {
2692 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2693 my $lead = esc_html
($1) || "";
2694 $lead = chop_str
($lead, 30, 10);
2695 my $match = esc_html
($2) || "";
2696 my $trail = esc_html
($3) || "";
2697 $trail = chop_str
($trail, 30, 10);
2698 my $text = "$lead<span class=\"match\">$match</span>$trail";
2699 print chop_str
($text, 80, 5) . "<br/>\n";
2703 "<td class=\"link\">" .
2704 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
2705 " | " . $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
2712 if ($pickaxe_search) {
2714 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2717 while (my $line = <$fd>) {
2718 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2721 $set{'from_id'} = $3;
2723 $set{'id'} = $set{'to_id'};
2724 if ($set{'id'} =~ m/0{40}/) {
2725 $set{'id'} = $set{'from_id'};
2727 if ($set{'id'} =~ m/0{40}/) {
2731 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2734 print "<tr class=\"dark\">\n";
2736 print "<tr class=\"light\">\n";
2739 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2740 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2742 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list"}, "<b>" .
2743 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2744 while (my $setref = shift @files) {
2746 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$set{'id'}, hash_base
=>$co{'id'}, file_name
=>$set{'file'}), class => "list"},
2747 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2751 "<td class=\"link\">" .
2752 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
2753 " | " . $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
2757 %co = parse_commit
($1);
2767 my $head = git_get_head_hash
($project);
2768 if (!defined $hash) {
2771 if (!defined $page) {
2774 my $refs = git_get_references
();
2776 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2777 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2778 or die_error
(undef, "Open git-rev-list failed");
2779 my @revlist = map { chomp; $_ } <$fd>;
2782 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
2784 if ($#revlist >= (100 * ($page+1)-1)) {
2786 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
2787 -title
=> "Alt-n"}, "next");
2792 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
2793 git_print_header_div
('summary', $project);
2795 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
2800 ## ......................................................................
2801 ## feeds (RSS, OPML)
2804 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
2805 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash
($project)
2806 or die_error
(undef, "Open git-rev-list failed");
2807 my @revlist = map { chomp; $_ } <$fd>;
2808 close $fd or die_error
(undef, "Reading git-rev-list failed");
2809 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2810 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2811 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
2812 print "<channel>\n";
2813 print "<title>$project</title>\n".
2814 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
2815 "<description>$project log</description>\n".
2816 "<language>en</language>\n";
2818 for (my $i = 0; $i <= $#revlist; $i++) {
2819 my $commit = $revlist[$i];
2820 my %co = parse_commit
($commit);
2821 # we read 150, we always show 30 and the ones more recent than 48 hours
2822 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
2825 my %cd = parse_date
($co{'committer_epoch'});
2826 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
2827 my @difftree = map { chomp; $_ } <$fd>;
2831 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
2833 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
2834 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
2835 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
2836 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
2837 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
2838 "<content:encoded>" .
2840 my $comment = $co{'comment'};
2841 foreach my $line (@
$comment) {
2842 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
2843 print "$line<br/>\n";
2846 foreach my $line (@difftree) {
2847 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2850 my $file = validate_input
(unquote
($7));
2851 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
2852 print "$file<br/>\n";
2855 "</content:encoded>\n" .
2858 print "</channel></rss>";
2862 my @list = git_get_projects_list
();
2864 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2865 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2866 "<opml version=\"1.0\">\n".
2868 " <title>$site_name Git OPML Export</title>\n".
2871 "<outline text=\"git RSS feeds\">\n";
2873 foreach my $pr (@list) {
2875 my $head = git_get_head_hash
($proj{'path'});
2876 if (!defined $head) {
2879 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
2880 my %co = parse_commit
($head);
2885 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
2886 my $rss = "$my_url?p=$proj{'path'};a=rss";
2887 my $html = "$my_url?p=$proj{'path'};a=summary";
2888 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
2890 print "</outline>\n".