3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 our $version = "++GIT_VERSION++";
23 our $my_url = $cgi->url();
24 our $my_uri = $cgi->url(-absolute
=> 1);
26 # core git executable to use
27 # this can just be "git" if your webserver has a sensible PATH
28 our $GIT = "++GIT_BINDIR++/git";
30 # absolute fs-path which will be prepended to the project path
31 #our $projectroot = "/pub/scm";
32 our $projectroot = "++GITWEB_PROJECTROOT++";
34 # location for temporary files needed for diffs
35 our $git_temp = "/tmp/gitweb";
37 # target of the home link on top of all pages
38 our $home_link = $my_uri || "/";
40 # string of the home link on top of all pages
41 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
43 # name of your site or organization to appear in page titles
44 # replace this with something more descriptive for clearer bookmarks
45 our $site_name = "++GITWEB_SITENAME++" || $ENV{'SERVER_NAME'} || "Untitled";
47 # html text to include at home page
48 our $home_text = "++GITWEB_HOMETEXT++";
50 # URI of default stylesheet
51 our $stylesheet = "++GITWEB_CSS++";
53 our $logo = "++GITWEB_LOGO++";
55 # source of projects list
56 our $projects_list = "++GITWEB_LIST++";
58 # list of git base URLs used for URL to where fetch project from,
59 # i.e. full URL is "$git_base_url/$project"
60 our @git_base_url_list = ("++GITWEB_BASE_URL++");
62 # default blob_plain mimetype and default charset for text/plain blob
63 our $default_blob_plain_mimetype = 'text/plain';
64 our $default_text_plain_charset = undef;
66 # file to use for guessing MIME types before trying /etc/mime.types
67 # (relative to the current git repository)
68 our $mimetypes_file = undef;
70 # You define site-wide feature defaults here; override them with
71 # $GITWEB_CONFIG as necessary.
73 # feature => {'sub' => feature-sub, 'override' => allow-override, 'default' => [ default options...]
74 # if feature is overridable, feature-sub will be called with default options;
75 # return value indicates if to enable specified feature
78 'sub' => \
&feature_blame
,
83 'sub' => \
&feature_snapshot
,
85 # => [content-encoding, suffix, program]
86 'default' => ['x-gzip', 'gz', 'gzip']},
89 sub gitweb_check_feature
{
91 return undef unless exists $feature{$name};
92 my ($sub, $override, @defaults) = (
93 $feature{$name}{'sub'},
94 $feature{$name}{'override'},
95 @
{$feature{$name}{'default'}});
96 if (!$override) { return @defaults; }
97 return $sub->(@defaults);
100 # To enable system wide have in $GITWEB_CONFIG
101 # $feature{'blame'}{'default'} = [1];
102 # To have project specific config enable override in $GITWEB_CONFIG
103 # $feature{'blame'}{'override'} = 1;
104 # and in project config gitweb.blame = 0|1;
107 my ($val) = git_get_project_config
('blame', '--bool');
109 if ($val eq 'true') {
111 } elsif ($val eq 'false') {
118 # To disable system wide have in $GITWEB_CONFIG
119 # $feature{'snapshot'}{'default'} = [undef];
120 # To have project specific config enable override in $GITWEB_CONFIG
121 # $feature{'blame'}{'override'} = 1;
122 # and in project config gitweb.snapshot = none|gzip|bzip2
124 sub feature_snapshot
{
125 my ($ctype, $suffix, $command) = @_;
127 my ($val) = git_get_project_config
('snapshot');
129 if ($val eq 'gzip') {
130 return ('x-gzip', 'gz', 'gzip');
131 } elsif ($val eq 'bzip2') {
132 return ('x-bzip2', 'bz2', 'bzip2');
133 } elsif ($val eq 'none') {
137 return ($ctype, $suffix, $command);
140 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
141 require $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
143 # version of the core git binary
144 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
146 $projects_list ||= $projectroot;
147 if (! -d
$git_temp) {
148 mkdir($git_temp, 0700) || die_error
(undef, "Couldn't mkdir $git_temp");
151 # ======================================================================
152 # input validation and dispatch
153 our $action = $cgi->param('a');
154 if (defined $action) {
155 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
156 die_error
(undef, "Invalid action parameter");
160 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
161 if (defined $project) {
164 $project = undef unless $project;
166 if (defined $project) {
167 if (!validate_input
($project)) {
168 die_error
(undef, "Invalid project parameter");
170 if (!(-d
"$projectroot/$project")) {
171 die_error
(undef, "No such directory");
173 if (!(-e
"$projectroot/$project/HEAD")) {
174 die_error
(undef, "No such project");
176 $ENV{'GIT_DIR'} = "$projectroot/$project";
179 our $file_name = $cgi->param('f');
180 if (defined $file_name) {
181 if (!validate_input
($file_name)) {
182 die_error
(undef, "Invalid file parameter");
186 our $file_parent = $cgi->param('fp');
187 if (defined $file_parent) {
188 if (!validate_input
($file_parent)) {
189 die_error
(undef, "Invalid file parent parameter");
193 our $hash = $cgi->param('h');
195 if (!validate_input
($hash)) {
196 die_error
(undef, "Invalid hash parameter");
200 our $hash_parent = $cgi->param('hp');
201 if (defined $hash_parent) {
202 if (!validate_input
($hash_parent)) {
203 die_error
(undef, "Invalid hash parent parameter");
207 our $hash_base = $cgi->param('hb');
208 if (defined $hash_base) {
209 if (!validate_input
($hash_base)) {
210 die_error
(undef, "Invalid hash base parameter");
214 our $page = $cgi->param('pg');
216 if ($page =~ m/[^0-9]$/) {
217 die_error
(undef, "Invalid page parameter");
221 our $searchtext = $cgi->param('s');
222 if (defined $searchtext) {
223 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
224 die_error
(undef, "Invalid search parameter");
226 $searchtext = quotemeta $searchtext;
231 "blame" => \
&git_blame2
,
232 "blobdiff" => \
&git_blobdiff
,
233 "blobdiff_plain" => \
&git_blobdiff_plain
,
234 "blob" => \
&git_blob
,
235 "blob_plain" => \
&git_blob_plain
,
236 "commitdiff" => \
&git_commitdiff
,
237 "commitdiff_plain" => \
&git_commitdiff_plain
,
238 "commit" => \
&git_commit
,
239 "heads" => \
&git_heads
,
240 "history" => \
&git_history
,
243 "search" => \
&git_search
,
244 "shortlog" => \
&git_shortlog
,
245 "summary" => \
&git_summary
,
247 "tags" => \
&git_tags
,
248 "tree" => \
&git_tree
,
249 "snapshot" => \
&git_snapshot
,
250 # those below don't need $project
251 "opml" => \
&git_opml
,
252 "project_list" => \
&git_project_list
,
255 if (defined $project) {
256 $action ||= 'summary';
258 $action ||= 'project_list';
260 if (!defined($actions{$action})) {
261 die_error
(undef, "Unknown action");
263 $actions{$action}->();
266 ## ======================================================================
283 $params{"project"} ||= $project;
285 my $href = "$my_uri?";
286 $href .= esc_param
( join(";",
288 "$mapping{$_}=$params{$_}" if defined $params{$_}
296 ## ======================================================================
297 ## validation, quoting/unquoting and escaping
302 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
305 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
308 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
314 # quote unsafe chars, but keep the slash, even when it's not
315 # correct, but quoted slashes look too horrible in bookmarks
318 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
324 # replace invalid utf8 character with SUBSTITUTION sequence
327 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
328 $str = escapeHTML
($str);
329 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
333 # git may return quoted and escaped filenames
336 if ($str =~ m/^"(.*)"$/) {
338 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
343 # escape tabs (convert tabs to spaces)
347 while ((my $pos = index($line, "\t")) != -1) {
348 if (my $count = (8 - ($pos % 8))) {
349 my $spaces = ' ' x
$count;
350 $line =~ s/\t/$spaces/;
357 ## ----------------------------------------------------------------------
358 ## HTML aware string manipulation
363 my $add_len = shift || 10;
365 # allow only $len chars, but don't cut a word if it would fit in $add_len
366 # if it doesn't fit, cut it if it's still longer than the dots we would add
367 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
370 if (length($tail) > 4) {
372 $body =~ s/&[^;]*$//; # remove chopped character entities
377 ## ----------------------------------------------------------------------
378 ## functions returning short strings
380 # CSS class for given age value (in seconds)
384 if ($age < 60*60*2) {
386 } elsif ($age < 60*60*24*2) {
393 # convert age in seconds to "nn units ago" string
398 if ($age > 60*60*24*365*2) {
399 $age_str = (int $age/60/60/24/365);
400 $age_str .= " years ago";
401 } elsif ($age > 60*60*24*(365/12)*2) {
402 $age_str = int $age/60/60/24/(365/12);
403 $age_str .= " months ago";
404 } elsif ($age > 60*60*24*7*2) {
405 $age_str = int $age/60/60/24/7;
406 $age_str .= " weeks ago";
407 } elsif ($age > 60*60*24*2) {
408 $age_str = int $age/60/60/24;
409 $age_str .= " days ago";
410 } elsif ($age > 60*60*2) {
411 $age_str = int $age/60/60;
412 $age_str .= " hours ago";
413 } elsif ($age > 60*2) {
414 $age_str = int $age/60;
415 $age_str .= " min ago";
418 $age_str .= " sec ago";
420 $age_str .= " right now";
425 # convert file mode in octal to symbolic file mode string
427 my $mode = oct shift;
429 if (S_ISDIR
($mode & S_IFMT
)) {
431 } elsif (S_ISLNK
($mode)) {
433 } elsif (S_ISREG
($mode)) {
434 # git cares only about the executable bit
435 if ($mode & S_IXUSR
) {
445 # convert file mode in octal to file type string
447 my $mode = oct shift;
449 if (S_ISDIR
($mode & S_IFMT
)) {
451 } elsif (S_ISLNK
($mode)) {
453 } elsif (S_ISREG
($mode)) {
460 ## ----------------------------------------------------------------------
461 ## functions returning short HTML fragments, or transforming HTML fragments
462 ## which don't beling to other sections
464 # format line of commit message or tag comment
465 sub format_log_line_html
{
468 $line = esc_html
($line);
469 $line =~ s/ / /g;
470 if ($line =~ m/([0-9a-fA-F]{40})/) {
472 if (git_get_type
($hash_text) eq "commit") {
474 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
475 -class => "text"}, $hash_text);
476 $line =~ s/$hash_text/$link/;
482 # format marker of refs pointing to given object
483 sub format_ref_marker
{
484 my ($refs, $id) = @_;
487 if (defined $refs->{$id}) {
488 foreach my $ref (@
{$refs->{$id}}) {
489 my ($type, $name) = qw();
490 # e.g. tags/v2.6.11 or heads/next
491 if ($ref =~ m!^(.*?)s?/(.*)$!) {
499 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
504 return ' <span class="refs">'. $markers . '</span>';
510 # format, perhaps shortened and with markers, title line
511 sub format_subject_html
{
512 my ($long, $short, $href, $extra) = @_;
513 $extra = '' unless defined($extra);
515 if (length($short) < length($long)) {
516 return $cgi->a({-href
=> $href, -class => "list subject",
518 esc_html
($short) . $extra);
520 return $cgi->a({-href
=> $href, -class => "list subject"},
521 esc_html
($long) . $extra);
525 ## ----------------------------------------------------------------------
526 ## git utility subroutines, invoking git commands
528 # get HEAD ref of given project as hash
529 sub git_get_head_hash
{
531 my $oENV = $ENV{'GIT_DIR'};
533 $ENV{'GIT_DIR'} = "$projectroot/$project";
534 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
537 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
542 $ENV{'GIT_DIR'} = $oENV;
547 # get type of given object
551 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
558 sub git_get_project_config
{
559 my ($key, $type) = @_;
561 return unless ($key);
562 $key =~ s/^gitweb\.//;
563 return if ($key =~ m/\W/);
565 my @x = ($GIT, 'repo-config');
566 if (defined $type) { push @x, $type; }
568 push @x, "gitweb.$key";
574 # get hash of given path at given ref
575 sub git_get_hash_by_path
{
577 my $path = shift || return undef;
581 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
582 or die_error
(undef, "Open git-ls-tree failed");
584 close $fd or return undef;
586 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
587 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
591 ## ......................................................................
592 ## git utility functions, directly accessing git repository
594 # assumes that PATH is not symref
595 sub git_get_hash_by_ref
{
598 open my $fd, "$projectroot/$path" or return undef;
602 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
607 sub git_get_project_description
{
610 open my $fd, "$projectroot/$path/description" or return undef;
617 sub git_get_project_url_list
{
620 open my $fd, "$projectroot/$path/cloneurl" or return undef;
621 my @git_project_url_list = map { chomp; $_ } <$fd>;
624 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
627 sub git_get_projects_list
{
630 if (-d
$projects_list) {
631 # search in directory
632 my $dir = $projects_list;
633 opendir my ($dh), $dir or return undef;
634 while (my $dir = readdir($dh)) {
635 if (-e
"$projectroot/$dir/HEAD") {
643 } elsif (-f
$projects_list) {
644 # read from file(url-encoded):
645 # 'git%2Fgit.git Linus+Torvalds'
646 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
647 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
648 open my ($fd), $projects_list or return undef;
649 while (my $line = <$fd>) {
651 my ($path, $owner) = split ' ', $line;
652 $path = unescape
($path);
653 $owner = unescape
($owner);
654 if (!defined $path) {
657 if (-e
"$projectroot/$path/HEAD") {
660 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
667 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
671 sub git_get_project_owner
{
675 return undef unless $project;
677 # read from file (url-encoded):
678 # 'git%2Fgit.git Linus+Torvalds'
679 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
680 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
681 if (-f
$projects_list) {
682 open (my $fd , $projects_list);
683 while (my $line = <$fd>) {
685 my ($pr, $ow) = split ' ', $line;
688 if ($pr eq $project) {
689 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
695 if (!defined $owner) {
696 $owner = get_file_owner
("$projectroot/$project");
702 sub git_get_references
{
703 my $type = shift || "";
706 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
707 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
708 if (-f
"$projectroot/$project/info/refs") {
709 open $fd, "$projectroot/$project/info/refs"
712 open $fd, "-|", $GIT, "ls-remote", "."
716 while (my $line = <$fd>) {
718 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
719 if (defined $refs{$1}) {
720 push @
{$refs{$1}}, $2;
730 ## ----------------------------------------------------------------------
731 ## parse to hash functions
735 my $tz = shift || "-0000";
738 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
739 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
740 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
741 $date{'hour'} = $hour;
742 $date{'minute'} = $min;
743 $date{'mday'} = $mday;
744 $date{'day'} = $days[$wday];
745 $date{'month'} = $months[$mon];
746 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
747 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
748 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
749 $mday, $months[$mon], $hour ,$min;
751 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
752 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
753 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
754 $date{'hour_local'} = $hour;
755 $date{'minute_local'} = $min;
756 $date{'tz_local'} = $tz;
765 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
766 $tag{'id'} = $tag_id;
767 while (my $line = <$fd>) {
769 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
771 } elsif ($line =~ m/^type (.+)$/) {
773 } elsif ($line =~ m/^tag (.+)$/) {
775 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
779 } elsif ($line =~ m/--BEGIN/) {
780 push @comment, $line;
782 } elsif ($line eq "") {
786 push @comment, <$fd>;
787 $tag{'comment'} = \
@comment;
789 if (!defined $tag{'name'}) {
796 my $commit_id = shift;
797 my $commit_text = shift;
802 if (defined $commit_text) {
803 @commit_lines = @
$commit_text;
806 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id
808 @commit_lines = split '\n', <$fd>;
813 my $header = shift @commit_lines;
814 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
817 ($co{'id'}, my @parents) = split ' ', $header;
818 $co{'parents'} = \
@parents;
819 $co{'parent'} = $parents[0];
820 while (my $line = shift @commit_lines) {
821 last if $line eq "\n";
822 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
824 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
826 $co{'author_epoch'} = $2;
827 $co{'author_tz'} = $3;
828 if ($co{'author'} =~ m/^([^<]+) </) {
829 $co{'author_name'} = $1;
831 $co{'author_name'} = $co{'author'};
833 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
834 $co{'committer'} = $1;
835 $co{'committer_epoch'} = $2;
836 $co{'committer_tz'} = $3;
837 $co{'committer_name'} = $co{'committer'};
838 $co{'committer_name'} =~ s/ <.*//;
841 if (!defined $co{'tree'}) {
845 foreach my $title (@commit_lines) {
848 $co{'title'} = chop_str
($title, 80, 5);
849 # remove leading stuff of merges to make the interesting part visible
850 if (length($title) > 50) {
851 $title =~ s/^Automatic //;
852 $title =~ s/^merge (of|with) /Merge ... /i;
853 if (length($title) > 50) {
854 $title =~ s/(http|rsync):\/\///;
856 if (length($title) > 50) {
857 $title =~ s/(master|www|rsync)\.//;
859 if (length($title) > 50) {
860 $title =~ s/kernel.org:?//;
862 if (length($title) > 50) {
863 $title =~ s/\/pub\/scm//;
866 $co{'title_short'} = chop_str
($title, 50, 5);
870 # remove added spaces
871 foreach my $line (@commit_lines) {
874 $co{'comment'} = \
@commit_lines;
876 my $age = time - $co{'committer_epoch'};
878 $co{'age_string'} = age_string
($age);
879 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
880 if ($age > 60*60*24*7*2) {
881 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
882 $co{'age_string_age'} = $co{'age_string'};
884 $co{'age_string_date'} = $co{'age_string'};
885 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
890 # parse ref from ref_file, given by ref_id, with given type
892 my $ref_file = shift;
894 my $type = shift || git_get_type
($ref_id);
897 $ref_item{'type'} = $type;
898 $ref_item{'id'} = $ref_id;
899 $ref_item{'epoch'} = 0;
900 $ref_item{'age'} = "unknown";
901 if ($type eq "tag") {
902 my %tag = parse_tag
($ref_id);
903 $ref_item{'comment'} = $tag{'comment'};
904 if ($tag{'type'} eq "commit") {
905 my %co = parse_commit
($tag{'object'});
906 $ref_item{'epoch'} = $co{'committer_epoch'};
907 $ref_item{'age'} = $co{'age_string'};
908 } elsif (defined($tag{'epoch'})) {
909 my $age = time - $tag{'epoch'};
910 $ref_item{'epoch'} = $tag{'epoch'};
911 $ref_item{'age'} = age_string
($age);
913 $ref_item{'reftype'} = $tag{'type'};
914 $ref_item{'name'} = $tag{'name'};
915 $ref_item{'refid'} = $tag{'object'};
916 } elsif ($type eq "commit"){
917 my %co = parse_commit
($ref_id);
918 $ref_item{'reftype'} = "commit";
919 $ref_item{'name'} = $ref_file;
920 $ref_item{'title'} = $co{'title'};
921 $ref_item{'refid'} = $ref_id;
922 $ref_item{'epoch'} = $co{'committer_epoch'};
923 $ref_item{'age'} = $co{'age_string'};
925 $ref_item{'reftype'} = $type;
926 $ref_item{'name'} = $ref_file;
927 $ref_item{'refid'} = $ref_id;
933 # parse line of git-diff-tree "raw" output
934 sub parse_difftree_raw_line
{
938 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
939 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
940 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
941 $res{'from_mode'} = $1;
942 $res{'to_mode'} = $2;
943 $res{'from_id'} = $3;
946 $res{'similarity'} = $6;
947 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
948 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
950 $res{'file'} = unquote
($7);
953 # 'c512b523472485aef4fff9e57b229d9d243c967f'
954 #elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
955 # $res{'commit'} = $1;
958 return wantarray ?
%res : \
%res;
961 ## ......................................................................
962 ## parse to array of hashes functions
964 sub git_get_refs_list
{
969 my $pfxlen = length("$projectroot/$project/$ref_dir");
970 File
::Find
::find
(sub {
973 push @refs, substr($File::Find
::name
, $pfxlen + 1);
975 }, "$projectroot/$project/$ref_dir");
977 foreach my $ref_file (@refs) {
978 my $ref_id = git_get_hash_by_ref
("$project/$ref_dir/$ref_file");
979 my $type = git_get_type
($ref_id) || next;
980 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
982 push @reflist, \
%ref_item;
985 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
989 ## ----------------------------------------------------------------------
990 ## filesystem-related functions
995 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
996 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
997 if (!defined $gcos) {
1001 $owner =~ s/[,;].*$//;
1002 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
1005 ## ......................................................................
1006 ## mimetype related functions
1008 sub mimetype_guess_file
{
1009 my $filename = shift;
1010 my $mimemap = shift;
1011 -r
$mimemap or return undef;
1014 open(MIME
, $mimemap) or return undef;
1016 next if m/^#/; # skip comments
1017 my ($mime, $exts) = split(/\t+/);
1018 if (defined $exts) {
1019 my @exts = split(/\s+/, $exts);
1020 foreach my $ext (@exts) {
1021 $mimemap{$ext} = $mime;
1027 $filename =~ /\.(.*?)$/;
1028 return $mimemap{$1};
1031 sub mimetype_guess
{
1032 my $filename = shift;
1034 $filename =~ /\./ or return undef;
1036 if ($mimetypes_file) {
1037 my $file = $mimetypes_file;
1038 if ($file !~ m!^/!) { # if it is relative path
1039 # it is relative to project
1040 $file = "$projectroot/$project/$file";
1042 $mime = mimetype_guess_file
($filename, $file);
1044 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1050 my $filename = shift;
1053 my $mime = mimetype_guess
($filename);
1054 $mime and return $mime;
1058 return $default_blob_plain_mimetype unless $fd;
1061 return 'text/plain' .
1062 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1063 } elsif (! $filename) {
1064 return 'application/octet-stream';
1065 } elsif ($filename =~ m/\.png$/i) {
1067 } elsif ($filename =~ m/\.gif$/i) {
1069 } elsif ($filename =~ m/\.jpe?g$/i) {
1070 return 'image/jpeg';
1072 return 'application/octet-stream';
1076 ## ======================================================================
1077 ## functions printing HTML: header, footer, error page
1079 sub git_header_html
{
1080 my $status = shift || "200 OK";
1081 my $expires = shift;
1083 my $title = "$site_name git";
1084 if (defined $project) {
1085 $title .= " - $project";
1086 if (defined $action) {
1087 $title .= "/$action";
1088 if (defined $file_name) {
1089 $title .= " - $file_name";
1090 if ($action eq "tree" && $file_name !~ m
|/$|) {
1097 # require explicit support from the UA if we are to send the page as
1098 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1099 # we have to do this because MSIE sometimes globs '*/*', pretending to
1100 # support xhtml+xml but choking when it gets what it asked for.
1101 if (defined $cgi->http('HTTP_ACCEPT') &&
1102 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1103 $cgi->Accept('application/xhtml+xml') != 0) {
1104 $content_type = 'application/xhtml+xml';
1106 $content_type = 'text/html';
1108 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1109 -status
=> $status, -expires
=> $expires);
1111 <?xml version="1.0" encoding="utf-8"?>
1112 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1113 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1114 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1115 <!-- git core binaries version $git_version -->
1117 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1118 <meta name="generator" content="gitweb/$version git/$git_version"/>
1119 <meta name="robots" content="index, nofollow"/>
1120 <title>$title</title>
1121 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1123 if (defined $project) {
1124 printf('<link rel="alternate" title="%s log" '.
1125 'href="%s" type="application/rss+xml"/>'."\n",
1126 esc_param
($project), href
(action
=>"rss"));
1131 "<div class=\"page_header\">\n" .
1132 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1133 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1135 print $cgi->a({-href
=> esc_param
($home_link)}, $home_link_str) . " / ";
1136 if (defined $project) {
1137 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1138 if (defined $action) {
1142 if (!defined $searchtext) {
1146 if (defined $hash_base) {
1147 $search_hash = $hash_base;
1148 } elsif (defined $hash) {
1149 $search_hash = $hash;
1151 $search_hash = "HEAD";
1153 $cgi->param("a", "search");
1154 $cgi->param("h", $search_hash);
1155 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1156 "<div class=\"search\">\n" .
1157 $cgi->hidden(-name
=> "p") . "\n" .
1158 $cgi->hidden(-name
=> "a") . "\n" .
1159 $cgi->hidden(-name
=> "h") . "\n" .
1160 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1162 $cgi->end_form() . "\n";
1167 sub git_footer_html
{
1168 print "<div class=\"page_footer\">\n";
1169 if (defined $project) {
1170 my $descr = git_get_project_description
($project);
1171 if (defined $descr) {
1172 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1174 print $cgi->a({-href
=> href
(action
=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1176 print $cgi->a({-href
=> href
(action
=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1184 my $status = shift || "403 Forbidden";
1185 my $error = shift || "Malformed query, file missing or permission denied";
1187 git_header_html
($status);
1188 print "<div class=\"page_body\">\n" .
1190 "$status - $error\n" .
1197 ## ----------------------------------------------------------------------
1198 ## functions printing or outputting HTML: navigation
1200 sub git_print_page_nav
{
1201 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1202 $extra = '' if !defined $extra; # pager or formats
1204 my @navs = qw(summary shortlog log commit commitdiff tree);
1206 @navs = grep { $_ ne $suppress } @navs;
1209 my %arg = map { $_ => {action
=>$_} } @navs;
1210 if (defined $head) {
1211 for (qw(commit commitdiff)) {
1212 $arg{$_}{hash
} = $head;
1214 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1215 for (qw(shortlog log)) {
1216 $arg{$_}{hash
} = $head;
1220 $arg{tree
}{hash
} = $treehead if defined $treehead;
1221 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1223 print "<div class=\"page_nav\">\n" .
1225 map { $_ eq $current ?
1226 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1228 print "<br/>\n$extra<br/>\n" .
1232 sub format_paging_nav
{
1233 my ($action, $hash, $head, $page, $nrevs) = @_;
1237 if ($hash ne $head || $page) {
1238 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1240 $paging_nav .= "HEAD";
1244 $paging_nav .= " ⋅ " .
1245 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1246 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1248 $paging_nav .= " ⋅ prev";
1251 if ($nrevs >= (100 * ($page+1)-1)) {
1252 $paging_nav .= " ⋅ " .
1253 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1254 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1256 $paging_nav .= " ⋅ next";
1262 ## ......................................................................
1263 ## functions printing or outputting HTML: div
1265 sub git_print_header_div
{
1266 my ($action, $title, $hash, $hash_base) = @_;
1269 $args{action
} = $action;
1270 $args{hash
} = $hash if $hash;
1271 $args{hash_base
} = $hash_base if $hash_base;
1273 print "<div class=\"header\">\n" .
1274 $cgi->a({-href
=> href
(%args), -class => "title"},
1275 $title ?
$title : $action) .
1279 sub git_print_page_path
{
1284 if (!defined $name) {
1285 print "<div class=\"page_path\">/</div>\n";
1286 } elsif (defined $type && $type eq 'blob') {
1287 print "<div class=\"page_path\">";
1289 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1293 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name)},
1296 print "<br/></div>\n";
1298 print "<div class=\"page_path\">" . esc_html
($name) . "<br/></div>\n";
1305 # remove leading empty lines
1306 while (defined $log->[0] && $log->[0] eq "") {
1313 foreach my $line (@
$log) {
1314 # print only one empty line
1315 # do not print empty line after signoff
1317 next if ($empty || $signoff);
1322 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1324 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1327 print format_log_line_html
($line) . "<br/>\n";
1332 sub git_print_simplified_log
{
1334 my $remove_title = shift;
1336 shift @
$log if $remove_title;
1337 # remove leading empty lines
1338 while (defined $log->[0] && $log->[0] eq "") {
1342 # simplify and print log
1344 foreach my $line (@
$log) {
1345 # remove signoff lines
1346 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1349 # print only one empty line
1356 print format_log_line_html
($line) . "<br/>\n";
1358 # end with single empty line
1359 print "<br/>\n" unless $empty;
1362 ## ......................................................................
1363 ## functions printing large fragments of HTML
1365 sub git_difftree_body
{
1366 my ($difftree, $parent) = @_;
1368 print "<div class=\"list_head\">\n";
1369 if ($#{$difftree} > 10) {
1370 print(($#{$difftree} + 1) . " files changed:\n");
1374 print "<table class=\"diff_tree\">\n";
1376 foreach my $line (@
{$difftree}) {
1377 my %diff = parse_difftree_raw_line
($line);
1380 print "<tr class=\"dark\">\n";
1382 print "<tr class=\"light\">\n";
1386 my ($to_mode_oct, $to_mode_str, $to_file_type);
1387 my ($from_mode_oct, $from_mode_str, $from_file_type);
1388 if ($diff{'to_mode'} ne ('0' x
6)) {
1389 $to_mode_oct = oct $diff{'to_mode'};
1390 if (S_ISREG
($to_mode_oct)) { # only for regular file
1391 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1393 $to_file_type = file_type
($diff{'to_mode'});
1395 if ($diff{'from_mode'} ne ('0' x
6)) {
1396 $from_mode_oct = oct $diff{'from_mode'};
1397 if (S_ISREG
($to_mode_oct)) { # only for regular file
1398 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1400 $from_file_type = file_type
($diff{'from_mode'});
1403 if ($diff{'status'} eq "A") { # created
1404 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1405 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1406 $mode_chng .= "]</span>";
1408 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1409 hash_base
=>$hash, file_name
=>$diff{'file'}),
1410 -class => "list"}, esc_html
($diff{'file'})) .
1412 "<td>$mode_chng</td>\n" .
1413 "<td class=\"link\">" .
1414 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1415 hash_base
=>$hash, file_name
=>$diff{'file'})},
1419 } elsif ($diff{'status'} eq "D") { # deleted
1420 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1422 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1423 hash_base
=>$parent, file_name
=>$diff{'file'}),
1424 -class => "list"}, esc_html
($diff{'file'})) .
1426 "<td>$mode_chng</td>\n" .
1427 "<td class=\"link\">" .
1428 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1429 hash_base
=>$parent, file_name
=>$diff{'file'})},
1432 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1433 file_name
=>$diff{'file'})},\
1437 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1438 my $mode_chnge = "";
1439 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1440 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1441 if ($from_file_type != $to_file_type) {
1442 $mode_chnge .= " from $from_file_type to $to_file_type";
1444 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1445 if ($from_mode_str && $to_mode_str) {
1446 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1447 } elsif ($to_mode_str) {
1448 $mode_chnge .= " mode: $to_mode_str";
1451 $mode_chnge .= "]</span>\n";
1454 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1455 print $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1456 hash_base
=>$hash, file_name
=>$diff{'file'}),
1457 -class => "list"}, esc_html
($diff{'file'}));
1458 } else { # only mode changed
1459 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1460 hash_base
=>$hash, file_name
=>$diff{'file'}),
1461 -class => "list"}, esc_html
($diff{'file'}));
1464 "<td>$mode_chnge</td>\n" .
1465 "<td class=\"link\">" .
1466 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1467 hash_base
=>$hash, file_name
=>$diff{'file'})},
1469 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1471 $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1472 hash_base
=>$hash, file_name
=>$diff{'file'})},
1476 $cgi->a({-href
=> href
(action
=>"history",
1477 hash_base
=>$hash, file_name
=>$diff{'file'})},
1481 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1482 my %status_name = ('R' => 'moved', 'C' => 'copied');
1483 my $nstatus = $status_name{$diff{'status'}};
1485 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1486 # mode also for directories, so we cannot use $to_mode_str
1487 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1490 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1491 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1492 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1493 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1494 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1495 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1496 -class => "list"}, esc_html
($diff{'from_file'})) .
1497 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1498 "<td class=\"link\">" .
1499 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1500 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'})},
1502 if ($diff{'to_id'} ne $diff{'from_id'}) {
1504 $cgi->a({-href
=> href
(action
=>"blobdiff", hash_base
=>$hash,
1505 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1506 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1511 } # we should not encounter Unmerged (U) or Unknown (X) status
1517 sub git_shortlog_body
{
1518 # uses global variable $project
1519 my ($revlist, $from, $to, $refs, $extra) = @_;
1521 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
1522 my $have_snapshot = (defined $ctype && defined $suffix);
1524 $from = 0 unless defined $from;
1525 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1527 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1529 for (my $i = $from; $i <= $to; $i++) {
1530 my $commit = $revlist->[$i];
1531 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1532 my $ref = format_ref_marker
($refs, $commit);
1533 my %co = parse_commit
($commit);
1535 print "<tr class=\"dark\">\n";
1537 print "<tr class=\"light\">\n";
1540 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1541 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1542 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1544 print format_subject_html
($co{'title'}, $co{'title_short'},
1545 href
(action
=>"commit", hash
=>$commit), $ref);
1547 "<td class=\"link\">" .
1548 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1549 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
1550 if ($have_snapshot) {
1551 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
1556 if (defined $extra) {
1558 "<td colspan=\"4\">$extra</td>\n" .
1564 sub git_history_body
{
1565 # Warning: assumes constant type (blob or tree) during history
1566 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1568 print "<table class=\"history\" cellspacing=\"0\">\n";
1570 while (my $line = <$fd>) {
1571 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1576 my %co = parse_commit
($commit);
1581 my $ref = format_ref_marker
($refs, $commit);
1584 print "<tr class=\"dark\">\n";
1586 print "<tr class=\"light\">\n";
1589 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1590 # shortlog uses chop_str($co{'author_name'}, 10)
1591 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1593 # originally git_history used chop_str($co{'title'}, 50)
1594 print format_subject_html
($co{'title'}, $co{'title_short'},
1595 href
(action
=>"commit", hash
=>$commit), $ref);
1597 "<td class=\"link\">" .
1598 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1599 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
1600 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype);
1602 if ($ftype eq 'blob') {
1603 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
1604 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
1605 if (defined $blob_current && defined $blob_parent &&
1606 $blob_current ne $blob_parent) {
1608 $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$blob_current, hash_parent
=>$blob_parent,
1609 hash_base
=>$commit, file_name
=>$file_name)},
1616 if (defined $extra) {
1618 "<td colspan=\"4\">$extra</td>\n" .
1625 # uses global variable $project
1626 my ($taglist, $from, $to, $extra) = @_;
1627 $from = 0 unless defined $from;
1628 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1630 print "<table class=\"tags\" cellspacing=\"0\">\n";
1632 for (my $i = $from; $i <= $to; $i++) {
1633 my $entry = $taglist->[$i];
1635 my $comment_lines = $tag{'comment'};
1636 my $comment = shift @
$comment_lines;
1638 if (defined $comment) {
1639 $comment_short = chop_str
($comment, 30, 5);
1642 print "<tr class=\"dark\">\n";
1644 print "<tr class=\"light\">\n";
1647 print "<td><i>$tag{'age'}</i></td>\n" .
1649 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
1650 -class => "list name"}, esc_html
($tag{'name'})) .
1653 if (defined $comment) {
1654 print format_subject_html
($comment, $comment_short,
1655 href
(action
=>"tag", hash
=>$tag{'id'}));
1658 "<td class=\"selflink\">";
1659 if ($tag{'type'} eq "tag") {
1660 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
1665 "<td class=\"link\">" . " | " .
1666 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
1667 if ($tag{'reftype'} eq "commit") {
1668 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
1669 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
1670 } elsif ($tag{'reftype'} eq "blob") {
1671 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
1676 if (defined $extra) {
1678 "<td colspan=\"5\">$extra</td>\n" .
1684 sub git_heads_body
{
1685 # uses global variable $project
1686 my ($taglist, $head, $from, $to, $extra) = @_;
1687 $from = 0 unless defined $from;
1688 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1690 print "<table class=\"heads\" cellspacing=\"0\">\n";
1692 for (my $i = $from; $i <= $to; $i++) {
1693 my $entry = $taglist->[$i];
1695 my $curr = $tag{'id'} eq $head;
1697 print "<tr class=\"dark\">\n";
1699 print "<tr class=\"light\">\n";
1702 print "<td><i>$tag{'age'}</i></td>\n" .
1703 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1704 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
1705 -class => "list name"},esc_html
($tag{'name'})) .
1707 "<td class=\"link\">" .
1708 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
1709 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") .
1713 if (defined $extra) {
1715 "<td colspan=\"3\">$extra</td>\n" .
1721 ## ----------------------------------------------------------------------
1722 ## functions printing large fragments, format as one of arguments
1724 sub git_diff_print
{
1726 my $from_name = shift;
1728 my $to_name = shift;
1729 my $format = shift || "html";
1731 my $from_tmp = "/dev/null";
1732 my $to_tmp = "/dev/null";
1735 # create tmp from-file
1736 if (defined $from) {
1737 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1738 open my $fd2, "> $from_tmp";
1739 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1746 # create tmp to-file
1748 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1749 open my $fd2, "> $to_tmp";
1750 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1757 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1758 if ($format eq "plain") {
1763 while (my $line = <$fd>) {
1765 my $char = substr($line, 0, 1);
1766 my $diff_class = "";
1768 $diff_class = " add";
1769 } elsif ($char eq "-") {
1770 $diff_class = " rem";
1771 } elsif ($char eq "@") {
1772 $diff_class = " chunk_header";
1773 } elsif ($char eq "\\") {
1777 $line = untabify
($line);
1778 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
1783 if (defined $from) {
1792 ## ======================================================================
1793 ## ======================================================================
1796 sub git_project_list
{
1797 my $order = $cgi->param('o');
1798 if (defined $order && $order !~ m/project|descr|owner|age/) {
1799 die_error
(undef, "Unknown order parameter");
1802 my @list = git_get_projects_list
();
1805 die_error
(undef, "No projects found");
1807 foreach my $pr (@list) {
1808 my $head = git_get_head_hash
($pr->{'path'});
1809 if (!defined $head) {
1812 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1813 my %co = parse_commit
($head);
1817 $pr->{'commit'} = \
%co;
1818 if (!defined $pr->{'descr'}) {
1819 my $descr = git_get_project_description
($pr->{'path'}) || "";
1820 $pr->{'descr'} = chop_str
($descr, 25, 5);
1822 if (!defined $pr->{'owner'}) {
1823 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
1825 push @projects, $pr;
1829 if (-f
$home_text) {
1830 print "<div class=\"index_include\">\n";
1831 open (my $fd, $home_text);
1836 print "<table class=\"project_list\">\n" .
1838 $order ||= "project";
1839 if ($order eq "project") {
1840 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1841 print "<th>Project</th>\n";
1844 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
1845 -class => "header"}, "Project") .
1848 if ($order eq "descr") {
1849 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1850 print "<th>Description</th>\n";
1853 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
1854 -class => "header"}, "Description") .
1857 if ($order eq "owner") {
1858 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1859 print "<th>Owner</th>\n";
1862 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
1863 -class => "header"}, "Owner") .
1866 if ($order eq "age") {
1867 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1868 print "<th>Last Change</th>\n";
1871 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
1872 -class => "header"}, "Last Change") .
1875 print "<th></th>\n" .
1878 foreach my $pr (@projects) {
1880 print "<tr class=\"dark\">\n";
1882 print "<tr class=\"light\">\n";
1885 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
1886 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
1887 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
1888 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
1889 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
1890 $pr->{'commit'}{'age_string'} . "</td>\n" .
1891 "<td class=\"link\">" .
1892 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
1893 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
1894 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") .
1903 my $descr = git_get_project_description
($project) || "none";
1904 my $head = git_get_head_hash
($project);
1905 my %co = parse_commit
($head);
1906 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
1908 my $owner = git_get_project_owner
($project);
1910 my $refs = git_get_references
();
1912 git_print_page_nav
('summary','', $head);
1914 print "<div class=\"title\"> </div>\n";
1915 print "<table cellspacing=\"0\">\n" .
1916 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1917 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1918 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
1919 # use per project git URL list in $projectroot/$project/cloneurl
1920 # or make project git URL from git base URL and project name
1921 my $url_tag = "URL";
1922 my @url_list = git_get_project_url_list
($project);
1923 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
1924 foreach my $git_url (@url_list) {
1925 next unless $git_url;
1926 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
1931 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash
($project)
1932 or die_error
(undef, "Open git-rev-list failed");
1933 my @revlist = map { chomp; $_ } <$fd>;
1935 git_print_header_div
('shortlog');
1936 git_shortlog_body
(\
@revlist, 0, 15, $refs,
1937 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
1939 my $taglist = git_get_refs_list
("refs/tags");
1940 if (defined @
$taglist) {
1941 git_print_header_div
('tags');
1942 git_tags_body
($taglist, 0, 15,
1943 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
1946 my $headlist = git_get_refs_list
("refs/heads");
1947 if (defined @
$headlist) {
1948 git_print_header_div
('heads');
1949 git_heads_body
($headlist, $head, 0, 15,
1950 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
1957 my $head = git_get_head_hash
($project);
1959 git_print_page_nav
('','', $head,undef,$head);
1960 my %tag = parse_tag
($hash);
1961 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
1962 print "<div class=\"title_text\">\n" .
1963 "<table cellspacing=\"0\">\n" .
1965 "<td>object</td>\n" .
1966 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
1967 $tag{'object'}) . "</td>\n" .
1968 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
1969 $tag{'type'}) . "</td>\n" .
1971 if (defined($tag{'author'})) {
1972 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
1973 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1974 print "<tr><td></td><td>" . $ad{'rfc2822'} .
1975 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
1978 print "</table>\n\n" .
1980 print "<div class=\"page_body\">";
1981 my $comment = $tag{'comment'};
1982 foreach my $line (@
$comment) {
1983 print esc_html
($line) . "<br/>\n";
1993 if (!gitweb_check_feature
('blame')) {
1994 die_error
('403 Permission denied', "Permission denied");
1996 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1997 $hash_base ||= git_get_head_hash
($project);
1998 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
1999 my %co = parse_commit
($hash_base)
2000 or die_error
(undef, "Reading commit failed");
2001 if (!defined $hash) {
2002 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2003 or die_error
(undef, "Error looking up file");
2005 $ftype = git_get_type
($hash);
2006 if ($ftype !~ "blob") {
2007 die_error
("400 Bad Request", "Object is not a blob");
2009 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
2010 or die_error
(undef, "Open git-blame failed");
2013 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2016 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2018 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2019 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2020 git_print_page_path
($file_name, $ftype, $hash_base);
2021 my @rev_color = (qw(light2 dark2));
2022 my $num_colors = scalar(@rev_color);
2023 my $current_color = 0;
2025 print "<div class=\"page_body\">\n";
2026 print "<table class=\"blame\">\n";
2027 print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
2029 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2031 my $rev = substr($full_rev, 0, 8);
2035 if (!defined $last_rev) {
2036 $last_rev = $full_rev;
2037 } elsif ($last_rev ne $full_rev) {
2038 $last_rev = $full_rev;
2039 $current_color = ++$current_color % $num_colors;
2041 print "<tr class=\"$rev_color[$current_color]\">\n";
2042 print "<td class=\"sha1\">" .
2043 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)},
2044 esc_html
($rev)) . "</td>\n";
2045 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2046 esc_html
($lineno) . "</a></td>\n";
2047 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2053 or print "Reading blob failed\n";
2060 if (!gitweb_check_feature
('blame')) {
2061 die_error
('403 Permission denied', "Permission denied");
2063 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2064 $hash_base ||= git_get_head_hash
($project);
2065 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2066 my %co = parse_commit
($hash_base)
2067 or die_error
(undef, "Reading commit failed");
2068 if (!defined $hash) {
2069 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2070 or die_error
(undef, "Error lookup file");
2072 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2073 or die_error
(undef, "Open git-annotate failed");
2076 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2079 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2081 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2082 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2083 git_print_page_path
($file_name, 'blob', $hash_base);
2084 print "<div class=\"page_body\">\n";
2086 <table class="blame">
2095 my @line_class = (qw(light dark));
2096 my $line_class_len = scalar (@line_class);
2097 my $line_class_num = $#line_class;
2098 while (my $line = <$fd>) {
2110 $line_class_num = ($line_class_num + 1) % $line_class_len;
2112 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
2119 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2122 $short_rev = substr ($long_rev, 0, 8);
2123 $age = time () - $time;
2124 $age_str = age_string
($age);
2125 $age_str =~ s/ / /g;
2126 $age_class = age_class
($age);
2127 $author = esc_html
($author);
2128 $author =~ s/ / /g;
2130 $data = untabify
($data);
2131 $data = esc_html
($data);
2134 <tr class="$line_class[$line_class_num]">
2135 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2136 <td class="$age_class">$age_str</td>
2138 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2139 <td class="pre">$data</td>
2142 } # while (my $line = <$fd>)
2143 print "</table>\n\n";
2145 or print "Reading blob failed.\n";
2151 my $head = git_get_head_hash
($project);
2153 git_print_page_nav
('','', $head,undef,$head);
2154 git_print_header_div
('summary', $project);
2156 my $taglist = git_get_refs_list
("refs/tags");
2157 if (defined @
$taglist) {
2158 git_tags_body
($taglist);
2164 my $head = git_get_head_hash
($project);
2166 git_print_page_nav
('','', $head,undef,$head);
2167 git_print_header_div
('summary', $project);
2169 my $taglist = git_get_refs_list
("refs/heads");
2170 if (defined @
$taglist) {
2171 git_heads_body
($taglist, $head);
2176 sub git_blob_plain
{
2177 if (!defined $hash) {
2178 if (defined $file_name) {
2179 my $base = $hash_base || git_get_head_hash
($project);
2180 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2181 or die_error
(undef, "Error lookup file");
2183 die_error
(undef, "No file name defined");
2187 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2188 or die_error
(undef, "Couldn't cat $file_name, $hash");
2190 $type ||= blob_mimetype
($fd, $file_name);
2192 # save as filename, even when no $file_name is given
2193 my $save_as = "$hash";
2194 if (defined $file_name) {
2195 $save_as = $file_name;
2196 } elsif ($type =~ m/^text\//) {
2200 print $cgi->header(-type
=> "$type",
2201 -content_disposition
=> "inline; filename=\"$save_as\"");
2203 binmode STDOUT
, ':raw';
2205 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2211 if (!defined $hash) {
2212 if (defined $file_name) {
2213 my $base = $hash_base || git_get_head_hash
($project);
2214 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2215 or die_error
(undef, "Error lookup file");
2217 die_error
(undef, "No file name defined");
2220 my $have_blame = gitweb_check_feature
('blame');
2221 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2222 or die_error
(undef, "Couldn't cat $file_name, $hash");
2223 my $mimetype = blob_mimetype
($fd, $file_name);
2224 if ($mimetype !~ m/^text\//) {
2226 return git_blob_plain
($mimetype);
2229 my $formats_nav = '';
2230 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2231 if (defined $file_name) {
2234 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2235 hash
=>$hash, file_name
=>$file_name)},
2240 $cgi->a({-href
=> href
(action
=>"blob_plain",
2241 hash
=>$hash, file_name
=>$file_name)},
2244 $cgi->a({-href
=> href
(action
=>"blob",
2245 hash_base
=>"HEAD", file_name
=>$file_name)},
2249 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "plain");
2251 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2252 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2254 print "<div class=\"page_nav\">\n" .
2255 "<br/><br/></div>\n" .
2256 "<div class=\"title\">$hash</div>\n";
2258 git_print_page_path
($file_name, "blob", $hash_base);
2259 print "<div class=\"page_body\">\n";
2261 while (my $line = <$fd>) {
2264 $line = untabify
($line);
2265 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2266 $nr, $nr, $nr, esc_html
($line);
2269 or print "Reading blob failed.\n";
2275 if (!defined $hash) {
2276 $hash = git_get_head_hash
($project);
2277 if (defined $file_name) {
2278 my $base = $hash_base || $hash;
2279 $hash = git_get_hash_by_path
($base, $file_name, "tree");
2281 if (!defined $hash_base) {
2286 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
2287 or die_error
(undef, "Open git-ls-tree failed");
2288 my @entries = map { chomp; $_ } <$fd>;
2289 close $fd or die_error
(undef, "Reading tree failed");
2292 my $refs = git_get_references
();
2293 my $ref = format_ref_marker
($refs, $hash_base);
2297 my $have_blame = gitweb_check_feature
('blame');
2298 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2299 $base_key{hash_base
} = $hash_base;
2300 git_print_page_nav
('tree','', $hash_base);
2301 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2303 print "<div class=\"page_nav\">\n";
2304 print "<br/><br/></div>\n";
2305 print "<div class=\"title\">$hash</div>\n";
2307 if (defined $file_name) {
2308 $base = esc_html
("$file_name/");
2310 git_print_page_path
($file_name, 'tree', $hash_base);
2311 print "<div class=\"page_body\">\n";
2312 print "<table cellspacing=\"0\">\n";
2314 foreach my $line (@entries) {
2315 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2316 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2320 my $t_name = validate_input
($4);
2322 print "<tr class=\"dark\">\n";
2324 print "<tr class=\"light\">\n";
2327 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
2328 if ($t_type eq "blob") {
2329 print "<td class=\"list\">" .
2330 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key),
2331 -class => "list"}, esc_html
($t_name)) .
2333 "<td class=\"link\">" .
2334 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2338 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2342 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2343 hash
=>$t_hash, file_name
=>"$base$t_name")},
2346 $cgi->a({-href
=> href
(action
=>"blob_plain",
2347 hash
=>$t_hash, file_name
=>"$base$t_name")},
2350 } elsif ($t_type eq "tree") {
2351 print "<td class=\"list\">" .
2352 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2353 esc_html
($t_name)) .
2355 "<td class=\"link\">" .
2356 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2359 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base, file_name
=>"$base$t_name")},
2365 print "</table>\n" .
2372 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2373 my $have_snapshot = (defined $ctype && defined $suffix);
2374 if (!$have_snapshot) {
2375 die_error
('403 Permission denied', "Permission denied");
2378 if (!defined $hash) {
2379 $hash = git_get_head_hash
($project);
2382 my $filename = basename
($project) . "-$hash.tar.$suffix";
2384 print $cgi->header(-type
=> 'application/x-tar',
2385 -content_encoding
=> $ctype,
2386 -content_disposition
=> "inline; filename=\"$filename\"",
2387 -status
=> '200 OK');
2389 open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | $command" or
2390 die_error
(undef, "Execute git-tar-tree failed.");
2391 binmode STDOUT
, ':raw';
2393 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2399 my $head = git_get_head_hash
($project);
2400 if (!defined $hash) {
2403 if (!defined $page) {
2406 my $refs = git_get_references
();
2408 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2409 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2410 or die_error
(undef, "Open git-rev-list failed");
2411 my @revlist = map { chomp; $_ } <$fd>;
2414 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2417 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2420 my %co = parse_commit
($hash);
2422 git_print_header_div
('summary', $project);
2423 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2425 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2426 my $commit = $revlist[$i];
2427 my $ref = format_ref_marker
($refs, $commit);
2428 my %co = parse_commit
($commit);
2430 my %ad = parse_date
($co{'author_epoch'});
2431 git_print_header_div
('commit',
2432 "<span class=\"age\">$co{'age_string'}</span>" .
2433 esc_html
($co{'title'}) . $ref,
2435 print "<div class=\"title_text\">\n" .
2436 "<div class=\"log_link\">\n" .
2437 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2439 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2442 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2445 print "<div class=\"log_body\">\n";
2446 git_print_simplified_log
($co{'comment'});
2453 my %co = parse_commit
($hash);
2455 die_error
(undef, "Unknown commit object");
2457 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2458 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2460 my $parent = $co{'parent'};
2461 if (!defined $parent) {
2464 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
2465 or die_error
(undef, "Open git-diff-tree failed");
2466 my @difftree = map { chomp; $_ } <$fd>;
2467 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2469 # non-textual hash id's can be cached
2471 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2474 my $refs = git_get_references
();
2475 my $ref = format_ref_marker
($refs, $co{'id'});
2477 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2478 my $have_snapshot = (defined $ctype && defined $suffix);
2480 my $formats_nav = '';
2481 if (defined $file_name && defined $co{'parent'}) {
2482 my $parent = $co{'parent'};
2484 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
2487 git_header_html
(undef, $expires);
2488 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
2489 $hash, $co{'tree'}, $hash,
2492 if (defined $co{'parent'}) {
2493 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2495 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
2497 print "<div class=\"title_text\">\n" .
2498 "<table cellspacing=\"0\">\n";
2499 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2501 "<td></td><td> $ad{'rfc2822'}";
2502 if ($ad{'hour_local'} < 6) {
2503 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2504 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2506 printf(" (%02d:%02d %s)",
2507 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2511 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2512 print "<tr><td></td><td> $cd{'rfc2822'}" .
2513 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2515 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2518 "<td class=\"sha1\">" .
2519 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
2520 class => "list"}, $co{'tree'}) .
2522 "<td class=\"link\">" .
2523 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
2525 if ($have_snapshot) {
2527 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
2531 my $parents = $co{'parents'};
2532 foreach my $par (@
$parents) {
2535 "<td class=\"sha1\">" .
2536 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
2537 class => "list"}, $par) .
2539 "<td class=\"link\">" .
2540 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
2542 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "commitdiff") .
2549 print "<div class=\"page_body\">\n";
2550 git_print_log
($co{'comment'});
2553 git_difftree_body
(\
@difftree, $parent);
2559 mkdir($git_temp, 0700);
2561 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2563 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
2564 hash
=>$hash, hash_parent
=>$hash_parent)},
2566 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2567 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2569 print "<div class=\"page_nav\">\n" .
2570 "<br/><br/></div>\n" .
2571 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2573 git_print_page_path
($file_name, "blob", $hash_base);
2574 print "<div class=\"page_body\">\n" .
2575 "<div class=\"diff_info\">blob:" .
2576 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash_parent,
2577 hash_base
=>$hash_base, file_name
=>($file_parent || $file_name))},
2580 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash,
2581 hash_base
=>$hash_base, file_name
=>$file_name)},
2584 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2585 print "</div>"; # page_body
2589 sub git_blobdiff_plain
{
2590 mkdir($git_temp, 0700);
2591 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2592 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2595 sub git_commitdiff
{
2596 mkdir($git_temp, 0700);
2597 my %co = parse_commit
($hash);
2599 die_error
(undef, "Unknown commit object");
2601 if (!defined $hash_parent) {
2602 $hash_parent = $co{'parent'} || '--root';
2604 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2605 or die_error
(undef, "Open git-diff-tree failed");
2606 my @difftree = map { chomp; $_ } <$fd>;
2607 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2609 # non-textual hash id's can be cached
2611 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2614 my $refs = git_get_references
();
2615 my $ref = format_ref_marker
($refs, $co{'id'});
2617 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", hash
=>$hash, hash_parent
=>$hash_parent)},
2619 git_header_html
(undef, $expires);
2620 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2621 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2622 print "<div class=\"page_body\">\n";
2623 git_print_simplified_log
($co{'comment'}, 1); # skip title
2625 foreach my $line (@difftree) {
2626 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2627 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2628 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2636 my $file = validate_input
(unquote
($6));
2637 if ($status eq "A") {
2638 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2639 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2640 hash
=>$to_id, file_name
=>$file)},
2643 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2644 } elsif ($status eq "D") {
2645 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2646 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2647 hash
=>$from_id, file_name
=>$file)},
2648 $from_id) . "(deleted)" .
2650 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2651 } elsif ($status eq "M") {
2652 if ($from_id ne $to_id) {
2653 print "<div class=\"diff_info\">" .
2654 file_type
($from_mode) . ":" .
2655 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2656 hash
=>$from_id, file_name
=>$file)},
2659 file_type
($to_mode) . ":" .
2660 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2661 hash
=>$to_id, file_name
=>$file)},
2664 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2673 sub git_commitdiff_plain
{
2674 mkdir($git_temp, 0700);
2675 my %co = parse_commit
($hash);
2677 die_error
(undef, "Unknown commit object");
2679 if (!defined $hash_parent) {
2680 $hash_parent = $co{'parent'} || '--root';
2682 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2683 or die_error
(undef, "Open git-diff-tree failed");
2684 my @difftree = map { chomp; $_ } <$fd>;
2685 close $fd or die_error
(undef, "Reading diff-tree failed");
2687 # try to figure out the next tag after this commit
2689 my $refs = git_get_references
("tags");
2690 open $fd, "-|", $GIT, "rev-list", "HEAD";
2691 my @commits = map { chomp; $_ } <$fd>;
2693 foreach my $commit (@commits) {
2694 if (defined $refs->{$commit}) {
2695 $tagname = $refs->{$commit}
2697 if ($commit eq $hash) {
2702 print $cgi->header(-type
=> "text/plain",
2703 -charset
=> 'utf-8',
2704 -content_disposition
=> "inline; filename=\"git-$hash.patch\"");
2705 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2706 my $comment = $co{'comment'};
2707 print "From: $co{'author'}\n" .
2708 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2709 "Subject: $co{'title'}\n";
2710 if (defined $tagname) {
2711 print "X-Git-Tag: $tagname\n";
2713 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2716 foreach my $line (@
$comment) {;
2721 foreach my $line (@difftree) {
2722 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2729 if ($status eq "A") {
2730 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2731 } elsif ($status eq "D") {
2732 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2733 } elsif ($status eq "M") {
2734 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2740 if (!defined $hash_base) {
2741 $hash_base = git_get_head_hash
($project);
2744 my %co = parse_commit
($hash_base);
2746 die_error
(undef, "Unknown commit object");
2748 my $refs = git_get_references
();
2750 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2751 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2752 if (!defined $hash && defined $file_name) {
2753 $hash = git_get_hash_by_path
($hash_base, $file_name);
2755 if (defined $hash) {
2756 $ftype = git_get_type
($hash);
2758 git_print_page_path
($file_name, $ftype, $hash_base);
2761 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2762 git_history_body
($fd, $refs, $hash_base, $ftype);
2769 if (!defined $searchtext) {
2770 die_error
(undef, "Text field empty");
2772 if (!defined $hash) {
2773 $hash = git_get_head_hash
($project);
2775 my %co = parse_commit
($hash);
2777 die_error
(undef, "Unknown commit object");
2779 # pickaxe may take all resources of your box and run for several minutes
2780 # with every query - so decide by yourself how public you make this feature :)
2781 my $commit_search = 1;
2782 my $author_search = 0;
2783 my $committer_search = 0;
2784 my $pickaxe_search = 0;
2785 if ($searchtext =~ s/^author\\://i) {
2787 } elsif ($searchtext =~ s/^committer\\://i) {
2788 $committer_search = 1;
2789 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2791 $pickaxe_search = 1;
2794 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
2795 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
2797 print "<table cellspacing=\"0\">\n";
2799 if ($commit_search) {
2801 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2802 while (my $commit_text = <$fd>) {
2803 if (!grep m/$searchtext/i, $commit_text) {
2806 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2809 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2812 my @commit_lines = split "\n", $commit_text;
2813 my %co = parse_commit
(undef, \
@commit_lines);
2818 print "<tr class=\"dark\">\n";
2820 print "<tr class=\"light\">\n";
2823 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2824 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2826 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
2827 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
2828 my $comment = $co{'comment'};
2829 foreach my $line (@
$comment) {
2830 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2831 my $lead = esc_html
($1) || "";
2832 $lead = chop_str
($lead, 30, 10);
2833 my $match = esc_html
($2) || "";
2834 my $trail = esc_html
($3) || "";
2835 $trail = chop_str
($trail, 30, 10);
2836 my $text = "$lead<span class=\"match\">$match</span>$trail";
2837 print chop_str
($text, 80, 5) . "<br/>\n";
2841 "<td class=\"link\">" .
2842 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
2844 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
2851 if ($pickaxe_search) {
2853 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2856 while (my $line = <$fd>) {
2857 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2860 $set{'from_id'} = $3;
2862 $set{'id'} = $set{'to_id'};
2863 if ($set{'id'} =~ m/0{40}/) {
2864 $set{'id'} = $set{'from_id'};
2866 if ($set{'id'} =~ m/0{40}/) {
2870 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2873 print "<tr class=\"dark\">\n";
2875 print "<tr class=\"light\">\n";
2878 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2879 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2881 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
2882 -class => "list subject"},
2883 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
2884 while (my $setref = shift @files) {
2886 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
2887 hash
=>$set{'id'}, file_name
=>$set{'file'}),
2889 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2893 "<td class=\"link\">" .
2894 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
2896 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
2900 %co = parse_commit
($1);
2910 my $head = git_get_head_hash
($project);
2911 if (!defined $hash) {
2914 if (!defined $page) {
2917 my $refs = git_get_references
();
2919 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2920 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2921 or die_error
(undef, "Open git-rev-list failed");
2922 my @revlist = map { chomp; $_ } <$fd>;
2925 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
2927 if ($#revlist >= (100 * ($page+1)-1)) {
2929 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
2930 -title
=> "Alt-n"}, "next");
2935 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
2936 git_print_header_div
('summary', $project);
2938 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
2943 ## ......................................................................
2944 ## feeds (RSS, OPML)
2947 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
2948 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash
($project)
2949 or die_error
(undef, "Open git-rev-list failed");
2950 my @revlist = map { chomp; $_ } <$fd>;
2951 close $fd or die_error
(undef, "Reading git-rev-list failed");
2952 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2953 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2954 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
2955 print "<channel>\n";
2956 print "<title>$project</title>\n".
2957 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
2958 "<description>$project log</description>\n".
2959 "<language>en</language>\n";
2961 for (my $i = 0; $i <= $#revlist; $i++) {
2962 my $commit = $revlist[$i];
2963 my %co = parse_commit
($commit);
2964 # we read 150, we always show 30 and the ones more recent than 48 hours
2965 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
2968 my %cd = parse_date
($co{'committer_epoch'});
2969 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
2970 my @difftree = map { chomp; $_ } <$fd>;
2974 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
2976 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
2977 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
2978 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
2979 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
2980 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
2981 "<content:encoded>" .
2983 my $comment = $co{'comment'};
2984 foreach my $line (@
$comment) {
2985 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
2986 print "$line<br/>\n";
2989 foreach my $line (@difftree) {
2990 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2993 my $file = validate_input
(unquote
($7));
2994 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
2995 print "$file<br/>\n";
2998 "</content:encoded>\n" .
3001 print "</channel></rss>";
3005 my @list = git_get_projects_list
();
3007 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3008 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
3009 "<opml version=\"1.0\">\n".
3011 " <title>$site_name Git OPML Export</title>\n".
3014 "<outline text=\"git RSS feeds\">\n";
3016 foreach my $pr (@list) {
3018 my $head = git_get_head_hash
($proj{'path'});
3019 if (!defined $head) {
3022 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
3023 my %co = parse_commit
($head);
3028 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3029 my $rss = "$my_url?p=$proj{'path'};a=rss";
3030 my $html = "$my_url?p=$proj{'path'};a=summary";
3031 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
3033 print "</outline>\n".