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 = "++GIT_VERSION++";
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 = "++GIT_BINDIR++/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "++GITWEB_PROJECTROOT++";
38 # target of the home link on top of all pages
39 our $home_link = $my_uri || "/";
41 # string of the home link on top of all pages
42 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
44 # name of your site or organization to appear in page titles
45 # replace this with something more descriptive for clearer bookmarks
46 our $site_name = "++GITWEB_SITENAME++"
47 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
49 # filename of html text to include at top of each page
50 our $site_header = "++GITWEB_SITE_HEADER++";
51 # html text to include at home page
52 our $home_text = "++GITWEB_HOMETEXT++";
53 # filename of html text to include at bottom of each page
54 our $site_footer = "++GITWEB_SITE_FOOTER++";
57 our @stylesheets = ("++GITWEB_CSS++");
58 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
59 our $stylesheet = undef;
61 # URI of GIT logo (72x27 size)
62 our $logo = "++GITWEB_LOGO++";
63 # URI of GIT favicon, assumed to be image/png type
64 our $favicon = "++GITWEB_FAVICON++";
66 # URI and label (title) of GIT logo link
67 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
68 #our $logo_label = "git documentation";
69 our $logo_url = "http://git.or.cz/";
70 our $logo_label = "git homepage";
72 # source of projects list
73 our $projects_list = "++GITWEB_LIST++";
75 # default order of projects list
76 # valid values are none, project, descr, owner, and age
77 our $default_projects_order = "project";
79 # show repository only if this file exists
80 # (only effective if this variable evaluates to true)
81 our $export_ok = "++GITWEB_EXPORT_OK++";
83 # only allow viewing of repositories also shown on the overview page
84 our $strict_export = "++GITWEB_STRICT_EXPORT++";
86 # list of git base URLs used for URL to where fetch project from,
87 # i.e. full URL is "$git_base_url/$project"
88 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
90 # default blob_plain mimetype and default charset for text/plain blob
91 our $default_blob_plain_mimetype = 'text/plain';
92 our $default_text_plain_charset = undef;
94 # file to use for guessing MIME types before trying /etc/mime.types
95 # (relative to the current git repository)
96 our $mimetypes_file = undef;
98 # assume this charset if line contains non-UTF-8 characters;
99 # it should be valid encoding (see Encoding::Supported(3pm) for list),
100 # for which encoding all byte sequences are valid, for example
101 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
102 # could be even 'utf-8' for the old behavior)
103 our $fallback_encoding = 'latin1';
105 # You define site-wide feature defaults here; override them with
106 # $GITWEB_CONFIG as necessary.
109 # 'sub' => feature-sub (subroutine),
110 # 'override' => allow-override (boolean),
111 # 'default' => [ default options...] (array reference)}
113 # if feature is overridable (it means that allow-override has true value),
114 # then feature-sub will be called with default options as parameters;
115 # return value of feature-sub indicates if to enable specified feature
117 # if there is no 'sub' key (no feature-sub), then feature cannot be
120 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
122 # Enable the 'blame' blob view, showing the last commit that modified
123 # each line in the file. This can be very CPU-intensive.
125 # To enable system wide have in $GITWEB_CONFIG
126 # $feature{'blame'}{'default'} = [1];
127 # To have project specific config enable override in $GITWEB_CONFIG
128 # $feature{'blame'}{'override'} = 1;
129 # and in project config gitweb.blame = 0|1;
131 'sub' => \
&feature_blame
,
135 # Enable the 'snapshot' link, providing a compressed tarball of any
136 # tree. This can potentially generate high traffic if you have large
139 # To disable system wide have in $GITWEB_CONFIG
140 # $feature{'snapshot'}{'default'} = [undef];
141 # To have project specific config enable override in $GITWEB_CONFIG
142 # $feature{'snapshot'}{'override'} = 1;
143 # and in project config gitweb.snapshot = none|gzip|bzip2|zip;
145 'sub' => \
&feature_snapshot
,
147 # => [content-encoding, suffix, program]
148 'default' => ['x-gzip', 'gz', 'gzip']},
150 # Enable text search, which will list the commits which match author,
151 # committer or commit text to a given string. Enabled by default.
152 # Project specific override is not supported.
157 # Enable grep search, which will list the files in currently selected
158 # tree containing the given string. Enabled by default. This can be
159 # potentially CPU-intensive, of course.
161 # To enable system wide have in $GITWEB_CONFIG
162 # $feature{'grep'}{'default'} = [1];
163 # To have project specific config enable override in $GITWEB_CONFIG
164 # $feature{'grep'}{'override'} = 1;
165 # and in project config gitweb.grep = 0|1;
170 # Enable the pickaxe search, which will list the commits that modified
171 # a given string in a file. This can be practical and quite faster
172 # alternative to 'blame', but still potentially CPU-intensive.
174 # To enable system wide have in $GITWEB_CONFIG
175 # $feature{'pickaxe'}{'default'} = [1];
176 # To have project specific config enable override in $GITWEB_CONFIG
177 # $feature{'pickaxe'}{'override'} = 1;
178 # and in project config gitweb.pickaxe = 0|1;
180 'sub' => \
&feature_pickaxe
,
184 # Make gitweb use an alternative format of the URLs which can be
185 # more readable and natural-looking: project name is embedded
186 # directly in the path and the query string contains other
187 # auxiliary information. All gitweb installations recognize
188 # URL in either format; this configures in which formats gitweb
191 # To enable system wide have in $GITWEB_CONFIG
192 # $feature{'pathinfo'}{'default'} = [1];
193 # Project specific override is not supported.
195 # Note that you will need to change the default location of CSS,
196 # favicon, logo and possibly other files to an absolute URL. Also,
197 # if gitweb.cgi serves as your indexfile, you will need to force
198 # $my_uri to contain the script name in your $GITWEB_CONFIG.
203 # Make gitweb consider projects in project root subdirectories
204 # to be forks of existing projects. Given project $projname.git,
205 # projects matching $projname/*.git will not be shown in the main
206 # projects list, instead a '+' mark will be added to $projname
207 # there and a 'forks' view will be enabled for the project, listing
208 # all the forks. If project list is taken from a file, forks have
209 # to be listed after the main project.
211 # To enable system wide have in $GITWEB_CONFIG
212 # $feature{'forks'}{'default'} = [1];
213 # Project specific override is not supported.
219 sub gitweb_check_feature
{
221 return unless exists $feature{$name};
222 my ($sub, $override, @defaults) = (
223 $feature{$name}{'sub'},
224 $feature{$name}{'override'},
225 @{$feature{$name}{'default'}});
226 if (!$override) { return @defaults; }
228 warn "feature $name is not overrideable";
231 return $sub->(@defaults);
235 my ($val) = git_get_project_config
('blame', '--bool');
237 if ($val eq 'true') {
239 } elsif ($val eq 'false') {
246 sub feature_snapshot
{
247 my ($ctype, $suffix, $command) = @_;
249 my ($val) = git_get_project_config
('snapshot');
251 if ($val eq 'gzip') {
252 return ('x-gzip', 'gz', 'gzip');
253 } elsif ($val eq 'bzip2') {
254 return ('x-bzip2', 'bz2', 'bzip2');
255 } elsif ($val eq 'zip') {
256 return ('x-zip', 'zip', '');
257 } elsif ($val eq 'none') {
261 return ($ctype, $suffix, $command);
264 sub gitweb_have_snapshot
{
265 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
266 my $have_snapshot = (defined $ctype && defined $suffix);
268 return $have_snapshot;
272 my ($val) = git_get_project_config
('grep', '--bool');
274 if ($val eq 'true') {
276 } elsif ($val eq 'false') {
283 sub feature_pickaxe
{
284 my ($val) = git_get_project_config
('pickaxe', '--bool');
286 if ($val eq 'true') {
288 } elsif ($val eq 'false') {
295 # checking HEAD file with -e is fragile if the repository was
296 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
298 sub check_head_link
{
300 my $headfile = "$dir/HEAD";
301 return ((-e
$headfile) ||
302 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
305 sub check_export_ok
{
307 return (check_head_link
($dir) &&
308 (!$export_ok || -e
"$dir/$export_ok"));
311 # rename detection options for git-diff and git-diff-tree
312 # - default is '-M', with the cost proportional to
313 # (number of removed files) * (number of new files).
314 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
315 # (number of changed files + number of removed files) * (number of new files)
316 # - even more costly is '-C', '--find-copies-harder' with cost
317 # (number of files in the original tree) * (number of new files)
318 # - one might want to include '-B' option, e.g. '-B', '-M'
319 our @diff_opts = ('-M'); # taken from git_commit
321 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
322 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
324 # version of the core git binary
325 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
327 $projects_list ||= $projectroot;
329 # ======================================================================
330 # input validation and dispatch
331 our $action = $cgi->param('a');
332 if (defined $action) {
333 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
334 die_error
(undef, "Invalid action parameter");
338 # parameters which are pathnames
339 our $project = $cgi->param('p');
340 if (defined $project) {
341 if (!validate_pathname
($project) ||
342 !(-d
"$projectroot/$project") ||
343 !check_head_link
("$projectroot/$project") ||
344 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
345 ($strict_export && !project_in_list
($project))) {
347 die_error
(undef, "No such project");
351 our $file_name = $cgi->param('f');
352 if (defined $file_name) {
353 if (!validate_pathname
($file_name)) {
354 die_error
(undef, "Invalid file parameter");
358 our $file_parent = $cgi->param('fp');
359 if (defined $file_parent) {
360 if (!validate_pathname
($file_parent)) {
361 die_error
(undef, "Invalid file parent parameter");
365 # parameters which are refnames
366 our $hash = $cgi->param('h');
368 if (!validate_refname
($hash)) {
369 die_error
(undef, "Invalid hash parameter");
373 our $hash_parent = $cgi->param('hp');
374 if (defined $hash_parent) {
375 if (!validate_refname
($hash_parent)) {
376 die_error
(undef, "Invalid hash parent parameter");
380 our $hash_base = $cgi->param('hb');
381 if (defined $hash_base) {
382 if (!validate_refname
($hash_base)) {
383 die_error
(undef, "Invalid hash base parameter");
387 our $hash_parent_base = $cgi->param('hpb');
388 if (defined $hash_parent_base) {
389 if (!validate_refname
($hash_parent_base)) {
390 die_error
(undef, "Invalid hash parent base parameter");
395 our $page = $cgi->param('pg');
397 if ($page =~ m/[^0-9]/) {
398 die_error
(undef, "Invalid page parameter");
402 our $searchtype = $cgi->param('st');
403 if (defined $searchtype) {
404 if ($searchtype =~ m/[^a-z]/) {
405 die_error
(undef, "Invalid searchtype parameter");
409 our $searchtext = $cgi->param('s');
411 if (defined $searchtext) {
412 if ($searchtype ne 'grep' and $searchtype ne 'pickaxe' and $searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
413 die_error
(undef, "Invalid search parameter");
415 if (length($searchtext) < 2) {
416 die_error
(undef, "At least two characters are required for search parameter");
418 $search_regexp = quotemeta $searchtext;
421 # now read PATH_INFO and use it as alternative to parameters
422 sub evaluate_path_info
{
423 return if defined $project;
424 my $path_info = $ENV{"PATH_INFO"};
425 return if !$path_info;
426 $path_info =~ s
,^/+,,;
427 return if !$path_info;
428 # find which part of PATH_INFO is project
429 $project = $path_info;
431 while ($project && !check_head_link
("$projectroot/$project")) {
432 $project =~ s
,/*[^/]*$,,;
435 $project = validate_pathname
($project);
437 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
438 ($strict_export && !project_in_list
($project))) {
442 # do not change any parameters if an action is given using the query string
444 $path_info =~ s
,^$project/*,,;
445 my ($refname, $pathname) = split(/:/, $path_info, 2);
446 if (defined $pathname) {
447 # we got "project.git/branch:filename" or "project.git/branch:dir/"
448 # we could use git_get_type(branch:pathname), but it needs $git_dir
449 $pathname =~ s
,^/+,,;
450 if (!$pathname || substr($pathname, -1) eq "/") {
454 $action ||= "blob_plain";
456 $hash_base ||= validate_refname
($refname);
457 $file_name ||= validate_pathname
($pathname);
458 } elsif (defined $refname) {
459 # we got "project.git/branch"
460 $action ||= "shortlog";
461 $hash ||= validate_refname
($refname);
464 evaluate_path_info
();
466 # path to the current git repository
468 $git_dir = "$projectroot/$project" if $project;
472 "blame" => \
&git_blame2
,
473 "blobdiff" => \
&git_blobdiff
,
474 "blobdiff_plain" => \
&git_blobdiff_plain
,
475 "blob" => \
&git_blob
,
476 "blob_plain" => \
&git_blob_plain
,
477 "commitdiff" => \
&git_commitdiff
,
478 "commitdiff_plain" => \
&git_commitdiff_plain
,
479 "commit" => \
&git_commit
,
480 "forks" => \
&git_forks
,
481 "heads" => \
&git_heads
,
482 "history" => \
&git_history
,
485 "atom" => \
&git_atom
,
486 "search" => \
&git_search
,
487 "search_help" => \
&git_search_help
,
488 "shortlog" => \
&git_shortlog
,
489 "summary" => \
&git_summary
,
491 "tags" => \
&git_tags
,
492 "tree" => \
&git_tree
,
493 "snapshot" => \
&git_snapshot
,
494 "object" => \
&git_object
,
495 # those below don't need $project
496 "opml" => \
&git_opml
,
497 "project_list" => \
&git_project_list
,
498 "project_index" => \
&git_project_index
,
501 if (!defined $action) {
503 $action = git_get_type
($hash);
504 } elsif (defined $hash_base && defined $file_name) {
505 $action = git_get_type
("$hash_base:$file_name");
506 } elsif (defined $project) {
509 $action = 'project_list';
512 if (!defined($actions{$action})) {
513 die_error
(undef, "Unknown action");
515 if ($action !~ m/^(opml|project_list|project_index)$/ &&
517 die_error
(undef, "Project needed");
519 $actions{$action}->();
522 ## ======================================================================
527 # default is to use -absolute url() i.e. $my_uri
528 my $href = $params{-full
} ? $my_url : $my_uri;
530 # XXX: Warning: If you touch this, check the search form for updating,
541 hash_parent_base
=> "hpb",
547 my %mapping = @mapping;
549 $params{'project'} = $project unless exists $params{'project'};
551 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
553 # use PATH_INFO for project name
554 $href .= "/$params{'project'}" if defined $params{'project'};
555 delete $params{'project'};
557 # Summary just uses the project path URL
558 if (defined $params{'action'} && $params{'action'} eq 'summary') {
559 delete $params{'action'};
563 # now encode the parameters explicitly
565 for (my $i = 0; $i < @mapping; $i += 2) {
566 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
567 if (defined $params{$name}) {
568 push @result, $symbol . "=" . esc_param
($params{$name});
571 $href .= "?" . join(';', @result) if scalar @result;
577 ## ======================================================================
578 ## validation, quoting/unquoting and escaping
580 sub validate_pathname
{
581 my $input = shift || return undef;
583 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
584 # at the beginning, at the end, and between slashes.
585 # also this catches doubled slashes
586 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
590 if ($input =~ m!\0!) {
596 sub validate_refname
{
597 my $input = shift || return undef;
599 # textual hashes are O.K.
600 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
603 # it must be correct pathname
604 $input = validate_pathname
($input)
606 # restrictions on ref name according to git-check-ref-format
607 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
613 # decode sequences of octets in utf8 into Perl's internal form,
614 # which is utf-8 with utf8 flag set if needed. gitweb writes out
615 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
619 eval { $res = decode_utf8
($str, Encode
::FB_CROAK
); };
623 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
627 # quote unsafe chars, but keep the slash, even when it's not
628 # correct, but quoted slashes look too horrible in bookmarks
631 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
637 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
640 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
646 # replace invalid utf8 character with SUBSTITUTION sequence
651 $str = to_utf8
($str);
652 $str = $cgi->escapeHTML($str);
653 if ($opts{'-nbsp'}) {
654 $str =~ s/ / /g;
656 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
660 # quote control characters and escape filename to HTML
665 $str = to_utf8
($str);
666 $str = $cgi->escapeHTML($str);
667 if ($opts{'-nbsp'}) {
668 $str =~ s/ / /g;
670 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
674 # Make control characters "printable", using character escape codes (CEC)
677 my %es = ( # character escape codes, aka escape sequences
678 "\t" => '\t', # tab (HT)
679 "\n" => '\n', # line feed (LF)
680 "\r" => '\r', # carrige return (CR)
681 "\f" => '\f', # form feed (FF)
682 "\b" => '\b', # backspace (BS)
683 "\a" => '\a', # alarm (bell) (BEL)
684 "\e" => '\e', # escape (ESC)
685 "\013" => '\v', # vertical tab (VT)
686 "\000" => '\0', # nul character (NUL)
688 my $chr = ( (exists $es{$cntrl})
690 : sprintf('\%03o', ord($cntrl)) );
691 return "<span class=\"cntrl\">$chr</span>";
694 # Alternatively use unicode control pictures codepoints,
695 # Unicode "printable representation" (PR)
698 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
699 return "<span class=\"cntrl\">$chr</span>";
702 # git may return quoted and escaped filenames
708 my %es = ( # character escape codes, aka escape sequences
709 't' => "\t", # tab (HT, TAB)
710 'n' => "\n", # newline (NL)
711 'r' => "\r", # return (CR)
712 'f' => "\f", # form feed (FF)
713 'b' => "\b", # backspace (BS)
714 'a' => "\a", # alarm (bell) (BEL)
715 'e' => "\e", # escape (ESC)
716 'v' => "\013", # vertical tab (VT)
719 if ($seq =~ m/^[0-7]{1,3}$/) {
720 # octal char sequence
721 return chr(oct($seq));
722 } elsif (exists $es{$seq}) {
723 # C escape sequence, aka character escape code
726 # quoted ordinary character
730 if ($str =~ m/^"(.*)"$/) {
733 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
738 # escape tabs (convert tabs to spaces)
742 while ((my $pos = index($line, "\t")) != -1) {
743 if (my $count = (8 - ($pos % 8))) {
744 my $spaces = ' ' x
$count;
745 $line =~ s/\t/$spaces/;
752 sub project_in_list
{
754 my @list = git_get_projects_list
();
755 return @list && scalar(grep { $_->{'path'} eq $project } @list);
758 ## ----------------------------------------------------------------------
759 ## HTML aware string manipulation
764 my $add_len = shift || 10;
766 # allow only $len chars, but don't cut a word if it would fit in $add_len
767 # if it doesn't fit, cut it if it's still longer than the dots we would add
768 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
771 if (length($tail) > 4) {
773 $body =~ s/&[^;]*$//; # remove chopped character entities
778 ## ----------------------------------------------------------------------
779 ## functions returning short strings
781 # CSS class for given age value (in seconds)
787 } elsif ($age < 60*60*2) {
789 } elsif ($age < 60*60*24*2) {
796 # convert age in seconds to "nn units ago" string
801 if ($age > 60*60*24*365*2) {
802 $age_str = (int $age/60/60/24/365);
803 $age_str .= " years ago";
804 } elsif ($age > 60*60*24*(365/12)*2) {
805 $age_str = int $age/60/60/24/(365/12);
806 $age_str .= " months ago";
807 } elsif ($age > 60*60*24*7*2) {
808 $age_str = int $age/60/60/24/7;
809 $age_str .= " weeks ago";
810 } elsif ($age > 60*60*24*2) {
811 $age_str = int $age/60/60/24;
812 $age_str .= " days ago";
813 } elsif ($age > 60*60*2) {
814 $age_str = int $age/60/60;
815 $age_str .= " hours ago";
816 } elsif ($age > 60*2) {
817 $age_str = int $age/60;
818 $age_str .= " min ago";
821 $age_str .= " sec ago";
823 $age_str .= " right now";
828 # convert file mode in octal to symbolic file mode string
830 my $mode = oct shift;
832 if (S_ISDIR
($mode & S_IFMT
)) {
834 } elsif (S_ISLNK
($mode)) {
836 } elsif (S_ISREG
($mode)) {
837 # git cares only about the executable bit
838 if ($mode & S_IXUSR
) {
848 # convert file mode in octal to file type string
852 if ($mode !~ m/^[0-7]+$/) {
858 if (S_ISDIR
($mode & S_IFMT
)) {
860 } elsif (S_ISLNK
($mode)) {
862 } elsif (S_ISREG
($mode)) {
869 # convert file mode in octal to file type description string
873 if ($mode !~ m/^[0-7]+$/) {
879 if (S_ISDIR
($mode & S_IFMT
)) {
881 } elsif (S_ISLNK
($mode)) {
883 } elsif (S_ISREG
($mode)) {
884 if ($mode & S_IXUSR
) {
895 ## ----------------------------------------------------------------------
896 ## functions returning short HTML fragments, or transforming HTML fragments
897 ## which don't belong to other sections
899 # format line of commit message.
900 sub format_log_line_html
{
903 $line = esc_html
($line, -nbsp
=>1);
904 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
907 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
908 -class => "text"}, $hash_text);
909 $line =~ s/$hash_text/$link/;
914 # format marker of refs pointing to given object
915 sub format_ref_marker
{
916 my ($refs, $id) = @_;
919 if (defined $refs->{$id}) {
920 foreach my $ref (@{$refs->{$id}}) {
921 my ($type, $name) = qw();
922 # e.g. tags/v2.6.11 or heads/next
923 if ($ref =~ m!^(.*?)s?/(.*)$!) {
931 $markers .= " <span class=\"$type\" title=\"$ref\">" .
932 esc_html
($name) . "</span>";
937 return ' <span class="refs">'. $markers . '</span>';
943 # format, perhaps shortened and with markers, title line
944 sub format_subject_html
{
945 my ($long, $short, $href, $extra) = @_;
946 $extra = '' unless defined($extra);
948 if (length($short) < length($long)) {
949 return $cgi->a({-href
=> $href, -class => "list subject",
950 -title
=> to_utf8
($long)},
951 esc_html
($short) . $extra);
953 return $cgi->a({-href
=> $href, -class => "list subject"},
954 esc_html
($long) . $extra);
958 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
959 sub format_git_diff_header_line
{
961 my $diffinfo = shift;
962 my ($from, $to) = @_;
964 if ($diffinfo->{'nparents'}) {
966 $line =~ s!^(diff (.*?) )"?.*$!$1!;
968 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
969 esc_path
($to->{'file'}));
970 } else { # file was deleted (no href)
971 $line .= esc_path
($to->{'file'});
975 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
976 if ($from->{'href'}) {
977 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
978 'a/' . esc_path
($from->{'file'}));
979 } else { # file was added (no href)
980 $line .= 'a/' . esc_path
($from->{'file'});
984 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
985 'b/' . esc_path
($to->{'file'}));
986 } else { # file was deleted
987 $line .= 'b/' . esc_path
($to->{'file'});
991 return "<div class=\"diff header\">$line</div>\n";
994 # format extended diff header line, before patch itself
995 sub format_extended_diff_header_line
{
997 my $diffinfo = shift;
998 my ($from, $to) = @_;
1001 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1002 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1003 esc_path
($from->{'file'}));
1005 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1006 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1007 esc_path
($to->{'file'}));
1009 # match single <mode>
1010 if ($line =~ m/\s(\d{6})$/) {
1011 $line .= '<span class="info"> (' .
1012 file_type_long
($1) .
1016 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1017 # can match only for combined diff
1019 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1020 if ($from->{'href'}[$i]) {
1021 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1023 substr($diffinfo->{'from_id'}[$i],0,7));
1028 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1031 if ($to->{'href'}) {
1032 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1033 substr($diffinfo->{'to_id'},0,7));
1038 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1039 # can match only for ordinary diff
1040 my ($from_link, $to_link);
1041 if ($from->{'href'}) {
1042 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1043 substr($diffinfo->{'from_id'},0,7));
1045 $from_link = '0' x
7;
1047 if ($to->{'href'}) {
1048 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1049 substr($diffinfo->{'to_id'},0,7));
1053 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1054 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1057 return $line . "<br/>\n";
1060 # format from-file/to-file diff header
1061 sub format_diff_from_to_header
{
1062 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1067 #assert($line =~ m/^---/) if DEBUG;
1068 # no extra formatting for "^--- /dev/null"
1069 if (! $diffinfo->{'nparents'}) {
1070 # ordinary (single parent) diff
1071 if ($line =~ m!^--- "?a/!) {
1072 if ($from->{'href'}) {
1074 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1075 esc_path
($from->{'file'}));
1078 esc_path
($from->{'file'});
1081 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1084 # combined diff (merge commit)
1085 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1086 if ($from->{'href'}[$i]) {
1088 $cgi->a({-href
=>href
(action
=>"blobdiff",
1089 hash_parent
=>$diffinfo->{'from_id'}[$i],
1090 hash_parent_base
=>$parents[$i],
1091 file_parent
=>$from->{'file'}[$i],
1092 hash
=>$diffinfo->{'to_id'},
1094 file_name
=>$to->{'file'}),
1096 -title
=>"diff" . ($i+1)},
1099 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1100 esc_path
($from->{'file'}[$i]));
1102 $line = '--- /dev/null';
1104 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1109 #assert($line =~ m/^\+\+\+/) if DEBUG;
1110 # no extra formatting for "^+++ /dev/null"
1111 if ($line =~ m!^\+\+\+ "?b/!) {
1112 if ($to->{'href'}) {
1114 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1115 esc_path
($to->{'file'}));
1118 esc_path
($to->{'file'});
1121 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1126 # create note for patch simplified by combined diff
1127 sub format_diff_cc_simplified
{
1128 my ($diffinfo, @parents) = @_;
1131 $result .= "<div class=\"diff header\">" .
1133 if (!is_deleted
($diffinfo)) {
1134 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1136 hash
=>$diffinfo->{'to_id'},
1137 file_name
=>$diffinfo->{'to_file'}),
1139 esc_path
($diffinfo->{'to_file'}));
1141 $result .= esc_path
($diffinfo->{'to_file'});
1143 $result .= "</div>\n" . # class="diff header"
1144 "<div class=\"diff nodifferences\">" .
1146 "</div>\n"; # class="diff nodifferences"
1151 # format patch (diff) line (not to be used for diff headers)
1152 sub format_diff_line
{
1154 my ($from, $to) = @_;
1155 my $diff_class = "";
1159 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1161 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1162 if ($line =~ m/^\@{3}/) {
1163 $diff_class = " chunk_header";
1164 } elsif ($line =~ m/^\\/) {
1165 $diff_class = " incomplete";
1166 } elsif ($prefix =~ tr/+/+/) {
1167 $diff_class = " add";
1168 } elsif ($prefix =~ tr/-/-/) {
1169 $diff_class = " rem";
1172 # assume ordinary diff
1173 my $char = substr($line, 0, 1);
1175 $diff_class = " add";
1176 } elsif ($char eq '-') {
1177 $diff_class = " rem";
1178 } elsif ($char eq '@') {
1179 $diff_class = " chunk_header";
1180 } elsif ($char eq "\\") {
1181 $diff_class = " incomplete";
1184 $line = untabify
($line);
1185 if ($from && $to && $line =~ m/^\@{2} /) {
1186 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1187 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1189 $from_lines = 0 unless defined $from_lines;
1190 $to_lines = 0 unless defined $to_lines;
1192 if ($from->{'href'}) {
1193 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1194 -class=>"list"}, $from_text);
1196 if ($to->{'href'}) {
1197 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1198 -class=>"list"}, $to_text);
1200 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1201 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1202 return "<div class=\"diff$diff_class\">$line</div>\n";
1203 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1204 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1205 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1207 @from_text = split(' ', $ranges);
1208 for (my $i = 0; $i < @from_text; ++$i) {
1209 ($from_start[$i], $from_nlines[$i]) =
1210 (split(',', substr($from_text[$i], 1)), 0);
1213 $to_text = pop @from_text;
1214 $to_start = pop @from_start;
1215 $to_nlines = pop @from_nlines;
1217 $line = "<span class=\"chunk_info\">$prefix ";
1218 for (my $i = 0; $i < @from_text; ++$i) {
1219 if ($from->{'href'}[$i]) {
1220 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1221 -class=>"list"}, $from_text[$i]);
1223 $line .= $from_text[$i];
1227 if ($to->{'href'}) {
1228 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1229 -class=>"list"}, $to_text);
1233 $line .= " $prefix</span>" .
1234 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1235 return "<div class=\"diff$diff_class\">$line</div>\n";
1237 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1240 ## ----------------------------------------------------------------------
1241 ## git utility subroutines, invoking git commands
1243 # returns path to the core git executable and the --git-dir parameter as list
1245 return $GIT, '--git-dir='.$git_dir;
1248 # returns path to the core git executable and the --git-dir parameter as string
1250 return join(' ', git_cmd
());
1253 # get HEAD ref of given project as hash
1254 sub git_get_head_hash
{
1255 my $project = shift;
1256 my $o_git_dir = $git_dir;
1258 $git_dir = "$projectroot/$project";
1259 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1262 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1266 if (defined $o_git_dir) {
1267 $git_dir = $o_git_dir;
1272 # get type of given object
1276 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1278 close $fd or return;
1283 sub git_get_project_config
{
1284 my ($key, $type) = @_;
1286 return unless ($key);
1287 $key =~ s/^gitweb\.//;
1288 return if ($key =~ m/\W/);
1290 my @x = (git_cmd
(), 'config');
1291 if (defined $type) { push @x, $type; }
1293 push @x, "gitweb.$key";
1299 # get hash of given path at given ref
1300 sub git_get_hash_by_path
{
1302 my $path = shift || return undef;
1307 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1308 or die_error
(undef, "Open git-ls-tree failed");
1310 close $fd or return undef;
1312 if (!defined $line) {
1313 # there is no tree or hash given by $path at $base
1317 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1318 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1319 if (defined $type && $type ne $2) {
1320 # type doesn't match
1326 # get path of entry with given hash at given tree-ish (ref)
1327 # used to get 'from' filename for combined diff (merge commit) for renames
1328 sub git_get_path_by_hash
{
1329 my $base = shift || return;
1330 my $hash = shift || return;
1334 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1336 while (my $line = <$fd>) {
1339 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1340 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1341 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1350 ## ......................................................................
1351 ## git utility functions, directly accessing git repository
1353 sub git_get_project_description
{
1356 open my $fd, "$projectroot/$path/description" or return undef;
1359 if (defined $descr) {
1365 sub git_get_project_url_list
{
1368 open my $fd, "$projectroot/$path/cloneurl" or return;
1369 my @git_project_url_list = map { chomp; $_ } <$fd>;
1372 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1375 sub git_get_projects_list
{
1380 $filter =~ s/\.git$//;
1382 my ($check_forks) = gitweb_check_feature
('forks');
1384 if (-d
$projects_list) {
1385 # search in directory
1386 my $dir = $projects_list . ($filter ? "/$filter" : '');
1387 # remove the trailing "/"
1389 my $pfxlen = length("$dir");
1392 follow_fast
=> 1, # follow symbolic links
1393 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1395 # skip project-list toplevel, if we get it.
1396 return if (m!^[/.]$!);
1397 # only directories can be git repositories
1398 return unless (-d
$_);
1400 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1401 # we check related file in $projectroot
1402 if ($check_forks and $subdir =~ m
#/.#) {
1403 $File::Find
::prune
= 1;
1404 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1405 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1406 $File::Find
::prune
= 1;
1411 } elsif (-f
$projects_list) {
1412 # read from file(url-encoded):
1413 # 'git%2Fgit.git Linus+Torvalds'
1414 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1415 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1417 open my ($fd), $projects_list or return;
1419 while (my $line = <$fd>) {
1421 my ($path, $owner) = split ' ', $line;
1422 $path = unescape
($path);
1423 $owner = unescape
($owner);
1424 if (!defined $path) {
1427 if ($filter ne '') {
1428 # looking for forks;
1429 my $pfx = substr($path, 0, length($filter));
1430 if ($pfx ne $filter) {
1433 my $sfx = substr($path, length($filter));
1434 if ($sfx !~ /^\/.*\
.git
$/) {
1437 } elsif ($check_forks) {
1439 foreach my $filter (keys %paths) {
1440 # looking for forks;
1441 my $pfx = substr($path, 0, length($filter));
1442 if ($pfx ne $filter) {
1445 my $sfx = substr($path, length($filter));
1446 if ($sfx !~ /^\/.*\
.git
$/) {
1449 # is a fork, don't include it in
1454 if (check_export_ok
("$projectroot/$path")) {
1457 owner
=> to_utf8
($owner),
1460 (my $forks_path = $path) =~ s/\.git$//;
1461 $paths{$forks_path}++;
1469 sub git_get_project_owner
{
1470 my $project = shift;
1473 return undef unless $project;
1475 # read from file (url-encoded):
1476 # 'git%2Fgit.git Linus+Torvalds'
1477 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1478 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1479 if (-f
$projects_list) {
1480 open (my $fd , $projects_list);
1481 while (my $line = <$fd>) {
1483 my ($pr, $ow) = split ' ', $line;
1484 $pr = unescape
($pr);
1485 $ow = unescape
($ow);
1486 if ($pr eq $project) {
1487 $owner = to_utf8
($ow);
1493 if (!defined $owner) {
1494 $owner = get_file_owner
("$projectroot/$project");
1500 sub git_get_last_activity
{
1504 $git_dir = "$projectroot/$path";
1505 open($fd, "-|", git_cmd
(), 'for-each-ref',
1506 '--format=%(committer)',
1507 '--sort=-committerdate',
1509 'refs/heads') or return;
1510 my $most_recent = <$fd>;
1511 close $fd or return;
1512 if (defined $most_recent &&
1513 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1515 my $age = time - $timestamp;
1516 return ($age, age_string
($age));
1520 sub git_get_references
{
1521 my $type = shift || "";
1523 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1524 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1525 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1526 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1529 while (my $line = <$fd>) {
1531 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1532 if (defined $refs{$1}) {
1533 push @{$refs{$1}}, $2;
1539 close $fd or return;
1543 sub git_get_rev_name_tags
{
1544 my $hash = shift || return undef;
1546 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1548 my $name_rev = <$fd>;
1551 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1554 # catches also '$hash undefined' output
1559 ## ----------------------------------------------------------------------
1560 ## parse to hash functions
1564 my $tz = shift || "-0000";
1567 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1568 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1569 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1570 $date{'hour'} = $hour;
1571 $date{'minute'} = $min;
1572 $date{'mday'} = $mday;
1573 $date{'day'} = $days[$wday];
1574 $date{'month'} = $months[$mon];
1575 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1576 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1577 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1578 $mday, $months[$mon], $hour ,$min;
1579 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1580 1900+$year, $mon, $mday, $hour ,$min, $sec;
1582 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1583 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1584 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1585 $date{'hour_local'} = $hour;
1586 $date{'minute_local'} = $min;
1587 $date{'tz_local'} = $tz;
1588 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1589 1900+$year, $mon+1, $mday,
1590 $hour, $min, $sec, $tz);
1599 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1600 $tag{'id'} = $tag_id;
1601 while (my $line = <$fd>) {
1603 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1604 $tag{'object'} = $1;
1605 } elsif ($line =~ m/^type (.+)$/) {
1607 } elsif ($line =~ m/^tag (.+)$/) {
1609 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1610 $tag{'author'} = $1;
1613 } elsif ($line =~ m/--BEGIN/) {
1614 push @comment, $line;
1616 } elsif ($line eq "") {
1620 push @comment, <$fd>;
1621 $tag{'comment'} = \
@comment;
1622 close $fd or return;
1623 if (!defined $tag{'name'}) {
1629 sub parse_commit_text
{
1630 my ($commit_text, $withparents) = @_;
1631 my @commit_lines = split '\n', $commit_text;
1634 pop @commit_lines; # Remove '\0'
1636 if (! @commit_lines) {
1640 my $header = shift @commit_lines;
1641 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1644 ($co{'id'}, my @parents) = split ' ', $header;
1645 while (my $line = shift @commit_lines) {
1646 last if $line eq "\n";
1647 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1649 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1651 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1653 $co{'author_epoch'} = $2;
1654 $co{'author_tz'} = $3;
1655 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1656 $co{'author_name'} = $1;
1657 $co{'author_email'} = $2;
1659 $co{'author_name'} = $co{'author'};
1661 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1662 $co{'committer'} = $1;
1663 $co{'committer_epoch'} = $2;
1664 $co{'committer_tz'} = $3;
1665 $co{'committer_name'} = $co{'committer'};
1666 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1667 $co{'committer_name'} = $1;
1668 $co{'committer_email'} = $2;
1670 $co{'committer_name'} = $co{'committer'};
1674 if (!defined $co{'tree'}) {
1677 $co{'parents'} = \
@parents;
1678 $co{'parent'} = $parents[0];
1680 foreach my $title (@commit_lines) {
1683 $co{'title'} = chop_str
($title, 80, 5);
1684 # remove leading stuff of merges to make the interesting part visible
1685 if (length($title) > 50) {
1686 $title =~ s/^Automatic //;
1687 $title =~ s/^merge (of|with) /Merge ... /i;
1688 if (length($title) > 50) {
1689 $title =~ s/(http|rsync):\/\///;
1691 if (length($title) > 50) {
1692 $title =~ s/(master|www|rsync)\.//;
1694 if (length($title) > 50) {
1695 $title =~ s/kernel.org:?//;
1697 if (length($title) > 50) {
1698 $title =~ s/\/pub\/scm//;
1701 $co{'title_short'} = chop_str
($title, 50, 5);
1705 if ($co{'title'} eq "") {
1706 $co{'title'} = $co{'title_short'} = '(no commit message)';
1708 # remove added spaces
1709 foreach my $line (@commit_lines) {
1712 $co{'comment'} = \
@commit_lines;
1714 my $age = time - $co{'committer_epoch'};
1716 $co{'age_string'} = age_string
($age);
1717 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1718 if ($age > 60*60*24*7*2) {
1719 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1720 $co{'age_string_age'} = $co{'age_string'};
1722 $co{'age_string_date'} = $co{'age_string'};
1723 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1729 my ($commit_id) = @_;
1734 open my $fd, "-|", git_cmd
(), "rev-list",
1740 or die_error
(undef, "Open git-rev-list failed");
1741 %co = parse_commit_text
(<$fd>, 1);
1748 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1756 open my $fd, "-|", git_cmd
(), "rev-list",
1758 ($arg ? ($arg) : ()),
1759 ("--max-count=" . $maxcount),
1760 ("--skip=" . $skip),
1763 ($filename ? ($filename) : ())
1764 or die_error
(undef, "Open git-rev-list failed");
1765 while (my $line = <$fd>) {
1766 my %co = parse_commit_text
($line);
1771 return wantarray ? @cos : \
@cos;
1774 # parse ref from ref_file, given by ref_id, with given type
1776 my $ref_file = shift;
1778 my $type = shift || git_get_type
($ref_id);
1781 $ref_item{'type'} = $type;
1782 $ref_item{'id'} = $ref_id;
1783 $ref_item{'epoch'} = 0;
1784 $ref_item{'age'} = "unknown";
1785 if ($type eq "tag") {
1786 my %tag = parse_tag
($ref_id);
1787 $ref_item{'comment'} = $tag{'comment'};
1788 if ($tag{'type'} eq "commit") {
1789 my %co = parse_commit
($tag{'object'});
1790 $ref_item{'epoch'} = $co{'committer_epoch'};
1791 $ref_item{'age'} = $co{'age_string'};
1792 } elsif (defined($tag{'epoch'})) {
1793 my $age = time - $tag{'epoch'};
1794 $ref_item{'epoch'} = $tag{'epoch'};
1795 $ref_item{'age'} = age_string
($age);
1797 $ref_item{'reftype'} = $tag{'type'};
1798 $ref_item{'name'} = $tag{'name'};
1799 $ref_item{'refid'} = $tag{'object'};
1800 } elsif ($type eq "commit"){
1801 my %co = parse_commit
($ref_id);
1802 $ref_item{'reftype'} = "commit";
1803 $ref_item{'name'} = $ref_file;
1804 $ref_item{'title'} = $co{'title'};
1805 $ref_item{'refid'} = $ref_id;
1806 $ref_item{'epoch'} = $co{'committer_epoch'};
1807 $ref_item{'age'} = $co{'age_string'};
1809 $ref_item{'reftype'} = $type;
1810 $ref_item{'name'} = $ref_file;
1811 $ref_item{'refid'} = $ref_id;
1817 # parse line of git-diff-tree "raw" output
1818 sub parse_difftree_raw_line
{
1822 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1823 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1824 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1825 $res{'from_mode'} = $1;
1826 $res{'to_mode'} = $2;
1827 $res{'from_id'} = $3;
1829 $res{'status'} = $5;
1830 $res{'similarity'} = $6;
1831 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1832 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1834 $res{'file'} = unquote
($7);
1837 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1838 # combined diff (for merge commit)
1839 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1840 $res{'nparents'} = length($1);
1841 $res{'from_mode'} = [ split(' ', $2) ];
1842 $res{'to_mode'} = pop @{$res{'from_mode'}};
1843 $res{'from_id'} = [ split(' ', $3) ];
1844 $res{'to_id'} = pop @{$res{'from_id'}};
1845 $res{'status'} = [ split('', $4) ];
1846 $res{'to_file'} = unquote
($5);
1848 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1849 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1850 $res{'commit'} = $1;
1853 return wantarray ? %res : \
%res;
1856 # parse line of git-ls-tree output
1857 sub parse_ls_tree_line
($;%) {
1862 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1863 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1871 $res{'name'} = unquote
($4);
1874 return wantarray ? %res : \
%res;
1877 # generates _two_ hashes, references to which are passed as 2 and 3 argument
1878 sub parse_from_to_diffinfo
{
1879 my ($diffinfo, $from, $to, @parents) = @_;
1881 if ($diffinfo->{'nparents'}) {
1883 $from->{'file'} = [];
1884 $from->{'href'} = [];
1885 fill_from_file_info
($diffinfo, @parents)
1886 unless exists $diffinfo->{'from_file'};
1887 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1888 $from->{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
1889 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
1890 $from->{'href'}[$i] = href
(action
=>"blob",
1891 hash_base
=>$parents[$i],
1892 hash
=>$diffinfo->{'from_id'}[$i],
1893 file_name
=>$from->{'file'}[$i]);
1895 $from->{'href'}[$i] = undef;
1899 $from->{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
1900 if ($diffinfo->{'status'} ne "A") { # not new (added) file
1901 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
1902 hash
=>$diffinfo->{'from_id'},
1903 file_name
=>$from->{'file'});
1905 delete $from->{'href'};
1909 $to->{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
1910 if (!is_deleted
($diffinfo)) { # file exists in result
1911 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
1912 hash
=>$diffinfo->{'to_id'},
1913 file_name
=>$to->{'file'});
1915 delete $to->{'href'};
1919 ## ......................................................................
1920 ## parse to array of hashes functions
1922 sub git_get_heads_list
{
1926 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1927 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1928 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1931 while (my $line = <$fd>) {
1935 my ($refinfo, $committerinfo) = split(/\0/, $line);
1936 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1937 my ($committer, $epoch, $tz) =
1938 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1939 $name =~ s!^refs/heads/!!;
1941 $ref_item{'name'} = $name;
1942 $ref_item{'id'} = $hash;
1943 $ref_item{'title'} = $title || '(no commit message)';
1944 $ref_item{'epoch'} = $epoch;
1946 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1948 $ref_item{'age'} = "unknown";
1951 push @headslist, \
%ref_item;
1955 return wantarray ? @headslist : \
@headslist;
1958 sub git_get_tags_list
{
1962 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1963 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1964 '--format=%(objectname) %(objecttype) %(refname) '.
1965 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1968 while (my $line = <$fd>) {
1972 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1973 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1974 my ($creator, $epoch, $tz) =
1975 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1976 $name =~ s!^refs/tags/!!;
1978 $ref_item{'type'} = $type;
1979 $ref_item{'id'} = $id;
1980 $ref_item{'name'} = $name;
1981 if ($type eq "tag") {
1982 $ref_item{'subject'} = $title;
1983 $ref_item{'reftype'} = $reftype;
1984 $ref_item{'refid'} = $refid;
1986 $ref_item{'reftype'} = $type;
1987 $ref_item{'refid'} = $id;
1990 if ($type eq "tag" || $type eq "commit") {
1991 $ref_item{'epoch'} = $epoch;
1993 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1995 $ref_item{'age'} = "unknown";
1999 push @tagslist, \
%ref_item;
2003 return wantarray ? @tagslist : \
@tagslist;
2006 ## ----------------------------------------------------------------------
2007 ## filesystem-related functions
2009 sub get_file_owner
{
2012 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2013 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2014 if (!defined $gcos) {
2018 $owner =~ s/[,;].*$//;
2019 return to_utf8
($owner);
2022 ## ......................................................................
2023 ## mimetype related functions
2025 sub mimetype_guess_file
{
2026 my $filename = shift;
2027 my $mimemap = shift;
2028 -r
$mimemap or return undef;
2031 open(MIME
, $mimemap) or return undef;
2033 next if m/^#/; # skip comments
2034 my ($mime, $exts) = split(/\t+/);
2035 if (defined $exts) {
2036 my @exts = split(/\s+/, $exts);
2037 foreach my $ext (@exts) {
2038 $mimemap{$ext} = $mime;
2044 $filename =~ /\.([^.]*)$/;
2045 return $mimemap{$1};
2048 sub mimetype_guess
{
2049 my $filename = shift;
2051 $filename =~ /\./ or return undef;
2053 if ($mimetypes_file) {
2054 my $file = $mimetypes_file;
2055 if ($file !~ m!^/!) { # if it is relative path
2056 # it is relative to project
2057 $file = "$projectroot/$project/$file";
2059 $mime = mimetype_guess_file
($filename, $file);
2061 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2067 my $filename = shift;
2070 my $mime = mimetype_guess
($filename);
2071 $mime and return $mime;
2075 return $default_blob_plain_mimetype unless $fd;
2078 return 'text/plain' .
2079 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
2080 } elsif (! $filename) {
2081 return 'application/octet-stream';
2082 } elsif ($filename =~ m/\.png$/i) {
2084 } elsif ($filename =~ m/\.gif$/i) {
2086 } elsif ($filename =~ m/\.jpe?g$/i) {
2087 return 'image/jpeg';
2089 return 'application/octet-stream';
2093 ## ======================================================================
2094 ## functions printing HTML: header, footer, error page
2096 sub git_header_html
{
2097 my $status = shift || "200 OK";
2098 my $expires = shift;
2100 my $title = "$site_name";
2101 if (defined $project) {
2102 $title .= " - " . to_utf8
($project);
2103 if (defined $action) {
2104 $title .= "/$action";
2105 if (defined $file_name) {
2106 $title .= " - " . esc_path
($file_name);
2107 if ($action eq "tree" && $file_name !~ m
|/$|) {
2114 # require explicit support from the UA if we are to send the page as
2115 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2116 # we have to do this because MSIE sometimes globs '*/*', pretending to
2117 # support xhtml+xml but choking when it gets what it asked for.
2118 if (defined $cgi->http('HTTP_ACCEPT') &&
2119 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2120 $cgi->Accept('application/xhtml+xml') != 0) {
2121 $content_type = 'application/xhtml+xml';
2123 $content_type = 'text/html';
2125 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2126 -status
=> $status, -expires
=> $expires);
2127 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2129 <?xml version="1.0" encoding="utf-8"?>
2130 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2131 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2132 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2133 <!-- git core binaries version $git_version -->
2135 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2136 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2137 <meta name="robots" content="index, nofollow"/>
2138 <title>$title</title>
2140 # print out each stylesheet that exist
2141 if (defined $stylesheet) {
2142 #provides backwards capability for those people who define style sheet in a config file
2143 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2145 foreach my $stylesheet (@stylesheets) {
2146 next unless $stylesheet;
2147 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2150 if (defined $project) {
2151 printf('<link rel="alternate" title="%s log RSS feed" '.
2152 'href="%s" type="application/rss+xml" />'."\n",
2153 esc_param
($project), href
(action
=>"rss"));
2154 printf('<link rel="alternate" title="%s log Atom feed" '.
2155 'href="%s" type="application/atom+xml" />'."\n",
2156 esc_param
($project), href
(action
=>"atom"));
2158 printf('<link rel="alternate" title="%s projects list" '.
2159 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2160 $site_name, href
(project
=>undef, action
=>"project_index"));
2161 printf('<link rel="alternate" title="%s projects feeds" '.
2162 'href="%s" type="text/x-opml"/>'."\n",
2163 $site_name, href
(project
=>undef, action
=>"opml"));
2165 if (defined $favicon) {
2166 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
2172 if (-f
$site_header) {
2173 open (my $fd, $site_header);
2178 print "<div class=\"page_header\">\n" .
2179 $cgi->a({-href
=> esc_url
($logo_url),
2180 -title
=> $logo_label},
2181 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2182 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2183 if (defined $project) {
2184 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2185 if (defined $action) {
2192 my ($have_search) = gitweb_check_feature
('search');
2193 if ((defined $project) && ($have_search)) {
2194 if (!defined $searchtext) {
2198 if (defined $hash_base) {
2199 $search_hash = $hash_base;
2200 } elsif (defined $hash) {
2201 $search_hash = $hash;
2203 $search_hash = "HEAD";
2205 $cgi->param("a", "search");
2206 $cgi->param("h", $search_hash);
2207 $cgi->param("p", $project);
2208 print $cgi->startform(-method => "get", -action
=> $my_uri) .
2209 "<div class=\"search\">\n" .
2210 $cgi->hidden(-name
=> "p") . "\n" .
2211 $cgi->hidden(-name
=> "a") . "\n" .
2212 $cgi->hidden(-name
=> "h") . "\n" .
2213 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2214 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2215 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2217 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2219 $cgi->end_form() . "\n";
2223 sub git_footer_html
{
2224 print "<div class=\"page_footer\">\n";
2225 if (defined $project) {
2226 my $descr = git_get_project_description
($project);
2227 if (defined $descr) {
2228 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2230 print $cgi->a({-href
=> href
(action
=>"rss"),
2231 -class => "rss_logo"}, "RSS") . " ";
2232 print $cgi->a({-href
=> href
(action
=>"atom"),
2233 -class => "rss_logo"}, "Atom") . "\n";
2235 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2236 -class => "rss_logo"}, "OPML") . " ";
2237 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2238 -class => "rss_logo"}, "TXT") . "\n";
2242 if (-f
$site_footer) {
2243 open (my $fd, $site_footer);
2253 my $status = shift || "403 Forbidden";
2254 my $error = shift || "Malformed query, file missing or permission denied";
2256 git_header_html
($status);
2258 <div class="page_body">
2268 ## ----------------------------------------------------------------------
2269 ## functions printing or outputting HTML: navigation
2271 sub git_print_page_nav
{
2272 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2273 $extra = '' if !defined $extra; # pager or formats
2275 my @navs = qw(summary shortlog log commit commitdiff tree);
2277 @navs = grep { $_ ne $suppress } @navs;
2280 my %arg = map { $_ => {action
=>$_} } @navs;
2281 if (defined $head) {
2282 for (qw(commit commitdiff)) {
2283 $arg{$_}{'hash'} = $head;
2285 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2286 for (qw(shortlog log)) {
2287 $arg{$_}{'hash'} = $head;
2291 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2292 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2294 print "<div class=\"page_nav\">\n" .
2296 map { $_ eq $current ?
2297 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2299 print "<br/>\n$extra<br/>\n" .
2303 sub format_paging_nav
{
2304 my ($action, $hash, $head, $page, $nrevs) = @_;
2308 if ($hash ne $head || $page) {
2309 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2311 $paging_nav .= "HEAD";
2315 $paging_nav .= " ⋅ " .
2316 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2317 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2319 $paging_nav .= " ⋅ prev";
2322 if ($nrevs >= (100 * ($page+1)-1)) {
2323 $paging_nav .= " ⋅ " .
2324 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2325 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2327 $paging_nav .= " ⋅ next";
2333 ## ......................................................................
2334 ## functions printing or outputting HTML: div
2336 sub git_print_header_div
{
2337 my ($action, $title, $hash, $hash_base) = @_;
2340 $args{'action'} = $action;
2341 $args{'hash'} = $hash if $hash;
2342 $args{'hash_base'} = $hash_base if $hash_base;
2344 print "<div class=\"header\">\n" .
2345 $cgi->a({-href
=> href
(%args), -class => "title"},
2346 $title ? $title : $action) .
2350 #sub git_print_authorship (\%) {
2351 sub git_print_authorship
{
2354 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2355 print "<div class=\"author_date\">" .
2356 esc_html
($co->{'author_name'}) .
2358 if ($ad{'hour_local'} < 6) {
2359 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2360 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2362 printf(" (%02d:%02d %s)",
2363 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2368 sub git_print_page_path
{
2374 print "<div class=\"page_path\">";
2375 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2376 -title
=> 'tree root'}, to_utf8
("[$project]"));
2378 if (defined $name) {
2379 my @dirname = split '/', $name;
2380 my $basename = pop @dirname;
2383 foreach my $dir (@dirname) {
2384 $fullname .= ($fullname ? '/' : '') . $dir;
2385 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2387 -title
=> $fullname}, esc_path
($dir));
2390 if (defined $type && $type eq 'blob') {
2391 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2393 -title
=> $name}, esc_path
($basename));
2394 } elsif (defined $type && $type eq 'tree') {
2395 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2397 -title
=> $name}, esc_path
($basename));
2400 print esc_path
($basename);
2403 print "<br/></div>\n";
2406 # sub git_print_log (\@;%) {
2407 sub git_print_log
($;%) {
2411 if ($opts{'-remove_title'}) {
2412 # remove title, i.e. first line of log
2415 # remove leading empty lines
2416 while (defined $log->[0] && $log->[0] eq "") {
2423 foreach my $line (@$log) {
2424 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2427 if (! $opts{'-remove_signoff'}) {
2428 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2431 # remove signoff lines
2438 # print only one empty line
2439 # do not print empty line after signoff
2441 next if ($empty || $signoff);
2447 print format_log_line_html
($line) . "<br/>\n";
2450 if ($opts{'-final_empty_line'}) {
2451 # end with single empty line
2452 print "<br/>\n" unless $empty;
2456 # return link target (what link points to)
2457 sub git_get_link_target
{
2462 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2466 $link_target = <$fd>;
2471 return $link_target;
2474 # given link target, and the directory (basedir) the link is in,
2475 # return target of link relative to top directory (top tree);
2476 # return undef if it is not possible (including absolute links).
2477 sub normalize_link_target
{
2478 my ($link_target, $basedir, $hash_base) = @_;
2480 # we can normalize symlink target only if $hash_base is provided
2481 return unless $hash_base;
2483 # absolute symlinks (beginning with '/') cannot be normalized
2484 return if (substr($link_target, 0, 1) eq '/');
2486 # normalize link target to path from top (root) tree (dir)
2489 $path = $basedir . '/' . $link_target;
2491 # we are in top (root) tree (dir)
2492 $path = $link_target;
2495 # remove //, /./, and /../
2497 foreach my $part (split('/', $path)) {
2498 # discard '.' and ''
2499 next if (!$part || $part eq '.');
2501 if ($part eq '..') {
2505 # link leads outside repository (outside top dir)
2509 push @path_parts, $part;
2512 $path = join('/', @path_parts);
2517 # print tree entry (row of git_tree), but without encompassing <tr> element
2518 sub git_print_tree_entry
{
2519 my ($t, $basedir, $hash_base, $have_blame) = @_;
2522 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2524 # The format of a table row is: mode list link. Where mode is
2525 # the mode of the entry, list is the name of the entry, an href,
2526 # and link is the action links of the entry.
2528 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2529 if ($t->{'type'} eq "blob") {
2530 print "<td class=\"list\">" .
2531 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2532 file_name
=>"$basedir$t->{'name'}", %base_key),
2533 -class => "list"}, esc_path
($t->{'name'}));
2534 if (S_ISLNK
(oct $t->{'mode'})) {
2535 my $link_target = git_get_link_target
($t->{'hash'});
2537 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2538 if (defined $norm_target) {
2540 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2541 file_name
=>$norm_target),
2542 -title
=> $norm_target}, esc_path
($link_target));
2544 print " -> " . esc_path
($link_target);
2549 print "<td class=\"link\">";
2550 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2551 file_name
=>"$basedir$t->{'name'}", %base_key)},
2555 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2556 file_name
=>"$basedir$t->{'name'}", %base_key)},
2559 if (defined $hash_base) {
2561 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2562 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2566 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2567 file_name
=>"$basedir$t->{'name'}")},
2571 } elsif ($t->{'type'} eq "tree") {
2572 print "<td class=\"list\">";
2573 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2574 file_name
=>"$basedir$t->{'name'}", %base_key)},
2575 esc_path
($t->{'name'}));
2577 print "<td class=\"link\">";
2578 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2579 file_name
=>"$basedir$t->{'name'}", %base_key)},
2581 if (defined $hash_base) {
2583 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2584 file_name
=>"$basedir$t->{'name'}")},
2591 ## ......................................................................
2592 ## functions printing large fragments of HTML
2594 sub fill_from_file_info
{
2595 my ($diff, @parents) = @_;
2597 $diff->{'from_file'} = [ ];
2598 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2599 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2600 if ($diff->{'status'}[$i] eq 'R' ||
2601 $diff->{'status'}[$i] eq 'C') {
2602 $diff->{'from_file'}[$i] =
2603 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2610 # parameters can be strings, or references to arrays of strings
2614 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @$a == @$b) {
2615 for (my $i = 0; $i < @$a; ++$i) {
2616 return 0 unless ($a->[$i] eq $b->[$i]);
2619 } elsif (!ref($a) && !ref($b)) {
2627 my $diffinfo = shift;
2629 return $diffinfo->{'to_id'} eq ('0' x
40);
2632 sub git_difftree_body
{
2633 my ($difftree, $hash, @parents) = @_;
2634 my ($parent) = $parents[0];
2635 my ($have_blame) = gitweb_check_feature
('blame');
2636 print "<div class=\"list_head\">\n";
2637 if ($#{$difftree} > 10) {
2638 print(($#{$difftree} + 1) . " files changed:\n");
2642 print "<table class=\"" .
2643 (@parents > 1 ? "combined " : "") .
2646 # header only for combined diff in 'commitdiff' view
2647 my $has_header = @parents > 1 && $action eq 'commitdiff';
2650 print "<thead><tr>\n" .
2651 "<th></th><th></th>\n"; # filename, patchN link
2652 for (my $i = 0; $i < @parents; $i++) {
2653 my $par = $parents[$i];
2655 $cgi->a({-href
=> href
(action
=>"commitdiff",
2656 hash
=>$hash, hash_parent
=>$par),
2657 -title
=> 'commitdiff to parent number ' .
2658 ($i+1) . ': ' . substr($par,0,7)},
2662 print "</tr></thead>\n<tbody>\n";
2667 foreach my $line (@{$difftree}) {
2669 if (ref($line) eq "HASH") {
2670 # pre-parsed (or generated by hand)
2673 $diff = parse_difftree_raw_line
($line);
2677 print "<tr class=\"dark\">\n";
2679 print "<tr class=\"light\">\n";
2683 if (exists $diff->{'nparents'}) { # combined diff
2685 fill_from_file_info
($diff, @parents)
2686 unless exists $diff->{'from_file'};
2688 if (!is_deleted
($diff)) {
2689 # file exists in the result (child) commit
2691 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2692 file_name
=>$diff->{'to_file'},
2694 -class => "list"}, esc_path
($diff->{'to_file'})) .
2698 esc_path
($diff->{'to_file'}) .
2702 if ($action eq 'commitdiff') {
2705 print "<td class=\"link\">" .
2706 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2711 my $has_history = 0;
2712 my $not_deleted = 0;
2713 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2714 my $hash_parent = $parents[$i];
2715 my $from_hash = $diff->{'from_id'}[$i];
2716 my $from_path = $diff->{'from_file'}[$i];
2717 my $status = $diff->{'status'}[$i];
2719 $has_history ||= ($status ne 'A');
2720 $not_deleted ||= ($status ne 'D');
2722 if ($status eq 'A') {
2723 print "<td class=\"link\" align=\"right\"> | </td>\n";
2724 } elsif ($status eq 'D') {
2725 print "<td class=\"link\">" .
2726 $cgi->a({-href
=> href
(action
=>"blob",
2729 file_name
=>$from_path)},
2733 if ($diff->{'to_id'} eq $from_hash) {
2734 print "<td class=\"link nochange\">";
2736 print "<td class=\"link\">";
2738 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2739 hash
=>$diff->{'to_id'},
2740 hash_parent
=>$from_hash,
2742 hash_parent_base
=>$hash_parent,
2743 file_name
=>$diff->{'to_file'},
2744 file_parent
=>$from_path)},
2750 print "<td class=\"link\">";
2752 print $cgi->a({-href
=> href
(action
=>"blob",
2753 hash
=>$diff->{'to_id'},
2754 file_name
=>$diff->{'to_file'},
2757 print " | " if ($has_history);
2760 print $cgi->a({-href
=> href
(action
=>"history",
2761 file_name
=>$diff->{'to_file'},
2768 next; # instead of 'else' clause, to avoid extra indent
2770 # else ordinary diff
2772 my ($to_mode_oct, $to_mode_str, $to_file_type);
2773 my ($from_mode_oct, $from_mode_str, $from_file_type);
2774 if ($diff->{'to_mode'} ne ('0' x
6)) {
2775 $to_mode_oct = oct $diff->{'to_mode'};
2776 if (S_ISREG
($to_mode_oct)) { # only for regular file
2777 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2779 $to_file_type = file_type
($diff->{'to_mode'});
2781 if ($diff->{'from_mode'} ne ('0' x
6)) {
2782 $from_mode_oct = oct $diff->{'from_mode'};
2783 if (S_ISREG
($to_mode_oct)) { # only for regular file
2784 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2786 $from_file_type = file_type
($diff->{'from_mode'});
2789 if ($diff->{'status'} eq "A") { # created
2790 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2791 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2792 $mode_chng .= "]</span>";
2794 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2795 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2796 -class => "list"}, esc_path
($diff->{'file'}));
2798 print "<td>$mode_chng</td>\n";
2799 print "<td class=\"link\">";
2800 if ($action eq 'commitdiff') {
2803 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2806 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2807 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2811 } elsif ($diff->{'status'} eq "D") { # deleted
2812 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2814 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2815 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2816 -class => "list"}, esc_path
($diff->{'file'}));
2818 print "<td>$mode_chng</td>\n";
2819 print "<td class=\"link\">";
2820 if ($action eq 'commitdiff') {
2823 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2826 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2827 hash_base
=>$parent, file_name
=>$diff->{'file'})},
2830 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2831 file_name
=>$diff->{'file'})},
2834 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2835 file_name
=>$diff->{'file'})},
2839 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2840 my $mode_chnge = "";
2841 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2842 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2843 if ($from_file_type ne $to_file_type) {
2844 $mode_chnge .= " from $from_file_type to $to_file_type";
2846 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2847 if ($from_mode_str && $to_mode_str) {
2848 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2849 } elsif ($to_mode_str) {
2850 $mode_chnge .= " mode: $to_mode_str";
2853 $mode_chnge .= "]</span>\n";
2856 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2857 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2858 -class => "list"}, esc_path
($diff->{'file'}));
2860 print "<td>$mode_chnge</td>\n";
2861 print "<td class=\"link\">";
2862 if ($action eq 'commitdiff') {
2865 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2867 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2868 # "commit" view and modified file (not onlu mode changed)
2869 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2870 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2871 hash_base
=>$hash, hash_parent_base
=>$parent,
2872 file_name
=>$diff->{'file'})},
2876 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2877 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2880 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2881 file_name
=>$diff->{'file'})},
2884 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2885 file_name
=>$diff->{'file'})},
2889 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
2890 my %status_name = ('R' => 'moved', 'C' => 'copied');
2891 my $nstatus = $status_name{$diff->{'status'}};
2893 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2894 # mode also for directories, so we cannot use $to_mode_str
2895 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2898 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2899 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
2900 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
2901 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2902 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2903 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
2904 -class => "list"}, esc_path
($diff->{'from_file'})) .
2905 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2906 "<td class=\"link\">";
2907 if ($action eq 'commitdiff') {
2910 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2912 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2913 # "commit" view and modified file (not only pure rename or copy)
2914 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2915 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2916 hash_base
=>$hash, hash_parent_base
=>$parent,
2917 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
2921 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2922 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
2925 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2926 file_name
=>$diff->{'to_file'})},
2929 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2930 file_name
=>$diff->{'to_file'})},
2934 } # we should not encounter Unmerged (U) or Unknown (X) status
2937 print "</tbody>" if $has_header;
2941 sub git_patchset_body
{
2942 my ($fd, $difftree, $hash, @hash_parents) = @_;
2943 my ($hash_parent) = $hash_parents[0];
2946 my $patch_number = 0;
2951 print "<div class=\"patchset\">\n";
2953 # skip to first patch
2954 while ($patch_line = <$fd>) {
2957 last if ($patch_line =~ m/^diff /);
2961 while ($patch_line) {
2963 my ($from_id, $to_id);
2966 #assert($patch_line =~ m/^diff /) if DEBUG;
2967 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2969 push @diff_header, $patch_line;
2971 # extended diff header
2973 while ($patch_line = <$fd>) {
2976 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2978 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2981 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2982 $from_id = [ split(',', $1) ];
2986 push @diff_header, $patch_line;
2988 my $last_patch_line = $patch_line;
2990 # check if current patch belong to current raw line
2991 # and parse raw git-diff line if needed
2992 if (defined $diffinfo &&
2993 defined $from_id && defined $to_id &&
2994 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
2995 $diffinfo->{'to_id'} eq $to_id) {
2996 # this is continuation of a split patch
2997 print "<div class=\"patch cont\">\n";
2999 # advance raw git-diff output if needed
3000 $patch_idx++ if defined $diffinfo;
3002 # compact combined diff output can have some patches skipped
3003 # find which patch (using pathname of result) we are at now
3005 if ($diff_header[0] =~ m!^diff --cc "?(.*)"?$!) {
3010 # read and prepare patch information
3011 if (ref($difftree->[$patch_idx]) eq "HASH") {
3012 # pre-parsed (or generated by hand)
3013 $diffinfo = $difftree->[$patch_idx];
3015 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
3018 # check if current raw line has no patch (it got simplified)
3019 if (defined $to_name && $to_name ne $diffinfo->{'to_file'}) {
3020 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3021 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3022 "</div>\n"; # class="patch"
3027 } until (!defined $to_name || $to_name eq $diffinfo->{'to_file'} ||
3028 $patch_idx > $#$difftree);
3029 # modifies %from, %to hashes
3030 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3031 if ($diffinfo->{'nparents'}) {
3035 fill_from_file_info
($diffinfo, @hash_parents)
3036 unless exists $diffinfo->{'from_file'};
3037 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
3038 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
3039 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
3040 $from{'href'}[$i] = href
(action
=>"blob",
3041 hash_base
=>$hash_parents[$i],
3042 hash
=>$diffinfo->{'from_id'}[$i],
3043 file_name
=>$from{'file'}[$i]);
3045 $from{'href'}[$i] = undef;
3049 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
3050 if ($diffinfo->{'status'} ne "A") { # not new (added) file
3051 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
3052 hash
=>$diffinfo->{'from_id'},
3053 file_name
=>$from{'file'});
3055 delete $from{'href'};
3059 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
3060 if (!is_deleted
($diffinfo)) { # file exists in result
3061 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
3062 hash
=>$diffinfo->{'to_id'},
3063 file_name
=>$to{'file'});
3067 # this is first patch for raw difftree line with $patch_idx index
3068 # we index @$difftree array from 0, but number patches from 1
3069 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3072 # print "git diff" header
3073 $patch_line = shift @diff_header;
3074 print format_git_diff_header_line
($patch_line, $diffinfo,
3077 # print extended diff header
3078 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
3080 foreach $patch_line (@diff_header) {
3081 print format_extended_diff_header_line
($patch_line, $diffinfo,
3084 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
3086 # from-file/to-file diff header
3087 $patch_line = $last_patch_line;
3088 if (! $patch_line) {
3089 print "</div>\n"; # class="patch"
3092 next PATCH
if ($patch_line =~ m/^diff /);
3093 #assert($patch_line =~ m/^---/) if DEBUG;
3094 #assert($patch_line eq $last_patch_line) if DEBUG;
3096 $patch_line = <$fd>;
3098 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3100 print format_diff_from_to_header
($last_patch_line, $patch_line,
3101 $diffinfo, \
%from, \
%to,
3106 while ($patch_line = <$fd>) {
3109 next PATCH
if ($patch_line =~ m/^diff /);
3111 print format_diff_line
($patch_line, \
%from, \
%to);
3115 print "</div>\n"; # class="patch"
3118 # for compact combined (--cc) format, with chunk and patch simpliciaction
3119 # patchset might be empty, but there might be unprocessed raw lines
3120 for ($patch_idx++ if $patch_number > 0;
3121 $patch_idx < @$difftree;
3123 # read and prepare patch information
3124 if (ref($difftree->[$patch_idx]) eq "HASH") {
3125 # pre-parsed (or generated by hand)
3126 $diffinfo = $difftree->[$patch_idx];
3128 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
3131 # generate anchor for "patch" links in difftree / whatchanged part
3132 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3133 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3134 "</div>\n"; # class="patch"
3139 if ($patch_number == 0) {
3140 if (@hash_parents > 1) {
3141 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3143 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3147 print "</div>\n"; # class="patchset"
3150 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3152 sub git_project_list_body
{
3153 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3155 my ($check_forks) = gitweb_check_feature
('forks');
3158 foreach my $pr (@$projlist) {
3159 my (@aa) = git_get_last_activity
($pr->{'path'});
3163 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3164 if (!defined $pr->{'descr'}) {
3165 my $descr = git_get_project_description
($pr->{'path'}) || "";
3166 $pr->{'descr_long'} = to_utf8
($descr);
3167 $pr->{'descr'} = chop_str
($descr, 25, 5);
3169 if (!defined $pr->{'owner'}) {
3170 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
3173 my $pname = $pr->{'path'};
3174 if (($pname =~ s/\.git$//) &&
3175 ($pname !~ /\/$/) &&
3176 (-d
"$projectroot/$pname")) {
3177 $pr->{'forks'} = "-d $projectroot/$pname";
3183 push @projects, $pr;
3186 $order ||= $default_projects_order;
3187 $from = 0 unless defined $from;
3188 $to = $#projects if (!defined $to || $#projects < $to);
3190 print "<table class=\"project_list\">\n";
3191 unless ($no_header) {
3194 print "<th></th>\n";
3196 if ($order eq "project") {
3197 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3198 print "<th>Project</th>\n";
3201 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3202 -class => "header"}, "Project") .
3205 if ($order eq "descr") {
3206 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3207 print "<th>Description</th>\n";
3210 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3211 -class => "header"}, "Description") .
3214 if ($order eq "owner") {
3215 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3216 print "<th>Owner</th>\n";
3219 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3220 -class => "header"}, "Owner") .
3223 if ($order eq "age") {
3224 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3225 print "<th>Last Change</th>\n";
3228 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3229 -class => "header"}, "Last Change") .
3232 print "<th></th>\n" .
3236 for (my $i = $from; $i <= $to; $i++) {
3237 my $pr = $projects[$i];
3239 print "<tr class=\"dark\">\n";
3241 print "<tr class=\"light\">\n";
3246 if ($pr->{'forks'}) {
3247 print "<!-- $pr->{'forks'} -->\n";
3248 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3252 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3253 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3254 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3255 -class => "list", -title
=> $pr->{'descr_long'}},
3256 esc_html
($pr->{'descr'})) . "</td>\n" .
3257 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
3258 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3259 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3260 "<td class=\"link\">" .
3261 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3262 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3263 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3264 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3265 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3269 if (defined $extra) {
3272 print "<td></td>\n";
3274 print "<td colspan=\"5\">$extra</td>\n" .
3280 sub git_shortlog_body
{
3281 # uses global variable $project
3282 my ($commitlist, $from, $to, $refs, $extra) = @_;
3284 my $have_snapshot = gitweb_have_snapshot
();
3286 $from = 0 unless defined $from;
3287 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3289 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3291 for (my $i = $from; $i <= $to; $i++) {
3292 my %co = %{$commitlist->[$i]};
3293 my $commit = $co{'id'};
3294 my $ref = format_ref_marker
($refs, $commit);
3296 print "<tr class=\"dark\">\n";
3298 print "<tr class=\"light\">\n";
3301 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3302 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3303 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3305 print format_subject_html
($co{'title'}, $co{'title_short'},
3306 href
(action
=>"commit", hash
=>$commit), $ref);
3308 "<td class=\"link\">" .
3309 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3310 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3311 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3312 if ($have_snapshot) {
3313 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
3318 if (defined $extra) {
3320 "<td colspan=\"4\">$extra</td>\n" .
3326 sub git_history_body
{
3327 # Warning: assumes constant type (blob or tree) during history
3328 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3330 $from = 0 unless defined $from;
3331 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3333 print "<table class=\"history\" cellspacing=\"0\">\n";
3335 for (my $i = $from; $i <= $to; $i++) {
3336 my %co = %{$commitlist->[$i]};
3340 my $commit = $co{'id'};
3342 my $ref = format_ref_marker
($refs, $commit);
3345 print "<tr class=\"dark\">\n";
3347 print "<tr class=\"light\">\n";
3350 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3351 # shortlog uses chop_str($co{'author_name'}, 10)
3352 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3354 # originally git_history used chop_str($co{'title'}, 50)
3355 print format_subject_html
($co{'title'}, $co{'title_short'},
3356 href
(action
=>"commit", hash
=>$commit), $ref);
3358 "<td class=\"link\">" .
3359 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3360 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3362 if ($ftype eq 'blob') {
3363 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3364 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3365 if (defined $blob_current && defined $blob_parent &&
3366 $blob_current ne $blob_parent) {
3368 $cgi->a({-href
=> href
(action
=>"blobdiff",
3369 hash
=>$blob_current, hash_parent
=>$blob_parent,
3370 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3371 file_name
=>$file_name)},
3378 if (defined $extra) {
3380 "<td colspan=\"4\">$extra</td>\n" .
3387 # uses global variable $project
3388 my ($taglist, $from, $to, $extra) = @_;
3389 $from = 0 unless defined $from;
3390 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3392 print "<table class=\"tags\" cellspacing=\"0\">\n";
3394 for (my $i = $from; $i <= $to; $i++) {
3395 my $entry = $taglist->[$i];
3397 my $comment = $tag{'subject'};
3399 if (defined $comment) {
3400 $comment_short = chop_str
($comment, 30, 5);
3403 print "<tr class=\"dark\">\n";
3405 print "<tr class=\"light\">\n";
3408 if (defined $tag{'age'}) {
3409 print "<td><i>$tag{'age'}</i></td>\n";
3411 print "<td></td>\n";
3414 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3415 -class => "list name"}, esc_html
($tag{'name'})) .
3418 if (defined $comment) {
3419 print format_subject_html
($comment, $comment_short,
3420 href
(action
=>"tag", hash
=>$tag{'id'}));
3423 "<td class=\"selflink\">";
3424 if ($tag{'type'} eq "tag") {
3425 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3430 "<td class=\"link\">" . " | " .
3431 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3432 if ($tag{'reftype'} eq "commit") {
3433 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3434 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3435 } elsif ($tag{'reftype'} eq "blob") {
3436 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3441 if (defined $extra) {
3443 "<td colspan=\"5\">$extra</td>\n" .
3449 sub git_heads_body
{
3450 # uses global variable $project
3451 my ($headlist, $head, $from, $to, $extra) = @_;
3452 $from = 0 unless defined $from;
3453 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3455 print "<table class=\"heads\" cellspacing=\"0\">\n";
3457 for (my $i = $from; $i <= $to; $i++) {
3458 my $entry = $headlist->[$i];
3460 my $curr = $ref{'id'} eq $head;
3462 print "<tr class=\"dark\">\n";
3464 print "<tr class=\"light\">\n";
3467 print "<td><i>$ref{'age'}</i></td>\n" .
3468 ($curr ? "<td class=\"current_head\">" : "<td>") .
3469 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3470 -class => "list name"},esc_html
($ref{'name'})) .
3472 "<td class=\"link\">" .
3473 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3474 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3475 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3479 if (defined $extra) {
3481 "<td colspan=\"3\">$extra</td>\n" .
3487 sub git_search_grep_body
{
3488 my ($commitlist, $from, $to, $extra) = @_;
3489 $from = 0 unless defined $from;
3490 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3492 print "<table class=\"grep\" cellspacing=\"0\">\n";
3494 for (my $i = $from; $i <= $to; $i++) {
3495 my %co = %{$commitlist->[$i]};
3499 my $commit = $co{'id'};
3501 print "<tr class=\"dark\">\n";
3503 print "<tr class=\"light\">\n";
3506 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3507 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3509 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3510 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3511 my $comment = $co{'comment'};
3512 foreach my $line (@$comment) {
3513 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3514 my $lead = esc_html
($1) || "";
3515 $lead = chop_str
($lead, 30, 10);
3516 my $match = esc_html
($2) || "";
3517 my $trail = esc_html
($3) || "";
3518 $trail = chop_str
($trail, 30, 10);
3519 my $text = "$lead<span class=\"match\">$match</span>$trail";
3520 print chop_str
($text, 80, 5) . "<br/>\n";
3524 "<td class=\"link\">" .
3525 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3527 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3531 if (defined $extra) {
3533 "<td colspan=\"3\">$extra</td>\n" .
3539 ## ======================================================================
3540 ## ======================================================================
3543 sub git_project_list
{
3544 my $order = $cgi->param('o');
3545 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3546 die_error
(undef, "Unknown order parameter");
3549 my @list = git_get_projects_list
();
3551 die_error
(undef, "No projects found");
3555 if (-f
$home_text) {
3556 print "<div class=\"index_include\">\n";
3557 open (my $fd, $home_text);
3562 git_project_list_body
(\
@list, $order);
3567 my $order = $cgi->param('o');
3568 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3569 die_error
(undef, "Unknown order parameter");
3572 my @list = git_get_projects_list
($project);
3574 die_error
(undef, "No forks found");
3578 git_print_page_nav
('','');
3579 git_print_header_div
('summary', "$project forks");
3580 git_project_list_body
(\
@list, $order);
3584 sub git_project_index
{
3585 my @projects = git_get_projects_list
($project);
3588 -type
=> 'text/plain',
3589 -charset
=> 'utf-8',
3590 -content_disposition
=> 'inline; filename="index.aux"');
3592 foreach my $pr (@projects) {
3593 if (!exists $pr->{'owner'}) {
3594 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3597 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3598 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3599 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3600 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3604 print "$path $owner\n";
3609 my $descr = git_get_project_description
($project) || "none";
3610 my %co = parse_commit
("HEAD");
3611 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3612 my $head = $co{'id'};
3614 my $owner = git_get_project_owner
($project);
3616 my $refs = git_get_references
();
3617 # These get_*_list functions return one more to allow us to see if
3618 # there are more ...
3619 my @taglist = git_get_tags_list
(16);
3620 my @headlist = git_get_heads_list
(16);
3622 my ($check_forks) = gitweb_check_feature
('forks');
3625 @forklist = git_get_projects_list
($project);
3629 git_print_page_nav
('summary','', $head);
3631 print "<div class=\"title\"> </div>\n";
3632 print "<table cellspacing=\"0\">\n" .
3633 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3634 "<tr><td>owner</td><td>$owner</td></tr>\n";
3635 if (defined $cd{'rfc2822'}) {
3636 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3639 # use per project git URL list in $projectroot/$project/cloneurl
3640 # or make project git URL from git base URL and project name
3641 my $url_tag = "URL";
3642 my @url_list = git_get_project_url_list
($project);
3643 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3644 foreach my $git_url (@url_list) {
3645 next unless $git_url;
3646 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3651 if (-s
"$projectroot/$project/README.html") {
3652 if (open my $fd, "$projectroot/$project/README.html") {
3653 print "<div class=\"title\">readme</div>\n";
3654 print $_ while (<$fd>);
3659 # we need to request one more than 16 (0..15) to check if
3661 my @commitlist = $head ? parse_commits
($head, 17) : ();
3663 git_print_header_div
('shortlog');
3664 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3665 $#commitlist <= 15 ? undef :
3666 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3670 git_print_header_div
('tags');
3671 git_tags_body
(\
@taglist, 0, 15,
3672 $#taglist <= 15 ? undef :
3673 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3677 git_print_header_div
('heads');
3678 git_heads_body
(\
@headlist, $head, 0, 15,
3679 $#headlist <= 15 ? undef :
3680 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3684 git_print_header_div
('forks');
3685 git_project_list_body
(\
@forklist, undef, 0, 15,
3686 $#forklist <= 15 ? undef :
3687 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3695 my $head = git_get_head_hash
($project);
3697 git_print_page_nav
('','', $head,undef,$head);
3698 my %tag = parse_tag
($hash);
3701 die_error
(undef, "Unknown tag object");
3704 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3705 print "<div class=\"title_text\">\n" .
3706 "<table cellspacing=\"0\">\n" .
3708 "<td>object</td>\n" .
3709 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3710 $tag{'object'}) . "</td>\n" .
3711 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3712 $tag{'type'}) . "</td>\n" .
3714 if (defined($tag{'author'})) {
3715 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3716 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3717 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3718 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3721 print "</table>\n\n" .
3723 print "<div class=\"page_body\">";
3724 my $comment = $tag{'comment'};
3725 foreach my $line (@$comment) {
3727 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3737 my ($have_blame) = gitweb_check_feature
('blame');
3739 die_error
('403 Permission denied', "Permission denied");
3741 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3742 $hash_base ||= git_get_head_hash
($project);
3743 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3744 my %co = parse_commit
($hash_base)
3745 or die_error
(undef, "Reading commit failed");
3746 if (!defined $hash) {
3747 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3748 or die_error
(undef, "Error looking up file");
3750 $ftype = git_get_type
($hash);
3751 if ($ftype !~ "blob") {
3752 die_error
('400 Bad Request', "Object is not a blob");
3754 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3755 $file_name, $hash_base)
3756 or die_error
(undef, "Open git-blame failed");
3759 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3762 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3765 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3767 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3768 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3769 git_print_page_path
($file_name, $ftype, $hash_base);
3770 my @rev_color = (qw(light2 dark2));
3771 my $num_colors = scalar(@rev_color);
3772 my $current_color = 0;
3775 <div class="page_body">
3776 <table class="blame">
3777 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3782 last unless defined $_;
3783 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3784 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3785 if (!exists $metainfo{$full_rev}) {
3786 $metainfo{$full_rev} = {};
3788 my $meta = $metainfo{$full_rev};
3791 if (/^(\S+) (.*)$/) {
3797 my $rev = substr($full_rev, 0, 8);
3798 my $author = $meta->{'author'};
3799 my %date = parse_date
($meta->{'author-time'},
3800 $meta->{'author-tz'});
3801 my $date = $date{'iso-tz'};
3803 $current_color = ++$current_color % $num_colors;
3805 print "<tr class=\"$rev_color[$current_color]\">\n";
3807 print "<td class=\"sha1\"";
3808 print " title=\"". esc_html
($author) . ", $date\"";
3809 print " rowspan=\"$group_size\"" if ($group_size > 1);
3811 print $cgi->a({-href
=> href
(action
=>"commit",
3813 file_name
=>$file_name)},
3817 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3818 or die_error
(undef, "Open git-rev-parse failed");
3819 my $parent_commit = <$dd>;
3821 chomp($parent_commit);
3822 my $blamed = href
(action
=> 'blame',
3823 file_name
=> $meta->{'filename'},
3824 hash_base
=> $parent_commit);
3825 print "<td class=\"linenr\">";
3826 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3828 -class => "linenr" },
3831 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3837 or print "Reading blob failed\n";
3844 my ($have_blame) = gitweb_check_feature
('blame');
3846 die_error
('403 Permission denied', "Permission denied");
3848 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3849 $hash_base ||= git_get_head_hash
($project);
3850 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3851 my %co = parse_commit
($hash_base)
3852 or die_error
(undef, "Reading commit failed");
3853 if (!defined $hash) {
3854 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3855 or die_error
(undef, "Error lookup file");
3857 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3858 or die_error
(undef, "Open git-annotate failed");
3861 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3864 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3867 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3869 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3870 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3871 git_print_page_path
($file_name, 'blob', $hash_base);
3872 print "<div class=\"page_body\">\n";
3874 <table class="blame">
3883 my @line_class = (qw(light dark));
3884 my $line_class_len = scalar (@line_class);
3885 my $line_class_num = $#line_class;
3886 while (my $line = <$fd>) {
3898 $line_class_num = ($line_class_num + 1) % $line_class_len;
3900 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3907 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3910 $short_rev = substr ($long_rev, 0, 8);
3911 $age = time () - $time;
3912 $age_str = age_string
($age);
3913 $age_str =~ s/ / /g;
3914 $age_class = age_class
($age);
3915 $author = esc_html
($author);
3916 $author =~ s/ / /g;
3918 $data = untabify
($data);
3919 $data = esc_html
($data);
3922 <tr class="$line_class[$line_class_num]">
3923 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3924 <td class="$age_class">$age_str</td>
3926 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3927 <td class="pre">$data</td>
3930 } # while (my $line = <$fd>)
3931 print "</table>\n\n";
3933 or print "Reading blob failed.\n";
3939 my $head = git_get_head_hash
($project);
3941 git_print_page_nav
('','', $head,undef,$head);
3942 git_print_header_div
('summary', $project);
3944 my @tagslist = git_get_tags_list
();
3946 git_tags_body
(\
@tagslist);
3952 my $head = git_get_head_hash
($project);
3954 git_print_page_nav
('','', $head,undef,$head);
3955 git_print_header_div
('summary', $project);
3957 my @headslist = git_get_heads_list
();
3959 git_heads_body
(\
@headslist, $head);
3964 sub git_blob_plain
{
3967 if (!defined $hash) {
3968 if (defined $file_name) {
3969 my $base = $hash_base || git_get_head_hash
($project);
3970 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3971 or die_error
(undef, "Error lookup file");
3973 die_error
(undef, "No file name defined");
3975 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3976 # blobs defined by non-textual hash id's can be cached
3981 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3982 or die_error
(undef, "Couldn't cat $file_name, $hash");
3984 $type ||= blob_mimetype
($fd, $file_name);
3986 # save as filename, even when no $file_name is given
3987 my $save_as = "$hash";
3988 if (defined $file_name) {
3989 $save_as = $file_name;
3990 } elsif ($type =~ m/^text\//) {
3997 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3999 binmode STDOUT
, ':raw';
4001 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4009 if (!defined $hash) {
4010 if (defined $file_name) {
4011 my $base = $hash_base || git_get_head_hash
($project);
4012 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4013 or die_error
(undef, "Error lookup file");
4015 die_error
(undef, "No file name defined");
4017 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4018 # blobs defined by non-textual hash id's can be cached
4022 my ($have_blame) = gitweb_check_feature
('blame');
4023 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4024 or die_error
(undef, "Couldn't cat $file_name, $hash");
4025 my $mimetype = blob_mimetype
($fd, $file_name);
4026 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
4028 return git_blob_plain
($mimetype);
4030 # we can have blame only for text/* mimetype
4031 $have_blame &&= ($mimetype =~ m!^text/!);
4033 git_header_html
(undef, $expires);
4034 my $formats_nav = '';
4035 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4036 if (defined $file_name) {
4039 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
4040 hash
=>$hash, file_name
=>$file_name)},
4045 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4046 hash
=>$hash, file_name
=>$file_name)},
4049 $cgi->a({-href
=> href
(action
=>"blob_plain",
4050 hash
=>$hash, file_name
=>$file_name)},
4053 $cgi->a({-href
=> href
(action
=>"blob",
4054 hash_base
=>"HEAD", file_name
=>$file_name)},
4058 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
4060 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4061 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4063 print "<div class=\"page_nav\">\n" .
4064 "<br/><br/></div>\n" .
4065 "<div class=\"title\">$hash</div>\n";
4067 git_print_page_path
($file_name, "blob", $hash_base);
4068 print "<div class=\"page_body\">\n";
4069 if ($mimetype =~ m!^text/!) {
4071 while (my $line = <$fd>) {
4074 $line = untabify
($line);
4075 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4076 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4078 } elsif ($mimetype =~ m!^image/!) {
4079 print qq
!<img type
="$mimetype"!;
4081 print qq
! alt
="$file_name" title
="$file_name"!;
4084 href(action=>"blob_plain
", hash=>$hash,
4085 hash_base=>$hash_base, file_name=>$file_name) .
4089 or print "Reading blob failed.\n";
4095 my $have_snapshot = gitweb_have_snapshot
();
4097 if (!defined $hash_base) {
4098 $hash_base = "HEAD";
4100 if (!defined $hash) {
4101 if (defined $file_name) {
4102 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4108 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4109 or die_error
(undef, "Open git-ls-tree failed");
4110 my @entries = map { chomp; $_ } <$fd>;
4111 close $fd or die_error
(undef, "Reading tree failed");
4114 my $refs = git_get_references
();
4115 my $ref = format_ref_marker
($refs, $hash_base);
4118 my ($have_blame) = gitweb_check_feature
('blame');
4119 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4121 if (defined $file_name) {
4123 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4124 hash
=>$hash, file_name
=>$file_name)},
4126 $cgi->a({-href
=> href
(action
=>"tree",
4127 hash_base
=>"HEAD", file_name
=>$file_name)},
4130 if ($have_snapshot) {
4131 # FIXME: Should be available when we have no hash base as well.
4133 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
4136 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4137 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4140 print "<div class=\"page_nav\">\n";
4141 print "<br/><br/></div>\n";
4142 print "<div class=\"title\">$hash</div>\n";
4144 if (defined $file_name) {
4145 $basedir = $file_name;
4146 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4150 git_print_page_path
($file_name, 'tree', $hash_base);
4151 print "<div class=\"page_body\">\n";
4152 print "<table cellspacing=\"0\">\n";
4154 # '..' (top directory) link if possible
4155 if (defined $hash_base &&
4156 defined $file_name && $file_name =~ m![^/]+$!) {
4158 print "<tr class=\"dark\">\n";
4160 print "<tr class=\"light\">\n";
4164 my $up = $file_name;
4165 $up =~ s!/?[^/]+$!!;
4166 undef $up unless $up;
4167 # based on git_print_tree_entry
4168 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4169 print '<td class="list">';
4170 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4174 print "<td class=\"link\"></td>\n";
4178 foreach my $line (@entries) {
4179 my %t = parse_ls_tree_line
($line, -z
=> 1);
4182 print "<tr class=\"dark\">\n";
4184 print "<tr class=\"light\">\n";
4188 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4192 print "</table>\n" .
4198 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
4199 my $have_snapshot = (defined $ctype && defined $suffix);
4200 if (!$have_snapshot) {
4201 die_error
('403 Permission denied', "Permission denied");
4204 if (!defined $hash) {
4205 $hash = git_get_head_hash
($project);
4208 my $git = git_cmd_str
();
4209 my $name = $project;
4210 $name =~ s
,([^/])/*\
.git
$,$1,;
4211 $name = basename
($name);
4212 my $filename = to_utf8
($name);
4213 $name =~ s/\047/\047\\\047\047/g;
4215 if ($suffix eq 'zip') {
4216 $filename .= "-$hash.$suffix";
4217 $cmd = "$git archive --format=zip --prefix=\'$name\'/ $hash";
4219 $filename .= "-$hash.tar.$suffix";
4220 $cmd = "$git archive --format=tar --prefix=\'$name\'/ $hash | $command";
4224 -type
=> "application/$ctype",
4225 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4226 -status
=> '200 OK');
4228 open my $fd, "-|", $cmd
4229 or die_error
(undef, "Execute git-archive failed");
4230 binmode STDOUT
, ':raw';
4232 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4238 my $head = git_get_head_hash
($project);
4239 if (!defined $hash) {
4242 if (!defined $page) {
4245 my $refs = git_get_references
();
4247 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4249 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4252 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4255 my %co = parse_commit
($hash);
4257 git_print_header_div
('summary', $project);
4258 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4260 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4261 for (my $i = 0; $i <= $to; $i++) {
4262 my %co = %{$commitlist[$i]};
4264 my $commit = $co{'id'};
4265 my $ref = format_ref_marker
($refs, $commit);
4266 my %ad = parse_date
($co{'author_epoch'});
4267 git_print_header_div
('commit',
4268 "<span class=\"age\">$co{'age_string'}</span>" .
4269 esc_html
($co{'title'}) . $ref,
4271 print "<div class=\"title_text\">\n" .
4272 "<div class=\"log_link\">\n" .
4273 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4275 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4277 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4280 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4283 print "<div class=\"log_body\">\n";
4284 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4287 if ($#commitlist >= 100) {
4288 print "<div class=\"page_nav\">\n";
4289 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4290 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4297 $hash ||= $hash_base || "HEAD";
4298 my %co = parse_commit
($hash);
4300 die_error
(undef, "Unknown commit object");
4302 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4303 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4305 my $parent = $co{'parent'};
4306 my $parents = $co{'parents'}; # listref
4308 # we need to prepare $formats_nav before any parameter munging
4310 if (!defined $parent) {
4312 $formats_nav .= '(initial)';
4313 } elsif (@$parents == 1) {
4314 # single parent commit
4317 $cgi->a({-href
=> href
(action
=>"commit",
4319 esc_html
(substr($parent, 0, 7))) .
4326 $cgi->a({-href
=> href
(action
=>"commit",
4328 esc_html
(substr($_, 0, 7)));
4333 if (!defined $parent) {
4337 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4339 (@$parents <= 1 ? $parent : '-c'),
4341 or die_error
(undef, "Open git-diff-tree failed");
4342 @difftree = map { chomp; $_ } <$fd>;
4343 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4345 # non-textual hash id's can be cached
4347 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4350 my $refs = git_get_references
();
4351 my $ref = format_ref_marker
($refs, $co{'id'});
4353 my $have_snapshot = gitweb_have_snapshot
();
4355 git_header_html
(undef, $expires);
4356 git_print_page_nav
('commit', '',
4357 $hash, $co{'tree'}, $hash,
4360 if (defined $co{'parent'}) {
4361 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4363 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4365 print "<div class=\"title_text\">\n" .
4366 "<table cellspacing=\"0\">\n";
4367 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4369 "<td></td><td> $ad{'rfc2822'}";
4370 if ($ad{'hour_local'} < 6) {
4371 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4372 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4374 printf(" (%02d:%02d %s)",
4375 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4379 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4380 print "<tr><td></td><td> $cd{'rfc2822'}" .
4381 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4383 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4386 "<td class=\"sha1\">" .
4387 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4388 class => "list"}, $co{'tree'}) .
4390 "<td class=\"link\">" .
4391 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4393 if ($have_snapshot) {
4395 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
4400 foreach my $par (@$parents) {
4403 "<td class=\"sha1\">" .
4404 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4405 class => "list"}, $par) .
4407 "<td class=\"link\">" .
4408 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4410 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4417 print "<div class=\"page_body\">\n";
4418 git_print_log
($co{'comment'});
4421 git_difftree_body
(\
@difftree, $hash, @$parents);
4427 # object is defined by:
4428 # - hash or hash_base alone
4429 # - hash_base and file_name
4432 # - hash or hash_base alone
4433 if ($hash || ($hash_base && !defined $file_name)) {
4434 my $object_id = $hash || $hash_base;
4436 my $git_command = git_cmd_str
();
4437 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4438 or die_error
('404 Not Found', "Object does not exist");
4442 or die_error
('404 Not Found', "Object does not exist");
4444 # - hash_base and file_name
4445 } elsif ($hash_base && defined $file_name) {
4446 $file_name =~ s
,/+$,,;
4448 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4449 or die_error
('404 Not Found', "Base object does not exist");
4451 # here errors should not hapen
4452 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4453 or die_error
(undef, "Open git-ls-tree failed");
4457 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4458 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4459 die_error
('404 Not Found', "File or directory for given base does not exist");
4464 die_error
('404 Not Found', "Not enough information to find object");
4467 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4468 hash
=>$hash, hash_base
=>$hash_base,
4469 file_name
=>$file_name),
4470 -status
=> '302 Found');
4474 my $format = shift || 'html';
4481 # preparing $fd and %diffinfo for git_patchset_body
4483 if (defined $hash_base && defined $hash_parent_base) {
4484 if (defined $file_name) {
4486 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4487 $hash_parent_base, $hash_base,
4488 "--", (defined $file_parent ? $file_parent : ()), $file_name
4489 or die_error
(undef, "Open git-diff-tree failed");
4490 @difftree = map { chomp; $_ } <$fd>;
4492 or die_error
(undef, "Reading git-diff-tree failed");
4494 or die_error
('404 Not Found', "Blob diff not found");
4496 } elsif (defined $hash &&
4497 $hash =~ /[0-9a-fA-F]{40}/) {
4498 # try to find filename from $hash
4500 # read filtered raw output
4501 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4502 $hash_parent_base, $hash_base, "--"
4503 or die_error
(undef, "Open git-diff-tree failed");
4505 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4507 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4508 map { chomp; $_ } <$fd>;
4510 or die_error
(undef, "Reading git-diff-tree failed");
4512 or die_error
('404 Not Found', "Blob diff not found");
4515 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4518 if (@difftree > 1) {
4519 die_error
('404 Not Found', "Ambiguous blob diff specification");
4522 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4523 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4524 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4526 $hash_parent ||= $diffinfo{'from_id'};
4527 $hash ||= $diffinfo{'to_id'};
4529 # non-textual hash id's can be cached
4530 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4531 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4536 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4537 '-p', ($format eq 'html' ? "--full-index" : ()),
4538 $hash_parent_base, $hash_base,
4539 "--", (defined $file_parent ? $file_parent : ()), $file_name
4540 or die_error
(undef, "Open git-diff-tree failed");
4543 # old/legacy style URI
4544 if (!%diffinfo && # if new style URI failed
4545 defined $hash && defined $hash_parent) {
4546 # fake git-diff-tree raw output
4547 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4548 $diffinfo{'from_id'} = $hash_parent;
4549 $diffinfo{'to_id'} = $hash;
4550 if (defined $file_name) {
4551 if (defined $file_parent) {
4552 $diffinfo{'status'} = '2';
4553 $diffinfo{'from_file'} = $file_parent;
4554 $diffinfo{'to_file'} = $file_name;
4555 } else { # assume not renamed
4556 $diffinfo{'status'} = '1';
4557 $diffinfo{'from_file'} = $file_name;
4558 $diffinfo{'to_file'} = $file_name;
4560 } else { # no filename given
4561 $diffinfo{'status'} = '2';
4562 $diffinfo{'from_file'} = $hash_parent;
4563 $diffinfo{'to_file'} = $hash;
4566 # non-textual hash id's can be cached
4567 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4568 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4573 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4574 '-p', ($format eq 'html' ? "--full-index" : ()),
4575 $hash_parent, $hash, "--"
4576 or die_error
(undef, "Open git-diff failed");
4578 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4583 if ($format eq 'html') {
4585 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4586 hash
=>$hash, hash_parent
=>$hash_parent,
4587 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4588 file_name
=>$file_name, file_parent
=>$file_parent)},
4590 git_header_html
(undef, $expires);
4591 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4592 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4593 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4595 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4596 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4598 if (defined $file_name) {
4599 git_print_page_path
($file_name, "blob", $hash_base);
4601 print "<div class=\"page_path\"></div>\n";
4604 } elsif ($format eq 'plain') {
4606 -type
=> 'text/plain',
4607 -charset
=> 'utf-8',
4608 -expires
=> $expires,
4609 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4611 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4614 die_error
(undef, "Unknown blobdiff format");
4618 if ($format eq 'html') {
4619 print "<div class=\"page_body\">\n";
4621 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4624 print "</div>\n"; # class="page_body"
4628 while (my $line = <$fd>) {
4629 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4630 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4634 last if $line =~ m!^\+\+\+!;
4642 sub git_blobdiff_plain
{
4643 git_blobdiff
('plain');
4646 sub git_commitdiff
{
4647 my $format = shift || 'html';
4648 $hash ||= $hash_base || "HEAD";
4649 my %co = parse_commit
($hash);
4651 die_error
(undef, "Unknown commit object");
4654 # choose format for commitdiff for merge
4655 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
4656 $hash_parent = '--cc';
4658 # we need to prepare $formats_nav before almost any parameter munging
4660 if ($format eq 'html') {
4662 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4663 hash
=>$hash, hash_parent
=>$hash_parent)},
4666 if (defined $hash_parent &&
4667 $hash_parent ne '-c' && $hash_parent ne '--cc') {
4668 # commitdiff with two commits given
4669 my $hash_parent_short = $hash_parent;
4670 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4671 $hash_parent_short = substr($hash_parent, 0, 7);
4675 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
4676 if ($co{'parents'}[$i] eq $hash_parent) {
4677 $formats_nav .= ' parent ' . ($i+1);
4681 $formats_nav .= ': ' .
4682 $cgi->a({-href
=> href
(action
=>"commitdiff",
4683 hash
=>$hash_parent)},
4684 esc_html
($hash_parent_short)) .
4686 } elsif (!$co{'parent'}) {
4688 $formats_nav .= ' (initial)';
4689 } elsif (scalar @{$co{'parents'}} == 1) {
4690 # single parent commit
4693 $cgi->a({-href
=> href
(action
=>"commitdiff",
4694 hash
=>$co{'parent'})},
4695 esc_html
(substr($co{'parent'}, 0, 7))) .
4699 if ($hash_parent eq '--cc') {
4700 $formats_nav .= ' | ' .
4701 $cgi->a({-href
=> href
(action
=>"commitdiff",
4702 hash
=>$hash, hash_parent
=>'-c')},
4704 } else { # $hash_parent eq '-c'
4705 $formats_nav .= ' | ' .
4706 $cgi->a({-href
=> href
(action
=>"commitdiff",
4707 hash
=>$hash, hash_parent
=>'--cc')},
4713 $cgi->a({-href
=> href
(action
=>"commitdiff",
4715 esc_html
(substr($_, 0, 7)));
4716 } @{$co{'parents'}} ) .
4721 my $hash_parent_param = $hash_parent;
4722 if (!defined $hash_parent_param) {
4723 # --cc for multiple parents, --root for parentless
4724 $hash_parent_param =
4725 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
4731 if ($format eq 'html') {
4732 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4733 "--no-commit-id", "--patch-with-raw", "--full-index",
4734 $hash_parent_param, $hash, "--"
4735 or die_error
(undef, "Open git-diff-tree failed");
4737 while (my $line = <$fd>) {
4739 # empty line ends raw part of diff-tree output
4741 push @difftree, scalar parse_difftree_raw_line
($line);
4744 } elsif ($format eq 'plain') {
4745 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4746 '-p', $hash_parent_param, $hash, "--"
4747 or die_error
(undef, "Open git-diff-tree failed");
4750 die_error
(undef, "Unknown commitdiff format");
4753 # non-textual hash id's can be cached
4755 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4759 # write commit message
4760 if ($format eq 'html') {
4761 my $refs = git_get_references
();
4762 my $ref = format_ref_marker
($refs, $co{'id'});
4764 git_header_html
(undef, $expires);
4765 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4766 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4767 git_print_authorship
(\
%co);
4768 print "<div class=\"page_body\">\n";
4769 if (@{$co{'comment'}} > 1) {
4770 print "<div class=\"log\">\n";
4771 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4772 print "</div>\n"; # class="log"
4775 } elsif ($format eq 'plain') {
4776 my $refs = git_get_references
("tags");
4777 my $tagname = git_get_rev_name_tags
($hash);
4778 my $filename = basename
($project) . "-$hash.patch";
4781 -type
=> 'text/plain',
4782 -charset
=> 'utf-8',
4783 -expires
=> $expires,
4784 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4785 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4788 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4789 Subject: $co{'title'}
4791 print "X-Git-Tag: $tagname\n" if $tagname;
4792 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4794 foreach my $line (@{$co{'comment'}}) {
4801 if ($format eq 'html') {
4802 my $use_parents = !defined $hash_parent ||
4803 $hash_parent eq '-c' || $hash_parent eq '--cc';
4804 git_difftree_body
(\
@difftree, $hash,
4805 $use_parents ? @{$co{'parents'}} : $hash_parent);
4808 git_patchset_body
($fd, \
@difftree, $hash,
4809 $use_parents ? @{$co{'parents'}} : $hash_parent);
4811 print "</div>\n"; # class="page_body"
4814 } elsif ($format eq 'plain') {
4818 or print "Reading git-diff-tree failed\n";
4822 sub git_commitdiff_plain
{
4823 git_commitdiff
('plain');
4827 if (!defined $hash_base) {
4828 $hash_base = git_get_head_hash
($project);
4830 if (!defined $page) {
4834 my %co = parse_commit
($hash_base);
4836 die_error
(undef, "Unknown commit object");
4839 my $refs = git_get_references
();
4840 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4842 if (!defined $hash && defined $file_name) {
4843 $hash = git_get_hash_by_path
($hash_base, $file_name);
4845 if (defined $hash) {
4846 $ftype = git_get_type
($hash);
4849 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4851 my $paging_nav = '';
4854 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4855 file_name
=>$file_name)},
4857 $paging_nav .= " ⋅ " .
4858 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4859 file_name
=>$file_name, page
=>$page-1),
4860 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4862 $paging_nav .= "first";
4863 $paging_nav .= " ⋅ prev";
4865 if ($#commitlist >= 100) {
4866 $paging_nav .= " ⋅ " .
4867 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4868 file_name
=>$file_name, page
=>$page+1),
4869 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4871 $paging_nav .= " ⋅ next";
4874 if ($#commitlist >= 100) {
4876 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4877 file_name
=>$file_name, page
=>$page+1),
4878 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4882 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4883 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4884 git_print_page_path
($file_name, $ftype, $hash_base);
4886 git_history_body
(\
@commitlist, 0, 99,
4887 $refs, $hash_base, $ftype, $next_link);
4893 my ($have_search) = gitweb_check_feature
('search');
4894 if (!$have_search) {
4895 die_error
('403 Permission denied', "Permission denied");
4897 if (!defined $searchtext) {
4898 die_error
(undef, "Text field empty");
4900 if (!defined $hash) {
4901 $hash = git_get_head_hash
($project);
4903 my %co = parse_commit
($hash);
4905 die_error
(undef, "Unknown commit object");
4907 if (!defined $page) {
4911 $searchtype ||= 'commit';
4912 if ($searchtype eq 'pickaxe') {
4913 # pickaxe may take all resources of your box and run for several minutes
4914 # with every query - so decide by yourself how public you make this feature
4915 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4916 if (!$have_pickaxe) {
4917 die_error
('403 Permission denied', "Permission denied");
4920 if ($searchtype eq 'grep') {
4921 my ($have_grep) = gitweb_check_feature
('grep');
4923 die_error
('403 Permission denied', "Permission denied");
4929 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4931 if ($searchtype eq 'commit') {
4932 $greptype = "--grep=";
4933 } elsif ($searchtype eq 'author') {
4934 $greptype = "--author=";
4935 } elsif ($searchtype eq 'committer') {
4936 $greptype = "--committer=";
4938 $greptype .= $search_regexp;
4939 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4941 my $paging_nav = '';
4944 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4945 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4947 $paging_nav .= " ⋅ " .
4948 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4949 searchtext
=>$searchtext, searchtype
=>$searchtype,
4951 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4953 $paging_nav .= "first";
4954 $paging_nav .= " ⋅ prev";
4956 if ($#commitlist >= 100) {
4957 $paging_nav .= " ⋅ " .
4958 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4959 searchtext
=>$searchtext, searchtype
=>$searchtype,
4961 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4963 $paging_nav .= " ⋅ next";
4966 if ($#commitlist >= 100) {
4968 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4969 searchtext
=>$searchtext, searchtype
=>$searchtype,
4971 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4974 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4975 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4976 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4979 if ($searchtype eq 'pickaxe') {
4980 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4981 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4983 print "<table cellspacing=\"0\">\n";
4986 my $git_command = git_cmd_str
();
4987 my $searchqtext = $searchtext;
4988 $searchqtext =~ s/'/'\\''/;
4989 open my $fd, "-|", "$git_command rev-list $hash | " .
4990 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
4993 while (my $line = <$fd>) {
4994 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4997 $set{'from_id'} = $3;
4999 $set{'id'} = $set{'to_id'};
5000 if ($set{'id'} =~ m/0{40}/) {
5001 $set{'id'} = $set{'from_id'};
5003 if ($set{'id'} =~ m/0{40}/) {
5007 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
5010 print "<tr class=\"dark\">\n";
5012 print "<tr class=\"light\">\n";
5015 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5016 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
5018 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5019 -class => "list subject"},
5020 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
5021 while (my $setref = shift @files) {
5023 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5024 hash
=>$set{'id'}, file_name
=>$set{'file'}),
5026 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5030 "<td class=\"link\">" .
5031 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5033 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5037 %co = parse_commit
($1);
5045 if ($searchtype eq 'grep') {
5046 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5047 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5049 print "<table cellspacing=\"0\">\n";
5053 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
5055 while (my $line = <$fd>) {
5057 my ($file, $lno, $ltext, $binary);
5058 last if ($matches++ > 1000);
5059 if ($line =~ /^Binary file (.+) matches$/) {
5063 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5065 if ($file ne $lastfile) {
5066 $lastfile and print "</td></tr>\n";
5068 print "<tr class=\"dark\">\n";
5070 print "<tr class=\"light\">\n";
5072 print "<td class=\"list\">".
5073 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5074 file_name
=>"$file"),
5075 -class => "list"}, esc_path
($file));
5076 print "</td><td>\n";
5080 print "<div class=\"binary\">Binary file</div>\n";
5082 $ltext = untabify
($ltext);
5083 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
5084 $ltext = esc_html
($1, -nbsp
=>1);
5085 $ltext .= '<span class="match">';
5086 $ltext .= esc_html
($2, -nbsp
=>1);
5087 $ltext .= '</span>';
5088 $ltext .= esc_html
($3, -nbsp
=>1);
5090 $ltext = esc_html
($ltext, -nbsp
=>1);
5092 print "<div class=\"pre\">" .
5093 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5094 file_name
=>"$file").'#l'.$lno,
5095 -class => "linenr"}, sprintf('%4i', $lno))
5096 . ' ' . $ltext . "</div>\n";
5100 print "</td></tr>\n";
5101 if ($matches > 1000) {
5102 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5105 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5114 sub git_search_help
{
5116 git_print_page_nav
('','', $hash,$hash,$hash);
5119 <dt><b>commit</b></dt>
5120 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
5122 my ($have_grep) = gitweb_check_feature
('grep');
5125 <dt><b>grep</b></dt>
5126 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5127 a different one) are searched for the given
5128 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5129 (POSIX extended) and the matches are listed. On large
5130 trees, this search can take a while and put some strain on the server, so please use it with
5131 some consideration.</dd>
5135 <dt><b>author</b></dt>
5136 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5137 <dt><b>committer</b></dt>
5138 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5140 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5141 if ($have_pickaxe) {
5143 <dt><b>pickaxe</b></dt>
5144 <dd>All commits that caused the string to appear or disappear from any file (changes that
5145 added, removed or "modified" the string) will be listed. This search can take a while and
5146 takes a lot of strain on the server, so please use it wisely.</dd>
5154 my $head = git_get_head_hash
($project);
5155 if (!defined $hash) {
5158 if (!defined $page) {
5161 my $refs = git_get_references
();
5163 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5165 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
5167 if ($#commitlist >= 100) {
5169 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
5170 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5174 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5175 git_print_header_div
('summary', $project);
5177 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5182 ## ......................................................................
5183 ## feeds (RSS, Atom; OPML)
5186 my $format = shift || 'atom';
5187 my ($have_blame) = gitweb_check_feature
('blame');
5189 # Atom: http://www.atomenabled.org/developers/syndication/
5190 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5191 if ($format ne 'rss' && $format ne 'atom') {
5192 die_error
(undef, "Unknown web feed format");
5195 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5196 my $head = $hash || 'HEAD';
5197 my @commitlist = parse_commits
($head, 150);
5201 my $content_type = "application/$format+xml";
5202 if (defined $cgi->http('HTTP_ACCEPT') &&
5203 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5204 # browser (feed reader) prefers text/xml
5205 $content_type = 'text/xml';
5207 if (defined($commitlist[0])) {
5208 %latest_commit = %{$commitlist[0]};
5209 %latest_date = parse_date
($latest_commit{'author_epoch'});
5211 -type
=> $content_type,
5212 -charset
=> 'utf-8',
5213 -last_modified
=> $latest_date{'rfc2822'});
5216 -type
=> $content_type,
5217 -charset
=> 'utf-8');
5220 # Optimization: skip generating the body if client asks only
5221 # for Last-Modified date.
5222 return if ($cgi->request_method() eq 'HEAD');
5225 my $title = "$site_name - $project/$action";
5226 my $feed_type = 'log';
5227 if (defined $hash) {
5228 $title .= " - '$hash'";
5229 $feed_type = 'branch log';
5230 if (defined $file_name) {
5231 $title .= " :: $file_name";
5232 $feed_type = 'history';
5234 } elsif (defined $file_name) {
5235 $title .= " - $file_name";
5236 $feed_type = 'history';
5238 $title .= " $feed_type";
5239 my $descr = git_get_project_description
($project);
5240 if (defined $descr) {
5241 $descr = esc_html
($descr);
5243 $descr = "$project " .
5244 ($format eq 'rss' ? 'RSS' : 'Atom') .
5247 my $owner = git_get_project_owner
($project);
5248 $owner = esc_html
($owner);
5252 if (defined $file_name) {
5253 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5254 } elsif (defined $hash) {
5255 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5257 $alt_url = href
(-full
=>1, action
=>"summary");
5259 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5260 if ($format eq 'rss') {
5262 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5265 print "<title>$title</title>\n" .
5266 "<link>$alt_url</link>\n" .
5267 "<description>$descr</description>\n" .
5268 "<language>en</language>\n";
5269 } elsif ($format eq 'atom') {
5271 <feed xmlns="http://www.w3.org/2005/Atom">
5273 print "<title>$title</title>\n" .
5274 "<subtitle>$descr</subtitle>\n" .
5275 '<link rel="alternate" type="text/html" href="' .
5276 $alt_url . '" />' . "\n" .
5277 '<link rel="self" type="' . $content_type . '" href="' .
5278 $cgi->self_url() . '" />' . "\n" .
5279 "<id>" . href
(-full
=>1) . "</id>\n" .
5280 # use project owner for feed author
5281 "<author><name>$owner</name></author>\n";
5282 if (defined $favicon) {
5283 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5285 if (defined $logo_url) {
5286 # not twice as wide as tall: 72 x 27 pixels
5287 print "<logo>" . esc_url
($logo) . "</logo>\n";
5289 if (! %latest_date) {
5290 # dummy date to keep the feed valid until commits trickle in:
5291 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5293 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5298 for (my $i = 0; $i <= $#commitlist; $i++) {
5299 my %co = %{$commitlist[$i]};
5300 my $commit = $co{'id'};
5301 # we read 150, we always show 30 and the ones more recent than 48 hours
5302 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5305 my %cd = parse_date
($co{'author_epoch'});
5307 # get list of changed files
5308 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5309 $co{'parent'} || "--root",
5310 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5312 my @difftree = map { chomp; $_ } <$fd>;
5316 # print element (entry, item)
5317 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5318 if ($format eq 'rss') {
5320 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5321 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5322 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5323 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5324 "<link>$co_url</link>\n" .
5325 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5326 "<content:encoded>" .
5328 } elsif ($format eq 'atom') {
5330 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5331 "<updated>$cd{'iso-8601'}</updated>\n" .
5333 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5334 if ($co{'author_email'}) {
5335 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5337 print "</author>\n" .
5338 # use committer for contributor
5340 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5341 if ($co{'committer_email'}) {
5342 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5344 print "</contributor>\n" .
5345 "<published>$cd{'iso-8601'}</published>\n" .
5346 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5347 "<id>$co_url</id>\n" .
5348 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5349 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5351 my $comment = $co{'comment'};
5353 foreach my $line (@$comment) {
5354 $line = esc_html
($line);
5357 print "</pre><ul>\n";
5358 foreach my $difftree_line (@difftree) {
5359 my %difftree = parse_difftree_raw_line
($difftree_line);
5360 next if !$difftree{'from_id'};
5362 my $file = $difftree{'file'} || $difftree{'to_file'};
5366 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5367 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5368 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5369 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5370 -title
=> "diff"}, 'D');
5372 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5373 file_name
=>$file, hash_base
=>$commit),
5374 -title
=> "blame"}, 'B');
5376 # if this is not a feed of a file history
5377 if (!defined $file_name || $file_name ne $file) {
5378 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5379 file_name
=>$file, hash
=>$commit),
5380 -title
=> "history"}, 'H');
5382 $file = esc_path
($file);
5386 if ($format eq 'rss') {
5387 print "</ul>]]>\n" .
5388 "</content:encoded>\n" .
5390 } elsif ($format eq 'atom') {
5391 print "</ul>\n</div>\n" .
5398 if ($format eq 'rss') {
5399 print "</channel>\n</rss>\n";
5400 } elsif ($format eq 'atom') {
5414 my @list = git_get_projects_list
();
5416 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5418 <?xml version="1.0" encoding="utf-8"?>
5419 <opml version="1.0">
5421 <title>$site_name OPML Export</title>
5424 <outline text="git RSS feeds">
5427 foreach my $pr (@list) {
5429 my $head = git_get_head_hash
($proj{'path'});
5430 if (!defined $head) {
5433 $git_dir = "$projectroot/$proj{'path'}";
5434 my %co = parse_commit
($head);
5439 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5440 my $rss = "$my_url?p=$proj{'path'};a=rss";
5441 my $html = "$my_url?p=$proj{'path'};a=summary";
5442 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";