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.
70 # feature => {'sub' => feature-sub, 'override' => allow-override, 'default' => [ default options...]
71 # if feature is overridable, feature-sub will be called with default options;
72 # return value indicates if to enable specified feature
75 'sub' => \
&feature_blame
,
80 'sub' => \
&feature_snapshot
,
82 # => [content-encoding, suffix, program]
83 'default' => ['x-gzip', 'gz', 'gzip']},
86 sub gitweb_check_feature
{
88 return undef unless exists $feature{$name};
89 my ($sub, $override, @defaults) = (
90 $feature{$name}{'sub'},
91 $feature{$name}{'override'},
92 @
{$feature{$name}{'default'}});
93 if (!$override) { return @defaults; }
94 return $sub->(@defaults);
97 # To enable system wide have in $GITWEB_CONFIG
98 # $feature{'blame'}{'default'} = [1];
99 # To have project specific config enable override in $GITWEB_CONFIG
100 # $feature{'blame'}{'override'} = 1;
101 # and in project config gitweb.blame = 0|1;
104 my ($val) = git_get_project_config
('blame', '--bool');
106 if ($val eq 'true') {
108 } elsif ($val eq 'false') {
115 # To disable system wide have in $GITWEB_CONFIG
116 # $feature{'snapshot'}{'default'} = [undef];
117 # To have project specific config enable override in $GITWEB_CONFIG
118 # $feature{'blame'}{'override'} = 1;
119 # and in project config gitweb.snapshot = none|gzip|bzip2
121 sub feature_snapshot
{
122 my ($ctype, $suffix, $command) = @_;
124 my ($val) = git_get_project_config
('snapshot');
126 if ($val eq 'gzip') {
127 return ('x-gzip', 'gz', 'gzip');
128 } elsif ($val eq 'bzip2') {
129 return ('x-bzip2', 'bz2', 'bzip2');
130 } elsif ($val eq 'none') {
134 return ($ctype, $suffix, $command);
137 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
138 require $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
140 # version of the core git binary
141 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
143 $projects_list ||= $projectroot;
145 # ======================================================================
146 # input validation and dispatch
147 our $action = $cgi->param('a');
148 if (defined $action) {
149 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
150 die_error
(undef, "Invalid action parameter");
154 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
155 if (defined $project) {
158 $project = undef unless $project;
160 if (defined $project) {
161 if (!validate_input
($project)) {
162 die_error
(undef, "Invalid project parameter");
164 if (!(-d
"$projectroot/$project")) {
165 die_error
(undef, "No such directory");
167 if (!(-e
"$projectroot/$project/HEAD")) {
168 die_error
(undef, "No such project");
170 $ENV{'GIT_DIR'} = "$projectroot/$project";
173 our $file_name = $cgi->param('f');
174 if (defined $file_name) {
175 if (!validate_input
($file_name)) {
176 die_error
(undef, "Invalid file parameter");
180 our $file_parent = $cgi->param('fp');
181 if (defined $file_parent) {
182 if (!validate_input
($file_parent)) {
183 die_error
(undef, "Invalid file parent parameter");
187 our $hash = $cgi->param('h');
189 if (!validate_input
($hash)) {
190 die_error
(undef, "Invalid hash parameter");
194 our $hash_parent = $cgi->param('hp');
195 if (defined $hash_parent) {
196 if (!validate_input
($hash_parent)) {
197 die_error
(undef, "Invalid hash parent parameter");
201 our $hash_base = $cgi->param('hb');
202 if (defined $hash_base) {
203 if (!validate_input
($hash_base)) {
204 die_error
(undef, "Invalid hash base parameter");
208 our $hash_parent_base = $cgi->param('hpb');
209 if (defined $hash_parent_base) {
210 if (!validate_input
($hash_parent_base)) {
211 die_error
(undef, "Invalid hash parent base parameter");
215 our $page = $cgi->param('pg');
217 if ($page =~ m/[^0-9]$/) {
218 die_error
(undef, "Invalid page parameter");
222 our $searchtext = $cgi->param('s');
223 if (defined $searchtext) {
224 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
225 die_error
(undef, "Invalid search parameter");
227 $searchtext = quotemeta $searchtext;
232 "blame" => \
&git_blame2
,
233 "blobdiff" => \
&git_blobdiff
,
234 "blobdiff_plain" => \
&git_blobdiff_plain
,
235 "blob" => \
&git_blob
,
236 "blob_plain" => \
&git_blob_plain
,
237 "commitdiff" => \
&git_commitdiff
,
238 "commitdiff_plain" => \
&git_commitdiff_plain
,
239 "commit" => \
&git_commit
,
240 "heads" => \
&git_heads
,
241 "history" => \
&git_history
,
244 "search" => \
&git_search
,
245 "shortlog" => \
&git_shortlog
,
246 "summary" => \
&git_summary
,
248 "tags" => \
&git_tags
,
249 "tree" => \
&git_tree
,
250 "snapshot" => \
&git_snapshot
,
251 # those below don't need $project
252 "opml" => \
&git_opml
,
253 "project_list" => \
&git_project_list
,
256 if (defined $project) {
257 $action ||= 'summary';
259 $action ||= 'project_list';
261 if (!defined($actions{$action})) {
262 die_error
(undef, "Unknown action");
264 $actions{$action}->();
267 ## ======================================================================
281 hash_parent_base
=> "hpb",
285 my %mapping = @mapping;
287 $params{"project"} ||= $project;
290 for (my $i = 0; $i < @mapping; $i += 2) {
291 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
292 if (defined $params{$name}) {
293 push @result, $symbol . "=" . esc_param
($params{$name});
296 return "$my_uri?" . join(';', @result);
300 ## ======================================================================
301 ## validation, quoting/unquoting and escaping
306 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
309 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
312 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
318 # quote unsafe chars, but keep the slash, even when it's not
319 # correct, but quoted slashes look too horrible in bookmarks
322 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
328 # replace invalid utf8 character with SUBSTITUTION sequence
331 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
332 $str = escapeHTML
($str);
333 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
337 # git may return quoted and escaped filenames
340 if ($str =~ m/^"(.*)"$/) {
342 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
347 # escape tabs (convert tabs to spaces)
351 while ((my $pos = index($line, "\t")) != -1) {
352 if (my $count = (8 - ($pos % 8))) {
353 my $spaces = ' ' x
$count;
354 $line =~ s/\t/$spaces/;
361 ## ----------------------------------------------------------------------
362 ## HTML aware string manipulation
367 my $add_len = shift || 10;
369 # allow only $len chars, but don't cut a word if it would fit in $add_len
370 # if it doesn't fit, cut it if it's still longer than the dots we would add
371 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
374 if (length($tail) > 4) {
376 $body =~ s/&[^;]*$//; # remove chopped character entities
381 ## ----------------------------------------------------------------------
382 ## functions returning short strings
384 # CSS class for given age value (in seconds)
388 if ($age < 60*60*2) {
390 } elsif ($age < 60*60*24*2) {
397 # convert age in seconds to "nn units ago" string
402 if ($age > 60*60*24*365*2) {
403 $age_str = (int $age/60/60/24/365);
404 $age_str .= " years ago";
405 } elsif ($age > 60*60*24*(365/12)*2) {
406 $age_str = int $age/60/60/24/(365/12);
407 $age_str .= " months ago";
408 } elsif ($age > 60*60*24*7*2) {
409 $age_str = int $age/60/60/24/7;
410 $age_str .= " weeks ago";
411 } elsif ($age > 60*60*24*2) {
412 $age_str = int $age/60/60/24;
413 $age_str .= " days ago";
414 } elsif ($age > 60*60*2) {
415 $age_str = int $age/60/60;
416 $age_str .= " hours ago";
417 } elsif ($age > 60*2) {
418 $age_str = int $age/60;
419 $age_str .= " min ago";
422 $age_str .= " sec ago";
424 $age_str .= " right now";
429 # convert file mode in octal to symbolic file mode string
431 my $mode = oct shift;
433 if (S_ISDIR
($mode & S_IFMT
)) {
435 } elsif (S_ISLNK
($mode)) {
437 } elsif (S_ISREG
($mode)) {
438 # git cares only about the executable bit
439 if ($mode & S_IXUSR
) {
449 # convert file mode in octal to file type string
453 if ($mode !~ m/^[0-7]+$/) {
459 if (S_ISDIR
($mode & S_IFMT
)) {
461 } elsif (S_ISLNK
($mode)) {
463 } elsif (S_ISREG
($mode)) {
470 ## ----------------------------------------------------------------------
471 ## functions returning short HTML fragments, or transforming HTML fragments
472 ## which don't beling to other sections
474 # format line of commit message or tag comment
475 sub format_log_line_html
{
478 $line = esc_html
($line);
479 $line =~ s/ / /g;
480 if ($line =~ m/([0-9a-fA-F]{40})/) {
482 if (git_get_type
($hash_text) eq "commit") {
484 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
485 -class => "text"}, $hash_text);
486 $line =~ s/$hash_text/$link/;
492 # format marker of refs pointing to given object
493 sub format_ref_marker
{
494 my ($refs, $id) = @_;
497 if (defined $refs->{$id}) {
498 foreach my $ref (@
{$refs->{$id}}) {
499 my ($type, $name) = qw();
500 # e.g. tags/v2.6.11 or heads/next
501 if ($ref =~ m!^(.*?)s?/(.*)$!) {
509 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
514 return ' <span class="refs">'. $markers . '</span>';
520 # format, perhaps shortened and with markers, title line
521 sub format_subject_html
{
522 my ($long, $short, $href, $extra) = @_;
523 $extra = '' unless defined($extra);
525 if (length($short) < length($long)) {
526 return $cgi->a({-href
=> $href, -class => "list subject",
528 esc_html
($short) . $extra);
530 return $cgi->a({-href
=> $href, -class => "list subject"},
531 esc_html
($long) . $extra);
535 sub format_diff_line
{
537 my $char = substr($line, 0, 1);
543 $diff_class = " add";
544 } elsif ($char eq "-") {
545 $diff_class = " rem";
546 } elsif ($char eq "@") {
547 $diff_class = " chunk_header";
548 } elsif ($char eq "\\") {
549 $diff_class = " incomplete";
551 $line = untabify
($line);
552 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
555 ## ----------------------------------------------------------------------
556 ## git utility subroutines, invoking git commands
558 # get HEAD ref of given project as hash
559 sub git_get_head_hash
{
561 my $oENV = $ENV{'GIT_DIR'};
563 $ENV{'GIT_DIR'} = "$projectroot/$project";
564 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
567 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
572 $ENV{'GIT_DIR'} = $oENV;
577 # get type of given object
581 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
588 sub git_get_project_config
{
589 my ($key, $type) = @_;
591 return unless ($key);
592 $key =~ s/^gitweb\.//;
593 return if ($key =~ m/\W/);
595 my @x = ($GIT, 'repo-config');
596 if (defined $type) { push @x, $type; }
598 push @x, "gitweb.$key";
604 # get hash of given path at given ref
605 sub git_get_hash_by_path
{
607 my $path = shift || return undef;
611 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
612 or die_error
(undef, "Open git-ls-tree failed");
614 close $fd or return undef;
616 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
617 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
621 # converts symbolic name to hash
624 return undef unless @params;
626 open my $fd, "-|", $GIT, "rev-parse", @params
628 my @hashes = map { chomp; $_ } <$fd>;
633 } elsif (scalar(@hashes) == 1) {
641 ## ......................................................................
642 ## git utility functions, directly accessing git repository
644 # assumes that PATH is not symref
645 sub git_get_hash_by_ref
{
648 open my $fd, "$projectroot/$path" or return undef;
652 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
657 sub git_get_project_description
{
660 open my $fd, "$projectroot/$path/description" or return undef;
667 sub git_get_project_url_list
{
670 open my $fd, "$projectroot/$path/cloneurl" or return undef;
671 my @git_project_url_list = map { chomp; $_ } <$fd>;
674 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
677 sub git_get_projects_list
{
680 if (-d
$projects_list) {
681 # search in directory
682 my $dir = $projects_list;
683 opendir my ($dh), $dir or return undef;
684 while (my $dir = readdir($dh)) {
685 if (-e
"$projectroot/$dir/HEAD") {
693 } elsif (-f
$projects_list) {
694 # read from file(url-encoded):
695 # 'git%2Fgit.git Linus+Torvalds'
696 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
697 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
698 open my ($fd), $projects_list or return undef;
699 while (my $line = <$fd>) {
701 my ($path, $owner) = split ' ', $line;
702 $path = unescape
($path);
703 $owner = unescape
($owner);
704 if (!defined $path) {
707 if (-e
"$projectroot/$path/HEAD") {
710 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
717 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
721 sub git_get_project_owner
{
725 return undef unless $project;
727 # read from file (url-encoded):
728 # 'git%2Fgit.git Linus+Torvalds'
729 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
730 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
731 if (-f
$projects_list) {
732 open (my $fd , $projects_list);
733 while (my $line = <$fd>) {
735 my ($pr, $ow) = split ' ', $line;
738 if ($pr eq $project) {
739 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
745 if (!defined $owner) {
746 $owner = get_file_owner
("$projectroot/$project");
752 sub git_get_references
{
753 my $type = shift || "";
756 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
757 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
758 if (-f
"$projectroot/$project/info/refs") {
759 open $fd, "$projectroot/$project/info/refs"
762 open $fd, "-|", $GIT, "ls-remote", "."
766 while (my $line = <$fd>) {
768 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
769 if (defined $refs{$1}) {
770 push @
{$refs{$1}}, $2;
780 sub git_get_following_references
{
781 my $hash = shift || return undef;
783 my $base = shift || $hash_base || "HEAD";
785 my $refs = git_get_references
($type);
786 open my $fd, "-|", $GIT, "rev-list", $base
788 my @commits = map { chomp; $_ } <$fd>;
795 foreach my $commit (@commits) {
796 foreach my $ref (@
{$refs->{$commit}}) {
798 push @reflist, $lastref;
800 if ($commit eq $hash) {
805 return wantarray ?
@reflist : $lastref;
808 sub git_get_preceding_references
{
809 my $hash = shift || return undef;
812 my $refs = git_get_references
($type);
813 open my $fd, "-|", $GIT, "rev-list", $hash
815 my @commits = map { chomp; $_ } <$fd>;
821 foreach my $commit (@commits) {
822 foreach my $ref (@
{$refs->{$commit}}) {
823 return $ref unless wantarray;
831 sub git_get_rev_name_tags
{
832 my $hash = shift || return undef;
834 open my $fd, "-|", $GIT, "name-rev", "--tags", $hash
836 my $name_rev = <$fd>;
839 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
842 # catches also '$hash undefined' output
847 ## ----------------------------------------------------------------------
848 ## parse to hash functions
852 my $tz = shift || "-0000";
855 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
856 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
857 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
858 $date{'hour'} = $hour;
859 $date{'minute'} = $min;
860 $date{'mday'} = $mday;
861 $date{'day'} = $days[$wday];
862 $date{'month'} = $months[$mon];
863 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
864 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
865 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
866 $mday, $months[$mon], $hour ,$min;
868 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
869 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
870 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
871 $date{'hour_local'} = $hour;
872 $date{'minute_local'} = $min;
873 $date{'tz_local'} = $tz;
882 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
883 $tag{'id'} = $tag_id;
884 while (my $line = <$fd>) {
886 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
888 } elsif ($line =~ m/^type (.+)$/) {
890 } elsif ($line =~ m/^tag (.+)$/) {
892 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
896 } elsif ($line =~ m/--BEGIN/) {
897 push @comment, $line;
899 } elsif ($line eq "") {
903 push @comment, <$fd>;
904 $tag{'comment'} = \
@comment;
906 if (!defined $tag{'name'}) {
913 my $commit_id = shift;
914 my $commit_text = shift;
919 if (defined $commit_text) {
920 @commit_lines = @
$commit_text;
923 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id
925 @commit_lines = split '\n', <$fd>;
930 my $header = shift @commit_lines;
931 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
934 ($co{'id'}, my @parents) = split ' ', $header;
935 $co{'parents'} = \
@parents;
936 $co{'parent'} = $parents[0];
937 while (my $line = shift @commit_lines) {
938 last if $line eq "\n";
939 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
941 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
943 $co{'author_epoch'} = $2;
944 $co{'author_tz'} = $3;
945 if ($co{'author'} =~ m/^([^<]+) </) {
946 $co{'author_name'} = $1;
948 $co{'author_name'} = $co{'author'};
950 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
951 $co{'committer'} = $1;
952 $co{'committer_epoch'} = $2;
953 $co{'committer_tz'} = $3;
954 $co{'committer_name'} = $co{'committer'};
955 $co{'committer_name'} =~ s/ <.*//;
958 if (!defined $co{'tree'}) {
962 foreach my $title (@commit_lines) {
965 $co{'title'} = chop_str
($title, 80, 5);
966 # remove leading stuff of merges to make the interesting part visible
967 if (length($title) > 50) {
968 $title =~ s/^Automatic //;
969 $title =~ s/^merge (of|with) /Merge ... /i;
970 if (length($title) > 50) {
971 $title =~ s/(http|rsync):\/\///;
973 if (length($title) > 50) {
974 $title =~ s/(master|www|rsync)\.//;
976 if (length($title) > 50) {
977 $title =~ s/kernel.org:?//;
979 if (length($title) > 50) {
980 $title =~ s/\/pub\/scm//;
983 $co{'title_short'} = chop_str
($title, 50, 5);
987 # remove added spaces
988 foreach my $line (@commit_lines) {
991 $co{'comment'} = \
@commit_lines;
993 my $age = time - $co{'committer_epoch'};
995 $co{'age_string'} = age_string
($age);
996 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
997 if ($age > 60*60*24*7*2) {
998 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
999 $co{'age_string_age'} = $co{'age_string'};
1001 $co{'age_string_date'} = $co{'age_string'};
1002 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1007 # parse ref from ref_file, given by ref_id, with given type
1009 my $ref_file = shift;
1011 my $type = shift || git_get_type
($ref_id);
1014 $ref_item{'type'} = $type;
1015 $ref_item{'id'} = $ref_id;
1016 $ref_item{'epoch'} = 0;
1017 $ref_item{'age'} = "unknown";
1018 if ($type eq "tag") {
1019 my %tag = parse_tag
($ref_id);
1020 $ref_item{'comment'} = $tag{'comment'};
1021 if ($tag{'type'} eq "commit") {
1022 my %co = parse_commit
($tag{'object'});
1023 $ref_item{'epoch'} = $co{'committer_epoch'};
1024 $ref_item{'age'} = $co{'age_string'};
1025 } elsif (defined($tag{'epoch'})) {
1026 my $age = time - $tag{'epoch'};
1027 $ref_item{'epoch'} = $tag{'epoch'};
1028 $ref_item{'age'} = age_string
($age);
1030 $ref_item{'reftype'} = $tag{'type'};
1031 $ref_item{'name'} = $tag{'name'};
1032 $ref_item{'refid'} = $tag{'object'};
1033 } elsif ($type eq "commit"){
1034 my %co = parse_commit
($ref_id);
1035 $ref_item{'reftype'} = "commit";
1036 $ref_item{'name'} = $ref_file;
1037 $ref_item{'title'} = $co{'title'};
1038 $ref_item{'refid'} = $ref_id;
1039 $ref_item{'epoch'} = $co{'committer_epoch'};
1040 $ref_item{'age'} = $co{'age_string'};
1042 $ref_item{'reftype'} = $type;
1043 $ref_item{'name'} = $ref_file;
1044 $ref_item{'refid'} = $ref_id;
1050 # parse line of git-diff-tree "raw" output
1051 sub parse_difftree_raw_line
{
1055 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1056 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1057 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1058 $res{'from_mode'} = $1;
1059 $res{'to_mode'} = $2;
1060 $res{'from_id'} = $3;
1062 $res{'status'} = $5;
1063 $res{'similarity'} = $6;
1064 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1065 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1067 $res{'file'} = unquote
($7);
1070 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1071 #elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1072 # $res{'commit'} = $1;
1075 return wantarray ?
%res : \
%res;
1078 ## ......................................................................
1079 ## parse to array of hashes functions
1081 sub git_get_refs_list
{
1082 my $ref_dir = shift;
1086 my $pfxlen = length("$projectroot/$project/$ref_dir");
1087 File
::Find
::find
(sub {
1090 push @refs, substr($File::Find
::name
, $pfxlen + 1);
1092 }, "$projectroot/$project/$ref_dir");
1094 foreach my $ref_file (@refs) {
1095 my $ref_id = git_get_hash_by_ref
("$project/$ref_dir/$ref_file");
1096 my $type = git_get_type
($ref_id) || next;
1097 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1099 push @reflist, \
%ref_item;
1102 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1106 ## ----------------------------------------------------------------------
1107 ## filesystem-related functions
1109 sub get_file_owner
{
1112 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1113 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1114 if (!defined $gcos) {
1118 $owner =~ s/[,;].*$//;
1119 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
1122 ## ......................................................................
1123 ## mimetype related functions
1125 sub mimetype_guess_file
{
1126 my $filename = shift;
1127 my $mimemap = shift;
1128 -r
$mimemap or return undef;
1131 open(MIME
, $mimemap) or return undef;
1133 next if m/^#/; # skip comments
1134 my ($mime, $exts) = split(/\t+/);
1135 if (defined $exts) {
1136 my @exts = split(/\s+/, $exts);
1137 foreach my $ext (@exts) {
1138 $mimemap{$ext} = $mime;
1144 $filename =~ /\.(.*?)$/;
1145 return $mimemap{$1};
1148 sub mimetype_guess
{
1149 my $filename = shift;
1151 $filename =~ /\./ or return undef;
1153 if ($mimetypes_file) {
1154 my $file = $mimetypes_file;
1155 if ($file !~ m!^/!) { # if it is relative path
1156 # it is relative to project
1157 $file = "$projectroot/$project/$file";
1159 $mime = mimetype_guess_file
($filename, $file);
1161 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1167 my $filename = shift;
1170 my $mime = mimetype_guess
($filename);
1171 $mime and return $mime;
1175 return $default_blob_plain_mimetype unless $fd;
1178 return 'text/plain' .
1179 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1180 } elsif (! $filename) {
1181 return 'application/octet-stream';
1182 } elsif ($filename =~ m/\.png$/i) {
1184 } elsif ($filename =~ m/\.gif$/i) {
1186 } elsif ($filename =~ m/\.jpe?g$/i) {
1187 return 'image/jpeg';
1189 return 'application/octet-stream';
1193 ## ======================================================================
1194 ## functions printing HTML: header, footer, error page
1196 sub git_header_html
{
1197 my $status = shift || "200 OK";
1198 my $expires = shift;
1200 my $title = "$site_name git";
1201 if (defined $project) {
1202 $title .= " - $project";
1203 if (defined $action) {
1204 $title .= "/$action";
1205 if (defined $file_name) {
1206 $title .= " - $file_name";
1207 if ($action eq "tree" && $file_name !~ m
|/$|) {
1214 # require explicit support from the UA if we are to send the page as
1215 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1216 # we have to do this because MSIE sometimes globs '*/*', pretending to
1217 # support xhtml+xml but choking when it gets what it asked for.
1218 if (defined $cgi->http('HTTP_ACCEPT') &&
1219 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1220 $cgi->Accept('application/xhtml+xml') != 0) {
1221 $content_type = 'application/xhtml+xml';
1223 $content_type = 'text/html';
1225 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1226 -status
=> $status, -expires
=> $expires);
1228 <?xml version="1.0" encoding="utf-8"?>
1229 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1230 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1231 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1232 <!-- git core binaries version $git_version -->
1234 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1235 <meta name="generator" content="gitweb/$version git/$git_version"/>
1236 <meta name="robots" content="index, nofollow"/>
1237 <title>$title</title>
1238 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1240 if (defined $project) {
1241 printf('<link rel="alternate" title="%s log" '.
1242 'href="%s" type="application/rss+xml"/>'."\n",
1243 esc_param
($project), href
(action
=>"rss"));
1248 "<div class=\"page_header\">\n" .
1249 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1250 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1252 print $cgi->a({-href
=> esc_param
($home_link)}, $home_link_str) . " / ";
1253 if (defined $project) {
1254 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1255 if (defined $action) {
1259 if (!defined $searchtext) {
1263 if (defined $hash_base) {
1264 $search_hash = $hash_base;
1265 } elsif (defined $hash) {
1266 $search_hash = $hash;
1268 $search_hash = "HEAD";
1270 $cgi->param("a", "search");
1271 $cgi->param("h", $search_hash);
1272 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1273 "<div class=\"search\">\n" .
1274 $cgi->hidden(-name
=> "p") . "\n" .
1275 $cgi->hidden(-name
=> "a") . "\n" .
1276 $cgi->hidden(-name
=> "h") . "\n" .
1277 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1279 $cgi->end_form() . "\n";
1284 sub git_footer_html
{
1285 print "<div class=\"page_footer\">\n";
1286 if (defined $project) {
1287 my $descr = git_get_project_description
($project);
1288 if (defined $descr) {
1289 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1291 print $cgi->a({-href
=> href
(action
=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1293 print $cgi->a({-href
=> href
(action
=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1301 my $status = shift || "403 Forbidden";
1302 my $error = shift || "Malformed query, file missing or permission denied";
1304 git_header_html
($status);
1306 <div class="page_body">
1316 ## ----------------------------------------------------------------------
1317 ## functions printing or outputting HTML: navigation
1319 sub git_print_page_nav
{
1320 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1321 $extra = '' if !defined $extra; # pager or formats
1323 my @navs = qw(summary shortlog log commit commitdiff tree);
1325 @navs = grep { $_ ne $suppress } @navs;
1328 my %arg = map { $_ => {action
=>$_} } @navs;
1329 if (defined $head) {
1330 for (qw(commit commitdiff)) {
1331 $arg{$_}{hash
} = $head;
1333 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1334 for (qw(shortlog log)) {
1335 $arg{$_}{hash
} = $head;
1339 $arg{tree
}{hash
} = $treehead if defined $treehead;
1340 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1342 print "<div class=\"page_nav\">\n" .
1344 map { $_ eq $current ?
1345 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1347 print "<br/>\n$extra<br/>\n" .
1351 sub format_paging_nav
{
1352 my ($action, $hash, $head, $page, $nrevs) = @_;
1356 if ($hash ne $head || $page) {
1357 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1359 $paging_nav .= "HEAD";
1363 $paging_nav .= " ⋅ " .
1364 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1365 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1367 $paging_nav .= " ⋅ prev";
1370 if ($nrevs >= (100 * ($page+1)-1)) {
1371 $paging_nav .= " ⋅ " .
1372 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1373 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1375 $paging_nav .= " ⋅ next";
1381 ## ......................................................................
1382 ## functions printing or outputting HTML: div
1384 sub git_print_header_div
{
1385 my ($action, $title, $hash, $hash_base) = @_;
1388 $args{action
} = $action;
1389 $args{hash
} = $hash if $hash;
1390 $args{hash_base
} = $hash_base if $hash_base;
1392 print "<div class=\"header\">\n" .
1393 $cgi->a({-href
=> href
(%args), -class => "title"},
1394 $title ?
$title : $action) .
1398 sub git_print_page_path
{
1403 if (!defined $name) {
1404 print "<div class=\"page_path\">/</div>\n";
1405 } elsif (defined $type && $type eq 'blob') {
1406 print "<div class=\"page_path\">";
1408 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1412 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name)},
1415 print "<br/></div>\n";
1417 print "<div class=\"page_path\">" . esc_html
($name) . "<br/></div>\n";
1424 # remove leading empty lines
1425 while (defined $log->[0] && $log->[0] eq "") {
1432 foreach my $line (@
$log) {
1433 # print only one empty line
1434 # do not print empty line after signoff
1436 next if ($empty || $signoff);
1441 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1443 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1446 print format_log_line_html
($line) . "<br/>\n";
1451 sub git_print_simplified_log
{
1453 my $remove_title = shift;
1455 shift @
$log if $remove_title;
1456 # remove leading empty lines
1457 while (defined $log->[0] && $log->[0] eq "") {
1461 # simplify and print log
1463 foreach my $line (@
$log) {
1464 # remove signoff lines
1465 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1468 # print only one empty line
1475 print format_log_line_html
($line) . "<br/>\n";
1477 # end with single empty line
1478 print "<br/>\n" unless $empty;
1481 ## ......................................................................
1482 ## functions printing large fragments of HTML
1484 sub git_difftree_body
{
1485 my ($difftree, $hash, $parent) = @_;
1487 print "<div class=\"list_head\">\n";
1488 if ($#{$difftree} > 10) {
1489 print(($#{$difftree} + 1) . " files changed:\n");
1493 print "<table class=\"diff_tree\">\n";
1495 foreach my $line (@
{$difftree}) {
1496 my %diff = parse_difftree_raw_line
($line);
1499 print "<tr class=\"dark\">\n";
1501 print "<tr class=\"light\">\n";
1505 my ($to_mode_oct, $to_mode_str, $to_file_type);
1506 my ($from_mode_oct, $from_mode_str, $from_file_type);
1507 if ($diff{'to_mode'} ne ('0' x
6)) {
1508 $to_mode_oct = oct $diff{'to_mode'};
1509 if (S_ISREG
($to_mode_oct)) { # only for regular file
1510 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1512 $to_file_type = file_type
($diff{'to_mode'});
1514 if ($diff{'from_mode'} ne ('0' x
6)) {
1515 $from_mode_oct = oct $diff{'from_mode'};
1516 if (S_ISREG
($to_mode_oct)) { # only for regular file
1517 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1519 $from_file_type = file_type
($diff{'from_mode'});
1522 if ($diff{'status'} eq "A") { # created
1523 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1524 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1525 $mode_chng .= "]</span>";
1527 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1528 hash_base
=>$hash, file_name
=>$diff{'file'}),
1529 -class => "list"}, esc_html
($diff{'file'})) .
1531 "<td>$mode_chng</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'})},
1538 } elsif ($diff{'status'} eq "D") { # deleted
1539 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1541 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1542 hash_base
=>$parent, file_name
=>$diff{'file'}),
1543 -class => "list"}, esc_html
($diff{'file'})) .
1545 "<td>$mode_chng</td>\n" .
1546 "<td class=\"link\">" .
1547 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1548 hash_base
=>$parent, file_name
=>$diff{'file'})},
1551 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1552 file_name
=>$diff{'file'})},\
1556 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1557 my $mode_chnge = "";
1558 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1559 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1560 if ($from_file_type != $to_file_type) {
1561 $mode_chnge .= " from $from_file_type to $to_file_type";
1563 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1564 if ($from_mode_str && $to_mode_str) {
1565 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1566 } elsif ($to_mode_str) {
1567 $mode_chnge .= " mode: $to_mode_str";
1570 $mode_chnge .= "]</span>\n";
1573 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1574 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1575 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1576 hash_base
=>$hash, hash_parent_base
=>$parent,
1577 file_name
=>$diff{'file'}),
1578 -class => "list"}, esc_html
($diff{'file'}));
1579 } else { # only mode changed
1580 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1581 hash_base
=>$hash, file_name
=>$diff{'file'}),
1582 -class => "list"}, esc_html
($diff{'file'}));
1585 "<td>$mode_chnge</td>\n" .
1586 "<td class=\"link\">" .
1587 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1588 hash_base
=>$hash, file_name
=>$diff{'file'})},
1590 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1592 $cgi->a({-href
=> href
(action
=>"blobdiff",
1593 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1594 hash_base
=>$hash, hash_parent_base
=>$parent,
1595 file_name
=>$diff{'file'})},
1599 $cgi->a({-href
=> href
(action
=>"history",
1600 hash_base
=>$hash, file_name
=>$diff{'file'})},
1604 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1605 my %status_name = ('R' => 'moved', 'C' => 'copied');
1606 my $nstatus = $status_name{$diff{'status'}};
1608 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1609 # mode also for directories, so we cannot use $to_mode_str
1610 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1613 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1614 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1615 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1616 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1617 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1618 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1619 -class => "list"}, esc_html
($diff{'from_file'})) .
1620 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1621 "<td class=\"link\">" .
1622 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1623 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'})},
1625 if ($diff{'to_id'} ne $diff{'from_id'}) {
1627 $cgi->a({-href
=> href
(action
=>"blobdiff",
1628 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1629 hash_base
=>$hash, hash_parent_base
=>$parent,
1630 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1635 } # we should not encounter Unmerged (U) or Unknown (X) status
1641 sub git_patchset_body
{
1642 my ($fd, $difftree, $hash, $hash_parent) = @_;
1646 my $patch_found = 0;
1649 print "<div class=\"patchset\">\n";
1652 while (my $patch_line @
$fd>) {
1655 if ($patch_line =~ m/^diff /) { # "git diff" header
1656 # beginning of patch (in patchset)
1658 # close previous patch
1659 print "</div>\n"; # class="patch"
1661 # first patch in patchset
1664 print "<div class=\"patch\">\n";
1666 if (ref($difftree->[$patch_idx]) eq "HASH") {
1667 $diffinfo = $difftree->[$patch_idx];
1669 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1673 # for now, no extended header, hence we skip empty patches
1674 # companion to next LINE if $in_header;
1675 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1680 if ($diffinfo->{'status'} eq "A") { # added
1681 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1682 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1683 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1684 $diffinfo->{'to_id'}) . "(new)" .
1685 "</div>\n"; # class="diff_info"
1687 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1688 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
1689 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1690 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1691 $diffinfo->{'from_id'}) . "(deleted)" .
1692 "</div>\n"; # class="diff_info"
1694 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1695 $diffinfo->{'status'} eq "C" || # copied
1696 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1697 print "<div class=\"diff_info\">" .
1698 file_type
($diffinfo->{'from_mode'}) . ":" .
1699 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1700 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
1701 $diffinfo->{'from_id'}) .
1703 file_type
($diffinfo->{'to_mode'}) . ":" .
1704 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1705 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
1706 $diffinfo->{'to_id'});
1707 print "</div>\n"; # class="diff_info"
1709 } else { # modified, mode changed, ...
1710 print "<div class=\"diff_info\">" .
1711 file_type
($diffinfo->{'from_mode'}) . ":" .
1712 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1713 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1714 $diffinfo->{'from_id'}) .
1716 file_type
($diffinfo->{'to_mode'}) . ":" .
1717 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1718 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1719 $diffinfo->{'to_id'});
1720 print "</div>\n"; # class="diff_info"
1723 #print "<div class=\"diff extended_header\">\n";
1726 } # start of patch in patchset
1729 if ($in_header && $patch_line =~ m/^---/) {
1730 #print "</div>\n"; # class="diff extended_header"
1733 my $file = $diffinfo->{'from_file'};
1734 $file ||= $diffinfo->{'file'};
1735 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1736 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
1737 -class => "list"}, esc_html
($file));
1738 $patch_line =~ s
|a
/.*$|a/$file|g
;
1739 print "<div class=\"diff from_file\">$patch_line</div>\n";
1741 $patch_line = <$fd>;
1744 #$patch_line =~ m/^+++/;
1745 $file = $diffinfo->{'to_file'};
1746 $file ||= $diffinfo->{'file'};
1747 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1748 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
1749 -class => "list"}, esc_html
($file));
1750 $patch_line =~ s
|b
/.*|b/$file|g
;
1751 print "<div class=\"diff to_file\">$patch_line</div>\n";
1755 next LINE
if $in_header;
1757 print format_diff_line
($patch_line);
1759 print "</div>\n" if $patch_found; # class="patch"
1761 print "</div>\n"; # class="patchset"
1764 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1766 sub git_shortlog_body
{
1767 # uses global variable $project
1768 my ($revlist, $from, $to, $refs, $extra) = @_;
1770 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
1771 my $have_snapshot = (defined $ctype && defined $suffix);
1773 $from = 0 unless defined $from;
1774 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1776 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1778 for (my $i = $from; $i <= $to; $i++) {
1779 my $commit = $revlist->[$i];
1780 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1781 my $ref = format_ref_marker
($refs, $commit);
1782 my %co = parse_commit
($commit);
1784 print "<tr class=\"dark\">\n";
1786 print "<tr class=\"light\">\n";
1789 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1790 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1791 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1793 print format_subject_html
($co{'title'}, $co{'title_short'},
1794 href
(action
=>"commit", hash
=>$commit), $ref);
1796 "<td class=\"link\">" .
1797 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1798 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
1799 if ($have_snapshot) {
1800 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
1805 if (defined $extra) {
1807 "<td colspan=\"4\">$extra</td>\n" .
1813 sub git_history_body
{
1814 # Warning: assumes constant type (blob or tree) during history
1815 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1817 print "<table class=\"history\" cellspacing=\"0\">\n";
1819 while (my $line = <$fd>) {
1820 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1825 my %co = parse_commit
($commit);
1830 my $ref = format_ref_marker
($refs, $commit);
1833 print "<tr class=\"dark\">\n";
1835 print "<tr class=\"light\">\n";
1838 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1839 # shortlog uses chop_str($co{'author_name'}, 10)
1840 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1842 # originally git_history used chop_str($co{'title'}, 50)
1843 print format_subject_html
($co{'title'}, $co{'title_short'},
1844 href
(action
=>"commit", hash
=>$commit), $ref);
1846 "<td class=\"link\">" .
1847 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1848 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
1849 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype);
1851 if ($ftype eq 'blob') {
1852 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
1853 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
1854 if (defined $blob_current && defined $blob_parent &&
1855 $blob_current ne $blob_parent) {
1857 $cgi->a({-href
=> href
(action
=>"blobdiff",
1858 hash
=>$blob_current, hash_parent
=>$blob_parent,
1859 hash_base
=>$hash_base, hash_parent_base
=>$commit,
1860 file_name
=>$file_name)},
1867 if (defined $extra) {
1869 "<td colspan=\"4\">$extra</td>\n" .
1876 # uses global variable $project
1877 my ($taglist, $from, $to, $extra) = @_;
1878 $from = 0 unless defined $from;
1879 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1881 print "<table class=\"tags\" cellspacing=\"0\">\n";
1883 for (my $i = $from; $i <= $to; $i++) {
1884 my $entry = $taglist->[$i];
1886 my $comment_lines = $tag{'comment'};
1887 my $comment = shift @
$comment_lines;
1889 if (defined $comment) {
1890 $comment_short = chop_str
($comment, 30, 5);
1893 print "<tr class=\"dark\">\n";
1895 print "<tr class=\"light\">\n";
1898 print "<td><i>$tag{'age'}</i></td>\n" .
1900 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
1901 -class => "list name"}, esc_html
($tag{'name'})) .
1904 if (defined $comment) {
1905 print format_subject_html
($comment, $comment_short,
1906 href
(action
=>"tag", hash
=>$tag{'id'}));
1909 "<td class=\"selflink\">";
1910 if ($tag{'type'} eq "tag") {
1911 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
1916 "<td class=\"link\">" . " | " .
1917 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
1918 if ($tag{'reftype'} eq "commit") {
1919 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
1920 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
1921 } elsif ($tag{'reftype'} eq "blob") {
1922 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
1927 if (defined $extra) {
1929 "<td colspan=\"5\">$extra</td>\n" .
1935 sub git_heads_body
{
1936 # uses global variable $project
1937 my ($taglist, $head, $from, $to, $extra) = @_;
1938 $from = 0 unless defined $from;
1939 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1941 print "<table class=\"heads\" cellspacing=\"0\">\n";
1943 for (my $i = $from; $i <= $to; $i++) {
1944 my $entry = $taglist->[$i];
1946 my $curr = $tag{'id'} eq $head;
1948 print "<tr class=\"dark\">\n";
1950 print "<tr class=\"light\">\n";
1953 print "<td><i>$tag{'age'}</i></td>\n" .
1954 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1955 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
1956 -class => "list name"},esc_html
($tag{'name'})) .
1958 "<td class=\"link\">" .
1959 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
1960 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") .
1964 if (defined $extra) {
1966 "<td colspan=\"3\">$extra</td>\n" .
1972 ## ======================================================================
1973 ## ======================================================================
1976 sub git_project_list
{
1977 my $order = $cgi->param('o');
1978 if (defined $order && $order !~ m/project|descr|owner|age/) {
1979 die_error
(undef, "Unknown order parameter");
1982 my @list = git_get_projects_list
();
1985 die_error
(undef, "No projects found");
1987 foreach my $pr (@list) {
1988 my $head = git_get_head_hash
($pr->{'path'});
1989 if (!defined $head) {
1992 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1993 my %co = parse_commit
($head);
1997 $pr->{'commit'} = \
%co;
1998 if (!defined $pr->{'descr'}) {
1999 my $descr = git_get_project_description
($pr->{'path'}) || "";
2000 $pr->{'descr'} = chop_str
($descr, 25, 5);
2002 if (!defined $pr->{'owner'}) {
2003 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2005 push @projects, $pr;
2009 if (-f
$home_text) {
2010 print "<div class=\"index_include\">\n";
2011 open (my $fd, $home_text);
2016 print "<table class=\"project_list\">\n" .
2018 $order ||= "project";
2019 if ($order eq "project") {
2020 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2021 print "<th>Project</th>\n";
2024 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
2025 -class => "header"}, "Project") .
2028 if ($order eq "descr") {
2029 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2030 print "<th>Description</th>\n";
2033 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
2034 -class => "header"}, "Description") .
2037 if ($order eq "owner") {
2038 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2039 print "<th>Owner</th>\n";
2042 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
2043 -class => "header"}, "Owner") .
2046 if ($order eq "age") {
2047 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2048 print "<th>Last Change</th>\n";
2051 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
2052 -class => "header"}, "Last Change") .
2055 print "<th></th>\n" .
2058 foreach my $pr (@projects) {
2060 print "<tr class=\"dark\">\n";
2062 print "<tr class=\"light\">\n";
2065 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2066 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2067 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2068 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2069 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2070 $pr->{'commit'}{'age_string'} . "</td>\n" .
2071 "<td class=\"link\">" .
2072 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2073 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2074 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") .
2083 my $descr = git_get_project_description
($project) || "none";
2084 my $head = git_get_head_hash
($project);
2085 my %co = parse_commit
($head);
2086 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2088 my $owner = git_get_project_owner
($project);
2090 my $refs = git_get_references
();
2092 git_print_page_nav
('summary','', $head);
2094 print "<div class=\"title\"> </div>\n";
2095 print "<table cellspacing=\"0\">\n" .
2096 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2097 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2098 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2099 # use per project git URL list in $projectroot/$project/cloneurl
2100 # or make project git URL from git base URL and project name
2101 my $url_tag = "URL";
2102 my @url_list = git_get_project_url_list
($project);
2103 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2104 foreach my $git_url (@url_list) {
2105 next unless $git_url;
2106 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2111 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash
($project)
2112 or die_error
(undef, "Open git-rev-list failed");
2113 my @revlist = map { chomp; $_ } <$fd>;
2115 git_print_header_div
('shortlog');
2116 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2117 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2119 my $taglist = git_get_refs_list
("refs/tags");
2120 if (defined @
$taglist) {
2121 git_print_header_div
('tags');
2122 git_tags_body
($taglist, 0, 15,
2123 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2126 my $headlist = git_get_refs_list
("refs/heads");
2127 if (defined @
$headlist) {
2128 git_print_header_div
('heads');
2129 git_heads_body
($headlist, $head, 0, 15,
2130 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2137 my $head = git_get_head_hash
($project);
2139 git_print_page_nav
('','', $head,undef,$head);
2140 my %tag = parse_tag
($hash);
2141 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2142 print "<div class=\"title_text\">\n" .
2143 "<table cellspacing=\"0\">\n" .
2145 "<td>object</td>\n" .
2146 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2147 $tag{'object'}) . "</td>\n" .
2148 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2149 $tag{'type'}) . "</td>\n" .
2151 if (defined($tag{'author'})) {
2152 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2153 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2154 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2155 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2158 print "</table>\n\n" .
2160 print "<div class=\"page_body\">";
2161 my $comment = $tag{'comment'};
2162 foreach my $line (@
$comment) {
2163 print esc_html
($line) . "<br/>\n";
2173 if (!gitweb_check_feature
('blame')) {
2174 die_error
('403 Permission denied', "Permission denied");
2176 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2177 $hash_base ||= git_get_head_hash
($project);
2178 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2179 my %co = parse_commit
($hash_base)
2180 or die_error
(undef, "Reading commit failed");
2181 if (!defined $hash) {
2182 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2183 or die_error
(undef, "Error looking up file");
2185 $ftype = git_get_type
($hash);
2186 if ($ftype !~ "blob") {
2187 die_error
("400 Bad Request", "Object is not a blob");
2189 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
2190 or die_error
(undef, "Open git-blame failed");
2193 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2196 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2198 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2199 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2200 git_print_page_path
($file_name, $ftype, $hash_base);
2201 my @rev_color = (qw(light2 dark2));
2202 my $num_colors = scalar(@rev_color);
2203 my $current_color = 0;
2206 <div class="page_body">
2207 <table class="blame">
2208 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2211 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2213 my $rev = substr($full_rev, 0, 8);
2217 if (!defined $last_rev) {
2218 $last_rev = $full_rev;
2219 } elsif ($last_rev ne $full_rev) {
2220 $last_rev = $full_rev;
2221 $current_color = ++$current_color % $num_colors;
2223 print "<tr class=\"$rev_color[$current_color]\">\n";
2224 print "<td class=\"sha1\">" .
2225 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)},
2226 esc_html
($rev)) . "</td>\n";
2227 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2228 esc_html
($lineno) . "</a></td>\n";
2229 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2235 or print "Reading blob failed\n";
2242 if (!gitweb_check_feature
('blame')) {
2243 die_error
('403 Permission denied', "Permission denied");
2245 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2246 $hash_base ||= git_get_head_hash
($project);
2247 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2248 my %co = parse_commit
($hash_base)
2249 or die_error
(undef, "Reading commit failed");
2250 if (!defined $hash) {
2251 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2252 or die_error
(undef, "Error lookup file");
2254 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2255 or die_error
(undef, "Open git-annotate failed");
2258 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2261 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2263 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2264 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2265 git_print_page_path
($file_name, 'blob', $hash_base);
2266 print "<div class=\"page_body\">\n";
2268 <table class="blame">
2277 my @line_class = (qw(light dark));
2278 my $line_class_len = scalar (@line_class);
2279 my $line_class_num = $#line_class;
2280 while (my $line = <$fd>) {
2292 $line_class_num = ($line_class_num + 1) % $line_class_len;
2294 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
2301 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2304 $short_rev = substr ($long_rev, 0, 8);
2305 $age = time () - $time;
2306 $age_str = age_string
($age);
2307 $age_str =~ s/ / /g;
2308 $age_class = age_class
($age);
2309 $author = esc_html
($author);
2310 $author =~ s/ / /g;
2312 $data = untabify
($data);
2313 $data = esc_html
($data);
2316 <tr class="$line_class[$line_class_num]">
2317 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2318 <td class="$age_class">$age_str</td>
2320 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2321 <td class="pre">$data</td>
2324 } # while (my $line = <$fd>)
2325 print "</table>\n\n";
2327 or print "Reading blob failed.\n";
2333 my $head = git_get_head_hash
($project);
2335 git_print_page_nav
('','', $head,undef,$head);
2336 git_print_header_div
('summary', $project);
2338 my $taglist = git_get_refs_list
("refs/tags");
2339 if (defined @
$taglist) {
2340 git_tags_body
($taglist);
2346 my $head = git_get_head_hash
($project);
2348 git_print_page_nav
('','', $head,undef,$head);
2349 git_print_header_div
('summary', $project);
2351 my $taglist = git_get_refs_list
("refs/heads");
2352 if (defined @
$taglist) {
2353 git_heads_body
($taglist, $head);
2358 sub git_blob_plain
{
2359 if (!defined $hash) {
2360 if (defined $file_name) {
2361 my $base = $hash_base || git_get_head_hash
($project);
2362 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2363 or die_error
(undef, "Error lookup file");
2365 die_error
(undef, "No file name defined");
2369 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2370 or die_error
(undef, "Couldn't cat $file_name, $hash");
2372 $type ||= blob_mimetype
($fd, $file_name);
2374 # save as filename, even when no $file_name is given
2375 my $save_as = "$hash";
2376 if (defined $file_name) {
2377 $save_as = $file_name;
2378 } elsif ($type =~ m/^text\//) {
2382 print $cgi->header(-type
=> "$type",
2383 -content_disposition
=> "inline; filename=\"$save_as\"");
2385 binmode STDOUT
, ':raw';
2387 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2393 if (!defined $hash) {
2394 if (defined $file_name) {
2395 my $base = $hash_base || git_get_head_hash
($project);
2396 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2397 or die_error
(undef, "Error lookup file");
2399 die_error
(undef, "No file name defined");
2402 my $have_blame = gitweb_check_feature
('blame');
2403 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2404 or die_error
(undef, "Couldn't cat $file_name, $hash");
2405 my $mimetype = blob_mimetype
($fd, $file_name);
2406 if ($mimetype !~ m/^text\//) {
2408 return git_blob_plain
($mimetype);
2411 my $formats_nav = '';
2412 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2413 if (defined $file_name) {
2416 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2417 hash
=>$hash, file_name
=>$file_name)},
2422 $cgi->a({-href
=> href
(action
=>"blob_plain",
2423 hash
=>$hash, file_name
=>$file_name)},
2426 $cgi->a({-href
=> href
(action
=>"blob",
2427 hash_base
=>"HEAD", file_name
=>$file_name)},
2431 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "plain");
2433 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2434 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2436 print "<div class=\"page_nav\">\n" .
2437 "<br/><br/></div>\n" .
2438 "<div class=\"title\">$hash</div>\n";
2440 git_print_page_path
($file_name, "blob", $hash_base);
2441 print "<div class=\"page_body\">\n";
2443 while (my $line = <$fd>) {
2446 $line = untabify
($line);
2447 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2448 $nr, $nr, $nr, esc_html
($line);
2451 or print "Reading blob failed.\n";
2457 if (!defined $hash) {
2458 $hash = git_get_head_hash
($project);
2459 if (defined $file_name) {
2460 my $base = $hash_base || $hash;
2461 $hash = git_get_hash_by_path
($base, $file_name, "tree");
2463 if (!defined $hash_base) {
2468 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
2469 or die_error
(undef, "Open git-ls-tree failed");
2470 my @entries = map { chomp; $_ } <$fd>;
2471 close $fd or die_error
(undef, "Reading tree failed");
2474 my $refs = git_get_references
();
2475 my $ref = format_ref_marker
($refs, $hash_base);
2479 my $have_blame = gitweb_check_feature
('blame');
2480 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2481 $base_key{hash_base
} = $hash_base;
2482 git_print_page_nav
('tree','', $hash_base);
2483 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2485 print "<div class=\"page_nav\">\n";
2486 print "<br/><br/></div>\n";
2487 print "<div class=\"title\">$hash</div>\n";
2489 if (defined $file_name) {
2490 $base = esc_html
("$file_name/");
2492 git_print_page_path
($file_name, 'tree', $hash_base);
2493 print "<div class=\"page_body\">\n";
2494 print "<table cellspacing=\"0\">\n";
2496 foreach my $line (@entries) {
2497 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2498 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2502 my $t_name = validate_input
($4);
2504 print "<tr class=\"dark\">\n";
2506 print "<tr class=\"light\">\n";
2509 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
2510 if ($t_type eq "blob") {
2511 print "<td class=\"list\">" .
2512 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key),
2513 -class => "list"}, esc_html
($t_name)) .
2515 "<td class=\"link\">" .
2516 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2520 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2524 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2525 hash
=>$t_hash, file_name
=>"$base$t_name")},
2528 $cgi->a({-href
=> href
(action
=>"blob_plain",
2529 hash
=>$t_hash, file_name
=>"$base$t_name")},
2532 } elsif ($t_type eq "tree") {
2533 print "<td class=\"list\">" .
2534 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2535 esc_html
($t_name)) .
2537 "<td class=\"link\">" .
2538 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2541 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base, file_name
=>"$base$t_name")},
2547 print "</table>\n" .
2554 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2555 my $have_snapshot = (defined $ctype && defined $suffix);
2556 if (!$have_snapshot) {
2557 die_error
('403 Permission denied', "Permission denied");
2560 if (!defined $hash) {
2561 $hash = git_get_head_hash
($project);
2564 my $filename = basename
($project) . "-$hash.tar.$suffix";
2566 print $cgi->header(-type
=> 'application/x-tar',
2567 -content_encoding
=> $ctype,
2568 -content_disposition
=> "inline; filename=\"$filename\"",
2569 -status
=> '200 OK');
2571 open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | $command" or
2572 die_error
(undef, "Execute git-tar-tree failed.");
2573 binmode STDOUT
, ':raw';
2575 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2581 my $head = git_get_head_hash
($project);
2582 if (!defined $hash) {
2585 if (!defined $page) {
2588 my $refs = git_get_references
();
2590 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2591 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2592 or die_error
(undef, "Open git-rev-list failed");
2593 my @revlist = map { chomp; $_ } <$fd>;
2596 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2599 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2602 my %co = parse_commit
($hash);
2604 git_print_header_div
('summary', $project);
2605 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2607 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2608 my $commit = $revlist[$i];
2609 my $ref = format_ref_marker
($refs, $commit);
2610 my %co = parse_commit
($commit);
2612 my %ad = parse_date
($co{'author_epoch'});
2613 git_print_header_div
('commit',
2614 "<span class=\"age\">$co{'age_string'}</span>" .
2615 esc_html
($co{'title'}) . $ref,
2617 print "<div class=\"title_text\">\n" .
2618 "<div class=\"log_link\">\n" .
2619 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2621 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2624 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2627 print "<div class=\"log_body\">\n";
2628 git_print_simplified_log
($co{'comment'});
2635 my %co = parse_commit
($hash);
2637 die_error
(undef, "Unknown commit object");
2639 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2640 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2642 my $parent = $co{'parent'};
2643 if (!defined $parent) {
2646 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
2647 or die_error
(undef, "Open git-diff-tree failed");
2648 my @difftree = map { chomp; $_ } <$fd>;
2649 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2651 # non-textual hash id's can be cached
2653 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2656 my $refs = git_get_references
();
2657 my $ref = format_ref_marker
($refs, $co{'id'});
2659 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2660 my $have_snapshot = (defined $ctype && defined $suffix);
2662 my $formats_nav = '';
2663 if (defined $file_name && defined $co{'parent'}) {
2664 my $parent = $co{'parent'};
2666 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
2669 git_header_html
(undef, $expires);
2670 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
2671 $hash, $co{'tree'}, $hash,
2674 if (defined $co{'parent'}) {
2675 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2677 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
2679 print "<div class=\"title_text\">\n" .
2680 "<table cellspacing=\"0\">\n";
2681 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2683 "<td></td><td> $ad{'rfc2822'}";
2684 if ($ad{'hour_local'} < 6) {
2685 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2686 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2688 printf(" (%02d:%02d %s)",
2689 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2693 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2694 print "<tr><td></td><td> $cd{'rfc2822'}" .
2695 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2697 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2700 "<td class=\"sha1\">" .
2701 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
2702 class => "list"}, $co{'tree'}) .
2704 "<td class=\"link\">" .
2705 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
2707 if ($have_snapshot) {
2709 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
2713 my $parents = $co{'parents'};
2714 foreach my $par (@
$parents) {
2717 "<td class=\"sha1\">" .
2718 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
2719 class => "list"}, $par) .
2721 "<td class=\"link\">" .
2722 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
2724 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "commitdiff") .
2731 print "<div class=\"page_body\">\n";
2732 git_print_log
($co{'comment'});
2735 git_difftree_body
(\
@difftree, $hash, $parent);
2741 my $format = shift || 'html';
2748 # preparing $fd and %diffinfo for git_patchset_body
2750 if (defined $hash_base && defined $hash_parent_base) {
2751 if (defined $file_name) {
2753 open $fd, "-|", $GIT, "diff-tree", '-r', '-M', '-C', $hash_parent_base, $hash_base,
2755 or die_error
(undef, "Open git-diff-tree failed");
2756 @difftree = map { chomp; $_ } <$fd>;
2758 or die_error
(undef, "Reading git-diff-tree failed");
2760 or die_error
('404 Not Found', "Blob diff not found");
2762 } elsif (defined $hash) { # try to find filename from $hash
2763 if ($hash !~ /[0-9a-fA-F]{40}/) {
2764 $hash = git_to_hash
($hash);
2767 # read filtered raw output
2768 open $fd, "-|", $GIT, "diff-tree", '-r', '-M', '-C', $hash_parent_base, $hash_base
2769 or die_error
(undef, "Open git-diff-tree failed");
2771 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
2773 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
2774 map { chomp; $_ } <$fd>;
2776 or die_error
(undef, "Reading git-diff-tree failed");
2778 or die_error
('404 Not Found', "Blob diff not found");
2781 die_error
('404 Not Found', "Missing one of the blob diff parameters");
2784 if (@difftree > 1) {
2785 die_error
('404 Not Found', "Ambiguous blob diff specification");
2788 %diffinfo = parse_difftree_raw_line
($difftree[0]);
2789 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
2790 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
2792 $hash_parent ||= $diffinfo{'from_id'};
2793 $hash ||= $diffinfo{'to_id'};
2795 # non-textual hash id's can be cached
2796 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
2797 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
2802 open $fd, "-|", $GIT, "diff-tree", '-r', '-p', '-M', '-C', $hash_parent_base, $hash_base,
2804 or die_error
(undef, "Open git-diff-tree failed");
2807 # old/legacy style URI
2808 if (!%diffinfo && # if new style URI failed
2809 defined $hash && defined $hash_parent) {
2810 # fake git-diff-tree raw output
2811 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
2812 $diffinfo{'from_id'} = $hash_parent;
2813 $diffinfo{'to_id'} = $hash;
2814 if (defined $file_name) {
2815 if (defined $file_parent) {
2816 $diffinfo{'status'} = '2';
2817 $diffinfo{'from_file'} = $file_parent;
2818 $diffinfo{'to_file'} = $file_name;
2819 } else { # assume not renamed
2820 $diffinfo{'status'} = '1';
2821 $diffinfo{'from_file'} = $file_name;
2822 $diffinfo{'to_file'} = $file_name;
2824 } else { # no filename given
2825 $diffinfo{'status'} = '2';
2826 $diffinfo{'from_file'} = $hash_parent;
2827 $diffinfo{'to_file'} = $hash;
2830 # non-textual hash id's can be cached
2831 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
2832 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
2837 #open $fd, "-|", $GIT, "diff", '-p', $hash_parent, $hash
2838 open $fd, "-|", $GIT, "diff", '-p', $hash, $hash_parent
2839 or die_error
(undef, "Open git-diff failed");
2841 die_error
('404 Not Found', "Missing one of the blob diff parameters")
2846 if ($format eq 'html') {
2848 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
2849 hash
=>$hash, hash_parent
=>$hash_parent,
2850 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
2851 file_name
=>$file_name, file_parent
=>$file_parent)},
2853 git_header_html
(undef, $expires);
2854 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2855 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2856 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2858 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
2859 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
2861 if (defined $file_name) {
2862 git_print_page_path
($file_name, "blob", $hash_base);
2864 print "<div class=\"page_path\"></div>\n";
2867 } elsif ($format eq 'plain') {
2869 -type
=> 'text/plain',
2870 -charset
=> 'utf-8',
2871 -expires
=> $expires,
2872 -content_disposition
=> qq(inline
; filename
="${file_name}.patch"));
2874 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
2877 die_error
(undef, "Unknown blobdiff format");
2881 if ($format eq 'html') {
2882 print "<div class=\"page_body\">\n";
2884 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
2887 print "</div>\n"; # class="page_body"
2891 while (my $line = <$fd>) {
2892 $line =~ s!a/($hash|$hash_parent)!a/$diffinfo{'from_file'}!g;
2893 $line =~ s!b/($hash|$hash_parent)!b/$diffinfo{'to_file'}!g;
2897 last if $line =~ m!^\+\+\+!;
2905 sub git_blobdiff_plain
{
2906 git_blobdiff
('plain');
2909 sub git_commitdiff
{
2910 my $format = shift || 'html';
2911 my %co = parse_commit
($hash);
2913 die_error
(undef, "Unknown commit object");
2915 if (!defined $hash_parent) {
2916 $hash_parent = $co{'parent'} || '--root';
2922 if ($format eq 'html') {
2923 open $fd, "-|", $GIT, "diff-tree", '-r', '-M', '-C',
2924 "--patch-with-raw", "--full-index", $hash_parent, $hash
2925 or die_error
(undef, "Open git-diff-tree failed");
2927 while (chomp(my $line = <$fd>)) {
2928 # empty line ends raw part of diff-tree output
2930 push @difftree, $line;
2933 } elsif ($format eq 'plain') {
2934 open $fd, "-|", $GIT, "diff-tree", '-r', '-p', '-B', $hash_parent, $hash
2935 or die_error
(undef, "Open git-diff-tree failed");
2938 die_error
(undef, "Unknown commitdiff format");
2941 # non-textual hash id's can be cached
2943 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2947 # write commit message
2948 if ($format eq 'html') {
2949 my $refs = git_get_references
();
2950 my $ref = format_ref_marker
($refs, $co{'id'});
2952 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
2953 hash
=>$hash, hash_parent
=>$hash_parent)},
2956 git_header_html
(undef, $expires);
2957 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2958 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2959 print "<div class=\"page_body\">\n";
2960 print "<div class=\"log\">\n";
2961 git_print_simplified_log
($co{'comment'}, 1); # skip title
2962 print "</div>\n"; # class="log"
2964 } elsif ($format eq 'plain') {
2965 my $refs = git_get_references
("tags");
2966 my $tagname = git_get_rev_name_tags
($hash);
2967 my $filename = basename
($project) . "-$hash.patch";
2970 -type
=> 'text/plain',
2971 -charset
=> 'utf-8',
2972 -expires
=> $expires,
2973 -content_disposition
=> qq(inline
; filename
="$filename"));
2974 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2977 Date: $ad{'rfc2822'} ($ad{'tz_local'})
2978 Subject: $co{'title'}
2980 print "X-Git-Tag: $tagname\n" if $tagname;
2981 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
2983 foreach my $line (@
{$co{'comment'}}) {
2990 if ($format eq 'html') {
2991 #git_difftree_body(\@difftree, $hash, $hash_parent);
2994 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
2996 print "</div>\n"; # class="page_body"
2999 } elsif ($format eq 'plain') {
3003 or print "Reading git-diff-tree failed\n";
3007 sub git_commitdiff_plain
{
3008 git_commitdiff
('plain');
3012 if (!defined $hash_base) {
3013 $hash_base = git_get_head_hash
($project);
3016 my %co = parse_commit
($hash_base);
3018 die_error
(undef, "Unknown commit object");
3020 my $refs = git_get_references
();
3022 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
3023 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3024 if (!defined $hash && defined $file_name) {
3025 $hash = git_get_hash_by_path
($hash_base, $file_name);
3027 if (defined $hash) {
3028 $ftype = git_get_type
($hash);
3030 git_print_page_path
($file_name, $ftype, $hash_base);
3033 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
3034 git_history_body
($fd, $refs, $hash_base, $ftype);
3041 if (!defined $searchtext) {
3042 die_error
(undef, "Text field empty");
3044 if (!defined $hash) {
3045 $hash = git_get_head_hash
($project);
3047 my %co = parse_commit
($hash);
3049 die_error
(undef, "Unknown commit object");
3051 # pickaxe may take all resources of your box and run for several minutes
3052 # with every query - so decide by yourself how public you make this feature :)
3053 my $commit_search = 1;
3054 my $author_search = 0;
3055 my $committer_search = 0;
3056 my $pickaxe_search = 0;
3057 if ($searchtext =~ s/^author\\://i) {
3059 } elsif ($searchtext =~ s/^committer\\://i) {
3060 $committer_search = 1;
3061 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3063 $pickaxe_search = 1;
3066 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3067 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3069 print "<table cellspacing=\"0\">\n";
3071 if ($commit_search) {
3073 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
3074 while (my $commit_text = <$fd>) {
3075 if (!grep m/$searchtext/i, $commit_text) {
3078 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3081 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3084 my @commit_lines = split "\n", $commit_text;
3085 my %co = parse_commit
(undef, \
@commit_lines);
3090 print "<tr class=\"dark\">\n";
3092 print "<tr class=\"light\">\n";
3095 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3096 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3098 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3099 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3100 my $comment = $co{'comment'};
3101 foreach my $line (@
$comment) {
3102 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3103 my $lead = esc_html
($1) || "";
3104 $lead = chop_str
($lead, 30, 10);
3105 my $match = esc_html
($2) || "";
3106 my $trail = esc_html
($3) || "";
3107 $trail = chop_str
($trail, 30, 10);
3108 my $text = "$lead<span class=\"match\">$match</span>$trail";
3109 print chop_str
($text, 80, 5) . "<br/>\n";
3113 "<td class=\"link\">" .
3114 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3116 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3123 if ($pickaxe_search) {
3125 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
3128 while (my $line = <$fd>) {
3129 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3132 $set{'from_id'} = $3;
3134 $set{'id'} = $set{'to_id'};
3135 if ($set{'id'} =~ m/0{40}/) {
3136 $set{'id'} = $set{'from_id'};
3138 if ($set{'id'} =~ m/0{40}/) {
3142 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3145 print "<tr class=\"dark\">\n";
3147 print "<tr class=\"light\">\n";
3150 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3151 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3153 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3154 -class => "list subject"},
3155 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3156 while (my $setref = shift @files) {
3158 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3159 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3161 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3165 "<td class=\"link\">" .
3166 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3168 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3172 %co = parse_commit
($1);
3182 my $head = git_get_head_hash
($project);
3183 if (!defined $hash) {
3186 if (!defined $page) {
3189 my $refs = git_get_references
();
3191 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3192 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
3193 or die_error
(undef, "Open git-rev-list failed");
3194 my @revlist = map { chomp; $_ } <$fd>;
3197 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3199 if ($#revlist >= (100 * ($page+1)-1)) {
3201 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3202 -title
=> "Alt-n"}, "next");
3207 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3208 git_print_header_div
('summary', $project);
3210 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3215 ## ......................................................................
3216 ## feeds (RSS, OPML)
3219 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3220 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash
($project)
3221 or die_error
(undef, "Open git-rev-list failed");
3222 my @revlist = map { chomp; $_ } <$fd>;
3223 close $fd or die_error
(undef, "Reading git-rev-list failed");
3224 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3226 <?xml version="1.0" encoding="utf-8"?>
3227 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3229 <title>$project $my_uri $my_url</title>
3230 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3231 <description>$project log</description>
3232 <language>en</language>
3235 for (my $i = 0; $i <= $#revlist; $i++) {
3236 my $commit = $revlist[$i];
3237 my %co = parse_commit
($commit);
3238 # we read 150, we always show 30 and the ones more recent than 48 hours
3239 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3242 my %cd = parse_date
($co{'committer_epoch'});
3243 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
3244 my @difftree = map { chomp; $_ } <$fd>;
3248 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3250 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3251 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3252 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3253 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3254 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3255 "<content:encoded>" .
3257 my $comment = $co{'comment'};
3258 foreach my $line (@
$comment) {
3259 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
3260 print "$line<br/>\n";
3263 foreach my $line (@difftree) {
3264 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3267 my $file = validate_input
(unquote
($7));
3268 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
3269 print "$file<br/>\n";
3272 "</content:encoded>\n" .
3275 print "</channel></rss>";
3279 my @list = git_get_projects_list
();
3281 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3283 <?xml version="1.0" encoding="utf-8"?>
3284 <opml version="1.0">
3286 <title>$site_name Git OPML Export</title>
3289 <outline text="git RSS feeds">
3292 foreach my $pr (@list) {
3294 my $head = git_get_head_hash
($proj{'path'});
3295 if (!defined $head) {
3298 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
3299 my %co = parse_commit
($head);
3304 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3305 my $rss = "$my_url?p=$proj{'path'};a=rss";
3306 my $html = "$my_url?p=$proj{'path'};a=summary";
3307 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";