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");
158 # action which does not check rest of parameters
159 if ($action eq "opml") {
165 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
166 if (defined $project) {
169 $project = undef unless $project;
171 if (defined $project) {
172 if (!validate_input
($project)) {
173 die_error
(undef, "Invalid project parameter");
175 if (!(-d
"$projectroot/$project")) {
176 die_error
(undef, "No such directory");
178 if (!(-e
"$projectroot/$project/HEAD")) {
179 die_error
(undef, "No such project");
181 $ENV{'GIT_DIR'} = "$projectroot/$project";
187 our $file_name = $cgi->param('f');
188 if (defined $file_name) {
189 if (!validate_input
($file_name)) {
190 die_error
(undef, "Invalid file parameter");
194 our $file_parent = $cgi->param('fp');
195 if (defined $file_parent) {
196 if (!validate_input
($file_parent)) {
197 die_error
(undef, "Invalid file parent parameter");
201 our $hash = $cgi->param('h');
203 if (!validate_input
($hash)) {
204 die_error
(undef, "Invalid hash parameter");
208 our $hash_parent = $cgi->param('hp');
209 if (defined $hash_parent) {
210 if (!validate_input
($hash_parent)) {
211 die_error
(undef, "Invalid hash parent parameter");
215 our $hash_base = $cgi->param('hb');
216 if (defined $hash_base) {
217 if (!validate_input
($hash_base)) {
218 die_error
(undef, "Invalid hash base parameter");
222 our $page = $cgi->param('pg');
224 if ($page =~ m/[^0-9]$/) {
225 die_error
(undef, "Invalid page parameter");
229 our $searchtext = $cgi->param('s');
230 if (defined $searchtext) {
231 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
232 die_error
(undef, "Invalid search parameter");
234 $searchtext = quotemeta $searchtext;
239 "blame" => \
&git_blame2
,
240 "blobdiff" => \
&git_blobdiff
,
241 "blobdiff_plain" => \
&git_blobdiff_plain
,
242 "blob" => \
&git_blob
,
243 "blob_plain" => \
&git_blob_plain
,
244 "commitdiff" => \
&git_commitdiff
,
245 "commitdiff_plain" => \
&git_commitdiff_plain
,
246 "commit" => \
&git_commit
,
247 "heads" => \
&git_heads
,
248 "history" => \
&git_history
,
251 "search" => \
&git_search
,
252 "shortlog" => \
&git_shortlog
,
253 "summary" => \
&git_summary
,
255 "tags" => \
&git_tags
,
256 "tree" => \
&git_tree
,
257 "snapshot" => \
&git_snapshot
,
260 $action = 'summary' if (!defined($action));
261 if (!defined($actions{$action})) {
262 die_error
(undef, "Unknown action");
264 $actions{$action}->();
267 ## ======================================================================
284 $params{"project"} ||= $project;
286 my $href = "$my_uri?";
287 $href .= esc_param
( join(";",
289 "$mapping{$_}=$params{$_}" if defined $params{$_}
297 ## ======================================================================
298 ## validation, quoting/unquoting and escaping
303 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
306 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
309 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
315 # quote unsafe chars, but keep the slash, even when it's not
316 # correct, but quoted slashes look too horrible in bookmarks
319 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
325 # replace invalid utf8 character with SUBSTITUTION sequence
328 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
329 $str = escapeHTML
($str);
330 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
334 # git may return quoted and escaped filenames
337 if ($str =~ m/^"(.*)"$/) {
339 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
344 # escape tabs (convert tabs to spaces)
348 while ((my $pos = index($line, "\t")) != -1) {
349 if (my $count = (8 - ($pos % 8))) {
350 my $spaces = ' ' x
$count;
351 $line =~ s/\t/$spaces/;
358 ## ----------------------------------------------------------------------
359 ## HTML aware string manipulation
364 my $add_len = shift || 10;
366 # allow only $len chars, but don't cut a word if it would fit in $add_len
367 # if it doesn't fit, cut it if it's still longer than the dots we would add
368 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
371 if (length($tail) > 4) {
373 $body =~ s/&[^;]*$//; # remove chopped character entities
378 ## ----------------------------------------------------------------------
379 ## functions returning short strings
381 # CSS class for given age value (in seconds)
385 if ($age < 60*60*2) {
387 } elsif ($age < 60*60*24*2) {
394 # convert age in seconds to "nn units ago" string
399 if ($age > 60*60*24*365*2) {
400 $age_str = (int $age/60/60/24/365);
401 $age_str .= " years ago";
402 } elsif ($age > 60*60*24*(365/12)*2) {
403 $age_str = int $age/60/60/24/(365/12);
404 $age_str .= " months ago";
405 } elsif ($age > 60*60*24*7*2) {
406 $age_str = int $age/60/60/24/7;
407 $age_str .= " weeks ago";
408 } elsif ($age > 60*60*24*2) {
409 $age_str = int $age/60/60/24;
410 $age_str .= " days ago";
411 } elsif ($age > 60*60*2) {
412 $age_str = int $age/60/60;
413 $age_str .= " hours ago";
414 } elsif ($age > 60*2) {
415 $age_str = int $age/60;
416 $age_str .= " min ago";
419 $age_str .= " sec ago";
421 $age_str .= " right now";
426 # convert file mode in octal to symbolic file mode string
428 my $mode = oct shift;
430 if (S_ISDIR
($mode & S_IFMT
)) {
432 } elsif (S_ISLNK
($mode)) {
434 } elsif (S_ISREG
($mode)) {
435 # git cares only about the executable bit
436 if ($mode & S_IXUSR
) {
446 # convert file mode in octal to file type string
448 my $mode = oct shift;
450 if (S_ISDIR
($mode & S_IFMT
)) {
452 } elsif (S_ISLNK
($mode)) {
454 } elsif (S_ISREG
($mode)) {
461 ## ----------------------------------------------------------------------
462 ## functions returning short HTML fragments, or transforming HTML fragments
463 ## which don't beling to other sections
465 # format line of commit message or tag comment
466 sub format_log_line_html
{
469 $line = esc_html
($line);
470 $line =~ s/ / /g;
471 if ($line =~ m/([0-9a-fA-F]{40})/) {
473 if (git_get_type
($hash_text) eq "commit") {
475 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
476 -class => "text"}, $hash_text);
477 $line =~ s/$hash_text/$link/;
483 # format marker of refs pointing to given object
484 sub format_ref_marker
{
485 my ($refs, $id) = @_;
488 if (defined $refs->{$id}) {
489 foreach my $ref (@
{$refs->{$id}}) {
490 my ($type, $name) = qw();
491 # e.g. tags/v2.6.11 or heads/next
492 if ($ref =~ m!^(.*?)s?/(.*)$!) {
500 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
505 return ' <span class="refs">'. $markers . '</span>';
511 # format, perhaps shortened and with markers, title line
512 sub format_subject_html
{
513 my ($long, $short, $href, $extra) = @_;
514 $extra = '' unless defined($extra);
516 if (length($short) < length($long)) {
517 return $cgi->a({-href
=> $href, -class => "list subject",
519 esc_html
($short) . $extra);
521 return $cgi->a({-href
=> $href, -class => "list subject"},
522 esc_html
($long) . $extra);
526 ## ----------------------------------------------------------------------
527 ## git utility subroutines, invoking git commands
529 # get HEAD ref of given project as hash
530 sub git_get_head_hash
{
532 my $oENV = $ENV{'GIT_DIR'};
534 $ENV{'GIT_DIR'} = "$projectroot/$project";
535 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
538 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
543 $ENV{'GIT_DIR'} = $oENV;
548 # get type of given object
552 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
559 sub git_get_project_config
{
560 my ($key, $type) = @_;
562 return unless ($key);
563 $key =~ s/^gitweb\.//;
564 return if ($key =~ m/\W/);
566 my @x = ($GIT, 'repo-config');
567 if (defined $type) { push @x, $type; }
569 push @x, "gitweb.$key";
575 # get hash of given path at given ref
576 sub git_get_hash_by_path
{
578 my $path = shift || return undef;
582 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
583 or die_error
(undef, "Open git-ls-tree failed");
585 close $fd or return undef;
587 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
588 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
592 ## ......................................................................
593 ## git utility functions, directly accessing git repository
595 # assumes that PATH is not symref
596 sub git_get_hash_by_ref
{
599 open my $fd, "$projectroot/$path" or return undef;
603 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
608 sub git_get_project_description
{
611 open my $fd, "$projectroot/$path/description" or return undef;
618 sub git_get_project_url_list
{
621 open my $fd, "$projectroot/$path/cloneurl" or return undef;
622 my @git_project_url_list = map { chomp; $_ } <$fd>;
625 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
628 sub git_get_projects_list
{
631 if (-d
$projects_list) {
632 # search in directory
633 my $dir = $projects_list;
634 opendir my ($dh), $dir or return undef;
635 while (my $dir = readdir($dh)) {
636 if (-e
"$projectroot/$dir/HEAD") {
644 } elsif (-f
$projects_list) {
645 # read from file(url-encoded):
646 # 'git%2Fgit.git Linus+Torvalds'
647 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
648 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
649 open my ($fd), $projects_list or return undef;
650 while (my $line = <$fd>) {
652 my ($path, $owner) = split ' ', $line;
653 $path = unescape
($path);
654 $owner = unescape
($owner);
655 if (!defined $path) {
658 if (-e
"$projectroot/$path/HEAD") {
661 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
668 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
672 sub git_get_project_owner
{
676 return undef unless $project;
678 # read from file (url-encoded):
679 # 'git%2Fgit.git Linus+Torvalds'
680 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
681 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
682 if (-f
$projects_list) {
683 open (my $fd , $projects_list);
684 while (my $line = <$fd>) {
686 my ($pr, $ow) = split ' ', $line;
689 if ($pr eq $project) {
690 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
696 if (!defined $owner) {
697 $owner = get_file_owner
("$projectroot/$project");
703 sub git_get_references
{
704 my $type = shift || "";
707 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
708 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
709 if (-f
"$projectroot/$project/info/refs") {
710 open $fd, "$projectroot/$project/info/refs"
713 open $fd, "-|", $GIT, "ls-remote", "."
717 while (my $line = <$fd>) {
719 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
720 if (defined $refs{$1}) {
721 push @
{$refs{$1}}, $2;
731 ## ----------------------------------------------------------------------
732 ## parse to hash functions
736 my $tz = shift || "-0000";
739 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
740 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
741 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
742 $date{'hour'} = $hour;
743 $date{'minute'} = $min;
744 $date{'mday'} = $mday;
745 $date{'day'} = $days[$wday];
746 $date{'month'} = $months[$mon];
747 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
748 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
749 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
750 $mday, $months[$mon], $hour ,$min;
752 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
753 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
754 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
755 $date{'hour_local'} = $hour;
756 $date{'minute_local'} = $min;
757 $date{'tz_local'} = $tz;
766 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
767 $tag{'id'} = $tag_id;
768 while (my $line = <$fd>) {
770 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
772 } elsif ($line =~ m/^type (.+)$/) {
774 } elsif ($line =~ m/^tag (.+)$/) {
776 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
780 } elsif ($line =~ m/--BEGIN/) {
781 push @comment, $line;
783 } elsif ($line eq "") {
787 push @comment, <$fd>;
788 $tag{'comment'} = \
@comment;
790 if (!defined $tag{'name'}) {
797 my $commit_id = shift;
798 my $commit_text = shift;
803 if (defined $commit_text) {
804 @commit_lines = @
$commit_text;
807 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id
809 @commit_lines = split '\n', <$fd>;
814 my $header = shift @commit_lines;
815 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
818 ($co{'id'}, my @parents) = split ' ', $header;
819 $co{'parents'} = \
@parents;
820 $co{'parent'} = $parents[0];
821 while (my $line = shift @commit_lines) {
822 last if $line eq "\n";
823 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
825 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
827 $co{'author_epoch'} = $2;
828 $co{'author_tz'} = $3;
829 if ($co{'author'} =~ m/^([^<]+) </) {
830 $co{'author_name'} = $1;
832 $co{'author_name'} = $co{'author'};
834 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
835 $co{'committer'} = $1;
836 $co{'committer_epoch'} = $2;
837 $co{'committer_tz'} = $3;
838 $co{'committer_name'} = $co{'committer'};
839 $co{'committer_name'} =~ s/ <.*//;
842 if (!defined $co{'tree'}) {
846 foreach my $title (@commit_lines) {
849 $co{'title'} = chop_str
($title, 80, 5);
850 # remove leading stuff of merges to make the interesting part visible
851 if (length($title) > 50) {
852 $title =~ s/^Automatic //;
853 $title =~ s/^merge (of|with) /Merge ... /i;
854 if (length($title) > 50) {
855 $title =~ s/(http|rsync):\/\///;
857 if (length($title) > 50) {
858 $title =~ s/(master|www|rsync)\.//;
860 if (length($title) > 50) {
861 $title =~ s/kernel.org:?//;
863 if (length($title) > 50) {
864 $title =~ s/\/pub\/scm//;
867 $co{'title_short'} = chop_str
($title, 50, 5);
871 # remove added spaces
872 foreach my $line (@commit_lines) {
875 $co{'comment'} = \
@commit_lines;
877 my $age = time - $co{'committer_epoch'};
879 $co{'age_string'} = age_string
($age);
880 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
881 if ($age > 60*60*24*7*2) {
882 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
883 $co{'age_string_age'} = $co{'age_string'};
885 $co{'age_string_date'} = $co{'age_string'};
886 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
891 # parse ref from ref_file, given by ref_id, with given type
893 my $ref_file = shift;
895 my $type = shift || git_get_type
($ref_id);
898 $ref_item{'type'} = $type;
899 $ref_item{'id'} = $ref_id;
900 $ref_item{'epoch'} = 0;
901 $ref_item{'age'} = "unknown";
902 if ($type eq "tag") {
903 my %tag = parse_tag
($ref_id);
904 $ref_item{'comment'} = $tag{'comment'};
905 if ($tag{'type'} eq "commit") {
906 my %co = parse_commit
($tag{'object'});
907 $ref_item{'epoch'} = $co{'committer_epoch'};
908 $ref_item{'age'} = $co{'age_string'};
909 } elsif (defined($tag{'epoch'})) {
910 my $age = time - $tag{'epoch'};
911 $ref_item{'epoch'} = $tag{'epoch'};
912 $ref_item{'age'} = age_string
($age);
914 $ref_item{'reftype'} = $tag{'type'};
915 $ref_item{'name'} = $tag{'name'};
916 $ref_item{'refid'} = $tag{'object'};
917 } elsif ($type eq "commit"){
918 my %co = parse_commit
($ref_id);
919 $ref_item{'reftype'} = "commit";
920 $ref_item{'name'} = $ref_file;
921 $ref_item{'title'} = $co{'title'};
922 $ref_item{'refid'} = $ref_id;
923 $ref_item{'epoch'} = $co{'committer_epoch'};
924 $ref_item{'age'} = $co{'age_string'};
926 $ref_item{'reftype'} = $type;
927 $ref_item{'name'} = $ref_file;
928 $ref_item{'refid'} = $ref_id;
934 # parse line of git-diff-tree "raw" output
935 sub parse_difftree_raw_line
{
939 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
940 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
941 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
942 $res{'from_mode'} = $1;
943 $res{'to_mode'} = $2;
944 $res{'from_id'} = $3;
947 $res{'similarity'} = $6;
948 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
949 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
951 $res{'file'} = unquote
($7);
954 # 'c512b523472485aef4fff9e57b229d9d243c967f'
955 #elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
956 # $res{'commit'} = $1;
959 return wantarray ?
%res : \
%res;
962 ## ......................................................................
963 ## parse to array of hashes functions
965 sub git_get_refs_list
{
970 my $pfxlen = length("$projectroot/$project/$ref_dir");
971 File
::Find
::find
(sub {
974 push @refs, substr($File::Find
::name
, $pfxlen + 1);
976 }, "$projectroot/$project/$ref_dir");
978 foreach my $ref_file (@refs) {
979 my $ref_id = git_get_hash_by_ref
("$project/$ref_dir/$ref_file");
980 my $type = git_get_type
($ref_id) || next;
981 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
983 push @reflist, \
%ref_item;
986 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
990 ## ----------------------------------------------------------------------
991 ## filesystem-related functions
996 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
997 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
998 if (!defined $gcos) {
1002 $owner =~ s/[,;].*$//;
1003 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
1006 ## ......................................................................
1007 ## mimetype related functions
1009 sub mimetype_guess_file
{
1010 my $filename = shift;
1011 my $mimemap = shift;
1012 -r
$mimemap or return undef;
1015 open(MIME
, $mimemap) or return undef;
1017 next if m/^#/; # skip comments
1018 my ($mime, $exts) = split(/\t+/);
1019 if (defined $exts) {
1020 my @exts = split(/\s+/, $exts);
1021 foreach my $ext (@exts) {
1022 $mimemap{$ext} = $mime;
1028 $filename =~ /\.(.*?)$/;
1029 return $mimemap{$1};
1032 sub mimetype_guess
{
1033 my $filename = shift;
1035 $filename =~ /\./ or return undef;
1037 if ($mimetypes_file) {
1038 my $file = $mimetypes_file;
1039 if ($file !~ m!^/!) { # if it is relative path
1040 # it is relative to project
1041 $file = "$projectroot/$project/$file";
1043 $mime = mimetype_guess_file
($filename, $file);
1045 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1051 my $filename = shift;
1054 my $mime = mimetype_guess
($filename);
1055 $mime and return $mime;
1059 return $default_blob_plain_mimetype unless $fd;
1062 return 'text/plain' .
1063 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1064 } elsif (! $filename) {
1065 return 'application/octet-stream';
1066 } elsif ($filename =~ m/\.png$/i) {
1068 } elsif ($filename =~ m/\.gif$/i) {
1070 } elsif ($filename =~ m/\.jpe?g$/i) {
1071 return 'image/jpeg';
1073 return 'application/octet-stream';
1077 ## ======================================================================
1078 ## functions printing HTML: header, footer, error page
1080 sub git_header_html
{
1081 my $status = shift || "200 OK";
1082 my $expires = shift;
1084 my $title = "$site_name git";
1085 if (defined $project) {
1086 $title .= " - $project";
1087 if (defined $action) {
1088 $title .= "/$action";
1089 if (defined $file_name) {
1090 $title .= " - $file_name";
1091 if ($action eq "tree" && $file_name !~ m
|/$|) {
1098 # require explicit support from the UA if we are to send the page as
1099 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1100 # we have to do this because MSIE sometimes globs '*/*', pretending to
1101 # support xhtml+xml but choking when it gets what it asked for.
1102 if (defined $cgi->http('HTTP_ACCEPT') &&
1103 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1104 $cgi->Accept('application/xhtml+xml') != 0) {
1105 $content_type = 'application/xhtml+xml';
1107 $content_type = 'text/html';
1109 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1110 -status
=> $status, -expires
=> $expires);
1112 <?xml version="1.0" encoding="utf-8"?>
1113 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1114 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1115 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1116 <!-- git core binaries version $git_version -->
1118 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1119 <meta name="generator" content="gitweb/$version git/$git_version"/>
1120 <meta name="robots" content="index, nofollow"/>
1121 <title>$title</title>
1122 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1124 if (defined $project) {
1125 printf('<link rel="alternate" title="%s log" '.
1126 'href="%s" type="application/rss+xml"/>'."\n",
1127 esc_param
($project), href
(action
=>"rss"));
1132 "<div class=\"page_header\">\n" .
1133 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1134 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1136 print $cgi->a({-href
=> esc_param
($home_link)}, $home_link_str) . " / ";
1137 if (defined $project) {
1138 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1139 if (defined $action) {
1143 if (!defined $searchtext) {
1147 if (defined $hash_base) {
1148 $search_hash = $hash_base;
1149 } elsif (defined $hash) {
1150 $search_hash = $hash;
1152 $search_hash = "HEAD";
1154 $cgi->param("a", "search");
1155 $cgi->param("h", $search_hash);
1156 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1157 "<div class=\"search\">\n" .
1158 $cgi->hidden(-name
=> "p") . "\n" .
1159 $cgi->hidden(-name
=> "a") . "\n" .
1160 $cgi->hidden(-name
=> "h") . "\n" .
1161 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1163 $cgi->end_form() . "\n";
1168 sub git_footer_html
{
1169 print "<div class=\"page_footer\">\n";
1170 if (defined $project) {
1171 my $descr = git_get_project_description
($project);
1172 if (defined $descr) {
1173 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1175 print $cgi->a({-href
=> href
(action
=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1177 print $cgi->a({-href
=> href
(action
=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1185 my $status = shift || "403 Forbidden";
1186 my $error = shift || "Malformed query, file missing or permission denied";
1188 git_header_html
($status);
1189 print "<div class=\"page_body\">\n" .
1191 "$status - $error\n" .
1198 ## ----------------------------------------------------------------------
1199 ## functions printing or outputting HTML: navigation
1201 sub git_print_page_nav
{
1202 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1203 $extra = '' if !defined $extra; # pager or formats
1205 my @navs = qw(summary shortlog log commit commitdiff tree);
1207 @navs = grep { $_ ne $suppress } @navs;
1210 my %arg = map { $_ => {action
=>$_} } @navs;
1211 if (defined $head) {
1212 for (qw(commit commitdiff)) {
1213 $arg{$_}{hash
} = $head;
1215 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1216 for (qw(shortlog log)) {
1217 $arg{$_}{hash
} = $head;
1221 $arg{tree
}{hash
} = $treehead if defined $treehead;
1222 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1224 print "<div class=\"page_nav\">\n" .
1226 map { $_ eq $current ?
1227 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1229 print "<br/>\n$extra<br/>\n" .
1233 sub format_paging_nav
{
1234 my ($action, $hash, $head, $page, $nrevs) = @_;
1238 if ($hash ne $head || $page) {
1239 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1241 $paging_nav .= "HEAD";
1245 $paging_nav .= " ⋅ " .
1246 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1247 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1249 $paging_nav .= " ⋅ prev";
1252 if ($nrevs >= (100 * ($page+1)-1)) {
1253 $paging_nav .= " ⋅ " .
1254 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1255 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1257 $paging_nav .= " ⋅ next";
1263 ## ......................................................................
1264 ## functions printing or outputting HTML: div
1266 sub git_print_header_div
{
1267 my ($action, $title, $hash, $hash_base) = @_;
1270 $args{action
} = $action;
1271 $args{hash
} = $hash if $hash;
1272 $args{hash_base
} = $hash_base if $hash_base;
1274 print "<div class=\"header\">\n" .
1275 $cgi->a({-href
=> href
(%args), -class => "title"},
1276 $title ?
$title : $action) .
1280 sub git_print_page_path
{
1285 if (!defined $name) {
1286 print "<div class=\"page_path\">/</div>\n";
1287 } elsif (defined $type && $type eq 'blob') {
1288 print "<div class=\"page_path\">";
1290 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1294 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name)},
1297 print "<br/></div>\n";
1299 print "<div class=\"page_path\">" . esc_html
($name) . "<br/></div>\n";
1306 # remove leading empty lines
1307 while (defined $log->[0] && $log->[0] eq "") {
1314 foreach my $line (@
$log) {
1315 # print only one empty line
1316 # do not print empty line after signoff
1318 next if ($empty || $signoff);
1323 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1325 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1328 print format_log_line_html
($line) . "<br/>\n";
1333 sub git_print_simplified_log
{
1335 my $remove_title = shift;
1337 shift @
$log if $remove_title;
1338 # remove leading empty lines
1339 while (defined $log->[0] && $log->[0] eq "") {
1343 # simplify and print log
1345 foreach my $line (@
$log) {
1346 # remove signoff lines
1347 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1350 # print only one empty line
1357 print format_log_line_html
($line) . "<br/>\n";
1359 # end with single empty line
1360 print "<br/>\n" unless $empty;
1363 ## ......................................................................
1364 ## functions printing large fragments of HTML
1366 sub git_difftree_body
{
1367 my ($difftree, $parent) = @_;
1369 print "<div class=\"list_head\">\n";
1370 if ($#{$difftree} > 10) {
1371 print(($#{$difftree} + 1) . " files changed:\n");
1375 print "<table class=\"diff_tree\">\n";
1377 foreach my $line (@
{$difftree}) {
1378 my %diff = parse_difftree_raw_line
($line);
1381 print "<tr class=\"dark\">\n";
1383 print "<tr class=\"light\">\n";
1387 my ($to_mode_oct, $to_mode_str, $to_file_type);
1388 my ($from_mode_oct, $from_mode_str, $from_file_type);
1389 if ($diff{'to_mode'} ne ('0' x
6)) {
1390 $to_mode_oct = oct $diff{'to_mode'};
1391 if (S_ISREG
($to_mode_oct)) { # only for regular file
1392 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1394 $to_file_type = file_type
($diff{'to_mode'});
1396 if ($diff{'from_mode'} ne ('0' x
6)) {
1397 $from_mode_oct = oct $diff{'from_mode'};
1398 if (S_ISREG
($to_mode_oct)) { # only for regular file
1399 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1401 $from_file_type = file_type
($diff{'from_mode'});
1404 if ($diff{'status'} eq "A") { # created
1405 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1406 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1407 $mode_chng .= "]</span>";
1409 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1410 hash_base
=>$hash, file_name
=>$diff{'file'}),
1411 -class => "list"}, esc_html
($diff{'file'})) .
1413 "<td>$mode_chng</td>\n" .
1414 "<td class=\"link\">" .
1415 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1416 hash_base
=>$hash, file_name
=>$diff{'file'})},
1420 } elsif ($diff{'status'} eq "D") { # deleted
1421 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1423 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1424 hash_base
=>$parent, file_name
=>$diff{'file'}),
1425 -class => "list"}, esc_html
($diff{'file'})) .
1427 "<td>$mode_chng</td>\n" .
1428 "<td class=\"link\">" .
1429 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1430 hash_base
=>$parent, file_name
=>$diff{'file'})},
1433 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1434 file_name
=>$diff{'file'})},\
1438 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1439 my $mode_chnge = "";
1440 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1441 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1442 if ($from_file_type != $to_file_type) {
1443 $mode_chnge .= " from $from_file_type to $to_file_type";
1445 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1446 if ($from_mode_str && $to_mode_str) {
1447 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1448 } elsif ($to_mode_str) {
1449 $mode_chnge .= " mode: $to_mode_str";
1452 $mode_chnge .= "]</span>\n";
1455 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1456 print $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1457 hash_base
=>$hash, file_name
=>$diff{'file'}),
1458 -class => "list"}, esc_html
($diff{'file'}));
1459 } else { # only mode changed
1460 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1461 hash_base
=>$hash, file_name
=>$diff{'file'}),
1462 -class => "list"}, esc_html
($diff{'file'}));
1465 "<td>$mode_chnge</td>\n" .
1466 "<td class=\"link\">" .
1467 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1468 hash_base
=>$hash, file_name
=>$diff{'file'})},
1470 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1472 $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1473 hash_base
=>$hash, file_name
=>$diff{'file'})},
1477 $cgi->a({-href
=> href
(action
=>"history",
1478 hash_base
=>$hash, file_name
=>$diff{'file'})},
1482 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1483 my %status_name = ('R' => 'moved', 'C' => 'copied');
1484 my $nstatus = $status_name{$diff{'status'}};
1486 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1487 # mode also for directories, so we cannot use $to_mode_str
1488 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1491 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1492 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1493 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1494 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1495 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1496 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1497 -class => "list"}, esc_html
($diff{'from_file'})) .
1498 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1499 "<td class=\"link\">" .
1500 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1501 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'})},
1503 if ($diff{'to_id'} ne $diff{'from_id'}) {
1505 $cgi->a({-href
=> href
(action
=>"blobdiff", hash_base
=>$hash,
1506 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1507 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1512 } # we should not encounter Unmerged (U) or Unknown (X) status
1518 sub git_shortlog_body
{
1519 # uses global variable $project
1520 my ($revlist, $from, $to, $refs, $extra) = @_;
1522 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
1523 my $have_snapshot = (defined $ctype && defined $suffix);
1525 $from = 0 unless defined $from;
1526 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1528 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1530 for (my $i = $from; $i <= $to; $i++) {
1531 my $commit = $revlist->[$i];
1532 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1533 my $ref = format_ref_marker
($refs, $commit);
1534 my %co = parse_commit
($commit);
1536 print "<tr class=\"dark\">\n";
1538 print "<tr class=\"light\">\n";
1541 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1542 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1543 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1545 print format_subject_html
($co{'title'}, $co{'title_short'},
1546 href
(action
=>"commit", hash
=>$commit), $ref);
1548 "<td class=\"link\">" .
1549 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1550 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
1551 if ($have_snapshot) {
1552 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
1557 if (defined $extra) {
1559 "<td colspan=\"4\">$extra</td>\n" .
1565 sub git_history_body
{
1566 # Warning: assumes constant type (blob or tree) during history
1567 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1569 print "<table class=\"history\" cellspacing=\"0\">\n";
1571 while (my $line = <$fd>) {
1572 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1577 my %co = parse_commit
($commit);
1582 my $ref = format_ref_marker
($refs, $commit);
1585 print "<tr class=\"dark\">\n";
1587 print "<tr class=\"light\">\n";
1590 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1591 # shortlog uses chop_str($co{'author_name'}, 10)
1592 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1594 # originally git_history used chop_str($co{'title'}, 50)
1595 print format_subject_html
($co{'title'}, $co{'title_short'},
1596 href
(action
=>"commit", hash
=>$commit), $ref);
1598 "<td class=\"link\">" .
1599 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1600 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
1601 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype);
1603 if ($ftype eq 'blob') {
1604 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
1605 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
1606 if (defined $blob_current && defined $blob_parent &&
1607 $blob_current ne $blob_parent) {
1609 $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$blob_current, hash_parent
=>$blob_parent,
1610 hash_base
=>$commit, file_name
=>$file_name)},
1617 if (defined $extra) {
1619 "<td colspan=\"4\">$extra</td>\n" .
1626 # uses global variable $project
1627 my ($taglist, $from, $to, $extra) = @_;
1628 $from = 0 unless defined $from;
1629 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1631 print "<table class=\"tags\" cellspacing=\"0\">\n";
1633 for (my $i = $from; $i <= $to; $i++) {
1634 my $entry = $taglist->[$i];
1636 my $comment_lines = $tag{'comment'};
1637 my $comment = shift @
$comment_lines;
1639 if (defined $comment) {
1640 $comment_short = chop_str
($comment, 30, 5);
1643 print "<tr class=\"dark\">\n";
1645 print "<tr class=\"light\">\n";
1648 print "<td><i>$tag{'age'}</i></td>\n" .
1650 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
1651 -class => "list name"}, esc_html
($tag{'name'})) .
1654 if (defined $comment) {
1655 print format_subject_html
($comment, $comment_short,
1656 href
(action
=>"tag", hash
=>$tag{'id'}));
1659 "<td class=\"selflink\">";
1660 if ($tag{'type'} eq "tag") {
1661 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
1666 "<td class=\"link\">" . " | " .
1667 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
1668 if ($tag{'reftype'} eq "commit") {
1669 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
1670 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
1671 } elsif ($tag{'reftype'} eq "blob") {
1672 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
1677 if (defined $extra) {
1679 "<td colspan=\"5\">$extra</td>\n" .
1685 sub git_heads_body
{
1686 # uses global variable $project
1687 my ($taglist, $head, $from, $to, $extra) = @_;
1688 $from = 0 unless defined $from;
1689 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1691 print "<table class=\"heads\" cellspacing=\"0\">\n";
1693 for (my $i = $from; $i <= $to; $i++) {
1694 my $entry = $taglist->[$i];
1696 my $curr = $tag{'id'} eq $head;
1698 print "<tr class=\"dark\">\n";
1700 print "<tr class=\"light\">\n";
1703 print "<td><i>$tag{'age'}</i></td>\n" .
1704 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1705 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
1706 -class => "list name"},esc_html
($tag{'name'})) .
1708 "<td class=\"link\">" .
1709 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
1710 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") .
1714 if (defined $extra) {
1716 "<td colspan=\"3\">$extra</td>\n" .
1722 ## ----------------------------------------------------------------------
1723 ## functions printing large fragments, format as one of arguments
1725 sub git_diff_print
{
1727 my $from_name = shift;
1729 my $to_name = shift;
1730 my $format = shift || "html";
1732 my $from_tmp = "/dev/null";
1733 my $to_tmp = "/dev/null";
1736 # create tmp from-file
1737 if (defined $from) {
1738 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1739 open my $fd2, "> $from_tmp";
1740 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1747 # create tmp to-file
1749 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1750 open my $fd2, "> $to_tmp";
1751 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1758 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1759 if ($format eq "plain") {
1764 while (my $line = <$fd>) {
1766 my $char = substr($line, 0, 1);
1767 my $diff_class = "";
1769 $diff_class = " add";
1770 } elsif ($char eq "-") {
1771 $diff_class = " rem";
1772 } elsif ($char eq "@") {
1773 $diff_class = " chunk_header";
1774 } elsif ($char eq "\\") {
1778 $line = untabify
($line);
1779 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
1784 if (defined $from) {
1793 ## ======================================================================
1794 ## ======================================================================
1797 sub git_project_list
{
1798 my $order = $cgi->param('o');
1799 if (defined $order && $order !~ m/project|descr|owner|age/) {
1800 die_error
(undef, "Unknown order parameter");
1803 my @list = git_get_projects_list
();
1806 die_error
(undef, "No projects found");
1808 foreach my $pr (@list) {
1809 my $head = git_get_head_hash
($pr->{'path'});
1810 if (!defined $head) {
1813 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1814 my %co = parse_commit
($head);
1818 $pr->{'commit'} = \
%co;
1819 if (!defined $pr->{'descr'}) {
1820 my $descr = git_get_project_description
($pr->{'path'}) || "";
1821 $pr->{'descr'} = chop_str
($descr, 25, 5);
1823 if (!defined $pr->{'owner'}) {
1824 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
1826 push @projects, $pr;
1830 if (-f
$home_text) {
1831 print "<div class=\"index_include\">\n";
1832 open (my $fd, $home_text);
1837 print "<table class=\"project_list\">\n" .
1839 $order ||= "project";
1840 if ($order eq "project") {
1841 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1842 print "<th>Project</th>\n";
1845 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
1846 -class => "header"}, "Project") .
1849 if ($order eq "descr") {
1850 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1851 print "<th>Description</th>\n";
1854 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
1855 -class => "header"}, "Description") .
1858 if ($order eq "owner") {
1859 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1860 print "<th>Owner</th>\n";
1863 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
1864 -class => "header"}, "Owner") .
1867 if ($order eq "age") {
1868 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1869 print "<th>Last Change</th>\n";
1872 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
1873 -class => "header"}, "Last Change") .
1876 print "<th></th>\n" .
1879 foreach my $pr (@projects) {
1881 print "<tr class=\"dark\">\n";
1883 print "<tr class=\"light\">\n";
1886 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
1887 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
1888 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
1889 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
1890 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
1891 $pr->{'commit'}{'age_string'} . "</td>\n" .
1892 "<td class=\"link\">" .
1893 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
1894 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
1895 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") .
1904 my $descr = git_get_project_description
($project) || "none";
1905 my $head = git_get_head_hash
($project);
1906 my %co = parse_commit
($head);
1907 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
1909 my $owner = git_get_project_owner
($project);
1911 my $refs = git_get_references
();
1913 git_print_page_nav
('summary','', $head);
1915 print "<div class=\"title\"> </div>\n";
1916 print "<table cellspacing=\"0\">\n" .
1917 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1918 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1919 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
1920 # use per project git URL list in $projectroot/$project/cloneurl
1921 # or make project git URL from git base URL and project name
1922 my $url_tag = "URL";
1923 my @url_list = git_get_project_url_list
($project);
1924 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
1925 foreach my $git_url (@url_list) {
1926 next unless $git_url;
1927 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
1932 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash
($project)
1933 or die_error
(undef, "Open git-rev-list failed");
1934 my @revlist = map { chomp; $_ } <$fd>;
1936 git_print_header_div
('shortlog');
1937 git_shortlog_body
(\
@revlist, 0, 15, $refs,
1938 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
1940 my $taglist = git_get_refs_list
("refs/tags");
1941 if (defined @
$taglist) {
1942 git_print_header_div
('tags');
1943 git_tags_body
($taglist, 0, 15,
1944 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
1947 my $headlist = git_get_refs_list
("refs/heads");
1948 if (defined @
$headlist) {
1949 git_print_header_div
('heads');
1950 git_heads_body
($headlist, $head, 0, 15,
1951 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
1958 my $head = git_get_head_hash
($project);
1960 git_print_page_nav
('','', $head,undef,$head);
1961 my %tag = parse_tag
($hash);
1962 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
1963 print "<div class=\"title_text\">\n" .
1964 "<table cellspacing=\"0\">\n" .
1966 "<td>object</td>\n" .
1967 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
1968 $tag{'object'}) . "</td>\n" .
1969 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
1970 $tag{'type'}) . "</td>\n" .
1972 if (defined($tag{'author'})) {
1973 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
1974 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1975 print "<tr><td></td><td>" . $ad{'rfc2822'} .
1976 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
1979 print "</table>\n\n" .
1981 print "<div class=\"page_body\">";
1982 my $comment = $tag{'comment'};
1983 foreach my $line (@
$comment) {
1984 print esc_html
($line) . "<br/>\n";
1994 if (!gitweb_check_feature
('blame')) {
1995 die_error
('403 Permission denied', "Permission denied");
1997 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1998 $hash_base ||= git_get_head_hash
($project);
1999 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2000 my %co = parse_commit
($hash_base)
2001 or die_error
(undef, "Reading commit failed");
2002 if (!defined $hash) {
2003 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2004 or die_error
(undef, "Error looking up file");
2006 $ftype = git_get_type
($hash);
2007 if ($ftype !~ "blob") {
2008 die_error
("400 Bad Request", "Object is not a blob");
2010 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
2011 or die_error
(undef, "Open git-blame failed");
2014 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2017 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2019 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2020 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2021 git_print_page_path
($file_name, $ftype, $hash_base);
2022 my @rev_color = (qw(light2 dark2));
2023 my $num_colors = scalar(@rev_color);
2024 my $current_color = 0;
2026 print "<div class=\"page_body\">\n";
2027 print "<table class=\"blame\">\n";
2028 print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
2030 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2032 my $rev = substr($full_rev, 0, 8);
2036 if (!defined $last_rev) {
2037 $last_rev = $full_rev;
2038 } elsif ($last_rev ne $full_rev) {
2039 $last_rev = $full_rev;
2040 $current_color = ++$current_color % $num_colors;
2042 print "<tr class=\"$rev_color[$current_color]\">\n";
2043 print "<td class=\"sha1\">" .
2044 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)},
2045 esc_html
($rev)) . "</td>\n";
2046 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2047 esc_html
($lineno) . "</a></td>\n";
2048 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2054 or print "Reading blob failed\n";
2061 if (!gitweb_check_feature
('blame')) {
2062 die_error
('403 Permission denied', "Permission denied");
2064 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2065 $hash_base ||= git_get_head_hash
($project);
2066 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2067 my %co = parse_commit
($hash_base)
2068 or die_error
(undef, "Reading commit failed");
2069 if (!defined $hash) {
2070 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2071 or die_error
(undef, "Error lookup file");
2073 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2074 or die_error
(undef, "Open git-annotate failed");
2077 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2080 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2082 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2083 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2084 git_print_page_path
($file_name, 'blob', $hash_base);
2085 print "<div class=\"page_body\">\n";
2087 <table class="blame">
2096 my @line_class = (qw(light dark));
2097 my $line_class_len = scalar (@line_class);
2098 my $line_class_num = $#line_class;
2099 while (my $line = <$fd>) {
2111 $line_class_num = ($line_class_num + 1) % $line_class_len;
2113 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
2120 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2123 $short_rev = substr ($long_rev, 0, 8);
2124 $age = time () - $time;
2125 $age_str = age_string
($age);
2126 $age_str =~ s/ / /g;
2127 $age_class = age_class
($age);
2128 $author = esc_html
($author);
2129 $author =~ s/ / /g;
2131 $data = untabify
($data);
2132 $data = esc_html
($data);
2135 <tr class="$line_class[$line_class_num]">
2136 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2137 <td class="$age_class">$age_str</td>
2139 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2140 <td class="pre">$data</td>
2143 } # while (my $line = <$fd>)
2144 print "</table>\n\n";
2146 or print "Reading blob failed.\n";
2152 my $head = git_get_head_hash
($project);
2154 git_print_page_nav
('','', $head,undef,$head);
2155 git_print_header_div
('summary', $project);
2157 my $taglist = git_get_refs_list
("refs/tags");
2158 if (defined @
$taglist) {
2159 git_tags_body
($taglist);
2165 my $head = git_get_head_hash
($project);
2167 git_print_page_nav
('','', $head,undef,$head);
2168 git_print_header_div
('summary', $project);
2170 my $taglist = git_get_refs_list
("refs/heads");
2171 if (defined @
$taglist) {
2172 git_heads_body
($taglist, $head);
2177 sub git_blob_plain
{
2178 if (!defined $hash) {
2179 if (defined $file_name) {
2180 my $base = $hash_base || git_get_head_hash
($project);
2181 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2182 or die_error
(undef, "Error lookup file");
2184 die_error
(undef, "No file name defined");
2188 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2189 or die_error
(undef, "Couldn't cat $file_name, $hash");
2191 $type ||= blob_mimetype
($fd, $file_name);
2193 # save as filename, even when no $file_name is given
2194 my $save_as = "$hash";
2195 if (defined $file_name) {
2196 $save_as = $file_name;
2197 } elsif ($type =~ m/^text\//) {
2201 print $cgi->header(-type
=> "$type", '-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".