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 # target of the home link on top of all pages
35 our $home_link = $my_uri || "/";
37 # string of the home link on top of all pages
38 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
40 # name of your site or organization to appear in page titles
41 # replace this with something more descriptive for clearer bookmarks
42 our $site_name = "++GITWEB_SITENAME++" || $ENV{'SERVER_NAME'} || "Untitled";
44 # html text to include at home page
45 our $home_text = "++GITWEB_HOMETEXT++";
47 # URI of default stylesheet
48 our $stylesheet = "++GITWEB_CSS++";
50 our $logo = "++GITWEB_LOGO++";
52 # source of projects list
53 our $projects_list = "++GITWEB_LIST++";
55 # list of git base URLs used for URL to where fetch project from,
56 # i.e. full URL is "$git_base_url/$project"
57 our @git_base_url_list = ("++GITWEB_BASE_URL++");
59 # default blob_plain mimetype and default charset for text/plain blob
60 our $default_blob_plain_mimetype = 'text/plain';
61 our $default_text_plain_charset = undef;
63 # file to use for guessing MIME types before trying /etc/mime.types
64 # (relative to the current git repository)
65 our $mimetypes_file = undef;
67 # You define site-wide feature defaults here; override them with
68 # $GITWEB_CONFIG as necessary.
71 # 'sub' => feature-sub (subroutine),
72 # 'override' => allow-override (boolean),
73 # 'default' => [ default options...] (array reference)}
75 # if feature is overridable (it means that allow-override has true value,
76 # then feature-sub will be called with default options as parameters;
77 # return value of feature-sub indicates if to enable specified feature
79 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
82 'sub' => \
&feature_blame
,
87 'sub' => \
&feature_snapshot
,
89 # => [content-encoding, suffix, program]
90 'default' => ['x-gzip', 'gz', 'gzip']},
93 sub gitweb_check_feature
{
95 return undef unless exists $feature{$name};
96 my ($sub, $override, @defaults) = (
97 $feature{$name}{'sub'},
98 $feature{$name}{'override'},
99 @
{$feature{$name}{'default'}});
100 if (!$override) { return @defaults; }
101 return $sub->(@defaults);
104 # To enable system wide have in $GITWEB_CONFIG
105 # $feature{'blame'}{'default'} = [1];
106 # To have project specific config enable override in $GITWEB_CONFIG
107 # $feature{'blame'}{'override'} = 1;
108 # and in project config gitweb.blame = 0|1;
111 my ($val) = git_get_project_config
('blame', '--bool');
113 if ($val eq 'true') {
115 } elsif ($val eq 'false') {
122 # To disable system wide have in $GITWEB_CONFIG
123 # $feature{'snapshot'}{'default'} = [undef];
124 # To have project specific config enable override in $GITWEB_CONFIG
125 # $feature{'blame'}{'override'} = 1;
126 # and in project config gitweb.snapshot = none|gzip|bzip2
128 sub feature_snapshot
{
129 my ($ctype, $suffix, $command) = @_;
131 my ($val) = git_get_project_config
('snapshot');
133 if ($val eq 'gzip') {
134 return ('x-gzip', 'gz', 'gzip');
135 } elsif ($val eq 'bzip2') {
136 return ('x-bzip2', 'bz2', 'bzip2');
137 } elsif ($val eq 'none') {
141 return ($ctype, $suffix, $command);
144 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
145 require $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
147 # version of the core git binary
148 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
150 $projects_list ||= $projectroot;
152 # ======================================================================
153 # input validation and dispatch
154 our $action = $cgi->param('a');
155 if (defined $action) {
156 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
157 die_error
(undef, "Invalid action parameter");
161 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
162 if (defined $project) {
165 $project = undef unless $project;
167 if (defined $project) {
168 if (!validate_input
($project)) {
169 die_error
(undef, "Invalid project parameter");
171 if (!(-d
"$projectroot/$project")) {
172 die_error
(undef, "No such directory");
174 if (!(-e
"$projectroot/$project/HEAD")) {
175 die_error
(undef, "No such project");
177 $ENV{'GIT_DIR'} = "$projectroot/$project";
180 our $file_name = $cgi->param('f');
181 if (defined $file_name) {
182 if (!validate_input
($file_name)) {
183 die_error
(undef, "Invalid file parameter");
187 our $file_parent = $cgi->param('fp');
188 if (defined $file_parent) {
189 if (!validate_input
($file_parent)) {
190 die_error
(undef, "Invalid file parent parameter");
194 our $hash = $cgi->param('h');
196 if (!validate_input
($hash)) {
197 die_error
(undef, "Invalid hash parameter");
201 our $hash_parent = $cgi->param('hp');
202 if (defined $hash_parent) {
203 if (!validate_input
($hash_parent)) {
204 die_error
(undef, "Invalid hash parent parameter");
208 our $hash_base = $cgi->param('hb');
209 if (defined $hash_base) {
210 if (!validate_input
($hash_base)) {
211 die_error
(undef, "Invalid hash base parameter");
215 our $hash_parent_base = $cgi->param('hpb');
216 if (defined $hash_parent_base) {
217 if (!validate_input
($hash_parent_base)) {
218 die_error
(undef, "Invalid hash parent 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
,
258 # those below don't need $project
259 "opml" => \
&git_opml
,
260 "project_list" => \
&git_project_list
,
263 if (defined $project) {
264 $action ||= 'summary';
266 $action ||= 'project_list';
268 if (!defined($actions{$action})) {
269 die_error
(undef, "Unknown action");
271 $actions{$action}->();
274 ## ======================================================================
288 hash_parent_base
=> "hpb",
292 my %mapping = @mapping;
294 $params{"project"} ||= $project;
297 for (my $i = 0; $i < @mapping; $i += 2) {
298 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
299 if (defined $params{$name}) {
300 push @result, $symbol . "=" . esc_param
($params{$name});
303 return "$my_uri?" . join(';', @result);
307 ## ======================================================================
308 ## validation, quoting/unquoting and escaping
313 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
316 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
319 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
325 # quote unsafe chars, but keep the slash, even when it's not
326 # correct, but quoted slashes look too horrible in bookmarks
329 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
335 # replace invalid utf8 character with SUBSTITUTION sequence
338 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
339 $str = escapeHTML
($str);
340 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
344 # git may return quoted and escaped filenames
347 if ($str =~ m/^"(.*)"$/) {
349 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
354 # escape tabs (convert tabs to spaces)
358 while ((my $pos = index($line, "\t")) != -1) {
359 if (my $count = (8 - ($pos % 8))) {
360 my $spaces = ' ' x
$count;
361 $line =~ s/\t/$spaces/;
368 ## ----------------------------------------------------------------------
369 ## HTML aware string manipulation
374 my $add_len = shift || 10;
376 # allow only $len chars, but don't cut a word if it would fit in $add_len
377 # if it doesn't fit, cut it if it's still longer than the dots we would add
378 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
381 if (length($tail) > 4) {
383 $body =~ s/&[^;]*$//; # remove chopped character entities
388 ## ----------------------------------------------------------------------
389 ## functions returning short strings
391 # CSS class for given age value (in seconds)
395 if ($age < 60*60*2) {
397 } elsif ($age < 60*60*24*2) {
404 # convert age in seconds to "nn units ago" string
409 if ($age > 60*60*24*365*2) {
410 $age_str = (int $age/60/60/24/365);
411 $age_str .= " years ago";
412 } elsif ($age > 60*60*24*(365/12)*2) {
413 $age_str = int $age/60/60/24/(365/12);
414 $age_str .= " months ago";
415 } elsif ($age > 60*60*24*7*2) {
416 $age_str = int $age/60/60/24/7;
417 $age_str .= " weeks ago";
418 } elsif ($age > 60*60*24*2) {
419 $age_str = int $age/60/60/24;
420 $age_str .= " days ago";
421 } elsif ($age > 60*60*2) {
422 $age_str = int $age/60/60;
423 $age_str .= " hours ago";
424 } elsif ($age > 60*2) {
425 $age_str = int $age/60;
426 $age_str .= " min ago";
429 $age_str .= " sec ago";
431 $age_str .= " right now";
436 # convert file mode in octal to symbolic file mode string
438 my $mode = oct shift;
440 if (S_ISDIR
($mode & S_IFMT
)) {
442 } elsif (S_ISLNK
($mode)) {
444 } elsif (S_ISREG
($mode)) {
445 # git cares only about the executable bit
446 if ($mode & S_IXUSR
) {
456 # convert file mode in octal to file type string
460 if ($mode !~ m/^[0-7]+$/) {
466 if (S_ISDIR
($mode & S_IFMT
)) {
468 } elsif (S_ISLNK
($mode)) {
470 } elsif (S_ISREG
($mode)) {
477 ## ----------------------------------------------------------------------
478 ## functions returning short HTML fragments, or transforming HTML fragments
479 ## which don't beling to other sections
481 # format line of commit message or tag comment
482 sub format_log_line_html
{
485 $line = esc_html
($line);
486 $line =~ s/ / /g;
487 if ($line =~ m/([0-9a-fA-F]{40})/) {
489 if (git_get_type
($hash_text) eq "commit") {
491 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
492 -class => "text"}, $hash_text);
493 $line =~ s/$hash_text/$link/;
499 # format marker of refs pointing to given object
500 sub format_ref_marker
{
501 my ($refs, $id) = @_;
504 if (defined $refs->{$id}) {
505 foreach my $ref (@
{$refs->{$id}}) {
506 my ($type, $name) = qw();
507 # e.g. tags/v2.6.11 or heads/next
508 if ($ref =~ m!^(.*?)s?/(.*)$!) {
516 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
521 return ' <span class="refs">'. $markers . '</span>';
527 # format, perhaps shortened and with markers, title line
528 sub format_subject_html
{
529 my ($long, $short, $href, $extra) = @_;
530 $extra = '' unless defined($extra);
532 if (length($short) < length($long)) {
533 return $cgi->a({-href
=> $href, -class => "list subject",
535 esc_html
($short) . $extra);
537 return $cgi->a({-href
=> $href, -class => "list subject"},
538 esc_html
($long) . $extra);
542 sub format_diff_line
{
544 my $char = substr($line, 0, 1);
550 $diff_class = " add";
551 } elsif ($char eq "-") {
552 $diff_class = " rem";
553 } elsif ($char eq "@") {
554 $diff_class = " chunk_header";
555 } elsif ($char eq "\\") {
556 $diff_class = " incomplete";
558 $line = untabify
($line);
559 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
562 ## ----------------------------------------------------------------------
563 ## git utility subroutines, invoking git commands
565 # get HEAD ref of given project as hash
566 sub git_get_head_hash
{
568 my $oENV = $ENV{'GIT_DIR'};
570 $ENV{'GIT_DIR'} = "$projectroot/$project";
571 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
574 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
579 $ENV{'GIT_DIR'} = $oENV;
584 # get type of given object
588 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
595 sub git_get_project_config
{
596 my ($key, $type) = @_;
598 return unless ($key);
599 $key =~ s/^gitweb\.//;
600 return if ($key =~ m/\W/);
602 my @x = ($GIT, 'repo-config');
603 if (defined $type) { push @x, $type; }
605 push @x, "gitweb.$key";
611 # get hash of given path at given ref
612 sub git_get_hash_by_path
{
614 my $path = shift || return undef;
618 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
619 or die_error
(undef, "Open git-ls-tree failed");
621 close $fd or return undef;
623 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
624 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
628 # converts symbolic name to hash
631 return undef unless @params;
633 open my $fd, "-|", $GIT, "rev-parse", @params
635 my @hashes = map { chomp; $_ } <$fd>;
640 } elsif (scalar(@hashes) == 1) {
648 ## ......................................................................
649 ## git utility functions, directly accessing git repository
651 # assumes that PATH is not symref
652 sub git_get_hash_by_ref
{
655 open my $fd, "$projectroot/$path" or return undef;
659 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
664 sub git_get_project_description
{
667 open my $fd, "$projectroot/$path/description" or return undef;
674 sub git_get_project_url_list
{
677 open my $fd, "$projectroot/$path/cloneurl" or return undef;
678 my @git_project_url_list = map { chomp; $_ } <$fd>;
681 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
684 sub git_get_projects_list
{
687 if (-d
$projects_list) {
688 # search in directory
689 my $dir = $projects_list;
690 opendir my ($dh), $dir or return undef;
691 while (my $dir = readdir($dh)) {
692 if (-e
"$projectroot/$dir/HEAD") {
700 } elsif (-f
$projects_list) {
701 # read from file(url-encoded):
702 # 'git%2Fgit.git Linus+Torvalds'
703 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
704 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
705 open my ($fd), $projects_list or return undef;
706 while (my $line = <$fd>) {
708 my ($path, $owner) = split ' ', $line;
709 $path = unescape
($path);
710 $owner = unescape
($owner);
711 if (!defined $path) {
714 if (-e
"$projectroot/$path/HEAD") {
717 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
724 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
728 sub git_get_project_owner
{
732 return undef unless $project;
734 # read from file (url-encoded):
735 # 'git%2Fgit.git Linus+Torvalds'
736 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
737 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
738 if (-f
$projects_list) {
739 open (my $fd , $projects_list);
740 while (my $line = <$fd>) {
742 my ($pr, $ow) = split ' ', $line;
745 if ($pr eq $project) {
746 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
752 if (!defined $owner) {
753 $owner = get_file_owner
("$projectroot/$project");
759 sub git_get_references
{
760 my $type = shift || "";
763 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
764 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
765 if (-f
"$projectroot/$project/info/refs") {
766 open $fd, "$projectroot/$project/info/refs"
769 open $fd, "-|", $GIT, "ls-remote", "."
773 while (my $line = <$fd>) {
775 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
776 if (defined $refs{$1}) {
777 push @
{$refs{$1}}, $2;
787 sub git_get_rev_name_tags
{
788 my $hash = shift || return undef;
790 open my $fd, "-|", $GIT, "name-rev", "--tags", $hash
792 my $name_rev = <$fd>;
795 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
798 # catches also '$hash undefined' output
803 ## ----------------------------------------------------------------------
804 ## parse to hash functions
808 my $tz = shift || "-0000";
811 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
812 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
813 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
814 $date{'hour'} = $hour;
815 $date{'minute'} = $min;
816 $date{'mday'} = $mday;
817 $date{'day'} = $days[$wday];
818 $date{'month'} = $months[$mon];
819 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
820 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
821 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
822 $mday, $months[$mon], $hour ,$min;
824 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
825 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
826 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
827 $date{'hour_local'} = $hour;
828 $date{'minute_local'} = $min;
829 $date{'tz_local'} = $tz;
838 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
839 $tag{'id'} = $tag_id;
840 while (my $line = <$fd>) {
842 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
844 } elsif ($line =~ m/^type (.+)$/) {
846 } elsif ($line =~ m/^tag (.+)$/) {
848 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
852 } elsif ($line =~ m/--BEGIN/) {
853 push @comment, $line;
855 } elsif ($line eq "") {
859 push @comment, <$fd>;
860 $tag{'comment'} = \
@comment;
862 if (!defined $tag{'name'}) {
869 my $commit_id = shift;
870 my $commit_text = shift;
875 if (defined $commit_text) {
876 @commit_lines = @
$commit_text;
879 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id
881 @commit_lines = split '\n', <$fd>;
886 my $header = shift @commit_lines;
887 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
890 ($co{'id'}, my @parents) = split ' ', $header;
891 $co{'parents'} = \
@parents;
892 $co{'parent'} = $parents[0];
893 while (my $line = shift @commit_lines) {
894 last if $line eq "\n";
895 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
897 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
899 $co{'author_epoch'} = $2;
900 $co{'author_tz'} = $3;
901 if ($co{'author'} =~ m/^([^<]+) </) {
902 $co{'author_name'} = $1;
904 $co{'author_name'} = $co{'author'};
906 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
907 $co{'committer'} = $1;
908 $co{'committer_epoch'} = $2;
909 $co{'committer_tz'} = $3;
910 $co{'committer_name'} = $co{'committer'};
911 $co{'committer_name'} =~ s/ <.*//;
914 if (!defined $co{'tree'}) {
918 foreach my $title (@commit_lines) {
921 $co{'title'} = chop_str
($title, 80, 5);
922 # remove leading stuff of merges to make the interesting part visible
923 if (length($title) > 50) {
924 $title =~ s/^Automatic //;
925 $title =~ s/^merge (of|with) /Merge ... /i;
926 if (length($title) > 50) {
927 $title =~ s/(http|rsync):\/\///;
929 if (length($title) > 50) {
930 $title =~ s/(master|www|rsync)\.//;
932 if (length($title) > 50) {
933 $title =~ s/kernel.org:?//;
935 if (length($title) > 50) {
936 $title =~ s/\/pub\/scm//;
939 $co{'title_short'} = chop_str
($title, 50, 5);
943 # remove added spaces
944 foreach my $line (@commit_lines) {
947 $co{'comment'} = \
@commit_lines;
949 my $age = time - $co{'committer_epoch'};
951 $co{'age_string'} = age_string
($age);
952 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
953 if ($age > 60*60*24*7*2) {
954 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
955 $co{'age_string_age'} = $co{'age_string'};
957 $co{'age_string_date'} = $co{'age_string'};
958 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
963 # parse ref from ref_file, given by ref_id, with given type
965 my $ref_file = shift;
967 my $type = shift || git_get_type
($ref_id);
970 $ref_item{'type'} = $type;
971 $ref_item{'id'} = $ref_id;
972 $ref_item{'epoch'} = 0;
973 $ref_item{'age'} = "unknown";
974 if ($type eq "tag") {
975 my %tag = parse_tag
($ref_id);
976 $ref_item{'comment'} = $tag{'comment'};
977 if ($tag{'type'} eq "commit") {
978 my %co = parse_commit
($tag{'object'});
979 $ref_item{'epoch'} = $co{'committer_epoch'};
980 $ref_item{'age'} = $co{'age_string'};
981 } elsif (defined($tag{'epoch'})) {
982 my $age = time - $tag{'epoch'};
983 $ref_item{'epoch'} = $tag{'epoch'};
984 $ref_item{'age'} = age_string
($age);
986 $ref_item{'reftype'} = $tag{'type'};
987 $ref_item{'name'} = $tag{'name'};
988 $ref_item{'refid'} = $tag{'object'};
989 } elsif ($type eq "commit"){
990 my %co = parse_commit
($ref_id);
991 $ref_item{'reftype'} = "commit";
992 $ref_item{'name'} = $ref_file;
993 $ref_item{'title'} = $co{'title'};
994 $ref_item{'refid'} = $ref_id;
995 $ref_item{'epoch'} = $co{'committer_epoch'};
996 $ref_item{'age'} = $co{'age_string'};
998 $ref_item{'reftype'} = $type;
999 $ref_item{'name'} = $ref_file;
1000 $ref_item{'refid'} = $ref_id;
1006 # parse line of git-diff-tree "raw" output
1007 sub parse_difftree_raw_line
{
1011 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1012 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1013 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1014 $res{'from_mode'} = $1;
1015 $res{'to_mode'} = $2;
1016 $res{'from_id'} = $3;
1018 $res{'status'} = $5;
1019 $res{'similarity'} = $6;
1020 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1021 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1023 $res{'file'} = unquote
($7);
1026 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1027 #elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1028 # $res{'commit'} = $1;
1031 return wantarray ?
%res : \
%res;
1034 ## ......................................................................
1035 ## parse to array of hashes functions
1037 sub git_get_refs_list
{
1038 my $ref_dir = shift;
1042 my $pfxlen = length("$projectroot/$project/$ref_dir");
1043 File
::Find
::find
(sub {
1046 push @refs, substr($File::Find
::name
, $pfxlen + 1);
1048 }, "$projectroot/$project/$ref_dir");
1050 foreach my $ref_file (@refs) {
1051 my $ref_id = git_get_hash_by_ref
("$project/$ref_dir/$ref_file");
1052 my $type = git_get_type
($ref_id) || next;
1053 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1055 push @reflist, \
%ref_item;
1058 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1062 ## ----------------------------------------------------------------------
1063 ## filesystem-related functions
1065 sub get_file_owner
{
1068 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1069 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1070 if (!defined $gcos) {
1074 $owner =~ s/[,;].*$//;
1075 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
1078 ## ......................................................................
1079 ## mimetype related functions
1081 sub mimetype_guess_file
{
1082 my $filename = shift;
1083 my $mimemap = shift;
1084 -r
$mimemap or return undef;
1087 open(MIME
, $mimemap) or return undef;
1089 next if m/^#/; # skip comments
1090 my ($mime, $exts) = split(/\t+/);
1091 if (defined $exts) {
1092 my @exts = split(/\s+/, $exts);
1093 foreach my $ext (@exts) {
1094 $mimemap{$ext} = $mime;
1100 $filename =~ /\.(.*?)$/;
1101 return $mimemap{$1};
1104 sub mimetype_guess
{
1105 my $filename = shift;
1107 $filename =~ /\./ or return undef;
1109 if ($mimetypes_file) {
1110 my $file = $mimetypes_file;
1111 if ($file !~ m!^/!) { # if it is relative path
1112 # it is relative to project
1113 $file = "$projectroot/$project/$file";
1115 $mime = mimetype_guess_file
($filename, $file);
1117 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1123 my $filename = shift;
1126 my $mime = mimetype_guess
($filename);
1127 $mime and return $mime;
1131 return $default_blob_plain_mimetype unless $fd;
1134 return 'text/plain' .
1135 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1136 } elsif (! $filename) {
1137 return 'application/octet-stream';
1138 } elsif ($filename =~ m/\.png$/i) {
1140 } elsif ($filename =~ m/\.gif$/i) {
1142 } elsif ($filename =~ m/\.jpe?g$/i) {
1143 return 'image/jpeg';
1145 return 'application/octet-stream';
1149 ## ======================================================================
1150 ## functions printing HTML: header, footer, error page
1152 sub git_header_html
{
1153 my $status = shift || "200 OK";
1154 my $expires = shift;
1156 my $title = "$site_name git";
1157 if (defined $project) {
1158 $title .= " - $project";
1159 if (defined $action) {
1160 $title .= "/$action";
1161 if (defined $file_name) {
1162 $title .= " - $file_name";
1163 if ($action eq "tree" && $file_name !~ m
|/$|) {
1170 # require explicit support from the UA if we are to send the page as
1171 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1172 # we have to do this because MSIE sometimes globs '*/*', pretending to
1173 # support xhtml+xml but choking when it gets what it asked for.
1174 if (defined $cgi->http('HTTP_ACCEPT') &&
1175 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1176 $cgi->Accept('application/xhtml+xml') != 0) {
1177 $content_type = 'application/xhtml+xml';
1179 $content_type = 'text/html';
1181 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1182 -status
=> $status, -expires
=> $expires);
1184 <?xml version="1.0" encoding="utf-8"?>
1185 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1186 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1187 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1188 <!-- git core binaries version $git_version -->
1190 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1191 <meta name="generator" content="gitweb/$version git/$git_version"/>
1192 <meta name="robots" content="index, nofollow"/>
1193 <title>$title</title>
1194 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1196 if (defined $project) {
1197 printf('<link rel="alternate" title="%s log" '.
1198 'href="%s" type="application/rss+xml"/>'."\n",
1199 esc_param
($project), href
(action
=>"rss"));
1204 "<div class=\"page_header\">\n" .
1205 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1206 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1208 print $cgi->a({-href
=> esc_param
($home_link)}, $home_link_str) . " / ";
1209 if (defined $project) {
1210 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1211 if (defined $action) {
1215 if (!defined $searchtext) {
1219 if (defined $hash_base) {
1220 $search_hash = $hash_base;
1221 } elsif (defined $hash) {
1222 $search_hash = $hash;
1224 $search_hash = "HEAD";
1226 $cgi->param("a", "search");
1227 $cgi->param("h", $search_hash);
1228 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1229 "<div class=\"search\">\n" .
1230 $cgi->hidden(-name
=> "p") . "\n" .
1231 $cgi->hidden(-name
=> "a") . "\n" .
1232 $cgi->hidden(-name
=> "h") . "\n" .
1233 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1235 $cgi->end_form() . "\n";
1240 sub git_footer_html
{
1241 print "<div class=\"page_footer\">\n";
1242 if (defined $project) {
1243 my $descr = git_get_project_description
($project);
1244 if (defined $descr) {
1245 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1247 print $cgi->a({-href
=> href
(action
=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1249 print $cgi->a({-href
=> href
(action
=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1257 my $status = shift || "403 Forbidden";
1258 my $error = shift || "Malformed query, file missing or permission denied";
1260 git_header_html
($status);
1262 <div class="page_body">
1272 ## ----------------------------------------------------------------------
1273 ## functions printing or outputting HTML: navigation
1275 sub git_print_page_nav
{
1276 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1277 $extra = '' if !defined $extra; # pager or formats
1279 my @navs = qw(summary shortlog log commit commitdiff tree);
1281 @navs = grep { $_ ne $suppress } @navs;
1284 my %arg = map { $_ => {action
=>$_} } @navs;
1285 if (defined $head) {
1286 for (qw(commit commitdiff)) {
1287 $arg{$_}{hash
} = $head;
1289 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1290 for (qw(shortlog log)) {
1291 $arg{$_}{hash
} = $head;
1295 $arg{tree
}{hash
} = $treehead if defined $treehead;
1296 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1298 print "<div class=\"page_nav\">\n" .
1300 map { $_ eq $current ?
1301 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1303 print "<br/>\n$extra<br/>\n" .
1307 sub format_paging_nav
{
1308 my ($action, $hash, $head, $page, $nrevs) = @_;
1312 if ($hash ne $head || $page) {
1313 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1315 $paging_nav .= "HEAD";
1319 $paging_nav .= " ⋅ " .
1320 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1321 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1323 $paging_nav .= " ⋅ prev";
1326 if ($nrevs >= (100 * ($page+1)-1)) {
1327 $paging_nav .= " ⋅ " .
1328 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1329 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1331 $paging_nav .= " ⋅ next";
1337 ## ......................................................................
1338 ## functions printing or outputting HTML: div
1340 sub git_print_header_div
{
1341 my ($action, $title, $hash, $hash_base) = @_;
1344 $args{action
} = $action;
1345 $args{hash
} = $hash if $hash;
1346 $args{hash_base
} = $hash_base if $hash_base;
1348 print "<div class=\"header\">\n" .
1349 $cgi->a({-href
=> href
(%args), -class => "title"},
1350 $title ?
$title : $action) .
1354 sub git_print_page_path
{
1359 if (!defined $name) {
1360 print "<div class=\"page_path\">/</div>\n";
1361 } elsif (defined $type && $type eq 'blob') {
1362 print "<div class=\"page_path\">";
1364 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1368 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name)},
1371 print "<br/></div>\n";
1373 print "<div class=\"page_path\">" . esc_html
($name) . "<br/></div>\n";
1380 # remove leading empty lines
1381 while (defined $log->[0] && $log->[0] eq "") {
1388 foreach my $line (@
$log) {
1389 # print only one empty line
1390 # do not print empty line after signoff
1392 next if ($empty || $signoff);
1397 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1399 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1402 print format_log_line_html
($line) . "<br/>\n";
1407 sub git_print_simplified_log
{
1409 my $remove_title = shift;
1411 shift @
$log if $remove_title;
1412 # remove leading empty lines
1413 while (defined $log->[0] && $log->[0] eq "") {
1417 # simplify and print log
1419 foreach my $line (@
$log) {
1420 # remove signoff lines
1421 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1424 # print only one empty line
1431 print format_log_line_html
($line) . "<br/>\n";
1433 # end with single empty line
1434 print "<br/>\n" unless $empty;
1437 ## ......................................................................
1438 ## functions printing large fragments of HTML
1440 sub git_difftree_body
{
1441 my ($difftree, $hash, $parent) = @_;
1443 print "<div class=\"list_head\">\n";
1444 if ($#{$difftree} > 10) {
1445 print(($#{$difftree} + 1) . " files changed:\n");
1449 print "<table class=\"diff_tree\">\n";
1451 foreach my $line (@
{$difftree}) {
1452 my %diff = parse_difftree_raw_line
($line);
1455 print "<tr class=\"dark\">\n";
1457 print "<tr class=\"light\">\n";
1461 my ($to_mode_oct, $to_mode_str, $to_file_type);
1462 my ($from_mode_oct, $from_mode_str, $from_file_type);
1463 if ($diff{'to_mode'} ne ('0' x
6)) {
1464 $to_mode_oct = oct $diff{'to_mode'};
1465 if (S_ISREG
($to_mode_oct)) { # only for regular file
1466 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1468 $to_file_type = file_type
($diff{'to_mode'});
1470 if ($diff{'from_mode'} ne ('0' x
6)) {
1471 $from_mode_oct = oct $diff{'from_mode'};
1472 if (S_ISREG
($to_mode_oct)) { # only for regular file
1473 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1475 $from_file_type = file_type
($diff{'from_mode'});
1478 if ($diff{'status'} eq "A") { # created
1479 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1480 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1481 $mode_chng .= "]</span>";
1483 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1484 hash_base
=>$hash, file_name
=>$diff{'file'}),
1485 -class => "list"}, esc_html
($diff{'file'})) .
1487 "<td>$mode_chng</td>\n" .
1488 "<td class=\"link\">" .
1489 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1490 hash_base
=>$hash, file_name
=>$diff{'file'})},
1494 } elsif ($diff{'status'} eq "D") { # deleted
1495 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1497 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1498 hash_base
=>$parent, file_name
=>$diff{'file'}),
1499 -class => "list"}, esc_html
($diff{'file'})) .
1501 "<td>$mode_chng</td>\n" .
1502 "<td class=\"link\">" .
1503 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1504 hash_base
=>$parent, file_name
=>$diff{'file'})},
1507 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1508 file_name
=>$diff{'file'})},
1512 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1513 my $mode_chnge = "";
1514 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1515 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1516 if ($from_file_type != $to_file_type) {
1517 $mode_chnge .= " from $from_file_type to $to_file_type";
1519 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1520 if ($from_mode_str && $to_mode_str) {
1521 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1522 } elsif ($to_mode_str) {
1523 $mode_chnge .= " mode: $to_mode_str";
1526 $mode_chnge .= "]</span>\n";
1529 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1530 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1531 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1532 hash_base
=>$hash, hash_parent_base
=>$parent,
1533 file_name
=>$diff{'file'}),
1534 -class => "list"}, esc_html
($diff{'file'}));
1535 } else { # only mode changed
1536 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1537 hash_base
=>$hash, file_name
=>$diff{'file'}),
1538 -class => "list"}, esc_html
($diff{'file'}));
1541 "<td>$mode_chnge</td>\n" .
1542 "<td class=\"link\">" .
1543 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1544 hash_base
=>$hash, file_name
=>$diff{'file'})},
1546 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1548 $cgi->a({-href
=> href
(action
=>"blobdiff",
1549 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1550 hash_base
=>$hash, hash_parent_base
=>$parent,
1551 file_name
=>$diff{'file'})},
1555 $cgi->a({-href
=> href
(action
=>"history",
1556 hash_base
=>$hash, file_name
=>$diff{'file'})},
1560 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1561 my %status_name = ('R' => 'moved', 'C' => 'copied');
1562 my $nstatus = $status_name{$diff{'status'}};
1564 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1565 # mode also for directories, so we cannot use $to_mode_str
1566 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1569 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1570 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1571 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1572 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1573 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1574 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1575 -class => "list"}, esc_html
($diff{'from_file'})) .
1576 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1577 "<td class=\"link\">" .
1578 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1579 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'})},
1581 if ($diff{'to_id'} ne $diff{'from_id'}) {
1583 $cgi->a({-href
=> href
(action
=>"blobdiff",
1584 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1585 hash_base
=>$hash, hash_parent_base
=>$parent,
1586 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1591 } # we should not encounter Unmerged (U) or Unknown (X) status
1597 sub git_patchset_body
{
1598 my ($fd, $difftree, $hash, $hash_parent) = @_;
1602 my $patch_found = 0;
1605 print "<div class=\"patchset\">\n";
1608 while (my $patch_line = <$fd>) {
1611 if ($patch_line =~ m/^diff /) { # "git diff" header
1612 # beginning of patch (in patchset)
1614 # close previous patch
1615 print "</div>\n"; # class="patch"
1617 # first patch in patchset
1620 print "<div class=\"patch\">\n";
1622 if (ref($difftree->[$patch_idx]) eq "HASH") {
1623 $diffinfo = $difftree->[$patch_idx];
1625 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1629 # for now, no extended header, hence we skip empty patches
1630 # companion to next LINE if $in_header;
1631 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1636 if ($diffinfo->{'status'} eq "A") { # added
1637 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1638 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1639 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1640 $diffinfo->{'to_id'}) . "(new)" .
1641 "</div>\n"; # class="diff_info"
1643 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1644 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
1645 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1646 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1647 $diffinfo->{'from_id'}) . "(deleted)" .
1648 "</div>\n"; # class="diff_info"
1650 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1651 $diffinfo->{'status'} eq "C" || # copied
1652 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1653 print "<div class=\"diff_info\">" .
1654 file_type
($diffinfo->{'from_mode'}) . ":" .
1655 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1656 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
1657 $diffinfo->{'from_id'}) .
1659 file_type
($diffinfo->{'to_mode'}) . ":" .
1660 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1661 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
1662 $diffinfo->{'to_id'});
1663 print "</div>\n"; # class="diff_info"
1665 } else { # modified, mode changed, ...
1666 print "<div class=\"diff_info\">" .
1667 file_type
($diffinfo->{'from_mode'}) . ":" .
1668 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1669 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1670 $diffinfo->{'from_id'}) .
1672 file_type
($diffinfo->{'to_mode'}) . ":" .
1673 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1674 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1675 $diffinfo->{'to_id'});
1676 print "</div>\n"; # class="diff_info"
1679 #print "<div class=\"diff extended_header\">\n";
1682 } # start of patch in patchset
1685 if ($in_header && $patch_line =~ m/^---/) {
1686 #print "</div>\n"; # class="diff extended_header"
1689 my $file = $diffinfo->{'from_file'};
1690 $file ||= $diffinfo->{'file'};
1691 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1692 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
1693 -class => "list"}, esc_html
($file));
1694 $patch_line =~ s
|a
/.*$|a/$file|g
;
1695 print "<div class=\"diff from_file\">$patch_line</div>\n";
1697 $patch_line = <$fd>;
1700 #$patch_line =~ m/^+++/;
1701 $file = $diffinfo->{'to_file'};
1702 $file ||= $diffinfo->{'file'};
1703 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1704 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
1705 -class => "list"}, esc_html
($file));
1706 $patch_line =~ s
|b
/.*|b/$file|g
;
1707 print "<div class=\"diff to_file\">$patch_line</div>\n";
1711 next LINE
if $in_header;
1713 print format_diff_line
($patch_line);
1715 print "</div>\n" if $patch_found; # class="patch"
1717 print "</div>\n"; # class="patchset"
1720 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1722 sub git_shortlog_body
{
1723 # uses global variable $project
1724 my ($revlist, $from, $to, $refs, $extra) = @_;
1726 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
1727 my $have_snapshot = (defined $ctype && defined $suffix);
1729 $from = 0 unless defined $from;
1730 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1732 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1734 for (my $i = $from; $i <= $to; $i++) {
1735 my $commit = $revlist->[$i];
1736 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1737 my $ref = format_ref_marker
($refs, $commit);
1738 my %co = parse_commit
($commit);
1740 print "<tr class=\"dark\">\n";
1742 print "<tr class=\"light\">\n";
1745 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1746 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1747 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1749 print format_subject_html
($co{'title'}, $co{'title_short'},
1750 href
(action
=>"commit", hash
=>$commit), $ref);
1752 "<td class=\"link\">" .
1753 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1754 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
1755 if ($have_snapshot) {
1756 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
1761 if (defined $extra) {
1763 "<td colspan=\"4\">$extra</td>\n" .
1769 sub git_history_body
{
1770 # Warning: assumes constant type (blob or tree) during history
1771 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1773 print "<table class=\"history\" cellspacing=\"0\">\n";
1775 while (my $line = <$fd>) {
1776 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1781 my %co = parse_commit
($commit);
1786 my $ref = format_ref_marker
($refs, $commit);
1789 print "<tr class=\"dark\">\n";
1791 print "<tr class=\"light\">\n";
1794 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1795 # shortlog uses chop_str($co{'author_name'}, 10)
1796 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1798 # originally git_history used chop_str($co{'title'}, 50)
1799 print format_subject_html
($co{'title'}, $co{'title_short'},
1800 href
(action
=>"commit", hash
=>$commit), $ref);
1802 "<td class=\"link\">" .
1803 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1804 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
1805 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype);
1807 if ($ftype eq 'blob') {
1808 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
1809 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
1810 if (defined $blob_current && defined $blob_parent &&
1811 $blob_current ne $blob_parent) {
1813 $cgi->a({-href
=> href
(action
=>"blobdiff",
1814 hash
=>$blob_current, hash_parent
=>$blob_parent,
1815 hash_base
=>$hash_base, hash_parent_base
=>$commit,
1816 file_name
=>$file_name)},
1823 if (defined $extra) {
1825 "<td colspan=\"4\">$extra</td>\n" .
1832 # uses global variable $project
1833 my ($taglist, $from, $to, $extra) = @_;
1834 $from = 0 unless defined $from;
1835 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1837 print "<table class=\"tags\" cellspacing=\"0\">\n";
1839 for (my $i = $from; $i <= $to; $i++) {
1840 my $entry = $taglist->[$i];
1842 my $comment_lines = $tag{'comment'};
1843 my $comment = shift @
$comment_lines;
1845 if (defined $comment) {
1846 $comment_short = chop_str
($comment, 30, 5);
1849 print "<tr class=\"dark\">\n";
1851 print "<tr class=\"light\">\n";
1854 print "<td><i>$tag{'age'}</i></td>\n" .
1856 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
1857 -class => "list name"}, esc_html
($tag{'name'})) .
1860 if (defined $comment) {
1861 print format_subject_html
($comment, $comment_short,
1862 href
(action
=>"tag", hash
=>$tag{'id'}));
1865 "<td class=\"selflink\">";
1866 if ($tag{'type'} eq "tag") {
1867 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
1872 "<td class=\"link\">" . " | " .
1873 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
1874 if ($tag{'reftype'} eq "commit") {
1875 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
1876 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
1877 } elsif ($tag{'reftype'} eq "blob") {
1878 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
1883 if (defined $extra) {
1885 "<td colspan=\"5\">$extra</td>\n" .
1891 sub git_heads_body
{
1892 # uses global variable $project
1893 my ($taglist, $head, $from, $to, $extra) = @_;
1894 $from = 0 unless defined $from;
1895 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1897 print "<table class=\"heads\" cellspacing=\"0\">\n";
1899 for (my $i = $from; $i <= $to; $i++) {
1900 my $entry = $taglist->[$i];
1902 my $curr = $tag{'id'} eq $head;
1904 print "<tr class=\"dark\">\n";
1906 print "<tr class=\"light\">\n";
1909 print "<td><i>$tag{'age'}</i></td>\n" .
1910 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1911 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
1912 -class => "list name"},esc_html
($tag{'name'})) .
1914 "<td class=\"link\">" .
1915 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
1916 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") .
1920 if (defined $extra) {
1922 "<td colspan=\"3\">$extra</td>\n" .
1928 ## ======================================================================
1929 ## ======================================================================
1932 sub git_project_list
{
1933 my $order = $cgi->param('o');
1934 if (defined $order && $order !~ m/project|descr|owner|age/) {
1935 die_error
(undef, "Unknown order parameter");
1938 my @list = git_get_projects_list
();
1941 die_error
(undef, "No projects found");
1943 foreach my $pr (@list) {
1944 my $head = git_get_head_hash
($pr->{'path'});
1945 if (!defined $head) {
1948 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1949 my %co = parse_commit
($head);
1953 $pr->{'commit'} = \
%co;
1954 if (!defined $pr->{'descr'}) {
1955 my $descr = git_get_project_description
($pr->{'path'}) || "";
1956 $pr->{'descr'} = chop_str
($descr, 25, 5);
1958 if (!defined $pr->{'owner'}) {
1959 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
1961 push @projects, $pr;
1965 if (-f
$home_text) {
1966 print "<div class=\"index_include\">\n";
1967 open (my $fd, $home_text);
1972 print "<table class=\"project_list\">\n" .
1974 $order ||= "project";
1975 if ($order eq "project") {
1976 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1977 print "<th>Project</th>\n";
1980 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
1981 -class => "header"}, "Project") .
1984 if ($order eq "descr") {
1985 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1986 print "<th>Description</th>\n";
1989 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
1990 -class => "header"}, "Description") .
1993 if ($order eq "owner") {
1994 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1995 print "<th>Owner</th>\n";
1998 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
1999 -class => "header"}, "Owner") .
2002 if ($order eq "age") {
2003 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2004 print "<th>Last Change</th>\n";
2007 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
2008 -class => "header"}, "Last Change") .
2011 print "<th></th>\n" .
2014 foreach my $pr (@projects) {
2016 print "<tr class=\"dark\">\n";
2018 print "<tr class=\"light\">\n";
2021 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2022 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2023 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2024 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2025 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2026 $pr->{'commit'}{'age_string'} . "</td>\n" .
2027 "<td class=\"link\">" .
2028 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2029 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2030 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") .
2039 my $descr = git_get_project_description
($project) || "none";
2040 my $head = git_get_head_hash
($project);
2041 my %co = parse_commit
($head);
2042 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2044 my $owner = git_get_project_owner
($project);
2046 my $refs = git_get_references
();
2048 git_print_page_nav
('summary','', $head);
2050 print "<div class=\"title\"> </div>\n";
2051 print "<table cellspacing=\"0\">\n" .
2052 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2053 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2054 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2055 # use per project git URL list in $projectroot/$project/cloneurl
2056 # or make project git URL from git base URL and project name
2057 my $url_tag = "URL";
2058 my @url_list = git_get_project_url_list
($project);
2059 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2060 foreach my $git_url (@url_list) {
2061 next unless $git_url;
2062 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2067 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash
($project)
2068 or die_error
(undef, "Open git-rev-list failed");
2069 my @revlist = map { chomp; $_ } <$fd>;
2071 git_print_header_div
('shortlog');
2072 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2073 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2075 my $taglist = git_get_refs_list
("refs/tags");
2076 if (defined @
$taglist) {
2077 git_print_header_div
('tags');
2078 git_tags_body
($taglist, 0, 15,
2079 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2082 my $headlist = git_get_refs_list
("refs/heads");
2083 if (defined @
$headlist) {
2084 git_print_header_div
('heads');
2085 git_heads_body
($headlist, $head, 0, 15,
2086 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2093 my $head = git_get_head_hash
($project);
2095 git_print_page_nav
('','', $head,undef,$head);
2096 my %tag = parse_tag
($hash);
2097 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2098 print "<div class=\"title_text\">\n" .
2099 "<table cellspacing=\"0\">\n" .
2101 "<td>object</td>\n" .
2102 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2103 $tag{'object'}) . "</td>\n" .
2104 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2105 $tag{'type'}) . "</td>\n" .
2107 if (defined($tag{'author'})) {
2108 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2109 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2110 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2111 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2114 print "</table>\n\n" .
2116 print "<div class=\"page_body\">";
2117 my $comment = $tag{'comment'};
2118 foreach my $line (@
$comment) {
2119 print esc_html
($line) . "<br/>\n";
2129 if (!gitweb_check_feature
('blame')) {
2130 die_error
('403 Permission denied', "Permission denied");
2132 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2133 $hash_base ||= git_get_head_hash
($project);
2134 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2135 my %co = parse_commit
($hash_base)
2136 or die_error
(undef, "Reading commit failed");
2137 if (!defined $hash) {
2138 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2139 or die_error
(undef, "Error looking up file");
2141 $ftype = git_get_type
($hash);
2142 if ($ftype !~ "blob") {
2143 die_error
("400 Bad Request", "Object is not a blob");
2145 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
2146 or die_error
(undef, "Open git-blame failed");
2149 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2152 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2154 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2155 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2156 git_print_page_path
($file_name, $ftype, $hash_base);
2157 my @rev_color = (qw(light2 dark2));
2158 my $num_colors = scalar(@rev_color);
2159 my $current_color = 0;
2162 <div class="page_body">
2163 <table class="blame">
2164 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2167 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2169 my $rev = substr($full_rev, 0, 8);
2173 if (!defined $last_rev) {
2174 $last_rev = $full_rev;
2175 } elsif ($last_rev ne $full_rev) {
2176 $last_rev = $full_rev;
2177 $current_color = ++$current_color % $num_colors;
2179 print "<tr class=\"$rev_color[$current_color]\">\n";
2180 print "<td class=\"sha1\">" .
2181 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)},
2182 esc_html
($rev)) . "</td>\n";
2183 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2184 esc_html
($lineno) . "</a></td>\n";
2185 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2191 or print "Reading blob failed\n";
2198 if (!gitweb_check_feature
('blame')) {
2199 die_error
('403 Permission denied', "Permission denied");
2201 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2202 $hash_base ||= git_get_head_hash
($project);
2203 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2204 my %co = parse_commit
($hash_base)
2205 or die_error
(undef, "Reading commit failed");
2206 if (!defined $hash) {
2207 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2208 or die_error
(undef, "Error lookup file");
2210 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2211 or die_error
(undef, "Open git-annotate failed");
2214 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2217 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2219 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2220 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2221 git_print_page_path
($file_name, 'blob', $hash_base);
2222 print "<div class=\"page_body\">\n";
2224 <table class="blame">
2233 my @line_class = (qw(light dark));
2234 my $line_class_len = scalar (@line_class);
2235 my $line_class_num = $#line_class;
2236 while (my $line = <$fd>) {
2248 $line_class_num = ($line_class_num + 1) % $line_class_len;
2250 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2257 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2260 $short_rev = substr ($long_rev, 0, 8);
2261 $age = time () - $time;
2262 $age_str = age_string
($age);
2263 $age_str =~ s/ / /g;
2264 $age_class = age_class
($age);
2265 $author = esc_html
($author);
2266 $author =~ s/ / /g;
2268 $data = untabify
($data);
2269 $data = esc_html
($data);
2272 <tr class="$line_class[$line_class_num]">
2273 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2274 <td class="$age_class">$age_str</td>
2276 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2277 <td class="pre">$data</td>
2280 } # while (my $line = <$fd>)
2281 print "</table>\n\n";
2283 or print "Reading blob failed.\n";
2289 my $head = git_get_head_hash
($project);
2291 git_print_page_nav
('','', $head,undef,$head);
2292 git_print_header_div
('summary', $project);
2294 my $taglist = git_get_refs_list
("refs/tags");
2295 if (defined @
$taglist) {
2296 git_tags_body
($taglist);
2302 my $head = git_get_head_hash
($project);
2304 git_print_page_nav
('','', $head,undef,$head);
2305 git_print_header_div
('summary', $project);
2307 my $taglist = git_get_refs_list
("refs/heads");
2308 if (defined @
$taglist) {
2309 git_heads_body
($taglist, $head);
2314 sub git_blob_plain
{
2315 # blobs defined by non-textual hash id's can be cached
2317 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2321 if (!defined $hash) {
2322 if (defined $file_name) {
2323 my $base = $hash_base || git_get_head_hash
($project);
2324 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2325 or die_error
(undef, "Error lookup file");
2327 die_error
(undef, "No file name defined");
2331 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2332 or die_error
(undef, "Couldn't cat $file_name, $hash");
2334 $type ||= blob_mimetype
($fd, $file_name);
2336 # save as filename, even when no $file_name is given
2337 my $save_as = "$hash";
2338 if (defined $file_name) {
2339 $save_as = $file_name;
2340 } elsif ($type =~ m/^text\//) {
2347 -content_disposition
=> "inline; filename=\"$save_as\"");
2349 binmode STDOUT
, ':raw';
2351 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2357 # blobs defined by non-textual hash id's can be cached
2359 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2363 if (!defined $hash) {
2364 if (defined $file_name) {
2365 my $base = $hash_base || git_get_head_hash
($project);
2366 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2367 or die_error
(undef, "Error lookup file");
2369 die_error
(undef, "No file name defined");
2372 my $have_blame = gitweb_check_feature
('blame');
2373 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2374 or die_error
(undef, "Couldn't cat $file_name, $hash");
2375 my $mimetype = blob_mimetype
($fd, $file_name);
2376 if ($mimetype !~ m/^text\//) {
2378 return git_blob_plain
($mimetype);
2380 git_header_html
(undef, $expires);
2381 my $formats_nav = '';
2382 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2383 if (defined $file_name) {
2386 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2387 hash
=>$hash, file_name
=>$file_name)},
2392 $cgi->a({-href
=> href
(action
=>"blob_plain",
2393 hash
=>$hash, file_name
=>$file_name)},
2396 $cgi->a({-href
=> href
(action
=>"blob",
2397 hash_base
=>"HEAD", file_name
=>$file_name)},
2401 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "plain");
2403 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2404 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2406 print "<div class=\"page_nav\">\n" .
2407 "<br/><br/></div>\n" .
2408 "<div class=\"title\">$hash</div>\n";
2410 git_print_page_path
($file_name, "blob", $hash_base);
2411 print "<div class=\"page_body\">\n";
2413 while (my $line = <$fd>) {
2416 $line = untabify
($line);
2417 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2418 $nr, $nr, $nr, esc_html
($line);
2421 or print "Reading blob failed.\n";
2427 if (!defined $hash) {
2428 $hash = git_get_head_hash
($project);
2429 if (defined $file_name) {
2430 my $base = $hash_base || $hash;
2431 $hash = git_get_hash_by_path
($base, $file_name, "tree");
2433 if (!defined $hash_base) {
2438 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
2439 or die_error
(undef, "Open git-ls-tree failed");
2440 my @entries = map { chomp; $_ } <$fd>;
2441 close $fd or die_error
(undef, "Reading tree failed");
2444 my $refs = git_get_references
();
2445 my $ref = format_ref_marker
($refs, $hash_base);
2449 my $have_blame = gitweb_check_feature
('blame');
2450 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2451 $base_key{hash_base
} = $hash_base;
2452 git_print_page_nav
('tree','', $hash_base);
2453 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2455 print "<div class=\"page_nav\">\n";
2456 print "<br/><br/></div>\n";
2457 print "<div class=\"title\">$hash</div>\n";
2459 if (defined $file_name) {
2460 $base = esc_html
("$file_name/");
2462 git_print_page_path
($file_name, 'tree', $hash_base);
2463 print "<div class=\"page_body\">\n";
2464 print "<table cellspacing=\"0\">\n";
2466 foreach my $line (@entries) {
2467 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2468 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2472 my $t_name = validate_input
($4);
2474 print "<tr class=\"dark\">\n";
2476 print "<tr class=\"light\">\n";
2479 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
2480 if ($t_type eq "blob") {
2481 print "<td class=\"list\">" .
2482 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key),
2483 -class => "list"}, esc_html
($t_name)) .
2485 "<td class=\"link\">" .
2486 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2490 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2494 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2495 hash
=>$t_hash, file_name
=>"$base$t_name")},
2498 $cgi->a({-href
=> href
(action
=>"blob_plain",
2499 hash
=>$t_hash, file_name
=>"$base$t_name")},
2502 } elsif ($t_type eq "tree") {
2503 print "<td class=\"list\">" .
2504 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2505 esc_html
($t_name)) .
2507 "<td class=\"link\">" .
2508 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2511 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base, file_name
=>"$base$t_name")},
2517 print "</table>\n" .
2524 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2525 my $have_snapshot = (defined $ctype && defined $suffix);
2526 if (!$have_snapshot) {
2527 die_error
('403 Permission denied', "Permission denied");
2530 if (!defined $hash) {
2531 $hash = git_get_head_hash
($project);
2534 my $filename = basename
($project) . "-$hash.tar.$suffix";
2536 print $cgi->header(-type
=> 'application/x-tar',
2537 -content_encoding
=> $ctype,
2538 -content_disposition
=> "inline; filename=\"$filename\"",
2539 -status
=> '200 OK');
2541 open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | $command" or
2542 die_error
(undef, "Execute git-tar-tree failed.");
2543 binmode STDOUT
, ':raw';
2545 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2551 my $head = git_get_head_hash
($project);
2552 if (!defined $hash) {
2555 if (!defined $page) {
2558 my $refs = git_get_references
();
2560 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2561 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2562 or die_error
(undef, "Open git-rev-list failed");
2563 my @revlist = map { chomp; $_ } <$fd>;
2566 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2569 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2572 my %co = parse_commit
($hash);
2574 git_print_header_div
('summary', $project);
2575 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2577 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2578 my $commit = $revlist[$i];
2579 my $ref = format_ref_marker
($refs, $commit);
2580 my %co = parse_commit
($commit);
2582 my %ad = parse_date
($co{'author_epoch'});
2583 git_print_header_div
('commit',
2584 "<span class=\"age\">$co{'age_string'}</span>" .
2585 esc_html
($co{'title'}) . $ref,
2587 print "<div class=\"title_text\">\n" .
2588 "<div class=\"log_link\">\n" .
2589 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2591 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2594 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2597 print "<div class=\"log_body\">\n";
2598 git_print_simplified_log
($co{'comment'});
2605 my %co = parse_commit
($hash);
2607 die_error
(undef, "Unknown commit object");
2609 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2610 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2612 my $parent = $co{'parent'};
2613 if (!defined $parent) {
2616 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
2617 or die_error
(undef, "Open git-diff-tree failed");
2618 my @difftree = map { chomp; $_ } <$fd>;
2619 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2621 # non-textual hash id's can be cached
2623 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2626 my $refs = git_get_references
();
2627 my $ref = format_ref_marker
($refs, $co{'id'});
2629 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2630 my $have_snapshot = (defined $ctype && defined $suffix);
2632 my $formats_nav = '';
2633 if (defined $file_name && defined $co{'parent'}) {
2634 my $parent = $co{'parent'};
2636 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
2639 git_header_html
(undef, $expires);
2640 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
2641 $hash, $co{'tree'}, $hash,
2644 if (defined $co{'parent'}) {
2645 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2647 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
2649 print "<div class=\"title_text\">\n" .
2650 "<table cellspacing=\"0\">\n";
2651 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2653 "<td></td><td> $ad{'rfc2822'}";
2654 if ($ad{'hour_local'} < 6) {
2655 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2656 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2658 printf(" (%02d:%02d %s)",
2659 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2663 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2664 print "<tr><td></td><td> $cd{'rfc2822'}" .
2665 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2667 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2670 "<td class=\"sha1\">" .
2671 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
2672 class => "list"}, $co{'tree'}) .
2674 "<td class=\"link\">" .
2675 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
2677 if ($have_snapshot) {
2679 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
2683 my $parents = $co{'parents'};
2684 foreach my $par (@
$parents) {
2687 "<td class=\"sha1\">" .
2688 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
2689 class => "list"}, $par) .
2691 "<td class=\"link\">" .
2692 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
2694 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "commitdiff") .
2701 print "<div class=\"page_body\">\n";
2702 git_print_log
($co{'comment'});
2705 git_difftree_body
(\
@difftree, $hash, $parent);
2711 my $format = shift || 'html';
2718 # preparing $fd and %diffinfo for git_patchset_body
2720 if (defined $hash_base && defined $hash_parent_base) {
2721 if (defined $file_name) {
2723 open $fd, "-|", $GIT, "diff-tree", '-r', '-M', '-C', $hash_parent_base, $hash_base,
2725 or die_error
(undef, "Open git-diff-tree failed");
2726 @difftree = map { chomp; $_ } <$fd>;
2728 or die_error
(undef, "Reading git-diff-tree failed");
2730 or die_error
('404 Not Found', "Blob diff not found");
2732 } elsif (defined $hash) { # try to find filename from $hash
2733 if ($hash !~ /[0-9a-fA-F]{40}/) {
2734 $hash = git_to_hash
($hash);
2737 # read filtered raw output
2738 open $fd, "-|", $GIT, "diff-tree", '-r', '-M', '-C', $hash_parent_base, $hash_base
2739 or die_error
(undef, "Open git-diff-tree failed");
2741 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
2743 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
2744 map { chomp; $_ } <$fd>;
2746 or die_error
(undef, "Reading git-diff-tree failed");
2748 or die_error
('404 Not Found', "Blob diff not found");
2751 die_error
('404 Not Found', "Missing one of the blob diff parameters");
2754 if (@difftree > 1) {
2755 die_error
('404 Not Found', "Ambiguous blob diff specification");
2758 %diffinfo = parse_difftree_raw_line
($difftree[0]);
2759 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
2760 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
2762 $hash_parent ||= $diffinfo{'from_id'};
2763 $hash ||= $diffinfo{'to_id'};
2765 # non-textual hash id's can be cached
2766 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
2767 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
2772 open $fd, "-|", $GIT, "diff-tree", '-r', '-p', '-M', '-C', $hash_parent_base, $hash_base,
2774 or die_error
(undef, "Open git-diff-tree failed");
2777 # old/legacy style URI
2778 if (!%diffinfo && # if new style URI failed
2779 defined $hash && defined $hash_parent) {
2780 # fake git-diff-tree raw output
2781 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
2782 $diffinfo{'from_id'} = $hash_parent;
2783 $diffinfo{'to_id'} = $hash;
2784 if (defined $file_name) {
2785 if (defined $file_parent) {
2786 $diffinfo{'status'} = '2';
2787 $diffinfo{'from_file'} = $file_parent;
2788 $diffinfo{'to_file'} = $file_name;
2789 } else { # assume not renamed
2790 $diffinfo{'status'} = '1';
2791 $diffinfo{'from_file'} = $file_name;
2792 $diffinfo{'to_file'} = $file_name;
2794 } else { # no filename given
2795 $diffinfo{'status'} = '2';
2796 $diffinfo{'from_file'} = $hash_parent;
2797 $diffinfo{'to_file'} = $hash;
2800 # non-textual hash id's can be cached
2801 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
2802 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
2807 open $fd, "-|", $GIT, "diff", '-p', $hash_parent, $hash
2808 or die_error
(undef, "Open git-diff failed");
2810 die_error
('404 Not Found', "Missing one of the blob diff parameters")
2815 if ($format eq 'html') {
2817 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
2818 hash
=>$hash, hash_parent
=>$hash_parent,
2819 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
2820 file_name
=>$file_name, file_parent
=>$file_parent)},
2822 git_header_html
(undef, $expires);
2823 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2824 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2825 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2827 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
2828 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
2830 if (defined $file_name) {
2831 git_print_page_path
($file_name, "blob", $hash_base);
2833 print "<div class=\"page_path\"></div>\n";
2836 } elsif ($format eq 'plain') {
2838 -type
=> 'text/plain',
2839 -charset
=> 'utf-8',
2840 -expires
=> $expires,
2841 -content_disposition
=> qq(inline
; filename
="${file_name}.patch"));
2843 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
2846 die_error
(undef, "Unknown blobdiff format");
2850 if ($format eq 'html') {
2851 print "<div class=\"page_body\">\n";
2853 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
2856 print "</div>\n"; # class="page_body"
2860 while (my $line = <$fd>) {
2861 $line =~ s!a/($hash|$hash_parent)!a/$diffinfo{'from_file'}!g;
2862 $line =~ s!b/($hash|$hash_parent)!b/$diffinfo{'to_file'}!g;
2866 last if $line =~ m!^\+\+\+!;
2874 sub git_blobdiff_plain
{
2875 git_blobdiff
('plain');
2878 sub git_commitdiff
{
2879 my $format = shift || 'html';
2880 my %co = parse_commit
($hash);
2882 die_error
(undef, "Unknown commit object");
2884 if (!defined $hash_parent) {
2885 $hash_parent = $co{'parent'} || '--root';
2891 if ($format eq 'html') {
2892 open $fd, "-|", $GIT, "diff-tree", '-r', '-M', '-C',
2893 "--patch-with-raw", "--full-index", $hash_parent, $hash
2894 or die_error
(undef, "Open git-diff-tree failed");
2896 while (chomp(my $line = <$fd>)) {
2897 # empty line ends raw part of diff-tree output
2899 push @difftree, $line;
2902 } elsif ($format eq 'plain') {
2903 open $fd, "-|", $GIT, "diff-tree", '-r', '-p', '-B', $hash_parent, $hash
2904 or die_error
(undef, "Open git-diff-tree failed");
2907 die_error
(undef, "Unknown commitdiff format");
2910 # non-textual hash id's can be cached
2912 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2916 # write commit message
2917 if ($format eq 'html') {
2918 my $refs = git_get_references
();
2919 my $ref = format_ref_marker
($refs, $co{'id'});
2921 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
2922 hash
=>$hash, hash_parent
=>$hash_parent)},
2925 git_header_html
(undef, $expires);
2926 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2927 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2928 print "<div class=\"page_body\">\n";
2929 print "<div class=\"log\">\n";
2930 git_print_simplified_log
($co{'comment'}, 1); # skip title
2931 print "</div>\n"; # class="log"
2933 } elsif ($format eq 'plain') {
2934 my $refs = git_get_references
("tags");
2935 my $tagname = git_get_rev_name_tags
($hash);
2936 my $filename = basename
($project) . "-$hash.patch";
2939 -type
=> 'text/plain',
2940 -charset
=> 'utf-8',
2941 -expires
=> $expires,
2942 -content_disposition
=> qq(inline
; filename
="$filename"));
2943 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2946 Date: $ad{'rfc2822'} ($ad{'tz_local'})
2947 Subject: $co{'title'}
2949 print "X-Git-Tag: $tagname\n" if $tagname;
2950 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
2952 foreach my $line (@
{$co{'comment'}}) {
2959 if ($format eq 'html') {
2960 #git_difftree_body(\@difftree, $hash, $hash_parent);
2963 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
2965 print "</div>\n"; # class="page_body"
2968 } elsif ($format eq 'plain') {
2972 or print "Reading git-diff-tree failed\n";
2976 sub git_commitdiff_plain
{
2977 git_commitdiff
('plain');
2981 if (!defined $hash_base) {
2982 $hash_base = git_get_head_hash
($project);
2985 my %co = parse_commit
($hash_base);
2987 die_error
(undef, "Unknown commit object");
2989 my $refs = git_get_references
();
2991 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2992 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2993 if (!defined $hash && defined $file_name) {
2994 $hash = git_get_hash_by_path
($hash_base, $file_name);
2996 if (defined $hash) {
2997 $ftype = git_get_type
($hash);
2999 git_print_page_path
($file_name, $ftype, $hash_base);
3002 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
3003 git_history_body
($fd, $refs, $hash_base, $ftype);
3010 if (!defined $searchtext) {
3011 die_error
(undef, "Text field empty");
3013 if (!defined $hash) {
3014 $hash = git_get_head_hash
($project);
3016 my %co = parse_commit
($hash);
3018 die_error
(undef, "Unknown commit object");
3020 # pickaxe may take all resources of your box and run for several minutes
3021 # with every query - so decide by yourself how public you make this feature :)
3022 my $commit_search = 1;
3023 my $author_search = 0;
3024 my $committer_search = 0;
3025 my $pickaxe_search = 0;
3026 if ($searchtext =~ s/^author\\://i) {
3028 } elsif ($searchtext =~ s/^committer\\://i) {
3029 $committer_search = 1;
3030 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3032 $pickaxe_search = 1;
3035 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3036 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3038 print "<table cellspacing=\"0\">\n";
3040 if ($commit_search) {
3042 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
3043 while (my $commit_text = <$fd>) {
3044 if (!grep m/$searchtext/i, $commit_text) {
3047 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3050 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3053 my @commit_lines = split "\n", $commit_text;
3054 my %co = parse_commit
(undef, \
@commit_lines);
3059 print "<tr class=\"dark\">\n";
3061 print "<tr class=\"light\">\n";
3064 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3065 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3067 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3068 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3069 my $comment = $co{'comment'};
3070 foreach my $line (@
$comment) {
3071 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3072 my $lead = esc_html
($1) || "";
3073 $lead = chop_str
($lead, 30, 10);
3074 my $match = esc_html
($2) || "";
3075 my $trail = esc_html
($3) || "";
3076 $trail = chop_str
($trail, 30, 10);
3077 my $text = "$lead<span class=\"match\">$match</span>$trail";
3078 print chop_str
($text, 80, 5) . "<br/>\n";
3082 "<td class=\"link\">" .
3083 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3085 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3092 if ($pickaxe_search) {
3094 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
3097 while (my $line = <$fd>) {
3098 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3101 $set{'from_id'} = $3;
3103 $set{'id'} = $set{'to_id'};
3104 if ($set{'id'} =~ m/0{40}/) {
3105 $set{'id'} = $set{'from_id'};
3107 if ($set{'id'} =~ m/0{40}/) {
3111 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3114 print "<tr class=\"dark\">\n";
3116 print "<tr class=\"light\">\n";
3119 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3120 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3122 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3123 -class => "list subject"},
3124 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3125 while (my $setref = shift @files) {
3127 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3128 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3130 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3134 "<td class=\"link\">" .
3135 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3137 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3141 %co = parse_commit
($1);
3151 my $head = git_get_head_hash
($project);
3152 if (!defined $hash) {
3155 if (!defined $page) {
3158 my $refs = git_get_references
();
3160 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3161 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
3162 or die_error
(undef, "Open git-rev-list failed");
3163 my @revlist = map { chomp; $_ } <$fd>;
3166 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3168 if ($#revlist >= (100 * ($page+1)-1)) {
3170 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3171 -title
=> "Alt-n"}, "next");
3176 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3177 git_print_header_div
('summary', $project);
3179 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3184 ## ......................................................................
3185 ## feeds (RSS, OPML)
3188 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3189 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash
($project)
3190 or die_error
(undef, "Open git-rev-list failed");
3191 my @revlist = map { chomp; $_ } <$fd>;
3192 close $fd or die_error
(undef, "Reading git-rev-list failed");
3193 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3195 <?xml version="1.0" encoding="utf-8"?>
3196 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3198 <title>$project $my_uri $my_url</title>
3199 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3200 <description>$project log</description>
3201 <language>en</language>
3204 for (my $i = 0; $i <= $#revlist; $i++) {
3205 my $commit = $revlist[$i];
3206 my %co = parse_commit
($commit);
3207 # we read 150, we always show 30 and the ones more recent than 48 hours
3208 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3211 my %cd = parse_date
($co{'committer_epoch'});
3212 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
3213 my @difftree = map { chomp; $_ } <$fd>;
3217 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3219 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3220 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3221 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3222 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3223 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3224 "<content:encoded>" .
3226 my $comment = $co{'comment'};
3227 foreach my $line (@
$comment) {
3228 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
3229 print "$line<br/>\n";
3232 foreach my $line (@difftree) {
3233 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3236 my $file = validate_input
(unquote
($7));
3237 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
3238 print "$file<br/>\n";
3241 "</content:encoded>\n" .
3244 print "</channel></rss>";
3248 my @list = git_get_projects_list
();
3250 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3252 <?xml version="1.0" encoding="utf-8"?>
3253 <opml version="1.0">
3255 <title>$site_name Git OPML Export</title>
3258 <outline text="git RSS feeds">
3261 foreach my $pr (@list) {
3263 my $head = git_get_head_hash
($proj{'path'});
3264 if (!defined $head) {
3267 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
3268 my %co = parse_commit
($head);
3273 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3274 my $rss = "$my_url?p=$proj{'path'};a=rss";
3275 my $html = "$my_url?p=$proj{'path'};a=summary";
3276 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";