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 CGI
->compile() if $ENV{'MOD_PERL'};
26 our $version = "debian.1.5.6.1.19.ge6b2";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # core git executable to use
31 # this can just be "git" if your webserver has a sensible PATH
32 our $GIT = "/usr/bin/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "/pub/git";
38 # fs traversing limit for getting project list
39 # the number is relative to the projectroot
40 our $project_maxdepth = 2007;
42 # target of the home link on top of all pages
43 our $home_link = $my_uri || "/";
45 # string of the home link on top of all pages
46 our $home_link_str = "projects";
48 # name of your site or organization to appear in page titles
49 # replace this with something more descriptive for clearer bookmarks
51 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
53 # filename of html text to include at top of each page
54 our $site_header = "";
55 # html text to include at home page
56 our $home_text = "indextext.html";
57 # filename of html text to include at bottom of each page
58 our $site_footer = "";
59 # filename of cached version of front page
60 our $cached_front_page = "";
63 our @stylesheets = ("gitweb.css");
64 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
65 our $stylesheet = undef;
66 # URI of GIT logo (72x27 size)
67 our $logo = "git-logo.png";
68 # URI of GIT favicon, assumed to be image/png type
69 our $favicon = "git-favicon.png";
71 # URI and label (title) of GIT logo link
72 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
73 #our $logo_label = "git documentation";
74 our $logo_url = "http://git.or.cz/";
75 our $logo_label = "git homepage";
77 # source of projects list
78 our $projects_list = "";
80 # the width (in characters) of the projects list "Description" column
81 our $projects_list_description_width = 25;
83 # default order of projects list
84 # valid values are none, project, descr, owner, and age
85 our $default_projects_order = "project";
87 # show repository only if this file exists
88 # (only effective if this variable evaluates to true)
91 # only allow viewing of repositories also shown on the overview page
92 our $strict_export = "";
94 # list of git base URLs used for URL to where fetch project from,
95 # i.e. full URL is "$git_base_url/$project"
96 our @git_base_url_list = grep { $_ ne '' } ("");
98 # default blob_plain mimetype and default charset for text/plain blob
99 our $default_blob_plain_mimetype = 'text/plain';
100 our $default_text_plain_charset = undef;
102 # file to use for guessing MIME types before trying /etc/mime.types
103 # (relative to the current git repository)
104 our $mimetypes_file = undef;
106 # assume this charset if line contains non-UTF-8 characters;
107 # it should be valid encoding (see Encoding::Supported(3pm) for list),
108 # for which encoding all byte sequences are valid, for example
109 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
110 # could be even 'utf-8' for the old behavior)
111 our $fallback_encoding = 'latin1';
113 # rename detection options for git-diff and git-diff-tree
114 # - default is '-M', with the cost proportional to
115 # (number of removed files) * (number of new files).
116 # - more costly is '-C' (which implies '-M'), with the cost proportional to
117 # (number of changed files + number of removed files) * (number of new files)
118 # - even more costly is '-C', '--find-copies-harder' with cost
119 # (number of files in the original tree) * (number of new files)
120 # - one might want to include '-B' option, e.g. '-B', '-M'
121 our @diff_opts = ('-M'); # taken from git_commit
123 # information about snapshot formats that gitweb is capable of serving
124 our %known_snapshot_formats = (
126 # 'display' => display name,
127 # 'type' => mime type,
128 # 'suffix' => filename suffix,
129 # 'format' => --format for git-archive,
130 # 'compressor' => [compressor command and arguments]
131 # (array reference, optional)}
134 'display' => 'tar.gz',
135 'type' => 'application/x-gzip',
136 'suffix' => '.tar.gz',
138 'compressor' => ['gzip']},
141 'display' => 'tar.bz2',
142 'type' => 'application/x-bzip2',
143 'suffix' => '.tar.bz2',
145 'compressor' => ['bzip2']},
149 'type' => 'application/x-zip',
154 # Aliases so we understand old gitweb.snapshot values in repository
156 our %known_snapshot_format_aliases = (
160 # backward compatibility: legacy gitweb config support
161 'x-gzip' => undef, 'gz' => undef,
162 'x-bzip2' => undef, 'bz2' => undef,
163 'x-zip' => undef, '' => undef,
166 # You define site-wide feature defaults here; override them with
167 # $GITWEB_CONFIG as necessary.
170 # 'sub' => feature-sub (subroutine),
171 # 'override' => allow-override (boolean),
172 # 'default' => [ default options...] (array reference)}
174 # if feature is overridable (it means that allow-override has true value),
175 # then feature-sub will be called with default options as parameters;
176 # return value of feature-sub indicates if to enable specified feature
178 # if there is no 'sub' key (no feature-sub), then feature cannot be
181 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
183 # Enable the 'blame' blob view, showing the last commit that modified
184 # each line in the file. This can be very CPU-intensive.
186 # To enable system wide have in $GITWEB_CONFIG
187 # $feature{'blame'}{'default'} = [1];
188 # To have project specific config enable override in $GITWEB_CONFIG
189 # $feature{'blame'}{'override'} = 1;
190 # and in project config gitweb.blame = 0|1;
192 'sub' => \
&feature_blame
,
196 # Enable the 'snapshot' link, providing a compressed archive of any
197 # tree. This can potentially generate high traffic if you have large
200 # Value is a list of formats defined in %known_snapshot_formats that
202 # To disable system wide have in $GITWEB_CONFIG
203 # $feature{'snapshot'}{'default'} = [];
204 # To have project specific config enable override in $GITWEB_CONFIG
205 # $feature{'snapshot'}{'override'} = 1;
206 # and in project config, a comma-separated list of formats or "none"
207 # to disable. Example: gitweb.snapshot = tbz2,zip;
209 'sub' => \
&feature_snapshot
,
211 'default' => ['tgz']},
213 # Enable text search, which will list the commits which match author,
214 # committer or commit text to a given string. Enabled by default.
215 # Project specific override is not supported.
220 # Enable grep search, which will list the files in currently selected
221 # tree containing the given string. Enabled by default. This can be
222 # potentially CPU-intensive, of course.
224 # To enable system wide have in $GITWEB_CONFIG
225 # $feature{'grep'}{'default'} = [1];
226 # To have project specific config enable override in $GITWEB_CONFIG
227 # $feature{'grep'}{'override'} = 1;
228 # and in project config gitweb.grep = 0|1;
233 # Enable the pickaxe search, which will list the commits that modified
234 # a given string in a file. This can be practical and quite faster
235 # alternative to 'blame', but still potentially CPU-intensive.
237 # To enable system wide have in $GITWEB_CONFIG
238 # $feature{'pickaxe'}{'default'} = [1];
239 # To have project specific config enable override in $GITWEB_CONFIG
240 # $feature{'pickaxe'}{'override'} = 1;
241 # and in project config gitweb.pickaxe = 0|1;
243 'sub' => \
&feature_pickaxe
,
247 # Make gitweb use an alternative format of the URLs which can be
248 # more readable and natural-looking: project name is embedded
249 # directly in the path and the query string contains other
250 # auxiliary information. All gitweb installations recognize
251 # URL in either format; this configures in which formats gitweb
254 # To enable system wide have in $GITWEB_CONFIG
255 # $feature{'pathinfo'}{'default'} = [1];
256 # Project specific override is not supported.
258 # Note that you will need to change the default location of CSS,
259 # favicon, logo and possibly other files to an absolute URL. Also,
260 # if gitweb.cgi serves as your indexfile, you will need to force
261 # $my_uri to contain the script name in your $GITWEB_CONFIG.
266 # Make gitweb consider projects in project root subdirectories
267 # to be forks of existing projects. Given project $projname.git,
268 # projects matching $projname/*.git will not be shown in the main
269 # projects list, instead a '+' mark will be added to $projname
270 # there and a 'forks' view will be enabled for the project, listing
271 # all the forks. If project list is taken from a file, forks have
272 # to be listed after the main project.
274 # To enable system wide have in $GITWEB_CONFIG
275 # $feature{'forks'}{'default'} = [1];
276 # Project specific override is not supported.
282 sub gitweb_check_feature
{
284 return unless exists $feature{$name};
285 my ($sub, $override, @defaults) = (
286 $feature{$name}{'sub'},
287 $feature{$name}{'override'},
288 @
{$feature{$name}{'default'}});
289 if (!$override) { return @defaults; }
291 warn "feature $name is not overrideable";
294 return $sub->(@defaults);
298 my ($val) = git_get_project_config
('blame', '--bool');
300 if ($val eq 'true') {
302 } elsif ($val eq 'false') {
309 sub feature_snapshot
{
312 my ($val) = git_get_project_config
('snapshot');
315 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
322 my ($val) = git_get_project_config
('grep', '--bool');
324 if ($val eq 'true') {
326 } elsif ($val eq 'false') {
333 sub feature_pickaxe
{
334 my ($val) = git_get_project_config
('pickaxe', '--bool');
336 if ($val eq 'true') {
338 } elsif ($val eq 'false') {
345 # checking HEAD file with -e is fragile if the repository was
346 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
348 sub check_head_link
{
350 my $headfile = "$dir/HEAD";
351 return ((-e
$headfile) ||
352 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
355 sub check_export_ok
{
357 return (check_head_link
($dir) &&
358 (!$export_ok || -e
"$dir/$export_ok"));
361 # process alternate names for backward compatibility
362 # filter out unsupported (unknown) snapshot formats
363 sub filter_snapshot_fmts
{
367 exists $known_snapshot_format_aliases{$_} ?
368 $known_snapshot_format_aliases{$_} : $_} @fmts;
369 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
373 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "gitweb_config.perl";
374 if (-e
$GITWEB_CONFIG) {
377 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "/etc/gitweb.conf";
378 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
381 # version of the core git binary
382 our $git_version = qx("$GIT" --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
384 $projects_list ||= $projectroot;
386 # ======================================================================
387 # input validation and dispatch
388 our $action = $cgi->param('a');
389 if (defined $action) {
390 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
391 die_error
(undef, "Invalid action parameter");
395 # parameters which are pathnames
396 our $project = $cgi->param('p');
397 if (defined $project) {
398 if (!validate_pathname
($project) ||
399 !(-d
"$projectroot/$project") ||
400 !check_head_link
("$projectroot/$project") ||
401 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
402 ($strict_export && !project_in_list
($project))) {
404 die_error
(undef, "No such project");
408 our $file_name = $cgi->param('f');
409 if (defined $file_name) {
410 if (!validate_pathname
($file_name)) {
411 die_error
(undef, "Invalid file parameter");
415 our $file_parent = $cgi->param('fp');
416 if (defined $file_parent) {
417 if (!validate_pathname
($file_parent)) {
418 die_error
(undef, "Invalid file parent parameter");
422 sub git_send_cached_front_page
{
423 my $status = shift || "200 OK";
426 # require explicit support from the UA if we are to send the page as
427 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
428 # we have to do this because MSIE sometimes globs '*/*', pretending to
429 # support xhtml+xml but choking when it gets what it asked for.
430 if (defined $cgi->http('HTTP_ACCEPT') &&
431 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
432 $cgi->Accept('application/xhtml+xml') != 0) {
433 $content_type = 'application/xhtml+xml';
435 $content_type = 'text/html';
437 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
438 -status
=> $status, -expires
=> $expires);
439 open (my $fd, $cached_front_page);
445 # Display a cached page if no parameters were provided and the
446 # "nocache" parameter was not passed.
447 our $nocache = $cgi->param('nocache');
448 our @params = $cgi->Vars;
449 if ($cached_front_page && ! defined $nocache && scalar @params == 0
450 && -f
$cached_front_page && -r
$cached_front_page) {
451 git_send_cached_front_page
();
454 # parameters which are refnames
455 our $hash = $cgi->param('h');
457 if (!validate_refname
($hash)) {
458 die_error
(undef, "Invalid hash parameter");
462 our $hash_parent = $cgi->param('hp');
463 if (defined $hash_parent) {
464 if (!validate_refname
($hash_parent)) {
465 die_error
(undef, "Invalid hash parent parameter");
469 our $hash_base = $cgi->param('hb');
470 if (defined $hash_base) {
471 if (!validate_refname
($hash_base)) {
472 die_error
(undef, "Invalid hash base parameter");
476 my %allowed_options = (
477 "--no-merges" => [ qw(rss atom log shortlog history) ],
480 our @extra_options = $cgi->param('opt');
481 if (defined @extra_options) {
482 foreach my $opt (@extra_options) {
483 if (not exists $allowed_options{$opt}) {
484 die_error
(undef, "Invalid option parameter");
486 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
487 die_error
(undef, "Invalid option parameter for this action");
492 our $hash_parent_base = $cgi->param('hpb');
493 if (defined $hash_parent_base) {
494 if (!validate_refname
($hash_parent_base)) {
495 die_error
(undef, "Invalid hash parent base parameter");
500 our $page = $cgi->param('pg');
502 if ($page =~ m/[^0-9]/) {
503 die_error
(undef, "Invalid page parameter");
507 our $searchtype = $cgi->param('st');
508 if (defined $searchtype) {
509 if ($searchtype =~ m/[^a-z]/) {
510 die_error
(undef, "Invalid searchtype parameter");
514 our $search_use_regexp = $cgi->param('sr');
516 our $searchtext = $cgi->param('s');
518 if (defined $searchtext) {
519 if (length($searchtext) < 2) {
520 die_error
(undef, "At least two characters are required for search parameter");
522 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
525 # now read PATH_INFO and use it as alternative to parameters
526 sub evaluate_path_info
{
527 return if defined $project;
528 my $path_info = $ENV{"PATH_INFO"};
529 return if !$path_info;
530 $path_info =~ s
,^/+,,;
531 return if !$path_info;
532 # find which part of PATH_INFO is project
533 $project = $path_info;
535 while ($project && !check_head_link
("$projectroot/$project")) {
536 $project =~ s
,/*[^/]*$,,;
539 $project = validate_pathname
($project);
541 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
542 ($strict_export && !project_in_list
($project))) {
546 # do not change any parameters if an action is given using the query string
548 $path_info =~ s
,^\Q
$project\E
/*,,;
549 my ($refname, $pathname) = split(/:/, $path_info, 2);
550 if (defined $pathname) {
551 # we got "project.git/branch:filename" or "project.git/branch:dir/"
552 # we could use git_get_type(branch:pathname), but it needs $git_dir
553 $pathname =~ s
,^/+,,;
554 if (!$pathname || substr($pathname, -1) eq "/") {
558 $action ||= "blob_plain";
560 $hash_base ||= validate_refname
($refname);
561 $file_name ||= validate_pathname
($pathname);
562 } elsif (defined $refname) {
563 # we got "project.git/branch"
564 $action ||= "shortlog";
565 $hash ||= validate_refname
($refname);
568 evaluate_path_info
();
570 # path to the current git repository
572 $git_dir = "$projectroot/$project" if $project;
576 "blame" => \
&git_blame2
,
577 "blobdiff" => \
&git_blobdiff
,
578 "blobdiff_plain" => \
&git_blobdiff_plain
,
579 "blob" => \
&git_blob
,
580 "blob_plain" => \
&git_blob_plain
,
581 "commitdiff" => \
&git_commitdiff
,
582 "commitdiff_plain" => \
&git_commitdiff_plain
,
583 "commit" => \
&git_commit
,
584 "forks" => \
&git_forks
,
585 "heads" => \
&git_heads
,
586 "history" => \
&git_history
,
589 "atom" => \
&git_atom
,
590 "search" => \
&git_search
,
591 "search_help" => \
&git_search_help
,
592 "shortlog" => \
&git_shortlog
,
593 "summary" => \
&git_summary
,
595 "tags" => \
&git_tags
,
596 "tree" => \
&git_tree
,
597 "snapshot" => \
&git_snapshot
,
598 "object" => \
&git_object
,
599 # those below don't need $project
600 "opml" => \
&git_opml
,
601 "project_list" => \
&git_project_list
,
602 "project_index" => \
&git_project_index
,
605 if (!defined $action) {
607 $action = git_get_type
($hash);
608 } elsif (defined $hash_base && defined $file_name) {
609 $action = git_get_type
("$hash_base:$file_name");
610 } elsif (defined $project) {
613 $action = 'project_list';
616 if (!defined($actions{$action})) {
617 die_error
(undef, "Unknown action");
619 if ($action !~ m/^(opml|project_list|project_index)$/ &&
621 die_error
(undef, "Project needed");
623 $actions{$action}->();
626 ## ======================================================================
631 # default is to use -absolute url() i.e. $my_uri
632 my $href = $params{-full
} ?
$my_url : $my_uri;
634 # XXX: Warning: If you touch this, check the search form for updating,
645 hash_parent_base
=> "hpb",
650 snapshot_format
=> "sf",
651 extra_options
=> "opt",
652 search_use_regexp
=> "sr",
654 my %mapping = @mapping;
656 $params{'project'} = $project unless exists $params{'project'};
658 if ($params{-replay
}) {
659 while (my ($name, $symbol) = each %mapping) {
660 if (!exists $params{$name}) {
661 # to allow for multivalued params we use arrayref form
662 $params{$name} = [ $cgi->param($symbol) ];
667 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
669 # use PATH_INFO for project name
670 $href .= "/".esc_url
($params{'project'}) if defined $params{'project'};
671 delete $params{'project'};
673 # Summary just uses the project path URL
674 if (defined $params{'action'} && $params{'action'} eq 'summary') {
675 delete $params{'action'};
679 # now encode the parameters explicitly
681 for (my $i = 0; $i < @mapping; $i += 2) {
682 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
683 if (defined $params{$name}) {
684 if (ref($params{$name}) eq "ARRAY") {
685 foreach my $par (@
{$params{$name}}) {
686 push @result, $symbol . "=" . esc_param
($par);
689 push @result, $symbol . "=" . esc_param
($params{$name});
693 $href .= "?" . join(';', @result) if scalar @result;
699 ## ======================================================================
700 ## validation, quoting/unquoting and escaping
702 sub validate_pathname
{
703 my $input = shift || return undef;
705 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
706 # at the beginning, at the end, and between slashes.
707 # also this catches doubled slashes
708 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
712 if ($input =~ m!\0!) {
718 sub validate_refname
{
719 my $input = shift || return undef;
721 # textual hashes are O.K.
722 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
725 # it must be correct pathname
726 $input = validate_pathname
($input)
728 # restrictions on ref name according to git-check-ref-format
729 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
735 # decode sequences of octets in utf8 into Perl's internal form,
736 # which is utf-8 with utf8 flag set if needed. gitweb writes out
737 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
740 if (utf8
::valid
($str)) {
744 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
748 # quote unsafe chars, but keep the slash, even when it's not
749 # correct, but quoted slashes look too horrible in bookmarks
752 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
758 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
761 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
767 # replace invalid utf8 character with SUBSTITUTION sequence
772 $str = to_utf8
($str);
773 $str = $cgi->escapeHTML($str);
774 if ($opts{'-nbsp'}) {
775 $str =~ s/ / /g;
777 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
781 # quote control characters and escape filename to HTML
786 $str = to_utf8
($str);
787 $str = $cgi->escapeHTML($str);
788 if ($opts{'-nbsp'}) {
789 $str =~ s/ / /g;
791 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
795 # Make control characters "printable", using character escape codes (CEC)
799 my %es = ( # character escape codes, aka escape sequences
800 "\t" => '\t', # tab (HT)
801 "\n" => '\n', # line feed (LF)
802 "\r" => '\r', # carrige return (CR)
803 "\f" => '\f', # form feed (FF)
804 "\b" => '\b', # backspace (BS)
805 "\a" => '\a', # alarm (bell) (BEL)
806 "\e" => '\e', # escape (ESC)
807 "\013" => '\v', # vertical tab (VT)
808 "\000" => '\0', # nul character (NUL)
810 my $chr = ( (exists $es{$cntrl})
812 : sprintf('\%03o', ord($cntrl)) );
813 if ($opts{-nohtml
}) {
816 return "<span class=\"cntrl\">$chr</span>";
820 # Alternatively use unicode control pictures codepoints,
821 # Unicode "printable representation" (PR)
826 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
827 if ($opts{-nohtml
}) {
830 return "<span class=\"cntrl\">$chr</span>";
834 # git may return quoted and escaped filenames
840 my %es = ( # character escape codes, aka escape sequences
841 't' => "\t", # tab (HT, TAB)
842 'n' => "\n", # newline (NL)
843 'r' => "\r", # return (CR)
844 'f' => "\f", # form feed (FF)
845 'b' => "\b", # backspace (BS)
846 'a' => "\a", # alarm (bell) (BEL)
847 'e' => "\e", # escape (ESC)
848 'v' => "\013", # vertical tab (VT)
851 if ($seq =~ m/^[0-7]{1,3}$/) {
852 # octal char sequence
853 return chr(oct($seq));
854 } elsif (exists $es{$seq}) {
855 # C escape sequence, aka character escape code
858 # quoted ordinary character
862 if ($str =~ m/^"(.*)"$/) {
865 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
870 # escape tabs (convert tabs to spaces)
874 while ((my $pos = index($line, "\t")) != -1) {
875 if (my $count = (8 - ($pos % 8))) {
876 my $spaces = ' ' x
$count;
877 $line =~ s/\t/$spaces/;
884 sub project_in_list
{
886 my @list = git_get_projects_list
();
887 return @list && scalar(grep { $_->{'path'} eq $project } @list);
890 ## ----------------------------------------------------------------------
891 ## HTML aware string manipulation
893 # Try to chop given string on a word boundary between position
894 # $len and $len+$add_len. If there is no word boundary there,
895 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
896 # (marking chopped part) would be longer than given string.
900 my $add_len = shift || 10;
901 my $where = shift || 'right'; # 'left' | 'center' | 'right'
903 # Make sure perl knows it is utf8 encoded so we don't
904 # cut in the middle of a utf8 multibyte char.
905 $str = to_utf8
($str);
907 # allow only $len chars, but don't cut a word if it would fit in $add_len
908 # if it doesn't fit, cut it if it's still longer than the dots we would add
909 # remove chopped character entities entirely
911 # when chopping in the middle, distribute $len into left and right part
912 # return early if chopping wouldn't make string shorter
913 if ($where eq 'center') {
914 return $str if ($len + 5 >= length($str)); # filler is length 5
917 return $str if ($len + 4 >= length($str)); # filler is length 4
920 # regexps: ending and beginning with word part up to $add_len
921 my $endre = qr/.{$len}\w{0,$add_len}/;
922 my $begre = qr/\w{0,$add_len}.{$len}/;
924 if ($where eq 'left') {
925 $str =~ m/^(.*?)($begre)$/;
926 my ($lead, $body) = ($1, $2);
927 if (length($lead) > 4) {
928 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
933 } elsif ($where eq 'center') {
934 $str =~ m/^($endre)(.*)$/;
935 my ($left, $str) = ($1, $2);
936 $str =~ m/^(.*?)($begre)$/;
937 my ($mid, $right) = ($1, $2);
938 if (length($mid) > 5) {
939 $left =~ s/&[^;]*$//;
940 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
943 return "$left$mid$right";
946 $str =~ m/^($endre)(.*)$/;
949 if (length($tail) > 4) {
950 $body =~ s/&[^;]*$//;
957 # takes the same arguments as chop_str, but also wraps a <span> around the
958 # result with a title attribute if it does get chopped. Additionally, the
959 # string is HTML-escaped.
960 sub chop_and_escape_str
{
963 my $chopped = chop_str
(@_);
964 if ($chopped eq $str) {
965 return esc_html
($chopped);
967 $str =~ s/([[:cntrl:]])/?/g;
968 return $cgi->span({-title
=>$str}, esc_html
($chopped));
972 ## ----------------------------------------------------------------------
973 ## functions returning short strings
975 # CSS class for given age value (in seconds)
981 } elsif ($age < 60*60*2) {
983 } elsif ($age < 60*60*24*2) {
990 # convert age in seconds to "nn units ago" string
995 if ($age > 60*60*24*365*2) {
996 $age_str = (int $age/60/60/24/365);
997 $age_str .= " years ago";
998 } elsif ($age > 60*60*24*(365/12)*2) {
999 $age_str = int $age/60/60/24/(365/12);
1000 $age_str .= " months ago";
1001 } elsif ($age > 60*60*24*7*2) {
1002 $age_str = int $age/60/60/24/7;
1003 $age_str .= " weeks ago";
1004 } elsif ($age > 60*60*24*2) {
1005 $age_str = int $age/60/60/24;
1006 $age_str .= " days ago";
1007 } elsif ($age > 60*60*2) {
1008 $age_str = int $age/60/60;
1009 $age_str .= " hours ago";
1010 } elsif ($age > 60*2) {
1011 $age_str = int $age/60;
1012 $age_str .= " min ago";
1013 } elsif ($age > 2) {
1014 $age_str = int $age;
1015 $age_str .= " sec ago";
1017 $age_str .= " right now";
1023 S_IFINVALID
=> 0030000,
1024 S_IFGITLINK
=> 0160000,
1027 # submodule/subproject, a commit object reference
1028 sub S_ISGITLINK
($) {
1031 return (($mode & S_IFMT
) == S_IFGITLINK
)
1034 # convert file mode in octal to symbolic file mode string
1036 my $mode = oct shift;
1038 if (S_ISGITLINK
($mode)) {
1039 return 'm---------';
1040 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1041 return 'drwxr-xr-x';
1042 } elsif (S_ISLNK
($mode)) {
1043 return 'lrwxrwxrwx';
1044 } elsif (S_ISREG
($mode)) {
1045 # git cares only about the executable bit
1046 if ($mode & S_IXUSR
) {
1047 return '-rwxr-xr-x';
1049 return '-rw-r--r--';
1052 return '----------';
1056 # convert file mode in octal to file type string
1060 if ($mode !~ m/^[0-7]+$/) {
1066 if (S_ISGITLINK
($mode)) {
1068 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1070 } elsif (S_ISLNK
($mode)) {
1072 } elsif (S_ISREG
($mode)) {
1079 # convert file mode in octal to file type description string
1080 sub file_type_long
{
1083 if ($mode !~ m/^[0-7]+$/) {
1089 if (S_ISGITLINK
($mode)) {
1091 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1093 } elsif (S_ISLNK
($mode)) {
1095 } elsif (S_ISREG
($mode)) {
1096 if ($mode & S_IXUSR
) {
1097 return "executable";
1107 ## ----------------------------------------------------------------------
1108 ## functions returning short HTML fragments, or transforming HTML fragments
1109 ## which don't belong to other sections
1111 # format line of commit message.
1112 sub format_log_line_html
{
1115 $line = esc_html
($line, -nbsp
=>1);
1116 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1119 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1120 -class => "text"}, $hash_text);
1121 $line =~ s/$hash_text/$link/;
1126 # format marker of refs pointing to given object
1127 sub format_ref_marker
{
1128 my ($refs, $id) = @_;
1131 if (defined $refs->{$id}) {
1132 foreach my $ref (@
{$refs->{$id}}) {
1133 my ($type, $name) = qw();
1134 # e.g. tags/v2.6.11 or heads/next
1135 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1143 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1144 esc_html
($name) . "</span>";
1149 return ' <span class="refs">'. $markers . '</span>';
1155 # format, perhaps shortened and with markers, title line
1156 sub format_subject_html
{
1157 my ($long, $short, $href, $extra) = @_;
1158 $extra = '' unless defined($extra);
1160 if (length($short) < length($long)) {
1161 return $cgi->a({-href
=> $href, -class => "list subject",
1162 -title
=> to_utf8
($long)},
1163 esc_html
($short) . $extra);
1165 return $cgi->a({-href
=> $href, -class => "list subject"},
1166 esc_html
($long) . $extra);
1170 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1171 sub format_git_diff_header_line
{
1173 my $diffinfo = shift;
1174 my ($from, $to) = @_;
1176 if ($diffinfo->{'nparents'}) {
1178 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1179 if ($to->{'href'}) {
1180 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1181 esc_path
($to->{'file'}));
1182 } else { # file was deleted (no href)
1183 $line .= esc_path
($to->{'file'});
1187 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1188 if ($from->{'href'}) {
1189 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1190 'a/' . esc_path
($from->{'file'}));
1191 } else { # file was added (no href)
1192 $line .= 'a/' . esc_path
($from->{'file'});
1195 if ($to->{'href'}) {
1196 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1197 'b/' . esc_path
($to->{'file'}));
1198 } else { # file was deleted
1199 $line .= 'b/' . esc_path
($to->{'file'});
1203 return "<div class=\"diff header\">$line</div>\n";
1206 # format extended diff header line, before patch itself
1207 sub format_extended_diff_header_line
{
1209 my $diffinfo = shift;
1210 my ($from, $to) = @_;
1213 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1214 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1215 esc_path
($from->{'file'}));
1217 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1218 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1219 esc_path
($to->{'file'}));
1221 # match single <mode>
1222 if ($line =~ m/\s(\d{6})$/) {
1223 $line .= '<span class="info"> (' .
1224 file_type_long
($1) .
1228 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1229 # can match only for combined diff
1231 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1232 if ($from->{'href'}[$i]) {
1233 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1235 substr($diffinfo->{'from_id'}[$i],0,7));
1240 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1243 if ($to->{'href'}) {
1244 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1245 substr($diffinfo->{'to_id'},0,7));
1250 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1251 # can match only for ordinary diff
1252 my ($from_link, $to_link);
1253 if ($from->{'href'}) {
1254 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1255 substr($diffinfo->{'from_id'},0,7));
1257 $from_link = '0' x
7;
1259 if ($to->{'href'}) {
1260 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1261 substr($diffinfo->{'to_id'},0,7));
1265 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1266 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1269 return $line . "<br/>\n";
1272 # format from-file/to-file diff header
1273 sub format_diff_from_to_header
{
1274 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1279 #assert($line =~ m/^---/) if DEBUG;
1280 # no extra formatting for "^--- /dev/null"
1281 if (! $diffinfo->{'nparents'}) {
1282 # ordinary (single parent) diff
1283 if ($line =~ m!^--- "?a/!) {
1284 if ($from->{'href'}) {
1286 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1287 esc_path
($from->{'file'}));
1290 esc_path
($from->{'file'});
1293 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1296 # combined diff (merge commit)
1297 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1298 if ($from->{'href'}[$i]) {
1300 $cgi->a({-href
=>href
(action
=>"blobdiff",
1301 hash_parent
=>$diffinfo->{'from_id'}[$i],
1302 hash_parent_base
=>$parents[$i],
1303 file_parent
=>$from->{'file'}[$i],
1304 hash
=>$diffinfo->{'to_id'},
1306 file_name
=>$to->{'file'}),
1308 -title
=>"diff" . ($i+1)},
1311 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1312 esc_path
($from->{'file'}[$i]));
1314 $line = '--- /dev/null';
1316 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1321 #assert($line =~ m/^\+\+\+/) if DEBUG;
1322 # no extra formatting for "^+++ /dev/null"
1323 if ($line =~ m!^\+\+\+ "?b/!) {
1324 if ($to->{'href'}) {
1326 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1327 esc_path
($to->{'file'}));
1330 esc_path
($to->{'file'});
1333 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1338 # create note for patch simplified by combined diff
1339 sub format_diff_cc_simplified
{
1340 my ($diffinfo, @parents) = @_;
1343 $result .= "<div class=\"diff header\">" .
1345 if (!is_deleted
($diffinfo)) {
1346 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1348 hash
=>$diffinfo->{'to_id'},
1349 file_name
=>$diffinfo->{'to_file'}),
1351 esc_path
($diffinfo->{'to_file'}));
1353 $result .= esc_path
($diffinfo->{'to_file'});
1355 $result .= "</div>\n" . # class="diff header"
1356 "<div class=\"diff nodifferences\">" .
1358 "</div>\n"; # class="diff nodifferences"
1363 # format patch (diff) line (not to be used for diff headers)
1364 sub format_diff_line
{
1366 my ($from, $to) = @_;
1367 my $diff_class = "";
1371 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1373 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1374 if ($line =~ m/^\@{3}/) {
1375 $diff_class = " chunk_header";
1376 } elsif ($line =~ m/^\\/) {
1377 $diff_class = " incomplete";
1378 } elsif ($prefix =~ tr/+/+/) {
1379 $diff_class = " add";
1380 } elsif ($prefix =~ tr/-/-/) {
1381 $diff_class = " rem";
1384 # assume ordinary diff
1385 my $char = substr($line, 0, 1);
1387 $diff_class = " add";
1388 } elsif ($char eq '-') {
1389 $diff_class = " rem";
1390 } elsif ($char eq '@') {
1391 $diff_class = " chunk_header";
1392 } elsif ($char eq "\\") {
1393 $diff_class = " incomplete";
1396 $line = untabify
($line);
1397 if ($from && $to && $line =~ m/^\@{2} /) {
1398 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1399 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1401 $from_lines = 0 unless defined $from_lines;
1402 $to_lines = 0 unless defined $to_lines;
1404 if ($from->{'href'}) {
1405 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1406 -class=>"list"}, $from_text);
1408 if ($to->{'href'}) {
1409 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1410 -class=>"list"}, $to_text);
1412 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1413 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1414 return "<div class=\"diff$diff_class\">$line</div>\n";
1415 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1416 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1417 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1419 @from_text = split(' ', $ranges);
1420 for (my $i = 0; $i < @from_text; ++$i) {
1421 ($from_start[$i], $from_nlines[$i]) =
1422 (split(',', substr($from_text[$i], 1)), 0);
1425 $to_text = pop @from_text;
1426 $to_start = pop @from_start;
1427 $to_nlines = pop @from_nlines;
1429 $line = "<span class=\"chunk_info\">$prefix ";
1430 for (my $i = 0; $i < @from_text; ++$i) {
1431 if ($from->{'href'}[$i]) {
1432 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1433 -class=>"list"}, $from_text[$i]);
1435 $line .= $from_text[$i];
1439 if ($to->{'href'}) {
1440 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1441 -class=>"list"}, $to_text);
1445 $line .= " $prefix</span>" .
1446 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1447 return "<div class=\"diff$diff_class\">$line</div>\n";
1449 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1452 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1453 # linked. Pass the hash of the tree/commit to snapshot.
1454 sub format_snapshot_links
{
1456 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1457 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1458 my $num_fmts = @snapshot_fmts;
1459 if ($num_fmts > 1) {
1460 # A parenthesized list of links bearing format names.
1461 # e.g. "snapshot (_tar.gz_ _zip_)"
1462 return "snapshot (" . join(' ', map
1469 }, $known_snapshot_formats{$_}{'display'})
1470 , @snapshot_fmts) . ")";
1471 } elsif ($num_fmts == 1) {
1472 # A single "snapshot" link whose tooltip bears the format name.
1474 my ($fmt) = @snapshot_fmts;
1480 snapshot_format
=>$fmt
1482 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1484 } else { # $num_fmts == 0
1489 ## ......................................................................
1490 ## functions returning values to be passed, perhaps after some
1491 ## transformation, to other functions; e.g. returning arguments to href()
1493 # returns hash to be passed to href to generate gitweb URL
1494 # in -title key it returns description of link
1496 my $format = shift || 'Atom';
1497 my %res = (action
=> lc($format));
1499 # feed links are possible only for project views
1500 return unless (defined $project);
1501 # some views should link to OPML, or to generic project feed,
1502 # or don't have specific feed yet (so they should use generic)
1503 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1506 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1507 # from tag links; this also makes possible to detect branch links
1508 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1509 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1512 # find log type for feed description (title)
1514 if (defined $file_name) {
1515 $type = "history of $file_name";
1516 $type .= "/" if ($action eq 'tree');
1517 $type .= " on '$branch'" if (defined $branch);
1519 $type = "log of $branch" if (defined $branch);
1522 $res{-title
} = $type;
1523 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
1524 $res{'file_name'} = $file_name;
1529 ## ----------------------------------------------------------------------
1530 ## git utility subroutines, invoking git commands
1532 # returns path to the core git executable and the --git-dir parameter as list
1534 return $GIT, '--git-dir='.$git_dir;
1537 # quote the given arguments for passing them to the shell
1538 # quote_command("command", "arg 1", "arg with ' and ! characters")
1539 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1540 # Try to avoid using this function wherever possible.
1543 map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1546 # get HEAD ref of given project as hash
1547 sub git_get_head_hash
{
1548 my $project = shift;
1549 my $o_git_dir = $git_dir;
1551 $git_dir = "$projectroot/$project";
1552 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1555 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1559 if (defined $o_git_dir) {
1560 $git_dir = $o_git_dir;
1565 # get type of given object
1569 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1571 close $fd or return;
1576 # repository configuration
1577 our $config_file = '';
1580 # store multiple values for single key as anonymous array reference
1581 # single values stored directly in the hash, not as [ <value> ]
1582 sub hash_set_multi
{
1583 my ($hash, $key, $value) = @_;
1585 if (!exists $hash->{$key}) {
1586 $hash->{$key} = $value;
1587 } elsif (!ref $hash->{$key}) {
1588 $hash->{$key} = [ $hash->{$key}, $value ];
1590 push @
{$hash->{$key}}, $value;
1594 # return hash of git project configuration
1595 # optionally limited to some section, e.g. 'gitweb'
1596 sub git_parse_project_config
{
1597 my $section_regexp = shift;
1602 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1605 while (my $keyval = <$fh>) {
1607 my ($key, $value) = split(/\n/, $keyval, 2);
1609 hash_set_multi
(\
%config, $key, $value)
1610 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1617 # convert config value to boolean, 'true' or 'false'
1618 # no value, number > 0, 'true' and 'yes' values are true
1619 # rest of values are treated as false (never as error)
1620 sub config_to_bool
{
1623 # strip leading and trailing whitespace
1627 return (!defined $val || # section.key
1628 ($val =~ /^\d+$/ && $val) || # section.key = 1
1629 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1632 # convert config value to simple decimal number
1633 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1634 # to be multiplied by 1024, 1048576, or 1073741824
1638 # strip leading and trailing whitespace
1642 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1644 # unknown unit is treated as 1
1645 return $num * ($unit eq 'g' ?
1073741824 :
1646 $unit eq 'm' ?
1048576 :
1647 $unit eq 'k' ?
1024 : 1);
1652 # convert config value to array reference, if needed
1653 sub config_to_multi
{
1656 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
1659 sub git_get_project_config
{
1660 my ($key, $type) = @_;
1663 return unless ($key);
1664 $key =~ s/^gitweb\.//;
1665 return if ($key =~ m/\W/);
1668 if (defined $type) {
1671 unless ($type eq 'bool' || $type eq 'int');
1675 if (!defined $config_file ||
1676 $config_file ne "$git_dir/config") {
1677 %config = git_parse_project_config
('gitweb');
1678 $config_file = "$git_dir/config";
1682 if (!defined $type) {
1683 return $config{"gitweb.$key"};
1684 } elsif ($type eq 'bool') {
1685 # backward compatibility: 'git config --bool' returns true/false
1686 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
1687 } elsif ($type eq 'int') {
1688 return config_to_int
($config{"gitweb.$key"});
1690 return $config{"gitweb.$key"};
1693 # get hash of given path at given ref
1694 sub git_get_hash_by_path
{
1696 my $path = shift || return undef;
1701 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1702 or die_error
(undef, "Open git-ls-tree failed");
1704 close $fd or return undef;
1706 if (!defined $line) {
1707 # there is no tree or hash given by $path at $base
1711 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1712 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1713 if (defined $type && $type ne $2) {
1714 # type doesn't match
1720 # get path of entry with given hash at given tree-ish (ref)
1721 # used to get 'from' filename for combined diff (merge commit) for renames
1722 sub git_get_path_by_hash
{
1723 my $base = shift || return;
1724 my $hash = shift || return;
1728 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1730 while (my $line = <$fd>) {
1733 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1734 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1735 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1744 ## ......................................................................
1745 ## git utility functions, directly accessing git repository
1747 sub git_get_project_description
{
1750 $git_dir = "$projectroot/$path";
1751 open my $fd, "$git_dir/description"
1752 or return git_get_project_config
('description');
1755 if (defined $descr) {
1761 sub git_get_project_url_list
{
1764 $git_dir = "$projectroot/$path";
1765 open my $fd, "$git_dir/cloneurl"
1766 or return wantarray ?
1767 @
{ config_to_multi
(git_get_project_config
('url')) } :
1768 config_to_multi
(git_get_project_config
('url'));
1769 my @git_project_url_list = map { chomp; $_ } <$fd>;
1772 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
1775 sub git_get_projects_list
{
1780 $filter =~ s/\.git$//;
1782 my ($check_forks) = gitweb_check_feature
('forks');
1784 if (-d
$projects_list) {
1785 # search in directory
1786 my $dir = $projects_list . ($filter ?
"/$filter" : '');
1787 # remove the trailing "/"
1789 my $pfxlen = length("$dir");
1790 my $pfxdepth = ($dir =~ tr!/!!);
1793 follow_fast
=> 1, # follow symbolic links
1794 follow_skip
=> 2, # ignore duplicates
1795 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1797 # skip project-list toplevel, if we get it.
1798 return if (m!^[/.]$!);
1799 # only directories can be git repositories
1800 return unless (-d
$_);
1801 # don't traverse too deep (Find is super slow on os x)
1802 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1803 $File::Find
::prune
= 1;
1807 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1808 # we check related file in $projectroot
1809 if ($check_forks and $subdir =~ m
#/.#) {
1810 $File::Find
::prune
= 1;
1811 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1812 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
1813 $File::Find
::prune
= 1;
1818 } elsif (-f
$projects_list) {
1819 # read from file(url-encoded):
1820 # 'git%2Fgit.git Linus+Torvalds'
1821 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1822 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1824 open my ($fd), $projects_list or return;
1826 while (my $line = <$fd>) {
1828 my ($path, $owner) = split ' ', $line;
1829 $path = unescape
($path);
1830 $owner = unescape
($owner);
1831 if (!defined $path) {
1834 if ($filter ne '') {
1835 # looking for forks;
1836 my $pfx = substr($path, 0, length($filter));
1837 if ($pfx ne $filter) {
1840 my $sfx = substr($path, length($filter));
1841 if ($sfx !~ /^\/.*\
.git
$/) {
1844 } elsif ($check_forks) {
1846 foreach my $filter (keys %paths) {
1847 # looking for forks;
1848 my $pfx = substr($path, 0, length($filter));
1849 if ($pfx ne $filter) {
1852 my $sfx = substr($path, length($filter));
1853 if ($sfx !~ /^\/.*\
.git
$/) {
1856 # is a fork, don't include it in
1861 if (check_export_ok
("$projectroot/$path")) {
1864 owner
=> to_utf8
($owner),
1867 (my $forks_path = $path) =~ s/\.git$//;
1868 $paths{$forks_path}++;
1876 our $gitweb_project_owner = undef;
1877 sub git_get_project_list_from_file
{
1879 return if (defined $gitweb_project_owner);
1881 $gitweb_project_owner = {};
1882 # read from file (url-encoded):
1883 # 'git%2Fgit.git Linus+Torvalds'
1884 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1885 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1886 if (-f
$projects_list) {
1887 open (my $fd , $projects_list);
1888 while (my $line = <$fd>) {
1890 my ($pr, $ow) = split ' ', $line;
1891 $pr = unescape
($pr);
1892 $ow = unescape
($ow);
1893 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1899 sub git_get_project_owner
{
1900 my $project = shift;
1903 return undef unless $project;
1904 $git_dir = "$projectroot/$project";
1906 if (!defined $gitweb_project_owner) {
1907 git_get_project_list_from_file
();
1910 if (exists $gitweb_project_owner->{$project}) {
1911 $owner = $gitweb_project_owner->{$project};
1913 if (!defined $owner){
1914 $owner = git_get_project_config
('owner');
1916 if (!defined $owner) {
1917 $owner = get_file_owner
("$git_dir");
1923 sub git_get_last_activity
{
1927 $git_dir = "$projectroot/$path";
1928 open($fd, "-|", git_cmd
(), 'for-each-ref',
1929 '--format=%(committer)',
1930 '--sort=-committerdate',
1932 'refs/heads') or return;
1933 my $most_recent = <$fd>;
1934 close $fd or return;
1935 if (defined $most_recent &&
1936 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1938 my $age = time - $timestamp;
1939 return ($age, age_string
($age));
1941 return (undef, undef);
1944 sub git_get_references
{
1945 my $type = shift || "";
1947 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1948 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1949 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1950 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
1953 while (my $line = <$fd>) {
1955 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1956 if (defined $refs{$1}) {
1957 push @
{$refs{$1}}, $2;
1963 close $fd or return;
1967 sub git_get_rev_name_tags
{
1968 my $hash = shift || return undef;
1970 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1972 my $name_rev = <$fd>;
1975 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1978 # catches also '$hash undefined' output
1983 ## ----------------------------------------------------------------------
1984 ## parse to hash functions
1988 my $tz = shift || "-0000";
1991 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1992 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1993 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1994 $date{'hour'} = $hour;
1995 $date{'minute'} = $min;
1996 $date{'mday'} = $mday;
1997 $date{'day'} = $days[$wday];
1998 $date{'month'} = $months[$mon];
1999 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2000 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2001 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2002 $mday, $months[$mon], $hour ,$min;
2003 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2004 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2006 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2007 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2008 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2009 $date{'hour_local'} = $hour;
2010 $date{'minute_local'} = $min;
2011 $date{'tz_local'} = $tz;
2012 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2013 1900+$year, $mon+1, $mday,
2014 $hour, $min, $sec, $tz);
2023 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2024 $tag{'id'} = $tag_id;
2025 while (my $line = <$fd>) {
2027 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2028 $tag{'object'} = $1;
2029 } elsif ($line =~ m/^type (.+)$/) {
2031 } elsif ($line =~ m/^tag (.+)$/) {
2033 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2034 $tag{'author'} = $1;
2037 } elsif ($line =~ m/--BEGIN/) {
2038 push @comment, $line;
2040 } elsif ($line eq "") {
2044 push @comment, <$fd>;
2045 $tag{'comment'} = \
@comment;
2046 close $fd or return;
2047 if (!defined $tag{'name'}) {
2053 sub parse_commit_text
{
2054 my ($commit_text, $withparents) = @_;
2055 my @commit_lines = split '\n', $commit_text;
2058 pop @commit_lines; # Remove '\0'
2060 if (! @commit_lines) {
2064 my $header = shift @commit_lines;
2065 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2068 ($co{'id'}, my @parents) = split ' ', $header;
2069 while (my $line = shift @commit_lines) {
2070 last if $line eq "\n";
2071 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2073 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2075 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2077 $co{'author_epoch'} = $2;
2078 $co{'author_tz'} = $3;
2079 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2080 $co{'author_name'} = $1;
2081 $co{'author_email'} = $2;
2083 $co{'author_name'} = $co{'author'};
2085 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2086 $co{'committer'} = $1;
2087 $co{'committer_epoch'} = $2;
2088 $co{'committer_tz'} = $3;
2089 $co{'committer_name'} = $co{'committer'};
2090 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2091 $co{'committer_name'} = $1;
2092 $co{'committer_email'} = $2;
2094 $co{'committer_name'} = $co{'committer'};
2098 if (!defined $co{'tree'}) {
2101 $co{'parents'} = \
@parents;
2102 $co{'parent'} = $parents[0];
2104 foreach my $title (@commit_lines) {
2107 $co{'title'} = chop_str
($title, 80, 5);
2108 # remove leading stuff of merges to make the interesting part visible
2109 if (length($title) > 50) {
2110 $title =~ s/^Automatic //;
2111 $title =~ s/^merge (of|with) /Merge ... /i;
2112 if (length($title) > 50) {
2113 $title =~ s/(http|rsync):\/\///;
2115 if (length($title) > 50) {
2116 $title =~ s/(master|www|rsync)\.//;
2118 if (length($title) > 50) {
2119 $title =~ s/kernel.org:?//;
2121 if (length($title) > 50) {
2122 $title =~ s/\/pub\/scm//;
2125 $co{'title_short'} = chop_str
($title, 50, 5);
2129 if ($co{'title'} eq "") {
2130 $co{'title'} = $co{'title_short'} = '(no commit message)';
2132 # remove added spaces
2133 foreach my $line (@commit_lines) {
2136 $co{'comment'} = \
@commit_lines;
2138 my $age = time - $co{'committer_epoch'};
2140 $co{'age_string'} = age_string
($age);
2141 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2142 if ($age > 60*60*24*7*2) {
2143 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2144 $co{'age_string_age'} = $co{'age_string'};
2146 $co{'age_string_date'} = $co{'age_string'};
2147 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2153 my ($commit_id) = @_;
2158 open my $fd, "-|", git_cmd
(), "rev-list",
2164 or die_error
(undef, "Open git-rev-list failed");
2165 %co = parse_commit_text
(<$fd>, 1);
2172 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2180 open my $fd, "-|", git_cmd
(), "rev-list",
2183 ("--max-count=" . $maxcount),
2184 ("--skip=" . $skip),
2188 ($filename ?
($filename) : ())
2189 or die_error
(undef, "Open git-rev-list failed");
2190 while (my $line = <$fd>) {
2191 my %co = parse_commit_text
($line);
2196 return wantarray ?
@cos : \
@cos;
2199 # parse line of git-diff-tree "raw" output
2200 sub parse_difftree_raw_line
{
2204 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2205 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2206 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2207 $res{'from_mode'} = $1;
2208 $res{'to_mode'} = $2;
2209 $res{'from_id'} = $3;
2211 $res{'status'} = $5;
2212 $res{'similarity'} = $6;
2213 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2214 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2216 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2219 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2220 # combined diff (for merge commit)
2221 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2222 $res{'nparents'} = length($1);
2223 $res{'from_mode'} = [ split(' ', $2) ];
2224 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2225 $res{'from_id'} = [ split(' ', $3) ];
2226 $res{'to_id'} = pop @
{$res{'from_id'}};
2227 $res{'status'} = [ split('', $4) ];
2228 $res{'to_file'} = unquote
($5);
2230 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2231 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2232 $res{'commit'} = $1;
2235 return wantarray ?
%res : \
%res;
2238 # wrapper: return parsed line of git-diff-tree "raw" output
2239 # (the argument might be raw line, or parsed info)
2240 sub parsed_difftree_line
{
2241 my $line_or_ref = shift;
2243 if (ref($line_or_ref) eq "HASH") {
2244 # pre-parsed (or generated by hand)
2245 return $line_or_ref;
2247 return parse_difftree_raw_line
($line_or_ref);
2251 # parse line of git-ls-tree output
2252 sub parse_ls_tree_line
($;%) {
2257 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2258 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2266 $res{'name'} = unquote
($4);
2269 return wantarray ?
%res : \
%res;
2272 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2273 sub parse_from_to_diffinfo
{
2274 my ($diffinfo, $from, $to, @parents) = @_;
2276 if ($diffinfo->{'nparents'}) {
2278 $from->{'file'} = [];
2279 $from->{'href'} = [];
2280 fill_from_file_info
($diffinfo, @parents)
2281 unless exists $diffinfo->{'from_file'};
2282 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2283 $from->{'file'}[$i] =
2284 defined $diffinfo->{'from_file'}[$i] ?
2285 $diffinfo->{'from_file'}[$i] :
2286 $diffinfo->{'to_file'};
2287 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2288 $from->{'href'}[$i] = href
(action
=>"blob",
2289 hash_base
=>$parents[$i],
2290 hash
=>$diffinfo->{'from_id'}[$i],
2291 file_name
=>$from->{'file'}[$i]);
2293 $from->{'href'}[$i] = undef;
2297 # ordinary (not combined) diff
2298 $from->{'file'} = $diffinfo->{'from_file'};
2299 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2300 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2301 hash
=>$diffinfo->{'from_id'},
2302 file_name
=>$from->{'file'});
2304 delete $from->{'href'};
2308 $to->{'file'} = $diffinfo->{'to_file'};
2309 if (!is_deleted
($diffinfo)) { # file exists in result
2310 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2311 hash
=>$diffinfo->{'to_id'},
2312 file_name
=>$to->{'file'});
2314 delete $to->{'href'};
2318 ## ......................................................................
2319 ## parse to array of hashes functions
2321 sub git_get_heads_list
{
2325 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2326 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2327 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2330 while (my $line = <$fd>) {
2334 my ($refinfo, $committerinfo) = split(/\0/, $line);
2335 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2336 my ($committer, $epoch, $tz) =
2337 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2338 $ref_item{'fullname'} = $name;
2339 $name =~ s!^refs/heads/!!;
2341 $ref_item{'name'} = $name;
2342 $ref_item{'id'} = $hash;
2343 $ref_item{'title'} = $title || '(no commit message)';
2344 $ref_item{'epoch'} = $epoch;
2346 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2348 $ref_item{'age'} = "unknown";
2351 push @headslist, \
%ref_item;
2355 return wantarray ?
@headslist : \
@headslist;
2358 sub git_get_tags_list
{
2362 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2363 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
2364 '--format=%(objectname) %(objecttype) %(refname) '.
2365 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2368 while (my $line = <$fd>) {
2372 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2373 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2374 my ($creator, $epoch, $tz) =
2375 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2376 $ref_item{'fullname'} = $name;
2377 $name =~ s!^refs/tags/!!;
2379 $ref_item{'type'} = $type;
2380 $ref_item{'id'} = $id;
2381 $ref_item{'name'} = $name;
2382 if ($type eq "tag") {
2383 $ref_item{'subject'} = $title;
2384 $ref_item{'reftype'} = $reftype;
2385 $ref_item{'refid'} = $refid;
2387 $ref_item{'reftype'} = $type;
2388 $ref_item{'refid'} = $id;
2391 if ($type eq "tag" || $type eq "commit") {
2392 $ref_item{'epoch'} = $epoch;
2394 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2396 $ref_item{'age'} = "unknown";
2400 push @tagslist, \
%ref_item;
2404 return wantarray ?
@tagslist : \
@tagslist;
2407 ## ----------------------------------------------------------------------
2408 ## filesystem-related functions
2410 sub get_file_owner
{
2413 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2414 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2415 if (!defined $gcos) {
2419 $owner =~ s/[,;].*$//;
2420 return to_utf8
($owner);
2423 ## ......................................................................
2424 ## mimetype related functions
2426 sub mimetype_guess_file
{
2427 my $filename = shift;
2428 my $mimemap = shift;
2429 -r
$mimemap or return undef;
2432 open(MIME
, $mimemap) or return undef;
2434 next if m/^#/; # skip comments
2435 my ($mime, $exts) = split(/\t+/);
2436 if (defined $exts) {
2437 my @exts = split(/\s+/, $exts);
2438 foreach my $ext (@exts) {
2439 $mimemap{$ext} = $mime;
2445 $filename =~ /\.([^.]*)$/;
2446 return $mimemap{$1};
2449 sub mimetype_guess
{
2450 my $filename = shift;
2452 $filename =~ /\./ or return undef;
2454 if ($mimetypes_file) {
2455 my $file = $mimetypes_file;
2456 if ($file !~ m!^/!) { # if it is relative path
2457 # it is relative to project
2458 $file = "$projectroot/$project/$file";
2460 $mime = mimetype_guess_file
($filename, $file);
2462 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2468 my $filename = shift;
2471 my $mime = mimetype_guess
($filename);
2472 $mime and return $mime;
2476 return $default_blob_plain_mimetype unless $fd;
2479 return 'text/plain';
2480 } elsif (! $filename) {
2481 return 'application/octet-stream';
2482 } elsif ($filename =~ m/\.png$/i) {
2484 } elsif ($filename =~ m/\.gif$/i) {
2486 } elsif ($filename =~ m/\.jpe?g$/i) {
2487 return 'image/jpeg';
2489 return 'application/octet-stream';
2493 sub blob_contenttype
{
2494 my ($fd, $file_name, $type) = @_;
2496 $type ||= blob_mimetype
($fd, $file_name);
2497 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2498 $type .= "; charset=$default_text_plain_charset";
2504 ## ======================================================================
2505 ## functions printing HTML: header, footer, error page
2507 sub git_header_html
{
2508 my $status = shift || "200 OK";
2509 my $expires = shift;
2511 my $title = "$site_name";
2512 if (defined $project) {
2513 $title .= " - " . to_utf8
($project);
2514 if (defined $action) {
2515 $title .= "/$action";
2516 if (defined $file_name) {
2517 $title .= " - " . esc_path
($file_name);
2518 if ($action eq "tree" && $file_name !~ m
|/$|) {
2525 # require explicit support from the UA if we are to send the page as
2526 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2527 # we have to do this because MSIE sometimes globs '*/*', pretending to
2528 # support xhtml+xml but choking when it gets what it asked for.
2529 if (defined $cgi->http('HTTP_ACCEPT') &&
2530 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2531 $cgi->Accept('application/xhtml+xml') != 0) {
2532 $content_type = 'application/xhtml+xml';
2534 $content_type = 'text/html';
2536 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2537 -status
=> $status, -expires
=> $expires);
2538 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
2540 <?xml version="1.0" encoding="utf-8"?>
2541 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2542 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2543 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2544 <!-- git core binaries version $git_version -->
2546 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2547 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2548 <meta name="robots" content="index, nofollow"/>
2549 <title>$title</title>
2551 # print out each stylesheet that exist
2552 if (defined $stylesheet) {
2553 #provides backwards capability for those people who define style sheet in a config file
2554 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2556 foreach my $stylesheet (@stylesheets) {
2557 next unless $stylesheet;
2558 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2561 if (defined $project) {
2562 my %href_params = get_feed_info
();
2563 if (!exists $href_params{'-title'}) {
2564 $href_params{'-title'} = 'log';
2567 foreach my $format qw(RSS Atom) {
2568 my $type = lc($format);
2570 '-rel' => 'alternate',
2571 '-title' => "$project - $href_params{'-title'} - $format feed",
2572 '-type' => "application/$type+xml"
2575 $href_params{'action'} = $type;
2576 $link_attr{'-href'} = href
(%href_params);
2578 "rel=\"$link_attr{'-rel'}\" ".
2579 "title=\"$link_attr{'-title'}\" ".
2580 "href=\"$link_attr{'-href'}\" ".
2581 "type=\"$link_attr{'-type'}\" ".
2584 $href_params{'extra_options'} = '--no-merges';
2585 $link_attr{'-href'} = href
(%href_params);
2586 $link_attr{'-title'} .= ' (no merges)';
2588 "rel=\"$link_attr{'-rel'}\" ".
2589 "title=\"$link_attr{'-title'}\" ".
2590 "href=\"$link_attr{'-href'}\" ".
2591 "type=\"$link_attr{'-type'}\" ".
2596 printf('<link rel="alternate" title="%s projects list" '.
2597 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2598 $site_name, href
(project
=>undef, action
=>"project_index"));
2599 printf('<link rel="alternate" title="%s projects feeds" '.
2600 'href="%s" type="text/x-opml" />'."\n",
2601 $site_name, href
(project
=>undef, action
=>"opml"));
2603 if (defined $favicon) {
2604 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png" />\n);
2610 if (-f
$site_header) {
2611 open (my $fd, $site_header);
2616 print "<div class=\"page_header\">\n" .
2617 $cgi->a({-href
=> esc_url
($logo_url),
2618 -title
=> $logo_label},
2619 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
2620 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2621 if (defined $project) {
2622 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2623 if (defined $action) {
2630 my ($have_search) = gitweb_check_feature
('search');
2631 if (defined $project && $have_search) {
2632 if (!defined $searchtext) {
2636 if (defined $hash_base) {
2637 $search_hash = $hash_base;
2638 } elsif (defined $hash) {
2639 $search_hash = $hash;
2641 $search_hash = "HEAD";
2643 my $action = $my_uri;
2644 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2645 if ($use_pathinfo) {
2646 $action .= "/".esc_url
($project);
2648 print $cgi->startform(-method
=> "get", -action
=> $action) .
2649 "<div class=\"search\">\n" .
2651 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
2652 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
2653 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
2654 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2655 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2656 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2658 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2659 "<span title=\"Extended regular expression\">" .
2660 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
2661 -checked
=> $search_use_regexp) .
2664 $cgi->end_form() . "\n";
2668 sub git_footer_html
{
2669 my $feed_class = 'rss_logo';
2671 print "<div class=\"page_footer\">\n";
2672 if (defined $project) {
2673 my $descr = git_get_project_description
($project);
2674 if (defined $descr) {
2675 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2678 my %href_params = get_feed_info
();
2679 if (!%href_params) {
2680 $feed_class .= ' generic';
2682 $href_params{'-title'} ||= 'log';
2684 foreach my $format qw(RSS Atom) {
2685 $href_params{'action'} = lc($format);
2686 print $cgi->a({-href
=> href
(%href_params),
2687 -title
=> "$href_params{'-title'} $format feed",
2688 -class => $feed_class}, $format)."\n";
2692 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2693 -class => $feed_class}, "OPML") . " ";
2694 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2695 -class => $feed_class}, "TXT") . "\n";
2697 print "</div>\n"; # class="page_footer"
2699 if (-f
$site_footer) {
2700 open (my $fd, $site_footer);
2710 my $status = shift || "403 Forbidden";
2711 my $error = shift || "Malformed query, file missing or permission denied";
2713 git_header_html
($status);
2715 <div class="page_body">
2725 ## ----------------------------------------------------------------------
2726 ## functions printing or outputting HTML: navigation
2728 sub git_print_page_nav
{
2729 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2730 $extra = '' if !defined $extra; # pager or formats
2732 my @navs = qw(summary shortlog log commit commitdiff tree);
2734 @navs = grep { $_ ne $suppress } @navs;
2737 my %arg = map { $_ => {action
=>$_} } @navs;
2738 if (defined $head) {
2739 for (qw(commit commitdiff)) {
2740 $arg{$_}{'hash'} = $head;
2742 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2743 for (qw(shortlog log)) {
2744 $arg{$_}{'hash'} = $head;
2748 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2749 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2751 print "<div class=\"page_nav\">\n" .
2753 map { $_ eq $current ?
2754 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2756 print "<br/>\n$extra<br/>\n" .
2760 sub format_paging_nav
{
2761 my ($action, $hash, $head, $page, $has_next_link) = @_;
2765 if ($hash ne $head || $page) {
2766 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2768 $paging_nav .= "HEAD";
2772 $paging_nav .= " ⋅ " .
2773 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
2774 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2776 $paging_nav .= " ⋅ prev";
2779 if ($has_next_link) {
2780 $paging_nav .= " ⋅ " .
2781 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
2782 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2784 $paging_nav .= " ⋅ next";
2790 ## ......................................................................
2791 ## functions printing or outputting HTML: div
2793 sub git_print_header_div
{
2794 my ($action, $title, $hash, $hash_base) = @_;
2797 $args{'action'} = $action;
2798 $args{'hash'} = $hash if $hash;
2799 $args{'hash_base'} = $hash_base if $hash_base;
2801 print "<div class=\"header\">\n" .
2802 $cgi->a({-href
=> href
(%args), -class => "title"},
2803 $title ?
$title : $action) .
2807 #sub git_print_authorship (\%) {
2808 sub git_print_authorship
{
2811 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2812 print "<div class=\"author_date\">" .
2813 esc_html
($co->{'author_name'}) .
2815 if ($ad{'hour_local'} < 6) {
2816 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2817 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2819 printf(" (%02d:%02d %s)",
2820 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2825 sub git_print_page_path
{
2831 print "<div class=\"page_path\">";
2832 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2833 -title
=> 'tree root'}, to_utf8
("[$project]"));
2835 if (defined $name) {
2836 my @dirname = split '/', $name;
2837 my $basename = pop @dirname;
2840 foreach my $dir (@dirname) {
2841 $fullname .= ($fullname ?
'/' : '') . $dir;
2842 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2844 -title
=> $fullname}, esc_path
($dir));
2847 if (defined $type && $type eq 'blob') {
2848 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2850 -title
=> $name}, esc_path
($basename));
2851 } elsif (defined $type && $type eq 'tree') {
2852 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2854 -title
=> $name}, esc_path
($basename));
2857 print esc_path
($basename);
2860 print "<br/></div>\n";
2863 # sub git_print_log (\@;%) {
2864 sub git_print_log
($;%) {
2868 if ($opts{'-remove_title'}) {
2869 # remove title, i.e. first line of log
2872 # remove leading empty lines
2873 while (defined $log->[0] && $log->[0] eq "") {
2880 foreach my $line (@
$log) {
2881 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2884 if (! $opts{'-remove_signoff'}) {
2885 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2888 # remove signoff lines
2895 # print only one empty line
2896 # do not print empty line after signoff
2898 next if ($empty || $signoff);
2904 print format_log_line_html
($line) . "<br/>\n";
2907 if ($opts{'-final_empty_line'}) {
2908 # end with single empty line
2909 print "<br/>\n" unless $empty;
2913 # return link target (what link points to)
2914 sub git_get_link_target
{
2919 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2923 $link_target = <$fd>;
2928 return $link_target;
2931 # given link target, and the directory (basedir) the link is in,
2932 # return target of link relative to top directory (top tree);
2933 # return undef if it is not possible (including absolute links).
2934 sub normalize_link_target
{
2935 my ($link_target, $basedir, $hash_base) = @_;
2937 # we can normalize symlink target only if $hash_base is provided
2938 return unless $hash_base;
2940 # absolute symlinks (beginning with '/') cannot be normalized
2941 return if (substr($link_target, 0, 1) eq '/');
2943 # normalize link target to path from top (root) tree (dir)
2946 $path = $basedir . '/' . $link_target;
2948 # we are in top (root) tree (dir)
2949 $path = $link_target;
2952 # remove //, /./, and /../
2954 foreach my $part (split('/', $path)) {
2955 # discard '.' and ''
2956 next if (!$part || $part eq '.');
2958 if ($part eq '..') {
2962 # link leads outside repository (outside top dir)
2966 push @path_parts, $part;
2969 $path = join('/', @path_parts);
2974 # print tree entry (row of git_tree), but without encompassing <tr> element
2975 sub git_print_tree_entry
{
2976 my ($t, $basedir, $hash_base, $have_blame) = @_;
2979 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2981 # The format of a table row is: mode list link. Where mode is
2982 # the mode of the entry, list is the name of the entry, an href,
2983 # and link is the action links of the entry.
2985 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2986 if ($t->{'type'} eq "blob") {
2987 print "<td class=\"list\">" .
2988 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2989 file_name
=>"$basedir$t->{'name'}", %base_key),
2990 -class => "list"}, esc_path
($t->{'name'}));
2991 if (S_ISLNK
(oct $t->{'mode'})) {
2992 my $link_target = git_get_link_target
($t->{'hash'});
2994 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2995 if (defined $norm_target) {
2997 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2998 file_name
=>$norm_target),
2999 -title
=> $norm_target}, esc_path
($link_target));
3001 print " -> " . esc_path
($link_target);
3006 print "<td class=\"link\">";
3007 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3008 file_name
=>"$basedir$t->{'name'}", %base_key)},
3012 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3013 file_name
=>"$basedir$t->{'name'}", %base_key)},
3016 if (defined $hash_base) {
3018 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3019 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3023 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3024 file_name
=>"$basedir$t->{'name'}")},
3028 } elsif ($t->{'type'} eq "tree") {
3029 print "<td class=\"list\">";
3030 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3031 file_name
=>"$basedir$t->{'name'}", %base_key)},
3032 esc_path
($t->{'name'}));
3034 print "<td class=\"link\">";
3035 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3036 file_name
=>"$basedir$t->{'name'}", %base_key)},
3038 if (defined $hash_base) {
3040 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3041 file_name
=>"$basedir$t->{'name'}")},
3046 # unknown object: we can only present history for it
3047 # (this includes 'commit' object, i.e. submodule support)
3048 print "<td class=\"list\">" .
3049 esc_path
($t->{'name'}) .
3051 print "<td class=\"link\">";
3052 if (defined $hash_base) {
3053 print $cgi->a({-href
=> href
(action
=>"history",
3054 hash_base
=>$hash_base,
3055 file_name
=>"$basedir$t->{'name'}")},
3062 ## ......................................................................
3063 ## functions printing large fragments of HTML
3065 # get pre-image filenames for merge (combined) diff
3066 sub fill_from_file_info
{
3067 my ($diff, @parents) = @_;
3069 $diff->{'from_file'} = [ ];
3070 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3071 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3072 if ($diff->{'status'}[$i] eq 'R' ||
3073 $diff->{'status'}[$i] eq 'C') {
3074 $diff->{'from_file'}[$i] =
3075 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3082 # is current raw difftree line of file deletion
3084 my $diffinfo = shift;
3086 return $diffinfo->{'to_id'} eq ('0' x
40);
3089 # does patch correspond to [previous] difftree raw line
3090 # $diffinfo - hashref of parsed raw diff format
3091 # $patchinfo - hashref of parsed patch diff format
3092 # (the same keys as in $diffinfo)
3093 sub is_patch_split
{
3094 my ($diffinfo, $patchinfo) = @_;
3096 return defined $diffinfo && defined $patchinfo
3097 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3101 sub git_difftree_body
{
3102 my ($difftree, $hash, @parents) = @_;
3103 my ($parent) = $parents[0];
3104 my ($have_blame) = gitweb_check_feature
('blame');
3105 print "<div class=\"list_head\">\n";
3106 if ($#{$difftree} > 10) {
3107 print(($#{$difftree} + 1) . " files changed:\n");
3111 print "<table class=\"" .
3112 (@parents > 1 ?
"combined " : "") .
3115 # header only for combined diff in 'commitdiff' view
3116 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
3119 print "<thead><tr>\n" .
3120 "<th></th><th></th>\n"; # filename, patchN link
3121 for (my $i = 0; $i < @parents; $i++) {
3122 my $par = $parents[$i];
3124 $cgi->a({-href
=> href
(action
=>"commitdiff",
3125 hash
=>$hash, hash_parent
=>$par),
3126 -title
=> 'commitdiff to parent number ' .
3127 ($i+1) . ': ' . substr($par,0,7)},
3131 print "</tr></thead>\n<tbody>\n";
3136 foreach my $line (@
{$difftree}) {
3137 my $diff = parsed_difftree_line
($line);
3140 print "<tr class=\"dark\">\n";
3142 print "<tr class=\"light\">\n";
3146 if (exists $diff->{'nparents'}) { # combined diff
3148 fill_from_file_info
($diff, @parents)
3149 unless exists $diff->{'from_file'};
3151 if (!is_deleted
($diff)) {
3152 # file exists in the result (child) commit
3154 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3155 file_name
=>$diff->{'to_file'},
3157 -class => "list"}, esc_path
($diff->{'to_file'})) .
3161 esc_path
($diff->{'to_file'}) .
3165 if ($action eq 'commitdiff') {
3168 print "<td class=\"link\">" .
3169 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3174 my $has_history = 0;
3175 my $not_deleted = 0;
3176 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3177 my $hash_parent = $parents[$i];
3178 my $from_hash = $diff->{'from_id'}[$i];
3179 my $from_path = $diff->{'from_file'}[$i];
3180 my $status = $diff->{'status'}[$i];
3182 $has_history ||= ($status ne 'A');
3183 $not_deleted ||= ($status ne 'D');
3185 if ($status eq 'A') {
3186 print "<td class=\"link\" align=\"right\"> | </td>\n";
3187 } elsif ($status eq 'D') {
3188 print "<td class=\"link\">" .
3189 $cgi->a({-href
=> href
(action
=>"blob",
3192 file_name
=>$from_path)},
3196 if ($diff->{'to_id'} eq $from_hash) {
3197 print "<td class=\"link nochange\">";
3199 print "<td class=\"link\">";
3201 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3202 hash
=>$diff->{'to_id'},
3203 hash_parent
=>$from_hash,
3205 hash_parent_base
=>$hash_parent,
3206 file_name
=>$diff->{'to_file'},
3207 file_parent
=>$from_path)},
3213 print "<td class=\"link\">";
3215 print $cgi->a({-href
=> href
(action
=>"blob",
3216 hash
=>$diff->{'to_id'},
3217 file_name
=>$diff->{'to_file'},
3220 print " | " if ($has_history);
3223 print $cgi->a({-href
=> href
(action
=>"history",
3224 file_name
=>$diff->{'to_file'},
3231 next; # instead of 'else' clause, to avoid extra indent
3233 # else ordinary diff
3235 my ($to_mode_oct, $to_mode_str, $to_file_type);
3236 my ($from_mode_oct, $from_mode_str, $from_file_type);
3237 if ($diff->{'to_mode'} ne ('0' x
6)) {
3238 $to_mode_oct = oct $diff->{'to_mode'};
3239 if (S_ISREG
($to_mode_oct)) { # only for regular file
3240 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3242 $to_file_type = file_type
($diff->{'to_mode'});
3244 if ($diff->{'from_mode'} ne ('0' x
6)) {
3245 $from_mode_oct = oct $diff->{'from_mode'};
3246 if (S_ISREG
($to_mode_oct)) { # only for regular file
3247 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3249 $from_file_type = file_type
($diff->{'from_mode'});
3252 if ($diff->{'status'} eq "A") { # created
3253 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3254 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3255 $mode_chng .= "]</span>";
3257 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3258 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3259 -class => "list"}, esc_path
($diff->{'file'}));
3261 print "<td>$mode_chng</td>\n";
3262 print "<td class=\"link\">";
3263 if ($action eq 'commitdiff') {
3266 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3269 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3270 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3274 } elsif ($diff->{'status'} eq "D") { # deleted
3275 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3277 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3278 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3279 -class => "list"}, esc_path
($diff->{'file'}));
3281 print "<td>$mode_chng</td>\n";
3282 print "<td class=\"link\">";
3283 if ($action eq 'commitdiff') {
3286 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3289 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3290 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3293 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3294 file_name
=>$diff->{'file'})},
3297 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3298 file_name
=>$diff->{'file'})},
3302 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3303 my $mode_chnge = "";
3304 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3305 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3306 if ($from_file_type ne $to_file_type) {
3307 $mode_chnge .= " from $from_file_type to $to_file_type";
3309 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3310 if ($from_mode_str && $to_mode_str) {
3311 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3312 } elsif ($to_mode_str) {
3313 $mode_chnge .= " mode: $to_mode_str";
3316 $mode_chnge .= "]</span>\n";
3319 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3320 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3321 -class => "list"}, esc_path
($diff->{'file'}));
3323 print "<td>$mode_chnge</td>\n";
3324 print "<td class=\"link\">";
3325 if ($action eq 'commitdiff') {
3328 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3330 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3331 # "commit" view and modified file (not onlu mode changed)
3332 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3333 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3334 hash_base
=>$hash, hash_parent_base
=>$parent,
3335 file_name
=>$diff->{'file'})},
3339 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3340 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3343 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3344 file_name
=>$diff->{'file'})},
3347 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3348 file_name
=>$diff->{'file'})},
3352 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3353 my %status_name = ('R' => 'moved', 'C' => 'copied');
3354 my $nstatus = $status_name{$diff->{'status'}};
3356 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3357 # mode also for directories, so we cannot use $to_mode_str
3358 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3361 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3362 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3363 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3364 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3365 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3366 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3367 -class => "list"}, esc_path
($diff->{'from_file'})) .
3368 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3369 "<td class=\"link\">";
3370 if ($action eq 'commitdiff') {
3373 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3375 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3376 # "commit" view and modified file (not only pure rename or copy)
3377 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3378 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3379 hash_base
=>$hash, hash_parent_base
=>$parent,
3380 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3384 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3385 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3388 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3389 file_name
=>$diff->{'to_file'})},
3392 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3393 file_name
=>$diff->{'to_file'})},
3397 } # we should not encounter Unmerged (U) or Unknown (X) status
3400 print "</tbody>" if $has_header;
3404 sub git_patchset_body
{
3405 my ($fd, $difftree, $hash, @hash_parents) = @_;
3406 my ($hash_parent) = $hash_parents[0];
3408 my $is_combined = (@hash_parents > 1);
3410 my $patch_number = 0;
3416 print "<div class=\"patchset\">\n";
3418 # skip to first patch
3419 while ($patch_line = <$fd>) {
3422 last if ($patch_line =~ m/^diff /);
3426 while ($patch_line) {
3428 # parse "git diff" header line
3429 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3430 # $1 is from_name, which we do not use
3431 $to_name = unquote
($2);
3432 $to_name =~ s!^b/!!;
3433 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3434 # $1 is 'cc' or 'combined', which we do not use
3435 $to_name = unquote
($2);
3440 # check if current patch belong to current raw line
3441 # and parse raw git-diff line if needed
3442 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3443 # this is continuation of a split patch
3444 print "<div class=\"patch cont\">\n";
3446 # advance raw git-diff output if needed
3447 $patch_idx++ if defined $diffinfo;
3449 # read and prepare patch information
3450 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3452 # compact combined diff output can have some patches skipped
3453 # find which patch (using pathname of result) we are at now;
3455 while ($to_name ne $diffinfo->{'to_file'}) {
3456 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3457 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3458 "</div>\n"; # class="patch"
3463 last if $patch_idx > $#$difftree;
3464 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3468 # modifies %from, %to hashes
3469 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3471 # this is first patch for raw difftree line with $patch_idx index
3472 # we index @$difftree array from 0, but number patches from 1
3473 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3477 #assert($patch_line =~ m/^diff /) if DEBUG;
3478 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3480 # print "git diff" header
3481 print format_git_diff_header_line
($patch_line, $diffinfo,
3484 # print extended diff header
3485 print "<div class=\"diff extended_header\">\n";
3487 while ($patch_line = <$fd>) {
3490 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3492 print format_extended_diff_header_line
($patch_line, $diffinfo,
3495 print "</div>\n"; # class="diff extended_header"
3497 # from-file/to-file diff header
3498 if (! $patch_line) {
3499 print "</div>\n"; # class="patch"
3502 next PATCH
if ($patch_line =~ m/^diff /);
3503 #assert($patch_line =~ m/^---/) if DEBUG;
3505 my $last_patch_line = $patch_line;
3506 $patch_line = <$fd>;
3508 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3510 print format_diff_from_to_header
($last_patch_line, $patch_line,
3511 $diffinfo, \
%from, \
%to,
3516 while ($patch_line = <$fd>) {
3519 next PATCH
if ($patch_line =~ m/^diff /);
3521 print format_diff_line
($patch_line, \
%from, \
%to);
3525 print "</div>\n"; # class="patch"
3528 # for compact combined (--cc) format, with chunk and patch simpliciaction
3529 # patchset might be empty, but there might be unprocessed raw lines
3530 for (++$patch_idx if $patch_number > 0;
3531 $patch_idx < @
$difftree;
3533 # read and prepare patch information
3534 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3536 # generate anchor for "patch" links in difftree / whatchanged part
3537 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3538 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3539 "</div>\n"; # class="patch"
3544 if ($patch_number == 0) {
3545 if (@hash_parents > 1) {
3546 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3548 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3552 print "</div>\n"; # class="patchset"
3555 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3557 sub git_project_list_body
{
3558 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3560 my ($check_forks) = gitweb_check_feature
('forks');
3563 foreach my $pr (@
$projlist) {
3564 my (@aa) = git_get_last_activity
($pr->{'path'});
3568 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3569 if (!defined $pr->{'descr'}) {
3570 my $descr = git_get_project_description
($pr->{'path'}) || "";
3571 $pr->{'descr_long'} = to_utf8
($descr);
3572 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3574 if (!defined $pr->{'owner'}) {
3575 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3578 my $pname = $pr->{'path'};
3579 if (($pname =~ s/\.git$//) &&
3580 ($pname !~ /\/$/) &&
3581 (-d
"$projectroot/$pname")) {
3582 $pr->{'forks'} = "-d $projectroot/$pname";
3588 push @projects, $pr;
3591 $order ||= $default_projects_order;
3592 $from = 0 unless defined $from;
3593 $to = $#projects if (!defined $to || $#projects < $to);
3595 print "<table class=\"project_list\">\n";
3596 unless ($no_header) {
3599 print "<th></th>\n";
3601 if ($order eq "project") {
3602 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3603 print "<th>Project</th>\n";
3606 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3607 -class => "header"}, "Project") .
3610 if ($order eq "descr") {
3611 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3612 print "<th>Description</th>\n";
3615 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3616 -class => "header"}, "Description") .
3619 if ($order eq "age") {
3620 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3621 print "<th>Last Change</th>\n";
3624 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3625 -class => "header"}, "Last Change") .
3628 print "<th></th>\n" .
3632 for (my $i = $from; $i <= $to; $i++) {
3633 my $pr = $projects[$i];
3635 print "<tr class=\"dark\">\n";
3637 print "<tr class=\"light\">\n";
3642 if ($pr->{'forks'}) {
3643 print "<!-- $pr->{'forks'} -->\n";
3644 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3648 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3649 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3650 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3651 -class => "list", -title
=> $pr->{'descr_long'}},
3652 esc_html
($pr->{'descr'})) . "</td>\n" .
3654 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3655 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
3656 "<td class=\"link\">" .
3657 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3658 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3659 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3660 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3661 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3665 if (defined $extra) {
3668 print "<td></td>\n";
3670 print "<td colspan=\"5\">$extra</td>\n" .
3676 sub git_shortlog_body
{
3677 # uses global variable $project
3678 my ($commitlist, $from, $to, $refs, $extra) = @_;
3680 $from = 0 unless defined $from;
3681 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3683 print "<table class=\"shortlog\">\n";
3685 for (my $i = $from; $i <= $to; $i++) {
3686 my %co = %{$commitlist->[$i]};
3687 my $commit = $co{'id'};
3688 my $ref = format_ref_marker
($refs, $commit);
3690 print "<tr class=\"dark\">\n";
3692 print "<tr class=\"light\">\n";
3695 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3696 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3697 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3698 "<td><i>" . $author . "</i></td>\n" .
3700 print format_subject_html
($co{'title'}, $co{'title_short'},
3701 href
(action
=>"commit", hash
=>$commit), $ref);
3703 "<td class=\"link\">" .
3704 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3705 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3706 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3707 my $snapshot_links = format_snapshot_links
($commit);
3708 if (defined $snapshot_links) {
3709 print " | " . $snapshot_links;
3714 if (defined $extra) {
3716 "<td colspan=\"4\">$extra</td>\n" .
3722 sub git_history_body
{
3723 # Warning: assumes constant type (blob or tree) during history
3724 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3726 $from = 0 unless defined $from;
3727 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3729 print "<table class=\"history\">\n";
3731 for (my $i = $from; $i <= $to; $i++) {
3732 my %co = %{$commitlist->[$i]};
3736 my $commit = $co{'id'};
3738 my $ref = format_ref_marker
($refs, $commit);
3741 print "<tr class=\"dark\">\n";
3743 print "<tr class=\"light\">\n";
3746 # shortlog uses chop_str($co{'author_name'}, 10)
3747 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3748 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3749 "<td><i>" . $author . "</i></td>\n" .
3751 # originally git_history used chop_str($co{'title'}, 50)
3752 print format_subject_html
($co{'title'}, $co{'title_short'},
3753 href
(action
=>"commit", hash
=>$commit), $ref);
3755 "<td class=\"link\">" .
3756 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3757 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3759 if ($ftype eq 'blob') {
3760 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3761 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3762 if (defined $blob_current && defined $blob_parent &&
3763 $blob_current ne $blob_parent) {
3765 $cgi->a({-href
=> href
(action
=>"blobdiff",
3766 hash
=>$blob_current, hash_parent
=>$blob_parent,
3767 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3768 file_name
=>$file_name)},
3775 if (defined $extra) {
3777 "<td colspan=\"4\">$extra</td>\n" .
3784 # uses global variable $project
3785 my ($taglist, $from, $to, $extra) = @_;
3786 $from = 0 unless defined $from;
3787 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3789 print "<table class=\"tags\">\n";
3791 for (my $i = $from; $i <= $to; $i++) {
3792 my $entry = $taglist->[$i];
3794 my $comment = $tag{'subject'};
3796 if (defined $comment) {
3797 $comment_short = chop_str
($comment, 30, 5);
3800 print "<tr class=\"dark\">\n";
3802 print "<tr class=\"light\">\n";
3805 if (defined $tag{'age'}) {
3806 print "<td><i>$tag{'age'}</i></td>\n";
3808 print "<td></td>\n";
3811 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3812 -class => "list name"}, esc_html
($tag{'name'})) .
3815 if (defined $comment) {
3816 print format_subject_html
($comment, $comment_short,
3817 href
(action
=>"tag", hash
=>$tag{'id'}));
3820 "<td class=\"selflink\">";
3821 if ($tag{'type'} eq "tag") {
3822 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3827 "<td class=\"link\">" . " | " .
3828 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3829 if ($tag{'reftype'} eq "commit") {
3830 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
3831 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
3832 } elsif ($tag{'reftype'} eq "blob") {
3833 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3838 if (defined $extra) {
3840 "<td colspan=\"5\">$extra</td>\n" .
3846 sub git_heads_body
{
3847 # uses global variable $project
3848 my ($headlist, $head, $from, $to, $extra) = @_;
3849 $from = 0 unless defined $from;
3850 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3852 print "<table class=\"heads\">\n";
3854 for (my $i = $from; $i <= $to; $i++) {
3855 my $entry = $headlist->[$i];
3857 my $curr = $ref{'id'} eq $head;
3859 print "<tr class=\"dark\">\n";
3861 print "<tr class=\"light\">\n";
3864 print "<td><i>$ref{'age'}</i></td>\n" .
3865 ($curr ?
"<td class=\"current_head\">" : "<td>") .
3866 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
3867 -class => "list name"},esc_html
($ref{'name'})) .
3869 "<td class=\"link\">" .
3870 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
3871 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
3872 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
3876 if (defined $extra) {
3878 "<td colspan=\"3\">$extra</td>\n" .
3884 sub git_search_grep_body
{
3885 my ($commitlist, $from, $to, $extra) = @_;
3886 $from = 0 unless defined $from;
3887 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3889 print "<table class=\"commit_search\">\n";
3891 for (my $i = $from; $i <= $to; $i++) {
3892 my %co = %{$commitlist->[$i]};
3896 my $commit = $co{'id'};
3898 print "<tr class=\"dark\">\n";
3900 print "<tr class=\"light\">\n";
3903 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
3904 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3905 "<td><i>" . $author . "</i></td>\n" .
3907 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3908 -class => "list subject"},
3909 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
3910 my $comment = $co{'comment'};
3911 foreach my $line (@
$comment) {
3912 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
3913 my ($lead, $match, $trail) = ($1, $2, $3);
3914 $match = chop_str
($match, 70, 5, 'center');
3915 my $contextlen = int((80 - length($match))/2);
3916 $contextlen = 30 if ($contextlen > 30);
3917 $lead = chop_str
($lead, $contextlen, 10, 'left');
3918 $trail = chop_str
($trail, $contextlen, 10, 'right');
3920 $lead = esc_html
($lead);
3921 $match = esc_html
($match);
3922 $trail = esc_html
($trail);
3924 print "$lead<span class=\"match\">$match</span>$trail<br />";
3928 "<td class=\"link\">" .
3929 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3931 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
3933 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3937 if (defined $extra) {
3939 "<td colspan=\"3\">$extra</td>\n" .
3945 ## ======================================================================
3946 ## ======================================================================
3949 sub git_project_list
{
3950 my $order = $cgi->param('o');
3951 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3952 die_error
(undef, "Unknown order parameter");
3955 my @list = git_get_projects_list
();
3957 die_error
(undef, "No projects found");
3961 if (-f
$home_text) {
3962 print "<div class=\"index_include\">\n";
3963 open (my $fd, $home_text);
3968 git_project_list_body
(\
@list, $order);
3973 my $order = $cgi->param('o');
3974 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3975 die_error
(undef, "Unknown order parameter");
3978 my @list = git_get_projects_list
($project);
3980 die_error
(undef, "No forks found");
3984 git_print_page_nav
('','');
3985 git_print_header_div
('summary', "$project forks");
3986 git_project_list_body
(\
@list, $order);
3990 sub git_project_index
{
3991 my @projects = git_get_projects_list
($project);
3994 -type
=> 'text/plain',
3995 -charset
=> 'utf-8',
3996 -content_disposition
=> 'inline; filename="index.aux"');
3998 foreach my $pr (@projects) {
3999 if (!exists $pr->{'owner'}) {
4000 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4003 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4004 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4005 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4006 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4010 print "$path $owner\n";
4015 my $descr = git_get_project_description
($project) || "none";
4016 my %co = parse_commit
("HEAD");
4017 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4018 my $head = $co{'id'};
4020 my $owner = git_get_project_owner
($project);
4022 my $refs = git_get_references
();
4023 # These get_*_list functions return one more to allow us to see if
4024 # there are more ...
4025 my @taglist = git_get_tags_list
(16);
4026 my @headlist = git_get_heads_list
(16);
4028 my ($check_forks) = gitweb_check_feature
('forks');
4031 @forklist = git_get_projects_list
($project);
4035 git_print_page_nav
('summary','', $head);
4037 print "<div class=\"title\"> </div>\n";
4038 print "<table class=\"projects_list\">\n" .
4039 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4040 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4041 if (defined $cd{'rfc2822'}) {
4042 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4045 # use per project git URL list in $projectroot/$project/cloneurl
4046 # or make project git URL from git base URL and project name
4047 my $url_tag = "URL";
4048 my @url_list = git_get_project_url_list
($project);
4049 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4050 foreach my $git_url (@url_list) {
4051 next unless $git_url;
4052 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
4057 if (-s
"$projectroot/$project/README.html") {
4058 if (open my $fd, "$projectroot/$project/README.html") {
4059 print "<div class=\"title\">readme</div>\n" .
4060 "<div class=\"readme\">\n";
4061 print $_ while (<$fd>);
4062 print "\n</div>\n"; # class="readme"
4067 # we need to request one more than 16 (0..15) to check if
4069 my @commitlist = $head ? parse_commits
($head, 17) : ();
4071 git_print_header_div
('shortlog');
4072 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4073 $#commitlist <= 15 ?
undef :
4074 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4078 git_print_header_div
('tags');
4079 git_tags_body
(\
@taglist, 0, 15,
4080 $#taglist <= 15 ?
undef :
4081 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4085 git_print_header_div
('heads');
4086 git_heads_body
(\
@headlist, $head, 0, 15,
4087 $#headlist <= 15 ?
undef :
4088 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4092 git_print_header_div
('forks');
4093 git_project_list_body
(\
@forklist, undef, 0, 15,
4094 $#forklist <= 15 ?
undef :
4095 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4103 my $head = git_get_head_hash
($project);
4105 git_print_page_nav
('','', $head,undef,$head);
4106 my %tag = parse_tag
($hash);
4109 die_error
(undef, "Unknown tag object");
4112 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4113 print "<div class=\"title_text\">\n" .
4114 "<table class=\"object_header\">\n" .
4116 "<td>object</td>\n" .
4117 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4118 $tag{'object'}) . "</td>\n" .
4119 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4120 $tag{'type'}) . "</td>\n" .
4122 if (defined($tag{'author'})) {
4123 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4124 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4125 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4126 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4129 print "</table>\n\n" .
4131 print "<div class=\"page_body\">";
4132 my $comment = $tag{'comment'};
4133 foreach my $line (@
$comment) {
4135 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4145 my ($have_blame) = gitweb_check_feature
('blame');
4147 die_error
('403 Permission denied', "Permission denied");
4149 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4150 $hash_base ||= git_get_head_hash
($project);
4151 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4152 my %co = parse_commit
($hash_base)
4153 or die_error
(undef, "Reading commit failed");
4154 if (!defined $hash) {
4155 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4156 or die_error
(undef, "Error looking up file");
4158 $ftype = git_get_type
($hash);
4159 if ($ftype !~ "blob") {
4160 die_error
('400 Bad Request', "Object is not a blob");
4162 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4163 $file_name, $hash_base)
4164 or die_error
(undef, "Open git-blame failed");
4167 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4170 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4173 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4175 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4176 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4177 git_print_page_path
($file_name, $ftype, $hash_base);
4178 my @rev_color = (qw(light2 dark2));
4179 my $num_colors = scalar(@rev_color);
4180 my $current_color = 0;
4183 <div class="page_body">
4184 <table class="blame">
4185 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4190 last unless defined $_;
4191 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4192 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4193 if (!exists $metainfo{$full_rev}) {
4194 $metainfo{$full_rev} = {};
4196 my $meta = $metainfo{$full_rev};
4199 if (/^(\S+) (.*)$/) {
4205 my $rev = substr($full_rev, 0, 8);
4206 my $author = $meta->{'author'};
4207 my %date = parse_date
($meta->{'author-time'},
4208 $meta->{'author-tz'});
4209 my $date = $date{'iso-tz'};
4211 $current_color = ++$current_color % $num_colors;
4213 print "<tr class=\"$rev_color[$current_color]\">\n";
4215 print "<td class=\"sha1\"";
4216 print " title=\"". esc_html
($author) . ", $date\"";
4217 print " rowspan=\"$group_size\"" if ($group_size > 1);
4219 print $cgi->a({-href
=> href
(action
=>"commit",
4221 file_name
=>$file_name)},
4225 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4226 or die_error
(undef, "Open git-rev-parse failed");
4227 my $parent_commit = <$dd>;
4229 chomp($parent_commit);
4230 my $blamed = href
(action
=> 'blame',
4231 file_name
=> $meta->{'filename'},
4232 hash_base
=> $parent_commit);
4233 print "<td class=\"linenr\">";
4234 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4236 -class => "linenr" },
4239 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4245 or print "Reading blob failed\n";
4252 my ($have_blame) = gitweb_check_feature
('blame');
4254 die_error
('403 Permission denied', "Permission denied");
4256 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4257 $hash_base ||= git_get_head_hash
($project);
4258 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4259 my %co = parse_commit
($hash_base)
4260 or die_error
(undef, "Reading commit failed");
4261 if (!defined $hash) {
4262 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4263 or die_error
(undef, "Error lookup file");
4265 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
4266 or die_error
(undef, "Open git-annotate failed");
4269 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4272 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4275 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4277 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4278 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4279 git_print_page_path
($file_name, 'blob', $hash_base);
4280 print "<div class=\"page_body\">\n";
4282 <table class="blame">
4291 my @line_class = (qw(light dark));
4292 my $line_class_len = scalar (@line_class);
4293 my $line_class_num = $#line_class;
4294 while (my $line = <$fd>) {
4306 $line_class_num = ($line_class_num + 1) % $line_class_len;
4308 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4315 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
4318 $short_rev = substr ($long_rev, 0, 8);
4319 $age = time () - $time;
4320 $age_str = age_string
($age);
4321 $age_str =~ s/ / /g;
4322 $age_class = age_class
($age);
4323 $author = esc_html
($author);
4324 $author =~ s/ / /g;
4326 $data = untabify
($data);
4327 $data = esc_html
($data);
4330 <tr class="$line_class[$line_class_num]">
4331 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4332 <td class="$age_class">$age_str</td>
4334 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4335 <td class="pre">$data</td>
4338 } # while (my $line = <$fd>)
4339 print "</table>\n\n";
4341 or print "Reading blob failed.\n";
4347 my $head = git_get_head_hash
($project);
4349 git_print_page_nav
('','', $head,undef,$head);
4350 git_print_header_div
('summary', $project);
4352 my @tagslist = git_get_tags_list
();
4354 git_tags_body
(\
@tagslist);
4360 my $head = git_get_head_hash
($project);
4362 git_print_page_nav
('','', $head,undef,$head);
4363 git_print_header_div
('summary', $project);
4365 my @headslist = git_get_heads_list
();
4367 git_heads_body
(\
@headslist, $head);
4372 sub git_blob_plain
{
4376 if (!defined $hash) {
4377 if (defined $file_name) {
4378 my $base = $hash_base || git_get_head_hash
($project);
4379 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4380 or die_error
(undef, "Error lookup file");
4382 die_error
(undef, "No file name defined");
4384 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4385 # blobs defined by non-textual hash id's can be cached
4389 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4390 or die_error
(undef, "Open git-cat-file blob '$hash' failed");
4392 # content-type (can include charset)
4393 $type = blob_contenttype
($fd, $file_name, $type);
4395 # "save as" filename, even when no $file_name is given
4396 my $save_as = "$hash";
4397 if (defined $file_name) {
4398 $save_as = $file_name;
4399 } elsif ($type =~ m/^text\//) {
4405 -expires
=> $expires,
4406 -content_disposition
=> 'inline; filename="' . $save_as . '"');
4408 binmode STDOUT
, ':raw';
4410 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4418 if (!defined $hash) {
4419 if (defined $file_name) {
4420 my $base = $hash_base || git_get_head_hash
($project);
4421 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4422 or die_error
(undef, "Error lookup file");
4424 die_error
(undef, "No file name defined");
4426 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4427 # blobs defined by non-textual hash id's can be cached
4431 my ($have_blame) = gitweb_check_feature
('blame');
4432 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4433 or die_error
(undef, "Couldn't cat $file_name, $hash");
4434 my $mimetype = blob_mimetype
($fd, $file_name);
4435 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4437 return git_blob_plain
($mimetype);
4439 # we can have blame only for text/* mimetype
4440 $have_blame &&= ($mimetype =~ m!^text/!);
4442 git_header_html
(undef, $expires);
4443 my $formats_nav = '';
4444 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4445 if (defined $file_name) {
4448 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4453 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4456 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4459 $cgi->a({-href
=> href
(action
=>"blob",
4460 hash_base
=>"HEAD", file_name
=>$file_name)},
4464 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4467 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4468 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4470 print "<div class=\"page_nav\">\n" .
4471 "<br/><br/></div>\n" .
4472 "<div class=\"title\">$hash</div>\n";
4474 git_print_page_path
($file_name, "blob", $hash_base);
4475 print "<div class=\"page_body\">\n";
4476 if ($mimetype =~ m!^image/!) {
4477 print qq!<img type
="$mimetype"!;
4479 print qq! alt
="$file_name" title
="$file_name"!;
4482 href(action=>"blob_plain
", hash=>$hash,
4483 hash_base=>$hash_base, file_name=>$file_name) .
4487 while (my $line = <$fd>) {
4490 $line = untabify
($line);
4491 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4492 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4496 or print "Reading blob failed.\n";
4502 if (!defined $hash_base) {
4503 $hash_base = "HEAD";
4505 if (!defined $hash) {
4506 if (defined $file_name) {
4507 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4513 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4514 or die_error
(undef, "Open git-ls-tree failed");
4515 my @entries = map { chomp; $_ } <$fd>;
4516 close $fd or die_error
(undef, "Reading tree failed");
4519 my $refs = git_get_references
();
4520 my $ref = format_ref_marker
($refs, $hash_base);
4523 my ($have_blame) = gitweb_check_feature
('blame');
4524 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4526 if (defined $file_name) {
4528 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4530 $cgi->a({-href
=> href
(action
=>"tree",
4531 hash_base
=>"HEAD", file_name
=>$file_name)},
4534 my $snapshot_links = format_snapshot_links
($hash);
4535 if (defined $snapshot_links) {
4536 # FIXME: Should be available when we have no hash base as well.
4537 push @views_nav, $snapshot_links;
4539 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4540 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4543 print "<div class=\"page_nav\">\n";
4544 print "<br/><br/></div>\n";
4545 print "<div class=\"title\">$hash</div>\n";
4547 if (defined $file_name) {
4548 $basedir = $file_name;
4549 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4553 git_print_page_path
($file_name, 'tree', $hash_base);
4554 print "<div class=\"page_body\">\n";
4555 print "<table class=\"tree\">\n";
4557 # '..' (top directory) link if possible
4558 if (defined $hash_base &&
4559 defined $file_name && $file_name =~ m![^/]+$!) {
4561 print "<tr class=\"dark\">\n";
4563 print "<tr class=\"light\">\n";
4567 my $up = $file_name;
4568 $up =~ s!/?[^/]+$!!;
4569 undef $up unless $up;
4570 # based on git_print_tree_entry
4571 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4572 print '<td class="list">';
4573 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4577 print "<td class=\"link\"></td>\n";
4581 foreach my $line (@entries) {
4582 my %t = parse_ls_tree_line
($line, -z
=> 1);
4585 print "<tr class=\"dark\">\n";
4587 print "<tr class=\"light\">\n";
4591 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4595 print "</table>\n" .
4601 my @supported_fmts = gitweb_check_feature
('snapshot');
4602 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4604 my $format = $cgi->param('sf');
4605 if (!@supported_fmts) {
4606 die_error
('403 Permission denied', "Permission denied");
4608 # default to first supported snapshot format
4609 $format ||= $supported_fmts[0];
4610 if ($format !~ m/^[a-z0-9]+$/) {
4611 die_error
(undef, "Invalid snapshot format parameter");
4612 } elsif (!exists($known_snapshot_formats{$format})) {
4613 die_error
(undef, "Unknown snapshot format");
4614 } elsif (!grep($_ eq $format, @supported_fmts)) {
4615 die_error
(undef, "Unsupported snapshot format");
4618 if (!defined $hash) {
4619 $hash = git_get_head_hash
($project);
4622 my $name = $project;
4623 $name =~ s
,([^/])/*\
.git
$,$1,;
4624 $name = basename
($name);
4625 my $filename = to_utf8
($name);
4626 $name =~ s/\047/\047\\\047\047/g;
4628 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4629 $cmd = quote_command
(
4630 git_cmd
(), 'archive',
4631 "--format=$known_snapshot_formats{$format}{'format'}",
4632 "--prefix=$name/", $hash);
4633 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4634 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
4638 -type
=> $known_snapshot_formats{$format}{'type'},
4639 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4640 -status
=> '200 OK');
4642 open my $fd, "-|", $cmd
4643 or die_error
(undef, "Execute git-archive failed");
4644 binmode STDOUT
, ':raw';
4646 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4651 my $head = git_get_head_hash
($project);
4652 if (!defined $hash) {
4655 if (!defined $page) {
4658 my $refs = git_get_references
();
4660 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4662 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
4665 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4668 my %co = parse_commit
($hash);
4670 git_print_header_div
('summary', $project);
4671 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4673 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
4674 for (my $i = 0; $i <= $to; $i++) {
4675 my %co = %{$commitlist[$i]};
4677 my $commit = $co{'id'};
4678 my $ref = format_ref_marker
($refs, $commit);
4679 my %ad = parse_date
($co{'author_epoch'});
4680 git_print_header_div
('commit',
4681 "<span class=\"age\">$co{'age_string'}</span>" .
4682 esc_html
($co{'title'}) . $ref,
4684 print "<div class=\"title_text\">\n" .
4685 "<div class=\"log_link\">\n" .
4686 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4688 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4690 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4693 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4696 print "<div class=\"log_body\">\n";
4697 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4700 if ($#commitlist >= 100) {
4701 print "<div class=\"page_nav\">\n";
4702 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4703 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4710 $hash ||= $hash_base || "HEAD";
4711 my %co = parse_commit
($hash);
4713 die_error
(undef, "Unknown commit object");
4715 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4716 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4718 my $parent = $co{'parent'};
4719 my $parents = $co{'parents'}; # listref
4721 # we need to prepare $formats_nav before any parameter munging
4723 if (!defined $parent) {
4725 $formats_nav .= '(initial)';
4726 } elsif (@
$parents == 1) {
4727 # single parent commit
4730 $cgi->a({-href
=> href
(action
=>"commit",
4732 esc_html
(substr($parent, 0, 7))) .
4739 $cgi->a({-href
=> href
(action
=>"commit",
4741 esc_html
(substr($_, 0, 7)));
4746 if (!defined $parent) {
4750 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4752 (@
$parents <= 1 ?
$parent : '-c'),
4754 or die_error
(undef, "Open git-diff-tree failed");
4755 @difftree = map { chomp; $_ } <$fd>;
4756 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4758 # non-textual hash id's can be cached
4760 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4763 my $refs = git_get_references
();
4764 my $ref = format_ref_marker
($refs, $co{'id'});
4766 git_header_html
(undef, $expires);
4767 git_print_page_nav
('commit', '',
4768 $hash, $co{'tree'}, $hash,
4771 if (defined $co{'parent'}) {
4772 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4774 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4776 print "<div class=\"title_text\">\n" .
4777 "<table class=\"object_header\">\n";
4778 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4780 "<td></td><td> $ad{'rfc2822'}";
4781 if ($ad{'hour_local'} < 6) {
4782 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4783 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4785 printf(" (%02d:%02d %s)",
4786 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4790 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4791 print "<tr><td></td><td> $cd{'rfc2822'}" .
4792 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4794 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4797 "<td class=\"sha1\">" .
4798 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4799 class => "list"}, $co{'tree'}) .
4801 "<td class=\"link\">" .
4802 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4804 my $snapshot_links = format_snapshot_links
($hash);
4805 if (defined $snapshot_links) {
4806 print " | " . $snapshot_links;
4811 foreach my $par (@
$parents) {
4814 "<td class=\"sha1\">" .
4815 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4816 class => "list"}, $par) .
4818 "<td class=\"link\">" .
4819 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4821 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4828 print "<div class=\"page_body\">\n";
4829 git_print_log
($co{'comment'});
4832 git_difftree_body
(\
@difftree, $hash, @
$parents);
4838 # object is defined by:
4839 # - hash or hash_base alone
4840 # - hash_base and file_name
4843 # - hash or hash_base alone
4844 if ($hash || ($hash_base && !defined $file_name)) {
4845 my $object_id = $hash || $hash_base;
4847 open my $fd, "-|", quote_command
(
4848 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
4849 or die_error
('404 Not Found', "Object does not exist");
4853 or die_error
('404 Not Found', "Object does not exist");
4855 # - hash_base and file_name
4856 } elsif ($hash_base && defined $file_name) {
4857 $file_name =~ s
,/+$,,;
4859 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4860 or die_error
('404 Not Found', "Base object does not exist");
4862 # here errors should not hapen
4863 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4864 or die_error
(undef, "Open git-ls-tree failed");
4868 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4869 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4870 die_error
('404 Not Found', "File or directory for given base does not exist");
4875 die_error
('404 Not Found', "Not enough information to find object");
4878 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4879 hash
=>$hash, hash_base
=>$hash_base,
4880 file_name
=>$file_name),
4881 -status
=> '302 Found');
4885 my $format = shift || 'html';
4892 # preparing $fd and %diffinfo for git_patchset_body
4894 if (defined $hash_base && defined $hash_parent_base) {
4895 if (defined $file_name) {
4897 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4898 $hash_parent_base, $hash_base,
4899 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4900 or die_error
(undef, "Open git-diff-tree failed");
4901 @difftree = map { chomp; $_ } <$fd>;
4903 or die_error
(undef, "Reading git-diff-tree failed");
4905 or die_error
('404 Not Found', "Blob diff not found");
4907 } elsif (defined $hash &&
4908 $hash =~ /[0-9a-fA-F]{40}/) {
4909 # try to find filename from $hash
4911 # read filtered raw output
4912 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4913 $hash_parent_base, $hash_base, "--"
4914 or die_error
(undef, "Open git-diff-tree failed");
4916 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4918 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4919 map { chomp; $_ } <$fd>;
4921 or die_error
(undef, "Reading git-diff-tree failed");
4923 or die_error
('404 Not Found', "Blob diff not found");
4926 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4929 if (@difftree > 1) {
4930 die_error
('404 Not Found', "Ambiguous blob diff specification");
4933 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4934 $file_parent ||= $diffinfo{'from_file'} || $file_name;
4935 $file_name ||= $diffinfo{'to_file'};
4937 $hash_parent ||= $diffinfo{'from_id'};
4938 $hash ||= $diffinfo{'to_id'};
4940 # non-textual hash id's can be cached
4941 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4942 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4947 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4948 '-p', ($format eq 'html' ?
"--full-index" : ()),
4949 $hash_parent_base, $hash_base,
4950 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4951 or die_error
(undef, "Open git-diff-tree failed");
4954 # old/legacy style URI
4955 if (!%diffinfo && # if new style URI failed
4956 defined $hash && defined $hash_parent) {
4957 # fake git-diff-tree raw output
4958 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4959 $diffinfo{'from_id'} = $hash_parent;
4960 $diffinfo{'to_id'} = $hash;
4961 if (defined $file_name) {
4962 if (defined $file_parent) {
4963 $diffinfo{'status'} = '2';
4964 $diffinfo{'from_file'} = $file_parent;
4965 $diffinfo{'to_file'} = $file_name;
4966 } else { # assume not renamed
4967 $diffinfo{'status'} = '1';
4968 $diffinfo{'from_file'} = $file_name;
4969 $diffinfo{'to_file'} = $file_name;
4971 } else { # no filename given
4972 $diffinfo{'status'} = '2';
4973 $diffinfo{'from_file'} = $hash_parent;
4974 $diffinfo{'to_file'} = $hash;
4977 # non-textual hash id's can be cached
4978 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4979 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4984 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4985 '-p', ($format eq 'html' ?
"--full-index" : ()),
4986 $hash_parent, $hash, "--"
4987 or die_error
(undef, "Open git-diff failed");
4989 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4994 if ($format eq 'html') {
4996 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
4998 git_header_html
(undef, $expires);
4999 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5000 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5001 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5003 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5004 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5006 if (defined $file_name) {
5007 git_print_page_path
($file_name, "blob", $hash_base);
5009 print "<div class=\"page_path\"></div>\n";
5012 } elsif ($format eq 'plain') {
5014 -type
=> 'text/plain',
5015 -charset
=> 'utf-8',
5016 -expires
=> $expires,
5017 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5019 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5022 die_error
(undef, "Unknown blobdiff format");
5026 if ($format eq 'html') {
5027 print "<div class=\"page_body\">\n";
5029 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5032 print "</div>\n"; # class="page_body"
5036 while (my $line = <$fd>) {
5037 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5038 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5042 last if $line =~ m!^\+\+\+!;
5050 sub git_blobdiff_plain
{
5051 git_blobdiff
('plain');
5054 sub git_commitdiff
{
5055 my $format = shift || 'html';
5056 $hash ||= $hash_base || "HEAD";
5057 my %co = parse_commit
($hash);
5059 die_error
(undef, "Unknown commit object");
5062 # choose format for commitdiff for merge
5063 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
5064 $hash_parent = '--cc';
5066 # we need to prepare $formats_nav before almost any parameter munging
5068 if ($format eq 'html') {
5070 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5073 if (defined $hash_parent &&
5074 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5075 # commitdiff with two commits given
5076 my $hash_parent_short = $hash_parent;
5077 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5078 $hash_parent_short = substr($hash_parent, 0, 7);
5082 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
5083 if ($co{'parents'}[$i] eq $hash_parent) {
5084 $formats_nav .= ' parent ' . ($i+1);
5088 $formats_nav .= ': ' .
5089 $cgi->a({-href
=> href
(action
=>"commitdiff",
5090 hash
=>$hash_parent)},
5091 esc_html
($hash_parent_short)) .
5093 } elsif (!$co{'parent'}) {
5095 $formats_nav .= ' (initial)';
5096 } elsif (scalar @
{$co{'parents'}} == 1) {
5097 # single parent commit
5100 $cgi->a({-href
=> href
(action
=>"commitdiff",
5101 hash
=>$co{'parent'})},
5102 esc_html
(substr($co{'parent'}, 0, 7))) .
5106 if ($hash_parent eq '--cc') {
5107 $formats_nav .= ' | ' .
5108 $cgi->a({-href
=> href
(action
=>"commitdiff",
5109 hash
=>$hash, hash_parent
=>'-c')},
5111 } else { # $hash_parent eq '-c'
5112 $formats_nav .= ' | ' .
5113 $cgi->a({-href
=> href
(action
=>"commitdiff",
5114 hash
=>$hash, hash_parent
=>'--cc')},
5120 $cgi->a({-href
=> href
(action
=>"commitdiff",
5122 esc_html
(substr($_, 0, 7)));
5123 } @
{$co{'parents'}} ) .
5128 my $hash_parent_param = $hash_parent;
5129 if (!defined $hash_parent_param) {
5130 # --cc for multiple parents, --root for parentless
5131 $hash_parent_param =
5132 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
5138 if ($format eq 'html') {
5139 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5140 "--no-commit-id", "--patch-with-raw", "--full-index",
5141 $hash_parent_param, $hash, "--"
5142 or die_error
(undef, "Open git-diff-tree failed");
5144 while (my $line = <$fd>) {
5146 # empty line ends raw part of diff-tree output
5148 push @difftree, scalar parse_difftree_raw_line
($line);
5151 } elsif ($format eq 'plain') {
5152 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5153 '-p', $hash_parent_param, $hash, "--"
5154 or die_error
(undef, "Open git-diff-tree failed");
5157 die_error
(undef, "Unknown commitdiff format");
5160 # non-textual hash id's can be cached
5162 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5166 # write commit message
5167 if ($format eq 'html') {
5168 my $refs = git_get_references
();
5169 my $ref = format_ref_marker
($refs, $co{'id'});
5171 git_header_html
(undef, $expires);
5172 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5173 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5174 git_print_authorship
(\
%co);
5175 print "<div class=\"page_body\">\n";
5176 if (@
{$co{'comment'}} > 1) {
5177 print "<div class=\"log\">\n";
5178 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5179 print "</div>\n"; # class="log"
5182 } elsif ($format eq 'plain') {
5183 my $refs = git_get_references
("tags");
5184 my $tagname = git_get_rev_name_tags
($hash);
5185 my $filename = basename
($project) . "-$hash.patch";
5188 -type
=> 'text/plain',
5189 -charset
=> 'utf-8',
5190 -expires
=> $expires,
5191 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5192 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5193 print "From: " . to_utf8
($co{'author'}) . "\n";
5194 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5195 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5197 print "X-Git-Tag: $tagname\n" if $tagname;
5198 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5200 foreach my $line (@
{$co{'comment'}}) {
5201 print to_utf8
($line) . "\n";
5207 if ($format eq 'html') {
5208 my $use_parents = !defined $hash_parent ||
5209 $hash_parent eq '-c' || $hash_parent eq '--cc';
5210 git_difftree_body
(\
@difftree, $hash,
5211 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5214 git_patchset_body
($fd, \
@difftree, $hash,
5215 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5217 print "</div>\n"; # class="page_body"
5220 } elsif ($format eq 'plain') {
5224 or print "Reading git-diff-tree failed\n";
5228 sub git_commitdiff_plain
{
5229 git_commitdiff
('plain');
5233 if (!defined $hash_base) {
5234 $hash_base = git_get_head_hash
($project);
5236 if (!defined $page) {
5240 my %co = parse_commit
($hash_base);
5242 die_error
(undef, "Unknown commit object");
5245 my $refs = git_get_references
();
5246 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5248 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5249 $file_name, "--full-history");
5251 die_error
('404 Not Found', "No such file or directory on given branch");
5254 if (!defined $hash && defined $file_name) {
5255 # some commits could have deleted file in question,
5256 # and not have it in tree, but one of them has to have it
5257 for (my $i = 0; $i <= @commitlist; $i++) {
5258 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5259 last if defined $hash;
5262 if (defined $hash) {
5263 $ftype = git_get_type
($hash);
5265 if (!defined $ftype) {
5266 die_error
(undef, "Unknown type of object");
5269 my $paging_nav = '';
5272 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5273 file_name
=>$file_name)},
5275 $paging_nav .= " ⋅ " .
5276 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5277 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5279 $paging_nav .= "first";
5280 $paging_nav .= " ⋅ prev";
5283 if ($#commitlist >= 100) {
5285 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5286 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5287 $paging_nav .= " ⋅ $next_link";
5289 $paging_nav .= " ⋅ next";
5293 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5294 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5295 git_print_page_path
($file_name, $ftype, $hash_base);
5297 git_history_body
(\
@commitlist, 0, 99,
5298 $refs, $hash_base, $ftype, $next_link);
5304 my ($have_search) = gitweb_check_feature
('search');
5305 if (!$have_search) {
5306 die_error
('403 Permission denied', "Permission denied");
5308 if (!defined $searchtext) {
5309 die_error
(undef, "Text field empty");
5311 if (!defined $hash) {
5312 $hash = git_get_head_hash
($project);
5314 my %co = parse_commit
($hash);
5316 die_error
(undef, "Unknown commit object");
5318 if (!defined $page) {
5322 $searchtype ||= 'commit';
5323 if ($searchtype eq 'pickaxe') {
5324 # pickaxe may take all resources of your box and run for several minutes
5325 # with every query - so decide by yourself how public you make this feature
5326 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5327 if (!$have_pickaxe) {
5328 die_error
('403 Permission denied', "Permission denied");
5331 if ($searchtype eq 'grep') {
5332 my ($have_grep) = gitweb_check_feature
('grep');
5334 die_error
('403 Permission denied', "Permission denied");
5340 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5342 if ($searchtype eq 'commit') {
5343 $greptype = "--grep=";
5344 } elsif ($searchtype eq 'author') {
5345 $greptype = "--author=";
5346 } elsif ($searchtype eq 'committer') {
5347 $greptype = "--committer=";
5349 $greptype .= $searchtext;
5350 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5351 $greptype, '--regexp-ignore-case',
5352 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
5354 my $paging_nav = '';
5357 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5358 searchtext
=>$searchtext,
5359 searchtype
=>$searchtype)},
5361 $paging_nav .= " ⋅ " .
5362 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5363 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5365 $paging_nav .= "first";
5366 $paging_nav .= " ⋅ prev";
5369 if ($#commitlist >= 100) {
5371 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5372 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5373 $paging_nav .= " ⋅ $next_link";
5375 $paging_nav .= " ⋅ next";
5378 if ($#commitlist >= 100) {
5381 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5382 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5383 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5386 if ($searchtype eq 'pickaxe') {
5387 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5388 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5390 print "<table class=\"pickaxe search\">\n";
5393 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5394 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5395 ($search_use_regexp ?
'--pickaxe-regex' : ());
5398 while (my $line = <$fd>) {
5402 my %set = parse_difftree_raw_line
($line);
5403 if (defined $set{'commit'}) {
5404 # finish previous commit
5407 "<td class=\"link\">" .
5408 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5410 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5416 print "<tr class=\"dark\">\n";
5418 print "<tr class=\"light\">\n";
5421 %co = parse_commit
($set{'commit'});
5422 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5423 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5424 "<td><i>$author</i></td>\n" .
5426 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5427 -class => "list subject"},
5428 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5429 } elsif (defined $set{'to_id'}) {
5430 next if ($set{'to_id'} =~ m/^0{40}$/);
5432 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5433 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5435 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5441 # finish last commit (warning: repetition!)
5444 "<td class=\"link\">" .
5445 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5447 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5455 if ($searchtype eq 'grep') {
5456 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5457 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5459 print "<table class=\"grep_search\">\n";
5463 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5464 $search_use_regexp ?
('-E', '-i') : '-F',
5465 $searchtext, $co{'tree'};
5467 while (my $line = <$fd>) {
5469 my ($file, $lno, $ltext, $binary);
5470 last if ($matches++ > 1000);
5471 if ($line =~ /^Binary file (.+) matches$/) {
5475 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5477 if ($file ne $lastfile) {
5478 $lastfile and print "</td></tr>\n";
5480 print "<tr class=\"dark\">\n";
5482 print "<tr class=\"light\">\n";
5484 print "<td class=\"list\">".
5485 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5486 file_name
=>"$file"),
5487 -class => "list"}, esc_path
($file));
5488 print "</td><td>\n";
5492 print "<div class=\"binary\">Binary file</div>\n";
5494 $ltext = untabify
($ltext);
5495 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5496 $ltext = esc_html
($1, -nbsp
=>1);
5497 $ltext .= '<span class="match">';
5498 $ltext .= esc_html
($2, -nbsp
=>1);
5499 $ltext .= '</span>';
5500 $ltext .= esc_html
($3, -nbsp
=>1);
5502 $ltext = esc_html
($ltext, -nbsp
=>1);
5504 print "<div class=\"pre\">" .
5505 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5506 file_name
=>"$file").'#l'.$lno,
5507 -class => "linenr"}, sprintf('%4i', $lno))
5508 . ' ' . $ltext . "</div>\n";
5512 print "</td></tr>\n";
5513 if ($matches > 1000) {
5514 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5517 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5526 sub git_search_help
{
5528 git_print_page_nav
('','', $hash,$hash,$hash);
5530 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5531 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5532 the pattern entered is recognized as the POSIX extended
5533 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5536 <dt><b>commit</b></dt>
5537 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5539 my ($have_grep) = gitweb_check_feature
('grep');
5542 <dt><b>grep</b></dt>
5543 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5544 a different one) are searched for the given pattern. On large trees, this search can take
5545 a while and put some strain on the server, so please use it with some consideration. Note that
5546 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5547 case-sensitive.</dd>
5551 <dt><b>author</b></dt>
5552 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5553 <dt><b>committer</b></dt>
5554 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5556 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5557 if ($have_pickaxe) {
5559 <dt><b>pickaxe</b></dt>
5560 <dd>All commits that caused the string to appear or disappear from any file (changes that
5561 added, removed or "modified" the string) will be listed. This search can take a while and
5562 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5563 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5571 my $head = git_get_head_hash
($project);
5572 if (!defined $hash) {
5575 if (!defined $page) {
5578 my $refs = git_get_references
();
5580 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5582 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
5584 if ($#commitlist >= 100) {
5586 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5587 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5591 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5592 git_print_header_div
('summary', $project);
5594 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5599 ## ......................................................................
5600 ## feeds (RSS, Atom; OPML)
5603 my $format = shift || 'atom';
5604 my ($have_blame) = gitweb_check_feature
('blame');
5606 # Atom: http://www.atomenabled.org/developers/syndication/
5607 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5608 if ($format ne 'rss' && $format ne 'atom') {
5609 die_error
(undef, "Unknown web feed format");
5612 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5613 my $head = $hash || 'HEAD';
5614 my @commitlist = parse_commits
($head, 150, 0, $file_name);
5618 my $content_type = "application/$format+xml";
5619 if (defined $cgi->http('HTTP_ACCEPT') &&
5620 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5621 # browser (feed reader) prefers text/xml
5622 $content_type = 'text/xml';
5624 if (defined($commitlist[0])) {
5625 %latest_commit = %{$commitlist[0]};
5626 %latest_date = parse_date
($latest_commit{'author_epoch'});
5628 -type
=> $content_type,
5629 -charset
=> 'utf-8',
5630 -last_modified
=> $latest_date{'rfc2822'});
5633 -type
=> $content_type,
5634 -charset
=> 'utf-8');
5637 # Optimization: skip generating the body if client asks only
5638 # for Last-Modified date.
5639 return if ($cgi->request_method() eq 'HEAD');
5642 my $title = "$site_name - $project/$action";
5643 my $feed_type = 'log';
5644 if (defined $hash) {
5645 $title .= " - '$hash'";
5646 $feed_type = 'branch log';
5647 if (defined $file_name) {
5648 $title .= " :: $file_name";
5649 $feed_type = 'history';
5651 } elsif (defined $file_name) {
5652 $title .= " - $file_name";
5653 $feed_type = 'history';
5655 $title .= " $feed_type";
5656 my $descr = git_get_project_description
($project);
5657 if (defined $descr) {
5658 $descr = esc_html
($descr);
5660 $descr = "$project " .
5661 ($format eq 'rss' ?
'RSS' : 'Atom') .
5664 my $owner = git_get_project_owner
($project);
5665 $owner = esc_html
($owner);
5669 if (defined $file_name) {
5670 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5671 } elsif (defined $hash) {
5672 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5674 $alt_url = href
(-full
=>1, action
=>"summary");
5676 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
5677 if ($format eq 'rss') {
5679 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5682 print "<title>$title</title>\n" .
5683 "<link>$alt_url</link>\n" .
5684 "<description>$descr</description>\n" .
5685 "<language>en</language>\n";
5686 } elsif ($format eq 'atom') {
5688 <feed xmlns="http://www.w3.org/2005/Atom">
5690 print "<title>$title</title>\n" .
5691 "<subtitle>$descr</subtitle>\n" .
5692 '<link rel="alternate" type="text/html" href="' .
5693 $alt_url . '" />' . "\n" .
5694 '<link rel="self" type="' . $content_type . '" href="' .
5695 $cgi->self_url() . '" />' . "\n" .
5696 "<id>" . href
(-full
=>1) . "</id>\n" .
5697 # use project owner for feed author
5698 "<author><name>$owner</name></author>\n";
5699 if (defined $favicon) {
5700 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5702 if (defined $logo_url) {
5703 # not twice as wide as tall: 72 x 27 pixels
5704 print "<logo>" . esc_url
($logo) . "</logo>\n";
5706 if (! %latest_date) {
5707 # dummy date to keep the feed valid until commits trickle in:
5708 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5710 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5715 for (my $i = 0; $i <= $#commitlist; $i++) {
5716 my %co = %{$commitlist[$i]};
5717 my $commit = $co{'id'};
5718 # we read 150, we always show 30 and the ones more recent than 48 hours
5719 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5722 my %cd = parse_date
($co{'author_epoch'});
5724 # get list of changed files
5725 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5726 $co{'parent'} || "--root",
5727 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
5729 my @difftree = map { chomp; $_ } <$fd>;
5733 # print element (entry, item)
5734 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
5735 if ($format eq 'rss') {
5737 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5738 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5739 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5740 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5741 "<link>$co_url</link>\n" .
5742 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5743 "<content:encoded>" .
5745 } elsif ($format eq 'atom') {
5747 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5748 "<updated>$cd{'iso-8601'}</updated>\n" .
5750 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5751 if ($co{'author_email'}) {
5752 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5754 print "</author>\n" .
5755 # use committer for contributor
5757 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5758 if ($co{'committer_email'}) {
5759 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5761 print "</contributor>\n" .
5762 "<published>$cd{'iso-8601'}</published>\n" .
5763 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5764 "<id>$co_url</id>\n" .
5765 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5766 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5768 my $comment = $co{'comment'};
5770 foreach my $line (@
$comment) {
5771 $line = esc_html
($line);
5774 print "</pre><ul>\n";
5775 foreach my $difftree_line (@difftree) {
5776 my %difftree = parse_difftree_raw_line
($difftree_line);
5777 next if !$difftree{'from_id'};
5779 my $file = $difftree{'file'} || $difftree{'to_file'};
5783 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5784 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5785 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5786 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5787 -title
=> "diff"}, 'D');
5789 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5790 file_name
=>$file, hash_base
=>$commit),
5791 -title
=> "blame"}, 'B');
5793 # if this is not a feed of a file history
5794 if (!defined $file_name || $file_name ne $file) {
5795 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5796 file_name
=>$file, hash
=>$commit),
5797 -title
=> "history"}, 'H');
5799 $file = esc_path
($file);
5803 if ($format eq 'rss') {
5804 print "</ul>]]>\n" .
5805 "</content:encoded>\n" .
5807 } elsif ($format eq 'atom') {
5808 print "</ul>\n</div>\n" .
5815 if ($format eq 'rss') {
5816 print "</channel>\n</rss>\n";
5817 } elsif ($format eq 'atom') {
5831 my @list = git_get_projects_list
();
5833 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5835 <?xml version="1.0" encoding="utf-8"?>
5836 <opml version="1.0">
5838 <title>$site_name OPML Export</title>
5841 <outline text="git RSS feeds">
5844 foreach my $pr (@list) {
5846 my $head = git_get_head_hash
($proj{'path'});
5847 if (!defined $head) {
5850 $git_dir = "$projectroot/$proj{'path'}";
5851 my %co = parse_commit
($head);
5856 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5857 my $rss = "$my_url?p=$proj{'path'};a=rss";
5858 my $html = "$my_url?p=$proj{'path'};a=summary";
5859 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";