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 # filename of html text to include at top of each page
45 our $site_header = "++GITWEB_SITE_HEADER++";
46 # html text to include at home page
47 our $home_text = "++GITWEB_HOMETEXT++";
48 # filename of html text to include at bottom of each page
49 our $site_footer = "++GITWEB_SITE_FOOTER++";
52 our @stylesheets = ("++GITWEB_CSS++");
54 # default is not to define style sheet, but it can be overwritten later
58 our $logo = "++GITWEB_LOGO++";
59 # URI of GIT favicon, assumed to be image/png type
60 our $favicon = "++GITWEB_FAVICON++";
62 # source of projects list
63 our $projects_list = "++GITWEB_LIST++";
65 # show repository only if this file exists
66 # (only effective if this variable evaluates to true)
67 our $export_ok = "++GITWEB_EXPORT_OK++";
69 # only allow viewing of repositories also shown on the overview page
70 our $strict_export = "++GITWEB_STRICT_EXPORT++";
72 # list of git base URLs used for URL to where fetch project from,
73 # i.e. full URL is "$git_base_url/$project"
74 our @git_base_url_list = ("++GITWEB_BASE_URL++");
76 # default blob_plain mimetype and default charset for text/plain blob
77 our $default_blob_plain_mimetype = 'text/plain';
78 our $default_text_plain_charset = undef;
80 # file to use for guessing MIME types before trying /etc/mime.types
81 # (relative to the current git repository)
82 our $mimetypes_file = undef;
84 # You define site-wide feature defaults here; override them with
85 # $GITWEB_CONFIG as necessary.
88 # 'sub' => feature-sub (subroutine),
89 # 'override' => allow-override (boolean),
90 # 'default' => [ default options...] (array reference)}
92 # if feature is overridable (it means that allow-override has true value,
93 # then feature-sub will be called with default options as parameters;
94 # return value of feature-sub indicates if to enable specified feature
96 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
99 'sub' => \
&feature_blame
,
104 'sub' => \
&feature_snapshot
,
106 # => [content-encoding, suffix, program]
107 'default' => ['x-gzip', 'gz', 'gzip']},
110 'sub' => \
&feature_pickaxe
,
119 sub gitweb_check_feature
{
121 return unless exists $feature{$name};
122 my ($sub, $override, @defaults) = (
123 $feature{$name}{'sub'},
124 $feature{$name}{'override'},
125 @{$feature{$name}{'default'}});
126 if (!$override) { return @defaults; }
127 return $sub->(@defaults);
130 # To enable system wide have in $GITWEB_CONFIG
131 # $feature{'blame'}{'default'} = [1];
132 # To have project specific config enable override in $GITWEB_CONFIG
133 # $feature{'blame'}{'override'} = 1;
134 # and in project config gitweb.blame = 0|1;
137 my ($val) = git_get_project_config
('blame', '--bool');
139 if ($val eq 'true') {
141 } elsif ($val eq 'false') {
148 # To disable system wide have in $GITWEB_CONFIG
149 # $feature{'snapshot'}{'default'} = [undef];
150 # To have project specific config enable override in $GITWEB_CONFIG
151 # $feature{'blame'}{'override'} = 1;
152 # and in project config gitweb.snapshot = none|gzip|bzip2
154 sub feature_snapshot
{
155 my ($ctype, $suffix, $command) = @_;
157 my ($val) = git_get_project_config
('snapshot');
159 if ($val eq 'gzip') {
160 return ('x-gzip', 'gz', 'gzip');
161 } elsif ($val eq 'bzip2') {
162 return ('x-bzip2', 'bz2', 'bzip2');
163 } elsif ($val eq 'none') {
167 return ($ctype, $suffix, $command);
170 sub gitweb_have_snapshot
{
171 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
172 my $have_snapshot = (defined $ctype && defined $suffix);
174 return $have_snapshot;
177 # To enable system wide have in $GITWEB_CONFIG
178 # $feature{'pickaxe'}{'default'} = [1];
179 # To have project specific config enable override in $GITWEB_CONFIG
180 # $feature{'pickaxe'}{'override'} = 1;
181 # and in project config gitweb.pickaxe = 0|1;
183 sub feature_pickaxe
{
184 my ($val) = git_get_project_config
('pickaxe', '--bool');
186 if ($val eq 'true') {
188 } elsif ($val eq 'false') {
195 # checking HEAD file with -e is fragile if the repository was
196 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
198 sub check_head_link
{
200 my $headfile = "$dir/HEAD";
201 return ((-e
$headfile) ||
202 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
205 sub check_export_ok
{
207 return (check_head_link
($dir) &&
208 (!$export_ok || -e
"$dir/$export_ok"));
211 # rename detection options for git-diff and git-diff-tree
212 # - default is '-M', with the cost proportional to
213 # (number of removed files) * (number of new files).
214 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
215 # (number of changed files + number of removed files) * (number of new files)
216 # - even more costly is '-C', '--find-copies-harder' with cost
217 # (number of files in the original tree) * (number of new files)
218 # - one might want to include '-B' option, e.g. '-B', '-M'
219 our @diff_opts = ('-M'); # taken from git_commit
221 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
222 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
224 # version of the core git binary
225 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
227 $projects_list ||= $projectroot;
229 # ======================================================================
230 # input validation and dispatch
231 our $action = $cgi->param('a');
232 if (defined $action) {
233 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
234 die_error
(undef, "Invalid action parameter");
238 # parameters which are pathnames
239 our $project = $cgi->param('p');
240 if (defined $project) {
241 if (!validate_pathname
($project) ||
242 !(-d
"$projectroot/$project") ||
243 !check_head_link
("$projectroot/$project") ||
244 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
245 ($strict_export && !project_in_list
($project))) {
247 die_error
(undef, "No such project");
251 our $file_name = $cgi->param('f');
252 if (defined $file_name) {
253 if (!validate_pathname
($file_name)) {
254 die_error
(undef, "Invalid file parameter");
258 our $file_parent = $cgi->param('fp');
259 if (defined $file_parent) {
260 if (!validate_pathname
($file_parent)) {
261 die_error
(undef, "Invalid file parent parameter");
265 # parameters which are refnames
266 our $hash = $cgi->param('h');
268 if (!validate_refname
($hash)) {
269 die_error
(undef, "Invalid hash parameter");
273 our $hash_parent = $cgi->param('hp');
274 if (defined $hash_parent) {
275 if (!validate_refname
($hash_parent)) {
276 die_error
(undef, "Invalid hash parent parameter");
280 our $hash_base = $cgi->param('hb');
281 if (defined $hash_base) {
282 if (!validate_refname
($hash_base)) {
283 die_error
(undef, "Invalid hash base parameter");
287 our $hash_parent_base = $cgi->param('hpb');
288 if (defined $hash_parent_base) {
289 if (!validate_refname
($hash_parent_base)) {
290 die_error
(undef, "Invalid hash parent base parameter");
295 our $page = $cgi->param('pg');
297 if ($page =~ m/[^0-9]/) {
298 die_error
(undef, "Invalid page parameter");
302 our $searchtext = $cgi->param('s');
303 if (defined $searchtext) {
304 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
305 die_error
(undef, "Invalid search parameter");
307 $searchtext = quotemeta $searchtext;
310 # now read PATH_INFO and use it as alternative to parameters
311 sub evaluate_path_info
{
312 return if defined $project;
313 my $path_info = $ENV{"PATH_INFO"};
314 return if !$path_info;
315 $path_info =~ s
,^/+,,;
316 return if !$path_info;
317 # find which part of PATH_INFO is project
318 $project = $path_info;
320 while ($project && !check_head_link
("$projectroot/$project")) {
321 $project =~ s
,/*[^/]*$,,;
324 $project = validate_pathname
($project);
326 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
327 ($strict_export && !project_in_list
($project))) {
331 # do not change any parameters if an action is given using the query string
333 $path_info =~ s
,^$project/*,,;
334 my ($refname, $pathname) = split(/:/, $path_info, 2);
335 if (defined $pathname) {
336 # we got "project.git/branch:filename" or "project.git/branch:dir/"
337 # we could use git_get_type(branch:pathname), but it needs $git_dir
338 $pathname =~ s
,^/+,,;
339 if (!$pathname || substr($pathname, -1) eq "/") {
343 $action ||= "blob_plain";
345 $hash_base ||= validate_refname
($refname);
346 $file_name ||= validate_pathname
($pathname);
347 } elsif (defined $refname) {
348 # we got "project.git/branch"
349 $action ||= "shortlog";
350 $hash ||= validate_refname
($refname);
353 evaluate_path_info
();
355 # path to the current git repository
357 $git_dir = "$projectroot/$project" if $project;
361 "blame" => \
&git_blame2
,
362 "blobdiff" => \
&git_blobdiff
,
363 "blobdiff_plain" => \
&git_blobdiff_plain
,
364 "blob" => \
&git_blob
,
365 "blob_plain" => \
&git_blob_plain
,
366 "commitdiff" => \
&git_commitdiff
,
367 "commitdiff_plain" => \
&git_commitdiff_plain
,
368 "commit" => \
&git_commit
,
369 "heads" => \
&git_heads
,
370 "history" => \
&git_history
,
373 "search" => \
&git_search
,
374 "shortlog" => \
&git_shortlog
,
375 "summary" => \
&git_summary
,
377 "tags" => \
&git_tags
,
378 "tree" => \
&git_tree
,
379 "snapshot" => \
&git_snapshot
,
380 # those below don't need $project
381 "opml" => \
&git_opml
,
382 "project_list" => \
&git_project_list
,
383 "project_index" => \
&git_project_index
,
386 if (defined $project) {
387 $action ||= 'summary';
389 $action ||= 'project_list';
391 if (!defined($actions{$action})) {
392 die_error
(undef, "Unknown action");
394 if ($action !~ m/^(opml|project_list|project_index)$/ &&
396 die_error
(undef, "Project needed");
398 $actions{$action}->();
401 ## ======================================================================
416 hash_parent_base
=> "hpb",
421 my %mapping = @mapping;
423 $params{'project'} = $project unless exists $params{'project'};
425 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
427 # use PATH_INFO for project name
428 $href .= "/$params{'project'}" if defined $params{'project'};
429 delete $params{'project'};
431 # Summary just uses the project path URL
432 if (defined $params{'action'} && $params{'action'} eq 'summary') {
433 delete $params{'action'};
437 # now encode the parameters explicitly
439 for (my $i = 0; $i < @mapping; $i += 2) {
440 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
441 if (defined $params{$name}) {
442 push @result, $symbol . "=" . esc_param
($params{$name});
445 $href .= "?" . join(';', @result) if scalar @result;
451 ## ======================================================================
452 ## validation, quoting/unquoting and escaping
454 sub validate_pathname
{
455 my $input = shift || return undef;
457 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
458 # at the beginning, at the end, and between slashes.
459 # also this catches doubled slashes
460 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
464 if ($input =~ m!\0!) {
470 sub validate_refname
{
471 my $input = shift || return undef;
473 # textual hashes are O.K.
474 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
477 # it must be correct pathname
478 $input = validate_pathname
($input)
480 # restrictions on ref name according to git-check-ref-format
481 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
487 # quote unsafe chars, but keep the slash, even when it's not
488 # correct, but quoted slashes look too horrible in bookmarks
491 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
497 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
500 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
506 # replace invalid utf8 character with SUBSTITUTION sequence
509 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
510 $str = escapeHTML
($str);
511 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
512 $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1)
516 # git may return quoted and escaped filenames
519 if ($str =~ m/^"(.*)"$/) {
521 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
526 # escape tabs (convert tabs to spaces)
530 while ((my $pos = index($line, "\t")) != -1) {
531 if (my $count = (8 - ($pos % 8))) {
532 my $spaces = ' ' x
$count;
533 $line =~ s/\t/$spaces/;
540 sub project_in_list
{
542 my @list = git_get_projects_list
();
543 return @list && scalar(grep { $_->{'path'} eq $project } @list);
546 ## ----------------------------------------------------------------------
547 ## HTML aware string manipulation
552 my $add_len = shift || 10;
554 # allow only $len chars, but don't cut a word if it would fit in $add_len
555 # if it doesn't fit, cut it if it's still longer than the dots we would add
556 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
559 if (length($tail) > 4) {
561 $body =~ s/&[^;]*$//; # remove chopped character entities
566 ## ----------------------------------------------------------------------
567 ## functions returning short strings
569 # CSS class for given age value (in seconds)
573 if ($age < 60*60*2) {
575 } elsif ($age < 60*60*24*2) {
582 # convert age in seconds to "nn units ago" string
587 if ($age > 60*60*24*365*2) {
588 $age_str = (int $age/60/60/24/365);
589 $age_str .= " years ago";
590 } elsif ($age > 60*60*24*(365/12)*2) {
591 $age_str = int $age/60/60/24/(365/12);
592 $age_str .= " months ago";
593 } elsif ($age > 60*60*24*7*2) {
594 $age_str = int $age/60/60/24/7;
595 $age_str .= " weeks ago";
596 } elsif ($age > 60*60*24*2) {
597 $age_str = int $age/60/60/24;
598 $age_str .= " days ago";
599 } elsif ($age > 60*60*2) {
600 $age_str = int $age/60/60;
601 $age_str .= " hours ago";
602 } elsif ($age > 60*2) {
603 $age_str = int $age/60;
604 $age_str .= " min ago";
607 $age_str .= " sec ago";
609 $age_str .= " right now";
614 # convert file mode in octal to symbolic file mode string
616 my $mode = oct shift;
618 if (S_ISDIR
($mode & S_IFMT
)) {
620 } elsif (S_ISLNK
($mode)) {
622 } elsif (S_ISREG
($mode)) {
623 # git cares only about the executable bit
624 if ($mode & S_IXUSR
) {
634 # convert file mode in octal to file type string
638 if ($mode !~ m/^[0-7]+$/) {
644 if (S_ISDIR
($mode & S_IFMT
)) {
646 } elsif (S_ISLNK
($mode)) {
648 } elsif (S_ISREG
($mode)) {
655 ## ----------------------------------------------------------------------
656 ## functions returning short HTML fragments, or transforming HTML fragments
657 ## which don't beling to other sections
659 # format line of commit message or tag comment
660 sub format_log_line_html
{
663 $line = esc_html
($line);
664 $line =~ s/ / /g;
665 if ($line =~ m/([0-9a-fA-F]{40})/) {
667 if (git_get_type
($hash_text) eq "commit") {
669 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
670 -class => "text"}, $hash_text);
671 $line =~ s/$hash_text/$link/;
677 # format marker of refs pointing to given object
678 sub format_ref_marker
{
679 my ($refs, $id) = @_;
682 if (defined $refs->{$id}) {
683 foreach my $ref (@{$refs->{$id}}) {
684 my ($type, $name) = qw();
685 # e.g. tags/v2.6.11 or heads/next
686 if ($ref =~ m!^(.*?)s?/(.*)$!) {
694 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
699 return ' <span class="refs">'. $markers . '</span>';
705 # format, perhaps shortened and with markers, title line
706 sub format_subject_html
{
707 my ($long, $short, $href, $extra) = @_;
708 $extra = '' unless defined($extra);
710 if (length($short) < length($long)) {
711 return $cgi->a({-href
=> $href, -class => "list subject",
712 -title
=> decode
("utf8", $long, Encode
::FB_DEFAULT
)},
713 esc_html
($short) . $extra);
715 return $cgi->a({-href
=> $href, -class => "list subject"},
716 esc_html
($long) . $extra);
720 sub format_diff_line
{
722 my $char = substr($line, 0, 1);
728 $diff_class = " add";
729 } elsif ($char eq "-") {
730 $diff_class = " rem";
731 } elsif ($char eq "@") {
732 $diff_class = " chunk_header";
733 } elsif ($char eq "\\") {
734 $diff_class = " incomplete";
736 $line = untabify
($line);
737 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
740 ## ----------------------------------------------------------------------
741 ## git utility subroutines, invoking git commands
743 # returns path to the core git executable and the --git-dir parameter as list
745 return $GIT, '--git-dir='.$git_dir;
748 # returns path to the core git executable and the --git-dir parameter as string
750 return join(' ', git_cmd
());
753 # get HEAD ref of given project as hash
754 sub git_get_head_hash
{
756 my $o_git_dir = $git_dir;
758 $git_dir = "$projectroot/$project";
759 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
762 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
766 if (defined $o_git_dir) {
767 $git_dir = $o_git_dir;
772 # get type of given object
776 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
783 sub git_get_project_config
{
784 my ($key, $type) = @_;
786 return unless ($key);
787 $key =~ s/^gitweb\.//;
788 return if ($key =~ m/\W/);
790 my @x = (git_cmd
(), 'repo-config');
791 if (defined $type) { push @x, $type; }
793 push @x, "gitweb.$key";
799 # get hash of given path at given ref
800 sub git_get_hash_by_path
{
802 my $path = shift || return undef;
807 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
808 or die_error
(undef, "Open git-ls-tree failed");
810 close $fd or return undef;
812 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
813 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
814 if (defined $type && $type ne $2) {
821 ## ......................................................................
822 ## git utility functions, directly accessing git repository
824 sub git_get_project_description
{
827 open my $fd, "$projectroot/$path/description" or return undef;
834 sub git_get_project_url_list
{
837 open my $fd, "$projectroot/$path/cloneurl" or return;
838 my @git_project_url_list = map { chomp; $_ } <$fd>;
841 return wantarray ? @git_project_url_list : \
@git_project_url_list;
844 sub git_get_projects_list
{
847 if (-d
$projects_list) {
848 # search in directory
849 my $dir = $projects_list;
850 my $pfxlen = length("$dir");
853 follow_fast
=> 1, # follow symbolic links
854 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
856 # skip project-list toplevel, if we get it.
857 return if (m!^[/.]$!);
858 # only directories can be git repositories
859 return unless (-d
$_);
861 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
862 # we check related file in $projectroot
863 if (check_export_ok
("$projectroot/$subdir")) {
864 push @list, { path
=> $subdir };
865 $File::Find
::prune
= 1;
870 } elsif (-f
$projects_list) {
871 # read from file(url-encoded):
872 # 'git%2Fgit.git Linus+Torvalds'
873 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
874 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
875 open my ($fd), $projects_list or return;
876 while (my $line = <$fd>) {
878 my ($path, $owner) = split ' ', $line;
879 $path = unescape
($path);
880 $owner = unescape
($owner);
881 if (!defined $path) {
884 if (check_export_ok
("$projectroot/$path")) {
887 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
894 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
898 sub git_get_project_owner
{
902 return undef unless $project;
904 # read from file (url-encoded):
905 # 'git%2Fgit.git Linus+Torvalds'
906 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
907 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
908 if (-f
$projects_list) {
909 open (my $fd , $projects_list);
910 while (my $line = <$fd>) {
912 my ($pr, $ow) = split ' ', $line;
915 if ($pr eq $project) {
916 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
922 if (!defined $owner) {
923 $owner = get_file_owner
("$projectroot/$project");
929 sub git_get_references
{
930 my $type = shift || "";
932 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
933 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
934 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
937 while (my $line = <$fd>) {
939 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
940 if (defined $refs{$1}) {
941 push @{$refs{$1}}, $2;
951 sub git_get_rev_name_tags
{
952 my $hash = shift || return undef;
954 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
956 my $name_rev = <$fd>;
959 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
962 # catches also '$hash undefined' output
967 ## ----------------------------------------------------------------------
968 ## parse to hash functions
972 my $tz = shift || "-0000";
975 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
976 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
977 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
978 $date{'hour'} = $hour;
979 $date{'minute'} = $min;
980 $date{'mday'} = $mday;
981 $date{'day'} = $days[$wday];
982 $date{'month'} = $months[$mon];
983 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
984 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
985 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
986 $mday, $months[$mon], $hour ,$min;
988 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
989 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
990 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
991 $date{'hour_local'} = $hour;
992 $date{'minute_local'} = $min;
993 $date{'tz_local'} = $tz;
1002 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1003 $tag{'id'} = $tag_id;
1004 while (my $line = <$fd>) {
1006 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1007 $tag{'object'} = $1;
1008 } elsif ($line =~ m/^type (.+)$/) {
1010 } elsif ($line =~ m/^tag (.+)$/) {
1012 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1013 $tag{'author'} = $1;
1016 } elsif ($line =~ m/--BEGIN/) {
1017 push @comment, $line;
1019 } elsif ($line eq "") {
1023 push @comment, <$fd>;
1024 $tag{'comment'} = \
@comment;
1025 close $fd or return;
1026 if (!defined $tag{'name'}) {
1033 my $commit_id = shift;
1034 my $commit_text = shift;
1039 if (defined $commit_text) {
1040 @commit_lines = @$commit_text;
1043 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
1045 @commit_lines = split '\n', <$fd>;
1046 close $fd or return;
1050 my $header = shift @commit_lines;
1051 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1054 ($co{'id'}, my @parents) = split ' ', $header;
1055 $co{'parents'} = \
@parents;
1056 $co{'parent'} = $parents[0];
1057 while (my $line = shift @commit_lines) {
1058 last if $line eq "\n";
1059 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1061 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1063 $co{'author_epoch'} = $2;
1064 $co{'author_tz'} = $3;
1065 if ($co{'author'} =~ m/^([^<]+) </) {
1066 $co{'author_name'} = $1;
1068 $co{'author_name'} = $co{'author'};
1070 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1071 $co{'committer'} = $1;
1072 $co{'committer_epoch'} = $2;
1073 $co{'committer_tz'} = $3;
1074 $co{'committer_name'} = $co{'committer'};
1075 $co{'committer_name'} =~ s/ <.*//;
1078 if (!defined $co{'tree'}) {
1082 foreach my $title (@commit_lines) {
1085 $co{'title'} = chop_str
($title, 80, 5);
1086 # remove leading stuff of merges to make the interesting part visible
1087 if (length($title) > 50) {
1088 $title =~ s/^Automatic //;
1089 $title =~ s/^merge (of|with) /Merge ... /i;
1090 if (length($title) > 50) {
1091 $title =~ s/(http|rsync):\/\///;
1093 if (length($title) > 50) {
1094 $title =~ s/(master|www|rsync)\.//;
1096 if (length($title) > 50) {
1097 $title =~ s/kernel.org:?//;
1099 if (length($title) > 50) {
1100 $title =~ s/\/pub\/scm//;
1103 $co{'title_short'} = chop_str
($title, 50, 5);
1107 # remove added spaces
1108 foreach my $line (@commit_lines) {
1111 $co{'comment'} = \
@commit_lines;
1113 my $age = time - $co{'committer_epoch'};
1115 $co{'age_string'} = age_string
($age);
1116 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1117 if ($age > 60*60*24*7*2) {
1118 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1119 $co{'age_string_age'} = $co{'age_string'};
1121 $co{'age_string_date'} = $co{'age_string'};
1122 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1127 # parse ref from ref_file, given by ref_id, with given type
1129 my $ref_file = shift;
1131 my $type = shift || git_get_type
($ref_id);
1134 $ref_item{'type'} = $type;
1135 $ref_item{'id'} = $ref_id;
1136 $ref_item{'epoch'} = 0;
1137 $ref_item{'age'} = "unknown";
1138 if ($type eq "tag") {
1139 my %tag = parse_tag
($ref_id);
1140 $ref_item{'comment'} = $tag{'comment'};
1141 if ($tag{'type'} eq "commit") {
1142 my %co = parse_commit
($tag{'object'});
1143 $ref_item{'epoch'} = $co{'committer_epoch'};
1144 $ref_item{'age'} = $co{'age_string'};
1145 } elsif (defined($tag{'epoch'})) {
1146 my $age = time - $tag{'epoch'};
1147 $ref_item{'epoch'} = $tag{'epoch'};
1148 $ref_item{'age'} = age_string
($age);
1150 $ref_item{'reftype'} = $tag{'type'};
1151 $ref_item{'name'} = $tag{'name'};
1152 $ref_item{'refid'} = $tag{'object'};
1153 } elsif ($type eq "commit"){
1154 my %co = parse_commit
($ref_id);
1155 $ref_item{'reftype'} = "commit";
1156 $ref_item{'name'} = $ref_file;
1157 $ref_item{'title'} = $co{'title'};
1158 $ref_item{'refid'} = $ref_id;
1159 $ref_item{'epoch'} = $co{'committer_epoch'};
1160 $ref_item{'age'} = $co{'age_string'};
1162 $ref_item{'reftype'} = $type;
1163 $ref_item{'name'} = $ref_file;
1164 $ref_item{'refid'} = $ref_id;
1170 # parse line of git-diff-tree "raw" output
1171 sub parse_difftree_raw_line
{
1175 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1176 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1177 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1178 $res{'from_mode'} = $1;
1179 $res{'to_mode'} = $2;
1180 $res{'from_id'} = $3;
1182 $res{'status'} = $5;
1183 $res{'similarity'} = $6;
1184 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1185 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1187 $res{'file'} = unquote
($7);
1190 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1191 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1192 $res{'commit'} = $1;
1195 return wantarray ? %res : \
%res;
1198 # parse line of git-ls-tree output
1199 sub parse_ls_tree_line
($;%) {
1204 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1205 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1213 $res{'name'} = unquote
($4);
1216 return wantarray ? %res : \
%res;
1219 ## ......................................................................
1220 ## parse to array of hashes functions
1222 sub git_get_refs_list
{
1223 my $type = shift || "";
1228 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1230 while (my $line = <$fd>) {
1232 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?([^\^]+))(\^\{\})?$/) {
1233 if (defined $refs{$1}) {
1234 push @{$refs{$1}}, $2;
1239 if (! $4) { # unpeeled, direct reference
1240 push @refs, { hash
=> $1, name
=> $3 }; # without type
1241 } elsif ($3 eq $refs[-1]{'name'}) {
1242 # most likely a tag is followed by its peeled
1243 # (deref) one, and when that happens we know the
1244 # previous one was of type 'tag'.
1245 $refs[-1]{'type'} = "tag";
1251 foreach my $ref (@refs) {
1252 my $ref_file = $ref->{'name'};
1253 my $ref_id = $ref->{'hash'};
1255 my $type = $ref->{'type'} || git_get_type
($ref_id) || next;
1256 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1258 push @reflist, \
%ref_item;
1261 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1262 return (\
@reflist, \
%refs);
1265 ## ----------------------------------------------------------------------
1266 ## filesystem-related functions
1268 sub get_file_owner
{
1271 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1272 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1273 if (!defined $gcos) {
1277 $owner =~ s/[,;].*$//;
1278 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
1281 ## ......................................................................
1282 ## mimetype related functions
1284 sub mimetype_guess_file
{
1285 my $filename = shift;
1286 my $mimemap = shift;
1287 -r
$mimemap or return undef;
1290 open(MIME
, $mimemap) or return undef;
1292 next if m/^#/; # skip comments
1293 my ($mime, $exts) = split(/\t+/);
1294 if (defined $exts) {
1295 my @exts = split(/\s+/, $exts);
1296 foreach my $ext (@exts) {
1297 $mimemap{$ext} = $mime;
1303 $filename =~ /\.([^.]*)$/;
1304 return $mimemap{$1};
1307 sub mimetype_guess
{
1308 my $filename = shift;
1310 $filename =~ /\./ or return undef;
1312 if ($mimetypes_file) {
1313 my $file = $mimetypes_file;
1314 if ($file !~ m!^/!) { # if it is relative path
1315 # it is relative to project
1316 $file = "$projectroot/$project/$file";
1318 $mime = mimetype_guess_file
($filename, $file);
1320 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1326 my $filename = shift;
1329 my $mime = mimetype_guess
($filename);
1330 $mime and return $mime;
1334 return $default_blob_plain_mimetype unless $fd;
1337 return 'text/plain' .
1338 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1339 } elsif (! $filename) {
1340 return 'application/octet-stream';
1341 } elsif ($filename =~ m/\.png$/i) {
1343 } elsif ($filename =~ m/\.gif$/i) {
1345 } elsif ($filename =~ m/\.jpe?g$/i) {
1346 return 'image/jpeg';
1348 return 'application/octet-stream';
1352 ## ======================================================================
1353 ## functions printing HTML: header, footer, error page
1355 sub git_header_html
{
1356 my $status = shift || "200 OK";
1357 my $expires = shift;
1359 my $title = "$site_name git";
1360 if (defined $project) {
1361 $title .= " - $project";
1362 if (defined $action) {
1363 $title .= "/$action";
1364 if (defined $file_name) {
1365 $title .= " - " . esc_html
($file_name);
1366 if ($action eq "tree" && $file_name !~ m
|/$|) {
1373 # require explicit support from the UA if we are to send the page as
1374 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1375 # we have to do this because MSIE sometimes globs '*/*', pretending to
1376 # support xhtml+xml but choking when it gets what it asked for.
1377 if (defined $cgi->http('HTTP_ACCEPT') &&
1378 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1379 $cgi->Accept('application/xhtml+xml') != 0) {
1380 $content_type = 'application/xhtml+xml';
1382 $content_type = 'text/html';
1384 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1385 -status
=> $status, -expires
=> $expires);
1387 <?xml version="1.0" encoding="utf-8"?>
1388 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1389 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1390 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1391 <!-- git core binaries version $git_version -->
1393 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1394 <meta name="generator" content="gitweb/$version git/$git_version"/>
1395 <meta name="robots" content="index, nofollow"/>
1396 <title>$title</title>
1398 # print out each stylesheet that exist
1399 if (defined $stylesheet) {
1400 #provides backwards capability for those people who define style sheet in a config file
1401 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1403 foreach my $stylesheet (@stylesheets) {
1404 next unless $stylesheet;
1405 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1408 if (defined $project) {
1409 printf('<link rel="alternate" title="%s log" '.
1410 'href="%s" type="application/rss+xml"/>'."\n",
1411 esc_param
($project), href
(action
=>"rss"));
1413 printf('<link rel="alternate" title="%s projects list" '.
1414 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1415 $site_name, href
(project
=>undef, action
=>"project_index"));
1416 printf('<link rel="alternate" title="%s projects logs" '.
1417 'href="%s" type="text/x-opml"/>'."\n",
1418 $site_name, href
(project
=>undef, action
=>"opml"));
1420 if (defined $favicon) {
1421 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1427 if (-f
$site_header) {
1428 open (my $fd, $site_header);
1433 print "<div class=\"page_header\">\n" .
1434 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1435 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1437 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1438 if (defined $project) {
1439 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1440 if (defined $action) {
1444 if (!defined $searchtext) {
1448 if (defined $hash_base) {
1449 $search_hash = $hash_base;
1450 } elsif (defined $hash) {
1451 $search_hash = $hash;
1453 $search_hash = "HEAD";
1455 $cgi->param("a", "search");
1456 $cgi->param("h", $search_hash);
1457 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1458 "<div class=\"search\">\n" .
1459 $cgi->hidden(-name
=> "p") . "\n" .
1460 $cgi->hidden(-name
=> "a") . "\n" .
1461 $cgi->hidden(-name
=> "h") . "\n" .
1462 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1464 $cgi->end_form() . "\n";
1469 sub git_footer_html
{
1470 print "<div class=\"page_footer\">\n";
1471 if (defined $project) {
1472 my $descr = git_get_project_description
($project);
1473 if (defined $descr) {
1474 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1476 print $cgi->a({-href
=> href
(action
=>"rss"),
1477 -class => "rss_logo"}, "RSS") . "\n";
1479 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1480 -class => "rss_logo"}, "OPML") . " ";
1481 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1482 -class => "rss_logo"}, "TXT") . "\n";
1486 if (-f
$site_footer) {
1487 open (my $fd, $site_footer);
1497 my $status = shift || "403 Forbidden";
1498 my $error = shift || "Malformed query, file missing or permission denied";
1500 git_header_html
($status);
1502 <div class="page_body">
1512 ## ----------------------------------------------------------------------
1513 ## functions printing or outputting HTML: navigation
1515 sub git_print_page_nav
{
1516 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1517 $extra = '' if !defined $extra; # pager or formats
1519 my @navs = qw(summary shortlog log commit commitdiff tree);
1521 @navs = grep { $_ ne $suppress } @navs;
1524 my %arg = map { $_ => {action
=>$_} } @navs;
1525 if (defined $head) {
1526 for (qw(commit commitdiff)) {
1527 $arg{$_}{hash
} = $head;
1529 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1530 for (qw(shortlog log)) {
1531 $arg{$_}{hash
} = $head;
1535 $arg{tree
}{hash
} = $treehead if defined $treehead;
1536 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1538 print "<div class=\"page_nav\">\n" .
1540 map { $_ eq $current ?
1541 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1543 print "<br/>\n$extra<br/>\n" .
1547 sub format_paging_nav
{
1548 my ($action, $hash, $head, $page, $nrevs) = @_;
1552 if ($hash ne $head || $page) {
1553 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1555 $paging_nav .= "HEAD";
1559 $paging_nav .= " ⋅ " .
1560 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1561 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1563 $paging_nav .= " ⋅ prev";
1566 if ($nrevs >= (100 * ($page+1)-1)) {
1567 $paging_nav .= " ⋅ " .
1568 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1569 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1571 $paging_nav .= " ⋅ next";
1577 ## ......................................................................
1578 ## functions printing or outputting HTML: div
1580 sub git_print_header_div
{
1581 my ($action, $title, $hash, $hash_base) = @_;
1584 $args{action
} = $action;
1585 $args{hash
} = $hash if $hash;
1586 $args{hash_base
} = $hash_base if $hash_base;
1588 print "<div class=\"header\">\n" .
1589 $cgi->a({-href
=> href
(%args), -class => "title"},
1590 $title ? $title : $action) .
1594 #sub git_print_authorship (\%) {
1595 sub git_print_authorship
{
1598 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1599 print "<div class=\"author_date\">" .
1600 esc_html
($co->{'author_name'}) .
1602 if ($ad{'hour_local'} < 6) {
1603 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1604 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1606 printf(" (%02d:%02d %s)",
1607 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1612 sub git_print_page_path
{
1617 if (!defined $name) {
1618 print "<div class=\"page_path\">/</div>\n";
1620 my @dirname = split '/', $name;
1621 my $basename = pop @dirname;
1624 print "<div class=\"page_path\">";
1625 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1626 -title
=> 'tree root'}, "[$project]");
1628 foreach my $dir (@dirname) {
1629 $fullname .= ($fullname ? '/' : '') . $dir;
1630 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1632 -title
=> $fullname}, esc_html
($dir));
1635 if (defined $type && $type eq 'blob') {
1636 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1638 -title
=> $name}, esc_html
($basename));
1639 } elsif (defined $type && $type eq 'tree') {
1640 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1642 -title
=> $name}, esc_html
($basename));
1644 print esc_html
($basename);
1646 print "<br/></div>\n";
1650 # sub git_print_log (\@;%) {
1651 sub git_print_log
($;%) {
1655 if ($opts{'-remove_title'}) {
1656 # remove title, i.e. first line of log
1659 # remove leading empty lines
1660 while (defined $log->[0] && $log->[0] eq "") {
1667 foreach my $line (@$log) {
1668 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1671 if (! $opts{'-remove_signoff'}) {
1672 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1675 # remove signoff lines
1682 # print only one empty line
1683 # do not print empty line after signoff
1685 next if ($empty || $signoff);
1691 print format_log_line_html
($line) . "<br/>\n";
1694 if ($opts{'-final_empty_line'}) {
1695 # end with single empty line
1696 print "<br/>\n" unless $empty;
1700 sub git_print_simplified_log
{
1702 my $remove_title = shift;
1705 -final_empty_line
=> 1,
1706 -remove_title
=> $remove_title);
1709 # print tree entry (row of git_tree), but without encompassing <tr> element
1710 sub git_print_tree_entry
{
1711 my ($t, $basedir, $hash_base, $have_blame) = @_;
1714 $base_key{hash_base
} = $hash_base if defined $hash_base;
1716 # The format of a table row is: mode list link. Where mode is
1717 # the mode of the entry, list is the name of the entry, an href,
1718 # and link is the action links of the entry.
1720 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1721 if ($t->{'type'} eq "blob") {
1722 print "<td class=\"list\">" .
1723 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1724 file_name
=>"$basedir$t->{'name'}", %base_key),
1725 -class => "list"}, esc_html
($t->{'name'})) . "</td>\n";
1726 print "<td class=\"link\">";
1728 print $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1729 file_name
=>"$basedir$t->{'name'}", %base_key)},
1732 if (defined $hash_base) {
1736 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1737 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1741 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
1742 file_name
=>"$basedir$t->{'name'}")},
1746 } elsif ($t->{'type'} eq "tree") {
1747 print "<td class=\"list\">";
1748 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1749 file_name
=>"$basedir$t->{'name'}", %base_key)},
1750 esc_html
($t->{'name'}));
1752 print "<td class=\"link\">";
1753 if (defined $hash_base) {
1754 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1755 file_name
=>"$basedir$t->{'name'}")},
1762 ## ......................................................................
1763 ## functions printing large fragments of HTML
1765 sub git_difftree_body
{
1766 my ($difftree, $hash, $parent) = @_;
1768 print "<div class=\"list_head\">\n";
1769 if ($#{$difftree} > 10) {
1770 print(($#{$difftree} + 1) . " files changed:\n");
1774 print "<table class=\"diff_tree\">\n";
1777 foreach my $line (@{$difftree}) {
1778 my %diff = parse_difftree_raw_line
($line);
1781 print "<tr class=\"dark\">\n";
1783 print "<tr class=\"light\">\n";
1787 my ($to_mode_oct, $to_mode_str, $to_file_type);
1788 my ($from_mode_oct, $from_mode_str, $from_file_type);
1789 if ($diff{'to_mode'} ne ('0' x
6)) {
1790 $to_mode_oct = oct $diff{'to_mode'};
1791 if (S_ISREG
($to_mode_oct)) { # only for regular file
1792 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1794 $to_file_type = file_type
($diff{'to_mode'});
1796 if ($diff{'from_mode'} ne ('0' x
6)) {
1797 $from_mode_oct = oct $diff{'from_mode'};
1798 if (S_ISREG
($to_mode_oct)) { # only for regular file
1799 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1801 $from_file_type = file_type
($diff{'from_mode'});
1804 if ($diff{'status'} eq "A") { # created
1805 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1806 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1807 $mode_chng .= "]</span>";
1809 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1810 hash_base
=>$hash, file_name
=>$diff{'file'}),
1811 -class => "list"}, esc_html
($diff{'file'}));
1813 print "<td>$mode_chng</td>\n";
1814 print "<td class=\"link\">";
1815 if ($action eq 'commitdiff') {
1818 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1822 } elsif ($diff{'status'} eq "D") { # deleted
1823 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1825 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1826 hash_base
=>$parent, file_name
=>$diff{'file'}),
1827 -class => "list"}, esc_html
($diff{'file'}));
1829 print "<td>$mode_chng</td>\n";
1830 print "<td class=\"link\">";
1831 if ($action eq 'commitdiff') {
1834 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1837 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1838 file_name
=>$diff{'file'})},
1840 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1841 file_name
=>$diff{'file'})},
1845 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1846 my $mode_chnge = "";
1847 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1848 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1849 if ($from_file_type != $to_file_type) {
1850 $mode_chnge .= " from $from_file_type to $to_file_type";
1852 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1853 if ($from_mode_str && $to_mode_str) {
1854 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1855 } elsif ($to_mode_str) {
1856 $mode_chnge .= " mode: $to_mode_str";
1859 $mode_chnge .= "]</span>\n";
1862 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1863 hash_base
=>$hash, file_name
=>$diff{'file'}),
1864 -class => "list"}, esc_html
($diff{'file'}));
1866 print "<td>$mode_chnge</td>\n";
1867 print "<td class=\"link\">";
1868 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1869 if ($action eq 'commitdiff') {
1872 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1874 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1875 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1876 hash_base
=>$hash, hash_parent_base
=>$parent,
1877 file_name
=>$diff{'file'})},
1882 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
1883 file_name
=>$diff{'file'})},
1885 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
1886 file_name
=>$diff{'file'})},
1890 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1891 my %status_name = ('R' => 'moved', 'C' => 'copied');
1892 my $nstatus = $status_name{$diff{'status'}};
1894 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1895 # mode also for directories, so we cannot use $to_mode_str
1896 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1899 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1900 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1901 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1902 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1903 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1904 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1905 -class => "list"}, esc_html
($diff{'from_file'})) .
1906 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1907 "<td class=\"link\">";
1908 if ($diff{'to_id'} ne $diff{'from_id'}) {
1909 if ($action eq 'commitdiff') {
1912 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1914 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1915 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1916 hash_base
=>$hash, hash_parent_base
=>$parent,
1917 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1922 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1923 file_name
=>$diff{'from_file'})},
1925 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1926 file_name
=>$diff{'from_file'})},
1930 } # we should not encounter Unmerged (U) or Unknown (X) status
1936 sub git_patchset_body
{
1937 my ($fd, $difftree, $hash, $hash_parent) = @_;
1941 my $patch_found = 0;
1944 print "<div class=\"patchset\">\n";
1947 while (my $patch_line = <$fd>) {
1950 if ($patch_line =~ m/^diff /) { # "git diff" header
1951 # beginning of patch (in patchset)
1953 # close previous patch
1954 print "</div>\n"; # class="patch"
1956 # first patch in patchset
1959 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1961 if (ref($difftree->[$patch_idx]) eq "HASH") {
1962 $diffinfo = $difftree->[$patch_idx];
1964 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1968 # for now, no extended header, hence we skip empty patches
1969 # companion to next LINE if $in_header;
1970 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1975 if ($diffinfo->{'status'} eq "A") { # added
1976 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1977 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1978 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1979 $diffinfo->{'to_id'}) . "(new)" .
1980 "</div>\n"; # class="diff_info"
1982 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1983 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
1984 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1985 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1986 $diffinfo->{'from_id'}) . "(deleted)" .
1987 "</div>\n"; # class="diff_info"
1989 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1990 $diffinfo->{'status'} eq "C" || # copied
1991 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1992 print "<div class=\"diff_info\">" .
1993 file_type
($diffinfo->{'from_mode'}) . ":" .
1994 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1995 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
1996 $diffinfo->{'from_id'}) .
1998 file_type
($diffinfo->{'to_mode'}) . ":" .
1999 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2000 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
2001 $diffinfo->{'to_id'});
2002 print "</div>\n"; # class="diff_info"
2004 } else { # modified, mode changed, ...
2005 print "<div class=\"diff_info\">" .
2006 file_type
($diffinfo->{'from_mode'}) . ":" .
2007 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2008 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2009 $diffinfo->{'from_id'}) .
2011 file_type
($diffinfo->{'to_mode'}) . ":" .
2012 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2013 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2014 $diffinfo->{'to_id'});
2015 print "</div>\n"; # class="diff_info"
2018 #print "<div class=\"diff extended_header\">\n";
2021 } # start of patch in patchset
2024 if ($in_header && $patch_line =~ m/^---/) {
2025 #print "</div>\n"; # class="diff extended_header"
2028 my $file = $diffinfo->{'from_file'};
2029 $file ||= $diffinfo->{'file'};
2030 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2031 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
2032 -class => "list"}, esc_html
($file));
2033 $patch_line =~ s
|a
/.*$|a/$file|g
;
2034 print "<div class=\"diff from_file\">$patch_line</div>\n";
2036 $patch_line = <$fd>;
2039 #$patch_line =~ m/^+++/;
2040 $file = $diffinfo->{'to_file'};
2041 $file ||= $diffinfo->{'file'};
2042 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2043 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
2044 -class => "list"}, esc_html
($file));
2045 $patch_line =~ s
|b
/.*|b/$file|g
;
2046 print "<div class=\"diff to_file\">$patch_line</div>\n";
2050 next LINE
if $in_header;
2052 print format_diff_line
($patch_line);
2054 print "</div>\n" if $patch_found; # class="patch"
2056 print "</div>\n"; # class="patchset"
2059 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2061 sub git_shortlog_body
{
2062 # uses global variable $project
2063 my ($revlist, $from, $to, $refs, $extra) = @_;
2065 $from = 0 unless defined $from;
2066 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2068 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2070 for (my $i = $from; $i <= $to; $i++) {
2071 my $commit = $revlist->[$i];
2072 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2073 my $ref = format_ref_marker
($refs, $commit);
2074 my %co = parse_commit
($commit);
2076 print "<tr class=\"dark\">\n";
2078 print "<tr class=\"light\">\n";
2081 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2082 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2083 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2085 print format_subject_html
($co{'title'}, $co{'title_short'},
2086 href
(action
=>"commit", hash
=>$commit), $ref);
2088 "<td class=\"link\">" .
2089 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2090 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") . " | " .
2091 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2095 if (defined $extra) {
2097 "<td colspan=\"4\">$extra</td>\n" .
2103 sub git_history_body
{
2104 # Warning: assumes constant type (blob or tree) during history
2105 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2107 $from = 0 unless defined $from;
2108 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2110 print "<table class=\"history\" cellspacing=\"0\">\n";
2112 for (my $i = $from; $i <= $to; $i++) {
2113 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2118 my %co = parse_commit
($commit);
2123 my $ref = format_ref_marker
($refs, $commit);
2126 print "<tr class=\"dark\">\n";
2128 print "<tr class=\"light\">\n";
2131 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2132 # shortlog uses chop_str($co{'author_name'}, 10)
2133 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2135 # originally git_history used chop_str($co{'title'}, 50)
2136 print format_subject_html
($co{'title'}, $co{'title_short'},
2137 href
(action
=>"commit", hash
=>$commit), $ref);
2139 "<td class=\"link\">" .
2140 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2141 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2143 if ($ftype eq 'blob') {
2144 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2145 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2146 if (defined $blob_current && defined $blob_parent &&
2147 $blob_current ne $blob_parent) {
2149 $cgi->a({-href
=> href
(action
=>"blobdiff",
2150 hash
=>$blob_current, hash_parent
=>$blob_parent,
2151 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2152 file_name
=>$file_name)},
2159 if (defined $extra) {
2161 "<td colspan=\"4\">$extra</td>\n" .
2168 # uses global variable $project
2169 my ($taglist, $from, $to, $extra) = @_;
2170 $from = 0 unless defined $from;
2171 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2173 print "<table class=\"tags\" cellspacing=\"0\">\n";
2175 for (my $i = $from; $i <= $to; $i++) {
2176 my $entry = $taglist->[$i];
2178 my $comment_lines = $tag{'comment'};
2179 my $comment = shift @$comment_lines;
2181 if (defined $comment) {
2182 $comment_short = chop_str
($comment, 30, 5);
2185 print "<tr class=\"dark\">\n";
2187 print "<tr class=\"light\">\n";
2190 print "<td><i>$tag{'age'}</i></td>\n" .
2192 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2193 -class => "list name"}, esc_html
($tag{'name'})) .
2196 if (defined $comment) {
2197 print format_subject_html
($comment, $comment_short,
2198 href
(action
=>"tag", hash
=>$tag{'id'}));
2201 "<td class=\"selflink\">";
2202 if ($tag{'type'} eq "tag") {
2203 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2208 "<td class=\"link\">" . " | " .
2209 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2210 if ($tag{'reftype'} eq "commit") {
2211 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2212 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
2213 } elsif ($tag{'reftype'} eq "blob") {
2214 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2219 if (defined $extra) {
2221 "<td colspan=\"5\">$extra</td>\n" .
2227 sub git_heads_body
{
2228 # uses global variable $project
2229 my ($headlist, $head, $from, $to, $extra) = @_;
2230 $from = 0 unless defined $from;
2231 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2233 print "<table class=\"heads\" cellspacing=\"0\">\n";
2235 for (my $i = $from; $i <= $to; $i++) {
2236 my $entry = $headlist->[$i];
2238 my $curr = $tag{'id'} eq $head;
2240 print "<tr class=\"dark\">\n";
2242 print "<tr class=\"light\">\n";
2245 print "<td><i>$tag{'age'}</i></td>\n" .
2246 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
2247 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
2248 -class => "list name"},esc_html
($tag{'name'})) .
2250 "<td class=\"link\">" .
2251 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
2252 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") . " | " .
2253 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$tag{'name'}, hash_base
=>$tag{'name'})}, "tree") .
2257 if (defined $extra) {
2259 "<td colspan=\"3\">$extra</td>\n" .
2265 ## ======================================================================
2266 ## ======================================================================
2269 sub git_project_list
{
2270 my $order = $cgi->param('o');
2271 if (defined $order && $order !~ m/project|descr|owner|age/) {
2272 die_error
(undef, "Unknown order parameter");
2275 my @list = git_get_projects_list
();
2278 die_error
(undef, "No projects found");
2280 foreach my $pr (@list) {
2281 my $head = git_get_head_hash
($pr->{'path'});
2282 if (!defined $head) {
2285 $git_dir = "$projectroot/$pr->{'path'}";
2286 my %co = parse_commit
($head);
2290 $pr->{'commit'} = \
%co;
2291 if (!defined $pr->{'descr'}) {
2292 my $descr = git_get_project_description
($pr->{'path'}) || "";
2293 $pr->{'descr'} = chop_str
($descr, 25, 5);
2295 if (!defined $pr->{'owner'}) {
2296 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2298 push @projects, $pr;
2302 if (-f
$home_text) {
2303 print "<div class=\"index_include\">\n";
2304 open (my $fd, $home_text);
2309 print "<table class=\"project_list\">\n" .
2311 $order ||= "project";
2312 if ($order eq "project") {
2313 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2314 print "<th>Project</th>\n";
2317 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2318 -class => "header"}, "Project") .
2321 if ($order eq "descr") {
2322 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2323 print "<th>Description</th>\n";
2326 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2327 -class => "header"}, "Description") .
2330 if ($order eq "owner") {
2331 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2332 print "<th>Owner</th>\n";
2335 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2336 -class => "header"}, "Owner") .
2339 if ($order eq "age") {
2340 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2341 print "<th>Last Change</th>\n";
2344 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2345 -class => "header"}, "Last Change") .
2348 print "<th></th>\n" .
2351 foreach my $pr (@projects) {
2353 print "<tr class=\"dark\">\n";
2355 print "<tr class=\"light\">\n";
2358 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2359 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2360 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2361 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2362 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2363 $pr->{'commit'}{'age_string'} . "</td>\n" .
2364 "<td class=\"link\">" .
2365 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2366 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2367 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2368 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2376 sub git_project_index
{
2377 my @projects = git_get_projects_list
();
2380 -type
=> 'text/plain',
2381 -charset
=> 'utf-8',
2382 -content_disposition
=> 'inline; filename="index.aux"');
2384 foreach my $pr (@projects) {
2385 if (!exists $pr->{'owner'}) {
2386 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2389 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2390 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2391 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2392 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2396 print "$path $owner\n";
2401 my $descr = git_get_project_description
($project) || "none";
2402 my $head = git_get_head_hash
($project);
2403 my %co = parse_commit
($head);
2404 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2406 my $owner = git_get_project_owner
($project);
2408 my ($reflist, $refs) = git_get_refs_list
();
2412 foreach my $ref (@$reflist) {
2413 if ($ref->{'name'} =~ s!^heads/!!) {
2414 push @headlist, $ref;
2416 $ref->{'name'} =~ s!^tags/!!;
2417 push @taglist, $ref;
2422 git_print_page_nav
('summary','', $head);
2424 print "<div class=\"title\"> </div>\n";
2425 print "<table cellspacing=\"0\">\n" .
2426 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2427 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2428 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2429 # use per project git URL list in $projectroot/$project/cloneurl
2430 # or make project git URL from git base URL and project name
2431 my $url_tag = "URL";
2432 my @url_list = git_get_project_url_list
($project);
2433 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2434 foreach my $git_url (@url_list) {
2435 next unless $git_url;
2436 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2441 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2442 git_get_head_hash
($project)
2443 or die_error
(undef, "Open git-rev-list failed");
2444 my @revlist = map { chomp; $_ } <$fd>;
2446 git_print_header_div
('shortlog');
2447 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2448 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2451 git_print_header_div
('tags');
2452 git_tags_body
(\
@taglist, 0, 15,
2453 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2457 git_print_header_div
('heads');
2458 git_heads_body
(\
@headlist, $head, 0, 15,
2459 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2466 my $head = git_get_head_hash
($project);
2468 git_print_page_nav
('','', $head,undef,$head);
2469 my %tag = parse_tag
($hash);
2470 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2471 print "<div class=\"title_text\">\n" .
2472 "<table cellspacing=\"0\">\n" .
2474 "<td>object</td>\n" .
2475 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2476 $tag{'object'}) . "</td>\n" .
2477 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2478 $tag{'type'}) . "</td>\n" .
2480 if (defined($tag{'author'})) {
2481 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2482 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2483 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2484 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2487 print "</table>\n\n" .
2489 print "<div class=\"page_body\">";
2490 my $comment = $tag{'comment'};
2491 foreach my $line (@$comment) {
2492 print esc_html
($line) . "<br/>\n";
2502 my ($have_blame) = gitweb_check_feature
('blame');
2504 die_error
('403 Permission denied', "Permission denied");
2506 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2507 $hash_base ||= git_get_head_hash
($project);
2508 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2509 my %co = parse_commit
($hash_base)
2510 or die_error
(undef, "Reading commit failed");
2511 if (!defined $hash) {
2512 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2513 or die_error
(undef, "Error looking up file");
2515 $ftype = git_get_type
($hash);
2516 if ($ftype !~ "blob") {
2517 die_error
("400 Bad Request", "Object is not a blob");
2519 open ($fd, "-|", git_cmd
(), "blame", '-l', '--', $file_name, $hash_base)
2520 or die_error
(undef, "Open git-blame failed");
2523 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2526 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2529 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2531 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2532 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2533 git_print_page_path
($file_name, $ftype, $hash_base);
2534 my @rev_color = (qw(light2 dark2));
2535 my $num_colors = scalar(@rev_color);
2536 my $current_color = 0;
2539 <div class="page_body">
2540 <table class="blame">
2541 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2544 my ($full_rev, $author, $date, $lineno, $data) =
2545 /^([0-9a-f]{40}).*?\s\((.*?)\s+([-\d]+ [:\d]+ [-+\d]+)\s+(\d+)\)\s(.*)/;
2546 my $rev = substr($full_rev, 0, 8);
2549 if (!defined $last_rev) {
2550 $last_rev = $full_rev;
2552 } elsif ($last_rev ne $full_rev) {
2553 $last_rev = $full_rev;
2554 $current_color = ++$current_color % $num_colors;
2557 print "<tr class=\"$rev_color[$current_color]\">\n";
2558 print "<td class=\"sha1\"";
2559 if ($print_c8 == 1) {
2560 print " title=\"$author, $date\"";
2563 if ($print_c8 == 1) {
2564 print $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)},
2568 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2569 esc_html
($lineno) . "</a></td>\n";
2570 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2576 or print "Reading blob failed\n";
2583 my ($have_blame) = gitweb_check_feature
('blame');
2585 die_error
('403 Permission denied', "Permission denied");
2587 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2588 $hash_base ||= git_get_head_hash
($project);
2589 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2590 my %co = parse_commit
($hash_base)
2591 or die_error
(undef, "Reading commit failed");
2592 if (!defined $hash) {
2593 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2594 or die_error
(undef, "Error lookup file");
2596 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2597 or die_error
(undef, "Open git-annotate failed");
2600 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2603 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2606 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2608 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2609 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2610 git_print_page_path
($file_name, 'blob', $hash_base);
2611 print "<div class=\"page_body\">\n";
2613 <table class="blame">
2622 my @line_class = (qw(light dark));
2623 my $line_class_len = scalar (@line_class);
2624 my $line_class_num = $#line_class;
2625 while (my $line = <$fd>) {
2637 $line_class_num = ($line_class_num + 1) % $line_class_len;
2639 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2646 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
2649 $short_rev = substr ($long_rev, 0, 8);
2650 $age = time () - $time;
2651 $age_str = age_string
($age);
2652 $age_str =~ s/ / /g;
2653 $age_class = age_class
($age);
2654 $author = esc_html
($author);
2655 $author =~ s/ / /g;
2657 $data = untabify
($data);
2658 $data = esc_html
($data);
2661 <tr class="$line_class[$line_class_num]">
2662 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2663 <td class="$age_class">$age_str</td>
2665 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2666 <td class="pre">$data</td>
2669 } # while (my $line = <$fd>)
2670 print "</table>\n\n";
2672 or print "Reading blob failed.\n";
2678 my $head = git_get_head_hash
($project);
2680 git_print_page_nav
('','', $head,undef,$head);
2681 git_print_header_div
('summary', $project);
2683 my ($taglist) = git_get_refs_list
("tags");
2685 git_tags_body
($taglist);
2691 my $head = git_get_head_hash
($project);
2693 git_print_page_nav
('','', $head,undef,$head);
2694 git_print_header_div
('summary', $project);
2696 my ($headlist) = git_get_refs_list
("heads");
2698 git_heads_body
($headlist, $head);
2703 sub git_blob_plain
{
2706 if (!defined $hash) {
2707 if (defined $file_name) {
2708 my $base = $hash_base || git_get_head_hash
($project);
2709 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2710 or die_error
(undef, "Error lookup file");
2712 die_error
(undef, "No file name defined");
2714 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2715 # blobs defined by non-textual hash id's can be cached
2720 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2721 or die_error
(undef, "Couldn't cat $file_name, $hash");
2723 $type ||= blob_mimetype
($fd, $file_name);
2725 # save as filename, even when no $file_name is given
2726 my $save_as = "$hash";
2727 if (defined $file_name) {
2728 $save_as = $file_name;
2729 } elsif ($type =~ m/^text\//) {
2736 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
2738 binmode STDOUT
, ':raw';
2740 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2748 if (!defined $hash) {
2749 if (defined $file_name) {
2750 my $base = $hash_base || git_get_head_hash
($project);
2751 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2752 or die_error
(undef, "Error lookup file");
2754 die_error
(undef, "No file name defined");
2756 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2757 # blobs defined by non-textual hash id's can be cached
2761 my ($have_blame) = gitweb_check_feature
('blame');
2762 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2763 or die_error
(undef, "Couldn't cat $file_name, $hash");
2764 my $mimetype = blob_mimetype
($fd, $file_name);
2765 if ($mimetype !~ m/^text\//) {
2767 return git_blob_plain
($mimetype);
2769 git_header_html
(undef, $expires);
2770 my $formats_nav = '';
2771 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2772 if (defined $file_name) {
2775 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2776 hash
=>$hash, file_name
=>$file_name)},
2781 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2782 hash
=>$hash, file_name
=>$file_name)},
2785 $cgi->a({-href
=> href
(action
=>"blob_plain",
2786 hash
=>$hash, file_name
=>$file_name)},
2789 $cgi->a({-href
=> href
(action
=>"blob",
2790 hash_base
=>"HEAD", file_name
=>$file_name)},
2794 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
2796 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2797 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2799 print "<div class=\"page_nav\">\n" .
2800 "<br/><br/></div>\n" .
2801 "<div class=\"title\">$hash</div>\n";
2803 git_print_page_path
($file_name, "blob", $hash_base);
2804 print "<div class=\"page_body\">\n";
2806 while (my $line = <$fd>) {
2809 $line = untabify
($line);
2810 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2811 $nr, $nr, $nr, esc_html
($line);
2814 or print "Reading blob failed.\n";
2820 my $have_snapshot = gitweb_have_snapshot
();
2822 if (!defined $hash_base) {
2823 $hash_base = "HEAD";
2825 if (!defined $hash) {
2826 if (defined $file_name) {
2827 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
2833 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
2834 or die_error
(undef, "Open git-ls-tree failed");
2835 my @entries = map { chomp; $_ } <$fd>;
2836 close $fd or die_error
(undef, "Reading tree failed");
2839 my $refs = git_get_references
();
2840 my $ref = format_ref_marker
($refs, $hash_base);
2843 my ($have_blame) = gitweb_check_feature
('blame');
2844 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2846 if (defined $file_name) {
2848 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2849 hash
=>$hash, file_name
=>$file_name)},
2851 $cgi->a({-href
=> href
(action
=>"tree",
2852 hash_base
=>"HEAD", file_name
=>$file_name)},
2855 if ($have_snapshot) {
2856 # FIXME: Should be available when we have no hash base as well.
2858 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
2861 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
2862 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2865 print "<div class=\"page_nav\">\n";
2866 print "<br/><br/></div>\n";
2867 print "<div class=\"title\">$hash</div>\n";
2869 if (defined $file_name) {
2870 $base = esc_html
("$file_name/");
2872 git_print_page_path
($file_name, 'tree', $hash_base);
2873 print "<div class=\"page_body\">\n";
2874 print "<table cellspacing=\"0\">\n";
2876 foreach my $line (@entries) {
2877 my %t = parse_ls_tree_line
($line, -z
=> 1);
2880 print "<tr class=\"dark\">\n";
2882 print "<tr class=\"light\">\n";
2886 git_print_tree_entry
(\
%t, $base, $hash_base, $have_blame);
2890 print "</table>\n" .
2896 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2897 my $have_snapshot = (defined $ctype && defined $suffix);
2898 if (!$have_snapshot) {
2899 die_error
('403 Permission denied', "Permission denied");
2902 if (!defined $hash) {
2903 $hash = git_get_head_hash
($project);
2906 my $filename = basename
($project) . "-$hash.tar.$suffix";
2909 -type
=> 'application/x-tar',
2910 -content_encoding
=> $ctype,
2911 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
2912 -status
=> '200 OK');
2914 my $git_command = git_cmd_str
();
2915 open my $fd, "-|", "$git_command tar-tree $hash \'$project\' | $command" or
2916 die_error
(undef, "Execute git-tar-tree failed.");
2917 binmode STDOUT
, ':raw';
2919 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2925 my $head = git_get_head_hash
($project);
2926 if (!defined $hash) {
2929 if (!defined $page) {
2932 my $refs = git_get_references
();
2934 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2935 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
2936 or die_error
(undef, "Open git-rev-list failed");
2937 my @revlist = map { chomp; $_ } <$fd>;
2940 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2943 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2946 my %co = parse_commit
($hash);
2948 git_print_header_div
('summary', $project);
2949 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2951 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2952 my $commit = $revlist[$i];
2953 my $ref = format_ref_marker
($refs, $commit);
2954 my %co = parse_commit
($commit);
2956 my %ad = parse_date
($co{'author_epoch'});
2957 git_print_header_div
('commit',
2958 "<span class=\"age\">$co{'age_string'}</span>" .
2959 esc_html
($co{'title'}) . $ref,
2961 print "<div class=\"title_text\">\n" .
2962 "<div class=\"log_link\">\n" .
2963 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2965 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2967 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
2970 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2973 print "<div class=\"log_body\">\n";
2974 git_print_simplified_log
($co{'comment'});
2981 my %co = parse_commit
($hash);
2983 die_error
(undef, "Unknown commit object");
2985 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2986 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2988 my $parent = $co{'parent'};
2989 if (!defined $parent) {
2992 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $parent, $hash
2993 or die_error
(undef, "Open git-diff-tree failed");
2994 my @difftree = map { chomp; $_ } <$fd>;
2995 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2997 # non-textual hash id's can be cached
2999 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3002 my $refs = git_get_references
();
3003 my $ref = format_ref_marker
($refs, $co{'id'});
3005 my $have_snapshot = gitweb_have_snapshot
();
3008 if (defined $file_name && defined $co{'parent'}) {
3010 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
3013 if (defined $co{'parent'}) {
3015 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash)}, "shortlog"),
3016 $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash)}, "log");
3018 git_header_html
(undef, $expires);
3019 git_print_page_nav
('commit', defined $co{'parent'} ? '' : 'commitdiff',
3020 $hash, $co{'tree'}, $hash,
3021 join (' | ', @views_nav));
3023 if (defined $co{'parent'}) {
3024 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3026 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3028 print "<div class=\"title_text\">\n" .
3029 "<table cellspacing=\"0\">\n";
3030 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3032 "<td></td><td> $ad{'rfc2822'}";
3033 if ($ad{'hour_local'} < 6) {
3034 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3035 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3037 printf(" (%02d:%02d %s)",
3038 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3042 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3043 print "<tr><td></td><td> $cd{'rfc2822'}" .
3044 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3046 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3049 "<td class=\"sha1\">" .
3050 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3051 class => "list"}, $co{'tree'}) .
3053 "<td class=\"link\">" .
3054 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3056 if ($have_snapshot) {
3058 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3062 my $parents = $co{'parents'};
3063 foreach my $par (@$parents) {
3066 "<td class=\"sha1\">" .
3067 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3068 class => "list"}, $par) .
3070 "<td class=\"link\">" .
3071 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3073 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3080 print "<div class=\"page_body\">\n";
3081 git_print_log
($co{'comment'});
3084 git_difftree_body
(\
@difftree, $hash, $parent);
3090 my $format = shift || 'html';
3097 # preparing $fd and %diffinfo for git_patchset_body
3099 if (defined $hash_base && defined $hash_parent_base) {
3100 if (defined $file_name) {
3102 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
3104 or die_error
(undef, "Open git-diff-tree failed");
3105 @difftree = map { chomp; $_ } <$fd>;
3107 or die_error
(undef, "Reading git-diff-tree failed");
3109 or die_error
('404 Not Found', "Blob diff not found");
3111 } elsif (defined $hash &&
3112 $hash =~ /[0-9a-fA-F]{40}/) {
3113 # try to find filename from $hash
3115 # read filtered raw output
3116 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
3117 or die_error
(undef, "Open git-diff-tree failed");
3119 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3121 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3122 map { chomp; $_ } <$fd>;
3124 or die_error
(undef, "Reading git-diff-tree failed");
3126 or die_error
('404 Not Found', "Blob diff not found");
3129 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3132 if (@difftree > 1) {
3133 die_error
('404 Not Found', "Ambiguous blob diff specification");
3136 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3137 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3138 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3140 $hash_parent ||= $diffinfo{'from_id'};
3141 $hash ||= $diffinfo{'to_id'};
3143 # non-textual hash id's can be cached
3144 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3145 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3150 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3151 '-p', $hash_parent_base, $hash_base,
3153 or die_error
(undef, "Open git-diff-tree failed");
3156 # old/legacy style URI
3157 if (!%diffinfo && # if new style URI failed
3158 defined $hash && defined $hash_parent) {
3159 # fake git-diff-tree raw output
3160 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3161 $diffinfo{'from_id'} = $hash_parent;
3162 $diffinfo{'to_id'} = $hash;
3163 if (defined $file_name) {
3164 if (defined $file_parent) {
3165 $diffinfo{'status'} = '2';
3166 $diffinfo{'from_file'} = $file_parent;
3167 $diffinfo{'to_file'} = $file_name;
3168 } else { # assume not renamed
3169 $diffinfo{'status'} = '1';
3170 $diffinfo{'from_file'} = $file_name;
3171 $diffinfo{'to_file'} = $file_name;
3173 } else { # no filename given
3174 $diffinfo{'status'} = '2';
3175 $diffinfo{'from_file'} = $hash_parent;
3176 $diffinfo{'to_file'} = $hash;
3179 # non-textual hash id's can be cached
3180 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3181 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3186 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts, $hash_parent, $hash
3187 or die_error
(undef, "Open git-diff failed");
3189 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3194 if ($format eq 'html') {
3196 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3197 hash
=>$hash, hash_parent
=>$hash_parent,
3198 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3199 file_name
=>$file_name, file_parent
=>$file_parent)},
3201 git_header_html
(undef, $expires);
3202 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3203 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3204 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3206 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3207 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3209 if (defined $file_name) {
3210 git_print_page_path
($file_name, "blob", $hash_base);
3212 print "<div class=\"page_path\"></div>\n";
3215 } elsif ($format eq 'plain') {
3217 -type
=> 'text/plain',
3218 -charset
=> 'utf-8',
3219 -expires
=> $expires,
3220 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3222 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3225 die_error
(undef, "Unknown blobdiff format");
3229 if ($format eq 'html') {
3230 print "<div class=\"page_body\">\n";
3232 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3235 print "</div>\n"; # class="page_body"
3239 while (my $line = <$fd>) {
3240 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_html($diffinfo{'from_file'})!eg;
3241 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_html($diffinfo{'to_file'})!eg;
3245 last if $line =~ m!^\+\+\+!;
3253 sub git_blobdiff_plain
{
3254 git_blobdiff
('plain');
3257 sub git_commitdiff
{
3258 my $format = shift || 'html';
3259 my %co = parse_commit
($hash);
3261 die_error
(undef, "Unknown commit object");
3263 if (!defined $hash_parent) {
3264 $hash_parent = $co{'parent'} || '--root';
3270 if ($format eq 'html') {
3271 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3272 "--patch-with-raw", "--full-index", $hash_parent, $hash
3273 or die_error
(undef, "Open git-diff-tree failed");
3275 while (chomp(my $line = <$fd>)) {
3276 # empty line ends raw part of diff-tree output
3278 push @difftree, $line;
3281 } elsif ($format eq 'plain') {
3282 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3283 '-p', $hash_parent, $hash
3284 or die_error
(undef, "Open git-diff-tree failed");
3287 die_error
(undef, "Unknown commitdiff format");
3290 # non-textual hash id's can be cached
3292 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3296 # write commit message
3297 if ($format eq 'html') {
3298 my $refs = git_get_references
();
3299 my $ref = format_ref_marker
($refs, $co{'id'});
3301 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3302 hash
=>$hash, hash_parent
=>$hash_parent)},
3305 git_header_html
(undef, $expires);
3306 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3307 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3308 git_print_authorship
(\
%co);
3309 print "<div class=\"page_body\">\n";
3310 print "<div class=\"log\">\n";
3311 git_print_simplified_log
($co{'comment'}, 1); # skip title
3312 print "</div>\n"; # class="log"
3314 } elsif ($format eq 'plain') {
3315 my $refs = git_get_references
("tags");
3316 my $tagname = git_get_rev_name_tags
($hash);
3317 my $filename = basename
($project) . "-$hash.patch";
3320 -type
=> 'text/plain',
3321 -charset
=> 'utf-8',
3322 -expires
=> $expires,
3323 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3324 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3327 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3328 Subject: $co{'title'}
3330 print "X-Git-Tag: $tagname\n" if $tagname;
3331 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3333 foreach my $line (@{$co{'comment'}}) {
3340 if ($format eq 'html') {
3341 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3344 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3346 print "</div>\n"; # class="page_body"
3349 } elsif ($format eq 'plain') {
3353 or print "Reading git-diff-tree failed\n";
3357 sub git_commitdiff_plain
{
3358 git_commitdiff
('plain');
3362 if (!defined $hash_base) {
3363 $hash_base = git_get_head_hash
($project);
3365 if (!defined $page) {
3369 my %co = parse_commit
($hash_base);
3371 die_error
(undef, "Unknown commit object");
3374 my $refs = git_get_references
();
3375 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3377 if (!defined $hash && defined $file_name) {
3378 $hash = git_get_hash_by_path
($hash_base, $file_name);
3380 if (defined $hash) {
3381 $ftype = git_get_type
($hash);
3385 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3386 or die_error
(undef, "Open git-rev-list-failed");
3387 my @revlist = map { chomp; $_ } <$fd>;
3389 or die_error
(undef, "Reading git-rev-list failed");
3391 my $paging_nav = '';
3394 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3395 file_name
=>$file_name)},
3397 $paging_nav .= " ⋅ " .
3398 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3399 file_name
=>$file_name, page
=>$page-1),
3400 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3402 $paging_nav .= "first";
3403 $paging_nav .= " ⋅ prev";
3405 if ($#revlist >= (100 * ($page+1)-1)) {
3406 $paging_nav .= " ⋅ " .
3407 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3408 file_name
=>$file_name, page
=>$page+1),
3409 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3411 $paging_nav .= " ⋅ next";
3414 if ($#revlist >= (100 * ($page+1)-1)) {
3416 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3417 file_name
=>$file_name, page
=>$page+1),
3418 -title
=> "Alt-n"}, "next");
3422 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3423 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3424 git_print_page_path
($file_name, $ftype, $hash_base);
3426 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3427 $refs, $hash_base, $ftype, $next_link);
3433 if (!defined $searchtext) {
3434 die_error
(undef, "Text field empty");
3436 if (!defined $hash) {
3437 $hash = git_get_head_hash
($project);
3439 my %co = parse_commit
($hash);
3441 die_error
(undef, "Unknown commit object");
3444 my $commit_search = 1;
3445 my $author_search = 0;
3446 my $committer_search = 0;
3447 my $pickaxe_search = 0;
3448 if ($searchtext =~ s/^author\\://i) {
3450 } elsif ($searchtext =~ s/^committer\\://i) {
3451 $committer_search = 1;
3452 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3454 $pickaxe_search = 1;
3456 # pickaxe may take all resources of your box and run for several minutes
3457 # with every query - so decide by yourself how public you make this feature
3458 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3459 if (!$have_pickaxe) {
3460 die_error
('403 Permission denied', "Permission denied");
3464 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3465 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3467 print "<table cellspacing=\"0\">\n";
3469 if ($commit_search) {
3471 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", $hash or next;
3472 while (my $commit_text = <$fd>) {
3473 if (!grep m/$searchtext/i, $commit_text) {
3476 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3479 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3482 my @commit_lines = split "\n", $commit_text;
3483 my %co = parse_commit
(undef, \
@commit_lines);
3488 print "<tr class=\"dark\">\n";
3490 print "<tr class=\"light\">\n";
3493 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3494 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3496 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3497 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3498 my $comment = $co{'comment'};
3499 foreach my $line (@$comment) {
3500 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3501 my $lead = esc_html
($1) || "";
3502 $lead = chop_str
($lead, 30, 10);
3503 my $match = esc_html
($2) || "";
3504 my $trail = esc_html
($3) || "";
3505 $trail = chop_str
($trail, 30, 10);
3506 my $text = "$lead<span class=\"match\">$match</span>$trail";
3507 print chop_str
($text, 80, 5) . "<br/>\n";
3511 "<td class=\"link\">" .
3512 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3514 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3521 if ($pickaxe_search) {
3523 my $git_command = git_cmd_str
();
3524 open my $fd, "-|", "$git_command rev-list $hash | " .
3525 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3528 while (my $line = <$fd>) {
3529 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3532 $set{'from_id'} = $3;
3534 $set{'id'} = $set{'to_id'};
3535 if ($set{'id'} =~ m/0{40}/) {
3536 $set{'id'} = $set{'from_id'};
3538 if ($set{'id'} =~ m/0{40}/) {
3542 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3545 print "<tr class=\"dark\">\n";
3547 print "<tr class=\"light\">\n";
3550 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3551 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3553 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3554 -class => "list subject"},
3555 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3556 while (my $setref = shift @files) {
3558 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3559 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3561 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3565 "<td class=\"link\">" .
3566 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3568 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3572 %co = parse_commit
($1);
3582 my $head = git_get_head_hash
($project);
3583 if (!defined $hash) {
3586 if (!defined $page) {
3589 my $refs = git_get_references
();
3591 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3592 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3593 or die_error
(undef, "Open git-rev-list failed");
3594 my @revlist = map { chomp; $_ } <$fd>;
3597 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3599 if ($#revlist >= (100 * ($page+1)-1)) {
3601 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3602 -title
=> "Alt-n"}, "next");
3607 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3608 git_print_header_div
('summary', $project);
3610 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3615 ## ......................................................................
3616 ## feeds (RSS, OPML)
3619 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3620 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150", git_get_head_hash
($project)
3621 or die_error
(undef, "Open git-rev-list failed");
3622 my @revlist = map { chomp; $_ } <$fd>;
3623 close $fd or die_error
(undef, "Reading git-rev-list failed");
3624 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3626 <?xml version="1.0" encoding="utf-8"?>
3627 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3629 <title>$project $my_uri $my_url</title>
3630 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3631 <description>$project log</description>
3632 <language>en</language>
3635 for (my $i = 0; $i <= $#revlist; $i++) {
3636 my $commit = $revlist[$i];
3637 my %co = parse_commit
($commit);
3638 # we read 150, we always show 30 and the ones more recent than 48 hours
3639 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3642 my %cd = parse_date
($co{'committer_epoch'});
3643 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3644 $co{'parent'}, $co{'id'}
3646 my @difftree = map { chomp; $_ } <$fd>;
3651 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3653 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3654 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3655 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3656 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3657 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3658 "<content:encoded>" .
3660 my $comment = $co{'comment'};
3661 foreach my $line (@$comment) {
3662 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
3663 print "$line<br/>\n";
3666 foreach my $line (@difftree) {
3667 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3670 my $file = esc_html
(unquote
($7));
3671 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
3672 print "$file<br/>\n";
3675 "</content:encoded>\n" .
3678 print "</channel></rss>";
3682 my @list = git_get_projects_list
();
3684 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3686 <?xml version="1.0" encoding="utf-8"?>
3687 <opml version="1.0">
3689 <title>$site_name Git OPML Export</title>
3692 <outline text="git RSS feeds">
3695 foreach my $pr (@list) {
3697 my $head = git_get_head_hash
($proj{'path'});
3698 if (!defined $head) {
3701 $git_dir = "$projectroot/$proj{'path'}";
3702 my %co = parse_commit
($head);
3707 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3708 my $rss = "$my_url?p=$proj{'path'};a=rss";
3709 my $html = "$my_url?p=$proj{'path'};a=summary";
3710 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";