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)
732 if ($age < 60*60*2) {
734 } elsif ($age < 60*60*24*2) {
741 # convert age in seconds to "nn units ago" string
746 if ($age > 60*60*24*365*2) {
747 $age_str = (int $age/60/60/24/365);
748 $age_str .= " years ago";
749 } elsif ($age > 60*60*24*(365/12)*2) {
750 $age_str = int $age/60/60/24/(365/12);
751 $age_str .= " months ago";
752 } elsif ($age > 60*60*24*7*2) {
753 $age_str = int $age/60/60/24/7;
754 $age_str .= " weeks ago";
755 } elsif ($age > 60*60*24*2) {
756 $age_str = int $age/60/60/24;
757 $age_str .= " days ago";
758 } elsif ($age > 60*60*2) {
759 $age_str = int $age/60/60;
760 $age_str .= " hours ago";
761 } elsif ($age > 60*2) {
762 $age_str = int $age/60;
763 $age_str .= " min ago";
766 $age_str .= " sec ago";
768 $age_str .= " right now";
773 # convert file mode in octal to symbolic file mode string
775 my $mode = oct shift;
777 if (S_ISDIR
($mode & S_IFMT
)) {
779 } elsif (S_ISLNK
($mode)) {
781 } elsif (S_ISREG
($mode)) {
782 # git cares only about the executable bit
783 if ($mode & S_IXUSR
) {
793 # convert file mode in octal to file type string
797 if ($mode !~ m/^[0-7]+$/) {
803 if (S_ISDIR
($mode & S_IFMT
)) {
805 } elsif (S_ISLNK
($mode)) {
807 } elsif (S_ISREG
($mode)) {
814 # convert file mode in octal to file type description string
818 if ($mode !~ m/^[0-7]+$/) {
824 if (S_ISDIR
($mode & S_IFMT
)) {
826 } elsif (S_ISLNK
($mode)) {
828 } elsif (S_ISREG
($mode)) {
829 if ($mode & S_IXUSR
) {
840 ## ----------------------------------------------------------------------
841 ## functions returning short HTML fragments, or transforming HTML fragments
842 ## which don't belong to other sections
844 # format line of commit message.
845 sub format_log_line_html
{
848 $line = esc_html
($line, -nbsp
=>1);
849 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
852 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
853 -class => "text"}, $hash_text);
854 $line =~ s/$hash_text/$link/;
859 # format marker of refs pointing to given object
860 sub format_ref_marker
{
861 my ($refs, $id) = @_;
864 if (defined $refs->{$id}) {
865 foreach my $ref (@{$refs->{$id}}) {
866 my ($type, $name) = qw();
867 # e.g. tags/v2.6.11 or heads/next
868 if ($ref =~ m!^(.*?)s?/(.*)$!) {
876 $markers .= " <span class=\"$type\" title=\"$ref\">" .
877 esc_html
($name) . "</span>";
882 return ' <span class="refs">'. $markers . '</span>';
888 # format, perhaps shortened and with markers, title line
889 sub format_subject_html
{
890 my ($long, $short, $href, $extra) = @_;
891 $extra = '' unless defined($extra);
893 if (length($short) < length($long)) {
894 return $cgi->a({-href
=> $href, -class => "list subject",
895 -title
=> decode_utf8
($long)},
896 esc_html
($short) . $extra);
898 return $cgi->a({-href
=> $href, -class => "list subject"},
899 esc_html
($long) . $extra);
903 # format patch (diff) line (rather not to be used for diff headers)
904 sub format_diff_line
{
906 my ($from, $to) = @_;
911 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
913 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
914 if ($line =~ m/^\@{3}/) {
915 $diff_class = " chunk_header";
916 } elsif ($line =~ m/^\\/) {
917 $diff_class = " incomplete";
918 } elsif ($prefix =~ tr/+/+/) {
919 $diff_class = " add";
920 } elsif ($prefix =~ tr/-/-/) {
921 $diff_class = " rem";
924 # assume ordinary diff
925 my $char = substr($line, 0, 1);
927 $diff_class = " add";
928 } elsif ($char eq '-') {
929 $diff_class = " rem";
930 } elsif ($char eq '@') {
931 $diff_class = " chunk_header";
932 } elsif ($char eq "\\") {
933 $diff_class = " incomplete";
936 $line = untabify
($line);
937 if ($from && $to && $line =~ m/^\@{2} /) {
938 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
939 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
941 $from_lines = 0 unless defined $from_lines;
942 $to_lines = 0 unless defined $to_lines;
944 if ($from->{'href'}) {
945 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
946 -class=>"list"}, $from_text);
949 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
950 -class=>"list"}, $to_text);
952 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
953 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
954 return "<div class=\"diff$diff_class\">$line</div>\n";
955 } elsif ($from && $to && $line =~ m/^\@{3}/) {
956 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
957 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
959 @from_text = split(' ', $ranges);
960 for (my $i = 0; $i < @from_text; ++$i) {
961 ($from_start[$i], $from_nlines[$i]) =
962 (split(',', substr($from_text[$i], 1)), 0);
965 $to_text = pop @from_text;
966 $to_start = pop @from_start;
967 $to_nlines = pop @from_nlines;
969 $line = "<span class=\"chunk_info\">$prefix ";
970 for (my $i = 0; $i < @from_text; ++$i) {
971 if ($from->{'href'}[$i]) {
972 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
973 -class=>"list"}, $from_text[$i]);
975 $line .= $from_text[$i];
980 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
981 -class=>"list"}, $to_text);
985 $line .= " $prefix</span>" .
986 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
987 return "<div class=\"diff$diff_class\">$line</div>\n";
989 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
992 ## ----------------------------------------------------------------------
993 ## git utility subroutines, invoking git commands
995 # returns path to the core git executable and the --git-dir parameter as list
997 return $GIT, '--git-dir='.$git_dir;
1000 # returns path to the core git executable and the --git-dir parameter as string
1002 return join(' ', git_cmd
());
1005 # get HEAD ref of given project as hash
1006 sub git_get_head_hash
{
1007 my $project = shift;
1008 my $o_git_dir = $git_dir;
1010 $git_dir = "$projectroot/$project";
1011 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1014 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1018 if (defined $o_git_dir) {
1019 $git_dir = $o_git_dir;
1024 # get type of given object
1028 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1030 close $fd or return;
1035 sub git_get_project_config
{
1036 my ($key, $type) = @_;
1038 return unless ($key);
1039 $key =~ s/^gitweb\.//;
1040 return if ($key =~ m/\W/);
1042 my @x = (git_cmd
(), 'config');
1043 if (defined $type) { push @x, $type; }
1045 push @x, "gitweb.$key";
1051 # get hash of given path at given ref
1052 sub git_get_hash_by_path
{
1054 my $path = shift || return undef;
1059 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1060 or die_error
(undef, "Open git-ls-tree failed");
1062 close $fd or return undef;
1064 if (!defined $line) {
1065 # there is no tree or hash given by $path at $base
1069 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1070 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1071 if (defined $type && $type ne $2) {
1072 # type doesn't match
1078 # get path of entry with given hash at given tree-ish (ref)
1079 # used to get 'from' filename for combined diff (merge commit) for renames
1080 sub git_get_path_by_hash
{
1081 my $base = shift || return;
1082 my $hash = shift || return;
1086 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1088 while (my $line = <$fd>) {
1091 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1092 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1093 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1102 ## ......................................................................
1103 ## git utility functions, directly accessing git repository
1105 sub git_get_project_description
{
1108 open my $fd, "$projectroot/$path/description" or return undef;
1115 sub git_get_project_url_list
{
1118 open my $fd, "$projectroot/$path/cloneurl" or return;
1119 my @git_project_url_list = map { chomp; $_ } <$fd>;
1122 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1125 sub git_get_projects_list
{
1130 $filter =~ s/\.git$//;
1132 my ($check_forks) = gitweb_check_feature
('forks');
1134 if (-d
$projects_list) {
1135 # search in directory
1136 my $dir = $projects_list . ($filter ? "/$filter" : '');
1137 # remove the trailing "/"
1139 my $pfxlen = length("$dir");
1142 follow_fast
=> 1, # follow symbolic links
1143 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1145 # skip project-list toplevel, if we get it.
1146 return if (m!^[/.]$!);
1147 # only directories can be git repositories
1148 return unless (-d
$_);
1150 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1151 # we check related file in $projectroot
1152 if ($check_forks and $subdir =~ m
#/.#) {
1153 $File::Find
::prune
= 1;
1154 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1155 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1156 $File::Find
::prune
= 1;
1161 } elsif (-f
$projects_list) {
1162 # read from file(url-encoded):
1163 # 'git%2Fgit.git Linus+Torvalds'
1164 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1165 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1167 open my ($fd), $projects_list or return;
1169 while (my $line = <$fd>) {
1171 my ($path, $owner) = split ' ', $line;
1172 $path = unescape
($path);
1173 $owner = unescape
($owner);
1174 if (!defined $path) {
1177 if ($filter ne '') {
1178 # looking for forks;
1179 my $pfx = substr($path, 0, length($filter));
1180 if ($pfx ne $filter) {
1183 my $sfx = substr($path, length($filter));
1184 if ($sfx !~ /^\/.*\
.git
$/) {
1187 } elsif ($check_forks) {
1189 foreach my $filter (keys %paths) {
1190 # looking for forks;
1191 my $pfx = substr($path, 0, length($filter));
1192 if ($pfx ne $filter) {
1195 my $sfx = substr($path, length($filter));
1196 if ($sfx !~ /^\/.*\
.git
$/) {
1199 # is a fork, don't include it in
1204 if (check_export_ok
("$projectroot/$path")) {
1207 owner
=> decode_utf8
($owner),
1210 (my $forks_path = $path) =~ s/\.git$//;
1211 $paths{$forks_path}++;
1219 sub git_get_project_owner
{
1220 my $project = shift;
1223 return undef unless $project;
1225 # read from file (url-encoded):
1226 # 'git%2Fgit.git Linus+Torvalds'
1227 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1228 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1229 if (-f
$projects_list) {
1230 open (my $fd , $projects_list);
1231 while (my $line = <$fd>) {
1233 my ($pr, $ow) = split ' ', $line;
1234 $pr = unescape
($pr);
1235 $ow = unescape
($ow);
1236 if ($pr eq $project) {
1237 $owner = decode_utf8
($ow);
1243 if (!defined $owner) {
1244 $owner = get_file_owner
("$projectroot/$project");
1250 sub git_get_last_activity
{
1254 $git_dir = "$projectroot/$path";
1255 open($fd, "-|", git_cmd
(), 'for-each-ref',
1256 '--format=%(committer)',
1257 '--sort=-committerdate',
1259 'refs/heads') or return;
1260 my $most_recent = <$fd>;
1261 close $fd or return;
1262 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1264 my $age = time - $timestamp;
1265 return ($age, age_string
($age));
1269 sub git_get_references
{
1270 my $type = shift || "";
1272 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1273 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1274 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1275 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1278 while (my $line = <$fd>) {
1280 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1281 if (defined $refs{$1}) {
1282 push @{$refs{$1}}, $2;
1288 close $fd or return;
1292 sub git_get_rev_name_tags
{
1293 my $hash = shift || return undef;
1295 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1297 my $name_rev = <$fd>;
1300 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1303 # catches also '$hash undefined' output
1308 ## ----------------------------------------------------------------------
1309 ## parse to hash functions
1313 my $tz = shift || "-0000";
1316 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1317 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1318 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1319 $date{'hour'} = $hour;
1320 $date{'minute'} = $min;
1321 $date{'mday'} = $mday;
1322 $date{'day'} = $days[$wday];
1323 $date{'month'} = $months[$mon];
1324 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1325 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1326 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1327 $mday, $months[$mon], $hour ,$min;
1328 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1329 1900+$year, $mon, $mday, $hour ,$min, $sec;
1331 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1332 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1333 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1334 $date{'hour_local'} = $hour;
1335 $date{'minute_local'} = $min;
1336 $date{'tz_local'} = $tz;
1337 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1338 1900+$year, $mon+1, $mday,
1339 $hour, $min, $sec, $tz);
1348 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1349 $tag{'id'} = $tag_id;
1350 while (my $line = <$fd>) {
1352 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1353 $tag{'object'} = $1;
1354 } elsif ($line =~ m/^type (.+)$/) {
1356 } elsif ($line =~ m/^tag (.+)$/) {
1358 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1359 $tag{'author'} = $1;
1362 } elsif ($line =~ m/--BEGIN/) {
1363 push @comment, $line;
1365 } elsif ($line eq "") {
1369 push @comment, <$fd>;
1370 $tag{'comment'} = \
@comment;
1371 close $fd or return;
1372 if (!defined $tag{'name'}) {
1378 sub parse_commit_text
{
1379 my ($commit_text, $withparents) = @_;
1380 my @commit_lines = split '\n', $commit_text;
1383 pop @commit_lines; # Remove '\0'
1385 if (! @commit_lines) {
1389 my $header = shift @commit_lines;
1390 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1393 ($co{'id'}, my @parents) = split ' ', $header;
1394 while (my $line = shift @commit_lines) {
1395 last if $line eq "\n";
1396 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1398 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1400 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1402 $co{'author_epoch'} = $2;
1403 $co{'author_tz'} = $3;
1404 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1405 $co{'author_name'} = $1;
1406 $co{'author_email'} = $2;
1408 $co{'author_name'} = $co{'author'};
1410 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1411 $co{'committer'} = $1;
1412 $co{'committer_epoch'} = $2;
1413 $co{'committer_tz'} = $3;
1414 $co{'committer_name'} = $co{'committer'};
1415 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1416 $co{'committer_name'} = $1;
1417 $co{'committer_email'} = $2;
1419 $co{'committer_name'} = $co{'committer'};
1423 if (!defined $co{'tree'}) {
1426 $co{'parents'} = \
@parents;
1427 $co{'parent'} = $parents[0];
1429 foreach my $title (@commit_lines) {
1432 $co{'title'} = chop_str
($title, 80, 5);
1433 # remove leading stuff of merges to make the interesting part visible
1434 if (length($title) > 50) {
1435 $title =~ s/^Automatic //;
1436 $title =~ s/^merge (of|with) /Merge ... /i;
1437 if (length($title) > 50) {
1438 $title =~ s/(http|rsync):\/\///;
1440 if (length($title) > 50) {
1441 $title =~ s/(master|www|rsync)\.//;
1443 if (length($title) > 50) {
1444 $title =~ s/kernel.org:?//;
1446 if (length($title) > 50) {
1447 $title =~ s/\/pub\/scm//;
1450 $co{'title_short'} = chop_str
($title, 50, 5);
1454 if ($co{'title'} eq "") {
1455 $co{'title'} = $co{'title_short'} = '(no commit message)';
1457 # remove added spaces
1458 foreach my $line (@commit_lines) {
1461 $co{'comment'} = \
@commit_lines;
1463 my $age = time - $co{'committer_epoch'};
1465 $co{'age_string'} = age_string
($age);
1466 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1467 if ($age > 60*60*24*7*2) {
1468 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1469 $co{'age_string_age'} = $co{'age_string'};
1471 $co{'age_string_date'} = $co{'age_string'};
1472 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1478 my ($commit_id) = @_;
1483 open my $fd, "-|", git_cmd
(), "rev-list",
1489 or die_error
(undef, "Open git-rev-list failed");
1490 %co = parse_commit_text
(<$fd>, 1);
1497 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1505 open my $fd, "-|", git_cmd
(), "rev-list",
1507 ($arg ? ($arg) : ()),
1508 ("--max-count=" . $maxcount),
1509 ("--skip=" . $skip),
1512 ($filename ? ($filename) : ())
1513 or die_error
(undef, "Open git-rev-list failed");
1514 while (my $line = <$fd>) {
1515 my %co = parse_commit_text
($line);
1520 return wantarray ? @cos : \
@cos;
1523 # parse ref from ref_file, given by ref_id, with given type
1525 my $ref_file = shift;
1527 my $type = shift || git_get_type
($ref_id);
1530 $ref_item{'type'} = $type;
1531 $ref_item{'id'} = $ref_id;
1532 $ref_item{'epoch'} = 0;
1533 $ref_item{'age'} = "unknown";
1534 if ($type eq "tag") {
1535 my %tag = parse_tag
($ref_id);
1536 $ref_item{'comment'} = $tag{'comment'};
1537 if ($tag{'type'} eq "commit") {
1538 my %co = parse_commit
($tag{'object'});
1539 $ref_item{'epoch'} = $co{'committer_epoch'};
1540 $ref_item{'age'} = $co{'age_string'};
1541 } elsif (defined($tag{'epoch'})) {
1542 my $age = time - $tag{'epoch'};
1543 $ref_item{'epoch'} = $tag{'epoch'};
1544 $ref_item{'age'} = age_string
($age);
1546 $ref_item{'reftype'} = $tag{'type'};
1547 $ref_item{'name'} = $tag{'name'};
1548 $ref_item{'refid'} = $tag{'object'};
1549 } elsif ($type eq "commit"){
1550 my %co = parse_commit
($ref_id);
1551 $ref_item{'reftype'} = "commit";
1552 $ref_item{'name'} = $ref_file;
1553 $ref_item{'title'} = $co{'title'};
1554 $ref_item{'refid'} = $ref_id;
1555 $ref_item{'epoch'} = $co{'committer_epoch'};
1556 $ref_item{'age'} = $co{'age_string'};
1558 $ref_item{'reftype'} = $type;
1559 $ref_item{'name'} = $ref_file;
1560 $ref_item{'refid'} = $ref_id;
1566 # parse line of git-diff-tree "raw" output
1567 sub parse_difftree_raw_line
{
1571 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1572 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1573 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1574 $res{'from_mode'} = $1;
1575 $res{'to_mode'} = $2;
1576 $res{'from_id'} = $3;
1578 $res{'status'} = $5;
1579 $res{'similarity'} = $6;
1580 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1581 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1583 $res{'file'} = unquote
($7);
1586 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1587 # combined diff (for merge commit)
1588 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1589 $res{'nparents'} = length($1);
1590 $res{'from_mode'} = [ split(' ', $2) ];
1591 $res{'to_mode'} = pop @{$res{'from_mode'}};
1592 $res{'from_id'} = [ split(' ', $3) ];
1593 $res{'to_id'} = pop @{$res{'from_id'}};
1594 $res{'status'} = [ split('', $4) ];
1595 $res{'to_file'} = unquote
($5);
1597 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1598 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1599 $res{'commit'} = $1;
1602 return wantarray ? %res : \
%res;
1605 # parse line of git-ls-tree output
1606 sub parse_ls_tree_line
($;%) {
1611 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1612 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1620 $res{'name'} = unquote
($4);
1623 return wantarray ? %res : \
%res;
1626 ## ......................................................................
1627 ## parse to array of hashes functions
1629 sub git_get_heads_list
{
1633 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1634 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1635 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1638 while (my $line = <$fd>) {
1642 my ($refinfo, $committerinfo) = split(/\0/, $line);
1643 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1644 my ($committer, $epoch, $tz) =
1645 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1646 $name =~ s!^refs/heads/!!;
1648 $ref_item{'name'} = $name;
1649 $ref_item{'id'} = $hash;
1650 $ref_item{'title'} = $title || '(no commit message)';
1651 $ref_item{'epoch'} = $epoch;
1653 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1655 $ref_item{'age'} = "unknown";
1658 push @headslist, \
%ref_item;
1662 return wantarray ? @headslist : \
@headslist;
1665 sub git_get_tags_list
{
1669 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1670 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1671 '--format=%(objectname) %(objecttype) %(refname) '.
1672 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1675 while (my $line = <$fd>) {
1679 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1680 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1681 my ($creator, $epoch, $tz) =
1682 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1683 $name =~ s!^refs/tags/!!;
1685 $ref_item{'type'} = $type;
1686 $ref_item{'id'} = $id;
1687 $ref_item{'name'} = $name;
1688 if ($type eq "tag") {
1689 $ref_item{'subject'} = $title;
1690 $ref_item{'reftype'} = $reftype;
1691 $ref_item{'refid'} = $refid;
1693 $ref_item{'reftype'} = $type;
1694 $ref_item{'refid'} = $id;
1697 if ($type eq "tag" || $type eq "commit") {
1698 $ref_item{'epoch'} = $epoch;
1700 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1702 $ref_item{'age'} = "unknown";
1706 push @tagslist, \
%ref_item;
1710 return wantarray ? @tagslist : \
@tagslist;
1713 ## ----------------------------------------------------------------------
1714 ## filesystem-related functions
1716 sub get_file_owner
{
1719 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1720 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1721 if (!defined $gcos) {
1725 $owner =~ s/[,;].*$//;
1726 return decode_utf8
($owner);
1729 ## ......................................................................
1730 ## mimetype related functions
1732 sub mimetype_guess_file
{
1733 my $filename = shift;
1734 my $mimemap = shift;
1735 -r
$mimemap or return undef;
1738 open(MIME
, $mimemap) or return undef;
1740 next if m/^#/; # skip comments
1741 my ($mime, $exts) = split(/\t+/);
1742 if (defined $exts) {
1743 my @exts = split(/\s+/, $exts);
1744 foreach my $ext (@exts) {
1745 $mimemap{$ext} = $mime;
1751 $filename =~ /\.([^.]*)$/;
1752 return $mimemap{$1};
1755 sub mimetype_guess
{
1756 my $filename = shift;
1758 $filename =~ /\./ or return undef;
1760 if ($mimetypes_file) {
1761 my $file = $mimetypes_file;
1762 if ($file !~ m!^/!) { # if it is relative path
1763 # it is relative to project
1764 $file = "$projectroot/$project/$file";
1766 $mime = mimetype_guess_file
($filename, $file);
1768 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1774 my $filename = shift;
1777 my $mime = mimetype_guess
($filename);
1778 $mime and return $mime;
1782 return $default_blob_plain_mimetype unless $fd;
1785 return 'text/plain' .
1786 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1787 } elsif (! $filename) {
1788 return 'application/octet-stream';
1789 } elsif ($filename =~ m/\.png$/i) {
1791 } elsif ($filename =~ m/\.gif$/i) {
1793 } elsif ($filename =~ m/\.jpe?g$/i) {
1794 return 'image/jpeg';
1796 return 'application/octet-stream';
1800 ## ======================================================================
1801 ## functions printing HTML: header, footer, error page
1803 sub git_header_html
{
1804 my $status = shift || "200 OK";
1805 my $expires = shift;
1807 my $title = "$site_name";
1808 if (defined $project) {
1809 $title .= " - " . decode_utf8
($project);
1810 if (defined $action) {
1811 $title .= "/$action";
1812 if (defined $file_name) {
1813 $title .= " - " . esc_path
($file_name);
1814 if ($action eq "tree" && $file_name !~ m
|/$|) {
1821 # require explicit support from the UA if we are to send the page as
1822 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1823 # we have to do this because MSIE sometimes globs '*/*', pretending to
1824 # support xhtml+xml but choking when it gets what it asked for.
1825 if (defined $cgi->http('HTTP_ACCEPT') &&
1826 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1827 $cgi->Accept('application/xhtml+xml') != 0) {
1828 $content_type = 'application/xhtml+xml';
1830 $content_type = 'text/html';
1832 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1833 -status
=> $status, -expires
=> $expires);
1834 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
1836 <?xml version="1.0" encoding="utf-8"?>
1837 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1838 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1839 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1840 <!-- git core binaries version $git_version -->
1842 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1843 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
1844 <meta name="robots" content="index, nofollow"/>
1845 <title>$title</title>
1847 # print out each stylesheet that exist
1848 if (defined $stylesheet) {
1849 #provides backwards capability for those people who define style sheet in a config file
1850 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1852 foreach my $stylesheet (@stylesheets) {
1853 next unless $stylesheet;
1854 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1857 if (defined $project) {
1858 printf('<link rel="alternate" title="%s log RSS feed" '.
1859 'href="%s" type="application/rss+xml" />'."\n",
1860 esc_param
($project), href
(action
=>"rss"));
1861 printf('<link rel="alternate" title="%s log Atom feed" '.
1862 'href="%s" type="application/atom+xml" />'."\n",
1863 esc_param
($project), href
(action
=>"atom"));
1865 printf('<link rel="alternate" title="%s projects list" '.
1866 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1867 $site_name, href
(project
=>undef, action
=>"project_index"));
1868 printf('<link rel="alternate" title="%s projects feeds" '.
1869 'href="%s" type="text/x-opml"/>'."\n",
1870 $site_name, href
(project
=>undef, action
=>"opml"));
1872 if (defined $favicon) {
1873 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1879 if (-f
$site_header) {
1880 open (my $fd, $site_header);
1885 print "<div class=\"page_header\">\n" .
1886 $cgi->a({-href
=> esc_url
($logo_url),
1887 -title
=> $logo_label},
1888 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1889 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1890 if (defined $project) {
1891 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1892 if (defined $action) {
1897 my ($have_search) = gitweb_check_feature
('search');
1898 if ((defined $project) && ($have_search)) {
1899 if (!defined $searchtext) {
1903 if (defined $hash_base) {
1904 $search_hash = $hash_base;
1905 } elsif (defined $hash) {
1906 $search_hash = $hash;
1908 $search_hash = "HEAD";
1910 $cgi->param("a", "search");
1911 $cgi->param("h", $search_hash);
1912 $cgi->param("p", $project);
1913 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1914 "<div class=\"search\">\n" .
1915 $cgi->hidden(-name
=> "p") . "\n" .
1916 $cgi->hidden(-name
=> "a") . "\n" .
1917 $cgi->hidden(-name
=> "h") . "\n" .
1918 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1919 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1920 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1922 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1924 $cgi->end_form() . "\n";
1929 sub git_footer_html
{
1930 print "<div class=\"page_footer\">\n";
1931 if (defined $project) {
1932 my $descr = git_get_project_description
($project);
1933 if (defined $descr) {
1934 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1936 print $cgi->a({-href
=> href
(action
=>"rss"),
1937 -class => "rss_logo"}, "RSS") . " ";
1938 print $cgi->a({-href
=> href
(action
=>"atom"),
1939 -class => "rss_logo"}, "Atom") . "\n";
1941 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1942 -class => "rss_logo"}, "OPML") . " ";
1943 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1944 -class => "rss_logo"}, "TXT") . "\n";
1948 if (-f
$site_footer) {
1949 open (my $fd, $site_footer);
1959 my $status = shift || "403 Forbidden";
1960 my $error = shift || "Malformed query, file missing or permission denied";
1962 git_header_html
($status);
1964 <div class="page_body">
1974 ## ----------------------------------------------------------------------
1975 ## functions printing or outputting HTML: navigation
1977 sub git_print_page_nav
{
1978 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1979 $extra = '' if !defined $extra; # pager or formats
1981 my @navs = qw(summary shortlog log commit commitdiff tree);
1983 @navs = grep { $_ ne $suppress } @navs;
1986 my %arg = map { $_ => {action
=>$_} } @navs;
1987 if (defined $head) {
1988 for (qw(commit commitdiff)) {
1989 $arg{$_}{'hash'} = $head;
1991 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1992 for (qw(shortlog log)) {
1993 $arg{$_}{'hash'} = $head;
1997 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
1998 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2000 print "<div class=\"page_nav\">\n" .
2002 map { $_ eq $current ?
2003 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2005 print "<br/>\n$extra<br/>\n" .
2009 sub format_paging_nav
{
2010 my ($action, $hash, $head, $page, $nrevs) = @_;
2014 if ($hash ne $head || $page) {
2015 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2017 $paging_nav .= "HEAD";
2021 $paging_nav .= " ⋅ " .
2022 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2023 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2025 $paging_nav .= " ⋅ prev";
2028 if ($nrevs >= (100 * ($page+1)-1)) {
2029 $paging_nav .= " ⋅ " .
2030 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2031 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2033 $paging_nav .= " ⋅ next";
2039 ## ......................................................................
2040 ## functions printing or outputting HTML: div
2042 sub git_print_header_div
{
2043 my ($action, $title, $hash, $hash_base) = @_;
2046 $args{'action'} = $action;
2047 $args{'hash'} = $hash if $hash;
2048 $args{'hash_base'} = $hash_base if $hash_base;
2050 print "<div class=\"header\">\n" .
2051 $cgi->a({-href
=> href
(%args), -class => "title"},
2052 $title ? $title : $action) .
2056 #sub git_print_authorship (\%) {
2057 sub git_print_authorship
{
2060 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2061 print "<div class=\"author_date\">" .
2062 esc_html
($co->{'author_name'}) .
2064 if ($ad{'hour_local'} < 6) {
2065 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2066 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2068 printf(" (%02d:%02d %s)",
2069 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2074 sub git_print_page_path
{
2080 print "<div class=\"page_path\">";
2081 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2082 -title
=> 'tree root'}, decode_utf8
("[$project]"));
2084 if (defined $name) {
2085 my @dirname = split '/', $name;
2086 my $basename = pop @dirname;
2089 foreach my $dir (@dirname) {
2090 $fullname .= ($fullname ? '/' : '') . $dir;
2091 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2093 -title
=> $fullname}, esc_path
($dir));
2096 if (defined $type && $type eq 'blob') {
2097 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2099 -title
=> $name}, esc_path
($basename));
2100 } elsif (defined $type && $type eq 'tree') {
2101 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2103 -title
=> $name}, esc_path
($basename));
2106 print esc_path
($basename);
2109 print "<br/></div>\n";
2112 # sub git_print_log (\@;%) {
2113 sub git_print_log
($;%) {
2117 if ($opts{'-remove_title'}) {
2118 # remove title, i.e. first line of log
2121 # remove leading empty lines
2122 while (defined $log->[0] && $log->[0] eq "") {
2129 foreach my $line (@$log) {
2130 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2133 if (! $opts{'-remove_signoff'}) {
2134 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2137 # remove signoff lines
2144 # print only one empty line
2145 # do not print empty line after signoff
2147 next if ($empty || $signoff);
2153 print format_log_line_html
($line) . "<br/>\n";
2156 if ($opts{'-final_empty_line'}) {
2157 # end with single empty line
2158 print "<br/>\n" unless $empty;
2162 # return link target (what link points to)
2163 sub git_get_link_target
{
2168 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2172 $link_target = <$fd>;
2177 return $link_target;
2180 # given link target, and the directory (basedir) the link is in,
2181 # return target of link relative to top directory (top tree);
2182 # return undef if it is not possible (including absolute links).
2183 sub normalize_link_target
{
2184 my ($link_target, $basedir, $hash_base) = @_;
2186 # we can normalize symlink target only if $hash_base is provided
2187 return unless $hash_base;
2189 # absolute symlinks (beginning with '/') cannot be normalized
2190 return if (substr($link_target, 0, 1) eq '/');
2192 # normalize link target to path from top (root) tree (dir)
2195 $path = $basedir . '/' . $link_target;
2197 # we are in top (root) tree (dir)
2198 $path = $link_target;
2201 # remove //, /./, and /../
2203 foreach my $part (split('/', $path)) {
2204 # discard '.' and ''
2205 next if (!$part || $part eq '.');
2207 if ($part eq '..') {
2211 # link leads outside repository (outside top dir)
2215 push @path_parts, $part;
2218 $path = join('/', @path_parts);
2223 # print tree entry (row of git_tree), but without encompassing <tr> element
2224 sub git_print_tree_entry
{
2225 my ($t, $basedir, $hash_base, $have_blame) = @_;
2228 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2230 # The format of a table row is: mode list link. Where mode is
2231 # the mode of the entry, list is the name of the entry, an href,
2232 # and link is the action links of the entry.
2234 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2235 if ($t->{'type'} eq "blob") {
2236 print "<td class=\"list\">" .
2237 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2238 file_name
=>"$basedir$t->{'name'}", %base_key),
2239 -class => "list"}, esc_path
($t->{'name'}));
2240 if (S_ISLNK
(oct $t->{'mode'})) {
2241 my $link_target = git_get_link_target
($t->{'hash'});
2243 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2244 if (defined $norm_target) {
2246 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2247 file_name
=>$norm_target),
2248 -title
=> $norm_target}, esc_path
($link_target));
2250 print " -> " . esc_path
($link_target);
2255 print "<td class=\"link\">";
2256 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2257 file_name
=>"$basedir$t->{'name'}", %base_key)},
2261 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2262 file_name
=>"$basedir$t->{'name'}", %base_key)},
2265 if (defined $hash_base) {
2267 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2268 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2272 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2273 file_name
=>"$basedir$t->{'name'}")},
2277 } elsif ($t->{'type'} eq "tree") {
2278 print "<td class=\"list\">";
2279 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2280 file_name
=>"$basedir$t->{'name'}", %base_key)},
2281 esc_path
($t->{'name'}));
2283 print "<td class=\"link\">";
2284 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2285 file_name
=>"$basedir$t->{'name'}", %base_key)},
2287 if (defined $hash_base) {
2289 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2290 file_name
=>"$basedir$t->{'name'}")},
2297 ## ......................................................................
2298 ## functions printing large fragments of HTML
2300 sub fill_from_file_info
{
2301 my ($diff, @parents) = @_;
2303 $diff->{'from_file'} = [ ];
2304 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2305 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2306 if ($diff->{'status'}[$i] eq 'R' ||
2307 $diff->{'status'}[$i] eq 'C') {
2308 $diff->{'from_file'}[$i] =
2309 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2316 # parameters can be strings, or references to arrays of strings
2320 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @$a == @$b) {
2321 for (my $i = 0; $i < @$a; ++$i) {
2322 return 0 unless ($a->[$i] eq $b->[$i]);
2325 } elsif (!ref($a) && !ref($b)) {
2333 sub git_difftree_body
{
2334 my ($difftree, $hash, @parents) = @_;
2335 my ($parent) = $parents[0];
2336 my ($have_blame) = gitweb_check_feature
('blame');
2337 print "<div class=\"list_head\">\n";
2338 if ($#{$difftree} > 10) {
2339 print(($#{$difftree} + 1) . " files changed:\n");
2343 print "<table class=\"" .
2344 (@parents > 1 ? "combined " : "") .
2348 foreach my $line (@{$difftree}) {
2350 if (ref($line) eq "HASH") {
2351 # pre-parsed (or generated by hand)
2354 $diff = parse_difftree_raw_line
($line);
2358 print "<tr class=\"dark\">\n";
2360 print "<tr class=\"light\">\n";
2364 if (exists $diff->{'nparents'}) { # combined diff
2366 fill_from_file_info
($diff, @parents)
2367 unless exists $diff->{'from_file'};
2369 if ($diff->{'to_id'} ne ('0' x
40)) {
2370 # file exists in the result (child) commit
2372 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2373 file_name
=>$diff->{'to_file'},
2375 -class => "list"}, esc_path
($diff->{'to_file'})) .
2379 esc_path
($diff->{'to_file'}) .
2383 if ($action eq 'commitdiff') {
2386 print "<td class=\"link\">" .
2387 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2392 my $has_history = 0;
2393 my $not_deleted = 0;
2394 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2395 my $hash_parent = $parents[$i];
2396 my $from_hash = $diff->{'from_id'}[$i];
2397 my $from_path = $diff->{'from_file'}[$i];
2398 my $status = $diff->{'status'}[$i];
2400 $has_history ||= ($status ne 'A');
2401 $not_deleted ||= ($status ne 'D');
2403 if ($status eq 'A') {
2404 print "<td class=\"link\" align=\"right\"> | </td>\n";
2405 } elsif ($status eq 'D') {
2406 print "<td class=\"link\">" .
2407 $cgi->a({-href
=> href
(action
=>"blob",
2410 file_name
=>$from_path)},
2414 if ($diff->{'to_id'} eq $from_hash) {
2415 print "<td class=\"link nochange\">";
2417 print "<td class=\"link\">";
2419 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2420 hash
=>$diff->{'to_id'},
2421 hash_parent
=>$from_hash,
2423 hash_parent_base
=>$hash_parent,
2424 file_name
=>$diff->{'to_file'},
2425 file_parent
=>$from_path)},
2431 print "<td class=\"link\">";
2433 print $cgi->a({-href
=> href
(action
=>"blob",
2434 hash
=>$diff->{'to_id'},
2435 file_name
=>$diff->{'to_file'},
2438 print " | " if ($has_history);
2441 print $cgi->a({-href
=> href
(action
=>"history",
2442 file_name
=>$diff->{'to_file'},
2449 next; # instead of 'else' clause, to avoid extra indent
2451 # else ordinary diff
2453 my ($to_mode_oct, $to_mode_str, $to_file_type);
2454 my ($from_mode_oct, $from_mode_str, $from_file_type);
2455 if ($diff->{'to_mode'} ne ('0' x
6)) {
2456 $to_mode_oct = oct $diff->{'to_mode'};
2457 if (S_ISREG
($to_mode_oct)) { # only for regular file
2458 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2460 $to_file_type = file_type
($diff->{'to_mode'});
2462 if ($diff->{'from_mode'} ne ('0' x
6)) {
2463 $from_mode_oct = oct $diff->{'from_mode'};
2464 if (S_ISREG
($to_mode_oct)) { # only for regular file
2465 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2467 $from_file_type = file_type
($diff->{'from_mode'});
2470 if ($diff->{'status'} eq "A") { # created
2471 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2472 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2473 $mode_chng .= "]</span>";
2475 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2476 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2477 -class => "list"}, esc_path
($diff->{'file'}));
2479 print "<td>$mode_chng</td>\n";
2480 print "<td class=\"link\">";
2481 if ($action eq 'commitdiff') {
2484 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2487 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2488 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2492 } elsif ($diff->{'status'} eq "D") { # deleted
2493 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2495 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2496 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2497 -class => "list"}, esc_path
($diff->{'file'}));
2499 print "<td>$mode_chng</td>\n";
2500 print "<td class=\"link\">";
2501 if ($action eq 'commitdiff') {
2504 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2507 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2508 hash_base
=>$parent, file_name
=>$diff->{'file'})},
2511 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2512 file_name
=>$diff->{'file'})},
2515 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2516 file_name
=>$diff->{'file'})},
2520 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2521 my $mode_chnge = "";
2522 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2523 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2524 if ($from_file_type ne $to_file_type) {
2525 $mode_chnge .= " from $from_file_type to $to_file_type";
2527 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2528 if ($from_mode_str && $to_mode_str) {
2529 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2530 } elsif ($to_mode_str) {
2531 $mode_chnge .= " mode: $to_mode_str";
2534 $mode_chnge .= "]</span>\n";
2537 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2538 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2539 -class => "list"}, esc_path
($diff->{'file'}));
2541 print "<td>$mode_chnge</td>\n";
2542 print "<td class=\"link\">";
2543 if ($action eq 'commitdiff') {
2546 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2548 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2549 # "commit" view and modified file (not onlu mode changed)
2550 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2551 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2552 hash_base
=>$hash, hash_parent_base
=>$parent,
2553 file_name
=>$diff->{'file'})},
2557 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2558 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2561 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2562 file_name
=>$diff->{'file'})},
2565 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2566 file_name
=>$diff->{'file'})},
2570 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
2571 my %status_name = ('R' => 'moved', 'C' => 'copied');
2572 my $nstatus = $status_name{$diff->{'status'}};
2574 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2575 # mode also for directories, so we cannot use $to_mode_str
2576 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2579 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2580 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
2581 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
2582 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2583 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2584 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
2585 -class => "list"}, esc_path
($diff->{'from_file'})) .
2586 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2587 "<td class=\"link\">";
2588 if ($action eq 'commitdiff') {
2591 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2593 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2594 # "commit" view and modified file (not only pure rename or copy)
2595 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2596 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2597 hash_base
=>$hash, hash_parent_base
=>$parent,
2598 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
2602 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2603 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
2606 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2607 file_name
=>$diff->{'to_file'})},
2610 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2611 file_name
=>$diff->{'to_file'})},
2615 } # we should not encounter Unmerged (U) or Unknown (X) status
2621 sub git_patchset_body
{
2622 my ($fd, $difftree, $hash, @hash_parents) = @_;
2623 my ($hash_parent) = $hash_parents[0];
2626 my $patch_number = 0;
2631 print "<div class=\"patchset\">\n";
2633 # skip to first patch
2634 while ($patch_line = <$fd>) {
2637 last if ($patch_line =~ m/^diff /);
2641 while ($patch_line) {
2643 my ($from_id, $to_id);
2646 #assert($patch_line =~ m/^diff /) if DEBUG;
2647 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2649 push @diff_header, $patch_line;
2651 # extended diff header
2653 while ($patch_line = <$fd>) {
2656 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2658 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2661 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2662 $from_id = [ split(',', $1) ];
2666 push @diff_header, $patch_line;
2668 my $last_patch_line = $patch_line;
2670 # check if current patch belong to current raw line
2671 # and parse raw git-diff line if needed
2672 if (defined $diffinfo &&
2673 defined $from_id && defined $to_id &&
2674 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
2675 $diffinfo->{'to_id'} eq $to_id) {
2676 # this is continuation of a split patch
2677 print "<div class=\"patch cont\">\n";
2679 # advance raw git-diff output if needed
2680 $patch_idx++ if defined $diffinfo;
2682 # read and prepare patch information
2683 if (ref($difftree->[$patch_idx]) eq "HASH") {
2684 # pre-parsed (or generated by hand)
2685 $diffinfo = $difftree->[$patch_idx];
2687 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2689 if ($diffinfo->{'nparents'}) {
2693 fill_from_file_info
($diffinfo, @hash_parents)
2694 unless exists $diffinfo->{'from_file'};
2695 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2696 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2697 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2698 $from{'href'}[$i] = href
(action
=>"blob",
2699 hash_base
=>$hash_parents[$i],
2700 hash
=>$diffinfo->{'from_id'}[$i],
2701 file_name
=>$from{'file'}[$i]);
2703 $from{'href'}[$i] = undef;
2707 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2708 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2709 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2710 hash
=>$diffinfo->{'from_id'},
2711 file_name
=>$from{'file'});
2713 delete $from{'href'};
2716 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2717 if ($diffinfo->{'status'} ne "D") { # not deleted file
2718 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2719 hash
=>$diffinfo->{'to_id'},
2720 file_name
=>$to{'file'});
2724 # this is first patch for raw difftree line with $patch_idx index
2725 # we index @$difftree array from 0, but number patches from 1
2726 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2729 # print "git diff" header
2730 $patch_line = shift @diff_header;
2731 if ($diffinfo->{'nparents'}) {
2734 $patch_line =~ s!^(diff (.*?) )"?.*$!$1!;
2736 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2737 esc_path
($to{'file'}));
2738 } else { # file was deleted
2739 $patch_line .= esc_path
($to{'file'});
2744 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2745 if ($from{'href'}) {
2746 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2747 'a/' . esc_path
($from{'file'}));
2748 } else { # file was added
2749 $patch_line .= 'a/' . esc_path
($from{'file'});
2753 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2754 'b/' . esc_path
($to{'file'}));
2755 } else { # file was deleted
2756 $patch_line .= 'b/' . esc_path
($to{'file'});
2760 print "<div class=\"diff header\">$patch_line</div>\n";
2762 # print extended diff header
2763 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2765 foreach $patch_line (@diff_header) {
2767 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2768 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2769 esc_path
($from{'file'}));
2771 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2772 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2773 esc_path
($to{'file'}));
2775 # match single <mode>
2776 if ($patch_line =~ m/\s(\d{6})$/) {
2777 $patch_line .= '<span class="info"> (' .
2778 file_type_long
($1) .
2782 if ($patch_line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
2783 # can match only for combined diff
2784 $patch_line = 'index ';
2785 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2786 if ($from{'href'}[$i]) {
2787 $patch_line .= $cgi->a({-href
=>$from{'href'}[$i],
2789 substr($diffinfo->{'from_id'}[$i],0,7));
2791 $patch_line .= '0' x
7;
2794 $patch_line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
2796 $patch_line .= '..';
2798 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2799 substr($diffinfo->{'to_id'},0,7));
2801 $patch_line .= '0' x
7;
2804 } elsif ($patch_line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
2805 # can match only for ordinary diff
2806 my ($from_link, $to_link);
2807 if ($from{'href'}) {
2808 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2809 substr($diffinfo->{'from_id'},0,7));
2811 $from_link = '0' x
7;
2814 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2815 substr($diffinfo->{'to_id'},0,7));
2820 # my ($from_hash, $to_hash) =
2821 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2822 # my ($from_id, $to_id) =
2823 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2824 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2826 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2827 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2829 print $patch_line . "<br/>\n";
2831 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2833 # from-file/to-file diff header
2834 $patch_line = $last_patch_line;
2835 if (! $patch_line) {
2836 print "</div>\n"; # class="patch"
2839 next PATCH
if ($patch_line =~ m/^diff /);
2840 #assert($patch_line =~ m/^---/) if DEBUG;
2841 if (!$diffinfo->{'nparents'} && # not from-file line for combined diff
2842 $from{'href'} && $patch_line =~ m!^--- "?a/!) {
2843 $patch_line = '--- a/' .
2844 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2845 esc_path
($from{'file'}));
2847 print "<div class=\"diff from_file\">$patch_line</div>\n";
2849 $patch_line = <$fd>;
2852 #assert($patch_line =~ m/^+++/) if DEBUG;
2853 if ($to{'href'} && $patch_line =~ m!^\+\+\+ "?b/!) {
2854 $patch_line = '+++ b/' .
2855 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2856 esc_path
($to{'file'}));
2858 print "<div class=\"diff to_file\">$patch_line</div>\n";
2862 while ($patch_line = <$fd>) {
2865 next PATCH
if ($patch_line =~ m/^diff /);
2867 print format_diff_line
($patch_line, \
%from, \
%to);
2871 print "</div>\n"; # class="patch"
2873 print "<div class=\"diff nodifferences\">No differences found</div>\n" if (!$patch_number);
2875 print "</div>\n"; # class="patchset"
2878 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2880 sub git_project_list_body
{
2881 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2883 my ($check_forks) = gitweb_check_feature
('forks');
2886 foreach my $pr (@$projlist) {
2887 my (@aa) = git_get_last_activity
($pr->{'path'});
2891 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2892 if (!defined $pr->{'descr'}) {
2893 my $descr = git_get_project_description
($pr->{'path'}) || "";
2894 $pr->{'descr_long'} = decode_utf8
($descr);
2895 $pr->{'descr'} = chop_str
($descr, 25, 5);
2897 if (!defined $pr->{'owner'}) {
2898 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2901 my $pname = $pr->{'path'};
2902 if (($pname =~ s/\.git$//) &&
2903 ($pname !~ /\/$/) &&
2904 (-d
"$projectroot/$pname")) {
2905 $pr->{'forks'} = "-d $projectroot/$pname";
2911 push @projects, $pr;
2914 $order ||= $default_projects_order;
2915 $from = 0 unless defined $from;
2916 $to = $#projects if (!defined $to || $#projects < $to);
2918 print "<table class=\"project_list\">\n";
2919 unless ($no_header) {
2922 print "<th></th>\n";
2924 if ($order eq "project") {
2925 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2926 print "<th>Project</th>\n";
2929 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2930 -class => "header"}, "Project") .
2933 if ($order eq "descr") {
2934 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2935 print "<th>Description</th>\n";
2938 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2939 -class => "header"}, "Description") .
2942 if ($order eq "owner") {
2943 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2944 print "<th>Owner</th>\n";
2947 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2948 -class => "header"}, "Owner") .
2951 if ($order eq "age") {
2952 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2953 print "<th>Last Change</th>\n";
2956 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2957 -class => "header"}, "Last Change") .
2960 print "<th></th>\n" .
2964 for (my $i = $from; $i <= $to; $i++) {
2965 my $pr = $projects[$i];
2967 print "<tr class=\"dark\">\n";
2969 print "<tr class=\"light\">\n";
2974 if ($pr->{'forks'}) {
2975 print "<!-- $pr->{'forks'} -->\n";
2976 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2980 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2981 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2982 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2983 -class => "list", -title
=> $pr->{'descr_long'}},
2984 esc_html
($pr->{'descr'})) . "</td>\n" .
2985 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2986 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2987 $pr->{'age_string'} . "</td>\n" .
2988 "<td class=\"link\">" .
2989 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2990 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2991 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2992 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2993 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
2997 if (defined $extra) {
3000 print "<td></td>\n";
3002 print "<td colspan=\"5\">$extra</td>\n" .
3008 sub git_shortlog_body
{
3009 # uses global variable $project
3010 my ($commitlist, $from, $to, $refs, $extra) = @_;
3012 my $have_snapshot = gitweb_have_snapshot
();
3014 $from = 0 unless defined $from;
3015 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3017 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3019 for (my $i = $from; $i <= $to; $i++) {
3020 my %co = %{$commitlist->[$i]};
3021 my $commit = $co{'id'};
3022 my $ref = format_ref_marker
($refs, $commit);
3024 print "<tr class=\"dark\">\n";
3026 print "<tr class=\"light\">\n";
3029 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3030 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3031 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3033 print format_subject_html
($co{'title'}, $co{'title_short'},
3034 href
(action
=>"commit", hash
=>$commit), $ref);
3036 "<td class=\"link\">" .
3037 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3038 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3039 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3040 if ($have_snapshot) {
3041 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
3046 if (defined $extra) {
3048 "<td colspan=\"4\">$extra</td>\n" .
3054 sub git_history_body
{
3055 # Warning: assumes constant type (blob or tree) during history
3056 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3058 $from = 0 unless defined $from;
3059 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3061 print "<table class=\"history\" cellspacing=\"0\">\n";
3063 for (my $i = $from; $i <= $to; $i++) {
3064 my %co = %{$commitlist->[$i]};
3068 my $commit = $co{'id'};
3070 my $ref = format_ref_marker
($refs, $commit);
3073 print "<tr class=\"dark\">\n";
3075 print "<tr class=\"light\">\n";
3078 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3079 # shortlog uses chop_str($co{'author_name'}, 10)
3080 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3082 # originally git_history used chop_str($co{'title'}, 50)
3083 print format_subject_html
($co{'title'}, $co{'title_short'},
3084 href
(action
=>"commit", hash
=>$commit), $ref);
3086 "<td class=\"link\">" .
3087 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3088 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3090 if ($ftype eq 'blob') {
3091 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3092 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3093 if (defined $blob_current && defined $blob_parent &&
3094 $blob_current ne $blob_parent) {
3096 $cgi->a({-href
=> href
(action
=>"blobdiff",
3097 hash
=>$blob_current, hash_parent
=>$blob_parent,
3098 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3099 file_name
=>$file_name)},
3106 if (defined $extra) {
3108 "<td colspan=\"4\">$extra</td>\n" .
3115 # uses global variable $project
3116 my ($taglist, $from, $to, $extra) = @_;
3117 $from = 0 unless defined $from;
3118 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3120 print "<table class=\"tags\" cellspacing=\"0\">\n";
3122 for (my $i = $from; $i <= $to; $i++) {
3123 my $entry = $taglist->[$i];
3125 my $comment = $tag{'subject'};
3127 if (defined $comment) {
3128 $comment_short = chop_str
($comment, 30, 5);
3131 print "<tr class=\"dark\">\n";
3133 print "<tr class=\"light\">\n";
3136 if (defined $tag{'age'}) {
3137 print "<td><i>$tag{'age'}</i></td>\n";
3139 print "<td></td>\n";
3142 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3143 -class => "list name"}, esc_html
($tag{'name'})) .
3146 if (defined $comment) {
3147 print format_subject_html
($comment, $comment_short,
3148 href
(action
=>"tag", hash
=>$tag{'id'}));
3151 "<td class=\"selflink\">";
3152 if ($tag{'type'} eq "tag") {
3153 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3158 "<td class=\"link\">" . " | " .
3159 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3160 if ($tag{'reftype'} eq "commit") {
3161 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3162 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3163 } elsif ($tag{'reftype'} eq "blob") {
3164 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3169 if (defined $extra) {
3171 "<td colspan=\"5\">$extra</td>\n" .
3177 sub git_heads_body
{
3178 # uses global variable $project
3179 my ($headlist, $head, $from, $to, $extra) = @_;
3180 $from = 0 unless defined $from;
3181 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3183 print "<table class=\"heads\" cellspacing=\"0\">\n";
3185 for (my $i = $from; $i <= $to; $i++) {
3186 my $entry = $headlist->[$i];
3188 my $curr = $ref{'id'} eq $head;
3190 print "<tr class=\"dark\">\n";
3192 print "<tr class=\"light\">\n";
3195 print "<td><i>$ref{'age'}</i></td>\n" .
3196 ($curr ? "<td class=\"current_head\">" : "<td>") .
3197 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3198 -class => "list name"},esc_html
($ref{'name'})) .
3200 "<td class=\"link\">" .
3201 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3202 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3203 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3207 if (defined $extra) {
3209 "<td colspan=\"3\">$extra</td>\n" .
3215 sub git_search_grep_body
{
3216 my ($commitlist, $from, $to, $extra) = @_;
3217 $from = 0 unless defined $from;
3218 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3220 print "<table class=\"grep\" cellspacing=\"0\">\n";
3222 for (my $i = $from; $i <= $to; $i++) {
3223 my %co = %{$commitlist->[$i]};
3227 my $commit = $co{'id'};
3229 print "<tr class=\"dark\">\n";
3231 print "<tr class=\"light\">\n";
3234 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3235 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3237 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3238 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3239 my $comment = $co{'comment'};
3240 foreach my $line (@$comment) {
3241 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3242 my $lead = esc_html
($1) || "";
3243 $lead = chop_str
($lead, 30, 10);
3244 my $match = esc_html
($2) || "";
3245 my $trail = esc_html
($3) || "";
3246 $trail = chop_str
($trail, 30, 10);
3247 my $text = "$lead<span class=\"match\">$match</span>$trail";
3248 print chop_str
($text, 80, 5) . "<br/>\n";
3252 "<td class=\"link\">" .
3253 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3255 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3259 if (defined $extra) {
3261 "<td colspan=\"3\">$extra</td>\n" .
3267 ## ======================================================================
3268 ## ======================================================================
3271 sub git_project_list
{
3272 my $order = $cgi->param('o');
3273 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3274 die_error
(undef, "Unknown order parameter");
3277 my @list = git_get_projects_list
();
3279 die_error
(undef, "No projects found");
3283 if (-f
$home_text) {
3284 print "<div class=\"index_include\">\n";
3285 open (my $fd, $home_text);
3290 git_project_list_body
(\
@list, $order);
3295 my $order = $cgi->param('o');
3296 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3297 die_error
(undef, "Unknown order parameter");
3300 my @list = git_get_projects_list
($project);
3302 die_error
(undef, "No forks found");
3306 git_print_page_nav
('','');
3307 git_print_header_div
('summary', "$project forks");
3308 git_project_list_body
(\
@list, $order);
3312 sub git_project_index
{
3313 my @projects = git_get_projects_list
($project);
3316 -type
=> 'text/plain',
3317 -charset
=> 'utf-8',
3318 -content_disposition
=> 'inline; filename="index.aux"');
3320 foreach my $pr (@projects) {
3321 if (!exists $pr->{'owner'}) {
3322 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3325 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3326 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3327 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3328 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3332 print "$path $owner\n";
3337 my $descr = git_get_project_description
($project) || "none";
3338 my %co = parse_commit
("HEAD");
3339 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3340 my $head = $co{'id'};
3342 my $owner = git_get_project_owner
($project);
3344 my $refs = git_get_references
();
3345 # These get_*_list functions return one more to allow us to see if
3346 # there are more ...
3347 my @taglist = git_get_tags_list
(16);
3348 my @headlist = git_get_heads_list
(16);
3350 my ($check_forks) = gitweb_check_feature
('forks');
3353 @forklist = git_get_projects_list
($project);
3357 git_print_page_nav
('summary','', $head);
3359 print "<div class=\"title\"> </div>\n";
3360 print "<table cellspacing=\"0\">\n" .
3361 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3362 "<tr><td>owner</td><td>$owner</td></tr>\n" .
3363 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3364 # use per project git URL list in $projectroot/$project/cloneurl
3365 # or make project git URL from git base URL and project name
3366 my $url_tag = "URL";
3367 my @url_list = git_get_project_url_list
($project);
3368 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3369 foreach my $git_url (@url_list) {
3370 next unless $git_url;
3371 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3376 if (-s
"$projectroot/$project/README.html") {
3377 if (open my $fd, "$projectroot/$project/README.html") {
3378 print "<div class=\"title\">readme</div>\n";
3379 print $_ while (<$fd>);
3384 # we need to request one more than 16 (0..15) to check if
3386 my @commitlist = parse_commits
($head, 17);
3387 git_print_header_div
('shortlog');
3388 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3389 $#commitlist <= 15 ? undef :
3390 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3393 git_print_header_div
('tags');
3394 git_tags_body
(\
@taglist, 0, 15,
3395 $#taglist <= 15 ? undef :
3396 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3400 git_print_header_div
('heads');
3401 git_heads_body
(\
@headlist, $head, 0, 15,
3402 $#headlist <= 15 ? undef :
3403 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3407 git_print_header_div
('forks');
3408 git_project_list_body
(\
@forklist, undef, 0, 15,
3409 $#forklist <= 15 ? undef :
3410 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3418 my $head = git_get_head_hash
($project);
3420 git_print_page_nav
('','', $head,undef,$head);
3421 my %tag = parse_tag
($hash);
3424 die_error
(undef, "Unknown tag object");
3427 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3428 print "<div class=\"title_text\">\n" .
3429 "<table cellspacing=\"0\">\n" .
3431 "<td>object</td>\n" .
3432 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3433 $tag{'object'}) . "</td>\n" .
3434 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3435 $tag{'type'}) . "</td>\n" .
3437 if (defined($tag{'author'})) {
3438 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3439 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3440 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3441 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3444 print "</table>\n\n" .
3446 print "<div class=\"page_body\">";
3447 my $comment = $tag{'comment'};
3448 foreach my $line (@$comment) {
3450 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3460 my ($have_blame) = gitweb_check_feature
('blame');
3462 die_error
('403 Permission denied', "Permission denied");
3464 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3465 $hash_base ||= git_get_head_hash
($project);
3466 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3467 my %co = parse_commit
($hash_base)
3468 or die_error
(undef, "Reading commit failed");
3469 if (!defined $hash) {
3470 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3471 or die_error
(undef, "Error looking up file");
3473 $ftype = git_get_type
($hash);
3474 if ($ftype !~ "blob") {
3475 die_error
('400 Bad Request', "Object is not a blob");
3477 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3478 $file_name, $hash_base)
3479 or die_error
(undef, "Open git-blame failed");
3482 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3485 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3488 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3490 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3491 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3492 git_print_page_path
($file_name, $ftype, $hash_base);
3493 my @rev_color = (qw(light2 dark2));
3494 my $num_colors = scalar(@rev_color);
3495 my $current_color = 0;
3498 <div class="page_body">
3499 <table class="blame">
3500 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3505 last unless defined $_;
3506 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3507 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3508 if (!exists $metainfo{$full_rev}) {
3509 $metainfo{$full_rev} = {};
3511 my $meta = $metainfo{$full_rev};
3514 if (/^(\S+) (.*)$/) {
3520 my $rev = substr($full_rev, 0, 8);
3521 my $author = $meta->{'author'};
3522 my %date = parse_date
($meta->{'author-time'},
3523 $meta->{'author-tz'});
3524 my $date = $date{'iso-tz'};
3526 $current_color = ++$current_color % $num_colors;
3528 print "<tr class=\"$rev_color[$current_color]\">\n";
3530 print "<td class=\"sha1\"";
3531 print " title=\"". esc_html
($author) . ", $date\"";
3532 print " rowspan=\"$group_size\"" if ($group_size > 1);
3534 print $cgi->a({-href
=> href
(action
=>"commit",
3536 file_name
=>$file_name)},
3540 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3541 or die_error
(undef, "Open git-rev-parse failed");
3542 my $parent_commit = <$dd>;
3544 chomp($parent_commit);
3545 my $blamed = href
(action
=> 'blame',
3546 file_name
=> $meta->{'filename'},
3547 hash_base
=> $parent_commit);
3548 print "<td class=\"linenr\">";
3549 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3551 -class => "linenr" },
3554 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3560 or print "Reading blob failed\n";
3567 my ($have_blame) = gitweb_check_feature
('blame');
3569 die_error
('403 Permission denied', "Permission denied");
3571 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3572 $hash_base ||= git_get_head_hash
($project);
3573 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3574 my %co = parse_commit
($hash_base)
3575 or die_error
(undef, "Reading commit failed");
3576 if (!defined $hash) {
3577 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3578 or die_error
(undef, "Error lookup file");
3580 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3581 or die_error
(undef, "Open git-annotate failed");
3584 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3587 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3590 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3592 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3593 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3594 git_print_page_path
($file_name, 'blob', $hash_base);
3595 print "<div class=\"page_body\">\n";
3597 <table class="blame">
3606 my @line_class = (qw(light dark));
3607 my $line_class_len = scalar (@line_class);
3608 my $line_class_num = $#line_class;
3609 while (my $line = <$fd>) {
3621 $line_class_num = ($line_class_num + 1) % $line_class_len;
3623 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3630 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3633 $short_rev = substr ($long_rev, 0, 8);
3634 $age = time () - $time;
3635 $age_str = age_string
($age);
3636 $age_str =~ s/ / /g;
3637 $age_class = age_class
($age);
3638 $author = esc_html
($author);
3639 $author =~ s/ / /g;
3641 $data = untabify
($data);
3642 $data = esc_html
($data);
3645 <tr class="$line_class[$line_class_num]">
3646 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3647 <td class="$age_class">$age_str</td>
3649 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3650 <td class="pre">$data</td>
3653 } # while (my $line = <$fd>)
3654 print "</table>\n\n";
3656 or print "Reading blob failed.\n";
3662 my $head = git_get_head_hash
($project);
3664 git_print_page_nav
('','', $head,undef,$head);
3665 git_print_header_div
('summary', $project);
3667 my @tagslist = git_get_tags_list
();
3669 git_tags_body
(\
@tagslist);
3675 my $head = git_get_head_hash
($project);
3677 git_print_page_nav
('','', $head,undef,$head);
3678 git_print_header_div
('summary', $project);
3680 my @headslist = git_get_heads_list
();
3682 git_heads_body
(\
@headslist, $head);
3687 sub git_blob_plain
{
3690 if (!defined $hash) {
3691 if (defined $file_name) {
3692 my $base = $hash_base || git_get_head_hash
($project);
3693 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3694 or die_error
(undef, "Error lookup file");
3696 die_error
(undef, "No file name defined");
3698 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3699 # blobs defined by non-textual hash id's can be cached
3704 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3705 or die_error
(undef, "Couldn't cat $file_name, $hash");
3707 $type ||= blob_mimetype
($fd, $file_name);
3709 # save as filename, even when no $file_name is given
3710 my $save_as = "$hash";
3711 if (defined $file_name) {
3712 $save_as = $file_name;
3713 } elsif ($type =~ m/^text\//) {
3720 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3722 binmode STDOUT
, ':raw';
3724 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3732 if (!defined $hash) {
3733 if (defined $file_name) {
3734 my $base = $hash_base || git_get_head_hash
($project);
3735 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3736 or die_error
(undef, "Error lookup file");
3738 die_error
(undef, "No file name defined");
3740 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3741 # blobs defined by non-textual hash id's can be cached
3745 my ($have_blame) = gitweb_check_feature
('blame');
3746 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3747 or die_error
(undef, "Couldn't cat $file_name, $hash");
3748 my $mimetype = blob_mimetype
($fd, $file_name);
3749 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3751 return git_blob_plain
($mimetype);
3753 # we can have blame only for text/* mimetype
3754 $have_blame &&= ($mimetype =~ m!^text/!);
3756 git_header_html
(undef, $expires);
3757 my $formats_nav = '';
3758 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3759 if (defined $file_name) {
3762 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3763 hash
=>$hash, file_name
=>$file_name)},
3768 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3769 hash
=>$hash, file_name
=>$file_name)},
3772 $cgi->a({-href
=> href
(action
=>"blob_plain",
3773 hash
=>$hash, file_name
=>$file_name)},
3776 $cgi->a({-href
=> href
(action
=>"blob",
3777 hash_base
=>"HEAD", file_name
=>$file_name)},
3781 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3783 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3784 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3786 print "<div class=\"page_nav\">\n" .
3787 "<br/><br/></div>\n" .
3788 "<div class=\"title\">$hash</div>\n";
3790 git_print_page_path
($file_name, "blob", $hash_base);
3791 print "<div class=\"page_body\">\n";
3792 if ($mimetype =~ m!^text/!) {
3794 while (my $line = <$fd>) {
3797 $line = untabify
($line);
3798 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3799 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3801 } elsif ($mimetype =~ m!^image/!) {
3802 print qq
!<img type
="$mimetype"!;
3804 print qq
! alt
="$file_name" title
="$file_name"!;
3807 href(action=>"blob_plain
", hash=>$hash,
3808 hash_base=>$hash_base, file_name=>$file_name) .
3812 or print "Reading blob failed.\n";
3818 my $have_snapshot = gitweb_have_snapshot
();
3820 if (!defined $hash_base) {
3821 $hash_base = "HEAD";
3823 if (!defined $hash) {
3824 if (defined $file_name) {
3825 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3831 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3832 or die_error
(undef, "Open git-ls-tree failed");
3833 my @entries = map { chomp; $_ } <$fd>;
3834 close $fd or die_error
(undef, "Reading tree failed");
3837 my $refs = git_get_references
();
3838 my $ref = format_ref_marker
($refs, $hash_base);
3841 my ($have_blame) = gitweb_check_feature
('blame');
3842 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3844 if (defined $file_name) {
3846 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3847 hash
=>$hash, file_name
=>$file_name)},
3849 $cgi->a({-href
=> href
(action
=>"tree",
3850 hash_base
=>"HEAD", file_name
=>$file_name)},
3853 if ($have_snapshot) {
3854 # FIXME: Should be available when we have no hash base as well.
3856 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3859 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3860 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3863 print "<div class=\"page_nav\">\n";
3864 print "<br/><br/></div>\n";
3865 print "<div class=\"title\">$hash</div>\n";
3867 if (defined $file_name) {
3868 $basedir = $file_name;
3869 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3873 git_print_page_path
($file_name, 'tree', $hash_base);
3874 print "<div class=\"page_body\">\n";
3875 print "<table cellspacing=\"0\">\n";
3877 # '..' (top directory) link if possible
3878 if (defined $hash_base &&
3879 defined $file_name && $file_name =~ m![^/]+$!) {
3881 print "<tr class=\"dark\">\n";
3883 print "<tr class=\"light\">\n";
3887 my $up = $file_name;
3888 $up =~ s!/?[^/]+$!!;
3889 undef $up unless $up;
3890 # based on git_print_tree_entry
3891 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3892 print '<td class="list">';
3893 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3897 print "<td class=\"link\"></td>\n";
3901 foreach my $line (@entries) {
3902 my %t = parse_ls_tree_line
($line, -z
=> 1);
3905 print "<tr class=\"dark\">\n";
3907 print "<tr class=\"light\">\n";
3911 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3915 print "</table>\n" .
3921 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3922 my $have_snapshot = (defined $ctype && defined $suffix);
3923 if (!$have_snapshot) {
3924 die_error
('403 Permission denied', "Permission denied");
3927 if (!defined $hash) {
3928 $hash = git_get_head_hash
($project);
3931 my $filename = decode_utf8
(basename
($project)) . "-$hash.tar.$suffix";
3934 -type
=> "application/$ctype",
3935 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3936 -status
=> '200 OK');
3938 my $git = git_cmd_str
();
3939 my $name = $project;
3940 $name =~ s/\047/\047\\\047\047/g;
3942 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3943 or die_error
(undef, "Execute git-tar-tree failed");
3944 binmode STDOUT
, ':raw';
3946 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3952 my $head = git_get_head_hash
($project);
3953 if (!defined $hash) {
3956 if (!defined $page) {
3959 my $refs = git_get_references
();
3961 my @commitlist = parse_commits
($hash, 101, (100 * $page));
3963 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
3966 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3969 my %co = parse_commit
($hash);
3971 git_print_header_div
('summary', $project);
3972 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3974 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
3975 for (my $i = 0; $i <= $to; $i++) {
3976 my %co = %{$commitlist[$i]};
3978 my $commit = $co{'id'};
3979 my $ref = format_ref_marker
($refs, $commit);
3980 my %ad = parse_date
($co{'author_epoch'});
3981 git_print_header_div
('commit',
3982 "<span class=\"age\">$co{'age_string'}</span>" .
3983 esc_html
($co{'title'}) . $ref,
3985 print "<div class=\"title_text\">\n" .
3986 "<div class=\"log_link\">\n" .
3987 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3989 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3991 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3994 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3997 print "<div class=\"log_body\">\n";
3998 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4001 if ($#commitlist >= 100) {
4002 print "<div class=\"page_nav\">\n";
4003 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4004 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4011 $hash ||= $hash_base || "HEAD";
4012 my %co = parse_commit
($hash);
4014 die_error
(undef, "Unknown commit object");
4016 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4017 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4019 my $parent = $co{'parent'};
4020 my $parents = $co{'parents'}; # listref
4022 # we need to prepare $formats_nav before any parameter munging
4024 if (!defined $parent) {
4026 $formats_nav .= '(initial)';
4027 } elsif (@$parents == 1) {
4028 # single parent commit
4031 $cgi->a({-href
=> href
(action
=>"commit",
4033 esc_html
(substr($parent, 0, 7))) .
4040 $cgi->a({-href
=> href
(action
=>"commit",
4042 esc_html
(substr($_, 0, 7)));
4047 if (!defined $parent) {
4051 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4053 (@$parents <= 1 ? $parent : '-c'),
4055 or die_error
(undef, "Open git-diff-tree failed");
4056 @difftree = map { chomp; $_ } <$fd>;
4057 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4059 # non-textual hash id's can be cached
4061 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4064 my $refs = git_get_references
();
4065 my $ref = format_ref_marker
($refs, $co{'id'});
4067 my $have_snapshot = gitweb_have_snapshot
();
4069 git_header_html
(undef, $expires);
4070 git_print_page_nav
('commit', '',
4071 $hash, $co{'tree'}, $hash,
4074 if (defined $co{'parent'}) {
4075 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4077 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4079 print "<div class=\"title_text\">\n" .
4080 "<table cellspacing=\"0\">\n";
4081 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4083 "<td></td><td> $ad{'rfc2822'}";
4084 if ($ad{'hour_local'} < 6) {
4085 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4086 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4088 printf(" (%02d:%02d %s)",
4089 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4093 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4094 print "<tr><td></td><td> $cd{'rfc2822'}" .
4095 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4097 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4100 "<td class=\"sha1\">" .
4101 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4102 class => "list"}, $co{'tree'}) .
4104 "<td class=\"link\">" .
4105 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4107 if ($have_snapshot) {
4109 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
4114 foreach my $par (@$parents) {
4117 "<td class=\"sha1\">" .
4118 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4119 class => "list"}, $par) .
4121 "<td class=\"link\">" .
4122 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4124 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4131 print "<div class=\"page_body\">\n";
4132 git_print_log
($co{'comment'});
4135 git_difftree_body
(\
@difftree, $hash, @$parents);
4141 # object is defined by:
4142 # - hash or hash_base alone
4143 # - hash_base and file_name
4146 # - hash or hash_base alone
4147 if ($hash || ($hash_base && !defined $file_name)) {
4148 my $object_id = $hash || $hash_base;
4150 my $git_command = git_cmd_str
();
4151 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4152 or die_error
('404 Not Found', "Object does not exist");
4156 or die_error
('404 Not Found', "Object does not exist");
4158 # - hash_base and file_name
4159 } elsif ($hash_base && defined $file_name) {
4160 $file_name =~ s
,/+$,,;
4162 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4163 or die_error
('404 Not Found', "Base object does not exist");
4165 # here errors should not hapen
4166 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4167 or die_error
(undef, "Open git-ls-tree failed");
4171 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4172 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4173 die_error
('404 Not Found', "File or directory for given base does not exist");
4178 die_error
('404 Not Found', "Not enough information to find object");
4181 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4182 hash
=>$hash, hash_base
=>$hash_base,
4183 file_name
=>$file_name),
4184 -status
=> '302 Found');
4188 my $format = shift || 'html';
4195 # preparing $fd and %diffinfo for git_patchset_body
4197 if (defined $hash_base && defined $hash_parent_base) {
4198 if (defined $file_name) {
4200 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4201 $hash_parent_base, $hash_base,
4202 "--", (defined $file_parent ? $file_parent : ()), $file_name
4203 or die_error
(undef, "Open git-diff-tree failed");
4204 @difftree = map { chomp; $_ } <$fd>;
4206 or die_error
(undef, "Reading git-diff-tree failed");
4208 or die_error
('404 Not Found', "Blob diff not found");
4210 } elsif (defined $hash &&
4211 $hash =~ /[0-9a-fA-F]{40}/) {
4212 # try to find filename from $hash
4214 # read filtered raw output
4215 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4216 $hash_parent_base, $hash_base, "--"
4217 or die_error
(undef, "Open git-diff-tree failed");
4219 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4221 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4222 map { chomp; $_ } <$fd>;
4224 or die_error
(undef, "Reading git-diff-tree failed");
4226 or die_error
('404 Not Found', "Blob diff not found");
4229 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4232 if (@difftree > 1) {
4233 die_error
('404 Not Found', "Ambiguous blob diff specification");
4236 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4237 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4238 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4240 $hash_parent ||= $diffinfo{'from_id'};
4241 $hash ||= $diffinfo{'to_id'};
4243 # non-textual hash id's can be cached
4244 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4245 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4250 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4251 '-p', ($format eq 'html' ? "--full-index" : ()),
4252 $hash_parent_base, $hash_base,
4253 "--", (defined $file_parent ? $file_parent : ()), $file_name
4254 or die_error
(undef, "Open git-diff-tree failed");
4257 # old/legacy style URI
4258 if (!%diffinfo && # if new style URI failed
4259 defined $hash && defined $hash_parent) {
4260 # fake git-diff-tree raw output
4261 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4262 $diffinfo{'from_id'} = $hash_parent;
4263 $diffinfo{'to_id'} = $hash;
4264 if (defined $file_name) {
4265 if (defined $file_parent) {
4266 $diffinfo{'status'} = '2';
4267 $diffinfo{'from_file'} = $file_parent;
4268 $diffinfo{'to_file'} = $file_name;
4269 } else { # assume not renamed
4270 $diffinfo{'status'} = '1';
4271 $diffinfo{'from_file'} = $file_name;
4272 $diffinfo{'to_file'} = $file_name;
4274 } else { # no filename given
4275 $diffinfo{'status'} = '2';
4276 $diffinfo{'from_file'} = $hash_parent;
4277 $diffinfo{'to_file'} = $hash;
4280 # non-textual hash id's can be cached
4281 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4282 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4287 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4288 '-p', ($format eq 'html' ? "--full-index" : ()),
4289 $hash_parent, $hash, "--"
4290 or die_error
(undef, "Open git-diff failed");
4292 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4297 if ($format eq 'html') {
4299 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4300 hash
=>$hash, hash_parent
=>$hash_parent,
4301 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4302 file_name
=>$file_name, file_parent
=>$file_parent)},
4304 git_header_html
(undef, $expires);
4305 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4306 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4307 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4309 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4310 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4312 if (defined $file_name) {
4313 git_print_page_path
($file_name, "blob", $hash_base);
4315 print "<div class=\"page_path\"></div>\n";
4318 } elsif ($format eq 'plain') {
4320 -type
=> 'text/plain',
4321 -charset
=> 'utf-8',
4322 -expires
=> $expires,
4323 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4325 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4328 die_error
(undef, "Unknown blobdiff format");
4332 if ($format eq 'html') {
4333 print "<div class=\"page_body\">\n";
4335 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4338 print "</div>\n"; # class="page_body"
4342 while (my $line = <$fd>) {
4343 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4344 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4348 last if $line =~ m!^\+\+\+!;
4356 sub git_blobdiff_plain
{
4357 git_blobdiff
('plain');
4360 sub git_commitdiff
{
4361 my $format = shift || 'html';
4362 $hash ||= $hash_base || "HEAD";
4363 my %co = parse_commit
($hash);
4365 die_error
(undef, "Unknown commit object");
4368 # we need to prepare $formats_nav before any parameter munging
4370 if ($format eq 'html') {
4372 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4373 hash
=>$hash, hash_parent
=>$hash_parent)},
4376 if (defined $hash_parent) {
4377 # commitdiff with two commits given
4378 my $hash_parent_short = $hash_parent;
4379 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4380 $hash_parent_short = substr($hash_parent, 0, 7);
4384 $cgi->a({-href
=> href
(action
=>"commitdiff",
4385 hash
=>$hash_parent)},
4386 esc_html
($hash_parent_short)) .
4388 } elsif (!$co{'parent'}) {
4390 $formats_nav .= ' (initial)';
4391 } elsif (scalar @{$co{'parents'}} == 1) {
4392 # single parent commit
4395 $cgi->a({-href
=> href
(action
=>"commitdiff",
4396 hash
=>$co{'parent'})},
4397 esc_html
(substr($co{'parent'}, 0, 7))) .
4404 $cgi->a({-href
=> href
(action
=>"commitdiff",
4406 esc_html
(substr($_, 0, 7)));
4407 } @{$co{'parents'}} ) .
4412 my $hash_parent_param = $hash_parent;
4413 if (!defined $hash_parent) {
4414 $hash_parent_param =
4415 @{$co{'parents'}} > 1 ? '-c' : $co{'parent'} || '--root';
4421 if ($format eq 'html') {
4422 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4423 "--no-commit-id", "--patch-with-raw", "--full-index",
4424 $hash_parent_param, $hash, "--"
4425 or die_error
(undef, "Open git-diff-tree failed");
4427 while (my $line = <$fd>) {
4429 # empty line ends raw part of diff-tree output
4431 push @difftree, scalar parse_difftree_raw_line
($line);
4434 } elsif ($format eq 'plain') {
4435 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4436 '-p', $hash_parent_param, $hash, "--"
4437 or die_error
(undef, "Open git-diff-tree failed");
4440 die_error
(undef, "Unknown commitdiff format");
4443 # non-textual hash id's can be cached
4445 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4449 # write commit message
4450 if ($format eq 'html') {
4451 my $refs = git_get_references
();
4452 my $ref = format_ref_marker
($refs, $co{'id'});
4454 git_header_html
(undef, $expires);
4455 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4456 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4457 git_print_authorship
(\
%co);
4458 print "<div class=\"page_body\">\n";
4459 if (@{$co{'comment'}} > 1) {
4460 print "<div class=\"log\">\n";
4461 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4462 print "</div>\n"; # class="log"
4465 } elsif ($format eq 'plain') {
4466 my $refs = git_get_references
("tags");
4467 my $tagname = git_get_rev_name_tags
($hash);
4468 my $filename = basename
($project) . "-$hash.patch";
4471 -type
=> 'text/plain',
4472 -charset
=> 'utf-8',
4473 -expires
=> $expires,
4474 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4475 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4478 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4479 Subject: $co{'title'}
4481 print "X-Git-Tag: $tagname\n" if $tagname;
4482 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4484 foreach my $line (@{$co{'comment'}}) {
4491 if ($format eq 'html') {
4492 git_difftree_body
(\
@difftree, $hash, $hash_parent || @{$co{'parents'}});
4495 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent || @{$co{'parents'}});
4497 print "</div>\n"; # class="page_body"
4500 } elsif ($format eq 'plain') {
4504 or print "Reading git-diff-tree failed\n";
4508 sub git_commitdiff_plain
{
4509 git_commitdiff
('plain');
4513 if (!defined $hash_base) {
4514 $hash_base = git_get_head_hash
($project);
4516 if (!defined $page) {
4520 my %co = parse_commit
($hash_base);
4522 die_error
(undef, "Unknown commit object");
4525 my $refs = git_get_references
();
4526 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4528 if (!defined $hash && defined $file_name) {
4529 $hash = git_get_hash_by_path
($hash_base, $file_name);
4531 if (defined $hash) {
4532 $ftype = git_get_type
($hash);
4535 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4537 my $paging_nav = '';
4540 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4541 file_name
=>$file_name)},
4543 $paging_nav .= " ⋅ " .
4544 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4545 file_name
=>$file_name, page
=>$page-1),
4546 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4548 $paging_nav .= "first";
4549 $paging_nav .= " ⋅ prev";
4551 if ($#commitlist >= 100) {
4552 $paging_nav .= " ⋅ " .
4553 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4554 file_name
=>$file_name, page
=>$page+1),
4555 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4557 $paging_nav .= " ⋅ next";
4560 if ($#commitlist >= 100) {
4562 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4563 file_name
=>$file_name, page
=>$page+1),
4564 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4568 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4569 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4570 git_print_page_path
($file_name, $ftype, $hash_base);
4572 git_history_body
(\
@commitlist, 0, 99,
4573 $refs, $hash_base, $ftype, $next_link);
4579 my ($have_search) = gitweb_check_feature
('search');
4580 if (!$have_search) {
4581 die_error
('403 Permission denied', "Permission denied");
4583 if (!defined $searchtext) {
4584 die_error
(undef, "Text field empty");
4586 if (!defined $hash) {
4587 $hash = git_get_head_hash
($project);
4589 my %co = parse_commit
($hash);
4591 die_error
(undef, "Unknown commit object");
4593 if (!defined $page) {
4597 $searchtype ||= 'commit';
4598 if ($searchtype eq 'pickaxe') {
4599 # pickaxe may take all resources of your box and run for several minutes
4600 # with every query - so decide by yourself how public you make this feature
4601 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4602 if (!$have_pickaxe) {
4603 die_error
('403 Permission denied', "Permission denied");
4609 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4611 if ($searchtype eq 'commit') {
4612 $greptype = "--grep=";
4613 } elsif ($searchtype eq 'author') {
4614 $greptype = "--author=";
4615 } elsif ($searchtype eq 'committer') {
4616 $greptype = "--committer=";
4618 $greptype .= $searchtext;
4619 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4621 my $paging_nav = '';
4624 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4625 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4627 $paging_nav .= " ⋅ " .
4628 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4629 searchtext
=>$searchtext, searchtype
=>$searchtype,
4631 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4633 $paging_nav .= "first";
4634 $paging_nav .= " ⋅ prev";
4636 if ($#commitlist >= 100) {
4637 $paging_nav .= " ⋅ " .
4638 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4639 searchtext
=>$searchtext, searchtype
=>$searchtype,
4641 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4643 $paging_nav .= " ⋅ next";
4646 if ($#commitlist >= 100) {
4648 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4649 searchtext
=>$searchtext, searchtype
=>$searchtype,
4651 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4654 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4655 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4656 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4659 if ($searchtype eq 'pickaxe') {
4660 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4661 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4663 print "<table cellspacing=\"0\">\n";
4666 my $git_command = git_cmd_str
();
4667 open my $fd, "-|", "$git_command rev-list $hash | " .
4668 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
4671 while (my $line = <$fd>) {
4672 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4675 $set{'from_id'} = $3;
4677 $set{'id'} = $set{'to_id'};
4678 if ($set{'id'} =~ m/0{40}/) {
4679 $set{'id'} = $set{'from_id'};
4681 if ($set{'id'} =~ m/0{40}/) {
4685 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4688 print "<tr class=\"dark\">\n";
4690 print "<tr class=\"light\">\n";
4693 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4694 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4696 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4697 -class => "list subject"},
4698 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4699 while (my $setref = shift @files) {
4701 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4702 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4704 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4708 "<td class=\"link\">" .
4709 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4711 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4715 %co = parse_commit
($1);
4725 sub git_search_help
{
4727 git_print_page_nav
('','', $hash,$hash,$hash);
4730 <dt><b>commit</b></dt>
4731 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4732 <dt><b>author</b></dt>
4733 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4734 <dt><b>committer</b></dt>
4735 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4737 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4738 if ($have_pickaxe) {
4740 <dt><b>pickaxe</b></dt>
4741 <dd>All commits that caused the string to appear or disappear from any file (changes that
4742 added, removed or "modified" the string) will be listed. This search can take a while and
4743 takes a lot of strain on the server, so please use it wisely.</dd>
4751 my $head = git_get_head_hash
($project);
4752 if (!defined $hash) {
4755 if (!defined $page) {
4758 my $refs = git_get_references
();
4760 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4762 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
4764 if ($#commitlist >= 100) {
4766 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4767 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4771 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4772 git_print_header_div
('summary', $project);
4774 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
4779 ## ......................................................................
4780 ## feeds (RSS, Atom; OPML)
4783 my $format = shift || 'atom';
4784 my ($have_blame) = gitweb_check_feature
('blame');
4786 # Atom: http://www.atomenabled.org/developers/syndication/
4787 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4788 if ($format ne 'rss' && $format ne 'atom') {
4789 die_error
(undef, "Unknown web feed format");
4792 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4793 my $head = $hash || 'HEAD';
4794 my @commitlist = parse_commits
($head, 150);
4798 my $content_type = "application/$format+xml";
4799 if (defined $cgi->http('HTTP_ACCEPT') &&
4800 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4801 # browser (feed reader) prefers text/xml
4802 $content_type = 'text/xml';
4804 if (defined($commitlist[0])) {
4805 %latest_commit = %{$commitlist[0]};
4806 %latest_date = parse_date
($latest_commit{'author_epoch'});
4808 -type
=> $content_type,
4809 -charset
=> 'utf-8',
4810 -last_modified
=> $latest_date{'rfc2822'});
4813 -type
=> $content_type,
4814 -charset
=> 'utf-8');
4817 # Optimization: skip generating the body if client asks only
4818 # for Last-Modified date.
4819 return if ($cgi->request_method() eq 'HEAD');
4822 my $title = "$site_name - $project/$action";
4823 my $feed_type = 'log';
4824 if (defined $hash) {
4825 $title .= " - '$hash'";
4826 $feed_type = 'branch log';
4827 if (defined $file_name) {
4828 $title .= " :: $file_name";
4829 $feed_type = 'history';
4831 } elsif (defined $file_name) {
4832 $title .= " - $file_name";
4833 $feed_type = 'history';
4835 $title .= " $feed_type";
4836 my $descr = git_get_project_description
($project);
4837 if (defined $descr) {
4838 $descr = esc_html
($descr);
4840 $descr = "$project " .
4841 ($format eq 'rss' ? 'RSS' : 'Atom') .
4844 my $owner = git_get_project_owner
($project);
4845 $owner = esc_html
($owner);
4849 if (defined $file_name) {
4850 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
4851 } elsif (defined $hash) {
4852 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
4854 $alt_url = href
(-full
=>1, action
=>"summary");
4856 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
4857 if ($format eq 'rss') {
4859 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
4862 print "<title>$title</title>\n" .
4863 "<link>$alt_url</link>\n" .
4864 "<description>$descr</description>\n" .
4865 "<language>en</language>\n";
4866 } elsif ($format eq 'atom') {
4868 <feed xmlns="http://www.w3.org/2005/Atom">
4870 print "<title>$title</title>\n" .
4871 "<subtitle>$descr</subtitle>\n" .
4872 '<link rel="alternate" type="text/html" href="' .
4873 $alt_url . '" />' . "\n" .
4874 '<link rel="self" type="' . $content_type . '" href="' .
4875 $cgi->self_url() . '" />' . "\n" .
4876 "<id>" . href
(-full
=>1) . "</id>\n" .
4877 # use project owner for feed author
4878 "<author><name>$owner</name></author>\n";
4879 if (defined $favicon) {
4880 print "<icon>" . esc_url
($favicon) . "</icon>\n";
4882 if (defined $logo_url) {
4883 # not twice as wide as tall: 72 x 27 pixels
4884 print "<logo>" . esc_url
($logo) . "</logo>\n";
4886 if (! %latest_date) {
4887 # dummy date to keep the feed valid until commits trickle in:
4888 print "<updated>1970-01-01T00:00:00Z</updated>\n";
4890 print "<updated>$latest_date{'iso-8601'}</updated>\n";
4895 for (my $i = 0; $i <= $#commitlist; $i++) {
4896 my %co = %{$commitlist[$i]};
4897 my $commit = $co{'id'};
4898 # we read 150, we always show 30 and the ones more recent than 48 hours
4899 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
4902 my %cd = parse_date
($co{'author_epoch'});
4904 # get list of changed files
4905 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4906 $co{'parent'}, $co{'id'}, "--", (defined $file_name ? $file_name : ())
4908 my @difftree = map { chomp; $_ } <$fd>;
4912 # print element (entry, item)
4913 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
4914 if ($format eq 'rss') {
4916 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
4917 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
4918 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
4919 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
4920 "<link>$co_url</link>\n" .
4921 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
4922 "<content:encoded>" .
4924 } elsif ($format eq 'atom') {
4926 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
4927 "<updated>$cd{'iso-8601'}</updated>\n" .
4929 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
4930 if ($co{'author_email'}) {
4931 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
4933 print "</author>\n" .
4934 # use committer for contributor
4936 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
4937 if ($co{'committer_email'}) {
4938 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
4940 print "</contributor>\n" .
4941 "<published>$cd{'iso-8601'}</published>\n" .
4942 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
4943 "<id>$co_url</id>\n" .
4944 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
4945 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
4947 my $comment = $co{'comment'};
4949 foreach my $line (@$comment) {
4950 $line = esc_html
($line);
4953 print "</pre><ul>\n";
4954 foreach my $difftree_line (@difftree) {
4955 my %difftree = parse_difftree_raw_line
($difftree_line);
4956 next if !$difftree{'from_id'};
4958 my $file = $difftree{'file'} || $difftree{'to_file'};
4962 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
4963 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
4964 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
4965 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
4966 -title
=> "diff"}, 'D');
4968 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
4969 file_name
=>$file, hash_base
=>$commit),
4970 -title
=> "blame"}, 'B');
4972 # if this is not a feed of a file history
4973 if (!defined $file_name || $file_name ne $file) {
4974 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
4975 file_name
=>$file, hash
=>$commit),
4976 -title
=> "history"}, 'H');
4978 $file = esc_path
($file);
4982 if ($format eq 'rss') {
4983 print "</ul>]]>\n" .
4984 "</content:encoded>\n" .
4986 } elsif ($format eq 'atom') {
4987 print "</ul>\n</div>\n" .
4994 if ($format eq 'rss') {
4995 print "</channel>\n</rss>\n";
4996 } elsif ($format eq 'atom') {
5010 my @list = git_get_projects_list
();
5012 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5014 <?xml version="1.0" encoding="utf-8"?>
5015 <opml version="1.0">
5017 <title>$site_name OPML Export</title>
5020 <outline text="git RSS feeds">
5023 foreach my $pr (@list) {
5025 my $head = git_get_head_hash
($proj{'path'});
5026 if (!defined $head) {
5029 $git_dir = "$projectroot/$proj{'path'}";
5030 my %co = parse_commit
($head);
5035 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5036 my $rss = "$my_url?p=$proj{'path'};a=rss";
5037 my $html = "$my_url?p=$proj{'path'};a=summary";
5038 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";