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 # rename detection options for git-diff and git-diff-tree
145 # - default is '-M', with the cost proportional to
146 # (number of removed files) * (number of new files).
147 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
148 # (number of changed files + number of removed files) * (number of new files)
149 # - even more costly is '-C', '--find-copies-harder' with cost
150 # (number of files in the original tree) * (number of new files)
151 # - one might want to include '-B' option, e.g. '-B', '-M'
152 our @diff_opts = ('-M'); # taken from git_commit
154 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
155 require $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
157 # version of the core git binary
158 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
160 $projects_list ||= $projectroot;
162 # ======================================================================
163 # input validation and dispatch
164 our $action = $cgi->param('a');
165 if (defined $action) {
166 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
167 die_error
(undef, "Invalid action parameter");
171 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
172 if (defined $project) {
175 $project = undef unless $project;
177 if (defined $project) {
178 if (!validate_input
($project)) {
179 die_error
(undef, "Invalid project parameter");
181 if (!(-d
"$projectroot/$project")) {
182 die_error
(undef, "No such directory");
184 if (!(-e
"$projectroot/$project/HEAD")) {
185 die_error
(undef, "No such project");
187 $ENV{'GIT_DIR'} = "$projectroot/$project";
190 our $file_name = $cgi->param('f');
191 if (defined $file_name) {
192 if (!validate_input
($file_name)) {
193 die_error
(undef, "Invalid file parameter");
197 our $file_parent = $cgi->param('fp');
198 if (defined $file_parent) {
199 if (!validate_input
($file_parent)) {
200 die_error
(undef, "Invalid file parent parameter");
204 our $hash = $cgi->param('h');
206 if (!validate_input
($hash)) {
207 die_error
(undef, "Invalid hash parameter");
211 our $hash_parent = $cgi->param('hp');
212 if (defined $hash_parent) {
213 if (!validate_input
($hash_parent)) {
214 die_error
(undef, "Invalid hash parent parameter");
218 our $hash_base = $cgi->param('hb');
219 if (defined $hash_base) {
220 if (!validate_input
($hash_base)) {
221 die_error
(undef, "Invalid hash base parameter");
225 our $hash_parent_base = $cgi->param('hpb');
226 if (defined $hash_parent_base) {
227 if (!validate_input
($hash_parent_base)) {
228 die_error
(undef, "Invalid hash parent base parameter");
232 our $page = $cgi->param('pg');
234 if ($page =~ m/[^0-9]$/) {
235 die_error
(undef, "Invalid page parameter");
239 our $searchtext = $cgi->param('s');
240 if (defined $searchtext) {
241 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
242 die_error
(undef, "Invalid search parameter");
244 $searchtext = quotemeta $searchtext;
249 "blame" => \
&git_blame2
,
250 "blobdiff" => \
&git_blobdiff
,
251 "blobdiff_plain" => \
&git_blobdiff_plain
,
252 "blob" => \
&git_blob
,
253 "blob_plain" => \
&git_blob_plain
,
254 "commitdiff" => \
&git_commitdiff
,
255 "commitdiff_plain" => \
&git_commitdiff_plain
,
256 "commit" => \
&git_commit
,
257 "heads" => \
&git_heads
,
258 "history" => \
&git_history
,
261 "search" => \
&git_search
,
262 "shortlog" => \
&git_shortlog
,
263 "summary" => \
&git_summary
,
265 "tags" => \
&git_tags
,
266 "tree" => \
&git_tree
,
267 "snapshot" => \
&git_snapshot
,
268 # those below don't need $project
269 "opml" => \
&git_opml
,
270 "project_list" => \
&git_project_list
,
273 if (defined $project) {
274 $action ||= 'summary';
276 $action ||= 'project_list';
278 if (!defined($actions{$action})) {
279 die_error
(undef, "Unknown action");
281 $actions{$action}->();
284 ## ======================================================================
298 hash_parent_base
=> "hpb",
302 my %mapping = @mapping;
304 $params{"project"} ||= $project;
307 for (my $i = 0; $i < @mapping; $i += 2) {
308 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
309 if (defined $params{$name}) {
310 push @result, $symbol . "=" . esc_param
($params{$name});
313 return "$my_uri?" . join(';', @result);
317 ## ======================================================================
318 ## validation, quoting/unquoting and escaping
323 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
326 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
329 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
335 # quote unsafe chars, but keep the slash, even when it's not
336 # correct, but quoted slashes look too horrible in bookmarks
339 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
345 # replace invalid utf8 character with SUBSTITUTION sequence
348 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
349 $str = escapeHTML
($str);
350 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
354 # git may return quoted and escaped filenames
357 if ($str =~ m/^"(.*)"$/) {
359 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
364 # escape tabs (convert tabs to spaces)
368 while ((my $pos = index($line, "\t")) != -1) {
369 if (my $count = (8 - ($pos % 8))) {
370 my $spaces = ' ' x
$count;
371 $line =~ s/\t/$spaces/;
378 ## ----------------------------------------------------------------------
379 ## HTML aware string manipulation
384 my $add_len = shift || 10;
386 # allow only $len chars, but don't cut a word if it would fit in $add_len
387 # if it doesn't fit, cut it if it's still longer than the dots we would add
388 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
391 if (length($tail) > 4) {
393 $body =~ s/&[^;]*$//; # remove chopped character entities
398 ## ----------------------------------------------------------------------
399 ## functions returning short strings
401 # CSS class for given age value (in seconds)
405 if ($age < 60*60*2) {
407 } elsif ($age < 60*60*24*2) {
414 # convert age in seconds to "nn units ago" string
419 if ($age > 60*60*24*365*2) {
420 $age_str = (int $age/60/60/24/365);
421 $age_str .= " years ago";
422 } elsif ($age > 60*60*24*(365/12)*2) {
423 $age_str = int $age/60/60/24/(365/12);
424 $age_str .= " months ago";
425 } elsif ($age > 60*60*24*7*2) {
426 $age_str = int $age/60/60/24/7;
427 $age_str .= " weeks ago";
428 } elsif ($age > 60*60*24*2) {
429 $age_str = int $age/60/60/24;
430 $age_str .= " days ago";
431 } elsif ($age > 60*60*2) {
432 $age_str = int $age/60/60;
433 $age_str .= " hours ago";
434 } elsif ($age > 60*2) {
435 $age_str = int $age/60;
436 $age_str .= " min ago";
439 $age_str .= " sec ago";
441 $age_str .= " right now";
446 # convert file mode in octal to symbolic file mode string
448 my $mode = oct shift;
450 if (S_ISDIR
($mode & S_IFMT
)) {
452 } elsif (S_ISLNK
($mode)) {
454 } elsif (S_ISREG
($mode)) {
455 # git cares only about the executable bit
456 if ($mode & S_IXUSR
) {
466 # convert file mode in octal to file type string
470 if ($mode !~ m/^[0-7]+$/) {
476 if (S_ISDIR
($mode & S_IFMT
)) {
478 } elsif (S_ISLNK
($mode)) {
480 } elsif (S_ISREG
($mode)) {
487 ## ----------------------------------------------------------------------
488 ## functions returning short HTML fragments, or transforming HTML fragments
489 ## which don't beling to other sections
491 # format line of commit message or tag comment
492 sub format_log_line_html
{
495 $line = esc_html
($line);
496 $line =~ s/ / /g;
497 if ($line =~ m/([0-9a-fA-F]{40})/) {
499 if (git_get_type
($hash_text) eq "commit") {
501 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
502 -class => "text"}, $hash_text);
503 $line =~ s/$hash_text/$link/;
509 # format marker of refs pointing to given object
510 sub format_ref_marker
{
511 my ($refs, $id) = @_;
514 if (defined $refs->{$id}) {
515 foreach my $ref (@
{$refs->{$id}}) {
516 my ($type, $name) = qw();
517 # e.g. tags/v2.6.11 or heads/next
518 if ($ref =~ m!^(.*?)s?/(.*)$!) {
526 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
531 return ' <span class="refs">'. $markers . '</span>';
537 # format, perhaps shortened and with markers, title line
538 sub format_subject_html
{
539 my ($long, $short, $href, $extra) = @_;
540 $extra = '' unless defined($extra);
542 if (length($short) < length($long)) {
543 return $cgi->a({-href
=> $href, -class => "list subject",
545 esc_html
($short) . $extra);
547 return $cgi->a({-href
=> $href, -class => "list subject"},
548 esc_html
($long) . $extra);
552 sub format_diff_line
{
554 my $char = substr($line, 0, 1);
560 $diff_class = " add";
561 } elsif ($char eq "-") {
562 $diff_class = " rem";
563 } elsif ($char eq "@") {
564 $diff_class = " chunk_header";
565 } elsif ($char eq "\\") {
566 $diff_class = " incomplete";
568 $line = untabify
($line);
569 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
572 ## ----------------------------------------------------------------------
573 ## git utility subroutines, invoking git commands
575 # get HEAD ref of given project as hash
576 sub git_get_head_hash
{
578 my $oENV = $ENV{'GIT_DIR'};
580 $ENV{'GIT_DIR'} = "$projectroot/$project";
581 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
584 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
589 $ENV{'GIT_DIR'} = $oENV;
594 # get type of given object
598 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
605 sub git_get_project_config
{
606 my ($key, $type) = @_;
608 return unless ($key);
609 $key =~ s/^gitweb\.//;
610 return if ($key =~ m/\W/);
612 my @x = ($GIT, 'repo-config');
613 if (defined $type) { push @x, $type; }
615 push @x, "gitweb.$key";
621 # get hash of given path at given ref
622 sub git_get_hash_by_path
{
624 my $path = shift || return undef;
628 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
629 or die_error
(undef, "Open git-ls-tree failed");
631 close $fd or return undef;
633 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
634 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
638 ## ......................................................................
639 ## git utility functions, directly accessing git repository
641 # assumes that PATH is not symref
642 sub git_get_hash_by_ref
{
645 open my $fd, "$projectroot/$path" or return undef;
649 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
654 sub git_get_project_description
{
657 open my $fd, "$projectroot/$path/description" or return undef;
664 sub git_get_project_url_list
{
667 open my $fd, "$projectroot/$path/cloneurl" or return undef;
668 my @git_project_url_list = map { chomp; $_ } <$fd>;
671 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
674 sub git_get_projects_list
{
677 if (-d
$projects_list) {
678 # search in directory
679 my $dir = $projects_list;
680 opendir my ($dh), $dir or return undef;
681 while (my $dir = readdir($dh)) {
682 if (-e
"$projectroot/$dir/HEAD") {
690 } elsif (-f
$projects_list) {
691 # read from file(url-encoded):
692 # 'git%2Fgit.git Linus+Torvalds'
693 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
694 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
695 open my ($fd), $projects_list or return undef;
696 while (my $line = <$fd>) {
698 my ($path, $owner) = split ' ', $line;
699 $path = unescape
($path);
700 $owner = unescape
($owner);
701 if (!defined $path) {
704 if (-e
"$projectroot/$path/HEAD") {
707 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
714 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
718 sub git_get_project_owner
{
722 return undef unless $project;
724 # read from file (url-encoded):
725 # 'git%2Fgit.git Linus+Torvalds'
726 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
727 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
728 if (-f
$projects_list) {
729 open (my $fd , $projects_list);
730 while (my $line = <$fd>) {
732 my ($pr, $ow) = split ' ', $line;
735 if ($pr eq $project) {
736 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
742 if (!defined $owner) {
743 $owner = get_file_owner
("$projectroot/$project");
749 sub git_get_references
{
750 my $type = shift || "";
753 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
754 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
755 if (-f
"$projectroot/$project/info/refs") {
756 open $fd, "$projectroot/$project/info/refs"
759 open $fd, "-|", $GIT, "ls-remote", "."
763 while (my $line = <$fd>) {
765 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
766 if (defined $refs{$1}) {
767 push @
{$refs{$1}}, $2;
777 sub git_get_rev_name_tags
{
778 my $hash = shift || return undef;
780 open my $fd, "-|", $GIT, "name-rev", "--tags", $hash
782 my $name_rev = <$fd>;
785 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
788 # catches also '$hash undefined' output
793 ## ----------------------------------------------------------------------
794 ## parse to hash functions
798 my $tz = shift || "-0000";
801 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
802 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
803 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
804 $date{'hour'} = $hour;
805 $date{'minute'} = $min;
806 $date{'mday'} = $mday;
807 $date{'day'} = $days[$wday];
808 $date{'month'} = $months[$mon];
809 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
810 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
811 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
812 $mday, $months[$mon], $hour ,$min;
814 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
815 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
816 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
817 $date{'hour_local'} = $hour;
818 $date{'minute_local'} = $min;
819 $date{'tz_local'} = $tz;
828 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
829 $tag{'id'} = $tag_id;
830 while (my $line = <$fd>) {
832 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
834 } elsif ($line =~ m/^type (.+)$/) {
836 } elsif ($line =~ m/^tag (.+)$/) {
838 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
842 } elsif ($line =~ m/--BEGIN/) {
843 push @comment, $line;
845 } elsif ($line eq "") {
849 push @comment, <$fd>;
850 $tag{'comment'} = \
@comment;
852 if (!defined $tag{'name'}) {
859 my $commit_id = shift;
860 my $commit_text = shift;
865 if (defined $commit_text) {
866 @commit_lines = @
$commit_text;
869 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id
871 @commit_lines = split '\n', <$fd>;
876 my $header = shift @commit_lines;
877 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
880 ($co{'id'}, my @parents) = split ' ', $header;
881 $co{'parents'} = \
@parents;
882 $co{'parent'} = $parents[0];
883 while (my $line = shift @commit_lines) {
884 last if $line eq "\n";
885 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
887 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
889 $co{'author_epoch'} = $2;
890 $co{'author_tz'} = $3;
891 if ($co{'author'} =~ m/^([^<]+) </) {
892 $co{'author_name'} = $1;
894 $co{'author_name'} = $co{'author'};
896 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
897 $co{'committer'} = $1;
898 $co{'committer_epoch'} = $2;
899 $co{'committer_tz'} = $3;
900 $co{'committer_name'} = $co{'committer'};
901 $co{'committer_name'} =~ s/ <.*//;
904 if (!defined $co{'tree'}) {
908 foreach my $title (@commit_lines) {
911 $co{'title'} = chop_str
($title, 80, 5);
912 # remove leading stuff of merges to make the interesting part visible
913 if (length($title) > 50) {
914 $title =~ s/^Automatic //;
915 $title =~ s/^merge (of|with) /Merge ... /i;
916 if (length($title) > 50) {
917 $title =~ s/(http|rsync):\/\///;
919 if (length($title) > 50) {
920 $title =~ s/(master|www|rsync)\.//;
922 if (length($title) > 50) {
923 $title =~ s/kernel.org:?//;
925 if (length($title) > 50) {
926 $title =~ s/\/pub\/scm//;
929 $co{'title_short'} = chop_str
($title, 50, 5);
933 # remove added spaces
934 foreach my $line (@commit_lines) {
937 $co{'comment'} = \
@commit_lines;
939 my $age = time - $co{'committer_epoch'};
941 $co{'age_string'} = age_string
($age);
942 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
943 if ($age > 60*60*24*7*2) {
944 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
945 $co{'age_string_age'} = $co{'age_string'};
947 $co{'age_string_date'} = $co{'age_string'};
948 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
953 # parse ref from ref_file, given by ref_id, with given type
955 my $ref_file = shift;
957 my $type = shift || git_get_type
($ref_id);
960 $ref_item{'type'} = $type;
961 $ref_item{'id'} = $ref_id;
962 $ref_item{'epoch'} = 0;
963 $ref_item{'age'} = "unknown";
964 if ($type eq "tag") {
965 my %tag = parse_tag
($ref_id);
966 $ref_item{'comment'} = $tag{'comment'};
967 if ($tag{'type'} eq "commit") {
968 my %co = parse_commit
($tag{'object'});
969 $ref_item{'epoch'} = $co{'committer_epoch'};
970 $ref_item{'age'} = $co{'age_string'};
971 } elsif (defined($tag{'epoch'})) {
972 my $age = time - $tag{'epoch'};
973 $ref_item{'epoch'} = $tag{'epoch'};
974 $ref_item{'age'} = age_string
($age);
976 $ref_item{'reftype'} = $tag{'type'};
977 $ref_item{'name'} = $tag{'name'};
978 $ref_item{'refid'} = $tag{'object'};
979 } elsif ($type eq "commit"){
980 my %co = parse_commit
($ref_id);
981 $ref_item{'reftype'} = "commit";
982 $ref_item{'name'} = $ref_file;
983 $ref_item{'title'} = $co{'title'};
984 $ref_item{'refid'} = $ref_id;
985 $ref_item{'epoch'} = $co{'committer_epoch'};
986 $ref_item{'age'} = $co{'age_string'};
988 $ref_item{'reftype'} = $type;
989 $ref_item{'name'} = $ref_file;
990 $ref_item{'refid'} = $ref_id;
996 # parse line of git-diff-tree "raw" output
997 sub parse_difftree_raw_line
{
1001 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1002 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1003 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1004 $res{'from_mode'} = $1;
1005 $res{'to_mode'} = $2;
1006 $res{'from_id'} = $3;
1008 $res{'status'} = $5;
1009 $res{'similarity'} = $6;
1010 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1011 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1013 $res{'file'} = unquote
($7);
1016 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1017 #elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1018 # $res{'commit'} = $1;
1021 return wantarray ?
%res : \
%res;
1024 ## ......................................................................
1025 ## parse to array of hashes functions
1027 sub git_get_refs_list
{
1028 my $ref_dir = shift;
1032 my $pfxlen = length("$projectroot/$project/$ref_dir");
1033 File
::Find
::find
(sub {
1036 push @refs, substr($File::Find
::name
, $pfxlen + 1);
1038 }, "$projectroot/$project/$ref_dir");
1040 foreach my $ref_file (@refs) {
1041 my $ref_id = git_get_hash_by_ref
("$project/$ref_dir/$ref_file");
1042 my $type = git_get_type
($ref_id) || next;
1043 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1045 push @reflist, \
%ref_item;
1048 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1052 ## ----------------------------------------------------------------------
1053 ## filesystem-related functions
1055 sub get_file_owner
{
1058 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1059 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1060 if (!defined $gcos) {
1064 $owner =~ s/[,;].*$//;
1065 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
1068 ## ......................................................................
1069 ## mimetype related functions
1071 sub mimetype_guess_file
{
1072 my $filename = shift;
1073 my $mimemap = shift;
1074 -r
$mimemap or return undef;
1077 open(MIME
, $mimemap) or return undef;
1079 next if m/^#/; # skip comments
1080 my ($mime, $exts) = split(/\t+/);
1081 if (defined $exts) {
1082 my @exts = split(/\s+/, $exts);
1083 foreach my $ext (@exts) {
1084 $mimemap{$ext} = $mime;
1090 $filename =~ /\.(.*?)$/;
1091 return $mimemap{$1};
1094 sub mimetype_guess
{
1095 my $filename = shift;
1097 $filename =~ /\./ or return undef;
1099 if ($mimetypes_file) {
1100 my $file = $mimetypes_file;
1101 if ($file !~ m!^/!) { # if it is relative path
1102 # it is relative to project
1103 $file = "$projectroot/$project/$file";
1105 $mime = mimetype_guess_file
($filename, $file);
1107 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1113 my $filename = shift;
1116 my $mime = mimetype_guess
($filename);
1117 $mime and return $mime;
1121 return $default_blob_plain_mimetype unless $fd;
1124 return 'text/plain' .
1125 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1126 } elsif (! $filename) {
1127 return 'application/octet-stream';
1128 } elsif ($filename =~ m/\.png$/i) {
1130 } elsif ($filename =~ m/\.gif$/i) {
1132 } elsif ($filename =~ m/\.jpe?g$/i) {
1133 return 'image/jpeg';
1135 return 'application/octet-stream';
1139 ## ======================================================================
1140 ## functions printing HTML: header, footer, error page
1142 sub git_header_html
{
1143 my $status = shift || "200 OK";
1144 my $expires = shift;
1146 my $title = "$site_name git";
1147 if (defined $project) {
1148 $title .= " - $project";
1149 if (defined $action) {
1150 $title .= "/$action";
1151 if (defined $file_name) {
1152 $title .= " - $file_name";
1153 if ($action eq "tree" && $file_name !~ m
|/$|) {
1160 # require explicit support from the UA if we are to send the page as
1161 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1162 # we have to do this because MSIE sometimes globs '*/*', pretending to
1163 # support xhtml+xml but choking when it gets what it asked for.
1164 if (defined $cgi->http('HTTP_ACCEPT') &&
1165 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1166 $cgi->Accept('application/xhtml+xml') != 0) {
1167 $content_type = 'application/xhtml+xml';
1169 $content_type = 'text/html';
1171 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1172 -status
=> $status, -expires
=> $expires);
1174 <?xml version="1.0" encoding="utf-8"?>
1175 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1176 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1177 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1178 <!-- git core binaries version $git_version -->
1180 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1181 <meta name="generator" content="gitweb/$version git/$git_version"/>
1182 <meta name="robots" content="index, nofollow"/>
1183 <title>$title</title>
1184 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1186 if (defined $project) {
1187 printf('<link rel="alternate" title="%s log" '.
1188 'href="%s" type="application/rss+xml"/>'."\n",
1189 esc_param
($project), href
(action
=>"rss"));
1194 "<div class=\"page_header\">\n" .
1195 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1196 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1198 print $cgi->a({-href
=> esc_param
($home_link)}, $home_link_str) . " / ";
1199 if (defined $project) {
1200 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1201 if (defined $action) {
1205 if (!defined $searchtext) {
1209 if (defined $hash_base) {
1210 $search_hash = $hash_base;
1211 } elsif (defined $hash) {
1212 $search_hash = $hash;
1214 $search_hash = "HEAD";
1216 $cgi->param("a", "search");
1217 $cgi->param("h", $search_hash);
1218 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1219 "<div class=\"search\">\n" .
1220 $cgi->hidden(-name
=> "p") . "\n" .
1221 $cgi->hidden(-name
=> "a") . "\n" .
1222 $cgi->hidden(-name
=> "h") . "\n" .
1223 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1225 $cgi->end_form() . "\n";
1230 sub git_footer_html
{
1231 print "<div class=\"page_footer\">\n";
1232 if (defined $project) {
1233 my $descr = git_get_project_description
($project);
1234 if (defined $descr) {
1235 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1237 print $cgi->a({-href
=> href
(action
=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1239 print $cgi->a({-href
=> href
(action
=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1247 my $status = shift || "403 Forbidden";
1248 my $error = shift || "Malformed query, file missing or permission denied";
1250 git_header_html
($status);
1252 <div class="page_body">
1262 ## ----------------------------------------------------------------------
1263 ## functions printing or outputting HTML: navigation
1265 sub git_print_page_nav
{
1266 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1267 $extra = '' if !defined $extra; # pager or formats
1269 my @navs = qw(summary shortlog log commit commitdiff tree);
1271 @navs = grep { $_ ne $suppress } @navs;
1274 my %arg = map { $_ => {action
=>$_} } @navs;
1275 if (defined $head) {
1276 for (qw(commit commitdiff)) {
1277 $arg{$_}{hash
} = $head;
1279 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1280 for (qw(shortlog log)) {
1281 $arg{$_}{hash
} = $head;
1285 $arg{tree
}{hash
} = $treehead if defined $treehead;
1286 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1288 print "<div class=\"page_nav\">\n" .
1290 map { $_ eq $current ?
1291 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1293 print "<br/>\n$extra<br/>\n" .
1297 sub format_paging_nav
{
1298 my ($action, $hash, $head, $page, $nrevs) = @_;
1302 if ($hash ne $head || $page) {
1303 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1305 $paging_nav .= "HEAD";
1309 $paging_nav .= " ⋅ " .
1310 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1311 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1313 $paging_nav .= " ⋅ prev";
1316 if ($nrevs >= (100 * ($page+1)-1)) {
1317 $paging_nav .= " ⋅ " .
1318 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1319 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1321 $paging_nav .= " ⋅ next";
1327 ## ......................................................................
1328 ## functions printing or outputting HTML: div
1330 sub git_print_header_div
{
1331 my ($action, $title, $hash, $hash_base) = @_;
1334 $args{action
} = $action;
1335 $args{hash
} = $hash if $hash;
1336 $args{hash_base
} = $hash_base if $hash_base;
1338 print "<div class=\"header\">\n" .
1339 $cgi->a({-href
=> href
(%args), -class => "title"},
1340 $title ?
$title : $action) .
1344 sub git_print_page_path
{
1349 if (!defined $name) {
1350 print "<div class=\"page_path\">/</div>\n";
1351 } elsif (defined $type && $type eq 'blob') {
1352 print "<div class=\"page_path\">";
1354 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1358 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name)},
1361 print "<br/></div>\n";
1363 print "<div class=\"page_path\">" . esc_html
($name) . "<br/></div>\n";
1370 # remove leading empty lines
1371 while (defined $log->[0] && $log->[0] eq "") {
1378 foreach my $line (@
$log) {
1379 # print only one empty line
1380 # do not print empty line after signoff
1382 next if ($empty || $signoff);
1387 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1389 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1392 print format_log_line_html
($line) . "<br/>\n";
1397 sub git_print_simplified_log
{
1399 my $remove_title = shift;
1401 shift @
$log if $remove_title;
1402 # remove leading empty lines
1403 while (defined $log->[0] && $log->[0] eq "") {
1407 # simplify and print log
1409 foreach my $line (@
$log) {
1410 # remove signoff lines
1411 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1414 # print only one empty line
1421 print format_log_line_html
($line) . "<br/>\n";
1423 # end with single empty line
1424 print "<br/>\n" unless $empty;
1427 ## ......................................................................
1428 ## functions printing large fragments of HTML
1430 sub git_difftree_body
{
1431 my ($difftree, $hash, $parent) = @_;
1433 print "<div class=\"list_head\">\n";
1434 if ($#{$difftree} > 10) {
1435 print(($#{$difftree} + 1) . " files changed:\n");
1439 print "<table class=\"diff_tree\">\n";
1441 foreach my $line (@
{$difftree}) {
1442 my %diff = parse_difftree_raw_line
($line);
1445 print "<tr class=\"dark\">\n";
1447 print "<tr class=\"light\">\n";
1451 my ($to_mode_oct, $to_mode_str, $to_file_type);
1452 my ($from_mode_oct, $from_mode_str, $from_file_type);
1453 if ($diff{'to_mode'} ne ('0' x
6)) {
1454 $to_mode_oct = oct $diff{'to_mode'};
1455 if (S_ISREG
($to_mode_oct)) { # only for regular file
1456 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1458 $to_file_type = file_type
($diff{'to_mode'});
1460 if ($diff{'from_mode'} ne ('0' x
6)) {
1461 $from_mode_oct = oct $diff{'from_mode'};
1462 if (S_ISREG
($to_mode_oct)) { # only for regular file
1463 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1465 $from_file_type = file_type
($diff{'from_mode'});
1468 if ($diff{'status'} eq "A") { # created
1469 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1470 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1471 $mode_chng .= "]</span>";
1473 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1474 hash_base
=>$hash, file_name
=>$diff{'file'}),
1475 -class => "list"}, esc_html
($diff{'file'})) .
1477 "<td>$mode_chng</td>\n" .
1478 "<td class=\"link\">" .
1479 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1480 hash_base
=>$hash, file_name
=>$diff{'file'})},
1484 } elsif ($diff{'status'} eq "D") { # deleted
1485 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1487 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1488 hash_base
=>$parent, file_name
=>$diff{'file'}),
1489 -class => "list"}, esc_html
($diff{'file'})) .
1491 "<td>$mode_chng</td>\n" .
1492 "<td class=\"link\">" .
1493 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1494 hash_base
=>$parent, file_name
=>$diff{'file'})},
1497 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1498 file_name
=>$diff{'file'})},
1502 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1503 my $mode_chnge = "";
1504 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1505 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1506 if ($from_file_type != $to_file_type) {
1507 $mode_chnge .= " from $from_file_type to $to_file_type";
1509 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1510 if ($from_mode_str && $to_mode_str) {
1511 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1512 } elsif ($to_mode_str) {
1513 $mode_chnge .= " mode: $to_mode_str";
1516 $mode_chnge .= "]</span>\n";
1519 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1520 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1521 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1522 hash_base
=>$hash, hash_parent_base
=>$parent,
1523 file_name
=>$diff{'file'}),
1524 -class => "list"}, esc_html
($diff{'file'}));
1525 } else { # only mode changed
1526 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1527 hash_base
=>$hash, file_name
=>$diff{'file'}),
1528 -class => "list"}, esc_html
($diff{'file'}));
1531 "<td>$mode_chnge</td>\n" .
1532 "<td class=\"link\">" .
1533 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1534 hash_base
=>$hash, file_name
=>$diff{'file'})},
1536 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1538 $cgi->a({-href
=> href
(action
=>"blobdiff",
1539 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1540 hash_base
=>$hash, hash_parent_base
=>$parent,
1541 file_name
=>$diff{'file'})},
1545 $cgi->a({-href
=> href
(action
=>"history",
1546 hash_base
=>$hash, file_name
=>$diff{'file'})},
1550 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1551 my %status_name = ('R' => 'moved', 'C' => 'copied');
1552 my $nstatus = $status_name{$diff{'status'}};
1554 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1555 # mode also for directories, so we cannot use $to_mode_str
1556 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1559 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1560 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1561 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1562 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1563 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1564 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1565 -class => "list"}, esc_html
($diff{'from_file'})) .
1566 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1567 "<td class=\"link\">" .
1568 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1569 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'})},
1571 if ($diff{'to_id'} ne $diff{'from_id'}) {
1573 $cgi->a({-href
=> href
(action
=>"blobdiff",
1574 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1575 hash_base
=>$hash, hash_parent_base
=>$parent,
1576 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1581 } # we should not encounter Unmerged (U) or Unknown (X) status
1587 sub git_patchset_body
{
1588 my ($fd, $difftree, $hash, $hash_parent) = @_;
1592 my $patch_found = 0;
1595 print "<div class=\"patchset\">\n";
1598 while (my $patch_line = <$fd>) {
1601 if ($patch_line =~ m/^diff /) { # "git diff" header
1602 # beginning of patch (in patchset)
1604 # close previous patch
1605 print "</div>\n"; # class="patch"
1607 # first patch in patchset
1610 print "<div class=\"patch\">\n";
1612 if (ref($difftree->[$patch_idx]) eq "HASH") {
1613 $diffinfo = $difftree->[$patch_idx];
1615 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1619 # for now, no extended header, hence we skip empty patches
1620 # companion to next LINE if $in_header;
1621 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1626 if ($diffinfo->{'status'} eq "A") { # added
1627 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1628 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1629 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1630 $diffinfo->{'to_id'}) . "(new)" .
1631 "</div>\n"; # class="diff_info"
1633 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1634 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
1635 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1636 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1637 $diffinfo->{'from_id'}) . "(deleted)" .
1638 "</div>\n"; # class="diff_info"
1640 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1641 $diffinfo->{'status'} eq "C" || # copied
1642 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1643 print "<div class=\"diff_info\">" .
1644 file_type
($diffinfo->{'from_mode'}) . ":" .
1645 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1646 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
1647 $diffinfo->{'from_id'}) .
1649 file_type
($diffinfo->{'to_mode'}) . ":" .
1650 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1651 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
1652 $diffinfo->{'to_id'});
1653 print "</div>\n"; # class="diff_info"
1655 } else { # modified, mode changed, ...
1656 print "<div class=\"diff_info\">" .
1657 file_type
($diffinfo->{'from_mode'}) . ":" .
1658 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1659 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1660 $diffinfo->{'from_id'}) .
1662 file_type
($diffinfo->{'to_mode'}) . ":" .
1663 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1664 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1665 $diffinfo->{'to_id'});
1666 print "</div>\n"; # class="diff_info"
1669 #print "<div class=\"diff extended_header\">\n";
1672 } # start of patch in patchset
1675 if ($in_header && $patch_line =~ m/^---/) {
1676 #print "</div>\n"; # class="diff extended_header"
1679 my $file = $diffinfo->{'from_file'};
1680 $file ||= $diffinfo->{'file'};
1681 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1682 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
1683 -class => "list"}, esc_html
($file));
1684 $patch_line =~ s
|a
/.*$|a/$file|g
;
1685 print "<div class=\"diff from_file\">$patch_line</div>\n";
1687 $patch_line = <$fd>;
1690 #$patch_line =~ m/^+++/;
1691 $file = $diffinfo->{'to_file'};
1692 $file ||= $diffinfo->{'file'};
1693 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1694 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
1695 -class => "list"}, esc_html
($file));
1696 $patch_line =~ s
|b
/.*|b/$file|g
;
1697 print "<div class=\"diff to_file\">$patch_line</div>\n";
1701 next LINE
if $in_header;
1703 print format_diff_line
($patch_line);
1705 print "</div>\n" if $patch_found; # class="patch"
1707 print "</div>\n"; # class="patchset"
1710 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1712 sub git_shortlog_body
{
1713 # uses global variable $project
1714 my ($revlist, $from, $to, $refs, $extra) = @_;
1716 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
1717 my $have_snapshot = (defined $ctype && defined $suffix);
1719 $from = 0 unless defined $from;
1720 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1722 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1724 for (my $i = $from; $i <= $to; $i++) {
1725 my $commit = $revlist->[$i];
1726 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1727 my $ref = format_ref_marker
($refs, $commit);
1728 my %co = parse_commit
($commit);
1730 print "<tr class=\"dark\">\n";
1732 print "<tr class=\"light\">\n";
1735 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1736 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1737 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1739 print format_subject_html
($co{'title'}, $co{'title_short'},
1740 href
(action
=>"commit", hash
=>$commit), $ref);
1742 "<td class=\"link\">" .
1743 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1744 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
1745 if ($have_snapshot) {
1746 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
1751 if (defined $extra) {
1753 "<td colspan=\"4\">$extra</td>\n" .
1759 sub git_history_body
{
1760 # Warning: assumes constant type (blob or tree) during history
1761 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1763 print "<table class=\"history\" cellspacing=\"0\">\n";
1765 while (my $line = <$fd>) {
1766 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1771 my %co = parse_commit
($commit);
1776 my $ref = format_ref_marker
($refs, $commit);
1779 print "<tr class=\"dark\">\n";
1781 print "<tr class=\"light\">\n";
1784 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1785 # shortlog uses chop_str($co{'author_name'}, 10)
1786 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1788 # originally git_history used chop_str($co{'title'}, 50)
1789 print format_subject_html
($co{'title'}, $co{'title_short'},
1790 href
(action
=>"commit", hash
=>$commit), $ref);
1792 "<td class=\"link\">" .
1793 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1794 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
1795 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype);
1797 if ($ftype eq 'blob') {
1798 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
1799 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
1800 if (defined $blob_current && defined $blob_parent &&
1801 $blob_current ne $blob_parent) {
1803 $cgi->a({-href
=> href
(action
=>"blobdiff",
1804 hash
=>$blob_current, hash_parent
=>$blob_parent,
1805 hash_base
=>$hash_base, hash_parent_base
=>$commit,
1806 file_name
=>$file_name)},
1813 if (defined $extra) {
1815 "<td colspan=\"4\">$extra</td>\n" .
1822 # uses global variable $project
1823 my ($taglist, $from, $to, $extra) = @_;
1824 $from = 0 unless defined $from;
1825 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1827 print "<table class=\"tags\" cellspacing=\"0\">\n";
1829 for (my $i = $from; $i <= $to; $i++) {
1830 my $entry = $taglist->[$i];
1832 my $comment_lines = $tag{'comment'};
1833 my $comment = shift @
$comment_lines;
1835 if (defined $comment) {
1836 $comment_short = chop_str
($comment, 30, 5);
1839 print "<tr class=\"dark\">\n";
1841 print "<tr class=\"light\">\n";
1844 print "<td><i>$tag{'age'}</i></td>\n" .
1846 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
1847 -class => "list name"}, esc_html
($tag{'name'})) .
1850 if (defined $comment) {
1851 print format_subject_html
($comment, $comment_short,
1852 href
(action
=>"tag", hash
=>$tag{'id'}));
1855 "<td class=\"selflink\">";
1856 if ($tag{'type'} eq "tag") {
1857 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
1862 "<td class=\"link\">" . " | " .
1863 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
1864 if ($tag{'reftype'} eq "commit") {
1865 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
1866 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
1867 } elsif ($tag{'reftype'} eq "blob") {
1868 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
1873 if (defined $extra) {
1875 "<td colspan=\"5\">$extra</td>\n" .
1881 sub git_heads_body
{
1882 # uses global variable $project
1883 my ($taglist, $head, $from, $to, $extra) = @_;
1884 $from = 0 unless defined $from;
1885 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1887 print "<table class=\"heads\" cellspacing=\"0\">\n";
1889 for (my $i = $from; $i <= $to; $i++) {
1890 my $entry = $taglist->[$i];
1892 my $curr = $tag{'id'} eq $head;
1894 print "<tr class=\"dark\">\n";
1896 print "<tr class=\"light\">\n";
1899 print "<td><i>$tag{'age'}</i></td>\n" .
1900 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1901 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
1902 -class => "list name"},esc_html
($tag{'name'})) .
1904 "<td class=\"link\">" .
1905 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
1906 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") .
1910 if (defined $extra) {
1912 "<td colspan=\"3\">$extra</td>\n" .
1918 ## ======================================================================
1919 ## ======================================================================
1922 sub git_project_list
{
1923 my $order = $cgi->param('o');
1924 if (defined $order && $order !~ m/project|descr|owner|age/) {
1925 die_error
(undef, "Unknown order parameter");
1928 my @list = git_get_projects_list
();
1931 die_error
(undef, "No projects found");
1933 foreach my $pr (@list) {
1934 my $head = git_get_head_hash
($pr->{'path'});
1935 if (!defined $head) {
1938 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1939 my %co = parse_commit
($head);
1943 $pr->{'commit'} = \
%co;
1944 if (!defined $pr->{'descr'}) {
1945 my $descr = git_get_project_description
($pr->{'path'}) || "";
1946 $pr->{'descr'} = chop_str
($descr, 25, 5);
1948 if (!defined $pr->{'owner'}) {
1949 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
1951 push @projects, $pr;
1955 if (-f
$home_text) {
1956 print "<div class=\"index_include\">\n";
1957 open (my $fd, $home_text);
1962 print "<table class=\"project_list\">\n" .
1964 $order ||= "project";
1965 if ($order eq "project") {
1966 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1967 print "<th>Project</th>\n";
1970 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
1971 -class => "header"}, "Project") .
1974 if ($order eq "descr") {
1975 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1976 print "<th>Description</th>\n";
1979 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
1980 -class => "header"}, "Description") .
1983 if ($order eq "owner") {
1984 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1985 print "<th>Owner</th>\n";
1988 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
1989 -class => "header"}, "Owner") .
1992 if ($order eq "age") {
1993 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1994 print "<th>Last Change</th>\n";
1997 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
1998 -class => "header"}, "Last Change") .
2001 print "<th></th>\n" .
2004 foreach my $pr (@projects) {
2006 print "<tr class=\"dark\">\n";
2008 print "<tr class=\"light\">\n";
2011 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2012 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2013 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2014 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2015 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2016 $pr->{'commit'}{'age_string'} . "</td>\n" .
2017 "<td class=\"link\">" .
2018 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2019 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2020 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") .
2029 my $descr = git_get_project_description
($project) || "none";
2030 my $head = git_get_head_hash
($project);
2031 my %co = parse_commit
($head);
2032 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2034 my $owner = git_get_project_owner
($project);
2036 my $refs = git_get_references
();
2038 git_print_page_nav
('summary','', $head);
2040 print "<div class=\"title\"> </div>\n";
2041 print "<table cellspacing=\"0\">\n" .
2042 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2043 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2044 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2045 # use per project git URL list in $projectroot/$project/cloneurl
2046 # or make project git URL from git base URL and project name
2047 my $url_tag = "URL";
2048 my @url_list = git_get_project_url_list
($project);
2049 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2050 foreach my $git_url (@url_list) {
2051 next unless $git_url;
2052 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2057 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash
($project)
2058 or die_error
(undef, "Open git-rev-list failed");
2059 my @revlist = map { chomp; $_ } <$fd>;
2061 git_print_header_div
('shortlog');
2062 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2063 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2065 my $taglist = git_get_refs_list
("refs/tags");
2066 if (defined @
$taglist) {
2067 git_print_header_div
('tags');
2068 git_tags_body
($taglist, 0, 15,
2069 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2072 my $headlist = git_get_refs_list
("refs/heads");
2073 if (defined @
$headlist) {
2074 git_print_header_div
('heads');
2075 git_heads_body
($headlist, $head, 0, 15,
2076 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2083 my $head = git_get_head_hash
($project);
2085 git_print_page_nav
('','', $head,undef,$head);
2086 my %tag = parse_tag
($hash);
2087 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2088 print "<div class=\"title_text\">\n" .
2089 "<table cellspacing=\"0\">\n" .
2091 "<td>object</td>\n" .
2092 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2093 $tag{'object'}) . "</td>\n" .
2094 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2095 $tag{'type'}) . "</td>\n" .
2097 if (defined($tag{'author'})) {
2098 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2099 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2100 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2101 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2104 print "</table>\n\n" .
2106 print "<div class=\"page_body\">";
2107 my $comment = $tag{'comment'};
2108 foreach my $line (@
$comment) {
2109 print esc_html
($line) . "<br/>\n";
2119 if (!gitweb_check_feature
('blame')) {
2120 die_error
('403 Permission denied', "Permission denied");
2122 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2123 $hash_base ||= git_get_head_hash
($project);
2124 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2125 my %co = parse_commit
($hash_base)
2126 or die_error
(undef, "Reading commit failed");
2127 if (!defined $hash) {
2128 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2129 or die_error
(undef, "Error looking up file");
2131 $ftype = git_get_type
($hash);
2132 if ($ftype !~ "blob") {
2133 die_error
("400 Bad Request", "Object is not a blob");
2135 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
2136 or die_error
(undef, "Open git-blame failed");
2139 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2142 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2144 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2145 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2146 git_print_page_path
($file_name, $ftype, $hash_base);
2147 my @rev_color = (qw(light2 dark2));
2148 my $num_colors = scalar(@rev_color);
2149 my $current_color = 0;
2152 <div class="page_body">
2153 <table class="blame">
2154 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2157 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2159 my $rev = substr($full_rev, 0, 8);
2163 if (!defined $last_rev) {
2164 $last_rev = $full_rev;
2165 } elsif ($last_rev ne $full_rev) {
2166 $last_rev = $full_rev;
2167 $current_color = ++$current_color % $num_colors;
2169 print "<tr class=\"$rev_color[$current_color]\">\n";
2170 print "<td class=\"sha1\">" .
2171 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)},
2172 esc_html
($rev)) . "</td>\n";
2173 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2174 esc_html
($lineno) . "</a></td>\n";
2175 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2181 or print "Reading blob failed\n";
2188 if (!gitweb_check_feature
('blame')) {
2189 die_error
('403 Permission denied', "Permission denied");
2191 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2192 $hash_base ||= git_get_head_hash
($project);
2193 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2194 my %co = parse_commit
($hash_base)
2195 or die_error
(undef, "Reading commit failed");
2196 if (!defined $hash) {
2197 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2198 or die_error
(undef, "Error lookup file");
2200 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2201 or die_error
(undef, "Open git-annotate failed");
2204 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2207 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2209 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2210 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2211 git_print_page_path
($file_name, 'blob', $hash_base);
2212 print "<div class=\"page_body\">\n";
2214 <table class="blame">
2223 my @line_class = (qw(light dark));
2224 my $line_class_len = scalar (@line_class);
2225 my $line_class_num = $#line_class;
2226 while (my $line = <$fd>) {
2238 $line_class_num = ($line_class_num + 1) % $line_class_len;
2240 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2247 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2250 $short_rev = substr ($long_rev, 0, 8);
2251 $age = time () - $time;
2252 $age_str = age_string
($age);
2253 $age_str =~ s/ / /g;
2254 $age_class = age_class
($age);
2255 $author = esc_html
($author);
2256 $author =~ s/ / /g;
2258 $data = untabify
($data);
2259 $data = esc_html
($data);
2262 <tr class="$line_class[$line_class_num]">
2263 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2264 <td class="$age_class">$age_str</td>
2266 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2267 <td class="pre">$data</td>
2270 } # while (my $line = <$fd>)
2271 print "</table>\n\n";
2273 or print "Reading blob failed.\n";
2279 my $head = git_get_head_hash
($project);
2281 git_print_page_nav
('','', $head,undef,$head);
2282 git_print_header_div
('summary', $project);
2284 my $taglist = git_get_refs_list
("refs/tags");
2285 if (defined @
$taglist) {
2286 git_tags_body
($taglist);
2292 my $head = git_get_head_hash
($project);
2294 git_print_page_nav
('','', $head,undef,$head);
2295 git_print_header_div
('summary', $project);
2297 my $taglist = git_get_refs_list
("refs/heads");
2298 if (defined @
$taglist) {
2299 git_heads_body
($taglist, $head);
2304 sub git_blob_plain
{
2305 # blobs defined by non-textual hash id's can be cached
2307 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2311 if (!defined $hash) {
2312 if (defined $file_name) {
2313 my $base = $hash_base || git_get_head_hash
($project);
2314 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2315 or die_error
(undef, "Error lookup file");
2317 die_error
(undef, "No file name defined");
2321 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2322 or die_error
(undef, "Couldn't cat $file_name, $hash");
2324 $type ||= blob_mimetype
($fd, $file_name);
2326 # save as filename, even when no $file_name is given
2327 my $save_as = "$hash";
2328 if (defined $file_name) {
2329 $save_as = $file_name;
2330 } elsif ($type =~ m/^text\//) {
2337 -content_disposition
=> "inline; filename=\"$save_as\"");
2339 binmode STDOUT
, ':raw';
2341 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2347 # blobs defined by non-textual hash id's can be cached
2349 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2353 if (!defined $hash) {
2354 if (defined $file_name) {
2355 my $base = $hash_base || git_get_head_hash
($project);
2356 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2357 or die_error
(undef, "Error lookup file");
2359 die_error
(undef, "No file name defined");
2362 my $have_blame = gitweb_check_feature
('blame');
2363 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2364 or die_error
(undef, "Couldn't cat $file_name, $hash");
2365 my $mimetype = blob_mimetype
($fd, $file_name);
2366 if ($mimetype !~ m/^text\//) {
2368 return git_blob_plain
($mimetype);
2370 git_header_html
(undef, $expires);
2371 my $formats_nav = '';
2372 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2373 if (defined $file_name) {
2376 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2377 hash
=>$hash, file_name
=>$file_name)},
2382 $cgi->a({-href
=> href
(action
=>"blob_plain",
2383 hash
=>$hash, file_name
=>$file_name)},
2386 $cgi->a({-href
=> href
(action
=>"blob",
2387 hash_base
=>"HEAD", file_name
=>$file_name)},
2391 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "plain");
2393 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2394 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2396 print "<div class=\"page_nav\">\n" .
2397 "<br/><br/></div>\n" .
2398 "<div class=\"title\">$hash</div>\n";
2400 git_print_page_path
($file_name, "blob", $hash_base);
2401 print "<div class=\"page_body\">\n";
2403 while (my $line = <$fd>) {
2406 $line = untabify
($line);
2407 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2408 $nr, $nr, $nr, esc_html
($line);
2411 or print "Reading blob failed.\n";
2417 if (!defined $hash) {
2418 $hash = git_get_head_hash
($project);
2419 if (defined $file_name) {
2420 my $base = $hash_base || $hash;
2421 $hash = git_get_hash_by_path
($base, $file_name, "tree");
2423 if (!defined $hash_base) {
2428 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
2429 or die_error
(undef, "Open git-ls-tree failed");
2430 my @entries = map { chomp; $_ } <$fd>;
2431 close $fd or die_error
(undef, "Reading tree failed");
2434 my $refs = git_get_references
();
2435 my $ref = format_ref_marker
($refs, $hash_base);
2439 my $have_blame = gitweb_check_feature
('blame');
2440 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2441 $base_key{hash_base
} = $hash_base;
2442 git_print_page_nav
('tree','', $hash_base);
2443 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2445 print "<div class=\"page_nav\">\n";
2446 print "<br/><br/></div>\n";
2447 print "<div class=\"title\">$hash</div>\n";
2449 if (defined $file_name) {
2450 $base = esc_html
("$file_name/");
2452 git_print_page_path
($file_name, 'tree', $hash_base);
2453 print "<div class=\"page_body\">\n";
2454 print "<table cellspacing=\"0\">\n";
2456 foreach my $line (@entries) {
2457 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2458 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2462 my $t_name = validate_input
($4);
2464 print "<tr class=\"dark\">\n";
2466 print "<tr class=\"light\">\n";
2469 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
2470 if ($t_type eq "blob") {
2471 print "<td class=\"list\">" .
2472 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key),
2473 -class => "list"}, esc_html
($t_name)) .
2475 "<td class=\"link\">" .
2476 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2480 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2484 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2485 hash
=>$t_hash, file_name
=>"$base$t_name")},
2488 $cgi->a({-href
=> href
(action
=>"blob_plain",
2489 hash
=>$t_hash, file_name
=>"$base$t_name")},
2492 } elsif ($t_type eq "tree") {
2493 print "<td class=\"list\">" .
2494 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2495 esc_html
($t_name)) .
2497 "<td class=\"link\">" .
2498 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2501 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base, file_name
=>"$base$t_name")},
2507 print "</table>\n" .
2514 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2515 my $have_snapshot = (defined $ctype && defined $suffix);
2516 if (!$have_snapshot) {
2517 die_error
('403 Permission denied', "Permission denied");
2520 if (!defined $hash) {
2521 $hash = git_get_head_hash
($project);
2524 my $filename = basename
($project) . "-$hash.tar.$suffix";
2526 print $cgi->header(-type
=> 'application/x-tar',
2527 -content_encoding
=> $ctype,
2528 -content_disposition
=> "inline; filename=\"$filename\"",
2529 -status
=> '200 OK');
2531 open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | $command" or
2532 die_error
(undef, "Execute git-tar-tree failed.");
2533 binmode STDOUT
, ':raw';
2535 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2541 my $head = git_get_head_hash
($project);
2542 if (!defined $hash) {
2545 if (!defined $page) {
2548 my $refs = git_get_references
();
2550 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2551 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2552 or die_error
(undef, "Open git-rev-list failed");
2553 my @revlist = map { chomp; $_ } <$fd>;
2556 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2559 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2562 my %co = parse_commit
($hash);
2564 git_print_header_div
('summary', $project);
2565 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2567 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2568 my $commit = $revlist[$i];
2569 my $ref = format_ref_marker
($refs, $commit);
2570 my %co = parse_commit
($commit);
2572 my %ad = parse_date
($co{'author_epoch'});
2573 git_print_header_div
('commit',
2574 "<span class=\"age\">$co{'age_string'}</span>" .
2575 esc_html
($co{'title'}) . $ref,
2577 print "<div class=\"title_text\">\n" .
2578 "<div class=\"log_link\">\n" .
2579 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2581 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2584 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2587 print "<div class=\"log_body\">\n";
2588 git_print_simplified_log
($co{'comment'});
2595 my %co = parse_commit
($hash);
2597 die_error
(undef, "Unknown commit object");
2599 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2600 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2602 my $parent = $co{'parent'};
2603 if (!defined $parent) {
2606 open my $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts, $parent, $hash
2607 or die_error
(undef, "Open git-diff-tree failed");
2608 my @difftree = map { chomp; $_ } <$fd>;
2609 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2611 # non-textual hash id's can be cached
2613 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2616 my $refs = git_get_references
();
2617 my $ref = format_ref_marker
($refs, $co{'id'});
2619 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2620 my $have_snapshot = (defined $ctype && defined $suffix);
2622 my $formats_nav = '';
2623 if (defined $file_name && defined $co{'parent'}) {
2624 my $parent = $co{'parent'};
2626 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
2629 git_header_html
(undef, $expires);
2630 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
2631 $hash, $co{'tree'}, $hash,
2634 if (defined $co{'parent'}) {
2635 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2637 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
2639 print "<div class=\"title_text\">\n" .
2640 "<table cellspacing=\"0\">\n";
2641 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2643 "<td></td><td> $ad{'rfc2822'}";
2644 if ($ad{'hour_local'} < 6) {
2645 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2646 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2648 printf(" (%02d:%02d %s)",
2649 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2653 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2654 print "<tr><td></td><td> $cd{'rfc2822'}" .
2655 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2657 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2660 "<td class=\"sha1\">" .
2661 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
2662 class => "list"}, $co{'tree'}) .
2664 "<td class=\"link\">" .
2665 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
2667 if ($have_snapshot) {
2669 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
2673 my $parents = $co{'parents'};
2674 foreach my $par (@
$parents) {
2677 "<td class=\"sha1\">" .
2678 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
2679 class => "list"}, $par) .
2681 "<td class=\"link\">" .
2682 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
2684 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "commitdiff") .
2691 print "<div class=\"page_body\">\n";
2692 git_print_log
($co{'comment'});
2695 git_difftree_body
(\
@difftree, $hash, $parent);
2701 my $format = shift || 'html';
2708 # preparing $fd and %diffinfo for git_patchset_body
2710 if (defined $hash_base && defined $hash_parent_base) {
2711 if (defined $file_name) {
2713 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
2715 or die_error
(undef, "Open git-diff-tree failed");
2716 @difftree = map { chomp; $_ } <$fd>;
2718 or die_error
(undef, "Reading git-diff-tree failed");
2720 or die_error
('404 Not Found', "Blob diff not found");
2722 } elsif (defined $hash) { # try to find filename from $hash
2723 if ($hash !~ /[0-9a-fA-F]{40}/) {
2724 $hash = git_to_hash
($hash);
2726 } elsif (defined $hash &&
2727 $hash =~ /[0-9a-fA-F]{40}/) {
2728 # try to find filename from $hash
2730 # read filtered raw output
2731 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
2732 or die_error
(undef, "Open git-diff-tree failed");
2734 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
2736 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
2737 map { chomp; $_ } <$fd>;
2739 or die_error
(undef, "Reading git-diff-tree failed");
2741 or die_error
('404 Not Found', "Blob diff not found");
2744 die_error
('404 Not Found', "Missing one of the blob diff parameters");
2747 if (@difftree > 1) {
2748 die_error
('404 Not Found', "Ambiguous blob diff specification");
2751 %diffinfo = parse_difftree_raw_line
($difftree[0]);
2752 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
2753 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
2755 $hash_parent ||= $diffinfo{'from_id'};
2756 $hash ||= $diffinfo{'to_id'};
2758 # non-textual hash id's can be cached
2759 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
2760 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
2765 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts,
2766 '-p', $hash_parent_base, $hash_base,
2768 or die_error
(undef, "Open git-diff-tree failed");
2771 # old/legacy style URI
2772 if (!%diffinfo && # if new style URI failed
2773 defined $hash && defined $hash_parent) {
2774 # fake git-diff-tree raw output
2775 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
2776 $diffinfo{'from_id'} = $hash_parent;
2777 $diffinfo{'to_id'} = $hash;
2778 if (defined $file_name) {
2779 if (defined $file_parent) {
2780 $diffinfo{'status'} = '2';
2781 $diffinfo{'from_file'} = $file_parent;
2782 $diffinfo{'to_file'} = $file_name;
2783 } else { # assume not renamed
2784 $diffinfo{'status'} = '1';
2785 $diffinfo{'from_file'} = $file_name;
2786 $diffinfo{'to_file'} = $file_name;
2788 } else { # no filename given
2789 $diffinfo{'status'} = '2';
2790 $diffinfo{'from_file'} = $hash_parent;
2791 $diffinfo{'to_file'} = $hash;
2794 # non-textual hash id's can be cached
2795 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
2796 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
2801 open $fd, "-|", $GIT, "diff", '-p', @diff_opts, $hash_parent, $hash
2802 or die_error
(undef, "Open git-diff failed");
2804 die_error
('404 Not Found', "Missing one of the blob diff parameters")
2809 if ($format eq 'html') {
2811 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
2812 hash
=>$hash, hash_parent
=>$hash_parent,
2813 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
2814 file_name
=>$file_name, file_parent
=>$file_parent)},
2816 git_header_html
(undef, $expires);
2817 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2818 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2819 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2821 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
2822 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
2824 if (defined $file_name) {
2825 git_print_page_path
($file_name, "blob", $hash_base);
2827 print "<div class=\"page_path\"></div>\n";
2830 } elsif ($format eq 'plain') {
2832 -type
=> 'text/plain',
2833 -charset
=> 'utf-8',
2834 -expires
=> $expires,
2835 -content_disposition
=> qq(inline
; filename
="${file_name}.patch"));
2837 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
2840 die_error
(undef, "Unknown blobdiff format");
2844 if ($format eq 'html') {
2845 print "<div class=\"page_body\">\n";
2847 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
2850 print "</div>\n"; # class="page_body"
2854 while (my $line = <$fd>) {
2855 $line =~ s!a/($hash|$hash_parent)!a/$diffinfo{'from_file'}!g;
2856 $line =~ s!b/($hash|$hash_parent)!b/$diffinfo{'to_file'}!g;
2860 last if $line =~ m!^\+\+\+!;
2868 sub git_blobdiff_plain
{
2869 git_blobdiff
('plain');
2872 sub git_commitdiff
{
2873 my $format = shift || 'html';
2874 my %co = parse_commit
($hash);
2876 die_error
(undef, "Unknown commit object");
2878 if (!defined $hash_parent) {
2879 $hash_parent = $co{'parent'} || '--root';
2885 if ($format eq 'html') {
2886 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts,
2887 "--patch-with-raw", "--full-index", $hash_parent, $hash
2888 or die_error
(undef, "Open git-diff-tree failed");
2890 while (chomp(my $line = <$fd>)) {
2891 # empty line ends raw part of diff-tree output
2893 push @difftree, $line;
2896 } elsif ($format eq 'plain') {
2897 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts,
2898 '-p', $hash_parent, $hash
2899 or die_error
(undef, "Open git-diff-tree failed");
2902 die_error
(undef, "Unknown commitdiff format");
2905 # non-textual hash id's can be cached
2907 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2911 # write commit message
2912 if ($format eq 'html') {
2913 my $refs = git_get_references
();
2914 my $ref = format_ref_marker
($refs, $co{'id'});
2916 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
2917 hash
=>$hash, hash_parent
=>$hash_parent)},
2920 git_header_html
(undef, $expires);
2921 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2922 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2923 print "<div class=\"page_body\">\n";
2924 print "<div class=\"log\">\n";
2925 git_print_simplified_log
($co{'comment'}, 1); # skip title
2926 print "</div>\n"; # class="log"
2928 } elsif ($format eq 'plain') {
2929 my $refs = git_get_references
("tags");
2930 my $tagname = git_get_rev_name_tags
($hash);
2931 my $filename = basename
($project) . "-$hash.patch";
2934 -type
=> 'text/plain',
2935 -charset
=> 'utf-8',
2936 -expires
=> $expires,
2937 -content_disposition
=> qq(inline
; filename
="$filename"));
2938 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2941 Date: $ad{'rfc2822'} ($ad{'tz_local'})
2942 Subject: $co{'title'}
2944 print "X-Git-Tag: $tagname\n" if $tagname;
2945 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
2947 foreach my $line (@
{$co{'comment'}}) {
2954 if ($format eq 'html') {
2955 #git_difftree_body(\@difftree, $hash, $hash_parent);
2958 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
2960 print "</div>\n"; # class="page_body"
2963 } elsif ($format eq 'plain') {
2967 or print "Reading git-diff-tree failed\n";
2971 sub git_commitdiff_plain
{
2972 git_commitdiff
('plain');
2976 if (!defined $hash_base) {
2977 $hash_base = git_get_head_hash
($project);
2980 my %co = parse_commit
($hash_base);
2982 die_error
(undef, "Unknown commit object");
2984 my $refs = git_get_references
();
2986 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2987 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2988 if (!defined $hash && defined $file_name) {
2989 $hash = git_get_hash_by_path
($hash_base, $file_name);
2991 if (defined $hash) {
2992 $ftype = git_get_type
($hash);
2994 git_print_page_path
($file_name, $ftype, $hash_base);
2997 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2998 git_history_body
($fd, $refs, $hash_base, $ftype);
3005 if (!defined $searchtext) {
3006 die_error
(undef, "Text field empty");
3008 if (!defined $hash) {
3009 $hash = git_get_head_hash
($project);
3011 my %co = parse_commit
($hash);
3013 die_error
(undef, "Unknown commit object");
3015 # pickaxe may take all resources of your box and run for several minutes
3016 # with every query - so decide by yourself how public you make this feature :)
3017 my $commit_search = 1;
3018 my $author_search = 0;
3019 my $committer_search = 0;
3020 my $pickaxe_search = 0;
3021 if ($searchtext =~ s/^author\\://i) {
3023 } elsif ($searchtext =~ s/^committer\\://i) {
3024 $committer_search = 1;
3025 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3027 $pickaxe_search = 1;
3030 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3031 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3033 print "<table cellspacing=\"0\">\n";
3035 if ($commit_search) {
3037 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
3038 while (my $commit_text = <$fd>) {
3039 if (!grep m/$searchtext/i, $commit_text) {
3042 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3045 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3048 my @commit_lines = split "\n", $commit_text;
3049 my %co = parse_commit
(undef, \
@commit_lines);
3054 print "<tr class=\"dark\">\n";
3056 print "<tr class=\"light\">\n";
3059 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3060 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3062 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3063 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3064 my $comment = $co{'comment'};
3065 foreach my $line (@
$comment) {
3066 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3067 my $lead = esc_html
($1) || "";
3068 $lead = chop_str
($lead, 30, 10);
3069 my $match = esc_html
($2) || "";
3070 my $trail = esc_html
($3) || "";
3071 $trail = chop_str
($trail, 30, 10);
3072 my $text = "$lead<span class=\"match\">$match</span>$trail";
3073 print chop_str
($text, 80, 5) . "<br/>\n";
3077 "<td class=\"link\">" .
3078 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3080 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3087 if ($pickaxe_search) {
3089 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
3092 while (my $line = <$fd>) {
3093 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3096 $set{'from_id'} = $3;
3098 $set{'id'} = $set{'to_id'};
3099 if ($set{'id'} =~ m/0{40}/) {
3100 $set{'id'} = $set{'from_id'};
3102 if ($set{'id'} =~ m/0{40}/) {
3106 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3109 print "<tr class=\"dark\">\n";
3111 print "<tr class=\"light\">\n";
3114 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3115 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3117 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3118 -class => "list subject"},
3119 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3120 while (my $setref = shift @files) {
3122 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3123 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3125 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3129 "<td class=\"link\">" .
3130 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3132 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3136 %co = parse_commit
($1);
3146 my $head = git_get_head_hash
($project);
3147 if (!defined $hash) {
3150 if (!defined $page) {
3153 my $refs = git_get_references
();
3155 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3156 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
3157 or die_error
(undef, "Open git-rev-list failed");
3158 my @revlist = map { chomp; $_ } <$fd>;
3161 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3163 if ($#revlist >= (100 * ($page+1)-1)) {
3165 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3166 -title
=> "Alt-n"}, "next");
3171 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3172 git_print_header_div
('summary', $project);
3174 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3179 ## ......................................................................
3180 ## feeds (RSS, OPML)
3183 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3184 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash
($project)
3185 or die_error
(undef, "Open git-rev-list failed");
3186 my @revlist = map { chomp; $_ } <$fd>;
3187 close $fd or die_error
(undef, "Reading git-rev-list failed");
3188 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3190 <?xml version="1.0" encoding="utf-8"?>
3191 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3193 <title>$project $my_uri $my_url</title>
3194 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3195 <description>$project log</description>
3196 <language>en</language>
3199 for (my $i = 0; $i <= $#revlist; $i++) {
3200 my $commit = $revlist[$i];
3201 my %co = parse_commit
($commit);
3202 # we read 150, we always show 30 and the ones more recent than 48 hours
3203 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3206 my %cd = parse_date
($co{'committer_epoch'});
3207 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts,
3208 $co{'parent'}, $co{'id'}
3210 my @difftree = map { chomp; $_ } <$fd>;
3215 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3217 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3218 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3219 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3220 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3221 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3222 "<content:encoded>" .
3224 my $comment = $co{'comment'};
3225 foreach my $line (@
$comment) {
3226 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
3227 print "$line<br/>\n";
3230 foreach my $line (@difftree) {
3231 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3234 my $file = validate_input
(unquote
($7));
3235 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
3236 print "$file<br/>\n";
3239 "</content:encoded>\n" .
3242 print "</channel></rss>";
3246 my @list = git_get_projects_list
();
3248 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3250 <?xml version="1.0" encoding="utf-8"?>
3251 <opml version="1.0">
3253 <title>$site_name Git OPML Export</title>
3256 <outline text="git RSS feeds">
3259 foreach my $pr (@list) {
3261 my $head = git_get_head_hash
($proj{'path'});
3262 if (!defined $head) {
3265 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
3266 my %co = parse_commit
($head);
3271 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3272 my $rss = "$my_url?p=$proj{'path'};a=rss";
3273 my $html = "$my_url?p=$proj{'path'};a=summary";
3274 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";