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 $hash_parent_base = $cgi->param('hpb');
215 if (defined $hash_parent_base) {
216 if (!validate_input
($hash_parent_base)) {
217 die_error
(undef, "Invalid hash parent base parameter");
221 our $page = $cgi->param('pg');
223 if ($page =~ m/[^0-9]$/) {
224 die_error
(undef, "Invalid page parameter");
228 our $searchtext = $cgi->param('s');
229 if (defined $searchtext) {
230 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
231 die_error
(undef, "Invalid search parameter");
233 $searchtext = quotemeta $searchtext;
238 "blame" => \
&git_blame2
,
239 "blobdiff" => \
&git_blobdiff
,
240 "blobdiff_plain" => \
&git_blobdiff_plain
,
241 "blob" => \
&git_blob
,
242 "blob_plain" => \
&git_blob_plain
,
243 "commitdiff" => \
&git_commitdiff
,
244 "commitdiff_plain" => \
&git_commitdiff_plain
,
245 "commit" => \
&git_commit
,
246 "heads" => \
&git_heads
,
247 "history" => \
&git_history
,
250 "search" => \
&git_search
,
251 "shortlog" => \
&git_shortlog
,
252 "summary" => \
&git_summary
,
254 "tags" => \
&git_tags
,
255 "tree" => \
&git_tree
,
256 "snapshot" => \
&git_snapshot
,
257 # those below don't need $project
258 "opml" => \
&git_opml
,
259 "project_list" => \
&git_project_list
,
262 if (defined $project) {
263 $action ||= 'summary';
265 $action ||= 'project_list';
267 if (!defined($actions{$action})) {
268 die_error
(undef, "Unknown action");
270 $actions{$action}->();
273 ## ======================================================================
287 hash_parent_base
=> "hpb",
291 my %mapping = @mapping;
293 $params{"project"} ||= $project;
296 for (my $i = 0; $i < @mapping; $i += 2) {
297 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
298 if (defined $params{$name}) {
299 push @result, $symbol . "=" . esc_param
($params{$name});
302 return "$my_uri?" . join(';', @result);
306 ## ======================================================================
307 ## validation, quoting/unquoting and escaping
312 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
315 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
318 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
324 # quote unsafe chars, but keep the slash, even when it's not
325 # correct, but quoted slashes look too horrible in bookmarks
328 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
334 # replace invalid utf8 character with SUBSTITUTION sequence
337 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
338 $str = escapeHTML
($str);
339 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
343 # git may return quoted and escaped filenames
346 if ($str =~ m/^"(.*)"$/) {
348 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
353 # escape tabs (convert tabs to spaces)
357 while ((my $pos = index($line, "\t")) != -1) {
358 if (my $count = (8 - ($pos % 8))) {
359 my $spaces = ' ' x
$count;
360 $line =~ s/\t/$spaces/;
367 ## ----------------------------------------------------------------------
368 ## HTML aware string manipulation
373 my $add_len = shift || 10;
375 # allow only $len chars, but don't cut a word if it would fit in $add_len
376 # if it doesn't fit, cut it if it's still longer than the dots we would add
377 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
380 if (length($tail) > 4) {
382 $body =~ s/&[^;]*$//; # remove chopped character entities
387 ## ----------------------------------------------------------------------
388 ## functions returning short strings
390 # CSS class for given age value (in seconds)
394 if ($age < 60*60*2) {
396 } elsif ($age < 60*60*24*2) {
403 # convert age in seconds to "nn units ago" string
408 if ($age > 60*60*24*365*2) {
409 $age_str = (int $age/60/60/24/365);
410 $age_str .= " years ago";
411 } elsif ($age > 60*60*24*(365/12)*2) {
412 $age_str = int $age/60/60/24/(365/12);
413 $age_str .= " months ago";
414 } elsif ($age > 60*60*24*7*2) {
415 $age_str = int $age/60/60/24/7;
416 $age_str .= " weeks ago";
417 } elsif ($age > 60*60*24*2) {
418 $age_str = int $age/60/60/24;
419 $age_str .= " days ago";
420 } elsif ($age > 60*60*2) {
421 $age_str = int $age/60/60;
422 $age_str .= " hours ago";
423 } elsif ($age > 60*2) {
424 $age_str = int $age/60;
425 $age_str .= " min ago";
428 $age_str .= " sec ago";
430 $age_str .= " right now";
435 # convert file mode in octal to symbolic file mode string
437 my $mode = oct shift;
439 if (S_ISDIR
($mode & S_IFMT
)) {
441 } elsif (S_ISLNK
($mode)) {
443 } elsif (S_ISREG
($mode)) {
444 # git cares only about the executable bit
445 if ($mode & S_IXUSR
) {
455 # convert file mode in octal to file type string
457 my $mode = oct shift;
459 if (S_ISDIR
($mode & S_IFMT
)) {
461 } elsif (S_ISLNK
($mode)) {
463 } elsif (S_ISREG
($mode)) {
470 ## ----------------------------------------------------------------------
471 ## functions returning short HTML fragments, or transforming HTML fragments
472 ## which don't beling to other sections
474 # format line of commit message or tag comment
475 sub format_log_line_html
{
478 $line = esc_html
($line);
479 $line =~ s/ / /g;
480 if ($line =~ m/([0-9a-fA-F]{40})/) {
482 if (git_get_type
($hash_text) eq "commit") {
484 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
485 -class => "text"}, $hash_text);
486 $line =~ s/$hash_text/$link/;
492 # format marker of refs pointing to given object
493 sub format_ref_marker
{
494 my ($refs, $id) = @_;
497 if (defined $refs->{$id}) {
498 foreach my $ref (@
{$refs->{$id}}) {
499 my ($type, $name) = qw();
500 # e.g. tags/v2.6.11 or heads/next
501 if ($ref =~ m!^(.*?)s?/(.*)$!) {
509 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
514 return ' <span class="refs">'. $markers . '</span>';
520 # format, perhaps shortened and with markers, title line
521 sub format_subject_html
{
522 my ($long, $short, $href, $extra) = @_;
523 $extra = '' unless defined($extra);
525 if (length($short) < length($long)) {
526 return $cgi->a({-href
=> $href, -class => "list subject",
528 esc_html
($short) . $extra);
530 return $cgi->a({-href
=> $href, -class => "list subject"},
531 esc_html
($long) . $extra);
535 sub format_diff_line
{
537 my $char = substr($line, 0, 1);
543 $diff_class = " add";
544 } elsif ($char eq "-") {
545 $diff_class = " rem";
546 } elsif ($char eq "@") {
547 $diff_class = " chunk_header";
548 } elsif ($char eq "\\") {
549 $diff_class = " incomplete";
551 $line = untabify
($line);
552 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
555 ## ----------------------------------------------------------------------
556 ## git utility subroutines, invoking git commands
558 # get HEAD ref of given project as hash
559 sub git_get_head_hash
{
561 my $oENV = $ENV{'GIT_DIR'};
563 $ENV{'GIT_DIR'} = "$projectroot/$project";
564 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
567 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
572 $ENV{'GIT_DIR'} = $oENV;
577 # get type of given object
581 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
588 sub git_get_project_config
{
589 my ($key, $type) = @_;
591 return unless ($key);
592 $key =~ s/^gitweb\.//;
593 return if ($key =~ m/\W/);
595 my @x = ($GIT, 'repo-config');
596 if (defined $type) { push @x, $type; }
598 push @x, "gitweb.$key";
604 # get hash of given path at given ref
605 sub git_get_hash_by_path
{
607 my $path = shift || return undef;
611 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
612 or die_error
(undef, "Open git-ls-tree failed");
614 close $fd or return undef;
616 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
617 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
621 ## ......................................................................
622 ## git utility functions, directly accessing git repository
624 # assumes that PATH is not symref
625 sub git_get_hash_by_ref
{
628 open my $fd, "$projectroot/$path" or return undef;
632 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
637 sub git_get_project_description
{
640 open my $fd, "$projectroot/$path/description" or return undef;
647 sub git_get_project_url_list
{
650 open my $fd, "$projectroot/$path/cloneurl" or return undef;
651 my @git_project_url_list = map { chomp; $_ } <$fd>;
654 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
657 sub git_get_projects_list
{
660 if (-d
$projects_list) {
661 # search in directory
662 my $dir = $projects_list;
663 opendir my ($dh), $dir or return undef;
664 while (my $dir = readdir($dh)) {
665 if (-e
"$projectroot/$dir/HEAD") {
673 } elsif (-f
$projects_list) {
674 # read from file(url-encoded):
675 # 'git%2Fgit.git Linus+Torvalds'
676 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
677 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
678 open my ($fd), $projects_list or return undef;
679 while (my $line = <$fd>) {
681 my ($path, $owner) = split ' ', $line;
682 $path = unescape
($path);
683 $owner = unescape
($owner);
684 if (!defined $path) {
687 if (-e
"$projectroot/$path/HEAD") {
690 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
697 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
701 sub git_get_project_owner
{
705 return undef unless $project;
707 # read from file (url-encoded):
708 # 'git%2Fgit.git Linus+Torvalds'
709 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
710 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
711 if (-f
$projects_list) {
712 open (my $fd , $projects_list);
713 while (my $line = <$fd>) {
715 my ($pr, $ow) = split ' ', $line;
718 if ($pr eq $project) {
719 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
725 if (!defined $owner) {
726 $owner = get_file_owner
("$projectroot/$project");
732 sub git_get_references
{
733 my $type = shift || "";
736 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
737 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
738 if (-f
"$projectroot/$project/info/refs") {
739 open $fd, "$projectroot/$project/info/refs"
742 open $fd, "-|", $GIT, "ls-remote", "."
746 while (my $line = <$fd>) {
748 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
749 if (defined $refs{$1}) {
750 push @
{$refs{$1}}, $2;
760 sub git_get_following_references
{
761 my $hash = shift || return undef;
763 my $base = shift || $hash_base || "HEAD";
765 my $refs = git_get_references
($type);
766 open my $fd, "-|", $GIT, "rev-list", $base
768 my @commits = map { chomp; $_ } <$fd>;
775 foreach my $commit (@commits) {
776 foreach my $ref (@
{$refs->{$commit}}) {
778 push @reflist, $lastref;
780 if ($commit eq $hash) {
785 return wantarray ?
@reflist : $lastref;
788 sub git_get_preceding_references
{
789 my $hash = shift || return undef;
792 my $refs = git_get_references
($type);
793 open my $fd, "-|", $GIT, "rev-list", $hash
795 my @commits = map { chomp; $_ } <$fd>;
801 foreach my $commit (@commits) {
802 foreach my $ref (@
{$refs->{$commit}}) {
803 return $ref unless wantarray;
811 sub git_get_rev_name_tags
{
812 my $hash = shift || return undef;
814 open my $fd, "-|", $GIT, "name-rev", "--tags", $hash
816 my $name_rev = <$fd>;
819 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
822 # catches also '$hash undefined' output
827 ## ----------------------------------------------------------------------
828 ## parse to hash functions
832 my $tz = shift || "-0000";
835 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
836 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
837 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
838 $date{'hour'} = $hour;
839 $date{'minute'} = $min;
840 $date{'mday'} = $mday;
841 $date{'day'} = $days[$wday];
842 $date{'month'} = $months[$mon];
843 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
844 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
845 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
846 $mday, $months[$mon], $hour ,$min;
848 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
849 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
850 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
851 $date{'hour_local'} = $hour;
852 $date{'minute_local'} = $min;
853 $date{'tz_local'} = $tz;
862 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
863 $tag{'id'} = $tag_id;
864 while (my $line = <$fd>) {
866 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
868 } elsif ($line =~ m/^type (.+)$/) {
870 } elsif ($line =~ m/^tag (.+)$/) {
872 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
876 } elsif ($line =~ m/--BEGIN/) {
877 push @comment, $line;
879 } elsif ($line eq "") {
883 push @comment, <$fd>;
884 $tag{'comment'} = \
@comment;
886 if (!defined $tag{'name'}) {
893 my $commit_id = shift;
894 my $commit_text = shift;
899 if (defined $commit_text) {
900 @commit_lines = @
$commit_text;
903 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id
905 @commit_lines = split '\n', <$fd>;
910 my $header = shift @commit_lines;
911 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
914 ($co{'id'}, my @parents) = split ' ', $header;
915 $co{'parents'} = \
@parents;
916 $co{'parent'} = $parents[0];
917 while (my $line = shift @commit_lines) {
918 last if $line eq "\n";
919 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
921 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
923 $co{'author_epoch'} = $2;
924 $co{'author_tz'} = $3;
925 if ($co{'author'} =~ m/^([^<]+) </) {
926 $co{'author_name'} = $1;
928 $co{'author_name'} = $co{'author'};
930 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
931 $co{'committer'} = $1;
932 $co{'committer_epoch'} = $2;
933 $co{'committer_tz'} = $3;
934 $co{'committer_name'} = $co{'committer'};
935 $co{'committer_name'} =~ s/ <.*//;
938 if (!defined $co{'tree'}) {
942 foreach my $title (@commit_lines) {
945 $co{'title'} = chop_str
($title, 80, 5);
946 # remove leading stuff of merges to make the interesting part visible
947 if (length($title) > 50) {
948 $title =~ s/^Automatic //;
949 $title =~ s/^merge (of|with) /Merge ... /i;
950 if (length($title) > 50) {
951 $title =~ s/(http|rsync):\/\///;
953 if (length($title) > 50) {
954 $title =~ s/(master|www|rsync)\.//;
956 if (length($title) > 50) {
957 $title =~ s/kernel.org:?//;
959 if (length($title) > 50) {
960 $title =~ s/\/pub\/scm//;
963 $co{'title_short'} = chop_str
($title, 50, 5);
967 # remove added spaces
968 foreach my $line (@commit_lines) {
971 $co{'comment'} = \
@commit_lines;
973 my $age = time - $co{'committer_epoch'};
975 $co{'age_string'} = age_string
($age);
976 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
977 if ($age > 60*60*24*7*2) {
978 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
979 $co{'age_string_age'} = $co{'age_string'};
981 $co{'age_string_date'} = $co{'age_string'};
982 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
987 # parse ref from ref_file, given by ref_id, with given type
989 my $ref_file = shift;
991 my $type = shift || git_get_type
($ref_id);
994 $ref_item{'type'} = $type;
995 $ref_item{'id'} = $ref_id;
996 $ref_item{'epoch'} = 0;
997 $ref_item{'age'} = "unknown";
998 if ($type eq "tag") {
999 my %tag = parse_tag
($ref_id);
1000 $ref_item{'comment'} = $tag{'comment'};
1001 if ($tag{'type'} eq "commit") {
1002 my %co = parse_commit
($tag{'object'});
1003 $ref_item{'epoch'} = $co{'committer_epoch'};
1004 $ref_item{'age'} = $co{'age_string'};
1005 } elsif (defined($tag{'epoch'})) {
1006 my $age = time - $tag{'epoch'};
1007 $ref_item{'epoch'} = $tag{'epoch'};
1008 $ref_item{'age'} = age_string
($age);
1010 $ref_item{'reftype'} = $tag{'type'};
1011 $ref_item{'name'} = $tag{'name'};
1012 $ref_item{'refid'} = $tag{'object'};
1013 } elsif ($type eq "commit"){
1014 my %co = parse_commit
($ref_id);
1015 $ref_item{'reftype'} = "commit";
1016 $ref_item{'name'} = $ref_file;
1017 $ref_item{'title'} = $co{'title'};
1018 $ref_item{'refid'} = $ref_id;
1019 $ref_item{'epoch'} = $co{'committer_epoch'};
1020 $ref_item{'age'} = $co{'age_string'};
1022 $ref_item{'reftype'} = $type;
1023 $ref_item{'name'} = $ref_file;
1024 $ref_item{'refid'} = $ref_id;
1030 # parse line of git-diff-tree "raw" output
1031 sub parse_difftree_raw_line
{
1035 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1036 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1037 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1038 $res{'from_mode'} = $1;
1039 $res{'to_mode'} = $2;
1040 $res{'from_id'} = $3;
1042 $res{'status'} = $5;
1043 $res{'similarity'} = $6;
1044 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1045 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1047 $res{'file'} = unquote
($7);
1050 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1051 #elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1052 # $res{'commit'} = $1;
1055 return wantarray ?
%res : \
%res;
1058 ## ......................................................................
1059 ## parse to array of hashes functions
1061 sub git_get_refs_list
{
1062 my $ref_dir = shift;
1066 my $pfxlen = length("$projectroot/$project/$ref_dir");
1067 File
::Find
::find
(sub {
1070 push @refs, substr($File::Find
::name
, $pfxlen + 1);
1072 }, "$projectroot/$project/$ref_dir");
1074 foreach my $ref_file (@refs) {
1075 my $ref_id = git_get_hash_by_ref
("$project/$ref_dir/$ref_file");
1076 my $type = git_get_type
($ref_id) || next;
1077 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1079 push @reflist, \
%ref_item;
1082 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1086 ## ----------------------------------------------------------------------
1087 ## filesystem-related functions
1089 sub get_file_owner
{
1092 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1093 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1094 if (!defined $gcos) {
1098 $owner =~ s/[,;].*$//;
1099 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
1102 ## ......................................................................
1103 ## mimetype related functions
1105 sub mimetype_guess_file
{
1106 my $filename = shift;
1107 my $mimemap = shift;
1108 -r
$mimemap or return undef;
1111 open(MIME
, $mimemap) or return undef;
1113 next if m/^#/; # skip comments
1114 my ($mime, $exts) = split(/\t+/);
1115 if (defined $exts) {
1116 my @exts = split(/\s+/, $exts);
1117 foreach my $ext (@exts) {
1118 $mimemap{$ext} = $mime;
1124 $filename =~ /\.(.*?)$/;
1125 return $mimemap{$1};
1128 sub mimetype_guess
{
1129 my $filename = shift;
1131 $filename =~ /\./ or return undef;
1133 if ($mimetypes_file) {
1134 my $file = $mimetypes_file;
1135 if ($file !~ m!^/!) { # if it is relative path
1136 # it is relative to project
1137 $file = "$projectroot/$project/$file";
1139 $mime = mimetype_guess_file
($filename, $file);
1141 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1147 my $filename = shift;
1150 my $mime = mimetype_guess
($filename);
1151 $mime and return $mime;
1155 return $default_blob_plain_mimetype unless $fd;
1158 return 'text/plain' .
1159 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1160 } elsif (! $filename) {
1161 return 'application/octet-stream';
1162 } elsif ($filename =~ m/\.png$/i) {
1164 } elsif ($filename =~ m/\.gif$/i) {
1166 } elsif ($filename =~ m/\.jpe?g$/i) {
1167 return 'image/jpeg';
1169 return 'application/octet-stream';
1173 ## ======================================================================
1174 ## functions printing HTML: header, footer, error page
1176 sub git_header_html
{
1177 my $status = shift || "200 OK";
1178 my $expires = shift;
1180 my $title = "$site_name git";
1181 if (defined $project) {
1182 $title .= " - $project";
1183 if (defined $action) {
1184 $title .= "/$action";
1185 if (defined $file_name) {
1186 $title .= " - $file_name";
1187 if ($action eq "tree" && $file_name !~ m
|/$|) {
1194 # require explicit support from the UA if we are to send the page as
1195 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1196 # we have to do this because MSIE sometimes globs '*/*', pretending to
1197 # support xhtml+xml but choking when it gets what it asked for.
1198 if (defined $cgi->http('HTTP_ACCEPT') &&
1199 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1200 $cgi->Accept('application/xhtml+xml') != 0) {
1201 $content_type = 'application/xhtml+xml';
1203 $content_type = 'text/html';
1205 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1206 -status
=> $status, -expires
=> $expires);
1208 <?xml version="1.0" encoding="utf-8"?>
1209 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1210 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1211 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1212 <!-- git core binaries version $git_version -->
1214 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1215 <meta name="generator" content="gitweb/$version git/$git_version"/>
1216 <meta name="robots" content="index, nofollow"/>
1217 <title>$title</title>
1218 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1220 if (defined $project) {
1221 printf('<link rel="alternate" title="%s log" '.
1222 'href="%s" type="application/rss+xml"/>'."\n",
1223 esc_param
($project), href
(action
=>"rss"));
1228 "<div class=\"page_header\">\n" .
1229 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1230 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1232 print $cgi->a({-href
=> esc_param
($home_link)}, $home_link_str) . " / ";
1233 if (defined $project) {
1234 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1235 if (defined $action) {
1239 if (!defined $searchtext) {
1243 if (defined $hash_base) {
1244 $search_hash = $hash_base;
1245 } elsif (defined $hash) {
1246 $search_hash = $hash;
1248 $search_hash = "HEAD";
1250 $cgi->param("a", "search");
1251 $cgi->param("h", $search_hash);
1252 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1253 "<div class=\"search\">\n" .
1254 $cgi->hidden(-name
=> "p") . "\n" .
1255 $cgi->hidden(-name
=> "a") . "\n" .
1256 $cgi->hidden(-name
=> "h") . "\n" .
1257 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1259 $cgi->end_form() . "\n";
1264 sub git_footer_html
{
1265 print "<div class=\"page_footer\">\n";
1266 if (defined $project) {
1267 my $descr = git_get_project_description
($project);
1268 if (defined $descr) {
1269 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1271 print $cgi->a({-href
=> href
(action
=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1273 print $cgi->a({-href
=> href
(action
=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1281 my $status = shift || "403 Forbidden";
1282 my $error = shift || "Malformed query, file missing or permission denied";
1284 git_header_html
($status);
1286 <div class="page_body">
1296 ## ----------------------------------------------------------------------
1297 ## functions printing or outputting HTML: navigation
1299 sub git_print_page_nav
{
1300 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1301 $extra = '' if !defined $extra; # pager or formats
1303 my @navs = qw(summary shortlog log commit commitdiff tree);
1305 @navs = grep { $_ ne $suppress } @navs;
1308 my %arg = map { $_ => {action
=>$_} } @navs;
1309 if (defined $head) {
1310 for (qw(commit commitdiff)) {
1311 $arg{$_}{hash
} = $head;
1313 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1314 for (qw(shortlog log)) {
1315 $arg{$_}{hash
} = $head;
1319 $arg{tree
}{hash
} = $treehead if defined $treehead;
1320 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1322 print "<div class=\"page_nav\">\n" .
1324 map { $_ eq $current ?
1325 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1327 print "<br/>\n$extra<br/>\n" .
1331 sub format_paging_nav
{
1332 my ($action, $hash, $head, $page, $nrevs) = @_;
1336 if ($hash ne $head || $page) {
1337 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1339 $paging_nav .= "HEAD";
1343 $paging_nav .= " ⋅ " .
1344 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1345 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1347 $paging_nav .= " ⋅ prev";
1350 if ($nrevs >= (100 * ($page+1)-1)) {
1351 $paging_nav .= " ⋅ " .
1352 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1353 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1355 $paging_nav .= " ⋅ next";
1361 ## ......................................................................
1362 ## functions printing or outputting HTML: div
1364 sub git_print_header_div
{
1365 my ($action, $title, $hash, $hash_base) = @_;
1368 $args{action
} = $action;
1369 $args{hash
} = $hash if $hash;
1370 $args{hash_base
} = $hash_base if $hash_base;
1372 print "<div class=\"header\">\n" .
1373 $cgi->a({-href
=> href
(%args), -class => "title"},
1374 $title ?
$title : $action) .
1378 sub git_print_page_path
{
1383 if (!defined $name) {
1384 print "<div class=\"page_path\">/</div>\n";
1385 } elsif (defined $type && $type eq 'blob') {
1386 print "<div class=\"page_path\">";
1388 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1392 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name)},
1395 print "<br/></div>\n";
1397 print "<div class=\"page_path\">" . esc_html
($name) . "<br/></div>\n";
1404 # remove leading empty lines
1405 while (defined $log->[0] && $log->[0] eq "") {
1412 foreach my $line (@
$log) {
1413 # print only one empty line
1414 # do not print empty line after signoff
1416 next if ($empty || $signoff);
1421 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1423 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1426 print format_log_line_html
($line) . "<br/>\n";
1431 sub git_print_simplified_log
{
1433 my $remove_title = shift;
1435 shift @
$log if $remove_title;
1436 # remove leading empty lines
1437 while (defined $log->[0] && $log->[0] eq "") {
1441 # simplify and print log
1443 foreach my $line (@
$log) {
1444 # remove signoff lines
1445 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1448 # print only one empty line
1455 print format_log_line_html
($line) . "<br/>\n";
1457 # end with single empty line
1458 print "<br/>\n" unless $empty;
1461 ## ......................................................................
1462 ## functions printing large fragments of HTML
1464 sub git_difftree_body
{
1465 my ($difftree, $hash, $parent) = @_;
1467 print "<div class=\"list_head\">\n";
1468 if ($#{$difftree} > 10) {
1469 print(($#{$difftree} + 1) . " files changed:\n");
1473 print "<table class=\"diff_tree\">\n";
1475 foreach my $line (@
{$difftree}) {
1476 my %diff = parse_difftree_raw_line
($line);
1479 print "<tr class=\"dark\">\n";
1481 print "<tr class=\"light\">\n";
1485 my ($to_mode_oct, $to_mode_str, $to_file_type);
1486 my ($from_mode_oct, $from_mode_str, $from_file_type);
1487 if ($diff{'to_mode'} ne ('0' x
6)) {
1488 $to_mode_oct = oct $diff{'to_mode'};
1489 if (S_ISREG
($to_mode_oct)) { # only for regular file
1490 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1492 $to_file_type = file_type
($diff{'to_mode'});
1494 if ($diff{'from_mode'} ne ('0' x
6)) {
1495 $from_mode_oct = oct $diff{'from_mode'};
1496 if (S_ISREG
($to_mode_oct)) { # only for regular file
1497 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1499 $from_file_type = file_type
($diff{'from_mode'});
1502 if ($diff{'status'} eq "A") { # created
1503 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1504 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1505 $mode_chng .= "]</span>";
1507 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1508 hash_base
=>$hash, file_name
=>$diff{'file'}),
1509 -class => "list"}, esc_html
($diff{'file'})) .
1511 "<td>$mode_chng</td>\n" .
1512 "<td class=\"link\">" .
1513 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1514 hash_base
=>$hash, file_name
=>$diff{'file'})},
1518 } elsif ($diff{'status'} eq "D") { # deleted
1519 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1521 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1522 hash_base
=>$parent, file_name
=>$diff{'file'}),
1523 -class => "list"}, esc_html
($diff{'file'})) .
1525 "<td>$mode_chng</td>\n" .
1526 "<td class=\"link\">" .
1527 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1528 hash_base
=>$parent, file_name
=>$diff{'file'})},
1531 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1532 file_name
=>$diff{'file'})},\
1536 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1537 my $mode_chnge = "";
1538 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1539 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1540 if ($from_file_type != $to_file_type) {
1541 $mode_chnge .= " from $from_file_type to $to_file_type";
1543 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1544 if ($from_mode_str && $to_mode_str) {
1545 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1546 } elsif ($to_mode_str) {
1547 $mode_chnge .= " mode: $to_mode_str";
1550 $mode_chnge .= "]</span>\n";
1553 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1554 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1555 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1556 hash_base
=>$hash, hash_parent_base
=>$parent,
1557 file_name
=>$diff{'file'}),
1558 -class => "list"}, esc_html
($diff{'file'}));
1559 } else { # only mode changed
1560 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1561 hash_base
=>$hash, file_name
=>$diff{'file'}),
1562 -class => "list"}, esc_html
($diff{'file'}));
1565 "<td>$mode_chnge</td>\n" .
1566 "<td class=\"link\">" .
1567 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1568 hash_base
=>$hash, file_name
=>$diff{'file'})},
1570 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1572 $cgi->a({-href
=> href
(action
=>"blobdiff",
1573 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1574 hash_base
=>$hash, hash_parent_base
=>$parent,
1575 file_name
=>$diff{'file'})},
1579 $cgi->a({-href
=> href
(action
=>"history",
1580 hash_base
=>$hash, file_name
=>$diff{'file'})},
1584 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1585 my %status_name = ('R' => 'moved', 'C' => 'copied');
1586 my $nstatus = $status_name{$diff{'status'}};
1588 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1589 # mode also for directories, so we cannot use $to_mode_str
1590 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1593 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1594 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1595 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1596 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1597 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1598 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1599 -class => "list"}, esc_html
($diff{'from_file'})) .
1600 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1601 "<td class=\"link\">" .
1602 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1603 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'})},
1605 if ($diff{'to_id'} ne $diff{'from_id'}) {
1607 $cgi->a({-href
=> href
(action
=>"blobdiff",
1608 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1609 hash_base
=>$hash, hash_parent_base
=>$parent,
1610 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1615 } # we should not encounter Unmerged (U) or Unknown (X) status
1621 sub git_patchset_body
{
1622 my ($fd, $difftree, $hash, $hash_parent) = @_;
1626 my $patch_found = 0;
1629 print "<div class=\"patchset\">\n";
1632 while (my $patch_line @
$fd>) {
1635 if ($patch_line =~ m/^diff /) { # "git diff" header
1636 # beginning of patch (in patchset)
1638 # close previous patch
1639 print "</div>\n"; # class="patch"
1641 # first patch in patchset
1644 print "<div class=\"patch\">\n";
1646 if (ref($difftree->[$patch_idx]) eq "HASH") {
1647 $diffinfo = $difftree->[$patch_idx];
1649 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1653 # for now, no extended header, hence we skip empty patches
1654 # companion to next LINE if $in_header;
1655 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1660 if ($diffinfo->{'status'} eq "A") { # added
1661 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1662 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1663 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1664 $diffinfo->{'to_id'}) . "(new)" .
1665 "</div>\n"; # class="diff_info"
1667 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1668 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
1669 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1670 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1671 $diffinfo->{'from_id'}) . "(deleted)" .
1672 "</div>\n"; # class="diff_info"
1674 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1675 $diffinfo->{'status'} eq "C") { # copied
1676 print "<div class=\"diff_info\">" .
1677 file_type
($diffinfo->{'from_mode'}) . ":" .
1678 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1679 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
1680 $diffinfo->{'from_id'}) .
1682 file_type
($diffinfo->{'to_mode'}) . ":" .
1683 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1684 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
1685 $diffinfo->{'to_id'});
1686 print "</div>\n"; # class="diff_info"
1688 } else { # modified, mode changed, ...
1689 print "<div class=\"diff_info\">" .
1690 file_type
($diffinfo->{'from_mode'}) . ":" .
1691 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1692 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1693 $diffinfo->{'from_id'}) .
1695 file_type
($diffinfo->{'to_mode'}) . ":" .
1696 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1697 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1698 $diffinfo->{'to_id'});
1699 print "</div>\n"; # class="diff_info"
1702 #print "<div class=\"diff extended_header\">\n";
1705 } # start of patch in patchset
1708 if ($in_header && $patch_line =~ m/^---/) {
1712 next LINE
if $in_header;
1714 print format_diff_line
($patch_line);
1716 print "</div>\n" if $patch_found; # class="patch"
1718 print "</div>\n"; # class="patchset"
1721 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1723 sub git_shortlog_body
{
1724 # uses global variable $project
1725 my ($revlist, $from, $to, $refs, $extra) = @_;
1727 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
1728 my $have_snapshot = (defined $ctype && defined $suffix);
1730 $from = 0 unless defined $from;
1731 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1733 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1735 for (my $i = $from; $i <= $to; $i++) {
1736 my $commit = $revlist->[$i];
1737 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1738 my $ref = format_ref_marker
($refs, $commit);
1739 my %co = parse_commit
($commit);
1741 print "<tr class=\"dark\">\n";
1743 print "<tr class=\"light\">\n";
1746 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1747 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1748 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1750 print format_subject_html
($co{'title'}, $co{'title_short'},
1751 href
(action
=>"commit", hash
=>$commit), $ref);
1753 "<td class=\"link\">" .
1754 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1755 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
1756 if ($have_snapshot) {
1757 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
1762 if (defined $extra) {
1764 "<td colspan=\"4\">$extra</td>\n" .
1770 sub git_history_body
{
1771 # Warning: assumes constant type (blob or tree) during history
1772 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1774 print "<table class=\"history\" cellspacing=\"0\">\n";
1776 while (my $line = <$fd>) {
1777 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1782 my %co = parse_commit
($commit);
1787 my $ref = format_ref_marker
($refs, $commit);
1790 print "<tr class=\"dark\">\n";
1792 print "<tr class=\"light\">\n";
1795 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1796 # shortlog uses chop_str($co{'author_name'}, 10)
1797 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1799 # originally git_history used chop_str($co{'title'}, 50)
1800 print format_subject_html
($co{'title'}, $co{'title_short'},
1801 href
(action
=>"commit", hash
=>$commit), $ref);
1803 "<td class=\"link\">" .
1804 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1805 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
1806 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype);
1808 if ($ftype eq 'blob') {
1809 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
1810 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
1811 if (defined $blob_current && defined $blob_parent &&
1812 $blob_current ne $blob_parent) {
1814 $cgi->a({-href
=> href
(action
=>"blobdiff",
1815 hash
=>$blob_current, hash_parent
=>$blob_parent,
1816 hash_base
=>$hash_base, hash_parent_base
=>$commit,
1817 file_name
=>$file_name)},
1824 if (defined $extra) {
1826 "<td colspan=\"4\">$extra</td>\n" .
1833 # uses global variable $project
1834 my ($taglist, $from, $to, $extra) = @_;
1835 $from = 0 unless defined $from;
1836 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1838 print "<table class=\"tags\" cellspacing=\"0\">\n";
1840 for (my $i = $from; $i <= $to; $i++) {
1841 my $entry = $taglist->[$i];
1843 my $comment_lines = $tag{'comment'};
1844 my $comment = shift @
$comment_lines;
1846 if (defined $comment) {
1847 $comment_short = chop_str
($comment, 30, 5);
1850 print "<tr class=\"dark\">\n";
1852 print "<tr class=\"light\">\n";
1855 print "<td><i>$tag{'age'}</i></td>\n" .
1857 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
1858 -class => "list name"}, esc_html
($tag{'name'})) .
1861 if (defined $comment) {
1862 print format_subject_html
($comment, $comment_short,
1863 href
(action
=>"tag", hash
=>$tag{'id'}));
1866 "<td class=\"selflink\">";
1867 if ($tag{'type'} eq "tag") {
1868 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
1873 "<td class=\"link\">" . " | " .
1874 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
1875 if ($tag{'reftype'} eq "commit") {
1876 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
1877 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
1878 } elsif ($tag{'reftype'} eq "blob") {
1879 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
1884 if (defined $extra) {
1886 "<td colspan=\"5\">$extra</td>\n" .
1892 sub git_heads_body
{
1893 # uses global variable $project
1894 my ($taglist, $head, $from, $to, $extra) = @_;
1895 $from = 0 unless defined $from;
1896 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1898 print "<table class=\"heads\" cellspacing=\"0\">\n";
1900 for (my $i = $from; $i <= $to; $i++) {
1901 my $entry = $taglist->[$i];
1903 my $curr = $tag{'id'} eq $head;
1905 print "<tr class=\"dark\">\n";
1907 print "<tr class=\"light\">\n";
1910 print "<td><i>$tag{'age'}</i></td>\n" .
1911 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1912 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
1913 -class => "list name"},esc_html
($tag{'name'})) .
1915 "<td class=\"link\">" .
1916 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
1917 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") .
1921 if (defined $extra) {
1923 "<td colspan=\"3\">$extra</td>\n" .
1929 ## ----------------------------------------------------------------------
1930 ## functions printing large fragments, format as one of arguments
1932 sub git_diff_print
{
1934 my $from_name = shift;
1936 my $to_name = shift;
1937 my $format = shift || "html";
1939 my $from_tmp = "/dev/null";
1940 my $to_tmp = "/dev/null";
1943 # create tmp from-file
1944 if (defined $from) {
1945 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1946 open my $fd2, "> $from_tmp";
1947 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1954 # create tmp to-file
1956 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1957 open my $fd2, "> $to_tmp";
1958 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1965 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1966 if ($format eq "plain") {
1971 while (my $line = <$fd>) {
1973 my $char = substr($line, 0, 1);
1974 my $diff_class = "";
1976 $diff_class = " add";
1977 } elsif ($char eq "-") {
1978 $diff_class = " rem";
1979 } elsif ($char eq "@") {
1980 $diff_class = " chunk_header";
1981 } elsif ($char eq "\\") {
1985 $line = untabify
($line);
1986 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
1991 if (defined $from) {
2000 ## ======================================================================
2001 ## ======================================================================
2004 sub git_project_list
{
2005 my $order = $cgi->param('o');
2006 if (defined $order && $order !~ m/project|descr|owner|age/) {
2007 die_error
(undef, "Unknown order parameter");
2010 my @list = git_get_projects_list
();
2013 die_error
(undef, "No projects found");
2015 foreach my $pr (@list) {
2016 my $head = git_get_head_hash
($pr->{'path'});
2017 if (!defined $head) {
2020 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
2021 my %co = parse_commit
($head);
2025 $pr->{'commit'} = \
%co;
2026 if (!defined $pr->{'descr'}) {
2027 my $descr = git_get_project_description
($pr->{'path'}) || "";
2028 $pr->{'descr'} = chop_str
($descr, 25, 5);
2030 if (!defined $pr->{'owner'}) {
2031 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2033 push @projects, $pr;
2037 if (-f
$home_text) {
2038 print "<div class=\"index_include\">\n";
2039 open (my $fd, $home_text);
2044 print "<table class=\"project_list\">\n" .
2046 $order ||= "project";
2047 if ($order eq "project") {
2048 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2049 print "<th>Project</th>\n";
2052 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
2053 -class => "header"}, "Project") .
2056 if ($order eq "descr") {
2057 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2058 print "<th>Description</th>\n";
2061 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
2062 -class => "header"}, "Description") .
2065 if ($order eq "owner") {
2066 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2067 print "<th>Owner</th>\n";
2070 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
2071 -class => "header"}, "Owner") .
2074 if ($order eq "age") {
2075 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2076 print "<th>Last Change</th>\n";
2079 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
2080 -class => "header"}, "Last Change") .
2083 print "<th></th>\n" .
2086 foreach my $pr (@projects) {
2088 print "<tr class=\"dark\">\n";
2090 print "<tr class=\"light\">\n";
2093 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2094 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2095 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2096 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2097 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2098 $pr->{'commit'}{'age_string'} . "</td>\n" .
2099 "<td class=\"link\">" .
2100 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2101 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2102 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") .
2111 my $descr = git_get_project_description
($project) || "none";
2112 my $head = git_get_head_hash
($project);
2113 my %co = parse_commit
($head);
2114 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2116 my $owner = git_get_project_owner
($project);
2118 my $refs = git_get_references
();
2120 git_print_page_nav
('summary','', $head);
2122 print "<div class=\"title\"> </div>\n";
2123 print "<table cellspacing=\"0\">\n" .
2124 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2125 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2126 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2127 # use per project git URL list in $projectroot/$project/cloneurl
2128 # or make project git URL from git base URL and project name
2129 my $url_tag = "URL";
2130 my @url_list = git_get_project_url_list
($project);
2131 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2132 foreach my $git_url (@url_list) {
2133 next unless $git_url;
2134 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2139 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash
($project)
2140 or die_error
(undef, "Open git-rev-list failed");
2141 my @revlist = map { chomp; $_ } <$fd>;
2143 git_print_header_div
('shortlog');
2144 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2145 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2147 my $taglist = git_get_refs_list
("refs/tags");
2148 if (defined @
$taglist) {
2149 git_print_header_div
('tags');
2150 git_tags_body
($taglist, 0, 15,
2151 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2154 my $headlist = git_get_refs_list
("refs/heads");
2155 if (defined @
$headlist) {
2156 git_print_header_div
('heads');
2157 git_heads_body
($headlist, $head, 0, 15,
2158 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2165 my $head = git_get_head_hash
($project);
2167 git_print_page_nav
('','', $head,undef,$head);
2168 my %tag = parse_tag
($hash);
2169 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2170 print "<div class=\"title_text\">\n" .
2171 "<table cellspacing=\"0\">\n" .
2173 "<td>object</td>\n" .
2174 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2175 $tag{'object'}) . "</td>\n" .
2176 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2177 $tag{'type'}) . "</td>\n" .
2179 if (defined($tag{'author'})) {
2180 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2181 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2182 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2183 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2186 print "</table>\n\n" .
2188 print "<div class=\"page_body\">";
2189 my $comment = $tag{'comment'};
2190 foreach my $line (@
$comment) {
2191 print esc_html
($line) . "<br/>\n";
2201 if (!gitweb_check_feature
('blame')) {
2202 die_error
('403 Permission denied', "Permission denied");
2204 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2205 $hash_base ||= git_get_head_hash
($project);
2206 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2207 my %co = parse_commit
($hash_base)
2208 or die_error
(undef, "Reading commit failed");
2209 if (!defined $hash) {
2210 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2211 or die_error
(undef, "Error looking up file");
2213 $ftype = git_get_type
($hash);
2214 if ($ftype !~ "blob") {
2215 die_error
("400 Bad Request", "Object is not a blob");
2217 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
2218 or die_error
(undef, "Open git-blame failed");
2221 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2224 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2226 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2227 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2228 git_print_page_path
($file_name, $ftype, $hash_base);
2229 my @rev_color = (qw(light2 dark2));
2230 my $num_colors = scalar(@rev_color);
2231 my $current_color = 0;
2234 <div class="page_body">
2235 <table class="blame">
2236 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2239 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2241 my $rev = substr($full_rev, 0, 8);
2245 if (!defined $last_rev) {
2246 $last_rev = $full_rev;
2247 } elsif ($last_rev ne $full_rev) {
2248 $last_rev = $full_rev;
2249 $current_color = ++$current_color % $num_colors;
2251 print "<tr class=\"$rev_color[$current_color]\">\n";
2252 print "<td class=\"sha1\">" .
2253 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)},
2254 esc_html
($rev)) . "</td>\n";
2255 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2256 esc_html
($lineno) . "</a></td>\n";
2257 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2263 or print "Reading blob failed\n";
2270 if (!gitweb_check_feature
('blame')) {
2271 die_error
('403 Permission denied', "Permission denied");
2273 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2274 $hash_base ||= git_get_head_hash
($project);
2275 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2276 my %co = parse_commit
($hash_base)
2277 or die_error
(undef, "Reading commit failed");
2278 if (!defined $hash) {
2279 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2280 or die_error
(undef, "Error lookup file");
2282 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2283 or die_error
(undef, "Open git-annotate failed");
2286 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2289 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2291 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2292 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2293 git_print_page_path
($file_name, 'blob', $hash_base);
2294 print "<div class=\"page_body\">\n";
2296 <table class="blame">
2305 my @line_class = (qw(light dark));
2306 my $line_class_len = scalar (@line_class);
2307 my $line_class_num = $#line_class;
2308 while (my $line = <$fd>) {
2320 $line_class_num = ($line_class_num + 1) % $line_class_len;
2322 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
2329 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2332 $short_rev = substr ($long_rev, 0, 8);
2333 $age = time () - $time;
2334 $age_str = age_string
($age);
2335 $age_str =~ s/ / /g;
2336 $age_class = age_class
($age);
2337 $author = esc_html
($author);
2338 $author =~ s/ / /g;
2340 $data = untabify
($data);
2341 $data = esc_html
($data);
2344 <tr class="$line_class[$line_class_num]">
2345 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2346 <td class="$age_class">$age_str</td>
2348 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2349 <td class="pre">$data</td>
2352 } # while (my $line = <$fd>)
2353 print "</table>\n\n";
2355 or print "Reading blob failed.\n";
2361 my $head = git_get_head_hash
($project);
2363 git_print_page_nav
('','', $head,undef,$head);
2364 git_print_header_div
('summary', $project);
2366 my $taglist = git_get_refs_list
("refs/tags");
2367 if (defined @
$taglist) {
2368 git_tags_body
($taglist);
2374 my $head = git_get_head_hash
($project);
2376 git_print_page_nav
('','', $head,undef,$head);
2377 git_print_header_div
('summary', $project);
2379 my $taglist = git_get_refs_list
("refs/heads");
2380 if (defined @
$taglist) {
2381 git_heads_body
($taglist, $head);
2386 sub git_blob_plain
{
2387 if (!defined $hash) {
2388 if (defined $file_name) {
2389 my $base = $hash_base || git_get_head_hash
($project);
2390 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2391 or die_error
(undef, "Error lookup file");
2393 die_error
(undef, "No file name defined");
2397 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2398 or die_error
(undef, "Couldn't cat $file_name, $hash");
2400 $type ||= blob_mimetype
($fd, $file_name);
2402 # save as filename, even when no $file_name is given
2403 my $save_as = "$hash";
2404 if (defined $file_name) {
2405 $save_as = $file_name;
2406 } elsif ($type =~ m/^text\//) {
2410 print $cgi->header(-type
=> "$type",
2411 -content_disposition
=> "inline; filename=\"$save_as\"");
2413 binmode STDOUT
, ':raw';
2415 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2421 if (!defined $hash) {
2422 if (defined $file_name) {
2423 my $base = $hash_base || git_get_head_hash
($project);
2424 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2425 or die_error
(undef, "Error lookup file");
2427 die_error
(undef, "No file name defined");
2430 my $have_blame = gitweb_check_feature
('blame');
2431 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2432 or die_error
(undef, "Couldn't cat $file_name, $hash");
2433 my $mimetype = blob_mimetype
($fd, $file_name);
2434 if ($mimetype !~ m/^text\//) {
2436 return git_blob_plain
($mimetype);
2439 my $formats_nav = '';
2440 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2441 if (defined $file_name) {
2444 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2445 hash
=>$hash, file_name
=>$file_name)},
2450 $cgi->a({-href
=> href
(action
=>"blob_plain",
2451 hash
=>$hash, file_name
=>$file_name)},
2454 $cgi->a({-href
=> href
(action
=>"blob",
2455 hash_base
=>"HEAD", file_name
=>$file_name)},
2459 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "plain");
2461 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2462 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2464 print "<div class=\"page_nav\">\n" .
2465 "<br/><br/></div>\n" .
2466 "<div class=\"title\">$hash</div>\n";
2468 git_print_page_path
($file_name, "blob", $hash_base);
2469 print "<div class=\"page_body\">\n";
2471 while (my $line = <$fd>) {
2474 $line = untabify
($line);
2475 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2476 $nr, $nr, $nr, esc_html
($line);
2479 or print "Reading blob failed.\n";
2485 if (!defined $hash) {
2486 $hash = git_get_head_hash
($project);
2487 if (defined $file_name) {
2488 my $base = $hash_base || $hash;
2489 $hash = git_get_hash_by_path
($base, $file_name, "tree");
2491 if (!defined $hash_base) {
2496 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
2497 or die_error
(undef, "Open git-ls-tree failed");
2498 my @entries = map { chomp; $_ } <$fd>;
2499 close $fd or die_error
(undef, "Reading tree failed");
2502 my $refs = git_get_references
();
2503 my $ref = format_ref_marker
($refs, $hash_base);
2507 my $have_blame = gitweb_check_feature
('blame');
2508 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2509 $base_key{hash_base
} = $hash_base;
2510 git_print_page_nav
('tree','', $hash_base);
2511 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2513 print "<div class=\"page_nav\">\n";
2514 print "<br/><br/></div>\n";
2515 print "<div class=\"title\">$hash</div>\n";
2517 if (defined $file_name) {
2518 $base = esc_html
("$file_name/");
2520 git_print_page_path
($file_name, 'tree', $hash_base);
2521 print "<div class=\"page_body\">\n";
2522 print "<table cellspacing=\"0\">\n";
2524 foreach my $line (@entries) {
2525 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2526 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2530 my $t_name = validate_input
($4);
2532 print "<tr class=\"dark\">\n";
2534 print "<tr class=\"light\">\n";
2537 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
2538 if ($t_type eq "blob") {
2539 print "<td class=\"list\">" .
2540 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key),
2541 -class => "list"}, esc_html
($t_name)) .
2543 "<td class=\"link\">" .
2544 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2548 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2552 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2553 hash
=>$t_hash, file_name
=>"$base$t_name")},
2556 $cgi->a({-href
=> href
(action
=>"blob_plain",
2557 hash
=>$t_hash, file_name
=>"$base$t_name")},
2560 } elsif ($t_type eq "tree") {
2561 print "<td class=\"list\">" .
2562 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2563 esc_html
($t_name)) .
2565 "<td class=\"link\">" .
2566 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2569 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base, file_name
=>"$base$t_name")},
2575 print "</table>\n" .
2582 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2583 my $have_snapshot = (defined $ctype && defined $suffix);
2584 if (!$have_snapshot) {
2585 die_error
('403 Permission denied', "Permission denied");
2588 if (!defined $hash) {
2589 $hash = git_get_head_hash
($project);
2592 my $filename = basename
($project) . "-$hash.tar.$suffix";
2594 print $cgi->header(-type
=> 'application/x-tar',
2595 -content_encoding
=> $ctype,
2596 -content_disposition
=> "inline; filename=\"$filename\"",
2597 -status
=> '200 OK');
2599 open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | $command" or
2600 die_error
(undef, "Execute git-tar-tree failed.");
2601 binmode STDOUT
, ':raw';
2603 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2609 my $head = git_get_head_hash
($project);
2610 if (!defined $hash) {
2613 if (!defined $page) {
2616 my $refs = git_get_references
();
2618 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2619 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2620 or die_error
(undef, "Open git-rev-list failed");
2621 my @revlist = map { chomp; $_ } <$fd>;
2624 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2627 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2630 my %co = parse_commit
($hash);
2632 git_print_header_div
('summary', $project);
2633 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2635 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2636 my $commit = $revlist[$i];
2637 my $ref = format_ref_marker
($refs, $commit);
2638 my %co = parse_commit
($commit);
2640 my %ad = parse_date
($co{'author_epoch'});
2641 git_print_header_div
('commit',
2642 "<span class=\"age\">$co{'age_string'}</span>" .
2643 esc_html
($co{'title'}) . $ref,
2645 print "<div class=\"title_text\">\n" .
2646 "<div class=\"log_link\">\n" .
2647 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2649 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2652 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2655 print "<div class=\"log_body\">\n";
2656 git_print_simplified_log
($co{'comment'});
2663 my %co = parse_commit
($hash);
2665 die_error
(undef, "Unknown commit object");
2667 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2668 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2670 my $parent = $co{'parent'};
2671 if (!defined $parent) {
2674 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
2675 or die_error
(undef, "Open git-diff-tree failed");
2676 my @difftree = map { chomp; $_ } <$fd>;
2677 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2679 # non-textual hash id's can be cached
2681 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2684 my $refs = git_get_references
();
2685 my $ref = format_ref_marker
($refs, $co{'id'});
2687 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2688 my $have_snapshot = (defined $ctype && defined $suffix);
2690 my $formats_nav = '';
2691 if (defined $file_name && defined $co{'parent'}) {
2692 my $parent = $co{'parent'};
2694 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
2697 git_header_html
(undef, $expires);
2698 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
2699 $hash, $co{'tree'}, $hash,
2702 if (defined $co{'parent'}) {
2703 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2705 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
2707 print "<div class=\"title_text\">\n" .
2708 "<table cellspacing=\"0\">\n";
2709 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2711 "<td></td><td> $ad{'rfc2822'}";
2712 if ($ad{'hour_local'} < 6) {
2713 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2714 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2716 printf(" (%02d:%02d %s)",
2717 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2721 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2722 print "<tr><td></td><td> $cd{'rfc2822'}" .
2723 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2725 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2728 "<td class=\"sha1\">" .
2729 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
2730 class => "list"}, $co{'tree'}) .
2732 "<td class=\"link\">" .
2733 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
2735 if ($have_snapshot) {
2737 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
2741 my $parents = $co{'parents'};
2742 foreach my $par (@
$parents) {
2745 "<td class=\"sha1\">" .
2746 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
2747 class => "list"}, $par) .
2749 "<td class=\"link\">" .
2750 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
2752 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "commitdiff") .
2759 print "<div class=\"page_body\">\n";
2760 git_print_log
($co{'comment'});
2763 git_difftree_body
(\
@difftree, $hash, $parent);
2769 mkdir($git_temp, 0700);
2771 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2773 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
2774 hash
=>$hash, hash_parent
=>$hash_parent,
2775 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
2776 file_name
=>$file_name, file_parent
=>$file_parent)},
2778 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2779 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2782 <div class="page_nav"><br/><br/></div>
2783 <div class="title">$hash vs $hash_parent</div>
2786 git_print_page_path
($file_name, "blob", $hash_base);
2787 print "<div class=\"page_body\">\n" .
2788 "<div class=\"diff_info\">blob:" .
2789 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash_parent,
2790 hash_base
=>$hash_parent_base, file_name
=>($file_parent || $file_name))},
2793 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash,
2794 hash_base
=>$hash_base, file_name
=>$file_name)},
2797 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2798 print "</div>"; # page_body
2802 sub git_blobdiff_plain
{
2803 mkdir($git_temp, 0700);
2804 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2805 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2808 sub git_commitdiff
{
2809 my $format = shift || 'html';
2810 my %co = parse_commit
($hash);
2812 die_error
(undef, "Unknown commit object");
2814 if (!defined $hash_parent) {
2815 $hash_parent = $co{'parent'} || '--root';
2821 if ($format eq 'html') {
2822 open $fd, "-|", $GIT, "diff-tree", '-r', '-M', '-C',
2823 "--patch-with-raw", "--full-index", $hash_parent, $hash
2824 or die_error
(undef, "Open git-diff-tree failed");
2826 while (chomp(my $line = <$fd>)) {
2827 # empty line ends raw part of diff-tree output
2829 push @difftree, $line;
2832 } elsif ($format eq 'plain') {
2833 open $fd, "-|", $GIT, "diff-tree", '-r', '-p', '-B', $hash_parent, $hash
2834 or die_error
(undef, "Open git-diff-tree failed");
2837 die_error
(undef, "Unknown commitdiff format");
2840 # non-textual hash id's can be cached
2842 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2846 # write commit message
2847 if ($format eq 'html') {
2848 my $refs = git_get_references
();
2849 my $ref = format_ref_marker
($refs, $co{'id'});
2851 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
2852 hash
=>$hash, hash_parent
=>$hash_parent)},
2855 git_header_html
(undef, $expires);
2856 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2857 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2858 print "<div class=\"page_body\">\n";
2859 print "<div class=\"log\">\n";
2860 git_print_simplified_log
($co{'comment'}, 1); # skip title
2861 print "</div>\n"; # class="log"
2863 } elsif ($format eq 'plain') {
2864 my $refs = git_get_references
("tags");
2865 my $tagname = git_get_rev_name_tags
($hash);
2866 my $filename = basename
($project) . "-$hash.patch";
2869 -type
=> 'text/plain',
2870 -charset
=> 'utf-8',
2871 -expires
=> $expires,
2872 -content_disposition
=> qq(inline
; filename
="$filename"));
2873 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2876 Date: $ad{'rfc2822'} ($ad{'tz_local'})
2877 Subject: $co{'title'}
2879 print "X-Git-Tag: $tagname\n" if $tagname;
2880 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
2882 foreach my $line (@
{$co{'comment'}}) {
2889 if ($format eq 'html') {
2890 #git_difftree_body(\@difftree, $hash, $hash_parent);
2893 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
2895 print "</div>\n"; # class="page_body"
2898 } elsif ($format eq 'plain') {
2902 or print "Reading git-diff-tree failed\n";
2906 sub git_commitdiff_plain
{
2907 git_commitdiff
('plain');
2911 if (!defined $hash_base) {
2912 $hash_base = git_get_head_hash
($project);
2915 my %co = parse_commit
($hash_base);
2917 die_error
(undef, "Unknown commit object");
2919 my $refs = git_get_references
();
2921 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2922 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2923 if (!defined $hash && defined $file_name) {
2924 $hash = git_get_hash_by_path
($hash_base, $file_name);
2926 if (defined $hash) {
2927 $ftype = git_get_type
($hash);
2929 git_print_page_path
($file_name, $ftype, $hash_base);
2932 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2933 git_history_body
($fd, $refs, $hash_base, $ftype);
2940 if (!defined $searchtext) {
2941 die_error
(undef, "Text field empty");
2943 if (!defined $hash) {
2944 $hash = git_get_head_hash
($project);
2946 my %co = parse_commit
($hash);
2948 die_error
(undef, "Unknown commit object");
2950 # pickaxe may take all resources of your box and run for several minutes
2951 # with every query - so decide by yourself how public you make this feature :)
2952 my $commit_search = 1;
2953 my $author_search = 0;
2954 my $committer_search = 0;
2955 my $pickaxe_search = 0;
2956 if ($searchtext =~ s/^author\\://i) {
2958 } elsif ($searchtext =~ s/^committer\\://i) {
2959 $committer_search = 1;
2960 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2962 $pickaxe_search = 1;
2965 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
2966 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
2968 print "<table cellspacing=\"0\">\n";
2970 if ($commit_search) {
2972 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2973 while (my $commit_text = <$fd>) {
2974 if (!grep m/$searchtext/i, $commit_text) {
2977 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2980 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2983 my @commit_lines = split "\n", $commit_text;
2984 my %co = parse_commit
(undef, \
@commit_lines);
2989 print "<tr class=\"dark\">\n";
2991 print "<tr class=\"light\">\n";
2994 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2995 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2997 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
2998 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
2999 my $comment = $co{'comment'};
3000 foreach my $line (@
$comment) {
3001 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3002 my $lead = esc_html
($1) || "";
3003 $lead = chop_str
($lead, 30, 10);
3004 my $match = esc_html
($2) || "";
3005 my $trail = esc_html
($3) || "";
3006 $trail = chop_str
($trail, 30, 10);
3007 my $text = "$lead<span class=\"match\">$match</span>$trail";
3008 print chop_str
($text, 80, 5) . "<br/>\n";
3012 "<td class=\"link\">" .
3013 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3015 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3022 if ($pickaxe_search) {
3024 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
3027 while (my $line = <$fd>) {
3028 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3031 $set{'from_id'} = $3;
3033 $set{'id'} = $set{'to_id'};
3034 if ($set{'id'} =~ m/0{40}/) {
3035 $set{'id'} = $set{'from_id'};
3037 if ($set{'id'} =~ m/0{40}/) {
3041 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3044 print "<tr class=\"dark\">\n";
3046 print "<tr class=\"light\">\n";
3049 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3050 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3052 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3053 -class => "list subject"},
3054 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3055 while (my $setref = shift @files) {
3057 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3058 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3060 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3064 "<td class=\"link\">" .
3065 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3067 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3071 %co = parse_commit
($1);
3081 my $head = git_get_head_hash
($project);
3082 if (!defined $hash) {
3085 if (!defined $page) {
3088 my $refs = git_get_references
();
3090 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3091 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
3092 or die_error
(undef, "Open git-rev-list failed");
3093 my @revlist = map { chomp; $_ } <$fd>;
3096 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3098 if ($#revlist >= (100 * ($page+1)-1)) {
3100 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3101 -title
=> "Alt-n"}, "next");
3106 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3107 git_print_header_div
('summary', $project);
3109 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3114 ## ......................................................................
3115 ## feeds (RSS, OPML)
3118 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3119 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash
($project)
3120 or die_error
(undef, "Open git-rev-list failed");
3121 my @revlist = map { chomp; $_ } <$fd>;
3122 close $fd or die_error
(undef, "Reading git-rev-list failed");
3123 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3125 <?xml version="1.0" encoding="utf-8"?>
3126 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3128 <title>$project $my_uri $my_url</title>
3129 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3130 <description>$project log</description>
3131 <language>en</language>
3134 for (my $i = 0; $i <= $#revlist; $i++) {
3135 my $commit = $revlist[$i];
3136 my %co = parse_commit
($commit);
3137 # we read 150, we always show 30 and the ones more recent than 48 hours
3138 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3141 my %cd = parse_date
($co{'committer_epoch'});
3142 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
3143 my @difftree = map { chomp; $_ } <$fd>;
3147 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3149 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3150 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3151 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3152 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3153 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3154 "<content:encoded>" .
3156 my $comment = $co{'comment'};
3157 foreach my $line (@
$comment) {
3158 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
3159 print "$line<br/>\n";
3162 foreach my $line (@difftree) {
3163 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3166 my $file = validate_input
(unquote
($7));
3167 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
3168 print "$file<br/>\n";
3171 "</content:encoded>\n" .
3174 print "</channel></rss>";
3178 my @list = git_get_projects_list
();
3180 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3182 <?xml version="1.0" encoding="utf-8"?>
3183 <opml version="1.0">
3185 <title>$site_name Git OPML Export</title>
3188 <outline text="git RSS feeds">
3191 foreach my $pr (@list) {
3193 my $head = git_get_head_hash
($proj{'path'});
3194 if (!defined $head) {
3197 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
3198 my %co = parse_commit
($head);
3203 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3204 my $rss = "$my_url?p=$proj{'path'};a=rss";
3205 my $html = "$my_url?p=$proj{'path'};a=summary";
3206 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";