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 # hcoop-change: Customize.
47 our $home_link_str = "HCoop";
49 # name of your site or organization to appear in page titles
50 # replace this with something more descriptive for clearer bookmarks
51 # hcoop-change: Customize.
52 our $site_name = "HCoop Git"
53 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
55 # filename of html text to include at top of each page
56 our $site_header = "";
57 # html text to include at home page
58 our $home_text = "indextext.html";
59 # filename of html text to include at bottom of each page
60 our $site_footer = "";
61 # filename of cached version of front page
62 our $cached_front_page = "/var/local/lib/gitweb/indexcache.html";
65 our @stylesheets = ("gitweb.css");
66 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
67 our $stylesheet = undef;
68 # URI of GIT logo (72x27 size)
69 our $logo = "git-logo.png";
70 # URI of GIT favicon, assumed to be image/png type
71 our $favicon = "git-favicon.png";
73 # URI and label (title) of GIT logo link
74 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
75 #our $logo_label = "git documentation";
76 our $logo_url = "http://git.or.cz/";
77 our $logo_label = "git homepage";
79 # source of projects list
80 our $projects_list = "";
82 # the width (in characters) of the projects list "Description" column
83 our $projects_list_description_width = 25;
85 # default order of projects list
86 # valid values are none, project, descr, owner, and age
87 our $default_projects_order = "project";
89 # show repository only if this file exists
90 # (only effective if this variable evaluates to true)
93 # only allow viewing of repositories also shown on the overview page
94 our $strict_export = "";
96 # list of git base URLs used for URL to where fetch project from,
97 # i.e. full URL is "$git_base_url/$project"
98 # hcoop-change: We like several URLs.
99 #our @git_base_url_list = grep { $_ ne '' } ("");
100 our @git_base_url_list = ('git://git.hcoop.net/git',
101 'http://git.hcoop.net/git');
103 # default blob_plain mimetype and default charset for text/plain blob
104 our $default_blob_plain_mimetype = 'text/plain';
105 our $default_text_plain_charset = undef;
107 # file to use for guessing MIME types before trying /etc/mime.types
108 # (relative to the current git repository)
109 our $mimetypes_file = undef;
111 # assume this charset if line contains non-UTF-8 characters;
112 # it should be valid encoding (see Encoding::Supported(3pm) for list),
113 # for which encoding all byte sequences are valid, for example
114 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
115 # could be even 'utf-8' for the old behavior)
116 our $fallback_encoding = 'latin1';
118 # rename detection options for git-diff and git-diff-tree
119 # - default is '-M', with the cost proportional to
120 # (number of removed files) * (number of new files).
121 # - more costly is '-C' (which implies '-M'), with the cost proportional to
122 # (number of changed files + number of removed files) * (number of new files)
123 # - even more costly is '-C', '--find-copies-harder' with cost
124 # (number of files in the original tree) * (number of new files)
125 # - one might want to include '-B' option, e.g. '-B', '-M'
126 our @diff_opts = ('-M'); # taken from git_commit
128 # information about snapshot formats that gitweb is capable of serving
129 our %known_snapshot_formats = (
131 # 'display' => display name,
132 # 'type' => mime type,
133 # 'suffix' => filename suffix,
134 # 'format' => --format for git-archive,
135 # 'compressor' => [compressor command and arguments]
136 # (array reference, optional)}
139 'display' => 'tar.gz',
140 'type' => 'application/x-gzip',
141 'suffix' => '.tar.gz',
143 'compressor' => ['gzip']},
146 'display' => 'tar.bz2',
147 'type' => 'application/x-bzip2',
148 'suffix' => '.tar.bz2',
150 'compressor' => ['bzip2']},
154 'type' => 'application/x-zip',
159 # Aliases so we understand old gitweb.snapshot values in repository
161 our %known_snapshot_format_aliases = (
165 # backward compatibility: legacy gitweb config support
166 'x-gzip' => undef, 'gz' => undef,
167 'x-bzip2' => undef, 'bz2' => undef,
168 'x-zip' => undef, '' => undef,
171 # You define site-wide feature defaults here; override them with
172 # $GITWEB_CONFIG as necessary.
175 # 'sub' => feature-sub (subroutine),
176 # 'override' => allow-override (boolean),
177 # 'default' => [ default options...] (array reference)}
179 # if feature is overridable (it means that allow-override has true value),
180 # then feature-sub will be called with default options as parameters;
181 # return value of feature-sub indicates if to enable specified feature
183 # if there is no 'sub' key (no feature-sub), then feature cannot be
186 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
188 # Enable the 'blame' blob view, showing the last commit that modified
189 # each line in the file. This can be very CPU-intensive.
191 # To enable system wide have in $GITWEB_CONFIG
192 # $feature{'blame'}{'default'} = [1];
193 # To have project specific config enable override in $GITWEB_CONFIG
194 # $feature{'blame'}{'override'} = 1;
195 # and in project config gitweb.blame = 0|1;
197 'sub' => \
&feature_blame
,
201 # Enable the 'snapshot' link, providing a compressed archive of any
202 # tree. This can potentially generate high traffic if you have large
205 # Value is a list of formats defined in %known_snapshot_formats that
207 # To disable system wide have in $GITWEB_CONFIG
208 # $feature{'snapshot'}{'default'} = [];
209 # To have project specific config enable override in $GITWEB_CONFIG
210 # $feature{'snapshot'}{'override'} = 1;
211 # and in project config, a comma-separated list of formats or "none"
212 # to disable. Example: gitweb.snapshot = tbz2,zip;
214 'sub' => \
&feature_snapshot
,
216 'default' => ['tgz']},
218 # Enable text search, which will list the commits which match author,
219 # committer or commit text to a given string. Enabled by default.
220 # Project specific override is not supported.
225 # Enable grep search, which will list the files in currently selected
226 # tree containing the given string. Enabled by default. This can be
227 # potentially CPU-intensive, of course.
229 # To enable system wide have in $GITWEB_CONFIG
230 # $feature{'grep'}{'default'} = [1];
231 # To have project specific config enable override in $GITWEB_CONFIG
232 # $feature{'grep'}{'override'} = 1;
233 # and in project config gitweb.grep = 0|1;
238 # Enable the pickaxe search, which will list the commits that modified
239 # a given string in a file. This can be practical and quite faster
240 # alternative to 'blame', but still potentially CPU-intensive.
242 # To enable system wide have in $GITWEB_CONFIG
243 # $feature{'pickaxe'}{'default'} = [1];
244 # To have project specific config enable override in $GITWEB_CONFIG
245 # $feature{'pickaxe'}{'override'} = 1;
246 # and in project config gitweb.pickaxe = 0|1;
248 'sub' => \
&feature_pickaxe
,
252 # Make gitweb use an alternative format of the URLs which can be
253 # more readable and natural-looking: project name is embedded
254 # directly in the path and the query string contains other
255 # auxiliary information. All gitweb installations recognize
256 # URL in either format; this configures in which formats gitweb
259 # To enable system wide have in $GITWEB_CONFIG
260 # $feature{'pathinfo'}{'default'} = [1];
261 # Project specific override is not supported.
263 # Note that you will need to change the default location of CSS,
264 # favicon, logo and possibly other files to an absolute URL. Also,
265 # if gitweb.cgi serves as your indexfile, you will need to force
266 # $my_uri to contain the script name in your $GITWEB_CONFIG.
271 # Make gitweb consider projects in project root subdirectories
272 # to be forks of existing projects. Given project $projname.git,
273 # projects matching $projname/*.git will not be shown in the main
274 # projects list, instead a '+' mark will be added to $projname
275 # there and a 'forks' view will be enabled for the project, listing
276 # all the forks. If project list is taken from a file, forks have
277 # to be listed after the main project.
279 # To enable system wide have in $GITWEB_CONFIG
280 # $feature{'forks'}{'default'} = [1];
281 # Project specific override is not supported.
287 sub gitweb_check_feature
{
289 return unless exists $feature{$name};
290 my ($sub, $override, @defaults) = (
291 $feature{$name}{'sub'},
292 $feature{$name}{'override'},
293 @
{$feature{$name}{'default'}});
294 if (!$override) { return @defaults; }
296 warn "feature $name is not overrideable";
299 return $sub->(@defaults);
303 my ($val) = git_get_project_config
('blame', '--bool');
305 if ($val eq 'true') {
307 } elsif ($val eq 'false') {
314 sub feature_snapshot
{
317 my ($val) = git_get_project_config
('snapshot');
320 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
327 my ($val) = git_get_project_config
('grep', '--bool');
329 if ($val eq 'true') {
331 } elsif ($val eq 'false') {
338 sub feature_pickaxe
{
339 my ($val) = git_get_project_config
('pickaxe', '--bool');
341 if ($val eq 'true') {
343 } elsif ($val eq 'false') {
350 # checking HEAD file with -e is fragile if the repository was
351 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
353 sub check_head_link
{
355 my $headfile = "$dir/HEAD";
356 return ((-e
$headfile) ||
357 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
360 sub check_export_ok
{
362 return (check_head_link
($dir) &&
363 (!$export_ok || -e
"$dir/$export_ok"));
366 # process alternate names for backward compatibility
367 # filter out unsupported (unknown) snapshot formats
368 sub filter_snapshot_fmts
{
372 exists $known_snapshot_format_aliases{$_} ?
373 $known_snapshot_format_aliases{$_} : $_} @fmts;
374 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
378 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "gitweb_config.perl";
379 if (-e
$GITWEB_CONFIG) {
382 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "/etc/gitweb.conf";
383 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
386 # version of the core git binary
387 our $git_version = qx("$GIT" --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
389 $projects_list ||= $projectroot;
391 # ======================================================================
392 # input validation and dispatch
393 our $action = $cgi->param('a');
394 if (defined $action) {
395 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
396 die_error
(undef, "Invalid action parameter");
400 # parameters which are pathnames
401 our $project = $cgi->param('p');
402 if (defined $project) {
403 if (!validate_pathname
($project) ||
404 !(-d
"$projectroot/$project") ||
405 !check_head_link
("$projectroot/$project") ||
406 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
407 ($strict_export && !project_in_list
($project))) {
409 die_error
(undef, "No such project");
413 our $file_name = $cgi->param('f');
414 if (defined $file_name) {
415 if (!validate_pathname
($file_name)) {
416 die_error
(undef, "Invalid file parameter");
420 our $file_parent = $cgi->param('fp');
421 if (defined $file_parent) {
422 if (!validate_pathname
($file_parent)) {
423 die_error
(undef, "Invalid file parent parameter");
427 sub git_send_cached_front_page
{
428 my $status = shift || "200 OK";
431 # require explicit support from the UA if we are to send the page as
432 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
433 # we have to do this because MSIE sometimes globs '*/*', pretending to
434 # support xhtml+xml but choking when it gets what it asked for.
435 if (defined $cgi->http('HTTP_ACCEPT') &&
436 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
437 $cgi->Accept('application/xhtml+xml') != 0) {
438 $content_type = 'application/xhtml+xml';
440 $content_type = 'text/html';
442 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
443 -status
=> $status, -expires
=> $expires);
444 open (my $fd, $cached_front_page);
450 # Display a cached page if no parameters were provided and the
451 # "nocache" parameter was not passed.
452 our $nocache = $cgi->param('nocache');
453 our @params = $cgi->Vars;
454 if ($cached_front_page && ! defined $nocache && scalar @params == 0
455 && -f
$cached_front_page && -r
$cached_front_page) {
456 git_send_cached_front_page
();
459 # parameters which are refnames
460 our $hash = $cgi->param('h');
462 if (!validate_refname
($hash)) {
463 die_error
(undef, "Invalid hash parameter");
467 our $hash_parent = $cgi->param('hp');
468 if (defined $hash_parent) {
469 if (!validate_refname
($hash_parent)) {
470 die_error
(undef, "Invalid hash parent parameter");
474 our $hash_base = $cgi->param('hb');
475 if (defined $hash_base) {
476 if (!validate_refname
($hash_base)) {
477 die_error
(undef, "Invalid hash base parameter");
481 my %allowed_options = (
482 "--no-merges" => [ qw(rss atom log shortlog history) ],
485 our @extra_options = $cgi->param('opt');
486 if (defined @extra_options) {
487 foreach my $opt (@extra_options) {
488 if (not exists $allowed_options{$opt}) {
489 die_error
(undef, "Invalid option parameter");
491 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
492 die_error
(undef, "Invalid option parameter for this action");
497 our $hash_parent_base = $cgi->param('hpb');
498 if (defined $hash_parent_base) {
499 if (!validate_refname
($hash_parent_base)) {
500 die_error
(undef, "Invalid hash parent base parameter");
505 our $page = $cgi->param('pg');
507 if ($page =~ m/[^0-9]/) {
508 die_error
(undef, "Invalid page parameter");
512 our $searchtype = $cgi->param('st');
513 if (defined $searchtype) {
514 if ($searchtype =~ m/[^a-z]/) {
515 die_error
(undef, "Invalid searchtype parameter");
519 our $search_use_regexp = $cgi->param('sr');
521 our $searchtext = $cgi->param('s');
523 if (defined $searchtext) {
524 if (length($searchtext) < 2) {
525 die_error
(undef, "At least two characters are required for search parameter");
527 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
530 # now read PATH_INFO and use it as alternative to parameters
531 sub evaluate_path_info
{
532 return if defined $project;
533 my $path_info = $ENV{"PATH_INFO"};
534 return if !$path_info;
535 $path_info =~ s
,^/+,,;
536 return if !$path_info;
537 # find which part of PATH_INFO is project
538 $project = $path_info;
540 while ($project && !check_head_link
("$projectroot/$project")) {
541 $project =~ s
,/*[^/]*$,,;
544 $project = validate_pathname
($project);
546 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
547 ($strict_export && !project_in_list
($project))) {
551 # do not change any parameters if an action is given using the query string
553 $path_info =~ s
,^\Q
$project\E
/*,,;
554 my ($refname, $pathname) = split(/:/, $path_info, 2);
555 if (defined $pathname) {
556 # we got "project.git/branch:filename" or "project.git/branch:dir/"
557 # we could use git_get_type(branch:pathname), but it needs $git_dir
558 $pathname =~ s
,^/+,,;
559 if (!$pathname || substr($pathname, -1) eq "/") {
563 $action ||= "blob_plain";
565 $hash_base ||= validate_refname
($refname);
566 $file_name ||= validate_pathname
($pathname);
567 } elsif (defined $refname) {
568 # we got "project.git/branch"
569 $action ||= "shortlog";
570 $hash ||= validate_refname
($refname);
573 evaluate_path_info
();
575 # path to the current git repository
577 $git_dir = "$projectroot/$project" if $project;
581 "blame" => \
&git_blame2
,
582 "blobdiff" => \
&git_blobdiff
,
583 "blobdiff_plain" => \
&git_blobdiff_plain
,
584 "blob" => \
&git_blob
,
585 "blob_plain" => \
&git_blob_plain
,
586 "commitdiff" => \
&git_commitdiff
,
587 "commitdiff_plain" => \
&git_commitdiff_plain
,
588 "commit" => \
&git_commit
,
589 "forks" => \
&git_forks
,
590 "heads" => \
&git_heads
,
591 "history" => \
&git_history
,
594 "atom" => \
&git_atom
,
595 "search" => \
&git_search
,
596 "search_help" => \
&git_search_help
,
597 "shortlog" => \
&git_shortlog
,
598 "summary" => \
&git_summary
,
600 "tags" => \
&git_tags
,
601 "tree" => \
&git_tree
,
602 "snapshot" => \
&git_snapshot
,
603 "object" => \
&git_object
,
604 # those below don't need $project
605 "opml" => \
&git_opml
,
606 "project_list" => \
&git_project_list
,
607 "project_index" => \
&git_project_index
,
610 if (!defined $action) {
612 $action = git_get_type
($hash);
613 } elsif (defined $hash_base && defined $file_name) {
614 $action = git_get_type
("$hash_base:$file_name");
615 } elsif (defined $project) {
618 $action = 'project_list';
621 if (!defined($actions{$action})) {
622 die_error
(undef, "Unknown action");
624 if ($action !~ m/^(opml|project_list|project_index)$/ &&
626 die_error
(undef, "Project needed");
628 $actions{$action}->();
631 ## ======================================================================
636 # default is to use -absolute url() i.e. $my_uri
637 my $href = $params{-full
} ?
$my_url : $my_uri;
639 # XXX: Warning: If you touch this, check the search form for updating,
650 hash_parent_base
=> "hpb",
655 snapshot_format
=> "sf",
656 extra_options
=> "opt",
657 search_use_regexp
=> "sr",
659 my %mapping = @mapping;
661 $params{'project'} = $project unless exists $params{'project'};
663 if ($params{-replay
}) {
664 while (my ($name, $symbol) = each %mapping) {
665 if (!exists $params{$name}) {
666 # to allow for multivalued params we use arrayref form
667 $params{$name} = [ $cgi->param($symbol) ];
672 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
674 # use PATH_INFO for project name
675 $href .= "/".esc_url
($params{'project'}) if defined $params{'project'};
676 delete $params{'project'};
678 # Summary just uses the project path URL
679 if (defined $params{'action'} && $params{'action'} eq 'summary') {
680 delete $params{'action'};
684 # now encode the parameters explicitly
686 for (my $i = 0; $i < @mapping; $i += 2) {
687 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
688 if (defined $params{$name}) {
689 if (ref($params{$name}) eq "ARRAY") {
690 foreach my $par (@
{$params{$name}}) {
691 push @result, $symbol . "=" . esc_param
($par);
694 push @result, $symbol . "=" . esc_param
($params{$name});
698 $href .= "?" . join(';', @result) if scalar @result;
704 ## ======================================================================
705 ## validation, quoting/unquoting and escaping
707 sub validate_pathname
{
708 my $input = shift || return undef;
710 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
711 # at the beginning, at the end, and between slashes.
712 # also this catches doubled slashes
713 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
717 if ($input =~ m!\0!) {
723 sub validate_refname
{
724 my $input = shift || return undef;
726 # textual hashes are O.K.
727 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
730 # it must be correct pathname
731 $input = validate_pathname
($input)
733 # restrictions on ref name according to git-check-ref-format
734 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
740 # decode sequences of octets in utf8 into Perl's internal form,
741 # which is utf-8 with utf8 flag set if needed. gitweb writes out
742 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
745 if (utf8
::valid
($str)) {
749 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
753 # quote unsafe chars, but keep the slash, even when it's not
754 # correct, but quoted slashes look too horrible in bookmarks
757 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
763 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
766 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
772 # replace invalid utf8 character with SUBSTITUTION sequence
777 $str = to_utf8
($str);
778 $str = $cgi->escapeHTML($str);
779 if ($opts{'-nbsp'}) {
780 $str =~ s/ / /g;
782 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
786 # quote control characters and escape filename to HTML
791 $str = to_utf8
($str);
792 $str = $cgi->escapeHTML($str);
793 if ($opts{'-nbsp'}) {
794 $str =~ s/ / /g;
796 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
800 # Make control characters "printable", using character escape codes (CEC)
804 my %es = ( # character escape codes, aka escape sequences
805 "\t" => '\t', # tab (HT)
806 "\n" => '\n', # line feed (LF)
807 "\r" => '\r', # carrige return (CR)
808 "\f" => '\f', # form feed (FF)
809 "\b" => '\b', # backspace (BS)
810 "\a" => '\a', # alarm (bell) (BEL)
811 "\e" => '\e', # escape (ESC)
812 "\013" => '\v', # vertical tab (VT)
813 "\000" => '\0', # nul character (NUL)
815 my $chr = ( (exists $es{$cntrl})
817 : sprintf('\%03o', ord($cntrl)) );
818 if ($opts{-nohtml
}) {
821 return "<span class=\"cntrl\">$chr</span>";
825 # Alternatively use unicode control pictures codepoints,
826 # Unicode "printable representation" (PR)
831 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
832 if ($opts{-nohtml
}) {
835 return "<span class=\"cntrl\">$chr</span>";
839 # git may return quoted and escaped filenames
845 my %es = ( # character escape codes, aka escape sequences
846 't' => "\t", # tab (HT, TAB)
847 'n' => "\n", # newline (NL)
848 'r' => "\r", # return (CR)
849 'f' => "\f", # form feed (FF)
850 'b' => "\b", # backspace (BS)
851 'a' => "\a", # alarm (bell) (BEL)
852 'e' => "\e", # escape (ESC)
853 'v' => "\013", # vertical tab (VT)
856 if ($seq =~ m/^[0-7]{1,3}$/) {
857 # octal char sequence
858 return chr(oct($seq));
859 } elsif (exists $es{$seq}) {
860 # C escape sequence, aka character escape code
863 # quoted ordinary character
867 if ($str =~ m/^"(.*)"$/) {
870 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
875 # escape tabs (convert tabs to spaces)
879 while ((my $pos = index($line, "\t")) != -1) {
880 if (my $count = (8 - ($pos % 8))) {
881 my $spaces = ' ' x
$count;
882 $line =~ s/\t/$spaces/;
889 sub project_in_list
{
891 my @list = git_get_projects_list
();
892 return @list && scalar(grep { $_->{'path'} eq $project } @list);
895 ## ----------------------------------------------------------------------
896 ## HTML aware string manipulation
898 # Try to chop given string on a word boundary between position
899 # $len and $len+$add_len. If there is no word boundary there,
900 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
901 # (marking chopped part) would be longer than given string.
905 my $add_len = shift || 10;
906 my $where = shift || 'right'; # 'left' | 'center' | 'right'
908 # Make sure perl knows it is utf8 encoded so we don't
909 # cut in the middle of a utf8 multibyte char.
910 $str = to_utf8
($str);
912 # allow only $len chars, but don't cut a word if it would fit in $add_len
913 # if it doesn't fit, cut it if it's still longer than the dots we would add
914 # remove chopped character entities entirely
916 # when chopping in the middle, distribute $len into left and right part
917 # return early if chopping wouldn't make string shorter
918 if ($where eq 'center') {
919 return $str if ($len + 5 >= length($str)); # filler is length 5
922 return $str if ($len + 4 >= length($str)); # filler is length 4
925 # regexps: ending and beginning with word part up to $add_len
926 my $endre = qr/.{$len}\w{0,$add_len}/;
927 my $begre = qr/\w{0,$add_len}.{$len}/;
929 if ($where eq 'left') {
930 $str =~ m/^(.*?)($begre)$/;
931 my ($lead, $body) = ($1, $2);
932 if (length($lead) > 4) {
933 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
938 } elsif ($where eq 'center') {
939 $str =~ m/^($endre)(.*)$/;
940 my ($left, $str) = ($1, $2);
941 $str =~ m/^(.*?)($begre)$/;
942 my ($mid, $right) = ($1, $2);
943 if (length($mid) > 5) {
944 $left =~ s/&[^;]*$//;
945 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
948 return "$left$mid$right";
951 $str =~ m/^($endre)(.*)$/;
954 if (length($tail) > 4) {
955 $body =~ s/&[^;]*$//;
962 # takes the same arguments as chop_str, but also wraps a <span> around the
963 # result with a title attribute if it does get chopped. Additionally, the
964 # string is HTML-escaped.
965 sub chop_and_escape_str
{
968 my $chopped = chop_str
(@_);
969 if ($chopped eq $str) {
970 return esc_html
($chopped);
972 $str =~ s/([[:cntrl:]])/?/g;
973 return $cgi->span({-title
=>$str}, esc_html
($chopped));
977 ## ----------------------------------------------------------------------
978 ## functions returning short strings
980 # CSS class for given age value (in seconds)
986 } elsif ($age < 60*60*2) {
988 } elsif ($age < 60*60*24*2) {
995 # convert age in seconds to "nn units ago" string
1000 if ($age > 60*60*24*365*2) {
1001 $age_str = (int $age/60/60/24/365);
1002 $age_str .= " years ago";
1003 } elsif ($age > 60*60*24*(365/12)*2) {
1004 $age_str = int $age/60/60/24/(365/12);
1005 $age_str .= " months ago";
1006 } elsif ($age > 60*60*24*7*2) {
1007 $age_str = int $age/60/60/24/7;
1008 $age_str .= " weeks ago";
1009 } elsif ($age > 60*60*24*2) {
1010 $age_str = int $age/60/60/24;
1011 $age_str .= " days ago";
1012 } elsif ($age > 60*60*2) {
1013 $age_str = int $age/60/60;
1014 $age_str .= " hours ago";
1015 } elsif ($age > 60*2) {
1016 $age_str = int $age/60;
1017 $age_str .= " min ago";
1018 } elsif ($age > 2) {
1019 $age_str = int $age;
1020 $age_str .= " sec ago";
1022 $age_str .= " right now";
1028 S_IFINVALID
=> 0030000,
1029 S_IFGITLINK
=> 0160000,
1032 # submodule/subproject, a commit object reference
1033 sub S_ISGITLINK
($) {
1036 return (($mode & S_IFMT
) == S_IFGITLINK
)
1039 # convert file mode in octal to symbolic file mode string
1041 my $mode = oct shift;
1043 if (S_ISGITLINK
($mode)) {
1044 return 'm---------';
1045 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1046 return 'drwxr-xr-x';
1047 } elsif (S_ISLNK
($mode)) {
1048 return 'lrwxrwxrwx';
1049 } elsif (S_ISREG
($mode)) {
1050 # git cares only about the executable bit
1051 if ($mode & S_IXUSR
) {
1052 return '-rwxr-xr-x';
1054 return '-rw-r--r--';
1057 return '----------';
1061 # convert file mode in octal to file type string
1065 if ($mode !~ m/^[0-7]+$/) {
1071 if (S_ISGITLINK
($mode)) {
1073 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1075 } elsif (S_ISLNK
($mode)) {
1077 } elsif (S_ISREG
($mode)) {
1084 # convert file mode in octal to file type description string
1085 sub file_type_long
{
1088 if ($mode !~ m/^[0-7]+$/) {
1094 if (S_ISGITLINK
($mode)) {
1096 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1098 } elsif (S_ISLNK
($mode)) {
1100 } elsif (S_ISREG
($mode)) {
1101 if ($mode & S_IXUSR
) {
1102 return "executable";
1112 ## ----------------------------------------------------------------------
1113 ## functions returning short HTML fragments, or transforming HTML fragments
1114 ## which don't belong to other sections
1116 # format line of commit message.
1117 sub format_log_line_html
{
1120 $line = esc_html
($line, -nbsp
=>1);
1121 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1124 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1125 -class => "text"}, $hash_text);
1126 $line =~ s/$hash_text/$link/;
1131 # format marker of refs pointing to given object
1132 sub format_ref_marker
{
1133 my ($refs, $id) = @_;
1136 if (defined $refs->{$id}) {
1137 foreach my $ref (@
{$refs->{$id}}) {
1138 my ($type, $name) = qw();
1139 # e.g. tags/v2.6.11 or heads/next
1140 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1148 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1149 esc_html
($name) . "</span>";
1154 return ' <span class="refs">'. $markers . '</span>';
1160 # format, perhaps shortened and with markers, title line
1161 sub format_subject_html
{
1162 my ($long, $short, $href, $extra) = @_;
1163 $extra = '' unless defined($extra);
1165 if (length($short) < length($long)) {
1166 return $cgi->a({-href
=> $href, -class => "list subject",
1167 -title
=> to_utf8
($long)},
1168 esc_html
($short) . $extra);
1170 return $cgi->a({-href
=> $href, -class => "list subject"},
1171 esc_html
($long) . $extra);
1175 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1176 sub format_git_diff_header_line
{
1178 my $diffinfo = shift;
1179 my ($from, $to) = @_;
1181 if ($diffinfo->{'nparents'}) {
1183 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1184 if ($to->{'href'}) {
1185 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1186 esc_path
($to->{'file'}));
1187 } else { # file was deleted (no href)
1188 $line .= esc_path
($to->{'file'});
1192 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1193 if ($from->{'href'}) {
1194 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1195 'a/' . esc_path
($from->{'file'}));
1196 } else { # file was added (no href)
1197 $line .= 'a/' . esc_path
($from->{'file'});
1200 if ($to->{'href'}) {
1201 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1202 'b/' . esc_path
($to->{'file'}));
1203 } else { # file was deleted
1204 $line .= 'b/' . esc_path
($to->{'file'});
1208 return "<div class=\"diff header\">$line</div>\n";
1211 # format extended diff header line, before patch itself
1212 sub format_extended_diff_header_line
{
1214 my $diffinfo = shift;
1215 my ($from, $to) = @_;
1218 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1219 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1220 esc_path
($from->{'file'}));
1222 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1223 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1224 esc_path
($to->{'file'}));
1226 # match single <mode>
1227 if ($line =~ m/\s(\d{6})$/) {
1228 $line .= '<span class="info"> (' .
1229 file_type_long
($1) .
1233 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1234 # can match only for combined diff
1236 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1237 if ($from->{'href'}[$i]) {
1238 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1240 substr($diffinfo->{'from_id'}[$i],0,7));
1245 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1248 if ($to->{'href'}) {
1249 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1250 substr($diffinfo->{'to_id'},0,7));
1255 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1256 # can match only for ordinary diff
1257 my ($from_link, $to_link);
1258 if ($from->{'href'}) {
1259 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1260 substr($diffinfo->{'from_id'},0,7));
1262 $from_link = '0' x
7;
1264 if ($to->{'href'}) {
1265 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1266 substr($diffinfo->{'to_id'},0,7));
1270 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1271 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1274 return $line . "<br/>\n";
1277 # format from-file/to-file diff header
1278 sub format_diff_from_to_header
{
1279 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1284 #assert($line =~ m/^---/) if DEBUG;
1285 # no extra formatting for "^--- /dev/null"
1286 if (! $diffinfo->{'nparents'}) {
1287 # ordinary (single parent) diff
1288 if ($line =~ m!^--- "?a/!) {
1289 if ($from->{'href'}) {
1291 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1292 esc_path
($from->{'file'}));
1295 esc_path
($from->{'file'});
1298 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1301 # combined diff (merge commit)
1302 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1303 if ($from->{'href'}[$i]) {
1305 $cgi->a({-href
=>href
(action
=>"blobdiff",
1306 hash_parent
=>$diffinfo->{'from_id'}[$i],
1307 hash_parent_base
=>$parents[$i],
1308 file_parent
=>$from->{'file'}[$i],
1309 hash
=>$diffinfo->{'to_id'},
1311 file_name
=>$to->{'file'}),
1313 -title
=>"diff" . ($i+1)},
1316 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1317 esc_path
($from->{'file'}[$i]));
1319 $line = '--- /dev/null';
1321 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1326 #assert($line =~ m/^\+\+\+/) if DEBUG;
1327 # no extra formatting for "^+++ /dev/null"
1328 if ($line =~ m!^\+\+\+ "?b/!) {
1329 if ($to->{'href'}) {
1331 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1332 esc_path
($to->{'file'}));
1335 esc_path
($to->{'file'});
1338 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1343 # create note for patch simplified by combined diff
1344 sub format_diff_cc_simplified
{
1345 my ($diffinfo, @parents) = @_;
1348 $result .= "<div class=\"diff header\">" .
1350 if (!is_deleted
($diffinfo)) {
1351 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1353 hash
=>$diffinfo->{'to_id'},
1354 file_name
=>$diffinfo->{'to_file'}),
1356 esc_path
($diffinfo->{'to_file'}));
1358 $result .= esc_path
($diffinfo->{'to_file'});
1360 $result .= "</div>\n" . # class="diff header"
1361 "<div class=\"diff nodifferences\">" .
1363 "</div>\n"; # class="diff nodifferences"
1368 # format patch (diff) line (not to be used for diff headers)
1369 sub format_diff_line
{
1371 my ($from, $to) = @_;
1372 my $diff_class = "";
1376 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1378 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1379 if ($line =~ m/^\@{3}/) {
1380 $diff_class = " chunk_header";
1381 } elsif ($line =~ m/^\\/) {
1382 $diff_class = " incomplete";
1383 } elsif ($prefix =~ tr/+/+/) {
1384 $diff_class = " add";
1385 } elsif ($prefix =~ tr/-/-/) {
1386 $diff_class = " rem";
1389 # assume ordinary diff
1390 my $char = substr($line, 0, 1);
1392 $diff_class = " add";
1393 } elsif ($char eq '-') {
1394 $diff_class = " rem";
1395 } elsif ($char eq '@') {
1396 $diff_class = " chunk_header";
1397 } elsif ($char eq "\\") {
1398 $diff_class = " incomplete";
1401 $line = untabify
($line);
1402 if ($from && $to && $line =~ m/^\@{2} /) {
1403 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1404 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1406 $from_lines = 0 unless defined $from_lines;
1407 $to_lines = 0 unless defined $to_lines;
1409 if ($from->{'href'}) {
1410 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1411 -class=>"list"}, $from_text);
1413 if ($to->{'href'}) {
1414 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1415 -class=>"list"}, $to_text);
1417 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1418 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1419 return "<div class=\"diff$diff_class\">$line</div>\n";
1420 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1421 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1422 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1424 @from_text = split(' ', $ranges);
1425 for (my $i = 0; $i < @from_text; ++$i) {
1426 ($from_start[$i], $from_nlines[$i]) =
1427 (split(',', substr($from_text[$i], 1)), 0);
1430 $to_text = pop @from_text;
1431 $to_start = pop @from_start;
1432 $to_nlines = pop @from_nlines;
1434 $line = "<span class=\"chunk_info\">$prefix ";
1435 for (my $i = 0; $i < @from_text; ++$i) {
1436 if ($from->{'href'}[$i]) {
1437 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1438 -class=>"list"}, $from_text[$i]);
1440 $line .= $from_text[$i];
1444 if ($to->{'href'}) {
1445 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1446 -class=>"list"}, $to_text);
1450 $line .= " $prefix</span>" .
1451 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1452 return "<div class=\"diff$diff_class\">$line</div>\n";
1454 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1457 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1458 # linked. Pass the hash of the tree/commit to snapshot.
1459 sub format_snapshot_links
{
1461 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1462 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1463 my $num_fmts = @snapshot_fmts;
1464 if ($num_fmts > 1) {
1465 # A parenthesized list of links bearing format names.
1466 # e.g. "snapshot (_tar.gz_ _zip_)"
1467 return "snapshot (" . join(' ', map
1474 }, $known_snapshot_formats{$_}{'display'})
1475 , @snapshot_fmts) . ")";
1476 } elsif ($num_fmts == 1) {
1477 # A single "snapshot" link whose tooltip bears the format name.
1479 my ($fmt) = @snapshot_fmts;
1485 snapshot_format
=>$fmt
1487 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1489 } else { # $num_fmts == 0
1494 ## ......................................................................
1495 ## functions returning values to be passed, perhaps after some
1496 ## transformation, to other functions; e.g. returning arguments to href()
1498 # returns hash to be passed to href to generate gitweb URL
1499 # in -title key it returns description of link
1501 my $format = shift || 'Atom';
1502 my %res = (action
=> lc($format));
1504 # feed links are possible only for project views
1505 return unless (defined $project);
1506 # some views should link to OPML, or to generic project feed,
1507 # or don't have specific feed yet (so they should use generic)
1508 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1511 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1512 # from tag links; this also makes possible to detect branch links
1513 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1514 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1517 # find log type for feed description (title)
1519 if (defined $file_name) {
1520 $type = "history of $file_name";
1521 $type .= "/" if ($action eq 'tree');
1522 $type .= " on '$branch'" if (defined $branch);
1524 $type = "log of $branch" if (defined $branch);
1527 $res{-title
} = $type;
1528 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
1529 $res{'file_name'} = $file_name;
1534 ## ----------------------------------------------------------------------
1535 ## git utility subroutines, invoking git commands
1537 # returns path to the core git executable and the --git-dir parameter as list
1539 return $GIT, '--git-dir='.$git_dir;
1542 # quote the given arguments for passing them to the shell
1543 # quote_command("command", "arg 1", "arg with ' and ! characters")
1544 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1545 # Try to avoid using this function wherever possible.
1548 map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1551 # get HEAD ref of given project as hash
1552 sub git_get_head_hash
{
1553 my $project = shift;
1554 my $o_git_dir = $git_dir;
1556 $git_dir = "$projectroot/$project";
1557 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1560 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1564 if (defined $o_git_dir) {
1565 $git_dir = $o_git_dir;
1570 # get type of given object
1574 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1576 close $fd or return;
1581 # repository configuration
1582 our $config_file = '';
1585 # store multiple values for single key as anonymous array reference
1586 # single values stored directly in the hash, not as [ <value> ]
1587 sub hash_set_multi
{
1588 my ($hash, $key, $value) = @_;
1590 if (!exists $hash->{$key}) {
1591 $hash->{$key} = $value;
1592 } elsif (!ref $hash->{$key}) {
1593 $hash->{$key} = [ $hash->{$key}, $value ];
1595 push @
{$hash->{$key}}, $value;
1599 # return hash of git project configuration
1600 # optionally limited to some section, e.g. 'gitweb'
1601 sub git_parse_project_config
{
1602 my $section_regexp = shift;
1607 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1610 while (my $keyval = <$fh>) {
1612 my ($key, $value) = split(/\n/, $keyval, 2);
1614 hash_set_multi
(\
%config, $key, $value)
1615 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1622 # convert config value to boolean, 'true' or 'false'
1623 # no value, number > 0, 'true' and 'yes' values are true
1624 # rest of values are treated as false (never as error)
1625 sub config_to_bool
{
1628 # strip leading and trailing whitespace
1632 return (!defined $val || # section.key
1633 ($val =~ /^\d+$/ && $val) || # section.key = 1
1634 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1637 # convert config value to simple decimal number
1638 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1639 # to be multiplied by 1024, 1048576, or 1073741824
1643 # strip leading and trailing whitespace
1647 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1649 # unknown unit is treated as 1
1650 return $num * ($unit eq 'g' ?
1073741824 :
1651 $unit eq 'm' ?
1048576 :
1652 $unit eq 'k' ?
1024 : 1);
1657 # convert config value to array reference, if needed
1658 sub config_to_multi
{
1661 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
1664 sub git_get_project_config
{
1665 my ($key, $type) = @_;
1668 return unless ($key);
1669 $key =~ s/^gitweb\.//;
1670 return if ($key =~ m/\W/);
1673 if (defined $type) {
1676 unless ($type eq 'bool' || $type eq 'int');
1680 if (!defined $config_file ||
1681 $config_file ne "$git_dir/config") {
1682 %config = git_parse_project_config
('gitweb');
1683 $config_file = "$git_dir/config";
1687 if (!defined $type) {
1688 return $config{"gitweb.$key"};
1689 } elsif ($type eq 'bool') {
1690 # backward compatibility: 'git config --bool' returns true/false
1691 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
1692 } elsif ($type eq 'int') {
1693 return config_to_int
($config{"gitweb.$key"});
1695 return $config{"gitweb.$key"};
1698 # get hash of given path at given ref
1699 sub git_get_hash_by_path
{
1701 my $path = shift || return undef;
1706 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1707 or die_error
(undef, "Open git-ls-tree failed");
1709 close $fd or return undef;
1711 if (!defined $line) {
1712 # there is no tree or hash given by $path at $base
1716 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1717 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1718 if (defined $type && $type ne $2) {
1719 # type doesn't match
1725 # get path of entry with given hash at given tree-ish (ref)
1726 # used to get 'from' filename for combined diff (merge commit) for renames
1727 sub git_get_path_by_hash
{
1728 my $base = shift || return;
1729 my $hash = shift || return;
1733 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1735 while (my $line = <$fd>) {
1738 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1739 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1740 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1749 ## ......................................................................
1750 ## git utility functions, directly accessing git repository
1752 sub git_get_project_description
{
1755 $git_dir = "$projectroot/$path";
1756 open my $fd, "$git_dir/description"
1757 or return git_get_project_config
('description');
1760 if (defined $descr) {
1766 sub git_get_project_url_list
{
1769 $git_dir = "$projectroot/$path";
1770 open my $fd, "$git_dir/cloneurl"
1771 or return wantarray ?
1772 @
{ config_to_multi
(git_get_project_config
('url')) } :
1773 config_to_multi
(git_get_project_config
('url'));
1774 my @git_project_url_list = map { chomp; $_ } <$fd>;
1777 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
1780 sub git_get_projects_list
{
1785 $filter =~ s/\.git$//;
1787 my ($check_forks) = gitweb_check_feature
('forks');
1789 if (-d
$projects_list) {
1790 # search in directory
1791 my $dir = $projects_list . ($filter ?
"/$filter" : '');
1792 # remove the trailing "/"
1794 my $pfxlen = length("$dir");
1795 my $pfxdepth = ($dir =~ tr!/!!);
1798 follow_fast
=> 1, # follow symbolic links
1799 follow_skip
=> 2, # ignore duplicates
1800 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1802 # skip project-list toplevel, if we get it.
1803 return if (m!^[/.]$!);
1804 # only directories can be git repositories
1805 return unless (-d
$_);
1806 # don't traverse too deep (Find is super slow on os x)
1807 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1808 $File::Find
::prune
= 1;
1812 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1813 # we check related file in $projectroot
1814 if ($check_forks and $subdir =~ m
#/.#) {
1815 $File::Find
::prune
= 1;
1816 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1817 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
1818 $File::Find
::prune
= 1;
1823 } elsif (-f
$projects_list) {
1824 # read from file(url-encoded):
1825 # 'git%2Fgit.git Linus+Torvalds'
1826 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1827 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1829 open my ($fd), $projects_list or return;
1831 while (my $line = <$fd>) {
1833 my ($path, $owner) = split ' ', $line;
1834 $path = unescape
($path);
1835 $owner = unescape
($owner);
1836 if (!defined $path) {
1839 if ($filter ne '') {
1840 # looking for forks;
1841 my $pfx = substr($path, 0, length($filter));
1842 if ($pfx ne $filter) {
1845 my $sfx = substr($path, length($filter));
1846 if ($sfx !~ /^\/.*\
.git
$/) {
1849 } elsif ($check_forks) {
1851 foreach my $filter (keys %paths) {
1852 # looking for forks;
1853 my $pfx = substr($path, 0, length($filter));
1854 if ($pfx ne $filter) {
1857 my $sfx = substr($path, length($filter));
1858 if ($sfx !~ /^\/.*\
.git
$/) {
1861 # is a fork, don't include it in
1866 if (check_export_ok
("$projectroot/$path")) {
1869 owner
=> to_utf8
($owner),
1872 (my $forks_path = $path) =~ s/\.git$//;
1873 $paths{$forks_path}++;
1881 our $gitweb_project_owner = undef;
1882 sub git_get_project_list_from_file
{
1884 return if (defined $gitweb_project_owner);
1886 $gitweb_project_owner = {};
1887 # read from file (url-encoded):
1888 # 'git%2Fgit.git Linus+Torvalds'
1889 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1890 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1891 if (-f
$projects_list) {
1892 open (my $fd , $projects_list);
1893 while (my $line = <$fd>) {
1895 my ($pr, $ow) = split ' ', $line;
1896 $pr = unescape
($pr);
1897 $ow = unescape
($ow);
1898 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1904 sub git_get_project_owner
{
1905 my $project = shift;
1908 return undef unless $project;
1909 $git_dir = "$projectroot/$project";
1911 if (!defined $gitweb_project_owner) {
1912 git_get_project_list_from_file
();
1915 if (exists $gitweb_project_owner->{$project}) {
1916 $owner = $gitweb_project_owner->{$project};
1918 if (!defined $owner){
1919 $owner = git_get_project_config
('owner');
1921 if (!defined $owner) {
1922 $owner = get_file_owner
("$git_dir");
1928 sub git_get_last_activity
{
1932 $git_dir = "$projectroot/$path";
1933 open($fd, "-|", git_cmd
(), 'for-each-ref',
1934 '--format=%(committer)',
1935 '--sort=-committerdate',
1937 'refs/heads') or return;
1938 my $most_recent = <$fd>;
1939 close $fd or return;
1940 if (defined $most_recent &&
1941 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1943 my $age = time - $timestamp;
1944 return ($age, age_string
($age));
1946 return (undef, undef);
1949 sub git_get_references
{
1950 my $type = shift || "";
1952 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1953 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1954 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1955 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
1958 while (my $line = <$fd>) {
1960 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1961 if (defined $refs{$1}) {
1962 push @
{$refs{$1}}, $2;
1968 close $fd or return;
1972 sub git_get_rev_name_tags
{
1973 my $hash = shift || return undef;
1975 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1977 my $name_rev = <$fd>;
1980 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1983 # catches also '$hash undefined' output
1988 ## ----------------------------------------------------------------------
1989 ## parse to hash functions
1993 my $tz = shift || "-0000";
1996 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1997 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1998 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1999 $date{'hour'} = $hour;
2000 $date{'minute'} = $min;
2001 $date{'mday'} = $mday;
2002 $date{'day'} = $days[$wday];
2003 $date{'month'} = $months[$mon];
2004 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2005 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2006 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2007 $mday, $months[$mon], $hour ,$min;
2008 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2009 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2011 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2012 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2013 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2014 $date{'hour_local'} = $hour;
2015 $date{'minute_local'} = $min;
2016 $date{'tz_local'} = $tz;
2017 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2018 1900+$year, $mon+1, $mday,
2019 $hour, $min, $sec, $tz);
2028 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2029 $tag{'id'} = $tag_id;
2030 while (my $line = <$fd>) {
2032 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2033 $tag{'object'} = $1;
2034 } elsif ($line =~ m/^type (.+)$/) {
2036 } elsif ($line =~ m/^tag (.+)$/) {
2038 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2039 $tag{'author'} = $1;
2042 } elsif ($line =~ m/--BEGIN/) {
2043 push @comment, $line;
2045 } elsif ($line eq "") {
2049 push @comment, <$fd>;
2050 $tag{'comment'} = \
@comment;
2051 close $fd or return;
2052 if (!defined $tag{'name'}) {
2058 sub parse_commit_text
{
2059 my ($commit_text, $withparents) = @_;
2060 my @commit_lines = split '\n', $commit_text;
2063 pop @commit_lines; # Remove '\0'
2065 if (! @commit_lines) {
2069 my $header = shift @commit_lines;
2070 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2073 ($co{'id'}, my @parents) = split ' ', $header;
2074 while (my $line = shift @commit_lines) {
2075 last if $line eq "\n";
2076 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2078 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2080 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2082 $co{'author_epoch'} = $2;
2083 $co{'author_tz'} = $3;
2084 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2085 $co{'author_name'} = $1;
2086 $co{'author_email'} = $2;
2088 $co{'author_name'} = $co{'author'};
2090 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2091 $co{'committer'} = $1;
2092 $co{'committer_epoch'} = $2;
2093 $co{'committer_tz'} = $3;
2094 $co{'committer_name'} = $co{'committer'};
2095 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2096 $co{'committer_name'} = $1;
2097 $co{'committer_email'} = $2;
2099 $co{'committer_name'} = $co{'committer'};
2103 if (!defined $co{'tree'}) {
2106 $co{'parents'} = \
@parents;
2107 $co{'parent'} = $parents[0];
2109 foreach my $title (@commit_lines) {
2112 $co{'title'} = chop_str
($title, 80, 5);
2113 # remove leading stuff of merges to make the interesting part visible
2114 if (length($title) > 50) {
2115 $title =~ s/^Automatic //;
2116 $title =~ s/^merge (of|with) /Merge ... /i;
2117 if (length($title) > 50) {
2118 $title =~ s/(http|rsync):\/\///;
2120 if (length($title) > 50) {
2121 $title =~ s/(master|www|rsync)\.//;
2123 if (length($title) > 50) {
2124 $title =~ s/kernel.org:?//;
2126 if (length($title) > 50) {
2127 $title =~ s/\/pub\/scm//;
2130 $co{'title_short'} = chop_str
($title, 50, 5);
2134 if ($co{'title'} eq "") {
2135 $co{'title'} = $co{'title_short'} = '(no commit message)';
2137 # remove added spaces
2138 foreach my $line (@commit_lines) {
2141 $co{'comment'} = \
@commit_lines;
2143 my $age = time - $co{'committer_epoch'};
2145 $co{'age_string'} = age_string
($age);
2146 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2147 if ($age > 60*60*24*7*2) {
2148 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2149 $co{'age_string_age'} = $co{'age_string'};
2151 $co{'age_string_date'} = $co{'age_string'};
2152 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2158 my ($commit_id) = @_;
2163 open my $fd, "-|", git_cmd
(), "rev-list",
2169 or die_error
(undef, "Open git-rev-list failed");
2170 %co = parse_commit_text
(<$fd>, 1);
2177 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2185 open my $fd, "-|", git_cmd
(), "rev-list",
2188 ("--max-count=" . $maxcount),
2189 ("--skip=" . $skip),
2193 ($filename ?
($filename) : ())
2194 or die_error
(undef, "Open git-rev-list failed");
2195 while (my $line = <$fd>) {
2196 my %co = parse_commit_text
($line);
2201 return wantarray ?
@cos : \
@cos;
2204 # parse line of git-diff-tree "raw" output
2205 sub parse_difftree_raw_line
{
2209 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2210 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2211 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2212 $res{'from_mode'} = $1;
2213 $res{'to_mode'} = $2;
2214 $res{'from_id'} = $3;
2216 $res{'status'} = $5;
2217 $res{'similarity'} = $6;
2218 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2219 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2221 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2224 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2225 # combined diff (for merge commit)
2226 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2227 $res{'nparents'} = length($1);
2228 $res{'from_mode'} = [ split(' ', $2) ];
2229 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2230 $res{'from_id'} = [ split(' ', $3) ];
2231 $res{'to_id'} = pop @
{$res{'from_id'}};
2232 $res{'status'} = [ split('', $4) ];
2233 $res{'to_file'} = unquote
($5);
2235 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2236 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2237 $res{'commit'} = $1;
2240 return wantarray ?
%res : \
%res;
2243 # wrapper: return parsed line of git-diff-tree "raw" output
2244 # (the argument might be raw line, or parsed info)
2245 sub parsed_difftree_line
{
2246 my $line_or_ref = shift;
2248 if (ref($line_or_ref) eq "HASH") {
2249 # pre-parsed (or generated by hand)
2250 return $line_or_ref;
2252 return parse_difftree_raw_line
($line_or_ref);
2256 # parse line of git-ls-tree output
2257 sub parse_ls_tree_line
($;%) {
2262 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2263 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2271 $res{'name'} = unquote
($4);
2274 return wantarray ?
%res : \
%res;
2277 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2278 sub parse_from_to_diffinfo
{
2279 my ($diffinfo, $from, $to, @parents) = @_;
2281 if ($diffinfo->{'nparents'}) {
2283 $from->{'file'} = [];
2284 $from->{'href'} = [];
2285 fill_from_file_info
($diffinfo, @parents)
2286 unless exists $diffinfo->{'from_file'};
2287 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2288 $from->{'file'}[$i] =
2289 defined $diffinfo->{'from_file'}[$i] ?
2290 $diffinfo->{'from_file'}[$i] :
2291 $diffinfo->{'to_file'};
2292 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2293 $from->{'href'}[$i] = href
(action
=>"blob",
2294 hash_base
=>$parents[$i],
2295 hash
=>$diffinfo->{'from_id'}[$i],
2296 file_name
=>$from->{'file'}[$i]);
2298 $from->{'href'}[$i] = undef;
2302 # ordinary (not combined) diff
2303 $from->{'file'} = $diffinfo->{'from_file'};
2304 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2305 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2306 hash
=>$diffinfo->{'from_id'},
2307 file_name
=>$from->{'file'});
2309 delete $from->{'href'};
2313 $to->{'file'} = $diffinfo->{'to_file'};
2314 if (!is_deleted
($diffinfo)) { # file exists in result
2315 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2316 hash
=>$diffinfo->{'to_id'},
2317 file_name
=>$to->{'file'});
2319 delete $to->{'href'};
2323 ## ......................................................................
2324 ## parse to array of hashes functions
2326 sub git_get_heads_list
{
2330 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2331 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2332 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2335 while (my $line = <$fd>) {
2339 my ($refinfo, $committerinfo) = split(/\0/, $line);
2340 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2341 my ($committer, $epoch, $tz) =
2342 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2343 $ref_item{'fullname'} = $name;
2344 $name =~ s!^refs/heads/!!;
2346 $ref_item{'name'} = $name;
2347 $ref_item{'id'} = $hash;
2348 $ref_item{'title'} = $title || '(no commit message)';
2349 $ref_item{'epoch'} = $epoch;
2351 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2353 $ref_item{'age'} = "unknown";
2356 push @headslist, \
%ref_item;
2360 return wantarray ?
@headslist : \
@headslist;
2363 sub git_get_tags_list
{
2367 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2368 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
2369 '--format=%(objectname) %(objecttype) %(refname) '.
2370 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2373 while (my $line = <$fd>) {
2377 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2378 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2379 my ($creator, $epoch, $tz) =
2380 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2381 $ref_item{'fullname'} = $name;
2382 $name =~ s!^refs/tags/!!;
2384 $ref_item{'type'} = $type;
2385 $ref_item{'id'} = $id;
2386 $ref_item{'name'} = $name;
2387 if ($type eq "tag") {
2388 $ref_item{'subject'} = $title;
2389 $ref_item{'reftype'} = $reftype;
2390 $ref_item{'refid'} = $refid;
2392 $ref_item{'reftype'} = $type;
2393 $ref_item{'refid'} = $id;
2396 if ($type eq "tag" || $type eq "commit") {
2397 $ref_item{'epoch'} = $epoch;
2399 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2401 $ref_item{'age'} = "unknown";
2405 push @tagslist, \
%ref_item;
2409 return wantarray ?
@tagslist : \
@tagslist;
2412 ## ----------------------------------------------------------------------
2413 ## filesystem-related functions
2415 sub get_file_owner
{
2418 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2419 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2420 if (!defined $gcos) {
2424 $owner =~ s/[,;].*$//;
2425 return to_utf8
($owner);
2428 ## ......................................................................
2429 ## mimetype related functions
2431 sub mimetype_guess_file
{
2432 my $filename = shift;
2433 my $mimemap = shift;
2434 -r
$mimemap or return undef;
2437 open(MIME
, $mimemap) or return undef;
2439 next if m/^#/; # skip comments
2440 my ($mime, $exts) = split(/\t+/);
2441 if (defined $exts) {
2442 my @exts = split(/\s+/, $exts);
2443 foreach my $ext (@exts) {
2444 $mimemap{$ext} = $mime;
2450 $filename =~ /\.([^.]*)$/;
2451 return $mimemap{$1};
2454 sub mimetype_guess
{
2455 my $filename = shift;
2457 $filename =~ /\./ or return undef;
2459 if ($mimetypes_file) {
2460 my $file = $mimetypes_file;
2461 if ($file !~ m!^/!) { # if it is relative path
2462 # it is relative to project
2463 $file = "$projectroot/$project/$file";
2465 $mime = mimetype_guess_file
($filename, $file);
2467 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2473 my $filename = shift;
2476 my $mime = mimetype_guess
($filename);
2477 $mime and return $mime;
2481 return $default_blob_plain_mimetype unless $fd;
2484 return 'text/plain';
2485 } elsif (! $filename) {
2486 return 'application/octet-stream';
2487 } elsif ($filename =~ m/\.png$/i) {
2489 } elsif ($filename =~ m/\.gif$/i) {
2491 } elsif ($filename =~ m/\.jpe?g$/i) {
2492 return 'image/jpeg';
2494 return 'application/octet-stream';
2498 sub blob_contenttype
{
2499 my ($fd, $file_name, $type) = @_;
2501 $type ||= blob_mimetype
($fd, $file_name);
2502 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2503 $type .= "; charset=$default_text_plain_charset";
2509 ## ======================================================================
2510 ## functions printing HTML: header, footer, error page
2512 sub git_header_html
{
2513 my $status = shift || "200 OK";
2514 my $expires = shift;
2516 my $title = "$site_name";
2517 if (defined $project) {
2518 $title .= " - " . to_utf8
($project);
2519 if (defined $action) {
2520 $title .= "/$action";
2521 if (defined $file_name) {
2522 $title .= " - " . esc_path
($file_name);
2523 if ($action eq "tree" && $file_name !~ m
|/$|) {
2530 # require explicit support from the UA if we are to send the page as
2531 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2532 # we have to do this because MSIE sometimes globs '*/*', pretending to
2533 # support xhtml+xml but choking when it gets what it asked for.
2534 if (defined $cgi->http('HTTP_ACCEPT') &&
2535 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2536 $cgi->Accept('application/xhtml+xml') != 0) {
2537 $content_type = 'application/xhtml+xml';
2539 $content_type = 'text/html';
2541 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2542 -status
=> $status, -expires
=> $expires);
2543 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
2545 <?xml version="1.0" encoding="utf-8"?>
2546 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2547 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2548 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2549 <!-- git core binaries version $git_version -->
2551 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2552 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2553 <meta name="robots" content="index, nofollow"/>
2554 <title>$title</title>
2556 # print out each stylesheet that exist
2557 if (defined $stylesheet) {
2558 #provides backwards capability for those people who define style sheet in a config file
2559 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2561 foreach my $stylesheet (@stylesheets) {
2562 next unless $stylesheet;
2563 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2566 if (defined $project) {
2567 my %href_params = get_feed_info
();
2568 if (!exists $href_params{'-title'}) {
2569 $href_params{'-title'} = 'log';
2572 foreach my $format qw(RSS Atom) {
2573 my $type = lc($format);
2575 '-rel' => 'alternate',
2576 '-title' => "$project - $href_params{'-title'} - $format feed",
2577 '-type' => "application/$type+xml"
2580 $href_params{'action'} = $type;
2581 $link_attr{'-href'} = href
(%href_params);
2583 "rel=\"$link_attr{'-rel'}\" ".
2584 "title=\"$link_attr{'-title'}\" ".
2585 "href=\"$link_attr{'-href'}\" ".
2586 "type=\"$link_attr{'-type'}\" ".
2589 $href_params{'extra_options'} = '--no-merges';
2590 $link_attr{'-href'} = href
(%href_params);
2591 $link_attr{'-title'} .= ' (no merges)';
2593 "rel=\"$link_attr{'-rel'}\" ".
2594 "title=\"$link_attr{'-title'}\" ".
2595 "href=\"$link_attr{'-href'}\" ".
2596 "type=\"$link_attr{'-type'}\" ".
2601 printf('<link rel="alternate" title="%s projects list" '.
2602 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2603 $site_name, href
(project
=>undef, action
=>"project_index"));
2604 printf('<link rel="alternate" title="%s projects feeds" '.
2605 'href="%s" type="text/x-opml" />'."\n",
2606 $site_name, href
(project
=>undef, action
=>"opml"));
2608 if (defined $favicon) {
2609 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png" />\n);
2615 if (-f
$site_header) {
2616 open (my $fd, $site_header);
2621 print "<div class=\"page_header\">\n" .
2622 $cgi->a({-href
=> esc_url
($logo_url),
2623 -title
=> $logo_label},
2624 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
2625 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2626 if (defined $project) {
2627 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2628 if (defined $action) {
2635 my ($have_search) = gitweb_check_feature
('search');
2636 if (defined $project && $have_search) {
2637 if (!defined $searchtext) {
2641 if (defined $hash_base) {
2642 $search_hash = $hash_base;
2643 } elsif (defined $hash) {
2644 $search_hash = $hash;
2646 $search_hash = "HEAD";
2648 my $action = $my_uri;
2649 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2650 if ($use_pathinfo) {
2651 $action .= "/".esc_url
($project);
2653 print $cgi->startform(-method
=> "get", -action
=> $action) .
2654 "<div class=\"search\">\n" .
2656 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
2657 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
2658 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
2659 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2660 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2661 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2663 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2664 "<span title=\"Extended regular expression\">" .
2665 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
2666 -checked
=> $search_use_regexp) .
2669 $cgi->end_form() . "\n";
2673 sub git_footer_html
{
2674 my $feed_class = 'rss_logo';
2676 print "<div class=\"page_footer\">\n";
2677 if (defined $project) {
2678 my $descr = git_get_project_description
($project);
2679 if (defined $descr) {
2680 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2683 my %href_params = get_feed_info
();
2684 if (!%href_params) {
2685 $feed_class .= ' generic';
2687 $href_params{'-title'} ||= 'log';
2689 foreach my $format qw(RSS Atom) {
2690 $href_params{'action'} = lc($format);
2691 print $cgi->a({-href
=> href
(%href_params),
2692 -title
=> "$href_params{'-title'} $format feed",
2693 -class => $feed_class}, $format)."\n";
2697 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2698 -class => $feed_class}, "OPML") . " ";
2699 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2700 -class => $feed_class}, "TXT") . "\n";
2702 print "</div>\n"; # class="page_footer"
2704 if (-f
$site_footer) {
2705 open (my $fd, $site_footer);
2715 my $status = shift || "403 Forbidden";
2716 my $error = shift || "Malformed query, file missing or permission denied";
2718 git_header_html
($status);
2720 <div class="page_body">
2730 ## ----------------------------------------------------------------------
2731 ## functions printing or outputting HTML: navigation
2733 sub git_print_page_nav
{
2734 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2735 $extra = '' if !defined $extra; # pager or formats
2737 my @navs = qw(summary shortlog log commit commitdiff tree);
2739 @navs = grep { $_ ne $suppress } @navs;
2742 my %arg = map { $_ => {action
=>$_} } @navs;
2743 if (defined $head) {
2744 for (qw(commit commitdiff)) {
2745 $arg{$_}{'hash'} = $head;
2747 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2748 for (qw(shortlog log)) {
2749 $arg{$_}{'hash'} = $head;
2753 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2754 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2756 print "<div class=\"page_nav\">\n" .
2758 map { $_ eq $current ?
2759 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2761 print "<br/>\n$extra<br/>\n" .
2765 sub format_paging_nav
{
2766 my ($action, $hash, $head, $page, $has_next_link) = @_;
2770 if ($hash ne $head || $page) {
2771 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2773 $paging_nav .= "HEAD";
2777 $paging_nav .= " ⋅ " .
2778 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
2779 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2781 $paging_nav .= " ⋅ prev";
2784 if ($has_next_link) {
2785 $paging_nav .= " ⋅ " .
2786 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
2787 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2789 $paging_nav .= " ⋅ next";
2795 ## ......................................................................
2796 ## functions printing or outputting HTML: div
2798 sub git_print_header_div
{
2799 my ($action, $title, $hash, $hash_base) = @_;
2802 $args{'action'} = $action;
2803 $args{'hash'} = $hash if $hash;
2804 $args{'hash_base'} = $hash_base if $hash_base;
2806 print "<div class=\"header\">\n" .
2807 $cgi->a({-href
=> href
(%args), -class => "title"},
2808 $title ?
$title : $action) .
2812 #sub git_print_authorship (\%) {
2813 sub git_print_authorship
{
2816 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2817 print "<div class=\"author_date\">" .
2818 esc_html
($co->{'author_name'}) .
2820 if ($ad{'hour_local'} < 6) {
2821 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2822 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2824 printf(" (%02d:%02d %s)",
2825 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2830 sub git_print_page_path
{
2836 print "<div class=\"page_path\">";
2837 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2838 -title
=> 'tree root'}, to_utf8
("[$project]"));
2840 if (defined $name) {
2841 my @dirname = split '/', $name;
2842 my $basename = pop @dirname;
2845 foreach my $dir (@dirname) {
2846 $fullname .= ($fullname ?
'/' : '') . $dir;
2847 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2849 -title
=> $fullname}, esc_path
($dir));
2852 if (defined $type && $type eq 'blob') {
2853 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2855 -title
=> $name}, esc_path
($basename));
2856 } elsif (defined $type && $type eq 'tree') {
2857 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2859 -title
=> $name}, esc_path
($basename));
2862 print esc_path
($basename);
2865 print "<br/></div>\n";
2868 # sub git_print_log (\@;%) {
2869 sub git_print_log
($;%) {
2873 if ($opts{'-remove_title'}) {
2874 # remove title, i.e. first line of log
2877 # remove leading empty lines
2878 while (defined $log->[0] && $log->[0] eq "") {
2885 foreach my $line (@
$log) {
2886 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2889 if (! $opts{'-remove_signoff'}) {
2890 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2893 # remove signoff lines
2900 # print only one empty line
2901 # do not print empty line after signoff
2903 next if ($empty || $signoff);
2909 print format_log_line_html
($line) . "<br/>\n";
2912 if ($opts{'-final_empty_line'}) {
2913 # end with single empty line
2914 print "<br/>\n" unless $empty;
2918 # return link target (what link points to)
2919 sub git_get_link_target
{
2924 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2928 $link_target = <$fd>;
2933 return $link_target;
2936 # given link target, and the directory (basedir) the link is in,
2937 # return target of link relative to top directory (top tree);
2938 # return undef if it is not possible (including absolute links).
2939 sub normalize_link_target
{
2940 my ($link_target, $basedir, $hash_base) = @_;
2942 # we can normalize symlink target only if $hash_base is provided
2943 return unless $hash_base;
2945 # absolute symlinks (beginning with '/') cannot be normalized
2946 return if (substr($link_target, 0, 1) eq '/');
2948 # normalize link target to path from top (root) tree (dir)
2951 $path = $basedir . '/' . $link_target;
2953 # we are in top (root) tree (dir)
2954 $path = $link_target;
2957 # remove //, /./, and /../
2959 foreach my $part (split('/', $path)) {
2960 # discard '.' and ''
2961 next if (!$part || $part eq '.');
2963 if ($part eq '..') {
2967 # link leads outside repository (outside top dir)
2971 push @path_parts, $part;
2974 $path = join('/', @path_parts);
2979 # print tree entry (row of git_tree), but without encompassing <tr> element
2980 sub git_print_tree_entry
{
2981 my ($t, $basedir, $hash_base, $have_blame) = @_;
2984 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2986 # The format of a table row is: mode list link. Where mode is
2987 # the mode of the entry, list is the name of the entry, an href,
2988 # and link is the action links of the entry.
2990 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2991 if ($t->{'type'} eq "blob") {
2992 print "<td class=\"list\">" .
2993 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2994 file_name
=>"$basedir$t->{'name'}", %base_key),
2995 -class => "list"}, esc_path
($t->{'name'}));
2996 if (S_ISLNK
(oct $t->{'mode'})) {
2997 my $link_target = git_get_link_target
($t->{'hash'});
2999 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
3000 if (defined $norm_target) {
3002 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3003 file_name
=>$norm_target),
3004 -title
=> $norm_target}, esc_path
($link_target));
3006 print " -> " . esc_path
($link_target);
3011 print "<td class=\"link\">";
3012 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3013 file_name
=>"$basedir$t->{'name'}", %base_key)},
3017 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3018 file_name
=>"$basedir$t->{'name'}", %base_key)},
3021 if (defined $hash_base) {
3023 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3024 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3028 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3029 file_name
=>"$basedir$t->{'name'}")},
3033 } elsif ($t->{'type'} eq "tree") {
3034 print "<td class=\"list\">";
3035 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3036 file_name
=>"$basedir$t->{'name'}", %base_key)},
3037 esc_path
($t->{'name'}));
3039 print "<td class=\"link\">";
3040 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3041 file_name
=>"$basedir$t->{'name'}", %base_key)},
3043 if (defined $hash_base) {
3045 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3046 file_name
=>"$basedir$t->{'name'}")},
3051 # unknown object: we can only present history for it
3052 # (this includes 'commit' object, i.e. submodule support)
3053 print "<td class=\"list\">" .
3054 esc_path
($t->{'name'}) .
3056 print "<td class=\"link\">";
3057 if (defined $hash_base) {
3058 print $cgi->a({-href
=> href
(action
=>"history",
3059 hash_base
=>$hash_base,
3060 file_name
=>"$basedir$t->{'name'}")},
3067 ## ......................................................................
3068 ## functions printing large fragments of HTML
3070 # get pre-image filenames for merge (combined) diff
3071 sub fill_from_file_info
{
3072 my ($diff, @parents) = @_;
3074 $diff->{'from_file'} = [ ];
3075 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3076 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3077 if ($diff->{'status'}[$i] eq 'R' ||
3078 $diff->{'status'}[$i] eq 'C') {
3079 $diff->{'from_file'}[$i] =
3080 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3087 # is current raw difftree line of file deletion
3089 my $diffinfo = shift;
3091 return $diffinfo->{'to_id'} eq ('0' x
40);
3094 # does patch correspond to [previous] difftree raw line
3095 # $diffinfo - hashref of parsed raw diff format
3096 # $patchinfo - hashref of parsed patch diff format
3097 # (the same keys as in $diffinfo)
3098 sub is_patch_split
{
3099 my ($diffinfo, $patchinfo) = @_;
3101 return defined $diffinfo && defined $patchinfo
3102 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3106 sub git_difftree_body
{
3107 my ($difftree, $hash, @parents) = @_;
3108 my ($parent) = $parents[0];
3109 my ($have_blame) = gitweb_check_feature
('blame');
3110 print "<div class=\"list_head\">\n";
3111 if ($#{$difftree} > 10) {
3112 print(($#{$difftree} + 1) . " files changed:\n");
3116 print "<table class=\"" .
3117 (@parents > 1 ?
"combined " : "") .
3120 # header only for combined diff in 'commitdiff' view
3121 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
3124 print "<thead><tr>\n" .
3125 "<th></th><th></th>\n"; # filename, patchN link
3126 for (my $i = 0; $i < @parents; $i++) {
3127 my $par = $parents[$i];
3129 $cgi->a({-href
=> href
(action
=>"commitdiff",
3130 hash
=>$hash, hash_parent
=>$par),
3131 -title
=> 'commitdiff to parent number ' .
3132 ($i+1) . ': ' . substr($par,0,7)},
3136 print "</tr></thead>\n<tbody>\n";
3141 foreach my $line (@
{$difftree}) {
3142 my $diff = parsed_difftree_line
($line);
3145 print "<tr class=\"dark\">\n";
3147 print "<tr class=\"light\">\n";
3151 if (exists $diff->{'nparents'}) { # combined diff
3153 fill_from_file_info
($diff, @parents)
3154 unless exists $diff->{'from_file'};
3156 if (!is_deleted
($diff)) {
3157 # file exists in the result (child) commit
3159 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3160 file_name
=>$diff->{'to_file'},
3162 -class => "list"}, esc_path
($diff->{'to_file'})) .
3166 esc_path
($diff->{'to_file'}) .
3170 if ($action eq 'commitdiff') {
3173 print "<td class=\"link\">" .
3174 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3179 my $has_history = 0;
3180 my $not_deleted = 0;
3181 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3182 my $hash_parent = $parents[$i];
3183 my $from_hash = $diff->{'from_id'}[$i];
3184 my $from_path = $diff->{'from_file'}[$i];
3185 my $status = $diff->{'status'}[$i];
3187 $has_history ||= ($status ne 'A');
3188 $not_deleted ||= ($status ne 'D');
3190 if ($status eq 'A') {
3191 print "<td class=\"link\" align=\"right\"> | </td>\n";
3192 } elsif ($status eq 'D') {
3193 print "<td class=\"link\">" .
3194 $cgi->a({-href
=> href
(action
=>"blob",
3197 file_name
=>$from_path)},
3201 if ($diff->{'to_id'} eq $from_hash) {
3202 print "<td class=\"link nochange\">";
3204 print "<td class=\"link\">";
3206 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3207 hash
=>$diff->{'to_id'},
3208 hash_parent
=>$from_hash,
3210 hash_parent_base
=>$hash_parent,
3211 file_name
=>$diff->{'to_file'},
3212 file_parent
=>$from_path)},
3218 print "<td class=\"link\">";
3220 print $cgi->a({-href
=> href
(action
=>"blob",
3221 hash
=>$diff->{'to_id'},
3222 file_name
=>$diff->{'to_file'},
3225 print " | " if ($has_history);
3228 print $cgi->a({-href
=> href
(action
=>"history",
3229 file_name
=>$diff->{'to_file'},
3236 next; # instead of 'else' clause, to avoid extra indent
3238 # else ordinary diff
3240 my ($to_mode_oct, $to_mode_str, $to_file_type);
3241 my ($from_mode_oct, $from_mode_str, $from_file_type);
3242 if ($diff->{'to_mode'} ne ('0' x
6)) {
3243 $to_mode_oct = oct $diff->{'to_mode'};
3244 if (S_ISREG
($to_mode_oct)) { # only for regular file
3245 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3247 $to_file_type = file_type
($diff->{'to_mode'});
3249 if ($diff->{'from_mode'} ne ('0' x
6)) {
3250 $from_mode_oct = oct $diff->{'from_mode'};
3251 if (S_ISREG
($to_mode_oct)) { # only for regular file
3252 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3254 $from_file_type = file_type
($diff->{'from_mode'});
3257 if ($diff->{'status'} eq "A") { # created
3258 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3259 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3260 $mode_chng .= "]</span>";
3262 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3263 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3264 -class => "list"}, esc_path
($diff->{'file'}));
3266 print "<td>$mode_chng</td>\n";
3267 print "<td class=\"link\">";
3268 if ($action eq 'commitdiff') {
3271 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3274 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3275 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3279 } elsif ($diff->{'status'} eq "D") { # deleted
3280 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3282 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3283 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3284 -class => "list"}, esc_path
($diff->{'file'}));
3286 print "<td>$mode_chng</td>\n";
3287 print "<td class=\"link\">";
3288 if ($action eq 'commitdiff') {
3291 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3294 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3295 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3298 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3299 file_name
=>$diff->{'file'})},
3302 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3303 file_name
=>$diff->{'file'})},
3307 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3308 my $mode_chnge = "";
3309 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3310 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3311 if ($from_file_type ne $to_file_type) {
3312 $mode_chnge .= " from $from_file_type to $to_file_type";
3314 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3315 if ($from_mode_str && $to_mode_str) {
3316 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3317 } elsif ($to_mode_str) {
3318 $mode_chnge .= " mode: $to_mode_str";
3321 $mode_chnge .= "]</span>\n";