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 # assume this charset if line contains non-UTF-8 characters;
99 # it should be valid encoding (see Encoding::Supported(3pm) for list),
100 # for which encoding all byte sequences are valid, for example
101 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
102 # could be even 'utf-8' for the old behavior)
103 our $fallback_encoding = 'latin1';
105 # You define site-wide feature defaults here; override them with
106 # $GITWEB_CONFIG as necessary.
109 # 'sub' => feature-sub (subroutine),
110 # 'override' => allow-override (boolean),
111 # 'default' => [ default options...] (array reference)}
113 # if feature is overridable (it means that allow-override has true value),
114 # then feature-sub will be called with default options as parameters;
115 # return value of feature-sub indicates if to enable specified feature
117 # if there is no 'sub' key (no feature-sub), then feature cannot be
120 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
122 # Enable the 'blame' blob view, showing the last commit that modified
123 # each line in the file. This can be very CPU-intensive.
125 # To enable system wide have in $GITWEB_CONFIG
126 # $feature{'blame'}{'default'} = [1];
127 # To have project specific config enable override in $GITWEB_CONFIG
128 # $feature{'blame'}{'override'} = 1;
129 # and in project config gitweb.blame = 0|1;
131 'sub' => \
&feature_blame
,
135 # Enable the 'snapshot' link, providing a compressed tarball of any
136 # tree. This can potentially generate high traffic if you have large
139 # To disable system wide have in $GITWEB_CONFIG
140 # $feature{'snapshot'}{'default'} = [undef];
141 # To have project specific config enable override in $GITWEB_CONFIG
142 # $feature{'snapshot'}{'override'} = 1;
143 # and in project config gitweb.snapshot = none|gzip|bzip2|zip;
145 'sub' => \
&feature_snapshot
,
147 # => [content-encoding, suffix, program]
148 'default' => ['x-gzip', 'gz', 'gzip']},
150 # Enable text search, which will list the commits which match author,
151 # committer or commit text to a given string. Enabled by default.
152 # Project specific override is not supported.
157 # Enable grep search, which will list the files in currently selected
158 # tree containing the given string. Enabled by default. This can be
159 # potentially CPU-intensive, of course.
161 # To enable system wide have in $GITWEB_CONFIG
162 # $feature{'grep'}{'default'} = [1];
163 # To have project specific config enable override in $GITWEB_CONFIG
164 # $feature{'grep'}{'override'} = 1;
165 # and in project config gitweb.grep = 0|1;
170 # Enable the pickaxe search, which will list the commits that modified
171 # a given string in a file. This can be practical and quite faster
172 # alternative to 'blame', but still potentially CPU-intensive.
174 # To enable system wide have in $GITWEB_CONFIG
175 # $feature{'pickaxe'}{'default'} = [1];
176 # To have project specific config enable override in $GITWEB_CONFIG
177 # $feature{'pickaxe'}{'override'} = 1;
178 # and in project config gitweb.pickaxe = 0|1;
180 'sub' => \
&feature_pickaxe
,
184 # Make gitweb use an alternative format of the URLs which can be
185 # more readable and natural-looking: project name is embedded
186 # directly in the path and the query string contains other
187 # auxiliary information. All gitweb installations recognize
188 # URL in either format; this configures in which formats gitweb
191 # To enable system wide have in $GITWEB_CONFIG
192 # $feature{'pathinfo'}{'default'} = [1];
193 # Project specific override is not supported.
195 # Note that you will need to change the default location of CSS,
196 # favicon, logo and possibly other files to an absolute URL. Also,
197 # if gitweb.cgi serves as your indexfile, you will need to force
198 # $my_uri to contain the script name in your $GITWEB_CONFIG.
203 # Make gitweb consider projects in project root subdirectories
204 # to be forks of existing projects. Given project $projname.git,
205 # projects matching $projname/*.git will not be shown in the main
206 # projects list, instead a '+' mark will be added to $projname
207 # there and a 'forks' view will be enabled for the project, listing
208 # all the forks. If project list is taken from a file, forks have
209 # to be listed after the main project.
211 # To enable system wide have in $GITWEB_CONFIG
212 # $feature{'forks'}{'default'} = [1];
213 # Project specific override is not supported.
219 sub gitweb_check_feature
{
221 return unless exists $feature{$name};
222 my ($sub, $override, @defaults) = (
223 $feature{$name}{'sub'},
224 $feature{$name}{'override'},
225 @{$feature{$name}{'default'}});
226 if (!$override) { return @defaults; }
228 warn "feature $name is not overrideable";
231 return $sub->(@defaults);
235 my ($val) = git_get_project_config
('blame', '--bool');
237 if ($val eq 'true') {
239 } elsif ($val eq 'false') {
246 sub feature_snapshot
{
247 my ($ctype, $suffix, $command) = @_;
249 my ($val) = git_get_project_config
('snapshot');
251 if ($val eq 'gzip') {
252 return ('x-gzip', 'gz', 'gzip');
253 } elsif ($val eq 'bzip2') {
254 return ('x-bzip2', 'bz2', 'bzip2');
255 } elsif ($val eq 'zip') {
256 return ('x-zip', 'zip', '');
257 } elsif ($val eq 'none') {
261 return ($ctype, $suffix, $command);
264 sub gitweb_have_snapshot
{
265 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
266 my $have_snapshot = (defined $ctype && defined $suffix);
268 return $have_snapshot;
272 my ($val) = git_get_project_config
('grep', '--bool');
274 if ($val eq 'true') {
276 } elsif ($val eq 'false') {
283 sub feature_pickaxe
{
284 my ($val) = git_get_project_config
('pickaxe', '--bool');
286 if ($val eq 'true') {
288 } elsif ($val eq 'false') {
295 # checking HEAD file with -e is fragile if the repository was
296 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
298 sub check_head_link
{
300 my $headfile = "$dir/HEAD";
301 return ((-e
$headfile) ||
302 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
305 sub check_export_ok
{
307 return (check_head_link
($dir) &&
308 (!$export_ok || -e
"$dir/$export_ok"));
311 # rename detection options for git-diff and git-diff-tree
312 # - default is '-M', with the cost proportional to
313 # (number of removed files) * (number of new files).
314 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
315 # (number of changed files + number of removed files) * (number of new files)
316 # - even more costly is '-C', '--find-copies-harder' with cost
317 # (number of files in the original tree) * (number of new files)
318 # - one might want to include '-B' option, e.g. '-B', '-M'
319 our @diff_opts = ('-M'); # taken from git_commit
321 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
322 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
324 # version of the core git binary
325 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
327 $projects_list ||= $projectroot;
329 # ======================================================================
330 # input validation and dispatch
331 our $action = $cgi->param('a');
332 if (defined $action) {
333 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
334 die_error
(undef, "Invalid action parameter");
338 # parameters which are pathnames
339 our $project = $cgi->param('p');
340 if (defined $project) {
341 if (!validate_pathname
($project) ||
342 !(-d
"$projectroot/$project") ||
343 !check_head_link
("$projectroot/$project") ||
344 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
345 ($strict_export && !project_in_list
($project))) {
347 die_error
(undef, "No such project");
351 our $file_name = $cgi->param('f');
352 if (defined $file_name) {
353 if (!validate_pathname
($file_name)) {
354 die_error
(undef, "Invalid file parameter");
358 our $file_parent = $cgi->param('fp');
359 if (defined $file_parent) {
360 if (!validate_pathname
($file_parent)) {
361 die_error
(undef, "Invalid file parent parameter");
365 # parameters which are refnames
366 our $hash = $cgi->param('h');
368 if (!validate_refname
($hash)) {
369 die_error
(undef, "Invalid hash parameter");
373 our $hash_parent = $cgi->param('hp');
374 if (defined $hash_parent) {
375 if (!validate_refname
($hash_parent)) {
376 die_error
(undef, "Invalid hash parent parameter");
380 our $hash_base = $cgi->param('hb');
381 if (defined $hash_base) {
382 if (!validate_refname
($hash_base)) {
383 die_error
(undef, "Invalid hash base parameter");
387 our $hash_parent_base = $cgi->param('hpb');
388 if (defined $hash_parent_base) {
389 if (!validate_refname
($hash_parent_base)) {
390 die_error
(undef, "Invalid hash parent base parameter");
395 our $page = $cgi->param('pg');
397 if ($page =~ m/[^0-9]/) {
398 die_error
(undef, "Invalid page parameter");
402 our $searchtype = $cgi->param('st');
403 if (defined $searchtype) {
404 if ($searchtype =~ m/[^a-z]/) {
405 die_error
(undef, "Invalid searchtype parameter");
409 our $searchtext = $cgi->param('s');
411 if (defined $searchtext) {
412 if ($searchtype ne 'grep' and $searchtype ne 'pickaxe' and $searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
413 die_error
(undef, "Invalid search parameter");
415 if (length($searchtext) < 2) {
416 die_error
(undef, "At least two characters are required for search parameter");
418 $search_regexp = quotemeta $searchtext;
421 # now read PATH_INFO and use it as alternative to parameters
422 sub evaluate_path_info
{
423 return if defined $project;
424 my $path_info = $ENV{"PATH_INFO"};
425 return if !$path_info;
426 $path_info =~ s
,^/+,,;
427 return if !$path_info;
428 # find which part of PATH_INFO is project
429 $project = $path_info;
431 while ($project && !check_head_link
("$projectroot/$project")) {
432 $project =~ s
,/*[^/]*$,,;
435 $project = validate_pathname
($project);
437 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
438 ($strict_export && !project_in_list
($project))) {
442 # do not change any parameters if an action is given using the query string
444 $path_info =~ s
,^$project/*,,;
445 my ($refname, $pathname) = split(/:/, $path_info, 2);
446 if (defined $pathname) {
447 # we got "project.git/branch:filename" or "project.git/branch:dir/"
448 # we could use git_get_type(branch:pathname), but it needs $git_dir
449 $pathname =~ s
,^/+,,;
450 if (!$pathname || substr($pathname, -1) eq "/") {
454 $action ||= "blob_plain";
456 $hash_base ||= validate_refname
($refname);
457 $file_name ||= validate_pathname
($pathname);
458 } elsif (defined $refname) {
459 # we got "project.git/branch"
460 $action ||= "shortlog";
461 $hash ||= validate_refname
($refname);
464 evaluate_path_info
();
466 # path to the current git repository
468 $git_dir = "$projectroot/$project" if $project;
472 "blame" => \
&git_blame2
,
473 "blobdiff" => \
&git_blobdiff
,
474 "blobdiff_plain" => \
&git_blobdiff_plain
,
475 "blob" => \
&git_blob
,
476 "blob_plain" => \
&git_blob_plain
,
477 "commitdiff" => \
&git_commitdiff
,
478 "commitdiff_plain" => \
&git_commitdiff_plain
,
479 "commit" => \
&git_commit
,
480 "forks" => \
&git_forks
,
481 "heads" => \
&git_heads
,
482 "history" => \
&git_history
,
485 "atom" => \
&git_atom
,
486 "search" => \
&git_search
,
487 "search_help" => \
&git_search_help
,
488 "shortlog" => \
&git_shortlog
,
489 "summary" => \
&git_summary
,
491 "tags" => \
&git_tags
,
492 "tree" => \
&git_tree
,
493 "snapshot" => \
&git_snapshot
,
494 "object" => \
&git_object
,
495 # those below don't need $project
496 "opml" => \
&git_opml
,
497 "project_list" => \
&git_project_list
,
498 "project_index" => \
&git_project_index
,
501 if (!defined $action) {
503 $action = git_get_type
($hash);
504 } elsif (defined $hash_base && defined $file_name) {
505 $action = git_get_type
("$hash_base:$file_name");
506 } elsif (defined $project) {
509 $action = 'project_list';
512 if (!defined($actions{$action})) {
513 die_error
(undef, "Unknown action");
515 if ($action !~ m/^(opml|project_list|project_index)$/ &&
517 die_error
(undef, "Project needed");
519 $actions{$action}->();
522 ## ======================================================================
527 # default is to use -absolute url() i.e. $my_uri
528 my $href = $params{-full
} ? $my_url : $my_uri;
530 # XXX: Warning: If you touch this, check the search form for updating,
541 hash_parent_base
=> "hpb",
547 my %mapping = @mapping;
549 $params{'project'} = $project unless exists $params{'project'};
551 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
553 # use PATH_INFO for project name
554 $href .= "/$params{'project'}" if defined $params{'project'};
555 delete $params{'project'};
557 # Summary just uses the project path URL
558 if (defined $params{'action'} && $params{'action'} eq 'summary') {
559 delete $params{'action'};
563 # now encode the parameters explicitly
565 for (my $i = 0; $i < @mapping; $i += 2) {
566 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
567 if (defined $params{$name}) {
568 push @result, $symbol . "=" . esc_param
($params{$name});
571 $href .= "?" . join(';', @result) if scalar @result;
577 ## ======================================================================
578 ## validation, quoting/unquoting and escaping
580 sub validate_pathname
{
581 my $input = shift || return undef;
583 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
584 # at the beginning, at the end, and between slashes.
585 # also this catches doubled slashes
586 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
590 if ($input =~ m!\0!) {
596 sub validate_refname
{
597 my $input = shift || return undef;
599 # textual hashes are O.K.
600 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
603 # it must be correct pathname
604 $input = validate_pathname
($input)
606 # restrictions on ref name according to git-check-ref-format
607 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
613 # decode sequences of octets in utf8 into Perl's internal form,
614 # which is utf-8 with utf8 flag set if needed. gitweb writes out
615 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
619 eval { $res = decode_utf8
($str, Encode
::FB_CROAK
); };
623 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
627 # quote unsafe chars, but keep the slash, even when it's not
628 # correct, but quoted slashes look too horrible in bookmarks
631 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
637 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
640 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
646 # replace invalid utf8 character with SUBSTITUTION sequence
651 $str = to_utf8
($str);
652 $str = $cgi->escapeHTML($str);
653 if ($opts{'-nbsp'}) {
654 $str =~ s/ / /g;
656 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
660 # quote control characters and escape filename to HTML
665 $str = to_utf8
($str);
666 $str = $cgi->escapeHTML($str);
667 if ($opts{'-nbsp'}) {
668 $str =~ s/ / /g;
670 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
674 # Make control characters "printable", using character escape codes (CEC)
677 my %es = ( # character escape codes, aka escape sequences
678 "\t" => '\t', # tab (HT)
679 "\n" => '\n', # line feed (LF)
680 "\r" => '\r', # carrige return (CR)
681 "\f" => '\f', # form feed (FF)
682 "\b" => '\b', # backspace (BS)
683 "\a" => '\a', # alarm (bell) (BEL)
684 "\e" => '\e', # escape (ESC)
685 "\013" => '\v', # vertical tab (VT)
686 "\000" => '\0', # nul character (NUL)
688 my $chr = ( (exists $es{$cntrl})
690 : sprintf('\%03o', ord($cntrl)) );
691 return "<span class=\"cntrl\">$chr</span>";
694 # Alternatively use unicode control pictures codepoints,
695 # Unicode "printable representation" (PR)
698 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
699 return "<span class=\"cntrl\">$chr</span>";
702 # git may return quoted and escaped filenames
708 my %es = ( # character escape codes, aka escape sequences
709 't' => "\t", # tab (HT, TAB)
710 'n' => "\n", # newline (NL)
711 'r' => "\r", # return (CR)
712 'f' => "\f", # form feed (FF)
713 'b' => "\b", # backspace (BS)
714 'a' => "\a", # alarm (bell) (BEL)
715 'e' => "\e", # escape (ESC)
716 'v' => "\013", # vertical tab (VT)
719 if ($seq =~ m/^[0-7]{1,3}$/) {
720 # octal char sequence
721 return chr(oct($seq));
722 } elsif (exists $es{$seq}) {
723 # C escape sequence, aka character escape code
726 # quoted ordinary character
730 if ($str =~ m/^"(.*)"$/) {
733 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
738 # escape tabs (convert tabs to spaces)
742 while ((my $pos = index($line, "\t")) != -1) {
743 if (my $count = (8 - ($pos % 8))) {
744 my $spaces = ' ' x
$count;
745 $line =~ s/\t/$spaces/;
752 sub project_in_list
{
754 my @list = git_get_projects_list
();
755 return @list && scalar(grep { $_->{'path'} eq $project } @list);
758 ## ----------------------------------------------------------------------
759 ## HTML aware string manipulation
764 my $add_len = shift || 10;
766 # allow only $len chars, but don't cut a word if it would fit in $add_len
767 # if it doesn't fit, cut it if it's still longer than the dots we would add
768 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
771 if (length($tail) > 4) {
773 $body =~ s/&[^;]*$//; # remove chopped character entities
778 ## ----------------------------------------------------------------------
779 ## functions returning short strings
781 # CSS class for given age value (in seconds)
787 } elsif ($age < 60*60*2) {
789 } elsif ($age < 60*60*24*2) {
796 # convert age in seconds to "nn units ago" string
801 if ($age > 60*60*24*365*2) {
802 $age_str = (int $age/60/60/24/365);
803 $age_str .= " years ago";
804 } elsif ($age > 60*60*24*(365/12)*2) {
805 $age_str = int $age/60/60/24/(365/12);
806 $age_str .= " months ago";
807 } elsif ($age > 60*60*24*7*2) {
808 $age_str = int $age/60/60/24/7;
809 $age_str .= " weeks ago";
810 } elsif ($age > 60*60*24*2) {
811 $age_str = int $age/60/60/24;
812 $age_str .= " days ago";
813 } elsif ($age > 60*60*2) {
814 $age_str = int $age/60/60;
815 $age_str .= " hours ago";
816 } elsif ($age > 60*2) {
817 $age_str = int $age/60;
818 $age_str .= " min ago";
821 $age_str .= " sec ago";
823 $age_str .= " right now";
828 # convert file mode in octal to symbolic file mode string
830 my $mode = oct shift;
832 if (S_ISDIR
($mode & S_IFMT
)) {
834 } elsif (S_ISLNK
($mode)) {
836 } elsif (S_ISREG
($mode)) {
837 # git cares only about the executable bit
838 if ($mode & S_IXUSR
) {
848 # convert file mode in octal to file type string
852 if ($mode !~ m/^[0-7]+$/) {
858 if (S_ISDIR
($mode & S_IFMT
)) {
860 } elsif (S_ISLNK
($mode)) {
862 } elsif (S_ISREG
($mode)) {
869 # convert file mode in octal to file type description string
873 if ($mode !~ m/^[0-7]+$/) {
879 if (S_ISDIR
($mode & S_IFMT
)) {
881 } elsif (S_ISLNK
($mode)) {
883 } elsif (S_ISREG
($mode)) {
884 if ($mode & S_IXUSR
) {
895 ## ----------------------------------------------------------------------
896 ## functions returning short HTML fragments, or transforming HTML fragments
897 ## which don't belong to other sections
899 # format line of commit message.
900 sub format_log_line_html
{
903 $line = esc_html
($line, -nbsp
=>1);
904 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
907 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
908 -class => "text"}, $hash_text);
909 $line =~ s/$hash_text/$link/;
914 # format marker of refs pointing to given object
915 sub format_ref_marker
{
916 my ($refs, $id) = @_;
919 if (defined $refs->{$id}) {
920 foreach my $ref (@{$refs->{$id}}) {
921 my ($type, $name) = qw();
922 # e.g. tags/v2.6.11 or heads/next
923 if ($ref =~ m!^(.*?)s?/(.*)$!) {
931 $markers .= " <span class=\"$type\" title=\"$ref\">" .
932 esc_html
($name) . "</span>";
937 return ' <span class="refs">'. $markers . '</span>';
943 # format, perhaps shortened and with markers, title line
944 sub format_subject_html
{
945 my ($long, $short, $href, $extra) = @_;
946 $extra = '' unless defined($extra);
948 if (length($short) < length($long)) {
949 return $cgi->a({-href
=> $href, -class => "list subject",
950 -title
=> to_utf8
($long)},
951 esc_html
($short) . $extra);
953 return $cgi->a({-href
=> $href, -class => "list subject"},
954 esc_html
($long) . $extra);
958 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
959 sub format_git_diff_header_line
{
961 my $diffinfo = shift;
962 my ($from, $to) = @_;
964 if ($diffinfo->{'nparents'}) {
966 $line =~ s!^(diff (.*?) )"?.*$!$1!;
968 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
969 esc_path
($to->{'file'}));
970 } else { # file was deleted (no href)
971 $line .= esc_path
($to->{'file'});
975 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
976 if ($from->{'href'}) {
977 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
978 'a/' . esc_path
($from->{'file'}));
979 } else { # file was added (no href)
980 $line .= 'a/' . esc_path
($from->{'file'});
984 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
985 'b/' . esc_path
($to->{'file'}));
986 } else { # file was deleted
987 $line .= 'b/' . esc_path
($to->{'file'});
991 return "<div class=\"diff header\">$line</div>\n";
994 # format extended diff header line, before patch itself
995 sub format_extended_diff_header_line
{
997 my $diffinfo = shift;
998 my ($from, $to) = @_;
1001 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1002 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1003 esc_path
($from->{'file'}));
1005 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1006 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1007 esc_path
($to->{'file'}));
1009 # match single <mode>
1010 if ($line =~ m/\s(\d{6})$/) {
1011 $line .= '<span class="info"> (' .
1012 file_type_long
($1) .
1016 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1017 # can match only for combined diff
1019 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1020 if ($from->{'href'}[$i]) {
1021 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1023 substr($diffinfo->{'from_id'}[$i],0,7));
1028 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1031 if ($to->{'href'}) {
1032 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1033 substr($diffinfo->{'to_id'},0,7));
1038 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1039 # can match only for ordinary diff
1040 my ($from_link, $to_link);
1041 if ($from->{'href'}) {
1042 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1043 substr($diffinfo->{'from_id'},0,7));
1045 $from_link = '0' x
7;
1047 if ($to->{'href'}) {
1048 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1049 substr($diffinfo->{'to_id'},0,7));
1053 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1054 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1057 return $line . "<br/>\n";
1060 # format from-file/to-file diff header
1061 sub format_diff_from_to_header
{
1062 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1067 #assert($line =~ m/^---/) if DEBUG;
1068 # no extra formatting for "^--- /dev/null"
1069 if (! $diffinfo->{'nparents'}) {
1070 # ordinary (single parent) diff
1071 if ($line =~ m!^--- "?a/!) {
1072 if ($from->{'href'}) {
1074 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1075 esc_path
($from->{'file'}));
1078 esc_path
($from->{'file'});
1081 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1084 # combined diff (merge commit)
1085 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1086 if ($from->{'href'}[$i]) {
1088 $cgi->a({-href
=>href
(action
=>"blobdiff",
1089 hash_parent
=>$diffinfo->{'from_id'}[$i],
1090 hash_parent_base
=>$parents[$i],
1091 file_parent
=>$from->{'file'}[$i],
1092 hash
=>$diffinfo->{'to_id'},
1094 file_name
=>$to->{'file'}),
1096 -title
=>"diff" . ($i+1)},
1099 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1100 esc_path
($from->{'file'}[$i]));
1102 $line = '--- /dev/null';
1104 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1109 #assert($line =~ m/^\+\+\+/) if DEBUG;
1110 # no extra formatting for "^+++ /dev/null"
1111 if ($line =~ m!^\+\+\+ "?b/!) {
1112 if ($to->{'href'}) {
1114 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1115 esc_path
($to->{'file'}));
1118 esc_path
($to->{'file'});
1121 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1126 # create note for patch simplified by combined diff
1127 sub format_diff_cc_simplified
{
1128 my ($diffinfo, @parents) = @_;
1131 $result .= "<div class=\"diff header\">" .
1133 if (!is_deleted
($diffinfo)) {
1134 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1136 hash
=>$diffinfo->{'to_id'},
1137 file_name
=>$diffinfo->{'to_file'}),
1139 esc_path
($diffinfo->{'to_file'}));
1141 $result .= esc_path
($diffinfo->{'to_file'});
1143 $result .= "</div>\n" . # class="diff header"
1144 "<div class=\"diff nodifferences\">" .
1146 "</div>\n"; # class="diff nodifferences"
1151 # format patch (diff) line (not to be used for diff headers)
1152 sub format_diff_line
{
1154 my ($from, $to) = @_;
1155 my $diff_class = "";
1159 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1161 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1162 if ($line =~ m/^\@{3}/) {
1163 $diff_class = " chunk_header";
1164 } elsif ($line =~ m/^\\/) {
1165 $diff_class = " incomplete";
1166 } elsif ($prefix =~ tr/+/+/) {
1167 $diff_class = " add";
1168 } elsif ($prefix =~ tr/-/-/) {
1169 $diff_class = " rem";
1172 # assume ordinary diff
1173 my $char = substr($line, 0, 1);
1175 $diff_class = " add";
1176 } elsif ($char eq '-') {
1177 $diff_class = " rem";
1178 } elsif ($char eq '@') {
1179 $diff_class = " chunk_header";
1180 } elsif ($char eq "\\") {
1181 $diff_class = " incomplete";
1184 $line = untabify
($line);
1185 if ($from && $to && $line =~ m/^\@{2} /) {
1186 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1187 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1189 $from_lines = 0 unless defined $from_lines;
1190 $to_lines = 0 unless defined $to_lines;
1192 if ($from->{'href'}) {
1193 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1194 -class=>"list"}, $from_text);
1196 if ($to->{'href'}) {
1197 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1198 -class=>"list"}, $to_text);
1200 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1201 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1202 return "<div class=\"diff$diff_class\">$line</div>\n";
1203 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1204 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1205 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1207 @from_text = split(' ', $ranges);
1208 for (my $i = 0; $i < @from_text; ++$i) {
1209 ($from_start[$i], $from_nlines[$i]) =
1210 (split(',', substr($from_text[$i], 1)), 0);
1213 $to_text = pop @from_text;
1214 $to_start = pop @from_start;
1215 $to_nlines = pop @from_nlines;
1217 $line = "<span class=\"chunk_info\">$prefix ";
1218 for (my $i = 0; $i < @from_text; ++$i) {
1219 if ($from->{'href'}[$i]) {
1220 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1221 -class=>"list"}, $from_text[$i]);
1223 $line .= $from_text[$i];
1227 if ($to->{'href'}) {
1228 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1229 -class=>"list"}, $to_text);
1233 $line .= " $prefix</span>" .
1234 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1235 return "<div class=\"diff$diff_class\">$line</div>\n";
1237 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1240 ## ----------------------------------------------------------------------
1241 ## git utility subroutines, invoking git commands
1243 # returns path to the core git executable and the --git-dir parameter as list
1245 return $GIT, '--git-dir='.$git_dir;
1248 # returns path to the core git executable and the --git-dir parameter as string
1250 return join(' ', git_cmd
());
1253 # get HEAD ref of given project as hash
1254 sub git_get_head_hash
{
1255 my $project = shift;
1256 my $o_git_dir = $git_dir;
1258 $git_dir = "$projectroot/$project";
1259 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1262 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1266 if (defined $o_git_dir) {
1267 $git_dir = $o_git_dir;
1272 # get type of given object
1276 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1278 close $fd or return;
1283 sub git_get_project_config
{
1284 my ($key, $type) = @_;
1286 return unless ($key);
1287 $key =~ s/^gitweb\.//;
1288 return if ($key =~ m/\W/);
1290 my @x = (git_cmd
(), 'config');
1291 if (defined $type) { push @x, $type; }
1293 push @x, "gitweb.$key";
1299 # get hash of given path at given ref
1300 sub git_get_hash_by_path
{
1302 my $path = shift || return undef;
1307 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1308 or die_error
(undef, "Open git-ls-tree failed");
1310 close $fd or return undef;
1312 if (!defined $line) {
1313 # there is no tree or hash given by $path at $base
1317 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1318 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1319 if (defined $type && $type ne $2) {
1320 # type doesn't match
1326 # get path of entry with given hash at given tree-ish (ref)
1327 # used to get 'from' filename for combined diff (merge commit) for renames
1328 sub git_get_path_by_hash
{
1329 my $base = shift || return;
1330 my $hash = shift || return;
1334 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1336 while (my $line = <$fd>) {
1339 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1340 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1341 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1350 ## ......................................................................
1351 ## git utility functions, directly accessing git repository
1353 sub git_get_project_description
{
1356 open my $fd, "$projectroot/$path/description" or return undef;
1359 if (defined $descr) {
1365 sub git_get_project_url_list
{
1368 open my $fd, "$projectroot/$path/cloneurl" or return;
1369 my @git_project_url_list = map { chomp; $_ } <$fd>;
1372 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1375 sub git_get_projects_list
{
1380 $filter =~ s/\.git$//;
1382 my ($check_forks) = gitweb_check_feature
('forks');
1384 if (-d
$projects_list) {
1385 # search in directory
1386 my $dir = $projects_list . ($filter ? "/$filter" : '');
1387 # remove the trailing "/"
1389 my $pfxlen = length("$dir");
1392 follow_fast
=> 1, # follow symbolic links
1393 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1395 # skip project-list toplevel, if we get it.
1396 return if (m!^[/.]$!);
1397 # only directories can be git repositories
1398 return unless (-d
$_);
1400 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1401 # we check related file in $projectroot
1402 if ($check_forks and $subdir =~ m
#/.#) {
1403 $File::Find
::prune
= 1;
1404 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1405 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1406 $File::Find
::prune
= 1;
1411 } elsif (-f
$projects_list) {
1412 # read from file(url-encoded):
1413 # 'git%2Fgit.git Linus+Torvalds'
1414 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1415 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1417 open my ($fd), $projects_list or return;
1419 while (my $line = <$fd>) {
1421 my ($path, $owner) = split ' ', $line;
1422 $path = unescape
($path);
1423 $owner = unescape
($owner);
1424 if (!defined $path) {
1427 if ($filter ne '') {
1428 # looking for forks;
1429 my $pfx = substr($path, 0, length($filter));
1430 if ($pfx ne $filter) {
1433 my $sfx = substr($path, length($filter));
1434 if ($sfx !~ /^\/.*\
.git
$/) {
1437 } elsif ($check_forks) {
1439 foreach my $filter (keys %paths) {
1440 # looking for forks;
1441 my $pfx = substr($path, 0, length($filter));
1442 if ($pfx ne $filter) {
1445 my $sfx = substr($path, length($filter));
1446 if ($sfx !~ /^\/.*\
.git
$/) {
1449 # is a fork, don't include it in
1454 if (check_export_ok
("$projectroot/$path")) {
1457 owner
=> to_utf8
($owner),
1460 (my $forks_path = $path) =~ s/\.git$//;
1461 $paths{$forks_path}++;
1469 our $gitweb_project_owner = undef;
1470 sub git_get_project_list_from_file
{
1472 return if (defined $gitweb_project_owner);
1474 $gitweb_project_owner = {};
1475 # read from file (url-encoded):
1476 # 'git%2Fgit.git Linus+Torvalds'
1477 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1478 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1479 if (-f
$projects_list) {
1480 open (my $fd , $projects_list);
1481 while (my $line = <$fd>) {
1483 my ($pr, $ow) = split ' ', $line;
1484 $pr = unescape
($pr);
1485 $ow = unescape
($ow);
1486 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1492 sub git_get_project_owner
{
1493 my $project = shift;
1496 return undef unless $project;
1498 if (!defined $gitweb_project_owner) {
1499 git_get_project_list_from_file
();
1502 if (exists $gitweb_project_owner->{$project}) {
1503 $owner = $gitweb_project_owner->{$project};
1505 if (!defined $owner) {
1506 $owner = get_file_owner
("$projectroot/$project");
1512 sub git_get_last_activity
{
1516 $git_dir = "$projectroot/$path";
1517 open($fd, "-|", git_cmd
(), 'for-each-ref',
1518 '--format=%(committer)',
1519 '--sort=-committerdate',
1521 'refs/heads') or return;
1522 my $most_recent = <$fd>;
1523 close $fd or return;
1524 if (defined $most_recent &&
1525 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1527 my $age = time - $timestamp;
1528 return ($age, age_string
($age));
1532 sub git_get_references
{
1533 my $type = shift || "";
1535 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1536 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1537 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1538 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1541 while (my $line = <$fd>) {
1543 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1544 if (defined $refs{$1}) {
1545 push @{$refs{$1}}, $2;
1551 close $fd or return;
1555 sub git_get_rev_name_tags
{
1556 my $hash = shift || return undef;
1558 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1560 my $name_rev = <$fd>;
1563 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1566 # catches also '$hash undefined' output
1571 ## ----------------------------------------------------------------------
1572 ## parse to hash functions
1576 my $tz = shift || "-0000";
1579 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1580 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1581 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1582 $date{'hour'} = $hour;
1583 $date{'minute'} = $min;
1584 $date{'mday'} = $mday;
1585 $date{'day'} = $days[$wday];
1586 $date{'month'} = $months[$mon];
1587 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1588 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1589 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1590 $mday, $months[$mon], $hour ,$min;
1591 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1592 1900+$year, $mon, $mday, $hour ,$min, $sec;
1594 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1595 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1596 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1597 $date{'hour_local'} = $hour;
1598 $date{'minute_local'} = $min;
1599 $date{'tz_local'} = $tz;
1600 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1601 1900+$year, $mon+1, $mday,
1602 $hour, $min, $sec, $tz);
1611 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1612 $tag{'id'} = $tag_id;
1613 while (my $line = <$fd>) {
1615 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1616 $tag{'object'} = $1;
1617 } elsif ($line =~ m/^type (.+)$/) {
1619 } elsif ($line =~ m/^tag (.+)$/) {
1621 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1622 $tag{'author'} = $1;
1625 } elsif ($line =~ m/--BEGIN/) {
1626 push @comment, $line;
1628 } elsif ($line eq "") {
1632 push @comment, <$fd>;
1633 $tag{'comment'} = \
@comment;
1634 close $fd or return;
1635 if (!defined $tag{'name'}) {
1641 sub parse_commit_text
{
1642 my ($commit_text, $withparents) = @_;
1643 my @commit_lines = split '\n', $commit_text;
1646 pop @commit_lines; # Remove '\0'
1648 if (! @commit_lines) {
1652 my $header = shift @commit_lines;
1653 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1656 ($co{'id'}, my @parents) = split ' ', $header;
1657 while (my $line = shift @commit_lines) {
1658 last if $line eq "\n";
1659 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1661 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1663 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1665 $co{'author_epoch'} = $2;
1666 $co{'author_tz'} = $3;
1667 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1668 $co{'author_name'} = $1;
1669 $co{'author_email'} = $2;
1671 $co{'author_name'} = $co{'author'};
1673 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1674 $co{'committer'} = $1;
1675 $co{'committer_epoch'} = $2;
1676 $co{'committer_tz'} = $3;
1677 $co{'committer_name'} = $co{'committer'};
1678 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1679 $co{'committer_name'} = $1;
1680 $co{'committer_email'} = $2;
1682 $co{'committer_name'} = $co{'committer'};
1686 if (!defined $co{'tree'}) {
1689 $co{'parents'} = \
@parents;
1690 $co{'parent'} = $parents[0];
1692 foreach my $title (@commit_lines) {
1695 $co{'title'} = chop_str
($title, 80, 5);
1696 # remove leading stuff of merges to make the interesting part visible
1697 if (length($title) > 50) {
1698 $title =~ s/^Automatic //;
1699 $title =~ s/^merge (of|with) /Merge ... /i;
1700 if (length($title) > 50) {
1701 $title =~ s/(http|rsync):\/\///;
1703 if (length($title) > 50) {
1704 $title =~ s/(master|www|rsync)\.//;
1706 if (length($title) > 50) {
1707 $title =~ s/kernel.org:?//;
1709 if (length($title) > 50) {
1710 $title =~ s/\/pub\/scm//;
1713 $co{'title_short'} = chop_str
($title, 50, 5);
1717 if ($co{'title'} eq "") {
1718 $co{'title'} = $co{'title_short'} = '(no commit message)';
1720 # remove added spaces
1721 foreach my $line (@commit_lines) {
1724 $co{'comment'} = \
@commit_lines;
1726 my $age = time - $co{'committer_epoch'};
1728 $co{'age_string'} = age_string
($age);
1729 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1730 if ($age > 60*60*24*7*2) {
1731 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1732 $co{'age_string_age'} = $co{'age_string'};
1734 $co{'age_string_date'} = $co{'age_string'};
1735 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1741 my ($commit_id) = @_;
1746 open my $fd, "-|", git_cmd
(), "rev-list",
1752 or die_error
(undef, "Open git-rev-list failed");
1753 %co = parse_commit_text
(<$fd>, 1);
1760 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1768 open my $fd, "-|", git_cmd
(), "rev-list",
1770 ($arg ? ($arg) : ()),
1771 ("--max-count=" . $maxcount),
1772 ("--skip=" . $skip),
1775 ($filename ? ($filename) : ())
1776 or die_error
(undef, "Open git-rev-list failed");
1777 while (my $line = <$fd>) {
1778 my %co = parse_commit_text
($line);
1783 return wantarray ? @cos : \
@cos;
1786 # parse ref from ref_file, given by ref_id, with given type
1788 my $ref_file = shift;
1790 my $type = shift || git_get_type
($ref_id);
1793 $ref_item{'type'} = $type;
1794 $ref_item{'id'} = $ref_id;
1795 $ref_item{'epoch'} = 0;
1796 $ref_item{'age'} = "unknown";
1797 if ($type eq "tag") {
1798 my %tag = parse_tag
($ref_id);
1799 $ref_item{'comment'} = $tag{'comment'};
1800 if ($tag{'type'} eq "commit") {
1801 my %co = parse_commit
($tag{'object'});
1802 $ref_item{'epoch'} = $co{'committer_epoch'};
1803 $ref_item{'age'} = $co{'age_string'};
1804 } elsif (defined($tag{'epoch'})) {
1805 my $age = time - $tag{'epoch'};
1806 $ref_item{'epoch'} = $tag{'epoch'};
1807 $ref_item{'age'} = age_string
($age);
1809 $ref_item{'reftype'} = $tag{'type'};
1810 $ref_item{'name'} = $tag{'name'};
1811 $ref_item{'refid'} = $tag{'object'};
1812 } elsif ($type eq "commit"){
1813 my %co = parse_commit
($ref_id);
1814 $ref_item{'reftype'} = "commit";
1815 $ref_item{'name'} = $ref_file;
1816 $ref_item{'title'} = $co{'title'};
1817 $ref_item{'refid'} = $ref_id;
1818 $ref_item{'epoch'} = $co{'committer_epoch'};
1819 $ref_item{'age'} = $co{'age_string'};
1821 $ref_item{'reftype'} = $type;
1822 $ref_item{'name'} = $ref_file;
1823 $ref_item{'refid'} = $ref_id;
1829 # parse line of git-diff-tree "raw" output
1830 sub parse_difftree_raw_line
{
1834 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1835 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1836 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1837 $res{'from_mode'} = $1;
1838 $res{'to_mode'} = $2;
1839 $res{'from_id'} = $3;
1841 $res{'status'} = $5;
1842 $res{'similarity'} = $6;
1843 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1844 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1846 $res{'file'} = unquote
($7);
1849 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1850 # combined diff (for merge commit)
1851 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1852 $res{'nparents'} = length($1);
1853 $res{'from_mode'} = [ split(' ', $2) ];
1854 $res{'to_mode'} = pop @{$res{'from_mode'}};
1855 $res{'from_id'} = [ split(' ', $3) ];
1856 $res{'to_id'} = pop @{$res{'from_id'}};
1857 $res{'status'} = [ split('', $4) ];
1858 $res{'to_file'} = unquote
($5);
1860 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1861 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1862 $res{'commit'} = $1;
1865 return wantarray ? %res : \
%res;
1868 # parse line of git-ls-tree output
1869 sub parse_ls_tree_line
($;%) {
1874 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1875 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1883 $res{'name'} = unquote
($4);
1886 return wantarray ? %res : \
%res;
1889 # generates _two_ hashes, references to which are passed as 2 and 3 argument
1890 sub parse_from_to_diffinfo
{
1891 my ($diffinfo, $from, $to, @parents) = @_;
1893 if ($diffinfo->{'nparents'}) {
1895 $from->{'file'} = [];
1896 $from->{'href'} = [];
1897 fill_from_file_info
($diffinfo, @parents)
1898 unless exists $diffinfo->{'from_file'};
1899 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1900 $from->{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
1901 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
1902 $from->{'href'}[$i] = href
(action
=>"blob",
1903 hash_base
=>$parents[$i],
1904 hash
=>$diffinfo->{'from_id'}[$i],
1905 file_name
=>$from->{'file'}[$i]);
1907 $from->{'href'}[$i] = undef;
1911 $from->{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
1912 if ($diffinfo->{'status'} ne "A") { # not new (added) file
1913 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
1914 hash
=>$diffinfo->{'from_id'},
1915 file_name
=>$from->{'file'});
1917 delete $from->{'href'};
1921 $to->{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
1922 if (!is_deleted
($diffinfo)) { # file exists in result
1923 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
1924 hash
=>$diffinfo->{'to_id'},
1925 file_name
=>$to->{'file'});
1927 delete $to->{'href'};
1931 ## ......................................................................
1932 ## parse to array of hashes functions
1934 sub git_get_heads_list
{
1938 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1939 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1940 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1943 while (my $line = <$fd>) {
1947 my ($refinfo, $committerinfo) = split(/\0/, $line);
1948 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1949 my ($committer, $epoch, $tz) =
1950 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1951 $name =~ s!^refs/heads/!!;
1953 $ref_item{'name'} = $name;
1954 $ref_item{'id'} = $hash;
1955 $ref_item{'title'} = $title || '(no commit message)';
1956 $ref_item{'epoch'} = $epoch;
1958 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1960 $ref_item{'age'} = "unknown";
1963 push @headslist, \
%ref_item;
1967 return wantarray ? @headslist : \
@headslist;
1970 sub git_get_tags_list
{
1974 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1975 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1976 '--format=%(objectname) %(objecttype) %(refname) '.
1977 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1980 while (my $line = <$fd>) {
1984 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1985 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1986 my ($creator, $epoch, $tz) =
1987 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1988 $name =~ s!^refs/tags/!!;
1990 $ref_item{'type'} = $type;
1991 $ref_item{'id'} = $id;
1992 $ref_item{'name'} = $name;
1993 if ($type eq "tag") {
1994 $ref_item{'subject'} = $title;
1995 $ref_item{'reftype'} = $reftype;
1996 $ref_item{'refid'} = $refid;
1998 $ref_item{'reftype'} = $type;
1999 $ref_item{'refid'} = $id;
2002 if ($type eq "tag" || $type eq "commit") {
2003 $ref_item{'epoch'} = $epoch;
2005 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2007 $ref_item{'age'} = "unknown";
2011 push @tagslist, \
%ref_item;
2015 return wantarray ? @tagslist : \
@tagslist;
2018 ## ----------------------------------------------------------------------
2019 ## filesystem-related functions
2021 sub get_file_owner
{
2024 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2025 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2026 if (!defined $gcos) {
2030 $owner =~ s/[,;].*$//;
2031 return to_utf8
($owner);
2034 ## ......................................................................
2035 ## mimetype related functions
2037 sub mimetype_guess_file
{
2038 my $filename = shift;
2039 my $mimemap = shift;
2040 -r
$mimemap or return undef;
2043 open(MIME
, $mimemap) or return undef;
2045 next if m/^#/; # skip comments
2046 my ($mime, $exts) = split(/\t+/);
2047 if (defined $exts) {
2048 my @exts = split(/\s+/, $exts);
2049 foreach my $ext (@exts) {
2050 $mimemap{$ext} = $mime;
2056 $filename =~ /\.([^.]*)$/;
2057 return $mimemap{$1};
2060 sub mimetype_guess
{
2061 my $filename = shift;
2063 $filename =~ /\./ or return undef;
2065 if ($mimetypes_file) {
2066 my $file = $mimetypes_file;
2067 if ($file !~ m!^/!) { # if it is relative path
2068 # it is relative to project
2069 $file = "$projectroot/$project/$file";
2071 $mime = mimetype_guess_file
($filename, $file);
2073 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2079 my $filename = shift;
2082 my $mime = mimetype_guess
($filename);
2083 $mime and return $mime;
2087 return $default_blob_plain_mimetype unless $fd;
2090 return 'text/plain' .
2091 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
2092 } elsif (! $filename) {
2093 return 'application/octet-stream';
2094 } elsif ($filename =~ m/\.png$/i) {
2096 } elsif ($filename =~ m/\.gif$/i) {
2098 } elsif ($filename =~ m/\.jpe?g$/i) {
2099 return 'image/jpeg';
2101 return 'application/octet-stream';
2105 ## ======================================================================
2106 ## functions printing HTML: header, footer, error page
2108 sub git_header_html
{
2109 my $status = shift || "200 OK";
2110 my $expires = shift;
2112 my $title = "$site_name";
2113 if (defined $project) {
2114 $title .= " - " . to_utf8
($project);
2115 if (defined $action) {
2116 $title .= "/$action";
2117 if (defined $file_name) {
2118 $title .= " - " . esc_path
($file_name);
2119 if ($action eq "tree" && $file_name !~ m
|/$|) {
2126 # require explicit support from the UA if we are to send the page as
2127 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2128 # we have to do this because MSIE sometimes globs '*/*', pretending to
2129 # support xhtml+xml but choking when it gets what it asked for.
2130 if (defined $cgi->http('HTTP_ACCEPT') &&
2131 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2132 $cgi->Accept('application/xhtml+xml') != 0) {
2133 $content_type = 'application/xhtml+xml';
2135 $content_type = 'text/html';
2137 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2138 -status
=> $status, -expires
=> $expires);
2139 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2141 <?xml version="1.0" encoding="utf-8"?>
2142 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2143 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2144 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2145 <!-- git core binaries version $git_version -->
2147 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2148 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2149 <meta name="robots" content="index, nofollow"/>
2150 <title>$title</title>
2152 # print out each stylesheet that exist
2153 if (defined $stylesheet) {
2154 #provides backwards capability for those people who define style sheet in a config file
2155 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2157 foreach my $stylesheet (@stylesheets) {
2158 next unless $stylesheet;
2159 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2162 if (defined $project) {
2163 printf('<link rel="alternate" title="%s log RSS feed" '.
2164 'href="%s" type="application/rss+xml" />'."\n",
2165 esc_param
($project), href
(action
=>"rss"));
2166 printf('<link rel="alternate" title="%s log Atom feed" '.
2167 'href="%s" type="application/atom+xml" />'."\n",
2168 esc_param
($project), href
(action
=>"atom"));
2170 printf('<link rel="alternate" title="%s projects list" '.
2171 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2172 $site_name, href
(project
=>undef, action
=>"project_index"));
2173 printf('<link rel="alternate" title="%s projects feeds" '.
2174 'href="%s" type="text/x-opml"/>'."\n",
2175 $site_name, href
(project
=>undef, action
=>"opml"));
2177 if (defined $favicon) {
2178 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
2184 if (-f
$site_header) {
2185 open (my $fd, $site_header);
2190 print "<div class=\"page_header\">\n" .
2191 $cgi->a({-href
=> esc_url
($logo_url),
2192 -title
=> $logo_label},
2193 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2194 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2195 if (defined $project) {
2196 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2197 if (defined $action) {
2204 my ($have_search) = gitweb_check_feature
('search');
2205 if ((defined $project) && ($have_search)) {
2206 if (!defined $searchtext) {
2210 if (defined $hash_base) {
2211 $search_hash = $hash_base;
2212 } elsif (defined $hash) {
2213 $search_hash = $hash;
2215 $search_hash = "HEAD";
2217 $cgi->param("a", "search");
2218 $cgi->param("h", $search_hash);
2219 $cgi->param("p", $project);
2220 print $cgi->startform(-method => "get", -action
=> $my_uri) .
2221 "<div class=\"search\">\n" .
2222 $cgi->hidden(-name
=> "p") . "\n" .
2223 $cgi->hidden(-name
=> "a") . "\n" .
2224 $cgi->hidden(-name
=> "h") . "\n" .
2225 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2226 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2227 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2229 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2231 $cgi->end_form() . "\n";
2235 sub git_footer_html
{
2236 print "<div class=\"page_footer\">\n";
2237 if (defined $project) {
2238 my $descr = git_get_project_description
($project);
2239 if (defined $descr) {
2240 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2242 print $cgi->a({-href
=> href
(action
=>"rss"),
2243 -class => "rss_logo"}, "RSS") . " ";
2244 print $cgi->a({-href
=> href
(action
=>"atom"),
2245 -class => "rss_logo"}, "Atom") . "\n";
2247 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2248 -class => "rss_logo"}, "OPML") . " ";
2249 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2250 -class => "rss_logo"}, "TXT") . "\n";
2254 if (-f
$site_footer) {
2255 open (my $fd, $site_footer);
2265 my $status = shift || "403 Forbidden";
2266 my $error = shift || "Malformed query, file missing or permission denied";
2268 git_header_html
($status);
2270 <div class="page_body">
2280 ## ----------------------------------------------------------------------
2281 ## functions printing or outputting HTML: navigation
2283 sub git_print_page_nav
{
2284 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2285 $extra = '' if !defined $extra; # pager or formats
2287 my @navs = qw(summary shortlog log commit commitdiff tree);
2289 @navs = grep { $_ ne $suppress } @navs;
2292 my %arg = map { $_ => {action
=>$_} } @navs;
2293 if (defined $head) {
2294 for (qw(commit commitdiff)) {
2295 $arg{$_}{'hash'} = $head;
2297 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2298 for (qw(shortlog log)) {
2299 $arg{$_}{'hash'} = $head;
2303 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2304 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2306 print "<div class=\"page_nav\">\n" .
2308 map { $_ eq $current ?
2309 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2311 print "<br/>\n$extra<br/>\n" .
2315 sub format_paging_nav
{
2316 my ($action, $hash, $head, $page, $nrevs) = @_;
2320 if ($hash ne $head || $page) {
2321 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2323 $paging_nav .= "HEAD";
2327 $paging_nav .= " ⋅ " .
2328 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2329 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2331 $paging_nav .= " ⋅ prev";
2334 if ($nrevs >= (100 * ($page+1)-1)) {
2335 $paging_nav .= " ⋅ " .
2336 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2337 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2339 $paging_nav .= " ⋅ next";
2345 ## ......................................................................
2346 ## functions printing or outputting HTML: div
2348 sub git_print_header_div
{
2349 my ($action, $title, $hash, $hash_base) = @_;
2352 $args{'action'} = $action;
2353 $args{'hash'} = $hash if $hash;
2354 $args{'hash_base'} = $hash_base if $hash_base;
2356 print "<div class=\"header\">\n" .
2357 $cgi->a({-href
=> href
(%args), -class => "title"},
2358 $title ? $title : $action) .
2362 #sub git_print_authorship (\%) {
2363 sub git_print_authorship
{
2366 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2367 print "<div class=\"author_date\">" .
2368 esc_html
($co->{'author_name'}) .
2370 if ($ad{'hour_local'} < 6) {
2371 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2372 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2374 printf(" (%02d:%02d %s)",
2375 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2380 sub git_print_page_path
{
2386 print "<div class=\"page_path\">";
2387 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2388 -title
=> 'tree root'}, to_utf8
("[$project]"));
2390 if (defined $name) {
2391 my @dirname = split '/', $name;
2392 my $basename = pop @dirname;
2395 foreach my $dir (@dirname) {
2396 $fullname .= ($fullname ? '/' : '') . $dir;
2397 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2399 -title
=> $fullname}, esc_path
($dir));
2402 if (defined $type && $type eq 'blob') {
2403 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2405 -title
=> $name}, esc_path
($basename));
2406 } elsif (defined $type && $type eq 'tree') {
2407 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2409 -title
=> $name}, esc_path
($basename));
2412 print esc_path
($basename);
2415 print "<br/></div>\n";
2418 # sub git_print_log (\@;%) {
2419 sub git_print_log
($;%) {
2423 if ($opts{'-remove_title'}) {
2424 # remove title, i.e. first line of log
2427 # remove leading empty lines
2428 while (defined $log->[0] && $log->[0] eq "") {
2435 foreach my $line (@$log) {
2436 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2439 if (! $opts{'-remove_signoff'}) {
2440 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2443 # remove signoff lines
2450 # print only one empty line
2451 # do not print empty line after signoff
2453 next if ($empty || $signoff);
2459 print format_log_line_html
($line) . "<br/>\n";
2462 if ($opts{'-final_empty_line'}) {
2463 # end with single empty line
2464 print "<br/>\n" unless $empty;
2468 # return link target (what link points to)
2469 sub git_get_link_target
{
2474 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2478 $link_target = <$fd>;
2483 return $link_target;
2486 # given link target, and the directory (basedir) the link is in,
2487 # return target of link relative to top directory (top tree);
2488 # return undef if it is not possible (including absolute links).
2489 sub normalize_link_target
{
2490 my ($link_target, $basedir, $hash_base) = @_;
2492 # we can normalize symlink target only if $hash_base is provided
2493 return unless $hash_base;
2495 # absolute symlinks (beginning with '/') cannot be normalized
2496 return if (substr($link_target, 0, 1) eq '/');
2498 # normalize link target to path from top (root) tree (dir)
2501 $path = $basedir . '/' . $link_target;
2503 # we are in top (root) tree (dir)
2504 $path = $link_target;
2507 # remove //, /./, and /../
2509 foreach my $part (split('/', $path)) {
2510 # discard '.' and ''
2511 next if (!$part || $part eq '.');
2513 if ($part eq '..') {
2517 # link leads outside repository (outside top dir)
2521 push @path_parts, $part;
2524 $path = join('/', @path_parts);
2529 # print tree entry (row of git_tree), but without encompassing <tr> element
2530 sub git_print_tree_entry
{
2531 my ($t, $basedir, $hash_base, $have_blame) = @_;
2534 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2536 # The format of a table row is: mode list link. Where mode is
2537 # the mode of the entry, list is the name of the entry, an href,
2538 # and link is the action links of the entry.
2540 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2541 if ($t->{'type'} eq "blob") {
2542 print "<td class=\"list\">" .
2543 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2544 file_name
=>"$basedir$t->{'name'}", %base_key),
2545 -class => "list"}, esc_path
($t->{'name'}));
2546 if (S_ISLNK
(oct $t->{'mode'})) {
2547 my $link_target = git_get_link_target
($t->{'hash'});
2549 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2550 if (defined $norm_target) {
2552 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2553 file_name
=>$norm_target),
2554 -title
=> $norm_target}, esc_path
($link_target));
2556 print " -> " . esc_path
($link_target);
2561 print "<td class=\"link\">";
2562 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2563 file_name
=>"$basedir$t->{'name'}", %base_key)},
2567 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2568 file_name
=>"$basedir$t->{'name'}", %base_key)},
2571 if (defined $hash_base) {
2573 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2574 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2578 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2579 file_name
=>"$basedir$t->{'name'}")},
2583 } elsif ($t->{'type'} eq "tree") {
2584 print "<td class=\"list\">";
2585 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2586 file_name
=>"$basedir$t->{'name'}", %base_key)},
2587 esc_path
($t->{'name'}));
2589 print "<td class=\"link\">";
2590 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2591 file_name
=>"$basedir$t->{'name'}", %base_key)},
2593 if (defined $hash_base) {
2595 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2596 file_name
=>"$basedir$t->{'name'}")},
2603 ## ......................................................................
2604 ## functions printing large fragments of HTML
2606 sub fill_from_file_info
{
2607 my ($diff, @parents) = @_;
2609 $diff->{'from_file'} = [ ];
2610 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2611 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2612 if ($diff->{'status'}[$i] eq 'R' ||
2613 $diff->{'status'}[$i] eq 'C') {
2614 $diff->{'from_file'}[$i] =
2615 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2622 # parameters can be strings, or references to arrays of strings
2626 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @$a == @$b) {
2627 for (my $i = 0; $i < @$a; ++$i) {
2628 return 0 unless ($a->[$i] eq $b->[$i]);
2631 } elsif (!ref($a) && !ref($b)) {
2639 my $diffinfo = shift;
2641 return $diffinfo->{'to_id'} eq ('0' x
40);
2644 sub git_difftree_body
{
2645 my ($difftree, $hash, @parents) = @_;
2646 my ($parent) = $parents[0];
2647 my ($have_blame) = gitweb_check_feature
('blame');
2648 print "<div class=\"list_head\">\n";
2649 if ($#{$difftree} > 10) {
2650 print(($#{$difftree} + 1) . " files changed:\n");
2654 print "<table class=\"" .
2655 (@parents > 1 ? "combined " : "") .
2658 # header only for combined diff in 'commitdiff' view
2659 my $has_header = @parents > 1 && $action eq 'commitdiff';
2662 print "<thead><tr>\n" .
2663 "<th></th><th></th>\n"; # filename, patchN link
2664 for (my $i = 0; $i < @parents; $i++) {
2665 my $par = $parents[$i];
2667 $cgi->a({-href
=> href
(action
=>"commitdiff",
2668 hash
=>$hash, hash_parent
=>$par),
2669 -title
=> 'commitdiff to parent number ' .
2670 ($i+1) . ': ' . substr($par,0,7)},
2674 print "</tr></thead>\n<tbody>\n";
2679 foreach my $line (@{$difftree}) {
2681 if (ref($line) eq "HASH") {
2682 # pre-parsed (or generated by hand)
2685 $diff = parse_difftree_raw_line
($line);
2689 print "<tr class=\"dark\">\n";
2691 print "<tr class=\"light\">\n";
2695 if (exists $diff->{'nparents'}) { # combined diff
2697 fill_from_file_info
($diff, @parents)
2698 unless exists $diff->{'from_file'};
2700 if (!is_deleted
($diff)) {
2701 # file exists in the result (child) commit
2703 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2704 file_name
=>$diff->{'to_file'},
2706 -class => "list"}, esc_path
($diff->{'to_file'})) .
2710 esc_path
($diff->{'to_file'}) .
2714 if ($action eq 'commitdiff') {
2717 print "<td class=\"link\">" .
2718 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2723 my $has_history = 0;
2724 my $not_deleted = 0;
2725 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2726 my $hash_parent = $parents[$i];
2727 my $from_hash = $diff->{'from_id'}[$i];
2728 my $from_path = $diff->{'from_file'}[$i];
2729 my $status = $diff->{'status'}[$i];
2731 $has_history ||= ($status ne 'A');
2732 $not_deleted ||= ($status ne 'D');
2734 if ($status eq 'A') {
2735 print "<td class=\"link\" align=\"right\"> | </td>\n";
2736 } elsif ($status eq 'D') {
2737 print "<td class=\"link\">" .
2738 $cgi->a({-href
=> href
(action
=>"blob",
2741 file_name
=>$from_path)},
2745 if ($diff->{'to_id'} eq $from_hash) {
2746 print "<td class=\"link nochange\">";
2748 print "<td class=\"link\">";
2750 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2751 hash
=>$diff->{'to_id'},
2752 hash_parent
=>$from_hash,
2754 hash_parent_base
=>$hash_parent,
2755 file_name
=>$diff->{'to_file'},
2756 file_parent
=>$from_path)},
2762 print "<td class=\"link\">";
2764 print $cgi->a({-href
=> href
(action
=>"blob",
2765 hash
=>$diff->{'to_id'},
2766 file_name
=>$diff->{'to_file'},
2769 print " | " if ($has_history);
2772 print $cgi->a({-href
=> href
(action
=>"history",
2773 file_name
=>$diff->{'to_file'},
2780 next; # instead of 'else' clause, to avoid extra indent
2782 # else ordinary diff
2784 my ($to_mode_oct, $to_mode_str, $to_file_type);
2785 my ($from_mode_oct, $from_mode_str, $from_file_type);
2786 if ($diff->{'to_mode'} ne ('0' x
6)) {
2787 $to_mode_oct = oct $diff->{'to_mode'};
2788 if (S_ISREG
($to_mode_oct)) { # only for regular file
2789 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2791 $to_file_type = file_type
($diff->{'to_mode'});
2793 if ($diff->{'from_mode'} ne ('0' x
6)) {
2794 $from_mode_oct = oct $diff->{'from_mode'};
2795 if (S_ISREG
($to_mode_oct)) { # only for regular file
2796 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2798 $from_file_type = file_type
($diff->{'from_mode'});
2801 if ($diff->{'status'} eq "A") { # created
2802 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2803 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2804 $mode_chng .= "]</span>";
2806 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2807 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2808 -class => "list"}, esc_path
($diff->{'file'}));
2810 print "<td>$mode_chng</td>\n";
2811 print "<td class=\"link\">";
2812 if ($action eq 'commitdiff') {
2815 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2818 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2819 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2823 } elsif ($diff->{'status'} eq "D") { # deleted
2824 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2826 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2827 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2828 -class => "list"}, esc_path
($diff->{'file'}));
2830 print "<td>$mode_chng</td>\n";
2831 print "<td class=\"link\">";
2832 if ($action eq 'commitdiff') {
2835 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2838 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2839 hash_base
=>$parent, file_name
=>$diff->{'file'})},
2842 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2843 file_name
=>$diff->{'file'})},
2846 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2847 file_name
=>$diff->{'file'})},
2851 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2852 my $mode_chnge = "";
2853 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2854 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2855 if ($from_file_type ne $to_file_type) {
2856 $mode_chnge .= " from $from_file_type to $to_file_type";
2858 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2859 if ($from_mode_str && $to_mode_str) {
2860 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2861 } elsif ($to_mode_str) {
2862 $mode_chnge .= " mode: $to_mode_str";
2865 $mode_chnge .= "]</span>\n";
2868 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2869 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2870 -class => "list"}, esc_path
($diff->{'file'}));
2872 print "<td>$mode_chnge</td>\n";
2873 print "<td class=\"link\">";
2874 if ($action eq 'commitdiff') {
2877 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2879 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2880 # "commit" view and modified file (not onlu mode changed)
2881 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2882 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2883 hash_base
=>$hash, hash_parent_base
=>$parent,
2884 file_name
=>$diff->{'file'})},
2888 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2889 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2892 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2893 file_name
=>$diff->{'file'})},
2896 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2897 file_name
=>$diff->{'file'})},
2901 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
2902 my %status_name = ('R' => 'moved', 'C' => 'copied');
2903 my $nstatus = $status_name{$diff->{'status'}};
2905 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2906 # mode also for directories, so we cannot use $to_mode_str
2907 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2910 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2911 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
2912 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
2913 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2914 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2915 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
2916 -class => "list"}, esc_path
($diff->{'from_file'})) .
2917 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2918 "<td class=\"link\">";
2919 if ($action eq 'commitdiff') {
2922 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2924 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2925 # "commit" view and modified file (not only pure rename or copy)
2926 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2927 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2928 hash_base
=>$hash, hash_parent_base
=>$parent,
2929 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
2933 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2934 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
2937 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2938 file_name
=>$diff->{'to_file'})},
2941 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2942 file_name
=>$diff->{'to_file'})},
2946 } # we should not encounter Unmerged (U) or Unknown (X) status
2949 print "</tbody>" if $has_header;
2953 sub git_patchset_body
{
2954 my ($fd, $difftree, $hash, @hash_parents) = @_;
2955 my ($hash_parent) = $hash_parents[0];
2958 my $patch_number = 0;
2963 print "<div class=\"patchset\">\n";
2965 # skip to first patch
2966 while ($patch_line = <$fd>) {
2969 last if ($patch_line =~ m/^diff /);
2973 while ($patch_line) {
2975 my ($from_id, $to_id);
2978 #assert($patch_line =~ m/^diff /) if DEBUG;
2979 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2981 push @diff_header, $patch_line;
2983 # extended diff header
2985 while ($patch_line = <$fd>) {
2988 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2990 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2993 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2994 $from_id = [ split(',', $1) ];
2998 push @diff_header, $patch_line;
3000 my $last_patch_line = $patch_line;
3002 # check if current patch belong to current raw line
3003 # and parse raw git-diff line if needed
3004 if (defined $diffinfo &&
3005 defined $from_id && defined $to_id &&
3006 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
3007 $diffinfo->{'to_id'} eq $to_id) {
3008 # this is continuation of a split patch
3009 print "<div class=\"patch cont\">\n";
3011 # advance raw git-diff output if needed
3012 $patch_idx++ if defined $diffinfo;
3014 # compact combined diff output can have some patches skipped
3015 # find which patch (using pathname of result) we are at now
3017 if ($diff_header[0] =~ m!^diff --cc "?(.*)"?$!) {
3022 # read and prepare patch information
3023 if (ref($difftree->[$patch_idx]) eq "HASH") {
3024 # pre-parsed (or generated by hand)
3025 $diffinfo = $difftree->[$patch_idx];
3027 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
3030 # check if current raw line has no patch (it got simplified)
3031 if (defined $to_name && $to_name ne $diffinfo->{'to_file'}) {
3032 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3033 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3034 "</div>\n"; # class="patch"
3039 } until (!defined $to_name || $to_name eq $diffinfo->{'to_file'} ||
3040 $patch_idx > $#$difftree);
3041 # modifies %from, %to hashes
3042 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3043 if ($diffinfo->{'nparents'}) {
3047 fill_from_file_info
($diffinfo, @hash_parents)
3048 unless exists $diffinfo->{'from_file'};
3049 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
3050 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
3051 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
3052 $from{'href'}[$i] = href
(action
=>"blob",
3053 hash_base
=>$hash_parents[$i],
3054 hash
=>$diffinfo->{'from_id'}[$i],
3055 file_name
=>$from{'file'}[$i]);
3057 $from{'href'}[$i] = undef;
3061 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
3062 if ($diffinfo->{'status'} ne "A") { # not new (added) file
3063 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
3064 hash
=>$diffinfo->{'from_id'},
3065 file_name
=>$from{'file'});
3067 delete $from{'href'};
3071 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
3072 if (!is_deleted
($diffinfo)) { # file exists in result
3073 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
3074 hash
=>$diffinfo->{'to_id'},
3075 file_name
=>$to{'file'});
3079 # this is first patch for raw difftree line with $patch_idx index
3080 # we index @$difftree array from 0, but number patches from 1
3081 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3084 # print "git diff" header
3085 $patch_line = shift @diff_header;
3086 print format_git_diff_header_line
($patch_line, $diffinfo,
3089 # print extended diff header
3090 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
3092 foreach $patch_line (@diff_header) {
3093 print format_extended_diff_header_line
($patch_line, $diffinfo,
3096 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
3098 # from-file/to-file diff header
3099 $patch_line = $last_patch_line;
3100 if (! $patch_line) {
3101 print "</div>\n"; # class="patch"
3104 next PATCH
if ($patch_line =~ m/^diff /);
3105 #assert($patch_line =~ m/^---/) if DEBUG;
3106 #assert($patch_line eq $last_patch_line) if DEBUG;
3108 $patch_line = <$fd>;
3110 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3112 print format_diff_from_to_header
($last_patch_line, $patch_line,
3113 $diffinfo, \
%from, \
%to,
3118 while ($patch_line = <$fd>) {
3121 next PATCH
if ($patch_line =~ m/^diff /);
3123 print format_diff_line
($patch_line, \
%from, \
%to);
3127 print "</div>\n"; # class="patch"
3130 # for compact combined (--cc) format, with chunk and patch simpliciaction
3131 # patchset might be empty, but there might be unprocessed raw lines
3132 for ($patch_idx++ if $patch_number > 0;
3133 $patch_idx < @$difftree;
3135 # read and prepare patch information
3136 if (ref($difftree->[$patch_idx]) eq "HASH") {
3137 # pre-parsed (or generated by hand)
3138 $diffinfo = $difftree->[$patch_idx];
3140 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
3143 # generate anchor for "patch" links in difftree / whatchanged part
3144 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3145 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3146 "</div>\n"; # class="patch"
3151 if ($patch_number == 0) {
3152 if (@hash_parents > 1) {
3153 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3155 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3159 print "</div>\n"; # class="patchset"
3162 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3164 sub git_project_list_body
{
3165 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3167 my ($check_forks) = gitweb_check_feature
('forks');
3170 foreach my $pr (@$projlist) {
3171 my (@aa) = git_get_last_activity
($pr->{'path'});
3175 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3176 if (!defined $pr->{'descr'}) {
3177 my $descr = git_get_project_description
($pr->{'path'}) || "";
3178 $pr->{'descr_long'} = to_utf8
($descr);
3179 $pr->{'descr'} = chop_str
($descr, 25, 5);
3181 if (!defined $pr->{'owner'}) {
3182 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
3185 my $pname = $pr->{'path'};
3186 if (($pname =~ s/\.git$//) &&
3187 ($pname !~ /\/$/) &&
3188 (-d
"$projectroot/$pname")) {
3189 $pr->{'forks'} = "-d $projectroot/$pname";
3195 push @projects, $pr;
3198 $order ||= $default_projects_order;
3199 $from = 0 unless defined $from;
3200 $to = $#projects if (!defined $to || $#projects < $to);
3202 print "<table class=\"project_list\">\n";
3203 unless ($no_header) {
3206 print "<th></th>\n";
3208 if ($order eq "project") {
3209 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3210 print "<th>Project</th>\n";
3213 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3214 -class => "header"}, "Project") .
3217 if ($order eq "descr") {
3218 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3219 print "<th>Description</th>\n";
3222 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3223 -class => "header"}, "Description") .
3226 if ($order eq "owner") {
3227 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3228 print "<th>Owner</th>\n";
3231 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3232 -class => "header"}, "Owner") .
3235 if ($order eq "age") {
3236 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3237 print "<th>Last Change</th>\n";
3240 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3241 -class => "header"}, "Last Change") .
3244 print "<th></th>\n" .
3248 for (my $i = $from; $i <= $to; $i++) {
3249 my $pr = $projects[$i];
3251 print "<tr class=\"dark\">\n";
3253 print "<tr class=\"light\">\n";
3258 if ($pr->{'forks'}) {
3259 print "<!-- $pr->{'forks'} -->\n";
3260 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3264 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3265 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3266 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3267 -class => "list", -title
=> $pr->{'descr_long'}},
3268 esc_html
($pr->{'descr'})) . "</td>\n" .
3269 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
3270 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3271 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3272 "<td class=\"link\">" .
3273 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3274 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3275 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3276 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3277 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3281 if (defined $extra) {
3284 print "<td></td>\n";
3286 print "<td colspan=\"5\">$extra</td>\n" .
3292 sub git_shortlog_body
{
3293 # uses global variable $project
3294 my ($commitlist, $from, $to, $refs, $extra) = @_;
3296 my $have_snapshot = gitweb_have_snapshot
();
3298 $from = 0 unless defined $from;
3299 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3301 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3303 for (my $i = $from; $i <= $to; $i++) {
3304 my %co = %{$commitlist->[$i]};
3305 my $commit = $co{'id'};
3306 my $ref = format_ref_marker
($refs, $commit);
3308 print "<tr class=\"dark\">\n";
3310 print "<tr class=\"light\">\n";
3313 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3314 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3315 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3317 print format_subject_html
($co{'title'}, $co{'title_short'},
3318 href
(action
=>"commit", hash
=>$commit), $ref);
3320 "<td class=\"link\">" .
3321 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3322 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3323 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3324 if ($have_snapshot) {
3325 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
3330 if (defined $extra) {
3332 "<td colspan=\"4\">$extra</td>\n" .
3338 sub git_history_body
{
3339 # Warning: assumes constant type (blob or tree) during history
3340 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3342 $from = 0 unless defined $from;
3343 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3345 print "<table class=\"history\" cellspacing=\"0\">\n";
3347 for (my $i = $from; $i <= $to; $i++) {
3348 my %co = %{$commitlist->[$i]};
3352 my $commit = $co{'id'};
3354 my $ref = format_ref_marker
($refs, $commit);
3357 print "<tr class=\"dark\">\n";
3359 print "<tr class=\"light\">\n";
3362 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3363 # shortlog uses chop_str($co{'author_name'}, 10)
3364 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3366 # originally git_history used chop_str($co{'title'}, 50)
3367 print format_subject_html
($co{'title'}, $co{'title_short'},
3368 href
(action
=>"commit", hash
=>$commit), $ref);
3370 "<td class=\"link\">" .
3371 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3372 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3374 if ($ftype eq 'blob') {
3375 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3376 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3377 if (defined $blob_current && defined $blob_parent &&
3378 $blob_current ne $blob_parent) {
3380 $cgi->a({-href
=> href
(action
=>"blobdiff",
3381 hash
=>$blob_current, hash_parent
=>$blob_parent,
3382 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3383 file_name
=>$file_name)},
3390 if (defined $extra) {
3392 "<td colspan=\"4\">$extra</td>\n" .
3399 # uses global variable $project
3400 my ($taglist, $from, $to, $extra) = @_;
3401 $from = 0 unless defined $from;
3402 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3404 print "<table class=\"tags\" cellspacing=\"0\">\n";
3406 for (my $i = $from; $i <= $to; $i++) {
3407 my $entry = $taglist->[$i];
3409 my $comment = $tag{'subject'};
3411 if (defined $comment) {
3412 $comment_short = chop_str
($comment, 30, 5);
3415 print "<tr class=\"dark\">\n";
3417 print "<tr class=\"light\">\n";
3420 if (defined $tag{'age'}) {
3421 print "<td><i>$tag{'age'}</i></td>\n";
3423 print "<td></td>\n";
3426 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3427 -class => "list name"}, esc_html
($tag{'name'})) .
3430 if (defined $comment) {
3431 print format_subject_html
($comment, $comment_short,
3432 href
(action
=>"tag", hash
=>$tag{'id'}));
3435 "<td class=\"selflink\">";
3436 if ($tag{'type'} eq "tag") {
3437 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3442 "<td class=\"link\">" . " | " .
3443 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3444 if ($tag{'reftype'} eq "commit") {
3445 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3446 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3447 } elsif ($tag{'reftype'} eq "blob") {
3448 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3453 if (defined $extra) {
3455 "<td colspan=\"5\">$extra</td>\n" .
3461 sub git_heads_body
{
3462 # uses global variable $project
3463 my ($headlist, $head, $from, $to, $extra) = @_;
3464 $from = 0 unless defined $from;
3465 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3467 print "<table class=\"heads\" cellspacing=\"0\">\n";
3469 for (my $i = $from; $i <= $to; $i++) {
3470 my $entry = $headlist->[$i];
3472 my $curr = $ref{'id'} eq $head;
3474 print "<tr class=\"dark\">\n";
3476 print "<tr class=\"light\">\n";
3479 print "<td><i>$ref{'age'}</i></td>\n" .
3480 ($curr ? "<td class=\"current_head\">" : "<td>") .
3481 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3482 -class => "list name"},esc_html
($ref{'name'})) .
3484 "<td class=\"link\">" .
3485 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3486 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3487 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3491 if (defined $extra) {
3493 "<td colspan=\"3\">$extra</td>\n" .
3499 sub git_search_grep_body
{
3500 my ($commitlist, $from, $to, $extra) = @_;
3501 $from = 0 unless defined $from;
3502 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3504 print "<table class=\"grep\" cellspacing=\"0\">\n";
3506 for (my $i = $from; $i <= $to; $i++) {
3507 my %co = %{$commitlist->[$i]};
3511 my $commit = $co{'id'};
3513 print "<tr class=\"dark\">\n";
3515 print "<tr class=\"light\">\n";
3518 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3519 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3521 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3522 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3523 my $comment = $co{'comment'};
3524 foreach my $line (@$comment) {
3525 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3526 my $lead = esc_html
($1) || "";
3527 $lead = chop_str
($lead, 30, 10);
3528 my $match = esc_html
($2) || "";
3529 my $trail = esc_html
($3) || "";
3530 $trail = chop_str
($trail, 30, 10);
3531 my $text = "$lead<span class=\"match\">$match</span>$trail";
3532 print chop_str
($text, 80, 5) . "<br/>\n";
3536 "<td class=\"link\">" .
3537 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3539 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3543 if (defined $extra) {
3545 "<td colspan=\"3\">$extra</td>\n" .
3551 ## ======================================================================
3552 ## ======================================================================
3555 sub git_project_list
{
3556 my $order = $cgi->param('o');
3557 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3558 die_error
(undef, "Unknown order parameter");
3561 my @list = git_get_projects_list
();
3563 die_error
(undef, "No projects found");
3567 if (-f
$home_text) {
3568 print "<div class=\"index_include\">\n";
3569 open (my $fd, $home_text);
3574 git_project_list_body
(\
@list, $order);
3579 my $order = $cgi->param('o');
3580 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3581 die_error
(undef, "Unknown order parameter");
3584 my @list = git_get_projects_list
($project);
3586 die_error
(undef, "No forks found");
3590 git_print_page_nav
('','');
3591 git_print_header_div
('summary', "$project forks");
3592 git_project_list_body
(\
@list, $order);
3596 sub git_project_index
{
3597 my @projects = git_get_projects_list
($project);
3600 -type
=> 'text/plain',
3601 -charset
=> 'utf-8',
3602 -content_disposition
=> 'inline; filename="index.aux"');
3604 foreach my $pr (@projects) {
3605 if (!exists $pr->{'owner'}) {
3606 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3609 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3610 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3611 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3612 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3616 print "$path $owner\n";
3621 my $descr = git_get_project_description
($project) || "none";
3622 my %co = parse_commit
("HEAD");
3623 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3624 my $head = $co{'id'};
3626 my $owner = git_get_project_owner
($project);
3628 my $refs = git_get_references
();
3629 # These get_*_list functions return one more to allow us to see if
3630 # there are more ...
3631 my @taglist = git_get_tags_list
(16);
3632 my @headlist = git_get_heads_list
(16);
3634 my ($check_forks) = gitweb_check_feature
('forks');
3637 @forklist = git_get_projects_list
($project);
3641 git_print_page_nav
('summary','', $head);
3643 print "<div class=\"title\"> </div>\n";
3644 print "<table cellspacing=\"0\">\n" .
3645 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3646 "<tr><td>owner</td><td>$owner</td></tr>\n";
3647 if (defined $cd{'rfc2822'}) {
3648 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3651 # use per project git URL list in $projectroot/$project/cloneurl
3652 # or make project git URL from git base URL and project name
3653 my $url_tag = "URL";
3654 my @url_list = git_get_project_url_list
($project);
3655 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3656 foreach my $git_url (@url_list) {
3657 next unless $git_url;
3658 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3663 if (-s
"$projectroot/$project/README.html") {
3664 if (open my $fd, "$projectroot/$project/README.html") {
3665 print "<div class=\"title\">readme</div>\n";
3666 print $_ while (<$fd>);
3671 # we need to request one more than 16 (0..15) to check if
3673 my @commitlist = $head ? parse_commits
($head, 17) : ();
3675 git_print_header_div
('shortlog');
3676 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3677 $#commitlist <= 15 ? undef :
3678 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3682 git_print_header_div
('tags');
3683 git_tags_body
(\
@taglist, 0, 15,
3684 $#taglist <= 15 ? undef :
3685 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3689 git_print_header_div
('heads');
3690 git_heads_body
(\
@headlist, $head, 0, 15,
3691 $#headlist <= 15 ? undef :
3692 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3696 git_print_header_div
('forks');
3697 git_project_list_body
(\
@forklist, undef, 0, 15,
3698 $#forklist <= 15 ? undef :
3699 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3707 my $head = git_get_head_hash
($project);
3709 git_print_page_nav
('','', $head,undef,$head);
3710 my %tag = parse_tag
($hash);
3713 die_error
(undef, "Unknown tag object");
3716 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3717 print "<div class=\"title_text\">\n" .
3718 "<table cellspacing=\"0\">\n" .
3720 "<td>object</td>\n" .
3721 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3722 $tag{'object'}) . "</td>\n" .
3723 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3724 $tag{'type'}) . "</td>\n" .
3726 if (defined($tag{'author'})) {
3727 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3728 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3729 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3730 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3733 print "</table>\n\n" .
3735 print "<div class=\"page_body\">";
3736 my $comment = $tag{'comment'};
3737 foreach my $line (@$comment) {
3739 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3749 my ($have_blame) = gitweb_check_feature
('blame');
3751 die_error
('403 Permission denied', "Permission denied");
3753 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3754 $hash_base ||= git_get_head_hash
($project);
3755 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3756 my %co = parse_commit
($hash_base)
3757 or die_error
(undef, "Reading commit failed");
3758 if (!defined $hash) {
3759 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3760 or die_error
(undef, "Error looking up file");
3762 $ftype = git_get_type
($hash);
3763 if ($ftype !~ "blob") {
3764 die_error
('400 Bad Request', "Object is not a blob");
3766 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3767 $file_name, $hash_base)
3768 or die_error
(undef, "Open git-blame failed");
3771 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3774 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3777 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3779 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3780 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3781 git_print_page_path
($file_name, $ftype, $hash_base);
3782 my @rev_color = (qw(light2 dark2));
3783 my $num_colors = scalar(@rev_color);
3784 my $current_color = 0;
3787 <div class="page_body">
3788 <table class="blame">
3789 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3794 last unless defined $_;
3795 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3796 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3797 if (!exists $metainfo{$full_rev}) {
3798 $metainfo{$full_rev} = {};
3800 my $meta = $metainfo{$full_rev};
3803 if (/^(\S+) (.*)$/) {
3809 my $rev = substr($full_rev, 0, 8);
3810 my $author = $meta->{'author'};
3811 my %date = parse_date
($meta->{'author-time'},
3812 $meta->{'author-tz'});
3813 my $date = $date{'iso-tz'};
3815 $current_color = ++$current_color % $num_colors;
3817 print "<tr class=\"$rev_color[$current_color]\">\n";
3819 print "<td class=\"sha1\"";
3820 print " title=\"". esc_html
($author) . ", $date\"";
3821 print " rowspan=\"$group_size\"" if ($group_size > 1);
3823 print $cgi->a({-href
=> href
(action
=>"commit",
3825 file_name
=>$file_name)},
3829 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3830 or die_error
(undef, "Open git-rev-parse failed");
3831 my $parent_commit = <$dd>;
3833 chomp($parent_commit);
3834 my $blamed = href
(action
=> 'blame',
3835 file_name
=> $meta->{'filename'},
3836 hash_base
=> $parent_commit);
3837 print "<td class=\"linenr\">";
3838 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3840 -class => "linenr" },
3843 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3849 or print "Reading blob failed\n";
3856 my ($have_blame) = gitweb_check_feature
('blame');
3858 die_error
('403 Permission denied', "Permission denied");
3860 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3861 $hash_base ||= git_get_head_hash
($project);
3862 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3863 my %co = parse_commit
($hash_base)
3864 or die_error
(undef, "Reading commit failed");
3865 if (!defined $hash) {
3866 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3867 or die_error
(undef, "Error lookup file");
3869 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3870 or die_error
(undef, "Open git-annotate failed");
3873 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3876 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3879 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3881 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3882 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3883 git_print_page_path
($file_name, 'blob', $hash_base);
3884 print "<div class=\"page_body\">\n";
3886 <table class="blame">
3895 my @line_class = (qw(light dark));
3896 my $line_class_len = scalar (@line_class);
3897 my $line_class_num = $#line_class;
3898 while (my $line = <$fd>) {
3910 $line_class_num = ($line_class_num + 1) % $line_class_len;
3912 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3919 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3922 $short_rev = substr ($long_rev, 0, 8);
3923 $age = time () - $time;
3924 $age_str = age_string
($age);
3925 $age_str =~ s/ / /g;
3926 $age_class = age_class
($age);
3927 $author = esc_html
($author);
3928 $author =~ s/ / /g;
3930 $data = untabify
($data);
3931 $data = esc_html
($data);
3934 <tr class="$line_class[$line_class_num]">
3935 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3936 <td class="$age_class">$age_str</td>
3938 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3939 <td class="pre">$data</td>
3942 } # while (my $line = <$fd>)
3943 print "</table>\n\n";
3945 or print "Reading blob failed.\n";
3951 my $head = git_get_head_hash
($project);
3953 git_print_page_nav
('','', $head,undef,$head);
3954 git_print_header_div
('summary', $project);
3956 my @tagslist = git_get_tags_list
();
3958 git_tags_body
(\
@tagslist);
3964 my $head = git_get_head_hash
($project);
3966 git_print_page_nav
('','', $head,undef,$head);
3967 git_print_header_div
('summary', $project);
3969 my @headslist = git_get_heads_list
();
3971 git_heads_body
(\
@headslist, $head);
3976 sub git_blob_plain
{
3979 if (!defined $hash) {
3980 if (defined $file_name) {
3981 my $base = $hash_base || git_get_head_hash
($project);
3982 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3983 or die_error
(undef, "Error lookup file");
3985 die_error
(undef, "No file name defined");
3987 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3988 # blobs defined by non-textual hash id's can be cached
3993 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3994 or die_error
(undef, "Couldn't cat $file_name, $hash");
3996 $type ||= blob_mimetype
($fd, $file_name);
3998 # save as filename, even when no $file_name is given
3999 my $save_as = "$hash";
4000 if (defined $file_name) {
4001 $save_as = $file_name;
4002 } elsif ($type =~ m/^text\//) {
4009 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
4011 binmode STDOUT
, ':raw';
4013 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4021 if (!defined $hash) {
4022 if (defined $file_name) {
4023 my $base = $hash_base || git_get_head_hash
($project);
4024 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4025 or die_error
(undef, "Error lookup file");
4027 die_error
(undef, "No file name defined");
4029 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4030 # blobs defined by non-textual hash id's can be cached
4034 my ($have_blame) = gitweb_check_feature
('blame');
4035 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4036 or die_error
(undef, "Couldn't cat $file_name, $hash");
4037 my $mimetype = blob_mimetype
($fd, $file_name);
4038 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
4040 return git_blob_plain
($mimetype);
4042 # we can have blame only for text/* mimetype
4043 $have_blame &&= ($mimetype =~ m!^text/!);
4045 git_header_html
(undef, $expires);
4046 my $formats_nav = '';
4047 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4048 if (defined $file_name) {
4051 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
4052 hash
=>$hash, file_name
=>$file_name)},
4057 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4058 hash
=>$hash, file_name
=>$file_name)},
4061 $cgi->a({-href
=> href
(action
=>"blob_plain",
4062 hash
=>$hash, file_name
=>$file_name)},
4065 $cgi->a({-href
=> href
(action
=>"blob",
4066 hash_base
=>"HEAD", file_name
=>$file_name)},
4070 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
4072 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4073 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4075 print "<div class=\"page_nav\">\n" .
4076 "<br/><br/></div>\n" .
4077 "<div class=\"title\">$hash</div>\n";
4079 git_print_page_path
($file_name, "blob", $hash_base);
4080 print "<div class=\"page_body\">\n";
4081 if ($mimetype =~ m!^text/!) {
4083 while (my $line = <$fd>) {
4086 $line = untabify
($line);
4087 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4088 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4090 } elsif ($mimetype =~ m!^image/!) {
4091 print qq
!<img type
="$mimetype"!;
4093 print qq
! alt
="$file_name" title
="$file_name"!;
4096 href(action=>"blob_plain
", hash=>$hash,
4097 hash_base=>$hash_base, file_name=>$file_name) .
4101 or print "Reading blob failed.\n";
4107 my $have_snapshot = gitweb_have_snapshot
();
4109 if (!defined $hash_base) {
4110 $hash_base = "HEAD";
4112 if (!defined $hash) {
4113 if (defined $file_name) {
4114 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4120 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4121 or die_error
(undef, "Open git-ls-tree failed");
4122 my @entries = map { chomp; $_ } <$fd>;
4123 close $fd or die_error
(undef, "Reading tree failed");
4126 my $refs = git_get_references
();
4127 my $ref = format_ref_marker
($refs, $hash_base);
4130 my ($have_blame) = gitweb_check_feature
('blame');
4131 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4133 if (defined $file_name) {
4135 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4136 hash
=>$hash, file_name
=>$file_name)},
4138 $cgi->a({-href
=> href
(action
=>"tree",
4139 hash_base
=>"HEAD", file_name
=>$file_name)},
4142 if ($have_snapshot) {
4143 # FIXME: Should be available when we have no hash base as well.
4145 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
4148 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4149 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4152 print "<div class=\"page_nav\">\n";
4153 print "<br/><br/></div>\n";
4154 print "<div class=\"title\">$hash</div>\n";
4156 if (defined $file_name) {
4157 $basedir = $file_name;
4158 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4162 git_print_page_path
($file_name, 'tree', $hash_base);
4163 print "<div class=\"page_body\">\n";
4164 print "<table cellspacing=\"0\">\n";
4166 # '..' (top directory) link if possible
4167 if (defined $hash_base &&
4168 defined $file_name && $file_name =~ m![^/]+$!) {
4170 print "<tr class=\"dark\">\n";
4172 print "<tr class=\"light\">\n";
4176 my $up = $file_name;
4177 $up =~ s!/?[^/]+$!!;
4178 undef $up unless $up;
4179 # based on git_print_tree_entry
4180 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4181 print '<td class="list">';
4182 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4186 print "<td class=\"link\"></td>\n";
4190 foreach my $line (@entries) {
4191 my %t = parse_ls_tree_line
($line, -z
=> 1);
4194 print "<tr class=\"dark\">\n";
4196 print "<tr class=\"light\">\n";
4200 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4204 print "</table>\n" .
4210 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
4211 my $have_snapshot = (defined $ctype && defined $suffix);
4212 if (!$have_snapshot) {
4213 die_error
('403 Permission denied', "Permission denied");
4216 if (!defined $hash) {
4217 $hash = git_get_head_hash
($project);
4220 my $git = git_cmd_str
();
4221 my $name = $project;
4222 $name =~ s
,([^/])/*\
.git
$,$1,;
4223 $name = basename
($name);
4224 my $filename = to_utf8
($name);
4225 $name =~ s/\047/\047\\\047\047/g;
4227 if ($suffix eq 'zip') {
4228 $filename .= "-$hash.$suffix";
4229 $cmd = "$git archive --format=zip --prefix=\'$name\'/ $hash";
4231 $filename .= "-$hash.tar.$suffix";
4232 $cmd = "$git archive --format=tar --prefix=\'$name\'/ $hash | $command";
4236 -type
=> "application/$ctype",
4237 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4238 -status
=> '200 OK');
4240 open my $fd, "-|", $cmd
4241 or die_error
(undef, "Execute git-archive failed");
4242 binmode STDOUT
, ':raw';
4244 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4250 my $head = git_get_head_hash
($project);
4251 if (!defined $hash) {
4254 if (!defined $page) {
4257 my $refs = git_get_references
();
4259 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4261 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4264 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4267 my %co = parse_commit
($hash);
4269 git_print_header_div
('summary', $project);
4270 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4272 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4273 for (my $i = 0; $i <= $to; $i++) {
4274 my %co = %{$commitlist[$i]};
4276 my $commit = $co{'id'};
4277 my $ref = format_ref_marker
($refs, $commit);
4278 my %ad = parse_date
($co{'author_epoch'});
4279 git_print_header_div
('commit',
4280 "<span class=\"age\">$co{'age_string'}</span>" .
4281 esc_html
($co{'title'}) . $ref,
4283 print "<div class=\"title_text\">\n" .
4284 "<div class=\"log_link\">\n" .
4285 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4287 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4289 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4292 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4295 print "<div class=\"log_body\">\n";
4296 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4299 if ($#commitlist >= 100) {
4300 print "<div class=\"page_nav\">\n";
4301 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4302 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4309 $hash ||= $hash_base || "HEAD";
4310 my %co = parse_commit
($hash);
4312 die_error
(undef, "Unknown commit object");
4314 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4315 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4317 my $parent = $co{'parent'};
4318 my $parents = $co{'parents'}; # listref
4320 # we need to prepare $formats_nav before any parameter munging
4322 if (!defined $parent) {
4324 $formats_nav .= '(initial)';
4325 } elsif (@$parents == 1) {
4326 # single parent commit
4329 $cgi->a({-href
=> href
(action
=>"commit",
4331 esc_html
(substr($parent, 0, 7))) .
4338 $cgi->a({-href
=> href
(action
=>"commit",
4340 esc_html
(substr($_, 0, 7)));
4345 if (!defined $parent) {
4349 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4351 (@$parents <= 1 ? $parent : '-c'),
4353 or die_error
(undef, "Open git-diff-tree failed");
4354 @difftree = map { chomp; $_ } <$fd>;
4355 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4357 # non-textual hash id's can be cached
4359 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4362 my $refs = git_get_references
();
4363 my $ref = format_ref_marker
($refs, $co{'id'});
4365 my $have_snapshot = gitweb_have_snapshot
();
4367 git_header_html
(undef, $expires);
4368 git_print_page_nav
('commit', '',
4369 $hash, $co{'tree'}, $hash,
4372 if (defined $co{'parent'}) {
4373 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4375 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4377 print "<div class=\"title_text\">\n" .
4378 "<table cellspacing=\"0\">\n";
4379 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4381 "<td></td><td> $ad{'rfc2822'}";
4382 if ($ad{'hour_local'} < 6) {
4383 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4384 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4386 printf(" (%02d:%02d %s)",
4387 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4391 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4392 print "<tr><td></td><td> $cd{'rfc2822'}" .
4393 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4395 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4398 "<td class=\"sha1\">" .
4399 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4400 class => "list"}, $co{'tree'}) .
4402 "<td class=\"link\">" .
4403 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4405 if ($have_snapshot) {
4407 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
4412 foreach my $par (@$parents) {
4415 "<td class=\"sha1\">" .
4416 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4417 class => "list"}, $par) .
4419 "<td class=\"link\">" .
4420 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4422 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4429 print "<div class=\"page_body\">\n";
4430 git_print_log
($co{'comment'});
4433 git_difftree_body
(\
@difftree, $hash, @$parents);
4439 # object is defined by:
4440 # - hash or hash_base alone
4441 # - hash_base and file_name
4444 # - hash or hash_base alone
4445 if ($hash || ($hash_base && !defined $file_name)) {
4446 my $object_id = $hash || $hash_base;
4448 my $git_command = git_cmd_str
();
4449 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4450 or die_error
('404 Not Found', "Object does not exist");
4454 or die_error
('404 Not Found', "Object does not exist");
4456 # - hash_base and file_name
4457 } elsif ($hash_base && defined $file_name) {
4458 $file_name =~ s
,/+$,,;
4460 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4461 or die_error
('404 Not Found', "Base object does not exist");
4463 # here errors should not hapen
4464 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4465 or die_error
(undef, "Open git-ls-tree failed");
4469 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4470 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4471 die_error
('404 Not Found', "File or directory for given base does not exist");
4476 die_error
('404 Not Found', "Not enough information to find object");
4479 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4480 hash
=>$hash, hash_base
=>$hash_base,
4481 file_name
=>$file_name),
4482 -status
=> '302 Found');
4486 my $format = shift || 'html';
4493 # preparing $fd and %diffinfo for git_patchset_body
4495 if (defined $hash_base && defined $hash_parent_base) {
4496 if (defined $file_name) {
4498 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4499 $hash_parent_base, $hash_base,
4500 "--", (defined $file_parent ? $file_parent : ()), $file_name
4501 or die_error
(undef, "Open git-diff-tree failed");
4502 @difftree = map { chomp; $_ } <$fd>;
4504 or die_error
(undef, "Reading git-diff-tree failed");
4506 or die_error
('404 Not Found', "Blob diff not found");
4508 } elsif (defined $hash &&
4509 $hash =~ /[0-9a-fA-F]{40}/) {
4510 # try to find filename from $hash
4512 # read filtered raw output
4513 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4514 $hash_parent_base, $hash_base, "--"
4515 or die_error
(undef, "Open git-diff-tree failed");
4517 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4519 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4520 map { chomp; $_ } <$fd>;
4522 or die_error
(undef, "Reading git-diff-tree failed");
4524 or die_error
('404 Not Found', "Blob diff not found");
4527 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4530 if (@difftree > 1) {
4531 die_error
('404 Not Found', "Ambiguous blob diff specification");
4534 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4535 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4536 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4538 $hash_parent ||= $diffinfo{'from_id'};
4539 $hash ||= $diffinfo{'to_id'};
4541 # non-textual hash id's can be cached
4542 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4543 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4548 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4549 '-p', ($format eq 'html' ? "--full-index" : ()),
4550 $hash_parent_base, $hash_base,
4551 "--", (defined $file_parent ? $file_parent : ()), $file_name
4552 or die_error
(undef, "Open git-diff-tree failed");
4555 # old/legacy style URI
4556 if (!%diffinfo && # if new style URI failed
4557 defined $hash && defined $hash_parent) {
4558 # fake git-diff-tree raw output
4559 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4560 $diffinfo{'from_id'} = $hash_parent;
4561 $diffinfo{'to_id'} = $hash;
4562 if (defined $file_name) {
4563 if (defined $file_parent) {
4564 $diffinfo{'status'} = '2';
4565 $diffinfo{'from_file'} = $file_parent;
4566 $diffinfo{'to_file'} = $file_name;
4567 } else { # assume not renamed
4568 $diffinfo{'status'} = '1';
4569 $diffinfo{'from_file'} = $file_name;
4570 $diffinfo{'to_file'} = $file_name;
4572 } else { # no filename given
4573 $diffinfo{'status'} = '2';
4574 $diffinfo{'from_file'} = $hash_parent;
4575 $diffinfo{'to_file'} = $hash;
4578 # non-textual hash id's can be cached
4579 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4580 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4585 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4586 '-p', ($format eq 'html' ? "--full-index" : ()),
4587 $hash_parent, $hash, "--"
4588 or die_error
(undef, "Open git-diff failed");
4590 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4595 if ($format eq 'html') {
4597 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4598 hash
=>$hash, hash_parent
=>$hash_parent,
4599 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4600 file_name
=>$file_name, file_parent
=>$file_parent)},
4602 git_header_html
(undef, $expires);
4603 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4604 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4605 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4607 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4608 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4610 if (defined $file_name) {
4611 git_print_page_path
($file_name, "blob", $hash_base);
4613 print "<div class=\"page_path\"></div>\n";
4616 } elsif ($format eq 'plain') {
4618 -type
=> 'text/plain',
4619 -charset
=> 'utf-8',
4620 -expires
=> $expires,
4621 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4623 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4626 die_error
(undef, "Unknown blobdiff format");
4630 if ($format eq 'html') {
4631 print "<div class=\"page_body\">\n";
4633 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4636 print "</div>\n"; # class="page_body"
4640 while (my $line = <$fd>) {
4641 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4642 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4646 last if $line =~ m!^\+\+\+!;
4654 sub git_blobdiff_plain
{
4655 git_blobdiff
('plain');
4658 sub git_commitdiff
{
4659 my $format = shift || 'html';
4660 $hash ||= $hash_base || "HEAD";
4661 my %co = parse_commit
($hash);
4663 die_error
(undef, "Unknown commit object");
4666 # choose format for commitdiff for merge
4667 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
4668 $hash_parent = '--cc';
4670 # we need to prepare $formats_nav before almost any parameter munging
4672 if ($format eq 'html') {
4674 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4675 hash
=>$hash, hash_parent
=>$hash_parent)},
4678 if (defined $hash_parent &&
4679 $hash_parent ne '-c' && $hash_parent ne '--cc') {
4680 # commitdiff with two commits given
4681 my $hash_parent_short = $hash_parent;
4682 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4683 $hash_parent_short = substr($hash_parent, 0, 7);
4687 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
4688 if ($co{'parents'}[$i] eq $hash_parent) {
4689 $formats_nav .= ' parent ' . ($i+1);
4693 $formats_nav .= ': ' .
4694 $cgi->a({-href
=> href
(action
=>"commitdiff",
4695 hash
=>$hash_parent)},
4696 esc_html
($hash_parent_short)) .
4698 } elsif (!$co{'parent'}) {
4700 $formats_nav .= ' (initial)';
4701 } elsif (scalar @{$co{'parents'}} == 1) {
4702 # single parent commit
4705 $cgi->a({-href
=> href
(action
=>"commitdiff",
4706 hash
=>$co{'parent'})},
4707 esc_html
(substr($co{'parent'}, 0, 7))) .
4711 if ($hash_parent eq '--cc') {
4712 $formats_nav .= ' | ' .
4713 $cgi->a({-href
=> href
(action
=>"commitdiff",
4714 hash
=>$hash, hash_parent
=>'-c')},
4716 } else { # $hash_parent eq '-c'
4717 $formats_nav .= ' | ' .
4718 $cgi->a({-href
=> href
(action
=>"commitdiff",
4719 hash
=>$hash, hash_parent
=>'--cc')},
4725 $cgi->a({-href
=> href
(action
=>"commitdiff",
4727 esc_html
(substr($_, 0, 7)));
4728 } @{$co{'parents'}} ) .
4733 my $hash_parent_param = $hash_parent;
4734 if (!defined $hash_parent_param) {
4735 # --cc for multiple parents, --root for parentless
4736 $hash_parent_param =
4737 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
4743 if ($format eq 'html') {
4744 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4745 "--no-commit-id", "--patch-with-raw", "--full-index",
4746 $hash_parent_param, $hash, "--"
4747 or die_error
(undef, "Open git-diff-tree failed");
4749 while (my $line = <$fd>) {
4751 # empty line ends raw part of diff-tree output
4753 push @difftree, scalar parse_difftree_raw_line
($line);
4756 } elsif ($format eq 'plain') {
4757 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4758 '-p', $hash_parent_param, $hash, "--"
4759 or die_error
(undef, "Open git-diff-tree failed");
4762 die_error
(undef, "Unknown commitdiff format");
4765 # non-textual hash id's can be cached
4767 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4771 # write commit message
4772 if ($format eq 'html') {
4773 my $refs = git_get_references
();
4774 my $ref = format_ref_marker
($refs, $co{'id'});
4776 git_header_html
(undef, $expires);
4777 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4778 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4779 git_print_authorship
(\
%co);
4780 print "<div class=\"page_body\">\n";
4781 if (@{$co{'comment'}} > 1) {
4782 print "<div class=\"log\">\n";
4783 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4784 print "</div>\n"; # class="log"
4787 } elsif ($format eq 'plain') {
4788 my $refs = git_get_references
("tags");
4789 my $tagname = git_get_rev_name_tags
($hash);
4790 my $filename = basename
($project) . "-$hash.patch";
4793 -type
=> 'text/plain',
4794 -charset
=> 'utf-8',
4795 -expires
=> $expires,
4796 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4797 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4800 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4801 Subject: $co{'title'}
4803 print "X-Git-Tag: $tagname\n" if $tagname;
4804 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4806 foreach my $line (@{$co{'comment'}}) {
4813 if ($format eq 'html') {
4814 my $use_parents = !defined $hash_parent ||
4815 $hash_parent eq '-c' || $hash_parent eq '--cc';
4816 git_difftree_body
(\
@difftree, $hash,
4817 $use_parents ? @{$co{'parents'}} : $hash_parent);
4820 git_patchset_body
($fd, \
@difftree, $hash,
4821 $use_parents ? @{$co{'parents'}} : $hash_parent);
4823 print "</div>\n"; # class="page_body"
4826 } elsif ($format eq 'plain') {
4830 or print "Reading git-diff-tree failed\n";
4834 sub git_commitdiff_plain
{
4835 git_commitdiff
('plain');
4839 if (!defined $hash_base) {
4840 $hash_base = git_get_head_hash
($project);
4842 if (!defined $page) {
4846 my %co = parse_commit
($hash_base);
4848 die_error
(undef, "Unknown commit object");
4851 my $refs = git_get_references
();
4852 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4854 if (!defined $hash && defined $file_name) {
4855 $hash = git_get_hash_by_path
($hash_base, $file_name);
4857 if (defined $hash) {
4858 $ftype = git_get_type
($hash);
4861 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4863 my $paging_nav = '';
4866 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4867 file_name
=>$file_name)},
4869 $paging_nav .= " ⋅ " .
4870 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4871 file_name
=>$file_name, page
=>$page-1),
4872 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4874 $paging_nav .= "first";
4875 $paging_nav .= " ⋅ prev";
4877 if ($#commitlist >= 100) {
4878 $paging_nav .= " ⋅ " .
4879 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4880 file_name
=>$file_name, page
=>$page+1),
4881 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4883 $paging_nav .= " ⋅ next";
4886 if ($#commitlist >= 100) {
4888 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4889 file_name
=>$file_name, page
=>$page+1),
4890 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4894 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4895 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4896 git_print_page_path
($file_name, $ftype, $hash_base);
4898 git_history_body
(\
@commitlist, 0, 99,
4899 $refs, $hash_base, $ftype, $next_link);
4905 my ($have_search) = gitweb_check_feature
('search');
4906 if (!$have_search) {
4907 die_error
('403 Permission denied', "Permission denied");
4909 if (!defined $searchtext) {
4910 die_error
(undef, "Text field empty");
4912 if (!defined $hash) {
4913 $hash = git_get_head_hash
($project);
4915 my %co = parse_commit
($hash);
4917 die_error
(undef, "Unknown commit object");
4919 if (!defined $page) {
4923 $searchtype ||= 'commit';
4924 if ($searchtype eq 'pickaxe') {
4925 # pickaxe may take all resources of your box and run for several minutes
4926 # with every query - so decide by yourself how public you make this feature
4927 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4928 if (!$have_pickaxe) {
4929 die_error
('403 Permission denied', "Permission denied");
4932 if ($searchtype eq 'grep') {
4933 my ($have_grep) = gitweb_check_feature
('grep');
4935 die_error
('403 Permission denied', "Permission denied");
4941 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4943 if ($searchtype eq 'commit') {
4944 $greptype = "--grep=";
4945 } elsif ($searchtype eq 'author') {
4946 $greptype = "--author=";
4947 } elsif ($searchtype eq 'committer') {
4948 $greptype = "--committer=";
4950 $greptype .= $search_regexp;
4951 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4953 my $paging_nav = '';
4956 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4957 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4959 $paging_nav .= " ⋅ " .
4960 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4961 searchtext
=>$searchtext, searchtype
=>$searchtype,
4963 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4965 $paging_nav .= "first";
4966 $paging_nav .= " ⋅ prev";
4968 if ($#commitlist >= 100) {
4969 $paging_nav .= " ⋅ " .
4970 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4971 searchtext
=>$searchtext, searchtype
=>$searchtype,
4973 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4975 $paging_nav .= " ⋅ next";
4978 if ($#commitlist >= 100) {
4980 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4981 searchtext
=>$searchtext, searchtype
=>$searchtype,
4983 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4986 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4987 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4988 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4991 if ($searchtype eq 'pickaxe') {
4992 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4993 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4995 print "<table cellspacing=\"0\">\n";
4998 my $git_command = git_cmd_str
();
4999 my $searchqtext = $searchtext;
5000 $searchqtext =~ s/'/'\\''/;
5001 open my $fd, "-|", "$git_command rev-list $hash | " .
5002 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
5005 while (my $line = <$fd>) {
5006 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
5009 $set{'from_id'} = $3;
5011 $set{'id'} = $set{'to_id'};
5012 if ($set{'id'} =~ m/0{40}/) {
5013 $set{'id'} = $set{'from_id'};
5015 if ($set{'id'} =~ m/0{40}/) {
5019 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
5022 print "<tr class=\"dark\">\n";
5024 print "<tr class=\"light\">\n";
5027 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5028 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
5030 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5031 -class => "list subject"},
5032 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
5033 while (my $setref = shift @files) {
5035 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5036 hash
=>$set{'id'}, file_name
=>$set{'file'}),
5038 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5042 "<td class=\"link\">" .
5043 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5045 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5049 %co = parse_commit
($1);
5057 if ($searchtype eq 'grep') {
5058 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5059 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5061 print "<table cellspacing=\"0\">\n";
5065 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
5067 while (my $line = <$fd>) {
5069 my ($file, $lno, $ltext, $binary);
5070 last if ($matches++ > 1000);
5071 if ($line =~ /^Binary file (.+) matches$/) {
5075 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5077 if ($file ne $lastfile) {
5078 $lastfile and print "</td></tr>\n";
5080 print "<tr class=\"dark\">\n";
5082 print "<tr class=\"light\">\n";
5084 print "<td class=\"list\">".
5085 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5086 file_name
=>"$file"),
5087 -class => "list"}, esc_path
($file));
5088 print "</td><td>\n";
5092 print "<div class=\"binary\">Binary file</div>\n";
5094 $ltext = untabify
($ltext);
5095 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
5096 $ltext = esc_html
($1, -nbsp
=>1);
5097 $ltext .= '<span class="match">';
5098 $ltext .= esc_html
($2, -nbsp
=>1);
5099 $ltext .= '</span>';
5100 $ltext .= esc_html
($3, -nbsp
=>1);
5102 $ltext = esc_html
($ltext, -nbsp
=>1);
5104 print "<div class=\"pre\">" .
5105 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5106 file_name
=>"$file").'#l'.$lno,
5107 -class => "linenr"}, sprintf('%4i', $lno))
5108 . ' ' . $ltext . "</div>\n";
5112 print "</td></tr>\n";
5113 if ($matches > 1000) {
5114 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5117 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5126 sub git_search_help
{
5128 git_print_page_nav
('','', $hash,$hash,$hash);
5131 <dt><b>commit</b></dt>
5132 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
5134 my ($have_grep) = gitweb_check_feature
('grep');
5137 <dt><b>grep</b></dt>
5138 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5139 a different one) are searched for the given
5140 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5141 (POSIX extended) and the matches are listed. On large
5142 trees, this search can take a while and put some strain on the server, so please use it with
5143 some consideration.</dd>
5147 <dt><b>author</b></dt>
5148 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5149 <dt><b>committer</b></dt>
5150 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5152 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5153 if ($have_pickaxe) {
5155 <dt><b>pickaxe</b></dt>
5156 <dd>All commits that caused the string to appear or disappear from any file (changes that
5157 added, removed or "modified" the string) will be listed. This search can take a while and
5158 takes a lot of strain on the server, so please use it wisely.</dd>
5166 my $head = git_get_head_hash
($project);
5167 if (!defined $hash) {
5170 if (!defined $page) {
5173 my $refs = git_get_references
();
5175 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5177 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
5179 if ($#commitlist >= 100) {
5181 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
5182 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5186 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5187 git_print_header_div
('summary', $project);
5189 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5194 ## ......................................................................
5195 ## feeds (RSS, Atom; OPML)
5198 my $format = shift || 'atom';
5199 my ($have_blame) = gitweb_check_feature
('blame');
5201 # Atom: http://www.atomenabled.org/developers/syndication/
5202 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5203 if ($format ne 'rss' && $format ne 'atom') {
5204 die_error
(undef, "Unknown web feed format");
5207 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5208 my $head = $hash || 'HEAD';
5209 my @commitlist = parse_commits
($head, 150);
5213 my $content_type = "application/$format+xml";
5214 if (defined $cgi->http('HTTP_ACCEPT') &&
5215 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5216 # browser (feed reader) prefers text/xml
5217 $content_type = 'text/xml';
5219 if (defined($commitlist[0])) {
5220 %latest_commit = %{$commitlist[0]};
5221 %latest_date = parse_date
($latest_commit{'author_epoch'});
5223 -type
=> $content_type,
5224 -charset
=> 'utf-8',
5225 -last_modified
=> $latest_date{'rfc2822'});
5228 -type
=> $content_type,
5229 -charset
=> 'utf-8');
5232 # Optimization: skip generating the body if client asks only
5233 # for Last-Modified date.
5234 return if ($cgi->request_method() eq 'HEAD');
5237 my $title = "$site_name - $project/$action";
5238 my $feed_type = 'log';
5239 if (defined $hash) {
5240 $title .= " - '$hash'";
5241 $feed_type = 'branch log';
5242 if (defined $file_name) {
5243 $title .= " :: $file_name";
5244 $feed_type = 'history';
5246 } elsif (defined $file_name) {
5247 $title .= " - $file_name";
5248 $feed_type = 'history';
5250 $title .= " $feed_type";
5251 my $descr = git_get_project_description
($project);
5252 if (defined $descr) {
5253 $descr = esc_html
($descr);
5255 $descr = "$project " .
5256 ($format eq 'rss' ? 'RSS' : 'Atom') .
5259 my $owner = git_get_project_owner
($project);
5260 $owner = esc_html
($owner);
5264 if (defined $file_name) {
5265 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5266 } elsif (defined $hash) {
5267 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5269 $alt_url = href
(-full
=>1, action
=>"summary");
5271 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5272 if ($format eq 'rss') {
5274 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5277 print "<title>$title</title>\n" .
5278 "<link>$alt_url</link>\n" .
5279 "<description>$descr</description>\n" .
5280 "<language>en</language>\n";
5281 } elsif ($format eq 'atom') {
5283 <feed xmlns="http://www.w3.org/2005/Atom">
5285 print "<title>$title</title>\n" .
5286 "<subtitle>$descr</subtitle>\n" .
5287 '<link rel="alternate" type="text/html" href="' .
5288 $alt_url . '" />' . "\n" .
5289 '<link rel="self" type="' . $content_type . '" href="' .
5290 $cgi->self_url() . '" />' . "\n" .
5291 "<id>" . href
(-full
=>1) . "</id>\n" .
5292 # use project owner for feed author
5293 "<author><name>$owner</name></author>\n";
5294 if (defined $favicon) {
5295 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5297 if (defined $logo_url) {
5298 # not twice as wide as tall: 72 x 27 pixels
5299 print "<logo>" . esc_url
($logo) . "</logo>\n";
5301 if (! %latest_date) {
5302 # dummy date to keep the feed valid until commits trickle in:
5303 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5305 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5310 for (my $i = 0; $i <= $#commitlist; $i++) {
5311 my %co = %{$commitlist[$i]};
5312 my $commit = $co{'id'};
5313 # we read 150, we always show 30 and the ones more recent than 48 hours
5314 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5317 my %cd = parse_date
($co{'author_epoch'});
5319 # get list of changed files
5320 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5321 $co{'parent'} || "--root",
5322 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5324 my @difftree = map { chomp; $_ } <$fd>;
5328 # print element (entry, item)
5329 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5330 if ($format eq 'rss') {
5332 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5333 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5334 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5335 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5336 "<link>$co_url</link>\n" .
5337 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5338 "<content:encoded>" .
5340 } elsif ($format eq 'atom') {
5342 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5343 "<updated>$cd{'iso-8601'}</updated>\n" .
5345 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5346 if ($co{'author_email'}) {
5347 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5349 print "</author>\n" .
5350 # use committer for contributor
5352 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5353 if ($co{'committer_email'}) {
5354 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5356 print "</contributor>\n" .
5357 "<published>$cd{'iso-8601'}</published>\n" .
5358 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5359 "<id>$co_url</id>\n" .
5360 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5361 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5363 my $comment = $co{'comment'};
5365 foreach my $line (@$comment) {
5366 $line = esc_html
($line);
5369 print "</pre><ul>\n";
5370 foreach my $difftree_line (@difftree) {
5371 my %difftree = parse_difftree_raw_line
($difftree_line);
5372 next if !$difftree{'from_id'};
5374 my $file = $difftree{'file'} || $difftree{'to_file'};
5378 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5379 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5380 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5381 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5382 -title
=> "diff"}, 'D');
5384 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5385 file_name
=>$file, hash_base
=>$commit),
5386 -title
=> "blame"}, 'B');
5388 # if this is not a feed of a file history
5389 if (!defined $file_name || $file_name ne $file) {
5390 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5391 file_name
=>$file, hash
=>$commit),
5392 -title
=> "history"}, 'H');
5394 $file = esc_path
($file);
5398 if ($format eq 'rss') {
5399 print "</ul>]]>\n" .
5400 "</content:encoded>\n" .
5402 } elsif ($format eq 'atom') {
5403 print "</ul>\n</div>\n" .
5410 if ($format eq 'rss') {
5411 print "</channel>\n</rss>\n";
5412 } elsif ($format eq 'atom') {
5426 my @list = git_get_projects_list
();
5428 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5430 <?xml version="1.0" encoding="utf-8"?>
5431 <opml version="1.0">
5433 <title>$site_name OPML Export</title>
5436 <outline text="git RSS feeds">
5439 foreach my $pr (@list) {
5441 my $head = git_get_head_hash
($proj{'path'});
5442 if (!defined $head) {
5445 $git_dir = "$projectroot/$proj{'path'}";
5446 my %co = parse_commit
($head);
5451 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5452 my $rss = "$my_url?p=$proj{'path'};a=rss";
5453 my $html = "$my_url?p=$proj{'path'};a=summary";
5454 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";