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 "owner") {
3620 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3621 print "<th>Owner</th>\n";
3624 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3625 -class => "header"}, "Owner") .
3628 if ($order eq "age") {
3629 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3630 print "<th>Last Change</th>\n";
3633 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3634 -class => "header"}, "Last Change") .
3637 print "<th></th>\n" .
3641 for (my $i = $from; $i <= $to; $i++) {
3642 my $pr = $projects[$i];
3644 print "<tr class=\"dark\">\n";
3646 print "<tr class=\"light\">\n";
3651 if ($pr->{'forks'}) {
3652 print "<!-- $pr->{'forks'} -->\n";
3653 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3657 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3658 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3659 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3660 -class => "list", -title
=> $pr->{'descr_long'}},
3661 esc_html
($pr->{'descr'})) . "</td>\n" .
3662 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3663 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3664 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
3665 "<td class=\"link\">" .
3666 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3667 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3668 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3669 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3670 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3674 if (defined $extra) {
3677 print "<td></td>\n";
3679 print "<td colspan=\"5\">$extra</td>\n" .
3685 sub git_shortlog_body
{
3686 # uses global variable $project
3687 my ($commitlist, $from, $to, $refs, $extra) = @_;
3689 $from = 0 unless defined $from;
3690 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3692 print "<table class=\"shortlog\">\n";
3694 for (my $i = $from; $i <= $to; $i++) {
3695 my %co = %{$commitlist->[$i]};
3696 my $commit = $co{'id'};
3697 my $ref = format_ref_marker
($refs, $commit);
3699 print "<tr class=\"dark\">\n";
3701 print "<tr class=\"light\">\n";
3704 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3705 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3706 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3707 "<td><i>" . $author . "</i></td>\n" .
3709 print format_subject_html
($co{'title'}, $co{'title_short'},
3710 href
(action
=>"commit", hash
=>$commit), $ref);
3712 "<td class=\"link\">" .
3713 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3714 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3715 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3716 my $snapshot_links = format_snapshot_links
($commit);
3717 if (defined $snapshot_links) {
3718 print " | " . $snapshot_links;
3723 if (defined $extra) {
3725 "<td colspan=\"4\">$extra</td>\n" .
3731 sub git_history_body
{
3732 # Warning: assumes constant type (blob or tree) during history
3733 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3735 $from = 0 unless defined $from;
3736 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3738 print "<table class=\"history\">\n";
3740 for (my $i = $from; $i <= $to; $i++) {
3741 my %co = %{$commitlist->[$i]};
3745 my $commit = $co{'id'};
3747 my $ref = format_ref_marker
($refs, $commit);
3750 print "<tr class=\"dark\">\n";
3752 print "<tr class=\"light\">\n";
3755 # shortlog uses chop_str($co{'author_name'}, 10)
3756 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3757 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3758 "<td><i>" . $author . "</i></td>\n" .
3760 # originally git_history used chop_str($co{'title'}, 50)
3761 print format_subject_html
($co{'title'}, $co{'title_short'},
3762 href
(action
=>"commit", hash
=>$commit), $ref);
3764 "<td class=\"link\">" .
3765 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3766 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3768 if ($ftype eq 'blob') {
3769 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3770 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3771 if (defined $blob_current && defined $blob_parent &&
3772 $blob_current ne $blob_parent) {
3774 $cgi->a({-href
=> href
(action
=>"blobdiff",
3775 hash
=>$blob_current, hash_parent
=>$blob_parent,
3776 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3777 file_name
=>$file_name)},
3784 if (defined $extra) {
3786 "<td colspan=\"4\">$extra</td>\n" .
3793 # uses global variable $project
3794 my ($taglist, $from, $to, $extra) = @_;
3795 $from = 0 unless defined $from;
3796 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3798 print "<table class=\"tags\">\n";
3800 for (my $i = $from; $i <= $to; $i++) {
3801 my $entry = $taglist->[$i];
3803 my $comment = $tag{'subject'};
3805 if (defined $comment) {
3806 $comment_short = chop_str
($comment, 30, 5);
3809 print "<tr class=\"dark\">\n";
3811 print "<tr class=\"light\">\n";
3814 if (defined $tag{'age'}) {
3815 print "<td><i>$tag{'age'}</i></td>\n";
3817 print "<td></td>\n";
3820 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3821 -class => "list name"}, esc_html
($tag{'name'})) .
3824 if (defined $comment) {
3825 print format_subject_html
($comment, $comment_short,
3826 href
(action
=>"tag", hash
=>$tag{'id'}));
3829 "<td class=\"selflink\">";
3830 if ($tag{'type'} eq "tag") {
3831 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3836 "<td class=\"link\">" . " | " .
3837 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3838 if ($tag{'reftype'} eq "commit") {
3839 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
3840 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
3841 } elsif ($tag{'reftype'} eq "blob") {
3842 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3847 if (defined $extra) {
3849 "<td colspan=\"5\">$extra</td>\n" .
3855 sub git_heads_body
{
3856 # uses global variable $project
3857 my ($headlist, $head, $from, $to, $extra) = @_;
3858 $from = 0 unless defined $from;
3859 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3861 print "<table class=\"heads\">\n";
3863 for (my $i = $from; $i <= $to; $i++) {
3864 my $entry = $headlist->[$i];
3866 my $curr = $ref{'id'} eq $head;
3868 print "<tr class=\"dark\">\n";
3870 print "<tr class=\"light\">\n";
3873 print "<td><i>$ref{'age'}</i></td>\n" .
3874 ($curr ?
"<td class=\"current_head\">" : "<td>") .
3875 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
3876 -class => "list name"},esc_html
($ref{'name'})) .
3878 "<td class=\"link\">" .
3879 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
3880 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
3881 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
3885 if (defined $extra) {
3887 "<td colspan=\"3\">$extra</td>\n" .
3893 sub git_search_grep_body
{
3894 my ($commitlist, $from, $to, $extra) = @_;
3895 $from = 0 unless defined $from;
3896 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3898 print "<table class=\"commit_search\">\n";
3900 for (my $i = $from; $i <= $to; $i++) {
3901 my %co = %{$commitlist->[$i]};
3905 my $commit = $co{'id'};
3907 print "<tr class=\"dark\">\n";
3909 print "<tr class=\"light\">\n";
3912 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
3913 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3914 "<td><i>" . $author . "</i></td>\n" .
3916 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3917 -class => "list subject"},
3918 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
3919 my $comment = $co{'comment'};
3920 foreach my $line (@
$comment) {
3921 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
3922 my ($lead, $match, $trail) = ($1, $2, $3);
3923 $match = chop_str
($match, 70, 5, 'center');
3924 my $contextlen = int((80 - length($match))/2);
3925 $contextlen = 30 if ($contextlen > 30);
3926 $lead = chop_str
($lead, $contextlen, 10, 'left');
3927 $trail = chop_str
($trail, $contextlen, 10, 'right');
3929 $lead = esc_html
($lead);
3930 $match = esc_html
($match);
3931 $trail = esc_html
($trail);
3933 print "$lead<span class=\"match\">$match</span>$trail<br />";
3937 "<td class=\"link\">" .
3938 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3940 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
3942 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3946 if (defined $extra) {
3948 "<td colspan=\"3\">$extra</td>\n" .
3954 ## ======================================================================
3955 ## ======================================================================
3958 sub git_project_list
{
3959 my $order = $cgi->param('o');
3960 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3961 die_error
(undef, "Unknown order parameter");
3964 my @list = git_get_projects_list
();
3966 die_error
(undef, "No projects found");
3970 if (-f
$home_text) {
3971 print "<div class=\"index_include\">\n";
3972 open (my $fd, $home_text);
3977 git_project_list_body
(\
@list, $order);
3982 my $order = $cgi->param('o');
3983 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3984 die_error
(undef, "Unknown order parameter");
3987 my @list = git_get_projects_list
($project);
3989 die_error
(undef, "No forks found");
3993 git_print_page_nav
('','');
3994 git_print_header_div
('summary', "$project forks");
3995 git_project_list_body
(\
@list, $order);
3999 sub git_project_index
{
4000 my @projects = git_get_projects_list
($project);
4003 -type
=> 'text/plain',
4004 -charset
=> 'utf-8',
4005 -content_disposition
=> 'inline; filename="index.aux"');
4007 foreach my $pr (@projects) {
4008 if (!exists $pr->{'owner'}) {
4009 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4012 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4013 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4014 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4015 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4019 print "$path $owner\n";
4024 my $descr = git_get_project_description
($project) || "none";
4025 my %co = parse_commit
("HEAD");
4026 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4027 my $head = $co{'id'};
4029 my $owner = git_get_project_owner
($project);
4031 my $refs = git_get_references
();
4032 # These get_*_list functions return one more to allow us to see if
4033 # there are more ...
4034 my @taglist = git_get_tags_list
(16);
4035 my @headlist = git_get_heads_list
(16);
4037 my ($check_forks) = gitweb_check_feature
('forks');
4040 @forklist = git_get_projects_list
($project);
4044 git_print_page_nav
('summary','', $head);
4046 print "<div class=\"title\"> </div>\n";
4047 print "<table class=\"projects_list\">\n" .
4048 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4049 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4050 if (defined $cd{'rfc2822'}) {
4051 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4054 # use per project git URL list in $projectroot/$project/cloneurl
4055 # or make project git URL from git base URL and project name
4056 my $url_tag = "URL";
4057 my @url_list = git_get_project_url_list
($project);
4058 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4059 foreach my $git_url (@url_list) {
4060 next unless $git_url;
4061 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
4066 if (-s
"$projectroot/$project/README.html") {
4067 if (open my $fd, "$projectroot/$project/README.html") {
4068 print "<div class=\"title\">readme</div>\n" .
4069 "<div class=\"readme\">\n";
4070 print $_ while (<$fd>);
4071 print "\n</div>\n"; # class="readme"
4076 # we need to request one more than 16 (0..15) to check if
4078 my @commitlist = $head ? parse_commits
($head, 17) : ();
4080 git_print_header_div
('shortlog');
4081 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4082 $#commitlist <= 15 ?
undef :
4083 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4087 git_print_header_div
('tags');
4088 git_tags_body
(\
@taglist, 0, 15,
4089 $#taglist <= 15 ?
undef :
4090 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4094 git_print_header_div
('heads');
4095 git_heads_body
(\
@headlist, $head, 0, 15,
4096 $#headlist <= 15 ?
undef :
4097 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4101 git_print_header_div
('forks');
4102 git_project_list_body
(\
@forklist, undef, 0, 15,
4103 $#forklist <= 15 ?
undef :
4104 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4112 my $head = git_get_head_hash
($project);
4114 git_print_page_nav
('','', $head,undef,$head);
4115 my %tag = parse_tag
($hash);
4118 die_error
(undef, "Unknown tag object");
4121 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4122 print "<div class=\"title_text\">\n" .
4123 "<table class=\"object_header\">\n" .
4125 "<td>object</td>\n" .
4126 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4127 $tag{'object'}) . "</td>\n" .
4128 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4129 $tag{'type'}) . "</td>\n" .
4131 if (defined($tag{'author'})) {
4132 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4133 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4134 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4135 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4138 print "</table>\n\n" .
4140 print "<div class=\"page_body\">";
4141 my $comment = $tag{'comment'};
4142 foreach my $line (@
$comment) {
4144 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4154 my ($have_blame) = gitweb_check_feature
('blame');
4156 die_error
('403 Permission denied', "Permission denied");
4158 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4159 $hash_base ||= git_get_head_hash
($project);
4160 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4161 my %co = parse_commit
($hash_base)
4162 or die_error
(undef, "Reading commit failed");
4163 if (!defined $hash) {
4164 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4165 or die_error
(undef, "Error looking up file");
4167 $ftype = git_get_type
($hash);
4168 if ($ftype !~ "blob") {
4169 die_error
('400 Bad Request', "Object is not a blob");
4171 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4172 $file_name, $hash_base)
4173 or die_error
(undef, "Open git-blame failed");
4176 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4179 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4182 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4184 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4185 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4186 git_print_page_path
($file_name, $ftype, $hash_base);
4187 my @rev_color = (qw(light2 dark2));
4188 my $num_colors = scalar(@rev_color);
4189 my $current_color = 0;
4192 <div class="page_body">
4193 <table class="blame">
4194 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4199 last unless defined $_;
4200 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4201 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4202 if (!exists $metainfo{$full_rev}) {
4203 $metainfo{$full_rev} = {};
4205 my $meta = $metainfo{$full_rev};
4208 if (/^(\S+) (.*)$/) {
4214 my $rev = substr($full_rev, 0, 8);
4215 my $author = $meta->{'author'};
4216 my %date = parse_date
($meta->{'author-time'},
4217 $meta->{'author-tz'});
4218 my $date = $date{'iso-tz'};
4220 $current_color = ++$current_color % $num_colors;
4222 print "<tr class=\"$rev_color[$current_color]\">\n";
4224 print "<td class=\"sha1\"";
4225 print " title=\"". esc_html
($author) . ", $date\"";
4226 print " rowspan=\"$group_size\"" if ($group_size > 1);
4228 print $cgi->a({-href
=> href
(action
=>"commit",
4230 file_name
=>$file_name)},
4234 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4235 or die_error
(undef, "Open git-rev-parse failed");
4236 my $parent_commit = <$dd>;
4238 chomp($parent_commit);
4239 my $blamed = href
(action
=> 'blame',
4240 file_name
=> $meta->{'filename'},
4241 hash_base
=> $parent_commit);
4242 print "<td class=\"linenr\">";
4243 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4245 -class => "linenr" },
4248 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4254 or print "Reading blob failed\n";
4261 my ($have_blame) = gitweb_check_feature
('blame');
4263 die_error
('403 Permission denied', "Permission denied");
4265 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4266 $hash_base ||= git_get_head_hash
($project);
4267 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4268 my %co = parse_commit
($hash_base)
4269 or die_error
(undef, "Reading commit failed");
4270 if (!defined $hash) {
4271 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4272 or die_error
(undef, "Error lookup file");
4274 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
4275 or die_error
(undef, "Open git-annotate failed");
4278 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4281 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4284 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4286 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4287 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4288 git_print_page_path
($file_name, 'blob', $hash_base);
4289 print "<div class=\"page_body\">\n";
4291 <table class="blame">
4300 my @line_class = (qw(light dark));
4301 my $line_class_len = scalar (@line_class);
4302 my $line_class_num = $#line_class;
4303 while (my $line = <$fd>) {
4315 $line_class_num = ($line_class_num + 1) % $line_class_len;
4317 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4324 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
4327 $short_rev = substr ($long_rev, 0, 8);
4328 $age = time () - $time;
4329 $age_str = age_string
($age);
4330 $age_str =~ s/ / /g;
4331 $age_class = age_class
($age);
4332 $author = esc_html
($author);
4333 $author =~ s/ / /g;
4335 $data = untabify
($data);
4336 $data = esc_html
($data);
4339 <tr class="$line_class[$line_class_num]">
4340 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4341 <td class="$age_class">$age_str</td>
4343 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4344 <td class="pre">$data</td>
4347 } # while (my $line = <$fd>)
4348 print "</table>\n\n";
4350 or print "Reading blob failed.\n";
4356 my $head = git_get_head_hash
($project);
4358 git_print_page_nav
('','', $head,undef,$head);
4359 git_print_header_div
('summary', $project);
4361 my @tagslist = git_get_tags_list
();
4363 git_tags_body
(\
@tagslist);
4369 my $head = git_get_head_hash
($project);
4371 git_print_page_nav
('','', $head,undef,$head);
4372 git_print_header_div
('summary', $project);
4374 my @headslist = git_get_heads_list
();
4376 git_heads_body
(\
@headslist, $head);
4381 sub git_blob_plain
{
4385 if (!defined $hash) {
4386 if (defined $file_name) {
4387 my $base = $hash_base || git_get_head_hash
($project);
4388 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4389 or die_error
(undef, "Error lookup file");
4391 die_error
(undef, "No file name defined");
4393 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4394 # blobs defined by non-textual hash id's can be cached
4398 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4399 or die_error
(undef, "Open git-cat-file blob '$hash' failed");
4401 # content-type (can include charset)
4402 $type = blob_contenttype
($fd, $file_name, $type);
4404 # "save as" filename, even when no $file_name is given
4405 my $save_as = "$hash";
4406 if (defined $file_name) {
4407 $save_as = $file_name;
4408 } elsif ($type =~ m/^text\//) {
4414 -expires
=> $expires,
4415 -content_disposition
=> 'inline; filename="' . $save_as . '"');
4417 binmode STDOUT
, ':raw';
4419 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4427 if (!defined $hash) {
4428 if (defined $file_name) {
4429 my $base = $hash_base || git_get_head_hash
($project);
4430 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4431 or die_error
(undef, "Error lookup file");
4433 die_error
(undef, "No file name defined");
4435 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4436 # blobs defined by non-textual hash id's can be cached
4440 my ($have_blame) = gitweb_check_feature
('blame');
4441 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4442 or die_error
(undef, "Couldn't cat $file_name, $hash");
4443 my $mimetype = blob_mimetype
($fd, $file_name);
4444 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4446 return git_blob_plain
($mimetype);
4448 # we can have blame only for text/* mimetype
4449 $have_blame &&= ($mimetype =~ m!^text/!);
4451 git_header_html
(undef, $expires);
4452 my $formats_nav = '';
4453 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4454 if (defined $file_name) {
4457 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4462 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4465 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4468 $cgi->a({-href
=> href
(action
=>"blob",
4469 hash_base
=>"HEAD", file_name
=>$file_name)},
4473 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4476 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4477 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4479 print "<div class=\"page_nav\">\n" .
4480 "<br/><br/></div>\n" .
4481 "<div class=\"title\">$hash</div>\n";
4483 git_print_page_path
($file_name, "blob", $hash_base);
4484 print "<div class=\"page_body\">\n";
4485 if ($mimetype =~ m!^image/!) {
4486 print qq!<img type
="$mimetype"!;
4488 print qq! alt
="$file_name" title
="$file_name"!;
4491 href(action=>"blob_plain
", hash=>$hash,
4492 hash_base=>$hash_base, file_name=>$file_name) .
4496 while (my $line = <$fd>) {
4499 $line = untabify
($line);
4500 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4501 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4505 or print "Reading blob failed.\n";
4511 if (!defined $hash_base) {
4512 $hash_base = "HEAD";
4514 if (!defined $hash) {
4515 if (defined $file_name) {
4516 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4522 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4523 or die_error
(undef, "Open git-ls-tree failed");
4524 my @entries = map { chomp; $_ } <$fd>;
4525 close $fd or die_error
(undef, "Reading tree failed");
4528 my $refs = git_get_references
();
4529 my $ref = format_ref_marker
($refs, $hash_base);
4532 my ($have_blame) = gitweb_check_feature
('blame');
4533 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4535 if (defined $file_name) {
4537 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4539 $cgi->a({-href
=> href
(action
=>"tree",
4540 hash_base
=>"HEAD", file_name
=>$file_name)},
4543 my $snapshot_links = format_snapshot_links
($hash);
4544 if (defined $snapshot_links) {
4545 # FIXME: Should be available when we have no hash base as well.
4546 push @views_nav, $snapshot_links;
4548 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4549 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4552 print "<div class=\"page_nav\">\n";
4553 print "<br/><br/></div>\n";
4554 print "<div class=\"title\">$hash</div>\n";
4556 if (defined $file_name) {
4557 $basedir = $file_name;
4558 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4562 git_print_page_path
($file_name, 'tree', $hash_base);
4563 print "<div class=\"page_body\">\n";
4564 print "<table class=\"tree\">\n";
4566 # '..' (top directory) link if possible
4567 if (defined $hash_base &&
4568 defined $file_name && $file_name =~ m![^/]+$!) {
4570 print "<tr class=\"dark\">\n";
4572 print "<tr class=\"light\">\n";
4576 my $up = $file_name;
4577 $up =~ s!/?[^/]+$!!;
4578 undef $up unless $up;
4579 # based on git_print_tree_entry
4580 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4581 print '<td class="list">';
4582 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4586 print "<td class=\"link\"></td>\n";
4590 foreach my $line (@entries) {
4591 my %t = parse_ls_tree_line
($line, -z
=> 1);
4594 print "<tr class=\"dark\">\n";
4596 print "<tr class=\"light\">\n";
4600 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4604 print "</table>\n" .
4610 my @supported_fmts = gitweb_check_feature
('snapshot');
4611 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4613 my $format = $cgi->param('sf');
4614 if (!@supported_fmts) {
4615 die_error
('403 Permission denied', "Permission denied");
4617 # default to first supported snapshot format
4618 $format ||= $supported_fmts[0];
4619 if ($format !~ m/^[a-z0-9]+$/) {
4620 die_error
(undef, "Invalid snapshot format parameter");
4621 } elsif (!exists($known_snapshot_formats{$format})) {
4622 die_error
(undef, "Unknown snapshot format");
4623 } elsif (!grep($_ eq $format, @supported_fmts)) {
4624 die_error
(undef, "Unsupported snapshot format");
4627 if (!defined $hash) {
4628 $hash = git_get_head_hash
($project);
4631 my $name = $project;
4632 $name =~ s
,([^/])/*\
.git
$,$1,;
4633 $name = basename
($name);
4634 my $filename = to_utf8
($name);
4635 $name =~ s/\047/\047\\\047\047/g;
4637 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4638 $cmd = quote_command
(
4639 git_cmd
(), 'archive',
4640 "--format=$known_snapshot_formats{$format}{'format'}",
4641 "--prefix=$name/", $hash);
4642 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4643 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
4647 -type
=> $known_snapshot_formats{$format}{'type'},
4648 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4649 -status
=> '200 OK');
4651 open my $fd, "-|", $cmd
4652 or die_error
(undef, "Execute git-archive failed");
4653 binmode STDOUT
, ':raw';
4655 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4660 my $head = git_get_head_hash
($project);
4661 if (!defined $hash) {
4664 if (!defined $page) {
4667 my $refs = git_get_references
();
4669 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4671 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
4674 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4677 my %co = parse_commit
($hash);
4679 git_print_header_div
('summary', $project);
4680 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4682 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
4683 for (my $i = 0; $i <= $to; $i++) {
4684 my %co = %{$commitlist[$i]};
4686 my $commit = $co{'id'};
4687 my $ref = format_ref_marker
($refs, $commit);
4688 my %ad = parse_date
($co{'author_epoch'});
4689 git_print_header_div
('commit',
4690 "<span class=\"age\">$co{'age_string'}</span>" .
4691 esc_html
($co{'title'}) . $ref,
4693 print "<div class=\"title_text\">\n" .
4694 "<div class=\"log_link\">\n" .
4695 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4697 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4699 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4702 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4705 print "<div class=\"log_body\">\n";
4706 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4709 if ($#commitlist >= 100) {
4710 print "<div class=\"page_nav\">\n";
4711 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4712 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4719 $hash ||= $hash_base || "HEAD";
4720 my %co = parse_commit
($hash);
4722 die_error
(undef, "Unknown commit object");
4724 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4725 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4727 my $parent = $co{'parent'};
4728 my $parents = $co{'parents'}; # listref
4730 # we need to prepare $formats_nav before any parameter munging
4732 if (!defined $parent) {
4734 $formats_nav .= '(initial)';
4735 } elsif (@
$parents == 1) {
4736 # single parent commit
4739 $cgi->a({-href
=> href
(action
=>"commit",
4741 esc_html
(substr($parent, 0, 7))) .
4748 $cgi->a({-href
=> href
(action
=>"commit",
4750 esc_html
(substr($_, 0, 7)));
4755 if (!defined $parent) {
4759 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4761 (@
$parents <= 1 ?
$parent : '-c'),
4763 or die_error
(undef, "Open git-diff-tree failed");
4764 @difftree = map { chomp; $_ } <$fd>;
4765 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4767 # non-textual hash id's can be cached
4769 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4772 my $refs = git_get_references
();
4773 my $ref = format_ref_marker
($refs, $co{'id'});
4775 git_header_html
(undef, $expires);
4776 git_print_page_nav
('commit', '',
4777 $hash, $co{'tree'}, $hash,
4780 if (defined $co{'parent'}) {
4781 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4783 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4785 print "<div class=\"title_text\">\n" .
4786 "<table class=\"object_header\">\n";
4787 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4789 "<td></td><td> $ad{'rfc2822'}";
4790 if ($ad{'hour_local'} < 6) {
4791 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4792 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4794 printf(" (%02d:%02d %s)",
4795 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4799 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4800 print "<tr><td></td><td> $cd{'rfc2822'}" .
4801 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4803 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4806 "<td class=\"sha1\">" .
4807 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4808 class => "list"}, $co{'tree'}) .
4810 "<td class=\"link\">" .
4811 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4813 my $snapshot_links = format_snapshot_links
($hash);
4814 if (defined $snapshot_links) {
4815 print " | " . $snapshot_links;
4820 foreach my $par (@
$parents) {
4823 "<td class=\"sha1\">" .
4824 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4825 class => "list"}, $par) .
4827 "<td class=\"link\">" .
4828 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4830 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4837 print "<div class=\"page_body\">\n";
4838 git_print_log
($co{'comment'});
4841 git_difftree_body
(\
@difftree, $hash, @
$parents);
4847 # object is defined by:
4848 # - hash or hash_base alone
4849 # - hash_base and file_name
4852 # - hash or hash_base alone
4853 if ($hash || ($hash_base && !defined $file_name)) {
4854 my $object_id = $hash || $hash_base;
4856 open my $fd, "-|", quote_command
(
4857 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
4858 or die_error
('404 Not Found', "Object does not exist");
4862 or die_error
('404 Not Found', "Object does not exist");
4864 # - hash_base and file_name
4865 } elsif ($hash_base && defined $file_name) {
4866 $file_name =~ s
,/+$,,;
4868 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4869 or die_error
('404 Not Found', "Base object does not exist");
4871 # here errors should not hapen
4872 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4873 or die_error
(undef, "Open git-ls-tree failed");
4877 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4878 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4879 die_error
('404 Not Found', "File or directory for given base does not exist");
4884 die_error
('404 Not Found', "Not enough information to find object");
4887 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4888 hash
=>$hash, hash_base
=>$hash_base,
4889 file_name
=>$file_name),
4890 -status
=> '302 Found');
4894 my $format = shift || 'html';
4901 # preparing $fd and %diffinfo for git_patchset_body
4903 if (defined $hash_base && defined $hash_parent_base) {
4904 if (defined $file_name) {
4906 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4907 $hash_parent_base, $hash_base,
4908 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4909 or die_error
(undef, "Open git-diff-tree failed");
4910 @difftree = map { chomp; $_ } <$fd>;
4912 or die_error
(undef, "Reading git-diff-tree failed");
4914 or die_error
('404 Not Found', "Blob diff not found");
4916 } elsif (defined $hash &&
4917 $hash =~ /[0-9a-fA-F]{40}/) {
4918 # try to find filename from $hash
4920 # read filtered raw output
4921 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4922 $hash_parent_base, $hash_base, "--"
4923 or die_error
(undef, "Open git-diff-tree failed");
4925 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4927 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4928 map { chomp; $_ } <$fd>;
4930 or die_error
(undef, "Reading git-diff-tree failed");
4932 or die_error
('404 Not Found', "Blob diff not found");
4935 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4938 if (@difftree > 1) {
4939 die_error
('404 Not Found', "Ambiguous blob diff specification");
4942 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4943 $file_parent ||= $diffinfo{'from_file'} || $file_name;
4944 $file_name ||= $diffinfo{'to_file'};
4946 $hash_parent ||= $diffinfo{'from_id'};
4947 $hash ||= $diffinfo{'to_id'};
4949 # non-textual hash id's can be cached
4950 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4951 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4956 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4957 '-p', ($format eq 'html' ?
"--full-index" : ()),
4958 $hash_parent_base, $hash_base,
4959 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4960 or die_error
(undef, "Open git-diff-tree failed");
4963 # old/legacy style URI
4964 if (!%diffinfo && # if new style URI failed
4965 defined $hash && defined $hash_parent) {
4966 # fake git-diff-tree raw output
4967 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4968 $diffinfo{'from_id'} = $hash_parent;
4969 $diffinfo{'to_id'} = $hash;
4970 if (defined $file_name) {
4971 if (defined $file_parent) {
4972 $diffinfo{'status'} = '2';
4973 $diffinfo{'from_file'} = $file_parent;
4974 $diffinfo{'to_file'} = $file_name;
4975 } else { # assume not renamed
4976 $diffinfo{'status'} = '1';
4977 $diffinfo{'from_file'} = $file_name;
4978 $diffinfo{'to_file'} = $file_name;
4980 } else { # no filename given
4981 $diffinfo{'status'} = '2';
4982 $diffinfo{'from_file'} = $hash_parent;
4983 $diffinfo{'to_file'} = $hash;
4986 # non-textual hash id's can be cached
4987 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4988 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4993 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4994 '-p', ($format eq 'html' ?
"--full-index" : ()),
4995 $hash_parent, $hash, "--"
4996 or die_error
(undef, "Open git-diff failed");
4998 die_error
('404 Not Found', "Missing one of the blob diff parameters")
5003 if ($format eq 'html') {
5005 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5007 git_header_html
(undef, $expires);
5008 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5009 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5010 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5012 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5013 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5015 if (defined $file_name) {
5016 git_print_page_path
($file_name, "blob", $hash_base);
5018 print "<div class=\"page_path\"></div>\n";
5021 } elsif ($format eq 'plain') {
5023 -type
=> 'text/plain',
5024 -charset
=> 'utf-8',
5025 -expires
=> $expires,
5026 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5028 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5031 die_error
(undef, "Unknown blobdiff format");
5035 if ($format eq 'html') {
5036 print "<div class=\"page_body\">\n";
5038 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5041 print "</div>\n"; # class="page_body"
5045 while (my $line = <$fd>) {
5046 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5047 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5051 last if $line =~ m!^\+\+\+!;
5059 sub git_blobdiff_plain
{
5060 git_blobdiff
('plain');
5063 sub git_commitdiff
{
5064 my $format = shift || 'html';
5065 $hash ||= $hash_base || "HEAD";
5066 my %co = parse_commit
($hash);
5068 die_error
(undef, "Unknown commit object");
5071 # choose format for commitdiff for merge
5072 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
5073 $hash_parent = '--cc';
5075 # we need to prepare $formats_nav before almost any parameter munging
5077 if ($format eq 'html') {
5079 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5082 if (defined $hash_parent &&
5083 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5084 # commitdiff with two commits given
5085 my $hash_parent_short = $hash_parent;
5086 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5087 $hash_parent_short = substr($hash_parent, 0, 7);
5091 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
5092 if ($co{'parents'}[$i] eq $hash_parent) {
5093 $formats_nav .= ' parent ' . ($i+1);
5097 $formats_nav .= ': ' .
5098 $cgi->a({-href
=> href
(action
=>"commitdiff",
5099 hash
=>$hash_parent)},
5100 esc_html
($hash_parent_short)) .
5102 } elsif (!$co{'parent'}) {
5104 $formats_nav .= ' (initial)';
5105 } elsif (scalar @
{$co{'parents'}} == 1) {
5106 # single parent commit
5109 $cgi->a({-href
=> href
(action
=>"commitdiff",
5110 hash
=>$co{'parent'})},
5111 esc_html
(substr($co{'parent'}, 0, 7))) .
5115 if ($hash_parent eq '--cc') {
5116 $formats_nav .= ' | ' .
5117 $cgi->a({-href
=> href
(action
=>"commitdiff",
5118 hash
=>$hash, hash_parent
=>'-c')},
5120 } else { # $hash_parent eq '-c'
5121 $formats_nav .= ' | ' .
5122 $cgi->a({-href
=> href
(action
=>"commitdiff",
5123 hash
=>$hash, hash_parent
=>'--cc')},
5129 $cgi->a({-href
=> href
(action
=>"commitdiff",
5131 esc_html
(substr($_, 0, 7)));
5132 } @
{$co{'parents'}} ) .
5137 my $hash_parent_param = $hash_parent;
5138 if (!defined $hash_parent_param) {
5139 # --cc for multiple parents, --root for parentless
5140 $hash_parent_param =
5141 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
5147 if ($format eq 'html') {
5148 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5149 "--no-commit-id", "--patch-with-raw", "--full-index",
5150 $hash_parent_param, $hash, "--"
5151 or die_error
(undef, "Open git-diff-tree failed");
5153 while (my $line = <$fd>) {
5155 # empty line ends raw part of diff-tree output
5157 push @difftree, scalar parse_difftree_raw_line
($line);
5160 } elsif ($format eq 'plain') {
5161 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5162 '-p', $hash_parent_param, $hash, "--"
5163 or die_error
(undef, "Open git-diff-tree failed");
5166 die_error
(undef, "Unknown commitdiff format");
5169 # non-textual hash id's can be cached
5171 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5175 # write commit message
5176 if ($format eq 'html') {
5177 my $refs = git_get_references
();
5178 my $ref = format_ref_marker
($refs, $co{'id'});
5180 git_header_html
(undef, $expires);
5181 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5182 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5183 git_print_authorship
(\
%co);
5184 print "<div class=\"page_body\">\n";
5185 if (@
{$co{'comment'}} > 1) {
5186 print "<div class=\"log\">\n";
5187 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5188 print "</div>\n"; # class="log"
5191 } elsif ($format eq 'plain') {
5192 my $refs = git_get_references
("tags");
5193 my $tagname = git_get_rev_name_tags
($hash);
5194 my $filename = basename
($project) . "-$hash.patch";
5197 -type
=> 'text/plain',
5198 -charset
=> 'utf-8',
5199 -expires
=> $expires,
5200 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5201 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5202 print "From: " . to_utf8
($co{'author'}) . "\n";
5203 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5204 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5206 print "X-Git-Tag: $tagname\n" if $tagname;
5207 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5209 foreach my $line (@
{$co{'comment'}}) {
5210 print to_utf8
($line) . "\n";
5216 if ($format eq 'html') {
5217 my $use_parents = !defined $hash_parent ||
5218 $hash_parent eq '-c' || $hash_parent eq '--cc';
5219 git_difftree_body
(\
@difftree, $hash,
5220 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5223 git_patchset_body
($fd, \
@difftree, $hash,
5224 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5226 print "</div>\n"; # class="page_body"
5229 } elsif ($format eq 'plain') {
5233 or print "Reading git-diff-tree failed\n";
5237 sub git_commitdiff_plain
{
5238 git_commitdiff
('plain');
5242 if (!defined $hash_base) {
5243 $hash_base = git_get_head_hash
($project);
5245 if (!defined $page) {
5249 my %co = parse_commit
($hash_base);
5251 die_error
(undef, "Unknown commit object");
5254 my $refs = git_get_references
();
5255 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5257 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5258 $file_name, "--full-history");
5260 die_error
('404 Not Found', "No such file or directory on given branch");
5263 if (!defined $hash && defined $file_name) {
5264 # some commits could have deleted file in question,
5265 # and not have it in tree, but one of them has to have it
5266 for (my $i = 0; $i <= @commitlist; $i++) {
5267 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5268 last if defined $hash;
5271 if (defined $hash) {
5272 $ftype = git_get_type
($hash);
5274 if (!defined $ftype) {
5275 die_error
(undef, "Unknown type of object");
5278 my $paging_nav = '';
5281 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5282 file_name
=>$file_name)},
5284 $paging_nav .= " ⋅ " .
5285 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5286 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5288 $paging_nav .= "first";
5289 $paging_nav .= " ⋅ prev";
5292 if ($#commitlist >= 100) {
5294 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5295 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5296 $paging_nav .= " ⋅ $next_link";
5298 $paging_nav .= " ⋅ next";
5302 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5303 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5304 git_print_page_path
($file_name, $ftype, $hash_base);
5306 git_history_body
(\
@commitlist, 0, 99,
5307 $refs, $hash_base, $ftype, $next_link);
5313 my ($have_search) = gitweb_check_feature
('search');
5314 if (!$have_search) {
5315 die_error
('403 Permission denied', "Permission denied");
5317 if (!defined $searchtext) {
5318 die_error
(undef, "Text field empty");
5320 if (!defined $hash) {
5321 $hash = git_get_head_hash
($project);
5323 my %co = parse_commit
($hash);
5325 die_error
(undef, "Unknown commit object");
5327 if (!defined $page) {
5331 $searchtype ||= 'commit';
5332 if ($searchtype eq 'pickaxe') {
5333 # pickaxe may take all resources of your box and run for several minutes
5334 # with every query - so decide by yourself how public you make this feature
5335 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5336 if (!$have_pickaxe) {
5337 die_error
('403 Permission denied', "Permission denied");
5340 if ($searchtype eq 'grep') {
5341 my ($have_grep) = gitweb_check_feature
('grep');
5343 die_error
('403 Permission denied', "Permission denied");
5349 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5351 if ($searchtype eq 'commit') {
5352 $greptype = "--grep=";
5353 } elsif ($searchtype eq 'author') {
5354 $greptype = "--author=";
5355 } elsif ($searchtype eq 'committer') {
5356 $greptype = "--committer=";
5358 $greptype .= $searchtext;
5359 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5360 $greptype, '--regexp-ignore-case',
5361 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
5363 my $paging_nav = '';
5366 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5367 searchtext
=>$searchtext,
5368 searchtype
=>$searchtype)},
5370 $paging_nav .= " ⋅ " .
5371 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5372 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5374 $paging_nav .= "first";
5375 $paging_nav .= " ⋅ prev";
5378 if ($#commitlist >= 100) {
5380 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5381 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5382 $paging_nav .= " ⋅ $next_link";
5384 $paging_nav .= " ⋅ next";
5387 if ($#commitlist >= 100) {
5390 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5391 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5392 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5395 if ($searchtype eq 'pickaxe') {
5396 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5397 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5399 print "<table class=\"pickaxe search\">\n";
5402 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5403 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5404 ($search_use_regexp ?
'--pickaxe-regex' : ());
5407 while (my $line = <$fd>) {
5411 my %set = parse_difftree_raw_line
($line);
5412 if (defined $set{'commit'}) {
5413 # finish previous commit
5416 "<td class=\"link\">" .
5417 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5419 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5425 print "<tr class=\"dark\">\n";
5427 print "<tr class=\"light\">\n";
5430 %co = parse_commit
($set{'commit'});
5431 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5432 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5433 "<td><i>$author</i></td>\n" .
5435 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5436 -class => "list subject"},
5437 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5438 } elsif (defined $set{'to_id'}) {
5439 next if ($set{'to_id'} =~ m/^0{40}$/);
5441 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5442 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5444 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5450 # finish last commit (warning: repetition!)
5453 "<td class=\"link\">" .
5454 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5456 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5464 if ($searchtype eq 'grep') {
5465 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5466 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5468 print "<table class=\"grep_search\">\n";
5472 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5473 $search_use_regexp ?
('-E', '-i') : '-F',
5474 $searchtext, $co{'tree'};
5476 while (my $line = <$fd>) {
5478 my ($file, $lno, $ltext, $binary);
5479 last if ($matches++ > 1000);
5480 if ($line =~ /^Binary file (.+) matches$/) {
5484 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5486 if ($file ne $lastfile) {
5487 $lastfile and print "</td></tr>\n";
5489 print "<tr class=\"dark\">\n";
5491 print "<tr class=\"light\">\n";
5493 print "<td class=\"list\">".
5494 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5495 file_name
=>"$file"),
5496 -class => "list"}, esc_path
($file));
5497 print "</td><td>\n";
5501 print "<div class=\"binary\">Binary file</div>\n";
5503 $ltext = untabify
($ltext);
5504 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5505 $ltext = esc_html
($1, -nbsp
=>1);
5506 $ltext .= '<span class="match">';
5507 $ltext .= esc_html
($2, -nbsp
=>1);
5508 $ltext .= '</span>';
5509 $ltext .= esc_html
($3, -nbsp
=>1);
5511 $ltext = esc_html
($ltext, -nbsp
=>1);
5513 print "<div class=\"pre\">" .
5514 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5515 file_name
=>"$file").'#l'.$lno,
5516 -class => "linenr"}, sprintf('%4i', $lno))
5517 . ' ' . $ltext . "</div>\n";
5521 print "</td></tr>\n";
5522 if ($matches > 1000) {
5523 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5526 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5535 sub git_search_help
{
5537 git_print_page_nav
('','', $hash,$hash,$hash);
5539 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5540 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5541 the pattern entered is recognized as the POSIX extended
5542 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5545 <dt><b>commit</b></dt>
5546 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5548 my ($have_grep) = gitweb_check_feature
('grep');
5551 <dt><b>grep</b></dt>
5552 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5553 a different one) are searched for the given pattern. On large trees, this search can take
5554 a while and put some strain on the server, so please use it with some consideration. Note that
5555 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5556 case-sensitive.</dd>
5560 <dt><b>author</b></dt>
5561 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5562 <dt><b>committer</b></dt>
5563 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5565 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5566 if ($have_pickaxe) {
5568 <dt><b>pickaxe</b></dt>
5569 <dd>All commits that caused the string to appear or disappear from any file (changes that
5570 added, removed or "modified" the string) will be listed. This search can take a while and
5571 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5572 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5580 my $head = git_get_head_hash
($project);
5581 if (!defined $hash) {
5584 if (!defined $page) {
5587 my $refs = git_get_references
();
5589 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5591 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
5593 if ($#commitlist >= 100) {
5595 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5596 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5600 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5601 git_print_header_div
('summary', $project);
5603 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5608 ## ......................................................................
5609 ## feeds (RSS, Atom; OPML)
5612 my $format = shift || 'atom';
5613 my ($have_blame) = gitweb_check_feature
('blame');
5615 # Atom: http://www.atomenabled.org/developers/syndication/
5616 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5617 if ($format ne 'rss' && $format ne 'atom') {
5618 die_error
(undef, "Unknown web feed format");
5621 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5622 my $head = $hash || 'HEAD';
5623 my @commitlist = parse_commits
($head, 150, 0, $file_name);
5627 my $content_type = "application/$format+xml";
5628 if (defined $cgi->http('HTTP_ACCEPT') &&
5629 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5630 # browser (feed reader) prefers text/xml
5631 $content_type = 'text/xml';
5633 if (defined($commitlist[0])) {
5634 %latest_commit = %{$commitlist[0]};
5635 %latest_date = parse_date
($latest_commit{'author_epoch'});
5637 -type
=> $content_type,
5638 -charset
=> 'utf-8',
5639 -last_modified
=> $latest_date{'rfc2822'});
5642 -type
=> $content_type,
5643 -charset
=> 'utf-8');
5646 # Optimization: skip generating the body if client asks only
5647 # for Last-Modified date.
5648 return if ($cgi->request_method() eq 'HEAD');
5651 my $title = "$site_name - $project/$action";
5652 my $feed_type = 'log';
5653 if (defined $hash) {
5654 $title .= " - '$hash'";
5655 $feed_type = 'branch log';
5656 if (defined $file_name) {
5657 $title .= " :: $file_name";
5658 $feed_type = 'history';
5660 } elsif (defined $file_name) {
5661 $title .= " - $file_name";
5662 $feed_type = 'history';
5664 $title .= " $feed_type";
5665 my $descr = git_get_project_description
($project);
5666 if (defined $descr) {
5667 $descr = esc_html
($descr);
5669 $descr = "$project " .
5670 ($format eq 'rss' ?
'RSS' : 'Atom') .
5673 my $owner = git_get_project_owner
($project);
5674 $owner = esc_html
($owner);
5678 if (defined $file_name) {
5679 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5680 } elsif (defined $hash) {
5681 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5683 $alt_url = href
(-full
=>1, action
=>"summary");
5685 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
5686 if ($format eq 'rss') {
5688 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5691 print "<title>$title</title>\n" .
5692 "<link>$alt_url</link>\n" .
5693 "<description>$descr</description>\n" .
5694 "<language>en</language>\n";
5695 } elsif ($format eq 'atom') {
5697 <feed xmlns="http://www.w3.org/2005/Atom">
5699 print "<title>$title</title>\n" .
5700 "<subtitle>$descr</subtitle>\n" .
5701 '<link rel="alternate" type="text/html" href="' .
5702 $alt_url . '" />' . "\n" .
5703 '<link rel="self" type="' . $content_type . '" href="' .
5704 $cgi->self_url() . '" />' . "\n" .
5705 "<id>" . href
(-full
=>1) . "</id>\n" .
5706 # use project owner for feed author
5707 "<author><name>$owner</name></author>\n";
5708 if (defined $favicon) {
5709 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5711 if (defined $logo_url) {
5712 # not twice as wide as tall: 72 x 27 pixels
5713 print "<logo>" . esc_url
($logo) . "</logo>\n";
5715 if (! %latest_date) {
5716 # dummy date to keep the feed valid until commits trickle in:
5717 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5719 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5724 for (my $i = 0; $i <= $#commitlist; $i++) {
5725 my %co = %{$commitlist[$i]};
5726 my $commit = $co{'id'};
5727 # we read 150, we always show 30 and the ones more recent than 48 hours
5728 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5731 my %cd = parse_date
($co{'author_epoch'});
5733 # get list of changed files
5734 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5735 $co{'parent'} || "--root",
5736 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
5738 my @difftree = map { chomp; $_ } <$fd>;
5742 # print element (entry, item)
5743 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
5744 if ($format eq 'rss') {
5746 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5747 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5748 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5749 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5750 "<link>$co_url</link>\n" .
5751 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5752 "<content:encoded>" .
5754 } elsif ($format eq 'atom') {
5756 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5757 "<updated>$cd{'iso-8601'}</updated>\n" .
5759 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5760 if ($co{'author_email'}) {
5761 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5763 print "</author>\n" .
5764 # use committer for contributor
5766 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5767 if ($co{'committer_email'}) {
5768 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5770 print "</contributor>\n" .
5771 "<published>$cd{'iso-8601'}</published>\n" .
5772 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5773 "<id>$co_url</id>\n" .
5774 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5775 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5777 my $comment = $co{'comment'};
5779 foreach my $line (@
$comment) {
5780 $line = esc_html
($line);
5783 print "</pre><ul>\n";
5784 foreach my $difftree_line (@difftree) {
5785 my %difftree = parse_difftree_raw_line
($difftree_line);
5786 next if !$difftree{'from_id'};
5788 my $file = $difftree{'file'} || $difftree{'to_file'};
5792 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5793 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5794 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5795 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5796 -title
=> "diff"}, 'D');
5798 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5799 file_name
=>$file, hash_base
=>$commit),
5800 -title
=> "blame"}, 'B');
5802 # if this is not a feed of a file history
5803 if (!defined $file_name || $file_name ne $file) {
5804 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5805 file_name
=>$file, hash
=>$commit),
5806 -title
=> "history"}, 'H');
5808 $file = esc_path
($file);
5812 if ($format eq 'rss') {
5813 print "</ul>]]>\n" .
5814 "</content:encoded>\n" .
5816 } elsif ($format eq 'atom') {
5817 print "</ul>\n</div>\n" .
5824 if ($format eq 'rss') {
5825 print "</channel>\n</rss>\n";
5826 } elsif ($format eq 'atom') {
5840 my @list = git_get_projects_list
();
5842 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5844 <?xml version="1.0" encoding="utf-8"?>
5845 <opml version="1.0">
5847 <title>$site_name OPML Export</title>
5850 <outline text="git RSS feeds">
5853 foreach my $pr (@list) {
5855 my $head = git_get_head_hash
($proj{'path'});
5856 if (!defined $head) {
5859 $git_dir = "$projectroot/$proj{'path'}";
5860 my %co = parse_commit
($head);
5865 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5866 my $rss = "$my_url?p=$proj{'path'};a=rss";
5867 my $html = "$my_url?p=$proj{'path'};a=summary";
5868 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";