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 sub parse_difftree_raw_line
{
925 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
926 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
927 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
928 $res{'from_mode'} = $1;
929 $res{'to_mode'} = $2;
930 $res{'from_id'} = $3;
933 $res{'similarity'} = $6;
934 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
935 ($res{'from_file'}, $res{'to_file'}) = map(unquote
, split("\t", $7));
937 $res{'file'} = unquote
($7);
940 # 'c512b523472485aef4fff9e57b229d9d243c967f'
941 #elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
942 # $res{'commit'} = $1;
945 return wantarray ?
%res : \
%res;
948 ## ......................................................................
949 ## parse to array of hashes functions
951 sub git_get_refs_list
{
956 my $pfxlen = length("$projectroot/$project/$ref_dir");
957 File
::Find
::find
(sub {
960 push @refs, substr($File::Find
::name
, $pfxlen + 1);
962 }, "$projectroot/$project/$ref_dir");
964 foreach my $ref_file (@refs) {
965 my $ref_id = git_get_hash_by_ref
("$project/$ref_dir/$ref_file");
966 my $type = git_get_type
($ref_id) || next;
967 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
969 push @reflist, \
%ref_item;
972 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
976 ## ----------------------------------------------------------------------
977 ## filesystem-related functions
982 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
983 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
984 if (!defined $gcos) {
988 $owner =~ s/[,;].*$//;
989 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
992 ## ......................................................................
993 ## mimetype related functions
995 sub mimetype_guess_file
{
996 my $filename = shift;
998 -r
$mimemap or return undef;
1001 open(MIME
, $mimemap) or return undef;
1003 next if m/^#/; # skip comments
1004 my ($mime, $exts) = split(/\t+/);
1005 if (defined $exts) {
1006 my @exts = split(/\s+/, $exts);
1007 foreach my $ext (@exts) {
1008 $mimemap{$ext} = $mime;
1014 $filename =~ /\.(.*?)$/;
1015 return $mimemap{$1};
1018 sub mimetype_guess
{
1019 my $filename = shift;
1021 $filename =~ /\./ or return undef;
1023 if ($mimetypes_file) {
1024 my $file = $mimetypes_file;
1025 if ($file !~ m!^/!) { # if it is relative path
1026 # it is relative to project
1027 $file = "$projectroot/$project/$file";
1029 $mime = mimetype_guess_file
($filename, $file);
1031 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1037 my $filename = shift;
1040 my $mime = mimetype_guess
($filename);
1041 $mime and return $mime;
1045 return $default_blob_plain_mimetype unless $fd;
1048 return 'text/plain' .
1049 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1050 } elsif (! $filename) {
1051 return 'application/octet-stream';
1052 } elsif ($filename =~ m/\.png$/i) {
1054 } elsif ($filename =~ m/\.gif$/i) {
1056 } elsif ($filename =~ m/\.jpe?g$/i) {
1057 return 'image/jpeg';
1059 return 'application/octet-stream';
1063 ## ======================================================================
1064 ## functions printing HTML: header, footer, error page
1066 sub git_header_html
{
1067 my $status = shift || "200 OK";
1068 my $expires = shift;
1070 my $title = "$site_name git";
1071 if (defined $project) {
1072 $title .= " - $project";
1073 if (defined $action) {
1074 $title .= "/$action";
1075 if (defined $file_name) {
1076 $title .= " - $file_name";
1077 if ($action eq "tree" && $file_name !~ m
|/$|) {
1084 # require explicit support from the UA if we are to send the page as
1085 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1086 # we have to do this because MSIE sometimes globs '*/*', pretending to
1087 # support xhtml+xml but choking when it gets what it asked for.
1088 if (defined $cgi->http('HTTP_ACCEPT') && $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ && $cgi->Accept('application/xhtml
+xml
') != 0) {
1089 $content_type = 'application
/xhtml
+xml
';
1091 $content_type = 'text
/html
';
1093 print $cgi->header(-type=>$content_type, -charset => 'utf
-8', -status=> $status, -expires => $expires);
1095 <?xml version="1.0" encoding="utf-8"?>
1096 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1097 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1098 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1099 <!-- git core binaries version $git_version -->
1101 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1102 <meta name="generator" content="gitweb/$version git/$git_version"/>
1103 <meta name="robots" content="index, nofollow"/>
1104 <title>$title</title>
1105 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1107 if (defined $project) {
1108 printf('<link rel="alternate" title="%s log" '.
1109 'href="%s" type="application/rss+xml"/>'."\n",
1110 esc_param
($project), href
(action
=>"rss"));
1115 "<div class=\"page_header\">\n" .
1116 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1117 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1119 print $cgi->a({-href
=> esc_param
($home_link)}, $home_link_str) . " / ";
1120 if (defined $project) {
1121 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1122 if (defined $action) {
1126 if (!defined $searchtext) {
1130 if (defined $hash_base) {
1131 $search_hash = $hash_base;
1132 } elsif (defined $hash) {
1133 $search_hash = $hash;
1135 $search_hash = "HEAD";
1137 $cgi->param("a", "search");
1138 $cgi->param("h", $search_hash);
1139 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1140 "<div class=\"search\">\n" .
1141 $cgi->hidden(-name
=> "p") . "\n" .
1142 $cgi->hidden(-name
=> "a") . "\n" .
1143 $cgi->hidden(-name
=> "h") . "\n" .
1144 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1146 $cgi->end_form() . "\n";
1151 sub git_footer_html
{
1152 print "<div class=\"page_footer\">\n";
1153 if (defined $project) {
1154 my $descr = git_get_project_description
($project);
1155 if (defined $descr) {
1156 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1158 print $cgi->a({-href
=> href
(action
=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1160 print $cgi->a({-href
=> href
(action
=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1168 my $status = shift || "403 Forbidden";
1169 my $error = shift || "Malformed query, file missing or permission denied";
1171 git_header_html
($status);
1172 print "<div class=\"page_body\">\n" .
1174 "$status - $error\n" .
1181 ## ----------------------------------------------------------------------
1182 ## functions printing or outputting HTML: navigation
1184 sub git_print_page_nav
{
1185 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1186 $extra = '' if !defined $extra; # pager or formats
1188 my @navs = qw(summary shortlog log commit commitdiff tree);
1190 @navs = grep { $_ ne $suppress } @navs;
1193 my %arg = map { $_ => {action
=>$_} } @navs;
1194 if (defined $head) {
1195 for (qw(commit commitdiff)) {
1196 $arg{$_}{hash
} = $head;
1198 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1199 for (qw(shortlog log)) {
1200 $arg{$_}{hash
} = $head;
1204 $arg{tree
}{hash
} = $treehead if defined $treehead;
1205 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1207 print "<div class=\"page_nav\">\n" .
1209 map { $_ eq $current ?
1210 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1212 print "<br/>\n$extra<br/>\n" .
1216 sub format_paging_nav
{
1217 my ($action, $hash, $head, $page, $nrevs) = @_;
1221 if ($hash ne $head || $page) {
1222 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1224 $paging_nav .= "HEAD";
1228 $paging_nav .= " ⋅ " .
1229 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1230 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1232 $paging_nav .= " ⋅ prev";
1235 if ($nrevs >= (100 * ($page+1)-1)) {
1236 $paging_nav .= " ⋅ " .
1237 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1238 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1240 $paging_nav .= " ⋅ next";
1246 ## ......................................................................
1247 ## functions printing or outputting HTML: div
1249 sub git_print_header_div
{
1250 my ($action, $title, $hash, $hash_base) = @_;
1253 $args{action
} = $action;
1254 $args{hash
} = $hash if $hash;
1255 $args{hash_base
} = $hash_base if $hash_base;
1257 print "<div class=\"header\">\n" .
1258 $cgi->a({-href
=> href
(%args), -class => "title"},
1259 $title ?
$title : $action) .
1263 sub git_print_page_path
{
1268 if (!defined $name) {
1269 print "<div class=\"page_path\"><b>/</b></div>\n";
1270 } elsif (defined $type && $type eq 'blob') {
1271 print "<div class=\"page_path\"><b>";
1273 print $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hb, file_name
=>$file_name)}, esc_html
($name));
1275 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name)}, esc_html
($name));
1277 print "</b><br/></div>\n";
1279 print "<div class=\"page_path\"><b>" . esc_html
($name) . "</b><br/></div>\n";
1286 # remove leading empty lines
1287 while (defined $log->[0] && $log->[0] eq "") {
1294 foreach my $line (@
$log) {
1295 # print only one empty line
1296 # do not print empty line after signoff
1298 next if ($empty || $signoff);
1303 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1305 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1308 print format_log_line_html
($line) . "<br/>\n";
1313 sub git_print_simplified_log
{
1315 my $remove_title = shift;
1317 shift @
$log if $remove_title;
1318 # remove leading empty lines
1319 while (defined $log->[0] && $log->[0] eq "") {
1323 # simplify and print log
1325 foreach my $line (@
$log) {
1326 # remove signoff lines
1327 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1330 # print only one empty line
1337 print format_log_line_html
($line) . "<br/>\n";
1339 # end with single empty line
1340 print "<br/>\n" unless $empty;
1343 ## ......................................................................
1344 ## functions printing large fragments of HTML
1346 sub git_difftree_body
{
1347 my ($difftree, $parent) = @_;
1349 print "<div class=\"list_head\">\n";
1350 if ($#{$difftree} > 10) {
1351 print(($#{$difftree} + 1) . " files changed:\n");
1355 print "<table class=\"diff_tree\">\n";
1357 foreach my $line (@
{$difftree}) {
1358 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1359 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1360 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1368 my $similarity = $6; # score
1369 my $file = validate_input
(unquote
($7));
1372 print "<tr class=\"dark\">\n";
1374 print "<tr class=\"light\">\n";
1378 if ($status eq "A") { # created
1380 if (S_ISREG
(oct $to_mode)) {
1381 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1384 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file),
1385 -class => "list"}, esc_html
($file)) .
1387 "<td><span class=\"file_status new\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
1388 "<td class=\"link\">" .
1389 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file)}, "blob") .
1392 } elsif ($status eq "D") { # deleted
1394 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$file),
1395 -class => "list"}, esc_html
($file)) . "</td>\n" .
1396 "<td><span class=\"file_status deleted\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
1397 "<td class=\"link\">" .
1398 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$file)}, "blob") . " | " .
1399 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent, file_name
=>$file)}, "history") .
1402 } elsif ($status eq "M" || $status eq "T") { # modified, or type changed
1403 my $mode_chnge = "";
1404 if ($from_mode != $to_mode) {
1405 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
1406 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
1407 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
1409 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1410 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
1411 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1412 } elsif (S_ISREG
($to_mode)) {
1413 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1416 $mode_chnge .= "]</span>\n";
1419 if ($to_id ne $from_id) { # modified
1420 print $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$to_id, hash_parent
=>$from_id, hash_base
=>$hash, file_name
=>$file),
1421 -class => "list"}, esc_html
($file));
1422 } else { # mode changed
1423 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file),
1424 -class => "list"}, esc_html
($file));
1427 "<td>$mode_chnge</td>\n" .
1428 "<td class=\"link\">" .
1429 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file)}, "blob");
1430 if ($to_id ne $from_id) { # modified
1431 print " | " . $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$to_id, hash_parent
=>$from_id, hash_base
=>$hash, file_name
=>$file)}, "diff");
1433 print " | " . $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash, file_name
=>$file)}, "history") . "\n";
1436 } elsif ($status eq "R") { # renamed
1437 my ($from_file, $to_file) = split "\t", $file;
1439 if ($from_mode != $to_mode) {
1440 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1443 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file),
1444 -class => "list"}, esc_html
($to_file)) . "</td>\n" .
1445 "<td><span class=\"file_status moved\">[moved from " .
1446 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$from_file),
1447 -class => "list"}, esc_html
($from_file)) .
1448 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1449 "<td class=\"link\">" .
1450 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file)}, "blob");
1451 if ($to_id ne $from_id) {
1453 $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");
1457 } elsif ($status eq "C") { # copied
1458 my ($from_file, $to_file) = split "\t", $file;
1460 if ($from_mode != $to_mode) {
1461 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1464 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file),
1465 -class => "list"}, esc_html
($to_file)) . "</td>\n" .
1466 "<td><span class=\"file_status copied\">[copied from " .
1467 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$from_file),
1468 -class => "list"}, esc_html
($from_file)) .
1469 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1470 "<td class=\"link\">" .
1471 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file)}, "blob");
1472 if ($to_id ne $from_id) {
1474 $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");
1477 } # we should not encounter Unmerged (U) or Unknown (X) status
1483 sub git_shortlog_body
{
1484 # uses global variable $project
1485 my ($revlist, $from, $to, $refs, $extra) = @_;
1487 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
1488 my $have_snapshot = (defined $ctype && defined $suffix);
1490 $from = 0 unless defined $from;
1491 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1493 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1495 for (my $i = $from; $i <= $to; $i++) {
1496 my $commit = $revlist->[$i];
1497 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1498 my $ref = format_ref_marker
($refs, $commit);
1499 my %co = parse_commit
($commit);
1501 print "<tr class=\"dark\">\n";
1503 print "<tr class=\"light\">\n";
1506 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1507 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1508 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1510 print format_subject_html
($co{'title'}, $co{'title_short'}, href
(action
=>"commit", hash
=>$commit), $ref);
1512 "<td class=\"link\">" .
1513 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1514 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
1515 if ($have_snapshot) {
1516 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
1521 if (defined $extra) {
1523 "<td colspan=\"4\">$extra</td>\n" .
1529 sub git_history_body
{
1530 # Warning: assumes constant type (blob or tree) during history
1531 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1533 print "<table class=\"history\" cellspacing=\"0\">\n";
1535 while (my $line = <$fd>) {
1536 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1541 my %co = parse_commit
($commit);
1546 my $ref = format_ref_marker
($refs, $commit);
1549 print "<tr class=\"dark\">\n";
1551 print "<tr class=\"light\">\n";
1554 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1555 # shortlog uses chop_str($co{'author_name'}, 10)
1556 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1558 # originally git_history used chop_str($co{'title'}, 50)
1559 print format_subject_html
($co{'title'}, $co{'title_short'}, href
(action
=>"commit", hash
=>$commit), $ref);
1561 "<td class=\"link\">" .
1562 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1563 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
1564 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype);
1566 if ($ftype eq 'blob') {
1567 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
1568 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
1569 if (defined $blob_current && defined $blob_parent &&
1570 $blob_current ne $blob_parent) {
1572 $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$blob_current, hash_parent
=>$blob_parent, hash_base
=>$commit, file_name
=>$file_name)},
1579 if (defined $extra) {
1581 "<td colspan=\"4\">$extra</td>\n" .
1588 # uses global variable $project
1589 my ($taglist, $from, $to, $extra) = @_;
1590 $from = 0 unless defined $from;
1591 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1593 print "<table class=\"tags\" cellspacing=\"0\">\n";
1595 for (my $i = $from; $i <= $to; $i++) {
1596 my $entry = $taglist->[$i];
1598 my $comment_lines = $tag{'comment'};
1599 my $comment = shift @
$comment_lines;
1601 if (defined $comment) {
1602 $comment_short = chop_str
($comment, 30, 5);
1605 print "<tr class=\"dark\">\n";
1607 print "<tr class=\"light\">\n";
1610 print "<td><i>$tag{'age'}</i></td>\n" .
1612 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
1613 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1616 if (defined $comment) {
1617 print format_subject_html
($comment, $comment_short, href
(action
=>"tag", hash
=>$tag{'id'}));
1620 "<td class=\"selflink\">";
1621 if ($tag{'type'} eq "tag") {
1622 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
1627 "<td class=\"link\">" . " | " .
1628 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
1629 if ($tag{'reftype'} eq "commit") {
1630 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
1631 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
1632 } elsif ($tag{'reftype'} eq "blob") {
1633 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
1638 if (defined $extra) {
1640 "<td colspan=\"5\">$extra</td>\n" .
1646 sub git_heads_body
{
1647 # uses global variable $project
1648 my ($taglist, $head, $from, $to, $extra) = @_;
1649 $from = 0 unless defined $from;
1650 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1652 print "<table class=\"heads\" cellspacing=\"0\">\n";
1654 for (my $i = $from; $i <= $to; $i++) {
1655 my $entry = $taglist->[$i];
1657 my $curr = $tag{'id'} eq $head;
1659 print "<tr class=\"dark\">\n";
1661 print "<tr class=\"light\">\n";
1664 print "<td><i>$tag{'age'}</i></td>\n" .
1665 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1666 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
1667 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1669 "<td class=\"link\">" .
1670 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
1671 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") .
1675 if (defined $extra) {
1677 "<td colspan=\"3\">$extra</td>\n" .
1683 ## ----------------------------------------------------------------------
1684 ## functions printing large fragments, format as one of arguments
1686 sub git_diff_print
{
1688 my $from_name = shift;
1690 my $to_name = shift;
1691 my $format = shift || "html";
1693 my $from_tmp = "/dev/null";
1694 my $to_tmp = "/dev/null";
1697 # create tmp from-file
1698 if (defined $from) {
1699 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1700 open my $fd2, "> $from_tmp";
1701 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1708 # create tmp to-file
1710 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1711 open my $fd2, "> $to_tmp";
1712 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1719 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1720 if ($format eq "plain") {
1725 while (my $line = <$fd>) {
1727 my $char = substr($line, 0, 1);
1728 my $diff_class = "";
1730 $diff_class = " add";
1731 } elsif ($char eq "-") {
1732 $diff_class = " rem";
1733 } elsif ($char eq "@") {
1734 $diff_class = " chunk_header";
1735 } elsif ($char eq "\\") {
1739 $line = untabify
($line);
1740 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
1745 if (defined $from) {
1754 ## ======================================================================
1755 ## ======================================================================
1758 sub git_project_list
{
1759 my $order = $cgi->param('o');
1760 if (defined $order && $order !~ m/project|descr|owner|age/) {
1761 die_error
(undef, "Unknown order parameter");
1764 my @list = git_get_projects_list
();
1767 die_error
(undef, "No projects found");
1769 foreach my $pr (@list) {
1770 my $head = git_get_head_hash
($pr->{'path'});
1771 if (!defined $head) {
1774 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1775 my %co = parse_commit
($head);
1779 $pr->{'commit'} = \
%co;
1780 if (!defined $pr->{'descr'}) {
1781 my $descr = git_get_project_description
($pr->{'path'}) || "";
1782 $pr->{'descr'} = chop_str
($descr, 25, 5);
1784 if (!defined $pr->{'owner'}) {
1785 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
1787 push @projects, $pr;
1791 if (-f
$home_text) {
1792 print "<div class=\"index_include\">\n";
1793 open (my $fd, $home_text);
1798 print "<table class=\"project_list\">\n" .
1800 $order ||= "project";
1801 if ($order eq "project") {
1802 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1803 print "<th>Project</th>\n";
1806 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
1807 -class => "header"}, "Project") .
1810 if ($order eq "descr") {
1811 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1812 print "<th>Description</th>\n";
1815 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
1816 -class => "header"}, "Description") .
1819 if ($order eq "owner") {
1820 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1821 print "<th>Owner</th>\n";
1824 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
1825 -class => "header"}, "Owner") .
1828 if ($order eq "age") {
1829 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1830 print "<th>Last Change</th>\n";
1833 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
1834 -class => "header"}, "Last Change") .
1837 print "<th></th>\n" .
1840 foreach my $pr (@projects) {
1842 print "<tr class=\"dark\">\n";
1844 print "<tr class=\"light\">\n";
1847 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
1848 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
1849 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
1850 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
1851 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
1852 $pr->{'commit'}{'age_string'} . "</td>\n" .
1853 "<td class=\"link\">" .
1854 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
1855 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
1856 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") .
1865 my $descr = git_get_project_description
($project) || "none";
1866 my $head = git_get_head_hash
($project);
1867 my %co = parse_commit
($head);
1868 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
1870 my $owner = git_get_project_owner
($project);
1872 my $refs = git_get_references
();
1874 git_print_page_nav
('summary','', $head);
1876 print "<div class=\"title\"> </div>\n";
1877 print "<table cellspacing=\"0\">\n" .
1878 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1879 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1880 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
1881 # use per project git URL list in $projectroot/$project/cloneurl
1882 # or make project git URL from git base URL and project name
1883 my $url_tag = "URL";
1884 my @url_list = git_get_project_url_list
($project);
1885 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
1886 foreach my $git_url (@url_list) {
1887 next unless $git_url;
1888 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
1893 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash
($project)
1894 or die_error
(undef, "Open git-rev-list failed");
1895 my @revlist = map { chomp; $_ } <$fd>;
1897 git_print_header_div
('shortlog');
1898 git_shortlog_body
(\
@revlist, 0, 15, $refs,
1899 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
1901 my $taglist = git_get_refs_list
("refs/tags");
1902 if (defined @
$taglist) {
1903 git_print_header_div
('tags');
1904 git_tags_body
($taglist, 0, 15,
1905 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
1908 my $headlist = git_get_refs_list
("refs/heads");
1909 if (defined @
$headlist) {
1910 git_print_header_div
('heads');
1911 git_heads_body
($headlist, $head, 0, 15,
1912 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
1919 my $head = git_get_head_hash
($project);
1921 git_print_page_nav
('','', $head,undef,$head);
1922 my %tag = parse_tag
($hash);
1923 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
1924 print "<div class=\"title_text\">\n" .
1925 "<table cellspacing=\"0\">\n" .
1927 "<td>object</td>\n" .
1928 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})}, $tag{'object'}) . "</td>\n" .
1929 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})}, $tag{'type'}) . "</td>\n" .
1931 if (defined($tag{'author'})) {
1932 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
1933 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1934 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1936 print "</table>\n\n" .
1938 print "<div class=\"page_body\">";
1939 my $comment = $tag{'comment'};
1940 foreach my $line (@
$comment) {
1941 print esc_html
($line) . "<br/>\n";
1951 if (!gitweb_check_feature
('blame')) {
1952 die_error
('403 Permission denied', "Permission denied");
1954 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1955 $hash_base ||= git_get_head_hash
($project);
1956 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
1957 my %co = parse_commit
($hash_base)
1958 or die_error
(undef, "Reading commit failed");
1959 if (!defined $hash) {
1960 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1961 or die_error
(undef, "Error looking up file");
1963 $ftype = git_get_type
($hash);
1964 if ($ftype !~ "blob") {
1965 die_error
("400 Bad Request", "Object is not a blob");
1967 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
1968 or die_error
(undef, "Open git-blame failed");
1971 $cgi->a({-href
=> href
(action
=>"blobl", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, "blob") .
1972 " | " . $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)}, "head");
1973 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1974 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1975 git_print_page_path
($file_name, $ftype, $hash_base);
1976 my @rev_color = (qw(light2 dark2));
1977 my $num_colors = scalar(@rev_color);
1978 my $current_color = 0;
1980 print "<div class=\"page_body\">\n";
1981 print "<table class=\"blame\">\n";
1982 print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
1984 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
1986 my $rev = substr($full_rev, 0, 8);
1990 if (!defined $last_rev) {
1991 $last_rev = $full_rev;
1992 } elsif ($last_rev ne $full_rev) {
1993 $last_rev = $full_rev;
1994 $current_color = ++$current_color % $num_colors;
1996 print "<tr class=\"$rev_color[$current_color]\">\n";
1997 print "<td class=\"sha1\">" .
1998 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)}, esc_html
($rev)) . "</td>\n";
1999 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html
($lineno) . "</a></td>\n";
2000 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2005 close $fd or print "Reading blob failed\n";
2012 if (!gitweb_check_feature
('blame')) {
2013 die_error
('403 Permission denied', "Permission denied");
2015 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2016 $hash_base ||= git_get_head_hash
($project);
2017 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2018 my %co = parse_commit
($hash_base)
2019 or die_error
(undef, "Reading commit failed");
2020 if (!defined $hash) {
2021 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2022 or die_error
(undef, "Error lookup file");
2024 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2025 or die_error
(undef, "Open git-annotate failed");
2028 $cgi->a({-href
=> href
(action
=>"blobl", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, "blob") .
2029 " | " . $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)}, "head");
2030 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2031 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2032 git_print_page_path
($file_name, 'blob', $hash_base);
2033 print "<div class=\"page_body\">\n";
2035 <table class="blame">
2044 my @line_class = (qw(light dark));
2045 my $line_class_len = scalar (@line_class);
2046 my $line_class_num = $#line_class;
2047 while (my $line = <$fd>) {
2059 $line_class_num = ($line_class_num + 1) % $line_class_len;
2061 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
2068 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2071 $short_rev = substr ($long_rev, 0, 8);
2072 $age = time () - $time;
2073 $age_str = age_string
($age);
2074 $age_str =~ s/ / /g;
2075 $age_class = age_class
($age);
2076 $author = esc_html
($author);
2077 $author =~ s/ / /g;
2079 $data = untabify
($data);
2080 $data = esc_html
($data);
2083 <tr class="$line_class[$line_class_num]">
2084 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2085 <td class="$age_class">$age_str</td>
2087 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2088 <td class="pre">$data</td>
2091 } # while (my $line = <$fd>)
2092 print "</table>\n\n";
2093 close $fd or print "Reading blob failed.\n";
2099 my $head = git_get_head_hash
($project);
2101 git_print_page_nav
('','', $head,undef,$head);
2102 git_print_header_div
('summary', $project);
2104 my $taglist = git_get_refs_list
("refs/tags");
2105 if (defined @
$taglist) {
2106 git_tags_body
($taglist);
2112 my $head = git_get_head_hash
($project);
2114 git_print_page_nav
('','', $head,undef,$head);
2115 git_print_header_div
('summary', $project);
2117 my $taglist = git_get_refs_list
("refs/heads");
2118 if (defined @
$taglist) {
2119 git_heads_body
($taglist, $head);
2124 sub git_blob_plain
{
2125 if (!defined $hash) {
2126 if (defined $file_name) {
2127 my $base = $hash_base || git_get_head_hash
($project);
2128 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2129 or die_error
(undef, "Error lookup file");
2131 die_error
(undef, "No file name defined");
2135 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2136 or die_error
(undef, "Couldn't cat $file_name, $hash");
2138 $type ||= blob_mimetype
($fd, $file_name);
2140 # save as filename, even when no $file_name is given
2141 my $save_as = "$hash";
2142 if (defined $file_name) {
2143 $save_as = $file_name;
2144 } elsif ($type =~ m/^text\//) {
2148 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
2150 binmode STDOUT
, ':raw';
2152 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2158 if (!defined $hash) {
2159 if (defined $file_name) {
2160 my $base = $hash_base || git_get_head_hash
($project);
2161 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2162 or die_error
(undef, "Error lookup file");
2164 die_error
(undef, "No file name defined");
2167 my $have_blame = gitweb_check_feature
('blame');
2168 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2169 or die_error
(undef, "Couldn't cat $file_name, $hash");
2170 my $mimetype = blob_mimetype
($fd, $file_name);
2171 if ($mimetype !~ m/^text\//) {
2173 return git_blob_plain
($mimetype);
2176 my $formats_nav = '';
2177 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2178 if (defined $file_name) {
2180 $formats_nav .= $cgi->a({-href
=> href
(action
=>"blame", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, "blame") . " | ";
2183 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash, file_name
=>$file_name)}, "plain") .
2184 " | " . $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>"HEAD", file_name
=>$file_name)}, "head");
2186 $formats_nav .= $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "plain");
2188 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2189 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2191 print "<div class=\"page_nav\">\n" .
2192 "<br/><br/></div>\n" .
2193 "<div class=\"title\">$hash</div>\n";
2195 git_print_page_path
($file_name, "blob", $hash_base);
2196 print "<div class=\"page_body\">\n";
2198 while (my $line = <$fd>) {
2201 $line = untabify
($line);
2202 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
2204 close $fd or print "Reading blob failed.\n";
2210 if (!defined $hash) {
2211 $hash = git_get_head_hash
($project);
2212 if (defined $file_name) {
2213 my $base = $hash_base || $hash;
2214 $hash = git_get_hash_by_path
($base, $file_name, "tree");
2216 if (!defined $hash_base) {
2221 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
2222 or die_error
(undef, "Open git-ls-tree failed");
2223 my @entries = map { chomp; $_ } <$fd>;
2224 close $fd or die_error
(undef, "Reading tree failed");
2227 my $refs = git_get_references
();
2228 my $ref = format_ref_marker
($refs, $hash_base);
2232 my $have_blame = gitweb_check_feature
('blame');
2233 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2234 $base_key{hash_base
} = $hash_base;
2235 git_print_page_nav
('tree','', $hash_base);
2236 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2238 print "<div class=\"page_nav\">\n";
2239 print "<br/><br/></div>\n";
2240 print "<div class=\"title\">$hash</div>\n";
2242 if (defined $file_name) {
2243 $base = esc_html
("$file_name/");
2245 git_print_page_path
($file_name, 'tree', $hash_base);
2246 print "<div class=\"page_body\">\n";
2247 print "<table cellspacing=\"0\">\n";
2249 foreach my $line (@entries) {
2250 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2251 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2255 my $t_name = validate_input
($4);
2257 print "<tr class=\"dark\">\n";
2259 print "<tr class=\"light\">\n";
2262 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
2263 if ($t_type eq "blob") {
2264 print "<td class=\"list\">" .
2265 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key), -class => "list"}, esc_html
($t_name)) .
2267 "<td class=\"link\">" .
2268 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)}, "blob");
2270 print " | " . $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)}, "blame");
2272 print " | " . $cgi->a({-href
=> href
(action
=>"history", hash
=>$t_hash, hash_base
=>$hash_base, file_name
=>"$base$t_name")}, "history") .
2273 " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$t_hash, file_name
=>"$base$t_name")}, "raw") .
2275 } elsif ($t_type eq "tree") {
2276 print "<td class=\"list\">" .
2277 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)}, esc_html
($t_name)) .
2279 "<td class=\"link\">" .
2280 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)}, "tree") .
2281 " | " . $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base, file_name
=>"$base$t_name")}, "history") .
2286 print "</table>\n" .
2293 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2294 my $have_snapshot = (defined $ctype && defined $suffix);
2295 if (!$have_snapshot) {
2296 die_error
('403 Permission denied', "Permission denied");
2299 if (!defined $hash) {
2300 $hash = git_get_head_hash
($project);
2303 my $filename = basename
($project) . "-$hash.tar.$suffix";
2305 print $cgi->header(-type
=> 'application/x-tar',
2306 -content
-encoding
=> $ctype,
2307 '-content-disposition' =>
2308 "inline; filename=\"$filename\"",
2309 -status
=> '200 OK');
2311 open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | $command" or
2312 die_error
(undef, "Execute git-tar-tree failed.");
2313 binmode STDOUT
, ':raw';
2315 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2321 my $head = git_get_head_hash
($project);
2322 if (!defined $hash) {
2325 if (!defined $page) {
2328 my $refs = git_get_references
();
2330 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2331 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2332 or die_error
(undef, "Open git-rev-list failed");
2333 my @revlist = map { chomp; $_ } <$fd>;
2336 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2339 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2342 my %co = parse_commit
($hash);
2344 git_print_header_div
('summary', $project);
2345 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2347 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2348 my $commit = $revlist[$i];
2349 my $ref = format_ref_marker
($refs, $commit);
2350 my %co = parse_commit
($commit);
2352 my %ad = parse_date
($co{'author_epoch'});
2353 git_print_header_div
('commit',
2354 "<span class=\"age\">$co{'age_string'}</span>" .
2355 esc_html
($co{'title'}) . $ref,
2357 print "<div class=\"title_text\">\n" .
2358 "<div class=\"log_link\">\n" .
2359 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2360 " | " . $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2363 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2366 print "<div class=\"log_body\">\n";
2367 git_print_simplified_log
($co{'comment'});
2374 my %co = parse_commit
($hash);
2376 die_error
(undef, "Unknown commit object");
2378 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2379 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2381 my $parent = $co{'parent'};
2382 if (!defined $parent) {
2385 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
2386 or die_error
(undef, "Open git-diff-tree failed");
2387 my @difftree = map { chomp; $_ } <$fd>;
2388 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2390 # non-textual hash id's can be cached
2392 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2395 my $refs = git_get_references
();
2396 my $ref = format_ref_marker
($refs, $co{'id'});
2398 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2399 my $have_snapshot = (defined $ctype && defined $suffix);
2401 my $formats_nav = '';
2402 if (defined $file_name && defined $co{'parent'}) {
2403 my $parent = $co{'parent'};
2404 $formats_nav .= $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)}, "blame");
2406 git_header_html
(undef, $expires);
2407 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
2408 $hash, $co{'tree'}, $hash,
2411 if (defined $co{'parent'}) {
2412 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2414 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
2416 print "<div class=\"title_text\">\n" .
2417 "<table cellspacing=\"0\">\n";
2418 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2420 "<td></td><td> $ad{'rfc2822'}";
2421 if ($ad{'hour_local'} < 6) {
2422 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2424 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2428 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2429 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
2430 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2433 "<td class=\"sha1\">" .
2434 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash), class => "list"}, $co{'tree'}) .
2436 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)}, "tree");
2437 if ($have_snapshot) {
2438 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
2442 my $parents = $co{'parents'};
2443 foreach my $par (@
$parents) {
2446 "<td class=\"sha1\">" . $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par), class => "list"}, $par) . "</td>" .
2447 "<td class=\"link\">" .
2448 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
2449 " | " . $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "commitdiff") .
2456 print "<div class=\"page_body\">\n";
2457 git_print_log
($co{'comment'});
2460 git_difftree_body
(\
@difftree, $parent);
2466 mkdir($git_temp, 0700);
2468 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2470 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", hash
=>$hash, hash_parent
=>$hash_parent)}, "plain");
2471 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2472 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2474 print "<div class=\"page_nav\">\n" .
2475 "<br/><br/></div>\n" .
2476 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2478 git_print_page_path
($file_name, "blob", $hash_base);
2479 print "<div class=\"page_body\">\n" .
2480 "<div class=\"diff_info\">blob:" .
2481 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash_parent, hash_base
=>$hash_base, file_name
=>($file_parent || $file_name))}, $hash_parent) .
2483 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, $hash) .
2485 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2490 sub git_blobdiff_plain
{
2491 mkdir($git_temp, 0700);
2492 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2493 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2496 sub git_commitdiff
{
2497 mkdir($git_temp, 0700);
2498 my %co = parse_commit
($hash);
2500 die_error
(undef, "Unknown commit object");
2502 if (!defined $hash_parent) {
2503 $hash_parent = $co{'parent'} || '--root';
2505 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2506 or die_error
(undef, "Open git-diff-tree failed");
2507 my @difftree = map { chomp; $_ } <$fd>;
2508 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2510 # non-textual hash id's can be cached
2512 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2515 my $refs = git_get_references
();
2516 my $ref = format_ref_marker
($refs, $co{'id'});
2518 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", hash
=>$hash, hash_parent
=>$hash_parent)}, "plain");
2519 git_header_html
(undef, $expires);
2520 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2521 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2522 print "<div class=\"page_body\">\n";
2523 git_print_simplified_log
($co{'comment'}, 1); # skip title
2525 foreach my $line (@difftree) {
2526 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2527 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2528 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2536 my $file = validate_input
(unquote
($6));
2537 if ($status eq "A") {
2538 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2539 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file)}, $to_id) . "(new)" .
2541 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2542 } elsif ($status eq "D") {
2543 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2544 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$hash_parent, file_name
=>$file)}, $from_id) . "(deleted)" .
2546 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2547 } elsif ($status eq "M") {
2548 if ($from_id ne $to_id) {
2549 print "<div class=\"diff_info\">" .
2550 file_type
($from_mode) . ":" .
2551 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$hash_parent, file_name
=>$file)}, $from_id) .
2553 file_type
($to_mode) . ":" .
2554 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file)}, $to_id);
2556 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2565 sub git_commitdiff_plain
{
2566 mkdir($git_temp, 0700);
2567 my %co = parse_commit
($hash);
2569 die_error
(undef, "Unknown commit object");
2571 if (!defined $hash_parent) {
2572 $hash_parent = $co{'parent'} || '--root';
2574 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2575 or die_error
(undef, "Open git-diff-tree failed");
2576 my @difftree = map { chomp; $_ } <$fd>;
2577 close $fd or die_error
(undef, "Reading diff-tree failed");
2579 # try to figure out the next tag after this commit
2581 my $refs = git_get_references
("tags");
2582 open $fd, "-|", $GIT, "rev-list", "HEAD";
2583 my @commits = map { chomp; $_ } <$fd>;
2585 foreach my $commit (@commits) {
2586 if (defined $refs->{$commit}) {
2587 $tagname = $refs->{$commit}
2589 if ($commit eq $hash) {
2594 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2595 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2596 my $comment = $co{'comment'};
2597 print "From: $co{'author'}\n" .
2598 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2599 "Subject: $co{'title'}\n";
2600 if (defined $tagname) {
2601 print "X-Git-Tag: $tagname\n";
2603 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2606 foreach my $line (@
$comment) {;
2611 foreach my $line (@difftree) {
2612 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2619 if ($status eq "A") {
2620 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2621 } elsif ($status eq "D") {
2622 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2623 } elsif ($status eq "M") {
2624 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2630 if (!defined $hash_base) {
2631 $hash_base = git_get_head_hash
($project);
2634 my %co = parse_commit
($hash_base);
2636 die_error
(undef, "Unknown commit object");
2638 my $refs = git_get_references
();
2640 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2641 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2642 if (!defined $hash && defined $file_name) {
2643 $hash = git_get_hash_by_path
($hash_base, $file_name);
2645 if (defined $hash) {
2646 $ftype = git_get_type
($hash);
2648 git_print_page_path
($file_name, $ftype, $hash_base);
2651 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2652 git_history_body
($fd, $refs, $hash_base, $ftype);
2659 if (!defined $searchtext) {
2660 die_error
(undef, "Text field empty");
2662 if (!defined $hash) {
2663 $hash = git_get_head_hash
($project);
2665 my %co = parse_commit
($hash);
2667 die_error
(undef, "Unknown commit object");
2669 # pickaxe may take all resources of your box and run for several minutes
2670 # with every query - so decide by yourself how public you make this feature :)
2671 my $commit_search = 1;
2672 my $author_search = 0;
2673 my $committer_search = 0;
2674 my $pickaxe_search = 0;
2675 if ($searchtext =~ s/^author\\://i) {
2677 } elsif ($searchtext =~ s/^committer\\://i) {
2678 $committer_search = 1;
2679 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2681 $pickaxe_search = 1;
2684 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
2685 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
2687 print "<table cellspacing=\"0\">\n";
2689 if ($commit_search) {
2691 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2692 while (my $commit_text = <$fd>) {
2693 if (!grep m/$searchtext/i, $commit_text) {
2696 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2699 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2702 my @commit_lines = split "\n", $commit_text;
2703 my %co = parse_commit
(undef, \
@commit_lines);
2708 print "<tr class=\"dark\">\n";
2710 print "<tr class=\"light\">\n";
2713 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2714 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2716 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}) -class => "list"}, "<b>" . esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2717 my $comment = $co{'comment'};
2718 foreach my $line (@
$comment) {
2719 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2720 my $lead = esc_html
($1) || "";
2721 $lead = chop_str
($lead, 30, 10);
2722 my $match = esc_html
($2) || "";
2723 my $trail = esc_html
($3) || "";
2724 $trail = chop_str
($trail, 30, 10);
2725 my $text = "$lead<span class=\"match\">$match</span>$trail";
2726 print chop_str
($text, 80, 5) . "<br/>\n";
2730 "<td class=\"link\">" .
2731 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
2732 " | " . $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
2739 if ($pickaxe_search) {
2741 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2744 while (my $line = <$fd>) {
2745 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2748 $set{'from_id'} = $3;
2750 $set{'id'} = $set{'to_id'};
2751 if ($set{'id'} =~ m/0{40}/) {
2752 $set{'id'} = $set{'from_id'};
2754 if ($set{'id'} =~ m/0{40}/) {
2758 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2761 print "<tr class=\"dark\">\n";
2763 print "<tr class=\"light\">\n";
2766 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2767 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2769 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list"}, "<b>" .
2770 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2771 while (my $setref = shift @files) {
2773 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$set{'id'}, hash_base
=>$co{'id'}, file_name
=>$set{'file'}), class => "list"},
2774 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2778 "<td class=\"link\">" .
2779 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
2780 " | " . $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
2784 %co = parse_commit
($1);
2794 my $head = git_get_head_hash
($project);
2795 if (!defined $hash) {
2798 if (!defined $page) {
2801 my $refs = git_get_references
();
2803 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2804 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2805 or die_error
(undef, "Open git-rev-list failed");
2806 my @revlist = map { chomp; $_ } <$fd>;
2809 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
2811 if ($#revlist >= (100 * ($page+1)-1)) {
2813 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
2814 -title
=> "Alt-n"}, "next");
2819 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
2820 git_print_header_div
('summary', $project);
2822 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
2827 ## ......................................................................
2828 ## feeds (RSS, OPML)
2831 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
2832 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash
($project)
2833 or die_error
(undef, "Open git-rev-list failed");
2834 my @revlist = map { chomp; $_ } <$fd>;
2835 close $fd or die_error
(undef, "Reading git-rev-list failed");
2836 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2837 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2838 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
2839 print "<channel>\n";
2840 print "<title>$project</title>\n".
2841 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
2842 "<description>$project log</description>\n".
2843 "<language>en</language>\n";
2845 for (my $i = 0; $i <= $#revlist; $i++) {
2846 my $commit = $revlist[$i];
2847 my %co = parse_commit
($commit);
2848 # we read 150, we always show 30 and the ones more recent than 48 hours
2849 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
2852 my %cd = parse_date
($co{'committer_epoch'});
2853 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
2854 my @difftree = map { chomp; $_ } <$fd>;
2858 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
2860 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
2861 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
2862 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
2863 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
2864 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
2865 "<content:encoded>" .
2867 my $comment = $co{'comment'};
2868 foreach my $line (@
$comment) {
2869 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
2870 print "$line<br/>\n";
2873 foreach my $line (@difftree) {
2874 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2877 my $file = validate_input
(unquote
($7));
2878 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
2879 print "$file<br/>\n";
2882 "</content:encoded>\n" .
2885 print "</channel></rss>";
2889 my @list = git_get_projects_list
();
2891 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2892 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2893 "<opml version=\"1.0\">\n".
2895 " <title>$site_name Git OPML Export</title>\n".
2898 "<outline text=\"git RSS feeds\">\n";
2900 foreach my $pr (@list) {
2902 my $head = git_get_head_hash
($proj{'path'});
2903 if (!defined $head) {
2906 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
2907 my %co = parse_commit
($head);
2912 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
2913 my $rss = "$my_url?p=$proj{'path'};a=rss";
2914 my $html = "$my_url?p=$proj{'path'};a=summary";
2915 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
2917 print "</outline>\n".