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) = @_;
1067 #assert($line =~ m/^---/) if DEBUG;
1068 # no extra formatting "^--- /dev/null"
1069 if ($line =~ m!^--- "?a/!) {
1070 if (!$diffinfo->{'nparents'} && # multiple 'from'
1073 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1074 esc_path
($from->{'file'}));
1077 esc_path
($from->{'file'});
1080 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1083 #assert($line =~ m/^\+\+\+/) if DEBUG;
1084 # no extra formatting for "^+++ /dev/null"
1085 if ($line =~ m!^\+\+\+ "?b/!) {
1086 if ($to->{'href'}) {
1088 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1089 esc_path
($to->{'file'}));
1092 esc_path
($to->{'file'});
1095 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1100 # format patch (diff) line (not to be used for diff headers)
1101 sub format_diff_line
{
1103 my ($from, $to) = @_;
1104 my $diff_class = "";
1108 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1110 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1111 if ($line =~ m/^\@{3}/) {
1112 $diff_class = " chunk_header";
1113 } elsif ($line =~ m/^\\/) {
1114 $diff_class = " incomplete";
1115 } elsif ($prefix =~ tr/+/+/) {
1116 $diff_class = " add";
1117 } elsif ($prefix =~ tr/-/-/) {
1118 $diff_class = " rem";
1121 # assume ordinary diff
1122 my $char = substr($line, 0, 1);
1124 $diff_class = " add";
1125 } elsif ($char eq '-') {
1126 $diff_class = " rem";
1127 } elsif ($char eq '@') {
1128 $diff_class = " chunk_header";
1129 } elsif ($char eq "\\") {
1130 $diff_class = " incomplete";
1133 $line = untabify
($line);
1134 if ($from && $to && $line =~ m/^\@{2} /) {
1135 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1136 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1138 $from_lines = 0 unless defined $from_lines;
1139 $to_lines = 0 unless defined $to_lines;
1141 if ($from->{'href'}) {
1142 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1143 -class=>"list"}, $from_text);
1145 if ($to->{'href'}) {
1146 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1147 -class=>"list"}, $to_text);
1149 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1150 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1151 return "<div class=\"diff$diff_class\">$line</div>\n";
1152 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1153 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1154 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1156 @from_text = split(' ', $ranges);
1157 for (my $i = 0; $i < @from_text; ++$i) {
1158 ($from_start[$i], $from_nlines[$i]) =
1159 (split(',', substr($from_text[$i], 1)), 0);
1162 $to_text = pop @from_text;
1163 $to_start = pop @from_start;
1164 $to_nlines = pop @from_nlines;
1166 $line = "<span class=\"chunk_info\">$prefix ";
1167 for (my $i = 0; $i < @from_text; ++$i) {
1168 if ($from->{'href'}[$i]) {
1169 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1170 -class=>"list"}, $from_text[$i]);
1172 $line .= $from_text[$i];
1176 if ($to->{'href'}) {
1177 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1178 -class=>"list"}, $to_text);
1182 $line .= " $prefix</span>" .
1183 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1184 return "<div class=\"diff$diff_class\">$line</div>\n";
1186 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1189 ## ----------------------------------------------------------------------
1190 ## git utility subroutines, invoking git commands
1192 # returns path to the core git executable and the --git-dir parameter as list
1194 return $GIT, '--git-dir='.$git_dir;
1197 # returns path to the core git executable and the --git-dir parameter as string
1199 return join(' ', git_cmd
());
1202 # get HEAD ref of given project as hash
1203 sub git_get_head_hash
{
1204 my $project = shift;
1205 my $o_git_dir = $git_dir;
1207 $git_dir = "$projectroot/$project";
1208 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1211 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1215 if (defined $o_git_dir) {
1216 $git_dir = $o_git_dir;
1221 # get type of given object
1225 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1227 close $fd or return;
1232 sub git_get_project_config
{
1233 my ($key, $type) = @_;
1235 return unless ($key);
1236 $key =~ s/^gitweb\.//;
1237 return if ($key =~ m/\W/);
1239 my @x = (git_cmd
(), 'config');
1240 if (defined $type) { push @x, $type; }
1242 push @x, "gitweb.$key";
1248 # get hash of given path at given ref
1249 sub git_get_hash_by_path
{
1251 my $path = shift || return undef;
1256 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1257 or die_error
(undef, "Open git-ls-tree failed");
1259 close $fd or return undef;
1261 if (!defined $line) {
1262 # there is no tree or hash given by $path at $base
1266 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1267 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1268 if (defined $type && $type ne $2) {
1269 # type doesn't match
1275 # get path of entry with given hash at given tree-ish (ref)
1276 # used to get 'from' filename for combined diff (merge commit) for renames
1277 sub git_get_path_by_hash
{
1278 my $base = shift || return;
1279 my $hash = shift || return;
1283 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1285 while (my $line = <$fd>) {
1288 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1289 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1290 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1299 ## ......................................................................
1300 ## git utility functions, directly accessing git repository
1302 sub git_get_project_description
{
1305 open my $fd, "$projectroot/$path/description" or return undef;
1308 if (defined $descr) {
1314 sub git_get_project_url_list
{
1317 open my $fd, "$projectroot/$path/cloneurl" or return;
1318 my @git_project_url_list = map { chomp; $_ } <$fd>;
1321 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1324 sub git_get_projects_list
{
1329 $filter =~ s/\.git$//;
1331 my ($check_forks) = gitweb_check_feature
('forks');
1333 if (-d
$projects_list) {
1334 # search in directory
1335 my $dir = $projects_list . ($filter ? "/$filter" : '');
1336 # remove the trailing "/"
1338 my $pfxlen = length("$dir");
1341 follow_fast
=> 1, # follow symbolic links
1342 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1344 # skip project-list toplevel, if we get it.
1345 return if (m!^[/.]$!);
1346 # only directories can be git repositories
1347 return unless (-d
$_);
1349 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1350 # we check related file in $projectroot
1351 if ($check_forks and $subdir =~ m
#/.#) {
1352 $File::Find
::prune
= 1;
1353 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1354 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1355 $File::Find
::prune
= 1;
1360 } elsif (-f
$projects_list) {
1361 # read from file(url-encoded):
1362 # 'git%2Fgit.git Linus+Torvalds'
1363 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1364 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1366 open my ($fd), $projects_list or return;
1368 while (my $line = <$fd>) {
1370 my ($path, $owner) = split ' ', $line;
1371 $path = unescape
($path);
1372 $owner = unescape
($owner);
1373 if (!defined $path) {
1376 if ($filter ne '') {
1377 # looking for forks;
1378 my $pfx = substr($path, 0, length($filter));
1379 if ($pfx ne $filter) {
1382 my $sfx = substr($path, length($filter));
1383 if ($sfx !~ /^\/.*\
.git
$/) {
1386 } elsif ($check_forks) {
1388 foreach my $filter (keys %paths) {
1389 # looking for forks;
1390 my $pfx = substr($path, 0, length($filter));
1391 if ($pfx ne $filter) {
1394 my $sfx = substr($path, length($filter));
1395 if ($sfx !~ /^\/.*\
.git
$/) {
1398 # is a fork, don't include it in
1403 if (check_export_ok
("$projectroot/$path")) {
1406 owner
=> to_utf8
($owner),
1409 (my $forks_path = $path) =~ s/\.git$//;
1410 $paths{$forks_path}++;
1418 sub git_get_project_owner
{
1419 my $project = shift;
1422 return undef unless $project;
1424 # read from file (url-encoded):
1425 # 'git%2Fgit.git Linus+Torvalds'
1426 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1427 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1428 if (-f
$projects_list) {
1429 open (my $fd , $projects_list);
1430 while (my $line = <$fd>) {
1432 my ($pr, $ow) = split ' ', $line;
1433 $pr = unescape
($pr);
1434 $ow = unescape
($ow);
1435 if ($pr eq $project) {
1436 $owner = to_utf8
($ow);
1442 if (!defined $owner) {
1443 $owner = get_file_owner
("$projectroot/$project");
1449 sub git_get_last_activity
{
1453 $git_dir = "$projectroot/$path";
1454 open($fd, "-|", git_cmd
(), 'for-each-ref',
1455 '--format=%(committer)',
1456 '--sort=-committerdate',
1458 'refs/heads') or return;
1459 my $most_recent = <$fd>;
1460 close $fd or return;
1461 if (defined $most_recent &&
1462 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1464 my $age = time - $timestamp;
1465 return ($age, age_string
($age));
1469 sub git_get_references
{
1470 my $type = shift || "";
1472 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1473 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1474 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1475 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1478 while (my $line = <$fd>) {
1480 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1481 if (defined $refs{$1}) {
1482 push @{$refs{$1}}, $2;
1488 close $fd or return;
1492 sub git_get_rev_name_tags
{
1493 my $hash = shift || return undef;
1495 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1497 my $name_rev = <$fd>;
1500 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1503 # catches also '$hash undefined' output
1508 ## ----------------------------------------------------------------------
1509 ## parse to hash functions
1513 my $tz = shift || "-0000";
1516 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1517 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1518 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1519 $date{'hour'} = $hour;
1520 $date{'minute'} = $min;
1521 $date{'mday'} = $mday;
1522 $date{'day'} = $days[$wday];
1523 $date{'month'} = $months[$mon];
1524 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1525 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1526 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1527 $mday, $months[$mon], $hour ,$min;
1528 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1529 1900+$year, $mon, $mday, $hour ,$min, $sec;
1531 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1532 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1533 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1534 $date{'hour_local'} = $hour;
1535 $date{'minute_local'} = $min;
1536 $date{'tz_local'} = $tz;
1537 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1538 1900+$year, $mon+1, $mday,
1539 $hour, $min, $sec, $tz);
1548 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1549 $tag{'id'} = $tag_id;
1550 while (my $line = <$fd>) {
1552 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1553 $tag{'object'} = $1;
1554 } elsif ($line =~ m/^type (.+)$/) {
1556 } elsif ($line =~ m/^tag (.+)$/) {
1558 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1559 $tag{'author'} = $1;
1562 } elsif ($line =~ m/--BEGIN/) {
1563 push @comment, $line;
1565 } elsif ($line eq "") {
1569 push @comment, <$fd>;
1570 $tag{'comment'} = \
@comment;
1571 close $fd or return;
1572 if (!defined $tag{'name'}) {
1578 sub parse_commit_text
{
1579 my ($commit_text, $withparents) = @_;
1580 my @commit_lines = split '\n', $commit_text;
1583 pop @commit_lines; # Remove '\0'
1585 if (! @commit_lines) {
1589 my $header = shift @commit_lines;
1590 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1593 ($co{'id'}, my @parents) = split ' ', $header;
1594 while (my $line = shift @commit_lines) {
1595 last if $line eq "\n";
1596 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1598 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1600 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1602 $co{'author_epoch'} = $2;
1603 $co{'author_tz'} = $3;
1604 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1605 $co{'author_name'} = $1;
1606 $co{'author_email'} = $2;
1608 $co{'author_name'} = $co{'author'};
1610 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1611 $co{'committer'} = $1;
1612 $co{'committer_epoch'} = $2;
1613 $co{'committer_tz'} = $3;
1614 $co{'committer_name'} = $co{'committer'};
1615 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1616 $co{'committer_name'} = $1;
1617 $co{'committer_email'} = $2;
1619 $co{'committer_name'} = $co{'committer'};
1623 if (!defined $co{'tree'}) {
1626 $co{'parents'} = \
@parents;
1627 $co{'parent'} = $parents[0];
1629 foreach my $title (@commit_lines) {
1632 $co{'title'} = chop_str
($title, 80, 5);
1633 # remove leading stuff of merges to make the interesting part visible
1634 if (length($title) > 50) {
1635 $title =~ s/^Automatic //;
1636 $title =~ s/^merge (of|with) /Merge ... /i;
1637 if (length($title) > 50) {
1638 $title =~ s/(http|rsync):\/\///;
1640 if (length($title) > 50) {
1641 $title =~ s/(master|www|rsync)\.//;
1643 if (length($title) > 50) {
1644 $title =~ s/kernel.org:?//;
1646 if (length($title) > 50) {
1647 $title =~ s/\/pub\/scm//;
1650 $co{'title_short'} = chop_str
($title, 50, 5);
1654 if ($co{'title'} eq "") {
1655 $co{'title'} = $co{'title_short'} = '(no commit message)';
1657 # remove added spaces
1658 foreach my $line (@commit_lines) {
1661 $co{'comment'} = \
@commit_lines;
1663 my $age = time - $co{'committer_epoch'};
1665 $co{'age_string'} = age_string
($age);
1666 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1667 if ($age > 60*60*24*7*2) {
1668 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1669 $co{'age_string_age'} = $co{'age_string'};
1671 $co{'age_string_date'} = $co{'age_string'};
1672 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1678 my ($commit_id) = @_;
1683 open my $fd, "-|", git_cmd
(), "rev-list",
1689 or die_error
(undef, "Open git-rev-list failed");
1690 %co = parse_commit_text
(<$fd>, 1);
1697 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1705 open my $fd, "-|", git_cmd
(), "rev-list",
1707 ($arg ? ($arg) : ()),
1708 ("--max-count=" . $maxcount),
1709 ("--skip=" . $skip),
1712 ($filename ? ($filename) : ())
1713 or die_error
(undef, "Open git-rev-list failed");
1714 while (my $line = <$fd>) {
1715 my %co = parse_commit_text
($line);
1720 return wantarray ? @cos : \
@cos;
1723 # parse ref from ref_file, given by ref_id, with given type
1725 my $ref_file = shift;
1727 my $type = shift || git_get_type
($ref_id);
1730 $ref_item{'type'} = $type;
1731 $ref_item{'id'} = $ref_id;
1732 $ref_item{'epoch'} = 0;
1733 $ref_item{'age'} = "unknown";
1734 if ($type eq "tag") {
1735 my %tag = parse_tag
($ref_id);
1736 $ref_item{'comment'} = $tag{'comment'};
1737 if ($tag{'type'} eq "commit") {
1738 my %co = parse_commit
($tag{'object'});
1739 $ref_item{'epoch'} = $co{'committer_epoch'};
1740 $ref_item{'age'} = $co{'age_string'};
1741 } elsif (defined($tag{'epoch'})) {
1742 my $age = time - $tag{'epoch'};
1743 $ref_item{'epoch'} = $tag{'epoch'};
1744 $ref_item{'age'} = age_string
($age);
1746 $ref_item{'reftype'} = $tag{'type'};
1747 $ref_item{'name'} = $tag{'name'};
1748 $ref_item{'refid'} = $tag{'object'};
1749 } elsif ($type eq "commit"){
1750 my %co = parse_commit
($ref_id);
1751 $ref_item{'reftype'} = "commit";
1752 $ref_item{'name'} = $ref_file;
1753 $ref_item{'title'} = $co{'title'};
1754 $ref_item{'refid'} = $ref_id;
1755 $ref_item{'epoch'} = $co{'committer_epoch'};
1756 $ref_item{'age'} = $co{'age_string'};
1758 $ref_item{'reftype'} = $type;
1759 $ref_item{'name'} = $ref_file;
1760 $ref_item{'refid'} = $ref_id;
1766 # parse line of git-diff-tree "raw" output
1767 sub parse_difftree_raw_line
{
1771 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1772 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1773 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1774 $res{'from_mode'} = $1;
1775 $res{'to_mode'} = $2;
1776 $res{'from_id'} = $3;
1778 $res{'status'} = $5;
1779 $res{'similarity'} = $6;
1780 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1781 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1783 $res{'file'} = unquote
($7);
1786 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1787 # combined diff (for merge commit)
1788 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1789 $res{'nparents'} = length($1);
1790 $res{'from_mode'} = [ split(' ', $2) ];
1791 $res{'to_mode'} = pop @{$res{'from_mode'}};
1792 $res{'from_id'} = [ split(' ', $3) ];
1793 $res{'to_id'} = pop @{$res{'from_id'}};
1794 $res{'status'} = [ split('', $4) ];
1795 $res{'to_file'} = unquote
($5);
1797 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1798 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1799 $res{'commit'} = $1;
1802 return wantarray ? %res : \
%res;
1805 # parse line of git-ls-tree output
1806 sub parse_ls_tree_line
($;%) {
1811 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1812 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1820 $res{'name'} = unquote
($4);
1823 return wantarray ? %res : \
%res;
1826 # generates _two_ hashes, references to which are passed as 2 and 3 argument
1827 sub parse_from_to_diffinfo
{
1828 my ($diffinfo, $from, $to, @parents) = @_;
1830 if ($diffinfo->{'nparents'}) {
1832 $from->{'file'} = [];
1833 $from->{'href'} = [];
1834 fill_from_file_info
($diffinfo, @parents)
1835 unless exists $diffinfo->{'from_file'};
1836 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1837 $from->{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
1838 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
1839 $from->{'href'}[$i] = href
(action
=>"blob",
1840 hash_base
=>$parents[$i],
1841 hash
=>$diffinfo->{'from_id'}[$i],
1842 file_name
=>$from->{'file'}[$i]);
1844 $from->{'href'}[$i] = undef;
1848 $from->{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
1849 if ($diffinfo->{'status'} ne "A") { # not new (added) file
1850 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
1851 hash
=>$diffinfo->{'from_id'},
1852 file_name
=>$from->{'file'});
1854 delete $from->{'href'};
1858 $to->{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
1859 if (!is_deleted
($diffinfo)) { # file exists in result
1860 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
1861 hash
=>$diffinfo->{'to_id'},
1862 file_name
=>$to->{'file'});
1864 delete $to->{'href'};
1868 ## ......................................................................
1869 ## parse to array of hashes functions
1871 sub git_get_heads_list
{
1875 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1876 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1877 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1880 while (my $line = <$fd>) {
1884 my ($refinfo, $committerinfo) = split(/\0/, $line);
1885 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1886 my ($committer, $epoch, $tz) =
1887 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1888 $name =~ s!^refs/heads/!!;
1890 $ref_item{'name'} = $name;
1891 $ref_item{'id'} = $hash;
1892 $ref_item{'title'} = $title || '(no commit message)';
1893 $ref_item{'epoch'} = $epoch;
1895 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1897 $ref_item{'age'} = "unknown";
1900 push @headslist, \
%ref_item;
1904 return wantarray ? @headslist : \
@headslist;
1907 sub git_get_tags_list
{
1911 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1912 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1913 '--format=%(objectname) %(objecttype) %(refname) '.
1914 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1917 while (my $line = <$fd>) {
1921 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1922 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1923 my ($creator, $epoch, $tz) =
1924 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1925 $name =~ s!^refs/tags/!!;
1927 $ref_item{'type'} = $type;
1928 $ref_item{'id'} = $id;
1929 $ref_item{'name'} = $name;
1930 if ($type eq "tag") {
1931 $ref_item{'subject'} = $title;
1932 $ref_item{'reftype'} = $reftype;
1933 $ref_item{'refid'} = $refid;
1935 $ref_item{'reftype'} = $type;
1936 $ref_item{'refid'} = $id;
1939 if ($type eq "tag" || $type eq "commit") {
1940 $ref_item{'epoch'} = $epoch;
1942 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1944 $ref_item{'age'} = "unknown";
1948 push @tagslist, \
%ref_item;
1952 return wantarray ? @tagslist : \
@tagslist;
1955 ## ----------------------------------------------------------------------
1956 ## filesystem-related functions
1958 sub get_file_owner
{
1961 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1962 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1963 if (!defined $gcos) {
1967 $owner =~ s/[,;].*$//;
1968 return to_utf8
($owner);
1971 ## ......................................................................
1972 ## mimetype related functions
1974 sub mimetype_guess_file
{
1975 my $filename = shift;
1976 my $mimemap = shift;
1977 -r
$mimemap or return undef;
1980 open(MIME
, $mimemap) or return undef;
1982 next if m/^#/; # skip comments
1983 my ($mime, $exts) = split(/\t+/);
1984 if (defined $exts) {
1985 my @exts = split(/\s+/, $exts);
1986 foreach my $ext (@exts) {
1987 $mimemap{$ext} = $mime;
1993 $filename =~ /\.([^.]*)$/;
1994 return $mimemap{$1};
1997 sub mimetype_guess
{
1998 my $filename = shift;
2000 $filename =~ /\./ or return undef;
2002 if ($mimetypes_file) {
2003 my $file = $mimetypes_file;
2004 if ($file !~ m!^/!) { # if it is relative path
2005 # it is relative to project
2006 $file = "$projectroot/$project/$file";
2008 $mime = mimetype_guess_file
($filename, $file);
2010 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2016 my $filename = shift;
2019 my $mime = mimetype_guess
($filename);
2020 $mime and return $mime;
2024 return $default_blob_plain_mimetype unless $fd;
2027 return 'text/plain' .
2028 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
2029 } elsif (! $filename) {
2030 return 'application/octet-stream';
2031 } elsif ($filename =~ m/\.png$/i) {
2033 } elsif ($filename =~ m/\.gif$/i) {
2035 } elsif ($filename =~ m/\.jpe?g$/i) {
2036 return 'image/jpeg';
2038 return 'application/octet-stream';
2042 ## ======================================================================
2043 ## functions printing HTML: header, footer, error page
2045 sub git_header_html
{
2046 my $status = shift || "200 OK";
2047 my $expires = shift;
2049 my $title = "$site_name";
2050 if (defined $project) {
2051 $title .= " - " . to_utf8
($project);
2052 if (defined $action) {
2053 $title .= "/$action";
2054 if (defined $file_name) {
2055 $title .= " - " . esc_path
($file_name);
2056 if ($action eq "tree" && $file_name !~ m
|/$|) {
2063 # require explicit support from the UA if we are to send the page as
2064 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2065 # we have to do this because MSIE sometimes globs '*/*', pretending to
2066 # support xhtml+xml but choking when it gets what it asked for.
2067 if (defined $cgi->http('HTTP_ACCEPT') &&
2068 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2069 $cgi->Accept('application/xhtml+xml') != 0) {
2070 $content_type = 'application/xhtml+xml';
2072 $content_type = 'text/html';
2074 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2075 -status
=> $status, -expires
=> $expires);
2076 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2078 <?xml version="1.0" encoding="utf-8"?>
2079 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2080 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2081 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2082 <!-- git core binaries version $git_version -->
2084 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2085 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2086 <meta name="robots" content="index, nofollow"/>
2087 <title>$title</title>
2089 # print out each stylesheet that exist
2090 if (defined $stylesheet) {
2091 #provides backwards capability for those people who define style sheet in a config file
2092 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2094 foreach my $stylesheet (@stylesheets) {
2095 next unless $stylesheet;
2096 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2099 if (defined $project) {
2100 printf('<link rel="alternate" title="%s log RSS feed" '.
2101 'href="%s" type="application/rss+xml" />'."\n",
2102 esc_param
($project), href
(action
=>"rss"));
2103 printf('<link rel="alternate" title="%s log Atom feed" '.
2104 'href="%s" type="application/atom+xml" />'."\n",
2105 esc_param
($project), href
(action
=>"atom"));
2107 printf('<link rel="alternate" title="%s projects list" '.
2108 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2109 $site_name, href
(project
=>undef, action
=>"project_index"));
2110 printf('<link rel="alternate" title="%s projects feeds" '.
2111 'href="%s" type="text/x-opml"/>'."\n",
2112 $site_name, href
(project
=>undef, action
=>"opml"));
2114 if (defined $favicon) {
2115 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
2121 if (-f
$site_header) {
2122 open (my $fd, $site_header);
2127 print "<div class=\"page_header\">\n" .
2128 $cgi->a({-href
=> esc_url
($logo_url),
2129 -title
=> $logo_label},
2130 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2131 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2132 if (defined $project) {
2133 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2134 if (defined $action) {
2141 my ($have_search) = gitweb_check_feature
('search');
2142 if ((defined $project) && ($have_search)) {
2143 if (!defined $searchtext) {
2147 if (defined $hash_base) {
2148 $search_hash = $hash_base;
2149 } elsif (defined $hash) {
2150 $search_hash = $hash;
2152 $search_hash = "HEAD";
2154 $cgi->param("a", "search");
2155 $cgi->param("h", $search_hash);
2156 $cgi->param("p", $project);
2157 print $cgi->startform(-method => "get", -action
=> $my_uri) .
2158 "<div class=\"search\">\n" .
2159 $cgi->hidden(-name
=> "p") . "\n" .
2160 $cgi->hidden(-name
=> "a") . "\n" .
2161 $cgi->hidden(-name
=> "h") . "\n" .
2162 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2163 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2164 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2166 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2168 $cgi->end_form() . "\n";
2172 sub git_footer_html
{
2173 print "<div class=\"page_footer\">\n";
2174 if (defined $project) {
2175 my $descr = git_get_project_description
($project);
2176 if (defined $descr) {
2177 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2179 print $cgi->a({-href
=> href
(action
=>"rss"),
2180 -class => "rss_logo"}, "RSS") . " ";
2181 print $cgi->a({-href
=> href
(action
=>"atom"),
2182 -class => "rss_logo"}, "Atom") . "\n";
2184 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2185 -class => "rss_logo"}, "OPML") . " ";
2186 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2187 -class => "rss_logo"}, "TXT") . "\n";
2191 if (-f
$site_footer) {
2192 open (my $fd, $site_footer);
2202 my $status = shift || "403 Forbidden";
2203 my $error = shift || "Malformed query, file missing or permission denied";
2205 git_header_html
($status);
2207 <div class="page_body">
2217 ## ----------------------------------------------------------------------
2218 ## functions printing or outputting HTML: navigation
2220 sub git_print_page_nav
{
2221 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2222 $extra = '' if !defined $extra; # pager or formats
2224 my @navs = qw(summary shortlog log commit commitdiff tree);
2226 @navs = grep { $_ ne $suppress } @navs;
2229 my %arg = map { $_ => {action
=>$_} } @navs;
2230 if (defined $head) {
2231 for (qw(commit commitdiff)) {
2232 $arg{$_}{'hash'} = $head;
2234 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2235 for (qw(shortlog log)) {
2236 $arg{$_}{'hash'} = $head;
2240 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2241 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2243 print "<div class=\"page_nav\">\n" .
2245 map { $_ eq $current ?
2246 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2248 print "<br/>\n$extra<br/>\n" .
2252 sub format_paging_nav
{
2253 my ($action, $hash, $head, $page, $nrevs) = @_;
2257 if ($hash ne $head || $page) {
2258 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2260 $paging_nav .= "HEAD";
2264 $paging_nav .= " ⋅ " .
2265 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2266 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2268 $paging_nav .= " ⋅ prev";
2271 if ($nrevs >= (100 * ($page+1)-1)) {
2272 $paging_nav .= " ⋅ " .
2273 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2274 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2276 $paging_nav .= " ⋅ next";
2282 ## ......................................................................
2283 ## functions printing or outputting HTML: div
2285 sub git_print_header_div
{
2286 my ($action, $title, $hash, $hash_base) = @_;
2289 $args{'action'} = $action;
2290 $args{'hash'} = $hash if $hash;
2291 $args{'hash_base'} = $hash_base if $hash_base;
2293 print "<div class=\"header\">\n" .
2294 $cgi->a({-href
=> href
(%args), -class => "title"},
2295 $title ? $title : $action) .
2299 #sub git_print_authorship (\%) {
2300 sub git_print_authorship
{
2303 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2304 print "<div class=\"author_date\">" .
2305 esc_html
($co->{'author_name'}) .
2307 if ($ad{'hour_local'} < 6) {
2308 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2309 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2311 printf(" (%02d:%02d %s)",
2312 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2317 sub git_print_page_path
{
2323 print "<div class=\"page_path\">";
2324 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2325 -title
=> 'tree root'}, to_utf8
("[$project]"));
2327 if (defined $name) {
2328 my @dirname = split '/', $name;
2329 my $basename = pop @dirname;
2332 foreach my $dir (@dirname) {
2333 $fullname .= ($fullname ? '/' : '') . $dir;
2334 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2336 -title
=> $fullname}, esc_path
($dir));
2339 if (defined $type && $type eq 'blob') {
2340 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2342 -title
=> $name}, esc_path
($basename));
2343 } elsif (defined $type && $type eq 'tree') {
2344 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2346 -title
=> $name}, esc_path
($basename));
2349 print esc_path
($basename);
2352 print "<br/></div>\n";
2355 # sub git_print_log (\@;%) {
2356 sub git_print_log
($;%) {
2360 if ($opts{'-remove_title'}) {
2361 # remove title, i.e. first line of log
2364 # remove leading empty lines
2365 while (defined $log->[0] && $log->[0] eq "") {
2372 foreach my $line (@$log) {
2373 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2376 if (! $opts{'-remove_signoff'}) {
2377 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2380 # remove signoff lines
2387 # print only one empty line
2388 # do not print empty line after signoff
2390 next if ($empty || $signoff);
2396 print format_log_line_html
($line) . "<br/>\n";
2399 if ($opts{'-final_empty_line'}) {
2400 # end with single empty line
2401 print "<br/>\n" unless $empty;
2405 # return link target (what link points to)
2406 sub git_get_link_target
{
2411 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2415 $link_target = <$fd>;
2420 return $link_target;
2423 # given link target, and the directory (basedir) the link is in,
2424 # return target of link relative to top directory (top tree);
2425 # return undef if it is not possible (including absolute links).
2426 sub normalize_link_target
{
2427 my ($link_target, $basedir, $hash_base) = @_;
2429 # we can normalize symlink target only if $hash_base is provided
2430 return unless $hash_base;
2432 # absolute symlinks (beginning with '/') cannot be normalized
2433 return if (substr($link_target, 0, 1) eq '/');
2435 # normalize link target to path from top (root) tree (dir)
2438 $path = $basedir . '/' . $link_target;
2440 # we are in top (root) tree (dir)
2441 $path = $link_target;
2444 # remove //, /./, and /../
2446 foreach my $part (split('/', $path)) {
2447 # discard '.' and ''
2448 next if (!$part || $part eq '.');
2450 if ($part eq '..') {
2454 # link leads outside repository (outside top dir)
2458 push @path_parts, $part;
2461 $path = join('/', @path_parts);
2466 # print tree entry (row of git_tree), but without encompassing <tr> element
2467 sub git_print_tree_entry
{
2468 my ($t, $basedir, $hash_base, $have_blame) = @_;
2471 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2473 # The format of a table row is: mode list link. Where mode is
2474 # the mode of the entry, list is the name of the entry, an href,
2475 # and link is the action links of the entry.
2477 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2478 if ($t->{'type'} eq "blob") {
2479 print "<td class=\"list\">" .
2480 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2481 file_name
=>"$basedir$t->{'name'}", %base_key),
2482 -class => "list"}, esc_path
($t->{'name'}));
2483 if (S_ISLNK
(oct $t->{'mode'})) {
2484 my $link_target = git_get_link_target
($t->{'hash'});
2486 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2487 if (defined $norm_target) {
2489 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2490 file_name
=>$norm_target),
2491 -title
=> $norm_target}, esc_path
($link_target));
2493 print " -> " . esc_path
($link_target);
2498 print "<td class=\"link\">";
2499 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2500 file_name
=>"$basedir$t->{'name'}", %base_key)},
2504 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2505 file_name
=>"$basedir$t->{'name'}", %base_key)},
2508 if (defined $hash_base) {
2510 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2511 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2515 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2516 file_name
=>"$basedir$t->{'name'}")},
2520 } elsif ($t->{'type'} eq "tree") {
2521 print "<td class=\"list\">";
2522 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2523 file_name
=>"$basedir$t->{'name'}", %base_key)},
2524 esc_path
($t->{'name'}));
2526 print "<td class=\"link\">";
2527 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2528 file_name
=>"$basedir$t->{'name'}", %base_key)},
2530 if (defined $hash_base) {
2532 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2533 file_name
=>"$basedir$t->{'name'}")},
2540 ## ......................................................................
2541 ## functions printing large fragments of HTML
2543 sub fill_from_file_info
{
2544 my ($diff, @parents) = @_;
2546 $diff->{'from_file'} = [ ];
2547 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2548 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2549 if ($diff->{'status'}[$i] eq 'R' ||
2550 $diff->{'status'}[$i] eq 'C') {
2551 $diff->{'from_file'}[$i] =
2552 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2559 # parameters can be strings, or references to arrays of strings
2563 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @$a == @$b) {
2564 for (my $i = 0; $i < @$a; ++$i) {
2565 return 0 unless ($a->[$i] eq $b->[$i]);
2568 } elsif (!ref($a) && !ref($b)) {
2576 my $diffinfo = shift;
2578 return $diffinfo->{'to_id'} eq ('0' x
40);
2581 sub git_difftree_body
{
2582 my ($difftree, $hash, @parents) = @_;
2583 my ($parent) = $parents[0];
2584 my ($have_blame) = gitweb_check_feature
('blame');
2585 print "<div class=\"list_head\">\n";
2586 if ($#{$difftree} > 10) {
2587 print(($#{$difftree} + 1) . " files changed:\n");
2591 print "<table class=\"" .
2592 (@parents > 1 ? "combined " : "") .
2595 # header only for combined diff in 'commitdiff' view
2596 my $has_header = @parents > 1 && $action eq 'commitdiff';
2599 print "<thead><tr>\n" .
2600 "<th></th><th></th>\n"; # filename, patchN link
2601 for (my $i = 0; $i < @parents; $i++) {
2602 my $par = $parents[$i];
2604 $cgi->a({-href
=> href
(action
=>"commitdiff",
2605 hash
=>$hash, hash_parent
=>$par),
2606 -title
=> 'commitdiff to parent number ' .
2607 ($i+1) . ': ' . substr($par,0,7)},
2611 print "</tr></thead>\n<tbody>\n";
2616 foreach my $line (@{$difftree}) {
2618 if (ref($line) eq "HASH") {
2619 # pre-parsed (or generated by hand)
2622 $diff = parse_difftree_raw_line
($line);
2626 print "<tr class=\"dark\">\n";
2628 print "<tr class=\"light\">\n";
2632 if (exists $diff->{'nparents'}) { # combined diff
2634 fill_from_file_info
($diff, @parents)
2635 unless exists $diff->{'from_file'};
2637 if (!is_deleted
($diff)) {
2638 # file exists in the result (child) commit
2640 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2641 file_name
=>$diff->{'to_file'},
2643 -class => "list"}, esc_path
($diff->{'to_file'})) .
2647 esc_path
($diff->{'to_file'}) .
2651 if ($action eq 'commitdiff') {
2654 print "<td class=\"link\">" .
2655 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2660 my $has_history = 0;
2661 my $not_deleted = 0;
2662 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2663 my $hash_parent = $parents[$i];
2664 my $from_hash = $diff->{'from_id'}[$i];
2665 my $from_path = $diff->{'from_file'}[$i];
2666 my $status = $diff->{'status'}[$i];
2668 $has_history ||= ($status ne 'A');
2669 $not_deleted ||= ($status ne 'D');
2671 if ($status eq 'A') {
2672 print "<td class=\"link\" align=\"right\"> | </td>\n";
2673 } elsif ($status eq 'D') {
2674 print "<td class=\"link\">" .
2675 $cgi->a({-href
=> href
(action
=>"blob",
2678 file_name
=>$from_path)},
2682 if ($diff->{'to_id'} eq $from_hash) {
2683 print "<td class=\"link nochange\">";
2685 print "<td class=\"link\">";
2687 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2688 hash
=>$diff->{'to_id'},
2689 hash_parent
=>$from_hash,
2691 hash_parent_base
=>$hash_parent,
2692 file_name
=>$diff->{'to_file'},
2693 file_parent
=>$from_path)},
2699 print "<td class=\"link\">";
2701 print $cgi->a({-href
=> href
(action
=>"blob",
2702 hash
=>$diff->{'to_id'},
2703 file_name
=>$diff->{'to_file'},
2706 print " | " if ($has_history);
2709 print $cgi->a({-href
=> href
(action
=>"history",
2710 file_name
=>$diff->{'to_file'},
2717 next; # instead of 'else' clause, to avoid extra indent
2719 # else ordinary diff
2721 my ($to_mode_oct, $to_mode_str, $to_file_type);
2722 my ($from_mode_oct, $from_mode_str, $from_file_type);
2723 if ($diff->{'to_mode'} ne ('0' x
6)) {
2724 $to_mode_oct = oct $diff->{'to_mode'};
2725 if (S_ISREG
($to_mode_oct)) { # only for regular file
2726 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2728 $to_file_type = file_type
($diff->{'to_mode'});
2730 if ($diff->{'from_mode'} ne ('0' x
6)) {
2731 $from_mode_oct = oct $diff->{'from_mode'};
2732 if (S_ISREG
($to_mode_oct)) { # only for regular file
2733 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2735 $from_file_type = file_type
($diff->{'from_mode'});
2738 if ($diff->{'status'} eq "A") { # created
2739 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2740 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2741 $mode_chng .= "]</span>";
2743 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2744 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2745 -class => "list"}, esc_path
($diff->{'file'}));
2747 print "<td>$mode_chng</td>\n";
2748 print "<td class=\"link\">";
2749 if ($action eq 'commitdiff') {
2752 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2755 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2756 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2760 } elsif ($diff->{'status'} eq "D") { # deleted
2761 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2763 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2764 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2765 -class => "list"}, esc_path
($diff->{'file'}));
2767 print "<td>$mode_chng</td>\n";
2768 print "<td class=\"link\">";
2769 if ($action eq 'commitdiff') {
2772 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2775 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2776 hash_base
=>$parent, file_name
=>$diff->{'file'})},
2779 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2780 file_name
=>$diff->{'file'})},
2783 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2784 file_name
=>$diff->{'file'})},
2788 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2789 my $mode_chnge = "";
2790 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2791 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2792 if ($from_file_type ne $to_file_type) {
2793 $mode_chnge .= " from $from_file_type to $to_file_type";
2795 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2796 if ($from_mode_str && $to_mode_str) {
2797 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2798 } elsif ($to_mode_str) {
2799 $mode_chnge .= " mode: $to_mode_str";
2802 $mode_chnge .= "]</span>\n";
2805 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2806 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2807 -class => "list"}, esc_path
($diff->{'file'}));
2809 print "<td>$mode_chnge</td>\n";
2810 print "<td class=\"link\">";
2811 if ($action eq 'commitdiff') {
2814 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2816 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2817 # "commit" view and modified file (not onlu mode changed)
2818 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2819 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2820 hash_base
=>$hash, hash_parent_base
=>$parent,
2821 file_name
=>$diff->{'file'})},
2825 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2826 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2829 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2830 file_name
=>$diff->{'file'})},
2833 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2834 file_name
=>$diff->{'file'})},
2838 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
2839 my %status_name = ('R' => 'moved', 'C' => 'copied');
2840 my $nstatus = $status_name{$diff->{'status'}};
2842 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2843 # mode also for directories, so we cannot use $to_mode_str
2844 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2847 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2848 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
2849 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
2850 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2851 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2852 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
2853 -class => "list"}, esc_path
($diff->{'from_file'})) .
2854 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2855 "<td class=\"link\">";
2856 if ($action eq 'commitdiff') {
2859 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2861 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2862 # "commit" view and modified file (not only pure rename or copy)
2863 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2864 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2865 hash_base
=>$hash, hash_parent_base
=>$parent,
2866 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
2870 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2871 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
2874 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2875 file_name
=>$diff->{'to_file'})},
2878 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2879 file_name
=>$diff->{'to_file'})},
2883 } # we should not encounter Unmerged (U) or Unknown (X) status
2886 print "</tbody>" if $has_header;
2890 sub git_patchset_body
{
2891 my ($fd, $difftree, $hash, @hash_parents) = @_;
2892 my ($hash_parent) = $hash_parents[0];
2895 my $patch_number = 0;
2900 print "<div class=\"patchset\">\n";
2902 # skip to first patch
2903 while ($patch_line = <$fd>) {
2906 last if ($patch_line =~ m/^diff /);
2910 while ($patch_line) {
2912 my ($from_id, $to_id);
2915 #assert($patch_line =~ m/^diff /) if DEBUG;
2916 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2918 push @diff_header, $patch_line;
2920 # extended diff header
2922 while ($patch_line = <$fd>) {
2925 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2927 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2930 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2931 $from_id = [ split(',', $1) ];
2935 push @diff_header, $patch_line;
2937 my $last_patch_line = $patch_line;
2939 # check if current patch belong to current raw line
2940 # and parse raw git-diff line if needed
2941 if (defined $diffinfo &&
2942 defined $from_id && defined $to_id &&
2943 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
2944 $diffinfo->{'to_id'} eq $to_id) {
2945 # this is continuation of a split patch
2946 print "<div class=\"patch cont\">\n";
2948 # advance raw git-diff output if needed
2949 $patch_idx++ if defined $diffinfo;
2951 # read and prepare patch information
2952 if (ref($difftree->[$patch_idx]) eq "HASH") {
2953 # pre-parsed (or generated by hand)
2954 $diffinfo = $difftree->[$patch_idx];
2956 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2958 # modifies %from, %to hashes
2959 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
2960 if ($diffinfo->{'nparents'}) {
2964 fill_from_file_info
($diffinfo, @hash_parents)
2965 unless exists $diffinfo->{'from_file'};
2966 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2967 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2968 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2969 $from{'href'}[$i] = href
(action
=>"blob",
2970 hash_base
=>$hash_parents[$i],
2971 hash
=>$diffinfo->{'from_id'}[$i],
2972 file_name
=>$from{'file'}[$i]);
2974 $from{'href'}[$i] = undef;
2978 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2979 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2980 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2981 hash
=>$diffinfo->{'from_id'},
2982 file_name
=>$from{'file'});
2984 delete $from{'href'};
2988 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2989 if (!is_deleted
($diffinfo)) { # file exists in result
2990 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2991 hash
=>$diffinfo->{'to_id'},
2992 file_name
=>$to{'file'});
2996 # this is first patch for raw difftree line with $patch_idx index
2997 # we index @$difftree array from 0, but number patches from 1
2998 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3001 # print "git diff" header
3002 $patch_line = shift @diff_header;
3003 print format_git_diff_header_line
($patch_line, $diffinfo,
3006 # print extended diff header
3007 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
3009 foreach $patch_line (@diff_header) {
3010 print format_extended_diff_header_line
($patch_line, $diffinfo,
3013 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
3015 # from-file/to-file diff header
3016 $patch_line = $last_patch_line;
3017 if (! $patch_line) {
3018 print "</div>\n"; # class="patch"
3021 next PATCH
if ($patch_line =~ m/^diff /);
3022 #assert($patch_line =~ m/^---/) if DEBUG;
3023 #assert($patch_line eq $last_patch_line) if DEBUG;
3025 $patch_line = <$fd>;
3027 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3029 print format_diff_from_to_header
($last_patch_line, $patch_line,
3030 $diffinfo, \
%from, \
%to);
3034 while ($patch_line = <$fd>) {
3037 next PATCH
if ($patch_line =~ m/^diff /);
3039 print format_diff_line
($patch_line, \
%from, \
%to);
3043 print "</div>\n"; # class="patch"
3046 if ($patch_number == 0) {
3047 if (@hash_parents > 1) {
3048 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3050 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3054 print "</div>\n"; # class="patchset"
3057 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3059 sub git_project_list_body
{
3060 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3062 my ($check_forks) = gitweb_check_feature
('forks');
3065 foreach my $pr (@$projlist) {
3066 my (@aa) = git_get_last_activity
($pr->{'path'});
3070 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3071 if (!defined $pr->{'descr'}) {
3072 my $descr = git_get_project_description
($pr->{'path'}) || "";
3073 $pr->{'descr_long'} = to_utf8
($descr);
3074 $pr->{'descr'} = chop_str
($descr, 25, 5);
3076 if (!defined $pr->{'owner'}) {
3077 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
3080 my $pname = $pr->{'path'};
3081 if (($pname =~ s/\.git$//) &&
3082 ($pname !~ /\/$/) &&
3083 (-d
"$projectroot/$pname")) {
3084 $pr->{'forks'} = "-d $projectroot/$pname";
3090 push @projects, $pr;
3093 $order ||= $default_projects_order;
3094 $from = 0 unless defined $from;
3095 $to = $#projects if (!defined $to || $#projects < $to);
3097 print "<table class=\"project_list\">\n";
3098 unless ($no_header) {
3101 print "<th></th>\n";
3103 if ($order eq "project") {
3104 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3105 print "<th>Project</th>\n";
3108 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3109 -class => "header"}, "Project") .
3112 if ($order eq "descr") {
3113 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3114 print "<th>Description</th>\n";
3117 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3118 -class => "header"}, "Description") .
3121 if ($order eq "owner") {
3122 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3123 print "<th>Owner</th>\n";
3126 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3127 -class => "header"}, "Owner") .
3130 if ($order eq "age") {
3131 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3132 print "<th>Last Change</th>\n";
3135 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3136 -class => "header"}, "Last Change") .
3139 print "<th></th>\n" .
3143 for (my $i = $from; $i <= $to; $i++) {
3144 my $pr = $projects[$i];
3146 print "<tr class=\"dark\">\n";
3148 print "<tr class=\"light\">\n";
3153 if ($pr->{'forks'}) {
3154 print "<!-- $pr->{'forks'} -->\n";
3155 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3159 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3160 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3161 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3162 -class => "list", -title
=> $pr->{'descr_long'}},
3163 esc_html
($pr->{'descr'})) . "</td>\n" .
3164 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
3165 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3166 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3167 "<td class=\"link\">" .
3168 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3169 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3170 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3171 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3172 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3176 if (defined $extra) {
3179 print "<td></td>\n";
3181 print "<td colspan=\"5\">$extra</td>\n" .
3187 sub git_shortlog_body
{
3188 # uses global variable $project
3189 my ($commitlist, $from, $to, $refs, $extra) = @_;
3191 my $have_snapshot = gitweb_have_snapshot
();
3193 $from = 0 unless defined $from;
3194 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3196 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3198 for (my $i = $from; $i <= $to; $i++) {
3199 my %co = %{$commitlist->[$i]};
3200 my $commit = $co{'id'};
3201 my $ref = format_ref_marker
($refs, $commit);
3203 print "<tr class=\"dark\">\n";
3205 print "<tr class=\"light\">\n";
3208 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3209 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3210 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3212 print format_subject_html
($co{'title'}, $co{'title_short'},
3213 href
(action
=>"commit", hash
=>$commit), $ref);
3215 "<td class=\"link\">" .
3216 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3217 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3218 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3219 if ($have_snapshot) {
3220 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
3225 if (defined $extra) {
3227 "<td colspan=\"4\">$extra</td>\n" .
3233 sub git_history_body
{
3234 # Warning: assumes constant type (blob or tree) during history
3235 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3237 $from = 0 unless defined $from;
3238 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3240 print "<table class=\"history\" cellspacing=\"0\">\n";
3242 for (my $i = $from; $i <= $to; $i++) {
3243 my %co = %{$commitlist->[$i]};
3247 my $commit = $co{'id'};
3249 my $ref = format_ref_marker
($refs, $commit);
3252 print "<tr class=\"dark\">\n";
3254 print "<tr class=\"light\">\n";
3257 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3258 # shortlog uses chop_str($co{'author_name'}, 10)
3259 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3261 # originally git_history used chop_str($co{'title'}, 50)
3262 print format_subject_html
($co{'title'}, $co{'title_short'},
3263 href
(action
=>"commit", hash
=>$commit), $ref);
3265 "<td class=\"link\">" .
3266 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3267 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3269 if ($ftype eq 'blob') {
3270 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3271 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3272 if (defined $blob_current && defined $blob_parent &&
3273 $blob_current ne $blob_parent) {
3275 $cgi->a({-href
=> href
(action
=>"blobdiff",
3276 hash
=>$blob_current, hash_parent
=>$blob_parent,
3277 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3278 file_name
=>$file_name)},
3285 if (defined $extra) {
3287 "<td colspan=\"4\">$extra</td>\n" .
3294 # uses global variable $project
3295 my ($taglist, $from, $to, $extra) = @_;
3296 $from = 0 unless defined $from;
3297 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3299 print "<table class=\"tags\" cellspacing=\"0\">\n";
3301 for (my $i = $from; $i <= $to; $i++) {
3302 my $entry = $taglist->[$i];
3304 my $comment = $tag{'subject'};
3306 if (defined $comment) {
3307 $comment_short = chop_str
($comment, 30, 5);
3310 print "<tr class=\"dark\">\n";
3312 print "<tr class=\"light\">\n";
3315 if (defined $tag{'age'}) {
3316 print "<td><i>$tag{'age'}</i></td>\n";
3318 print "<td></td>\n";
3321 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3322 -class => "list name"}, esc_html
($tag{'name'})) .
3325 if (defined $comment) {
3326 print format_subject_html
($comment, $comment_short,
3327 href
(action
=>"tag", hash
=>$tag{'id'}));
3330 "<td class=\"selflink\">";
3331 if ($tag{'type'} eq "tag") {
3332 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3337 "<td class=\"link\">" . " | " .
3338 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3339 if ($tag{'reftype'} eq "commit") {
3340 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3341 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3342 } elsif ($tag{'reftype'} eq "blob") {
3343 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3348 if (defined $extra) {
3350 "<td colspan=\"5\">$extra</td>\n" .
3356 sub git_heads_body
{
3357 # uses global variable $project
3358 my ($headlist, $head, $from, $to, $extra) = @_;
3359 $from = 0 unless defined $from;
3360 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3362 print "<table class=\"heads\" cellspacing=\"0\">\n";
3364 for (my $i = $from; $i <= $to; $i++) {
3365 my $entry = $headlist->[$i];
3367 my $curr = $ref{'id'} eq $head;
3369 print "<tr class=\"dark\">\n";
3371 print "<tr class=\"light\">\n";
3374 print "<td><i>$ref{'age'}</i></td>\n" .
3375 ($curr ? "<td class=\"current_head\">" : "<td>") .
3376 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3377 -class => "list name"},esc_html
($ref{'name'})) .
3379 "<td class=\"link\">" .
3380 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3381 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3382 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3386 if (defined $extra) {
3388 "<td colspan=\"3\">$extra</td>\n" .
3394 sub git_search_grep_body
{
3395 my ($commitlist, $from, $to, $extra) = @_;
3396 $from = 0 unless defined $from;
3397 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3399 print "<table class=\"grep\" cellspacing=\"0\">\n";
3401 for (my $i = $from; $i <= $to; $i++) {
3402 my %co = %{$commitlist->[$i]};
3406 my $commit = $co{'id'};
3408 print "<tr class=\"dark\">\n";
3410 print "<tr class=\"light\">\n";
3413 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3414 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3416 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3417 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3418 my $comment = $co{'comment'};
3419 foreach my $line (@$comment) {
3420 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3421 my $lead = esc_html
($1) || "";
3422 $lead = chop_str
($lead, 30, 10);
3423 my $match = esc_html
($2) || "";
3424 my $trail = esc_html
($3) || "";
3425 $trail = chop_str
($trail, 30, 10);
3426 my $text = "$lead<span class=\"match\">$match</span>$trail";
3427 print chop_str
($text, 80, 5) . "<br/>\n";
3431 "<td class=\"link\">" .
3432 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3434 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3438 if (defined $extra) {
3440 "<td colspan=\"3\">$extra</td>\n" .
3446 ## ======================================================================
3447 ## ======================================================================
3450 sub git_project_list
{
3451 my $order = $cgi->param('o');
3452 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3453 die_error
(undef, "Unknown order parameter");
3456 my @list = git_get_projects_list
();
3458 die_error
(undef, "No projects found");
3462 if (-f
$home_text) {
3463 print "<div class=\"index_include\">\n";
3464 open (my $fd, $home_text);
3469 git_project_list_body
(\
@list, $order);
3474 my $order = $cgi->param('o');
3475 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3476 die_error
(undef, "Unknown order parameter");
3479 my @list = git_get_projects_list
($project);
3481 die_error
(undef, "No forks found");
3485 git_print_page_nav
('','');
3486 git_print_header_div
('summary', "$project forks");
3487 git_project_list_body
(\
@list, $order);
3491 sub git_project_index
{
3492 my @projects = git_get_projects_list
($project);
3495 -type
=> 'text/plain',
3496 -charset
=> 'utf-8',
3497 -content_disposition
=> 'inline; filename="index.aux"');
3499 foreach my $pr (@projects) {
3500 if (!exists $pr->{'owner'}) {
3501 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3504 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3505 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3506 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3507 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3511 print "$path $owner\n";
3516 my $descr = git_get_project_description
($project) || "none";
3517 my %co = parse_commit
("HEAD");
3518 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3519 my $head = $co{'id'};
3521 my $owner = git_get_project_owner
($project);
3523 my $refs = git_get_references
();
3524 # These get_*_list functions return one more to allow us to see if
3525 # there are more ...
3526 my @taglist = git_get_tags_list
(16);
3527 my @headlist = git_get_heads_list
(16);
3529 my ($check_forks) = gitweb_check_feature
('forks');
3532 @forklist = git_get_projects_list
($project);
3536 git_print_page_nav
('summary','', $head);
3538 print "<div class=\"title\"> </div>\n";
3539 print "<table cellspacing=\"0\">\n" .
3540 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3541 "<tr><td>owner</td><td>$owner</td></tr>\n";
3542 if (defined $cd{'rfc2822'}) {
3543 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3546 # use per project git URL list in $projectroot/$project/cloneurl
3547 # or make project git URL from git base URL and project name
3548 my $url_tag = "URL";
3549 my @url_list = git_get_project_url_list
($project);
3550 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3551 foreach my $git_url (@url_list) {
3552 next unless $git_url;
3553 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3558 if (-s
"$projectroot/$project/README.html") {
3559 if (open my $fd, "$projectroot/$project/README.html") {
3560 print "<div class=\"title\">readme</div>\n";
3561 print $_ while (<$fd>);
3566 # we need to request one more than 16 (0..15) to check if
3568 my @commitlist = $head ? parse_commits
($head, 17) : ();
3570 git_print_header_div
('shortlog');
3571 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3572 $#commitlist <= 15 ? undef :
3573 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3577 git_print_header_div
('tags');
3578 git_tags_body
(\
@taglist, 0, 15,
3579 $#taglist <= 15 ? undef :
3580 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3584 git_print_header_div
('heads');
3585 git_heads_body
(\
@headlist, $head, 0, 15,
3586 $#headlist <= 15 ? undef :
3587 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3591 git_print_header_div
('forks');
3592 git_project_list_body
(\
@forklist, undef, 0, 15,
3593 $#forklist <= 15 ? undef :
3594 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3602 my $head = git_get_head_hash
($project);
3604 git_print_page_nav
('','', $head,undef,$head);
3605 my %tag = parse_tag
($hash);
3608 die_error
(undef, "Unknown tag object");
3611 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3612 print "<div class=\"title_text\">\n" .
3613 "<table cellspacing=\"0\">\n" .
3615 "<td>object</td>\n" .
3616 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3617 $tag{'object'}) . "</td>\n" .
3618 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3619 $tag{'type'}) . "</td>\n" .
3621 if (defined($tag{'author'})) {
3622 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3623 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3624 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3625 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3628 print "</table>\n\n" .
3630 print "<div class=\"page_body\">";
3631 my $comment = $tag{'comment'};
3632 foreach my $line (@$comment) {
3634 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3644 my ($have_blame) = gitweb_check_feature
('blame');
3646 die_error
('403 Permission denied', "Permission denied");
3648 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3649 $hash_base ||= git_get_head_hash
($project);
3650 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3651 my %co = parse_commit
($hash_base)
3652 or die_error
(undef, "Reading commit failed");
3653 if (!defined $hash) {
3654 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3655 or die_error
(undef, "Error looking up file");
3657 $ftype = git_get_type
($hash);
3658 if ($ftype !~ "blob") {
3659 die_error
('400 Bad Request', "Object is not a blob");
3661 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3662 $file_name, $hash_base)
3663 or die_error
(undef, "Open git-blame failed");
3666 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3669 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3672 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3674 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3675 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3676 git_print_page_path
($file_name, $ftype, $hash_base);
3677 my @rev_color = (qw(light2 dark2));
3678 my $num_colors = scalar(@rev_color);
3679 my $current_color = 0;
3682 <div class="page_body">
3683 <table class="blame">
3684 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3689 last unless defined $_;
3690 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3691 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3692 if (!exists $metainfo{$full_rev}) {
3693 $metainfo{$full_rev} = {};
3695 my $meta = $metainfo{$full_rev};
3698 if (/^(\S+) (.*)$/) {
3704 my $rev = substr($full_rev, 0, 8);
3705 my $author = $meta->{'author'};
3706 my %date = parse_date
($meta->{'author-time'},
3707 $meta->{'author-tz'});
3708 my $date = $date{'iso-tz'};
3710 $current_color = ++$current_color % $num_colors;
3712 print "<tr class=\"$rev_color[$current_color]\">\n";
3714 print "<td class=\"sha1\"";
3715 print " title=\"". esc_html
($author) . ", $date\"";
3716 print " rowspan=\"$group_size\"" if ($group_size > 1);
3718 print $cgi->a({-href
=> href
(action
=>"commit",
3720 file_name
=>$file_name)},
3724 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3725 or die_error
(undef, "Open git-rev-parse failed");
3726 my $parent_commit = <$dd>;
3728 chomp($parent_commit);
3729 my $blamed = href
(action
=> 'blame',
3730 file_name
=> $meta->{'filename'},
3731 hash_base
=> $parent_commit);
3732 print "<td class=\"linenr\">";
3733 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3735 -class => "linenr" },
3738 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3744 or print "Reading blob failed\n";
3751 my ($have_blame) = gitweb_check_feature
('blame');
3753 die_error
('403 Permission denied', "Permission denied");
3755 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3756 $hash_base ||= git_get_head_hash
($project);
3757 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3758 my %co = parse_commit
($hash_base)
3759 or die_error
(undef, "Reading commit failed");
3760 if (!defined $hash) {
3761 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3762 or die_error
(undef, "Error lookup file");
3764 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3765 or die_error
(undef, "Open git-annotate failed");
3768 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3771 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3774 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3776 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3777 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3778 git_print_page_path
($file_name, 'blob', $hash_base);
3779 print "<div class=\"page_body\">\n";
3781 <table class="blame">
3790 my @line_class = (qw(light dark));
3791 my $line_class_len = scalar (@line_class);
3792 my $line_class_num = $#line_class;
3793 while (my $line = <$fd>) {
3805 $line_class_num = ($line_class_num + 1) % $line_class_len;
3807 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3814 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3817 $short_rev = substr ($long_rev, 0, 8);
3818 $age = time () - $time;
3819 $age_str = age_string
($age);
3820 $age_str =~ s/ / /g;
3821 $age_class = age_class
($age);
3822 $author = esc_html
($author);
3823 $author =~ s/ / /g;
3825 $data = untabify
($data);
3826 $data = esc_html
($data);
3829 <tr class="$line_class[$line_class_num]">
3830 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3831 <td class="$age_class">$age_str</td>
3833 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3834 <td class="pre">$data</td>
3837 } # while (my $line = <$fd>)
3838 print "</table>\n\n";
3840 or print "Reading blob failed.\n";
3846 my $head = git_get_head_hash
($project);
3848 git_print_page_nav
('','', $head,undef,$head);
3849 git_print_header_div
('summary', $project);
3851 my @tagslist = git_get_tags_list
();
3853 git_tags_body
(\
@tagslist);
3859 my $head = git_get_head_hash
($project);
3861 git_print_page_nav
('','', $head,undef,$head);
3862 git_print_header_div
('summary', $project);
3864 my @headslist = git_get_heads_list
();
3866 git_heads_body
(\
@headslist, $head);
3871 sub git_blob_plain
{
3874 if (!defined $hash) {
3875 if (defined $file_name) {
3876 my $base = $hash_base || git_get_head_hash
($project);
3877 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3878 or die_error
(undef, "Error lookup file");
3880 die_error
(undef, "No file name defined");
3882 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3883 # blobs defined by non-textual hash id's can be cached
3888 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3889 or die_error
(undef, "Couldn't cat $file_name, $hash");
3891 $type ||= blob_mimetype
($fd, $file_name);
3893 # save as filename, even when no $file_name is given
3894 my $save_as = "$hash";
3895 if (defined $file_name) {
3896 $save_as = $file_name;
3897 } elsif ($type =~ m/^text\//) {
3904 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3906 binmode STDOUT
, ':raw';
3908 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3916 if (!defined $hash) {
3917 if (defined $file_name) {
3918 my $base = $hash_base || git_get_head_hash
($project);
3919 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3920 or die_error
(undef, "Error lookup file");
3922 die_error
(undef, "No file name defined");
3924 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3925 # blobs defined by non-textual hash id's can be cached
3929 my ($have_blame) = gitweb_check_feature
('blame');
3930 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3931 or die_error
(undef, "Couldn't cat $file_name, $hash");
3932 my $mimetype = blob_mimetype
($fd, $file_name);
3933 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3935 return git_blob_plain
($mimetype);
3937 # we can have blame only for text/* mimetype
3938 $have_blame &&= ($mimetype =~ m!^text/!);
3940 git_header_html
(undef, $expires);
3941 my $formats_nav = '';
3942 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3943 if (defined $file_name) {
3946 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3947 hash
=>$hash, file_name
=>$file_name)},
3952 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3953 hash
=>$hash, file_name
=>$file_name)},
3956 $cgi->a({-href
=> href
(action
=>"blob_plain",
3957 hash
=>$hash, file_name
=>$file_name)},
3960 $cgi->a({-href
=> href
(action
=>"blob",
3961 hash_base
=>"HEAD", file_name
=>$file_name)},
3965 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3967 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3968 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3970 print "<div class=\"page_nav\">\n" .
3971 "<br/><br/></div>\n" .
3972 "<div class=\"title\">$hash</div>\n";
3974 git_print_page_path
($file_name, "blob", $hash_base);
3975 print "<div class=\"page_body\">\n";
3976 if ($mimetype =~ m!^text/!) {
3978 while (my $line = <$fd>) {
3981 $line = untabify
($line);
3982 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3983 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3985 } elsif ($mimetype =~ m!^image/!) {
3986 print qq
!<img type
="$mimetype"!;
3988 print qq
! alt
="$file_name" title
="$file_name"!;
3991 href(action=>"blob_plain
", hash=>$hash,
3992 hash_base=>$hash_base, file_name=>$file_name) .
3996 or print "Reading blob failed.\n";
4002 my $have_snapshot = gitweb_have_snapshot
();
4004 if (!defined $hash_base) {
4005 $hash_base = "HEAD";
4007 if (!defined $hash) {
4008 if (defined $file_name) {
4009 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4015 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4016 or die_error
(undef, "Open git-ls-tree failed");
4017 my @entries = map { chomp; $_ } <$fd>;
4018 close $fd or die_error
(undef, "Reading tree failed");
4021 my $refs = git_get_references
();
4022 my $ref = format_ref_marker
($refs, $hash_base);
4025 my ($have_blame) = gitweb_check_feature
('blame');
4026 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4028 if (defined $file_name) {
4030 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4031 hash
=>$hash, file_name
=>$file_name)},
4033 $cgi->a({-href
=> href
(action
=>"tree",
4034 hash_base
=>"HEAD", file_name
=>$file_name)},
4037 if ($have_snapshot) {
4038 # FIXME: Should be available when we have no hash base as well.
4040 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
4043 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4044 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4047 print "<div class=\"page_nav\">\n";
4048 print "<br/><br/></div>\n";
4049 print "<div class=\"title\">$hash</div>\n";
4051 if (defined $file_name) {
4052 $basedir = $file_name;
4053 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4057 git_print_page_path
($file_name, 'tree', $hash_base);
4058 print "<div class=\"page_body\">\n";
4059 print "<table cellspacing=\"0\">\n";
4061 # '..' (top directory) link if possible
4062 if (defined $hash_base &&
4063 defined $file_name && $file_name =~ m![^/]+$!) {
4065 print "<tr class=\"dark\">\n";
4067 print "<tr class=\"light\">\n";
4071 my $up = $file_name;
4072 $up =~ s!/?[^/]+$!!;
4073 undef $up unless $up;
4074 # based on git_print_tree_entry
4075 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4076 print '<td class="list">';
4077 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4081 print "<td class=\"link\"></td>\n";
4085 foreach my $line (@entries) {
4086 my %t = parse_ls_tree_line
($line, -z
=> 1);
4089 print "<tr class=\"dark\">\n";
4091 print "<tr class=\"light\">\n";
4095 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4099 print "</table>\n" .
4105 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
4106 my $have_snapshot = (defined $ctype && defined $suffix);
4107 if (!$have_snapshot) {
4108 die_error
('403 Permission denied', "Permission denied");
4111 if (!defined $hash) {
4112 $hash = git_get_head_hash
($project);
4115 my $git = git_cmd_str
();
4116 my $name = $project;
4117 $name =~ s/\047/\047\\\047\047/g;
4118 my $filename = to_utf8
(basename
($project));
4120 if ($suffix eq 'zip') {
4121 $filename .= "-$hash.$suffix";
4122 $cmd = "$git archive --format=zip --prefix=\'$name\'/ $hash";
4124 $filename .= "-$hash.tar.$suffix";
4125 $cmd = "$git archive --format=tar --prefix=\'$name\'/ $hash | $command";
4129 -type
=> "application/$ctype",
4130 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4131 -status
=> '200 OK');
4133 open my $fd, "-|", $cmd
4134 or die_error
(undef, "Execute git-archive failed");
4135 binmode STDOUT
, ':raw';
4137 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4143 my $head = git_get_head_hash
($project);
4144 if (!defined $hash) {
4147 if (!defined $page) {
4150 my $refs = git_get_references
();
4152 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4154 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4157 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4160 my %co = parse_commit
($hash);
4162 git_print_header_div
('summary', $project);
4163 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4165 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4166 for (my $i = 0; $i <= $to; $i++) {
4167 my %co = %{$commitlist[$i]};
4169 my $commit = $co{'id'};
4170 my $ref = format_ref_marker
($refs, $commit);
4171 my %ad = parse_date
($co{'author_epoch'});
4172 git_print_header_div
('commit',
4173 "<span class=\"age\">$co{'age_string'}</span>" .
4174 esc_html
($co{'title'}) . $ref,
4176 print "<div class=\"title_text\">\n" .
4177 "<div class=\"log_link\">\n" .
4178 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4180 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4182 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4185 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4188 print "<div class=\"log_body\">\n";
4189 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4192 if ($#commitlist >= 100) {
4193 print "<div class=\"page_nav\">\n";
4194 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4195 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4202 $hash ||= $hash_base || "HEAD";
4203 my %co = parse_commit
($hash);
4205 die_error
(undef, "Unknown commit object");
4207 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4208 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4210 my $parent = $co{'parent'};
4211 my $parents = $co{'parents'}; # listref
4213 # we need to prepare $formats_nav before any parameter munging
4215 if (!defined $parent) {
4217 $formats_nav .= '(initial)';
4218 } elsif (@$parents == 1) {
4219 # single parent commit
4222 $cgi->a({-href
=> href
(action
=>"commit",
4224 esc_html
(substr($parent, 0, 7))) .
4231 $cgi->a({-href
=> href
(action
=>"commit",
4233 esc_html
(substr($_, 0, 7)));
4238 if (!defined $parent) {
4242 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4244 (@$parents <= 1 ? $parent : '-c'),
4246 or die_error
(undef, "Open git-diff-tree failed");
4247 @difftree = map { chomp; $_ } <$fd>;
4248 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4250 # non-textual hash id's can be cached
4252 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4255 my $refs = git_get_references
();
4256 my $ref = format_ref_marker
($refs, $co{'id'});
4258 my $have_snapshot = gitweb_have_snapshot
();
4260 git_header_html
(undef, $expires);
4261 git_print_page_nav
('commit', '',
4262 $hash, $co{'tree'}, $hash,
4265 if (defined $co{'parent'}) {
4266 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4268 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4270 print "<div class=\"title_text\">\n" .
4271 "<table cellspacing=\"0\">\n";
4272 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4274 "<td></td><td> $ad{'rfc2822'}";
4275 if ($ad{'hour_local'} < 6) {
4276 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4277 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4279 printf(" (%02d:%02d %s)",
4280 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4284 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4285 print "<tr><td></td><td> $cd{'rfc2822'}" .
4286 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4288 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4291 "<td class=\"sha1\">" .
4292 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4293 class => "list"}, $co{'tree'}) .
4295 "<td class=\"link\">" .
4296 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4298 if ($have_snapshot) {
4300 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
4305 foreach my $par (@$parents) {
4308 "<td class=\"sha1\">" .
4309 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4310 class => "list"}, $par) .
4312 "<td class=\"link\">" .
4313 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4315 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4322 print "<div class=\"page_body\">\n";
4323 git_print_log
($co{'comment'});
4326 git_difftree_body
(\
@difftree, $hash, @$parents);
4332 # object is defined by:
4333 # - hash or hash_base alone
4334 # - hash_base and file_name
4337 # - hash or hash_base alone
4338 if ($hash || ($hash_base && !defined $file_name)) {
4339 my $object_id = $hash || $hash_base;
4341 my $git_command = git_cmd_str
();
4342 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4343 or die_error
('404 Not Found', "Object does not exist");
4347 or die_error
('404 Not Found', "Object does not exist");
4349 # - hash_base and file_name
4350 } elsif ($hash_base && defined $file_name) {
4351 $file_name =~ s
,/+$,,;
4353 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4354 or die_error
('404 Not Found', "Base object does not exist");
4356 # here errors should not hapen
4357 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4358 or die_error
(undef, "Open git-ls-tree failed");
4362 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4363 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4364 die_error
('404 Not Found', "File or directory for given base does not exist");
4369 die_error
('404 Not Found', "Not enough information to find object");
4372 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4373 hash
=>$hash, hash_base
=>$hash_base,
4374 file_name
=>$file_name),
4375 -status
=> '302 Found');
4379 my $format = shift || 'html';
4386 # preparing $fd and %diffinfo for git_patchset_body
4388 if (defined $hash_base && defined $hash_parent_base) {
4389 if (defined $file_name) {
4391 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4392 $hash_parent_base, $hash_base,
4393 "--", (defined $file_parent ? $file_parent : ()), $file_name
4394 or die_error
(undef, "Open git-diff-tree failed");
4395 @difftree = map { chomp; $_ } <$fd>;
4397 or die_error
(undef, "Reading git-diff-tree failed");
4399 or die_error
('404 Not Found', "Blob diff not found");
4401 } elsif (defined $hash &&
4402 $hash =~ /[0-9a-fA-F]{40}/) {
4403 # try to find filename from $hash
4405 # read filtered raw output
4406 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4407 $hash_parent_base, $hash_base, "--"
4408 or die_error
(undef, "Open git-diff-tree failed");
4410 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4412 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4413 map { chomp; $_ } <$fd>;
4415 or die_error
(undef, "Reading git-diff-tree failed");
4417 or die_error
('404 Not Found', "Blob diff not found");
4420 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4423 if (@difftree > 1) {
4424 die_error
('404 Not Found', "Ambiguous blob diff specification");
4427 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4428 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4429 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4431 $hash_parent ||= $diffinfo{'from_id'};
4432 $hash ||= $diffinfo{'to_id'};
4434 # non-textual hash id's can be cached
4435 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4436 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4441 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4442 '-p', ($format eq 'html' ? "--full-index" : ()),
4443 $hash_parent_base, $hash_base,
4444 "--", (defined $file_parent ? $file_parent : ()), $file_name
4445 or die_error
(undef, "Open git-diff-tree failed");
4448 # old/legacy style URI
4449 if (!%diffinfo && # if new style URI failed
4450 defined $hash && defined $hash_parent) {
4451 # fake git-diff-tree raw output
4452 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4453 $diffinfo{'from_id'} = $hash_parent;
4454 $diffinfo{'to_id'} = $hash;
4455 if (defined $file_name) {
4456 if (defined $file_parent) {
4457 $diffinfo{'status'} = '2';
4458 $diffinfo{'from_file'} = $file_parent;
4459 $diffinfo{'to_file'} = $file_name;
4460 } else { # assume not renamed
4461 $diffinfo{'status'} = '1';
4462 $diffinfo{'from_file'} = $file_name;
4463 $diffinfo{'to_file'} = $file_name;
4465 } else { # no filename given
4466 $diffinfo{'status'} = '2';
4467 $diffinfo{'from_file'} = $hash_parent;
4468 $diffinfo{'to_file'} = $hash;
4471 # non-textual hash id's can be cached
4472 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4473 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4478 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4479 '-p', ($format eq 'html' ? "--full-index" : ()),
4480 $hash_parent, $hash, "--"
4481 or die_error
(undef, "Open git-diff failed");
4483 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4488 if ($format eq 'html') {
4490 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4491 hash
=>$hash, hash_parent
=>$hash_parent,
4492 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4493 file_name
=>$file_name, file_parent
=>$file_parent)},
4495 git_header_html
(undef, $expires);
4496 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4497 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4498 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4500 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4501 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4503 if (defined $file_name) {
4504 git_print_page_path
($file_name, "blob", $hash_base);
4506 print "<div class=\"page_path\"></div>\n";
4509 } elsif ($format eq 'plain') {
4511 -type
=> 'text/plain',
4512 -charset
=> 'utf-8',
4513 -expires
=> $expires,
4514 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4516 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4519 die_error
(undef, "Unknown blobdiff format");
4523 if ($format eq 'html') {
4524 print "<div class=\"page_body\">\n";
4526 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4529 print "</div>\n"; # class="page_body"
4533 while (my $line = <$fd>) {
4534 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4535 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4539 last if $line =~ m!^\+\+\+!;
4547 sub git_blobdiff_plain
{
4548 git_blobdiff
('plain');
4551 sub git_commitdiff
{
4552 my $format = shift || 'html';
4553 $hash ||= $hash_base || "HEAD";
4554 my %co = parse_commit
($hash);
4556 die_error
(undef, "Unknown commit object");
4559 # we need to prepare $formats_nav before any parameter munging
4561 if ($format eq 'html') {
4563 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4564 hash
=>$hash, hash_parent
=>$hash_parent)},
4567 if (defined $hash_parent) {
4568 # commitdiff with two commits given
4569 my $hash_parent_short = $hash_parent;
4570 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4571 $hash_parent_short = substr($hash_parent, 0, 7);
4575 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
4576 if ($co{'parents'}[$i] eq $hash_parent) {
4577 $formats_nav .= ' parent ' . ($i+1);
4581 $formats_nav .= ': ' .
4582 $cgi->a({-href
=> href
(action
=>"commitdiff",
4583 hash
=>$hash_parent)},
4584 esc_html
($hash_parent_short)) .
4586 } elsif (!$co{'parent'}) {
4588 $formats_nav .= ' (initial)';
4589 } elsif (scalar @{$co{'parents'}} == 1) {
4590 # single parent commit
4593 $cgi->a({-href
=> href
(action
=>"commitdiff",
4594 hash
=>$co{'parent'})},
4595 esc_html
(substr($co{'parent'}, 0, 7))) .
4602 $cgi->a({-href
=> href
(action
=>"commitdiff",
4604 esc_html
(substr($_, 0, 7)));
4605 } @{$co{'parents'}} ) .
4610 my $hash_parent_param = $hash_parent;
4611 if (!defined $hash_parent) {
4612 $hash_parent_param =
4613 @{$co{'parents'}} > 1 ? '-c' : $co{'parent'} || '--root';
4619 if ($format eq 'html') {
4620 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4621 "--no-commit-id", "--patch-with-raw", "--full-index",
4622 $hash_parent_param, $hash, "--"
4623 or die_error
(undef, "Open git-diff-tree failed");
4625 while (my $line = <$fd>) {
4627 # empty line ends raw part of diff-tree output
4629 push @difftree, scalar parse_difftree_raw_line
($line);
4632 } elsif ($format eq 'plain') {
4633 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4634 '-p', $hash_parent_param, $hash, "--"
4635 or die_error
(undef, "Open git-diff-tree failed");
4638 die_error
(undef, "Unknown commitdiff format");
4641 # non-textual hash id's can be cached
4643 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4647 # write commit message
4648 if ($format eq 'html') {
4649 my $refs = git_get_references
();
4650 my $ref = format_ref_marker
($refs, $co{'id'});
4652 git_header_html
(undef, $expires);
4653 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4654 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4655 git_print_authorship
(\
%co);
4656 print "<div class=\"page_body\">\n";
4657 if (@{$co{'comment'}} > 1) {
4658 print "<div class=\"log\">\n";
4659 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4660 print "</div>\n"; # class="log"
4663 } elsif ($format eq 'plain') {
4664 my $refs = git_get_references
("tags");
4665 my $tagname = git_get_rev_name_tags
($hash);
4666 my $filename = basename
($project) . "-$hash.patch";
4669 -type
=> 'text/plain',
4670 -charset
=> 'utf-8',
4671 -expires
=> $expires,
4672 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4673 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4676 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4677 Subject: $co{'title'}
4679 print "X-Git-Tag: $tagname\n" if $tagname;
4680 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4682 foreach my $line (@{$co{'comment'}}) {
4689 if ($format eq 'html') {
4690 git_difftree_body
(\
@difftree, $hash, $hash_parent || @{$co{'parents'}});
4693 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent || @{$co{'parents'}});
4695 print "</div>\n"; # class="page_body"
4698 } elsif ($format eq 'plain') {
4702 or print "Reading git-diff-tree failed\n";
4706 sub git_commitdiff_plain
{
4707 git_commitdiff
('plain');
4711 if (!defined $hash_base) {
4712 $hash_base = git_get_head_hash
($project);
4714 if (!defined $page) {
4718 my %co = parse_commit
($hash_base);
4720 die_error
(undef, "Unknown commit object");
4723 my $refs = git_get_references
();
4724 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4726 if (!defined $hash && defined $file_name) {
4727 $hash = git_get_hash_by_path
($hash_base, $file_name);
4729 if (defined $hash) {
4730 $ftype = git_get_type
($hash);
4733 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4735 my $paging_nav = '';
4738 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4739 file_name
=>$file_name)},
4741 $paging_nav .= " ⋅ " .
4742 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4743 file_name
=>$file_name, page
=>$page-1),
4744 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4746 $paging_nav .= "first";
4747 $paging_nav .= " ⋅ prev";
4749 if ($#commitlist >= 100) {
4750 $paging_nav .= " ⋅ " .
4751 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4752 file_name
=>$file_name, page
=>$page+1),
4753 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4755 $paging_nav .= " ⋅ next";
4758 if ($#commitlist >= 100) {
4760 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4761 file_name
=>$file_name, page
=>$page+1),
4762 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4766 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4767 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4768 git_print_page_path
($file_name, $ftype, $hash_base);
4770 git_history_body
(\
@commitlist, 0, 99,
4771 $refs, $hash_base, $ftype, $next_link);
4777 my ($have_search) = gitweb_check_feature
('search');
4778 if (!$have_search) {
4779 die_error
('403 Permission denied', "Permission denied");
4781 if (!defined $searchtext) {
4782 die_error
(undef, "Text field empty");
4784 if (!defined $hash) {
4785 $hash = git_get_head_hash
($project);
4787 my %co = parse_commit
($hash);
4789 die_error
(undef, "Unknown commit object");
4791 if (!defined $page) {
4795 $searchtype ||= 'commit';
4796 if ($searchtype eq 'pickaxe') {
4797 # pickaxe may take all resources of your box and run for several minutes
4798 # with every query - so decide by yourself how public you make this feature
4799 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4800 if (!$have_pickaxe) {
4801 die_error
('403 Permission denied', "Permission denied");
4804 if ($searchtype eq 'grep') {
4805 my ($have_grep) = gitweb_check_feature
('grep');
4807 die_error
('403 Permission denied', "Permission denied");
4813 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4815 if ($searchtype eq 'commit') {
4816 $greptype = "--grep=";
4817 } elsif ($searchtype eq 'author') {
4818 $greptype = "--author=";
4819 } elsif ($searchtype eq 'committer') {
4820 $greptype = "--committer=";
4822 $greptype .= $search_regexp;
4823 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4825 my $paging_nav = '';
4828 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4829 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4831 $paging_nav .= " ⋅ " .
4832 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4833 searchtext
=>$searchtext, searchtype
=>$searchtype,
4835 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4837 $paging_nav .= "first";
4838 $paging_nav .= " ⋅ prev";
4840 if ($#commitlist >= 100) {
4841 $paging_nav .= " ⋅ " .
4842 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4843 searchtext
=>$searchtext, searchtype
=>$searchtype,
4845 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4847 $paging_nav .= " ⋅ next";
4850 if ($#commitlist >= 100) {
4852 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4853 searchtext
=>$searchtext, searchtype
=>$searchtype,
4855 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4858 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4859 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4860 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4863 if ($searchtype eq 'pickaxe') {
4864 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4865 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4867 print "<table cellspacing=\"0\">\n";
4870 my $git_command = git_cmd_str
();
4871 my $searchqtext = $searchtext;
4872 $searchqtext =~ s/'/'\\''/;
4873 open my $fd, "-|", "$git_command rev-list $hash | " .
4874 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
4877 while (my $line = <$fd>) {
4878 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4881 $set{'from_id'} = $3;
4883 $set{'id'} = $set{'to_id'};
4884 if ($set{'id'} =~ m/0{40}/) {
4885 $set{'id'} = $set{'from_id'};
4887 if ($set{'id'} =~ m/0{40}/) {
4891 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4894 print "<tr class=\"dark\">\n";
4896 print "<tr class=\"light\">\n";
4899 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4900 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4902 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4903 -class => "list subject"},
4904 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4905 while (my $setref = shift @files) {
4907 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4908 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4910 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4914 "<td class=\"link\">" .
4915 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4917 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4921 %co = parse_commit
($1);
4929 if ($searchtype eq 'grep') {
4930 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4931 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4933 print "<table cellspacing=\"0\">\n";
4937 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
4939 while (my $line = <$fd>) {
4941 my ($file, $lno, $ltext, $binary);
4942 last if ($matches++ > 1000);
4943 if ($line =~ /^Binary file (.+) matches$/) {
4947 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
4949 if ($file ne $lastfile) {
4950 $lastfile and print "</td></tr>\n";
4952 print "<tr class=\"dark\">\n";
4954 print "<tr class=\"light\">\n";
4956 print "<td class=\"list\">".
4957 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
4958 file_name
=>"$file"),
4959 -class => "list"}, esc_path
($file));
4960 print "</td><td>\n";
4964 print "<div class=\"binary\">Binary file</div>\n";
4966 $ltext = untabify
($ltext);
4967 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
4968 $ltext = esc_html
($1, -nbsp
=>1);
4969 $ltext .= '<span class="match">';
4970 $ltext .= esc_html
($2, -nbsp
=>1);
4971 $ltext .= '</span>';
4972 $ltext .= esc_html
($3, -nbsp
=>1);
4974 $ltext = esc_html
($ltext, -nbsp
=>1);
4976 print "<div class=\"pre\">" .
4977 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
4978 file_name
=>"$file").'#l'.$lno,
4979 -class => "linenr"}, sprintf('%4i', $lno))
4980 . ' ' . $ltext . "</div>\n";
4984 print "</td></tr>\n";
4985 if ($matches > 1000) {
4986 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
4989 print "<div class=\"diff nodifferences\">No matches found</div>\n";
4998 sub git_search_help
{
5000 git_print_page_nav
('','', $hash,$hash,$hash);
5003 <dt><b>commit</b></dt>
5004 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
5006 my ($have_grep) = gitweb_check_feature
('grep');
5009 <dt><b>grep</b></dt>
5010 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5011 a different one) are searched for the given
5012 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5013 (POSIX extended) and the matches are listed. On large
5014 trees, this search can take a while and put some strain on the server, so please use it with
5015 some consideration.</dd>
5019 <dt><b>author</b></dt>
5020 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5021 <dt><b>committer</b></dt>
5022 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5024 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5025 if ($have_pickaxe) {
5027 <dt><b>pickaxe</b></dt>
5028 <dd>All commits that caused the string to appear or disappear from any file (changes that
5029 added, removed or "modified" the string) will be listed. This search can take a while and
5030 takes a lot of strain on the server, so please use it wisely.</dd>
5038 my $head = git_get_head_hash
($project);
5039 if (!defined $hash) {
5042 if (!defined $page) {
5045 my $refs = git_get_references
();
5047 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5049 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
5051 if ($#commitlist >= 100) {
5053 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
5054 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5058 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5059 git_print_header_div
('summary', $project);
5061 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5066 ## ......................................................................
5067 ## feeds (RSS, Atom; OPML)
5070 my $format = shift || 'atom';
5071 my ($have_blame) = gitweb_check_feature
('blame');
5073 # Atom: http://www.atomenabled.org/developers/syndication/
5074 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5075 if ($format ne 'rss' && $format ne 'atom') {
5076 die_error
(undef, "Unknown web feed format");
5079 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5080 my $head = $hash || 'HEAD';
5081 my @commitlist = parse_commits
($head, 150);
5085 my $content_type = "application/$format+xml";
5086 if (defined $cgi->http('HTTP_ACCEPT') &&
5087 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5088 # browser (feed reader) prefers text/xml
5089 $content_type = 'text/xml';
5091 if (defined($commitlist[0])) {
5092 %latest_commit = %{$commitlist[0]};
5093 %latest_date = parse_date
($latest_commit{'author_epoch'});
5095 -type
=> $content_type,
5096 -charset
=> 'utf-8',
5097 -last_modified
=> $latest_date{'rfc2822'});
5100 -type
=> $content_type,
5101 -charset
=> 'utf-8');
5104 # Optimization: skip generating the body if client asks only
5105 # for Last-Modified date.
5106 return if ($cgi->request_method() eq 'HEAD');
5109 my $title = "$site_name - $project/$action";
5110 my $feed_type = 'log';
5111 if (defined $hash) {
5112 $title .= " - '$hash'";
5113 $feed_type = 'branch log';
5114 if (defined $file_name) {
5115 $title .= " :: $file_name";
5116 $feed_type = 'history';
5118 } elsif (defined $file_name) {
5119 $title .= " - $file_name";
5120 $feed_type = 'history';
5122 $title .= " $feed_type";
5123 my $descr = git_get_project_description
($project);
5124 if (defined $descr) {
5125 $descr = esc_html
($descr);
5127 $descr = "$project " .
5128 ($format eq 'rss' ? 'RSS' : 'Atom') .
5131 my $owner = git_get_project_owner
($project);
5132 $owner = esc_html
($owner);
5136 if (defined $file_name) {
5137 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5138 } elsif (defined $hash) {
5139 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5141 $alt_url = href
(-full
=>1, action
=>"summary");
5143 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5144 if ($format eq 'rss') {
5146 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5149 print "<title>$title</title>\n" .
5150 "<link>$alt_url</link>\n" .
5151 "<description>$descr</description>\n" .
5152 "<language>en</language>\n";
5153 } elsif ($format eq 'atom') {
5155 <feed xmlns="http://www.w3.org/2005/Atom">
5157 print "<title>$title</title>\n" .
5158 "<subtitle>$descr</subtitle>\n" .
5159 '<link rel="alternate" type="text/html" href="' .
5160 $alt_url . '" />' . "\n" .
5161 '<link rel="self" type="' . $content_type . '" href="' .
5162 $cgi->self_url() . '" />' . "\n" .
5163 "<id>" . href
(-full
=>1) . "</id>\n" .
5164 # use project owner for feed author
5165 "<author><name>$owner</name></author>\n";
5166 if (defined $favicon) {
5167 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5169 if (defined $logo_url) {
5170 # not twice as wide as tall: 72 x 27 pixels
5171 print "<logo>" . esc_url
($logo) . "</logo>\n";
5173 if (! %latest_date) {
5174 # dummy date to keep the feed valid until commits trickle in:
5175 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5177 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5182 for (my $i = 0; $i <= $#commitlist; $i++) {
5183 my %co = %{$commitlist[$i]};
5184 my $commit = $co{'id'};
5185 # we read 150, we always show 30 and the ones more recent than 48 hours
5186 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5189 my %cd = parse_date
($co{'author_epoch'});
5191 # get list of changed files
5192 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5193 $co{'parent'} || "--root",
5194 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5196 my @difftree = map { chomp; $_ } <$fd>;
5200 # print element (entry, item)
5201 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5202 if ($format eq 'rss') {
5204 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5205 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5206 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5207 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5208 "<link>$co_url</link>\n" .
5209 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5210 "<content:encoded>" .
5212 } elsif ($format eq 'atom') {
5214 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5215 "<updated>$cd{'iso-8601'}</updated>\n" .
5217 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5218 if ($co{'author_email'}) {
5219 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5221 print "</author>\n" .
5222 # use committer for contributor
5224 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5225 if ($co{'committer_email'}) {
5226 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5228 print "</contributor>\n" .
5229 "<published>$cd{'iso-8601'}</published>\n" .
5230 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5231 "<id>$co_url</id>\n" .
5232 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5233 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5235 my $comment = $co{'comment'};
5237 foreach my $line (@$comment) {
5238 $line = esc_html
($line);
5241 print "</pre><ul>\n";
5242 foreach my $difftree_line (@difftree) {
5243 my %difftree = parse_difftree_raw_line
($difftree_line);
5244 next if !$difftree{'from_id'};
5246 my $file = $difftree{'file'} || $difftree{'to_file'};
5250 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5251 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5252 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5253 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5254 -title
=> "diff"}, 'D');
5256 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5257 file_name
=>$file, hash_base
=>$commit),
5258 -title
=> "blame"}, 'B');
5260 # if this is not a feed of a file history
5261 if (!defined $file_name || $file_name ne $file) {
5262 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5263 file_name
=>$file, hash
=>$commit),
5264 -title
=> "history"}, 'H');
5266 $file = esc_path
($file);
5270 if ($format eq 'rss') {
5271 print "</ul>]]>\n" .
5272 "</content:encoded>\n" .
5274 } elsif ($format eq 'atom') {
5275 print "</ul>\n</div>\n" .
5282 if ($format eq 'rss') {
5283 print "</channel>\n</rss>\n";
5284 } elsif ($format eq 'atom') {
5298 my @list = git_get_projects_list
();
5300 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5302 <?xml version="1.0" encoding="utf-8"?>
5303 <opml version="1.0">
5305 <title>$site_name OPML Export</title>
5308 <outline text="git RSS feeds">
5311 foreach my $pr (@list) {
5313 my $head = git_get_head_hash
($proj{'path'});
5314 if (!defined $head) {
5317 $git_dir = "$projectroot/$proj{'path'}";
5318 my %co = parse_commit
($head);
5323 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5324 my $rss = "$my_url?p=$proj{'path'};a=rss";
5325 my $html = "$my_url?p=$proj{'path'};a=summary";
5326 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";