3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI-
>compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # core git executable to use
31 # this can just be "git" if your webserver has a sensible PATH
32 our $GIT = "++GIT_BINDIR++/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "++GITWEB_PROJECTROOT++";
38 # target of the home link on top of all pages
39 our $home_link = $my_uri || "/";
41 # string of the home link on top of all pages
42 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
44 # name of your site or organization to appear in page titles
45 # replace this with something more descriptive for clearer bookmarks
46 our $site_name = "++GITWEB_SITENAME++"
47 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
49 # filename of html text to include at top of each page
50 our $site_header = "++GITWEB_SITE_HEADER++";
51 # html text to include at home page
52 our $home_text = "++GITWEB_HOMETEXT++";
53 # filename of html text to include at bottom of each page
54 our $site_footer = "++GITWEB_SITE_FOOTER++";
57 our @stylesheets = ("++GITWEB_CSS++");
58 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
59 our $stylesheet = undef;
61 # URI of GIT logo (72x27 size)
62 our $logo = "++GITWEB_LOGO++";
63 # URI of GIT favicon, assumed to be image/png type
64 our $favicon = "++GITWEB_FAVICON++";
66 # URI and label (title) of GIT logo link
67 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
68 #our $logo_label = "git documentation";
69 our $logo_url = "http://git.or.cz/";
70 our $logo_label = "git homepage";
72 # source of projects list
73 our $projects_list = "++GITWEB_LIST++";
75 # default order of projects list
76 # valid values are none, project, descr, owner, and age
77 our $default_projects_order = "project";
79 # show repository only if this file exists
80 # (only effective if this variable evaluates to true)
81 our $export_ok = "++GITWEB_EXPORT_OK++";
83 # only allow viewing of repositories also shown on the overview page
84 our $strict_export = "++GITWEB_STRICT_EXPORT++";
86 # list of git base URLs used for URL to where fetch project from,
87 # i.e. full URL is "$git_base_url/$project"
88 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
90 # default blob_plain mimetype and default charset for text/plain blob
91 our $default_blob_plain_mimetype = 'text/plain';
92 our $default_text_plain_charset = undef;
94 # file to use for guessing MIME types before trying /etc/mime.types
95 # (relative to the current git repository)
96 our $mimetypes_file = undef;
98 # You define site-wide feature defaults here; override them with
99 # $GITWEB_CONFIG as necessary.
102 # 'sub' => feature-sub (subroutine),
103 # 'override' => allow-override (boolean),
104 # 'default' => [ default options...] (array reference)}
106 # if feature is overridable (it means that allow-override has true value,
107 # then feature-sub will be called with default options as parameters;
108 # return value of feature-sub indicates if to enable specified feature
110 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
112 # Enable the 'blame' blob view, showing the last commit that modified
113 # each line in the file. This can be very CPU-intensive.
115 # To enable system wide have in $GITWEB_CONFIG
116 # $feature{'blame'}{'default'} = [1];
117 # To have project specific config enable override in $GITWEB_CONFIG
118 # $feature{'blame'}{'override'} = 1;
119 # and in project config gitweb.blame = 0|1;
121 'sub' => \
&feature_blame
,
125 # Enable the 'snapshot' link, providing a compressed tarball of any
126 # tree. This can potentially generate high traffic if you have large
129 # To disable system wide have in $GITWEB_CONFIG
130 # $feature{'snapshot'}{'default'} = [undef];
131 # To have project specific config enable override in $GITWEB_CONFIG
132 # $feature{'snapshot'}{'override'} = 1;
133 # and in project config gitweb.snapshot = none|gzip|bzip2;
135 'sub' => \
&feature_snapshot
,
137 # => [content-encoding, suffix, program]
138 'default' => ['x-gzip', 'gz', 'gzip']},
140 # Enable text search, which will list the commits which match author,
141 # committer or commit text to a given string. Enabled by default.
146 # Enable the pickaxe search, which will list the commits that modified
147 # a given string in a file. This can be practical and quite faster
148 # alternative to 'blame', but still potentially CPU-intensive.
150 # To enable system wide have in $GITWEB_CONFIG
151 # $feature{'pickaxe'}{'default'} = [1];
152 # To have project specific config enable override in $GITWEB_CONFIG
153 # $feature{'pickaxe'}{'override'} = 1;
154 # and in project config gitweb.pickaxe = 0|1;
156 'sub' => \
&feature_pickaxe
,
160 # Make gitweb use an alternative format of the URLs which can be
161 # more readable and natural-looking: project name is embedded
162 # directly in the path and the query string contains other
163 # auxiliary information. All gitweb installations recognize
164 # URL in either format; this configures in which formats gitweb
167 # To enable system wide have in $GITWEB_CONFIG
168 # $feature{'pathinfo'}{'default'} = [1];
169 # Project specific override is not supported.
171 # Note that you will need to change the default location of CSS,
172 # favicon, logo and possibly other files to an absolute URL. Also,
173 # if gitweb.cgi serves as your indexfile, you will need to force
174 # $my_uri to contain the script name in your $GITWEB_CONFIG.
179 # Make gitweb consider projects in project root subdirectories
180 # to be forks of existing projects. Given project $projname.git,
181 # projects matching $projname/*.git will not be shown in the main
182 # projects list, instead a '+' mark will be added to $projname
183 # there and a 'forks' view will be enabled for the project, listing
184 # all the forks. If project list is taken from a file, forks have
185 # to be listed after the main project.
187 # To enable system wide have in $GITWEB_CONFIG
188 # $feature{'forks'}{'default'} = [1];
189 # Project specific override is not supported.
195 sub gitweb_check_feature
{
197 return unless exists $feature{$name};
198 my ($sub, $override, @defaults) = (
199 $feature{$name}{'sub'},
200 $feature{$name}{'override'},
201 @{$feature{$name}{'default'}});
202 if (!$override) { return @defaults; }
204 warn "feature $name is not overrideable";
207 return $sub->(@defaults);
211 my ($val) = git_get_project_config
('blame', '--bool');
213 if ($val eq 'true') {
215 } elsif ($val eq 'false') {
222 sub feature_snapshot
{
223 my ($ctype, $suffix, $command) = @_;
225 my ($val) = git_get_project_config
('snapshot');
227 if ($val eq 'gzip') {
228 return ('x-gzip', 'gz', 'gzip');
229 } elsif ($val eq 'bzip2') {
230 return ('x-bzip2', 'bz2', 'bzip2');
231 } elsif ($val eq 'none') {
235 return ($ctype, $suffix, $command);
238 sub gitweb_have_snapshot
{
239 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
240 my $have_snapshot = (defined $ctype && defined $suffix);
242 return $have_snapshot;
245 sub feature_pickaxe
{
246 my ($val) = git_get_project_config
('pickaxe', '--bool');
248 if ($val eq 'true') {
250 } elsif ($val eq 'false') {
257 # checking HEAD file with -e is fragile if the repository was
258 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
260 sub check_head_link
{
262 my $headfile = "$dir/HEAD";
263 return ((-e
$headfile) ||
264 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
267 sub check_export_ok
{
269 return (check_head_link
($dir) &&
270 (!$export_ok || -e
"$dir/$export_ok"));
273 # rename detection options for git-diff and git-diff-tree
274 # - default is '-M', with the cost proportional to
275 # (number of removed files) * (number of new files).
276 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
277 # (number of changed files + number of removed files) * (number of new files)
278 # - even more costly is '-C', '--find-copies-harder' with cost
279 # (number of files in the original tree) * (number of new files)
280 # - one might want to include '-B' option, e.g. '-B', '-M'
281 our @diff_opts = ('-M'); # taken from git_commit
283 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
284 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
286 # version of the core git binary
287 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
289 $projects_list ||= $projectroot;
291 # ======================================================================
292 # input validation and dispatch
293 our $action = $cgi->param('a');
294 if (defined $action) {
295 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
296 die_error
(undef, "Invalid action parameter");
300 # parameters which are pathnames
301 our $project = $cgi->param('p');
302 if (defined $project) {
303 if (!validate_pathname
($project) ||
304 !(-d
"$projectroot/$project") ||
305 !check_head_link
("$projectroot/$project") ||
306 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
307 ($strict_export && !project_in_list
($project))) {
309 die_error
(undef, "No such project");
313 our $file_name = $cgi->param('f');
314 if (defined $file_name) {
315 if (!validate_pathname
($file_name)) {
316 die_error
(undef, "Invalid file parameter");
320 our $file_parent = $cgi->param('fp');
321 if (defined $file_parent) {
322 if (!validate_pathname
($file_parent)) {
323 die_error
(undef, "Invalid file parent parameter");
327 # parameters which are refnames
328 our $hash = $cgi->param('h');
330 if (!validate_refname
($hash)) {
331 die_error
(undef, "Invalid hash parameter");
335 our $hash_parent = $cgi->param('hp');
336 if (defined $hash_parent) {
337 if (!validate_refname
($hash_parent)) {
338 die_error
(undef, "Invalid hash parent parameter");
342 our $hash_base = $cgi->param('hb');
343 if (defined $hash_base) {
344 if (!validate_refname
($hash_base)) {
345 die_error
(undef, "Invalid hash base parameter");
349 our $hash_parent_base = $cgi->param('hpb');
350 if (defined $hash_parent_base) {
351 if (!validate_refname
($hash_parent_base)) {
352 die_error
(undef, "Invalid hash parent base parameter");
357 our $page = $cgi->param('pg');
359 if ($page =~ m/[^0-9]/) {
360 die_error
(undef, "Invalid page parameter");
364 our $searchtext = $cgi->param('s');
365 if (defined $searchtext) {
366 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
367 die_error
(undef, "Invalid search parameter");
369 if (length($searchtext) < 2) {
370 die_error
(undef, "At least two characters are required for search parameter");
372 $searchtext = quotemeta $searchtext;
375 our $searchtype = $cgi->param('st');
376 if (defined $searchtype) {
377 if ($searchtype =~ m/[^a-z]/) {
378 die_error
(undef, "Invalid searchtype parameter");
382 # now read PATH_INFO and use it as alternative to parameters
383 sub evaluate_path_info
{
384 return if defined $project;
385 my $path_info = $ENV{"PATH_INFO"};
386 return if !$path_info;
387 $path_info =~ s
,^/+,,;
388 return if !$path_info;
389 # find which part of PATH_INFO is project
390 $project = $path_info;
392 while ($project && !check_head_link
("$projectroot/$project")) {
393 $project =~ s
,/*[^/]*$,,;
396 $project = validate_pathname
($project);
398 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
399 ($strict_export && !project_in_list
($project))) {
403 # do not change any parameters if an action is given using the query string
405 $path_info =~ s
,^$project/*,,;
406 my ($refname, $pathname) = split(/:/, $path_info, 2);
407 if (defined $pathname) {
408 # we got "project.git/branch:filename" or "project.git/branch:dir/"
409 # we could use git_get_type(branch:pathname), but it needs $git_dir
410 $pathname =~ s
,^/+,,;
411 if (!$pathname || substr($pathname, -1) eq "/") {
415 $action ||= "blob_plain";
417 $hash_base ||= validate_refname
($refname);
418 $file_name ||= validate_pathname
($pathname);
419 } elsif (defined $refname) {
420 # we got "project.git/branch"
421 $action ||= "shortlog";
422 $hash ||= validate_refname
($refname);
425 evaluate_path_info
();
427 # path to the current git repository
429 $git_dir = "$projectroot/$project" if $project;
433 "blame" => \
&git_blame2
,
434 "blobdiff" => \
&git_blobdiff
,
435 "blobdiff_plain" => \
&git_blobdiff_plain
,
436 "blob" => \
&git_blob
,
437 "blob_plain" => \
&git_blob_plain
,
438 "commitdiff" => \
&git_commitdiff
,
439 "commitdiff_plain" => \
&git_commitdiff_plain
,
440 "commit" => \
&git_commit
,
441 "forks" => \
&git_forks
,
442 "heads" => \
&git_heads
,
443 "history" => \
&git_history
,
446 "atom" => \
&git_atom
,
447 "search" => \
&git_search
,
448 "search_help" => \
&git_search_help
,
449 "shortlog" => \
&git_shortlog
,
450 "summary" => \
&git_summary
,
452 "tags" => \
&git_tags
,
453 "tree" => \
&git_tree
,
454 "snapshot" => \
&git_snapshot
,
455 "object" => \
&git_object
,
456 # those below don't need $project
457 "opml" => \
&git_opml
,
458 "project_list" => \
&git_project_list
,
459 "project_index" => \
&git_project_index
,
462 if (!defined $action) {
464 $action = git_get_type
($hash);
465 } elsif (defined $hash_base && defined $file_name) {
466 $action = git_get_type
("$hash_base:$file_name");
467 } elsif (defined $project) {
470 $action = 'project_list';
473 if (!defined($actions{$action})) {
474 die_error
(undef, "Unknown action");
476 if ($action !~ m/^(opml|project_list|project_index)$/ &&
478 die_error
(undef, "Project needed");
480 $actions{$action}->();
483 ## ======================================================================
488 # default is to use -absolute url() i.e. $my_uri
489 my $href = $params{-full
} ? $my_url : $my_uri;
491 # XXX: Warning: If you touch this, check the search form for updating,
502 hash_parent_base
=> "hpb",
508 my %mapping = @mapping;
510 $params{'project'} = $project unless exists $params{'project'};
512 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
514 # use PATH_INFO for project name
515 $href .= "/$params{'project'}" if defined $params{'project'};
516 delete $params{'project'};
518 # Summary just uses the project path URL
519 if (defined $params{'action'} && $params{'action'} eq 'summary') {
520 delete $params{'action'};
524 # now encode the parameters explicitly
526 for (my $i = 0; $i < @mapping; $i += 2) {
527 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
528 if (defined $params{$name}) {
529 push @result, $symbol . "=" . esc_param
($params{$name});
532 $href .= "?" . join(';', @result) if scalar @result;
538 ## ======================================================================
539 ## validation, quoting/unquoting and escaping
541 sub validate_pathname
{
542 my $input = shift || return undef;
544 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
545 # at the beginning, at the end, and between slashes.
546 # also this catches doubled slashes
547 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
551 if ($input =~ m!\0!) {
557 sub validate_refname
{
558 my $input = shift || return undef;
560 # textual hashes are O.K.
561 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
564 # it must be correct pathname
565 $input = validate_pathname
($input)
567 # restrictions on ref name according to git-check-ref-format
568 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
574 # quote unsafe chars, but keep the slash, even when it's not
575 # correct, but quoted slashes look too horrible in bookmarks
578 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
584 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
587 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
593 # replace invalid utf8 character with SUBSTITUTION sequence
598 $str = decode_utf8
($str);
599 $str = $cgi->escapeHTML($str);
600 if ($opts{'-nbsp'}) {
601 $str =~ s/ / /g;
603 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
607 # quote control characters and escape filename to HTML
612 $str = decode_utf8
($str);
613 $str = $cgi->escapeHTML($str);
614 if ($opts{'-nbsp'}) {
615 $str =~ s/ / /g;
617 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
621 # Make control characters "printable", using character escape codes (CEC)
624 my %es = ( # character escape codes, aka escape sequences
625 "\t" => '\t', # tab (HT)
626 "\n" => '\n', # line feed (LF)
627 "\r" => '\r', # carrige return (CR)
628 "\f" => '\f', # form feed (FF)
629 "\b" => '\b', # backspace (BS)
630 "\a" => '\a', # alarm (bell) (BEL)
631 "\e" => '\e', # escape (ESC)
632 "\013" => '\v', # vertical tab (VT)
633 "\000" => '\0', # nul character (NUL)
635 my $chr = ( (exists $es{$cntrl})
637 : sprintf('\%03o', ord($cntrl)) );
638 return "<span class=\"cntrl\">$chr</span>";
641 # Alternatively use unicode control pictures codepoints,
642 # Unicode "printable representation" (PR)
645 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
646 return "<span class=\"cntrl\">$chr</span>";
649 # git may return quoted and escaped filenames
655 my %es = ( # character escape codes, aka escape sequences
656 't' => "\t", # tab (HT, TAB)
657 'n' => "\n", # newline (NL)
658 'r' => "\r", # return (CR)
659 'f' => "\f", # form feed (FF)
660 'b' => "\b", # backspace (BS)
661 'a' => "\a", # alarm (bell) (BEL)
662 'e' => "\e", # escape (ESC)
663 'v' => "\013", # vertical tab (VT)
666 if ($seq =~ m/^[0-7]{1,3}$/) {
667 # octal char sequence
668 return chr(oct($seq));
669 } elsif (exists $es{$seq}) {
670 # C escape sequence, aka character escape code
673 # quoted ordinary character
677 if ($str =~ m/^"(.*)"$/) {
680 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
685 # escape tabs (convert tabs to spaces)
689 while ((my $pos = index($line, "\t")) != -1) {
690 if (my $count = (8 - ($pos % 8))) {
691 my $spaces = ' ' x
$count;
692 $line =~ s/\t/$spaces/;
699 sub project_in_list
{
701 my @list = git_get_projects_list
();
702 return @list && scalar(grep { $_->{'path'} eq $project } @list);
705 ## ----------------------------------------------------------------------
706 ## HTML aware string manipulation
711 my $add_len = shift || 10;
713 # allow only $len chars, but don't cut a word if it would fit in $add_len
714 # if it doesn't fit, cut it if it's still longer than the dots we would add
715 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
718 if (length($tail) > 4) {
720 $body =~ s/&[^;]*$//; # remove chopped character entities
725 ## ----------------------------------------------------------------------
726 ## functions returning short strings
728 # CSS class for given age value (in seconds)
734 } elsif ($age < 60*60*2) {
736 } elsif ($age < 60*60*24*2) {
743 # convert age in seconds to "nn units ago" string
748 if ($age > 60*60*24*365*2) {
749 $age_str = (int $age/60/60/24/365);
750 $age_str .= " years ago";
751 } elsif ($age > 60*60*24*(365/12)*2) {
752 $age_str = int $age/60/60/24/(365/12);
753 $age_str .= " months ago";
754 } elsif ($age > 60*60*24*7*2) {
755 $age_str = int $age/60/60/24/7;
756 $age_str .= " weeks ago";
757 } elsif ($age > 60*60*24*2) {
758 $age_str = int $age/60/60/24;
759 $age_str .= " days ago";
760 } elsif ($age > 60*60*2) {
761 $age_str = int $age/60/60;
762 $age_str .= " hours ago";
763 } elsif ($age > 60*2) {
764 $age_str = int $age/60;
765 $age_str .= " min ago";
768 $age_str .= " sec ago";
770 $age_str .= " right now";
775 # convert file mode in octal to symbolic file mode string
777 my $mode = oct shift;
779 if (S_ISDIR
($mode & S_IFMT
)) {
781 } elsif (S_ISLNK
($mode)) {
783 } elsif (S_ISREG
($mode)) {
784 # git cares only about the executable bit
785 if ($mode & S_IXUSR
) {
795 # convert file mode in octal to file type string
799 if ($mode !~ m/^[0-7]+$/) {
805 if (S_ISDIR
($mode & S_IFMT
)) {
807 } elsif (S_ISLNK
($mode)) {
809 } elsif (S_ISREG
($mode)) {
816 # convert file mode in octal to file type description string
820 if ($mode !~ m/^[0-7]+$/) {
826 if (S_ISDIR
($mode & S_IFMT
)) {
828 } elsif (S_ISLNK
($mode)) {
830 } elsif (S_ISREG
($mode)) {
831 if ($mode & S_IXUSR
) {
842 ## ----------------------------------------------------------------------
843 ## functions returning short HTML fragments, or transforming HTML fragments
844 ## which don't belong to other sections
846 # format line of commit message.
847 sub format_log_line_html
{
850 $line = esc_html
($line, -nbsp
=>1);
851 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
854 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
855 -class => "text"}, $hash_text);
856 $line =~ s/$hash_text/$link/;
861 # format marker of refs pointing to given object
862 sub format_ref_marker
{
863 my ($refs, $id) = @_;
866 if (defined $refs->{$id}) {
867 foreach my $ref (@{$refs->{$id}}) {
868 my ($type, $name) = qw();
869 # e.g. tags/v2.6.11 or heads/next
870 if ($ref =~ m!^(.*?)s?/(.*)$!) {
878 $markers .= " <span class=\"$type\" title=\"$ref\">" .
879 esc_html
($name) . "</span>";
884 return ' <span class="refs">'. $markers . '</span>';
890 # format, perhaps shortened and with markers, title line
891 sub format_subject_html
{
892 my ($long, $short, $href, $extra) = @_;
893 $extra = '' unless defined($extra);
895 if (length($short) < length($long)) {
896 return $cgi->a({-href
=> $href, -class => "list subject",
897 -title
=> decode_utf8
($long)},
898 esc_html
($short) . $extra);
900 return $cgi->a({-href
=> $href, -class => "list subject"},
901 esc_html
($long) . $extra);
905 # format patch (diff) line (rather not to be used for diff headers)
906 sub format_diff_line
{
908 my ($from, $to) = @_;
913 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
915 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
916 if ($line =~ m/^\@{3}/) {
917 $diff_class = " chunk_header";
918 } elsif ($line =~ m/^\\/) {
919 $diff_class = " incomplete";
920 } elsif ($prefix =~ tr/+/+/) {
921 $diff_class = " add";
922 } elsif ($prefix =~ tr/-/-/) {
923 $diff_class = " rem";
926 # assume ordinary diff
927 my $char = substr($line, 0, 1);
929 $diff_class = " add";
930 } elsif ($char eq '-') {
931 $diff_class = " rem";
932 } elsif ($char eq '@') {
933 $diff_class = " chunk_header";
934 } elsif ($char eq "\\") {
935 $diff_class = " incomplete";
938 $line = untabify
($line);
939 if ($from && $to && $line =~ m/^\@{2} /) {
940 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
941 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
943 $from_lines = 0 unless defined $from_lines;
944 $to_lines = 0 unless defined $to_lines;
946 if ($from->{'href'}) {
947 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
948 -class=>"list"}, $from_text);
951 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
952 -class=>"list"}, $to_text);
954 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
955 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
956 return "<div class=\"diff$diff_class\">$line</div>\n";
957 } elsif ($from && $to && $line =~ m/^\@{3}/) {
958 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
959 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
961 @from_text = split(' ', $ranges);
962 for (my $i = 0; $i < @from_text; ++$i) {
963 ($from_start[$i], $from_nlines[$i]) =
964 (split(',', substr($from_text[$i], 1)), 0);
967 $to_text = pop @from_text;
968 $to_start = pop @from_start;
969 $to_nlines = pop @from_nlines;
971 $line = "<span class=\"chunk_info\">$prefix ";
972 for (my $i = 0; $i < @from_text; ++$i) {
973 if ($from->{'href'}[$i]) {
974 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
975 -class=>"list"}, $from_text[$i]);
977 $line .= $from_text[$i];
982 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
983 -class=>"list"}, $to_text);
987 $line .= " $prefix</span>" .
988 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
989 return "<div class=\"diff$diff_class\">$line</div>\n";
991 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
994 ## ----------------------------------------------------------------------
995 ## git utility subroutines, invoking git commands
997 # returns path to the core git executable and the --git-dir parameter as list
999 return $GIT, '--git-dir='.$git_dir;
1002 # returns path to the core git executable and the --git-dir parameter as string
1004 return join(' ', git_cmd
());
1007 # get HEAD ref of given project as hash
1008 sub git_get_head_hash
{
1009 my $project = shift;
1010 my $o_git_dir = $git_dir;
1012 $git_dir = "$projectroot/$project";
1013 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1016 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1020 if (defined $o_git_dir) {
1021 $git_dir = $o_git_dir;
1026 # get type of given object
1030 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1032 close $fd or return;
1037 sub git_get_project_config
{
1038 my ($key, $type) = @_;
1040 return unless ($key);
1041 $key =~ s/^gitweb\.//;
1042 return if ($key =~ m/\W/);
1044 my @x = (git_cmd
(), 'config');
1045 if (defined $type) { push @x, $type; }
1047 push @x, "gitweb.$key";
1053 # get hash of given path at given ref
1054 sub git_get_hash_by_path
{
1056 my $path = shift || return undef;
1061 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1062 or die_error
(undef, "Open git-ls-tree failed");
1064 close $fd or return undef;
1066 if (!defined $line) {
1067 # there is no tree or hash given by $path at $base
1071 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1072 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1073 if (defined $type && $type ne $2) {
1074 # type doesn't match
1080 # get path of entry with given hash at given tree-ish (ref)
1081 # used to get 'from' filename for combined diff (merge commit) for renames
1082 sub git_get_path_by_hash
{
1083 my $base = shift || return;
1084 my $hash = shift || return;
1088 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1090 while (my $line = <$fd>) {
1093 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1094 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1095 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1104 ## ......................................................................
1105 ## git utility functions, directly accessing git repository
1107 sub git_get_project_description
{
1110 open my $fd, "$projectroot/$path/description" or return undef;
1117 sub git_get_project_url_list
{
1120 open my $fd, "$projectroot/$path/cloneurl" or return;
1121 my @git_project_url_list = map { chomp; $_ } <$fd>;
1124 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1127 sub git_get_projects_list
{
1132 $filter =~ s/\.git$//;
1134 my ($check_forks) = gitweb_check_feature
('forks');
1136 if (-d
$projects_list) {
1137 # search in directory
1138 my $dir = $projects_list . ($filter ? "/$filter" : '');
1139 # remove the trailing "/"
1141 my $pfxlen = length("$dir");
1144 follow_fast
=> 1, # follow symbolic links
1145 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1147 # skip project-list toplevel, if we get it.
1148 return if (m!^[/.]$!);
1149 # only directories can be git repositories
1150 return unless (-d
$_);
1152 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1153 # we check related file in $projectroot
1154 if ($check_forks and $subdir =~ m
#/.#) {
1155 $File::Find
::prune
= 1;
1156 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1157 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1158 $File::Find
::prune
= 1;
1163 } elsif (-f
$projects_list) {
1164 # read from file(url-encoded):
1165 # 'git%2Fgit.git Linus+Torvalds'
1166 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1167 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1169 open my ($fd), $projects_list or return;
1171 while (my $line = <$fd>) {
1173 my ($path, $owner) = split ' ', $line;
1174 $path = unescape
($path);
1175 $owner = unescape
($owner);
1176 if (!defined $path) {
1179 if ($filter ne '') {
1180 # looking for forks;
1181 my $pfx = substr($path, 0, length($filter));
1182 if ($pfx ne $filter) {
1185 my $sfx = substr($path, length($filter));
1186 if ($sfx !~ /^\/.*\
.git
$/) {
1189 } elsif ($check_forks) {
1191 foreach my $filter (keys %paths) {
1192 # looking for forks;
1193 my $pfx = substr($path, 0, length($filter));
1194 if ($pfx ne $filter) {
1197 my $sfx = substr($path, length($filter));
1198 if ($sfx !~ /^\/.*\
.git
$/) {
1201 # is a fork, don't include it in
1206 if (check_export_ok
("$projectroot/$path")) {
1209 owner
=> decode_utf8
($owner),
1212 (my $forks_path = $path) =~ s/\.git$//;
1213 $paths{$forks_path}++;
1221 sub git_get_project_owner
{
1222 my $project = shift;
1225 return undef unless $project;
1227 # read from file (url-encoded):
1228 # 'git%2Fgit.git Linus+Torvalds'
1229 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1230 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1231 if (-f
$projects_list) {
1232 open (my $fd , $projects_list);
1233 while (my $line = <$fd>) {
1235 my ($pr, $ow) = split ' ', $line;
1236 $pr = unescape
($pr);
1237 $ow = unescape
($ow);
1238 if ($pr eq $project) {
1239 $owner = decode_utf8
($ow);
1245 if (!defined $owner) {
1246 $owner = get_file_owner
("$projectroot/$project");
1252 sub git_get_last_activity
{
1256 $git_dir = "$projectroot/$path";
1257 open($fd, "-|", git_cmd
(), 'for-each-ref',
1258 '--format=%(committer)',
1259 '--sort=-committerdate',
1261 'refs/heads') or return;
1262 my $most_recent = <$fd>;
1263 close $fd or return;
1264 if (defined $most_recent &&
1265 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1267 my $age = time - $timestamp;
1268 return ($age, age_string
($age));
1272 sub git_get_references
{
1273 my $type = shift || "";
1275 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1276 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1277 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1278 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1281 while (my $line = <$fd>) {
1283 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1284 if (defined $refs{$1}) {
1285 push @{$refs{$1}}, $2;
1291 close $fd or return;
1295 sub git_get_rev_name_tags
{
1296 my $hash = shift || return undef;
1298 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1300 my $name_rev = <$fd>;
1303 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1306 # catches also '$hash undefined' output
1311 ## ----------------------------------------------------------------------
1312 ## parse to hash functions
1316 my $tz = shift || "-0000";
1319 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1320 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1321 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1322 $date{'hour'} = $hour;
1323 $date{'minute'} = $min;
1324 $date{'mday'} = $mday;
1325 $date{'day'} = $days[$wday];
1326 $date{'month'} = $months[$mon];
1327 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1328 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1329 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1330 $mday, $months[$mon], $hour ,$min;
1331 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1332 1900+$year, $mon, $mday, $hour ,$min, $sec;
1334 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1335 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1336 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1337 $date{'hour_local'} = $hour;
1338 $date{'minute_local'} = $min;
1339 $date{'tz_local'} = $tz;
1340 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1341 1900+$year, $mon+1, $mday,
1342 $hour, $min, $sec, $tz);
1351 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1352 $tag{'id'} = $tag_id;
1353 while (my $line = <$fd>) {
1355 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1356 $tag{'object'} = $1;
1357 } elsif ($line =~ m/^type (.+)$/) {
1359 } elsif ($line =~ m/^tag (.+)$/) {
1361 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1362 $tag{'author'} = $1;
1365 } elsif ($line =~ m/--BEGIN/) {
1366 push @comment, $line;
1368 } elsif ($line eq "") {
1372 push @comment, <$fd>;
1373 $tag{'comment'} = \
@comment;
1374 close $fd or return;
1375 if (!defined $tag{'name'}) {
1381 sub parse_commit_text
{
1382 my ($commit_text, $withparents) = @_;
1383 my @commit_lines = split '\n', $commit_text;
1386 pop @commit_lines; # Remove '\0'
1388 if (! @commit_lines) {
1392 my $header = shift @commit_lines;
1393 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1396 ($co{'id'}, my @parents) = split ' ', $header;
1397 while (my $line = shift @commit_lines) {
1398 last if $line eq "\n";
1399 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1401 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1403 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1405 $co{'author_epoch'} = $2;
1406 $co{'author_tz'} = $3;
1407 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1408 $co{'author_name'} = $1;
1409 $co{'author_email'} = $2;
1411 $co{'author_name'} = $co{'author'};
1413 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1414 $co{'committer'} = $1;
1415 $co{'committer_epoch'} = $2;
1416 $co{'committer_tz'} = $3;
1417 $co{'committer_name'} = $co{'committer'};
1418 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1419 $co{'committer_name'} = $1;
1420 $co{'committer_email'} = $2;
1422 $co{'committer_name'} = $co{'committer'};
1426 if (!defined $co{'tree'}) {
1429 $co{'parents'} = \
@parents;
1430 $co{'parent'} = $parents[0];
1432 foreach my $title (@commit_lines) {
1435 $co{'title'} = chop_str
($title, 80, 5);
1436 # remove leading stuff of merges to make the interesting part visible
1437 if (length($title) > 50) {
1438 $title =~ s/^Automatic //;
1439 $title =~ s/^merge (of|with) /Merge ... /i;
1440 if (length($title) > 50) {
1441 $title =~ s/(http|rsync):\/\///;
1443 if (length($title) > 50) {
1444 $title =~ s/(master|www|rsync)\.//;
1446 if (length($title) > 50) {
1447 $title =~ s/kernel.org:?//;
1449 if (length($title) > 50) {
1450 $title =~ s/\/pub\/scm//;
1453 $co{'title_short'} = chop_str
($title, 50, 5);
1457 if ($co{'title'} eq "") {
1458 $co{'title'} = $co{'title_short'} = '(no commit message)';
1460 # remove added spaces
1461 foreach my $line (@commit_lines) {
1464 $co{'comment'} = \
@commit_lines;
1466 my $age = time - $co{'committer_epoch'};
1468 $co{'age_string'} = age_string
($age);
1469 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1470 if ($age > 60*60*24*7*2) {
1471 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1472 $co{'age_string_age'} = $co{'age_string'};
1474 $co{'age_string_date'} = $co{'age_string'};
1475 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1481 my ($commit_id) = @_;
1486 open my $fd, "-|", git_cmd
(), "rev-list",
1492 or die_error
(undef, "Open git-rev-list failed");
1493 %co = parse_commit_text
(<$fd>, 1);
1500 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1508 open my $fd, "-|", git_cmd
(), "rev-list",
1510 ($arg ? ($arg) : ()),
1511 ("--max-count=" . $maxcount),
1512 ("--skip=" . $skip),
1515 ($filename ? ($filename) : ())
1516 or die_error
(undef, "Open git-rev-list failed");
1517 while (my $line = <$fd>) {
1518 my %co = parse_commit_text
($line);
1523 return wantarray ? @cos : \
@cos;
1526 # parse ref from ref_file, given by ref_id, with given type
1528 my $ref_file = shift;
1530 my $type = shift || git_get_type
($ref_id);
1533 $ref_item{'type'} = $type;
1534 $ref_item{'id'} = $ref_id;
1535 $ref_item{'epoch'} = 0;
1536 $ref_item{'age'} = "unknown";
1537 if ($type eq "tag") {
1538 my %tag = parse_tag
($ref_id);
1539 $ref_item{'comment'} = $tag{'comment'};
1540 if ($tag{'type'} eq "commit") {
1541 my %co = parse_commit
($tag{'object'});
1542 $ref_item{'epoch'} = $co{'committer_epoch'};
1543 $ref_item{'age'} = $co{'age_string'};
1544 } elsif (defined($tag{'epoch'})) {
1545 my $age = time - $tag{'epoch'};
1546 $ref_item{'epoch'} = $tag{'epoch'};
1547 $ref_item{'age'} = age_string
($age);
1549 $ref_item{'reftype'} = $tag{'type'};
1550 $ref_item{'name'} = $tag{'name'};
1551 $ref_item{'refid'} = $tag{'object'};
1552 } elsif ($type eq "commit"){
1553 my %co = parse_commit
($ref_id);
1554 $ref_item{'reftype'} = "commit";
1555 $ref_item{'name'} = $ref_file;
1556 $ref_item{'title'} = $co{'title'};
1557 $ref_item{'refid'} = $ref_id;
1558 $ref_item{'epoch'} = $co{'committer_epoch'};
1559 $ref_item{'age'} = $co{'age_string'};
1561 $ref_item{'reftype'} = $type;
1562 $ref_item{'name'} = $ref_file;
1563 $ref_item{'refid'} = $ref_id;
1569 # parse line of git-diff-tree "raw" output
1570 sub parse_difftree_raw_line
{
1574 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1575 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1576 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1577 $res{'from_mode'} = $1;
1578 $res{'to_mode'} = $2;
1579 $res{'from_id'} = $3;
1581 $res{'status'} = $5;
1582 $res{'similarity'} = $6;
1583 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1584 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1586 $res{'file'} = unquote
($7);
1589 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1590 # combined diff (for merge commit)
1591 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1592 $res{'nparents'} = length($1);
1593 $res{'from_mode'} = [ split(' ', $2) ];
1594 $res{'to_mode'} = pop @{$res{'from_mode'}};
1595 $res{'from_id'} = [ split(' ', $3) ];
1596 $res{'to_id'} = pop @{$res{'from_id'}};
1597 $res{'status'} = [ split('', $4) ];
1598 $res{'to_file'} = unquote
($5);
1600 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1601 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1602 $res{'commit'} = $1;
1605 return wantarray ? %res : \
%res;
1608 # parse line of git-ls-tree output
1609 sub parse_ls_tree_line
($;%) {
1614 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1615 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1623 $res{'name'} = unquote
($4);
1626 return wantarray ? %res : \
%res;
1629 ## ......................................................................
1630 ## parse to array of hashes functions
1632 sub git_get_heads_list
{
1636 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1637 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1638 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1641 while (my $line = <$fd>) {
1645 my ($refinfo, $committerinfo) = split(/\0/, $line);
1646 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1647 my ($committer, $epoch, $tz) =
1648 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1649 $name =~ s!^refs/heads/!!;
1651 $ref_item{'name'} = $name;
1652 $ref_item{'id'} = $hash;
1653 $ref_item{'title'} = $title || '(no commit message)';
1654 $ref_item{'epoch'} = $epoch;
1656 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1658 $ref_item{'age'} = "unknown";
1661 push @headslist, \
%ref_item;
1665 return wantarray ? @headslist : \
@headslist;
1668 sub git_get_tags_list
{
1672 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1673 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1674 '--format=%(objectname) %(objecttype) %(refname) '.
1675 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1678 while (my $line = <$fd>) {
1682 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1683 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1684 my ($creator, $epoch, $tz) =
1685 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1686 $name =~ s!^refs/tags/!!;
1688 $ref_item{'type'} = $type;
1689 $ref_item{'id'} = $id;
1690 $ref_item{'name'} = $name;
1691 if ($type eq "tag") {
1692 $ref_item{'subject'} = $title;
1693 $ref_item{'reftype'} = $reftype;
1694 $ref_item{'refid'} = $refid;
1696 $ref_item{'reftype'} = $type;
1697 $ref_item{'refid'} = $id;
1700 if ($type eq "tag" || $type eq "commit") {
1701 $ref_item{'epoch'} = $epoch;
1703 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1705 $ref_item{'age'} = "unknown";
1709 push @tagslist, \
%ref_item;
1713 return wantarray ? @tagslist : \
@tagslist;
1716 ## ----------------------------------------------------------------------
1717 ## filesystem-related functions
1719 sub get_file_owner
{
1722 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1723 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1724 if (!defined $gcos) {
1728 $owner =~ s/[,;].*$//;
1729 return decode_utf8
($owner);
1732 ## ......................................................................
1733 ## mimetype related functions
1735 sub mimetype_guess_file
{
1736 my $filename = shift;
1737 my $mimemap = shift;
1738 -r
$mimemap or return undef;
1741 open(MIME
, $mimemap) or return undef;
1743 next if m/^#/; # skip comments
1744 my ($mime, $exts) = split(/\t+/);
1745 if (defined $exts) {
1746 my @exts = split(/\s+/, $exts);
1747 foreach my $ext (@exts) {
1748 $mimemap{$ext} = $mime;
1754 $filename =~ /\.([^.]*)$/;
1755 return $mimemap{$1};
1758 sub mimetype_guess
{
1759 my $filename = shift;
1761 $filename =~ /\./ or return undef;
1763 if ($mimetypes_file) {
1764 my $file = $mimetypes_file;
1765 if ($file !~ m!^/!) { # if it is relative path
1766 # it is relative to project
1767 $file = "$projectroot/$project/$file";
1769 $mime = mimetype_guess_file
($filename, $file);
1771 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1777 my $filename = shift;
1780 my $mime = mimetype_guess
($filename);
1781 $mime and return $mime;
1785 return $default_blob_plain_mimetype unless $fd;
1788 return 'text/plain' .
1789 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1790 } elsif (! $filename) {
1791 return 'application/octet-stream';
1792 } elsif ($filename =~ m/\.png$/i) {
1794 } elsif ($filename =~ m/\.gif$/i) {
1796 } elsif ($filename =~ m/\.jpe?g$/i) {
1797 return 'image/jpeg';
1799 return 'application/octet-stream';
1803 ## ======================================================================
1804 ## functions printing HTML: header, footer, error page
1806 sub git_header_html
{
1807 my $status = shift || "200 OK";
1808 my $expires = shift;
1810 my $title = "$site_name";
1811 if (defined $project) {
1812 $title .= " - " . decode_utf8
($project);
1813 if (defined $action) {
1814 $title .= "/$action";
1815 if (defined $file_name) {
1816 $title .= " - " . esc_path
($file_name);
1817 if ($action eq "tree" && $file_name !~ m
|/$|) {
1824 # require explicit support from the UA if we are to send the page as
1825 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1826 # we have to do this because MSIE sometimes globs '*/*', pretending to
1827 # support xhtml+xml but choking when it gets what it asked for.
1828 if (defined $cgi->http('HTTP_ACCEPT') &&
1829 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1830 $cgi->Accept('application/xhtml+xml') != 0) {
1831 $content_type = 'application/xhtml+xml';
1833 $content_type = 'text/html';
1835 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1836 -status
=> $status, -expires
=> $expires);
1837 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
1839 <?xml version="1.0" encoding="utf-8"?>
1840 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1841 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1842 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1843 <!-- git core binaries version $git_version -->
1845 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1846 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
1847 <meta name="robots" content="index, nofollow"/>
1848 <title>$title</title>
1850 # print out each stylesheet that exist
1851 if (defined $stylesheet) {
1852 #provides backwards capability for those people who define style sheet in a config file
1853 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1855 foreach my $stylesheet (@stylesheets) {
1856 next unless $stylesheet;
1857 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1860 if (defined $project) {
1861 printf('<link rel="alternate" title="%s log RSS feed" '.
1862 'href="%s" type="application/rss+xml" />'."\n",
1863 esc_param
($project), href
(action
=>"rss"));
1864 printf('<link rel="alternate" title="%s log Atom feed" '.
1865 'href="%s" type="application/atom+xml" />'."\n",
1866 esc_param
($project), href
(action
=>"atom"));
1868 printf('<link rel="alternate" title="%s projects list" '.
1869 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1870 $site_name, href
(project
=>undef, action
=>"project_index"));
1871 printf('<link rel="alternate" title="%s projects feeds" '.
1872 'href="%s" type="text/x-opml"/>'."\n",
1873 $site_name, href
(project
=>undef, action
=>"opml"));
1875 if (defined $favicon) {
1876 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1882 if (-f
$site_header) {
1883 open (my $fd, $site_header);
1888 print "<div class=\"page_header\">\n" .
1889 $cgi->a({-href
=> esc_url
($logo_url),
1890 -title
=> $logo_label},
1891 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1892 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1893 if (defined $project) {
1894 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1895 if (defined $action) {
1900 my ($have_search) = gitweb_check_feature
('search');
1901 if ((defined $project) && ($have_search)) {
1902 if (!defined $searchtext) {
1906 if (defined $hash_base) {
1907 $search_hash = $hash_base;
1908 } elsif (defined $hash) {
1909 $search_hash = $hash;
1911 $search_hash = "HEAD";
1913 $cgi->param("a", "search");
1914 $cgi->param("h", $search_hash);
1915 $cgi->param("p", $project);
1916 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1917 "<div class=\"search\">\n" .
1918 $cgi->hidden(-name
=> "p") . "\n" .
1919 $cgi->hidden(-name
=> "a") . "\n" .
1920 $cgi->hidden(-name
=> "h") . "\n" .
1921 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1922 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1923 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1925 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1927 $cgi->end_form() . "\n";
1932 sub git_footer_html
{
1933 print "<div class=\"page_footer\">\n";
1934 if (defined $project) {
1935 my $descr = git_get_project_description
($project);
1936 if (defined $descr) {
1937 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1939 print $cgi->a({-href
=> href
(action
=>"rss"),
1940 -class => "rss_logo"}, "RSS") . " ";
1941 print $cgi->a({-href
=> href
(action
=>"atom"),
1942 -class => "rss_logo"}, "Atom") . "\n";
1944 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1945 -class => "rss_logo"}, "OPML") . " ";
1946 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1947 -class => "rss_logo"}, "TXT") . "\n";
1951 if (-f
$site_footer) {
1952 open (my $fd, $site_footer);
1962 my $status = shift || "403 Forbidden";
1963 my $error = shift || "Malformed query, file missing or permission denied";
1965 git_header_html
($status);
1967 <div class="page_body">
1977 ## ----------------------------------------------------------------------
1978 ## functions printing or outputting HTML: navigation
1980 sub git_print_page_nav
{
1981 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1982 $extra = '' if !defined $extra; # pager or formats
1984 my @navs = qw(summary shortlog log commit commitdiff tree);
1986 @navs = grep { $_ ne $suppress } @navs;
1989 my %arg = map { $_ => {action
=>$_} } @navs;
1990 if (defined $head) {
1991 for (qw(commit commitdiff)) {
1992 $arg{$_}{'hash'} = $head;
1994 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1995 for (qw(shortlog log)) {
1996 $arg{$_}{'hash'} = $head;
2000 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2001 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2003 print "<div class=\"page_nav\">\n" .
2005 map { $_ eq $current ?
2006 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2008 print "<br/>\n$extra<br/>\n" .
2012 sub format_paging_nav
{
2013 my ($action, $hash, $head, $page, $nrevs) = @_;
2017 if ($hash ne $head || $page) {
2018 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2020 $paging_nav .= "HEAD";
2024 $paging_nav .= " ⋅ " .
2025 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2026 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2028 $paging_nav .= " ⋅ prev";
2031 if ($nrevs >= (100 * ($page+1)-1)) {
2032 $paging_nav .= " ⋅ " .
2033 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2034 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2036 $paging_nav .= " ⋅ next";
2042 ## ......................................................................
2043 ## functions printing or outputting HTML: div
2045 sub git_print_header_div
{
2046 my ($action, $title, $hash, $hash_base) = @_;
2049 $args{'action'} = $action;
2050 $args{'hash'} = $hash if $hash;
2051 $args{'hash_base'} = $hash_base if $hash_base;
2053 print "<div class=\"header\">\n" .
2054 $cgi->a({-href
=> href
(%args), -class => "title"},
2055 $title ? $title : $action) .
2059 #sub git_print_authorship (\%) {
2060 sub git_print_authorship
{
2063 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2064 print "<div class=\"author_date\">" .
2065 esc_html
($co->{'author_name'}) .
2067 if ($ad{'hour_local'} < 6) {
2068 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2069 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2071 printf(" (%02d:%02d %s)",
2072 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2077 sub git_print_page_path
{
2083 print "<div class=\"page_path\">";
2084 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2085 -title
=> 'tree root'}, decode_utf8
("[$project]"));
2087 if (defined $name) {
2088 my @dirname = split '/', $name;
2089 my $basename = pop @dirname;
2092 foreach my $dir (@dirname) {
2093 $fullname .= ($fullname ? '/' : '') . $dir;
2094 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2096 -title
=> $fullname}, esc_path
($dir));
2099 if (defined $type && $type eq 'blob') {
2100 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2102 -title
=> $name}, esc_path
($basename));
2103 } elsif (defined $type && $type eq 'tree') {
2104 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2106 -title
=> $name}, esc_path
($basename));
2109 print esc_path
($basename);
2112 print "<br/></div>\n";
2115 # sub git_print_log (\@;%) {
2116 sub git_print_log
($;%) {
2120 if ($opts{'-remove_title'}) {
2121 # remove title, i.e. first line of log
2124 # remove leading empty lines
2125 while (defined $log->[0] && $log->[0] eq "") {
2132 foreach my $line (@$log) {
2133 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2136 if (! $opts{'-remove_signoff'}) {
2137 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2140 # remove signoff lines
2147 # print only one empty line
2148 # do not print empty line after signoff
2150 next if ($empty || $signoff);
2156 print format_log_line_html
($line) . "<br/>\n";
2159 if ($opts{'-final_empty_line'}) {
2160 # end with single empty line
2161 print "<br/>\n" unless $empty;
2165 # return link target (what link points to)
2166 sub git_get_link_target
{
2171 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2175 $link_target = <$fd>;
2180 return $link_target;
2183 # given link target, and the directory (basedir) the link is in,
2184 # return target of link relative to top directory (top tree);
2185 # return undef if it is not possible (including absolute links).
2186 sub normalize_link_target
{
2187 my ($link_target, $basedir, $hash_base) = @_;
2189 # we can normalize symlink target only if $hash_base is provided
2190 return unless $hash_base;
2192 # absolute symlinks (beginning with '/') cannot be normalized
2193 return if (substr($link_target, 0, 1) eq '/');
2195 # normalize link target to path from top (root) tree (dir)
2198 $path = $basedir . '/' . $link_target;
2200 # we are in top (root) tree (dir)
2201 $path = $link_target;
2204 # remove //, /./, and /../
2206 foreach my $part (split('/', $path)) {
2207 # discard '.' and ''
2208 next if (!$part || $part eq '.');
2210 if ($part eq '..') {
2214 # link leads outside repository (outside top dir)
2218 push @path_parts, $part;
2221 $path = join('/', @path_parts);
2226 # print tree entry (row of git_tree), but without encompassing <tr> element
2227 sub git_print_tree_entry
{
2228 my ($t, $basedir, $hash_base, $have_blame) = @_;
2231 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2233 # The format of a table row is: mode list link. Where mode is
2234 # the mode of the entry, list is the name of the entry, an href,
2235 # and link is the action links of the entry.
2237 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2238 if ($t->{'type'} eq "blob") {
2239 print "<td class=\"list\">" .
2240 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2241 file_name
=>"$basedir$t->{'name'}", %base_key),
2242 -class => "list"}, esc_path
($t->{'name'}));
2243 if (S_ISLNK
(oct $t->{'mode'})) {
2244 my $link_target = git_get_link_target
($t->{'hash'});
2246 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2247 if (defined $norm_target) {
2249 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2250 file_name
=>$norm_target),
2251 -title
=> $norm_target}, esc_path
($link_target));
2253 print " -> " . esc_path
($link_target);
2258 print "<td class=\"link\">";
2259 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2260 file_name
=>"$basedir$t->{'name'}", %base_key)},
2264 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2265 file_name
=>"$basedir$t->{'name'}", %base_key)},
2268 if (defined $hash_base) {
2270 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2271 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2275 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2276 file_name
=>"$basedir$t->{'name'}")},
2280 } elsif ($t->{'type'} eq "tree") {
2281 print "<td class=\"list\">";
2282 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2283 file_name
=>"$basedir$t->{'name'}", %base_key)},
2284 esc_path
($t->{'name'}));
2286 print "<td class=\"link\">";
2287 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2288 file_name
=>"$basedir$t->{'name'}", %base_key)},
2290 if (defined $hash_base) {
2292 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2293 file_name
=>"$basedir$t->{'name'}")},
2300 ## ......................................................................
2301 ## functions printing large fragments of HTML
2303 sub fill_from_file_info
{
2304 my ($diff, @parents) = @_;
2306 $diff->{'from_file'} = [ ];
2307 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2308 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2309 if ($diff->{'status'}[$i] eq 'R' ||
2310 $diff->{'status'}[$i] eq 'C') {
2311 $diff->{'from_file'}[$i] =
2312 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2319 # parameters can be strings, or references to arrays of strings
2323 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @$a == @$b) {
2324 for (my $i = 0; $i < @$a; ++$i) {
2325 return 0 unless ($a->[$i] eq $b->[$i]);
2328 } elsif (!ref($a) && !ref($b)) {
2336 sub git_difftree_body
{
2337 my ($difftree, $hash, @parents) = @_;
2338 my ($parent) = $parents[0];
2339 my ($have_blame) = gitweb_check_feature
('blame');
2340 print "<div class=\"list_head\">\n";
2341 if ($#{$difftree} > 10) {
2342 print(($#{$difftree} + 1) . " files changed:\n");
2346 print "<table class=\"" .
2347 (@parents > 1 ? "combined " : "") .
2351 foreach my $line (@{$difftree}) {
2353 if (ref($line) eq "HASH") {
2354 # pre-parsed (or generated by hand)
2357 $diff = parse_difftree_raw_line
($line);
2361 print "<tr class=\"dark\">\n";
2363 print "<tr class=\"light\">\n";
2367 if (exists $diff->{'nparents'}) { # combined diff
2369 fill_from_file_info
($diff, @parents)
2370 unless exists $diff->{'from_file'};
2372 if ($diff->{'to_id'} ne ('0' x
40)) {
2373 # file exists in the result (child) commit
2375 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2376 file_name
=>$diff->{'to_file'},
2378 -class => "list"}, esc_path
($diff->{'to_file'})) .
2382 esc_path
($diff->{'to_file'}) .
2386 if ($action eq 'commitdiff') {
2389 print "<td class=\"link\">" .
2390 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2395 my $has_history = 0;
2396 my $not_deleted = 0;
2397 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2398 my $hash_parent = $parents[$i];
2399 my $from_hash = $diff->{'from_id'}[$i];
2400 my $from_path = $diff->{'from_file'}[$i];
2401 my $status = $diff->{'status'}[$i];
2403 $has_history ||= ($status ne 'A');
2404 $not_deleted ||= ($status ne 'D');
2406 if ($status eq 'A') {
2407 print "<td class=\"link\" align=\"right\"> | </td>\n";
2408 } elsif ($status eq 'D') {
2409 print "<td class=\"link\">" .
2410 $cgi->a({-href
=> href
(action
=>"blob",
2413 file_name
=>$from_path)},
2417 if ($diff->{'to_id'} eq $from_hash) {
2418 print "<td class=\"link nochange\">";
2420 print "<td class=\"link\">";
2422 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2423 hash
=>$diff->{'to_id'},
2424 hash_parent
=>$from_hash,
2426 hash_parent_base
=>$hash_parent,
2427 file_name
=>$diff->{'to_file'},
2428 file_parent
=>$from_path)},
2434 print "<td class=\"link\">";
2436 print $cgi->a({-href
=> href
(action
=>"blob",
2437 hash
=>$diff->{'to_id'},
2438 file_name
=>$diff->{'to_file'},
2441 print " | " if ($has_history);
2444 print $cgi->a({-href
=> href
(action
=>"history",
2445 file_name
=>$diff->{'to_file'},
2452 next; # instead of 'else' clause, to avoid extra indent
2454 # else ordinary diff
2456 my ($to_mode_oct, $to_mode_str, $to_file_type);
2457 my ($from_mode_oct, $from_mode_str, $from_file_type);
2458 if ($diff->{'to_mode'} ne ('0' x
6)) {
2459 $to_mode_oct = oct $diff->{'to_mode'};
2460 if (S_ISREG
($to_mode_oct)) { # only for regular file
2461 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2463 $to_file_type = file_type
($diff->{'to_mode'});
2465 if ($diff->{'from_mode'} ne ('0' x
6)) {
2466 $from_mode_oct = oct $diff->{'from_mode'};
2467 if (S_ISREG
($to_mode_oct)) { # only for regular file
2468 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2470 $from_file_type = file_type
($diff->{'from_mode'});
2473 if ($diff->{'status'} eq "A") { # created
2474 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2475 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2476 $mode_chng .= "]</span>";
2478 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2479 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2480 -class => "list"}, esc_path
($diff->{'file'}));
2482 print "<td>$mode_chng</td>\n";
2483 print "<td class=\"link\">";
2484 if ($action eq 'commitdiff') {
2487 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2490 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2491 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2495 } elsif ($diff->{'status'} eq "D") { # deleted
2496 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2498 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2499 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2500 -class => "list"}, esc_path
($diff->{'file'}));
2502 print "<td>$mode_chng</td>\n";
2503 print "<td class=\"link\">";
2504 if ($action eq 'commitdiff') {
2507 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2510 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2511 hash_base
=>$parent, file_name
=>$diff->{'file'})},
2514 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2515 file_name
=>$diff->{'file'})},
2518 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2519 file_name
=>$diff->{'file'})},
2523 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2524 my $mode_chnge = "";
2525 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2526 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2527 if ($from_file_type ne $to_file_type) {
2528 $mode_chnge .= " from $from_file_type to $to_file_type";
2530 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2531 if ($from_mode_str && $to_mode_str) {
2532 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2533 } elsif ($to_mode_str) {
2534 $mode_chnge .= " mode: $to_mode_str";
2537 $mode_chnge .= "]</span>\n";
2540 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2541 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2542 -class => "list"}, esc_path
($diff->{'file'}));
2544 print "<td>$mode_chnge</td>\n";
2545 print "<td class=\"link\">";
2546 if ($action eq 'commitdiff') {
2549 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2551 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2552 # "commit" view and modified file (not onlu mode changed)
2553 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2554 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2555 hash_base
=>$hash, hash_parent_base
=>$parent,
2556 file_name
=>$diff->{'file'})},
2560 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2561 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2564 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2565 file_name
=>$diff->{'file'})},
2568 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2569 file_name
=>$diff->{'file'})},
2573 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
2574 my %status_name = ('R' => 'moved', 'C' => 'copied');
2575 my $nstatus = $status_name{$diff->{'status'}};
2577 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2578 # mode also for directories, so we cannot use $to_mode_str
2579 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2582 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2583 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
2584 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
2585 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2586 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2587 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
2588 -class => "list"}, esc_path
($diff->{'from_file'})) .
2589 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2590 "<td class=\"link\">";
2591 if ($action eq 'commitdiff') {
2594 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2596 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2597 # "commit" view and modified file (not only pure rename or copy)
2598 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2599 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2600 hash_base
=>$hash, hash_parent_base
=>$parent,
2601 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
2605 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2606 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
2609 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2610 file_name
=>$diff->{'to_file'})},
2613 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2614 file_name
=>$diff->{'to_file'})},
2618 } # we should not encounter Unmerged (U) or Unknown (X) status
2624 sub git_patchset_body
{
2625 my ($fd, $difftree, $hash, @hash_parents) = @_;
2626 my ($hash_parent) = $hash_parents[0];
2629 my $patch_number = 0;
2634 print "<div class=\"patchset\">\n";
2636 # skip to first patch
2637 while ($patch_line = <$fd>) {
2640 last if ($patch_line =~ m/^diff /);
2644 while ($patch_line) {
2646 my ($from_id, $to_id);
2649 #assert($patch_line =~ m/^diff /) if DEBUG;
2650 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2652 push @diff_header, $patch_line;
2654 # extended diff header
2656 while ($patch_line = <$fd>) {
2659 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2661 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2664 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2665 $from_id = [ split(',', $1) ];
2669 push @diff_header, $patch_line;
2671 my $last_patch_line = $patch_line;
2673 # check if current patch belong to current raw line
2674 # and parse raw git-diff line if needed
2675 if (defined $diffinfo &&
2676 defined $from_id && defined $to_id &&
2677 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
2678 $diffinfo->{'to_id'} eq $to_id) {
2679 # this is continuation of a split patch
2680 print "<div class=\"patch cont\">\n";
2682 # advance raw git-diff output if needed
2683 $patch_idx++ if defined $diffinfo;
2685 # read and prepare patch information
2686 if (ref($difftree->[$patch_idx]) eq "HASH") {
2687 # pre-parsed (or generated by hand)
2688 $diffinfo = $difftree->[$patch_idx];
2690 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2692 if ($diffinfo->{'nparents'}) {
2696 fill_from_file_info
($diffinfo, @hash_parents)
2697 unless exists $diffinfo->{'from_file'};
2698 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2699 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2700 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2701 $from{'href'}[$i] = href
(action
=>"blob",
2702 hash_base
=>$hash_parents[$i],
2703 hash
=>$diffinfo->{'from_id'}[$i],
2704 file_name
=>$from{'file'}[$i]);
2706 $from{'href'}[$i] = undef;
2710 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2711 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2712 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2713 hash
=>$diffinfo->{'from_id'},
2714 file_name
=>$from{'file'});
2716 delete $from{'href'};
2719 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2720 if ($diffinfo->{'status'} ne "D") { # not deleted file
2721 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2722 hash
=>$diffinfo->{'to_id'},
2723 file_name
=>$to{'file'});
2727 # this is first patch for raw difftree line with $patch_idx index
2728 # we index @$difftree array from 0, but number patches from 1
2729 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2732 # print "git diff" header
2733 $patch_line = shift @diff_header;
2734 if ($diffinfo->{'nparents'}) {
2737 $patch_line =~ s!^(diff (.*?) )"?.*$!$1!;
2739 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2740 esc_path
($to{'file'}));
2741 } else { # file was deleted
2742 $patch_line .= esc_path
($to{'file'});
2747 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2748 if ($from{'href'}) {
2749 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2750 'a/' . esc_path
($from{'file'}));
2751 } else { # file was added
2752 $patch_line .= 'a/' . esc_path
($from{'file'});
2756 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2757 'b/' . esc_path
($to{'file'}));
2758 } else { # file was deleted
2759 $patch_line .= 'b/' . esc_path
($to{'file'});
2763 print "<div class=\"diff header\">$patch_line</div>\n";
2765 # print extended diff header
2766 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2768 foreach $patch_line (@diff_header) {
2770 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2771 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2772 esc_path
($from{'file'}));
2774 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2775 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2776 esc_path
($to{'file'}));
2778 # match single <mode>
2779 if ($patch_line =~ m/\s(\d{6})$/) {
2780 $patch_line .= '<span class="info"> (' .
2781 file_type_long
($1) .
2785 if ($patch_line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
2786 # can match only for combined diff
2787 $patch_line = 'index ';
2788 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2789 if ($from{'href'}[$i]) {
2790 $patch_line .= $cgi->a({-href
=>$from{'href'}[$i],
2792 substr($diffinfo->{'from_id'}[$i],0,7));
2794 $patch_line .= '0' x
7;
2797 $patch_line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
2799 $patch_line .= '..';
2801 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2802 substr($diffinfo->{'to_id'},0,7));
2804 $patch_line .= '0' x
7;
2807 } elsif ($patch_line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
2808 # can match only for ordinary diff
2809 my ($from_link, $to_link);
2810 if ($from{'href'}) {
2811 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2812 substr($diffinfo->{'from_id'},0,7));
2814 $from_link = '0' x
7;
2817 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2818 substr($diffinfo->{'to_id'},0,7));
2823 # my ($from_hash, $to_hash) =
2824 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2825 # my ($from_id, $to_id) =
2826 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2827 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2829 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2830 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2832 print $patch_line . "<br/>\n";
2834 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2836 # from-file/to-file diff header
2837 $patch_line = $last_patch_line;
2838 if (! $patch_line) {
2839 print "</div>\n"; # class="patch"
2842 next PATCH
if ($patch_line =~ m/^diff /);
2843 #assert($patch_line =~ m/^---/) if DEBUG;
2844 if (!$diffinfo->{'nparents'} && # not from-file line for combined diff
2845 $from{'href'} && $patch_line =~ m!^--- "?a/!) {
2846 $patch_line = '--- a/' .
2847 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2848 esc_path
($from{'file'}));
2850 print "<div class=\"diff from_file\">$patch_line</div>\n";
2852 $patch_line = <$fd>;
2855 #assert($patch_line =~ m/^+++/) if DEBUG;
2856 if ($to{'href'} && $patch_line =~ m!^\+\+\+ "?b/!) {
2857 $patch_line = '+++ b/' .
2858 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2859 esc_path
($to{'file'}));
2861 print "<div class=\"diff to_file\">$patch_line</div>\n";
2865 while ($patch_line = <$fd>) {
2868 next PATCH
if ($patch_line =~ m/^diff /);
2870 print format_diff_line
($patch_line, \
%from, \
%to);
2874 print "</div>\n"; # class="patch"
2876 print "<div class=\"diff nodifferences\">No differences found</div>\n" if (!$patch_number);
2878 print "</div>\n"; # class="patchset"
2881 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2883 sub git_project_list_body
{
2884 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2886 my ($check_forks) = gitweb_check_feature
('forks');
2889 foreach my $pr (@$projlist) {
2890 my (@aa) = git_get_last_activity
($pr->{'path'});
2894 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2895 if (!defined $pr->{'descr'}) {
2896 my $descr = git_get_project_description
($pr->{'path'}) || "";
2897 $pr->{'descr_long'} = decode_utf8
($descr);
2898 $pr->{'descr'} = chop_str
($descr, 25, 5);
2900 if (!defined $pr->{'owner'}) {
2901 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2904 my $pname = $pr->{'path'};
2905 if (($pname =~ s/\.git$//) &&
2906 ($pname !~ /\/$/) &&
2907 (-d
"$projectroot/$pname")) {
2908 $pr->{'forks'} = "-d $projectroot/$pname";
2914 push @projects, $pr;
2917 $order ||= $default_projects_order;
2918 $from = 0 unless defined $from;
2919 $to = $#projects if (!defined $to || $#projects < $to);
2921 print "<table class=\"project_list\">\n";
2922 unless ($no_header) {
2925 print "<th></th>\n";
2927 if ($order eq "project") {
2928 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2929 print "<th>Project</th>\n";
2932 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2933 -class => "header"}, "Project") .
2936 if ($order eq "descr") {
2937 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2938 print "<th>Description</th>\n";
2941 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2942 -class => "header"}, "Description") .
2945 if ($order eq "owner") {
2946 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2947 print "<th>Owner</th>\n";
2950 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2951 -class => "header"}, "Owner") .
2954 if ($order eq "age") {
2955 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2956 print "<th>Last Change</th>\n";
2959 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2960 -class => "header"}, "Last Change") .
2963 print "<th></th>\n" .
2967 for (my $i = $from; $i <= $to; $i++) {
2968 my $pr = $projects[$i];
2970 print "<tr class=\"dark\">\n";
2972 print "<tr class=\"light\">\n";
2977 if ($pr->{'forks'}) {
2978 print "<!-- $pr->{'forks'} -->\n";
2979 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2983 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2984 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2985 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2986 -class => "list", -title
=> $pr->{'descr_long'}},
2987 esc_html
($pr->{'descr'})) . "</td>\n" .
2988 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2989 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2990 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
2991 "<td class=\"link\">" .
2992 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2993 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2994 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2995 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2996 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3000 if (defined $extra) {
3003 print "<td></td>\n";
3005 print "<td colspan=\"5\">$extra</td>\n" .
3011 sub git_shortlog_body
{
3012 # uses global variable $project
3013 my ($commitlist, $from, $to, $refs, $extra) = @_;
3015 my $have_snapshot = gitweb_have_snapshot
();
3017 $from = 0 unless defined $from;
3018 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3020 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3022 for (my $i = $from; $i <= $to; $i++) {
3023 my %co = %{$commitlist->[$i]};
3024 my $commit = $co{'id'};
3025 my $ref = format_ref_marker
($refs, $commit);
3027 print "<tr class=\"dark\">\n";
3029 print "<tr class=\"light\">\n";
3032 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3033 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3034 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3036 print format_subject_html
($co{'title'}, $co{'title_short'},
3037 href
(action
=>"commit", hash
=>$commit), $ref);
3039 "<td class=\"link\">" .
3040 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3041 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3042 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3043 if ($have_snapshot) {
3044 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
3049 if (defined $extra) {
3051 "<td colspan=\"4\">$extra</td>\n" .
3057 sub git_history_body
{
3058 # Warning: assumes constant type (blob or tree) during history
3059 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3061 $from = 0 unless defined $from;
3062 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3064 print "<table class=\"history\" cellspacing=\"0\">\n";
3066 for (my $i = $from; $i <= $to; $i++) {
3067 my %co = %{$commitlist->[$i]};
3071 my $commit = $co{'id'};
3073 my $ref = format_ref_marker
($refs, $commit);
3076 print "<tr class=\"dark\">\n";
3078 print "<tr class=\"light\">\n";
3081 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3082 # shortlog uses chop_str($co{'author_name'}, 10)
3083 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3085 # originally git_history used chop_str($co{'title'}, 50)
3086 print format_subject_html
($co{'title'}, $co{'title_short'},
3087 href
(action
=>"commit", hash
=>$commit), $ref);
3089 "<td class=\"link\">" .
3090 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3091 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3093 if ($ftype eq 'blob') {
3094 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3095 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3096 if (defined $blob_current && defined $blob_parent &&
3097 $blob_current ne $blob_parent) {
3099 $cgi->a({-href
=> href
(action
=>"blobdiff",
3100 hash
=>$blob_current, hash_parent
=>$blob_parent,
3101 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3102 file_name
=>$file_name)},
3109 if (defined $extra) {
3111 "<td colspan=\"4\">$extra</td>\n" .
3118 # uses global variable $project
3119 my ($taglist, $from, $to, $extra) = @_;
3120 $from = 0 unless defined $from;
3121 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3123 print "<table class=\"tags\" cellspacing=\"0\">\n";
3125 for (my $i = $from; $i <= $to; $i++) {
3126 my $entry = $taglist->[$i];
3128 my $comment = $tag{'subject'};
3130 if (defined $comment) {
3131 $comment_short = chop_str
($comment, 30, 5);
3134 print "<tr class=\"dark\">\n";
3136 print "<tr class=\"light\">\n";
3139 if (defined $tag{'age'}) {
3140 print "<td><i>$tag{'age'}</i></td>\n";
3142 print "<td></td>\n";
3145 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3146 -class => "list name"}, esc_html
($tag{'name'})) .
3149 if (defined $comment) {
3150 print format_subject_html
($comment, $comment_short,
3151 href
(action
=>"tag", hash
=>$tag{'id'}));
3154 "<td class=\"selflink\">";
3155 if ($tag{'type'} eq "tag") {
3156 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3161 "<td class=\"link\">" . " | " .
3162 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3163 if ($tag{'reftype'} eq "commit") {
3164 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3165 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3166 } elsif ($tag{'reftype'} eq "blob") {
3167 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3172 if (defined $extra) {
3174 "<td colspan=\"5\">$extra</td>\n" .
3180 sub git_heads_body
{
3181 # uses global variable $project
3182 my ($headlist, $head, $from, $to, $extra) = @_;
3183 $from = 0 unless defined $from;
3184 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3186 print "<table class=\"heads\" cellspacing=\"0\">\n";
3188 for (my $i = $from; $i <= $to; $i++) {
3189 my $entry = $headlist->[$i];
3191 my $curr = $ref{'id'} eq $head;
3193 print "<tr class=\"dark\">\n";
3195 print "<tr class=\"light\">\n";
3198 print "<td><i>$ref{'age'}</i></td>\n" .
3199 ($curr ? "<td class=\"current_head\">" : "<td>") .
3200 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3201 -class => "list name"},esc_html
($ref{'name'})) .
3203 "<td class=\"link\">" .
3204 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3205 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3206 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3210 if (defined $extra) {
3212 "<td colspan=\"3\">$extra</td>\n" .
3218 sub git_search_grep_body
{
3219 my ($commitlist, $from, $to, $extra) = @_;
3220 $from = 0 unless defined $from;
3221 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3223 print "<table class=\"grep\" cellspacing=\"0\">\n";
3225 for (my $i = $from; $i <= $to; $i++) {
3226 my %co = %{$commitlist->[$i]};
3230 my $commit = $co{'id'};
3232 print "<tr class=\"dark\">\n";
3234 print "<tr class=\"light\">\n";
3237 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3238 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3240 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3241 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3242 my $comment = $co{'comment'};
3243 foreach my $line (@$comment) {
3244 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3245 my $lead = esc_html
($1) || "";
3246 $lead = chop_str
($lead, 30, 10);
3247 my $match = esc_html
($2) || "";
3248 my $trail = esc_html
($3) || "";
3249 $trail = chop_str
($trail, 30, 10);
3250 my $text = "$lead<span class=\"match\">$match</span>$trail";
3251 print chop_str
($text, 80, 5) . "<br/>\n";
3255 "<td class=\"link\">" .
3256 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3258 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3262 if (defined $extra) {
3264 "<td colspan=\"3\">$extra</td>\n" .
3270 ## ======================================================================
3271 ## ======================================================================
3274 sub git_project_list
{
3275 my $order = $cgi->param('o');
3276 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3277 die_error
(undef, "Unknown order parameter");
3280 my @list = git_get_projects_list
();
3282 die_error
(undef, "No projects found");
3286 if (-f
$home_text) {
3287 print "<div class=\"index_include\">\n";
3288 open (my $fd, $home_text);
3293 git_project_list_body
(\
@list, $order);
3298 my $order = $cgi->param('o');
3299 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3300 die_error
(undef, "Unknown order parameter");
3303 my @list = git_get_projects_list
($project);
3305 die_error
(undef, "No forks found");
3309 git_print_page_nav
('','');
3310 git_print_header_div
('summary', "$project forks");
3311 git_project_list_body
(\
@list, $order);
3315 sub git_project_index
{
3316 my @projects = git_get_projects_list
($project);
3319 -type
=> 'text/plain',
3320 -charset
=> 'utf-8',
3321 -content_disposition
=> 'inline; filename="index.aux"');
3323 foreach my $pr (@projects) {
3324 if (!exists $pr->{'owner'}) {
3325 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3328 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3329 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3330 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3331 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3335 print "$path $owner\n";
3340 my $descr = git_get_project_description
($project) || "none";
3341 my %co = parse_commit
("HEAD");
3342 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3343 my $head = $co{'id'};
3345 my $owner = git_get_project_owner
($project);
3347 my $refs = git_get_references
();
3348 # These get_*_list functions return one more to allow us to see if
3349 # there are more ...
3350 my @taglist = git_get_tags_list
(16);
3351 my @headlist = git_get_heads_list
(16);
3353 my ($check_forks) = gitweb_check_feature
('forks');
3356 @forklist = git_get_projects_list
($project);
3360 git_print_page_nav
('summary','', $head);
3362 print "<div class=\"title\"> </div>\n";
3363 print "<table cellspacing=\"0\">\n" .
3364 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3365 "<tr><td>owner</td><td>$owner</td></tr>\n";
3366 if (defined $cd{'rfc2822'}) {
3367 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3370 # use per project git URL list in $projectroot/$project/cloneurl
3371 # or make project git URL from git base URL and project name
3372 my $url_tag = "URL";
3373 my @url_list = git_get_project_url_list
($project);
3374 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3375 foreach my $git_url (@url_list) {
3376 next unless $git_url;
3377 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3382 if (-s
"$projectroot/$project/README.html") {
3383 if (open my $fd, "$projectroot/$project/README.html") {
3384 print "<div class=\"title\">readme</div>\n";
3385 print $_ while (<$fd>);
3390 # we need to request one more than 16 (0..15) to check if
3392 my @commitlist = $head ? parse_commits
($head, 17) : ();
3394 git_print_header_div
('shortlog');
3395 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3396 $#commitlist <= 15 ? undef :
3397 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3401 git_print_header_div
('tags');
3402 git_tags_body
(\
@taglist, 0, 15,
3403 $#taglist <= 15 ? undef :
3404 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3408 git_print_header_div
('heads');
3409 git_heads_body
(\
@headlist, $head, 0, 15,
3410 $#headlist <= 15 ? undef :
3411 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3415 git_print_header_div
('forks');
3416 git_project_list_body
(\
@forklist, undef, 0, 15,
3417 $#forklist <= 15 ? undef :
3418 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3426 my $head = git_get_head_hash
($project);
3428 git_print_page_nav
('','', $head,undef,$head);
3429 my %tag = parse_tag
($hash);
3432 die_error
(undef, "Unknown tag object");
3435 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3436 print "<div class=\"title_text\">\n" .
3437 "<table cellspacing=\"0\">\n" .
3439 "<td>object</td>\n" .
3440 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3441 $tag{'object'}) . "</td>\n" .
3442 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3443 $tag{'type'}) . "</td>\n" .
3445 if (defined($tag{'author'})) {
3446 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3447 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3448 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3449 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3452 print "</table>\n\n" .
3454 print "<div class=\"page_body\">";
3455 my $comment = $tag{'comment'};
3456 foreach my $line (@$comment) {
3458 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3468 my ($have_blame) = gitweb_check_feature
('blame');
3470 die_error
('403 Permission denied', "Permission denied");
3472 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3473 $hash_base ||= git_get_head_hash
($project);
3474 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3475 my %co = parse_commit
($hash_base)
3476 or die_error
(undef, "Reading commit failed");
3477 if (!defined $hash) {
3478 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3479 or die_error
(undef, "Error looking up file");
3481 $ftype = git_get_type
($hash);
3482 if ($ftype !~ "blob") {
3483 die_error
('400 Bad Request', "Object is not a blob");
3485 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3486 $file_name, $hash_base)
3487 or die_error
(undef, "Open git-blame failed");
3490 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3493 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3496 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3498 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3499 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3500 git_print_page_path
($file_name, $ftype, $hash_base);
3501 my @rev_color = (qw(light2 dark2));
3502 my $num_colors = scalar(@rev_color);
3503 my $current_color = 0;
3506 <div class="page_body">
3507 <table class="blame">
3508 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3513 last unless defined $_;
3514 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3515 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3516 if (!exists $metainfo{$full_rev}) {
3517 $metainfo{$full_rev} = {};
3519 my $meta = $metainfo{$full_rev};
3522 if (/^(\S+) (.*)$/) {
3528 my $rev = substr($full_rev, 0, 8);
3529 my $author = $meta->{'author'};
3530 my %date = parse_date
($meta->{'author-time'},
3531 $meta->{'author-tz'});
3532 my $date = $date{'iso-tz'};
3534 $current_color = ++$current_color % $num_colors;
3536 print "<tr class=\"$rev_color[$current_color]\">\n";
3538 print "<td class=\"sha1\"";
3539 print " title=\"". esc_html
($author) . ", $date\"";
3540 print " rowspan=\"$group_size\"" if ($group_size > 1);
3542 print $cgi->a({-href
=> href
(action
=>"commit",
3544 file_name
=>$file_name)},
3548 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3549 or die_error
(undef, "Open git-rev-parse failed");
3550 my $parent_commit = <$dd>;
3552 chomp($parent_commit);
3553 my $blamed = href
(action
=> 'blame',
3554 file_name
=> $meta->{'filename'},
3555 hash_base
=> $parent_commit);
3556 print "<td class=\"linenr\">";
3557 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3559 -class => "linenr" },
3562 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3568 or print "Reading blob failed\n";
3575 my ($have_blame) = gitweb_check_feature
('blame');
3577 die_error
('403 Permission denied', "Permission denied");
3579 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3580 $hash_base ||= git_get_head_hash
($project);
3581 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3582 my %co = parse_commit
($hash_base)
3583 or die_error
(undef, "Reading commit failed");
3584 if (!defined $hash) {
3585 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3586 or die_error
(undef, "Error lookup file");
3588 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3589 or die_error
(undef, "Open git-annotate failed");
3592 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3595 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3598 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3600 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3601 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3602 git_print_page_path
($file_name, 'blob', $hash_base);
3603 print "<div class=\"page_body\">\n";
3605 <table class="blame">
3614 my @line_class = (qw(light dark));
3615 my $line_class_len = scalar (@line_class);
3616 my $line_class_num = $#line_class;
3617 while (my $line = <$fd>) {
3629 $line_class_num = ($line_class_num + 1) % $line_class_len;
3631 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3638 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3641 $short_rev = substr ($long_rev, 0, 8);
3642 $age = time () - $time;
3643 $age_str = age_string
($age);
3644 $age_str =~ s/ / /g;
3645 $age_class = age_class
($age);
3646 $author = esc_html
($author);
3647 $author =~ s/ / /g;
3649 $data = untabify
($data);
3650 $data = esc_html
($data);
3653 <tr class="$line_class[$line_class_num]">
3654 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3655 <td class="$age_class">$age_str</td>
3657 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3658 <td class="pre">$data</td>
3661 } # while (my $line = <$fd>)
3662 print "</table>\n\n";
3664 or print "Reading blob failed.\n";
3670 my $head = git_get_head_hash
($project);
3672 git_print_page_nav
('','', $head,undef,$head);
3673 git_print_header_div
('summary', $project);
3675 my @tagslist = git_get_tags_list
();
3677 git_tags_body
(\
@tagslist);
3683 my $head = git_get_head_hash
($project);
3685 git_print_page_nav
('','', $head,undef,$head);
3686 git_print_header_div
('summary', $project);
3688 my @headslist = git_get_heads_list
();
3690 git_heads_body
(\
@headslist, $head);
3695 sub git_blob_plain
{
3698 if (!defined $hash) {
3699 if (defined $file_name) {
3700 my $base = $hash_base || git_get_head_hash
($project);
3701 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3702 or die_error
(undef, "Error lookup file");
3704 die_error
(undef, "No file name defined");
3706 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3707 # blobs defined by non-textual hash id's can be cached
3712 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3713 or die_error
(undef, "Couldn't cat $file_name, $hash");
3715 $type ||= blob_mimetype
($fd, $file_name);
3717 # save as filename, even when no $file_name is given
3718 my $save_as = "$hash";
3719 if (defined $file_name) {
3720 $save_as = $file_name;
3721 } elsif ($type =~ m/^text\//) {
3728 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3730 binmode STDOUT
, ':raw';
3732 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3740 if (!defined $hash) {
3741 if (defined $file_name) {
3742 my $base = $hash_base || git_get_head_hash
($project);
3743 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3744 or die_error
(undef, "Error lookup file");
3746 die_error
(undef, "No file name defined");
3748 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3749 # blobs defined by non-textual hash id's can be cached
3753 my ($have_blame) = gitweb_check_feature
('blame');
3754 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3755 or die_error
(undef, "Couldn't cat $file_name, $hash");
3756 my $mimetype = blob_mimetype
($fd, $file_name);
3757 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3759 return git_blob_plain
($mimetype);
3761 # we can have blame only for text/* mimetype
3762 $have_blame &&= ($mimetype =~ m!^text/!);
3764 git_header_html
(undef, $expires);
3765 my $formats_nav = '';
3766 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3767 if (defined $file_name) {
3770 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3771 hash
=>$hash, file_name
=>$file_name)},
3776 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3777 hash
=>$hash, file_name
=>$file_name)},
3780 $cgi->a({-href
=> href
(action
=>"blob_plain",
3781 hash
=>$hash, file_name
=>$file_name)},
3784 $cgi->a({-href
=> href
(action
=>"blob",
3785 hash_base
=>"HEAD", file_name
=>$file_name)},
3789 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3791 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3792 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3794 print "<div class=\"page_nav\">\n" .
3795 "<br/><br/></div>\n" .
3796 "<div class=\"title\">$hash</div>\n";
3798 git_print_page_path
($file_name, "blob", $hash_base);
3799 print "<div class=\"page_body\">\n";
3800 if ($mimetype =~ m!^text/!) {
3802 while (my $line = <$fd>) {
3805 $line = untabify
($line);
3806 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3807 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3809 } elsif ($mimetype =~ m!^image/!) {
3810 print qq
!<img type
="$mimetype"!;
3812 print qq
! alt
="$file_name" title
="$file_name"!;
3815 href(action=>"blob_plain
", hash=>$hash,
3816 hash_base=>$hash_base, file_name=>$file_name) .
3820 or print "Reading blob failed.\n";
3826 my $have_snapshot = gitweb_have_snapshot
();
3828 if (!defined $hash_base) {
3829 $hash_base = "HEAD";
3831 if (!defined $hash) {
3832 if (defined $file_name) {
3833 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3839 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3840 or die_error
(undef, "Open git-ls-tree failed");
3841 my @entries = map { chomp; $_ } <$fd>;
3842 close $fd or die_error
(undef, "Reading tree failed");
3845 my $refs = git_get_references
();
3846 my $ref = format_ref_marker
($refs, $hash_base);
3849 my ($have_blame) = gitweb_check_feature
('blame');
3850 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3852 if (defined $file_name) {
3854 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3855 hash
=>$hash, file_name
=>$file_name)},
3857 $cgi->a({-href
=> href
(action
=>"tree",
3858 hash_base
=>"HEAD", file_name
=>$file_name)},
3861 if ($have_snapshot) {
3862 # FIXME: Should be available when we have no hash base as well.
3864 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3867 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3868 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3871 print "<div class=\"page_nav\">\n";
3872 print "<br/><br/></div>\n";
3873 print "<div class=\"title\">$hash</div>\n";
3875 if (defined $file_name) {
3876 $basedir = $file_name;
3877 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3881 git_print_page_path
($file_name, 'tree', $hash_base);
3882 print "<div class=\"page_body\">\n";
3883 print "<table cellspacing=\"0\">\n";
3885 # '..' (top directory) link if possible
3886 if (defined $hash_base &&
3887 defined $file_name && $file_name =~ m![^/]+$!) {
3889 print "<tr class=\"dark\">\n";
3891 print "<tr class=\"light\">\n";
3895 my $up = $file_name;
3896 $up =~ s!/?[^/]+$!!;
3897 undef $up unless $up;
3898 # based on git_print_tree_entry
3899 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3900 print '<td class="list">';
3901 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3905 print "<td class=\"link\"></td>\n";
3909 foreach my $line (@entries) {
3910 my %t = parse_ls_tree_line
($line, -z
=> 1);
3913 print "<tr class=\"dark\">\n";
3915 print "<tr class=\"light\">\n";
3919 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3923 print "</table>\n" .
3929 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3930 my $have_snapshot = (defined $ctype && defined $suffix);
3931 if (!$have_snapshot) {
3932 die_error
('403 Permission denied', "Permission denied");
3935 if (!defined $hash) {
3936 $hash = git_get_head_hash
($project);
3939 my $filename = decode_utf8
(basename
($project)) . "-$hash.tar.$suffix";
3942 -type
=> "application/$ctype",
3943 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3944 -status
=> '200 OK');
3946 my $git = git_cmd_str
();
3947 my $name = $project;
3948 $name =~ s/\047/\047\\\047\047/g;
3950 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3951 or die_error
(undef, "Execute git-tar-tree failed");
3952 binmode STDOUT
, ':raw';
3954 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3960 my $head = git_get_head_hash
($project);
3961 if (!defined $hash) {
3964 if (!defined $page) {
3967 my $refs = git_get_references
();
3969 my @commitlist = parse_commits
($hash, 101, (100 * $page));
3971 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
3974 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3977 my %co = parse_commit
($hash);
3979 git_print_header_div
('summary', $project);
3980 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3982 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
3983 for (my $i = 0; $i <= $to; $i++) {
3984 my %co = %{$commitlist[$i]};
3986 my $commit = $co{'id'};
3987 my $ref = format_ref_marker
($refs, $commit);
3988 my %ad = parse_date
($co{'author_epoch'});
3989 git_print_header_div
('commit',
3990 "<span class=\"age\">$co{'age_string'}</span>" .
3991 esc_html
($co{'title'}) . $ref,
3993 print "<div class=\"title_text\">\n" .
3994 "<div class=\"log_link\">\n" .
3995 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3997 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3999 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4002 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4005 print "<div class=\"log_body\">\n";
4006 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4009 if ($#commitlist >= 100) {
4010 print "<div class=\"page_nav\">\n";
4011 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4012 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4019 $hash ||= $hash_base || "HEAD";
4020 my %co = parse_commit
($hash);
4022 die_error
(undef, "Unknown commit object");
4024 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4025 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4027 my $parent = $co{'parent'};
4028 my $parents = $co{'parents'}; # listref
4030 # we need to prepare $formats_nav before any parameter munging
4032 if (!defined $parent) {
4034 $formats_nav .= '(initial)';
4035 } elsif (@$parents == 1) {
4036 # single parent commit
4039 $cgi->a({-href
=> href
(action
=>"commit",
4041 esc_html
(substr($parent, 0, 7))) .
4048 $cgi->a({-href
=> href
(action
=>"commit",
4050 esc_html
(substr($_, 0, 7)));
4055 if (!defined $parent) {
4059 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4061 (@$parents <= 1 ? $parent : '-c'),
4063 or die_error
(undef, "Open git-diff-tree failed");
4064 @difftree = map { chomp; $_ } <$fd>;
4065 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4067 # non-textual hash id's can be cached
4069 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4072 my $refs = git_get_references
();
4073 my $ref = format_ref_marker
($refs, $co{'id'});
4075 my $have_snapshot = gitweb_have_snapshot
();
4077 git_header_html
(undef, $expires);
4078 git_print_page_nav
('commit', '',
4079 $hash, $co{'tree'}, $hash,
4082 if (defined $co{'parent'}) {
4083 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4085 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4087 print "<div class=\"title_text\">\n" .
4088 "<table cellspacing=\"0\">\n";
4089 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4091 "<td></td><td> $ad{'rfc2822'}";
4092 if ($ad{'hour_local'} < 6) {
4093 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4094 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4096 printf(" (%02d:%02d %s)",
4097 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4101 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4102 print "<tr><td></td><td> $cd{'rfc2822'}" .
4103 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4105 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4108 "<td class=\"sha1\">" .
4109 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4110 class => "list"}, $co{'tree'}) .
4112 "<td class=\"link\">" .
4113 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4115 if ($have_snapshot) {
4117 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
4122 foreach my $par (@$parents) {
4125 "<td class=\"sha1\">" .
4126 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4127 class => "list"}, $par) .
4129 "<td class=\"link\">" .
4130 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4132 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4139 print "<div class=\"page_body\">\n";
4140 git_print_log
($co{'comment'});
4143 git_difftree_body
(\
@difftree, $hash, @$parents);
4149 # object is defined by:
4150 # - hash or hash_base alone
4151 # - hash_base and file_name
4154 # - hash or hash_base alone
4155 if ($hash || ($hash_base && !defined $file_name)) {
4156 my $object_id = $hash || $hash_base;
4158 my $git_command = git_cmd_str
();
4159 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4160 or die_error
('404 Not Found', "Object does not exist");
4164 or die_error
('404 Not Found', "Object does not exist");
4166 # - hash_base and file_name
4167 } elsif ($hash_base && defined $file_name) {
4168 $file_name =~ s
,/+$,,;
4170 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4171 or die_error
('404 Not Found', "Base object does not exist");
4173 # here errors should not hapen
4174 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4175 or die_error
(undef, "Open git-ls-tree failed");
4179 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4180 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4181 die_error
('404 Not Found', "File or directory for given base does not exist");
4186 die_error
('404 Not Found', "Not enough information to find object");
4189 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4190 hash
=>$hash, hash_base
=>$hash_base,
4191 file_name
=>$file_name),
4192 -status
=> '302 Found');
4196 my $format = shift || 'html';
4203 # preparing $fd and %diffinfo for git_patchset_body
4205 if (defined $hash_base && defined $hash_parent_base) {
4206 if (defined $file_name) {
4208 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4209 $hash_parent_base, $hash_base,
4210 "--", (defined $file_parent ? $file_parent : ()), $file_name
4211 or die_error
(undef, "Open git-diff-tree failed");
4212 @difftree = map { chomp; $_ } <$fd>;
4214 or die_error
(undef, "Reading git-diff-tree failed");
4216 or die_error
('404 Not Found', "Blob diff not found");
4218 } elsif (defined $hash &&
4219 $hash =~ /[0-9a-fA-F]{40}/) {
4220 # try to find filename from $hash
4222 # read filtered raw output
4223 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4224 $hash_parent_base, $hash_base, "--"
4225 or die_error
(undef, "Open git-diff-tree failed");
4227 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4229 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4230 map { chomp; $_ } <$fd>;
4232 or die_error
(undef, "Reading git-diff-tree failed");
4234 or die_error
('404 Not Found', "Blob diff not found");
4237 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4240 if (@difftree > 1) {
4241 die_error
('404 Not Found', "Ambiguous blob diff specification");
4244 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4245 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4246 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4248 $hash_parent ||= $diffinfo{'from_id'};
4249 $hash ||= $diffinfo{'to_id'};
4251 # non-textual hash id's can be cached
4252 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4253 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4258 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4259 '-p', ($format eq 'html' ? "--full-index" : ()),
4260 $hash_parent_base, $hash_base,
4261 "--", (defined $file_parent ? $file_parent : ()), $file_name
4262 or die_error
(undef, "Open git-diff-tree failed");
4265 # old/legacy style URI
4266 if (!%diffinfo && # if new style URI failed
4267 defined $hash && defined $hash_parent) {
4268 # fake git-diff-tree raw output
4269 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4270 $diffinfo{'from_id'} = $hash_parent;
4271 $diffinfo{'to_id'} = $hash;
4272 if (defined $file_name) {
4273 if (defined $file_parent) {
4274 $diffinfo{'status'} = '2';
4275 $diffinfo{'from_file'} = $file_parent;
4276 $diffinfo{'to_file'} = $file_name;
4277 } else { # assume not renamed
4278 $diffinfo{'status'} = '1';
4279 $diffinfo{'from_file'} = $file_name;
4280 $diffinfo{'to_file'} = $file_name;
4282 } else { # no filename given
4283 $diffinfo{'status'} = '2';
4284 $diffinfo{'from_file'} = $hash_parent;
4285 $diffinfo{'to_file'} = $hash;
4288 # non-textual hash id's can be cached
4289 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4290 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4295 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4296 '-p', ($format eq 'html' ? "--full-index" : ()),
4297 $hash_parent, $hash, "--"
4298 or die_error
(undef, "Open git-diff failed");
4300 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4305 if ($format eq 'html') {
4307 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4308 hash
=>$hash, hash_parent
=>$hash_parent,
4309 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4310 file_name
=>$file_name, file_parent
=>$file_parent)},
4312 git_header_html
(undef, $expires);
4313 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4314 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4315 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4317 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4318 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4320 if (defined $file_name) {
4321 git_print_page_path
($file_name, "blob", $hash_base);
4323 print "<div class=\"page_path\"></div>\n";
4326 } elsif ($format eq 'plain') {
4328 -type
=> 'text/plain',
4329 -charset
=> 'utf-8',
4330 -expires
=> $expires,
4331 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4333 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4336 die_error
(undef, "Unknown blobdiff format");
4340 if ($format eq 'html') {
4341 print "<div class=\"page_body\">\n";
4343 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4346 print "</div>\n"; # class="page_body"
4350 while (my $line = <$fd>) {
4351 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4352 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4356 last if $line =~ m!^\+\+\+!;
4364 sub git_blobdiff_plain
{
4365 git_blobdiff
('plain');
4368 sub git_commitdiff
{
4369 my $format = shift || 'html';
4370 $hash ||= $hash_base || "HEAD";
4371 my %co = parse_commit
($hash);
4373 die_error
(undef, "Unknown commit object");
4376 # we need to prepare $formats_nav before any parameter munging
4378 if ($format eq 'html') {
4380 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4381 hash
=>$hash, hash_parent
=>$hash_parent)},
4384 if (defined $hash_parent) {
4385 # commitdiff with two commits given
4386 my $hash_parent_short = $hash_parent;
4387 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4388 $hash_parent_short = substr($hash_parent, 0, 7);
4392 $cgi->a({-href
=> href
(action
=>"commitdiff",
4393 hash
=>$hash_parent)},
4394 esc_html
($hash_parent_short)) .
4396 } elsif (!$co{'parent'}) {
4398 $formats_nav .= ' (initial)';
4399 } elsif (scalar @{$co{'parents'}} == 1) {
4400 # single parent commit
4403 $cgi->a({-href
=> href
(action
=>"commitdiff",
4404 hash
=>$co{'parent'})},
4405 esc_html
(substr($co{'parent'}, 0, 7))) .
4412 $cgi->a({-href
=> href
(action
=>"commitdiff",
4414 esc_html
(substr($_, 0, 7)));
4415 } @{$co{'parents'}} ) .
4420 my $hash_parent_param = $hash_parent;
4421 if (!defined $hash_parent) {
4422 $hash_parent_param =
4423 @{$co{'parents'}} > 1 ? '-c' : $co{'parent'} || '--root';
4429 if ($format eq 'html') {
4430 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4431 "--no-commit-id", "--patch-with-raw", "--full-index",
4432 $hash_parent_param, $hash, "--"
4433 or die_error
(undef, "Open git-diff-tree failed");
4435 while (my $line = <$fd>) {
4437 # empty line ends raw part of diff-tree output
4439 push @difftree, scalar parse_difftree_raw_line
($line);
4442 } elsif ($format eq 'plain') {
4443 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4444 '-p', $hash_parent_param, $hash, "--"
4445 or die_error
(undef, "Open git-diff-tree failed");
4448 die_error
(undef, "Unknown commitdiff format");
4451 # non-textual hash id's can be cached
4453 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4457 # write commit message
4458 if ($format eq 'html') {
4459 my $refs = git_get_references
();
4460 my $ref = format_ref_marker
($refs, $co{'id'});
4462 git_header_html
(undef, $expires);
4463 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4464 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4465 git_print_authorship
(\
%co);
4466 print "<div class=\"page_body\">\n";
4467 if (@{$co{'comment'}} > 1) {
4468 print "<div class=\"log\">\n";
4469 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4470 print "</div>\n"; # class="log"
4473 } elsif ($format eq 'plain') {
4474 my $refs = git_get_references
("tags");
4475 my $tagname = git_get_rev_name_tags
($hash);
4476 my $filename = basename
($project) . "-$hash.patch";
4479 -type
=> 'text/plain',
4480 -charset
=> 'utf-8',
4481 -expires
=> $expires,
4482 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4483 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4486 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4487 Subject: $co{'title'}
4489 print "X-Git-Tag: $tagname\n" if $tagname;
4490 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4492 foreach my $line (@{$co{'comment'}}) {
4499 if ($format eq 'html') {
4500 git_difftree_body
(\
@difftree, $hash, $hash_parent || @{$co{'parents'}});
4503 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent || @{$co{'parents'}});
4505 print "</div>\n"; # class="page_body"
4508 } elsif ($format eq 'plain') {
4512 or print "Reading git-diff-tree failed\n";
4516 sub git_commitdiff_plain
{
4517 git_commitdiff
('plain');
4521 if (!defined $hash_base) {
4522 $hash_base = git_get_head_hash
($project);
4524 if (!defined $page) {
4528 my %co = parse_commit
($hash_base);
4530 die_error
(undef, "Unknown commit object");
4533 my $refs = git_get_references
();
4534 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4536 if (!defined $hash && defined $file_name) {
4537 $hash = git_get_hash_by_path
($hash_base, $file_name);
4539 if (defined $hash) {
4540 $ftype = git_get_type
($hash);
4543 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4545 my $paging_nav = '';
4548 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4549 file_name
=>$file_name)},
4551 $paging_nav .= " ⋅ " .
4552 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4553 file_name
=>$file_name, page
=>$page-1),
4554 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4556 $paging_nav .= "first";
4557 $paging_nav .= " ⋅ prev";
4559 if ($#commitlist >= 100) {
4560 $paging_nav .= " ⋅ " .
4561 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4562 file_name
=>$file_name, page
=>$page+1),
4563 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4565 $paging_nav .= " ⋅ next";
4568 if ($#commitlist >= 100) {
4570 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4571 file_name
=>$file_name, page
=>$page+1),
4572 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4576 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4577 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4578 git_print_page_path
($file_name, $ftype, $hash_base);
4580 git_history_body
(\
@commitlist, 0, 99,
4581 $refs, $hash_base, $ftype, $next_link);
4587 my ($have_search) = gitweb_check_feature
('search');
4588 if (!$have_search) {
4589 die_error
('403 Permission denied', "Permission denied");
4591 if (!defined $searchtext) {
4592 die_error
(undef, "Text field empty");
4594 if (!defined $hash) {
4595 $hash = git_get_head_hash
($project);
4597 my %co = parse_commit
($hash);
4599 die_error
(undef, "Unknown commit object");
4601 if (!defined $page) {
4605 $searchtype ||= 'commit';
4606 if ($searchtype eq 'pickaxe') {
4607 # pickaxe may take all resources of your box and run for several minutes
4608 # with every query - so decide by yourself how public you make this feature
4609 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4610 if (!$have_pickaxe) {
4611 die_error
('403 Permission denied', "Permission denied");
4617 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4619 if ($searchtype eq 'commit') {
4620 $greptype = "--grep=";
4621 } elsif ($searchtype eq 'author') {
4622 $greptype = "--author=";
4623 } elsif ($searchtype eq 'committer') {
4624 $greptype = "--committer=";
4626 $greptype .= $searchtext;
4627 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4629 my $paging_nav = '';
4632 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4633 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4635 $paging_nav .= " ⋅ " .
4636 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4637 searchtext
=>$searchtext, searchtype
=>$searchtype,
4639 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4641 $paging_nav .= "first";
4642 $paging_nav .= " ⋅ prev";
4644 if ($#commitlist >= 100) {
4645 $paging_nav .= " ⋅ " .
4646 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4647 searchtext
=>$searchtext, searchtype
=>$searchtype,
4649 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4651 $paging_nav .= " ⋅ next";
4654 if ($#commitlist >= 100) {
4656 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4657 searchtext
=>$searchtext, searchtype
=>$searchtype,
4659 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4662 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4663 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4664 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4667 if ($searchtype eq 'pickaxe') {
4668 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4669 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4671 print "<table cellspacing=\"0\">\n";
4674 my $git_command = git_cmd_str
();
4675 open my $fd, "-|", "$git_command rev-list $hash | " .
4676 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
4679 while (my $line = <$fd>) {
4680 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4683 $set{'from_id'} = $3;
4685 $set{'id'} = $set{'to_id'};
4686 if ($set{'id'} =~ m/0{40}/) {
4687 $set{'id'} = $set{'from_id'};
4689 if ($set{'id'} =~ m/0{40}/) {
4693 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4696 print "<tr class=\"dark\">\n";
4698 print "<tr class=\"light\">\n";
4701 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4702 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4704 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4705 -class => "list subject"},
4706 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4707 while (my $setref = shift @files) {
4709 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4710 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4712 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4716 "<td class=\"link\">" .
4717 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4719 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4723 %co = parse_commit
($1);
4733 sub git_search_help
{
4735 git_print_page_nav
('','', $hash,$hash,$hash);
4738 <dt><b>commit</b></dt>
4739 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4740 <dt><b>author</b></dt>
4741 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4742 <dt><b>committer</b></dt>
4743 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4745 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4746 if ($have_pickaxe) {
4748 <dt><b>pickaxe</b></dt>
4749 <dd>All commits that caused the string to appear or disappear from any file (changes that
4750 added, removed or "modified" the string) will be listed. This search can take a while and
4751 takes a lot of strain on the server, so please use it wisely.</dd>
4759 my $head = git_get_head_hash
($project);
4760 if (!defined $hash) {
4763 if (!defined $page) {
4766 my $refs = git_get_references
();
4768 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4770 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
4772 if ($#commitlist >= 100) {
4774 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4775 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4779 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4780 git_print_header_div
('summary', $project);
4782 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
4787 ## ......................................................................
4788 ## feeds (RSS, Atom; OPML)
4791 my $format = shift || 'atom';
4792 my ($have_blame) = gitweb_check_feature
('blame');
4794 # Atom: http://www.atomenabled.org/developers/syndication/
4795 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4796 if ($format ne 'rss' && $format ne 'atom') {
4797 die_error
(undef, "Unknown web feed format");
4800 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4801 my $head = $hash || 'HEAD';
4802 my @commitlist = parse_commits
($head, 150);
4806 my $content_type = "application/$format+xml";
4807 if (defined $cgi->http('HTTP_ACCEPT') &&
4808 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4809 # browser (feed reader) prefers text/xml
4810 $content_type = 'text/xml';
4812 if (defined($commitlist[0])) {
4813 %latest_commit = %{$commitlist[0]};
4814 %latest_date = parse_date
($latest_commit{'author_epoch'});
4816 -type
=> $content_type,
4817 -charset
=> 'utf-8',
4818 -last_modified
=> $latest_date{'rfc2822'});
4821 -type
=> $content_type,
4822 -charset
=> 'utf-8');
4825 # Optimization: skip generating the body if client asks only
4826 # for Last-Modified date.
4827 return if ($cgi->request_method() eq 'HEAD');
4830 my $title = "$site_name - $project/$action";
4831 my $feed_type = 'log';
4832 if (defined $hash) {
4833 $title .= " - '$hash'";
4834 $feed_type = 'branch log';
4835 if (defined $file_name) {
4836 $title .= " :: $file_name";
4837 $feed_type = 'history';
4839 } elsif (defined $file_name) {
4840 $title .= " - $file_name";
4841 $feed_type = 'history';
4843 $title .= " $feed_type";
4844 my $descr = git_get_project_description
($project);
4845 if (defined $descr) {
4846 $descr = esc_html
($descr);
4848 $descr = "$project " .
4849 ($format eq 'rss' ? 'RSS' : 'Atom') .
4852 my $owner = git_get_project_owner
($project);
4853 $owner = esc_html
($owner);
4857 if (defined $file_name) {
4858 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
4859 } elsif (defined $hash) {
4860 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
4862 $alt_url = href
(-full
=>1, action
=>"summary");
4864 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
4865 if ($format eq 'rss') {
4867 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
4870 print "<title>$title</title>\n" .
4871 "<link>$alt_url</link>\n" .
4872 "<description>$descr</description>\n" .
4873 "<language>en</language>\n";
4874 } elsif ($format eq 'atom') {
4876 <feed xmlns="http://www.w3.org/2005/Atom">
4878 print "<title>$title</title>\n" .
4879 "<subtitle>$descr</subtitle>\n" .
4880 '<link rel="alternate" type="text/html" href="' .
4881 $alt_url . '" />' . "\n" .
4882 '<link rel="self" type="' . $content_type . '" href="' .
4883 $cgi->self_url() . '" />' . "\n" .
4884 "<id>" . href
(-full
=>1) . "</id>\n" .
4885 # use project owner for feed author
4886 "<author><name>$owner</name></author>\n";
4887 if (defined $favicon) {
4888 print "<icon>" . esc_url
($favicon) . "</icon>\n";
4890 if (defined $logo_url) {
4891 # not twice as wide as tall: 72 x 27 pixels
4892 print "<logo>" . esc_url
($logo) . "</logo>\n";
4894 if (! %latest_date) {
4895 # dummy date to keep the feed valid until commits trickle in:
4896 print "<updated>1970-01-01T00:00:00Z</updated>\n";
4898 print "<updated>$latest_date{'iso-8601'}</updated>\n";
4903 for (my $i = 0; $i <= $#commitlist; $i++) {
4904 my %co = %{$commitlist[$i]};
4905 my $commit = $co{'id'};
4906 # we read 150, we always show 30 and the ones more recent than 48 hours
4907 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
4910 my %cd = parse_date
($co{'author_epoch'});
4912 # get list of changed files
4913 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4914 $co{'parent'}, $co{'id'}, "--", (defined $file_name ? $file_name : ())
4916 my @difftree = map { chomp; $_ } <$fd>;
4920 # print element (entry, item)
4921 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
4922 if ($format eq 'rss') {
4924 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
4925 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
4926 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
4927 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
4928 "<link>$co_url</link>\n" .
4929 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
4930 "<content:encoded>" .
4932 } elsif ($format eq 'atom') {
4934 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
4935 "<updated>$cd{'iso-8601'}</updated>\n" .
4937 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
4938 if ($co{'author_email'}) {
4939 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
4941 print "</author>\n" .
4942 # use committer for contributor
4944 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
4945 if ($co{'committer_email'}) {
4946 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
4948 print "</contributor>\n" .
4949 "<published>$cd{'iso-8601'}</published>\n" .
4950 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
4951 "<id>$co_url</id>\n" .
4952 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
4953 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
4955 my $comment = $co{'comment'};
4957 foreach my $line (@$comment) {
4958 $line = esc_html
($line);
4961 print "</pre><ul>\n";
4962 foreach my $difftree_line (@difftree) {
4963 my %difftree = parse_difftree_raw_line
($difftree_line);
4964 next if !$difftree{'from_id'};
4966 my $file = $difftree{'file'} || $difftree{'to_file'};
4970 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
4971 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
4972 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
4973 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
4974 -title
=> "diff"}, 'D');
4976 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
4977 file_name
=>$file, hash_base
=>$commit),
4978 -title
=> "blame"}, 'B');
4980 # if this is not a feed of a file history
4981 if (!defined $file_name || $file_name ne $file) {
4982 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
4983 file_name
=>$file, hash
=>$commit),
4984 -title
=> "history"}, 'H');
4986 $file = esc_path
($file);
4990 if ($format eq 'rss') {
4991 print "</ul>]]>\n" .
4992 "</content:encoded>\n" .
4994 } elsif ($format eq 'atom') {
4995 print "</ul>\n</div>\n" .
5002 if ($format eq 'rss') {
5003 print "</channel>\n</rss>\n";
5004 } elsif ($format eq 'atom') {
5018 my @list = git_get_projects_list
();
5020 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5022 <?xml version="1.0" encoding="utf-8"?>
5023 <opml version="1.0">
5025 <title>$site_name OPML Export</title>
5028 <outline text="git RSS feeds">
5031 foreach my $pr (@list) {
5033 my $head = git_get_head_hash
($proj{'path'});
5034 if (!defined $head) {
5037 $git_dir = "$projectroot/$proj{'path'}";
5038 my %co = parse_commit
($head);
5043 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5044 my $rss = "$my_url?p=$proj{'path'};a=rss";
5045 my $html = "$my_url?p=$proj{'path'};a=summary";
5046 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";