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 # You define site-wide feature defaults here; override them with
99 # $GITWEB_CONFIG as necessary.
102 # 'sub' => feature-sub (subroutine),
103 # 'override' => allow-override (boolean),
104 # 'default' => [ default options...] (array reference)}
106 # if feature is overridable (it means that allow-override has true value),
107 # then feature-sub will be called with default options as parameters;
108 # return value of feature-sub indicates if to enable specified feature
110 # if there is no 'sub' key (no feature-sub), then feature cannot be
113 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
115 # Enable the 'blame' blob view, showing the last commit that modified
116 # each line in the file. This can be very CPU-intensive.
118 # To enable system wide have in $GITWEB_CONFIG
119 # $feature{'blame'}{'default'} = [1];
120 # To have project specific config enable override in $GITWEB_CONFIG
121 # $feature{'blame'}{'override'} = 1;
122 # and in project config gitweb.blame = 0|1;
124 'sub' => \
&feature_blame
,
128 # Enable the 'snapshot' link, providing a compressed tarball of any
129 # tree. This can potentially generate high traffic if you have large
132 # To disable system wide have in $GITWEB_CONFIG
133 # $feature{'snapshot'}{'default'} = [undef];
134 # To have project specific config enable override in $GITWEB_CONFIG
135 # $feature{'snapshot'}{'override'} = 1;
136 # and in project config gitweb.snapshot = none|gzip|bzip2;
138 'sub' => \
&feature_snapshot
,
140 # => [content-encoding, suffix, program]
141 'default' => ['x-gzip', 'gz', 'gzip']},
143 # Enable text search, which will list the commits which match author,
144 # committer or commit text to a given string. Enabled by default.
145 # Project specific override is not supported.
150 # Enable the pickaxe search, which will list the commits that modified
151 # a given string in a file. This can be practical and quite faster
152 # alternative to 'blame', but still potentially CPU-intensive.
154 # To enable system wide have in $GITWEB_CONFIG
155 # $feature{'pickaxe'}{'default'} = [1];
156 # To have project specific config enable override in $GITWEB_CONFIG
157 # $feature{'pickaxe'}{'override'} = 1;
158 # and in project config gitweb.pickaxe = 0|1;
160 'sub' => \
&feature_pickaxe
,
164 # Make gitweb use an alternative format of the URLs which can be
165 # more readable and natural-looking: project name is embedded
166 # directly in the path and the query string contains other
167 # auxiliary information. All gitweb installations recognize
168 # URL in either format; this configures in which formats gitweb
171 # To enable system wide have in $GITWEB_CONFIG
172 # $feature{'pathinfo'}{'default'} = [1];
173 # Project specific override is not supported.
175 # Note that you will need to change the default location of CSS,
176 # favicon, logo and possibly other files to an absolute URL. Also,
177 # if gitweb.cgi serves as your indexfile, you will need to force
178 # $my_uri to contain the script name in your $GITWEB_CONFIG.
183 # Make gitweb consider projects in project root subdirectories
184 # to be forks of existing projects. Given project $projname.git,
185 # projects matching $projname/*.git will not be shown in the main
186 # projects list, instead a '+' mark will be added to $projname
187 # there and a 'forks' view will be enabled for the project, listing
188 # all the forks. If project list is taken from a file, forks have
189 # to be listed after the main project.
191 # To enable system wide have in $GITWEB_CONFIG
192 # $feature{'forks'}{'default'} = [1];
193 # Project specific override is not supported.
199 sub gitweb_check_feature
{
201 return unless exists $feature{$name};
202 my ($sub, $override, @defaults) = (
203 $feature{$name}{'sub'},
204 $feature{$name}{'override'},
205 @{$feature{$name}{'default'}});
206 if (!$override) { return @defaults; }
208 warn "feature $name is not overrideable";
211 return $sub->(@defaults);
215 my ($val) = git_get_project_config
('blame', '--bool');
217 if ($val eq 'true') {
219 } elsif ($val eq 'false') {
226 sub feature_snapshot
{
227 my ($ctype, $suffix, $command) = @_;
229 my ($val) = git_get_project_config
('snapshot');
231 if ($val eq 'gzip') {
232 return ('x-gzip', 'gz', 'gzip');
233 } elsif ($val eq 'bzip2') {
234 return ('x-bzip2', 'bz2', 'bzip2');
235 } elsif ($val eq 'none') {
239 return ($ctype, $suffix, $command);
242 sub gitweb_have_snapshot
{
243 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
244 my $have_snapshot = (defined $ctype && defined $suffix);
246 return $have_snapshot;
249 sub feature_pickaxe
{
250 my ($val) = git_get_project_config
('pickaxe', '--bool');
252 if ($val eq 'true') {
254 } elsif ($val eq 'false') {
261 # checking HEAD file with -e is fragile if the repository was
262 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
264 sub check_head_link
{
266 my $headfile = "$dir/HEAD";
267 return ((-e
$headfile) ||
268 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
271 sub check_export_ok
{
273 return (check_head_link
($dir) &&
274 (!$export_ok || -e
"$dir/$export_ok"));
277 # rename detection options for git-diff and git-diff-tree
278 # - default is '-M', with the cost proportional to
279 # (number of removed files) * (number of new files).
280 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
281 # (number of changed files + number of removed files) * (number of new files)
282 # - even more costly is '-C', '--find-copies-harder' with cost
283 # (number of files in the original tree) * (number of new files)
284 # - one might want to include '-B' option, e.g. '-B', '-M'
285 our @diff_opts = ('-M'); # taken from git_commit
287 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
288 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
290 # version of the core git binary
291 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
293 $projects_list ||= $projectroot;
295 # ======================================================================
296 # input validation and dispatch
297 our $action = $cgi->param('a');
298 if (defined $action) {
299 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
300 die_error
(undef, "Invalid action parameter");
304 # parameters which are pathnames
305 our $project = $cgi->param('p');
306 if (defined $project) {
307 if (!validate_pathname
($project) ||
308 !(-d
"$projectroot/$project") ||
309 !check_head_link
("$projectroot/$project") ||
310 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
311 ($strict_export && !project_in_list
($project))) {
313 die_error
(undef, "No such project");
317 our $file_name = $cgi->param('f');
318 if (defined $file_name) {
319 if (!validate_pathname
($file_name)) {
320 die_error
(undef, "Invalid file parameter");
324 our $file_parent = $cgi->param('fp');
325 if (defined $file_parent) {
326 if (!validate_pathname
($file_parent)) {
327 die_error
(undef, "Invalid file parent parameter");
331 # parameters which are refnames
332 our $hash = $cgi->param('h');
334 if (!validate_refname
($hash)) {
335 die_error
(undef, "Invalid hash parameter");
339 our $hash_parent = $cgi->param('hp');
340 if (defined $hash_parent) {
341 if (!validate_refname
($hash_parent)) {
342 die_error
(undef, "Invalid hash parent parameter");
346 our $hash_base = $cgi->param('hb');
347 if (defined $hash_base) {
348 if (!validate_refname
($hash_base)) {
349 die_error
(undef, "Invalid hash base parameter");
353 our $hash_parent_base = $cgi->param('hpb');
354 if (defined $hash_parent_base) {
355 if (!validate_refname
($hash_parent_base)) {
356 die_error
(undef, "Invalid hash parent base parameter");
361 our $page = $cgi->param('pg');
363 if ($page =~ m/[^0-9]/) {
364 die_error
(undef, "Invalid page parameter");
368 our $searchtext = $cgi->param('s');
370 if (defined $searchtext) {
371 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
372 die_error
(undef, "Invalid search parameter");
374 if (length($searchtext) < 2) {
375 die_error
(undef, "At least two characters are required for search parameter");
377 $search_regexp = quotemeta $searchtext;
380 our $searchtype = $cgi->param('st');
381 if (defined $searchtype) {
382 if ($searchtype =~ m/[^a-z]/) {
383 die_error
(undef, "Invalid searchtype parameter");
387 # now read PATH_INFO and use it as alternative to parameters
388 sub evaluate_path_info
{
389 return if defined $project;
390 my $path_info = $ENV{"PATH_INFO"};
391 return if !$path_info;
392 $path_info =~ s
,^/+,,;
393 return if !$path_info;
394 # find which part of PATH_INFO is project
395 $project = $path_info;
397 while ($project && !check_head_link
("$projectroot/$project")) {
398 $project =~ s
,/*[^/]*$,,;
401 $project = validate_pathname
($project);
403 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
404 ($strict_export && !project_in_list
($project))) {
408 # do not change any parameters if an action is given using the query string
410 $path_info =~ s
,^$project/*,,;
411 my ($refname, $pathname) = split(/:/, $path_info, 2);
412 if (defined $pathname) {
413 # we got "project.git/branch:filename" or "project.git/branch:dir/"
414 # we could use git_get_type(branch:pathname), but it needs $git_dir
415 $pathname =~ s
,^/+,,;
416 if (!$pathname || substr($pathname, -1) eq "/") {
420 $action ||= "blob_plain";
422 $hash_base ||= validate_refname
($refname);
423 $file_name ||= validate_pathname
($pathname);
424 } elsif (defined $refname) {
425 # we got "project.git/branch"
426 $action ||= "shortlog";
427 $hash ||= validate_refname
($refname);
430 evaluate_path_info
();
432 # path to the current git repository
434 $git_dir = "$projectroot/$project" if $project;
438 "blame" => \
&git_blame2
,
439 "blobdiff" => \
&git_blobdiff
,
440 "blobdiff_plain" => \
&git_blobdiff_plain
,
441 "blob" => \
&git_blob
,
442 "blob_plain" => \
&git_blob_plain
,
443 "commitdiff" => \
&git_commitdiff
,
444 "commitdiff_plain" => \
&git_commitdiff_plain
,
445 "commit" => \
&git_commit
,
446 "forks" => \
&git_forks
,
447 "heads" => \
&git_heads
,
448 "history" => \
&git_history
,
451 "atom" => \
&git_atom
,
452 "search" => \
&git_search
,
453 "search_help" => \
&git_search_help
,
454 "shortlog" => \
&git_shortlog
,
455 "summary" => \
&git_summary
,
457 "tags" => \
&git_tags
,
458 "tree" => \
&git_tree
,
459 "snapshot" => \
&git_snapshot
,
460 "object" => \
&git_object
,
461 # those below don't need $project
462 "opml" => \
&git_opml
,
463 "project_list" => \
&git_project_list
,
464 "project_index" => \
&git_project_index
,
467 if (!defined $action) {
469 $action = git_get_type
($hash);
470 } elsif (defined $hash_base && defined $file_name) {
471 $action = git_get_type
("$hash_base:$file_name");
472 } elsif (defined $project) {
475 $action = 'project_list';
478 if (!defined($actions{$action})) {
479 die_error
(undef, "Unknown action");
481 if ($action !~ m/^(opml|project_list|project_index)$/ &&
483 die_error
(undef, "Project needed");
485 $actions{$action}->();
488 ## ======================================================================
493 # default is to use -absolute url() i.e. $my_uri
494 my $href = $params{-full
} ? $my_url : $my_uri;
496 # XXX: Warning: If you touch this, check the search form for updating,
507 hash_parent_base
=> "hpb",
513 my %mapping = @mapping;
515 $params{'project'} = $project unless exists $params{'project'};
517 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
519 # use PATH_INFO for project name
520 $href .= "/$params{'project'}" if defined $params{'project'};
521 delete $params{'project'};
523 # Summary just uses the project path URL
524 if (defined $params{'action'} && $params{'action'} eq 'summary') {
525 delete $params{'action'};
529 # now encode the parameters explicitly
531 for (my $i = 0; $i < @mapping; $i += 2) {
532 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
533 if (defined $params{$name}) {
534 push @result, $symbol . "=" . esc_param
($params{$name});
537 $href .= "?" . join(';', @result) if scalar @result;
543 ## ======================================================================
544 ## validation, quoting/unquoting and escaping
546 sub validate_pathname
{
547 my $input = shift || return undef;
549 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
550 # at the beginning, at the end, and between slashes.
551 # also this catches doubled slashes
552 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
556 if ($input =~ m!\0!) {
562 sub validate_refname
{
563 my $input = shift || return undef;
565 # textual hashes are O.K.
566 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
569 # it must be correct pathname
570 $input = validate_pathname
($input)
572 # restrictions on ref name according to git-check-ref-format
573 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
579 # quote unsafe chars, but keep the slash, even when it's not
580 # correct, but quoted slashes look too horrible in bookmarks
583 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
589 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
592 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
598 # replace invalid utf8 character with SUBSTITUTION sequence
603 $str = decode_utf8
($str);
604 $str = $cgi->escapeHTML($str);
605 if ($opts{'-nbsp'}) {
606 $str =~ s/ / /g;
608 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
612 # quote control characters and escape filename to HTML
617 $str = decode_utf8
($str);
618 $str = $cgi->escapeHTML($str);
619 if ($opts{'-nbsp'}) {
620 $str =~ s/ / /g;
622 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
626 # Make control characters "printable", using character escape codes (CEC)
629 my %es = ( # character escape codes, aka escape sequences
630 "\t" => '\t', # tab (HT)
631 "\n" => '\n', # line feed (LF)
632 "\r" => '\r', # carrige return (CR)
633 "\f" => '\f', # form feed (FF)
634 "\b" => '\b', # backspace (BS)
635 "\a" => '\a', # alarm (bell) (BEL)
636 "\e" => '\e', # escape (ESC)
637 "\013" => '\v', # vertical tab (VT)
638 "\000" => '\0', # nul character (NUL)
640 my $chr = ( (exists $es{$cntrl})
642 : sprintf('\%03o', ord($cntrl)) );
643 return "<span class=\"cntrl\">$chr</span>";
646 # Alternatively use unicode control pictures codepoints,
647 # Unicode "printable representation" (PR)
650 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
651 return "<span class=\"cntrl\">$chr</span>";
654 # git may return quoted and escaped filenames
660 my %es = ( # character escape codes, aka escape sequences
661 't' => "\t", # tab (HT, TAB)
662 'n' => "\n", # newline (NL)
663 'r' => "\r", # return (CR)
664 'f' => "\f", # form feed (FF)
665 'b' => "\b", # backspace (BS)
666 'a' => "\a", # alarm (bell) (BEL)
667 'e' => "\e", # escape (ESC)
668 'v' => "\013", # vertical tab (VT)
671 if ($seq =~ m/^[0-7]{1,3}$/) {
672 # octal char sequence
673 return chr(oct($seq));
674 } elsif (exists $es{$seq}) {
675 # C escape sequence, aka character escape code
678 # quoted ordinary character
682 if ($str =~ m/^"(.*)"$/) {
685 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
690 # escape tabs (convert tabs to spaces)
694 while ((my $pos = index($line, "\t")) != -1) {
695 if (my $count = (8 - ($pos % 8))) {
696 my $spaces = ' ' x
$count;
697 $line =~ s/\t/$spaces/;
704 sub project_in_list
{
706 my @list = git_get_projects_list
();
707 return @list && scalar(grep { $_->{'path'} eq $project } @list);
710 ## ----------------------------------------------------------------------
711 ## HTML aware string manipulation
716 my $add_len = shift || 10;
718 # allow only $len chars, but don't cut a word if it would fit in $add_len
719 # if it doesn't fit, cut it if it's still longer than the dots we would add
720 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
723 if (length($tail) > 4) {
725 $body =~ s/&[^;]*$//; # remove chopped character entities
730 ## ----------------------------------------------------------------------
731 ## functions returning short strings
733 # CSS class for given age value (in seconds)
739 } elsif ($age < 60*60*2) {
741 } elsif ($age < 60*60*24*2) {
748 # convert age in seconds to "nn units ago" string
753 if ($age > 60*60*24*365*2) {
754 $age_str = (int $age/60/60/24/365);
755 $age_str .= " years ago";
756 } elsif ($age > 60*60*24*(365/12)*2) {
757 $age_str = int $age/60/60/24/(365/12);
758 $age_str .= " months ago";
759 } elsif ($age > 60*60*24*7*2) {
760 $age_str = int $age/60/60/24/7;
761 $age_str .= " weeks ago";
762 } elsif ($age > 60*60*24*2) {
763 $age_str = int $age/60/60/24;
764 $age_str .= " days ago";
765 } elsif ($age > 60*60*2) {
766 $age_str = int $age/60/60;
767 $age_str .= " hours ago";
768 } elsif ($age > 60*2) {
769 $age_str = int $age/60;
770 $age_str .= " min ago";
773 $age_str .= " sec ago";
775 $age_str .= " right now";
780 # convert file mode in octal to symbolic file mode string
782 my $mode = oct shift;
784 if (S_ISDIR
($mode & S_IFMT
)) {
786 } elsif (S_ISLNK
($mode)) {
788 } elsif (S_ISREG
($mode)) {
789 # git cares only about the executable bit
790 if ($mode & S_IXUSR
) {
800 # convert file mode in octal to file type string
804 if ($mode !~ m/^[0-7]+$/) {
810 if (S_ISDIR
($mode & S_IFMT
)) {
812 } elsif (S_ISLNK
($mode)) {
814 } elsif (S_ISREG
($mode)) {
821 # convert file mode in octal to file type description string
825 if ($mode !~ m/^[0-7]+$/) {
831 if (S_ISDIR
($mode & S_IFMT
)) {
833 } elsif (S_ISLNK
($mode)) {
835 } elsif (S_ISREG
($mode)) {
836 if ($mode & S_IXUSR
) {
847 ## ----------------------------------------------------------------------
848 ## functions returning short HTML fragments, or transforming HTML fragments
849 ## which don't belong to other sections
851 # format line of commit message.
852 sub format_log_line_html
{
855 $line = esc_html
($line, -nbsp
=>1);
856 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
859 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
860 -class => "text"}, $hash_text);
861 $line =~ s/$hash_text/$link/;
866 # format marker of refs pointing to given object
867 sub format_ref_marker
{
868 my ($refs, $id) = @_;
871 if (defined $refs->{$id}) {
872 foreach my $ref (@{$refs->{$id}}) {
873 my ($type, $name) = qw();
874 # e.g. tags/v2.6.11 or heads/next
875 if ($ref =~ m!^(.*?)s?/(.*)$!) {
883 $markers .= " <span class=\"$type\" title=\"$ref\">" .
884 esc_html
($name) . "</span>";
889 return ' <span class="refs">'. $markers . '</span>';
895 # format, perhaps shortened and with markers, title line
896 sub format_subject_html
{
897 my ($long, $short, $href, $extra) = @_;
898 $extra = '' unless defined($extra);
900 if (length($short) < length($long)) {
901 return $cgi->a({-href
=> $href, -class => "list subject",
902 -title
=> decode_utf8
($long)},
903 esc_html
($short) . $extra);
905 return $cgi->a({-href
=> $href, -class => "list subject"},
906 esc_html
($long) . $extra);
910 # format patch (diff) line (rather not to be used for diff headers)
911 sub format_diff_line
{
913 my ($from, $to) = @_;
918 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
920 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
921 if ($line =~ m/^\@{3}/) {
922 $diff_class = " chunk_header";
923 } elsif ($line =~ m/^\\/) {
924 $diff_class = " incomplete";
925 } elsif ($prefix =~ tr/+/+/) {
926 $diff_class = " add";
927 } elsif ($prefix =~ tr/-/-/) {
928 $diff_class = " rem";
931 # assume ordinary diff
932 my $char = substr($line, 0, 1);
934 $diff_class = " add";
935 } elsif ($char eq '-') {
936 $diff_class = " rem";
937 } elsif ($char eq '@') {
938 $diff_class = " chunk_header";
939 } elsif ($char eq "\\") {
940 $diff_class = " incomplete";
943 $line = untabify
($line);
944 if ($from && $to && $line =~ m/^\@{2} /) {
945 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
946 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
948 $from_lines = 0 unless defined $from_lines;
949 $to_lines = 0 unless defined $to_lines;
951 if ($from->{'href'}) {
952 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
953 -class=>"list"}, $from_text);
956 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
957 -class=>"list"}, $to_text);
959 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
960 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
961 return "<div class=\"diff$diff_class\">$line</div>\n";
962 } elsif ($from && $to && $line =~ m/^\@{3}/) {
963 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
964 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
966 @from_text = split(' ', $ranges);
967 for (my $i = 0; $i < @from_text; ++$i) {
968 ($from_start[$i], $from_nlines[$i]) =
969 (split(',', substr($from_text[$i], 1)), 0);
972 $to_text = pop @from_text;
973 $to_start = pop @from_start;
974 $to_nlines = pop @from_nlines;
976 $line = "<span class=\"chunk_info\">$prefix ";
977 for (my $i = 0; $i < @from_text; ++$i) {
978 if ($from->{'href'}[$i]) {
979 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
980 -class=>"list"}, $from_text[$i]);
982 $line .= $from_text[$i];
987 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
988 -class=>"list"}, $to_text);
992 $line .= " $prefix</span>" .
993 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
994 return "<div class=\"diff$diff_class\">$line</div>\n";
996 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
999 ## ----------------------------------------------------------------------
1000 ## git utility subroutines, invoking git commands
1002 # returns path to the core git executable and the --git-dir parameter as list
1004 return $GIT, '--git-dir='.$git_dir;
1007 # returns path to the core git executable and the --git-dir parameter as string
1009 return join(' ', git_cmd
());
1012 # get HEAD ref of given project as hash
1013 sub git_get_head_hash
{
1014 my $project = shift;
1015 my $o_git_dir = $git_dir;
1017 $git_dir = "$projectroot/$project";
1018 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1021 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1025 if (defined $o_git_dir) {
1026 $git_dir = $o_git_dir;
1031 # get type of given object
1035 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1037 close $fd or return;
1042 sub git_get_project_config
{
1043 my ($key, $type) = @_;
1045 return unless ($key);
1046 $key =~ s/^gitweb\.//;
1047 return if ($key =~ m/\W/);
1049 my @x = (git_cmd
(), 'config');
1050 if (defined $type) { push @x, $type; }
1052 push @x, "gitweb.$key";
1058 # get hash of given path at given ref
1059 sub git_get_hash_by_path
{
1061 my $path = shift || return undef;
1066 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1067 or die_error
(undef, "Open git-ls-tree failed");
1069 close $fd or return undef;
1071 if (!defined $line) {
1072 # there is no tree or hash given by $path at $base
1076 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1077 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1078 if (defined $type && $type ne $2) {
1079 # type doesn't match
1085 # get path of entry with given hash at given tree-ish (ref)
1086 # used to get 'from' filename for combined diff (merge commit) for renames
1087 sub git_get_path_by_hash
{
1088 my $base = shift || return;
1089 my $hash = shift || return;
1093 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1095 while (my $line = <$fd>) {
1098 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1099 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1100 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1109 ## ......................................................................
1110 ## git utility functions, directly accessing git repository
1112 sub git_get_project_description
{
1115 open my $fd, "$projectroot/$path/description" or return undef;
1118 if (defined $descr) {
1124 sub git_get_project_url_list
{
1127 open my $fd, "$projectroot/$path/cloneurl" or return;
1128 my @git_project_url_list = map { chomp; $_ } <$fd>;
1131 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1134 sub git_get_projects_list
{
1139 $filter =~ s/\.git$//;
1141 my ($check_forks) = gitweb_check_feature
('forks');
1143 if (-d
$projects_list) {
1144 # search in directory
1145 my $dir = $projects_list . ($filter ? "/$filter" : '');
1146 # remove the trailing "/"
1148 my $pfxlen = length("$dir");
1151 follow_fast
=> 1, # follow symbolic links
1152 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1154 # skip project-list toplevel, if we get it.
1155 return if (m!^[/.]$!);
1156 # only directories can be git repositories
1157 return unless (-d
$_);
1159 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1160 # we check related file in $projectroot
1161 if ($check_forks and $subdir =~ m
#/.#) {
1162 $File::Find
::prune
= 1;
1163 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1164 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1165 $File::Find
::prune
= 1;
1170 } elsif (-f
$projects_list) {
1171 # read from file(url-encoded):
1172 # 'git%2Fgit.git Linus+Torvalds'
1173 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1174 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1176 open my ($fd), $projects_list or return;
1178 while (my $line = <$fd>) {
1180 my ($path, $owner) = split ' ', $line;
1181 $path = unescape
($path);
1182 $owner = unescape
($owner);
1183 if (!defined $path) {
1186 if ($filter ne '') {
1187 # looking for forks;
1188 my $pfx = substr($path, 0, length($filter));
1189 if ($pfx ne $filter) {
1192 my $sfx = substr($path, length($filter));
1193 if ($sfx !~ /^\/.*\
.git
$/) {
1196 } elsif ($check_forks) {
1198 foreach my $filter (keys %paths) {
1199 # looking for forks;
1200 my $pfx = substr($path, 0, length($filter));
1201 if ($pfx ne $filter) {
1204 my $sfx = substr($path, length($filter));
1205 if ($sfx !~ /^\/.*\
.git
$/) {
1208 # is a fork, don't include it in
1213 if (check_export_ok
("$projectroot/$path")) {
1216 owner
=> decode_utf8
($owner),
1219 (my $forks_path = $path) =~ s/\.git$//;
1220 $paths{$forks_path}++;
1228 sub git_get_project_owner
{
1229 my $project = shift;
1232 return undef unless $project;
1234 # read from file (url-encoded):
1235 # 'git%2Fgit.git Linus+Torvalds'
1236 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1237 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1238 if (-f
$projects_list) {
1239 open (my $fd , $projects_list);
1240 while (my $line = <$fd>) {
1242 my ($pr, $ow) = split ' ', $line;
1243 $pr = unescape
($pr);
1244 $ow = unescape
($ow);
1245 if ($pr eq $project) {
1246 $owner = decode_utf8
($ow);
1252 if (!defined $owner) {
1253 $owner = get_file_owner
("$projectroot/$project");
1259 sub git_get_last_activity
{
1263 $git_dir = "$projectroot/$path";
1264 open($fd, "-|", git_cmd
(), 'for-each-ref',
1265 '--format=%(committer)',
1266 '--sort=-committerdate',
1268 'refs/heads') or return;
1269 my $most_recent = <$fd>;
1270 close $fd or return;
1271 if (defined $most_recent &&
1272 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1274 my $age = time - $timestamp;
1275 return ($age, age_string
($age));
1279 sub git_get_references
{
1280 my $type = shift || "";
1282 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1283 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1284 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1285 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1288 while (my $line = <$fd>) {
1290 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1291 if (defined $refs{$1}) {
1292 push @{$refs{$1}}, $2;
1298 close $fd or return;
1302 sub git_get_rev_name_tags
{
1303 my $hash = shift || return undef;
1305 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1307 my $name_rev = <$fd>;
1310 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1313 # catches also '$hash undefined' output
1318 ## ----------------------------------------------------------------------
1319 ## parse to hash functions
1323 my $tz = shift || "-0000";
1326 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1327 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1328 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1329 $date{'hour'} = $hour;
1330 $date{'minute'} = $min;
1331 $date{'mday'} = $mday;
1332 $date{'day'} = $days[$wday];
1333 $date{'month'} = $months[$mon];
1334 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1335 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1336 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1337 $mday, $months[$mon], $hour ,$min;
1338 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1339 1900+$year, $mon, $mday, $hour ,$min, $sec;
1341 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1342 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1343 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1344 $date{'hour_local'} = $hour;
1345 $date{'minute_local'} = $min;
1346 $date{'tz_local'} = $tz;
1347 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1348 1900+$year, $mon+1, $mday,
1349 $hour, $min, $sec, $tz);
1358 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1359 $tag{'id'} = $tag_id;
1360 while (my $line = <$fd>) {
1362 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1363 $tag{'object'} = $1;
1364 } elsif ($line =~ m/^type (.+)$/) {
1366 } elsif ($line =~ m/^tag (.+)$/) {
1368 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1369 $tag{'author'} = $1;
1372 } elsif ($line =~ m/--BEGIN/) {
1373 push @comment, $line;
1375 } elsif ($line eq "") {
1379 push @comment, <$fd>;
1380 $tag{'comment'} = \
@comment;
1381 close $fd or return;
1382 if (!defined $tag{'name'}) {
1388 sub parse_commit_text
{
1389 my ($commit_text, $withparents) = @_;
1390 my @commit_lines = split '\n', $commit_text;
1393 pop @commit_lines; # Remove '\0'
1395 if (! @commit_lines) {
1399 my $header = shift @commit_lines;
1400 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1403 ($co{'id'}, my @parents) = split ' ', $header;
1404 while (my $line = shift @commit_lines) {
1405 last if $line eq "\n";
1406 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1408 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1410 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1412 $co{'author_epoch'} = $2;
1413 $co{'author_tz'} = $3;
1414 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1415 $co{'author_name'} = $1;
1416 $co{'author_email'} = $2;
1418 $co{'author_name'} = $co{'author'};
1420 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1421 $co{'committer'} = $1;
1422 $co{'committer_epoch'} = $2;
1423 $co{'committer_tz'} = $3;
1424 $co{'committer_name'} = $co{'committer'};
1425 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1426 $co{'committer_name'} = $1;
1427 $co{'committer_email'} = $2;
1429 $co{'committer_name'} = $co{'committer'};
1433 if (!defined $co{'tree'}) {
1436 $co{'parents'} = \
@parents;
1437 $co{'parent'} = $parents[0];
1439 foreach my $title (@commit_lines) {
1442 $co{'title'} = chop_str
($title, 80, 5);
1443 # remove leading stuff of merges to make the interesting part visible
1444 if (length($title) > 50) {
1445 $title =~ s/^Automatic //;
1446 $title =~ s/^merge (of|with) /Merge ... /i;
1447 if (length($title) > 50) {
1448 $title =~ s/(http|rsync):\/\///;
1450 if (length($title) > 50) {
1451 $title =~ s/(master|www|rsync)\.//;
1453 if (length($title) > 50) {
1454 $title =~ s/kernel.org:?//;
1456 if (length($title) > 50) {
1457 $title =~ s/\/pub\/scm//;
1460 $co{'title_short'} = chop_str
($title, 50, 5);
1464 if ($co{'title'} eq "") {
1465 $co{'title'} = $co{'title_short'} = '(no commit message)';
1467 # remove added spaces
1468 foreach my $line (@commit_lines) {
1471 $co{'comment'} = \
@commit_lines;
1473 my $age = time - $co{'committer_epoch'};
1475 $co{'age_string'} = age_string
($age);
1476 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1477 if ($age > 60*60*24*7*2) {
1478 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1479 $co{'age_string_age'} = $co{'age_string'};
1481 $co{'age_string_date'} = $co{'age_string'};
1482 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1488 my ($commit_id) = @_;
1493 open my $fd, "-|", git_cmd
(), "rev-list",
1499 or die_error
(undef, "Open git-rev-list failed");
1500 %co = parse_commit_text
(<$fd>, 1);
1507 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1515 open my $fd, "-|", git_cmd
(), "rev-list",
1517 ($arg ? ($arg) : ()),
1518 ("--max-count=" . $maxcount),
1519 ("--skip=" . $skip),
1522 ($filename ? ($filename) : ())
1523 or die_error
(undef, "Open git-rev-list failed");
1524 while (my $line = <$fd>) {
1525 my %co = parse_commit_text
($line);
1530 return wantarray ? @cos : \
@cos;
1533 # parse ref from ref_file, given by ref_id, with given type
1535 my $ref_file = shift;
1537 my $type = shift || git_get_type
($ref_id);
1540 $ref_item{'type'} = $type;
1541 $ref_item{'id'} = $ref_id;
1542 $ref_item{'epoch'} = 0;
1543 $ref_item{'age'} = "unknown";
1544 if ($type eq "tag") {
1545 my %tag = parse_tag
($ref_id);
1546 $ref_item{'comment'} = $tag{'comment'};
1547 if ($tag{'type'} eq "commit") {
1548 my %co = parse_commit
($tag{'object'});
1549 $ref_item{'epoch'} = $co{'committer_epoch'};
1550 $ref_item{'age'} = $co{'age_string'};
1551 } elsif (defined($tag{'epoch'})) {
1552 my $age = time - $tag{'epoch'};
1553 $ref_item{'epoch'} = $tag{'epoch'};
1554 $ref_item{'age'} = age_string
($age);
1556 $ref_item{'reftype'} = $tag{'type'};
1557 $ref_item{'name'} = $tag{'name'};
1558 $ref_item{'refid'} = $tag{'object'};
1559 } elsif ($type eq "commit"){
1560 my %co = parse_commit
($ref_id);
1561 $ref_item{'reftype'} = "commit";
1562 $ref_item{'name'} = $ref_file;
1563 $ref_item{'title'} = $co{'title'};
1564 $ref_item{'refid'} = $ref_id;
1565 $ref_item{'epoch'} = $co{'committer_epoch'};
1566 $ref_item{'age'} = $co{'age_string'};
1568 $ref_item{'reftype'} = $type;
1569 $ref_item{'name'} = $ref_file;
1570 $ref_item{'refid'} = $ref_id;
1576 # parse line of git-diff-tree "raw" output
1577 sub parse_difftree_raw_line
{
1581 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1582 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1583 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1584 $res{'from_mode'} = $1;
1585 $res{'to_mode'} = $2;
1586 $res{'from_id'} = $3;
1588 $res{'status'} = $5;
1589 $res{'similarity'} = $6;
1590 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1591 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1593 $res{'file'} = unquote
($7);
1596 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1597 # combined diff (for merge commit)
1598 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1599 $res{'nparents'} = length($1);
1600 $res{'from_mode'} = [ split(' ', $2) ];
1601 $res{'to_mode'} = pop @{$res{'from_mode'}};
1602 $res{'from_id'} = [ split(' ', $3) ];
1603 $res{'to_id'} = pop @{$res{'from_id'}};
1604 $res{'status'} = [ split('', $4) ];
1605 $res{'to_file'} = unquote
($5);
1607 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1608 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1609 $res{'commit'} = $1;
1612 return wantarray ? %res : \
%res;
1615 # parse line of git-ls-tree output
1616 sub parse_ls_tree_line
($;%) {
1621 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1622 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1630 $res{'name'} = unquote
($4);
1633 return wantarray ? %res : \
%res;
1636 ## ......................................................................
1637 ## parse to array of hashes functions
1639 sub git_get_heads_list
{
1643 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1644 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1645 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1648 while (my $line = <$fd>) {
1652 my ($refinfo, $committerinfo) = split(/\0/, $line);
1653 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1654 my ($committer, $epoch, $tz) =
1655 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1656 $name =~ s!^refs/heads/!!;
1658 $ref_item{'name'} = $name;
1659 $ref_item{'id'} = $hash;
1660 $ref_item{'title'} = $title || '(no commit message)';
1661 $ref_item{'epoch'} = $epoch;
1663 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1665 $ref_item{'age'} = "unknown";
1668 push @headslist, \
%ref_item;
1672 return wantarray ? @headslist : \
@headslist;
1675 sub git_get_tags_list
{
1679 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1680 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1681 '--format=%(objectname) %(objecttype) %(refname) '.
1682 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1685 while (my $line = <$fd>) {
1689 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1690 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1691 my ($creator, $epoch, $tz) =
1692 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1693 $name =~ s!^refs/tags/!!;
1695 $ref_item{'type'} = $type;
1696 $ref_item{'id'} = $id;
1697 $ref_item{'name'} = $name;
1698 if ($type eq "tag") {
1699 $ref_item{'subject'} = $title;
1700 $ref_item{'reftype'} = $reftype;
1701 $ref_item{'refid'} = $refid;
1703 $ref_item{'reftype'} = $type;
1704 $ref_item{'refid'} = $id;
1707 if ($type eq "tag" || $type eq "commit") {
1708 $ref_item{'epoch'} = $epoch;
1710 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1712 $ref_item{'age'} = "unknown";
1716 push @tagslist, \
%ref_item;
1720 return wantarray ? @tagslist : \
@tagslist;
1723 ## ----------------------------------------------------------------------
1724 ## filesystem-related functions
1726 sub get_file_owner
{
1729 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1730 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1731 if (!defined $gcos) {
1735 $owner =~ s/[,;].*$//;
1736 return decode_utf8
($owner);
1739 ## ......................................................................
1740 ## mimetype related functions
1742 sub mimetype_guess_file
{
1743 my $filename = shift;
1744 my $mimemap = shift;
1745 -r
$mimemap or return undef;
1748 open(MIME
, $mimemap) or return undef;
1750 next if m/^#/; # skip comments
1751 my ($mime, $exts) = split(/\t+/);
1752 if (defined $exts) {
1753 my @exts = split(/\s+/, $exts);
1754 foreach my $ext (@exts) {
1755 $mimemap{$ext} = $mime;
1761 $filename =~ /\.([^.]*)$/;
1762 return $mimemap{$1};
1765 sub mimetype_guess
{
1766 my $filename = shift;
1768 $filename =~ /\./ or return undef;
1770 if ($mimetypes_file) {
1771 my $file = $mimetypes_file;
1772 if ($file !~ m!^/!) { # if it is relative path
1773 # it is relative to project
1774 $file = "$projectroot/$project/$file";
1776 $mime = mimetype_guess_file
($filename, $file);
1778 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1784 my $filename = shift;
1787 my $mime = mimetype_guess
($filename);
1788 $mime and return $mime;
1792 return $default_blob_plain_mimetype unless $fd;
1795 return 'text/plain' .
1796 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1797 } elsif (! $filename) {
1798 return 'application/octet-stream';
1799 } elsif ($filename =~ m/\.png$/i) {
1801 } elsif ($filename =~ m/\.gif$/i) {
1803 } elsif ($filename =~ m/\.jpe?g$/i) {
1804 return 'image/jpeg';
1806 return 'application/octet-stream';
1810 ## ======================================================================
1811 ## functions printing HTML: header, footer, error page
1813 sub git_header_html
{
1814 my $status = shift || "200 OK";
1815 my $expires = shift;
1817 my $title = "$site_name";
1818 if (defined $project) {
1819 $title .= " - " . decode_utf8
($project);
1820 if (defined $action) {
1821 $title .= "/$action";
1822 if (defined $file_name) {
1823 $title .= " - " . esc_path
($file_name);
1824 if ($action eq "tree" && $file_name !~ m
|/$|) {
1831 # require explicit support from the UA if we are to send the page as
1832 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1833 # we have to do this because MSIE sometimes globs '*/*', pretending to
1834 # support xhtml+xml but choking when it gets what it asked for.
1835 if (defined $cgi->http('HTTP_ACCEPT') &&
1836 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1837 $cgi->Accept('application/xhtml+xml') != 0) {
1838 $content_type = 'application/xhtml+xml';
1840 $content_type = 'text/html';
1842 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1843 -status
=> $status, -expires
=> $expires);
1844 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
1846 <?xml version="1.0" encoding="utf-8"?>
1847 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1848 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1849 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1850 <!-- git core binaries version $git_version -->
1852 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1853 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
1854 <meta name="robots" content="index, nofollow"/>
1855 <title>$title</title>
1857 # print out each stylesheet that exist
1858 if (defined $stylesheet) {
1859 #provides backwards capability for those people who define style sheet in a config file
1860 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1862 foreach my $stylesheet (@stylesheets) {
1863 next unless $stylesheet;
1864 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1867 if (defined $project) {
1868 printf('<link rel="alternate" title="%s log RSS feed" '.
1869 'href="%s" type="application/rss+xml" />'."\n",
1870 esc_param
($project), href
(action
=>"rss"));
1871 printf('<link rel="alternate" title="%s log Atom feed" '.
1872 'href="%s" type="application/atom+xml" />'."\n",
1873 esc_param
($project), href
(action
=>"atom"));
1875 printf('<link rel="alternate" title="%s projects list" '.
1876 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1877 $site_name, href
(project
=>undef, action
=>"project_index"));
1878 printf('<link rel="alternate" title="%s projects feeds" '.
1879 'href="%s" type="text/x-opml"/>'."\n",
1880 $site_name, href
(project
=>undef, action
=>"opml"));
1882 if (defined $favicon) {
1883 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1889 if (-f
$site_header) {
1890 open (my $fd, $site_header);
1895 print "<div class=\"page_header\">\n" .
1896 $cgi->a({-href
=> esc_url
($logo_url),
1897 -title
=> $logo_label},
1898 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1899 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1900 if (defined $project) {
1901 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1902 if (defined $action) {
1909 my ($have_search) = gitweb_check_feature
('search');
1910 if ((defined $project) && ($have_search)) {
1911 if (!defined $searchtext) {
1915 if (defined $hash_base) {
1916 $search_hash = $hash_base;
1917 } elsif (defined $hash) {
1918 $search_hash = $hash;
1920 $search_hash = "HEAD";
1922 $cgi->param("a", "search");
1923 $cgi->param("h", $search_hash);
1924 $cgi->param("p", $project);
1925 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1926 "<div class=\"search\">\n" .
1927 $cgi->hidden(-name
=> "p") . "\n" .
1928 $cgi->hidden(-name
=> "a") . "\n" .
1929 $cgi->hidden(-name
=> "h") . "\n" .
1930 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1931 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1932 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1934 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1936 $cgi->end_form() . "\n";
1940 sub git_footer_html
{
1941 print "<div class=\"page_footer\">\n";
1942 if (defined $project) {
1943 my $descr = git_get_project_description
($project);
1944 if (defined $descr) {
1945 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1947 print $cgi->a({-href
=> href
(action
=>"rss"),
1948 -class => "rss_logo"}, "RSS") . " ";
1949 print $cgi->a({-href
=> href
(action
=>"atom"),
1950 -class => "rss_logo"}, "Atom") . "\n";
1952 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1953 -class => "rss_logo"}, "OPML") . " ";
1954 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1955 -class => "rss_logo"}, "TXT") . "\n";
1959 if (-f
$site_footer) {
1960 open (my $fd, $site_footer);
1970 my $status = shift || "403 Forbidden";
1971 my $error = shift || "Malformed query, file missing or permission denied";
1973 git_header_html
($status);
1975 <div class="page_body">
1985 ## ----------------------------------------------------------------------
1986 ## functions printing or outputting HTML: navigation
1988 sub git_print_page_nav
{
1989 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1990 $extra = '' if !defined $extra; # pager or formats
1992 my @navs = qw(summary shortlog log commit commitdiff tree);
1994 @navs = grep { $_ ne $suppress } @navs;
1997 my %arg = map { $_ => {action
=>$_} } @navs;
1998 if (defined $head) {
1999 for (qw(commit commitdiff)) {
2000 $arg{$_}{'hash'} = $head;
2002 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2003 for (qw(shortlog log)) {
2004 $arg{$_}{'hash'} = $head;
2008 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2009 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2011 print "<div class=\"page_nav\">\n" .
2013 map { $_ eq $current ?
2014 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2016 print "<br/>\n$extra<br/>\n" .
2020 sub format_paging_nav
{
2021 my ($action, $hash, $head, $page, $nrevs) = @_;
2025 if ($hash ne $head || $page) {
2026 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2028 $paging_nav .= "HEAD";
2032 $paging_nav .= " ⋅ " .
2033 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2034 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2036 $paging_nav .= " ⋅ prev";
2039 if ($nrevs >= (100 * ($page+1)-1)) {
2040 $paging_nav .= " ⋅ " .
2041 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2042 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2044 $paging_nav .= " ⋅ next";
2050 ## ......................................................................
2051 ## functions printing or outputting HTML: div
2053 sub git_print_header_div
{
2054 my ($action, $title, $hash, $hash_base) = @_;
2057 $args{'action'} = $action;
2058 $args{'hash'} = $hash if $hash;
2059 $args{'hash_base'} = $hash_base if $hash_base;
2061 print "<div class=\"header\">\n" .
2062 $cgi->a({-href
=> href
(%args), -class => "title"},
2063 $title ? $title : $action) .
2067 #sub git_print_authorship (\%) {
2068 sub git_print_authorship
{
2071 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2072 print "<div class=\"author_date\">" .
2073 esc_html
($co->{'author_name'}) .
2075 if ($ad{'hour_local'} < 6) {
2076 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2077 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2079 printf(" (%02d:%02d %s)",
2080 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2085 sub git_print_page_path
{
2091 print "<div class=\"page_path\">";
2092 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2093 -title
=> 'tree root'}, decode_utf8
("[$project]"));
2095 if (defined $name) {
2096 my @dirname = split '/', $name;
2097 my $basename = pop @dirname;
2100 foreach my $dir (@dirname) {
2101 $fullname .= ($fullname ? '/' : '') . $dir;
2102 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2104 -title
=> $fullname}, esc_path
($dir));
2107 if (defined $type && $type eq 'blob') {
2108 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2110 -title
=> $name}, esc_path
($basename));
2111 } elsif (defined $type && $type eq 'tree') {
2112 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2114 -title
=> $name}, esc_path
($basename));
2117 print esc_path
($basename);
2120 print "<br/></div>\n";
2123 # sub git_print_log (\@;%) {
2124 sub git_print_log
($;%) {
2128 if ($opts{'-remove_title'}) {
2129 # remove title, i.e. first line of log
2132 # remove leading empty lines
2133 while (defined $log->[0] && $log->[0] eq "") {
2140 foreach my $line (@$log) {
2141 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2144 if (! $opts{'-remove_signoff'}) {
2145 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2148 # remove signoff lines
2155 # print only one empty line
2156 # do not print empty line after signoff
2158 next if ($empty || $signoff);
2164 print format_log_line_html
($line) . "<br/>\n";
2167 if ($opts{'-final_empty_line'}) {
2168 # end with single empty line
2169 print "<br/>\n" unless $empty;
2173 # return link target (what link points to)
2174 sub git_get_link_target
{
2179 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2183 $link_target = <$fd>;
2188 return $link_target;
2191 # given link target, and the directory (basedir) the link is in,
2192 # return target of link relative to top directory (top tree);
2193 # return undef if it is not possible (including absolute links).
2194 sub normalize_link_target
{
2195 my ($link_target, $basedir, $hash_base) = @_;
2197 # we can normalize symlink target only if $hash_base is provided
2198 return unless $hash_base;
2200 # absolute symlinks (beginning with '/') cannot be normalized
2201 return if (substr($link_target, 0, 1) eq '/');
2203 # normalize link target to path from top (root) tree (dir)
2206 $path = $basedir . '/' . $link_target;
2208 # we are in top (root) tree (dir)
2209 $path = $link_target;
2212 # remove //, /./, and /../
2214 foreach my $part (split('/', $path)) {
2215 # discard '.' and ''
2216 next if (!$part || $part eq '.');
2218 if ($part eq '..') {
2222 # link leads outside repository (outside top dir)
2226 push @path_parts, $part;
2229 $path = join('/', @path_parts);
2234 # print tree entry (row of git_tree), but without encompassing <tr> element
2235 sub git_print_tree_entry
{
2236 my ($t, $basedir, $hash_base, $have_blame) = @_;
2239 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2241 # The format of a table row is: mode list link. Where mode is
2242 # the mode of the entry, list is the name of the entry, an href,
2243 # and link is the action links of the entry.
2245 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2246 if ($t->{'type'} eq "blob") {
2247 print "<td class=\"list\">" .
2248 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2249 file_name
=>"$basedir$t->{'name'}", %base_key),
2250 -class => "list"}, esc_path
($t->{'name'}));
2251 if (S_ISLNK
(oct $t->{'mode'})) {
2252 my $link_target = git_get_link_target
($t->{'hash'});
2254 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2255 if (defined $norm_target) {
2257 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2258 file_name
=>$norm_target),
2259 -title
=> $norm_target}, esc_path
($link_target));
2261 print " -> " . esc_path
($link_target);
2266 print "<td class=\"link\">";
2267 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2268 file_name
=>"$basedir$t->{'name'}", %base_key)},
2272 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2273 file_name
=>"$basedir$t->{'name'}", %base_key)},
2276 if (defined $hash_base) {
2278 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2279 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2283 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2284 file_name
=>"$basedir$t->{'name'}")},
2288 } elsif ($t->{'type'} eq "tree") {
2289 print "<td class=\"list\">";
2290 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2291 file_name
=>"$basedir$t->{'name'}", %base_key)},
2292 esc_path
($t->{'name'}));
2294 print "<td class=\"link\">";
2295 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2296 file_name
=>"$basedir$t->{'name'}", %base_key)},
2298 if (defined $hash_base) {
2300 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2301 file_name
=>"$basedir$t->{'name'}")},
2308 ## ......................................................................
2309 ## functions printing large fragments of HTML
2311 sub fill_from_file_info
{
2312 my ($diff, @parents) = @_;
2314 $diff->{'from_file'} = [ ];
2315 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2316 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2317 if ($diff->{'status'}[$i] eq 'R' ||
2318 $diff->{'status'}[$i] eq 'C') {
2319 $diff->{'from_file'}[$i] =
2320 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2327 # parameters can be strings, or references to arrays of strings
2331 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @$a == @$b) {
2332 for (my $i = 0; $i < @$a; ++$i) {
2333 return 0 unless ($a->[$i] eq $b->[$i]);
2336 } elsif (!ref($a) && !ref($b)) {
2344 sub git_difftree_body
{
2345 my ($difftree, $hash, @parents) = @_;
2346 my ($parent) = $parents[0];
2347 my ($have_blame) = gitweb_check_feature
('blame');
2348 print "<div class=\"list_head\">\n";
2349 if ($#{$difftree} > 10) {
2350 print(($#{$difftree} + 1) . " files changed:\n");
2354 print "<table class=\"" .
2355 (@parents > 1 ? "combined " : "") .
2359 foreach my $line (@{$difftree}) {
2361 if (ref($line) eq "HASH") {
2362 # pre-parsed (or generated by hand)
2365 $diff = parse_difftree_raw_line
($line);
2369 print "<tr class=\"dark\">\n";
2371 print "<tr class=\"light\">\n";
2375 if (exists $diff->{'nparents'}) { # combined diff
2377 fill_from_file_info
($diff, @parents)
2378 unless exists $diff->{'from_file'};
2380 if ($diff->{'to_id'} ne ('0' x
40)) {
2381 # file exists in the result (child) commit
2383 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2384 file_name
=>$diff->{'to_file'},
2386 -class => "list"}, esc_path
($diff->{'to_file'})) .
2390 esc_path
($diff->{'to_file'}) .
2394 if ($action eq 'commitdiff') {
2397 print "<td class=\"link\">" .
2398 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2403 my $has_history = 0;
2404 my $not_deleted = 0;
2405 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2406 my $hash_parent = $parents[$i];
2407 my $from_hash = $diff->{'from_id'}[$i];
2408 my $from_path = $diff->{'from_file'}[$i];
2409 my $status = $diff->{'status'}[$i];
2411 $has_history ||= ($status ne 'A');
2412 $not_deleted ||= ($status ne 'D');
2414 if ($status eq 'A') {
2415 print "<td class=\"link\" align=\"right\"> | </td>\n";
2416 } elsif ($status eq 'D') {
2417 print "<td class=\"link\">" .
2418 $cgi->a({-href
=> href
(action
=>"blob",
2421 file_name
=>$from_path)},
2425 if ($diff->{'to_id'} eq $from_hash) {
2426 print "<td class=\"link nochange\">";
2428 print "<td class=\"link\">";
2430 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2431 hash
=>$diff->{'to_id'},
2432 hash_parent
=>$from_hash,
2434 hash_parent_base
=>$hash_parent,
2435 file_name
=>$diff->{'to_file'},
2436 file_parent
=>$from_path)},
2442 print "<td class=\"link\">";
2444 print $cgi->a({-href
=> href
(action
=>"blob",
2445 hash
=>$diff->{'to_id'},
2446 file_name
=>$diff->{'to_file'},
2449 print " | " if ($has_history);
2452 print $cgi->a({-href
=> href
(action
=>"history",
2453 file_name
=>$diff->{'to_file'},
2460 next; # instead of 'else' clause, to avoid extra indent
2462 # else ordinary diff
2464 my ($to_mode_oct, $to_mode_str, $to_file_type);
2465 my ($from_mode_oct, $from_mode_str, $from_file_type);
2466 if ($diff->{'to_mode'} ne ('0' x
6)) {
2467 $to_mode_oct = oct $diff->{'to_mode'};
2468 if (S_ISREG
($to_mode_oct)) { # only for regular file
2469 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2471 $to_file_type = file_type
($diff->{'to_mode'});
2473 if ($diff->{'from_mode'} ne ('0' x
6)) {
2474 $from_mode_oct = oct $diff->{'from_mode'};
2475 if (S_ISREG
($to_mode_oct)) { # only for regular file
2476 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2478 $from_file_type = file_type
($diff->{'from_mode'});
2481 if ($diff->{'status'} eq "A") { # created
2482 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2483 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2484 $mode_chng .= "]</span>";
2486 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2487 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2488 -class => "list"}, esc_path
($diff->{'file'}));
2490 print "<td>$mode_chng</td>\n";
2491 print "<td class=\"link\">";
2492 if ($action eq 'commitdiff') {
2495 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2498 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2499 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2503 } elsif ($diff->{'status'} eq "D") { # deleted
2504 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2506 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2507 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2508 -class => "list"}, esc_path
($diff->{'file'}));
2510 print "<td>$mode_chng</td>\n";
2511 print "<td class=\"link\">";
2512 if ($action eq 'commitdiff') {
2515 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2518 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2519 hash_base
=>$parent, file_name
=>$diff->{'file'})},
2522 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2523 file_name
=>$diff->{'file'})},
2526 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2527 file_name
=>$diff->{'file'})},
2531 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2532 my $mode_chnge = "";
2533 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2534 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2535 if ($from_file_type ne $to_file_type) {
2536 $mode_chnge .= " from $from_file_type to $to_file_type";
2538 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2539 if ($from_mode_str && $to_mode_str) {
2540 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2541 } elsif ($to_mode_str) {
2542 $mode_chnge .= " mode: $to_mode_str";
2545 $mode_chnge .= "]</span>\n";
2548 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2549 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2550 -class => "list"}, esc_path
($diff->{'file'}));
2552 print "<td>$mode_chnge</td>\n";
2553 print "<td class=\"link\">";
2554 if ($action eq 'commitdiff') {
2557 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2559 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2560 # "commit" view and modified file (not onlu mode changed)
2561 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2562 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2563 hash_base
=>$hash, hash_parent_base
=>$parent,
2564 file_name
=>$diff->{'file'})},
2568 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2569 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2572 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2573 file_name
=>$diff->{'file'})},
2576 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2577 file_name
=>$diff->{'file'})},
2581 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
2582 my %status_name = ('R' => 'moved', 'C' => 'copied');
2583 my $nstatus = $status_name{$diff->{'status'}};
2585 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2586 # mode also for directories, so we cannot use $to_mode_str
2587 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2590 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2591 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
2592 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
2593 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2594 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2595 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
2596 -class => "list"}, esc_path
($diff->{'from_file'})) .
2597 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2598 "<td class=\"link\">";
2599 if ($action eq 'commitdiff') {
2602 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2604 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2605 # "commit" view and modified file (not only pure rename or copy)
2606 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2607 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2608 hash_base
=>$hash, hash_parent_base
=>$parent,
2609 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
2613 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2614 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
2617 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2618 file_name
=>$diff->{'to_file'})},
2621 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2622 file_name
=>$diff->{'to_file'})},
2626 } # we should not encounter Unmerged (U) or Unknown (X) status
2632 sub git_patchset_body
{
2633 my ($fd, $difftree, $hash, @hash_parents) = @_;
2634 my ($hash_parent) = $hash_parents[0];
2637 my $patch_number = 0;
2642 print "<div class=\"patchset\">\n";
2644 # skip to first patch
2645 while ($patch_line = <$fd>) {
2648 last if ($patch_line =~ m/^diff /);
2652 while ($patch_line) {
2654 my ($from_id, $to_id);
2657 #assert($patch_line =~ m/^diff /) if DEBUG;
2658 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2660 push @diff_header, $patch_line;
2662 # extended diff header
2664 while ($patch_line = <$fd>) {
2667 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2669 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2672 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2673 $from_id = [ split(',', $1) ];
2677 push @diff_header, $patch_line;
2679 my $last_patch_line = $patch_line;
2681 # check if current patch belong to current raw line
2682 # and parse raw git-diff line if needed
2683 if (defined $diffinfo &&
2684 defined $from_id && defined $to_id &&
2685 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
2686 $diffinfo->{'to_id'} eq $to_id) {
2687 # this is continuation of a split patch
2688 print "<div class=\"patch cont\">\n";
2690 # advance raw git-diff output if needed
2691 $patch_idx++ if defined $diffinfo;
2693 # read and prepare patch information
2694 if (ref($difftree->[$patch_idx]) eq "HASH") {
2695 # pre-parsed (or generated by hand)
2696 $diffinfo = $difftree->[$patch_idx];
2698 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2700 if ($diffinfo->{'nparents'}) {
2704 fill_from_file_info
($diffinfo, @hash_parents)
2705 unless exists $diffinfo->{'from_file'};
2706 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2707 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2708 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2709 $from{'href'}[$i] = href
(action
=>"blob",
2710 hash_base
=>$hash_parents[$i],
2711 hash
=>$diffinfo->{'from_id'}[$i],
2712 file_name
=>$from{'file'}[$i]);
2714 $from{'href'}[$i] = undef;
2718 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2719 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2720 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2721 hash
=>$diffinfo->{'from_id'},
2722 file_name
=>$from{'file'});
2724 delete $from{'href'};
2728 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2729 if ($diffinfo->{'to_id'} ne ('0' x
40)) { # file exists in result
2730 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2731 hash
=>$diffinfo->{'to_id'},
2732 file_name
=>$to{'file'});
2736 # this is first patch for raw difftree line with $patch_idx index
2737 # we index @$difftree array from 0, but number patches from 1
2738 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2741 # print "git diff" header
2742 $patch_line = shift @diff_header;
2743 if ($diffinfo->{'nparents'}) {
2746 $patch_line =~ s!^(diff (.*?) )"?.*$!$1!;
2748 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2749 esc_path
($to{'file'}));
2750 } else { # file was deleted
2751 $patch_line .= esc_path
($to{'file'});
2756 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2757 if ($from{'href'}) {
2758 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2759 'a/' . esc_path
($from{'file'}));
2760 } else { # file was added
2761 $patch_line .= 'a/' . esc_path
($from{'file'});
2765 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2766 'b/' . esc_path
($to{'file'}));
2767 } else { # file was deleted
2768 $patch_line .= 'b/' . esc_path
($to{'file'});
2772 print "<div class=\"diff header\">$patch_line</div>\n";
2774 # print extended diff header
2775 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2777 foreach $patch_line (@diff_header) {
2779 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2780 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2781 esc_path
($from{'file'}));
2783 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2784 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2785 esc_path
($to{'file'}));
2787 # match single <mode>
2788 if ($patch_line =~ m/\s(\d{6})$/) {
2789 $patch_line .= '<span class="info"> (' .
2790 file_type_long
($1) .
2794 if ($patch_line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
2795 # can match only for combined diff
2796 $patch_line = 'index ';
2797 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2798 if ($from{'href'}[$i]) {
2799 $patch_line .= $cgi->a({-href
=>$from{'href'}[$i],
2801 substr($diffinfo->{'from_id'}[$i],0,7));
2803 $patch_line .= '0' x
7;
2806 $patch_line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
2808 $patch_line .= '..';
2810 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2811 substr($diffinfo->{'to_id'},0,7));
2813 $patch_line .= '0' x
7;
2816 } elsif ($patch_line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
2817 # can match only for ordinary diff
2818 my ($from_link, $to_link);
2819 if ($from{'href'}) {
2820 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2821 substr($diffinfo->{'from_id'},0,7));
2823 $from_link = '0' x
7;
2826 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2827 substr($diffinfo->{'to_id'},0,7));
2832 # my ($from_hash, $to_hash) =
2833 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2834 # my ($from_id, $to_id) =
2835 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2836 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2838 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2839 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2841 print $patch_line . "<br/>\n";
2843 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2845 # from-file/to-file diff header
2846 $patch_line = $last_patch_line;
2847 if (! $patch_line) {
2848 print "</div>\n"; # class="patch"
2851 next PATCH
if ($patch_line =~ m/^diff /);
2852 #assert($patch_line =~ m/^---/) if DEBUG;
2853 if (!$diffinfo->{'nparents'} && # not from-file line for combined diff
2854 $from{'href'} && $patch_line =~ m!^--- "?a/!) {
2855 $patch_line = '--- a/' .
2856 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2857 esc_path
($from{'file'}));
2859 print "<div class=\"diff from_file\">$patch_line</div>\n";
2861 $patch_line = <$fd>;
2864 #assert($patch_line =~ m/^+++/) if DEBUG;
2865 if ($to{'href'} && $patch_line =~ m!^\+\+\+ "?b/!) {
2866 $patch_line = '+++ b/' .
2867 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2868 esc_path
($to{'file'}));
2870 print "<div class=\"diff to_file\">$patch_line</div>\n";
2874 while ($patch_line = <$fd>) {
2877 next PATCH
if ($patch_line =~ m/^diff /);
2879 print format_diff_line
($patch_line, \
%from, \
%to);
2883 print "</div>\n"; # class="patch"
2886 if ($patch_number == 0) {
2887 if (@hash_parents > 1) {
2888 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
2890 print "<div class=\"diff nodifferences\">No differences found</div>\n";
2894 print "</div>\n"; # class="patchset"
2897 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2899 sub git_project_list_body
{
2900 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2902 my ($check_forks) = gitweb_check_feature
('forks');
2905 foreach my $pr (@$projlist) {
2906 my (@aa) = git_get_last_activity
($pr->{'path'});
2910 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2911 if (!defined $pr->{'descr'}) {
2912 my $descr = git_get_project_description
($pr->{'path'}) || "";
2913 $pr->{'descr_long'} = decode_utf8
($descr);
2914 $pr->{'descr'} = chop_str
($descr, 25, 5);
2916 if (!defined $pr->{'owner'}) {
2917 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2920 my $pname = $pr->{'path'};
2921 if (($pname =~ s/\.git$//) &&
2922 ($pname !~ /\/$/) &&
2923 (-d
"$projectroot/$pname")) {
2924 $pr->{'forks'} = "-d $projectroot/$pname";
2930 push @projects, $pr;
2933 $order ||= $default_projects_order;
2934 $from = 0 unless defined $from;
2935 $to = $#projects if (!defined $to || $#projects < $to);
2937 print "<table class=\"project_list\">\n";
2938 unless ($no_header) {
2941 print "<th></th>\n";
2943 if ($order eq "project") {
2944 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2945 print "<th>Project</th>\n";
2948 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2949 -class => "header"}, "Project") .
2952 if ($order eq "descr") {
2953 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2954 print "<th>Description</th>\n";
2957 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2958 -class => "header"}, "Description") .
2961 if ($order eq "owner") {
2962 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2963 print "<th>Owner</th>\n";
2966 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2967 -class => "header"}, "Owner") .
2970 if ($order eq "age") {
2971 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2972 print "<th>Last Change</th>\n";
2975 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2976 -class => "header"}, "Last Change") .
2979 print "<th></th>\n" .
2983 for (my $i = $from; $i <= $to; $i++) {
2984 my $pr = $projects[$i];
2986 print "<tr class=\"dark\">\n";
2988 print "<tr class=\"light\">\n";
2993 if ($pr->{'forks'}) {
2994 print "<!-- $pr->{'forks'} -->\n";
2995 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2999 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3000 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3001 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3002 -class => "list", -title
=> $pr->{'descr_long'}},
3003 esc_html
($pr->{'descr'})) . "</td>\n" .
3004 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
3005 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3006 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3007 "<td class=\"link\">" .
3008 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3009 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3010 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3011 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3012 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3016 if (defined $extra) {
3019 print "<td></td>\n";
3021 print "<td colspan=\"5\">$extra</td>\n" .
3027 sub git_shortlog_body
{
3028 # uses global variable $project
3029 my ($commitlist, $from, $to, $refs, $extra) = @_;
3031 my $have_snapshot = gitweb_have_snapshot
();
3033 $from = 0 unless defined $from;
3034 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3036 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3038 for (my $i = $from; $i <= $to; $i++) {
3039 my %co = %{$commitlist->[$i]};
3040 my $commit = $co{'id'};
3041 my $ref = format_ref_marker
($refs, $commit);
3043 print "<tr class=\"dark\">\n";
3045 print "<tr class=\"light\">\n";
3048 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3049 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3050 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3052 print format_subject_html
($co{'title'}, $co{'title_short'},
3053 href
(action
=>"commit", hash
=>$commit), $ref);
3055 "<td class=\"link\">" .
3056 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3057 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3058 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3059 if ($have_snapshot) {
3060 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
3065 if (defined $extra) {
3067 "<td colspan=\"4\">$extra</td>\n" .
3073 sub git_history_body
{
3074 # Warning: assumes constant type (blob or tree) during history
3075 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3077 $from = 0 unless defined $from;
3078 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3080 print "<table class=\"history\" cellspacing=\"0\">\n";
3082 for (my $i = $from; $i <= $to; $i++) {
3083 my %co = %{$commitlist->[$i]};
3087 my $commit = $co{'id'};
3089 my $ref = format_ref_marker
($refs, $commit);
3092 print "<tr class=\"dark\">\n";
3094 print "<tr class=\"light\">\n";
3097 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3098 # shortlog uses chop_str($co{'author_name'}, 10)
3099 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3101 # originally git_history used chop_str($co{'title'}, 50)
3102 print format_subject_html
($co{'title'}, $co{'title_short'},
3103 href
(action
=>"commit", hash
=>$commit), $ref);
3105 "<td class=\"link\">" .
3106 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3107 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3109 if ($ftype eq 'blob') {
3110 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3111 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3112 if (defined $blob_current && defined $blob_parent &&
3113 $blob_current ne $blob_parent) {
3115 $cgi->a({-href
=> href
(action
=>"blobdiff",
3116 hash
=>$blob_current, hash_parent
=>$blob_parent,
3117 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3118 file_name
=>$file_name)},
3125 if (defined $extra) {
3127 "<td colspan=\"4\">$extra</td>\n" .
3134 # uses global variable $project
3135 my ($taglist, $from, $to, $extra) = @_;
3136 $from = 0 unless defined $from;
3137 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3139 print "<table class=\"tags\" cellspacing=\"0\">\n";
3141 for (my $i = $from; $i <= $to; $i++) {
3142 my $entry = $taglist->[$i];
3144 my $comment = $tag{'subject'};
3146 if (defined $comment) {
3147 $comment_short = chop_str
($comment, 30, 5);
3150 print "<tr class=\"dark\">\n";
3152 print "<tr class=\"light\">\n";
3155 if (defined $tag{'age'}) {
3156 print "<td><i>$tag{'age'}</i></td>\n";
3158 print "<td></td>\n";
3161 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3162 -class => "list name"}, esc_html
($tag{'name'})) .
3165 if (defined $comment) {
3166 print format_subject_html
($comment, $comment_short,
3167 href
(action
=>"tag", hash
=>$tag{'id'}));
3170 "<td class=\"selflink\">";
3171 if ($tag{'type'} eq "tag") {
3172 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3177 "<td class=\"link\">" . " | " .
3178 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3179 if ($tag{'reftype'} eq "commit") {
3180 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3181 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3182 } elsif ($tag{'reftype'} eq "blob") {
3183 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3188 if (defined $extra) {
3190 "<td colspan=\"5\">$extra</td>\n" .
3196 sub git_heads_body
{
3197 # uses global variable $project
3198 my ($headlist, $head, $from, $to, $extra) = @_;
3199 $from = 0 unless defined $from;
3200 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3202 print "<table class=\"heads\" cellspacing=\"0\">\n";
3204 for (my $i = $from; $i <= $to; $i++) {
3205 my $entry = $headlist->[$i];
3207 my $curr = $ref{'id'} eq $head;
3209 print "<tr class=\"dark\">\n";
3211 print "<tr class=\"light\">\n";
3214 print "<td><i>$ref{'age'}</i></td>\n" .
3215 ($curr ? "<td class=\"current_head\">" : "<td>") .
3216 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3217 -class => "list name"},esc_html
($ref{'name'})) .
3219 "<td class=\"link\">" .
3220 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3221 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3222 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3226 if (defined $extra) {
3228 "<td colspan=\"3\">$extra</td>\n" .
3234 sub git_search_grep_body
{
3235 my ($commitlist, $from, $to, $extra) = @_;
3236 $from = 0 unless defined $from;
3237 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3239 print "<table class=\"grep\" cellspacing=\"0\">\n";
3241 for (my $i = $from; $i <= $to; $i++) {
3242 my %co = %{$commitlist->[$i]};
3246 my $commit = $co{'id'};
3248 print "<tr class=\"dark\">\n";
3250 print "<tr class=\"light\">\n";
3253 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3254 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3256 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3257 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3258 my $comment = $co{'comment'};
3259 foreach my $line (@$comment) {
3260 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3261 my $lead = esc_html
($1) || "";
3262 $lead = chop_str
($lead, 30, 10);
3263 my $match = esc_html
($2) || "";
3264 my $trail = esc_html
($3) || "";
3265 $trail = chop_str
($trail, 30, 10);
3266 my $text = "$lead<span class=\"match\">$match</span>$trail";
3267 print chop_str
($text, 80, 5) . "<br/>\n";
3271 "<td class=\"link\">" .
3272 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3274 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3278 if (defined $extra) {
3280 "<td colspan=\"3\">$extra</td>\n" .
3286 ## ======================================================================
3287 ## ======================================================================
3290 sub git_project_list
{
3291 my $order = $cgi->param('o');
3292 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3293 die_error
(undef, "Unknown order parameter");
3296 my @list = git_get_projects_list
();
3298 die_error
(undef, "No projects found");
3302 if (-f
$home_text) {
3303 print "<div class=\"index_include\">\n";
3304 open (my $fd, $home_text);
3309 git_project_list_body
(\
@list, $order);
3314 my $order = $cgi->param('o');
3315 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3316 die_error
(undef, "Unknown order parameter");
3319 my @list = git_get_projects_list
($project);
3321 die_error
(undef, "No forks found");
3325 git_print_page_nav
('','');
3326 git_print_header_div
('summary', "$project forks");
3327 git_project_list_body
(\
@list, $order);
3331 sub git_project_index
{
3332 my @projects = git_get_projects_list
($project);
3335 -type
=> 'text/plain',
3336 -charset
=> 'utf-8',
3337 -content_disposition
=> 'inline; filename="index.aux"');
3339 foreach my $pr (@projects) {
3340 if (!exists $pr->{'owner'}) {
3341 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3344 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3345 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3346 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3347 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3351 print "$path $owner\n";
3356 my $descr = git_get_project_description
($project) || "none";
3357 my %co = parse_commit
("HEAD");
3358 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3359 my $head = $co{'id'};
3361 my $owner = git_get_project_owner
($project);
3363 my $refs = git_get_references
();
3364 # These get_*_list functions return one more to allow us to see if
3365 # there are more ...
3366 my @taglist = git_get_tags_list
(16);
3367 my @headlist = git_get_heads_list
(16);
3369 my ($check_forks) = gitweb_check_feature
('forks');
3372 @forklist = git_get_projects_list
($project);
3376 git_print_page_nav
('summary','', $head);
3378 print "<div class=\"title\"> </div>\n";
3379 print "<table cellspacing=\"0\">\n" .
3380 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3381 "<tr><td>owner</td><td>$owner</td></tr>\n";
3382 if (defined $cd{'rfc2822'}) {
3383 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3386 # use per project git URL list in $projectroot/$project/cloneurl
3387 # or make project git URL from git base URL and project name
3388 my $url_tag = "URL";
3389 my @url_list = git_get_project_url_list
($project);
3390 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3391 foreach my $git_url (@url_list) {
3392 next unless $git_url;
3393 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3398 if (-s
"$projectroot/$project/README.html") {
3399 if (open my $fd, "$projectroot/$project/README.html") {
3400 print "<div class=\"title\">readme</div>\n";
3401 print $_ while (<$fd>);
3406 # we need to request one more than 16 (0..15) to check if
3408 my @commitlist = $head ? parse_commits
($head, 17) : ();
3410 git_print_header_div
('shortlog');
3411 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3412 $#commitlist <= 15 ? undef :
3413 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3417 git_print_header_div
('tags');
3418 git_tags_body
(\
@taglist, 0, 15,
3419 $#taglist <= 15 ? undef :
3420 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3424 git_print_header_div
('heads');
3425 git_heads_body
(\
@headlist, $head, 0, 15,
3426 $#headlist <= 15 ? undef :
3427 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3431 git_print_header_div
('forks');
3432 git_project_list_body
(\
@forklist, undef, 0, 15,
3433 $#forklist <= 15 ? undef :
3434 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3442 my $head = git_get_head_hash
($project);
3444 git_print_page_nav
('','', $head,undef,$head);
3445 my %tag = parse_tag
($hash);
3448 die_error
(undef, "Unknown tag object");
3451 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3452 print "<div class=\"title_text\">\n" .
3453 "<table cellspacing=\"0\">\n" .
3455 "<td>object</td>\n" .
3456 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3457 $tag{'object'}) . "</td>\n" .
3458 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3459 $tag{'type'}) . "</td>\n" .
3461 if (defined($tag{'author'})) {
3462 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3463 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3464 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3465 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3468 print "</table>\n\n" .
3470 print "<div class=\"page_body\">";
3471 my $comment = $tag{'comment'};
3472 foreach my $line (@$comment) {
3474 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3484 my ($have_blame) = gitweb_check_feature
('blame');
3486 die_error
('403 Permission denied', "Permission denied");
3488 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3489 $hash_base ||= git_get_head_hash
($project);
3490 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3491 my %co = parse_commit
($hash_base)
3492 or die_error
(undef, "Reading commit failed");
3493 if (!defined $hash) {
3494 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3495 or die_error
(undef, "Error looking up file");
3497 $ftype = git_get_type
($hash);
3498 if ($ftype !~ "blob") {
3499 die_error
('400 Bad Request', "Object is not a blob");
3501 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3502 $file_name, $hash_base)
3503 or die_error
(undef, "Open git-blame failed");
3506 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3509 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3512 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3514 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3515 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3516 git_print_page_path
($file_name, $ftype, $hash_base);
3517 my @rev_color = (qw(light2 dark2));
3518 my $num_colors = scalar(@rev_color);
3519 my $current_color = 0;
3522 <div class="page_body">
3523 <table class="blame">
3524 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3529 last unless defined $_;
3530 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3531 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3532 if (!exists $metainfo{$full_rev}) {
3533 $metainfo{$full_rev} = {};
3535 my $meta = $metainfo{$full_rev};
3538 if (/^(\S+) (.*)$/) {
3544 my $rev = substr($full_rev, 0, 8);
3545 my $author = $meta->{'author'};
3546 my %date = parse_date
($meta->{'author-time'},
3547 $meta->{'author-tz'});
3548 my $date = $date{'iso-tz'};
3550 $current_color = ++$current_color % $num_colors;
3552 print "<tr class=\"$rev_color[$current_color]\">\n";
3554 print "<td class=\"sha1\"";
3555 print " title=\"". esc_html
($author) . ", $date\"";
3556 print " rowspan=\"$group_size\"" if ($group_size > 1);
3558 print $cgi->a({-href
=> href
(action
=>"commit",
3560 file_name
=>$file_name)},
3564 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3565 or die_error
(undef, "Open git-rev-parse failed");
3566 my $parent_commit = <$dd>;
3568 chomp($parent_commit);
3569 my $blamed = href
(action
=> 'blame',
3570 file_name
=> $meta->{'filename'},
3571 hash_base
=> $parent_commit);
3572 print "<td class=\"linenr\">";
3573 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3575 -class => "linenr" },
3578 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3584 or print "Reading blob failed\n";
3591 my ($have_blame) = gitweb_check_feature
('blame');
3593 die_error
('403 Permission denied', "Permission denied");
3595 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3596 $hash_base ||= git_get_head_hash
($project);
3597 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3598 my %co = parse_commit
($hash_base)
3599 or die_error
(undef, "Reading commit failed");
3600 if (!defined $hash) {
3601 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3602 or die_error
(undef, "Error lookup file");
3604 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3605 or die_error
(undef, "Open git-annotate failed");
3608 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3611 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3614 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3616 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3617 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3618 git_print_page_path
($file_name, 'blob', $hash_base);
3619 print "<div class=\"page_body\">\n";
3621 <table class="blame">
3630 my @line_class = (qw(light dark));
3631 my $line_class_len = scalar (@line_class);
3632 my $line_class_num = $#line_class;
3633 while (my $line = <$fd>) {
3645 $line_class_num = ($line_class_num + 1) % $line_class_len;
3647 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3654 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3657 $short_rev = substr ($long_rev, 0, 8);
3658 $age = time () - $time;
3659 $age_str = age_string
($age);
3660 $age_str =~ s/ / /g;
3661 $age_class = age_class
($age);
3662 $author = esc_html
($author);
3663 $author =~ s/ / /g;
3665 $data = untabify
($data);
3666 $data = esc_html
($data);
3669 <tr class="$line_class[$line_class_num]">
3670 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3671 <td class="$age_class">$age_str</td>
3673 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3674 <td class="pre">$data</td>
3677 } # while (my $line = <$fd>)
3678 print "</table>\n\n";
3680 or print "Reading blob failed.\n";
3686 my $head = git_get_head_hash
($project);
3688 git_print_page_nav
('','', $head,undef,$head);
3689 git_print_header_div
('summary', $project);
3691 my @tagslist = git_get_tags_list
();
3693 git_tags_body
(\
@tagslist);
3699 my $head = git_get_head_hash
($project);
3701 git_print_page_nav
('','', $head,undef,$head);
3702 git_print_header_div
('summary', $project);
3704 my @headslist = git_get_heads_list
();
3706 git_heads_body
(\
@headslist, $head);
3711 sub git_blob_plain
{
3714 if (!defined $hash) {
3715 if (defined $file_name) {
3716 my $base = $hash_base || git_get_head_hash
($project);
3717 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3718 or die_error
(undef, "Error lookup file");
3720 die_error
(undef, "No file name defined");
3722 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3723 # blobs defined by non-textual hash id's can be cached
3728 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3729 or die_error
(undef, "Couldn't cat $file_name, $hash");
3731 $type ||= blob_mimetype
($fd, $file_name);
3733 # save as filename, even when no $file_name is given
3734 my $save_as = "$hash";
3735 if (defined $file_name) {
3736 $save_as = $file_name;
3737 } elsif ($type =~ m/^text\//) {
3744 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3746 binmode STDOUT
, ':raw';
3748 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3756 if (!defined $hash) {
3757 if (defined $file_name) {
3758 my $base = $hash_base || git_get_head_hash
($project);
3759 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3760 or die_error
(undef, "Error lookup file");
3762 die_error
(undef, "No file name defined");
3764 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3765 # blobs defined by non-textual hash id's can be cached
3769 my ($have_blame) = gitweb_check_feature
('blame');
3770 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3771 or die_error
(undef, "Couldn't cat $file_name, $hash");
3772 my $mimetype = blob_mimetype
($fd, $file_name);
3773 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3775 return git_blob_plain
($mimetype);
3777 # we can have blame only for text/* mimetype
3778 $have_blame &&= ($mimetype =~ m!^text/!);
3780 git_header_html
(undef, $expires);
3781 my $formats_nav = '';
3782 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3783 if (defined $file_name) {
3786 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3787 hash
=>$hash, file_name
=>$file_name)},
3792 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3793 hash
=>$hash, file_name
=>$file_name)},
3796 $cgi->a({-href
=> href
(action
=>"blob_plain",
3797 hash
=>$hash, file_name
=>$file_name)},
3800 $cgi->a({-href
=> href
(action
=>"blob",
3801 hash_base
=>"HEAD", file_name
=>$file_name)},
3805 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3807 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3808 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3810 print "<div class=\"page_nav\">\n" .
3811 "<br/><br/></div>\n" .
3812 "<div class=\"title\">$hash</div>\n";
3814 git_print_page_path
($file_name, "blob", $hash_base);
3815 print "<div class=\"page_body\">\n";
3816 if ($mimetype =~ m!^text/!) {
3818 while (my $line = <$fd>) {
3821 $line = untabify
($line);
3822 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3823 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3825 } elsif ($mimetype =~ m!^image/!) {
3826 print qq
!<img type
="$mimetype"!;
3828 print qq
! alt
="$file_name" title
="$file_name"!;
3831 href(action=>"blob_plain
", hash=>$hash,
3832 hash_base=>$hash_base, file_name=>$file_name) .
3836 or print "Reading blob failed.\n";
3842 my $have_snapshot = gitweb_have_snapshot
();
3844 if (!defined $hash_base) {
3845 $hash_base = "HEAD";
3847 if (!defined $hash) {
3848 if (defined $file_name) {
3849 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3855 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3856 or die_error
(undef, "Open git-ls-tree failed");
3857 my @entries = map { chomp; $_ } <$fd>;
3858 close $fd or die_error
(undef, "Reading tree failed");
3861 my $refs = git_get_references
();
3862 my $ref = format_ref_marker
($refs, $hash_base);
3865 my ($have_blame) = gitweb_check_feature
('blame');
3866 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3868 if (defined $file_name) {
3870 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3871 hash
=>$hash, file_name
=>$file_name)},
3873 $cgi->a({-href
=> href
(action
=>"tree",
3874 hash_base
=>"HEAD", file_name
=>$file_name)},
3877 if ($have_snapshot) {
3878 # FIXME: Should be available when we have no hash base as well.
3880 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3883 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3884 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3887 print "<div class=\"page_nav\">\n";
3888 print "<br/><br/></div>\n";
3889 print "<div class=\"title\">$hash</div>\n";
3891 if (defined $file_name) {
3892 $basedir = $file_name;
3893 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3897 git_print_page_path
($file_name, 'tree', $hash_base);
3898 print "<div class=\"page_body\">\n";
3899 print "<table cellspacing=\"0\">\n";
3901 # '..' (top directory) link if possible
3902 if (defined $hash_base &&
3903 defined $file_name && $file_name =~ m![^/]+$!) {
3905 print "<tr class=\"dark\">\n";
3907 print "<tr class=\"light\">\n";
3911 my $up = $file_name;
3912 $up =~ s!/?[^/]+$!!;
3913 undef $up unless $up;
3914 # based on git_print_tree_entry
3915 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3916 print '<td class="list">';
3917 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3921 print "<td class=\"link\"></td>\n";
3925 foreach my $line (@entries) {
3926 my %t = parse_ls_tree_line
($line, -z
=> 1);
3929 print "<tr class=\"dark\">\n";
3931 print "<tr class=\"light\">\n";
3935 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3939 print "</table>\n" .
3945 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3946 my $have_snapshot = (defined $ctype && defined $suffix);
3947 if (!$have_snapshot) {
3948 die_error
('403 Permission denied', "Permission denied");
3951 if (!defined $hash) {
3952 $hash = git_get_head_hash
($project);
3955 my $filename = decode_utf8
(basename
($project)) . "-$hash.tar.$suffix";
3958 -type
=> "application/$ctype",
3959 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3960 -status
=> '200 OK');
3962 my $git = git_cmd_str
();
3963 my $name = $project;
3964 $name =~ s/\047/\047\\\047\047/g;
3966 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3967 or die_error
(undef, "Execute git-tar-tree failed");
3968 binmode STDOUT
, ':raw';
3970 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3976 my $head = git_get_head_hash
($project);
3977 if (!defined $hash) {
3980 if (!defined $page) {
3983 my $refs = git_get_references
();
3985 my @commitlist = parse_commits
($hash, 101, (100 * $page));
3987 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
3990 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3993 my %co = parse_commit
($hash);
3995 git_print_header_div
('summary', $project);
3996 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3998 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
3999 for (my $i = 0; $i <= $to; $i++) {
4000 my %co = %{$commitlist[$i]};
4002 my $commit = $co{'id'};
4003 my $ref = format_ref_marker
($refs, $commit);
4004 my %ad = parse_date
($co{'author_epoch'});
4005 git_print_header_div
('commit',
4006 "<span class=\"age\">$co{'age_string'}</span>" .
4007 esc_html
($co{'title'}) . $ref,
4009 print "<div class=\"title_text\">\n" .
4010 "<div class=\"log_link\">\n" .
4011 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4013 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4015 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4018 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4021 print "<div class=\"log_body\">\n";
4022 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4025 if ($#commitlist >= 100) {
4026 print "<div class=\"page_nav\">\n";
4027 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4028 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4035 $hash ||= $hash_base || "HEAD";
4036 my %co = parse_commit
($hash);
4038 die_error
(undef, "Unknown commit object");
4040 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4041 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4043 my $parent = $co{'parent'};
4044 my $parents = $co{'parents'}; # listref
4046 # we need to prepare $formats_nav before any parameter munging
4048 if (!defined $parent) {
4050 $formats_nav .= '(initial)';
4051 } elsif (@$parents == 1) {
4052 # single parent commit
4055 $cgi->a({-href
=> href
(action
=>"commit",
4057 esc_html
(substr($parent, 0, 7))) .
4064 $cgi->a({-href
=> href
(action
=>"commit",
4066 esc_html
(substr($_, 0, 7)));
4071 if (!defined $parent) {
4075 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4077 (@$parents <= 1 ? $parent : '-c'),
4079 or die_error
(undef, "Open git-diff-tree failed");
4080 @difftree = map { chomp; $_ } <$fd>;
4081 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4083 # non-textual hash id's can be cached
4085 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4088 my $refs = git_get_references
();
4089 my $ref = format_ref_marker
($refs, $co{'id'});
4091 my $have_snapshot = gitweb_have_snapshot
();
4093 git_header_html
(undef, $expires);
4094 git_print_page_nav
('commit', '',
4095 $hash, $co{'tree'}, $hash,
4098 if (defined $co{'parent'}) {
4099 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4101 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4103 print "<div class=\"title_text\">\n" .
4104 "<table cellspacing=\"0\">\n";
4105 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4107 "<td></td><td> $ad{'rfc2822'}";
4108 if ($ad{'hour_local'} < 6) {
4109 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4110 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4112 printf(" (%02d:%02d %s)",
4113 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4117 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4118 print "<tr><td></td><td> $cd{'rfc2822'}" .
4119 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4121 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4124 "<td class=\"sha1\">" .
4125 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4126 class => "list"}, $co{'tree'}) .
4128 "<td class=\"link\">" .
4129 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4131 if ($have_snapshot) {
4133 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
4138 foreach my $par (@$parents) {
4141 "<td class=\"sha1\">" .
4142 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4143 class => "list"}, $par) .
4145 "<td class=\"link\">" .
4146 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4148 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4155 print "<div class=\"page_body\">\n";
4156 git_print_log
($co{'comment'});
4159 git_difftree_body
(\
@difftree, $hash, @$parents);
4165 # object is defined by:
4166 # - hash or hash_base alone
4167 # - hash_base and file_name
4170 # - hash or hash_base alone
4171 if ($hash || ($hash_base && !defined $file_name)) {
4172 my $object_id = $hash || $hash_base;
4174 my $git_command = git_cmd_str
();
4175 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4176 or die_error
('404 Not Found', "Object does not exist");
4180 or die_error
('404 Not Found', "Object does not exist");
4182 # - hash_base and file_name
4183 } elsif ($hash_base && defined $file_name) {
4184 $file_name =~ s
,/+$,,;
4186 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4187 or die_error
('404 Not Found', "Base object does not exist");
4189 # here errors should not hapen
4190 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4191 or die_error
(undef, "Open git-ls-tree failed");
4195 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4196 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4197 die_error
('404 Not Found', "File or directory for given base does not exist");
4202 die_error
('404 Not Found', "Not enough information to find object");
4205 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4206 hash
=>$hash, hash_base
=>$hash_base,
4207 file_name
=>$file_name),
4208 -status
=> '302 Found');
4212 my $format = shift || 'html';
4219 # preparing $fd and %diffinfo for git_patchset_body
4221 if (defined $hash_base && defined $hash_parent_base) {
4222 if (defined $file_name) {
4224 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4225 $hash_parent_base, $hash_base,
4226 "--", (defined $file_parent ? $file_parent : ()), $file_name
4227 or die_error
(undef, "Open git-diff-tree failed");
4228 @difftree = map { chomp; $_ } <$fd>;
4230 or die_error
(undef, "Reading git-diff-tree failed");
4232 or die_error
('404 Not Found', "Blob diff not found");
4234 } elsif (defined $hash &&
4235 $hash =~ /[0-9a-fA-F]{40}/) {
4236 # try to find filename from $hash
4238 # read filtered raw output
4239 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4240 $hash_parent_base, $hash_base, "--"
4241 or die_error
(undef, "Open git-diff-tree failed");
4243 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4245 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4246 map { chomp; $_ } <$fd>;
4248 or die_error
(undef, "Reading git-diff-tree failed");
4250 or die_error
('404 Not Found', "Blob diff not found");
4253 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4256 if (@difftree > 1) {
4257 die_error
('404 Not Found', "Ambiguous blob diff specification");
4260 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4261 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4262 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4264 $hash_parent ||= $diffinfo{'from_id'};
4265 $hash ||= $diffinfo{'to_id'};
4267 # non-textual hash id's can be cached
4268 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4269 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4274 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4275 '-p', ($format eq 'html' ? "--full-index" : ()),
4276 $hash_parent_base, $hash_base,
4277 "--", (defined $file_parent ? $file_parent : ()), $file_name
4278 or die_error
(undef, "Open git-diff-tree failed");
4281 # old/legacy style URI
4282 if (!%diffinfo && # if new style URI failed
4283 defined $hash && defined $hash_parent) {
4284 # fake git-diff-tree raw output
4285 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4286 $diffinfo{'from_id'} = $hash_parent;
4287 $diffinfo{'to_id'} = $hash;
4288 if (defined $file_name) {
4289 if (defined $file_parent) {
4290 $diffinfo{'status'} = '2';
4291 $diffinfo{'from_file'} = $file_parent;
4292 $diffinfo{'to_file'} = $file_name;
4293 } else { # assume not renamed
4294 $diffinfo{'status'} = '1';
4295 $diffinfo{'from_file'} = $file_name;
4296 $diffinfo{'to_file'} = $file_name;
4298 } else { # no filename given
4299 $diffinfo{'status'} = '2';
4300 $diffinfo{'from_file'} = $hash_parent;
4301 $diffinfo{'to_file'} = $hash;
4304 # non-textual hash id's can be cached
4305 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4306 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4311 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4312 '-p', ($format eq 'html' ? "--full-index" : ()),
4313 $hash_parent, $hash, "--"
4314 or die_error
(undef, "Open git-diff failed");
4316 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4321 if ($format eq 'html') {
4323 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4324 hash
=>$hash, hash_parent
=>$hash_parent,
4325 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4326 file_name
=>$file_name, file_parent
=>$file_parent)},
4328 git_header_html
(undef, $expires);
4329 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4330 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4331 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4333 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4334 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4336 if (defined $file_name) {
4337 git_print_page_path
($file_name, "blob", $hash_base);
4339 print "<div class=\"page_path\"></div>\n";
4342 } elsif ($format eq 'plain') {
4344 -type
=> 'text/plain',
4345 -charset
=> 'utf-8',
4346 -expires
=> $expires,
4347 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4349 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4352 die_error
(undef, "Unknown blobdiff format");
4356 if ($format eq 'html') {
4357 print "<div class=\"page_body\">\n";
4359 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4362 print "</div>\n"; # class="page_body"
4366 while (my $line = <$fd>) {
4367 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4368 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4372 last if $line =~ m!^\+\+\+!;
4380 sub git_blobdiff_plain
{
4381 git_blobdiff
('plain');
4384 sub git_commitdiff
{
4385 my $format = shift || 'html';
4386 $hash ||= $hash_base || "HEAD";
4387 my %co = parse_commit
($hash);
4389 die_error
(undef, "Unknown commit object");
4392 # we need to prepare $formats_nav before any parameter munging
4394 if ($format eq 'html') {
4396 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4397 hash
=>$hash, hash_parent
=>$hash_parent)},
4400 if (defined $hash_parent) {
4401 # commitdiff with two commits given
4402 my $hash_parent_short = $hash_parent;
4403 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4404 $hash_parent_short = substr($hash_parent, 0, 7);
4408 $cgi->a({-href
=> href
(action
=>"commitdiff",
4409 hash
=>$hash_parent)},
4410 esc_html
($hash_parent_short)) .
4412 } elsif (!$co{'parent'}) {
4414 $formats_nav .= ' (initial)';
4415 } elsif (scalar @{$co{'parents'}} == 1) {
4416 # single parent commit
4419 $cgi->a({-href
=> href
(action
=>"commitdiff",
4420 hash
=>$co{'parent'})},
4421 esc_html
(substr($co{'parent'}, 0, 7))) .
4428 $cgi->a({-href
=> href
(action
=>"commitdiff",
4430 esc_html
(substr($_, 0, 7)));
4431 } @{$co{'parents'}} ) .
4436 my $hash_parent_param = $hash_parent;
4437 if (!defined $hash_parent) {
4438 $hash_parent_param =
4439 @{$co{'parents'}} > 1 ? '-c' : $co{'parent'} || '--root';
4445 if ($format eq 'html') {
4446 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4447 "--no-commit-id", "--patch-with-raw", "--full-index",
4448 $hash_parent_param, $hash, "--"
4449 or die_error
(undef, "Open git-diff-tree failed");
4451 while (my $line = <$fd>) {
4453 # empty line ends raw part of diff-tree output
4455 push @difftree, scalar parse_difftree_raw_line
($line);
4458 } elsif ($format eq 'plain') {
4459 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4460 '-p', $hash_parent_param, $hash, "--"
4461 or die_error
(undef, "Open git-diff-tree failed");
4464 die_error
(undef, "Unknown commitdiff format");
4467 # non-textual hash id's can be cached
4469 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4473 # write commit message
4474 if ($format eq 'html') {
4475 my $refs = git_get_references
();
4476 my $ref = format_ref_marker
($refs, $co{'id'});
4478 git_header_html
(undef, $expires);
4479 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4480 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4481 git_print_authorship
(\
%co);
4482 print "<div class=\"page_body\">\n";
4483 if (@{$co{'comment'}} > 1) {
4484 print "<div class=\"log\">\n";
4485 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4486 print "</div>\n"; # class="log"
4489 } elsif ($format eq 'plain') {
4490 my $refs = git_get_references
("tags");
4491 my $tagname = git_get_rev_name_tags
($hash);
4492 my $filename = basename
($project) . "-$hash.patch";
4495 -type
=> 'text/plain',
4496 -charset
=> 'utf-8',
4497 -expires
=> $expires,
4498 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4499 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4502 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4503 Subject: $co{'title'}
4505 print "X-Git-Tag: $tagname\n" if $tagname;
4506 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4508 foreach my $line (@{$co{'comment'}}) {
4515 if ($format eq 'html') {
4516 git_difftree_body
(\
@difftree, $hash, $hash_parent || @{$co{'parents'}});
4519 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent || @{$co{'parents'}});
4521 print "</div>\n"; # class="page_body"
4524 } elsif ($format eq 'plain') {
4528 or print "Reading git-diff-tree failed\n";
4532 sub git_commitdiff_plain
{
4533 git_commitdiff
('plain');
4537 if (!defined $hash_base) {
4538 $hash_base = git_get_head_hash
($project);
4540 if (!defined $page) {
4544 my %co = parse_commit
($hash_base);
4546 die_error
(undef, "Unknown commit object");
4549 my $refs = git_get_references
();
4550 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4552 if (!defined $hash && defined $file_name) {
4553 $hash = git_get_hash_by_path
($hash_base, $file_name);
4555 if (defined $hash) {
4556 $ftype = git_get_type
($hash);
4559 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4561 my $paging_nav = '';
4564 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4565 file_name
=>$file_name)},
4567 $paging_nav .= " ⋅ " .
4568 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4569 file_name
=>$file_name, page
=>$page-1),
4570 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4572 $paging_nav .= "first";
4573 $paging_nav .= " ⋅ prev";
4575 if ($#commitlist >= 100) {
4576 $paging_nav .= " ⋅ " .
4577 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4578 file_name
=>$file_name, page
=>$page+1),
4579 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4581 $paging_nav .= " ⋅ next";
4584 if ($#commitlist >= 100) {
4586 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4587 file_name
=>$file_name, page
=>$page+1),
4588 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4592 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4593 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4594 git_print_page_path
($file_name, $ftype, $hash_base);
4596 git_history_body
(\
@commitlist, 0, 99,
4597 $refs, $hash_base, $ftype, $next_link);
4603 my ($have_search) = gitweb_check_feature
('search');
4604 if (!$have_search) {
4605 die_error
('403 Permission denied', "Permission denied");
4607 if (!defined $searchtext) {
4608 die_error
(undef, "Text field empty");
4610 if (!defined $hash) {
4611 $hash = git_get_head_hash
($project);
4613 my %co = parse_commit
($hash);
4615 die_error
(undef, "Unknown commit object");
4617 if (!defined $page) {
4621 $searchtype ||= 'commit';
4622 if ($searchtype eq 'pickaxe') {
4623 # pickaxe may take all resources of your box and run for several minutes
4624 # with every query - so decide by yourself how public you make this feature
4625 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4626 if (!$have_pickaxe) {
4627 die_error
('403 Permission denied', "Permission denied");
4633 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4635 if ($searchtype eq 'commit') {
4636 $greptype = "--grep=";
4637 } elsif ($searchtype eq 'author') {
4638 $greptype = "--author=";
4639 } elsif ($searchtype eq 'committer') {
4640 $greptype = "--committer=";
4642 $greptype .= $search_regexp;
4643 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4645 my $paging_nav = '';
4648 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4649 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4651 $paging_nav .= " ⋅ " .
4652 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4653 searchtext
=>$searchtext, searchtype
=>$searchtype,
4655 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4657 $paging_nav .= "first";
4658 $paging_nav .= " ⋅ prev";
4660 if ($#commitlist >= 100) {
4661 $paging_nav .= " ⋅ " .
4662 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4663 searchtext
=>$searchtext, searchtype
=>$searchtype,
4665 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4667 $paging_nav .= " ⋅ next";
4670 if ($#commitlist >= 100) {
4672 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4673 searchtext
=>$searchtext, searchtype
=>$searchtype,
4675 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4678 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4679 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4680 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4683 if ($searchtype eq 'pickaxe') {
4684 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4685 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4687 print "<table cellspacing=\"0\">\n";
4690 my $git_command = git_cmd_str
();
4691 open my $fd, "-|", "$git_command rev-list $hash | " .
4692 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
4695 while (my $line = <$fd>) {
4696 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4699 $set{'from_id'} = $3;
4701 $set{'id'} = $set{'to_id'};
4702 if ($set{'id'} =~ m/0{40}/) {
4703 $set{'id'} = $set{'from_id'};
4705 if ($set{'id'} =~ m/0{40}/) {
4709 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4712 print "<tr class=\"dark\">\n";
4714 print "<tr class=\"light\">\n";
4717 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4718 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4720 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4721 -class => "list subject"},
4722 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4723 while (my $setref = shift @files) {
4725 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4726 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4728 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4732 "<td class=\"link\">" .
4733 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4735 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4739 %co = parse_commit
($1);
4749 sub git_search_help
{
4751 git_print_page_nav
('','', $hash,$hash,$hash);
4754 <dt><b>commit</b></dt>
4755 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4756 <dt><b>author</b></dt>
4757 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4758 <dt><b>committer</b></dt>
4759 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4761 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4762 if ($have_pickaxe) {
4764 <dt><b>pickaxe</b></dt>
4765 <dd>All commits that caused the string to appear or disappear from any file (changes that
4766 added, removed or "modified" the string) will be listed. This search can take a while and
4767 takes a lot of strain on the server, so please use it wisely.</dd>
4775 my $head = git_get_head_hash
($project);
4776 if (!defined $hash) {
4779 if (!defined $page) {
4782 my $refs = git_get_references
();
4784 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4786 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
4788 if ($#commitlist >= 100) {
4790 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4791 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4795 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4796 git_print_header_div
('summary', $project);
4798 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
4803 ## ......................................................................
4804 ## feeds (RSS, Atom; OPML)
4807 my $format = shift || 'atom';
4808 my ($have_blame) = gitweb_check_feature
('blame');
4810 # Atom: http://www.atomenabled.org/developers/syndication/
4811 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4812 if ($format ne 'rss' && $format ne 'atom') {
4813 die_error
(undef, "Unknown web feed format");
4816 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4817 my $head = $hash || 'HEAD';
4818 my @commitlist = parse_commits
($head, 150);
4822 my $content_type = "application/$format+xml";
4823 if (defined $cgi->http('HTTP_ACCEPT') &&
4824 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4825 # browser (feed reader) prefers text/xml
4826 $content_type = 'text/xml';
4828 if (defined($commitlist[0])) {
4829 %latest_commit = %{$commitlist[0]};
4830 %latest_date = parse_date
($latest_commit{'author_epoch'});
4832 -type
=> $content_type,
4833 -charset
=> 'utf-8',
4834 -last_modified
=> $latest_date{'rfc2822'});
4837 -type
=> $content_type,
4838 -charset
=> 'utf-8');
4841 # Optimization: skip generating the body if client asks only
4842 # for Last-Modified date.
4843 return if ($cgi->request_method() eq 'HEAD');
4846 my $title = "$site_name - $project/$action";
4847 my $feed_type = 'log';
4848 if (defined $hash) {
4849 $title .= " - '$hash'";
4850 $feed_type = 'branch log';
4851 if (defined $file_name) {
4852 $title .= " :: $file_name";
4853 $feed_type = 'history';
4855 } elsif (defined $file_name) {
4856 $title .= " - $file_name";
4857 $feed_type = 'history';
4859 $title .= " $feed_type";
4860 my $descr = git_get_project_description
($project);
4861 if (defined $descr) {
4862 $descr = esc_html
($descr);
4864 $descr = "$project " .
4865 ($format eq 'rss' ? 'RSS' : 'Atom') .
4868 my $owner = git_get_project_owner
($project);
4869 $owner = esc_html
($owner);
4873 if (defined $file_name) {
4874 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
4875 } elsif (defined $hash) {
4876 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
4878 $alt_url = href
(-full
=>1, action
=>"summary");
4880 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
4881 if ($format eq 'rss') {
4883 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
4886 print "<title>$title</title>\n" .
4887 "<link>$alt_url</link>\n" .
4888 "<description>$descr</description>\n" .
4889 "<language>en</language>\n";
4890 } elsif ($format eq 'atom') {
4892 <feed xmlns="http://www.w3.org/2005/Atom">
4894 print "<title>$title</title>\n" .
4895 "<subtitle>$descr</subtitle>\n" .
4896 '<link rel="alternate" type="text/html" href="' .
4897 $alt_url . '" />' . "\n" .
4898 '<link rel="self" type="' . $content_type . '" href="' .
4899 $cgi->self_url() . '" />' . "\n" .
4900 "<id>" . href
(-full
=>1) . "</id>\n" .
4901 # use project owner for feed author
4902 "<author><name>$owner</name></author>\n";
4903 if (defined $favicon) {
4904 print "<icon>" . esc_url
($favicon) . "</icon>\n";
4906 if (defined $logo_url) {
4907 # not twice as wide as tall: 72 x 27 pixels
4908 print "<logo>" . esc_url
($logo) . "</logo>\n";
4910 if (! %latest_date) {
4911 # dummy date to keep the feed valid until commits trickle in:
4912 print "<updated>1970-01-01T00:00:00Z</updated>\n";
4914 print "<updated>$latest_date{'iso-8601'}</updated>\n";
4919 for (my $i = 0; $i <= $#commitlist; $i++) {
4920 my %co = %{$commitlist[$i]};
4921 my $commit = $co{'id'};
4922 # we read 150, we always show 30 and the ones more recent than 48 hours
4923 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
4926 my %cd = parse_date
($co{'author_epoch'});
4928 # get list of changed files
4929 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4930 $co{'parent'}, $co{'id'}, "--", (defined $file_name ? $file_name : ())
4932 my @difftree = map { chomp; $_ } <$fd>;
4936 # print element (entry, item)
4937 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
4938 if ($format eq 'rss') {
4940 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
4941 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
4942 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
4943 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
4944 "<link>$co_url</link>\n" .
4945 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
4946 "<content:encoded>" .
4948 } elsif ($format eq 'atom') {
4950 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
4951 "<updated>$cd{'iso-8601'}</updated>\n" .
4953 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
4954 if ($co{'author_email'}) {
4955 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
4957 print "</author>\n" .
4958 # use committer for contributor
4960 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
4961 if ($co{'committer_email'}) {
4962 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
4964 print "</contributor>\n" .
4965 "<published>$cd{'iso-8601'}</published>\n" .
4966 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
4967 "<id>$co_url</id>\n" .
4968 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
4969 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
4971 my $comment = $co{'comment'};
4973 foreach my $line (@$comment) {
4974 $line = esc_html
($line);
4977 print "</pre><ul>\n";
4978 foreach my $difftree_line (@difftree) {
4979 my %difftree = parse_difftree_raw_line
($difftree_line);
4980 next if !$difftree{'from_id'};
4982 my $file = $difftree{'file'} || $difftree{'to_file'};
4986 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
4987 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
4988 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
4989 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
4990 -title
=> "diff"}, 'D');
4992 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
4993 file_name
=>$file, hash_base
=>$commit),
4994 -title
=> "blame"}, 'B');
4996 # if this is not a feed of a file history
4997 if (!defined $file_name || $file_name ne $file) {
4998 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
4999 file_name
=>$file, hash
=>$commit),
5000 -title
=> "history"}, 'H');
5002 $file = esc_path
($file);
5006 if ($format eq 'rss') {
5007 print "</ul>]]>\n" .
5008 "</content:encoded>\n" .
5010 } elsif ($format eq 'atom') {
5011 print "</ul>\n</div>\n" .
5018 if ($format eq 'rss') {
5019 print "</channel>\n</rss>\n";
5020 } elsif ($format eq 'atom') {
5034 my @list = git_get_projects_list
();
5036 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5038 <?xml version="1.0" encoding="utf-8"?>
5039 <opml version="1.0">
5041 <title>$site_name OPML Export</title>
5044 <outline text="git RSS feeds">
5047 foreach my $pr (@list) {
5049 my $head = git_get_head_hash
($proj{'path'});
5050 if (!defined $head) {
5053 $git_dir = "$projectroot/$proj{'path'}";
5054 my %co = parse_commit
($head);
5059 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5060 my $rss = "$my_url?p=$proj{'path'};a=rss";
5061 my $html = "$my_url?p=$proj{'path'};a=summary";
5062 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";