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++";
51 # URI of GIT favicon, assumed to be image/png type
52 our $favicon = "++GITWEB_FAVICON++";
54 # source of projects list
55 our $projects_list = "++GITWEB_LIST++";
57 # list of git base URLs used for URL to where fetch project from,
58 # i.e. full URL is "$git_base_url/$project"
59 our @git_base_url_list = ("++GITWEB_BASE_URL++");
61 # default blob_plain mimetype and default charset for text/plain blob
62 our $default_blob_plain_mimetype = 'text/plain';
63 our $default_text_plain_charset = undef;
65 # file to use for guessing MIME types before trying /etc/mime.types
66 # (relative to the current git repository)
67 our $mimetypes_file = undef;
69 # You define site-wide feature defaults here; override them with
70 # $GITWEB_CONFIG as necessary.
73 # 'sub' => feature-sub (subroutine),
74 # 'override' => allow-override (boolean),
75 # 'default' => [ default options...] (array reference)}
77 # if feature is overridable (it means that allow-override has true value,
78 # then feature-sub will be called with default options as parameters;
79 # return value of feature-sub indicates if to enable specified feature
81 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
84 'sub' => \
&feature_blame
,
89 'sub' => \
&feature_snapshot
,
91 # => [content-encoding, suffix, program]
92 'default' => ['x-gzip', 'gz', 'gzip']},
95 sub gitweb_check_feature
{
97 return undef unless exists $feature{$name};
98 my ($sub, $override, @defaults) = (
99 $feature{$name}{'sub'},
100 $feature{$name}{'override'},
101 @
{$feature{$name}{'default'}});
102 if (!$override) { return @defaults; }
103 return $sub->(@defaults);
106 # To enable system wide have in $GITWEB_CONFIG
107 # $feature{'blame'}{'default'} = [1];
108 # To have project specific config enable override in $GITWEB_CONFIG
109 # $feature{'blame'}{'override'} = 1;
110 # and in project config gitweb.blame = 0|1;
113 my ($val) = git_get_project_config
('blame', '--bool');
115 if ($val eq 'true') {
117 } elsif ($val eq 'false') {
124 # To disable system wide have in $GITWEB_CONFIG
125 # $feature{'snapshot'}{'default'} = [undef];
126 # To have project specific config enable override in $GITWEB_CONFIG
127 # $feature{'blame'}{'override'} = 1;
128 # and in project config gitweb.snapshot = none|gzip|bzip2
130 sub feature_snapshot
{
131 my ($ctype, $suffix, $command) = @_;
133 my ($val) = git_get_project_config
('snapshot');
135 if ($val eq 'gzip') {
136 return ('x-gzip', 'gz', 'gzip');
137 } elsif ($val eq 'bzip2') {
138 return ('x-bzip2', 'bz2', 'bzip2');
139 } elsif ($val eq 'none') {
143 return ($ctype, $suffix, $command);
146 # rename detection options for git-diff and git-diff-tree
147 # - default is '-M', with the cost proportional to
148 # (number of removed files) * (number of new files).
149 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
150 # (number of changed files + number of removed files) * (number of new files)
151 # - even more costly is '-C', '--find-copies-harder' with cost
152 # (number of files in the original tree) * (number of new files)
153 # - one might want to include '-B' option, e.g. '-B', '-M'
154 our @diff_opts = ('-M'); # taken from git_commit
156 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
157 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
159 # version of the core git binary
160 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
162 # path to the current git repository
165 $projects_list ||= $projectroot;
167 # ======================================================================
168 # input validation and dispatch
169 our $action = $cgi->param('a');
170 if (defined $action) {
171 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
172 die_error
(undef, "Invalid action parameter");
176 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
177 if (defined $project) {
180 $project = undef unless $project;
182 if (defined $project) {
183 if (!validate_input
($project)) {
184 die_error
(undef, "Invalid project parameter");
186 if (!(-d
"$projectroot/$project")) {
187 die_error
(undef, "No such directory");
189 if (!(-e
"$projectroot/$project/HEAD")) {
190 die_error
(undef, "No such project");
192 $git_dir = "$projectroot/$project";
195 our $file_name = $cgi->param('f');
196 if (defined $file_name) {
197 if (!validate_input
($file_name)) {
198 die_error
(undef, "Invalid file parameter");
202 our $file_parent = $cgi->param('fp');
203 if (defined $file_parent) {
204 if (!validate_input
($file_parent)) {
205 die_error
(undef, "Invalid file parent parameter");
209 our $hash = $cgi->param('h');
211 if (!validate_input
($hash)) {
212 die_error
(undef, "Invalid hash parameter");
216 our $hash_parent = $cgi->param('hp');
217 if (defined $hash_parent) {
218 if (!validate_input
($hash_parent)) {
219 die_error
(undef, "Invalid hash parent parameter");
223 our $hash_base = $cgi->param('hb');
224 if (defined $hash_base) {
225 if (!validate_input
($hash_base)) {
226 die_error
(undef, "Invalid hash base parameter");
230 our $hash_parent_base = $cgi->param('hpb');
231 if (defined $hash_parent_base) {
232 if (!validate_input
($hash_parent_base)) {
233 die_error
(undef, "Invalid hash parent base parameter");
237 our $page = $cgi->param('pg');
239 if ($page =~ m/[^0-9]$/) {
240 die_error
(undef, "Invalid page parameter");
244 our $searchtext = $cgi->param('s');
245 if (defined $searchtext) {
246 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
247 die_error
(undef, "Invalid search parameter");
249 $searchtext = quotemeta $searchtext;
254 "blame" => \
&git_blame2
,
255 "blobdiff" => \
&git_blobdiff
,
256 "blobdiff_plain" => \
&git_blobdiff_plain
,
257 "blob" => \
&git_blob
,
258 "blob_plain" => \
&git_blob_plain
,
259 "commitdiff" => \
&git_commitdiff
,
260 "commitdiff_plain" => \
&git_commitdiff_plain
,
261 "commit" => \
&git_commit
,
262 "heads" => \
&git_heads
,
263 "history" => \
&git_history
,
266 "search" => \
&git_search
,
267 "shortlog" => \
&git_shortlog
,
268 "summary" => \
&git_summary
,
270 "tags" => \
&git_tags
,
271 "tree" => \
&git_tree
,
272 "snapshot" => \
&git_snapshot
,
273 # those below don't need $project
274 "opml" => \
&git_opml
,
275 "project_list" => \
&git_project_list
,
278 if (defined $project) {
279 $action ||= 'summary';
281 $action ||= 'project_list';
283 if (!defined($actions{$action})) {
284 die_error
(undef, "Unknown action");
286 $actions{$action}->();
289 ## ======================================================================
303 hash_parent_base
=> "hpb",
307 my %mapping = @mapping;
309 $params{"project"} ||= $project;
312 for (my $i = 0; $i < @mapping; $i += 2) {
313 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
314 if (defined $params{$name}) {
315 push @result, $symbol . "=" . esc_param
($params{$name});
318 return "$my_uri?" . join(';', @result);
322 ## ======================================================================
323 ## validation, quoting/unquoting and escaping
328 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
331 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
334 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
340 # quote unsafe chars, but keep the slash, even when it's not
341 # correct, but quoted slashes look too horrible in bookmarks
344 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
350 # replace invalid utf8 character with SUBSTITUTION sequence
353 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
354 $str = escapeHTML
($str);
355 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
359 # git may return quoted and escaped filenames
362 if ($str =~ m/^"(.*)"$/) {
364 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
369 # escape tabs (convert tabs to spaces)
373 while ((my $pos = index($line, "\t")) != -1) {
374 if (my $count = (8 - ($pos % 8))) {
375 my $spaces = ' ' x
$count;
376 $line =~ s/\t/$spaces/;
383 ## ----------------------------------------------------------------------
384 ## HTML aware string manipulation
389 my $add_len = shift || 10;
391 # allow only $len chars, but don't cut a word if it would fit in $add_len
392 # if it doesn't fit, cut it if it's still longer than the dots we would add
393 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
396 if (length($tail) > 4) {
398 $body =~ s/&[^;]*$//; # remove chopped character entities
403 ## ----------------------------------------------------------------------
404 ## functions returning short strings
406 # CSS class for given age value (in seconds)
410 if ($age < 60*60*2) {
412 } elsif ($age < 60*60*24*2) {
419 # convert age in seconds to "nn units ago" string
424 if ($age > 60*60*24*365*2) {
425 $age_str = (int $age/60/60/24/365);
426 $age_str .= " years ago";
427 } elsif ($age > 60*60*24*(365/12)*2) {
428 $age_str = int $age/60/60/24/(365/12);
429 $age_str .= " months ago";
430 } elsif ($age > 60*60*24*7*2) {
431 $age_str = int $age/60/60/24/7;
432 $age_str .= " weeks ago";
433 } elsif ($age > 60*60*24*2) {
434 $age_str = int $age/60/60/24;
435 $age_str .= " days ago";
436 } elsif ($age > 60*60*2) {
437 $age_str = int $age/60/60;
438 $age_str .= " hours ago";
439 } elsif ($age > 60*2) {
440 $age_str = int $age/60;
441 $age_str .= " min ago";
444 $age_str .= " sec ago";
446 $age_str .= " right now";
451 # convert file mode in octal to symbolic file mode string
453 my $mode = oct shift;
455 if (S_ISDIR
($mode & S_IFMT
)) {
457 } elsif (S_ISLNK
($mode)) {
459 } elsif (S_ISREG
($mode)) {
460 # git cares only about the executable bit
461 if ($mode & S_IXUSR
) {
471 # convert file mode in octal to file type string
475 if ($mode !~ m/^[0-7]+$/) {
481 if (S_ISDIR
($mode & S_IFMT
)) {
483 } elsif (S_ISLNK
($mode)) {
485 } elsif (S_ISREG
($mode)) {
492 ## ----------------------------------------------------------------------
493 ## functions returning short HTML fragments, or transforming HTML fragments
494 ## which don't beling to other sections
496 # format line of commit message or tag comment
497 sub format_log_line_html
{
500 $line = esc_html
($line);
501 $line =~ s/ / /g;
502 if ($line =~ m/([0-9a-fA-F]{40})/) {
504 if (git_get_type
($hash_text) eq "commit") {
506 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
507 -class => "text"}, $hash_text);
508 $line =~ s/$hash_text/$link/;
514 # format marker of refs pointing to given object
515 sub format_ref_marker
{
516 my ($refs, $id) = @_;
519 if (defined $refs->{$id}) {
520 foreach my $ref (@
{$refs->{$id}}) {
521 my ($type, $name) = qw();
522 # e.g. tags/v2.6.11 or heads/next
523 if ($ref =~ m!^(.*?)s?/(.*)$!) {
531 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
536 return ' <span class="refs">'. $markers . '</span>';
542 # format, perhaps shortened and with markers, title line
543 sub format_subject_html
{
544 my ($long, $short, $href, $extra) = @_;
545 $extra = '' unless defined($extra);
547 if (length($short) < length($long)) {
548 return $cgi->a({-href
=> $href, -class => "list subject",
550 esc_html
($short) . $extra);
552 return $cgi->a({-href
=> $href, -class => "list subject"},
553 esc_html
($long) . $extra);
557 sub format_diff_line
{
559 my $char = substr($line, 0, 1);
565 $diff_class = " add";
566 } elsif ($char eq "-") {
567 $diff_class = " rem";
568 } elsif ($char eq "@") {
569 $diff_class = " chunk_header";
570 } elsif ($char eq "\\") {
571 $diff_class = " incomplete";
573 $line = untabify
($line);
574 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
577 ## ----------------------------------------------------------------------
578 ## git utility subroutines, invoking git commands
580 # returns path to the core git executable and the --git-dir parameter as list
582 return $GIT, '--git-dir='.$git_dir;
585 # returns path to the core git executable and the --git-dir parameter as string
587 return join(' ', git_cmd
());
590 # get HEAD ref of given project as hash
591 sub git_get_head_hash
{
593 my $o_git_dir = $git_dir;
595 $git_dir = "$projectroot/$project";
596 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
599 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
603 if (defined $o_git_dir) {
604 $git_dir = $o_git_dir;
609 # get type of given object
613 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
620 sub git_get_project_config
{
621 my ($key, $type) = @_;
623 return unless ($key);
624 $key =~ s/^gitweb\.//;
625 return if ($key =~ m/\W/);
627 my @x = (git_cmd
(), 'repo-config');
628 if (defined $type) { push @x, $type; }
630 push @x, "gitweb.$key";
636 # get hash of given path at given ref
637 sub git_get_hash_by_path
{
639 my $path = shift || return undef;
643 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
644 or die_error
(undef, "Open git-ls-tree failed");
646 close $fd or return undef;
648 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
649 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
653 ## ......................................................................
654 ## git utility functions, directly accessing git repository
656 # assumes that PATH is not symref
657 sub git_get_hash_by_ref
{
660 open my $fd, "$projectroot/$path" or return undef;
664 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
669 sub git_get_project_description
{
672 open my $fd, "$projectroot/$path/description" or return undef;
679 sub git_get_project_url_list
{
682 open my $fd, "$projectroot/$path/cloneurl" or return undef;
683 my @git_project_url_list = map { chomp; $_ } <$fd>;
686 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
689 sub git_get_projects_list
{
692 if (-d
$projects_list) {
693 # search in directory
694 my $dir = $projects_list;
695 opendir my ($dh), $dir or return undef;
696 while (my $dir = readdir($dh)) {
697 if (-e
"$projectroot/$dir/HEAD") {
705 } elsif (-f
$projects_list) {
706 # read from file(url-encoded):
707 # 'git%2Fgit.git Linus+Torvalds'
708 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
709 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
710 open my ($fd), $projects_list or return undef;
711 while (my $line = <$fd>) {
713 my ($path, $owner) = split ' ', $line;
714 $path = unescape
($path);
715 $owner = unescape
($owner);
716 if (!defined $path) {
719 if (-e
"$projectroot/$path/HEAD") {
722 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
729 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
733 sub git_get_project_owner
{
737 return undef unless $project;
739 # read from file (url-encoded):
740 # 'git%2Fgit.git Linus+Torvalds'
741 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
742 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
743 if (-f
$projects_list) {
744 open (my $fd , $projects_list);
745 while (my $line = <$fd>) {
747 my ($pr, $ow) = split ' ', $line;
750 if ($pr eq $project) {
751 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
757 if (!defined $owner) {
758 $owner = get_file_owner
("$projectroot/$project");
764 sub git_get_references
{
765 my $type = shift || "";
768 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
769 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
770 if (-f
"$projectroot/$project/info/refs") {
771 open $fd, "$projectroot/$project/info/refs"
774 open $fd, "-|", git_cmd
(), "ls-remote", "."
778 while (my $line = <$fd>) {
780 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
781 if (defined $refs{$1}) {
782 push @
{$refs{$1}}, $2;
792 sub git_get_rev_name_tags
{
793 my $hash = shift || return undef;
795 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
797 my $name_rev = <$fd>;
800 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
803 # catches also '$hash undefined' output
808 ## ----------------------------------------------------------------------
809 ## parse to hash functions
813 my $tz = shift || "-0000";
816 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
817 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
818 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
819 $date{'hour'} = $hour;
820 $date{'minute'} = $min;
821 $date{'mday'} = $mday;
822 $date{'day'} = $days[$wday];
823 $date{'month'} = $months[$mon];
824 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
825 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
826 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
827 $mday, $months[$mon], $hour ,$min;
829 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
830 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
831 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
832 $date{'hour_local'} = $hour;
833 $date{'minute_local'} = $min;
834 $date{'tz_local'} = $tz;
843 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
844 $tag{'id'} = $tag_id;
845 while (my $line = <$fd>) {
847 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
849 } elsif ($line =~ m/^type (.+)$/) {
851 } elsif ($line =~ m/^tag (.+)$/) {
853 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
857 } elsif ($line =~ m/--BEGIN/) {
858 push @comment, $line;
860 } elsif ($line eq "") {
864 push @comment, <$fd>;
865 $tag{'comment'} = \
@comment;
867 if (!defined $tag{'name'}) {
874 my $commit_id = shift;
875 my $commit_text = shift;
880 if (defined $commit_text) {
881 @commit_lines = @
$commit_text;
884 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
886 @commit_lines = split '\n', <$fd>;
891 my $header = shift @commit_lines;
892 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
895 ($co{'id'}, my @parents) = split ' ', $header;
896 $co{'parents'} = \
@parents;
897 $co{'parent'} = $parents[0];
898 while (my $line = shift @commit_lines) {
899 last if $line eq "\n";
900 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
902 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
904 $co{'author_epoch'} = $2;
905 $co{'author_tz'} = $3;
906 if ($co{'author'} =~ m/^([^<]+) </) {
907 $co{'author_name'} = $1;
909 $co{'author_name'} = $co{'author'};
911 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
912 $co{'committer'} = $1;
913 $co{'committer_epoch'} = $2;
914 $co{'committer_tz'} = $3;
915 $co{'committer_name'} = $co{'committer'};
916 $co{'committer_name'} =~ s/ <.*//;
919 if (!defined $co{'tree'}) {
923 foreach my $title (@commit_lines) {
926 $co{'title'} = chop_str
($title, 80, 5);
927 # remove leading stuff of merges to make the interesting part visible
928 if (length($title) > 50) {
929 $title =~ s/^Automatic //;
930 $title =~ s/^merge (of|with) /Merge ... /i;
931 if (length($title) > 50) {
932 $title =~ s/(http|rsync):\/\///;
934 if (length($title) > 50) {
935 $title =~ s/(master|www|rsync)\.//;
937 if (length($title) > 50) {
938 $title =~ s/kernel.org:?//;
940 if (length($title) > 50) {
941 $title =~ s/\/pub\/scm//;
944 $co{'title_short'} = chop_str
($title, 50, 5);
948 # remove added spaces
949 foreach my $line (@commit_lines) {
952 $co{'comment'} = \
@commit_lines;
954 my $age = time - $co{'committer_epoch'};
956 $co{'age_string'} = age_string
($age);
957 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
958 if ($age > 60*60*24*7*2) {
959 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
960 $co{'age_string_age'} = $co{'age_string'};
962 $co{'age_string_date'} = $co{'age_string'};
963 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
968 # parse ref from ref_file, given by ref_id, with given type
970 my $ref_file = shift;
972 my $type = shift || git_get_type
($ref_id);
975 $ref_item{'type'} = $type;
976 $ref_item{'id'} = $ref_id;
977 $ref_item{'epoch'} = 0;
978 $ref_item{'age'} = "unknown";
979 if ($type eq "tag") {
980 my %tag = parse_tag
($ref_id);
981 $ref_item{'comment'} = $tag{'comment'};
982 if ($tag{'type'} eq "commit") {
983 my %co = parse_commit
($tag{'object'});
984 $ref_item{'epoch'} = $co{'committer_epoch'};
985 $ref_item{'age'} = $co{'age_string'};
986 } elsif (defined($tag{'epoch'})) {
987 my $age = time - $tag{'epoch'};
988 $ref_item{'epoch'} = $tag{'epoch'};
989 $ref_item{'age'} = age_string
($age);
991 $ref_item{'reftype'} = $tag{'type'};
992 $ref_item{'name'} = $tag{'name'};
993 $ref_item{'refid'} = $tag{'object'};
994 } elsif ($type eq "commit"){
995 my %co = parse_commit
($ref_id);
996 $ref_item{'reftype'} = "commit";
997 $ref_item{'name'} = $ref_file;
998 $ref_item{'title'} = $co{'title'};
999 $ref_item{'refid'} = $ref_id;
1000 $ref_item{'epoch'} = $co{'committer_epoch'};
1001 $ref_item{'age'} = $co{'age_string'};
1003 $ref_item{'reftype'} = $type;
1004 $ref_item{'name'} = $ref_file;
1005 $ref_item{'refid'} = $ref_id;
1011 # parse line of git-diff-tree "raw" output
1012 sub parse_difftree_raw_line
{
1016 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1017 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1018 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1019 $res{'from_mode'} = $1;
1020 $res{'to_mode'} = $2;
1021 $res{'from_id'} = $3;
1023 $res{'status'} = $5;
1024 $res{'similarity'} = $6;
1025 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1026 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1028 $res{'file'} = unquote
($7);
1031 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1032 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1033 $res{'commit'} = $1;
1036 return wantarray ?
%res : \
%res;
1039 # parse line of git-ls-tree output
1040 sub parse_ls_tree_line
($;%) {
1045 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1046 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1054 $res{'name'} = unquote
($4);
1057 return wantarray ?
%res : \
%res;
1060 ## ......................................................................
1061 ## parse to array of hashes functions
1063 sub git_get_refs_list
{
1064 my $ref_dir = shift;
1068 my $pfxlen = length("$projectroot/$project/$ref_dir");
1069 File
::Find
::find
(sub {
1072 push @refs, substr($File::Find
::name
, $pfxlen + 1);
1074 }, "$projectroot/$project/$ref_dir");
1076 foreach my $ref_file (@refs) {
1077 my $ref_id = git_get_hash_by_ref
("$project/$ref_dir/$ref_file");
1078 my $type = git_get_type
($ref_id) || next;
1079 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1081 push @reflist, \
%ref_item;
1084 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1088 ## ----------------------------------------------------------------------
1089 ## filesystem-related functions
1091 sub get_file_owner
{
1094 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1095 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1096 if (!defined $gcos) {
1100 $owner =~ s/[,;].*$//;
1101 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
1104 ## ......................................................................
1105 ## mimetype related functions
1107 sub mimetype_guess_file
{
1108 my $filename = shift;
1109 my $mimemap = shift;
1110 -r
$mimemap or return undef;
1113 open(MIME
, $mimemap) or return undef;
1115 next if m/^#/; # skip comments
1116 my ($mime, $exts) = split(/\t+/);
1117 if (defined $exts) {
1118 my @exts = split(/\s+/, $exts);
1119 foreach my $ext (@exts) {
1120 $mimemap{$ext} = $mime;
1126 $filename =~ /\.(.*?)$/;
1127 return $mimemap{$1};
1130 sub mimetype_guess
{
1131 my $filename = shift;
1133 $filename =~ /\./ or return undef;
1135 if ($mimetypes_file) {
1136 my $file = $mimetypes_file;
1137 if ($file !~ m!^/!) { # if it is relative path
1138 # it is relative to project
1139 $file = "$projectroot/$project/$file";
1141 $mime = mimetype_guess_file
($filename, $file);
1143 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1149 my $filename = shift;
1152 my $mime = mimetype_guess
($filename);
1153 $mime and return $mime;
1157 return $default_blob_plain_mimetype unless $fd;
1160 return 'text/plain' .
1161 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1162 } elsif (! $filename) {
1163 return 'application/octet-stream';
1164 } elsif ($filename =~ m/\.png$/i) {
1166 } elsif ($filename =~ m/\.gif$/i) {
1168 } elsif ($filename =~ m/\.jpe?g$/i) {
1169 return 'image/jpeg';
1171 return 'application/octet-stream';
1175 ## ======================================================================
1176 ## functions printing HTML: header, footer, error page
1178 sub git_header_html
{
1179 my $status = shift || "200 OK";
1180 my $expires = shift;
1182 my $title = "$site_name git";
1183 if (defined $project) {
1184 $title .= " - $project";
1185 if (defined $action) {
1186 $title .= "/$action";
1187 if (defined $file_name) {
1188 $title .= " - $file_name";
1189 if ($action eq "tree" && $file_name !~ m
|/$|) {
1196 # require explicit support from the UA if we are to send the page as
1197 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1198 # we have to do this because MSIE sometimes globs '*/*', pretending to
1199 # support xhtml+xml but choking when it gets what it asked for.
1200 if (defined $cgi->http('HTTP_ACCEPT') &&
1201 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1202 $cgi->Accept('application/xhtml+xml') != 0) {
1203 $content_type = 'application/xhtml+xml';
1205 $content_type = 'text/html';
1207 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1208 -status
=> $status, -expires
=> $expires);
1210 <?xml version="1.0" encoding="utf-8"?>
1211 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1212 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1213 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1214 <!-- git core binaries version $git_version -->
1216 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1217 <meta name="generator" content="gitweb/$version git/$git_version"/>
1218 <meta name="robots" content="index, nofollow"/>
1219 <title>$title</title>
1220 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1222 if (defined $project) {
1223 printf('<link rel="alternate" title="%s log" '.
1224 'href="%s" type="application/rss+xml"/>'."\n",
1225 esc_param
($project), href
(action
=>"rss"));
1227 if (defined $favicon) {
1228 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
1233 "<div class=\"page_header\">\n" .
1234 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1235 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1237 print $cgi->a({-href
=> esc_param
($home_link)}, $home_link_str) . " / ";
1238 if (defined $project) {
1239 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1240 if (defined $action) {
1244 if (!defined $searchtext) {
1248 if (defined $hash_base) {
1249 $search_hash = $hash_base;
1250 } elsif (defined $hash) {
1251 $search_hash = $hash;
1253 $search_hash = "HEAD";
1255 $cgi->param("a", "search");
1256 $cgi->param("h", $search_hash);
1257 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1258 "<div class=\"search\">\n" .
1259 $cgi->hidden(-name
=> "p") . "\n" .
1260 $cgi->hidden(-name
=> "a") . "\n" .
1261 $cgi->hidden(-name
=> "h") . "\n" .
1262 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1264 $cgi->end_form() . "\n";
1269 sub git_footer_html
{
1270 print "<div class=\"page_footer\">\n";
1271 if (defined $project) {
1272 my $descr = git_get_project_description
($project);
1273 if (defined $descr) {
1274 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1276 print $cgi->a({-href
=> href
(action
=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1278 print $cgi->a({-href
=> href
(action
=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1286 my $status = shift || "403 Forbidden";
1287 my $error = shift || "Malformed query, file missing or permission denied";
1289 git_header_html
($status);
1291 <div class="page_body">
1301 ## ----------------------------------------------------------------------
1302 ## functions printing or outputting HTML: navigation
1304 sub git_print_page_nav
{
1305 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1306 $extra = '' if !defined $extra; # pager or formats
1308 my @navs = qw(summary shortlog log commit commitdiff tree);
1310 @navs = grep { $_ ne $suppress } @navs;
1313 my %arg = map { $_ => {action
=>$_} } @navs;
1314 if (defined $head) {
1315 for (qw(commit commitdiff)) {
1316 $arg{$_}{hash
} = $head;
1318 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1319 for (qw(shortlog log)) {
1320 $arg{$_}{hash
} = $head;
1324 $arg{tree
}{hash
} = $treehead if defined $treehead;
1325 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1327 print "<div class=\"page_nav\">\n" .
1329 map { $_ eq $current ?
1330 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1332 print "<br/>\n$extra<br/>\n" .
1336 sub format_paging_nav
{
1337 my ($action, $hash, $head, $page, $nrevs) = @_;
1341 if ($hash ne $head || $page) {
1342 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1344 $paging_nav .= "HEAD";
1348 $paging_nav .= " ⋅ " .
1349 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1350 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1352 $paging_nav .= " ⋅ prev";
1355 if ($nrevs >= (100 * ($page+1)-1)) {
1356 $paging_nav .= " ⋅ " .
1357 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1358 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1360 $paging_nav .= " ⋅ next";
1366 ## ......................................................................
1367 ## functions printing or outputting HTML: div
1369 sub git_print_header_div
{
1370 my ($action, $title, $hash, $hash_base) = @_;
1373 $args{action
} = $action;
1374 $args{hash
} = $hash if $hash;
1375 $args{hash_base
} = $hash_base if $hash_base;
1377 print "<div class=\"header\">\n" .
1378 $cgi->a({-href
=> href
(%args), -class => "title"},
1379 $title ?
$title : $action) .
1383 #sub git_print_authorship (\%) {
1384 sub git_print_authorship
{
1387 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1388 print "<div class=\"author_date\">" .
1389 esc_html
($co->{'author_name'}) .
1391 if ($ad{'hour_local'} < 6) {
1392 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1393 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1395 printf(" (%02d:%02d %s)",
1396 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1401 sub git_print_page_path
{
1406 if (!defined $name) {
1407 print "<div class=\"page_path\">/</div>\n";
1409 my @dirname = split '/', $name;
1410 my $basename = pop @dirname;
1413 print "<div class=\"page_path\">";
1414 foreach my $dir (@dirname) {
1415 $fullname .= $dir . '/';
1416 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1418 -title
=> $fullname}, esc_html
($dir));
1421 if (defined $type && $type eq 'blob') {
1422 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1424 -title
=> $name}, esc_html
($basename));
1425 } elsif (defined $type && $type eq 'tree') {
1426 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1428 -title
=> $name}, esc_html
($basename));
1431 print esc_html
($basename);
1433 print "<br/></div>\n";
1437 # sub git_print_log (\@;%) {
1438 sub git_print_log
($;%) {
1442 if ($opts{'-remove_title'}) {
1443 # remove title, i.e. first line of log
1446 # remove leading empty lines
1447 while (defined $log->[0] && $log->[0] eq "") {
1454 foreach my $line (@
$log) {
1455 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1458 if (! $opts{'-remove_signoff'}) {
1459 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1462 # remove signoff lines
1469 # print only one empty line
1470 # do not print empty line after signoff
1472 next if ($empty || $signoff);
1478 print format_log_line_html
($line) . "<br/>\n";
1481 if ($opts{'-final_empty_line'}) {
1482 # end with single empty line
1483 print "<br/>\n" unless $empty;
1487 sub git_print_simplified_log
{
1489 my $remove_title = shift;
1492 -final_empty_line
=> 1,
1493 -remove_title
=> $remove_title);
1496 # print tree entry (row of git_tree), but without encompassing <tr> element
1497 sub git_print_tree_entry
{
1498 my ($t, $basedir, $hash_base, $have_blame) = @_;
1501 $base_key{hash_base
} = $hash_base if defined $hash_base;
1503 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1504 if ($t->{'type'} eq "blob") {
1505 print "<td class=\"list\">" .
1506 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1507 file_name
=>"$basedir$t->{'name'}", %base_key),
1508 -class => "list"}, esc_html
($t->{'name'})) .
1510 "<td class=\"link\">" .
1511 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1512 file_name
=>"$basedir$t->{'name'}", %base_key)},
1516 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1517 file_name
=>"$basedir$t->{'name'}", %base_key)},
1520 if (defined $hash_base) {
1522 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1523 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1527 $cgi->a({-href
=> href
(action
=>"blob_plain",
1528 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1532 } elsif ($t->{'type'} eq "tree") {
1533 print "<td class=\"list\">" .
1534 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1535 file_name
=>"$basedir$t->{'name'}", %base_key)},
1536 esc_html
($t->{'name'})) .
1538 "<td class=\"link\">" .
1539 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1540 file_name
=>"$basedir$t->{'name'}", %base_key)},
1542 if (defined $hash_base) {
1544 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1545 file_name
=>"$basedir$t->{'name'}")},
1552 ## ......................................................................
1553 ## functions printing large fragments of HTML
1555 sub git_difftree_body
{
1556 my ($difftree, $hash, $parent) = @_;
1558 print "<div class=\"list_head\">\n";
1559 if ($#{$difftree} > 10) {
1560 print(($#{$difftree} + 1) . " files changed:\n");
1564 print "<table class=\"diff_tree\">\n";
1567 foreach my $line (@
{$difftree}) {
1568 my %diff = parse_difftree_raw_line
($line);
1571 print "<tr class=\"dark\">\n";
1573 print "<tr class=\"light\">\n";
1577 my ($to_mode_oct, $to_mode_str, $to_file_type);
1578 my ($from_mode_oct, $from_mode_str, $from_file_type);
1579 if ($diff{'to_mode'} ne ('0' x
6)) {
1580 $to_mode_oct = oct $diff{'to_mode'};
1581 if (S_ISREG
($to_mode_oct)) { # only for regular file
1582 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1584 $to_file_type = file_type
($diff{'to_mode'});
1586 if ($diff{'from_mode'} ne ('0' x
6)) {
1587 $from_mode_oct = oct $diff{'from_mode'};
1588 if (S_ISREG
($to_mode_oct)) { # only for regular file
1589 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1591 $from_file_type = file_type
($diff{'from_mode'});
1594 if ($diff{'status'} eq "A") { # created
1595 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1596 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1597 $mode_chng .= "]</span>";
1599 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1600 hash_base
=>$hash, file_name
=>$diff{'file'}),
1601 -class => "list"}, esc_html
($diff{'file'})) .
1603 "<td>$mode_chng</td>\n" .
1604 "<td class=\"link\">" .
1605 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1606 hash_base
=>$hash, file_name
=>$diff{'file'})},
1608 if ($action eq 'commitdiff') {
1612 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1616 } elsif ($diff{'status'} eq "D") { # deleted
1617 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1619 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1620 hash_base
=>$parent, file_name
=>$diff{'file'}),
1621 -class => "list"}, esc_html
($diff{'file'})) .
1623 "<td>$mode_chng</td>\n" .
1624 "<td class=\"link\">" .
1625 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1626 hash_base
=>$parent, file_name
=>$diff{'file'})},
1629 if ($action eq 'commitdiff') {
1633 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1635 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1636 file_name
=>$diff{'file'})},
1640 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1641 my $mode_chnge = "";
1642 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1643 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1644 if ($from_file_type != $to_file_type) {
1645 $mode_chnge .= " from $from_file_type to $to_file_type";
1647 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1648 if ($from_mode_str && $to_mode_str) {
1649 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1650 } elsif ($to_mode_str) {
1651 $mode_chnge .= " mode: $to_mode_str";
1654 $mode_chnge .= "]</span>\n";
1657 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1658 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1659 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1660 hash_base
=>$hash, hash_parent_base
=>$parent,
1661 file_name
=>$diff{'file'}),
1662 -class => "list"}, esc_html
($diff{'file'}));
1663 } else { # only mode changed
1664 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1665 hash_base
=>$hash, file_name
=>$diff{'file'}),
1666 -class => "list"}, esc_html
($diff{'file'}));
1669 "<td>$mode_chnge</td>\n" .
1670 "<td class=\"link\">" .
1671 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1672 hash_base
=>$hash, file_name
=>$diff{'file'})},
1674 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1675 if ($action eq 'commitdiff') {
1679 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1682 $cgi->a({-href
=> href
(action
=>"blobdiff",
1683 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1684 hash_base
=>$hash, hash_parent_base
=>$parent,
1685 file_name
=>$diff{'file'})},
1690 $cgi->a({-href
=> href
(action
=>"history",
1691 hash_base
=>$hash, file_name
=>$diff{'file'})},
1695 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1696 my %status_name = ('R' => 'moved', 'C' => 'copied');
1697 my $nstatus = $status_name{$diff{'status'}};
1699 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1700 # mode also for directories, so we cannot use $to_mode_str
1701 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1704 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1705 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1706 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1707 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1708 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1709 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1710 -class => "list"}, esc_html
($diff{'from_file'})) .
1711 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1712 "<td class=\"link\">" .
1713 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1714 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'})},
1716 if ($diff{'to_id'} ne $diff{'from_id'}) {
1717 if ($action eq 'commitdiff') {
1721 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1724 $cgi->a({-href
=> href
(action
=>"blobdiff",
1725 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1726 hash_base
=>$hash, hash_parent_base
=>$parent,
1727 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1733 } # we should not encounter Unmerged (U) or Unknown (X) status
1739 sub git_patchset_body
{
1740 my ($fd, $difftree, $hash, $hash_parent) = @_;
1744 my $patch_found = 0;
1747 print "<div class=\"patchset\">\n";
1750 while (my $patch_line = <$fd>) {
1753 if ($patch_line =~ m/^diff /) { # "git diff" header
1754 # beginning of patch (in patchset)
1756 # close previous patch
1757 print "</div>\n"; # class="patch"
1759 # first patch in patchset
1762 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1764 if (ref($difftree->[$patch_idx]) eq "HASH") {
1765 $diffinfo = $difftree->[$patch_idx];
1767 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1771 # for now, no extended header, hence we skip empty patches
1772 # companion to next LINE if $in_header;
1773 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1778 if ($diffinfo->{'status'} eq "A") { # added
1779 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1780 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1781 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1782 $diffinfo->{'to_id'}) . "(new)" .
1783 "</div>\n"; # class="diff_info"
1785 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1786 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
1787 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1788 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1789 $diffinfo->{'from_id'}) . "(deleted)" .
1790 "</div>\n"; # class="diff_info"
1792 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1793 $diffinfo->{'status'} eq "C" || # copied
1794 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1795 print "<div class=\"diff_info\">" .
1796 file_type
($diffinfo->{'from_mode'}) . ":" .
1797 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1798 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
1799 $diffinfo->{'from_id'}) .
1801 file_type
($diffinfo->{'to_mode'}) . ":" .
1802 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1803 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
1804 $diffinfo->{'to_id'});
1805 print "</div>\n"; # class="diff_info"
1807 } else { # modified, mode changed, ...
1808 print "<div class=\"diff_info\">" .
1809 file_type
($diffinfo->{'from_mode'}) . ":" .
1810 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1811 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1812 $diffinfo->{'from_id'}) .
1814 file_type
($diffinfo->{'to_mode'}) . ":" .
1815 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1816 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1817 $diffinfo->{'to_id'});
1818 print "</div>\n"; # class="diff_info"
1821 #print "<div class=\"diff extended_header\">\n";
1824 } # start of patch in patchset
1827 if ($in_header && $patch_line =~ m/^---/) {
1828 #print "</div>\n"; # class="diff extended_header"
1831 my $file = $diffinfo->{'from_file'};
1832 $file ||= $diffinfo->{'file'};
1833 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1834 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
1835 -class => "list"}, esc_html
($file));
1836 $patch_line =~ s
|a
/.*$|a/$file|g
;
1837 print "<div class=\"diff from_file\">$patch_line</div>\n";
1839 $patch_line = <$fd>;
1842 #$patch_line =~ m/^+++/;
1843 $file = $diffinfo->{'to_file'};
1844 $file ||= $diffinfo->{'file'};
1845 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1846 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
1847 -class => "list"}, esc_html
($file));
1848 $patch_line =~ s
|b
/.*|b/$file|g
;
1849 print "<div class=\"diff to_file\">$patch_line</div>\n";
1853 next LINE
if $in_header;
1855 print format_diff_line
($patch_line);
1857 print "</div>\n" if $patch_found; # class="patch"
1859 print "</div>\n"; # class="patchset"
1862 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1864 sub git_shortlog_body
{
1865 # uses global variable $project
1866 my ($revlist, $from, $to, $refs, $extra) = @_;
1868 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
1869 my $have_snapshot = (defined $ctype && defined $suffix);
1871 $from = 0 unless defined $from;
1872 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1874 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1876 for (my $i = $from; $i <= $to; $i++) {
1877 my $commit = $revlist->[$i];
1878 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1879 my $ref = format_ref_marker
($refs, $commit);
1880 my %co = parse_commit
($commit);
1882 print "<tr class=\"dark\">\n";
1884 print "<tr class=\"light\">\n";
1887 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1888 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1889 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1891 print format_subject_html
($co{'title'}, $co{'title_short'},
1892 href
(action
=>"commit", hash
=>$commit), $ref);
1894 "<td class=\"link\">" .
1895 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1896 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
1897 if ($have_snapshot) {
1898 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
1903 if (defined $extra) {
1905 "<td colspan=\"4\">$extra</td>\n" .
1911 sub git_history_body
{
1912 # Warning: assumes constant type (blob or tree) during history
1913 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1915 print "<table class=\"history\" cellspacing=\"0\">\n";
1917 while (my $line = <$fd>) {
1918 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1923 my %co = parse_commit
($commit);
1928 my $ref = format_ref_marker
($refs, $commit);
1931 print "<tr class=\"dark\">\n";
1933 print "<tr class=\"light\">\n";
1936 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1937 # shortlog uses chop_str($co{'author_name'}, 10)
1938 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1940 # originally git_history used chop_str($co{'title'}, 50)
1941 print format_subject_html
($co{'title'}, $co{'title_short'},
1942 href
(action
=>"commit", hash
=>$commit), $ref);
1944 "<td class=\"link\">" .
1945 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1946 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
1947 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype);
1949 if ($ftype eq 'blob') {
1950 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
1951 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
1952 if (defined $blob_current && defined $blob_parent &&
1953 $blob_current ne $blob_parent) {
1955 $cgi->a({-href
=> href
(action
=>"blobdiff",
1956 hash
=>$blob_current, hash_parent
=>$blob_parent,
1957 hash_base
=>$hash_base, hash_parent_base
=>$commit,
1958 file_name
=>$file_name)},
1965 if (defined $extra) {
1967 "<td colspan=\"4\">$extra</td>\n" .
1974 # uses global variable $project
1975 my ($taglist, $from, $to, $extra) = @_;
1976 $from = 0 unless defined $from;
1977 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1979 print "<table class=\"tags\" cellspacing=\"0\">\n";
1981 for (my $i = $from; $i <= $to; $i++) {
1982 my $entry = $taglist->[$i];
1984 my $comment_lines = $tag{'comment'};
1985 my $comment = shift @
$comment_lines;
1987 if (defined $comment) {
1988 $comment_short = chop_str
($comment, 30, 5);
1991 print "<tr class=\"dark\">\n";
1993 print "<tr class=\"light\">\n";
1996 print "<td><i>$tag{'age'}</i></td>\n" .
1998 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
1999 -class => "list name"}, esc_html
($tag{'name'})) .
2002 if (defined $comment) {
2003 print format_subject_html
($comment, $comment_short,
2004 href
(action
=>"tag", hash
=>$tag{'id'}));
2007 "<td class=\"selflink\">";
2008 if ($tag{'type'} eq "tag") {
2009 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2014 "<td class=\"link\">" . " | " .
2015 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2016 if ($tag{'reftype'} eq "commit") {
2017 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2018 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
2019 } elsif ($tag{'reftype'} eq "blob") {
2020 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2025 if (defined $extra) {
2027 "<td colspan=\"5\">$extra</td>\n" .
2033 sub git_heads_body
{
2034 # uses global variable $project
2035 my ($taglist, $head, $from, $to, $extra) = @_;
2036 $from = 0 unless defined $from;
2037 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2039 print "<table class=\"heads\" cellspacing=\"0\">\n";
2041 for (my $i = $from; $i <= $to; $i++) {
2042 my $entry = $taglist->[$i];
2044 my $curr = $tag{'id'} eq $head;
2046 print "<tr class=\"dark\">\n";
2048 print "<tr class=\"light\">\n";
2051 print "<td><i>$tag{'age'}</i></td>\n" .
2052 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
2053 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
2054 -class => "list name"},esc_html
($tag{'name'})) .
2056 "<td class=\"link\">" .
2057 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
2058 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") .
2062 if (defined $extra) {
2064 "<td colspan=\"3\">$extra</td>\n" .
2070 ## ======================================================================
2071 ## ======================================================================
2074 sub git_project_list
{
2075 my $order = $cgi->param('o');
2076 if (defined $order && $order !~ m/project|descr|owner|age/) {
2077 die_error
(undef, "Unknown order parameter");
2080 my @list = git_get_projects_list
();
2083 die_error
(undef, "No projects found");
2085 foreach my $pr (@list) {
2086 my $head = git_get_head_hash
($pr->{'path'});
2087 if (!defined $head) {
2090 $git_dir = "$projectroot/$pr->{'path'}";
2091 my %co = parse_commit
($head);
2095 $pr->{'commit'} = \
%co;
2096 if (!defined $pr->{'descr'}) {
2097 my $descr = git_get_project_description
($pr->{'path'}) || "";
2098 $pr->{'descr'} = chop_str
($descr, 25, 5);
2100 if (!defined $pr->{'owner'}) {
2101 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2103 push @projects, $pr;
2107 if (-f
$home_text) {
2108 print "<div class=\"index_include\">\n";
2109 open (my $fd, $home_text);
2114 print "<table class=\"project_list\">\n" .
2116 $order ||= "project";
2117 if ($order eq "project") {
2118 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2119 print "<th>Project</th>\n";
2122 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
2123 -class => "header"}, "Project") .
2126 if ($order eq "descr") {
2127 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2128 print "<th>Description</th>\n";
2131 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
2132 -class => "header"}, "Description") .
2135 if ($order eq "owner") {
2136 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2137 print "<th>Owner</th>\n";
2140 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
2141 -class => "header"}, "Owner") .
2144 if ($order eq "age") {
2145 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2146 print "<th>Last Change</th>\n";
2149 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
2150 -class => "header"}, "Last Change") .
2153 print "<th></th>\n" .
2156 foreach my $pr (@projects) {
2158 print "<tr class=\"dark\">\n";
2160 print "<tr class=\"light\">\n";
2163 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2164 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2165 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2166 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2167 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2168 $pr->{'commit'}{'age_string'} . "</td>\n" .
2169 "<td class=\"link\">" .
2170 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2171 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2172 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") .
2181 my $descr = git_get_project_description
($project) || "none";
2182 my $head = git_get_head_hash
($project);
2183 my %co = parse_commit
($head);
2184 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2186 my $owner = git_get_project_owner
($project);
2188 my $refs = git_get_references
();
2190 git_print_page_nav
('summary','', $head);
2192 print "<div class=\"title\"> </div>\n";
2193 print "<table cellspacing=\"0\">\n" .
2194 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2195 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2196 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2197 # use per project git URL list in $projectroot/$project/cloneurl
2198 # or make project git URL from git base URL and project name
2199 my $url_tag = "URL";
2200 my @url_list = git_get_project_url_list
($project);
2201 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2202 foreach my $git_url (@url_list) {
2203 next unless $git_url;
2204 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2209 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2210 git_get_head_hash
($project)
2211 or die_error
(undef, "Open git-rev-list failed");
2212 my @revlist = map { chomp; $_ } <$fd>;
2214 git_print_header_div
('shortlog');
2215 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2216 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2218 my $taglist = git_get_refs_list
("refs/tags");
2219 if (defined @
$taglist) {
2220 git_print_header_div
('tags');
2221 git_tags_body
($taglist, 0, 15,
2222 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2225 my $headlist = git_get_refs_list
("refs/heads");
2226 if (defined @
$headlist) {
2227 git_print_header_div
('heads');
2228 git_heads_body
($headlist, $head, 0, 15,
2229 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2236 my $head = git_get_head_hash
($project);
2238 git_print_page_nav
('','', $head,undef,$head);
2239 my %tag = parse_tag
($hash);
2240 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2241 print "<div class=\"title_text\">\n" .
2242 "<table cellspacing=\"0\">\n" .
2244 "<td>object</td>\n" .
2245 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2246 $tag{'object'}) . "</td>\n" .
2247 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2248 $tag{'type'}) . "</td>\n" .
2250 if (defined($tag{'author'})) {
2251 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2252 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2253 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2254 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2257 print "</table>\n\n" .
2259 print "<div class=\"page_body\">";
2260 my $comment = $tag{'comment'};
2261 foreach my $line (@
$comment) {
2262 print esc_html
($line) . "<br/>\n";
2272 my ($have_blame) = gitweb_check_feature
('blame');
2274 die_error
('403 Permission denied', "Permission denied");
2276 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2277 $hash_base ||= git_get_head_hash
($project);
2278 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2279 my %co = parse_commit
($hash_base)
2280 or die_error
(undef, "Reading commit failed");
2281 if (!defined $hash) {
2282 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2283 or die_error
(undef, "Error looking up file");
2285 $ftype = git_get_type
($hash);
2286 if ($ftype !~ "blob") {
2287 die_error
("400 Bad Request", "Object is not a blob");
2289 open ($fd, "-|", git_cmd
(), "blame", '-l', $file_name, $hash_base)
2290 or die_error
(undef, "Open git-blame failed");
2293 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2296 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2298 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2299 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2300 git_print_page_path
($file_name, $ftype, $hash_base);
2301 my @rev_color = (qw(light2 dark2));
2302 my $num_colors = scalar(@rev_color);
2303 my $current_color = 0;
2306 <div class="page_body">
2307 <table class="blame">
2308 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2311 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2313 my $rev = substr($full_rev, 0, 8);
2317 if (!defined $last_rev) {
2318 $last_rev = $full_rev;
2319 } elsif ($last_rev ne $full_rev) {
2320 $last_rev = $full_rev;
2321 $current_color = ++$current_color % $num_colors;
2323 print "<tr class=\"$rev_color[$current_color]\">\n";
2324 print "<td class=\"sha1\">" .
2325 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)},
2326 esc_html
($rev)) . "</td>\n";
2327 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2328 esc_html
($lineno) . "</a></td>\n";
2329 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2335 or print "Reading blob failed\n";
2342 my ($have_blame) = gitweb_check_feature
('blame');
2344 die_error
('403 Permission denied', "Permission denied");
2346 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2347 $hash_base ||= git_get_head_hash
($project);
2348 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2349 my %co = parse_commit
($hash_base)
2350 or die_error
(undef, "Reading commit failed");
2351 if (!defined $hash) {
2352 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2353 or die_error
(undef, "Error lookup file");
2355 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2356 or die_error
(undef, "Open git-annotate failed");
2359 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2362 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2364 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2365 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2366 git_print_page_path
($file_name, 'blob', $hash_base);
2367 print "<div class=\"page_body\">\n";
2369 <table class="blame">
2378 my @line_class = (qw(light dark));
2379 my $line_class_len = scalar (@line_class);
2380 my $line_class_num = $#line_class;
2381 while (my $line = <$fd>) {
2393 $line_class_num = ($line_class_num + 1) % $line_class_len;
2395 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2402 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2405 $short_rev = substr ($long_rev, 0, 8);
2406 $age = time () - $time;
2407 $age_str = age_string
($age);
2408 $age_str =~ s/ / /g;
2409 $age_class = age_class
($age);
2410 $author = esc_html
($author);
2411 $author =~ s/ / /g;
2413 $data = untabify
($data);
2414 $data = esc_html
($data);
2417 <tr class="$line_class[$line_class_num]">
2418 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2419 <td class="$age_class">$age_str</td>
2421 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2422 <td class="pre">$data</td>
2425 } # while (my $line = <$fd>)
2426 print "</table>\n\n";
2428 or print "Reading blob failed.\n";
2434 my $head = git_get_head_hash
($project);
2436 git_print_page_nav
('','', $head,undef,$head);
2437 git_print_header_div
('summary', $project);
2439 my $taglist = git_get_refs_list
("refs/tags");
2440 if (defined @
$taglist) {
2441 git_tags_body
($taglist);
2447 my $head = git_get_head_hash
($project);
2449 git_print_page_nav
('','', $head,undef,$head);
2450 git_print_header_div
('summary', $project);
2452 my $taglist = git_get_refs_list
("refs/heads");
2453 if (defined @
$taglist) {
2454 git_heads_body
($taglist, $head);
2459 sub git_blob_plain
{
2460 # blobs defined by non-textual hash id's can be cached
2462 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2466 if (!defined $hash) {
2467 if (defined $file_name) {
2468 my $base = $hash_base || git_get_head_hash
($project);
2469 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2470 or die_error
(undef, "Error lookup file");
2472 die_error
(undef, "No file name defined");
2476 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2477 or die_error
(undef, "Couldn't cat $file_name, $hash");
2479 $type ||= blob_mimetype
($fd, $file_name);
2481 # save as filename, even when no $file_name is given
2482 my $save_as = "$hash";
2483 if (defined $file_name) {
2484 $save_as = $file_name;
2485 } elsif ($type =~ m/^text\//) {
2492 -content_disposition
=> "inline; filename=\"$save_as\"");
2494 binmode STDOUT
, ':raw';
2496 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2502 # blobs defined by non-textual hash id's can be cached
2504 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2508 if (!defined $hash) {
2509 if (defined $file_name) {
2510 my $base = $hash_base || git_get_head_hash
($project);
2511 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2512 or die_error
(undef, "Error lookup file");
2514 die_error
(undef, "No file name defined");
2517 my ($have_blame) = gitweb_check_feature
('blame');
2518 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2519 or die_error
(undef, "Couldn't cat $file_name, $hash");
2520 my $mimetype = blob_mimetype
($fd, $file_name);
2521 if ($mimetype !~ m/^text\//) {
2523 return git_blob_plain
($mimetype);
2525 git_header_html
(undef, $expires);
2526 my $formats_nav = '';
2527 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2528 if (defined $file_name) {
2531 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2532 hash
=>$hash, file_name
=>$file_name)},
2537 $cgi->a({-href
=> href
(action
=>"blob_plain",
2538 hash
=>$hash, file_name
=>$file_name)},
2541 $cgi->a({-href
=> href
(action
=>"blob",
2542 hash_base
=>"HEAD", file_name
=>$file_name)},
2546 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "plain");
2548 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2549 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2551 print "<div class=\"page_nav\">\n" .
2552 "<br/><br/></div>\n" .
2553 "<div class=\"title\">$hash</div>\n";
2555 git_print_page_path
($file_name, "blob", $hash_base);
2556 print "<div class=\"page_body\">\n";
2558 while (my $line = <$fd>) {
2561 $line = untabify
($line);
2562 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2563 $nr, $nr, $nr, esc_html
($line);
2566 or print "Reading blob failed.\n";
2572 if (!defined $hash) {
2573 $hash = git_get_head_hash
($project);
2574 if (defined $file_name) {
2575 my $base = $hash_base || $hash;
2576 $hash = git_get_hash_by_path
($base, $file_name, "tree");
2578 if (!defined $hash_base) {
2583 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
2584 or die_error
(undef, "Open git-ls-tree failed");
2585 my @entries = map { chomp; $_ } <$fd>;
2586 close $fd or die_error
(undef, "Reading tree failed");
2589 my $refs = git_get_references
();
2590 my $ref = format_ref_marker
($refs, $hash_base);
2593 my ($have_blame) = gitweb_check_feature
('blame');
2594 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2595 git_print_page_nav
('tree','', $hash_base);
2596 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2599 print "<div class=\"page_nav\">\n";
2600 print "<br/><br/></div>\n";
2601 print "<div class=\"title\">$hash</div>\n";
2603 if (defined $file_name) {
2604 $base = esc_html
("$file_name/");
2606 git_print_page_path
($file_name, 'tree', $hash_base);
2607 print "<div class=\"page_body\">\n";
2608 print "<table cellspacing=\"0\">\n";
2610 foreach my $line (@entries) {
2611 my %t = parse_ls_tree_line
($line, -z
=> 1);
2614 print "<tr class=\"dark\">\n";
2616 print "<tr class=\"light\">\n";
2620 git_print_tree_entry
(\
%t, $base, $hash_base, $have_blame);
2624 print "</table>\n" .
2631 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2632 my $have_snapshot = (defined $ctype && defined $suffix);
2633 if (!$have_snapshot) {
2634 die_error
('403 Permission denied', "Permission denied");
2637 if (!defined $hash) {
2638 $hash = git_get_head_hash
($project);
2641 my $filename = basename
($project) . "-$hash.tar.$suffix";
2643 print $cgi->header(-type
=> 'application/x-tar',
2644 -content_encoding
=> $ctype,
2645 -content_disposition
=> "inline; filename=\"$filename\"",
2646 -status
=> '200 OK');
2648 my $git_command = git_cmd_str
();
2649 open my $fd, "-|", "$git_command tar-tree $hash \'$project\' | $command" or
2650 die_error
(undef, "Execute git-tar-tree failed.");
2651 binmode STDOUT
, ':raw';
2653 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2659 my $head = git_get_head_hash
($project);
2660 if (!defined $hash) {
2663 if (!defined $page) {
2666 my $refs = git_get_references
();
2668 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2669 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
2670 or die_error
(undef, "Open git-rev-list failed");
2671 my @revlist = map { chomp; $_ } <$fd>;
2674 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2677 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2680 my %co = parse_commit
($hash);
2682 git_print_header_div
('summary', $project);
2683 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2685 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2686 my $commit = $revlist[$i];
2687 my $ref = format_ref_marker
($refs, $commit);
2688 my %co = parse_commit
($commit);
2690 my %ad = parse_date
($co{'author_epoch'});
2691 git_print_header_div
('commit',
2692 "<span class=\"age\">$co{'age_string'}</span>" .
2693 esc_html
($co{'title'}) . $ref,
2695 print "<div class=\"title_text\">\n" .
2696 "<div class=\"log_link\">\n" .
2697 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2699 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2702 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2705 print "<div class=\"log_body\">\n";
2706 git_print_simplified_log
($co{'comment'});
2713 my %co = parse_commit
($hash);
2715 die_error
(undef, "Unknown commit object");
2717 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2718 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2720 my $parent = $co{'parent'};
2721 if (!defined $parent) {
2724 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $parent, $hash
2725 or die_error
(undef, "Open git-diff-tree failed");
2726 my @difftree = map { chomp; $_ } <$fd>;
2727 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2729 # non-textual hash id's can be cached
2731 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2734 my $refs = git_get_references
();
2735 my $ref = format_ref_marker
($refs, $co{'id'});
2737 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2738 my $have_snapshot = (defined $ctype && defined $suffix);
2740 my $formats_nav = '';
2741 if (defined $file_name && defined $co{'parent'}) {
2742 my $parent = $co{'parent'};
2744 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
2747 git_header_html
(undef, $expires);
2748 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
2749 $hash, $co{'tree'}, $hash,
2752 if (defined $co{'parent'}) {
2753 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2755 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
2757 print "<div class=\"title_text\">\n" .
2758 "<table cellspacing=\"0\">\n";
2759 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2761 "<td></td><td> $ad{'rfc2822'}";
2762 if ($ad{'hour_local'} < 6) {
2763 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2764 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2766 printf(" (%02d:%02d %s)",
2767 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2771 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2772 print "<tr><td></td><td> $cd{'rfc2822'}" .
2773 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2775 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2778 "<td class=\"sha1\">" .
2779 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
2780 class => "list"}, $co{'tree'}) .
2782 "<td class=\"link\">" .
2783 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
2785 if ($have_snapshot) {
2787 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
2791 my $parents = $co{'parents'};
2792 foreach my $par (@
$parents) {
2795 "<td class=\"sha1\">" .
2796 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
2797 class => "list"}, $par) .
2799 "<td class=\"link\">" .
2800 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
2802 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
2809 print "<div class=\"page_body\">\n";
2810 git_print_log
($co{'comment'});
2813 git_difftree_body
(\
@difftree, $hash, $parent);
2819 my $format = shift || 'html';
2826 # preparing $fd and %diffinfo for git_patchset_body
2828 if (defined $hash_base && defined $hash_parent_base) {
2829 if (defined $file_name) {
2831 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
2833 or die_error
(undef, "Open git-diff-tree failed");
2834 @difftree = map { chomp; $_ } <$fd>;
2836 or die_error
(undef, "Reading git-diff-tree failed");
2838 or die_error
('404 Not Found', "Blob diff not found");
2840 } elsif (defined $hash &&
2841 $hash =~ /[0-9a-fA-F]{40}/) {
2842 # try to find filename from $hash
2844 # read filtered raw output
2845 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
2846 or die_error
(undef, "Open git-diff-tree failed");
2848 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
2850 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
2851 map { chomp; $_ } <$fd>;
2853 or die_error
(undef, "Reading git-diff-tree failed");
2855 or die_error
('404 Not Found', "Blob diff not found");
2858 die_error
('404 Not Found', "Missing one of the blob diff parameters");
2861 if (@difftree > 1) {
2862 die_error
('404 Not Found', "Ambiguous blob diff specification");
2865 %diffinfo = parse_difftree_raw_line
($difftree[0]);
2866 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
2867 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
2869 $hash_parent ||= $diffinfo{'from_id'};
2870 $hash ||= $diffinfo{'to_id'};
2872 # non-textual hash id's can be cached
2873 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
2874 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
2879 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
2880 '-p', $hash_parent_base, $hash_base,
2882 or die_error
(undef, "Open git-diff-tree failed");
2885 # old/legacy style URI
2886 if (!%diffinfo && # if new style URI failed
2887 defined $hash && defined $hash_parent) {
2888 # fake git-diff-tree raw output
2889 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
2890 $diffinfo{'from_id'} = $hash_parent;
2891 $diffinfo{'to_id'} = $hash;
2892 if (defined $file_name) {
2893 if (defined $file_parent) {
2894 $diffinfo{'status'} = '2';
2895 $diffinfo{'from_file'} = $file_parent;
2896 $diffinfo{'to_file'} = $file_name;
2897 } else { # assume not renamed
2898 $diffinfo{'status'} = '1';
2899 $diffinfo{'from_file'} = $file_name;
2900 $diffinfo{'to_file'} = $file_name;
2902 } else { # no filename given
2903 $diffinfo{'status'} = '2';
2904 $diffinfo{'from_file'} = $hash_parent;
2905 $diffinfo{'to_file'} = $hash;
2908 # non-textual hash id's can be cached
2909 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
2910 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
2915 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts, $hash_parent, $hash
2916 or die_error
(undef, "Open git-diff failed");
2918 die_error
('404 Not Found', "Missing one of the blob diff parameters")
2923 if ($format eq 'html') {
2925 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
2926 hash
=>$hash, hash_parent
=>$hash_parent,
2927 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
2928 file_name
=>$file_name, file_parent
=>$file_parent)},
2930 git_header_html
(undef, $expires);
2931 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2932 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2933 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2935 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
2936 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
2938 if (defined $file_name) {
2939 git_print_page_path
($file_name, "blob", $hash_base);
2941 print "<div class=\"page_path\"></div>\n";
2944 } elsif ($format eq 'plain') {
2946 -type
=> 'text/plain',
2947 -charset
=> 'utf-8',
2948 -expires
=> $expires,
2949 -content_disposition
=> qq(inline
; filename
="${file_name}.patch"));
2951 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
2954 die_error
(undef, "Unknown blobdiff format");
2958 if ($format eq 'html') {
2959 print "<div class=\"page_body\">\n";
2961 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
2964 print "</div>\n"; # class="page_body"
2968 while (my $line = <$fd>) {
2969 $line =~ s!a/($hash|$hash_parent)!a/$diffinfo{'from_file'}!g;
2970 $line =~ s!b/($hash|$hash_parent)!b/$diffinfo{'to_file'}!g;
2974 last if $line =~ m!^\+\+\+!;
2982 sub git_blobdiff_plain
{
2983 git_blobdiff
('plain');
2986 sub git_commitdiff
{
2987 my $format = shift || 'html';
2988 my %co = parse_commit
($hash);
2990 die_error
(undef, "Unknown commit object");
2992 if (!defined $hash_parent) {
2993 $hash_parent = $co{'parent'} || '--root';
2999 if ($format eq 'html') {
3000 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3001 "--patch-with-raw", "--full-index", $hash_parent, $hash
3002 or die_error
(undef, "Open git-diff-tree failed");
3004 while (chomp(my $line = <$fd>)) {
3005 # empty line ends raw part of diff-tree output
3007 push @difftree, $line;
3010 } elsif ($format eq 'plain') {
3011 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3012 '-p', $hash_parent, $hash
3013 or die_error
(undef, "Open git-diff-tree failed");
3016 die_error
(undef, "Unknown commitdiff format");
3019 # non-textual hash id's can be cached
3021 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3025 # write commit message
3026 if ($format eq 'html') {
3027 my $refs = git_get_references
();
3028 my $ref = format_ref_marker
($refs, $co{'id'});
3030 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3031 hash
=>$hash, hash_parent
=>$hash_parent)},
3034 git_header_html
(undef, $expires);
3035 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3036 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3037 git_print_authorship
(\
%co);
3038 print "<div class=\"page_body\">\n";
3039 print "<div class=\"log\">\n";
3040 git_print_simplified_log
($co{'comment'}, 1); # skip title
3041 print "</div>\n"; # class="log"
3043 } elsif ($format eq 'plain') {
3044 my $refs = git_get_references
("tags");
3045 my $tagname = git_get_rev_name_tags
($hash);
3046 my $filename = basename
($project) . "-$hash.patch";
3049 -type
=> 'text/plain',
3050 -charset
=> 'utf-8',
3051 -expires
=> $expires,
3052 -content_disposition
=> qq(inline
; filename
="$filename"));
3053 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3056 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3057 Subject: $co{'title'}
3059 print "X-Git-Tag: $tagname\n" if $tagname;
3060 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3062 foreach my $line (@
{$co{'comment'}}) {
3069 if ($format eq 'html') {
3070 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3073 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3075 print "</div>\n"; # class="page_body"
3078 } elsif ($format eq 'plain') {
3082 or print "Reading git-diff-tree failed\n";
3086 sub git_commitdiff_plain
{
3087 git_commitdiff
('plain');
3091 if (!defined $hash_base) {
3092 $hash_base = git_get_head_hash
($project);
3095 my %co = parse_commit
($hash_base);
3097 die_error
(undef, "Unknown commit object");
3099 my $refs = git_get_references
();
3101 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
3102 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3103 if (!defined $hash && defined $file_name) {
3104 $hash = git_get_hash_by_path
($hash_base, $file_name);
3106 if (defined $hash) {
3107 $ftype = git_get_type
($hash);
3109 git_print_page_path
($file_name, $ftype, $hash_base);
3112 git_cmd
(), "rev-list", "--full-history", $hash_base, "--", $file_name;
3114 git_history_body
($fd, $refs, $hash_base, $ftype);
3121 if (!defined $searchtext) {
3122 die_error
(undef, "Text field empty");
3124 if (!defined $hash) {
3125 $hash = git_get_head_hash
($project);
3127 my %co = parse_commit
($hash);
3129 die_error
(undef, "Unknown commit object");
3131 # pickaxe may take all resources of your box and run for several minutes
3132 # with every query - so decide by yourself how public you make this feature :)
3133 my $commit_search = 1;
3134 my $author_search = 0;
3135 my $committer_search = 0;
3136 my $pickaxe_search = 0;
3137 if ($searchtext =~ s/^author\\://i) {
3139 } elsif ($searchtext =~ s/^committer\\://i) {
3140 $committer_search = 1;
3141 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3143 $pickaxe_search = 1;
3146 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3147 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3149 print "<table cellspacing=\"0\">\n";
3151 if ($commit_search) {
3153 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", $hash or next;
3154 while (my $commit_text = <$fd>) {
3155 if (!grep m/$searchtext/i, $commit_text) {
3158 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3161 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3164 my @commit_lines = split "\n", $commit_text;
3165 my %co = parse_commit
(undef, \
@commit_lines);
3170 print "<tr class=\"dark\">\n";
3172 print "<tr class=\"light\">\n";
3175 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3176 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3178 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3179 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3180 my $comment = $co{'comment'};
3181 foreach my $line (@
$comment) {
3182 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3183 my $lead = esc_html
($1) || "";
3184 $lead = chop_str
($lead, 30, 10);
3185 my $match = esc_html
($2) || "";
3186 my $trail = esc_html
($3) || "";
3187 $trail = chop_str
($trail, 30, 10);
3188 my $text = "$lead<span class=\"match\">$match</span>$trail";
3189 print chop_str
($text, 80, 5) . "<br/>\n";
3193 "<td class=\"link\">" .
3194 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3196 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3203 if ($pickaxe_search) {
3205 my $git_command = git_cmd_str
();
3206 open my $fd, "-|", "$git_command rev-list $hash | " .
3207 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3210 while (my $line = <$fd>) {
3211 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3214 $set{'from_id'} = $3;
3216 $set{'id'} = $set{'to_id'};
3217 if ($set{'id'} =~ m/0{40}/) {
3218 $set{'id'} = $set{'from_id'};
3220 if ($set{'id'} =~ m/0{40}/) {
3224 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3227 print "<tr class=\"dark\">\n";
3229 print "<tr class=\"light\">\n";
3232 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3233 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3235 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3236 -class => "list subject"},
3237 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3238 while (my $setref = shift @files) {
3240 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3241 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3243 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3247 "<td class=\"link\">" .
3248 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3250 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3254 %co = parse_commit
($1);
3264 my $head = git_get_head_hash
($project);
3265 if (!defined $hash) {
3268 if (!defined $page) {
3271 my $refs = git_get_references
();
3273 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3274 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3275 or die_error
(undef, "Open git-rev-list failed");
3276 my @revlist = map { chomp; $_ } <$fd>;
3279 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3281 if ($#revlist >= (100 * ($page+1)-1)) {
3283 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3284 -title
=> "Alt-n"}, "next");
3289 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3290 git_print_header_div
('summary', $project);
3292 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3297 ## ......................................................................
3298 ## feeds (RSS, OPML)
3301 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3302 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150", git_get_head_hash
($project)
3303 or die_error
(undef, "Open git-rev-list failed");
3304 my @revlist = map { chomp; $_ } <$fd>;
3305 close $fd or die_error
(undef, "Reading git-rev-list failed");
3306 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3308 <?xml version="1.0" encoding="utf-8"?>
3309 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3311 <title>$project $my_uri $my_url</title>
3312 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3313 <description>$project log</description>
3314 <language>en</language>
3317 for (my $i = 0; $i <= $#revlist; $i++) {
3318 my $commit = $revlist[$i];
3319 my %co = parse_commit
($commit);
3320 # we read 150, we always show 30 and the ones more recent than 48 hours
3321 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3324 my %cd = parse_date
($co{'committer_epoch'});
3325 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3326 $co{'parent'}, $co{'id'}
3328 my @difftree = map { chomp; $_ } <$fd>;
3333 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3335 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3336 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3337 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3338 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3339 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3340 "<content:encoded>" .
3342 my $comment = $co{'comment'};
3343 foreach my $line (@
$comment) {
3344 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
3345 print "$line<br/>\n";
3348 foreach my $line (@difftree) {
3349 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3352 my $file = validate_input
(unquote
($7));
3353 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
3354 print "$file<br/>\n";
3357 "</content:encoded>\n" .
3360 print "</channel></rss>";
3364 my @list = git_get_projects_list
();
3366 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3368 <?xml version="1.0" encoding="utf-8"?>
3369 <opml version="1.0">
3371 <title>$site_name Git OPML Export</title>
3374 <outline text="git RSS feeds">
3377 foreach my $pr (@list) {
3379 my $head = git_get_head_hash
($proj{'path'});
3380 if (!defined $head) {
3383 $git_dir = "$projectroot/$proj{'path'}";
3384 my %co = parse_commit
($head);
3389 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3390 my $rss = "$my_url?p=$proj{'path'};a=rss";
3391 my $html = "$my_url?p=$proj{'path'};a=summary";
3392 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";