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 # show repository only if this file exists
58 # (only effective if this variable evaluates to true)
59 our $export_ok = "++GITWEB_EXPORT_OK++";
61 # only allow viewing of repositories also shown on the overview page
62 our $strict_export = "++GITWEB_STRICT_EXPORT++";
64 # list of git base URLs used for URL to where fetch project from,
65 # i.e. full URL is "$git_base_url/$project"
66 our @git_base_url_list = ("++GITWEB_BASE_URL++");
68 # default blob_plain mimetype and default charset for text/plain blob
69 our $default_blob_plain_mimetype = 'text/plain';
70 our $default_text_plain_charset = undef;
72 # file to use for guessing MIME types before trying /etc/mime.types
73 # (relative to the current git repository)
74 our $mimetypes_file = undef;
76 # You define site-wide feature defaults here; override them with
77 # $GITWEB_CONFIG as necessary.
80 # 'sub' => feature-sub (subroutine),
81 # 'override' => allow-override (boolean),
82 # 'default' => [ default options...] (array reference)}
84 # if feature is overridable (it means that allow-override has true value,
85 # then feature-sub will be called with default options as parameters;
86 # return value of feature-sub indicates if to enable specified feature
88 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
91 'sub' => \
&feature_blame
,
96 'sub' => \
&feature_snapshot
,
98 # => [content-encoding, suffix, program]
99 'default' => ['x-gzip', 'gz', 'gzip']},
102 'sub' => \
&feature_pickaxe
,
111 sub gitweb_check_feature
{
113 return unless exists $feature{$name};
114 my ($sub, $override, @defaults) = (
115 $feature{$name}{'sub'},
116 $feature{$name}{'override'},
117 @{$feature{$name}{'default'}});
118 if (!$override) { return @defaults; }
119 return $sub->(@defaults);
122 # To enable system wide have in $GITWEB_CONFIG
123 # $feature{'blame'}{'default'} = [1];
124 # To have project specific config enable override in $GITWEB_CONFIG
125 # $feature{'blame'}{'override'} = 1;
126 # and in project config gitweb.blame = 0|1;
129 my ($val) = git_get_project_config
('blame', '--bool');
131 if ($val eq 'true') {
133 } elsif ($val eq 'false') {
140 # To disable system wide have in $GITWEB_CONFIG
141 # $feature{'snapshot'}{'default'} = [undef];
142 # To have project specific config enable override in $GITWEB_CONFIG
143 # $feature{'blame'}{'override'} = 1;
144 # and in project config gitweb.snapshot = none|gzip|bzip2
146 sub feature_snapshot
{
147 my ($ctype, $suffix, $command) = @_;
149 my ($val) = git_get_project_config
('snapshot');
151 if ($val eq 'gzip') {
152 return ('x-gzip', 'gz', 'gzip');
153 } elsif ($val eq 'bzip2') {
154 return ('x-bzip2', 'bz2', 'bzip2');
155 } elsif ($val eq 'none') {
159 return ($ctype, $suffix, $command);
162 sub gitweb_have_snapshot
{
163 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
164 my $have_snapshot = (defined $ctype && defined $suffix);
166 return $have_snapshot;
169 # To enable system wide have in $GITWEB_CONFIG
170 # $feature{'pickaxe'}{'default'} = [1];
171 # To have project specific config enable override in $GITWEB_CONFIG
172 # $feature{'pickaxe'}{'override'} = 1;
173 # and in project config gitweb.pickaxe = 0|1;
175 sub feature_pickaxe
{
176 my ($val) = git_get_project_config
('pickaxe', '--bool');
178 if ($val eq 'true') {
180 } elsif ($val eq 'false') {
187 # checking HEAD file with -e is fragile if the repository was
188 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
190 sub check_head_link
{
192 my $headfile = "$dir/HEAD";
193 return ((-e
$headfile) ||
194 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
197 sub check_export_ok
{
199 return (check_head_link
($dir) &&
200 (!$export_ok || -e
"$dir/$export_ok"));
203 # rename detection options for git-diff and git-diff-tree
204 # - default is '-M', with the cost proportional to
205 # (number of removed files) * (number of new files).
206 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
207 # (number of changed files + number of removed files) * (number of new files)
208 # - even more costly is '-C', '--find-copies-harder' with cost
209 # (number of files in the original tree) * (number of new files)
210 # - one might want to include '-B' option, e.g. '-B', '-M'
211 our @diff_opts = ('-M'); # taken from git_commit
213 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
214 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
216 # version of the core git binary
217 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
219 $projects_list ||= $projectroot;
221 # ======================================================================
222 # input validation and dispatch
223 our $action = $cgi->param('a');
224 if (defined $action) {
225 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
226 die_error
(undef, "Invalid action parameter");
230 # parameters which are pathnames
231 our $project = $cgi->param('p');
232 if (defined $project) {
233 if (!validate_pathname
($project) ||
234 !(-d
"$projectroot/$project") ||
235 !check_head_link
("$projectroot/$project") ||
236 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
237 ($strict_export && !project_in_list
($project))) {
239 die_error
(undef, "No such project");
243 our $file_name = $cgi->param('f');
244 if (defined $file_name) {
245 if (!validate_pathname
($file_name)) {
246 die_error
(undef, "Invalid file parameter");
250 our $file_parent = $cgi->param('fp');
251 if (defined $file_parent) {
252 if (!validate_pathname
($file_parent)) {
253 die_error
(undef, "Invalid file parent parameter");
257 # parameters which are refnames
258 our $hash = $cgi->param('h');
260 if (!validate_refname
($hash)) {
261 die_error
(undef, "Invalid hash parameter");
265 our $hash_parent = $cgi->param('hp');
266 if (defined $hash_parent) {
267 if (!validate_refname
($hash_parent)) {
268 die_error
(undef, "Invalid hash parent parameter");
272 our $hash_base = $cgi->param('hb');
273 if (defined $hash_base) {
274 if (!validate_refname
($hash_base)) {
275 die_error
(undef, "Invalid hash base parameter");
279 our $hash_parent_base = $cgi->param('hpb');
280 if (defined $hash_parent_base) {
281 if (!validate_refname
($hash_parent_base)) {
282 die_error
(undef, "Invalid hash parent base parameter");
287 our $page = $cgi->param('pg');
289 if ($page =~ m/[^0-9]/) {
290 die_error
(undef, "Invalid page parameter");
294 our $searchtext = $cgi->param('s');
295 if (defined $searchtext) {
296 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
297 die_error
(undef, "Invalid search parameter");
299 $searchtext = quotemeta $searchtext;
302 # now read PATH_INFO and use it as alternative to parameters
303 sub evaluate_path_info
{
304 return if defined $project;
305 my $path_info = $ENV{"PATH_INFO"};
306 return if !$path_info;
307 $path_info =~ s
,^/+,,;
308 return if !$path_info;
309 # find which part of PATH_INFO is project
310 $project = $path_info;
312 while ($project && !check_head_link
("$projectroot/$project")) {
313 $project =~ s
,/*[^/]*$,,;
316 $project = validate_pathname
($project);
318 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
319 ($strict_export && !project_in_list
($project))) {
323 # do not change any parameters if an action is given using the query string
325 $path_info =~ s
,^$project/*,,;
326 my ($refname, $pathname) = split(/:/, $path_info, 2);
327 if (defined $pathname) {
328 # we got "project.git/branch:filename" or "project.git/branch:dir/"
329 # we could use git_get_type(branch:pathname), but it needs $git_dir
330 $pathname =~ s
,^/+,,;
331 if (!$pathname || substr($pathname, -1) eq "/") {
335 $action ||= "blob_plain";
337 $hash_base ||= validate_refname
($refname);
338 $file_name ||= validate_pathname
($pathname);
339 } elsif (defined $refname) {
340 # we got "project.git/branch"
341 $action ||= "shortlog";
342 $hash ||= validate_refname
($refname);
345 evaluate_path_info
();
347 # path to the current git repository
349 $git_dir = "$projectroot/$project" if $project;
353 "blame" => \
&git_blame2
,
354 "blobdiff" => \
&git_blobdiff
,
355 "blobdiff_plain" => \
&git_blobdiff_plain
,
356 "blob" => \
&git_blob
,
357 "blob_plain" => \
&git_blob_plain
,
358 "commitdiff" => \
&git_commitdiff
,
359 "commitdiff_plain" => \
&git_commitdiff_plain
,
360 "commit" => \
&git_commit
,
361 "heads" => \
&git_heads
,
362 "history" => \
&git_history
,
365 "search" => \
&git_search
,
366 "shortlog" => \
&git_shortlog
,
367 "summary" => \
&git_summary
,
369 "tags" => \
&git_tags
,
370 "tree" => \
&git_tree
,
371 "snapshot" => \
&git_snapshot
,
372 # those below don't need $project
373 "opml" => \
&git_opml
,
374 "project_list" => \
&git_project_list
,
375 "project_index" => \
&git_project_index
,
378 if (defined $project) {
379 $action ||= 'summary';
381 $action ||= 'project_list';
383 if (!defined($actions{$action})) {
384 die_error
(undef, "Unknown action");
386 if ($action !~ m/^(opml|project_list|project_index)$/ &&
388 die_error
(undef, "Project needed");
390 $actions{$action}->();
393 ## ======================================================================
408 hash_parent_base
=> "hpb",
413 my %mapping = @mapping;
415 $params{'project'} = $project unless exists $params{'project'};
417 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
419 # use PATH_INFO for project name
420 $href .= "/$params{'project'}" if defined $params{'project'};
421 delete $params{'project'};
423 # Summary just uses the project path URL
424 if (defined $params{'action'} && $params{'action'} eq 'summary') {
425 delete $params{'action'};
429 # now encode the parameters explicitly
431 for (my $i = 0; $i < @mapping; $i += 2) {
432 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
433 if (defined $params{$name}) {
434 push @result, $symbol . "=" . esc_param
($params{$name});
437 $href .= "?" . join(';', @result) if scalar @result;
443 ## ======================================================================
444 ## validation, quoting/unquoting and escaping
446 sub validate_pathname
{
447 my $input = shift || return undef;
449 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
450 # at the beginning, at the end, and between slashes.
451 # also this catches doubled slashes
452 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
456 if ($input =~ m!\0!) {
462 sub validate_refname
{
463 my $input = shift || return undef;
465 # textual hashes are O.K.
466 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
469 # it must be correct pathname
470 $input = validate_pathname
($input)
472 # restrictions on ref name according to git-check-ref-format
473 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
479 # quote unsafe chars, but keep the slash, even when it's not
480 # correct, but quoted slashes look too horrible in bookmarks
483 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
489 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
492 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
498 # replace invalid utf8 character with SUBSTITUTION sequence
501 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
502 $str = escapeHTML
($str);
503 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
504 $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1)
508 # git may return quoted and escaped filenames
511 if ($str =~ m/^"(.*)"$/) {
513 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
518 # escape tabs (convert tabs to spaces)
522 while ((my $pos = index($line, "\t")) != -1) {
523 if (my $count = (8 - ($pos % 8))) {
524 my $spaces = ' ' x
$count;
525 $line =~ s/\t/$spaces/;
532 sub project_in_list
{
534 my @list = git_get_projects_list
();
535 return @list && scalar(grep { $_->{'path'} eq $project } @list);
538 ## ----------------------------------------------------------------------
539 ## HTML aware string manipulation
544 my $add_len = shift || 10;
546 # allow only $len chars, but don't cut a word if it would fit in $add_len
547 # if it doesn't fit, cut it if it's still longer than the dots we would add
548 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
551 if (length($tail) > 4) {
553 $body =~ s/&[^;]*$//; # remove chopped character entities
558 ## ----------------------------------------------------------------------
559 ## functions returning short strings
561 # CSS class for given age value (in seconds)
565 if ($age < 60*60*2) {
567 } elsif ($age < 60*60*24*2) {
574 # convert age in seconds to "nn units ago" string
579 if ($age > 60*60*24*365*2) {
580 $age_str = (int $age/60/60/24/365);
581 $age_str .= " years ago";
582 } elsif ($age > 60*60*24*(365/12)*2) {
583 $age_str = int $age/60/60/24/(365/12);
584 $age_str .= " months ago";
585 } elsif ($age > 60*60*24*7*2) {
586 $age_str = int $age/60/60/24/7;
587 $age_str .= " weeks ago";
588 } elsif ($age > 60*60*24*2) {
589 $age_str = int $age/60/60/24;
590 $age_str .= " days ago";
591 } elsif ($age > 60*60*2) {
592 $age_str = int $age/60/60;
593 $age_str .= " hours ago";
594 } elsif ($age > 60*2) {
595 $age_str = int $age/60;
596 $age_str .= " min ago";
599 $age_str .= " sec ago";
601 $age_str .= " right now";
606 # convert file mode in octal to symbolic file mode string
608 my $mode = oct shift;
610 if (S_ISDIR
($mode & S_IFMT
)) {
612 } elsif (S_ISLNK
($mode)) {
614 } elsif (S_ISREG
($mode)) {
615 # git cares only about the executable bit
616 if ($mode & S_IXUSR
) {
626 # convert file mode in octal to file type string
630 if ($mode !~ m/^[0-7]+$/) {
636 if (S_ISDIR
($mode & S_IFMT
)) {
638 } elsif (S_ISLNK
($mode)) {
640 } elsif (S_ISREG
($mode)) {
647 ## ----------------------------------------------------------------------
648 ## functions returning short HTML fragments, or transforming HTML fragments
649 ## which don't beling to other sections
651 # format line of commit message or tag comment
652 sub format_log_line_html
{
655 $line = esc_html
($line);
656 $line =~ s/ / /g;
657 if ($line =~ m/([0-9a-fA-F]{40})/) {
659 if (git_get_type
($hash_text) eq "commit") {
661 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
662 -class => "text"}, $hash_text);
663 $line =~ s/$hash_text/$link/;
669 # format marker of refs pointing to given object
670 sub format_ref_marker
{
671 my ($refs, $id) = @_;
674 if (defined $refs->{$id}) {
675 foreach my $ref (@{$refs->{$id}}) {
676 my ($type, $name) = qw();
677 # e.g. tags/v2.6.11 or heads/next
678 if ($ref =~ m!^(.*?)s?/(.*)$!) {
686 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
691 return ' <span class="refs">'. $markers . '</span>';
697 # format, perhaps shortened and with markers, title line
698 sub format_subject_html
{
699 my ($long, $short, $href, $extra) = @_;
700 $extra = '' unless defined($extra);
702 if (length($short) < length($long)) {
703 return $cgi->a({-href
=> $href, -class => "list subject",
704 -title
=> decode
("utf8", $long, Encode
::FB_DEFAULT
)},
705 esc_html
($short) . $extra);
707 return $cgi->a({-href
=> $href, -class => "list subject"},
708 esc_html
($long) . $extra);
712 sub format_diff_line
{
714 my $char = substr($line, 0, 1);
720 $diff_class = " add";
721 } elsif ($char eq "-") {
722 $diff_class = " rem";
723 } elsif ($char eq "@") {
724 $diff_class = " chunk_header";
725 } elsif ($char eq "\\") {
726 $diff_class = " incomplete";
728 $line = untabify
($line);
729 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
732 ## ----------------------------------------------------------------------
733 ## git utility subroutines, invoking git commands
735 # returns path to the core git executable and the --git-dir parameter as list
737 return $GIT, '--git-dir='.$git_dir;
740 # returns path to the core git executable and the --git-dir parameter as string
742 return join(' ', git_cmd
());
745 # get HEAD ref of given project as hash
746 sub git_get_head_hash
{
748 my $o_git_dir = $git_dir;
750 $git_dir = "$projectroot/$project";
751 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
754 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
758 if (defined $o_git_dir) {
759 $git_dir = $o_git_dir;
764 # get type of given object
768 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
775 sub git_get_project_config
{
776 my ($key, $type) = @_;
778 return unless ($key);
779 $key =~ s/^gitweb\.//;
780 return if ($key =~ m/\W/);
782 my @x = (git_cmd
(), 'repo-config');
783 if (defined $type) { push @x, $type; }
785 push @x, "gitweb.$key";
791 # get hash of given path at given ref
792 sub git_get_hash_by_path
{
794 my $path = shift || return undef;
799 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
800 or die_error
(undef, "Open git-ls-tree failed");
802 close $fd or return undef;
804 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
805 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
806 if (defined $type && $type ne $2) {
813 ## ......................................................................
814 ## git utility functions, directly accessing git repository
816 sub git_get_project_description
{
819 open my $fd, "$projectroot/$path/description" or return undef;
826 sub git_get_project_url_list
{
829 open my $fd, "$projectroot/$path/cloneurl" or return;
830 my @git_project_url_list = map { chomp; $_ } <$fd>;
833 return wantarray ? @git_project_url_list : \
@git_project_url_list;
836 sub git_get_projects_list
{
839 if (-d
$projects_list) {
840 # search in directory
841 my $dir = $projects_list;
842 my $pfxlen = length("$dir");
845 follow_fast
=> 1, # follow symbolic links
846 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
848 # skip project-list toplevel, if we get it.
849 return if (m!^[/.]$!);
850 # only directories can be git repositories
851 return unless (-d
$_);
853 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
854 # we check related file in $projectroot
855 if (check_export_ok
("$projectroot/$subdir")) {
856 push @list, { path
=> $subdir };
857 $File::Find
::prune
= 1;
862 } elsif (-f
$projects_list) {
863 # read from file(url-encoded):
864 # 'git%2Fgit.git Linus+Torvalds'
865 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
866 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
867 open my ($fd), $projects_list or return;
868 while (my $line = <$fd>) {
870 my ($path, $owner) = split ' ', $line;
871 $path = unescape
($path);
872 $owner = unescape
($owner);
873 if (!defined $path) {
876 if (check_export_ok
("$projectroot/$path")) {
879 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
886 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
890 sub git_get_project_owner
{
894 return undef unless $project;
896 # read from file (url-encoded):
897 # 'git%2Fgit.git Linus+Torvalds'
898 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
899 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
900 if (-f
$projects_list) {
901 open (my $fd , $projects_list);
902 while (my $line = <$fd>) {
904 my ($pr, $ow) = split ' ', $line;
907 if ($pr eq $project) {
908 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
914 if (!defined $owner) {
915 $owner = get_file_owner
("$projectroot/$project");
921 sub git_get_references
{
922 my $type = shift || "";
924 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
925 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
926 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
929 while (my $line = <$fd>) {
931 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
932 if (defined $refs{$1}) {
933 push @{$refs{$1}}, $2;
943 sub git_get_rev_name_tags
{
944 my $hash = shift || return undef;
946 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
948 my $name_rev = <$fd>;
951 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
954 # catches also '$hash undefined' output
959 ## ----------------------------------------------------------------------
960 ## parse to hash functions
964 my $tz = shift || "-0000";
967 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
968 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
969 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
970 $date{'hour'} = $hour;
971 $date{'minute'} = $min;
972 $date{'mday'} = $mday;
973 $date{'day'} = $days[$wday];
974 $date{'month'} = $months[$mon];
975 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
976 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
977 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
978 $mday, $months[$mon], $hour ,$min;
980 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
981 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
982 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
983 $date{'hour_local'} = $hour;
984 $date{'minute_local'} = $min;
985 $date{'tz_local'} = $tz;
994 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
995 $tag{'id'} = $tag_id;
996 while (my $line = <$fd>) {
998 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1000 } elsif ($line =~ m/^type (.+)$/) {
1002 } elsif ($line =~ m/^tag (.+)$/) {
1004 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1005 $tag{'author'} = $1;
1008 } elsif ($line =~ m/--BEGIN/) {
1009 push @comment, $line;
1011 } elsif ($line eq "") {
1015 push @comment, <$fd>;
1016 $tag{'comment'} = \
@comment;
1017 close $fd or return;
1018 if (!defined $tag{'name'}) {
1025 my $commit_id = shift;
1026 my $commit_text = shift;
1031 if (defined $commit_text) {
1032 @commit_lines = @$commit_text;
1035 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
1037 @commit_lines = split '\n', <$fd>;
1038 close $fd or return;
1042 my $header = shift @commit_lines;
1043 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1046 ($co{'id'}, my @parents) = split ' ', $header;
1047 $co{'parents'} = \
@parents;
1048 $co{'parent'} = $parents[0];
1049 while (my $line = shift @commit_lines) {
1050 last if $line eq "\n";
1051 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1053 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1055 $co{'author_epoch'} = $2;
1056 $co{'author_tz'} = $3;
1057 if ($co{'author'} =~ m/^([^<]+) </) {
1058 $co{'author_name'} = $1;
1060 $co{'author_name'} = $co{'author'};
1062 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1063 $co{'committer'} = $1;
1064 $co{'committer_epoch'} = $2;
1065 $co{'committer_tz'} = $3;
1066 $co{'committer_name'} = $co{'committer'};
1067 $co{'committer_name'} =~ s/ <.*//;
1070 if (!defined $co{'tree'}) {
1074 foreach my $title (@commit_lines) {
1077 $co{'title'} = chop_str
($title, 80, 5);
1078 # remove leading stuff of merges to make the interesting part visible
1079 if (length($title) > 50) {
1080 $title =~ s/^Automatic //;
1081 $title =~ s/^merge (of|with) /Merge ... /i;
1082 if (length($title) > 50) {
1083 $title =~ s/(http|rsync):\/\///;
1085 if (length($title) > 50) {
1086 $title =~ s/(master|www|rsync)\.//;
1088 if (length($title) > 50) {
1089 $title =~ s/kernel.org:?//;
1091 if (length($title) > 50) {
1092 $title =~ s/\/pub\/scm//;
1095 $co{'title_short'} = chop_str
($title, 50, 5);
1099 # remove added spaces
1100 foreach my $line (@commit_lines) {
1103 $co{'comment'} = \
@commit_lines;
1105 my $age = time - $co{'committer_epoch'};
1107 $co{'age_string'} = age_string
($age);
1108 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1109 if ($age > 60*60*24*7*2) {
1110 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1111 $co{'age_string_age'} = $co{'age_string'};
1113 $co{'age_string_date'} = $co{'age_string'};
1114 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1119 # parse ref from ref_file, given by ref_id, with given type
1121 my $ref_file = shift;
1123 my $type = shift || git_get_type
($ref_id);
1126 $ref_item{'type'} = $type;
1127 $ref_item{'id'} = $ref_id;
1128 $ref_item{'epoch'} = 0;
1129 $ref_item{'age'} = "unknown";
1130 if ($type eq "tag") {
1131 my %tag = parse_tag
($ref_id);
1132 $ref_item{'comment'} = $tag{'comment'};
1133 if ($tag{'type'} eq "commit") {
1134 my %co = parse_commit
($tag{'object'});
1135 $ref_item{'epoch'} = $co{'committer_epoch'};
1136 $ref_item{'age'} = $co{'age_string'};
1137 } elsif (defined($tag{'epoch'})) {
1138 my $age = time - $tag{'epoch'};
1139 $ref_item{'epoch'} = $tag{'epoch'};
1140 $ref_item{'age'} = age_string
($age);
1142 $ref_item{'reftype'} = $tag{'type'};
1143 $ref_item{'name'} = $tag{'name'};
1144 $ref_item{'refid'} = $tag{'object'};
1145 } elsif ($type eq "commit"){
1146 my %co = parse_commit
($ref_id);
1147 $ref_item{'reftype'} = "commit";
1148 $ref_item{'name'} = $ref_file;
1149 $ref_item{'title'} = $co{'title'};
1150 $ref_item{'refid'} = $ref_id;
1151 $ref_item{'epoch'} = $co{'committer_epoch'};
1152 $ref_item{'age'} = $co{'age_string'};
1154 $ref_item{'reftype'} = $type;
1155 $ref_item{'name'} = $ref_file;
1156 $ref_item{'refid'} = $ref_id;
1162 # parse line of git-diff-tree "raw" output
1163 sub parse_difftree_raw_line
{
1167 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1168 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1169 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1170 $res{'from_mode'} = $1;
1171 $res{'to_mode'} = $2;
1172 $res{'from_id'} = $3;
1174 $res{'status'} = $5;
1175 $res{'similarity'} = $6;
1176 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1177 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1179 $res{'file'} = unquote
($7);
1182 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1183 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1184 $res{'commit'} = $1;
1187 return wantarray ? %res : \
%res;
1190 # parse line of git-ls-tree output
1191 sub parse_ls_tree_line
($;%) {
1196 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1197 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1205 $res{'name'} = unquote
($4);
1208 return wantarray ? %res : \
%res;
1211 ## ......................................................................
1212 ## parse to array of hashes functions
1214 sub git_get_refs_list
{
1215 my $type = shift || "";
1220 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1222 while (my $line = <$fd>) {
1224 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?([^\^]+))(\^\{\})?$/) {
1225 if (defined $refs{$1}) {
1226 push @{$refs{$1}}, $2;
1231 if (! $4) { # unpeeled, direct reference
1232 push @refs, { hash
=> $1, name
=> $3 }; # without type
1233 } elsif ($3 eq $refs[-1]{'name'}) {
1234 # most likely a tag is followed by its peeled
1235 # (deref) one, and when that happens we know the
1236 # previous one was of type 'tag'.
1237 $refs[-1]{'type'} = "tag";
1243 foreach my $ref (@refs) {
1244 my $ref_file = $ref->{'name'};
1245 my $ref_id = $ref->{'hash'};
1247 my $type = $ref->{'type'} || git_get_type
($ref_id) || next;
1248 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1250 push @reflist, \
%ref_item;
1253 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1254 return (\
@reflist, \
%refs);
1257 ## ----------------------------------------------------------------------
1258 ## filesystem-related functions
1260 sub get_file_owner
{
1263 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1264 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1265 if (!defined $gcos) {
1269 $owner =~ s/[,;].*$//;
1270 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
1273 ## ......................................................................
1274 ## mimetype related functions
1276 sub mimetype_guess_file
{
1277 my $filename = shift;
1278 my $mimemap = shift;
1279 -r
$mimemap or return undef;
1282 open(MIME
, $mimemap) or return undef;
1284 next if m/^#/; # skip comments
1285 my ($mime, $exts) = split(/\t+/);
1286 if (defined $exts) {
1287 my @exts = split(/\s+/, $exts);
1288 foreach my $ext (@exts) {
1289 $mimemap{$ext} = $mime;
1295 $filename =~ /\.([^.]*)$/;
1296 return $mimemap{$1};
1299 sub mimetype_guess
{
1300 my $filename = shift;
1302 $filename =~ /\./ or return undef;
1304 if ($mimetypes_file) {
1305 my $file = $mimetypes_file;
1306 if ($file !~ m!^/!) { # if it is relative path
1307 # it is relative to project
1308 $file = "$projectroot/$project/$file";
1310 $mime = mimetype_guess_file
($filename, $file);
1312 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1318 my $filename = shift;
1321 my $mime = mimetype_guess
($filename);
1322 $mime and return $mime;
1326 return $default_blob_plain_mimetype unless $fd;
1329 return 'text/plain' .
1330 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1331 } elsif (! $filename) {
1332 return 'application/octet-stream';
1333 } elsif ($filename =~ m/\.png$/i) {
1335 } elsif ($filename =~ m/\.gif$/i) {
1337 } elsif ($filename =~ m/\.jpe?g$/i) {
1338 return 'image/jpeg';
1340 return 'application/octet-stream';
1344 ## ======================================================================
1345 ## functions printing HTML: header, footer, error page
1347 sub git_header_html
{
1348 my $status = shift || "200 OK";
1349 my $expires = shift;
1351 my $title = "$site_name git";
1352 if (defined $project) {
1353 $title .= " - $project";
1354 if (defined $action) {
1355 $title .= "/$action";
1356 if (defined $file_name) {
1357 $title .= " - " . esc_html
($file_name);
1358 if ($action eq "tree" && $file_name !~ m
|/$|) {
1365 # require explicit support from the UA if we are to send the page as
1366 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1367 # we have to do this because MSIE sometimes globs '*/*', pretending to
1368 # support xhtml+xml but choking when it gets what it asked for.
1369 if (defined $cgi->http('HTTP_ACCEPT') &&
1370 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1371 $cgi->Accept('application/xhtml+xml') != 0) {
1372 $content_type = 'application/xhtml+xml';
1374 $content_type = 'text/html';
1376 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1377 -status
=> $status, -expires
=> $expires);
1379 <?xml version="1.0" encoding="utf-8"?>
1380 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1381 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1382 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1383 <!-- git core binaries version $git_version -->
1385 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1386 <meta name="generator" content="gitweb/$version git/$git_version"/>
1387 <meta name="robots" content="index, nofollow"/>
1388 <title>$title</title>
1389 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1391 if (defined $project) {
1392 printf('<link rel="alternate" title="%s log" '.
1393 'href="%s" type="application/rss+xml"/>'."\n",
1394 esc_param
($project), href
(action
=>"rss"));
1396 printf('<link rel="alternate" title="%s projects list" '.
1397 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1398 $site_name, href
(project
=>undef, action
=>"project_index"));
1399 printf('<link rel="alternate" title="%s projects logs" '.
1400 'href="%s" type="text/x-opml"/>'."\n",
1401 $site_name, href
(project
=>undef, action
=>"opml"));
1403 if (defined $favicon) {
1404 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1409 "<div class=\"page_header\">\n" .
1410 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1411 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1413 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1414 if (defined $project) {
1415 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1416 if (defined $action) {
1420 if (!defined $searchtext) {
1424 if (defined $hash_base) {
1425 $search_hash = $hash_base;
1426 } elsif (defined $hash) {
1427 $search_hash = $hash;
1429 $search_hash = "HEAD";
1431 $cgi->param("a", "search");
1432 $cgi->param("h", $search_hash);
1433 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1434 "<div class=\"search\">\n" .
1435 $cgi->hidden(-name
=> "p") . "\n" .
1436 $cgi->hidden(-name
=> "a") . "\n" .
1437 $cgi->hidden(-name
=> "h") . "\n" .
1438 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1440 $cgi->end_form() . "\n";
1445 sub git_footer_html
{
1446 print "<div class=\"page_footer\">\n";
1447 if (defined $project) {
1448 my $descr = git_get_project_description
($project);
1449 if (defined $descr) {
1450 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1452 print $cgi->a({-href
=> href
(action
=>"rss"),
1453 -class => "rss_logo"}, "RSS") . "\n";
1455 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1456 -class => "rss_logo"}, "OPML") . " ";
1457 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1458 -class => "rss_logo"}, "TXT") . "\n";
1466 my $status = shift || "403 Forbidden";
1467 my $error = shift || "Malformed query, file missing or permission denied";
1469 git_header_html
($status);
1471 <div class="page_body">
1481 ## ----------------------------------------------------------------------
1482 ## functions printing or outputting HTML: navigation
1484 sub git_print_page_nav
{
1485 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1486 $extra = '' if !defined $extra; # pager or formats
1488 my @navs = qw(summary shortlog log commit commitdiff tree);
1490 @navs = grep { $_ ne $suppress } @navs;
1493 my %arg = map { $_ => {action
=>$_} } @navs;
1494 if (defined $head) {
1495 for (qw(commit commitdiff)) {
1496 $arg{$_}{hash
} = $head;
1498 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1499 for (qw(shortlog log)) {
1500 $arg{$_}{hash
} = $head;
1504 $arg{tree
}{hash
} = $treehead if defined $treehead;
1505 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1507 print "<div class=\"page_nav\">\n" .
1509 map { $_ eq $current ?
1510 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1512 print "<br/>\n$extra<br/>\n" .
1516 sub format_paging_nav
{
1517 my ($action, $hash, $head, $page, $nrevs) = @_;
1521 if ($hash ne $head || $page) {
1522 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1524 $paging_nav .= "HEAD";
1528 $paging_nav .= " ⋅ " .
1529 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1530 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1532 $paging_nav .= " ⋅ prev";
1535 if ($nrevs >= (100 * ($page+1)-1)) {
1536 $paging_nav .= " ⋅ " .
1537 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1538 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1540 $paging_nav .= " ⋅ next";
1546 ## ......................................................................
1547 ## functions printing or outputting HTML: div
1549 sub git_print_header_div
{
1550 my ($action, $title, $hash, $hash_base) = @_;
1553 $args{action
} = $action;
1554 $args{hash
} = $hash if $hash;
1555 $args{hash_base
} = $hash_base if $hash_base;
1557 print "<div class=\"header\">\n" .
1558 $cgi->a({-href
=> href
(%args), -class => "title"},
1559 $title ? $title : $action) .
1563 #sub git_print_authorship (\%) {
1564 sub git_print_authorship
{
1567 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1568 print "<div class=\"author_date\">" .
1569 esc_html
($co->{'author_name'}) .
1571 if ($ad{'hour_local'} < 6) {
1572 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1573 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1575 printf(" (%02d:%02d %s)",
1576 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1581 sub git_print_page_path
{
1586 if (!defined $name) {
1587 print "<div class=\"page_path\">/</div>\n";
1589 my @dirname = split '/', $name;
1590 my $basename = pop @dirname;
1593 print "<div class=\"page_path\">";
1594 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1595 -title
=> 'tree root'}, "[$project]");
1597 foreach my $dir (@dirname) {
1598 $fullname .= ($fullname ? '/' : '') . $dir;
1599 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1601 -title
=> $fullname}, esc_html
($dir));
1604 if (defined $type && $type eq 'blob') {
1605 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1607 -title
=> $name}, esc_html
($basename));
1608 } elsif (defined $type && $type eq 'tree') {
1609 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1611 -title
=> $name}, esc_html
($basename));
1613 print esc_html
($basename);
1615 print "<br/></div>\n";
1619 # sub git_print_log (\@;%) {
1620 sub git_print_log
($;%) {
1624 if ($opts{'-remove_title'}) {
1625 # remove title, i.e. first line of log
1628 # remove leading empty lines
1629 while (defined $log->[0] && $log->[0] eq "") {
1636 foreach my $line (@$log) {
1637 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1640 if (! $opts{'-remove_signoff'}) {
1641 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1644 # remove signoff lines
1651 # print only one empty line
1652 # do not print empty line after signoff
1654 next if ($empty || $signoff);
1660 print format_log_line_html
($line) . "<br/>\n";
1663 if ($opts{'-final_empty_line'}) {
1664 # end with single empty line
1665 print "<br/>\n" unless $empty;
1669 sub git_print_simplified_log
{
1671 my $remove_title = shift;
1674 -final_empty_line
=> 1,
1675 -remove_title
=> $remove_title);
1678 # print tree entry (row of git_tree), but without encompassing <tr> element
1679 sub git_print_tree_entry
{
1680 my ($t, $basedir, $hash_base, $have_blame) = @_;
1683 $base_key{hash_base
} = $hash_base if defined $hash_base;
1685 # The format of a table row is: mode list link. Where mode is
1686 # the mode of the entry, list is the name of the entry, an href,
1687 # and link is the action links of the entry.
1689 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1690 if ($t->{'type'} eq "blob") {
1691 print "<td class=\"list\">" .
1692 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1693 file_name
=>"$basedir$t->{'name'}", %base_key),
1694 -class => "list"}, esc_html
($t->{'name'})) . "</td>\n";
1695 print "<td class=\"link\">";
1697 print $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1698 file_name
=>"$basedir$t->{'name'}", %base_key)},
1701 if (defined $hash_base) {
1705 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1706 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1710 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
1711 file_name
=>"$basedir$t->{'name'}")},
1715 } elsif ($t->{'type'} eq "tree") {
1716 print "<td class=\"list\">";
1717 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1718 file_name
=>"$basedir$t->{'name'}", %base_key)},
1719 esc_html
($t->{'name'}));
1721 print "<td class=\"link\">";
1722 if (defined $hash_base) {
1723 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1724 file_name
=>"$basedir$t->{'name'}")},
1731 ## ......................................................................
1732 ## functions printing large fragments of HTML
1734 sub git_difftree_body
{
1735 my ($difftree, $hash, $parent) = @_;
1737 print "<div class=\"list_head\">\n";
1738 if ($#{$difftree} > 10) {
1739 print(($#{$difftree} + 1) . " files changed:\n");
1743 print "<table class=\"diff_tree\">\n";
1746 foreach my $line (@{$difftree}) {
1747 my %diff = parse_difftree_raw_line
($line);
1750 print "<tr class=\"dark\">\n";
1752 print "<tr class=\"light\">\n";
1756 my ($to_mode_oct, $to_mode_str, $to_file_type);
1757 my ($from_mode_oct, $from_mode_str, $from_file_type);
1758 if ($diff{'to_mode'} ne ('0' x
6)) {
1759 $to_mode_oct = oct $diff{'to_mode'};
1760 if (S_ISREG
($to_mode_oct)) { # only for regular file
1761 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1763 $to_file_type = file_type
($diff{'to_mode'});
1765 if ($diff{'from_mode'} ne ('0' x
6)) {
1766 $from_mode_oct = oct $diff{'from_mode'};
1767 if (S_ISREG
($to_mode_oct)) { # only for regular file
1768 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1770 $from_file_type = file_type
($diff{'from_mode'});
1773 if ($diff{'status'} eq "A") { # created
1774 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1775 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1776 $mode_chng .= "]</span>";
1778 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1779 hash_base
=>$hash, file_name
=>$diff{'file'}),
1780 -class => "list"}, esc_html
($diff{'file'}));
1782 print "<td>$mode_chng</td>\n";
1783 print "<td class=\"link\">";
1784 if ($action eq 'commitdiff') {
1787 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1791 } elsif ($diff{'status'} eq "D") { # deleted
1792 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1794 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1795 hash_base
=>$parent, file_name
=>$diff{'file'}),
1796 -class => "list"}, esc_html
($diff{'file'}));
1798 print "<td>$mode_chng</td>\n";
1799 print "<td class=\"link\">";
1800 if ($action eq 'commitdiff') {
1803 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1806 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1807 file_name
=>$diff{'file'})},
1809 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1810 file_name
=>$diff{'file'})},
1814 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1815 my $mode_chnge = "";
1816 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1817 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1818 if ($from_file_type != $to_file_type) {
1819 $mode_chnge .= " from $from_file_type to $to_file_type";
1821 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1822 if ($from_mode_str && $to_mode_str) {
1823 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1824 } elsif ($to_mode_str) {
1825 $mode_chnge .= " mode: $to_mode_str";
1828 $mode_chnge .= "]</span>\n";
1831 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1832 hash_base
=>$hash, file_name
=>$diff{'file'}),
1833 -class => "list"}, esc_html
($diff{'file'}));
1835 print "<td>$mode_chnge</td>\n";
1836 print "<td class=\"link\">";
1837 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1838 if ($action eq 'commitdiff') {
1841 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1843 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1844 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1845 hash_base
=>$hash, hash_parent_base
=>$parent,
1846 file_name
=>$diff{'file'})},
1851 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
1852 file_name
=>$diff{'file'})},
1854 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
1855 file_name
=>$diff{'file'})},
1859 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1860 my %status_name = ('R' => 'moved', 'C' => 'copied');
1861 my $nstatus = $status_name{$diff{'status'}};
1863 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1864 # mode also for directories, so we cannot use $to_mode_str
1865 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1868 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1869 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1870 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1871 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1872 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1873 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1874 -class => "list"}, esc_html
($diff{'from_file'})) .
1875 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1876 "<td class=\"link\">";
1877 if ($diff{'to_id'} ne $diff{'from_id'}) {
1878 if ($action eq 'commitdiff') {
1881 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1883 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1884 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1885 hash_base
=>$hash, hash_parent_base
=>$parent,
1886 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1891 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1892 file_name
=>$diff{'from_file'})},
1894 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1895 file_name
=>$diff{'from_file'})},
1899 } # we should not encounter Unmerged (U) or Unknown (X) status
1905 sub git_patchset_body
{
1906 my ($fd, $difftree, $hash, $hash_parent) = @_;
1910 my $patch_found = 0;
1913 print "<div class=\"patchset\">\n";
1916 while (my $patch_line = <$fd>) {
1919 if ($patch_line =~ m/^diff /) { # "git diff" header
1920 # beginning of patch (in patchset)
1922 # close previous patch
1923 print "</div>\n"; # class="patch"
1925 # first patch in patchset
1928 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1930 if (ref($difftree->[$patch_idx]) eq "HASH") {
1931 $diffinfo = $difftree->[$patch_idx];
1933 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1937 # for now, no extended header, hence we skip empty patches
1938 # companion to next LINE if $in_header;
1939 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1944 if ($diffinfo->{'status'} eq "A") { # added
1945 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1946 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1947 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1948 $diffinfo->{'to_id'}) . "(new)" .
1949 "</div>\n"; # class="diff_info"
1951 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1952 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
1953 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1954 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1955 $diffinfo->{'from_id'}) . "(deleted)" .
1956 "</div>\n"; # class="diff_info"
1958 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1959 $diffinfo->{'status'} eq "C" || # copied
1960 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1961 print "<div class=\"diff_info\">" .
1962 file_type
($diffinfo->{'from_mode'}) . ":" .
1963 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1964 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
1965 $diffinfo->{'from_id'}) .
1967 file_type
($diffinfo->{'to_mode'}) . ":" .
1968 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1969 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
1970 $diffinfo->{'to_id'});
1971 print "</div>\n"; # class="diff_info"
1973 } else { # modified, mode changed, ...
1974 print "<div class=\"diff_info\">" .
1975 file_type
($diffinfo->{'from_mode'}) . ":" .
1976 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1977 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1978 $diffinfo->{'from_id'}) .
1980 file_type
($diffinfo->{'to_mode'}) . ":" .
1981 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1982 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1983 $diffinfo->{'to_id'});
1984 print "</div>\n"; # class="diff_info"
1987 #print "<div class=\"diff extended_header\">\n";
1990 } # start of patch in patchset
1993 if ($in_header && $patch_line =~ m/^---/) {
1994 #print "</div>\n"; # class="diff extended_header"
1997 my $file = $diffinfo->{'from_file'};
1998 $file ||= $diffinfo->{'file'};
1999 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2000 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
2001 -class => "list"}, esc_html
($file));
2002 $patch_line =~ s
|a
/.*$|a/$file|g
;
2003 print "<div class=\"diff from_file\">$patch_line</div>\n";
2005 $patch_line = <$fd>;
2008 #$patch_line =~ m/^+++/;
2009 $file = $diffinfo->{'to_file'};
2010 $file ||= $diffinfo->{'file'};
2011 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2012 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
2013 -class => "list"}, esc_html
($file));
2014 $patch_line =~ s
|b
/.*|b/$file|g
;
2015 print "<div class=\"diff to_file\">$patch_line</div>\n";
2019 next LINE
if $in_header;
2021 print format_diff_line
($patch_line);
2023 print "</div>\n" if $patch_found; # class="patch"
2025 print "</div>\n"; # class="patchset"
2028 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2030 sub git_shortlog_body
{
2031 # uses global variable $project
2032 my ($revlist, $from, $to, $refs, $extra) = @_;
2034 $from = 0 unless defined $from;
2035 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2037 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2039 for (my $i = $from; $i <= $to; $i++) {
2040 my $commit = $revlist->[$i];
2041 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2042 my $ref = format_ref_marker
($refs, $commit);
2043 my %co = parse_commit
($commit);
2045 print "<tr class=\"dark\">\n";
2047 print "<tr class=\"light\">\n";
2050 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2051 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2052 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2054 print format_subject_html
($co{'title'}, $co{'title_short'},
2055 href
(action
=>"commit", hash
=>$commit), $ref);
2057 "<td class=\"link\">" .
2058 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2059 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") . " | " .
2060 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2064 if (defined $extra) {
2066 "<td colspan=\"4\">$extra</td>\n" .
2072 sub git_history_body
{
2073 # Warning: assumes constant type (blob or tree) during history
2074 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2076 $from = 0 unless defined $from;
2077 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2079 print "<table class=\"history\" cellspacing=\"0\">\n";
2081 for (my $i = $from; $i <= $to; $i++) {
2082 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2087 my %co = parse_commit
($commit);
2092 my $ref = format_ref_marker
($refs, $commit);
2095 print "<tr class=\"dark\">\n";
2097 print "<tr class=\"light\">\n";
2100 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2101 # shortlog uses chop_str($co{'author_name'}, 10)
2102 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2104 # originally git_history used chop_str($co{'title'}, 50)
2105 print format_subject_html
($co{'title'}, $co{'title_short'},
2106 href
(action
=>"commit", hash
=>$commit), $ref);
2108 "<td class=\"link\">" .
2109 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2110 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2112 if ($ftype eq 'blob') {
2113 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2114 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2115 if (defined $blob_current && defined $blob_parent &&
2116 $blob_current ne $blob_parent) {
2118 $cgi->a({-href
=> href
(action
=>"blobdiff",
2119 hash
=>$blob_current, hash_parent
=>$blob_parent,
2120 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2121 file_name
=>$file_name)},
2128 if (defined $extra) {
2130 "<td colspan=\"4\">$extra</td>\n" .
2137 # uses global variable $project
2138 my ($taglist, $from, $to, $extra) = @_;
2139 $from = 0 unless defined $from;
2140 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2142 print "<table class=\"tags\" cellspacing=\"0\">\n";
2144 for (my $i = $from; $i <= $to; $i++) {
2145 my $entry = $taglist->[$i];
2147 my $comment_lines = $tag{'comment'};
2148 my $comment = shift @$comment_lines;
2150 if (defined $comment) {
2151 $comment_short = chop_str
($comment, 30, 5);
2154 print "<tr class=\"dark\">\n";
2156 print "<tr class=\"light\">\n";
2159 print "<td><i>$tag{'age'}</i></td>\n" .
2161 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2162 -class => "list name"}, esc_html
($tag{'name'})) .
2165 if (defined $comment) {
2166 print format_subject_html
($comment, $comment_short,
2167 href
(action
=>"tag", hash
=>$tag{'id'}));
2170 "<td class=\"selflink\">";
2171 if ($tag{'type'} eq "tag") {
2172 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2177 "<td class=\"link\">" . " | " .
2178 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2179 if ($tag{'reftype'} eq "commit") {
2180 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2181 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
2182 } elsif ($tag{'reftype'} eq "blob") {
2183 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2188 if (defined $extra) {
2190 "<td colspan=\"5\">$extra</td>\n" .
2196 sub git_heads_body
{
2197 # uses global variable $project
2198 my ($headlist, $head, $from, $to, $extra) = @_;
2199 $from = 0 unless defined $from;
2200 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2202 print "<table class=\"heads\" cellspacing=\"0\">\n";
2204 for (my $i = $from; $i <= $to; $i++) {
2205 my $entry = $headlist->[$i];
2207 my $curr = $tag{'id'} eq $head;
2209 print "<tr class=\"dark\">\n";
2211 print "<tr class=\"light\">\n";
2214 print "<td><i>$tag{'age'}</i></td>\n" .
2215 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
2216 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
2217 -class => "list name"},esc_html
($tag{'name'})) .
2219 "<td class=\"link\">" .
2220 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
2221 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") . " | " .
2222 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$tag{'name'}, hash_base
=>$tag{'name'})}, "tree") .
2226 if (defined $extra) {
2228 "<td colspan=\"3\">$extra</td>\n" .
2234 ## ======================================================================
2235 ## ======================================================================
2238 sub git_project_list
{
2239 my $order = $cgi->param('o');
2240 if (defined $order && $order !~ m/project|descr|owner|age/) {
2241 die_error
(undef, "Unknown order parameter");
2244 my @list = git_get_projects_list
();
2247 die_error
(undef, "No projects found");
2249 foreach my $pr (@list) {
2250 my $head = git_get_head_hash
($pr->{'path'});
2251 if (!defined $head) {
2254 $git_dir = "$projectroot/$pr->{'path'}";
2255 my %co = parse_commit
($head);
2259 $pr->{'commit'} = \
%co;
2260 if (!defined $pr->{'descr'}) {
2261 my $descr = git_get_project_description
($pr->{'path'}) || "";
2262 $pr->{'descr'} = chop_str
($descr, 25, 5);
2264 if (!defined $pr->{'owner'}) {
2265 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2267 push @projects, $pr;
2271 if (-f
$home_text) {
2272 print "<div class=\"index_include\">\n";
2273 open (my $fd, $home_text);
2278 print "<table class=\"project_list\">\n" .
2280 $order ||= "project";
2281 if ($order eq "project") {
2282 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2283 print "<th>Project</th>\n";
2286 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2287 -class => "header"}, "Project") .
2290 if ($order eq "descr") {
2291 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2292 print "<th>Description</th>\n";
2295 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2296 -class => "header"}, "Description") .
2299 if ($order eq "owner") {
2300 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2301 print "<th>Owner</th>\n";
2304 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2305 -class => "header"}, "Owner") .
2308 if ($order eq "age") {
2309 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2310 print "<th>Last Change</th>\n";
2313 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2314 -class => "header"}, "Last Change") .
2317 print "<th></th>\n" .
2320 foreach my $pr (@projects) {
2322 print "<tr class=\"dark\">\n";
2324 print "<tr class=\"light\">\n";
2327 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2328 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2329 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2330 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2331 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2332 $pr->{'commit'}{'age_string'} . "</td>\n" .
2333 "<td class=\"link\">" .
2334 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2335 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2336 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2337 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2345 sub git_project_index
{
2346 my @projects = git_get_projects_list
();
2349 -type
=> 'text/plain',
2350 -charset
=> 'utf-8',
2351 -content_disposition
=> 'inline; filename="index.aux"');
2353 foreach my $pr (@projects) {
2354 if (!exists $pr->{'owner'}) {
2355 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2358 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2359 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2360 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2361 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2365 print "$path $owner\n";
2370 my $descr = git_get_project_description
($project) || "none";
2371 my $head = git_get_head_hash
($project);
2372 my %co = parse_commit
($head);
2373 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2375 my $owner = git_get_project_owner
($project);
2377 my ($reflist, $refs) = git_get_refs_list
();
2381 foreach my $ref (@$reflist) {
2382 if ($ref->{'name'} =~ s!^heads/!!) {
2383 push @headlist, $ref;
2385 $ref->{'name'} =~ s!^tags/!!;
2386 push @taglist, $ref;
2391 git_print_page_nav
('summary','', $head);
2393 print "<div class=\"title\"> </div>\n";
2394 print "<table cellspacing=\"0\">\n" .
2395 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2396 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2397 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2398 # use per project git URL list in $projectroot/$project/cloneurl
2399 # or make project git URL from git base URL and project name
2400 my $url_tag = "URL";
2401 my @url_list = git_get_project_url_list
($project);
2402 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2403 foreach my $git_url (@url_list) {
2404 next unless $git_url;
2405 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2410 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2411 git_get_head_hash
($project)
2412 or die_error
(undef, "Open git-rev-list failed");
2413 my @revlist = map { chomp; $_ } <$fd>;
2415 git_print_header_div
('shortlog');
2416 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2417 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2420 git_print_header_div
('tags');
2421 git_tags_body
(\
@taglist, 0, 15,
2422 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2426 git_print_header_div
('heads');
2427 git_heads_body
(\
@headlist, $head, 0, 15,
2428 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2435 my $head = git_get_head_hash
($project);
2437 git_print_page_nav
('','', $head,undef,$head);
2438 my %tag = parse_tag
($hash);
2439 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2440 print "<div class=\"title_text\">\n" .
2441 "<table cellspacing=\"0\">\n" .
2443 "<td>object</td>\n" .
2444 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2445 $tag{'object'}) . "</td>\n" .
2446 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2447 $tag{'type'}) . "</td>\n" .
2449 if (defined($tag{'author'})) {
2450 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2451 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2452 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2453 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2456 print "</table>\n\n" .
2458 print "<div class=\"page_body\">";
2459 my $comment = $tag{'comment'};
2460 foreach my $line (@$comment) {
2461 print esc_html
($line) . "<br/>\n";
2467 sub git_blame_flush_chunk
{
2468 my ($name, $revdata, $color, $rev, @line) = @_;
2469 my $label = substr($rev, 0, 8);
2470 my $line = scalar(@line);
2474 if ($revdata->{$rev} ne '') {
2475 $pop = ' title="' . esc_html
($revdata->{$rev}) . '"';
2479 my ($lineno, $data) = @$_;
2481 print "<tr class=\"$color\">\n";
2483 print "<td class=\"sha1\"$pop";
2485 print " rowspan=\"$line\"";
2488 print $cgi->a({-href
=> href
(action
=>"commit",
2494 print "<td class=\"linenr\">".
2495 "<a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2496 esc_html
($lineno) . "</a></td>\n";
2497 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2502 # We can have up to N*2 lines. If it is more than N lines, split it
2503 # into two to avoid orphans.
2504 sub git_blame_flush_chunk_1
{
2505 my ($chunk_cap, $name, $revdata, $color, $rev, @chunk) = @_;
2506 if ($chunk_cap < @chunk) {
2507 my @first = splice(@chunk, 0, @chunk/2);
2508 git_blame_flush_chunk
($name,
2514 git_blame_flush_chunk
($name,
2526 my ($have_blame) = gitweb_check_feature
('blame');
2528 die_error
('403 Permission denied', "Permission denied");
2530 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2531 $hash_base ||= git_get_head_hash
($project);
2532 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2533 my %co = parse_commit
($hash_base)
2534 or die_error
(undef, "Reading commit failed");
2535 if (!defined $hash) {
2536 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2537 or die_error
(undef, "Error looking up file");
2539 $ftype = git_get_type
($hash);
2540 if ($ftype !~ "blob") {
2541 die_error
("400 Bad Request", "Object is not a blob");
2543 open ($fd, "-|", git_cmd
(), "blame", '-l', '--', $file_name, $hash_base)
2544 or die_error
(undef, "Open git-blame failed");
2547 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2550 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2553 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2555 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2556 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2557 git_print_page_path
($file_name, $ftype, $hash_base);
2558 my @rev_color = (qw(light2 dark2));
2559 my $num_colors = scalar(@rev_color);
2560 my $current_color = 0;
2563 <div class="page_body">
2564 <table class="blame">
2565 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2570 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2571 my ($full_rev, $author, $date, $lineno, $data) =
2572 /^([0-9a-f]{40}).*?\s\((.*?)\s+([-\d]+ [:\d]+ [-+\d]+)\s+(\d+)\)\s(.*)/;
2573 if (!exists $revdata{$full_rev}) {
2574 $revdata{$full_rev} = "$author, $date";
2576 if (!defined $last_rev) {
2577 $last_rev = $full_rev;
2578 } elsif ($last_rev ne $full_rev) {
2579 git_blame_flush_chunk_1
($chunk_cap,
2582 $rev_color[$current_color],
2585 $last_rev = $full_rev;
2586 $current_color = ++$current_color % $num_colors;
2588 elsif ($chunk_cap * 2 < @chunk) {
2589 # We have more than N*2 lines from the same
2590 # revision. Flush N lines and leave N lines
2591 # in @chunk to avoid orphaned lines.
2592 my @first = splice(@chunk, 0, $chunk_cap);
2593 git_blame_flush_chunk
($file_name,
2595 $rev_color[$current_color],
2598 push @chunk, [$lineno, $data];
2601 git_blame_flush_chunk_1
($chunk_cap,
2604 $rev_color[$current_color],
2610 or print "Reading blob failed\n";
2617 my ($have_blame) = gitweb_check_feature
('blame');
2619 die_error
('403 Permission denied', "Permission denied");
2621 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2622 $hash_base ||= git_get_head_hash
($project);
2623 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2624 my %co = parse_commit
($hash_base)
2625 or die_error
(undef, "Reading commit failed");
2626 if (!defined $hash) {
2627 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2628 or die_error
(undef, "Error lookup file");
2630 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2631 or die_error
(undef, "Open git-annotate failed");
2634 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2637 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2640 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2642 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2643 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2644 git_print_page_path
($file_name, 'blob', $hash_base);
2645 print "<div class=\"page_body\">\n";
2647 <table class="blame">
2656 my @line_class = (qw(light dark));
2657 my $line_class_len = scalar (@line_class);
2658 my $line_class_num = $#line_class;
2659 while (my $line = <$fd>) {
2671 $line_class_num = ($line_class_num + 1) % $line_class_len;
2673 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2680 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
2683 $short_rev = substr ($long_rev, 0, 8);
2684 $age = time () - $time;
2685 $age_str = age_string
($age);
2686 $age_str =~ s/ / /g;
2687 $age_class = age_class
($age);
2688 $author = esc_html
($author);
2689 $author =~ s/ / /g;
2691 $data = untabify
($data);
2692 $data = esc_html
($data);
2695 <tr class="$line_class[$line_class_num]">
2696 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2697 <td class="$age_class">$age_str</td>
2699 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2700 <td class="pre">$data</td>
2703 } # while (my $line = <$fd>)
2704 print "</table>\n\n";
2706 or print "Reading blob failed.\n";
2712 my $head = git_get_head_hash
($project);
2714 git_print_page_nav
('','', $head,undef,$head);
2715 git_print_header_div
('summary', $project);
2717 my ($taglist) = git_get_refs_list
("tags");
2719 git_tags_body
($taglist);
2725 my $head = git_get_head_hash
($project);
2727 git_print_page_nav
('','', $head,undef,$head);
2728 git_print_header_div
('summary', $project);
2730 my ($headlist) = git_get_refs_list
("heads");
2732 git_heads_body
($headlist, $head);
2737 sub git_blob_plain
{
2740 if (!defined $hash) {
2741 if (defined $file_name) {
2742 my $base = $hash_base || git_get_head_hash
($project);
2743 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2744 or die_error
(undef, "Error lookup file");
2746 die_error
(undef, "No file name defined");
2748 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2749 # blobs defined by non-textual hash id's can be cached
2754 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2755 or die_error
(undef, "Couldn't cat $file_name, $hash");
2757 $type ||= blob_mimetype
($fd, $file_name);
2759 # save as filename, even when no $file_name is given
2760 my $save_as = "$hash";
2761 if (defined $file_name) {
2762 $save_as = $file_name;
2763 } elsif ($type =~ m/^text\//) {
2770 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
2772 binmode STDOUT
, ':raw';
2774 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2782 if (!defined $hash) {
2783 if (defined $file_name) {
2784 my $base = $hash_base || git_get_head_hash
($project);
2785 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2786 or die_error
(undef, "Error lookup file");
2788 die_error
(undef, "No file name defined");
2790 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2791 # blobs defined by non-textual hash id's can be cached
2795 my ($have_blame) = gitweb_check_feature
('blame');
2796 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2797 or die_error
(undef, "Couldn't cat $file_name, $hash");
2798 my $mimetype = blob_mimetype
($fd, $file_name);
2799 if ($mimetype !~ m/^text\//) {
2801 return git_blob_plain
($mimetype);
2803 git_header_html
(undef, $expires);
2804 my $formats_nav = '';
2805 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2806 if (defined $file_name) {
2809 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2810 hash
=>$hash, file_name
=>$file_name)},
2815 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2816 hash
=>$hash, file_name
=>$file_name)},
2819 $cgi->a({-href
=> href
(action
=>"blob_plain",
2820 hash
=>$hash, file_name
=>$file_name)},
2823 $cgi->a({-href
=> href
(action
=>"blob",
2824 hash_base
=>"HEAD", file_name
=>$file_name)},
2828 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
2830 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2831 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2833 print "<div class=\"page_nav\">\n" .
2834 "<br/><br/></div>\n" .
2835 "<div class=\"title\">$hash</div>\n";
2837 git_print_page_path
($file_name, "blob", $hash_base);
2838 print "<div class=\"page_body\">\n";
2840 while (my $line = <$fd>) {
2843 $line = untabify
($line);
2844 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2845 $nr, $nr, $nr, esc_html
($line);
2848 or print "Reading blob failed.\n";
2854 my $have_snapshot = gitweb_have_snapshot
();
2856 if (!defined $hash_base) {
2857 $hash_base = "HEAD";
2859 if (!defined $hash) {
2860 if (defined $file_name) {
2861 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
2867 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
2868 or die_error
(undef, "Open git-ls-tree failed");
2869 my @entries = map { chomp; $_ } <$fd>;
2870 close $fd or die_error
(undef, "Reading tree failed");
2873 my $refs = git_get_references
();
2874 my $ref = format_ref_marker
($refs, $hash_base);
2877 my ($have_blame) = gitweb_check_feature
('blame');
2878 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2880 if (defined $file_name) {
2882 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2883 hash
=>$hash, file_name
=>$file_name)},
2885 $cgi->a({-href
=> href
(action
=>"tree",
2886 hash_base
=>"HEAD", file_name
=>$file_name)},
2889 if ($have_snapshot) {
2890 # FIXME: Should be available when we have no hash base as well.
2892 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
2895 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
2896 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2899 print "<div class=\"page_nav\">\n";
2900 print "<br/><br/></div>\n";
2901 print "<div class=\"title\">$hash</div>\n";
2903 if (defined $file_name) {
2904 $base = esc_html
("$file_name/");
2906 git_print_page_path
($file_name, 'tree', $hash_base);
2907 print "<div class=\"page_body\">\n";
2908 print "<table cellspacing=\"0\">\n";
2910 foreach my $line (@entries) {
2911 my %t = parse_ls_tree_line
($line, -z
=> 1);
2914 print "<tr class=\"dark\">\n";
2916 print "<tr class=\"light\">\n";
2920 git_print_tree_entry
(\
%t, $base, $hash_base, $have_blame);
2924 print "</table>\n" .
2930 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2931 my $have_snapshot = (defined $ctype && defined $suffix);
2932 if (!$have_snapshot) {
2933 die_error
('403 Permission denied', "Permission denied");
2936 if (!defined $hash) {
2937 $hash = git_get_head_hash
($project);
2940 my $filename = basename
($project) . "-$hash.tar.$suffix";
2943 -type
=> 'application/x-tar',
2944 -content_encoding
=> $ctype,
2945 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
2946 -status
=> '200 OK');
2948 my $git_command = git_cmd_str
();
2949 open my $fd, "-|", "$git_command tar-tree $hash \'$project\' | $command" or
2950 die_error
(undef, "Execute git-tar-tree failed.");
2951 binmode STDOUT
, ':raw';
2953 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2959 my $head = git_get_head_hash
($project);
2960 if (!defined $hash) {
2963 if (!defined $page) {
2966 my $refs = git_get_references
();
2968 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2969 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
2970 or die_error
(undef, "Open git-rev-list failed");
2971 my @revlist = map { chomp; $_ } <$fd>;
2974 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2977 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2980 my %co = parse_commit
($hash);
2982 git_print_header_div
('summary', $project);
2983 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2985 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2986 my $commit = $revlist[$i];
2987 my $ref = format_ref_marker
($refs, $commit);
2988 my %co = parse_commit
($commit);
2990 my %ad = parse_date
($co{'author_epoch'});
2991 git_print_header_div
('commit',
2992 "<span class=\"age\">$co{'age_string'}</span>" .
2993 esc_html
($co{'title'}) . $ref,
2995 print "<div class=\"title_text\">\n" .
2996 "<div class=\"log_link\">\n" .
2997 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2999 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3001 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3004 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3007 print "<div class=\"log_body\">\n";
3008 git_print_simplified_log
($co{'comment'});
3015 my %co = parse_commit
($hash);
3017 die_error
(undef, "Unknown commit object");
3019 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3020 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3022 my $parent = $co{'parent'};
3023 if (!defined $parent) {
3026 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $parent, $hash
3027 or die_error
(undef, "Open git-diff-tree failed");
3028 my @difftree = map { chomp; $_ } <$fd>;
3029 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3031 # non-textual hash id's can be cached
3033 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3036 my $refs = git_get_references
();
3037 my $ref = format_ref_marker
($refs, $co{'id'});
3039 my $have_snapshot = gitweb_have_snapshot
();
3042 if (defined $file_name && defined $co{'parent'}) {
3044 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
3047 if (defined $co{'parent'}) {
3049 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash)}, "shortlog"),
3050 $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash)}, "log");
3052 git_header_html
(undef, $expires);
3053 git_print_page_nav
('commit', defined $co{'parent'} ? '' : 'commitdiff',
3054 $hash, $co{'tree'}, $hash,
3055 join (' | ', @views_nav));
3057 if (defined $co{'parent'}) {
3058 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3060 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3062 print "<div class=\"title_text\">\n" .
3063 "<table cellspacing=\"0\">\n";
3064 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3066 "<td></td><td> $ad{'rfc2822'}";
3067 if ($ad{'hour_local'} < 6) {
3068 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3069 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3071 printf(" (%02d:%02d %s)",
3072 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3076 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3077 print "<tr><td></td><td> $cd{'rfc2822'}" .
3078 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3080 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3083 "<td class=\"sha1\">" .
3084 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3085 class => "list"}, $co{'tree'}) .
3087 "<td class=\"link\">" .
3088 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3090 if ($have_snapshot) {
3092 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3096 my $parents = $co{'parents'};
3097 foreach my $par (@$parents) {
3100 "<td class=\"sha1\">" .
3101 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3102 class => "list"}, $par) .
3104 "<td class=\"link\">" .
3105 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3107 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3114 print "<div class=\"page_body\">\n";
3115 git_print_log
($co{'comment'});
3118 git_difftree_body
(\
@difftree, $hash, $parent);
3124 my $format = shift || 'html';
3131 # preparing $fd and %diffinfo for git_patchset_body
3133 if (defined $hash_base && defined $hash_parent_base) {
3134 if (defined $file_name) {
3136 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
3138 or die_error
(undef, "Open git-diff-tree failed");
3139 @difftree = map { chomp; $_ } <$fd>;
3141 or die_error
(undef, "Reading git-diff-tree failed");
3143 or die_error
('404 Not Found', "Blob diff not found");
3145 } elsif (defined $hash &&
3146 $hash =~ /[0-9a-fA-F]{40}/) {
3147 # try to find filename from $hash
3149 # read filtered raw output
3150 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
3151 or die_error
(undef, "Open git-diff-tree failed");
3153 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3155 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3156 map { chomp; $_ } <$fd>;
3158 or die_error
(undef, "Reading git-diff-tree failed");
3160 or die_error
('404 Not Found', "Blob diff not found");
3163 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3166 if (@difftree > 1) {
3167 die_error
('404 Not Found', "Ambiguous blob diff specification");
3170 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3171 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3172 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3174 $hash_parent ||= $diffinfo{'from_id'};
3175 $hash ||= $diffinfo{'to_id'};
3177 # non-textual hash id's can be cached
3178 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3179 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3184 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3185 '-p', $hash_parent_base, $hash_base,
3187 or die_error
(undef, "Open git-diff-tree failed");
3190 # old/legacy style URI
3191 if (!%diffinfo && # if new style URI failed
3192 defined $hash && defined $hash_parent) {
3193 # fake git-diff-tree raw output
3194 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3195 $diffinfo{'from_id'} = $hash_parent;
3196 $diffinfo{'to_id'} = $hash;
3197 if (defined $file_name) {
3198 if (defined $file_parent) {
3199 $diffinfo{'status'} = '2';
3200 $diffinfo{'from_file'} = $file_parent;
3201 $diffinfo{'to_file'} = $file_name;
3202 } else { # assume not renamed
3203 $diffinfo{'status'} = '1';
3204 $diffinfo{'from_file'} = $file_name;
3205 $diffinfo{'to_file'} = $file_name;
3207 } else { # no filename given
3208 $diffinfo{'status'} = '2';
3209 $diffinfo{'from_file'} = $hash_parent;
3210 $diffinfo{'to_file'} = $hash;
3213 # non-textual hash id's can be cached
3214 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3215 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3220 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts, $hash_parent, $hash
3221 or die_error
(undef, "Open git-diff failed");
3223 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3228 if ($format eq 'html') {
3230 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3231 hash
=>$hash, hash_parent
=>$hash_parent,
3232 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3233 file_name
=>$file_name, file_parent
=>$file_parent)},
3235 git_header_html
(undef, $expires);
3236 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3237 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3238 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3240 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3241 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3243 if (defined $file_name) {
3244 git_print_page_path
($file_name, "blob", $hash_base);
3246 print "<div class=\"page_path\"></div>\n";
3249 } elsif ($format eq 'plain') {
3251 -type
=> 'text/plain',
3252 -charset
=> 'utf-8',
3253 -expires
=> $expires,
3254 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3256 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3259 die_error
(undef, "Unknown blobdiff format");
3263 if ($format eq 'html') {
3264 print "<div class=\"page_body\">\n";
3266 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3269 print "</div>\n"; # class="page_body"
3273 while (my $line = <$fd>) {
3274 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_html($diffinfo{'from_file'})!eg;
3275 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_html($diffinfo{'to_file'})!eg;
3279 last if $line =~ m!^\+\+\+!;
3287 sub git_blobdiff_plain
{
3288 git_blobdiff
('plain');
3291 sub git_commitdiff
{
3292 my $format = shift || 'html';
3293 my %co = parse_commit
($hash);
3295 die_error
(undef, "Unknown commit object");
3297 if (!defined $hash_parent) {
3298 $hash_parent = $co{'parent'} || '--root';
3304 if ($format eq 'html') {
3305 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3306 "--patch-with-raw", "--full-index", $hash_parent, $hash
3307 or die_error
(undef, "Open git-diff-tree failed");
3309 while (chomp(my $line = <$fd>)) {
3310 # empty line ends raw part of diff-tree output
3312 push @difftree, $line;
3315 } elsif ($format eq 'plain') {
3316 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3317 '-p', $hash_parent, $hash
3318 or die_error
(undef, "Open git-diff-tree failed");
3321 die_error
(undef, "Unknown commitdiff format");
3324 # non-textual hash id's can be cached
3326 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3330 # write commit message
3331 if ($format eq 'html') {
3332 my $refs = git_get_references
();
3333 my $ref = format_ref_marker
($refs, $co{'id'});
3335 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3336 hash
=>$hash, hash_parent
=>$hash_parent)},
3339 git_header_html
(undef, $expires);
3340 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3341 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3342 git_print_authorship
(\
%co);
3343 print "<div class=\"page_body\">\n";
3344 print "<div class=\"log\">\n";
3345 git_print_simplified_log
($co{'comment'}, 1); # skip title
3346 print "</div>\n"; # class="log"
3348 } elsif ($format eq 'plain') {
3349 my $refs = git_get_references
("tags");
3350 my $tagname = git_get_rev_name_tags
($hash);
3351 my $filename = basename
($project) . "-$hash.patch";
3354 -type
=> 'text/plain',
3355 -charset
=> 'utf-8',
3356 -expires
=> $expires,
3357 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3358 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3361 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3362 Subject: $co{'title'}
3364 print "X-Git-Tag: $tagname\n" if $tagname;
3365 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3367 foreach my $line (@{$co{'comment'}}) {
3374 if ($format eq 'html') {
3375 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3378 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3380 print "</div>\n"; # class="page_body"
3383 } elsif ($format eq 'plain') {
3387 or print "Reading git-diff-tree failed\n";
3391 sub git_commitdiff_plain
{
3392 git_commitdiff
('plain');
3396 if (!defined $hash_base) {
3397 $hash_base = git_get_head_hash
($project);
3399 if (!defined $page) {
3403 my %co = parse_commit
($hash_base);
3405 die_error
(undef, "Unknown commit object");
3408 my $refs = git_get_references
();
3409 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3411 if (!defined $hash && defined $file_name) {
3412 $hash = git_get_hash_by_path
($hash_base, $file_name);
3414 if (defined $hash) {
3415 $ftype = git_get_type
($hash);
3419 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3420 or die_error
(undef, "Open git-rev-list-failed");
3421 my @revlist = map { chomp; $_ } <$fd>;
3423 or die_error
(undef, "Reading git-rev-list failed");
3425 my $paging_nav = '';
3428 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3429 file_name
=>$file_name)},
3431 $paging_nav .= " ⋅ " .
3432 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3433 file_name
=>$file_name, page
=>$page-1),
3434 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3436 $paging_nav .= "first";
3437 $paging_nav .= " ⋅ prev";
3439 if ($#revlist >= (100 * ($page+1)-1)) {
3440 $paging_nav .= " ⋅ " .
3441 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3442 file_name
=>$file_name, page
=>$page+1),
3443 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3445 $paging_nav .= " ⋅ next";
3448 if ($#revlist >= (100 * ($page+1)-1)) {
3450 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3451 file_name
=>$file_name, page
=>$page+1),
3452 -title
=> "Alt-n"}, "next");
3456 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3457 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3458 git_print_page_path
($file_name, $ftype, $hash_base);
3460 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3461 $refs, $hash_base, $ftype, $next_link);
3467 if (!defined $searchtext) {
3468 die_error
(undef, "Text field empty");
3470 if (!defined $hash) {
3471 $hash = git_get_head_hash
($project);
3473 my %co = parse_commit
($hash);
3475 die_error
(undef, "Unknown commit object");
3478 my $commit_search = 1;
3479 my $author_search = 0;
3480 my $committer_search = 0;
3481 my $pickaxe_search = 0;
3482 if ($searchtext =~ s/^author\\://i) {
3484 } elsif ($searchtext =~ s/^committer\\://i) {
3485 $committer_search = 1;
3486 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3488 $pickaxe_search = 1;
3490 # pickaxe may take all resources of your box and run for several minutes
3491 # with every query - so decide by yourself how public you make this feature
3492 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3493 if (!$have_pickaxe) {
3494 die_error
('403 Permission denied', "Permission denied");
3498 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3499 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3501 print "<table cellspacing=\"0\">\n";
3503 if ($commit_search) {
3505 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", $hash or next;
3506 while (my $commit_text = <$fd>) {
3507 if (!grep m/$searchtext/i, $commit_text) {
3510 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3513 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3516 my @commit_lines = split "\n", $commit_text;
3517 my %co = parse_commit
(undef, \
@commit_lines);
3522 print "<tr class=\"dark\">\n";
3524 print "<tr class=\"light\">\n";
3527 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3528 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3530 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3531 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3532 my $comment = $co{'comment'};
3533 foreach my $line (@$comment) {
3534 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3535 my $lead = esc_html
($1) || "";
3536 $lead = chop_str
($lead, 30, 10);
3537 my $match = esc_html
($2) || "";
3538 my $trail = esc_html
($3) || "";
3539 $trail = chop_str
($trail, 30, 10);
3540 my $text = "$lead<span class=\"match\">$match</span>$trail";
3541 print chop_str
($text, 80, 5) . "<br/>\n";
3545 "<td class=\"link\">" .
3546 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3548 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3555 if ($pickaxe_search) {
3557 my $git_command = git_cmd_str
();
3558 open my $fd, "-|", "$git_command rev-list $hash | " .
3559 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3562 while (my $line = <$fd>) {
3563 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3566 $set{'from_id'} = $3;
3568 $set{'id'} = $set{'to_id'};
3569 if ($set{'id'} =~ m/0{40}/) {
3570 $set{'id'} = $set{'from_id'};
3572 if ($set{'id'} =~ m/0{40}/) {
3576 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3579 print "<tr class=\"dark\">\n";
3581 print "<tr class=\"light\">\n";
3584 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3585 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3587 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3588 -class => "list subject"},
3589 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3590 while (my $setref = shift @files) {
3592 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3593 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3595 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3599 "<td class=\"link\">" .
3600 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3602 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3606 %co = parse_commit
($1);
3616 my $head = git_get_head_hash
($project);
3617 if (!defined $hash) {
3620 if (!defined $page) {
3623 my $refs = git_get_references
();
3625 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3626 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3627 or die_error
(undef, "Open git-rev-list failed");
3628 my @revlist = map { chomp; $_ } <$fd>;
3631 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3633 if ($#revlist >= (100 * ($page+1)-1)) {
3635 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3636 -title
=> "Alt-n"}, "next");
3641 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3642 git_print_header_div
('summary', $project);
3644 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3649 ## ......................................................................
3650 ## feeds (RSS, OPML)
3653 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3654 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150", git_get_head_hash
($project)
3655 or die_error
(undef, "Open git-rev-list failed");
3656 my @revlist = map { chomp; $_ } <$fd>;
3657 close $fd or die_error
(undef, "Reading git-rev-list failed");
3658 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3660 <?xml version="1.0" encoding="utf-8"?>
3661 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3663 <title>$project $my_uri $my_url</title>
3664 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3665 <description>$project log</description>
3666 <language>en</language>
3669 for (my $i = 0; $i <= $#revlist; $i++) {
3670 my $commit = $revlist[$i];
3671 my %co = parse_commit
($commit);
3672 # we read 150, we always show 30 and the ones more recent than 48 hours
3673 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3676 my %cd = parse_date
($co{'committer_epoch'});
3677 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3678 $co{'parent'}, $co{'id'}
3680 my @difftree = map { chomp; $_ } <$fd>;
3685 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3687 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3688 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3689 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3690 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3691 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3692 "<content:encoded>" .
3694 my $comment = $co{'comment'};
3695 foreach my $line (@$comment) {
3696 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
3697 print "$line<br/>\n";
3700 foreach my $line (@difftree) {
3701 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3704 my $file = esc_html
(unquote
($7));
3705 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
3706 print "$file<br/>\n";
3709 "</content:encoded>\n" .
3712 print "</channel></rss>";
3716 my @list = git_get_projects_list
();
3718 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3720 <?xml version="1.0" encoding="utf-8"?>
3721 <opml version="1.0">
3723 <title>$site_name Git OPML Export</title>
3726 <outline text="git RSS feeds">
3729 foreach my $pr (@list) {
3731 my $head = git_get_head_hash
($proj{'path'});
3732 if (!defined $head) {
3735 $git_dir = "$projectroot/$proj{'path'}";
3736 my %co = parse_commit
($head);
3741 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3742 my $rss = "$my_url?p=$proj{'path'};a=rss";
3743 my $html = "$my_url?p=$proj{'path'};a=summary";
3744 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";