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 defined $params{$_} ?
"$mapping{$_}=$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);
1189 <div class="page_body">
1199 ## ----------------------------------------------------------------------
1200 ## functions printing or outputting HTML: navigation
1202 sub git_print_page_nav
{
1203 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1204 $extra = '' if !defined $extra; # pager or formats
1206 my @navs = qw(summary shortlog log commit commitdiff tree);
1208 @navs = grep { $_ ne $suppress } @navs;
1211 my %arg = map { $_ => {action
=>$_} } @navs;
1212 if (defined $head) {
1213 for (qw(commit commitdiff)) {
1214 $arg{$_}{hash
} = $head;
1216 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1217 for (qw(shortlog log)) {
1218 $arg{$_}{hash
} = $head;
1222 $arg{tree
}{hash
} = $treehead if defined $treehead;
1223 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1225 print "<div class=\"page_nav\">\n" .
1227 map { $_ eq $current ?
1228 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1230 print "<br/>\n$extra<br/>\n" .
1234 sub format_paging_nav
{
1235 my ($action, $hash, $head, $page, $nrevs) = @_;
1239 if ($hash ne $head || $page) {
1240 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1242 $paging_nav .= "HEAD";
1246 $paging_nav .= " ⋅ " .
1247 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1248 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1250 $paging_nav .= " ⋅ prev";
1253 if ($nrevs >= (100 * ($page+1)-1)) {
1254 $paging_nav .= " ⋅ " .
1255 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1256 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1258 $paging_nav .= " ⋅ next";
1264 ## ......................................................................
1265 ## functions printing or outputting HTML: div
1267 sub git_print_header_div
{
1268 my ($action, $title, $hash, $hash_base) = @_;
1271 $args{action
} = $action;
1272 $args{hash
} = $hash if $hash;
1273 $args{hash_base
} = $hash_base if $hash_base;
1275 print "<div class=\"header\">\n" .
1276 $cgi->a({-href
=> href
(%args), -class => "title"},
1277 $title ?
$title : $action) .
1281 sub git_print_page_path
{
1286 if (!defined $name) {
1287 print "<div class=\"page_path\">/</div>\n";
1288 } elsif (defined $type && $type eq 'blob') {
1289 print "<div class=\"page_path\">";
1291 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1295 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name)},
1298 print "<br/></div>\n";
1300 print "<div class=\"page_path\">" . esc_html
($name) . "<br/></div>\n";
1307 # remove leading empty lines
1308 while (defined $log->[0] && $log->[0] eq "") {
1315 foreach my $line (@
$log) {
1316 # print only one empty line
1317 # do not print empty line after signoff
1319 next if ($empty || $signoff);
1324 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1326 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1329 print format_log_line_html
($line) . "<br/>\n";
1334 sub git_print_simplified_log
{
1336 my $remove_title = shift;
1338 shift @
$log if $remove_title;
1339 # remove leading empty lines
1340 while (defined $log->[0] && $log->[0] eq "") {
1344 # simplify and print log
1346 foreach my $line (@
$log) {
1347 # remove signoff lines
1348 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1351 # print only one empty line
1358 print format_log_line_html
($line) . "<br/>\n";
1360 # end with single empty line
1361 print "<br/>\n" unless $empty;
1364 ## ......................................................................
1365 ## functions printing large fragments of HTML
1367 sub git_difftree_body
{
1368 my ($difftree, $parent) = @_;
1370 print "<div class=\"list_head\">\n";
1371 if ($#{$difftree} > 10) {
1372 print(($#{$difftree} + 1) . " files changed:\n");
1376 print "<table class=\"diff_tree\">\n";
1378 foreach my $line (@
{$difftree}) {
1379 my %diff = parse_difftree_raw_line
($line);
1382 print "<tr class=\"dark\">\n";
1384 print "<tr class=\"light\">\n";
1388 my ($to_mode_oct, $to_mode_str, $to_file_type);
1389 my ($from_mode_oct, $from_mode_str, $from_file_type);
1390 if ($diff{'to_mode'} ne ('0' x
6)) {
1391 $to_mode_oct = oct $diff{'to_mode'};
1392 if (S_ISREG
($to_mode_oct)) { # only for regular file
1393 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1395 $to_file_type = file_type
($diff{'to_mode'});
1397 if ($diff{'from_mode'} ne ('0' x
6)) {
1398 $from_mode_oct = oct $diff{'from_mode'};
1399 if (S_ISREG
($to_mode_oct)) { # only for regular file
1400 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1402 $from_file_type = file_type
($diff{'from_mode'});
1405 if ($diff{'status'} eq "A") { # created
1406 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1407 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1408 $mode_chng .= "]</span>";
1410 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1411 hash_base
=>$hash, file_name
=>$diff{'file'}),
1412 -class => "list"}, esc_html
($diff{'file'})) .
1414 "<td>$mode_chng</td>\n" .
1415 "<td class=\"link\">" .
1416 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1417 hash_base
=>$hash, file_name
=>$diff{'file'})},
1421 } elsif ($diff{'status'} eq "D") { # deleted
1422 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1424 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1425 hash_base
=>$parent, file_name
=>$diff{'file'}),
1426 -class => "list"}, esc_html
($diff{'file'})) .
1428 "<td>$mode_chng</td>\n" .
1429 "<td class=\"link\">" .
1430 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1431 hash_base
=>$parent, file_name
=>$diff{'file'})},
1434 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1435 file_name
=>$diff{'file'})},\
1439 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1440 my $mode_chnge = "";
1441 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1442 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1443 if ($from_file_type != $to_file_type) {
1444 $mode_chnge .= " from $from_file_type to $to_file_type";
1446 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1447 if ($from_mode_str && $to_mode_str) {
1448 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1449 } elsif ($to_mode_str) {
1450 $mode_chnge .= " mode: $to_mode_str";
1453 $mode_chnge .= "]</span>\n";
1456 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1457 print $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1458 hash_base
=>$hash, file_name
=>$diff{'file'}),
1459 -class => "list"}, esc_html
($diff{'file'}));
1460 } else { # only mode changed
1461 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1462 hash_base
=>$hash, file_name
=>$diff{'file'}),
1463 -class => "list"}, esc_html
($diff{'file'}));
1466 "<td>$mode_chnge</td>\n" .
1467 "<td class=\"link\">" .
1468 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1469 hash_base
=>$hash, file_name
=>$diff{'file'})},
1471 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1473 $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1474 hash_base
=>$hash, file_name
=>$diff{'file'})},
1478 $cgi->a({-href
=> href
(action
=>"history",
1479 hash_base
=>$hash, file_name
=>$diff{'file'})},
1483 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1484 my %status_name = ('R' => 'moved', 'C' => 'copied');
1485 my $nstatus = $status_name{$diff{'status'}};
1487 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1488 # mode also for directories, so we cannot use $to_mode_str
1489 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1492 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1493 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1494 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1495 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1496 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1497 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1498 -class => "list"}, esc_html
($diff{'from_file'})) .
1499 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1500 "<td class=\"link\">" .
1501 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1502 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'})},
1504 if ($diff{'to_id'} ne $diff{'from_id'}) {
1506 $cgi->a({-href
=> href
(action
=>"blobdiff", hash_base
=>$hash,
1507 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1508 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1513 } # we should not encounter Unmerged (U) or Unknown (X) status
1519 sub git_shortlog_body
{
1520 # uses global variable $project
1521 my ($revlist, $from, $to, $refs, $extra) = @_;
1523 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
1524 my $have_snapshot = (defined $ctype && defined $suffix);
1526 $from = 0 unless defined $from;
1527 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1529 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1531 for (my $i = $from; $i <= $to; $i++) {
1532 my $commit = $revlist->[$i];
1533 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1534 my $ref = format_ref_marker
($refs, $commit);
1535 my %co = parse_commit
($commit);
1537 print "<tr class=\"dark\">\n";
1539 print "<tr class=\"light\">\n";
1542 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1543 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1544 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1546 print format_subject_html
($co{'title'}, $co{'title_short'},
1547 href
(action
=>"commit", hash
=>$commit), $ref);
1549 "<td class=\"link\">" .
1550 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1551 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
1552 if ($have_snapshot) {
1553 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
1558 if (defined $extra) {
1560 "<td colspan=\"4\">$extra</td>\n" .
1566 sub git_history_body
{
1567 # Warning: assumes constant type (blob or tree) during history
1568 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1570 print "<table class=\"history\" cellspacing=\"0\">\n";
1572 while (my $line = <$fd>) {
1573 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1578 my %co = parse_commit
($commit);
1583 my $ref = format_ref_marker
($refs, $commit);
1586 print "<tr class=\"dark\">\n";
1588 print "<tr class=\"light\">\n";
1591 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1592 # shortlog uses chop_str($co{'author_name'}, 10)
1593 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1595 # originally git_history used chop_str($co{'title'}, 50)
1596 print format_subject_html
($co{'title'}, $co{'title_short'},
1597 href
(action
=>"commit", hash
=>$commit), $ref);
1599 "<td class=\"link\">" .
1600 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1601 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
1602 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype);
1604 if ($ftype eq 'blob') {
1605 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
1606 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
1607 if (defined $blob_current && defined $blob_parent &&
1608 $blob_current ne $blob_parent) {
1610 $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$blob_current, hash_parent
=>$blob_parent,
1611 hash_base
=>$commit, file_name
=>$file_name)},
1618 if (defined $extra) {
1620 "<td colspan=\"4\">$extra</td>\n" .
1627 # uses global variable $project
1628 my ($taglist, $from, $to, $extra) = @_;
1629 $from = 0 unless defined $from;
1630 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1632 print "<table class=\"tags\" cellspacing=\"0\">\n";
1634 for (my $i = $from; $i <= $to; $i++) {
1635 my $entry = $taglist->[$i];
1637 my $comment_lines = $tag{'comment'};
1638 my $comment = shift @
$comment_lines;
1640 if (defined $comment) {
1641 $comment_short = chop_str
($comment, 30, 5);
1644 print "<tr class=\"dark\">\n";
1646 print "<tr class=\"light\">\n";
1649 print "<td><i>$tag{'age'}</i></td>\n" .
1651 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
1652 -class => "list name"}, esc_html
($tag{'name'})) .
1655 if (defined $comment) {
1656 print format_subject_html
($comment, $comment_short,
1657 href
(action
=>"tag", hash
=>$tag{'id'}));
1660 "<td class=\"selflink\">";
1661 if ($tag{'type'} eq "tag") {
1662 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
1667 "<td class=\"link\">" . " | " .
1668 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
1669 if ($tag{'reftype'} eq "commit") {
1670 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
1671 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
1672 } elsif ($tag{'reftype'} eq "blob") {
1673 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
1678 if (defined $extra) {
1680 "<td colspan=\"5\">$extra</td>\n" .
1686 sub git_heads_body
{
1687 # uses global variable $project
1688 my ($taglist, $head, $from, $to, $extra) = @_;
1689 $from = 0 unless defined $from;
1690 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1692 print "<table class=\"heads\" cellspacing=\"0\">\n";
1694 for (my $i = $from; $i <= $to; $i++) {
1695 my $entry = $taglist->[$i];
1697 my $curr = $tag{'id'} eq $head;
1699 print "<tr class=\"dark\">\n";
1701 print "<tr class=\"light\">\n";
1704 print "<td><i>$tag{'age'}</i></td>\n" .
1705 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1706 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
1707 -class => "list name"},esc_html
($tag{'name'})) .
1709 "<td class=\"link\">" .
1710 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
1711 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") .
1715 if (defined $extra) {
1717 "<td colspan=\"3\">$extra</td>\n" .
1723 ## ----------------------------------------------------------------------
1724 ## functions printing large fragments, format as one of arguments
1726 sub git_diff_print
{
1728 my $from_name = shift;
1730 my $to_name = shift;
1731 my $format = shift || "html";
1733 my $from_tmp = "/dev/null";
1734 my $to_tmp = "/dev/null";
1737 # create tmp from-file
1738 if (defined $from) {
1739 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1740 open my $fd2, "> $from_tmp";
1741 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1748 # create tmp to-file
1750 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1751 open my $fd2, "> $to_tmp";
1752 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1759 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1760 if ($format eq "plain") {
1765 while (my $line = <$fd>) {
1767 my $char = substr($line, 0, 1);
1768 my $diff_class = "";
1770 $diff_class = " add";
1771 } elsif ($char eq "-") {
1772 $diff_class = " rem";
1773 } elsif ($char eq "@") {
1774 $diff_class = " chunk_header";
1775 } elsif ($char eq "\\") {
1779 $line = untabify
($line);
1780 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
1785 if (defined $from) {
1794 ## ======================================================================
1795 ## ======================================================================
1798 sub git_project_list
{
1799 my $order = $cgi->param('o');
1800 if (defined $order && $order !~ m/project|descr|owner|age/) {
1801 die_error
(undef, "Unknown order parameter");
1804 my @list = git_get_projects_list
();
1807 die_error
(undef, "No projects found");
1809 foreach my $pr (@list) {
1810 my $head = git_get_head_hash
($pr->{'path'});
1811 if (!defined $head) {
1814 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1815 my %co = parse_commit
($head);
1819 $pr->{'commit'} = \
%co;
1820 if (!defined $pr->{'descr'}) {
1821 my $descr = git_get_project_description
($pr->{'path'}) || "";
1822 $pr->{'descr'} = chop_str
($descr, 25, 5);
1824 if (!defined $pr->{'owner'}) {
1825 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
1827 push @projects, $pr;
1831 if (-f
$home_text) {
1832 print "<div class=\"index_include\">\n";
1833 open (my $fd, $home_text);
1838 print "<table class=\"project_list\">\n" .
1840 $order ||= "project";
1841 if ($order eq "project") {
1842 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1843 print "<th>Project</th>\n";
1846 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
1847 -class => "header"}, "Project") .
1850 if ($order eq "descr") {
1851 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1852 print "<th>Description</th>\n";
1855 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
1856 -class => "header"}, "Description") .
1859 if ($order eq "owner") {
1860 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1861 print "<th>Owner</th>\n";
1864 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
1865 -class => "header"}, "Owner") .
1868 if ($order eq "age") {
1869 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1870 print "<th>Last Change</th>\n";
1873 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
1874 -class => "header"}, "Last Change") .
1877 print "<th></th>\n" .
1880 foreach my $pr (@projects) {
1882 print "<tr class=\"dark\">\n";
1884 print "<tr class=\"light\">\n";
1887 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
1888 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
1889 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
1890 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
1891 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
1892 $pr->{'commit'}{'age_string'} . "</td>\n" .
1893 "<td class=\"link\">" .
1894 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
1895 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
1896 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") .
1905 my $descr = git_get_project_description
($project) || "none";
1906 my $head = git_get_head_hash
($project);
1907 my %co = parse_commit
($head);
1908 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
1910 my $owner = git_get_project_owner
($project);
1912 my $refs = git_get_references
();
1914 git_print_page_nav
('summary','', $head);
1916 print "<div class=\"title\"> </div>\n";
1917 print "<table cellspacing=\"0\">\n" .
1918 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1919 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1920 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
1921 # use per project git URL list in $projectroot/$project/cloneurl
1922 # or make project git URL from git base URL and project name
1923 my $url_tag = "URL";
1924 my @url_list = git_get_project_url_list
($project);
1925 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
1926 foreach my $git_url (@url_list) {
1927 next unless $git_url;
1928 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
1933 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash
($project)
1934 or die_error
(undef, "Open git-rev-list failed");
1935 my @revlist = map { chomp; $_ } <$fd>;
1937 git_print_header_div
('shortlog');
1938 git_shortlog_body
(\
@revlist, 0, 15, $refs,
1939 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
1941 my $taglist = git_get_refs_list
("refs/tags");
1942 if (defined @
$taglist) {
1943 git_print_header_div
('tags');
1944 git_tags_body
($taglist, 0, 15,
1945 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
1948 my $headlist = git_get_refs_list
("refs/heads");
1949 if (defined @
$headlist) {
1950 git_print_header_div
('heads');
1951 git_heads_body
($headlist, $head, 0, 15,
1952 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
1959 my $head = git_get_head_hash
($project);
1961 git_print_page_nav
('','', $head,undef,$head);
1962 my %tag = parse_tag
($hash);
1963 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
1964 print "<div class=\"title_text\">\n" .
1965 "<table cellspacing=\"0\">\n" .
1967 "<td>object</td>\n" .
1968 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
1969 $tag{'object'}) . "</td>\n" .
1970 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
1971 $tag{'type'}) . "</td>\n" .
1973 if (defined($tag{'author'})) {
1974 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
1975 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1976 print "<tr><td></td><td>" . $ad{'rfc2822'} .
1977 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
1980 print "</table>\n\n" .
1982 print "<div class=\"page_body\">";
1983 my $comment = $tag{'comment'};
1984 foreach my $line (@
$comment) {
1985 print esc_html
($line) . "<br/>\n";
1995 if (!gitweb_check_feature
('blame')) {
1996 die_error
('403 Permission denied', "Permission denied");
1998 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1999 $hash_base ||= git_get_head_hash
($project);
2000 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2001 my %co = parse_commit
($hash_base)
2002 or die_error
(undef, "Reading commit failed");
2003 if (!defined $hash) {
2004 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2005 or die_error
(undef, "Error looking up file");
2007 $ftype = git_get_type
($hash);
2008 if ($ftype !~ "blob") {
2009 die_error
("400 Bad Request", "Object is not a blob");
2011 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
2012 or die_error
(undef, "Open git-blame failed");
2015 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2018 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2020 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2021 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2022 git_print_page_path
($file_name, $ftype, $hash_base);
2023 my @rev_color = (qw(light2 dark2));
2024 my $num_colors = scalar(@rev_color);
2025 my $current_color = 0;
2028 <div class="page_body">
2029 <table class="blame">
2030 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2033 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2035 my $rev = substr($full_rev, 0, 8);
2039 if (!defined $last_rev) {
2040 $last_rev = $full_rev;
2041 } elsif ($last_rev ne $full_rev) {
2042 $last_rev = $full_rev;
2043 $current_color = ++$current_color % $num_colors;
2045 print "<tr class=\"$rev_color[$current_color]\">\n";
2046 print "<td class=\"sha1\">" .
2047 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)},
2048 esc_html
($rev)) . "</td>\n";
2049 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2050 esc_html
($lineno) . "</a></td>\n";
2051 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2057 or print "Reading blob failed\n";
2064 if (!gitweb_check_feature
('blame')) {
2065 die_error
('403 Permission denied', "Permission denied");
2067 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2068 $hash_base ||= git_get_head_hash
($project);
2069 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2070 my %co = parse_commit
($hash_base)
2071 or die_error
(undef, "Reading commit failed");
2072 if (!defined $hash) {
2073 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2074 or die_error
(undef, "Error lookup file");
2076 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2077 or die_error
(undef, "Open git-annotate failed");
2080 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2083 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2085 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2086 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2087 git_print_page_path
($file_name, 'blob', $hash_base);
2088 print "<div class=\"page_body\">\n";
2090 <table class="blame">
2099 my @line_class = (qw(light dark));
2100 my $line_class_len = scalar (@line_class);
2101 my $line_class_num = $#line_class;
2102 while (my $line = <$fd>) {
2114 $line_class_num = ($line_class_num + 1) % $line_class_len;
2116 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
2123 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2126 $short_rev = substr ($long_rev, 0, 8);
2127 $age = time () - $time;
2128 $age_str = age_string
($age);
2129 $age_str =~ s/ / /g;
2130 $age_class = age_class
($age);
2131 $author = esc_html
($author);
2132 $author =~ s/ / /g;
2134 $data = untabify
($data);
2135 $data = esc_html
($data);
2138 <tr class="$line_class[$line_class_num]">
2139 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2140 <td class="$age_class">$age_str</td>
2142 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2143 <td class="pre">$data</td>
2146 } # while (my $line = <$fd>)
2147 print "</table>\n\n";
2149 or print "Reading blob failed.\n";
2155 my $head = git_get_head_hash
($project);
2157 git_print_page_nav
('','', $head,undef,$head);
2158 git_print_header_div
('summary', $project);
2160 my $taglist = git_get_refs_list
("refs/tags");
2161 if (defined @
$taglist) {
2162 git_tags_body
($taglist);
2168 my $head = git_get_head_hash
($project);
2170 git_print_page_nav
('','', $head,undef,$head);
2171 git_print_header_div
('summary', $project);
2173 my $taglist = git_get_refs_list
("refs/heads");
2174 if (defined @
$taglist) {
2175 git_heads_body
($taglist, $head);
2180 sub git_blob_plain
{
2181 if (!defined $hash) {
2182 if (defined $file_name) {
2183 my $base = $hash_base || git_get_head_hash
($project);
2184 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2185 or die_error
(undef, "Error lookup file");
2187 die_error
(undef, "No file name defined");
2191 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2192 or die_error
(undef, "Couldn't cat $file_name, $hash");
2194 $type ||= blob_mimetype
($fd, $file_name);
2196 # save as filename, even when no $file_name is given
2197 my $save_as = "$hash";
2198 if (defined $file_name) {
2199 $save_as = $file_name;
2200 } elsif ($type =~ m/^text\//) {
2204 print $cgi->header(-type
=> "$type",
2205 -content_disposition
=> "inline; filename=\"$save_as\"");
2207 binmode STDOUT
, ':raw';
2209 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2215 if (!defined $hash) {
2216 if (defined $file_name) {
2217 my $base = $hash_base || git_get_head_hash
($project);
2218 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2219 or die_error
(undef, "Error lookup file");
2221 die_error
(undef, "No file name defined");
2224 my $have_blame = gitweb_check_feature
('blame');
2225 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2226 or die_error
(undef, "Couldn't cat $file_name, $hash");
2227 my $mimetype = blob_mimetype
($fd, $file_name);
2228 if ($mimetype !~ m/^text\//) {
2230 return git_blob_plain
($mimetype);
2233 my $formats_nav = '';
2234 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2235 if (defined $file_name) {
2238 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2239 hash
=>$hash, file_name
=>$file_name)},
2244 $cgi->a({-href
=> href
(action
=>"blob_plain",
2245 hash
=>$hash, file_name
=>$file_name)},
2248 $cgi->a({-href
=> href
(action
=>"blob",
2249 hash_base
=>"HEAD", file_name
=>$file_name)},
2253 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "plain");
2255 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2256 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2258 print "<div class=\"page_nav\">\n" .
2259 "<br/><br/></div>\n" .
2260 "<div class=\"title\">$hash</div>\n";
2262 git_print_page_path
($file_name, "blob", $hash_base);
2263 print "<div class=\"page_body\">\n";
2265 while (my $line = <$fd>) {
2268 $line = untabify
($line);
2269 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2270 $nr, $nr, $nr, esc_html
($line);
2273 or print "Reading blob failed.\n";
2279 if (!defined $hash) {
2280 $hash = git_get_head_hash
($project);
2281 if (defined $file_name) {
2282 my $base = $hash_base || $hash;
2283 $hash = git_get_hash_by_path
($base, $file_name, "tree");
2285 if (!defined $hash_base) {
2290 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
2291 or die_error
(undef, "Open git-ls-tree failed");
2292 my @entries = map { chomp; $_ } <$fd>;
2293 close $fd or die_error
(undef, "Reading tree failed");
2296 my $refs = git_get_references
();
2297 my $ref = format_ref_marker
($refs, $hash_base);
2301 my $have_blame = gitweb_check_feature
('blame');
2302 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2303 $base_key{hash_base
} = $hash_base;
2304 git_print_page_nav
('tree','', $hash_base);
2305 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2307 print "<div class=\"page_nav\">\n";
2308 print "<br/><br/></div>\n";
2309 print "<div class=\"title\">$hash</div>\n";
2311 if (defined $file_name) {
2312 $base = esc_html
("$file_name/");
2314 git_print_page_path
($file_name, 'tree', $hash_base);
2315 print "<div class=\"page_body\">\n";
2316 print "<table cellspacing=\"0\">\n";
2318 foreach my $line (@entries) {
2319 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2320 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2324 my $t_name = validate_input
($4);
2326 print "<tr class=\"dark\">\n";
2328 print "<tr class=\"light\">\n";
2331 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
2332 if ($t_type eq "blob") {
2333 print "<td class=\"list\">" .
2334 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key),
2335 -class => "list"}, esc_html
($t_name)) .
2337 "<td class=\"link\">" .
2338 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2342 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2346 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2347 hash
=>$t_hash, file_name
=>"$base$t_name")},
2350 $cgi->a({-href
=> href
(action
=>"blob_plain",
2351 hash
=>$t_hash, file_name
=>"$base$t_name")},
2354 } elsif ($t_type eq "tree") {
2355 print "<td class=\"list\">" .
2356 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2357 esc_html
($t_name)) .
2359 "<td class=\"link\">" .
2360 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2363 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base, file_name
=>"$base$t_name")},
2369 print "</table>\n" .
2376 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2377 my $have_snapshot = (defined $ctype && defined $suffix);
2378 if (!$have_snapshot) {
2379 die_error
('403 Permission denied', "Permission denied");
2382 if (!defined $hash) {
2383 $hash = git_get_head_hash
($project);
2386 my $filename = basename
($project) . "-$hash.tar.$suffix";
2388 print $cgi->header(-type
=> 'application/x-tar',
2389 -content_encoding
=> $ctype,
2390 -content_disposition
=> "inline; filename=\"$filename\"",
2391 -status
=> '200 OK');
2393 open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | $command" or
2394 die_error
(undef, "Execute git-tar-tree failed.");
2395 binmode STDOUT
, ':raw';
2397 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2403 my $head = git_get_head_hash
($project);
2404 if (!defined $hash) {
2407 if (!defined $page) {
2410 my $refs = git_get_references
();
2412 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2413 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2414 or die_error
(undef, "Open git-rev-list failed");
2415 my @revlist = map { chomp; $_ } <$fd>;
2418 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2421 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2424 my %co = parse_commit
($hash);
2426 git_print_header_div
('summary', $project);
2427 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2429 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2430 my $commit = $revlist[$i];
2431 my $ref = format_ref_marker
($refs, $commit);
2432 my %co = parse_commit
($commit);
2434 my %ad = parse_date
($co{'author_epoch'});
2435 git_print_header_div
('commit',
2436 "<span class=\"age\">$co{'age_string'}</span>" .
2437 esc_html
($co{'title'}) . $ref,
2439 print "<div class=\"title_text\">\n" .
2440 "<div class=\"log_link\">\n" .
2441 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2443 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2446 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2449 print "<div class=\"log_body\">\n";
2450 git_print_simplified_log
($co{'comment'});
2457 my %co = parse_commit
($hash);
2459 die_error
(undef, "Unknown commit object");
2461 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2462 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2464 my $parent = $co{'parent'};
2465 if (!defined $parent) {
2468 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
2469 or die_error
(undef, "Open git-diff-tree failed");
2470 my @difftree = map { chomp; $_ } <$fd>;
2471 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2473 # non-textual hash id's can be cached
2475 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2478 my $refs = git_get_references
();
2479 my $ref = format_ref_marker
($refs, $co{'id'});
2481 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2482 my $have_snapshot = (defined $ctype && defined $suffix);
2484 my $formats_nav = '';
2485 if (defined $file_name && defined $co{'parent'}) {
2486 my $parent = $co{'parent'};
2488 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
2491 git_header_html
(undef, $expires);
2492 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
2493 $hash, $co{'tree'}, $hash,
2496 if (defined $co{'parent'}) {
2497 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2499 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
2501 print "<div class=\"title_text\">\n" .
2502 "<table cellspacing=\"0\">\n";
2503 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2505 "<td></td><td> $ad{'rfc2822'}";
2506 if ($ad{'hour_local'} < 6) {
2507 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2508 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2510 printf(" (%02d:%02d %s)",
2511 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2515 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2516 print "<tr><td></td><td> $cd{'rfc2822'}" .
2517 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2519 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2522 "<td class=\"sha1\">" .
2523 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
2524 class => "list"}, $co{'tree'}) .
2526 "<td class=\"link\">" .
2527 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
2529 if ($have_snapshot) {
2531 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
2535 my $parents = $co{'parents'};
2536 foreach my $par (@
$parents) {
2539 "<td class=\"sha1\">" .
2540 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
2541 class => "list"}, $par) .
2543 "<td class=\"link\">" .
2544 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
2546 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "commitdiff") .
2553 print "<div class=\"page_body\">\n";
2554 git_print_log
($co{'comment'});
2557 git_difftree_body
(\
@difftree, $parent);
2563 mkdir($git_temp, 0700);
2565 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2567 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
2568 hash
=>$hash, hash_parent
=>$hash_parent)},
2570 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2571 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2574 <div class="page_nav"><br/><br/></div>
2575 <div class="title">$hash vs $hash_parent</div>
2578 git_print_page_path
($file_name, "blob", $hash_base);
2579 print "<div class=\"page_body\">\n" .
2580 "<div class=\"diff_info\">blob:" .
2581 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash_parent,
2582 hash_base
=>$hash_base, file_name
=>($file_parent || $file_name))},
2585 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash,
2586 hash_base
=>$hash_base, file_name
=>$file_name)},
2589 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2590 print "</div>"; # page_body
2594 sub git_blobdiff_plain
{
2595 mkdir($git_temp, 0700);
2596 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2597 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2600 sub git_commitdiff
{
2601 mkdir($git_temp, 0700);
2602 my %co = parse_commit
($hash);
2604 die_error
(undef, "Unknown commit object");
2606 if (!defined $hash_parent) {
2607 $hash_parent = $co{'parent'} || '--root';
2609 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2610 or die_error
(undef, "Open git-diff-tree failed");
2611 my @difftree = map { chomp; $_ } <$fd>;
2612 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2614 # non-textual hash id's can be cached
2616 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2619 my $refs = git_get_references
();
2620 my $ref = format_ref_marker
($refs, $co{'id'});
2622 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", hash
=>$hash, hash_parent
=>$hash_parent)},
2624 git_header_html
(undef, $expires);
2625 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2626 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2627 print "<div class=\"page_body\">\n";
2628 git_print_simplified_log
($co{'comment'}, 1); # skip title
2630 foreach my $line (@difftree) {
2631 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2632 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2633 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2641 my $file = validate_input
(unquote
($6));
2642 if ($status eq "A") {
2643 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2644 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2645 hash
=>$to_id, file_name
=>$file)},
2648 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2649 } elsif ($status eq "D") {
2650 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2651 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2652 hash
=>$from_id, file_name
=>$file)},
2653 $from_id) . "(deleted)" .
2655 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2656 } elsif ($status eq "M") {
2657 if ($from_id ne $to_id) {
2658 print "<div class=\"diff_info\">" .
2659 file_type
($from_mode) . ":" .
2660 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2661 hash
=>$from_id, file_name
=>$file)},
2664 file_type
($to_mode) . ":" .
2665 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2666 hash
=>$to_id, file_name
=>$file)},
2669 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2678 sub git_commitdiff_plain
{
2679 mkdir($git_temp, 0700);
2680 my %co = parse_commit
($hash);
2682 die_error
(undef, "Unknown commit object");
2684 if (!defined $hash_parent) {
2685 $hash_parent = $co{'parent'} || '--root';
2687 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2688 or die_error
(undef, "Open git-diff-tree failed");
2689 my @difftree = map { chomp; $_ } <$fd>;
2690 close $fd or die_error
(undef, "Reading diff-tree failed");
2692 # try to figure out the next tag after this commit
2694 my $refs = git_get_references
("tags");
2695 open $fd, "-|", $GIT, "rev-list", "HEAD";
2696 my @commits = map { chomp; $_ } <$fd>;
2698 foreach my $commit (@commits) {
2699 if (defined $refs->{$commit}) {
2700 $tagname = $refs->{$commit}
2702 if ($commit eq $hash) {
2707 print $cgi->header(-type
=> "text/plain",
2708 -charset
=> 'utf-8',
2709 -content_disposition
=> "inline; filename=\"git-$hash.patch\"");
2710 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2711 my $comment = $co{'comment'};
2714 Date: $ad{'rfc2822'} ($ad{'tz_local'})
2715 Subject: $co{'title'}
2717 if (defined $tagname) {
2718 print "X-Git-Tag: $tagname\n";
2720 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2723 foreach my $line (@
$comment) {;
2728 foreach my $line (@difftree) {
2729 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2736 if ($status eq "A") {
2737 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2738 } elsif ($status eq "D") {
2739 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2740 } elsif ($status eq "M") {
2741 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2747 if (!defined $hash_base) {
2748 $hash_base = git_get_head_hash
($project);
2751 my %co = parse_commit
($hash_base);
2753 die_error
(undef, "Unknown commit object");
2755 my $refs = git_get_references
();
2757 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2758 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2759 if (!defined $hash && defined $file_name) {
2760 $hash = git_get_hash_by_path
($hash_base, $file_name);
2762 if (defined $hash) {
2763 $ftype = git_get_type
($hash);
2765 git_print_page_path
($file_name, $ftype, $hash_base);
2768 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2769 git_history_body
($fd, $refs, $hash_base, $ftype);
2776 if (!defined $searchtext) {
2777 die_error
(undef, "Text field empty");
2779 if (!defined $hash) {
2780 $hash = git_get_head_hash
($project);
2782 my %co = parse_commit
($hash);
2784 die_error
(undef, "Unknown commit object");
2786 # pickaxe may take all resources of your box and run for several minutes
2787 # with every query - so decide by yourself how public you make this feature :)
2788 my $commit_search = 1;
2789 my $author_search = 0;
2790 my $committer_search = 0;
2791 my $pickaxe_search = 0;
2792 if ($searchtext =~ s/^author\\://i) {
2794 } elsif ($searchtext =~ s/^committer\\://i) {
2795 $committer_search = 1;
2796 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2798 $pickaxe_search = 1;
2801 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
2802 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
2804 print "<table cellspacing=\"0\">\n";
2806 if ($commit_search) {
2808 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2809 while (my $commit_text = <$fd>) {
2810 if (!grep m/$searchtext/i, $commit_text) {
2813 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2816 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2819 my @commit_lines = split "\n", $commit_text;
2820 my %co = parse_commit
(undef, \
@commit_lines);
2825 print "<tr class=\"dark\">\n";
2827 print "<tr class=\"light\">\n";
2830 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2831 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2833 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
2834 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
2835 my $comment = $co{'comment'};
2836 foreach my $line (@
$comment) {
2837 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2838 my $lead = esc_html
($1) || "";
2839 $lead = chop_str
($lead, 30, 10);
2840 my $match = esc_html
($2) || "";
2841 my $trail = esc_html
($3) || "";
2842 $trail = chop_str
($trail, 30, 10);
2843 my $text = "$lead<span class=\"match\">$match</span>$trail";
2844 print chop_str
($text, 80, 5) . "<br/>\n";
2848 "<td class=\"link\">" .
2849 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
2851 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
2858 if ($pickaxe_search) {
2860 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2863 while (my $line = <$fd>) {
2864 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2867 $set{'from_id'} = $3;
2869 $set{'id'} = $set{'to_id'};
2870 if ($set{'id'} =~ m/0{40}/) {
2871 $set{'id'} = $set{'from_id'};
2873 if ($set{'id'} =~ m/0{40}/) {
2877 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2880 print "<tr class=\"dark\">\n";
2882 print "<tr class=\"light\">\n";
2885 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2886 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2888 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
2889 -class => "list subject"},
2890 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
2891 while (my $setref = shift @files) {
2893 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
2894 hash
=>$set{'id'}, file_name
=>$set{'file'}),
2896 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2900 "<td class=\"link\">" .
2901 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
2903 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
2907 %co = parse_commit
($1);
2917 my $head = git_get_head_hash
($project);
2918 if (!defined $hash) {
2921 if (!defined $page) {
2924 my $refs = git_get_references
();
2926 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2927 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2928 or die_error
(undef, "Open git-rev-list failed");
2929 my @revlist = map { chomp; $_ } <$fd>;
2932 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
2934 if ($#revlist >= (100 * ($page+1)-1)) {
2936 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
2937 -title
=> "Alt-n"}, "next");
2942 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
2943 git_print_header_div
('summary', $project);
2945 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
2950 ## ......................................................................
2951 ## feeds (RSS, OPML)
2954 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
2955 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash
($project)
2956 or die_error
(undef, "Open git-rev-list failed");
2957 my @revlist = map { chomp; $_ } <$fd>;
2958 close $fd or die_error
(undef, "Reading git-rev-list failed");
2959 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2961 <?xml version="1.0" encoding="utf-8"?>
2962 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
2964 <title>$project $my_uri $my_url</title>
2965 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
2966 <description>$project log</description>
2967 <language>en</language>
2970 for (my $i = 0; $i <= $#revlist; $i++) {
2971 my $commit = $revlist[$i];
2972 my %co = parse_commit
($commit);
2973 # we read 150, we always show 30 and the ones more recent than 48 hours
2974 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
2977 my %cd = parse_date
($co{'committer_epoch'});
2978 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
2979 my @difftree = map { chomp; $_ } <$fd>;
2983 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
2985 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
2986 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
2987 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
2988 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
2989 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
2990 "<content:encoded>" .
2992 my $comment = $co{'comment'};
2993 foreach my $line (@
$comment) {
2994 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
2995 print "$line<br/>\n";
2998 foreach my $line (@difftree) {
2999 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3002 my $file = validate_input
(unquote
($7));
3003 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
3004 print "$file<br/>\n";
3007 "</content:encoded>\n" .
3010 print "</channel></rss>";
3014 my @list = git_get_projects_list
();
3016 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3018 <?xml version="1.0" encoding="utf-8"?>
3019 <opml version="1.0">
3021 <title>$site_name Git OPML Export</title>
3024 <outline text="git RSS feeds">
3027 foreach my $pr (@list) {
3029 my $head = git_get_head_hash
($proj{'path'});
3030 if (!defined $head) {
3033 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
3034 my %co = parse_commit
($head);
3039 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3040 my $rss = "$my_url?p=$proj{'path'};a=rss";
3041 my $html = "$my_url?p=$proj{'path'};a=summary";
3042 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";