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 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
112 # Enable the 'blame' blob view, showing the last commit that modified
113 # each line in the file. This can be very CPU-intensive.
115 # To enable system wide have in $GITWEB_CONFIG
116 # $feature{'blame'}{'default'} = [1];
117 # To have project specific config enable override in $GITWEB_CONFIG
118 # $feature{'blame'}{'override'} = 1;
119 # and in project config gitweb.blame = 0|1;
121 'sub' => \
&feature_blame
,
125 # Enable the 'snapshot' link, providing a compressed tarball of any
126 # tree. This can potentially generate high traffic if you have large
129 # To disable system wide have in $GITWEB_CONFIG
130 # $feature{'snapshot'}{'default'} = [undef];
131 # To have project specific config enable override in $GITWEB_CONFIG
132 # $feature{'snapshot'}{'override'} = 1;
133 # and in project config gitweb.snapshot = none|gzip|bzip2;
135 'sub' => \
&feature_snapshot
,
137 # => [content-encoding, suffix, program]
138 'default' => ['x-gzip', 'gz', 'gzip']},
140 # Enable text search, which will list the commits which match author,
141 # committer or commit text to a given string. Enabled by default.
146 # Enable the pickaxe search, which will list the commits that modified
147 # a given string in a file. This can be practical and quite faster
148 # alternative to 'blame', but still potentially CPU-intensive.
150 # To enable system wide have in $GITWEB_CONFIG
151 # $feature{'pickaxe'}{'default'} = [1];
152 # To have project specific config enable override in $GITWEB_CONFIG
153 # $feature{'pickaxe'}{'override'} = 1;
154 # and in project config gitweb.pickaxe = 0|1;
156 'sub' => \
&feature_pickaxe
,
160 # Make gitweb use an alternative format of the URLs which can be
161 # more readable and natural-looking: project name is embedded
162 # directly in the path and the query string contains other
163 # auxiliary information. All gitweb installations recognize
164 # URL in either format; this configures in which formats gitweb
167 # To enable system wide have in $GITWEB_CONFIG
168 # $feature{'pathinfo'}{'default'} = [1];
169 # Project specific override is not supported.
171 # Note that you will need to change the default location of CSS,
172 # favicon, logo and possibly other files to an absolute URL. Also,
173 # if gitweb.cgi serves as your indexfile, you will need to force
174 # $my_uri to contain the script name in your $GITWEB_CONFIG.
179 # Make gitweb consider projects in project root subdirectories
180 # to be forks of existing projects. Given project $projname.git,
181 # projects matching $projname/*.git will not be shown in the main
182 # projects list, instead a '+' mark will be added to $projname
183 # there and a 'forks' view will be enabled for the project, listing
184 # all the forks. If project list is taken from a file, forks have
185 # to be listed after the main project.
187 # To enable system wide have in $GITWEB_CONFIG
188 # $feature{'forks'}{'default'} = [1];
189 # Project specific override is not supported.
195 sub gitweb_check_feature
{
197 return unless exists $feature{$name};
198 my ($sub, $override, @defaults) = (
199 $feature{$name}{'sub'},
200 $feature{$name}{'override'},
201 @{$feature{$name}{'default'}});
202 if (!$override) { return @defaults; }
204 warn "feature $name is not overrideable";
207 return $sub->(@defaults);
211 my ($val) = git_get_project_config
('blame', '--bool');
213 if ($val eq 'true') {
215 } elsif ($val eq 'false') {
222 sub feature_snapshot
{
223 my ($ctype, $suffix, $command) = @_;
225 my ($val) = git_get_project_config
('snapshot');
227 if ($val eq 'gzip') {
228 return ('x-gzip', 'gz', 'gzip');
229 } elsif ($val eq 'bzip2') {
230 return ('x-bzip2', 'bz2', 'bzip2');
231 } elsif ($val eq 'none') {
235 return ($ctype, $suffix, $command);
238 sub gitweb_have_snapshot
{
239 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
240 my $have_snapshot = (defined $ctype && defined $suffix);
242 return $have_snapshot;
245 sub feature_pickaxe
{
246 my ($val) = git_get_project_config
('pickaxe', '--bool');
248 if ($val eq 'true') {
250 } elsif ($val eq 'false') {
257 # checking HEAD file with -e is fragile if the repository was
258 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
260 sub check_head_link
{
262 my $headfile = "$dir/HEAD";
263 return ((-e
$headfile) ||
264 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
267 sub check_export_ok
{
269 return (check_head_link
($dir) &&
270 (!$export_ok || -e
"$dir/$export_ok"));
273 # rename detection options for git-diff and git-diff-tree
274 # - default is '-M', with the cost proportional to
275 # (number of removed files) * (number of new files).
276 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
277 # (number of changed files + number of removed files) * (number of new files)
278 # - even more costly is '-C', '--find-copies-harder' with cost
279 # (number of files in the original tree) * (number of new files)
280 # - one might want to include '-B' option, e.g. '-B', '-M'
281 our @diff_opts = ('-M'); # taken from git_commit
283 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
284 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
286 # version of the core git binary
287 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
289 $projects_list ||= $projectroot;
291 # ======================================================================
292 # input validation and dispatch
293 our $action = $cgi->param('a');
294 if (defined $action) {
295 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
296 die_error
(undef, "Invalid action parameter");
300 # parameters which are pathnames
301 our $project = $cgi->param('p');
302 if (defined $project) {
303 if (!validate_pathname
($project) ||
304 !(-d
"$projectroot/$project") ||
305 !check_head_link
("$projectroot/$project") ||
306 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
307 ($strict_export && !project_in_list
($project))) {
309 die_error
(undef, "No such project");
313 our $file_name = $cgi->param('f');
314 if (defined $file_name) {
315 if (!validate_pathname
($file_name)) {
316 die_error
(undef, "Invalid file parameter");
320 our $file_parent = $cgi->param('fp');
321 if (defined $file_parent) {
322 if (!validate_pathname
($file_parent)) {
323 die_error
(undef, "Invalid file parent parameter");
327 # parameters which are refnames
328 our $hash = $cgi->param('h');
330 if (!validate_refname
($hash)) {
331 die_error
(undef, "Invalid hash parameter");
335 our $hash_parent = $cgi->param('hp');
336 if (defined $hash_parent) {
337 if (!validate_refname
($hash_parent)) {
338 die_error
(undef, "Invalid hash parent parameter");
342 our $hash_base = $cgi->param('hb');
343 if (defined $hash_base) {
344 if (!validate_refname
($hash_base)) {
345 die_error
(undef, "Invalid hash base parameter");
349 our $hash_parent_base = $cgi->param('hpb');
350 if (defined $hash_parent_base) {
351 if (!validate_refname
($hash_parent_base)) {
352 die_error
(undef, "Invalid hash parent base parameter");
357 our $page = $cgi->param('pg');
359 if ($page =~ m/[^0-9]/) {
360 die_error
(undef, "Invalid page parameter");
364 our $searchtext = $cgi->param('s');
365 if (defined $searchtext) {
366 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
367 die_error
(undef, "Invalid search parameter");
369 if (length($searchtext) < 2) {
370 die_error
(undef, "At least two characters are required for search parameter");
372 $searchtext = quotemeta $searchtext;
375 our $searchtype = $cgi->param('st');
376 if (defined $searchtype) {
377 if ($searchtype =~ m/[^a-z]/) {
378 die_error
(undef, "Invalid searchtype parameter");
382 # now read PATH_INFO and use it as alternative to parameters
383 sub evaluate_path_info
{
384 return if defined $project;
385 my $path_info = $ENV{"PATH_INFO"};
386 return if !$path_info;
387 $path_info =~ s
,^/+,,;
388 return if !$path_info;
389 # find which part of PATH_INFO is project
390 $project = $path_info;
392 while ($project && !check_head_link
("$projectroot/$project")) {
393 $project =~ s
,/*[^/]*$,,;
396 $project = validate_pathname
($project);
398 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
399 ($strict_export && !project_in_list
($project))) {
403 # do not change any parameters if an action is given using the query string
405 $path_info =~ s
,^$project/*,,;
406 my ($refname, $pathname) = split(/:/, $path_info, 2);
407 if (defined $pathname) {
408 # we got "project.git/branch:filename" or "project.git/branch:dir/"
409 # we could use git_get_type(branch:pathname), but it needs $git_dir
410 $pathname =~ s
,^/+,,;
411 if (!$pathname || substr($pathname, -1) eq "/") {
415 $action ||= "blob_plain";
417 $hash_base ||= validate_refname
($refname);
418 $file_name ||= validate_pathname
($pathname);
419 } elsif (defined $refname) {
420 # we got "project.git/branch"
421 $action ||= "shortlog";
422 $hash ||= validate_refname
($refname);
425 evaluate_path_info
();
427 # path to the current git repository
429 $git_dir = "$projectroot/$project" if $project;
433 "blame" => \
&git_blame2
,
434 "blobdiff" => \
&git_blobdiff
,
435 "blobdiff_plain" => \
&git_blobdiff_plain
,
436 "blob" => \
&git_blob
,
437 "blob_plain" => \
&git_blob_plain
,
438 "commitdiff" => \
&git_commitdiff
,
439 "commitdiff_plain" => \
&git_commitdiff_plain
,
440 "commit" => \
&git_commit
,
441 "forks" => \
&git_forks
,
442 "heads" => \
&git_heads
,
443 "history" => \
&git_history
,
446 "atom" => \
&git_atom
,
447 "search" => \
&git_search
,
448 "search_help" => \
&git_search_help
,
449 "shortlog" => \
&git_shortlog
,
450 "summary" => \
&git_summary
,
452 "tags" => \
&git_tags
,
453 "tree" => \
&git_tree
,
454 "snapshot" => \
&git_snapshot
,
455 "object" => \
&git_object
,
456 # those below don't need $project
457 "opml" => \
&git_opml
,
458 "project_list" => \
&git_project_list
,
459 "project_index" => \
&git_project_index
,
462 if (defined $project) {
463 $action ||= 'summary';
465 $action ||= 'project_list';
467 if (!defined($actions{$action})) {
468 die_error
(undef, "Unknown action");
470 if ($action !~ m/^(opml|project_list|project_index)$/ &&
472 die_error
(undef, "Project needed");
474 $actions{$action}->();
477 ## ======================================================================
482 # default is to use -absolute url() i.e. $my_uri
483 my $href = $params{-full
} ? $my_url : $my_uri;
485 # XXX: Warning: If you touch this, check the search form for updating,
496 hash_parent_base
=> "hpb",
502 my %mapping = @mapping;
504 $params{'project'} = $project unless exists $params{'project'};
506 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
508 # use PATH_INFO for project name
509 $href .= "/$params{'project'}" if defined $params{'project'};
510 delete $params{'project'};
512 # Summary just uses the project path URL
513 if (defined $params{'action'} && $params{'action'} eq 'summary') {
514 delete $params{'action'};
518 # now encode the parameters explicitly
520 for (my $i = 0; $i < @mapping; $i += 2) {
521 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
522 if (defined $params{$name}) {
523 push @result, $symbol . "=" . esc_param
($params{$name});
526 $href .= "?" . join(';', @result) if scalar @result;
532 ## ======================================================================
533 ## validation, quoting/unquoting and escaping
535 sub validate_pathname
{
536 my $input = shift || return undef;
538 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
539 # at the beginning, at the end, and between slashes.
540 # also this catches doubled slashes
541 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
545 if ($input =~ m!\0!) {
551 sub validate_refname
{
552 my $input = shift || return undef;
554 # textual hashes are O.K.
555 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
558 # it must be correct pathname
559 $input = validate_pathname
($input)
561 # restrictions on ref name according to git-check-ref-format
562 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
568 # quote unsafe chars, but keep the slash, even when it's not
569 # correct, but quoted slashes look too horrible in bookmarks
572 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
578 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
581 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
587 # replace invalid utf8 character with SUBSTITUTION sequence
592 $str = decode_utf8
($str);
593 $str = $cgi->escapeHTML($str);
594 if ($opts{'-nbsp'}) {
595 $str =~ s/ / /g;
597 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
601 # quote control characters and escape filename to HTML
606 $str = decode_utf8
($str);
607 $str = $cgi->escapeHTML($str);
608 if ($opts{'-nbsp'}) {
609 $str =~ s/ / /g;
611 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
615 # Make control characters "printable", using character escape codes (CEC)
618 my %es = ( # character escape codes, aka escape sequences
619 "\t" => '\t', # tab (HT)
620 "\n" => '\n', # line feed (LF)
621 "\r" => '\r', # carrige return (CR)
622 "\f" => '\f', # form feed (FF)
623 "\b" => '\b', # backspace (BS)
624 "\a" => '\a', # alarm (bell) (BEL)
625 "\e" => '\e', # escape (ESC)
626 "\013" => '\v', # vertical tab (VT)
627 "\000" => '\0', # nul character (NUL)
629 my $chr = ( (exists $es{$cntrl})
631 : sprintf('\%03o', ord($cntrl)) );
632 return "<span class=\"cntrl\">$chr</span>";
635 # Alternatively use unicode control pictures codepoints,
636 # Unicode "printable representation" (PR)
639 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
640 return "<span class=\"cntrl\">$chr</span>";
643 # git may return quoted and escaped filenames
649 my %es = ( # character escape codes, aka escape sequences
650 't' => "\t", # tab (HT, TAB)
651 'n' => "\n", # newline (NL)
652 'r' => "\r", # return (CR)
653 'f' => "\f", # form feed (FF)
654 'b' => "\b", # backspace (BS)
655 'a' => "\a", # alarm (bell) (BEL)
656 'e' => "\e", # escape (ESC)
657 'v' => "\013", # vertical tab (VT)
660 if ($seq =~ m/^[0-7]{1,3}$/) {
661 # octal char sequence
662 return chr(oct($seq));
663 } elsif (exists $es{$seq}) {
664 # C escape sequence, aka character escape code
667 # quoted ordinary character
671 if ($str =~ m/^"(.*)"$/) {
674 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
679 # escape tabs (convert tabs to spaces)
683 while ((my $pos = index($line, "\t")) != -1) {
684 if (my $count = (8 - ($pos % 8))) {
685 my $spaces = ' ' x
$count;
686 $line =~ s/\t/$spaces/;
693 sub project_in_list
{
695 my @list = git_get_projects_list
();
696 return @list && scalar(grep { $_->{'path'} eq $project } @list);
699 ## ----------------------------------------------------------------------
700 ## HTML aware string manipulation
705 my $add_len = shift || 10;
707 # allow only $len chars, but don't cut a word if it would fit in $add_len
708 # if it doesn't fit, cut it if it's still longer than the dots we would add
709 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
712 if (length($tail) > 4) {
714 $body =~ s/&[^;]*$//; # remove chopped character entities
719 ## ----------------------------------------------------------------------
720 ## functions returning short strings
722 # CSS class for given age value (in seconds)
726 if ($age < 60*60*2) {
728 } elsif ($age < 60*60*24*2) {
735 # convert age in seconds to "nn units ago" string
740 if ($age > 60*60*24*365*2) {
741 $age_str = (int $age/60/60/24/365);
742 $age_str .= " years ago";
743 } elsif ($age > 60*60*24*(365/12)*2) {
744 $age_str = int $age/60/60/24/(365/12);
745 $age_str .= " months ago";
746 } elsif ($age > 60*60*24*7*2) {
747 $age_str = int $age/60/60/24/7;
748 $age_str .= " weeks ago";
749 } elsif ($age > 60*60*24*2) {
750 $age_str = int $age/60/60/24;
751 $age_str .= " days ago";
752 } elsif ($age > 60*60*2) {
753 $age_str = int $age/60/60;
754 $age_str .= " hours ago";
755 } elsif ($age > 60*2) {
756 $age_str = int $age/60;
757 $age_str .= " min ago";
760 $age_str .= " sec ago";
762 $age_str .= " right now";
767 # convert file mode in octal to symbolic file mode string
769 my $mode = oct shift;
771 if (S_ISDIR
($mode & S_IFMT
)) {
773 } elsif (S_ISLNK
($mode)) {
775 } elsif (S_ISREG
($mode)) {
776 # git cares only about the executable bit
777 if ($mode & S_IXUSR
) {
787 # convert file mode in octal to file type string
791 if ($mode !~ m/^[0-7]+$/) {
797 if (S_ISDIR
($mode & S_IFMT
)) {
799 } elsif (S_ISLNK
($mode)) {
801 } elsif (S_ISREG
($mode)) {
808 # convert file mode in octal to file type description string
812 if ($mode !~ m/^[0-7]+$/) {
818 if (S_ISDIR
($mode & S_IFMT
)) {
820 } elsif (S_ISLNK
($mode)) {
822 } elsif (S_ISREG
($mode)) {
823 if ($mode & S_IXUSR
) {
834 ## ----------------------------------------------------------------------
835 ## functions returning short HTML fragments, or transforming HTML fragments
836 ## which don't belong to other sections
838 # format line of commit message.
839 sub format_log_line_html
{
842 $line = esc_html
($line, -nbsp
=>1);
843 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
846 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
847 -class => "text"}, $hash_text);
848 $line =~ s/$hash_text/$link/;
853 # format marker of refs pointing to given object
854 sub format_ref_marker
{
855 my ($refs, $id) = @_;
858 if (defined $refs->{$id}) {
859 foreach my $ref (@{$refs->{$id}}) {
860 my ($type, $name) = qw();
861 # e.g. tags/v2.6.11 or heads/next
862 if ($ref =~ m!^(.*?)s?/(.*)$!) {
870 $markers .= " <span class=\"$type\" title=\"$ref\">" .
871 esc_html
($name) . "</span>";
876 return ' <span class="refs">'. $markers . '</span>';
882 # format, perhaps shortened and with markers, title line
883 sub format_subject_html
{
884 my ($long, $short, $href, $extra) = @_;
885 $extra = '' unless defined($extra);
887 if (length($short) < length($long)) {
888 return $cgi->a({-href
=> $href, -class => "list subject",
889 -title
=> decode_utf8
($long)},
890 esc_html
($short) . $extra);
892 return $cgi->a({-href
=> $href, -class => "list subject"},
893 esc_html
($long) . $extra);
897 # format patch (diff) line (rather not to be used for diff headers)
898 sub format_diff_line
{
900 my ($from, $to) = @_;
905 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
907 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
908 if ($line =~ m/^\@{3}/) {
909 $diff_class = " chunk_header";
910 } elsif ($line =~ m/^\\/) {
911 $diff_class = " incomplete";
912 } elsif ($prefix =~ tr/+/+/) {
913 $diff_class = " add";
914 } elsif ($prefix =~ tr/-/-/) {
915 $diff_class = " rem";
918 # assume ordinary diff
919 my $char = substr($line, 0, 1);
921 $diff_class = " add";
922 } elsif ($char eq '-') {
923 $diff_class = " rem";
924 } elsif ($char eq '@') {
925 $diff_class = " chunk_header";
926 } elsif ($char eq "\\") {
927 $diff_class = " incomplete";
930 $line = untabify
($line);
931 if ($from && $to && $line =~ m/^\@{2} /) {
932 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
933 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
935 $from_lines = 0 unless defined $from_lines;
936 $to_lines = 0 unless defined $to_lines;
938 if ($from->{'href'}) {
939 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
940 -class=>"list"}, $from_text);
943 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
944 -class=>"list"}, $to_text);
946 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
947 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
948 return "<div class=\"diff$diff_class\">$line</div>\n";
949 } elsif ($from && $to && $line =~ m/^\@{3}/) {
950 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
951 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
953 @from_text = split(' ', $ranges);
954 for (my $i = 0; $i < @from_text; ++$i) {
955 ($from_start[$i], $from_nlines[$i]) =
956 (split(',', substr($from_text[$i], 1)), 0);
959 $to_text = pop @from_text;
960 $to_start = pop @from_start;
961 $to_nlines = pop @from_nlines;
963 $line = "<span class=\"chunk_info\">$prefix ";
964 for (my $i = 0; $i < @from_text; ++$i) {
965 if ($from->{'href'}[$i]) {
966 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
967 -class=>"list"}, $from_text[$i]);
969 $line .= $from_text[$i];
974 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
975 -class=>"list"}, $to_text);
979 $line .= " $prefix</span>" .
980 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
981 return "<div class=\"diff$diff_class\">$line</div>\n";
983 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
986 ## ----------------------------------------------------------------------
987 ## git utility subroutines, invoking git commands
989 # returns path to the core git executable and the --git-dir parameter as list
991 return $GIT, '--git-dir='.$git_dir;
994 # returns path to the core git executable and the --git-dir parameter as string
996 return join(' ', git_cmd
());
999 # get HEAD ref of given project as hash
1000 sub git_get_head_hash
{
1001 my $project = shift;
1002 my $o_git_dir = $git_dir;
1004 $git_dir = "$projectroot/$project";
1005 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1008 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1012 if (defined $o_git_dir) {
1013 $git_dir = $o_git_dir;
1018 # get type of given object
1022 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1024 close $fd or return;
1029 sub git_get_project_config
{
1030 my ($key, $type) = @_;
1032 return unless ($key);
1033 $key =~ s/^gitweb\.//;
1034 return if ($key =~ m/\W/);
1036 my @x = (git_cmd
(), 'config');
1037 if (defined $type) { push @x, $type; }
1039 push @x, "gitweb.$key";
1045 # get hash of given path at given ref
1046 sub git_get_hash_by_path
{
1048 my $path = shift || return undef;
1053 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1054 or die_error
(undef, "Open git-ls-tree failed");
1056 close $fd or return undef;
1058 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1059 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1060 if (defined $type && $type ne $2) {
1061 # type doesn't match
1067 # get path of entry with given hash at given tree-ish (ref)
1068 # used to get 'from' filename for combined diff (merge commit) for renames
1069 sub git_get_path_by_hash
{
1070 my $base = shift || return;
1071 my $hash = shift || return;
1075 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1077 while (my $line = <$fd>) {
1080 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1081 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1082 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1091 ## ......................................................................
1092 ## git utility functions, directly accessing git repository
1094 sub git_get_project_description
{
1097 open my $fd, "$projectroot/$path/description" or return undef;
1104 sub git_get_project_url_list
{
1107 open my $fd, "$projectroot/$path/cloneurl" or return;
1108 my @git_project_url_list = map { chomp; $_ } <$fd>;
1111 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1114 sub git_get_projects_list
{
1119 $filter =~ s/\.git$//;
1121 my ($check_forks) = gitweb_check_feature
('forks');
1123 if (-d
$projects_list) {
1124 # search in directory
1125 my $dir = $projects_list . ($filter ? "/$filter" : '');
1126 # remove the trailing "/"
1128 my $pfxlen = length("$dir");
1131 follow_fast
=> 1, # follow symbolic links
1132 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1134 # skip project-list toplevel, if we get it.
1135 return if (m!^[/.]$!);
1136 # only directories can be git repositories
1137 return unless (-d
$_);
1139 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1140 # we check related file in $projectroot
1141 if ($check_forks and $subdir =~ m
#/.#) {
1142 $File::Find
::prune
= 1;
1143 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1144 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1145 $File::Find
::prune
= 1;
1150 } elsif (-f
$projects_list) {
1151 # read from file(url-encoded):
1152 # 'git%2Fgit.git Linus+Torvalds'
1153 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1154 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1156 open my ($fd), $projects_list or return;
1158 while (my $line = <$fd>) {
1160 my ($path, $owner) = split ' ', $line;
1161 $path = unescape
($path);
1162 $owner = unescape
($owner);
1163 if (!defined $path) {
1166 if ($filter ne '') {
1167 # looking for forks;
1168 my $pfx = substr($path, 0, length($filter));
1169 if ($pfx ne $filter) {
1172 my $sfx = substr($path, length($filter));
1173 if ($sfx !~ /^\/.*\
.git
$/) {
1176 } elsif ($check_forks) {
1178 foreach my $filter (keys %paths) {
1179 # looking for forks;
1180 my $pfx = substr($path, 0, length($filter));
1181 if ($pfx ne $filter) {
1184 my $sfx = substr($path, length($filter));
1185 if ($sfx !~ /^\/.*\
.git
$/) {
1188 # is a fork, don't include it in
1193 if (check_export_ok
("$projectroot/$path")) {
1196 owner
=> decode_utf8
($owner),
1199 (my $forks_path = $path) =~ s/\.git$//;
1200 $paths{$forks_path}++;
1208 sub git_get_project_owner
{
1209 my $project = shift;
1212 return undef unless $project;
1214 # read from file (url-encoded):
1215 # 'git%2Fgit.git Linus+Torvalds'
1216 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1217 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1218 if (-f
$projects_list) {
1219 open (my $fd , $projects_list);
1220 while (my $line = <$fd>) {
1222 my ($pr, $ow) = split ' ', $line;
1223 $pr = unescape
($pr);
1224 $ow = unescape
($ow);
1225 if ($pr eq $project) {
1226 $owner = decode_utf8
($ow);
1232 if (!defined $owner) {
1233 $owner = get_file_owner
("$projectroot/$project");
1239 sub git_get_last_activity
{
1243 $git_dir = "$projectroot/$path";
1244 open($fd, "-|", git_cmd
(), 'for-each-ref',
1245 '--format=%(committer)',
1246 '--sort=-committerdate',
1248 'refs/heads') or return;
1249 my $most_recent = <$fd>;
1250 close $fd or return;
1251 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1253 my $age = time - $timestamp;
1254 return ($age, age_string
($age));
1258 sub git_get_references
{
1259 my $type = shift || "";
1261 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1262 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1263 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1264 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1267 while (my $line = <$fd>) {
1269 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1270 if (defined $refs{$1}) {
1271 push @{$refs{$1}}, $2;
1277 close $fd or return;
1281 sub git_get_rev_name_tags
{
1282 my $hash = shift || return undef;
1284 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1286 my $name_rev = <$fd>;
1289 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1292 # catches also '$hash undefined' output
1297 ## ----------------------------------------------------------------------
1298 ## parse to hash functions
1302 my $tz = shift || "-0000";
1305 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1306 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1307 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1308 $date{'hour'} = $hour;
1309 $date{'minute'} = $min;
1310 $date{'mday'} = $mday;
1311 $date{'day'} = $days[$wday];
1312 $date{'month'} = $months[$mon];
1313 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1314 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1315 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1316 $mday, $months[$mon], $hour ,$min;
1317 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1318 1900+$year, $mon, $mday, $hour ,$min, $sec;
1320 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1321 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1322 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1323 $date{'hour_local'} = $hour;
1324 $date{'minute_local'} = $min;
1325 $date{'tz_local'} = $tz;
1326 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1327 1900+$year, $mon+1, $mday,
1328 $hour, $min, $sec, $tz);
1337 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1338 $tag{'id'} = $tag_id;
1339 while (my $line = <$fd>) {
1341 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1342 $tag{'object'} = $1;
1343 } elsif ($line =~ m/^type (.+)$/) {
1345 } elsif ($line =~ m/^tag (.+)$/) {
1347 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1348 $tag{'author'} = $1;
1351 } elsif ($line =~ m/--BEGIN/) {
1352 push @comment, $line;
1354 } elsif ($line eq "") {
1358 push @comment, <$fd>;
1359 $tag{'comment'} = \
@comment;
1360 close $fd or return;
1361 if (!defined $tag{'name'}) {
1367 sub parse_commit_text
{
1368 my ($commit_text, $withparents) = @_;
1369 my @commit_lines = split '\n', $commit_text;
1372 pop @commit_lines; # Remove '\0'
1374 my $header = shift @commit_lines;
1375 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1378 ($co{'id'}, my @parents) = split ' ', $header;
1379 while (my $line = shift @commit_lines) {
1380 last if $line eq "\n";
1381 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1383 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1385 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1387 $co{'author_epoch'} = $2;
1388 $co{'author_tz'} = $3;
1389 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1390 $co{'author_name'} = $1;
1391 $co{'author_email'} = $2;
1393 $co{'author_name'} = $co{'author'};
1395 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1396 $co{'committer'} = $1;
1397 $co{'committer_epoch'} = $2;
1398 $co{'committer_tz'} = $3;
1399 $co{'committer_name'} = $co{'committer'};
1400 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1401 $co{'committer_name'} = $1;
1402 $co{'committer_email'} = $2;
1404 $co{'committer_name'} = $co{'committer'};
1408 if (!defined $co{'tree'}) {
1411 $co{'parents'} = \
@parents;
1412 $co{'parent'} = $parents[0];
1414 foreach my $title (@commit_lines) {
1417 $co{'title'} = chop_str
($title, 80, 5);
1418 # remove leading stuff of merges to make the interesting part visible
1419 if (length($title) > 50) {
1420 $title =~ s/^Automatic //;
1421 $title =~ s/^merge (of|with) /Merge ... /i;
1422 if (length($title) > 50) {
1423 $title =~ s/(http|rsync):\/\///;
1425 if (length($title) > 50) {
1426 $title =~ s/(master|www|rsync)\.//;
1428 if (length($title) > 50) {
1429 $title =~ s/kernel.org:?//;
1431 if (length($title) > 50) {
1432 $title =~ s/\/pub\/scm//;
1435 $co{'title_short'} = chop_str
($title, 50, 5);
1439 if ($co{'title'} eq "") {
1440 $co{'title'} = $co{'title_short'} = '(no commit message)';
1442 # remove added spaces
1443 foreach my $line (@commit_lines) {
1446 $co{'comment'} = \
@commit_lines;
1448 my $age = time - $co{'committer_epoch'};
1450 $co{'age_string'} = age_string
($age);
1451 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1452 if ($age > 60*60*24*7*2) {
1453 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1454 $co{'age_string_age'} = $co{'age_string'};
1456 $co{'age_string_date'} = $co{'age_string'};
1457 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1463 my ($commit_id) = @_;
1468 open my $fd, "-|", git_cmd
(), "rev-list",
1474 or die_error
(undef, "Open git-rev-list failed");
1475 %co = parse_commit_text
(<$fd>, 1);
1482 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1490 open my $fd, "-|", git_cmd
(), "rev-list",
1492 ($arg ? ($arg) : ()),
1493 ("--max-count=" . $maxcount),
1494 ("--skip=" . $skip),
1497 ($filename ? ($filename) : ())
1498 or die_error
(undef, "Open git-rev-list failed");
1499 while (my $line = <$fd>) {
1500 my %co = parse_commit_text
($line);
1505 return wantarray ? @cos : \
@cos;
1508 # parse ref from ref_file, given by ref_id, with given type
1510 my $ref_file = shift;
1512 my $type = shift || git_get_type
($ref_id);
1515 $ref_item{'type'} = $type;
1516 $ref_item{'id'} = $ref_id;
1517 $ref_item{'epoch'} = 0;
1518 $ref_item{'age'} = "unknown";
1519 if ($type eq "tag") {
1520 my %tag = parse_tag
($ref_id);
1521 $ref_item{'comment'} = $tag{'comment'};
1522 if ($tag{'type'} eq "commit") {
1523 my %co = parse_commit
($tag{'object'});
1524 $ref_item{'epoch'} = $co{'committer_epoch'};
1525 $ref_item{'age'} = $co{'age_string'};
1526 } elsif (defined($tag{'epoch'})) {
1527 my $age = time - $tag{'epoch'};
1528 $ref_item{'epoch'} = $tag{'epoch'};
1529 $ref_item{'age'} = age_string
($age);
1531 $ref_item{'reftype'} = $tag{'type'};
1532 $ref_item{'name'} = $tag{'name'};
1533 $ref_item{'refid'} = $tag{'object'};
1534 } elsif ($type eq "commit"){
1535 my %co = parse_commit
($ref_id);
1536 $ref_item{'reftype'} = "commit";
1537 $ref_item{'name'} = $ref_file;
1538 $ref_item{'title'} = $co{'title'};
1539 $ref_item{'refid'} = $ref_id;
1540 $ref_item{'epoch'} = $co{'committer_epoch'};
1541 $ref_item{'age'} = $co{'age_string'};
1543 $ref_item{'reftype'} = $type;
1544 $ref_item{'name'} = $ref_file;
1545 $ref_item{'refid'} = $ref_id;
1551 # parse line of git-diff-tree "raw" output
1552 sub parse_difftree_raw_line
{
1556 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1557 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1558 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1559 $res{'from_mode'} = $1;
1560 $res{'to_mode'} = $2;
1561 $res{'from_id'} = $3;
1563 $res{'status'} = $5;
1564 $res{'similarity'} = $6;
1565 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1566 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1568 $res{'file'} = unquote
($7);
1571 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1572 # combined diff (for merge commit)
1573 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1574 $res{'nparents'} = length($1);
1575 $res{'from_mode'} = [ split(' ', $2) ];
1576 $res{'to_mode'} = pop @{$res{'from_mode'}};
1577 $res{'from_id'} = [ split(' ', $3) ];
1578 $res{'to_id'} = pop @{$res{'from_id'}};
1579 $res{'status'} = [ split('', $4) ];
1580 $res{'to_file'} = unquote
($5);
1582 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1583 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1584 $res{'commit'} = $1;
1587 return wantarray ? %res : \
%res;
1590 # parse line of git-ls-tree output
1591 sub parse_ls_tree_line
($;%) {
1596 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1597 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1605 $res{'name'} = unquote
($4);
1608 return wantarray ? %res : \
%res;
1611 ## ......................................................................
1612 ## parse to array of hashes functions
1614 sub git_get_heads_list
{
1618 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1619 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1620 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1623 while (my $line = <$fd>) {
1627 my ($refinfo, $committerinfo) = split(/\0/, $line);
1628 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1629 my ($committer, $epoch, $tz) =
1630 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1631 $name =~ s!^refs/heads/!!;
1633 $ref_item{'name'} = $name;
1634 $ref_item{'id'} = $hash;
1635 $ref_item{'title'} = $title || '(no commit message)';
1636 $ref_item{'epoch'} = $epoch;
1638 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1640 $ref_item{'age'} = "unknown";
1643 push @headslist, \
%ref_item;
1647 return wantarray ? @headslist : \
@headslist;
1650 sub git_get_tags_list
{
1654 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1655 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1656 '--format=%(objectname) %(objecttype) %(refname) '.
1657 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1660 while (my $line = <$fd>) {
1664 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1665 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1666 my ($creator, $epoch, $tz) =
1667 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1668 $name =~ s!^refs/tags/!!;
1670 $ref_item{'type'} = $type;
1671 $ref_item{'id'} = $id;
1672 $ref_item{'name'} = $name;
1673 if ($type eq "tag") {
1674 $ref_item{'subject'} = $title;
1675 $ref_item{'reftype'} = $reftype;
1676 $ref_item{'refid'} = $refid;
1678 $ref_item{'reftype'} = $type;
1679 $ref_item{'refid'} = $id;
1682 if ($type eq "tag" || $type eq "commit") {
1683 $ref_item{'epoch'} = $epoch;
1685 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1687 $ref_item{'age'} = "unknown";
1691 push @tagslist, \
%ref_item;
1695 return wantarray ? @tagslist : \
@tagslist;
1698 ## ----------------------------------------------------------------------
1699 ## filesystem-related functions
1701 sub get_file_owner
{
1704 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1705 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1706 if (!defined $gcos) {
1710 $owner =~ s/[,;].*$//;
1711 return decode_utf8
($owner);
1714 ## ......................................................................
1715 ## mimetype related functions
1717 sub mimetype_guess_file
{
1718 my $filename = shift;
1719 my $mimemap = shift;
1720 -r
$mimemap or return undef;
1723 open(MIME
, $mimemap) or return undef;
1725 next if m/^#/; # skip comments
1726 my ($mime, $exts) = split(/\t+/);
1727 if (defined $exts) {
1728 my @exts = split(/\s+/, $exts);
1729 foreach my $ext (@exts) {
1730 $mimemap{$ext} = $mime;
1736 $filename =~ /\.([^.]*)$/;
1737 return $mimemap{$1};
1740 sub mimetype_guess
{
1741 my $filename = shift;
1743 $filename =~ /\./ or return undef;
1745 if ($mimetypes_file) {
1746 my $file = $mimetypes_file;
1747 if ($file !~ m!^/!) { # if it is relative path
1748 # it is relative to project
1749 $file = "$projectroot/$project/$file";
1751 $mime = mimetype_guess_file
($filename, $file);
1753 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1759 my $filename = shift;
1762 my $mime = mimetype_guess
($filename);
1763 $mime and return $mime;
1767 return $default_blob_plain_mimetype unless $fd;
1770 return 'text/plain' .
1771 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1772 } elsif (! $filename) {
1773 return 'application/octet-stream';
1774 } elsif ($filename =~ m/\.png$/i) {
1776 } elsif ($filename =~ m/\.gif$/i) {
1778 } elsif ($filename =~ m/\.jpe?g$/i) {
1779 return 'image/jpeg';
1781 return 'application/octet-stream';
1785 ## ======================================================================
1786 ## functions printing HTML: header, footer, error page
1788 sub git_header_html
{
1789 my $status = shift || "200 OK";
1790 my $expires = shift;
1792 my $title = "$site_name";
1793 if (defined $project) {
1794 $title .= " - " . decode_utf8
($project);
1795 if (defined $action) {
1796 $title .= "/$action";
1797 if (defined $file_name) {
1798 $title .= " - " . esc_path
($file_name);
1799 if ($action eq "tree" && $file_name !~ m
|/$|) {
1806 # require explicit support from the UA if we are to send the page as
1807 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1808 # we have to do this because MSIE sometimes globs '*/*', pretending to
1809 # support xhtml+xml but choking when it gets what it asked for.
1810 if (defined $cgi->http('HTTP_ACCEPT') &&
1811 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1812 $cgi->Accept('application/xhtml+xml') != 0) {
1813 $content_type = 'application/xhtml+xml';
1815 $content_type = 'text/html';
1817 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1818 -status
=> $status, -expires
=> $expires);
1819 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
1821 <?xml version="1.0" encoding="utf-8"?>
1822 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1823 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1824 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1825 <!-- git core binaries version $git_version -->
1827 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1828 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
1829 <meta name="robots" content="index, nofollow"/>
1830 <title>$title</title>
1832 # print out each stylesheet that exist
1833 if (defined $stylesheet) {
1834 #provides backwards capability for those people who define style sheet in a config file
1835 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1837 foreach my $stylesheet (@stylesheets) {
1838 next unless $stylesheet;
1839 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1842 if (defined $project) {
1843 printf('<link rel="alternate" title="%s log RSS feed" '.
1844 'href="%s" type="application/rss+xml" />'."\n",
1845 esc_param
($project), href
(action
=>"rss"));
1846 printf('<link rel="alternate" title="%s log Atom feed" '.
1847 'href="%s" type="application/atom+xml" />'."\n",
1848 esc_param
($project), href
(action
=>"atom"));
1850 printf('<link rel="alternate" title="%s projects list" '.
1851 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1852 $site_name, href
(project
=>undef, action
=>"project_index"));
1853 printf('<link rel="alternate" title="%s projects feeds" '.
1854 'href="%s" type="text/x-opml"/>'."\n",
1855 $site_name, href
(project
=>undef, action
=>"opml"));
1857 if (defined $favicon) {
1858 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1864 if (-f
$site_header) {
1865 open (my $fd, $site_header);
1870 print "<div class=\"page_header\">\n" .
1871 $cgi->a({-href
=> esc_url
($logo_url),
1872 -title
=> $logo_label},
1873 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1874 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1875 if (defined $project) {
1876 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1877 if (defined $action) {
1882 my ($have_search) = gitweb_check_feature
('search');
1883 if ((defined $project) && ($have_search)) {
1884 if (!defined $searchtext) {
1888 if (defined $hash_base) {
1889 $search_hash = $hash_base;
1890 } elsif (defined $hash) {
1891 $search_hash = $hash;
1893 $search_hash = "HEAD";
1895 $cgi->param("a", "search");
1896 $cgi->param("h", $search_hash);
1897 $cgi->param("p", $project);
1898 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1899 "<div class=\"search\">\n" .
1900 $cgi->hidden(-name
=> "p") . "\n" .
1901 $cgi->hidden(-name
=> "a") . "\n" .
1902 $cgi->hidden(-name
=> "h") . "\n" .
1903 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1904 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1905 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1907 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1909 $cgi->end_form() . "\n";
1914 sub git_footer_html
{
1915 print "<div class=\"page_footer\">\n";
1916 if (defined $project) {
1917 my $descr = git_get_project_description
($project);
1918 if (defined $descr) {
1919 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1921 print $cgi->a({-href
=> href
(action
=>"rss"),
1922 -class => "rss_logo"}, "RSS") . " ";
1923 print $cgi->a({-href
=> href
(action
=>"atom"),
1924 -class => "rss_logo"}, "Atom") . "\n";
1926 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1927 -class => "rss_logo"}, "OPML") . " ";
1928 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1929 -class => "rss_logo"}, "TXT") . "\n";
1933 if (-f
$site_footer) {
1934 open (my $fd, $site_footer);
1944 my $status = shift || "403 Forbidden";
1945 my $error = shift || "Malformed query, file missing or permission denied";
1947 git_header_html
($status);
1949 <div class="page_body">
1959 ## ----------------------------------------------------------------------
1960 ## functions printing or outputting HTML: navigation
1962 sub git_print_page_nav
{
1963 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1964 $extra = '' if !defined $extra; # pager or formats
1966 my @navs = qw(summary shortlog log commit commitdiff tree);
1968 @navs = grep { $_ ne $suppress } @navs;
1971 my %arg = map { $_ => {action
=>$_} } @navs;
1972 if (defined $head) {
1973 for (qw(commit commitdiff)) {
1974 $arg{$_}{'hash'} = $head;
1976 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1977 for (qw(shortlog log)) {
1978 $arg{$_}{'hash'} = $head;
1982 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
1983 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
1985 print "<div class=\"page_nav\">\n" .
1987 map { $_ eq $current ?
1988 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1990 print "<br/>\n$extra<br/>\n" .
1994 sub format_paging_nav
{
1995 my ($action, $hash, $head, $page, $nrevs) = @_;
1999 if ($hash ne $head || $page) {
2000 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2002 $paging_nav .= "HEAD";
2006 $paging_nav .= " ⋅ " .
2007 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2008 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2010 $paging_nav .= " ⋅ prev";
2013 if ($nrevs >= (100 * ($page+1)-1)) {
2014 $paging_nav .= " ⋅ " .
2015 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2016 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2018 $paging_nav .= " ⋅ next";
2024 ## ......................................................................
2025 ## functions printing or outputting HTML: div
2027 sub git_print_header_div
{
2028 my ($action, $title, $hash, $hash_base) = @_;
2031 $args{'action'} = $action;
2032 $args{'hash'} = $hash if $hash;
2033 $args{'hash_base'} = $hash_base if $hash_base;
2035 print "<div class=\"header\">\n" .
2036 $cgi->a({-href
=> href
(%args), -class => "title"},
2037 $title ? $title : $action) .
2041 #sub git_print_authorship (\%) {
2042 sub git_print_authorship
{
2045 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2046 print "<div class=\"author_date\">" .
2047 esc_html
($co->{'author_name'}) .
2049 if ($ad{'hour_local'} < 6) {
2050 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2051 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2053 printf(" (%02d:%02d %s)",
2054 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2059 sub git_print_page_path
{
2065 print "<div class=\"page_path\">";
2066 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2067 -title
=> 'tree root'}, decode_utf8
("[$project]"));
2069 if (defined $name) {
2070 my @dirname = split '/', $name;
2071 my $basename = pop @dirname;
2074 foreach my $dir (@dirname) {
2075 $fullname .= ($fullname ? '/' : '') . $dir;
2076 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2078 -title
=> $fullname}, esc_path
($dir));
2081 if (defined $type && $type eq 'blob') {
2082 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2084 -title
=> $name}, esc_path
($basename));
2085 } elsif (defined $type && $type eq 'tree') {
2086 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2088 -title
=> $name}, esc_path
($basename));
2091 print esc_path
($basename);
2094 print "<br/></div>\n";
2097 # sub git_print_log (\@;%) {
2098 sub git_print_log
($;%) {
2102 if ($opts{'-remove_title'}) {
2103 # remove title, i.e. first line of log
2106 # remove leading empty lines
2107 while (defined $log->[0] && $log->[0] eq "") {
2114 foreach my $line (@$log) {
2115 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2118 if (! $opts{'-remove_signoff'}) {
2119 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2122 # remove signoff lines
2129 # print only one empty line
2130 # do not print empty line after signoff
2132 next if ($empty || $signoff);
2138 print format_log_line_html
($line) . "<br/>\n";
2141 if ($opts{'-final_empty_line'}) {
2142 # end with single empty line
2143 print "<br/>\n" unless $empty;
2147 # return link target (what link points to)
2148 sub git_get_link_target
{
2153 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2157 $link_target = <$fd>;
2162 return $link_target;
2165 # given link target, and the directory (basedir) the link is in,
2166 # return target of link relative to top directory (top tree);
2167 # return undef if it is not possible (including absolute links).
2168 sub normalize_link_target
{
2169 my ($link_target, $basedir, $hash_base) = @_;
2171 # we can normalize symlink target only if $hash_base is provided
2172 return unless $hash_base;
2174 # absolute symlinks (beginning with '/') cannot be normalized
2175 return if (substr($link_target, 0, 1) eq '/');
2177 # normalize link target to path from top (root) tree (dir)
2180 $path = $basedir . '/' . $link_target;
2182 # we are in top (root) tree (dir)
2183 $path = $link_target;
2186 # remove //, /./, and /../
2188 foreach my $part (split('/', $path)) {
2189 # discard '.' and ''
2190 next if (!$part || $part eq '.');
2192 if ($part eq '..') {
2196 # link leads outside repository (outside top dir)
2200 push @path_parts, $part;
2203 $path = join('/', @path_parts);
2208 # print tree entry (row of git_tree), but without encompassing <tr> element
2209 sub git_print_tree_entry
{
2210 my ($t, $basedir, $hash_base, $have_blame) = @_;
2213 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2215 # The format of a table row is: mode list link. Where mode is
2216 # the mode of the entry, list is the name of the entry, an href,
2217 # and link is the action links of the entry.
2219 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2220 if ($t->{'type'} eq "blob") {
2221 print "<td class=\"list\">" .
2222 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2223 file_name
=>"$basedir$t->{'name'}", %base_key),
2224 -class => "list"}, esc_path
($t->{'name'}));
2225 if (S_ISLNK
(oct $t->{'mode'})) {
2226 my $link_target = git_get_link_target
($t->{'hash'});
2228 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2229 if (defined $norm_target) {
2231 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2232 file_name
=>$norm_target),
2233 -title
=> $norm_target}, esc_path
($link_target));
2235 print " -> " . esc_path
($link_target);
2240 print "<td class=\"link\">";
2241 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2242 file_name
=>"$basedir$t->{'name'}", %base_key)},
2246 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2247 file_name
=>"$basedir$t->{'name'}", %base_key)},
2250 if (defined $hash_base) {
2252 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2253 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2257 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2258 file_name
=>"$basedir$t->{'name'}")},
2262 } elsif ($t->{'type'} eq "tree") {
2263 print "<td class=\"list\">";
2264 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2265 file_name
=>"$basedir$t->{'name'}", %base_key)},
2266 esc_path
($t->{'name'}));
2268 print "<td class=\"link\">";
2269 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2270 file_name
=>"$basedir$t->{'name'}", %base_key)},
2272 if (defined $hash_base) {
2274 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2275 file_name
=>"$basedir$t->{'name'}")},
2282 ## ......................................................................
2283 ## functions printing large fragments of HTML
2285 sub fill_from_file_info
{
2286 my ($diff, @parents) = @_;
2288 $diff->{'from_file'} = [ ];
2289 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2290 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2291 if ($diff->{'status'}[$i] eq 'R' ||
2292 $diff->{'status'}[$i] eq 'C') {
2293 $diff->{'from_file'}[$i] =
2294 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2301 # parameters can be strings, or references to arrays of strings
2305 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @$a == @$b) {
2306 for (my $i = 0; $i < @$a; ++$i) {
2307 return 0 unless ($a->[$i] eq $b->[$i]);
2310 } elsif (!ref($a) && !ref($b)) {
2318 sub git_difftree_body
{
2319 my ($difftree, $hash, @parents) = @_;
2320 my ($parent) = $parents[0];
2321 my ($have_blame) = gitweb_check_feature
('blame');
2322 print "<div class=\"list_head\">\n";
2323 if ($#{$difftree} > 10) {
2324 print(($#{$difftree} + 1) . " files changed:\n");
2328 print "<table class=\"" .
2329 (@parents > 1 ? "combined " : "") .
2333 foreach my $line (@{$difftree}) {
2334 my %diff = parse_difftree_raw_line
($line);
2337 print "<tr class=\"dark\">\n";
2339 print "<tr class=\"light\">\n";
2343 if (exists $diff{'nparents'}) { # combined diff
2345 fill_from_file_info
(\
%diff, @parents);
2347 if ($diff{'to_id'} ne ('0' x
40)) {
2348 # file exists in the result (child) commit
2350 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2351 file_name
=>$diff{'to_file'},
2353 -class => "list"}, esc_path
($diff{'to_file'})) .
2357 esc_path
($diff{'to_file'}) .
2361 if ($action eq 'commitdiff') {
2364 print "<td class=\"link\">" .
2365 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2370 my $has_history = 0;
2371 my $not_deleted = 0;
2372 for (my $i = 0; $i < $diff{'nparents'}; $i++) {
2373 my $hash_parent = $parents[$i];
2374 my $from_hash = $diff{'from_id'}[$i];
2375 my $from_path = $diff{'from_file'}[$i];
2376 my $status = $diff{'status'}[$i];
2378 $has_history ||= ($status ne 'A');
2379 $not_deleted ||= ($status ne 'D');
2381 if ($status eq 'A') {
2382 print "<td class=\"link\" align=\"right\"> | </td>\n";
2383 } elsif ($status eq 'D') {
2384 print "<td class=\"link\">" .
2385 $cgi->a({-href
=> href
(action
=>"blob",
2388 file_name
=>$from_path)},
2392 if ($diff{'to_id'} eq $from_hash) {
2393 print "<td class=\"link nochange\">";
2395 print "<td class=\"link\">";
2397 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2398 hash
=>$diff{'to_id'},
2399 hash_parent
=>$from_hash,
2401 hash_parent_base
=>$hash_parent,
2402 file_name
=>$diff{'to_file'},
2403 file_parent
=>$from_path)},
2409 print "<td class=\"link\">";
2411 print $cgi->a({-href
=> href
(action
=>"blob",
2412 hash
=>$diff{'to_id'},
2413 file_name
=>$diff{'to_file'},
2416 print " | " if ($has_history);
2419 print $cgi->a({-href
=> href
(action
=>"history",
2420 file_name
=>$diff{'to_file'},
2427 next; # instead of 'else' clause, to avoid extra indent
2429 # else ordinary diff
2431 my ($to_mode_oct, $to_mode_str, $to_file_type);
2432 my ($from_mode_oct, $from_mode_str, $from_file_type);
2433 if ($diff{'to_mode'} ne ('0' x
6)) {
2434 $to_mode_oct = oct $diff{'to_mode'};
2435 if (S_ISREG
($to_mode_oct)) { # only for regular file
2436 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2438 $to_file_type = file_type
($diff{'to_mode'});
2440 if ($diff{'from_mode'} ne ('0' x
6)) {
2441 $from_mode_oct = oct $diff{'from_mode'};
2442 if (S_ISREG
($to_mode_oct)) { # only for regular file
2443 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2445 $from_file_type = file_type
($diff{'from_mode'});
2448 if ($diff{'status'} eq "A") { # created
2449 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2450 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2451 $mode_chng .= "]</span>";
2453 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2454 hash_base
=>$hash, file_name
=>$diff{'file'}),
2455 -class => "list"}, esc_path
($diff{'file'}));
2457 print "<td>$mode_chng</td>\n";
2458 print "<td class=\"link\">";
2459 if ($action eq 'commitdiff') {
2462 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2465 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2466 hash_base
=>$hash, file_name
=>$diff{'file'})},
2470 } elsif ($diff{'status'} eq "D") { # deleted
2471 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2473 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2474 hash_base
=>$parent, file_name
=>$diff{'file'}),
2475 -class => "list"}, esc_path
($diff{'file'}));
2477 print "<td>$mode_chng</td>\n";
2478 print "<td class=\"link\">";
2479 if ($action eq 'commitdiff') {
2482 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2485 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2486 hash_base
=>$parent, file_name
=>$diff{'file'})},
2489 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2490 file_name
=>$diff{'file'})},
2493 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2494 file_name
=>$diff{'file'})},
2498 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
2499 my $mode_chnge = "";
2500 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2501 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2502 if ($from_file_type ne $to_file_type) {
2503 $mode_chnge .= " from $from_file_type to $to_file_type";
2505 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2506 if ($from_mode_str && $to_mode_str) {
2507 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2508 } elsif ($to_mode_str) {
2509 $mode_chnge .= " mode: $to_mode_str";
2512 $mode_chnge .= "]</span>\n";
2515 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2516 hash_base
=>$hash, file_name
=>$diff{'file'}),
2517 -class => "list"}, esc_path
($diff{'file'}));
2519 print "<td>$mode_chnge</td>\n";
2520 print "<td class=\"link\">";
2521 if ($action eq 'commitdiff') {
2524 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2526 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2527 # "commit" view and modified file (not onlu mode changed)
2528 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2529 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2530 hash_base
=>$hash, hash_parent_base
=>$parent,
2531 file_name
=>$diff{'file'})},
2535 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2536 hash_base
=>$hash, file_name
=>$diff{'file'})},
2539 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2540 file_name
=>$diff{'file'})},
2543 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2544 file_name
=>$diff{'file'})},
2548 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
2549 my %status_name = ('R' => 'moved', 'C' => 'copied');
2550 my $nstatus = $status_name{$diff{'status'}};
2552 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2553 # mode also for directories, so we cannot use $to_mode_str
2554 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2557 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2558 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
2559 -class => "list"}, esc_path
($diff{'to_file'})) . "</td>\n" .
2560 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2561 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2562 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
2563 -class => "list"}, esc_path
($diff{'from_file'})) .
2564 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2565 "<td class=\"link\">";
2566 if ($action eq 'commitdiff') {
2569 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2571 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2572 # "commit" view and modified file (not only pure rename or copy)
2573 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2574 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2575 hash_base
=>$hash, hash_parent_base
=>$parent,
2576 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
2580 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2581 hash_base
=>$parent, file_name
=>$diff{'to_file'})},
2584 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2585 file_name
=>$diff{'to_file'})},
2588 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2589 file_name
=>$diff{'to_file'})},
2593 } # we should not encounter Unmerged (U) or Unknown (X) status
2599 sub git_patchset_body
{
2600 my ($fd, $difftree, $hash, @hash_parents) = @_;
2601 my ($hash_parent) = $hash_parents[0];
2604 my $patch_number = 0;
2609 print "<div class=\"patchset\">\n";
2611 # skip to first patch
2612 while ($patch_line = <$fd>) {
2615 last if ($patch_line =~ m/^diff /);
2619 while ($patch_line) {
2621 my ($from_id, $to_id);
2624 #assert($patch_line =~ m/^diff /) if DEBUG;
2625 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2627 push @diff_header, $patch_line;
2629 # extended diff header
2631 while ($patch_line = <$fd>) {
2634 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2636 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2639 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2640 $from_id = [ split(',', $1) ];
2644 push @diff_header, $patch_line;
2646 my $last_patch_line = $patch_line;
2648 # check if current patch belong to current raw line
2649 # and parse raw git-diff line if needed
2650 if (defined $diffinfo &&
2651 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
2652 $diffinfo->{'to_id'} eq $to_id) {
2653 # this is split patch
2654 print "<div class=\"patch cont\">\n";
2656 # advance raw git-diff output if needed
2657 $patch_idx++ if defined $diffinfo;
2659 # read and prepare patch information
2660 if (ref($difftree->[$patch_idx]) eq "HASH") {
2661 # pre-parsed (or generated by hand)
2662 $diffinfo = $difftree->[$patch_idx];
2664 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2666 if ($diffinfo->{'nparents'}) {
2670 fill_from_file_info
($diffinfo, @hash_parents)
2671 unless exists $diffinfo->{'from_file'};
2672 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2673 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2674 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2675 $from{'href'}[$i] = href
(action
=>"blob",
2676 hash_base
=>$hash_parents[$i],
2677 hash
=>$diffinfo->{'from_id'}[$i],
2678 file_name
=>$from{'file'}[$i]);
2680 $from{'href'}[$i] = undef;
2684 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2685 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2686 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2687 hash
=>$diffinfo->{'from_id'},
2688 file_name
=>$from{'file'});
2690 delete $from{'href'};
2693 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2694 if ($diffinfo->{'status'} ne "D") { # not deleted file
2695 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2696 hash
=>$diffinfo->{'to_id'},
2697 file_name
=>$to{'file'});
2701 # this is first patch for raw difftree line with $patch_idx index
2702 # we index @$difftree array from 0, but number patches from 1
2703 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2706 # print "git diff" header
2707 $patch_line = shift @diff_header;
2708 if ($diffinfo->{'nparents'}) {
2711 $patch_line =~ s!^(diff (.*?) )"?.*$!$1!;
2713 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2714 esc_path
($to{'file'}));
2715 } else { # file was deleted
2716 $patch_line .= esc_path
($to{'file'});
2721 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2722 if ($from{'href'}) {
2723 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2724 'a/' . esc_path
($from{'file'}));
2725 } else { # file was added
2726 $patch_line .= 'a/' . esc_path
($from{'file'});
2730 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2731 'b/' . esc_path
($to{'file'}));
2732 } else { # file was deleted
2733 $patch_line .= 'b/' . esc_path
($to{'file'});
2737 print "<div class=\"diff header\">$patch_line</div>\n";
2739 # print extended diff header
2740 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2742 foreach $patch_line (@diff_header) {
2744 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2745 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2746 esc_path
($from{'file'}));
2748 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2749 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2750 esc_path
($to{'file'}));
2752 # match single <mode>
2753 if ($patch_line =~ m/\s(\d{6})$/) {
2754 $patch_line .= '<span class="info"> (' .
2755 file_type_long
($1) .
2759 if ($patch_line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
2760 # can match only for combined diff
2761 $patch_line = 'index ';
2762 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2763 if ($from{'href'}[$i]) {
2764 $patch_line .= $cgi->a({-href
=>$from{'href'}[$i],
2766 substr($diffinfo->{'from_id'}[$i],0,7));
2768 $patch_line .= '0' x
7;
2771 $patch_line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
2773 $patch_line .= '..';
2775 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2776 substr($diffinfo->{'to_id'},0,7));
2778 $patch_line .= '0' x
7;
2781 } elsif ($patch_line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
2782 # can match only for ordinary diff
2783 my ($from_link, $to_link);
2784 if ($from{'href'}) {
2785 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2786 substr($diffinfo->{'from_id'},0,7));
2788 $from_link = '0' x
7;
2791 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2792 substr($diffinfo->{'to_id'},0,7));
2797 # my ($from_hash, $to_hash) =
2798 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2799 # my ($from_id, $to_id) =
2800 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2801 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2803 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2804 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2806 print $patch_line . "<br/>\n";
2808 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2810 # from-file/to-file diff header
2811 $patch_line = $last_patch_line;
2812 if (! $patch_line) {
2813 print "</div>\n"; # class="patch"
2816 next PATCH
if ($patch_line =~ m/^diff /);
2817 #assert($patch_line =~ m/^---/) if DEBUG;
2818 if (!$diffinfo->{'nparents'} && # not from-file line for combined diff
2819 $from{'href'} && $patch_line =~ m!^--- "?a/!) {
2820 $patch_line = '--- a/' .
2821 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2822 esc_path
($from{'file'}));
2824 print "<div class=\"diff from_file\">$patch_line</div>\n";
2826 $patch_line = <$fd>;
2829 #assert($patch_line =~ m/^+++/) if DEBUG;
2830 if ($to{'href'} && $patch_line =~ m!^\+\+\+ "?b/!) {
2831 $patch_line = '+++ b/' .
2832 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2833 esc_path
($to{'file'}));
2835 print "<div class=\"diff to_file\">$patch_line</div>\n";
2839 while ($patch_line = <$fd>) {
2842 next PATCH
if ($patch_line =~ m/^diff /);
2844 print format_diff_line
($patch_line, \
%from, \
%to);
2848 print "</div>\n"; # class="patch"
2850 print "<div class=\"diff nodifferences\">No differences found</div>\n" if (!$patch_number);
2852 print "</div>\n"; # class="patchset"
2855 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2857 sub git_project_list_body
{
2858 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2860 my ($check_forks) = gitweb_check_feature
('forks');
2863 foreach my $pr (@$projlist) {
2864 my (@aa) = git_get_last_activity
($pr->{'path'});
2868 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2869 if (!defined $pr->{'descr'}) {
2870 my $descr = git_get_project_description
($pr->{'path'}) || "";
2871 $pr->{'descr_long'} = decode_utf8
($descr);
2872 $pr->{'descr'} = chop_str
($descr, 25, 5);
2874 if (!defined $pr->{'owner'}) {
2875 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2878 my $pname = $pr->{'path'};
2879 if (($pname =~ s/\.git$//) &&
2880 ($pname !~ /\/$/) &&
2881 (-d
"$projectroot/$pname")) {
2882 $pr->{'forks'} = "-d $projectroot/$pname";
2888 push @projects, $pr;
2891 $order ||= $default_projects_order;
2892 $from = 0 unless defined $from;
2893 $to = $#projects if (!defined $to || $#projects < $to);
2895 print "<table class=\"project_list\">\n";
2896 unless ($no_header) {
2899 print "<th></th>\n";
2901 if ($order eq "project") {
2902 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2903 print "<th>Project</th>\n";
2906 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2907 -class => "header"}, "Project") .
2910 if ($order eq "descr") {
2911 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2912 print "<th>Description</th>\n";
2915 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2916 -class => "header"}, "Description") .
2919 if ($order eq "owner") {
2920 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2921 print "<th>Owner</th>\n";
2924 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2925 -class => "header"}, "Owner") .
2928 if ($order eq "age") {
2929 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2930 print "<th>Last Change</th>\n";
2933 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2934 -class => "header"}, "Last Change") .
2937 print "<th></th>\n" .
2941 for (my $i = $from; $i <= $to; $i++) {
2942 my $pr = $projects[$i];
2944 print "<tr class=\"dark\">\n";
2946 print "<tr class=\"light\">\n";
2951 if ($pr->{'forks'}) {
2952 print "<!-- $pr->{'forks'} -->\n";
2953 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2957 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2958 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2959 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2960 -class => "list", -title
=> $pr->{'descr_long'}},
2961 esc_html
($pr->{'descr'})) . "</td>\n" .
2962 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2963 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2964 $pr->{'age_string'} . "</td>\n" .
2965 "<td class=\"link\">" .
2966 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2967 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2968 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2969 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2970 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
2974 if (defined $extra) {
2977 print "<td></td>\n";
2979 print "<td colspan=\"5\">$extra</td>\n" .
2985 sub git_shortlog_body
{
2986 # uses global variable $project
2987 my ($commitlist, $from, $to, $refs, $extra) = @_;
2989 my $have_snapshot = gitweb_have_snapshot
();
2991 $from = 0 unless defined $from;
2992 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
2994 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2996 for (my $i = $from; $i <= $to; $i++) {
2997 my %co = %{$commitlist->[$i]};
2998 my $commit = $co{'id'};
2999 my $ref = format_ref_marker
($refs, $commit);
3001 print "<tr class=\"dark\">\n";
3003 print "<tr class=\"light\">\n";
3006 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3007 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3008 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3010 print format_subject_html
($co{'title'}, $co{'title_short'},
3011 href
(action
=>"commit", hash
=>$commit), $ref);
3013 "<td class=\"link\">" .
3014 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3015 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3016 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3017 if ($have_snapshot) {
3018 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
3023 if (defined $extra) {
3025 "<td colspan=\"4\">$extra</td>\n" .
3031 sub git_history_body
{
3032 # Warning: assumes constant type (blob or tree) during history
3033 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3035 $from = 0 unless defined $from;
3036 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3038 print "<table class=\"history\" cellspacing=\"0\">\n";
3040 for (my $i = $from; $i <= $to; $i++) {
3041 my %co = %{$commitlist->[$i]};
3045 my $commit = $co{'id'};
3047 my $ref = format_ref_marker
($refs, $commit);
3050 print "<tr class=\"dark\">\n";
3052 print "<tr class=\"light\">\n";
3055 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3056 # shortlog uses chop_str($co{'author_name'}, 10)
3057 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3059 # originally git_history used chop_str($co{'title'}, 50)
3060 print format_subject_html
($co{'title'}, $co{'title_short'},
3061 href
(action
=>"commit", hash
=>$commit), $ref);
3063 "<td class=\"link\">" .
3064 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3065 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3067 if ($ftype eq 'blob') {
3068 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3069 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3070 if (defined $blob_current && defined $blob_parent &&
3071 $blob_current ne $blob_parent) {
3073 $cgi->a({-href
=> href
(action
=>"blobdiff",
3074 hash
=>$blob_current, hash_parent
=>$blob_parent,
3075 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3076 file_name
=>$file_name)},
3083 if (defined $extra) {
3085 "<td colspan=\"4\">$extra</td>\n" .
3092 # uses global variable $project
3093 my ($taglist, $from, $to, $extra) = @_;
3094 $from = 0 unless defined $from;
3095 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3097 print "<table class=\"tags\" cellspacing=\"0\">\n";
3099 for (my $i = $from; $i <= $to; $i++) {
3100 my $entry = $taglist->[$i];
3102 my $comment = $tag{'subject'};
3104 if (defined $comment) {
3105 $comment_short = chop_str
($comment, 30, 5);
3108 print "<tr class=\"dark\">\n";
3110 print "<tr class=\"light\">\n";
3113 if (defined $tag{'age'}) {
3114 print "<td><i>$tag{'age'}</i></td>\n";
3116 print "<td></td>\n";
3119 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3120 -class => "list name"}, esc_html
($tag{'name'})) .
3123 if (defined $comment) {
3124 print format_subject_html
($comment, $comment_short,
3125 href
(action
=>"tag", hash
=>$tag{'id'}));
3128 "<td class=\"selflink\">";
3129 if ($tag{'type'} eq "tag") {
3130 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3135 "<td class=\"link\">" . " | " .
3136 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3137 if ($tag{'reftype'} eq "commit") {
3138 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3139 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3140 } elsif ($tag{'reftype'} eq "blob") {
3141 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3146 if (defined $extra) {
3148 "<td colspan=\"5\">$extra</td>\n" .
3154 sub git_heads_body
{
3155 # uses global variable $project
3156 my ($headlist, $head, $from, $to, $extra) = @_;
3157 $from = 0 unless defined $from;
3158 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3160 print "<table class=\"heads\" cellspacing=\"0\">\n";
3162 for (my $i = $from; $i <= $to; $i++) {
3163 my $entry = $headlist->[$i];
3165 my $curr = $ref{'id'} eq $head;
3167 print "<tr class=\"dark\">\n";
3169 print "<tr class=\"light\">\n";
3172 print "<td><i>$ref{'age'}</i></td>\n" .
3173 ($curr ? "<td class=\"current_head\">" : "<td>") .
3174 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3175 -class => "list name"},esc_html
($ref{'name'})) .
3177 "<td class=\"link\">" .
3178 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3179 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3180 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3184 if (defined $extra) {
3186 "<td colspan=\"3\">$extra</td>\n" .
3192 sub git_search_grep_body
{
3193 my ($commitlist, $from, $to, $extra) = @_;
3194 $from = 0 unless defined $from;
3195 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3197 print "<table class=\"grep\" cellspacing=\"0\">\n";
3199 for (my $i = $from; $i <= $to; $i++) {
3200 my %co = %{$commitlist->[$i]};
3204 my $commit = $co{'id'};
3206 print "<tr class=\"dark\">\n";
3208 print "<tr class=\"light\">\n";
3211 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3212 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3214 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3215 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3216 my $comment = $co{'comment'};
3217 foreach my $line (@$comment) {
3218 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3219 my $lead = esc_html
($1) || "";
3220 $lead = chop_str
($lead, 30, 10);
3221 my $match = esc_html
($2) || "";
3222 my $trail = esc_html
($3) || "";
3223 $trail = chop_str
($trail, 30, 10);
3224 my $text = "$lead<span class=\"match\">$match</span>$trail";
3225 print chop_str
($text, 80, 5) . "<br/>\n";
3229 "<td class=\"link\">" .
3230 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3232 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3236 if (defined $extra) {
3238 "<td colspan=\"3\">$extra</td>\n" .
3244 ## ======================================================================
3245 ## ======================================================================
3248 sub git_project_list
{
3249 my $order = $cgi->param('o');
3250 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3251 die_error
(undef, "Unknown order parameter");
3254 my @list = git_get_projects_list
();
3256 die_error
(undef, "No projects found");
3260 if (-f
$home_text) {
3261 print "<div class=\"index_include\">\n";
3262 open (my $fd, $home_text);
3267 git_project_list_body
(\
@list, $order);
3272 my $order = $cgi->param('o');
3273 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3274 die_error
(undef, "Unknown order parameter");
3277 my @list = git_get_projects_list
($project);
3279 die_error
(undef, "No forks found");
3283 git_print_page_nav
('','');
3284 git_print_header_div
('summary', "$project forks");
3285 git_project_list_body
(\
@list, $order);
3289 sub git_project_index
{
3290 my @projects = git_get_projects_list
($project);
3293 -type
=> 'text/plain',
3294 -charset
=> 'utf-8',
3295 -content_disposition
=> 'inline; filename="index.aux"');
3297 foreach my $pr (@projects) {
3298 if (!exists $pr->{'owner'}) {
3299 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3302 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3303 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3304 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3305 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3309 print "$path $owner\n";
3314 my $descr = git_get_project_description
($project) || "none";
3315 my %co = parse_commit
("HEAD");
3316 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3317 my $head = $co{'id'};
3319 my $owner = git_get_project_owner
($project);
3321 my $refs = git_get_references
();
3322 # These get_*_list functions return one more to allow us to see if
3323 # there are more ...
3324 my @taglist = git_get_tags_list
(16);
3325 my @headlist = git_get_heads_list
(16);
3327 my ($check_forks) = gitweb_check_feature
('forks');
3330 @forklist = git_get_projects_list
($project);
3334 git_print_page_nav
('summary','', $head);
3336 print "<div class=\"title\"> </div>\n";
3337 print "<table cellspacing=\"0\">\n" .
3338 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3339 "<tr><td>owner</td><td>$owner</td></tr>\n" .
3340 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3341 # use per project git URL list in $projectroot/$project/cloneurl
3342 # or make project git URL from git base URL and project name
3343 my $url_tag = "URL";
3344 my @url_list = git_get_project_url_list
($project);
3345 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3346 foreach my $git_url (@url_list) {
3347 next unless $git_url;
3348 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3353 if (-s
"$projectroot/$project/README.html") {
3354 if (open my $fd, "$projectroot/$project/README.html") {
3355 print "<div class=\"title\">readme</div>\n";
3356 print $_ while (<$fd>);
3361 # we need to request one more than 16 (0..15) to check if
3363 my @commitlist = parse_commits
($head, 17);
3364 git_print_header_div
('shortlog');
3365 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3366 $#commitlist <= 15 ? undef :
3367 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3370 git_print_header_div
('tags');
3371 git_tags_body
(\
@taglist, 0, 15,
3372 $#taglist <= 15 ? undef :
3373 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3377 git_print_header_div
('heads');
3378 git_heads_body
(\
@headlist, $head, 0, 15,
3379 $#headlist <= 15 ? undef :
3380 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3384 git_print_header_div
('forks');
3385 git_project_list_body
(\
@forklist, undef, 0, 15,
3386 $#forklist <= 15 ? undef :
3387 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3395 my $head = git_get_head_hash
($project);
3397 git_print_page_nav
('','', $head,undef,$head);
3398 my %tag = parse_tag
($hash);
3399 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3400 print "<div class=\"title_text\">\n" .
3401 "<table cellspacing=\"0\">\n" .
3403 "<td>object</td>\n" .
3404 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3405 $tag{'object'}) . "</td>\n" .
3406 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3407 $tag{'type'}) . "</td>\n" .
3409 if (defined($tag{'author'})) {
3410 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3411 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3412 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3413 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3416 print "</table>\n\n" .
3418 print "<div class=\"page_body\">";
3419 my $comment = $tag{'comment'};
3420 foreach my $line (@$comment) {
3422 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3432 my ($have_blame) = gitweb_check_feature
('blame');
3434 die_error
('403 Permission denied', "Permission denied");
3436 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3437 $hash_base ||= git_get_head_hash
($project);
3438 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3439 my %co = parse_commit
($hash_base)
3440 or die_error
(undef, "Reading commit failed");
3441 if (!defined $hash) {
3442 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3443 or die_error
(undef, "Error looking up file");
3445 $ftype = git_get_type
($hash);
3446 if ($ftype !~ "blob") {
3447 die_error
('400 Bad Request', "Object is not a blob");
3449 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3450 $file_name, $hash_base)
3451 or die_error
(undef, "Open git-blame failed");
3454 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3457 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3460 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3462 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3463 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3464 git_print_page_path
($file_name, $ftype, $hash_base);
3465 my @rev_color = (qw(light2 dark2));
3466 my $num_colors = scalar(@rev_color);
3467 my $current_color = 0;
3470 <div class="page_body">
3471 <table class="blame">
3472 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3477 last unless defined $_;
3478 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3479 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3480 if (!exists $metainfo{$full_rev}) {
3481 $metainfo{$full_rev} = {};
3483 my $meta = $metainfo{$full_rev};
3486 if (/^(\S+) (.*)$/) {
3492 my $rev = substr($full_rev, 0, 8);
3493 my $author = $meta->{'author'};
3494 my %date = parse_date
($meta->{'author-time'},
3495 $meta->{'author-tz'});
3496 my $date = $date{'iso-tz'};
3498 $current_color = ++$current_color % $num_colors;
3500 print "<tr class=\"$rev_color[$current_color]\">\n";
3502 print "<td class=\"sha1\"";
3503 print " title=\"". esc_html
($author) . ", $date\"";
3504 print " rowspan=\"$group_size\"" if ($group_size > 1);
3506 print $cgi->a({-href
=> href
(action
=>"commit",
3508 file_name
=>$file_name)},
3512 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3513 or die_error
(undef, "Open git-rev-parse failed");
3514 my $parent_commit = <$dd>;
3516 chomp($parent_commit);
3517 my $blamed = href
(action
=> 'blame',
3518 file_name
=> $meta->{'filename'},
3519 hash_base
=> $parent_commit);
3520 print "<td class=\"linenr\">";
3521 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3523 -class => "linenr" },
3526 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3532 or print "Reading blob failed\n";
3539 my ($have_blame) = gitweb_check_feature
('blame');
3541 die_error
('403 Permission denied', "Permission denied");
3543 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3544 $hash_base ||= git_get_head_hash
($project);
3545 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3546 my %co = parse_commit
($hash_base)
3547 or die_error
(undef, "Reading commit failed");
3548 if (!defined $hash) {
3549 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3550 or die_error
(undef, "Error lookup file");
3552 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3553 or die_error
(undef, "Open git-annotate failed");
3556 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3559 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3562 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3564 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3565 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3566 git_print_page_path
($file_name, 'blob', $hash_base);
3567 print "<div class=\"page_body\">\n";
3569 <table class="blame">
3578 my @line_class = (qw(light dark));
3579 my $line_class_len = scalar (@line_class);
3580 my $line_class_num = $#line_class;
3581 while (my $line = <$fd>) {
3593 $line_class_num = ($line_class_num + 1) % $line_class_len;
3595 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3602 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3605 $short_rev = substr ($long_rev, 0, 8);
3606 $age = time () - $time;
3607 $age_str = age_string
($age);
3608 $age_str =~ s/ / /g;
3609 $age_class = age_class
($age);
3610 $author = esc_html
($author);
3611 $author =~ s/ / /g;
3613 $data = untabify
($data);
3614 $data = esc_html
($data);
3617 <tr class="$line_class[$line_class_num]">
3618 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3619 <td class="$age_class">$age_str</td>
3621 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3622 <td class="pre">$data</td>
3625 } # while (my $line = <$fd>)
3626 print "</table>\n\n";
3628 or print "Reading blob failed.\n";
3634 my $head = git_get_head_hash
($project);
3636 git_print_page_nav
('','', $head,undef,$head);
3637 git_print_header_div
('summary', $project);
3639 my @tagslist = git_get_tags_list
();
3641 git_tags_body
(\
@tagslist);
3647 my $head = git_get_head_hash
($project);
3649 git_print_page_nav
('','', $head,undef,$head);
3650 git_print_header_div
('summary', $project);
3652 my @headslist = git_get_heads_list
();
3654 git_heads_body
(\
@headslist, $head);
3659 sub git_blob_plain
{
3662 if (!defined $hash) {
3663 if (defined $file_name) {
3664 my $base = $hash_base || git_get_head_hash
($project);
3665 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3666 or die_error
(undef, "Error lookup file");
3668 die_error
(undef, "No file name defined");
3670 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3671 # blobs defined by non-textual hash id's can be cached
3676 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3677 or die_error
(undef, "Couldn't cat $file_name, $hash");
3679 $type ||= blob_mimetype
($fd, $file_name);
3681 # save as filename, even when no $file_name is given
3682 my $save_as = "$hash";
3683 if (defined $file_name) {
3684 $save_as = $file_name;
3685 } elsif ($type =~ m/^text\//) {
3692 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3694 binmode STDOUT
, ':raw';
3696 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3704 if (!defined $hash) {
3705 if (defined $file_name) {
3706 my $base = $hash_base || git_get_head_hash
($project);
3707 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3708 or die_error
(undef, "Error lookup file");
3710 die_error
(undef, "No file name defined");
3712 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3713 # blobs defined by non-textual hash id's can be cached
3717 my ($have_blame) = gitweb_check_feature
('blame');
3718 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3719 or die_error
(undef, "Couldn't cat $file_name, $hash");
3720 my $mimetype = blob_mimetype
($fd, $file_name);
3721 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3723 return git_blob_plain
($mimetype);
3725 # we can have blame only for text/* mimetype
3726 $have_blame &&= ($mimetype =~ m!^text/!);
3728 git_header_html
(undef, $expires);
3729 my $formats_nav = '';
3730 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3731 if (defined $file_name) {
3734 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3735 hash
=>$hash, file_name
=>$file_name)},
3740 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3741 hash
=>$hash, file_name
=>$file_name)},
3744 $cgi->a({-href
=> href
(action
=>"blob_plain",
3745 hash
=>$hash, file_name
=>$file_name)},
3748 $cgi->a({-href
=> href
(action
=>"blob",
3749 hash_base
=>"HEAD", file_name
=>$file_name)},
3753 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3755 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3756 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3758 print "<div class=\"page_nav\">\n" .
3759 "<br/><br/></div>\n" .
3760 "<div class=\"title\">$hash</div>\n";
3762 git_print_page_path
($file_name, "blob", $hash_base);
3763 print "<div class=\"page_body\">\n";
3764 if ($mimetype =~ m!^text/!) {
3766 while (my $line = <$fd>) {
3769 $line = untabify
($line);
3770 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3771 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3773 } elsif ($mimetype =~ m!^image/!) {
3774 print qq
!<img type
="$mimetype"!;
3776 print qq
! alt
="$file_name" title
="$file_name"!;
3779 href(action=>"blob_plain
", hash=>$hash,
3780 hash_base=>$hash_base, file_name=>$file_name) .
3784 or print "Reading blob failed.\n";
3790 my $have_snapshot = gitweb_have_snapshot
();
3792 if (!defined $hash_base) {
3793 $hash_base = "HEAD";
3795 if (!defined $hash) {
3796 if (defined $file_name) {
3797 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3803 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3804 or die_error
(undef, "Open git-ls-tree failed");
3805 my @entries = map { chomp; $_ } <$fd>;
3806 close $fd or die_error
(undef, "Reading tree failed");
3809 my $refs = git_get_references
();
3810 my $ref = format_ref_marker
($refs, $hash_base);
3813 my ($have_blame) = gitweb_check_feature
('blame');
3814 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3816 if (defined $file_name) {
3818 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3819 hash
=>$hash, file_name
=>$file_name)},
3821 $cgi->a({-href
=> href
(action
=>"tree",
3822 hash_base
=>"HEAD", file_name
=>$file_name)},
3825 if ($have_snapshot) {
3826 # FIXME: Should be available when we have no hash base as well.
3828 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3831 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3832 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3835 print "<div class=\"page_nav\">\n";
3836 print "<br/><br/></div>\n";
3837 print "<div class=\"title\">$hash</div>\n";
3839 if (defined $file_name) {
3840 $basedir = $file_name;
3841 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3845 git_print_page_path
($file_name, 'tree', $hash_base);
3846 print "<div class=\"page_body\">\n";
3847 print "<table cellspacing=\"0\">\n";
3849 # '..' (top directory) link if possible
3850 if (defined $hash_base &&
3851 defined $file_name && $file_name =~ m![^/]+$!) {
3853 print "<tr class=\"dark\">\n";
3855 print "<tr class=\"light\">\n";
3859 my $up = $file_name;
3860 $up =~ s!/?[^/]+$!!;
3861 undef $up unless $up;
3862 # based on git_print_tree_entry
3863 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3864 print '<td class="list">';
3865 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3869 print "<td class=\"link\"></td>\n";
3873 foreach my $line (@entries) {
3874 my %t = parse_ls_tree_line
($line, -z
=> 1);
3877 print "<tr class=\"dark\">\n";
3879 print "<tr class=\"light\">\n";
3883 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3887 print "</table>\n" .
3893 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3894 my $have_snapshot = (defined $ctype && defined $suffix);
3895 if (!$have_snapshot) {
3896 die_error
('403 Permission denied', "Permission denied");
3899 if (!defined $hash) {
3900 $hash = git_get_head_hash
($project);
3903 my $filename = decode_utf8
(basename
($project)) . "-$hash.tar.$suffix";
3906 -type
=> "application/$ctype",
3907 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3908 -status
=> '200 OK');
3910 my $git = git_cmd_str
();
3911 my $name = $project;
3912 $name =~ s/\047/\047\\\047\047/g;
3914 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3915 or die_error
(undef, "Execute git-tar-tree failed");
3916 binmode STDOUT
, ':raw';
3918 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3924 my $head = git_get_head_hash
($project);
3925 if (!defined $hash) {
3928 if (!defined $page) {
3931 my $refs = git_get_references
();
3933 my @commitlist = parse_commits
($hash, 101, (100 * $page));
3935 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
3938 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3941 my %co = parse_commit
($hash);
3943 git_print_header_div
('summary', $project);
3944 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3946 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
3947 for (my $i = 0; $i <= $to; $i++) {
3948 my %co = %{$commitlist[$i]};
3950 my $commit = $co{'id'};
3951 my $ref = format_ref_marker
($refs, $commit);
3952 my %ad = parse_date
($co{'author_epoch'});
3953 git_print_header_div
('commit',
3954 "<span class=\"age\">$co{'age_string'}</span>" .
3955 esc_html
($co{'title'}) . $ref,
3957 print "<div class=\"title_text\">\n" .
3958 "<div class=\"log_link\">\n" .
3959 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3961 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3963 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3966 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3969 print "<div class=\"log_body\">\n";
3970 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
3973 if ($#commitlist >= 100) {
3974 print "<div class=\"page_nav\">\n";
3975 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
3976 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3983 $hash ||= $hash_base || "HEAD";
3984 my %co = parse_commit
($hash);
3986 die_error
(undef, "Unknown commit object");
3988 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3989 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3991 my $parent = $co{'parent'};
3992 my $parents = $co{'parents'}; # listref
3994 # we need to prepare $formats_nav before any parameter munging
3996 if (!defined $parent) {
3998 $formats_nav .= '(initial)';
3999 } elsif (@$parents == 1) {
4000 # single parent commit
4003 $cgi->a({-href
=> href
(action
=>"commit",
4005 esc_html
(substr($parent, 0, 7))) .
4012 $cgi->a({-href
=> href
(action
=>"commit",
4014 esc_html
(substr($_, 0, 7)));
4019 if (!defined $parent) {
4023 if (@$parents <= 1) {
4024 # difftree output is not printed for merges
4025 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4026 @diff_opts, $parent, $hash, "--"
4027 or die_error
(undef, "Open git-diff-tree failed");
4028 @difftree = map { chomp; $_ } <$fd>;
4029 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4032 # non-textual hash id's can be cached
4034 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4037 my $refs = git_get_references
();
4038 my $ref = format_ref_marker
($refs, $co{'id'});
4040 my $have_snapshot = gitweb_have_snapshot
();
4042 git_header_html
(undef, $expires);
4043 git_print_page_nav
('commit', '',
4044 $hash, $co{'tree'}, $hash,
4047 if (defined $co{'parent'}) {
4048 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4050 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4052 print "<div class=\"title_text\">\n" .
4053 "<table cellspacing=\"0\">\n";
4054 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4056 "<td></td><td> $ad{'rfc2822'}";
4057 if ($ad{'hour_local'} < 6) {
4058 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4059 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4061 printf(" (%02d:%02d %s)",
4062 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4066 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4067 print "<tr><td></td><td> $cd{'rfc2822'}" .
4068 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4070 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4073 "<td class=\"sha1\">" .
4074 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4075 class => "list"}, $co{'tree'}) .
4077 "<td class=\"link\">" .
4078 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4080 if ($have_snapshot) {
4082 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
4087 foreach my $par (@$parents) {
4090 "<td class=\"sha1\">" .
4091 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4092 class => "list"}, $par) .
4094 "<td class=\"link\">" .
4095 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4097 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4104 print "<div class=\"page_body\">\n";
4105 git_print_log
($co{'comment'});
4108 if (@$parents <= 1) {
4109 # do not output difftree/whatchanged for merges
4110 git_difftree_body
(\
@difftree, $hash, $parent);
4117 # object is defined by:
4118 # - hash or hash_base alone
4119 # - hash_base and file_name
4122 # - hash or hash_base alone
4123 if ($hash || ($hash_base && !defined $file_name)) {
4124 my $object_id = $hash || $hash_base;
4126 my $git_command = git_cmd_str
();
4127 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4128 or die_error
('404 Not Found', "Object does not exist");
4132 or die_error
('404 Not Found', "Object does not exist");
4134 # - hash_base and file_name
4135 } elsif ($hash_base && defined $file_name) {
4136 $file_name =~ s
,/+$,,;
4138 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4139 or die_error
('404 Not Found', "Base object does not exist");
4141 # here errors should not hapen
4142 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4143 or die_error
(undef, "Open git-ls-tree failed");
4147 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4148 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4149 die_error
('404 Not Found', "File or directory for given base does not exist");
4154 die_error
('404 Not Found', "Not enough information to find object");
4157 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4158 hash
=>$hash, hash_base
=>$hash_base,
4159 file_name
=>$file_name),
4160 -status
=> '302 Found');
4164 my $format = shift || 'html';
4171 # preparing $fd and %diffinfo for git_patchset_body
4173 if (defined $hash_base && defined $hash_parent_base) {
4174 if (defined $file_name) {
4176 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4177 $hash_parent_base, $hash_base,
4178 "--", (defined $file_parent ? $file_parent : ()), $file_name
4179 or die_error
(undef, "Open git-diff-tree failed");
4180 @difftree = map { chomp; $_ } <$fd>;
4182 or die_error
(undef, "Reading git-diff-tree failed");
4184 or die_error
('404 Not Found', "Blob diff not found");
4186 } elsif (defined $hash &&
4187 $hash =~ /[0-9a-fA-F]{40}/) {
4188 # try to find filename from $hash
4190 # read filtered raw output
4191 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4192 $hash_parent_base, $hash_base, "--"
4193 or die_error
(undef, "Open git-diff-tree failed");
4195 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4197 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4198 map { chomp; $_ } <$fd>;
4200 or die_error
(undef, "Reading git-diff-tree failed");
4202 or die_error
('404 Not Found', "Blob diff not found");
4205 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4208 if (@difftree > 1) {
4209 die_error
('404 Not Found', "Ambiguous blob diff specification");
4212 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4213 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4214 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4216 $hash_parent ||= $diffinfo{'from_id'};
4217 $hash ||= $diffinfo{'to_id'};
4219 # non-textual hash id's can be cached
4220 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4221 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4226 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4227 '-p', ($format eq 'html' ? "--full-index" : ()),
4228 $hash_parent_base, $hash_base,
4229 "--", (defined $file_parent ? $file_parent : ()), $file_name
4230 or die_error
(undef, "Open git-diff-tree failed");
4233 # old/legacy style URI
4234 if (!%diffinfo && # if new style URI failed
4235 defined $hash && defined $hash_parent) {
4236 # fake git-diff-tree raw output
4237 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4238 $diffinfo{'from_id'} = $hash_parent;
4239 $diffinfo{'to_id'} = $hash;
4240 if (defined $file_name) {
4241 if (defined $file_parent) {
4242 $diffinfo{'status'} = '2';
4243 $diffinfo{'from_file'} = $file_parent;
4244 $diffinfo{'to_file'} = $file_name;
4245 } else { # assume not renamed
4246 $diffinfo{'status'} = '1';
4247 $diffinfo{'from_file'} = $file_name;
4248 $diffinfo{'to_file'} = $file_name;
4250 } else { # no filename given
4251 $diffinfo{'status'} = '2';
4252 $diffinfo{'from_file'} = $hash_parent;
4253 $diffinfo{'to_file'} = $hash;
4256 # non-textual hash id's can be cached
4257 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4258 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4263 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4264 '-p', ($format eq 'html' ? "--full-index" : ()),
4265 $hash_parent, $hash, "--"
4266 or die_error
(undef, "Open git-diff failed");
4268 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4273 if ($format eq 'html') {
4275 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4276 hash
=>$hash, hash_parent
=>$hash_parent,
4277 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4278 file_name
=>$file_name, file_parent
=>$file_parent)},
4280 git_header_html
(undef, $expires);
4281 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4282 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4283 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4285 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4286 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4288 if (defined $file_name) {
4289 git_print_page_path
($file_name, "blob", $hash_base);
4291 print "<div class=\"page_path\"></div>\n";
4294 } elsif ($format eq 'plain') {
4296 -type
=> 'text/plain',
4297 -charset
=> 'utf-8',
4298 -expires
=> $expires,
4299 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4301 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4304 die_error
(undef, "Unknown blobdiff format");
4308 if ($format eq 'html') {
4309 print "<div class=\"page_body\">\n";
4311 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4314 print "</div>\n"; # class="page_body"
4318 while (my $line = <$fd>) {
4319 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4320 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4324 last if $line =~ m!^\+\+\+!;
4332 sub git_blobdiff_plain
{
4333 git_blobdiff
('plain');
4336 sub git_commitdiff
{
4337 my $format = shift || 'html';
4338 $hash ||= $hash_base || "HEAD";
4339 my %co = parse_commit
($hash);
4341 die_error
(undef, "Unknown commit object");
4344 # we need to prepare $formats_nav before any parameter munging
4346 if ($format eq 'html') {
4348 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4349 hash
=>$hash, hash_parent
=>$hash_parent)},
4352 if (defined $hash_parent) {
4353 # commitdiff with two commits given
4354 my $hash_parent_short = $hash_parent;
4355 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4356 $hash_parent_short = substr($hash_parent, 0, 7);
4360 $cgi->a({-href
=> href
(action
=>"commitdiff",
4361 hash
=>$hash_parent)},
4362 esc_html
($hash_parent_short)) .
4364 } elsif (!$co{'parent'}) {
4366 $formats_nav .= ' (initial)';
4367 } elsif (scalar @{$co{'parents'}} == 1) {
4368 # single parent commit
4371 $cgi->a({-href
=> href
(action
=>"commitdiff",
4372 hash
=>$co{'parent'})},
4373 esc_html
(substr($co{'parent'}, 0, 7))) .
4380 $cgi->a({-href
=> href
(action
=>"commitdiff",
4382 esc_html
(substr($_, 0, 7)));
4383 } @{$co{'parents'}} ) .
4388 if (!defined $hash_parent) {
4389 $hash_parent = $co{'parent'} || '--root';
4395 if ($format eq 'html') {
4396 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4397 "--no-commit-id", "--patch-with-raw", "--full-index",
4398 $hash_parent, $hash, "--"
4399 or die_error
(undef, "Open git-diff-tree failed");
4401 while (my $line = <$fd>) {
4403 # empty line ends raw part of diff-tree output
4405 push @difftree, $line;
4408 } elsif ($format eq 'plain') {
4409 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4410 '-p', $hash_parent, $hash, "--"
4411 or die_error
(undef, "Open git-diff-tree failed");
4414 die_error
(undef, "Unknown commitdiff format");
4417 # non-textual hash id's can be cached
4419 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4423 # write commit message
4424 if ($format eq 'html') {
4425 my $refs = git_get_references
();
4426 my $ref = format_ref_marker
($refs, $co{'id'});
4428 git_header_html
(undef, $expires);
4429 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4430 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4431 git_print_authorship
(\
%co);
4432 print "<div class=\"page_body\">\n";
4433 if (@{$co{'comment'}} > 1) {
4434 print "<div class=\"log\">\n";
4435 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4436 print "</div>\n"; # class="log"
4439 } elsif ($format eq 'plain') {
4440 my $refs = git_get_references
("tags");
4441 my $tagname = git_get_rev_name_tags
($hash);
4442 my $filename = basename
($project) . "-$hash.patch";
4445 -type
=> 'text/plain',
4446 -charset
=> 'utf-8',
4447 -expires
=> $expires,
4448 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4449 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4452 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4453 Subject: $co{'title'}
4455 print "X-Git-Tag: $tagname\n" if $tagname;
4456 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4458 foreach my $line (@{$co{'comment'}}) {
4465 if ($format eq 'html') {
4466 git_difftree_body
(\
@difftree, $hash, $hash_parent);
4469 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
4471 print "</div>\n"; # class="page_body"
4474 } elsif ($format eq 'plain') {
4478 or print "Reading git-diff-tree failed\n";
4482 sub git_commitdiff_plain
{
4483 git_commitdiff
('plain');
4487 if (!defined $hash_base) {
4488 $hash_base = git_get_head_hash
($project);
4490 if (!defined $page) {
4494 my %co = parse_commit
($hash_base);
4496 die_error
(undef, "Unknown commit object");
4499 my $refs = git_get_references
();
4500 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4502 if (!defined $hash && defined $file_name) {
4503 $hash = git_get_hash_by_path
($hash_base, $file_name);
4505 if (defined $hash) {
4506 $ftype = git_get_type
($hash);
4509 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4511 my $paging_nav = '';
4514 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4515 file_name
=>$file_name)},
4517 $paging_nav .= " ⋅ " .
4518 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4519 file_name
=>$file_name, page
=>$page-1),
4520 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4522 $paging_nav .= "first";
4523 $paging_nav .= " ⋅ prev";
4525 if ($#commitlist >= 100) {
4526 $paging_nav .= " ⋅ " .
4527 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4528 file_name
=>$file_name, page
=>$page+1),
4529 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4531 $paging_nav .= " ⋅ next";
4534 if ($#commitlist >= 100) {
4536 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4537 file_name
=>$file_name, page
=>$page+1),
4538 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4542 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4543 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4544 git_print_page_path
($file_name, $ftype, $hash_base);
4546 git_history_body
(\
@commitlist, 0, 99,
4547 $refs, $hash_base, $ftype, $next_link);
4553 my ($have_search) = gitweb_check_feature
('search');
4554 if (!$have_search) {
4555 die_error
('403 Permission denied', "Permission denied");
4557 if (!defined $searchtext) {
4558 die_error
(undef, "Text field empty");
4560 if (!defined $hash) {
4561 $hash = git_get_head_hash
($project);
4563 my %co = parse_commit
($hash);
4565 die_error
(undef, "Unknown commit object");
4567 if (!defined $page) {
4571 $searchtype ||= 'commit';
4572 if ($searchtype eq 'pickaxe') {
4573 # pickaxe may take all resources of your box and run for several minutes
4574 # with every query - so decide by yourself how public you make this feature
4575 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4576 if (!$have_pickaxe) {
4577 die_error
('403 Permission denied', "Permission denied");
4583 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4585 if ($searchtype eq 'commit') {
4586 $greptype = "--grep=";
4587 } elsif ($searchtype eq 'author') {
4588 $greptype = "--author=";
4589 } elsif ($searchtype eq 'committer') {
4590 $greptype = "--committer=";
4592 $greptype .= $searchtext;
4593 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4595 my $paging_nav = '';
4598 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4599 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4601 $paging_nav .= " ⋅ " .
4602 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4603 searchtext
=>$searchtext, searchtype
=>$searchtype,
4605 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4607 $paging_nav .= "first";
4608 $paging_nav .= " ⋅ prev";
4610 if ($#commitlist >= 100) {
4611 $paging_nav .= " ⋅ " .
4612 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4613 searchtext
=>$searchtext, searchtype
=>$searchtype,
4615 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4617 $paging_nav .= " ⋅ next";
4620 if ($#commitlist >= 100) {
4622 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4623 searchtext
=>$searchtext, searchtype
=>$searchtype,
4625 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4628 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4629 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4630 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4633 if ($searchtype eq 'pickaxe') {
4634 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4635 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4637 print "<table cellspacing=\"0\">\n";
4640 my $git_command = git_cmd_str
();
4641 open my $fd, "-|", "$git_command rev-list $hash | " .
4642 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
4645 while (my $line = <$fd>) {
4646 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4649 $set{'from_id'} = $3;
4651 $set{'id'} = $set{'to_id'};
4652 if ($set{'id'} =~ m/0{40}/) {
4653 $set{'id'} = $set{'from_id'};
4655 if ($set{'id'} =~ m/0{40}/) {
4659 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4662 print "<tr class=\"dark\">\n";
4664 print "<tr class=\"light\">\n";
4667 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4668 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4670 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4671 -class => "list subject"},
4672 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4673 while (my $setref = shift @files) {
4675 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4676 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4678 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4682 "<td class=\"link\">" .
4683 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4685 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4689 %co = parse_commit
($1);
4699 sub git_search_help
{
4701 git_print_page_nav
('','', $hash,$hash,$hash);
4704 <dt><b>commit</b></dt>
4705 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4706 <dt><b>author</b></dt>
4707 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4708 <dt><b>committer</b></dt>
4709 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4711 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4712 if ($have_pickaxe) {
4714 <dt><b>pickaxe</b></dt>
4715 <dd>All commits that caused the string to appear or disappear from any file (changes that
4716 added, removed or "modified" the string) will be listed. This search can take a while and
4717 takes a lot of strain on the server, so please use it wisely.</dd>
4725 my $head = git_get_head_hash
($project);
4726 if (!defined $hash) {
4729 if (!defined $page) {
4732 my $refs = git_get_references
();
4734 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4736 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
4738 if ($#commitlist >= 100) {
4740 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4741 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4745 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4746 git_print_header_div
('summary', $project);
4748 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
4753 ## ......................................................................
4754 ## feeds (RSS, Atom; OPML)
4757 my $format = shift || 'atom';
4758 my ($have_blame) = gitweb_check_feature
('blame');
4760 # Atom: http://www.atomenabled.org/developers/syndication/
4761 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4762 if ($format ne 'rss' && $format ne 'atom') {
4763 die_error
(undef, "Unknown web feed format");
4766 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4767 my $head = $hash || 'HEAD';
4768 my @commitlist = parse_commits
($head, 150);
4772 my $content_type = "application/$format+xml";
4773 if (defined $cgi->http('HTTP_ACCEPT') &&
4774 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4775 # browser (feed reader) prefers text/xml
4776 $content_type = 'text/xml';
4778 if (defined($commitlist[0])) {
4779 %latest_commit = %{$commitlist[0]};
4780 %latest_date = parse_date
($latest_commit{'author_epoch'});
4782 -type
=> $content_type,
4783 -charset
=> 'utf-8',
4784 -last_modified
=> $latest_date{'rfc2822'});
4787 -type
=> $content_type,
4788 -charset
=> 'utf-8');
4791 # Optimization: skip generating the body if client asks only
4792 # for Last-Modified date.
4793 return if ($cgi->request_method() eq 'HEAD');
4796 my $title = "$site_name - $project/$action";
4797 my $feed_type = 'log';
4798 if (defined $hash) {
4799 $title .= " - '$hash'";
4800 $feed_type = 'branch log';
4801 if (defined $file_name) {
4802 $title .= " :: $file_name";
4803 $feed_type = 'history';
4805 } elsif (defined $file_name) {
4806 $title .= " - $file_name";
4807 $feed_type = 'history';
4809 $title .= " $feed_type";
4810 my $descr = git_get_project_description
($project);
4811 if (defined $descr) {
4812 $descr = esc_html
($descr);
4814 $descr = "$project " .
4815 ($format eq 'rss' ? 'RSS' : 'Atom') .
4818 my $owner = git_get_project_owner
($project);
4819 $owner = esc_html
($owner);
4823 if (defined $file_name) {
4824 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
4825 } elsif (defined $hash) {
4826 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
4828 $alt_url = href
(-full
=>1, action
=>"summary");
4830 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
4831 if ($format eq 'rss') {
4833 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
4836 print "<title>$title</title>\n" .
4837 "<link>$alt_url</link>\n" .
4838 "<description>$descr</description>\n" .
4839 "<language>en</language>\n";
4840 } elsif ($format eq 'atom') {
4842 <feed xmlns="http://www.w3.org/2005/Atom">
4844 print "<title>$title</title>\n" .
4845 "<subtitle>$descr</subtitle>\n" .
4846 '<link rel="alternate" type="text/html" href="' .
4847 $alt_url . '" />' . "\n" .
4848 '<link rel="self" type="' . $content_type . '" href="' .
4849 $cgi->self_url() . '" />' . "\n" .
4850 "<id>" . href
(-full
=>1) . "</id>\n" .
4851 # use project owner for feed author
4852 "<author><name>$owner</name></author>\n";
4853 if (defined $favicon) {
4854 print "<icon>" . esc_url
($favicon) . "</icon>\n";
4856 if (defined $logo_url) {
4857 # not twice as wide as tall: 72 x 27 pixels
4858 print "<logo>" . esc_url
($logo) . "</logo>\n";
4860 if (! %latest_date) {
4861 # dummy date to keep the feed valid until commits trickle in:
4862 print "<updated>1970-01-01T00:00:00Z</updated>\n";
4864 print "<updated>$latest_date{'iso-8601'}</updated>\n";
4869 for (my $i = 0; $i <= $#commitlist; $i++) {
4870 my %co = %{$commitlist[$i]};
4871 my $commit = $co{'id'};
4872 # we read 150, we always show 30 and the ones more recent than 48 hours
4873 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
4876 my %cd = parse_date
($co{'author_epoch'});
4878 # get list of changed files
4879 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4880 $co{'parent'}, $co{'id'}, "--", (defined $file_name ? $file_name : ())
4882 my @difftree = map { chomp; $_ } <$fd>;
4886 # print element (entry, item)
4887 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
4888 if ($format eq 'rss') {
4890 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
4891 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
4892 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
4893 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
4894 "<link>$co_url</link>\n" .
4895 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
4896 "<content:encoded>" .
4898 } elsif ($format eq 'atom') {
4900 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
4901 "<updated>$cd{'iso-8601'}</updated>\n" .
4903 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
4904 if ($co{'author_email'}) {
4905 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
4907 print "</author>\n" .
4908 # use committer for contributor
4910 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
4911 if ($co{'committer_email'}) {
4912 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
4914 print "</contributor>\n" .
4915 "<published>$cd{'iso-8601'}</published>\n" .
4916 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
4917 "<id>$co_url</id>\n" .
4918 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
4919 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
4921 my $comment = $co{'comment'};
4923 foreach my $line (@$comment) {
4924 $line = esc_html
($line);
4927 print "</pre><ul>\n";
4928 foreach my $difftree_line (@difftree) {
4929 my %difftree = parse_difftree_raw_line
($difftree_line);
4930 next if !$difftree{'from_id'};
4932 my $file = $difftree{'file'} || $difftree{'to_file'};
4936 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
4937 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
4938 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
4939 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
4940 -title
=> "diff"}, 'D');
4942 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
4943 file_name
=>$file, hash_base
=>$commit),
4944 -title
=> "blame"}, 'B');
4946 # if this is not a feed of a file history
4947 if (!defined $file_name || $file_name ne $file) {
4948 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
4949 file_name
=>$file, hash
=>$commit),
4950 -title
=> "history"}, 'H');
4952 $file = esc_path
($file);
4956 if ($format eq 'rss') {
4957 print "</ul>]]>\n" .
4958 "</content:encoded>\n" .
4960 } elsif ($format eq 'atom') {
4961 print "</ul>\n</div>\n" .
4968 if ($format eq 'rss') {
4969 print "</channel>\n</rss>\n";
4970 } elsif ($format eq 'atom') {
4984 my @list = git_get_projects_list
();
4986 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
4988 <?xml version="1.0" encoding="utf-8"?>
4989 <opml version="1.0">
4991 <title>$site_name OPML Export</title>
4994 <outline text="git RSS feeds">
4997 foreach my $pr (@list) {
4999 my $head = git_get_head_hash
($proj{'path'});
5000 if (!defined $head) {
5003 $git_dir = "$projectroot/$proj{'path'}";
5004 my %co = parse_commit
($head);
5009 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5010 my $rss = "$my_url?p=$proj{'path'};a=rss";
5011 my $html = "$my_url?p=$proj{'path'};a=summary";
5012 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";