3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI-
>compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # core git executable to use
31 # this can just be "git" if your webserver has a sensible PATH
32 our $GIT = "++GIT_BINDIR++/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "++GITWEB_PROJECTROOT++";
38 # target of the home link on top of all pages
39 our $home_link = $my_uri || "/";
41 # string of the home link on top of all pages
42 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
44 # name of your site or organization to appear in page titles
45 # replace this with something more descriptive for clearer bookmarks
46 our $site_name = "++GITWEB_SITENAME++"
47 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
49 # filename of html text to include at top of each page
50 our $site_header = "++GITWEB_SITE_HEADER++";
51 # html text to include at home page
52 our $home_text = "++GITWEB_HOMETEXT++";
53 # filename of html text to include at bottom of each page
54 our $site_footer = "++GITWEB_SITE_FOOTER++";
57 our @stylesheets = ("++GITWEB_CSS++");
58 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
59 our $stylesheet = undef;
61 # URI of GIT logo (72x27 size)
62 our $logo = "++GITWEB_LOGO++";
63 # URI of GIT favicon, assumed to be image/png type
64 our $favicon = "++GITWEB_FAVICON++";
66 # URI and label (title) of GIT logo link
67 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
68 #our $logo_label = "git documentation";
69 our $logo_url = "http://git.or.cz/";
70 our $logo_label = "git homepage";
72 # source of projects list
73 our $projects_list = "++GITWEB_LIST++";
75 # default order of projects list
76 # valid values are none, project, descr, owner, and age
77 our $default_projects_order = "project";
79 # show repository only if this file exists
80 # (only effective if this variable evaluates to true)
81 our $export_ok = "++GITWEB_EXPORT_OK++";
83 # only allow viewing of repositories also shown on the overview page
84 our $strict_export = "++GITWEB_STRICT_EXPORT++";
86 # list of git base URLs used for URL to where fetch project from,
87 # i.e. full URL is "$git_base_url/$project"
88 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
90 # default blob_plain mimetype and default charset for text/plain blob
91 our $default_blob_plain_mimetype = 'text/plain';
92 our $default_text_plain_charset = undef;
94 # file to use for guessing MIME types before trying /etc/mime.types
95 # (relative to the current git repository)
96 our $mimetypes_file = undef;
98 # You define site-wide feature defaults here; override them with
99 # $GITWEB_CONFIG as necessary.
102 # 'sub' => feature-sub (subroutine),
103 # 'override' => allow-override (boolean),
104 # 'default' => [ default options...] (array reference)}
106 # if feature is overridable (it means that allow-override has true value),
107 # then feature-sub will be called with default options as parameters;
108 # return value of feature-sub indicates if to enable specified feature
110 # if there is no 'sub' key (no feature-sub), then feature cannot be
113 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
115 # Enable the 'blame' blob view, showing the last commit that modified
116 # each line in the file. This can be very CPU-intensive.
118 # To enable system wide have in $GITWEB_CONFIG
119 # $feature{'blame'}{'default'} = [1];
120 # To have project specific config enable override in $GITWEB_CONFIG
121 # $feature{'blame'}{'override'} = 1;
122 # and in project config gitweb.blame = 0|1;
124 'sub' => \
&feature_blame
,
128 # Enable the 'snapshot' link, providing a compressed tarball of any
129 # tree. This can potentially generate high traffic if you have large
132 # To disable system wide have in $GITWEB_CONFIG
133 # $feature{'snapshot'}{'default'} = [undef];
134 # To have project specific config enable override in $GITWEB_CONFIG
135 # $feature{'snapshot'}{'override'} = 1;
136 # and in project config gitweb.snapshot = none|gzip|bzip2;
138 'sub' => \
&feature_snapshot
,
140 # => [content-encoding, suffix, program]
141 'default' => ['x-gzip', 'gz', 'gzip']},
143 # Enable text search, which will list the commits which match author,
144 # committer or commit text to a given string. Enabled by default.
145 # Project specific override is not supported.
150 # Enable the pickaxe search, which will list the commits that modified
151 # a given string in a file. This can be practical and quite faster
152 # alternative to 'blame', but still potentially CPU-intensive.
154 # To enable system wide have in $GITWEB_CONFIG
155 # $feature{'pickaxe'}{'default'} = [1];
156 # To have project specific config enable override in $GITWEB_CONFIG
157 # $feature{'pickaxe'}{'override'} = 1;
158 # and in project config gitweb.pickaxe = 0|1;
160 'sub' => \
&feature_pickaxe
,
164 # Make gitweb use an alternative format of the URLs which can be
165 # more readable and natural-looking: project name is embedded
166 # directly in the path and the query string contains other
167 # auxiliary information. All gitweb installations recognize
168 # URL in either format; this configures in which formats gitweb
171 # To enable system wide have in $GITWEB_CONFIG
172 # $feature{'pathinfo'}{'default'} = [1];
173 # Project specific override is not supported.
175 # Note that you will need to change the default location of CSS,
176 # favicon, logo and possibly other files to an absolute URL. Also,
177 # if gitweb.cgi serves as your indexfile, you will need to force
178 # $my_uri to contain the script name in your $GITWEB_CONFIG.
183 # Make gitweb consider projects in project root subdirectories
184 # to be forks of existing projects. Given project $projname.git,
185 # projects matching $projname/*.git will not be shown in the main
186 # projects list, instead a '+' mark will be added to $projname
187 # there and a 'forks' view will be enabled for the project, listing
188 # all the forks. If project list is taken from a file, forks have
189 # to be listed after the main project.
191 # To enable system wide have in $GITWEB_CONFIG
192 # $feature{'forks'}{'default'} = [1];
193 # Project specific override is not supported.
199 sub gitweb_check_feature
{
201 return unless exists $feature{$name};
202 my ($sub, $override, @defaults) = (
203 $feature{$name}{'sub'},
204 $feature{$name}{'override'},
205 @{$feature{$name}{'default'}});
206 if (!$override) { return @defaults; }
208 warn "feature $name is not overrideable";
211 return $sub->(@defaults);
215 my ($val) = git_get_project_config
('blame', '--bool');
217 if ($val eq 'true') {
219 } elsif ($val eq 'false') {
226 sub feature_snapshot
{
227 my ($ctype, $suffix, $command) = @_;
229 my ($val) = git_get_project_config
('snapshot');
231 if ($val eq 'gzip') {
232 return ('x-gzip', 'gz', 'gzip');
233 } elsif ($val eq 'bzip2') {
234 return ('x-bzip2', 'bz2', 'bzip2');
235 } elsif ($val eq 'none') {
239 return ($ctype, $suffix, $command);
242 sub gitweb_have_snapshot
{
243 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
244 my $have_snapshot = (defined $ctype && defined $suffix);
246 return $have_snapshot;
249 sub feature_pickaxe
{
250 my ($val) = git_get_project_config
('pickaxe', '--bool');
252 if ($val eq 'true') {
254 } elsif ($val eq 'false') {
261 # checking HEAD file with -e is fragile if the repository was
262 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
264 sub check_head_link
{
266 my $headfile = "$dir/HEAD";
267 return ((-e
$headfile) ||
268 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
271 sub check_export_ok
{
273 return (check_head_link
($dir) &&
274 (!$export_ok || -e
"$dir/$export_ok"));
277 # rename detection options for git-diff and git-diff-tree
278 # - default is '-M', with the cost proportional to
279 # (number of removed files) * (number of new files).
280 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
281 # (number of changed files + number of removed files) * (number of new files)
282 # - even more costly is '-C', '--find-copies-harder' with cost
283 # (number of files in the original tree) * (number of new files)
284 # - one might want to include '-B' option, e.g. '-B', '-M'
285 our @diff_opts = ('-M'); # taken from git_commit
287 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
288 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
290 # version of the core git binary
291 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
293 $projects_list ||= $projectroot;
295 # ======================================================================
296 # input validation and dispatch
297 our $action = $cgi->param('a');
298 if (defined $action) {
299 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
300 die_error
(undef, "Invalid action parameter");
304 # parameters which are pathnames
305 our $project = $cgi->param('p');
306 if (defined $project) {
307 if (!validate_pathname
($project) ||
308 !(-d
"$projectroot/$project") ||
309 !check_head_link
("$projectroot/$project") ||
310 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
311 ($strict_export && !project_in_list
($project))) {
313 die_error
(undef, "No such project");
317 our $file_name = $cgi->param('f');
318 if (defined $file_name) {
319 if (!validate_pathname
($file_name)) {
320 die_error
(undef, "Invalid file parameter");
324 our $file_parent = $cgi->param('fp');
325 if (defined $file_parent) {
326 if (!validate_pathname
($file_parent)) {
327 die_error
(undef, "Invalid file parent parameter");
331 # parameters which are refnames
332 our $hash = $cgi->param('h');
334 if (!validate_refname
($hash)) {
335 die_error
(undef, "Invalid hash parameter");
339 our $hash_parent = $cgi->param('hp');
340 if (defined $hash_parent) {
341 if (!validate_refname
($hash_parent)) {
342 die_error
(undef, "Invalid hash parent parameter");
346 our $hash_base = $cgi->param('hb');
347 if (defined $hash_base) {
348 if (!validate_refname
($hash_base)) {
349 die_error
(undef, "Invalid hash base parameter");
353 our $hash_parent_base = $cgi->param('hpb');
354 if (defined $hash_parent_base) {
355 if (!validate_refname
($hash_parent_base)) {
356 die_error
(undef, "Invalid hash parent base parameter");
361 our $page = $cgi->param('pg');
363 if ($page =~ m/[^0-9]/) {
364 die_error
(undef, "Invalid page parameter");
368 our $searchtext = $cgi->param('s');
370 if (defined $searchtext) {
371 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
372 die_error
(undef, "Invalid search parameter");
374 if (length($searchtext) < 2) {
375 die_error
(undef, "At least two characters are required for search parameter");
377 $search_regexp = quotemeta $searchtext;
380 our $searchtype = $cgi->param('st');
381 if (defined $searchtype) {
382 if ($searchtype =~ m/[^a-z]/) {
383 die_error
(undef, "Invalid searchtype parameter");
387 # now read PATH_INFO and use it as alternative to parameters
388 sub evaluate_path_info
{
389 return if defined $project;
390 my $path_info = $ENV{"PATH_INFO"};
391 return if !$path_info;
392 $path_info =~ s
,^/+,,;
393 return if !$path_info;
394 # find which part of PATH_INFO is project
395 $project = $path_info;
397 while ($project && !check_head_link
("$projectroot/$project")) {
398 $project =~ s
,/*[^/]*$,,;
401 $project = validate_pathname
($project);
403 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
404 ($strict_export && !project_in_list
($project))) {
408 # do not change any parameters if an action is given using the query string
410 $path_info =~ s
,^$project/*,,;
411 my ($refname, $pathname) = split(/:/, $path_info, 2);
412 if (defined $pathname) {
413 # we got "project.git/branch:filename" or "project.git/branch:dir/"
414 # we could use git_get_type(branch:pathname), but it needs $git_dir
415 $pathname =~ s
,^/+,,;
416 if (!$pathname || substr($pathname, -1) eq "/") {
420 $action ||= "blob_plain";
422 $hash_base ||= validate_refname
($refname);
423 $file_name ||= validate_pathname
($pathname);
424 } elsif (defined $refname) {
425 # we got "project.git/branch"
426 $action ||= "shortlog";
427 $hash ||= validate_refname
($refname);
430 evaluate_path_info
();
432 # path to the current git repository
434 $git_dir = "$projectroot/$project" if $project;
438 "blame" => \
&git_blame2
,
439 "blobdiff" => \
&git_blobdiff
,
440 "blobdiff_plain" => \
&git_blobdiff_plain
,
441 "blob" => \
&git_blob
,
442 "blob_plain" => \
&git_blob_plain
,
443 "commitdiff" => \
&git_commitdiff
,
444 "commitdiff_plain" => \
&git_commitdiff_plain
,
445 "commit" => \
&git_commit
,
446 "forks" => \
&git_forks
,
447 "heads" => \
&git_heads
,
448 "history" => \
&git_history
,
451 "atom" => \
&git_atom
,
452 "search" => \
&git_search
,
453 "search_help" => \
&git_search_help
,
454 "shortlog" => \
&git_shortlog
,
455 "summary" => \
&git_summary
,
457 "tags" => \
&git_tags
,
458 "tree" => \
&git_tree
,
459 "snapshot" => \
&git_snapshot
,
460 "object" => \
&git_object
,
461 # those below don't need $project
462 "opml" => \
&git_opml
,
463 "project_list" => \
&git_project_list
,
464 "project_index" => \
&git_project_index
,
467 if (!defined $action) {
469 $action = git_get_type
($hash);
470 } elsif (defined $hash_base && defined $file_name) {
471 $action = git_get_type
("$hash_base:$file_name");
472 } elsif (defined $project) {
475 $action = 'project_list';
478 if (!defined($actions{$action})) {
479 die_error
(undef, "Unknown action");
481 if ($action !~ m/^(opml|project_list|project_index)$/ &&
483 die_error
(undef, "Project needed");
485 $actions{$action}->();
488 ## ======================================================================
493 # default is to use -absolute url() i.e. $my_uri
494 my $href = $params{-full
} ? $my_url : $my_uri;
496 # XXX: Warning: If you touch this, check the search form for updating,
507 hash_parent_base
=> "hpb",
513 my %mapping = @mapping;
515 $params{'project'} = $project unless exists $params{'project'};
517 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
519 # use PATH_INFO for project name
520 $href .= "/$params{'project'}" if defined $params{'project'};
521 delete $params{'project'};
523 # Summary just uses the project path URL
524 if (defined $params{'action'} && $params{'action'} eq 'summary') {
525 delete $params{'action'};
529 # now encode the parameters explicitly
531 for (my $i = 0; $i < @mapping; $i += 2) {
532 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
533 if (defined $params{$name}) {
534 push @result, $symbol . "=" . esc_param
($params{$name});
537 $href .= "?" . join(';', @result) if scalar @result;
543 ## ======================================================================
544 ## validation, quoting/unquoting and escaping
546 sub validate_pathname
{
547 my $input = shift || return undef;
549 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
550 # at the beginning, at the end, and between slashes.
551 # also this catches doubled slashes
552 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
556 if ($input =~ m!\0!) {
562 sub validate_refname
{
563 my $input = shift || return undef;
565 # textual hashes are O.K.
566 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
569 # it must be correct pathname
570 $input = validate_pathname
($input)
572 # restrictions on ref name according to git-check-ref-format
573 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
579 # quote unsafe chars, but keep the slash, even when it's not
580 # correct, but quoted slashes look too horrible in bookmarks
583 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
589 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
592 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
598 # replace invalid utf8 character with SUBSTITUTION sequence
603 $str = decode_utf8
($str);
604 $str = $cgi->escapeHTML($str);
605 if ($opts{'-nbsp'}) {
606 $str =~ s/ / /g;
608 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
612 # quote control characters and escape filename to HTML
617 $str = decode_utf8
($str);
618 $str = $cgi->escapeHTML($str);
619 if ($opts{'-nbsp'}) {
620 $str =~ s/ / /g;
622 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
626 # Make control characters "printable", using character escape codes (CEC)
629 my %es = ( # character escape codes, aka escape sequences
630 "\t" => '\t', # tab (HT)
631 "\n" => '\n', # line feed (LF)
632 "\r" => '\r', # carrige return (CR)
633 "\f" => '\f', # form feed (FF)
634 "\b" => '\b', # backspace (BS)
635 "\a" => '\a', # alarm (bell) (BEL)
636 "\e" => '\e', # escape (ESC)
637 "\013" => '\v', # vertical tab (VT)
638 "\000" => '\0', # nul character (NUL)
640 my $chr = ( (exists $es{$cntrl})
642 : sprintf('\%03o', ord($cntrl)) );
643 return "<span class=\"cntrl\">$chr</span>";
646 # Alternatively use unicode control pictures codepoints,
647 # Unicode "printable representation" (PR)
650 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
651 return "<span class=\"cntrl\">$chr</span>";
654 # git may return quoted and escaped filenames
660 my %es = ( # character escape codes, aka escape sequences
661 't' => "\t", # tab (HT, TAB)
662 'n' => "\n", # newline (NL)
663 'r' => "\r", # return (CR)
664 'f' => "\f", # form feed (FF)
665 'b' => "\b", # backspace (BS)
666 'a' => "\a", # alarm (bell) (BEL)
667 'e' => "\e", # escape (ESC)
668 'v' => "\013", # vertical tab (VT)
671 if ($seq =~ m/^[0-7]{1,3}$/) {
672 # octal char sequence
673 return chr(oct($seq));
674 } elsif (exists $es{$seq}) {
675 # C escape sequence, aka character escape code
678 # quoted ordinary character
682 if ($str =~ m/^"(.*)"$/) {
685 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
690 # escape tabs (convert tabs to spaces)
694 while ((my $pos = index($line, "\t")) != -1) {
695 if (my $count = (8 - ($pos % 8))) {
696 my $spaces = ' ' x
$count;
697 $line =~ s/\t/$spaces/;
704 sub project_in_list
{
706 my @list = git_get_projects_list
();
707 return @list && scalar(grep { $_->{'path'} eq $project } @list);
710 ## ----------------------------------------------------------------------
711 ## HTML aware string manipulation
716 my $add_len = shift || 10;
718 # allow only $len chars, but don't cut a word if it would fit in $add_len
719 # if it doesn't fit, cut it if it's still longer than the dots we would add
720 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
723 if (length($tail) > 4) {
725 $body =~ s/&[^;]*$//; # remove chopped character entities
730 ## ----------------------------------------------------------------------
731 ## functions returning short strings
733 # CSS class for given age value (in seconds)
739 } elsif ($age < 60*60*2) {
741 } elsif ($age < 60*60*24*2) {
748 # convert age in seconds to "nn units ago" string
753 if ($age > 60*60*24*365*2) {
754 $age_str = (int $age/60/60/24/365);
755 $age_str .= " years ago";
756 } elsif ($age > 60*60*24*(365/12)*2) {
757 $age_str = int $age/60/60/24/(365/12);
758 $age_str .= " months ago";
759 } elsif ($age > 60*60*24*7*2) {
760 $age_str = int $age/60/60/24/7;
761 $age_str .= " weeks ago";
762 } elsif ($age > 60*60*24*2) {
763 $age_str = int $age/60/60/24;
764 $age_str .= " days ago";
765 } elsif ($age > 60*60*2) {
766 $age_str = int $age/60/60;
767 $age_str .= " hours ago";
768 } elsif ($age > 60*2) {
769 $age_str = int $age/60;
770 $age_str .= " min ago";
773 $age_str .= " sec ago";
775 $age_str .= " right now";
780 # convert file mode in octal to symbolic file mode string
782 my $mode = oct shift;
784 if (S_ISDIR
($mode & S_IFMT
)) {
786 } elsif (S_ISLNK
($mode)) {
788 } elsif (S_ISREG
($mode)) {
789 # git cares only about the executable bit
790 if ($mode & S_IXUSR
) {
800 # convert file mode in octal to file type string
804 if ($mode !~ m/^[0-7]+$/) {
810 if (S_ISDIR
($mode & S_IFMT
)) {
812 } elsif (S_ISLNK
($mode)) {
814 } elsif (S_ISREG
($mode)) {
821 # convert file mode in octal to file type description string
825 if ($mode !~ m/^[0-7]+$/) {
831 if (S_ISDIR
($mode & S_IFMT
)) {
833 } elsif (S_ISLNK
($mode)) {
835 } elsif (S_ISREG
($mode)) {
836 if ($mode & S_IXUSR
) {
847 ## ----------------------------------------------------------------------
848 ## functions returning short HTML fragments, or transforming HTML fragments
849 ## which don't belong to other sections
851 # format line of commit message.
852 sub format_log_line_html
{
855 $line = esc_html
($line, -nbsp
=>1);
856 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
859 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
860 -class => "text"}, $hash_text);
861 $line =~ s/$hash_text/$link/;
866 # format marker of refs pointing to given object
867 sub format_ref_marker
{
868 my ($refs, $id) = @_;
871 if (defined $refs->{$id}) {
872 foreach my $ref (@{$refs->{$id}}) {
873 my ($type, $name) = qw();
874 # e.g. tags/v2.6.11 or heads/next
875 if ($ref =~ m!^(.*?)s?/(.*)$!) {
883 $markers .= " <span class=\"$type\" title=\"$ref\">" .
884 esc_html
($name) . "</span>";
889 return ' <span class="refs">'. $markers . '</span>';
895 # format, perhaps shortened and with markers, title line
896 sub format_subject_html
{
897 my ($long, $short, $href, $extra) = @_;
898 $extra = '' unless defined($extra);
900 if (length($short) < length($long)) {
901 return $cgi->a({-href
=> $href, -class => "list subject",
902 -title
=> decode_utf8
($long)},
903 esc_html
($short) . $extra);
905 return $cgi->a({-href
=> $href, -class => "list subject"},
906 esc_html
($long) . $extra);
910 # format patch (diff) line (rather not to be used for diff headers)
911 sub format_diff_line
{
913 my ($from, $to) = @_;
918 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
920 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
921 if ($line =~ m/^\@{3}/) {
922 $diff_class = " chunk_header";
923 } elsif ($line =~ m/^\\/) {
924 $diff_class = " incomplete";
925 } elsif ($prefix =~ tr/+/+/) {
926 $diff_class = " add";
927 } elsif ($prefix =~ tr/-/-/) {
928 $diff_class = " rem";
931 # assume ordinary diff
932 my $char = substr($line, 0, 1);
934 $diff_class = " add";
935 } elsif ($char eq '-') {
936 $diff_class = " rem";
937 } elsif ($char eq '@') {
938 $diff_class = " chunk_header";
939 } elsif ($char eq "\\") {
940 $diff_class = " incomplete";
943 $line = untabify
($line);
944 if ($from && $to && $line =~ m/^\@{2} /) {
945 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
946 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
948 $from_lines = 0 unless defined $from_lines;
949 $to_lines = 0 unless defined $to_lines;
951 if ($from->{'href'}) {
952 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
953 -class=>"list"}, $from_text);
956 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
957 -class=>"list"}, $to_text);
959 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
960 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
961 return "<div class=\"diff$diff_class\">$line</div>\n";
962 } elsif ($from && $to && $line =~ m/^\@{3}/) {
963 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
964 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
966 @from_text = split(' ', $ranges);
967 for (my $i = 0; $i < @from_text; ++$i) {
968 ($from_start[$i], $from_nlines[$i]) =
969 (split(',', substr($from_text[$i], 1)), 0);
972 $to_text = pop @from_text;
973 $to_start = pop @from_start;
974 $to_nlines = pop @from_nlines;
976 $line = "<span class=\"chunk_info\">$prefix ";
977 for (my $i = 0; $i < @from_text; ++$i) {
978 if ($from->{'href'}[$i]) {
979 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
980 -class=>"list"}, $from_text[$i]);
982 $line .= $from_text[$i];
987 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
988 -class=>"list"}, $to_text);
992 $line .= " $prefix</span>" .
993 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
994 return "<div class=\"diff$diff_class\">$line</div>\n";
996 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
999 ## ----------------------------------------------------------------------
1000 ## git utility subroutines, invoking git commands
1002 # returns path to the core git executable and the --git-dir parameter as list
1004 return $GIT, '--git-dir='.$git_dir;
1007 # returns path to the core git executable and the --git-dir parameter as string
1009 return join(' ', git_cmd
());
1012 # get HEAD ref of given project as hash
1013 sub git_get_head_hash
{
1014 my $project = shift;
1015 my $o_git_dir = $git_dir;
1017 $git_dir = "$projectroot/$project";
1018 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1021 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1025 if (defined $o_git_dir) {
1026 $git_dir = $o_git_dir;
1031 # get type of given object
1035 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1037 close $fd or return;
1042 sub git_get_project_config
{
1043 my ($key, $type) = @_;
1045 return unless ($key);
1046 $key =~ s/^gitweb\.//;
1047 return if ($key =~ m/\W/);
1049 my @x = (git_cmd
(), 'config');
1050 if (defined $type) { push @x, $type; }
1052 push @x, "gitweb.$key";
1058 # get hash of given path at given ref
1059 sub git_get_hash_by_path
{
1061 my $path = shift || return undef;
1066 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1067 or die_error
(undef, "Open git-ls-tree failed");
1069 close $fd or return undef;
1071 if (!defined $line) {
1072 # there is no tree or hash given by $path at $base
1076 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1077 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1078 if (defined $type && $type ne $2) {
1079 # type doesn't match
1085 # get path of entry with given hash at given tree-ish (ref)
1086 # used to get 'from' filename for combined diff (merge commit) for renames
1087 sub git_get_path_by_hash
{
1088 my $base = shift || return;
1089 my $hash = shift || return;
1093 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1095 while (my $line = <$fd>) {
1098 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1099 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1100 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1109 ## ......................................................................
1110 ## git utility functions, directly accessing git repository
1112 sub git_get_project_description
{
1115 open my $fd, "$projectroot/$path/description" or return undef;
1122 sub git_get_project_url_list
{
1125 open my $fd, "$projectroot/$path/cloneurl" or return;
1126 my @git_project_url_list = map { chomp; $_ } <$fd>;
1129 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1132 sub git_get_projects_list
{
1137 $filter =~ s/\.git$//;
1139 my ($check_forks) = gitweb_check_feature
('forks');
1141 if (-d
$projects_list) {
1142 # search in directory
1143 my $dir = $projects_list . ($filter ? "/$filter" : '');
1144 # remove the trailing "/"
1146 my $pfxlen = length("$dir");
1149 follow_fast
=> 1, # follow symbolic links
1150 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1152 # skip project-list toplevel, if we get it.
1153 return if (m!^[/.]$!);
1154 # only directories can be git repositories
1155 return unless (-d
$_);
1157 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1158 # we check related file in $projectroot
1159 if ($check_forks and $subdir =~ m
#/.#) {
1160 $File::Find
::prune
= 1;
1161 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1162 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1163 $File::Find
::prune
= 1;
1168 } elsif (-f
$projects_list) {
1169 # read from file(url-encoded):
1170 # 'git%2Fgit.git Linus+Torvalds'
1171 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1172 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1174 open my ($fd), $projects_list or return;
1176 while (my $line = <$fd>) {
1178 my ($path, $owner) = split ' ', $line;
1179 $path = unescape
($path);
1180 $owner = unescape
($owner);
1181 if (!defined $path) {
1184 if ($filter ne '') {
1185 # looking for forks;
1186 my $pfx = substr($path, 0, length($filter));
1187 if ($pfx ne $filter) {
1190 my $sfx = substr($path, length($filter));
1191 if ($sfx !~ /^\/.*\
.git
$/) {
1194 } elsif ($check_forks) {
1196 foreach my $filter (keys %paths) {
1197 # looking for forks;
1198 my $pfx = substr($path, 0, length($filter));
1199 if ($pfx ne $filter) {
1202 my $sfx = substr($path, length($filter));
1203 if ($sfx !~ /^\/.*\
.git
$/) {
1206 # is a fork, don't include it in
1211 if (check_export_ok
("$projectroot/$path")) {
1214 owner
=> decode_utf8
($owner),
1217 (my $forks_path = $path) =~ s/\.git$//;
1218 $paths{$forks_path}++;
1226 sub git_get_project_owner
{
1227 my $project = shift;
1230 return undef unless $project;
1232 # read from file (url-encoded):
1233 # 'git%2Fgit.git Linus+Torvalds'
1234 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1235 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1236 if (-f
$projects_list) {
1237 open (my $fd , $projects_list);
1238 while (my $line = <$fd>) {
1240 my ($pr, $ow) = split ' ', $line;
1241 $pr = unescape
($pr);
1242 $ow = unescape
($ow);
1243 if ($pr eq $project) {
1244 $owner = decode_utf8
($ow);
1250 if (!defined $owner) {
1251 $owner = get_file_owner
("$projectroot/$project");
1257 sub git_get_last_activity
{
1261 $git_dir = "$projectroot/$path";
1262 open($fd, "-|", git_cmd
(), 'for-each-ref',
1263 '--format=%(committer)',
1264 '--sort=-committerdate',
1266 'refs/heads') or return;
1267 my $most_recent = <$fd>;
1268 close $fd or return;
1269 if (defined $most_recent &&
1270 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1272 my $age = time - $timestamp;
1273 return ($age, age_string
($age));
1277 sub git_get_references
{
1278 my $type = shift || "";
1280 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1281 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1282 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1283 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1286 while (my $line = <$fd>) {
1288 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1289 if (defined $refs{$1}) {
1290 push @{$refs{$1}}, $2;
1296 close $fd or return;
1300 sub git_get_rev_name_tags
{
1301 my $hash = shift || return undef;
1303 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1305 my $name_rev = <$fd>;
1308 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1311 # catches also '$hash undefined' output
1316 ## ----------------------------------------------------------------------
1317 ## parse to hash functions
1321 my $tz = shift || "-0000";
1324 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1325 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1326 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1327 $date{'hour'} = $hour;
1328 $date{'minute'} = $min;
1329 $date{'mday'} = $mday;
1330 $date{'day'} = $days[$wday];
1331 $date{'month'} = $months[$mon];
1332 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1333 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1334 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1335 $mday, $months[$mon], $hour ,$min;
1336 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1337 1900+$year, $mon, $mday, $hour ,$min, $sec;
1339 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1340 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1341 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1342 $date{'hour_local'} = $hour;
1343 $date{'minute_local'} = $min;
1344 $date{'tz_local'} = $tz;
1345 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1346 1900+$year, $mon+1, $mday,
1347 $hour, $min, $sec, $tz);
1356 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1357 $tag{'id'} = $tag_id;
1358 while (my $line = <$fd>) {
1360 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1361 $tag{'object'} = $1;
1362 } elsif ($line =~ m/^type (.+)$/) {
1364 } elsif ($line =~ m/^tag (.+)$/) {
1366 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1367 $tag{'author'} = $1;
1370 } elsif ($line =~ m/--BEGIN/) {
1371 push @comment, $line;
1373 } elsif ($line eq "") {
1377 push @comment, <$fd>;
1378 $tag{'comment'} = \
@comment;
1379 close $fd or return;
1380 if (!defined $tag{'name'}) {
1386 sub parse_commit_text
{
1387 my ($commit_text, $withparents) = @_;
1388 my @commit_lines = split '\n', $commit_text;
1391 pop @commit_lines; # Remove '\0'
1393 if (! @commit_lines) {
1397 my $header = shift @commit_lines;
1398 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1401 ($co{'id'}, my @parents) = split ' ', $header;
1402 while (my $line = shift @commit_lines) {
1403 last if $line eq "\n";
1404 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1406 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1408 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1410 $co{'author_epoch'} = $2;
1411 $co{'author_tz'} = $3;
1412 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1413 $co{'author_name'} = $1;
1414 $co{'author_email'} = $2;
1416 $co{'author_name'} = $co{'author'};
1418 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1419 $co{'committer'} = $1;
1420 $co{'committer_epoch'} = $2;
1421 $co{'committer_tz'} = $3;
1422 $co{'committer_name'} = $co{'committer'};
1423 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1424 $co{'committer_name'} = $1;
1425 $co{'committer_email'} = $2;
1427 $co{'committer_name'} = $co{'committer'};
1431 if (!defined $co{'tree'}) {
1434 $co{'parents'} = \
@parents;
1435 $co{'parent'} = $parents[0];
1437 foreach my $title (@commit_lines) {
1440 $co{'title'} = chop_str
($title, 80, 5);
1441 # remove leading stuff of merges to make the interesting part visible
1442 if (length($title) > 50) {
1443 $title =~ s/^Automatic //;
1444 $title =~ s/^merge (of|with) /Merge ... /i;
1445 if (length($title) > 50) {
1446 $title =~ s/(http|rsync):\/\///;
1448 if (length($title) > 50) {
1449 $title =~ s/(master|www|rsync)\.//;
1451 if (length($title) > 50) {
1452 $title =~ s/kernel.org:?//;
1454 if (length($title) > 50) {
1455 $title =~ s/\/pub\/scm//;
1458 $co{'title_short'} = chop_str
($title, 50, 5);
1462 if ($co{'title'} eq "") {
1463 $co{'title'} = $co{'title_short'} = '(no commit message)';
1465 # remove added spaces
1466 foreach my $line (@commit_lines) {
1469 $co{'comment'} = \
@commit_lines;
1471 my $age = time - $co{'committer_epoch'};
1473 $co{'age_string'} = age_string
($age);
1474 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1475 if ($age > 60*60*24*7*2) {
1476 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1477 $co{'age_string_age'} = $co{'age_string'};
1479 $co{'age_string_date'} = $co{'age_string'};
1480 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1486 my ($commit_id) = @_;
1491 open my $fd, "-|", git_cmd
(), "rev-list",
1497 or die_error
(undef, "Open git-rev-list failed");
1498 %co = parse_commit_text
(<$fd>, 1);
1505 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1513 open my $fd, "-|", git_cmd
(), "rev-list",
1515 ($arg ? ($arg) : ()),
1516 ("--max-count=" . $maxcount),
1517 ("--skip=" . $skip),
1520 ($filename ? ($filename) : ())
1521 or die_error
(undef, "Open git-rev-list failed");
1522 while (my $line = <$fd>) {
1523 my %co = parse_commit_text
($line);
1528 return wantarray ? @cos : \
@cos;
1531 # parse ref from ref_file, given by ref_id, with given type
1533 my $ref_file = shift;
1535 my $type = shift || git_get_type
($ref_id);
1538 $ref_item{'type'} = $type;
1539 $ref_item{'id'} = $ref_id;
1540 $ref_item{'epoch'} = 0;
1541 $ref_item{'age'} = "unknown";
1542 if ($type eq "tag") {
1543 my %tag = parse_tag
($ref_id);
1544 $ref_item{'comment'} = $tag{'comment'};
1545 if ($tag{'type'} eq "commit") {
1546 my %co = parse_commit
($tag{'object'});
1547 $ref_item{'epoch'} = $co{'committer_epoch'};
1548 $ref_item{'age'} = $co{'age_string'};
1549 } elsif (defined($tag{'epoch'})) {
1550 my $age = time - $tag{'epoch'};
1551 $ref_item{'epoch'} = $tag{'epoch'};
1552 $ref_item{'age'} = age_string
($age);
1554 $ref_item{'reftype'} = $tag{'type'};
1555 $ref_item{'name'} = $tag{'name'};
1556 $ref_item{'refid'} = $tag{'object'};
1557 } elsif ($type eq "commit"){
1558 my %co = parse_commit
($ref_id);
1559 $ref_item{'reftype'} = "commit";
1560 $ref_item{'name'} = $ref_file;
1561 $ref_item{'title'} = $co{'title'};
1562 $ref_item{'refid'} = $ref_id;
1563 $ref_item{'epoch'} = $co{'committer_epoch'};
1564 $ref_item{'age'} = $co{'age_string'};
1566 $ref_item{'reftype'} = $type;
1567 $ref_item{'name'} = $ref_file;
1568 $ref_item{'refid'} = $ref_id;
1574 # parse line of git-diff-tree "raw" output
1575 sub parse_difftree_raw_line
{
1579 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1580 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1581 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1582 $res{'from_mode'} = $1;
1583 $res{'to_mode'} = $2;
1584 $res{'from_id'} = $3;
1586 $res{'status'} = $5;
1587 $res{'similarity'} = $6;
1588 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1589 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1591 $res{'file'} = unquote
($7);
1594 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1595 # combined diff (for merge commit)
1596 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1597 $res{'nparents'} = length($1);
1598 $res{'from_mode'} = [ split(' ', $2) ];
1599 $res{'to_mode'} = pop @{$res{'from_mode'}};
1600 $res{'from_id'} = [ split(' ', $3) ];
1601 $res{'to_id'} = pop @{$res{'from_id'}};
1602 $res{'status'} = [ split('', $4) ];
1603 $res{'to_file'} = unquote
($5);
1605 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1606 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1607 $res{'commit'} = $1;
1610 return wantarray ? %res : \
%res;
1613 # parse line of git-ls-tree output
1614 sub parse_ls_tree_line
($;%) {
1619 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1620 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1628 $res{'name'} = unquote
($4);
1631 return wantarray ? %res : \
%res;
1634 ## ......................................................................
1635 ## parse to array of hashes functions
1637 sub git_get_heads_list
{
1641 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1642 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1643 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1646 while (my $line = <$fd>) {
1650 my ($refinfo, $committerinfo) = split(/\0/, $line);
1651 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1652 my ($committer, $epoch, $tz) =
1653 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1654 $name =~ s!^refs/heads/!!;
1656 $ref_item{'name'} = $name;
1657 $ref_item{'id'} = $hash;
1658 $ref_item{'title'} = $title || '(no commit message)';
1659 $ref_item{'epoch'} = $epoch;
1661 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1663 $ref_item{'age'} = "unknown";
1666 push @headslist, \
%ref_item;
1670 return wantarray ? @headslist : \
@headslist;
1673 sub git_get_tags_list
{
1677 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1678 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1679 '--format=%(objectname) %(objecttype) %(refname) '.
1680 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1683 while (my $line = <$fd>) {
1687 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1688 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1689 my ($creator, $epoch, $tz) =
1690 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1691 $name =~ s!^refs/tags/!!;
1693 $ref_item{'type'} = $type;
1694 $ref_item{'id'} = $id;
1695 $ref_item{'name'} = $name;
1696 if ($type eq "tag") {
1697 $ref_item{'subject'} = $title;
1698 $ref_item{'reftype'} = $reftype;
1699 $ref_item{'refid'} = $refid;
1701 $ref_item{'reftype'} = $type;
1702 $ref_item{'refid'} = $id;
1705 if ($type eq "tag" || $type eq "commit") {
1706 $ref_item{'epoch'} = $epoch;
1708 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1710 $ref_item{'age'} = "unknown";
1714 push @tagslist, \
%ref_item;
1718 return wantarray ? @tagslist : \
@tagslist;
1721 ## ----------------------------------------------------------------------
1722 ## filesystem-related functions
1724 sub get_file_owner
{
1727 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1728 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1729 if (!defined $gcos) {
1733 $owner =~ s/[,;].*$//;
1734 return decode_utf8
($owner);
1737 ## ......................................................................
1738 ## mimetype related functions
1740 sub mimetype_guess_file
{
1741 my $filename = shift;
1742 my $mimemap = shift;
1743 -r
$mimemap or return undef;
1746 open(MIME
, $mimemap) or return undef;
1748 next if m/^#/; # skip comments
1749 my ($mime, $exts) = split(/\t+/);
1750 if (defined $exts) {
1751 my @exts = split(/\s+/, $exts);
1752 foreach my $ext (@exts) {
1753 $mimemap{$ext} = $mime;
1759 $filename =~ /\.([^.]*)$/;
1760 return $mimemap{$1};
1763 sub mimetype_guess
{
1764 my $filename = shift;
1766 $filename =~ /\./ or return undef;
1768 if ($mimetypes_file) {
1769 my $file = $mimetypes_file;
1770 if ($file !~ m!^/!) { # if it is relative path
1771 # it is relative to project
1772 $file = "$projectroot/$project/$file";
1774 $mime = mimetype_guess_file
($filename, $file);
1776 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1782 my $filename = shift;
1785 my $mime = mimetype_guess
($filename);
1786 $mime and return $mime;
1790 return $default_blob_plain_mimetype unless $fd;
1793 return 'text/plain' .
1794 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1795 } elsif (! $filename) {
1796 return 'application/octet-stream';
1797 } elsif ($filename =~ m/\.png$/i) {
1799 } elsif ($filename =~ m/\.gif$/i) {
1801 } elsif ($filename =~ m/\.jpe?g$/i) {
1802 return 'image/jpeg';
1804 return 'application/octet-stream';
1808 ## ======================================================================
1809 ## functions printing HTML: header, footer, error page
1811 sub git_header_html
{
1812 my $status = shift || "200 OK";
1813 my $expires = shift;
1815 my $title = "$site_name";
1816 if (defined $project) {
1817 $title .= " - " . decode_utf8
($project);
1818 if (defined $action) {
1819 $title .= "/$action";
1820 if (defined $file_name) {
1821 $title .= " - " . esc_path
($file_name);
1822 if ($action eq "tree" && $file_name !~ m
|/$|) {
1829 # require explicit support from the UA if we are to send the page as
1830 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1831 # we have to do this because MSIE sometimes globs '*/*', pretending to
1832 # support xhtml+xml but choking when it gets what it asked for.
1833 if (defined $cgi->http('HTTP_ACCEPT') &&
1834 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1835 $cgi->Accept('application/xhtml+xml') != 0) {
1836 $content_type = 'application/xhtml+xml';
1838 $content_type = 'text/html';
1840 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1841 -status
=> $status, -expires
=> $expires);
1842 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
1844 <?xml version="1.0" encoding="utf-8"?>
1845 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1846 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1847 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1848 <!-- git core binaries version $git_version -->
1850 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1851 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
1852 <meta name="robots" content="index, nofollow"/>
1853 <title>$title</title>
1855 # print out each stylesheet that exist
1856 if (defined $stylesheet) {
1857 #provides backwards capability for those people who define style sheet in a config file
1858 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1860 foreach my $stylesheet (@stylesheets) {
1861 next unless $stylesheet;
1862 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1865 if (defined $project) {
1866 printf('<link rel="alternate" title="%s log RSS feed" '.
1867 'href="%s" type="application/rss+xml" />'."\n",
1868 esc_param
($project), href
(action
=>"rss"));
1869 printf('<link rel="alternate" title="%s log Atom feed" '.
1870 'href="%s" type="application/atom+xml" />'."\n",
1871 esc_param
($project), href
(action
=>"atom"));
1873 printf('<link rel="alternate" title="%s projects list" '.
1874 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1875 $site_name, href
(project
=>undef, action
=>"project_index"));
1876 printf('<link rel="alternate" title="%s projects feeds" '.
1877 'href="%s" type="text/x-opml"/>'."\n",
1878 $site_name, href
(project
=>undef, action
=>"opml"));
1880 if (defined $favicon) {
1881 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1887 if (-f
$site_header) {
1888 open (my $fd, $site_header);
1893 print "<div class=\"page_header\">\n" .
1894 $cgi->a({-href
=> esc_url
($logo_url),
1895 -title
=> $logo_label},
1896 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1897 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1898 if (defined $project) {
1899 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1900 if (defined $action) {
1905 my ($have_search) = gitweb_check_feature
('search');
1906 if ((defined $project) && ($have_search)) {
1907 if (!defined $searchtext) {
1911 if (defined $hash_base) {
1912 $search_hash = $hash_base;
1913 } elsif (defined $hash) {
1914 $search_hash = $hash;
1916 $search_hash = "HEAD";
1918 $cgi->param("a", "search");
1919 $cgi->param("h", $search_hash);
1920 $cgi->param("p", $project);
1921 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1922 "<div class=\"search\">\n" .
1923 $cgi->hidden(-name
=> "p") . "\n" .
1924 $cgi->hidden(-name
=> "a") . "\n" .
1925 $cgi->hidden(-name
=> "h") . "\n" .
1926 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1927 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1928 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1930 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1932 $cgi->end_form() . "\n";
1937 sub git_footer_html
{
1938 print "<div class=\"page_footer\">\n";
1939 if (defined $project) {
1940 my $descr = git_get_project_description
($project);
1941 if (defined $descr) {
1942 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1944 print $cgi->a({-href
=> href
(action
=>"rss"),
1945 -class => "rss_logo"}, "RSS") . " ";
1946 print $cgi->a({-href
=> href
(action
=>"atom"),
1947 -class => "rss_logo"}, "Atom") . "\n";
1949 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1950 -class => "rss_logo"}, "OPML") . " ";
1951 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1952 -class => "rss_logo"}, "TXT") . "\n";
1956 if (-f
$site_footer) {
1957 open (my $fd, $site_footer);
1967 my $status = shift || "403 Forbidden";
1968 my $error = shift || "Malformed query, file missing or permission denied";
1970 git_header_html
($status);
1972 <div class="page_body">
1982 ## ----------------------------------------------------------------------
1983 ## functions printing or outputting HTML: navigation
1985 sub git_print_page_nav
{
1986 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1987 $extra = '' if !defined $extra; # pager or formats
1989 my @navs = qw(summary shortlog log commit commitdiff tree);
1991 @navs = grep { $_ ne $suppress } @navs;
1994 my %arg = map { $_ => {action
=>$_} } @navs;
1995 if (defined $head) {
1996 for (qw(commit commitdiff)) {
1997 $arg{$_}{'hash'} = $head;
1999 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2000 for (qw(shortlog log)) {
2001 $arg{$_}{'hash'} = $head;
2005 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2006 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2008 print "<div class=\"page_nav\">\n" .
2010 map { $_ eq $current ?
2011 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2013 print "<br/>\n$extra<br/>\n" .
2017 sub format_paging_nav
{
2018 my ($action, $hash, $head, $page, $nrevs) = @_;
2022 if ($hash ne $head || $page) {
2023 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2025 $paging_nav .= "HEAD";
2029 $paging_nav .= " ⋅ " .
2030 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2031 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2033 $paging_nav .= " ⋅ prev";
2036 if ($nrevs >= (100 * ($page+1)-1)) {
2037 $paging_nav .= " ⋅ " .
2038 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2039 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2041 $paging_nav .= " ⋅ next";
2047 ## ......................................................................
2048 ## functions printing or outputting HTML: div
2050 sub git_print_header_div
{
2051 my ($action, $title, $hash, $hash_base) = @_;
2054 $args{'action'} = $action;
2055 $args{'hash'} = $hash if $hash;
2056 $args{'hash_base'} = $hash_base if $hash_base;
2058 print "<div class=\"header\">\n" .
2059 $cgi->a({-href
=> href
(%args), -class => "title"},
2060 $title ? $title : $action) .
2064 #sub git_print_authorship (\%) {
2065 sub git_print_authorship
{
2068 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2069 print "<div class=\"author_date\">" .
2070 esc_html
($co->{'author_name'}) .
2072 if ($ad{'hour_local'} < 6) {
2073 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2074 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2076 printf(" (%02d:%02d %s)",
2077 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2082 sub git_print_page_path
{
2088 print "<div class=\"page_path\">";
2089 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2090 -title
=> 'tree root'}, decode_utf8
("[$project]"));
2092 if (defined $name) {
2093 my @dirname = split '/', $name;
2094 my $basename = pop @dirname;
2097 foreach my $dir (@dirname) {
2098 $fullname .= ($fullname ? '/' : '') . $dir;
2099 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2101 -title
=> $fullname}, esc_path
($dir));
2104 if (defined $type && $type eq 'blob') {
2105 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2107 -title
=> $name}, esc_path
($basename));
2108 } elsif (defined $type && $type eq 'tree') {
2109 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2111 -title
=> $name}, esc_path
($basename));
2114 print esc_path
($basename);
2117 print "<br/></div>\n";
2120 # sub git_print_log (\@;%) {
2121 sub git_print_log
($;%) {
2125 if ($opts{'-remove_title'}) {
2126 # remove title, i.e. first line of log
2129 # remove leading empty lines
2130 while (defined $log->[0] && $log->[0] eq "") {
2137 foreach my $line (@$log) {
2138 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2141 if (! $opts{'-remove_signoff'}) {
2142 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2145 # remove signoff lines
2152 # print only one empty line
2153 # do not print empty line after signoff
2155 next if ($empty || $signoff);
2161 print format_log_line_html
($line) . "<br/>\n";
2164 if ($opts{'-final_empty_line'}) {
2165 # end with single empty line
2166 print "<br/>\n" unless $empty;
2170 # return link target (what link points to)
2171 sub git_get_link_target
{
2176 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2180 $link_target = <$fd>;
2185 return $link_target;
2188 # given link target, and the directory (basedir) the link is in,
2189 # return target of link relative to top directory (top tree);
2190 # return undef if it is not possible (including absolute links).
2191 sub normalize_link_target
{
2192 my ($link_target, $basedir, $hash_base) = @_;
2194 # we can normalize symlink target only if $hash_base is provided
2195 return unless $hash_base;
2197 # absolute symlinks (beginning with '/') cannot be normalized
2198 return if (substr($link_target, 0, 1) eq '/');
2200 # normalize link target to path from top (root) tree (dir)
2203 $path = $basedir . '/' . $link_target;
2205 # we are in top (root) tree (dir)
2206 $path = $link_target;
2209 # remove //, /./, and /../
2211 foreach my $part (split('/', $path)) {
2212 # discard '.' and ''
2213 next if (!$part || $part eq '.');
2215 if ($part eq '..') {
2219 # link leads outside repository (outside top dir)
2223 push @path_parts, $part;
2226 $path = join('/', @path_parts);
2231 # print tree entry (row of git_tree), but without encompassing <tr> element
2232 sub git_print_tree_entry
{
2233 my ($t, $basedir, $hash_base, $have_blame) = @_;
2236 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2238 # The format of a table row is: mode list link. Where mode is
2239 # the mode of the entry, list is the name of the entry, an href,
2240 # and link is the action links of the entry.
2242 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2243 if ($t->{'type'} eq "blob") {
2244 print "<td class=\"list\">" .
2245 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2246 file_name
=>"$basedir$t->{'name'}", %base_key),
2247 -class => "list"}, esc_path
($t->{'name'}));
2248 if (S_ISLNK
(oct $t->{'mode'})) {
2249 my $link_target = git_get_link_target
($t->{'hash'});
2251 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2252 if (defined $norm_target) {
2254 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2255 file_name
=>$norm_target),
2256 -title
=> $norm_target}, esc_path
($link_target));
2258 print " -> " . esc_path
($link_target);
2263 print "<td class=\"link\">";
2264 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2265 file_name
=>"$basedir$t->{'name'}", %base_key)},
2269 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2270 file_name
=>"$basedir$t->{'name'}", %base_key)},
2273 if (defined $hash_base) {
2275 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2276 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2280 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2281 file_name
=>"$basedir$t->{'name'}")},
2285 } elsif ($t->{'type'} eq "tree") {
2286 print "<td class=\"list\">";
2287 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2288 file_name
=>"$basedir$t->{'name'}", %base_key)},
2289 esc_path
($t->{'name'}));
2291 print "<td class=\"link\">";
2292 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2293 file_name
=>"$basedir$t->{'name'}", %base_key)},
2295 if (defined $hash_base) {
2297 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2298 file_name
=>"$basedir$t->{'name'}")},
2305 ## ......................................................................
2306 ## functions printing large fragments of HTML
2308 sub fill_from_file_info
{
2309 my ($diff, @parents) = @_;
2311 $diff->{'from_file'} = [ ];
2312 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2313 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2314 if ($diff->{'status'}[$i] eq 'R' ||
2315 $diff->{'status'}[$i] eq 'C') {
2316 $diff->{'from_file'}[$i] =
2317 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2324 # parameters can be strings, or references to arrays of strings
2328 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @$a == @$b) {
2329 for (my $i = 0; $i < @$a; ++$i) {
2330 return 0 unless ($a->[$i] eq $b->[$i]);
2333 } elsif (!ref($a) && !ref($b)) {
2341 sub git_difftree_body
{
2342 my ($difftree, $hash, @parents) = @_;
2343 my ($parent) = $parents[0];
2344 my ($have_blame) = gitweb_check_feature
('blame');
2345 print "<div class=\"list_head\">\n";
2346 if ($#{$difftree} > 10) {
2347 print(($#{$difftree} + 1) . " files changed:\n");
2351 print "<table class=\"" .
2352 (@parents > 1 ? "combined " : "") .
2356 foreach my $line (@{$difftree}) {
2358 if (ref($line) eq "HASH") {
2359 # pre-parsed (or generated by hand)
2362 $diff = parse_difftree_raw_line
($line);
2366 print "<tr class=\"dark\">\n";
2368 print "<tr class=\"light\">\n";
2372 if (exists $diff->{'nparents'}) { # combined diff
2374 fill_from_file_info
($diff, @parents)
2375 unless exists $diff->{'from_file'};
2377 if ($diff->{'to_id'} ne ('0' x
40)) {
2378 # file exists in the result (child) commit
2380 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2381 file_name
=>$diff->{'to_file'},
2383 -class => "list"}, esc_path
($diff->{'to_file'})) .
2387 esc_path
($diff->{'to_file'}) .
2391 if ($action eq 'commitdiff') {
2394 print "<td class=\"link\">" .
2395 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2400 my $has_history = 0;
2401 my $not_deleted = 0;
2402 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2403 my $hash_parent = $parents[$i];
2404 my $from_hash = $diff->{'from_id'}[$i];
2405 my $from_path = $diff->{'from_file'}[$i];
2406 my $status = $diff->{'status'}[$i];
2408 $has_history ||= ($status ne 'A');
2409 $not_deleted ||= ($status ne 'D');
2411 if ($status eq 'A') {
2412 print "<td class=\"link\" align=\"right\"> | </td>\n";
2413 } elsif ($status eq 'D') {
2414 print "<td class=\"link\">" .
2415 $cgi->a({-href
=> href
(action
=>"blob",
2418 file_name
=>$from_path)},
2422 if ($diff->{'to_id'} eq $from_hash) {
2423 print "<td class=\"link nochange\">";
2425 print "<td class=\"link\">";
2427 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2428 hash
=>$diff->{'to_id'},
2429 hash_parent
=>$from_hash,
2431 hash_parent_base
=>$hash_parent,
2432 file_name
=>$diff->{'to_file'},
2433 file_parent
=>$from_path)},
2439 print "<td class=\"link\">";
2441 print $cgi->a({-href
=> href
(action
=>"blob",
2442 hash
=>$diff->{'to_id'},
2443 file_name
=>$diff->{'to_file'},
2446 print " | " if ($has_history);
2449 print $cgi->a({-href
=> href
(action
=>"history",
2450 file_name
=>$diff->{'to_file'},
2457 next; # instead of 'else' clause, to avoid extra indent
2459 # else ordinary diff
2461 my ($to_mode_oct, $to_mode_str, $to_file_type);
2462 my ($from_mode_oct, $from_mode_str, $from_file_type);
2463 if ($diff->{'to_mode'} ne ('0' x
6)) {
2464 $to_mode_oct = oct $diff->{'to_mode'};
2465 if (S_ISREG
($to_mode_oct)) { # only for regular file
2466 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2468 $to_file_type = file_type
($diff->{'to_mode'});
2470 if ($diff->{'from_mode'} ne ('0' x
6)) {
2471 $from_mode_oct = oct $diff->{'from_mode'};
2472 if (S_ISREG
($to_mode_oct)) { # only for regular file
2473 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2475 $from_file_type = file_type
($diff->{'from_mode'});
2478 if ($diff->{'status'} eq "A") { # created
2479 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2480 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2481 $mode_chng .= "]</span>";
2483 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2484 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2485 -class => "list"}, esc_path
($diff->{'file'}));
2487 print "<td>$mode_chng</td>\n";
2488 print "<td class=\"link\">";
2489 if ($action eq 'commitdiff') {
2492 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2495 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2496 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2500 } elsif ($diff->{'status'} eq "D") { # deleted
2501 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2503 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2504 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2505 -class => "list"}, esc_path
($diff->{'file'}));
2507 print "<td>$mode_chng</td>\n";
2508 print "<td class=\"link\">";
2509 if ($action eq 'commitdiff') {
2512 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2515 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2516 hash_base
=>$parent, file_name
=>$diff->{'file'})},
2519 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2520 file_name
=>$diff->{'file'})},
2523 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2524 file_name
=>$diff->{'file'})},
2528 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2529 my $mode_chnge = "";
2530 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2531 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2532 if ($from_file_type ne $to_file_type) {
2533 $mode_chnge .= " from $from_file_type to $to_file_type";
2535 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2536 if ($from_mode_str && $to_mode_str) {
2537 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2538 } elsif ($to_mode_str) {
2539 $mode_chnge .= " mode: $to_mode_str";
2542 $mode_chnge .= "]</span>\n";
2545 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2546 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2547 -class => "list"}, esc_path
($diff->{'file'}));
2549 print "<td>$mode_chnge</td>\n";
2550 print "<td class=\"link\">";
2551 if ($action eq 'commitdiff') {
2554 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2556 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2557 # "commit" view and modified file (not onlu mode changed)
2558 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2559 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2560 hash_base
=>$hash, hash_parent_base
=>$parent,
2561 file_name
=>$diff->{'file'})},
2565 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2566 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2569 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2570 file_name
=>$diff->{'file'})},
2573 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2574 file_name
=>$diff->{'file'})},
2578 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
2579 my %status_name = ('R' => 'moved', 'C' => 'copied');
2580 my $nstatus = $status_name{$diff->{'status'}};
2582 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2583 # mode also for directories, so we cannot use $to_mode_str
2584 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2587 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2588 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
2589 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
2590 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2591 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2592 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
2593 -class => "list"}, esc_path
($diff->{'from_file'})) .
2594 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2595 "<td class=\"link\">";
2596 if ($action eq 'commitdiff') {
2599 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2601 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2602 # "commit" view and modified file (not only pure rename or copy)
2603 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2604 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2605 hash_base
=>$hash, hash_parent_base
=>$parent,
2606 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
2610 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2611 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
2614 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2615 file_name
=>$diff->{'to_file'})},
2618 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2619 file_name
=>$diff->{'to_file'})},
2623 } # we should not encounter Unmerged (U) or Unknown (X) status
2629 sub git_patchset_body
{
2630 my ($fd, $difftree, $hash, @hash_parents) = @_;
2631 my ($hash_parent) = $hash_parents[0];
2634 my $patch_number = 0;
2639 print "<div class=\"patchset\">\n";
2641 # skip to first patch
2642 while ($patch_line = <$fd>) {
2645 last if ($patch_line =~ m/^diff /);
2649 while ($patch_line) {
2651 my ($from_id, $to_id);
2654 #assert($patch_line =~ m/^diff /) if DEBUG;
2655 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2657 push @diff_header, $patch_line;
2659 # extended diff header
2661 while ($patch_line = <$fd>) {
2664 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2666 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2669 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2670 $from_id = [ split(',', $1) ];
2674 push @diff_header, $patch_line;
2676 my $last_patch_line = $patch_line;
2678 # check if current patch belong to current raw line
2679 # and parse raw git-diff line if needed
2680 if (defined $diffinfo &&
2681 defined $from_id && defined $to_id &&
2682 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
2683 $diffinfo->{'to_id'} eq $to_id) {
2684 # this is continuation of a split patch
2685 print "<div class=\"patch cont\">\n";
2687 # advance raw git-diff output if needed
2688 $patch_idx++ if defined $diffinfo;
2690 # read and prepare patch information
2691 if (ref($difftree->[$patch_idx]) eq "HASH") {
2692 # pre-parsed (or generated by hand)
2693 $diffinfo = $difftree->[$patch_idx];
2695 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2697 if ($diffinfo->{'nparents'}) {
2701 fill_from_file_info
($diffinfo, @hash_parents)
2702 unless exists $diffinfo->{'from_file'};
2703 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2704 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2705 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2706 $from{'href'}[$i] = href
(action
=>"blob",
2707 hash_base
=>$hash_parents[$i],
2708 hash
=>$diffinfo->{'from_id'}[$i],
2709 file_name
=>$from{'file'}[$i]);
2711 $from{'href'}[$i] = undef;
2715 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2716 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2717 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2718 hash
=>$diffinfo->{'from_id'},
2719 file_name
=>$from{'file'});
2721 delete $from{'href'};
2724 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2725 if ($diffinfo->{'status'} ne "D") { # not deleted file
2726 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2727 hash
=>$diffinfo->{'to_id'},
2728 file_name
=>$to{'file'});
2732 # this is first patch for raw difftree line with $patch_idx index
2733 # we index @$difftree array from 0, but number patches from 1
2734 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2737 # print "git diff" header
2738 $patch_line = shift @diff_header;
2739 if ($diffinfo->{'nparents'}) {
2742 $patch_line =~ s!^(diff (.*?) )"?.*$!$1!;
2744 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2745 esc_path
($to{'file'}));
2746 } else { # file was deleted
2747 $patch_line .= esc_path
($to{'file'});
2752 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2753 if ($from{'href'}) {
2754 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2755 'a/' . esc_path
($from{'file'}));
2756 } else { # file was added
2757 $patch_line .= 'a/' . esc_path
($from{'file'});
2761 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2762 'b/' . esc_path
($to{'file'}));
2763 } else { # file was deleted
2764 $patch_line .= 'b/' . esc_path
($to{'file'});
2768 print "<div class=\"diff header\">$patch_line</div>\n";
2770 # print extended diff header
2771 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2773 foreach $patch_line (@diff_header) {
2775 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2776 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2777 esc_path
($from{'file'}));
2779 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2780 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2781 esc_path
($to{'file'}));
2783 # match single <mode>
2784 if ($patch_line =~ m/\s(\d{6})$/) {
2785 $patch_line .= '<span class="info"> (' .
2786 file_type_long
($1) .
2790 if ($patch_line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
2791 # can match only for combined diff
2792 $patch_line = 'index ';
2793 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2794 if ($from{'href'}[$i]) {
2795 $patch_line .= $cgi->a({-href
=>$from{'href'}[$i],
2797 substr($diffinfo->{'from_id'}[$i],0,7));
2799 $patch_line .= '0' x
7;
2802 $patch_line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
2804 $patch_line .= '..';
2806 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2807 substr($diffinfo->{'to_id'},0,7));
2809 $patch_line .= '0' x
7;
2812 } elsif ($patch_line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
2813 # can match only for ordinary diff
2814 my ($from_link, $to_link);
2815 if ($from{'href'}) {
2816 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2817 substr($diffinfo->{'from_id'},0,7));
2819 $from_link = '0' x
7;
2822 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2823 substr($diffinfo->{'to_id'},0,7));
2828 # my ($from_hash, $to_hash) =
2829 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2830 # my ($from_id, $to_id) =
2831 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2832 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2834 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2835 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2837 print $patch_line . "<br/>\n";
2839 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2841 # from-file/to-file diff header
2842 $patch_line = $last_patch_line;
2843 if (! $patch_line) {
2844 print "</div>\n"; # class="patch"
2847 next PATCH
if ($patch_line =~ m/^diff /);
2848 #assert($patch_line =~ m/^---/) if DEBUG;
2849 if (!$diffinfo->{'nparents'} && # not from-file line for combined diff
2850 $from{'href'} && $patch_line =~ m!^--- "?a/!) {
2851 $patch_line = '--- a/' .
2852 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2853 esc_path
($from{'file'}));
2855 print "<div class=\"diff from_file\">$patch_line</div>\n";
2857 $patch_line = <$fd>;
2860 #assert($patch_line =~ m/^+++/) if DEBUG;
2861 if ($to{'href'} && $patch_line =~ m!^\+\+\+ "?b/!) {
2862 $patch_line = '+++ b/' .
2863 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2864 esc_path
($to{'file'}));
2866 print "<div class=\"diff to_file\">$patch_line</div>\n";
2870 while ($patch_line = <$fd>) {
2873 next PATCH
if ($patch_line =~ m/^diff /);
2875 print format_diff_line
($patch_line, \
%from, \
%to);
2879 print "</div>\n"; # class="patch"
2881 print "<div class=\"diff nodifferences\">No differences found</div>\n" if (!$patch_number);
2883 print "</div>\n"; # class="patchset"
2886 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2888 sub git_project_list_body
{
2889 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2891 my ($check_forks) = gitweb_check_feature
('forks');
2894 foreach my $pr (@$projlist) {
2895 my (@aa) = git_get_last_activity
($pr->{'path'});
2899 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2900 if (!defined $pr->{'descr'}) {
2901 my $descr = git_get_project_description
($pr->{'path'}) || "";
2902 $pr->{'descr_long'} = decode_utf8
($descr);
2903 $pr->{'descr'} = chop_str
($descr, 25, 5);
2905 if (!defined $pr->{'owner'}) {
2906 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2909 my $pname = $pr->{'path'};
2910 if (($pname =~ s/\.git$//) &&
2911 ($pname !~ /\/$/) &&
2912 (-d
"$projectroot/$pname")) {
2913 $pr->{'forks'} = "-d $projectroot/$pname";
2919 push @projects, $pr;
2922 $order ||= $default_projects_order;
2923 $from = 0 unless defined $from;
2924 $to = $#projects if (!defined $to || $#projects < $to);
2926 print "<table class=\"project_list\">\n";
2927 unless ($no_header) {
2930 print "<th></th>\n";
2932 if ($order eq "project") {
2933 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2934 print "<th>Project</th>\n";
2937 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2938 -class => "header"}, "Project") .
2941 if ($order eq "descr") {
2942 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2943 print "<th>Description</th>\n";
2946 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2947 -class => "header"}, "Description") .
2950 if ($order eq "owner") {
2951 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2952 print "<th>Owner</th>\n";
2955 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2956 -class => "header"}, "Owner") .
2959 if ($order eq "age") {
2960 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2961 print "<th>Last Change</th>\n";
2964 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2965 -class => "header"}, "Last Change") .
2968 print "<th></th>\n" .
2972 for (my $i = $from; $i <= $to; $i++) {
2973 my $pr = $projects[$i];
2975 print "<tr class=\"dark\">\n";
2977 print "<tr class=\"light\">\n";
2982 if ($pr->{'forks'}) {
2983 print "<!-- $pr->{'forks'} -->\n";
2984 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2988 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2989 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2990 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2991 -class => "list", -title
=> $pr->{'descr_long'}},
2992 esc_html
($pr->{'descr'})) . "</td>\n" .
2993 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2994 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2995 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
2996 "<td class=\"link\">" .
2997 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2998 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2999 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3000 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3001 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3005 if (defined $extra) {
3008 print "<td></td>\n";
3010 print "<td colspan=\"5\">$extra</td>\n" .
3016 sub git_shortlog_body
{
3017 # uses global variable $project
3018 my ($commitlist, $from, $to, $refs, $extra) = @_;
3020 my $have_snapshot = gitweb_have_snapshot
();
3022 $from = 0 unless defined $from;
3023 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3025 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3027 for (my $i = $from; $i <= $to; $i++) {
3028 my %co = %{$commitlist->[$i]};
3029 my $commit = $co{'id'};
3030 my $ref = format_ref_marker
($refs, $commit);
3032 print "<tr class=\"dark\">\n";
3034 print "<tr class=\"light\">\n";
3037 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3038 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3039 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3041 print format_subject_html
($co{'title'}, $co{'title_short'},
3042 href
(action
=>"commit", hash
=>$commit), $ref);
3044 "<td class=\"link\">" .
3045 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3046 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3047 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3048 if ($have_snapshot) {
3049 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
3054 if (defined $extra) {
3056 "<td colspan=\"4\">$extra</td>\n" .
3062 sub git_history_body
{
3063 # Warning: assumes constant type (blob or tree) during history
3064 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3066 $from = 0 unless defined $from;
3067 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3069 print "<table class=\"history\" cellspacing=\"0\">\n";
3071 for (my $i = $from; $i <= $to; $i++) {
3072 my %co = %{$commitlist->[$i]};
3076 my $commit = $co{'id'};
3078 my $ref = format_ref_marker
($refs, $commit);
3081 print "<tr class=\"dark\">\n";
3083 print "<tr class=\"light\">\n";
3086 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3087 # shortlog uses chop_str($co{'author_name'}, 10)
3088 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3090 # originally git_history used chop_str($co{'title'}, 50)
3091 print format_subject_html
($co{'title'}, $co{'title_short'},
3092 href
(action
=>"commit", hash
=>$commit), $ref);
3094 "<td class=\"link\">" .
3095 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3096 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3098 if ($ftype eq 'blob') {
3099 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3100 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3101 if (defined $blob_current && defined $blob_parent &&
3102 $blob_current ne $blob_parent) {
3104 $cgi->a({-href
=> href
(action
=>"blobdiff",
3105 hash
=>$blob_current, hash_parent
=>$blob_parent,
3106 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3107 file_name
=>$file_name)},
3114 if (defined $extra) {
3116 "<td colspan=\"4\">$extra</td>\n" .
3123 # uses global variable $project
3124 my ($taglist, $from, $to, $extra) = @_;
3125 $from = 0 unless defined $from;
3126 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3128 print "<table class=\"tags\" cellspacing=\"0\">\n";
3130 for (my $i = $from; $i <= $to; $i++) {
3131 my $entry = $taglist->[$i];
3133 my $comment = $tag{'subject'};
3135 if (defined $comment) {
3136 $comment_short = chop_str
($comment, 30, 5);
3139 print "<tr class=\"dark\">\n";
3141 print "<tr class=\"light\">\n";
3144 if (defined $tag{'age'}) {
3145 print "<td><i>$tag{'age'}</i></td>\n";
3147 print "<td></td>\n";
3150 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3151 -class => "list name"}, esc_html
($tag{'name'})) .
3154 if (defined $comment) {
3155 print format_subject_html
($comment, $comment_short,
3156 href
(action
=>"tag", hash
=>$tag{'id'}));
3159 "<td class=\"selflink\">";
3160 if ($tag{'type'} eq "tag") {
3161 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3166 "<td class=\"link\">" . " | " .
3167 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3168 if ($tag{'reftype'} eq "commit") {
3169 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3170 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3171 } elsif ($tag{'reftype'} eq "blob") {
3172 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3177 if (defined $extra) {
3179 "<td colspan=\"5\">$extra</td>\n" .
3185 sub git_heads_body
{
3186 # uses global variable $project
3187 my ($headlist, $head, $from, $to, $extra) = @_;
3188 $from = 0 unless defined $from;
3189 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3191 print "<table class=\"heads\" cellspacing=\"0\">\n";
3193 for (my $i = $from; $i <= $to; $i++) {
3194 my $entry = $headlist->[$i];
3196 my $curr = $ref{'id'} eq $head;
3198 print "<tr class=\"dark\">\n";
3200 print "<tr class=\"light\">\n";
3203 print "<td><i>$ref{'age'}</i></td>\n" .
3204 ($curr ? "<td class=\"current_head\">" : "<td>") .
3205 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3206 -class => "list name"},esc_html
($ref{'name'})) .
3208 "<td class=\"link\">" .
3209 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3210 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3211 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3215 if (defined $extra) {
3217 "<td colspan=\"3\">$extra</td>\n" .
3223 sub git_search_grep_body
{
3224 my ($commitlist, $from, $to, $extra) = @_;
3225 $from = 0 unless defined $from;
3226 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3228 print "<table class=\"grep\" cellspacing=\"0\">\n";
3230 for (my $i = $from; $i <= $to; $i++) {
3231 my %co = %{$commitlist->[$i]};
3235 my $commit = $co{'id'};
3237 print "<tr class=\"dark\">\n";
3239 print "<tr class=\"light\">\n";
3242 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3243 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3245 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3246 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3247 my $comment = $co{'comment'};
3248 foreach my $line (@$comment) {
3249 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3250 my $lead = esc_html
($1) || "";
3251 $lead = chop_str
($lead, 30, 10);
3252 my $match = esc_html
($2) || "";
3253 my $trail = esc_html
($3) || "";
3254 $trail = chop_str
($trail, 30, 10);
3255 my $text = "$lead<span class=\"match\">$match</span>$trail";
3256 print chop_str
($text, 80, 5) . "<br/>\n";
3260 "<td class=\"link\">" .
3261 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3263 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3267 if (defined $extra) {
3269 "<td colspan=\"3\">$extra</td>\n" .
3275 ## ======================================================================
3276 ## ======================================================================
3279 sub git_project_list
{
3280 my $order = $cgi->param('o');
3281 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3282 die_error
(undef, "Unknown order parameter");
3285 my @list = git_get_projects_list
();
3287 die_error
(undef, "No projects found");
3291 if (-f
$home_text) {
3292 print "<div class=\"index_include\">\n";
3293 open (my $fd, $home_text);
3298 git_project_list_body
(\
@list, $order);
3303 my $order = $cgi->param('o');
3304 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3305 die_error
(undef, "Unknown order parameter");
3308 my @list = git_get_projects_list
($project);
3310 die_error
(undef, "No forks found");
3314 git_print_page_nav
('','');
3315 git_print_header_div
('summary', "$project forks");
3316 git_project_list_body
(\
@list, $order);
3320 sub git_project_index
{
3321 my @projects = git_get_projects_list
($project);
3324 -type
=> 'text/plain',
3325 -charset
=> 'utf-8',
3326 -content_disposition
=> 'inline; filename="index.aux"');
3328 foreach my $pr (@projects) {
3329 if (!exists $pr->{'owner'}) {
3330 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3333 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3334 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3335 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3336 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3340 print "$path $owner\n";
3345 my $descr = git_get_project_description
($project) || "none";
3346 my %co = parse_commit
("HEAD");
3347 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3348 my $head = $co{'id'};
3350 my $owner = git_get_project_owner
($project);
3352 my $refs = git_get_references
();
3353 # These get_*_list functions return one more to allow us to see if
3354 # there are more ...
3355 my @taglist = git_get_tags_list
(16);
3356 my @headlist = git_get_heads_list
(16);
3358 my ($check_forks) = gitweb_check_feature
('forks');
3361 @forklist = git_get_projects_list
($project);
3365 git_print_page_nav
('summary','', $head);
3367 print "<div class=\"title\"> </div>\n";
3368 print "<table cellspacing=\"0\">\n" .
3369 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3370 "<tr><td>owner</td><td>$owner</td></tr>\n";
3371 if (defined $cd{'rfc2822'}) {
3372 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3375 # use per project git URL list in $projectroot/$project/cloneurl
3376 # or make project git URL from git base URL and project name
3377 my $url_tag = "URL";
3378 my @url_list = git_get_project_url_list
($project);
3379 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3380 foreach my $git_url (@url_list) {
3381 next unless $git_url;
3382 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3387 if (-s
"$projectroot/$project/README.html") {
3388 if (open my $fd, "$projectroot/$project/README.html") {
3389 print "<div class=\"title\">readme</div>\n";
3390 print $_ while (<$fd>);
3395 # we need to request one more than 16 (0..15) to check if
3397 my @commitlist = $head ? parse_commits
($head, 17) : ();
3399 git_print_header_div
('shortlog');
3400 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3401 $#commitlist <= 15 ? undef :
3402 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3406 git_print_header_div
('tags');
3407 git_tags_body
(\
@taglist, 0, 15,
3408 $#taglist <= 15 ? undef :
3409 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3413 git_print_header_div
('heads');
3414 git_heads_body
(\
@headlist, $head, 0, 15,
3415 $#headlist <= 15 ? undef :
3416 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3420 git_print_header_div
('forks');
3421 git_project_list_body
(\
@forklist, undef, 0, 15,
3422 $#forklist <= 15 ? undef :
3423 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3431 my $head = git_get_head_hash
($project);
3433 git_print_page_nav
('','', $head,undef,$head);
3434 my %tag = parse_tag
($hash);
3437 die_error
(undef, "Unknown tag object");
3440 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3441 print "<div class=\"title_text\">\n" .
3442 "<table cellspacing=\"0\">\n" .
3444 "<td>object</td>\n" .
3445 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3446 $tag{'object'}) . "</td>\n" .
3447 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3448 $tag{'type'}) . "</td>\n" .
3450 if (defined($tag{'author'})) {
3451 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3452 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3453 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3454 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3457 print "</table>\n\n" .
3459 print "<div class=\"page_body\">";
3460 my $comment = $tag{'comment'};
3461 foreach my $line (@$comment) {
3463 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3473 my ($have_blame) = gitweb_check_feature
('blame');
3475 die_error
('403 Permission denied', "Permission denied");
3477 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3478 $hash_base ||= git_get_head_hash
($project);
3479 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3480 my %co = parse_commit
($hash_base)
3481 or die_error
(undef, "Reading commit failed");
3482 if (!defined $hash) {
3483 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3484 or die_error
(undef, "Error looking up file");
3486 $ftype = git_get_type
($hash);
3487 if ($ftype !~ "blob") {
3488 die_error
('400 Bad Request', "Object is not a blob");
3490 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3491 $file_name, $hash_base)
3492 or die_error
(undef, "Open git-blame failed");
3495 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3498 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3501 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3503 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3504 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3505 git_print_page_path
($file_name, $ftype, $hash_base);
3506 my @rev_color = (qw(light2 dark2));
3507 my $num_colors = scalar(@rev_color);
3508 my $current_color = 0;
3511 <div class="page_body">
3512 <table class="blame">
3513 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3518 last unless defined $_;
3519 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3520 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3521 if (!exists $metainfo{$full_rev}) {
3522 $metainfo{$full_rev} = {};
3524 my $meta = $metainfo{$full_rev};
3527 if (/^(\S+) (.*)$/) {
3533 my $rev = substr($full_rev, 0, 8);
3534 my $author = $meta->{'author'};
3535 my %date = parse_date
($meta->{'author-time'},
3536 $meta->{'author-tz'});
3537 my $date = $date{'iso-tz'};
3539 $current_color = ++$current_color % $num_colors;
3541 print "<tr class=\"$rev_color[$current_color]\">\n";
3543 print "<td class=\"sha1\"";
3544 print " title=\"". esc_html
($author) . ", $date\"";
3545 print " rowspan=\"$group_size\"" if ($group_size > 1);
3547 print $cgi->a({-href
=> href
(action
=>"commit",
3549 file_name
=>$file_name)},
3553 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3554 or die_error
(undef, "Open git-rev-parse failed");
3555 my $parent_commit = <$dd>;
3557 chomp($parent_commit);
3558 my $blamed = href
(action
=> 'blame',
3559 file_name
=> $meta->{'filename'},
3560 hash_base
=> $parent_commit);
3561 print "<td class=\"linenr\">";
3562 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3564 -class => "linenr" },
3567 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3573 or print "Reading blob failed\n";
3580 my ($have_blame) = gitweb_check_feature
('blame');
3582 die_error
('403 Permission denied', "Permission denied");
3584 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3585 $hash_base ||= git_get_head_hash
($project);
3586 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3587 my %co = parse_commit
($hash_base)
3588 or die_error
(undef, "Reading commit failed");
3589 if (!defined $hash) {
3590 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3591 or die_error
(undef, "Error lookup file");
3593 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3594 or die_error
(undef, "Open git-annotate failed");
3597 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3600 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3603 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3605 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3606 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3607 git_print_page_path
($file_name, 'blob', $hash_base);
3608 print "<div class=\"page_body\">\n";
3610 <table class="blame">
3619 my @line_class = (qw(light dark));
3620 my $line_class_len = scalar (@line_class);
3621 my $line_class_num = $#line_class;
3622 while (my $line = <$fd>) {
3634 $line_class_num = ($line_class_num + 1) % $line_class_len;
3636 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3643 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3646 $short_rev = substr ($long_rev, 0, 8);
3647 $age = time () - $time;
3648 $age_str = age_string
($age);
3649 $age_str =~ s/ / /g;
3650 $age_class = age_class
($age);
3651 $author = esc_html
($author);
3652 $author =~ s/ / /g;
3654 $data = untabify
($data);
3655 $data = esc_html
($data);
3658 <tr class="$line_class[$line_class_num]">
3659 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3660 <td class="$age_class">$age_str</td>
3662 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3663 <td class="pre">$data</td>
3666 } # while (my $line = <$fd>)
3667 print "</table>\n\n";
3669 or print "Reading blob failed.\n";
3675 my $head = git_get_head_hash
($project);
3677 git_print_page_nav
('','', $head,undef,$head);
3678 git_print_header_div
('summary', $project);
3680 my @tagslist = git_get_tags_list
();
3682 git_tags_body
(\
@tagslist);
3688 my $head = git_get_head_hash
($project);
3690 git_print_page_nav
('','', $head,undef,$head);
3691 git_print_header_div
('summary', $project);
3693 my @headslist = git_get_heads_list
();
3695 git_heads_body
(\
@headslist, $head);
3700 sub git_blob_plain
{
3703 if (!defined $hash) {
3704 if (defined $file_name) {
3705 my $base = $hash_base || git_get_head_hash
($project);
3706 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3707 or die_error
(undef, "Error lookup file");
3709 die_error
(undef, "No file name defined");
3711 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3712 # blobs defined by non-textual hash id's can be cached
3717 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3718 or die_error
(undef, "Couldn't cat $file_name, $hash");
3720 $type ||= blob_mimetype
($fd, $file_name);
3722 # save as filename, even when no $file_name is given
3723 my $save_as = "$hash";
3724 if (defined $file_name) {
3725 $save_as = $file_name;
3726 } elsif ($type =~ m/^text\//) {
3733 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3735 binmode STDOUT
, ':raw';
3737 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3745 if (!defined $hash) {
3746 if (defined $file_name) {
3747 my $base = $hash_base || git_get_head_hash
($project);
3748 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3749 or die_error
(undef, "Error lookup file");
3751 die_error
(undef, "No file name defined");
3753 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3754 # blobs defined by non-textual hash id's can be cached
3758 my ($have_blame) = gitweb_check_feature
('blame');
3759 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3760 or die_error
(undef, "Couldn't cat $file_name, $hash");
3761 my $mimetype = blob_mimetype
($fd, $file_name);
3762 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3764 return git_blob_plain
($mimetype);
3766 # we can have blame only for text/* mimetype
3767 $have_blame &&= ($mimetype =~ m!^text/!);
3769 git_header_html
(undef, $expires);
3770 my $formats_nav = '';
3771 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3772 if (defined $file_name) {
3775 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3776 hash
=>$hash, file_name
=>$file_name)},
3781 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3782 hash
=>$hash, file_name
=>$file_name)},
3785 $cgi->a({-href
=> href
(action
=>"blob_plain",
3786 hash
=>$hash, file_name
=>$file_name)},
3789 $cgi->a({-href
=> href
(action
=>"blob",
3790 hash_base
=>"HEAD", file_name
=>$file_name)},
3794 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3796 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3797 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3799 print "<div class=\"page_nav\">\n" .
3800 "<br/><br/></div>\n" .
3801 "<div class=\"title\">$hash</div>\n";
3803 git_print_page_path
($file_name, "blob", $hash_base);
3804 print "<div class=\"page_body\">\n";
3805 if ($mimetype =~ m!^text/!) {
3807 while (my $line = <$fd>) {
3810 $line = untabify
($line);
3811 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3812 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3814 } elsif ($mimetype =~ m!^image/!) {
3815 print qq
!<img type
="$mimetype"!;
3817 print qq
! alt
="$file_name" title
="$file_name"!;
3820 href(action=>"blob_plain
", hash=>$hash,
3821 hash_base=>$hash_base, file_name=>$file_name) .
3825 or print "Reading blob failed.\n";
3831 my $have_snapshot = gitweb_have_snapshot
();
3833 if (!defined $hash_base) {
3834 $hash_base = "HEAD";
3836 if (!defined $hash) {
3837 if (defined $file_name) {
3838 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3844 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3845 or die_error
(undef, "Open git-ls-tree failed");
3846 my @entries = map { chomp; $_ } <$fd>;
3847 close $fd or die_error
(undef, "Reading tree failed");
3850 my $refs = git_get_references
();
3851 my $ref = format_ref_marker
($refs, $hash_base);
3854 my ($have_blame) = gitweb_check_feature
('blame');
3855 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3857 if (defined $file_name) {
3859 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3860 hash
=>$hash, file_name
=>$file_name)},
3862 $cgi->a({-href
=> href
(action
=>"tree",
3863 hash_base
=>"HEAD", file_name
=>$file_name)},
3866 if ($have_snapshot) {
3867 # FIXME: Should be available when we have no hash base as well.
3869 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3872 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3873 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3876 print "<div class=\"page_nav\">\n";
3877 print "<br/><br/></div>\n";
3878 print "<div class=\"title\">$hash</div>\n";
3880 if (defined $file_name) {
3881 $basedir = $file_name;
3882 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3886 git_print_page_path
($file_name, 'tree', $hash_base);
3887 print "<div class=\"page_body\">\n";
3888 print "<table cellspacing=\"0\">\n";
3890 # '..' (top directory) link if possible
3891 if (defined $hash_base &&
3892 defined $file_name && $file_name =~ m![^/]+$!) {
3894 print "<tr class=\"dark\">\n";
3896 print "<tr class=\"light\">\n";
3900 my $up = $file_name;
3901 $up =~ s!/?[^/]+$!!;
3902 undef $up unless $up;
3903 # based on git_print_tree_entry
3904 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3905 print '<td class="list">';
3906 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3910 print "<td class=\"link\"></td>\n";
3914 foreach my $line (@entries) {
3915 my %t = parse_ls_tree_line
($line, -z
=> 1);
3918 print "<tr class=\"dark\">\n";
3920 print "<tr class=\"light\">\n";
3924 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3928 print "</table>\n" .
3934 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3935 my $have_snapshot = (defined $ctype && defined $suffix);
3936 if (!$have_snapshot) {
3937 die_error
('403 Permission denied', "Permission denied");
3940 if (!defined $hash) {
3941 $hash = git_get_head_hash
($project);
3944 my $filename = decode_utf8
(basename
($project)) . "-$hash.tar.$suffix";
3947 -type
=> "application/$ctype",
3948 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3949 -status
=> '200 OK');
3951 my $git = git_cmd_str
();
3952 my $name = $project;
3953 $name =~ s/\047/\047\\\047\047/g;
3955 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3956 or die_error
(undef, "Execute git-tar-tree failed");
3957 binmode STDOUT
, ':raw';
3959 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3965 my $head = git_get_head_hash
($project);
3966 if (!defined $hash) {
3969 if (!defined $page) {
3972 my $refs = git_get_references
();
3974 my @commitlist = parse_commits
($hash, 101, (100 * $page));
3976 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
3979 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3982 my %co = parse_commit
($hash);
3984 git_print_header_div
('summary', $project);
3985 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3987 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
3988 for (my $i = 0; $i <= $to; $i++) {
3989 my %co = %{$commitlist[$i]};
3991 my $commit = $co{'id'};
3992 my $ref = format_ref_marker
($refs, $commit);
3993 my %ad = parse_date
($co{'author_epoch'});
3994 git_print_header_div
('commit',
3995 "<span class=\"age\">$co{'age_string'}</span>" .
3996 esc_html
($co{'title'}) . $ref,
3998 print "<div class=\"title_text\">\n" .
3999 "<div class=\"log_link\">\n" .
4000 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4002 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4004 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4007 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4010 print "<div class=\"log_body\">\n";
4011 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4014 if ($#commitlist >= 100) {
4015 print "<div class=\"page_nav\">\n";
4016 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4017 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4024 $hash ||= $hash_base || "HEAD";
4025 my %co = parse_commit
($hash);
4027 die_error
(undef, "Unknown commit object");
4029 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4030 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4032 my $parent = $co{'parent'};
4033 my $parents = $co{'parents'}; # listref
4035 # we need to prepare $formats_nav before any parameter munging
4037 if (!defined $parent) {
4039 $formats_nav .= '(initial)';
4040 } elsif (@$parents == 1) {
4041 # single parent commit
4044 $cgi->a({-href
=> href
(action
=>"commit",
4046 esc_html
(substr($parent, 0, 7))) .
4053 $cgi->a({-href
=> href
(action
=>"commit",
4055 esc_html
(substr($_, 0, 7)));
4060 if (!defined $parent) {
4064 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4066 (@$parents <= 1 ? $parent : '-c'),
4068 or die_error
(undef, "Open git-diff-tree failed");
4069 @difftree = map { chomp; $_ } <$fd>;
4070 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4072 # non-textual hash id's can be cached
4074 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4077 my $refs = git_get_references
();
4078 my $ref = format_ref_marker
($refs, $co{'id'});
4080 my $have_snapshot = gitweb_have_snapshot
();
4082 git_header_html
(undef, $expires);
4083 git_print_page_nav
('commit', '',
4084 $hash, $co{'tree'}, $hash,
4087 if (defined $co{'parent'}) {
4088 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4090 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4092 print "<div class=\"title_text\">\n" .
4093 "<table cellspacing=\"0\">\n";
4094 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4096 "<td></td><td> $ad{'rfc2822'}";
4097 if ($ad{'hour_local'} < 6) {
4098 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4099 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4101 printf(" (%02d:%02d %s)",
4102 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4106 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4107 print "<tr><td></td><td> $cd{'rfc2822'}" .
4108 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4110 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4113 "<td class=\"sha1\">" .
4114 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4115 class => "list"}, $co{'tree'}) .
4117 "<td class=\"link\">" .
4118 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4120 if ($have_snapshot) {
4122 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
4127 foreach my $par (@$parents) {
4130 "<td class=\"sha1\">" .
4131 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4132 class => "list"}, $par) .
4134 "<td class=\"link\">" .
4135 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4137 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4144 print "<div class=\"page_body\">\n";
4145 git_print_log
($co{'comment'});
4148 git_difftree_body
(\
@difftree, $hash, @$parents);
4154 # object is defined by:
4155 # - hash or hash_base alone
4156 # - hash_base and file_name
4159 # - hash or hash_base alone
4160 if ($hash || ($hash_base && !defined $file_name)) {
4161 my $object_id = $hash || $hash_base;
4163 my $git_command = git_cmd_str
();
4164 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4165 or die_error
('404 Not Found', "Object does not exist");
4169 or die_error
('404 Not Found', "Object does not exist");
4171 # - hash_base and file_name
4172 } elsif ($hash_base && defined $file_name) {
4173 $file_name =~ s
,/+$,,;
4175 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4176 or die_error
('404 Not Found', "Base object does not exist");
4178 # here errors should not hapen
4179 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4180 or die_error
(undef, "Open git-ls-tree failed");
4184 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4185 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4186 die_error
('404 Not Found', "File or directory for given base does not exist");
4191 die_error
('404 Not Found', "Not enough information to find object");
4194 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4195 hash
=>$hash, hash_base
=>$hash_base,
4196 file_name
=>$file_name),
4197 -status
=> '302 Found');
4201 my $format = shift || 'html';
4208 # preparing $fd and %diffinfo for git_patchset_body
4210 if (defined $hash_base && defined $hash_parent_base) {
4211 if (defined $file_name) {
4213 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4214 $hash_parent_base, $hash_base,
4215 "--", (defined $file_parent ? $file_parent : ()), $file_name
4216 or die_error
(undef, "Open git-diff-tree failed");
4217 @difftree = map { chomp; $_ } <$fd>;
4219 or die_error
(undef, "Reading git-diff-tree failed");
4221 or die_error
('404 Not Found', "Blob diff not found");
4223 } elsif (defined $hash &&
4224 $hash =~ /[0-9a-fA-F]{40}/) {
4225 # try to find filename from $hash
4227 # read filtered raw output
4228 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4229 $hash_parent_base, $hash_base, "--"
4230 or die_error
(undef, "Open git-diff-tree failed");
4232 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4234 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4235 map { chomp; $_ } <$fd>;
4237 or die_error
(undef, "Reading git-diff-tree failed");
4239 or die_error
('404 Not Found', "Blob diff not found");
4242 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4245 if (@difftree > 1) {
4246 die_error
('404 Not Found', "Ambiguous blob diff specification");
4249 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4250 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4251 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4253 $hash_parent ||= $diffinfo{'from_id'};
4254 $hash ||= $diffinfo{'to_id'};
4256 # non-textual hash id's can be cached
4257 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4258 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4263 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4264 '-p', ($format eq 'html' ? "--full-index" : ()),
4265 $hash_parent_base, $hash_base,
4266 "--", (defined $file_parent ? $file_parent : ()), $file_name
4267 or die_error
(undef, "Open git-diff-tree failed");
4270 # old/legacy style URI
4271 if (!%diffinfo && # if new style URI failed
4272 defined $hash && defined $hash_parent) {
4273 # fake git-diff-tree raw output
4274 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4275 $diffinfo{'from_id'} = $hash_parent;
4276 $diffinfo{'to_id'} = $hash;
4277 if (defined $file_name) {
4278 if (defined $file_parent) {
4279 $diffinfo{'status'} = '2';
4280 $diffinfo{'from_file'} = $file_parent;
4281 $diffinfo{'to_file'} = $file_name;
4282 } else { # assume not renamed
4283 $diffinfo{'status'} = '1';
4284 $diffinfo{'from_file'} = $file_name;
4285 $diffinfo{'to_file'} = $file_name;
4287 } else { # no filename given
4288 $diffinfo{'status'} = '2';
4289 $diffinfo{'from_file'} = $hash_parent;
4290 $diffinfo{'to_file'} = $hash;
4293 # non-textual hash id's can be cached
4294 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4295 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4300 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4301 '-p', ($format eq 'html' ? "--full-index" : ()),
4302 $hash_parent, $hash, "--"
4303 or die_error
(undef, "Open git-diff failed");
4305 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4310 if ($format eq 'html') {
4312 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4313 hash
=>$hash, hash_parent
=>$hash_parent,
4314 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4315 file_name
=>$file_name, file_parent
=>$file_parent)},
4317 git_header_html
(undef, $expires);
4318 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4319 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4320 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4322 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4323 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4325 if (defined $file_name) {
4326 git_print_page_path
($file_name, "blob", $hash_base);
4328 print "<div class=\"page_path\"></div>\n";
4331 } elsif ($format eq 'plain') {
4333 -type
=> 'text/plain',
4334 -charset
=> 'utf-8',
4335 -expires
=> $expires,
4336 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4338 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4341 die_error
(undef, "Unknown blobdiff format");
4345 if ($format eq 'html') {
4346 print "<div class=\"page_body\">\n";
4348 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4351 print "</div>\n"; # class="page_body"
4355 while (my $line = <$fd>) {
4356 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4357 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4361 last if $line =~ m!^\+\+\+!;
4369 sub git_blobdiff_plain
{
4370 git_blobdiff
('plain');
4373 sub git_commitdiff
{
4374 my $format = shift || 'html';
4375 $hash ||= $hash_base || "HEAD";
4376 my %co = parse_commit
($hash);
4378 die_error
(undef, "Unknown commit object");
4381 # we need to prepare $formats_nav before any parameter munging
4383 if ($format eq 'html') {
4385 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4386 hash
=>$hash, hash_parent
=>$hash_parent)},
4389 if (defined $hash_parent) {
4390 # commitdiff with two commits given
4391 my $hash_parent_short = $hash_parent;
4392 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4393 $hash_parent_short = substr($hash_parent, 0, 7);
4397 $cgi->a({-href
=> href
(action
=>"commitdiff",
4398 hash
=>$hash_parent)},
4399 esc_html
($hash_parent_short)) .
4401 } elsif (!$co{'parent'}) {
4403 $formats_nav .= ' (initial)';
4404 } elsif (scalar @{$co{'parents'}} == 1) {
4405 # single parent commit
4408 $cgi->a({-href
=> href
(action
=>"commitdiff",
4409 hash
=>$co{'parent'})},
4410 esc_html
(substr($co{'parent'}, 0, 7))) .
4417 $cgi->a({-href
=> href
(action
=>"commitdiff",
4419 esc_html
(substr($_, 0, 7)));
4420 } @{$co{'parents'}} ) .
4425 my $hash_parent_param = $hash_parent;
4426 if (!defined $hash_parent) {
4427 $hash_parent_param =
4428 @{$co{'parents'}} > 1 ? '-c' : $co{'parent'} || '--root';
4434 if ($format eq 'html') {
4435 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4436 "--no-commit-id", "--patch-with-raw", "--full-index",
4437 $hash_parent_param, $hash, "--"
4438 or die_error
(undef, "Open git-diff-tree failed");
4440 while (my $line = <$fd>) {
4442 # empty line ends raw part of diff-tree output
4444 push @difftree, scalar parse_difftree_raw_line
($line);
4447 } elsif ($format eq 'plain') {
4448 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4449 '-p', $hash_parent_param, $hash, "--"
4450 or die_error
(undef, "Open git-diff-tree failed");
4453 die_error
(undef, "Unknown commitdiff format");
4456 # non-textual hash id's can be cached
4458 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4462 # write commit message
4463 if ($format eq 'html') {
4464 my $refs = git_get_references
();
4465 my $ref = format_ref_marker
($refs, $co{'id'});
4467 git_header_html
(undef, $expires);
4468 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4469 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4470 git_print_authorship
(\
%co);
4471 print "<div class=\"page_body\">\n";
4472 if (@{$co{'comment'}} > 1) {
4473 print "<div class=\"log\">\n";
4474 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4475 print "</div>\n"; # class="log"
4478 } elsif ($format eq 'plain') {
4479 my $refs = git_get_references
("tags");
4480 my $tagname = git_get_rev_name_tags
($hash);
4481 my $filename = basename
($project) . "-$hash.patch";
4484 -type
=> 'text/plain',
4485 -charset
=> 'utf-8',
4486 -expires
=> $expires,
4487 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4488 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4491 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4492 Subject: $co{'title'}
4494 print "X-Git-Tag: $tagname\n" if $tagname;
4495 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4497 foreach my $line (@{$co{'comment'}}) {
4504 if ($format eq 'html') {
4505 git_difftree_body
(\
@difftree, $hash, $hash_parent || @{$co{'parents'}});
4508 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent || @{$co{'parents'}});
4510 print "</div>\n"; # class="page_body"
4513 } elsif ($format eq 'plain') {
4517 or print "Reading git-diff-tree failed\n";
4521 sub git_commitdiff_plain
{
4522 git_commitdiff
('plain');
4526 if (!defined $hash_base) {
4527 $hash_base = git_get_head_hash
($project);
4529 if (!defined $page) {
4533 my %co = parse_commit
($hash_base);
4535 die_error
(undef, "Unknown commit object");
4538 my $refs = git_get_references
();
4539 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4541 if (!defined $hash && defined $file_name) {
4542 $hash = git_get_hash_by_path
($hash_base, $file_name);
4544 if (defined $hash) {
4545 $ftype = git_get_type
($hash);
4548 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4550 my $paging_nav = '';
4553 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4554 file_name
=>$file_name)},
4556 $paging_nav .= " ⋅ " .
4557 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4558 file_name
=>$file_name, page
=>$page-1),
4559 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4561 $paging_nav .= "first";
4562 $paging_nav .= " ⋅ prev";
4564 if ($#commitlist >= 100) {
4565 $paging_nav .= " ⋅ " .
4566 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4567 file_name
=>$file_name, page
=>$page+1),
4568 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4570 $paging_nav .= " ⋅ next";
4573 if ($#commitlist >= 100) {
4575 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4576 file_name
=>$file_name, page
=>$page+1),
4577 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4581 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4582 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4583 git_print_page_path
($file_name, $ftype, $hash_base);
4585 git_history_body
(\
@commitlist, 0, 99,
4586 $refs, $hash_base, $ftype, $next_link);
4592 my ($have_search) = gitweb_check_feature
('search');
4593 if (!$have_search) {
4594 die_error
('403 Permission denied', "Permission denied");
4596 if (!defined $searchtext) {
4597 die_error
(undef, "Text field empty");
4599 if (!defined $hash) {
4600 $hash = git_get_head_hash
($project);
4602 my %co = parse_commit
($hash);
4604 die_error
(undef, "Unknown commit object");
4606 if (!defined $page) {
4610 $searchtype ||= 'commit';
4611 if ($searchtype eq 'pickaxe') {
4612 # pickaxe may take all resources of your box and run for several minutes
4613 # with every query - so decide by yourself how public you make this feature
4614 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4615 if (!$have_pickaxe) {
4616 die_error
('403 Permission denied', "Permission denied");
4622 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4624 if ($searchtype eq 'commit') {
4625 $greptype = "--grep=";
4626 } elsif ($searchtype eq 'author') {
4627 $greptype = "--author=";
4628 } elsif ($searchtype eq 'committer') {
4629 $greptype = "--committer=";
4631 $greptype .= $search_regexp;
4632 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4634 my $paging_nav = '';
4637 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4638 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4640 $paging_nav .= " ⋅ " .
4641 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4642 searchtext
=>$searchtext, searchtype
=>$searchtype,
4644 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4646 $paging_nav .= "first";
4647 $paging_nav .= " ⋅ prev";
4649 if ($#commitlist >= 100) {
4650 $paging_nav .= " ⋅ " .
4651 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4652 searchtext
=>$searchtext, searchtype
=>$searchtype,
4654 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4656 $paging_nav .= " ⋅ next";
4659 if ($#commitlist >= 100) {
4661 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4662 searchtext
=>$searchtext, searchtype
=>$searchtype,
4664 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4667 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4668 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4669 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4672 if ($searchtype eq 'pickaxe') {
4673 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4674 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4676 print "<table cellspacing=\"0\">\n";
4679 my $git_command = git_cmd_str
();
4680 open my $fd, "-|", "$git_command rev-list $hash | " .
4681 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
4684 while (my $line = <$fd>) {
4685 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4688 $set{'from_id'} = $3;
4690 $set{'id'} = $set{'to_id'};
4691 if ($set{'id'} =~ m/0{40}/) {
4692 $set{'id'} = $set{'from_id'};
4694 if ($set{'id'} =~ m/0{40}/) {
4698 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4701 print "<tr class=\"dark\">\n";
4703 print "<tr class=\"light\">\n";
4706 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4707 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4709 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4710 -class => "list subject"},
4711 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4712 while (my $setref = shift @files) {
4714 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4715 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4717 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4721 "<td class=\"link\">" .
4722 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4724 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4728 %co = parse_commit
($1);
4738 sub git_search_help
{
4740 git_print_page_nav
('','', $hash,$hash,$hash);
4743 <dt><b>commit</b></dt>
4744 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4745 <dt><b>author</b></dt>
4746 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4747 <dt><b>committer</b></dt>
4748 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4750 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4751 if ($have_pickaxe) {
4753 <dt><b>pickaxe</b></dt>
4754 <dd>All commits that caused the string to appear or disappear from any file (changes that
4755 added, removed or "modified" the string) will be listed. This search can take a while and
4756 takes a lot of strain on the server, so please use it wisely.</dd>
4764 my $head = git_get_head_hash
($project);
4765 if (!defined $hash) {
4768 if (!defined $page) {
4771 my $refs = git_get_references
();
4773 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4775 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
4777 if ($#commitlist >= 100) {
4779 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4780 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4784 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4785 git_print_header_div
('summary', $project);
4787 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
4792 ## ......................................................................
4793 ## feeds (RSS, Atom; OPML)
4796 my $format = shift || 'atom';
4797 my ($have_blame) = gitweb_check_feature
('blame');
4799 # Atom: http://www.atomenabled.org/developers/syndication/
4800 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4801 if ($format ne 'rss' && $format ne 'atom') {
4802 die_error
(undef, "Unknown web feed format");
4805 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4806 my $head = $hash || 'HEAD';
4807 my @commitlist = parse_commits
($head, 150);
4811 my $content_type = "application/$format+xml";
4812 if (defined $cgi->http('HTTP_ACCEPT') &&
4813 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4814 # browser (feed reader) prefers text/xml
4815 $content_type = 'text/xml';
4817 if (defined($commitlist[0])) {
4818 %latest_commit = %{$commitlist[0]};
4819 %latest_date = parse_date
($latest_commit{'author_epoch'});
4821 -type
=> $content_type,
4822 -charset
=> 'utf-8',
4823 -last_modified
=> $latest_date{'rfc2822'});
4826 -type
=> $content_type,
4827 -charset
=> 'utf-8');
4830 # Optimization: skip generating the body if client asks only
4831 # for Last-Modified date.
4832 return if ($cgi->request_method() eq 'HEAD');
4835 my $title = "$site_name - $project/$action";
4836 my $feed_type = 'log';
4837 if (defined $hash) {
4838 $title .= " - '$hash'";
4839 $feed_type = 'branch log';
4840 if (defined $file_name) {
4841 $title .= " :: $file_name";
4842 $feed_type = 'history';
4844 } elsif (defined $file_name) {
4845 $title .= " - $file_name";
4846 $feed_type = 'history';
4848 $title .= " $feed_type";
4849 my $descr = git_get_project_description
($project);
4850 if (defined $descr) {
4851 $descr = esc_html
($descr);
4853 $descr = "$project " .
4854 ($format eq 'rss' ? 'RSS' : 'Atom') .
4857 my $owner = git_get_project_owner
($project);
4858 $owner = esc_html
($owner);
4862 if (defined $file_name) {
4863 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
4864 } elsif (defined $hash) {
4865 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
4867 $alt_url = href
(-full
=>1, action
=>"summary");
4869 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
4870 if ($format eq 'rss') {
4872 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
4875 print "<title>$title</title>\n" .
4876 "<link>$alt_url</link>\n" .
4877 "<description>$descr</description>\n" .
4878 "<language>en</language>\n";
4879 } elsif ($format eq 'atom') {
4881 <feed xmlns="http://www.w3.org/2005/Atom">
4883 print "<title>$title</title>\n" .
4884 "<subtitle>$descr</subtitle>\n" .
4885 '<link rel="alternate" type="text/html" href="' .
4886 $alt_url . '" />' . "\n" .
4887 '<link rel="self" type="' . $content_type . '" href="' .
4888 $cgi->self_url() . '" />' . "\n" .
4889 "<id>" . href
(-full
=>1) . "</id>\n" .
4890 # use project owner for feed author
4891 "<author><name>$owner</name></author>\n";
4892 if (defined $favicon) {
4893 print "<icon>" . esc_url
($favicon) . "</icon>\n";
4895 if (defined $logo_url) {
4896 # not twice as wide as tall: 72 x 27 pixels
4897 print "<logo>" . esc_url
($logo) . "</logo>\n";
4899 if (! %latest_date) {
4900 # dummy date to keep the feed valid until commits trickle in:
4901 print "<updated>1970-01-01T00:00:00Z</updated>\n";
4903 print "<updated>$latest_date{'iso-8601'}</updated>\n";
4908 for (my $i = 0; $i <= $#commitlist; $i++) {
4909 my %co = %{$commitlist[$i]};
4910 my $commit = $co{'id'};
4911 # we read 150, we always show 30 and the ones more recent than 48 hours
4912 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
4915 my %cd = parse_date
($co{'author_epoch'});
4917 # get list of changed files
4918 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4919 $co{'parent'}, $co{'id'}, "--", (defined $file_name ? $file_name : ())
4921 my @difftree = map { chomp; $_ } <$fd>;
4925 # print element (entry, item)
4926 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
4927 if ($format eq 'rss') {
4929 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
4930 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
4931 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
4932 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
4933 "<link>$co_url</link>\n" .
4934 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
4935 "<content:encoded>" .
4937 } elsif ($format eq 'atom') {
4939 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
4940 "<updated>$cd{'iso-8601'}</updated>\n" .
4942 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
4943 if ($co{'author_email'}) {
4944 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
4946 print "</author>\n" .
4947 # use committer for contributor
4949 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
4950 if ($co{'committer_email'}) {
4951 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
4953 print "</contributor>\n" .
4954 "<published>$cd{'iso-8601'}</published>\n" .
4955 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
4956 "<id>$co_url</id>\n" .
4957 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
4958 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
4960 my $comment = $co{'comment'};
4962 foreach my $line (@$comment) {
4963 $line = esc_html
($line);
4966 print "</pre><ul>\n";
4967 foreach my $difftree_line (@difftree) {
4968 my %difftree = parse_difftree_raw_line
($difftree_line);
4969 next if !$difftree{'from_id'};
4971 my $file = $difftree{'file'} || $difftree{'to_file'};
4975 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
4976 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
4977 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
4978 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
4979 -title
=> "diff"}, 'D');
4981 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
4982 file_name
=>$file, hash_base
=>$commit),
4983 -title
=> "blame"}, 'B');
4985 # if this is not a feed of a file history
4986 if (!defined $file_name || $file_name ne $file) {
4987 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
4988 file_name
=>$file, hash
=>$commit),
4989 -title
=> "history"}, 'H');
4991 $file = esc_path
($file);
4995 if ($format eq 'rss') {
4996 print "</ul>]]>\n" .
4997 "</content:encoded>\n" .
4999 } elsif ($format eq 'atom') {
5000 print "</ul>\n</div>\n" .
5007 if ($format eq 'rss') {
5008 print "</channel>\n</rss>\n";
5009 } elsif ($format eq 'atom') {
5023 my @list = git_get_projects_list
();
5025 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5027 <?xml version="1.0" encoding="utf-8"?>
5028 <opml version="1.0">
5030 <title>$site_name OPML Export</title>
5033 <outline text="git RSS feeds">
5036 foreach my $pr (@list) {
5038 my $head = git_get_head_hash
($proj{'path'});
5039 if (!defined $head) {
5042 $git_dir = "$projectroot/$proj{'path'}";
5043 my %co = parse_commit
($head);
5048 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5049 my $rss = "$my_url?p=$proj{'path'};a=rss";
5050 my $html = "$my_url?p=$proj{'path'};a=summary";
5051 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";