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 patch (diff) line (rather not to be used for diff headers)
959 sub format_diff_line
{
961 my ($from, $to) = @_;
966 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
968 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
969 if ($line =~ m/^\@{3}/) {
970 $diff_class = " chunk_header";
971 } elsif ($line =~ m/^\\/) {
972 $diff_class = " incomplete";
973 } elsif ($prefix =~ tr/+/+/) {
974 $diff_class = " add";
975 } elsif ($prefix =~ tr/-/-/) {
976 $diff_class = " rem";
979 # assume ordinary diff
980 my $char = substr($line, 0, 1);
982 $diff_class = " add";
983 } elsif ($char eq '-') {
984 $diff_class = " rem";
985 } elsif ($char eq '@') {
986 $diff_class = " chunk_header";
987 } elsif ($char eq "\\") {
988 $diff_class = " incomplete";
991 $line = untabify
($line);
992 if ($from && $to && $line =~ m/^\@{2} /) {
993 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
994 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
996 $from_lines = 0 unless defined $from_lines;
997 $to_lines = 0 unless defined $to_lines;
999 if ($from->{'href'}) {
1000 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1001 -class=>"list"}, $from_text);
1003 if ($to->{'href'}) {
1004 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1005 -class=>"list"}, $to_text);
1007 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1008 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1009 return "<div class=\"diff$diff_class\">$line</div>\n";
1010 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1011 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1012 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1014 @from_text = split(' ', $ranges);
1015 for (my $i = 0; $i < @from_text; ++$i) {
1016 ($from_start[$i], $from_nlines[$i]) =
1017 (split(',', substr($from_text[$i], 1)), 0);
1020 $to_text = pop @from_text;
1021 $to_start = pop @from_start;
1022 $to_nlines = pop @from_nlines;
1024 $line = "<span class=\"chunk_info\">$prefix ";
1025 for (my $i = 0; $i < @from_text; ++$i) {
1026 if ($from->{'href'}[$i]) {
1027 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1028 -class=>"list"}, $from_text[$i]);
1030 $line .= $from_text[$i];
1034 if ($to->{'href'}) {
1035 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1036 -class=>"list"}, $to_text);
1040 $line .= " $prefix</span>" .
1041 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1042 return "<div class=\"diff$diff_class\">$line</div>\n";
1044 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1047 ## ----------------------------------------------------------------------
1048 ## git utility subroutines, invoking git commands
1050 # returns path to the core git executable and the --git-dir parameter as list
1052 return $GIT, '--git-dir='.$git_dir;
1055 # returns path to the core git executable and the --git-dir parameter as string
1057 return join(' ', git_cmd
());
1060 # get HEAD ref of given project as hash
1061 sub git_get_head_hash
{
1062 my $project = shift;
1063 my $o_git_dir = $git_dir;
1065 $git_dir = "$projectroot/$project";
1066 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1069 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1073 if (defined $o_git_dir) {
1074 $git_dir = $o_git_dir;
1079 # get type of given object
1083 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1085 close $fd or return;
1090 sub git_get_project_config
{
1091 my ($key, $type) = @_;
1093 return unless ($key);
1094 $key =~ s/^gitweb\.//;
1095 return if ($key =~ m/\W/);
1097 my @x = (git_cmd
(), 'config');
1098 if (defined $type) { push @x, $type; }
1100 push @x, "gitweb.$key";
1106 # get hash of given path at given ref
1107 sub git_get_hash_by_path
{
1109 my $path = shift || return undef;
1114 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1115 or die_error
(undef, "Open git-ls-tree failed");
1117 close $fd or return undef;
1119 if (!defined $line) {
1120 # there is no tree or hash given by $path at $base
1124 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1125 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1126 if (defined $type && $type ne $2) {
1127 # type doesn't match
1133 # get path of entry with given hash at given tree-ish (ref)
1134 # used to get 'from' filename for combined diff (merge commit) for renames
1135 sub git_get_path_by_hash
{
1136 my $base = shift || return;
1137 my $hash = shift || return;
1141 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1143 while (my $line = <$fd>) {
1146 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1147 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1148 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1157 ## ......................................................................
1158 ## git utility functions, directly accessing git repository
1160 sub git_get_project_description
{
1163 open my $fd, "$projectroot/$path/description" or return undef;
1166 if (defined $descr) {
1172 sub git_get_project_url_list
{
1175 open my $fd, "$projectroot/$path/cloneurl" or return;
1176 my @git_project_url_list = map { chomp; $_ } <$fd>;
1179 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1182 sub git_get_projects_list
{
1187 $filter =~ s/\.git$//;
1189 my ($check_forks) = gitweb_check_feature
('forks');
1191 if (-d
$projects_list) {
1192 # search in directory
1193 my $dir = $projects_list . ($filter ? "/$filter" : '');
1194 # remove the trailing "/"
1196 my $pfxlen = length("$dir");
1199 follow_fast
=> 1, # follow symbolic links
1200 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1202 # skip project-list toplevel, if we get it.
1203 return if (m!^[/.]$!);
1204 # only directories can be git repositories
1205 return unless (-d
$_);
1207 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1208 # we check related file in $projectroot
1209 if ($check_forks and $subdir =~ m
#/.#) {
1210 $File::Find
::prune
= 1;
1211 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1212 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1213 $File::Find
::prune
= 1;
1218 } elsif (-f
$projects_list) {
1219 # read from file(url-encoded):
1220 # 'git%2Fgit.git Linus+Torvalds'
1221 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1222 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1224 open my ($fd), $projects_list or return;
1226 while (my $line = <$fd>) {
1228 my ($path, $owner) = split ' ', $line;
1229 $path = unescape
($path);
1230 $owner = unescape
($owner);
1231 if (!defined $path) {
1234 if ($filter ne '') {
1235 # looking for forks;
1236 my $pfx = substr($path, 0, length($filter));
1237 if ($pfx ne $filter) {
1240 my $sfx = substr($path, length($filter));
1241 if ($sfx !~ /^\/.*\
.git
$/) {
1244 } elsif ($check_forks) {
1246 foreach my $filter (keys %paths) {
1247 # looking for forks;
1248 my $pfx = substr($path, 0, length($filter));
1249 if ($pfx ne $filter) {
1252 my $sfx = substr($path, length($filter));
1253 if ($sfx !~ /^\/.*\
.git
$/) {
1256 # is a fork, don't include it in
1261 if (check_export_ok
("$projectroot/$path")) {
1264 owner
=> to_utf8
($owner),
1267 (my $forks_path = $path) =~ s/\.git$//;
1268 $paths{$forks_path}++;
1276 sub git_get_project_owner
{
1277 my $project = shift;
1280 return undef unless $project;
1282 # read from file (url-encoded):
1283 # 'git%2Fgit.git Linus+Torvalds'
1284 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1285 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1286 if (-f
$projects_list) {
1287 open (my $fd , $projects_list);
1288 while (my $line = <$fd>) {
1290 my ($pr, $ow) = split ' ', $line;
1291 $pr = unescape
($pr);
1292 $ow = unescape
($ow);
1293 if ($pr eq $project) {
1294 $owner = to_utf8
($ow);
1300 if (!defined $owner) {
1301 $owner = get_file_owner
("$projectroot/$project");
1307 sub git_get_last_activity
{
1311 $git_dir = "$projectroot/$path";
1312 open($fd, "-|", git_cmd
(), 'for-each-ref',
1313 '--format=%(committer)',
1314 '--sort=-committerdate',
1316 'refs/heads') or return;
1317 my $most_recent = <$fd>;
1318 close $fd or return;
1319 if (defined $most_recent &&
1320 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1322 my $age = time - $timestamp;
1323 return ($age, age_string
($age));
1327 sub git_get_references
{
1328 my $type = shift || "";
1330 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1331 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1332 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1333 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1336 while (my $line = <$fd>) {
1338 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1339 if (defined $refs{$1}) {
1340 push @{$refs{$1}}, $2;
1346 close $fd or return;
1350 sub git_get_rev_name_tags
{
1351 my $hash = shift || return undef;
1353 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1355 my $name_rev = <$fd>;
1358 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1361 # catches also '$hash undefined' output
1366 ## ----------------------------------------------------------------------
1367 ## parse to hash functions
1371 my $tz = shift || "-0000";
1374 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1375 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1376 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1377 $date{'hour'} = $hour;
1378 $date{'minute'} = $min;
1379 $date{'mday'} = $mday;
1380 $date{'day'} = $days[$wday];
1381 $date{'month'} = $months[$mon];
1382 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1383 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1384 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1385 $mday, $months[$mon], $hour ,$min;
1386 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1387 1900+$year, $mon, $mday, $hour ,$min, $sec;
1389 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1390 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1391 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1392 $date{'hour_local'} = $hour;
1393 $date{'minute_local'} = $min;
1394 $date{'tz_local'} = $tz;
1395 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1396 1900+$year, $mon+1, $mday,
1397 $hour, $min, $sec, $tz);
1406 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1407 $tag{'id'} = $tag_id;
1408 while (my $line = <$fd>) {
1410 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1411 $tag{'object'} = $1;
1412 } elsif ($line =~ m/^type (.+)$/) {
1414 } elsif ($line =~ m/^tag (.+)$/) {
1416 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1417 $tag{'author'} = $1;
1420 } elsif ($line =~ m/--BEGIN/) {
1421 push @comment, $line;
1423 } elsif ($line eq "") {
1427 push @comment, <$fd>;
1428 $tag{'comment'} = \
@comment;
1429 close $fd or return;
1430 if (!defined $tag{'name'}) {
1436 sub parse_commit_text
{
1437 my ($commit_text, $withparents) = @_;
1438 my @commit_lines = split '\n', $commit_text;
1441 pop @commit_lines; # Remove '\0'
1443 if (! @commit_lines) {
1447 my $header = shift @commit_lines;
1448 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1451 ($co{'id'}, my @parents) = split ' ', $header;
1452 while (my $line = shift @commit_lines) {
1453 last if $line eq "\n";
1454 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1456 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1458 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1460 $co{'author_epoch'} = $2;
1461 $co{'author_tz'} = $3;
1462 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1463 $co{'author_name'} = $1;
1464 $co{'author_email'} = $2;
1466 $co{'author_name'} = $co{'author'};
1468 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1469 $co{'committer'} = $1;
1470 $co{'committer_epoch'} = $2;
1471 $co{'committer_tz'} = $3;
1472 $co{'committer_name'} = $co{'committer'};
1473 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1474 $co{'committer_name'} = $1;
1475 $co{'committer_email'} = $2;
1477 $co{'committer_name'} = $co{'committer'};
1481 if (!defined $co{'tree'}) {
1484 $co{'parents'} = \
@parents;
1485 $co{'parent'} = $parents[0];
1487 foreach my $title (@commit_lines) {
1490 $co{'title'} = chop_str
($title, 80, 5);
1491 # remove leading stuff of merges to make the interesting part visible
1492 if (length($title) > 50) {
1493 $title =~ s/^Automatic //;
1494 $title =~ s/^merge (of|with) /Merge ... /i;
1495 if (length($title) > 50) {
1496 $title =~ s/(http|rsync):\/\///;
1498 if (length($title) > 50) {
1499 $title =~ s/(master|www|rsync)\.//;
1501 if (length($title) > 50) {
1502 $title =~ s/kernel.org:?//;
1504 if (length($title) > 50) {
1505 $title =~ s/\/pub\/scm//;
1508 $co{'title_short'} = chop_str
($title, 50, 5);
1512 if ($co{'title'} eq "") {
1513 $co{'title'} = $co{'title_short'} = '(no commit message)';
1515 # remove added spaces
1516 foreach my $line (@commit_lines) {
1519 $co{'comment'} = \
@commit_lines;
1521 my $age = time - $co{'committer_epoch'};
1523 $co{'age_string'} = age_string
($age);
1524 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1525 if ($age > 60*60*24*7*2) {
1526 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1527 $co{'age_string_age'} = $co{'age_string'};
1529 $co{'age_string_date'} = $co{'age_string'};
1530 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1536 my ($commit_id) = @_;
1541 open my $fd, "-|", git_cmd
(), "rev-list",
1547 or die_error
(undef, "Open git-rev-list failed");
1548 %co = parse_commit_text
(<$fd>, 1);
1555 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1563 open my $fd, "-|", git_cmd
(), "rev-list",
1565 ($arg ? ($arg) : ()),
1566 ("--max-count=" . $maxcount),
1567 ("--skip=" . $skip),
1570 ($filename ? ($filename) : ())
1571 or die_error
(undef, "Open git-rev-list failed");
1572 while (my $line = <$fd>) {
1573 my %co = parse_commit_text
($line);
1578 return wantarray ? @cos : \
@cos;
1581 # parse ref from ref_file, given by ref_id, with given type
1583 my $ref_file = shift;
1585 my $type = shift || git_get_type
($ref_id);
1588 $ref_item{'type'} = $type;
1589 $ref_item{'id'} = $ref_id;
1590 $ref_item{'epoch'} = 0;
1591 $ref_item{'age'} = "unknown";
1592 if ($type eq "tag") {
1593 my %tag = parse_tag
($ref_id);
1594 $ref_item{'comment'} = $tag{'comment'};
1595 if ($tag{'type'} eq "commit") {
1596 my %co = parse_commit
($tag{'object'});
1597 $ref_item{'epoch'} = $co{'committer_epoch'};
1598 $ref_item{'age'} = $co{'age_string'};
1599 } elsif (defined($tag{'epoch'})) {
1600 my $age = time - $tag{'epoch'};
1601 $ref_item{'epoch'} = $tag{'epoch'};
1602 $ref_item{'age'} = age_string
($age);
1604 $ref_item{'reftype'} = $tag{'type'};
1605 $ref_item{'name'} = $tag{'name'};
1606 $ref_item{'refid'} = $tag{'object'};
1607 } elsif ($type eq "commit"){
1608 my %co = parse_commit
($ref_id);
1609 $ref_item{'reftype'} = "commit";
1610 $ref_item{'name'} = $ref_file;
1611 $ref_item{'title'} = $co{'title'};
1612 $ref_item{'refid'} = $ref_id;
1613 $ref_item{'epoch'} = $co{'committer_epoch'};
1614 $ref_item{'age'} = $co{'age_string'};
1616 $ref_item{'reftype'} = $type;
1617 $ref_item{'name'} = $ref_file;
1618 $ref_item{'refid'} = $ref_id;
1624 # parse line of git-diff-tree "raw" output
1625 sub parse_difftree_raw_line
{
1629 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1630 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1631 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1632 $res{'from_mode'} = $1;
1633 $res{'to_mode'} = $2;
1634 $res{'from_id'} = $3;
1636 $res{'status'} = $5;
1637 $res{'similarity'} = $6;
1638 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1639 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1641 $res{'file'} = unquote
($7);
1644 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1645 # combined diff (for merge commit)
1646 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1647 $res{'nparents'} = length($1);
1648 $res{'from_mode'} = [ split(' ', $2) ];
1649 $res{'to_mode'} = pop @{$res{'from_mode'}};
1650 $res{'from_id'} = [ split(' ', $3) ];
1651 $res{'to_id'} = pop @{$res{'from_id'}};
1652 $res{'status'} = [ split('', $4) ];
1653 $res{'to_file'} = unquote
($5);
1655 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1656 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1657 $res{'commit'} = $1;
1660 return wantarray ? %res : \
%res;
1663 # parse line of git-ls-tree output
1664 sub parse_ls_tree_line
($;%) {
1669 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1670 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1678 $res{'name'} = unquote
($4);
1681 return wantarray ? %res : \
%res;
1684 ## ......................................................................
1685 ## parse to array of hashes functions
1687 sub git_get_heads_list
{
1691 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1692 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1693 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1696 while (my $line = <$fd>) {
1700 my ($refinfo, $committerinfo) = split(/\0/, $line);
1701 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1702 my ($committer, $epoch, $tz) =
1703 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1704 $name =~ s!^refs/heads/!!;
1706 $ref_item{'name'} = $name;
1707 $ref_item{'id'} = $hash;
1708 $ref_item{'title'} = $title || '(no commit message)';
1709 $ref_item{'epoch'} = $epoch;
1711 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1713 $ref_item{'age'} = "unknown";
1716 push @headslist, \
%ref_item;
1720 return wantarray ? @headslist : \
@headslist;
1723 sub git_get_tags_list
{
1727 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1728 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1729 '--format=%(objectname) %(objecttype) %(refname) '.
1730 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1733 while (my $line = <$fd>) {
1737 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1738 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1739 my ($creator, $epoch, $tz) =
1740 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1741 $name =~ s!^refs/tags/!!;
1743 $ref_item{'type'} = $type;
1744 $ref_item{'id'} = $id;
1745 $ref_item{'name'} = $name;
1746 if ($type eq "tag") {
1747 $ref_item{'subject'} = $title;
1748 $ref_item{'reftype'} = $reftype;
1749 $ref_item{'refid'} = $refid;
1751 $ref_item{'reftype'} = $type;
1752 $ref_item{'refid'} = $id;
1755 if ($type eq "tag" || $type eq "commit") {
1756 $ref_item{'epoch'} = $epoch;
1758 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1760 $ref_item{'age'} = "unknown";
1764 push @tagslist, \
%ref_item;
1768 return wantarray ? @tagslist : \
@tagslist;
1771 ## ----------------------------------------------------------------------
1772 ## filesystem-related functions
1774 sub get_file_owner
{
1777 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1778 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1779 if (!defined $gcos) {
1783 $owner =~ s/[,;].*$//;
1784 return to_utf8
($owner);
1787 ## ......................................................................
1788 ## mimetype related functions
1790 sub mimetype_guess_file
{
1791 my $filename = shift;
1792 my $mimemap = shift;
1793 -r
$mimemap or return undef;
1796 open(MIME
, $mimemap) or return undef;
1798 next if m/^#/; # skip comments
1799 my ($mime, $exts) = split(/\t+/);
1800 if (defined $exts) {
1801 my @exts = split(/\s+/, $exts);
1802 foreach my $ext (@exts) {
1803 $mimemap{$ext} = $mime;
1809 $filename =~ /\.([^.]*)$/;
1810 return $mimemap{$1};
1813 sub mimetype_guess
{
1814 my $filename = shift;
1816 $filename =~ /\./ or return undef;
1818 if ($mimetypes_file) {
1819 my $file = $mimetypes_file;
1820 if ($file !~ m!^/!) { # if it is relative path
1821 # it is relative to project
1822 $file = "$projectroot/$project/$file";
1824 $mime = mimetype_guess_file
($filename, $file);
1826 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1832 my $filename = shift;
1835 my $mime = mimetype_guess
($filename);
1836 $mime and return $mime;
1840 return $default_blob_plain_mimetype unless $fd;
1843 return 'text/plain' .
1844 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1845 } elsif (! $filename) {
1846 return 'application/octet-stream';
1847 } elsif ($filename =~ m/\.png$/i) {
1849 } elsif ($filename =~ m/\.gif$/i) {
1851 } elsif ($filename =~ m/\.jpe?g$/i) {
1852 return 'image/jpeg';
1854 return 'application/octet-stream';
1858 ## ======================================================================
1859 ## functions printing HTML: header, footer, error page
1861 sub git_header_html
{
1862 my $status = shift || "200 OK";
1863 my $expires = shift;
1865 my $title = "$site_name";
1866 if (defined $project) {
1867 $title .= " - " . to_utf8
($project);
1868 if (defined $action) {
1869 $title .= "/$action";
1870 if (defined $file_name) {
1871 $title .= " - " . esc_path
($file_name);
1872 if ($action eq "tree" && $file_name !~ m
|/$|) {
1879 # require explicit support from the UA if we are to send the page as
1880 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1881 # we have to do this because MSIE sometimes globs '*/*', pretending to
1882 # support xhtml+xml but choking when it gets what it asked for.
1883 if (defined $cgi->http('HTTP_ACCEPT') &&
1884 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1885 $cgi->Accept('application/xhtml+xml') != 0) {
1886 $content_type = 'application/xhtml+xml';
1888 $content_type = 'text/html';
1890 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1891 -status
=> $status, -expires
=> $expires);
1892 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
1894 <?xml version="1.0" encoding="utf-8"?>
1895 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1896 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1897 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1898 <!-- git core binaries version $git_version -->
1900 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1901 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
1902 <meta name="robots" content="index, nofollow"/>
1903 <title>$title</title>
1905 # print out each stylesheet that exist
1906 if (defined $stylesheet) {
1907 #provides backwards capability for those people who define style sheet in a config file
1908 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1910 foreach my $stylesheet (@stylesheets) {
1911 next unless $stylesheet;
1912 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1915 if (defined $project) {
1916 printf('<link rel="alternate" title="%s log RSS feed" '.
1917 'href="%s" type="application/rss+xml" />'."\n",
1918 esc_param
($project), href
(action
=>"rss"));
1919 printf('<link rel="alternate" title="%s log Atom feed" '.
1920 'href="%s" type="application/atom+xml" />'."\n",
1921 esc_param
($project), href
(action
=>"atom"));
1923 printf('<link rel="alternate" title="%s projects list" '.
1924 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1925 $site_name, href
(project
=>undef, action
=>"project_index"));
1926 printf('<link rel="alternate" title="%s projects feeds" '.
1927 'href="%s" type="text/x-opml"/>'."\n",
1928 $site_name, href
(project
=>undef, action
=>"opml"));
1930 if (defined $favicon) {
1931 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1937 if (-f
$site_header) {
1938 open (my $fd, $site_header);
1943 print "<div class=\"page_header\">\n" .
1944 $cgi->a({-href
=> esc_url
($logo_url),
1945 -title
=> $logo_label},
1946 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1947 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1948 if (defined $project) {
1949 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1950 if (defined $action) {
1957 my ($have_search) = gitweb_check_feature
('search');
1958 if ((defined $project) && ($have_search)) {
1959 if (!defined $searchtext) {
1963 if (defined $hash_base) {
1964 $search_hash = $hash_base;
1965 } elsif (defined $hash) {
1966 $search_hash = $hash;
1968 $search_hash = "HEAD";
1970 $cgi->param("a", "search");
1971 $cgi->param("h", $search_hash);
1972 $cgi->param("p", $project);
1973 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1974 "<div class=\"search\">\n" .
1975 $cgi->hidden(-name
=> "p") . "\n" .
1976 $cgi->hidden(-name
=> "a") . "\n" .
1977 $cgi->hidden(-name
=> "h") . "\n" .
1978 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1979 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
1980 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1982 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1984 $cgi->end_form() . "\n";
1988 sub git_footer_html
{
1989 print "<div class=\"page_footer\">\n";
1990 if (defined $project) {
1991 my $descr = git_get_project_description
($project);
1992 if (defined $descr) {
1993 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1995 print $cgi->a({-href
=> href
(action
=>"rss"),
1996 -class => "rss_logo"}, "RSS") . " ";
1997 print $cgi->a({-href
=> href
(action
=>"atom"),
1998 -class => "rss_logo"}, "Atom") . "\n";
2000 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2001 -class => "rss_logo"}, "OPML") . " ";
2002 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2003 -class => "rss_logo"}, "TXT") . "\n";
2007 if (-f
$site_footer) {
2008 open (my $fd, $site_footer);
2018 my $status = shift || "403 Forbidden";
2019 my $error = shift || "Malformed query, file missing or permission denied";
2021 git_header_html
($status);
2023 <div class="page_body">
2033 ## ----------------------------------------------------------------------
2034 ## functions printing or outputting HTML: navigation
2036 sub git_print_page_nav
{
2037 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2038 $extra = '' if !defined $extra; # pager or formats
2040 my @navs = qw(summary shortlog log commit commitdiff tree);
2042 @navs = grep { $_ ne $suppress } @navs;
2045 my %arg = map { $_ => {action
=>$_} } @navs;
2046 if (defined $head) {
2047 for (qw(commit commitdiff)) {
2048 $arg{$_}{'hash'} = $head;
2050 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2051 for (qw(shortlog log)) {
2052 $arg{$_}{'hash'} = $head;
2056 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2057 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2059 print "<div class=\"page_nav\">\n" .
2061 map { $_ eq $current ?
2062 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2064 print "<br/>\n$extra<br/>\n" .
2068 sub format_paging_nav
{
2069 my ($action, $hash, $head, $page, $nrevs) = @_;
2073 if ($hash ne $head || $page) {
2074 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2076 $paging_nav .= "HEAD";
2080 $paging_nav .= " ⋅ " .
2081 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2082 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2084 $paging_nav .= " ⋅ prev";
2087 if ($nrevs >= (100 * ($page+1)-1)) {
2088 $paging_nav .= " ⋅ " .
2089 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2090 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2092 $paging_nav .= " ⋅ next";
2098 ## ......................................................................
2099 ## functions printing or outputting HTML: div
2101 sub git_print_header_div
{
2102 my ($action, $title, $hash, $hash_base) = @_;
2105 $args{'action'} = $action;
2106 $args{'hash'} = $hash if $hash;
2107 $args{'hash_base'} = $hash_base if $hash_base;
2109 print "<div class=\"header\">\n" .
2110 $cgi->a({-href
=> href
(%args), -class => "title"},
2111 $title ? $title : $action) .
2115 #sub git_print_authorship (\%) {
2116 sub git_print_authorship
{
2119 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2120 print "<div class=\"author_date\">" .
2121 esc_html
($co->{'author_name'}) .
2123 if ($ad{'hour_local'} < 6) {
2124 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2125 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2127 printf(" (%02d:%02d %s)",
2128 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2133 sub git_print_page_path
{
2139 print "<div class=\"page_path\">";
2140 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2141 -title
=> 'tree root'}, to_utf8
("[$project]"));
2143 if (defined $name) {
2144 my @dirname = split '/', $name;
2145 my $basename = pop @dirname;
2148 foreach my $dir (@dirname) {
2149 $fullname .= ($fullname ? '/' : '') . $dir;
2150 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2152 -title
=> $fullname}, esc_path
($dir));
2155 if (defined $type && $type eq 'blob') {
2156 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2158 -title
=> $name}, esc_path
($basename));
2159 } elsif (defined $type && $type eq 'tree') {
2160 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2162 -title
=> $name}, esc_path
($basename));
2165 print esc_path
($basename);
2168 print "<br/></div>\n";
2171 # sub git_print_log (\@;%) {
2172 sub git_print_log
($;%) {
2176 if ($opts{'-remove_title'}) {
2177 # remove title, i.e. first line of log
2180 # remove leading empty lines
2181 while (defined $log->[0] && $log->[0] eq "") {
2188 foreach my $line (@$log) {
2189 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2192 if (! $opts{'-remove_signoff'}) {
2193 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2196 # remove signoff lines
2203 # print only one empty line
2204 # do not print empty line after signoff
2206 next if ($empty || $signoff);
2212 print format_log_line_html
($line) . "<br/>\n";
2215 if ($opts{'-final_empty_line'}) {
2216 # end with single empty line
2217 print "<br/>\n" unless $empty;
2221 # return link target (what link points to)
2222 sub git_get_link_target
{
2227 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2231 $link_target = <$fd>;
2236 return $link_target;
2239 # given link target, and the directory (basedir) the link is in,
2240 # return target of link relative to top directory (top tree);
2241 # return undef if it is not possible (including absolute links).
2242 sub normalize_link_target
{
2243 my ($link_target, $basedir, $hash_base) = @_;
2245 # we can normalize symlink target only if $hash_base is provided
2246 return unless $hash_base;
2248 # absolute symlinks (beginning with '/') cannot be normalized
2249 return if (substr($link_target, 0, 1) eq '/');
2251 # normalize link target to path from top (root) tree (dir)
2254 $path = $basedir . '/' . $link_target;
2256 # we are in top (root) tree (dir)
2257 $path = $link_target;
2260 # remove //, /./, and /../
2262 foreach my $part (split('/', $path)) {
2263 # discard '.' and ''
2264 next if (!$part || $part eq '.');
2266 if ($part eq '..') {
2270 # link leads outside repository (outside top dir)
2274 push @path_parts, $part;
2277 $path = join('/', @path_parts);
2282 # print tree entry (row of git_tree), but without encompassing <tr> element
2283 sub git_print_tree_entry
{
2284 my ($t, $basedir, $hash_base, $have_blame) = @_;
2287 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2289 # The format of a table row is: mode list link. Where mode is
2290 # the mode of the entry, list is the name of the entry, an href,
2291 # and link is the action links of the entry.
2293 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2294 if ($t->{'type'} eq "blob") {
2295 print "<td class=\"list\">" .
2296 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2297 file_name
=>"$basedir$t->{'name'}", %base_key),
2298 -class => "list"}, esc_path
($t->{'name'}));
2299 if (S_ISLNK
(oct $t->{'mode'})) {
2300 my $link_target = git_get_link_target
($t->{'hash'});
2302 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2303 if (defined $norm_target) {
2305 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2306 file_name
=>$norm_target),
2307 -title
=> $norm_target}, esc_path
($link_target));
2309 print " -> " . esc_path
($link_target);
2314 print "<td class=\"link\">";
2315 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2316 file_name
=>"$basedir$t->{'name'}", %base_key)},
2320 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2321 file_name
=>"$basedir$t->{'name'}", %base_key)},
2324 if (defined $hash_base) {
2326 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2327 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2331 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2332 file_name
=>"$basedir$t->{'name'}")},
2336 } elsif ($t->{'type'} eq "tree") {
2337 print "<td class=\"list\">";
2338 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2339 file_name
=>"$basedir$t->{'name'}", %base_key)},
2340 esc_path
($t->{'name'}));
2342 print "<td class=\"link\">";
2343 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2344 file_name
=>"$basedir$t->{'name'}", %base_key)},
2346 if (defined $hash_base) {
2348 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2349 file_name
=>"$basedir$t->{'name'}")},
2356 ## ......................................................................
2357 ## functions printing large fragments of HTML
2359 sub fill_from_file_info
{
2360 my ($diff, @parents) = @_;
2362 $diff->{'from_file'} = [ ];
2363 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2364 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2365 if ($diff->{'status'}[$i] eq 'R' ||
2366 $diff->{'status'}[$i] eq 'C') {
2367 $diff->{'from_file'}[$i] =
2368 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2375 # parameters can be strings, or references to arrays of strings
2379 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @$a == @$b) {
2380 for (my $i = 0; $i < @$a; ++$i) {
2381 return 0 unless ($a->[$i] eq $b->[$i]);
2384 } elsif (!ref($a) && !ref($b)) {
2392 sub git_difftree_body
{
2393 my ($difftree, $hash, @parents) = @_;
2394 my ($parent) = $parents[0];
2395 my ($have_blame) = gitweb_check_feature
('blame');
2396 print "<div class=\"list_head\">\n";
2397 if ($#{$difftree} > 10) {
2398 print(($#{$difftree} + 1) . " files changed:\n");
2402 print "<table class=\"" .
2403 (@parents > 1 ? "combined " : "") .
2407 foreach my $line (@{$difftree}) {
2409 if (ref($line) eq "HASH") {
2410 # pre-parsed (or generated by hand)
2413 $diff = parse_difftree_raw_line
($line);
2417 print "<tr class=\"dark\">\n";
2419 print "<tr class=\"light\">\n";
2423 if (exists $diff->{'nparents'}) { # combined diff
2425 fill_from_file_info
($diff, @parents)
2426 unless exists $diff->{'from_file'};
2428 if ($diff->{'to_id'} ne ('0' x
40)) {
2429 # file exists in the result (child) commit
2431 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2432 file_name
=>$diff->{'to_file'},
2434 -class => "list"}, esc_path
($diff->{'to_file'})) .
2438 esc_path
($diff->{'to_file'}) .
2442 if ($action eq 'commitdiff') {
2445 print "<td class=\"link\">" .
2446 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2451 my $has_history = 0;
2452 my $not_deleted = 0;
2453 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2454 my $hash_parent = $parents[$i];
2455 my $from_hash = $diff->{'from_id'}[$i];
2456 my $from_path = $diff->{'from_file'}[$i];
2457 my $status = $diff->{'status'}[$i];
2459 $has_history ||= ($status ne 'A');
2460 $not_deleted ||= ($status ne 'D');
2462 if ($status eq 'A') {
2463 print "<td class=\"link\" align=\"right\"> | </td>\n";
2464 } elsif ($status eq 'D') {
2465 print "<td class=\"link\">" .
2466 $cgi->a({-href
=> href
(action
=>"blob",
2469 file_name
=>$from_path)},
2473 if ($diff->{'to_id'} eq $from_hash) {
2474 print "<td class=\"link nochange\">";
2476 print "<td class=\"link\">";
2478 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2479 hash
=>$diff->{'to_id'},
2480 hash_parent
=>$from_hash,
2482 hash_parent_base
=>$hash_parent,
2483 file_name
=>$diff->{'to_file'},
2484 file_parent
=>$from_path)},
2490 print "<td class=\"link\">";
2492 print $cgi->a({-href
=> href
(action
=>"blob",
2493 hash
=>$diff->{'to_id'},
2494 file_name
=>$diff->{'to_file'},
2497 print " | " if ($has_history);
2500 print $cgi->a({-href
=> href
(action
=>"history",
2501 file_name
=>$diff->{'to_file'},
2508 next; # instead of 'else' clause, to avoid extra indent
2510 # else ordinary diff
2512 my ($to_mode_oct, $to_mode_str, $to_file_type);
2513 my ($from_mode_oct, $from_mode_str, $from_file_type);
2514 if ($diff->{'to_mode'} ne ('0' x
6)) {
2515 $to_mode_oct = oct $diff->{'to_mode'};
2516 if (S_ISREG
($to_mode_oct)) { # only for regular file
2517 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2519 $to_file_type = file_type
($diff->{'to_mode'});
2521 if ($diff->{'from_mode'} ne ('0' x
6)) {
2522 $from_mode_oct = oct $diff->{'from_mode'};
2523 if (S_ISREG
($to_mode_oct)) { # only for regular file
2524 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2526 $from_file_type = file_type
($diff->{'from_mode'});
2529 if ($diff->{'status'} eq "A") { # created
2530 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2531 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2532 $mode_chng .= "]</span>";
2534 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2535 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2536 -class => "list"}, esc_path
($diff->{'file'}));
2538 print "<td>$mode_chng</td>\n";
2539 print "<td class=\"link\">";
2540 if ($action eq 'commitdiff') {
2543 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2546 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2547 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2551 } elsif ($diff->{'status'} eq "D") { # deleted
2552 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2554 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2555 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2556 -class => "list"}, esc_path
($diff->{'file'}));
2558 print "<td>$mode_chng</td>\n";
2559 print "<td class=\"link\">";
2560 if ($action eq 'commitdiff') {
2563 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2566 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2567 hash_base
=>$parent, file_name
=>$diff->{'file'})},
2570 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2571 file_name
=>$diff->{'file'})},
2574 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2575 file_name
=>$diff->{'file'})},
2579 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2580 my $mode_chnge = "";
2581 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2582 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2583 if ($from_file_type ne $to_file_type) {
2584 $mode_chnge .= " from $from_file_type to $to_file_type";
2586 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2587 if ($from_mode_str && $to_mode_str) {
2588 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2589 } elsif ($to_mode_str) {
2590 $mode_chnge .= " mode: $to_mode_str";
2593 $mode_chnge .= "]</span>\n";
2596 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2597 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2598 -class => "list"}, esc_path
($diff->{'file'}));
2600 print "<td>$mode_chnge</td>\n";
2601 print "<td class=\"link\">";
2602 if ($action eq 'commitdiff') {
2605 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2607 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2608 # "commit" view and modified file (not onlu mode changed)
2609 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2610 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2611 hash_base
=>$hash, hash_parent_base
=>$parent,
2612 file_name
=>$diff->{'file'})},
2616 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2617 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2620 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2621 file_name
=>$diff->{'file'})},
2624 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2625 file_name
=>$diff->{'file'})},
2629 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
2630 my %status_name = ('R' => 'moved', 'C' => 'copied');
2631 my $nstatus = $status_name{$diff->{'status'}};
2633 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2634 # mode also for directories, so we cannot use $to_mode_str
2635 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2638 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2639 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
2640 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
2641 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2642 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2643 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
2644 -class => "list"}, esc_path
($diff->{'from_file'})) .
2645 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2646 "<td class=\"link\">";
2647 if ($action eq 'commitdiff') {
2650 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2652 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2653 # "commit" view and modified file (not only pure rename or copy)
2654 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2655 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2656 hash_base
=>$hash, hash_parent_base
=>$parent,
2657 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
2661 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2662 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
2665 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2666 file_name
=>$diff->{'to_file'})},
2669 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2670 file_name
=>$diff->{'to_file'})},
2674 } # we should not encounter Unmerged (U) or Unknown (X) status
2680 sub git_patchset_body
{
2681 my ($fd, $difftree, $hash, @hash_parents) = @_;
2682 my ($hash_parent) = $hash_parents[0];
2685 my $patch_number = 0;
2690 print "<div class=\"patchset\">\n";
2692 # skip to first patch
2693 while ($patch_line = <$fd>) {
2696 last if ($patch_line =~ m/^diff /);
2700 while ($patch_line) {
2702 my ($from_id, $to_id);
2705 #assert($patch_line =~ m/^diff /) if DEBUG;
2706 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2708 push @diff_header, $patch_line;
2710 # extended diff header
2712 while ($patch_line = <$fd>) {
2715 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2717 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2720 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2721 $from_id = [ split(',', $1) ];
2725 push @diff_header, $patch_line;
2727 my $last_patch_line = $patch_line;
2729 # check if current patch belong to current raw line
2730 # and parse raw git-diff line if needed
2731 if (defined $diffinfo &&
2732 defined $from_id && defined $to_id &&
2733 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
2734 $diffinfo->{'to_id'} eq $to_id) {
2735 # this is continuation of a split patch
2736 print "<div class=\"patch cont\">\n";
2738 # advance raw git-diff output if needed
2739 $patch_idx++ if defined $diffinfo;
2741 # read and prepare patch information
2742 if (ref($difftree->[$patch_idx]) eq "HASH") {
2743 # pre-parsed (or generated by hand)
2744 $diffinfo = $difftree->[$patch_idx];
2746 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2748 if ($diffinfo->{'nparents'}) {
2752 fill_from_file_info
($diffinfo, @hash_parents)
2753 unless exists $diffinfo->{'from_file'};
2754 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2755 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2756 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2757 $from{'href'}[$i] = href
(action
=>"blob",
2758 hash_base
=>$hash_parents[$i],
2759 hash
=>$diffinfo->{'from_id'}[$i],
2760 file_name
=>$from{'file'}[$i]);
2762 $from{'href'}[$i] = undef;
2766 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2767 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2768 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2769 hash
=>$diffinfo->{'from_id'},
2770 file_name
=>$from{'file'});
2772 delete $from{'href'};
2776 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2777 if ($diffinfo->{'to_id'} ne ('0' x
40)) { # file exists in result
2778 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2779 hash
=>$diffinfo->{'to_id'},
2780 file_name
=>$to{'file'});
2784 # this is first patch for raw difftree line with $patch_idx index
2785 # we index @$difftree array from 0, but number patches from 1
2786 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2789 # print "git diff" header
2790 $patch_line = shift @diff_header;
2791 if ($diffinfo->{'nparents'}) {
2794 $patch_line =~ s!^(diff (.*?) )"?.*$!$1!;
2796 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2797 esc_path
($to{'file'}));
2798 } else { # file was deleted
2799 $patch_line .= esc_path
($to{'file'});
2804 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2805 if ($from{'href'}) {
2806 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2807 'a/' . esc_path
($from{'file'}));
2808 } else { # file was added
2809 $patch_line .= 'a/' . esc_path
($from{'file'});
2813 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2814 'b/' . esc_path
($to{'file'}));
2815 } else { # file was deleted
2816 $patch_line .= 'b/' . esc_path
($to{'file'});
2820 print "<div class=\"diff header\">$patch_line</div>\n";
2822 # print extended diff header
2823 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2825 foreach $patch_line (@diff_header) {
2827 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2828 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2829 esc_path
($from{'file'}));
2831 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2832 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2833 esc_path
($to{'file'}));
2835 # match single <mode>
2836 if ($patch_line =~ m/\s(\d{6})$/) {
2837 $patch_line .= '<span class="info"> (' .
2838 file_type_long
($1) .
2842 if ($patch_line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
2843 # can match only for combined diff
2844 $patch_line = 'index ';
2845 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2846 if ($from{'href'}[$i]) {
2847 $patch_line .= $cgi->a({-href
=>$from{'href'}[$i],
2849 substr($diffinfo->{'from_id'}[$i],0,7));
2851 $patch_line .= '0' x
7;
2854 $patch_line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
2856 $patch_line .= '..';
2858 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2859 substr($diffinfo->{'to_id'},0,7));
2861 $patch_line .= '0' x
7;
2864 } elsif ($patch_line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
2865 # can match only for ordinary diff
2866 my ($from_link, $to_link);
2867 if ($from{'href'}) {
2868 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2869 substr($diffinfo->{'from_id'},0,7));
2871 $from_link = '0' x
7;
2874 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2875 substr($diffinfo->{'to_id'},0,7));
2880 # my ($from_hash, $to_hash) =
2881 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2882 # my ($from_id, $to_id) =
2883 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2884 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2886 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2887 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2889 print $patch_line . "<br/>\n";
2891 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2893 # from-file/to-file diff header
2894 $patch_line = $last_patch_line;
2895 if (! $patch_line) {
2896 print "</div>\n"; # class="patch"
2899 next PATCH
if ($patch_line =~ m/^diff /);
2900 #assert($patch_line =~ m/^---/) if DEBUG;
2901 if (!$diffinfo->{'nparents'} && # not from-file line for combined diff
2902 $from{'href'} && $patch_line =~ m!^--- "?a/!) {
2903 $patch_line = '--- a/' .
2904 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2905 esc_path
($from{'file'}));
2907 print "<div class=\"diff from_file\">$patch_line</div>\n";
2909 $patch_line = <$fd>;
2912 #assert($patch_line =~ m/^+++/) if DEBUG;
2913 if ($to{'href'} && $patch_line =~ m!^\+\+\+ "?b/!) {
2914 $patch_line = '+++ b/' .
2915 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2916 esc_path
($to{'file'}));
2918 print "<div class=\"diff to_file\">$patch_line</div>\n";
2922 while ($patch_line = <$fd>) {
2925 next PATCH
if ($patch_line =~ m/^diff /);
2927 print format_diff_line
($patch_line, \
%from, \
%to);
2931 print "</div>\n"; # class="patch"
2934 if ($patch_number == 0) {
2935 if (@hash_parents > 1) {
2936 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
2938 print "<div class=\"diff nodifferences\">No differences found</div>\n";
2942 print "</div>\n"; # class="patchset"
2945 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2947 sub git_project_list_body
{
2948 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2950 my ($check_forks) = gitweb_check_feature
('forks');
2953 foreach my $pr (@$projlist) {
2954 my (@aa) = git_get_last_activity
($pr->{'path'});
2958 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2959 if (!defined $pr->{'descr'}) {
2960 my $descr = git_get_project_description
($pr->{'path'}) || "";
2961 $pr->{'descr_long'} = to_utf8
($descr);
2962 $pr->{'descr'} = chop_str
($descr, 25, 5);
2964 if (!defined $pr->{'owner'}) {
2965 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2968 my $pname = $pr->{'path'};
2969 if (($pname =~ s/\.git$//) &&
2970 ($pname !~ /\/$/) &&
2971 (-d
"$projectroot/$pname")) {
2972 $pr->{'forks'} = "-d $projectroot/$pname";
2978 push @projects, $pr;
2981 $order ||= $default_projects_order;
2982 $from = 0 unless defined $from;
2983 $to = $#projects if (!defined $to || $#projects < $to);
2985 print "<table class=\"project_list\">\n";
2986 unless ($no_header) {
2989 print "<th></th>\n";
2991 if ($order eq "project") {
2992 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2993 print "<th>Project</th>\n";
2996 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2997 -class => "header"}, "Project") .
3000 if ($order eq "descr") {
3001 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3002 print "<th>Description</th>\n";
3005 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3006 -class => "header"}, "Description") .
3009 if ($order eq "owner") {
3010 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3011 print "<th>Owner</th>\n";
3014 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3015 -class => "header"}, "Owner") .
3018 if ($order eq "age") {
3019 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3020 print "<th>Last Change</th>\n";
3023 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3024 -class => "header"}, "Last Change") .
3027 print "<th></th>\n" .
3031 for (my $i = $from; $i <= $to; $i++) {
3032 my $pr = $projects[$i];
3034 print "<tr class=\"dark\">\n";
3036 print "<tr class=\"light\">\n";
3041 if ($pr->{'forks'}) {
3042 print "<!-- $pr->{'forks'} -->\n";
3043 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3047 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3048 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3049 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3050 -class => "list", -title
=> $pr->{'descr_long'}},
3051 esc_html
($pr->{'descr'})) . "</td>\n" .
3052 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
3053 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3054 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3055 "<td class=\"link\">" .
3056 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3057 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3058 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3059 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3060 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3064 if (defined $extra) {
3067 print "<td></td>\n";
3069 print "<td colspan=\"5\">$extra</td>\n" .
3075 sub git_shortlog_body
{
3076 # uses global variable $project
3077 my ($commitlist, $from, $to, $refs, $extra) = @_;
3079 my $have_snapshot = gitweb_have_snapshot
();
3081 $from = 0 unless defined $from;
3082 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3084 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3086 for (my $i = $from; $i <= $to; $i++) {
3087 my %co = %{$commitlist->[$i]};
3088 my $commit = $co{'id'};
3089 my $ref = format_ref_marker
($refs, $commit);
3091 print "<tr class=\"dark\">\n";
3093 print "<tr class=\"light\">\n";
3096 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3097 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3098 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3100 print format_subject_html
($co{'title'}, $co{'title_short'},
3101 href
(action
=>"commit", hash
=>$commit), $ref);
3103 "<td class=\"link\">" .
3104 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3105 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3106 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3107 if ($have_snapshot) {
3108 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
3113 if (defined $extra) {
3115 "<td colspan=\"4\">$extra</td>\n" .
3121 sub git_history_body
{
3122 # Warning: assumes constant type (blob or tree) during history
3123 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3125 $from = 0 unless defined $from;
3126 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3128 print "<table class=\"history\" cellspacing=\"0\">\n";
3130 for (my $i = $from; $i <= $to; $i++) {
3131 my %co = %{$commitlist->[$i]};
3135 my $commit = $co{'id'};
3137 my $ref = format_ref_marker
($refs, $commit);
3140 print "<tr class=\"dark\">\n";
3142 print "<tr class=\"light\">\n";
3145 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3146 # shortlog uses chop_str($co{'author_name'}, 10)
3147 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3149 # originally git_history used chop_str($co{'title'}, 50)
3150 print format_subject_html
($co{'title'}, $co{'title_short'},
3151 href
(action
=>"commit", hash
=>$commit), $ref);
3153 "<td class=\"link\">" .
3154 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3155 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3157 if ($ftype eq 'blob') {
3158 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3159 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3160 if (defined $blob_current && defined $blob_parent &&
3161 $blob_current ne $blob_parent) {
3163 $cgi->a({-href
=> href
(action
=>"blobdiff",
3164 hash
=>$blob_current, hash_parent
=>$blob_parent,
3165 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3166 file_name
=>$file_name)},
3173 if (defined $extra) {
3175 "<td colspan=\"4\">$extra</td>\n" .
3182 # uses global variable $project
3183 my ($taglist, $from, $to, $extra) = @_;
3184 $from = 0 unless defined $from;
3185 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3187 print "<table class=\"tags\" cellspacing=\"0\">\n";
3189 for (my $i = $from; $i <= $to; $i++) {
3190 my $entry = $taglist->[$i];
3192 my $comment = $tag{'subject'};
3194 if (defined $comment) {
3195 $comment_short = chop_str
($comment, 30, 5);
3198 print "<tr class=\"dark\">\n";
3200 print "<tr class=\"light\">\n";
3203 if (defined $tag{'age'}) {
3204 print "<td><i>$tag{'age'}</i></td>\n";
3206 print "<td></td>\n";
3209 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3210 -class => "list name"}, esc_html
($tag{'name'})) .
3213 if (defined $comment) {
3214 print format_subject_html
($comment, $comment_short,
3215 href
(action
=>"tag", hash
=>$tag{'id'}));
3218 "<td class=\"selflink\">";
3219 if ($tag{'type'} eq "tag") {
3220 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3225 "<td class=\"link\">" . " | " .
3226 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3227 if ($tag{'reftype'} eq "commit") {
3228 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3229 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3230 } elsif ($tag{'reftype'} eq "blob") {
3231 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3236 if (defined $extra) {
3238 "<td colspan=\"5\">$extra</td>\n" .
3244 sub git_heads_body
{
3245 # uses global variable $project
3246 my ($headlist, $head, $from, $to, $extra) = @_;
3247 $from = 0 unless defined $from;
3248 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3250 print "<table class=\"heads\" cellspacing=\"0\">\n";
3252 for (my $i = $from; $i <= $to; $i++) {
3253 my $entry = $headlist->[$i];
3255 my $curr = $ref{'id'} eq $head;
3257 print "<tr class=\"dark\">\n";
3259 print "<tr class=\"light\">\n";
3262 print "<td><i>$ref{'age'}</i></td>\n" .
3263 ($curr ? "<td class=\"current_head\">" : "<td>") .
3264 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3265 -class => "list name"},esc_html
($ref{'name'})) .
3267 "<td class=\"link\">" .
3268 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3269 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3270 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3274 if (defined $extra) {
3276 "<td colspan=\"3\">$extra</td>\n" .
3282 sub git_search_grep_body
{
3283 my ($commitlist, $from, $to, $extra) = @_;
3284 $from = 0 unless defined $from;
3285 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3287 print "<table class=\"grep\" cellspacing=\"0\">\n";
3289 for (my $i = $from; $i <= $to; $i++) {
3290 my %co = %{$commitlist->[$i]};
3294 my $commit = $co{'id'};
3296 print "<tr class=\"dark\">\n";
3298 print "<tr class=\"light\">\n";
3301 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3302 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3304 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3305 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3306 my $comment = $co{'comment'};
3307 foreach my $line (@$comment) {
3308 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3309 my $lead = esc_html
($1) || "";
3310 $lead = chop_str
($lead, 30, 10);
3311 my $match = esc_html
($2) || "";
3312 my $trail = esc_html
($3) || "";
3313 $trail = chop_str
($trail, 30, 10);
3314 my $text = "$lead<span class=\"match\">$match</span>$trail";
3315 print chop_str
($text, 80, 5) . "<br/>\n";
3319 "<td class=\"link\">" .
3320 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3322 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3326 if (defined $extra) {
3328 "<td colspan=\"3\">$extra</td>\n" .
3334 ## ======================================================================
3335 ## ======================================================================
3338 sub git_project_list
{
3339 my $order = $cgi->param('o');
3340 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3341 die_error
(undef, "Unknown order parameter");
3344 my @list = git_get_projects_list
();
3346 die_error
(undef, "No projects found");
3350 if (-f
$home_text) {
3351 print "<div class=\"index_include\">\n";
3352 open (my $fd, $home_text);
3357 git_project_list_body
(\
@list, $order);
3362 my $order = $cgi->param('o');
3363 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3364 die_error
(undef, "Unknown order parameter");
3367 my @list = git_get_projects_list
($project);
3369 die_error
(undef, "No forks found");
3373 git_print_page_nav
('','');
3374 git_print_header_div
('summary', "$project forks");
3375 git_project_list_body
(\
@list, $order);
3379 sub git_project_index
{
3380 my @projects = git_get_projects_list
($project);
3383 -type
=> 'text/plain',
3384 -charset
=> 'utf-8',
3385 -content_disposition
=> 'inline; filename="index.aux"');
3387 foreach my $pr (@projects) {
3388 if (!exists $pr->{'owner'}) {
3389 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3392 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3393 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3394 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3395 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3399 print "$path $owner\n";
3404 my $descr = git_get_project_description
($project) || "none";
3405 my %co = parse_commit
("HEAD");
3406 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3407 my $head = $co{'id'};
3409 my $owner = git_get_project_owner
($project);
3411 my $refs = git_get_references
();
3412 # These get_*_list functions return one more to allow us to see if
3413 # there are more ...
3414 my @taglist = git_get_tags_list
(16);
3415 my @headlist = git_get_heads_list
(16);
3417 my ($check_forks) = gitweb_check_feature
('forks');
3420 @forklist = git_get_projects_list
($project);
3424 git_print_page_nav
('summary','', $head);
3426 print "<div class=\"title\"> </div>\n";
3427 print "<table cellspacing=\"0\">\n" .
3428 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3429 "<tr><td>owner</td><td>$owner</td></tr>\n";
3430 if (defined $cd{'rfc2822'}) {
3431 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3434 # use per project git URL list in $projectroot/$project/cloneurl
3435 # or make project git URL from git base URL and project name
3436 my $url_tag = "URL";
3437 my @url_list = git_get_project_url_list
($project);
3438 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3439 foreach my $git_url (@url_list) {
3440 next unless $git_url;
3441 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3446 if (-s
"$projectroot/$project/README.html") {
3447 if (open my $fd, "$projectroot/$project/README.html") {
3448 print "<div class=\"title\">readme</div>\n";
3449 print $_ while (<$fd>);
3454 # we need to request one more than 16 (0..15) to check if
3456 my @commitlist = $head ? parse_commits
($head, 17) : ();
3458 git_print_header_div
('shortlog');
3459 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3460 $#commitlist <= 15 ? undef :
3461 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3465 git_print_header_div
('tags');
3466 git_tags_body
(\
@taglist, 0, 15,
3467 $#taglist <= 15 ? undef :
3468 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3472 git_print_header_div
('heads');
3473 git_heads_body
(\
@headlist, $head, 0, 15,
3474 $#headlist <= 15 ? undef :
3475 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3479 git_print_header_div
('forks');
3480 git_project_list_body
(\
@forklist, undef, 0, 15,
3481 $#forklist <= 15 ? undef :
3482 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3490 my $head = git_get_head_hash
($project);
3492 git_print_page_nav
('','', $head,undef,$head);
3493 my %tag = parse_tag
($hash);
3496 die_error
(undef, "Unknown tag object");
3499 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3500 print "<div class=\"title_text\">\n" .
3501 "<table cellspacing=\"0\">\n" .
3503 "<td>object</td>\n" .
3504 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3505 $tag{'object'}) . "</td>\n" .
3506 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3507 $tag{'type'}) . "</td>\n" .
3509 if (defined($tag{'author'})) {
3510 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3511 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3512 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3513 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3516 print "</table>\n\n" .
3518 print "<div class=\"page_body\">";
3519 my $comment = $tag{'comment'};
3520 foreach my $line (@$comment) {
3522 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3532 my ($have_blame) = gitweb_check_feature
('blame');
3534 die_error
('403 Permission denied', "Permission denied");
3536 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3537 $hash_base ||= git_get_head_hash
($project);
3538 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3539 my %co = parse_commit
($hash_base)
3540 or die_error
(undef, "Reading commit failed");
3541 if (!defined $hash) {
3542 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3543 or die_error
(undef, "Error looking up file");
3545 $ftype = git_get_type
($hash);
3546 if ($ftype !~ "blob") {
3547 die_error
('400 Bad Request', "Object is not a blob");
3549 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3550 $file_name, $hash_base)
3551 or die_error
(undef, "Open git-blame failed");
3554 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3557 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3560 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3562 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3563 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3564 git_print_page_path
($file_name, $ftype, $hash_base);
3565 my @rev_color = (qw(light2 dark2));
3566 my $num_colors = scalar(@rev_color);
3567 my $current_color = 0;
3570 <div class="page_body">
3571 <table class="blame">
3572 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3577 last unless defined $_;
3578 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3579 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3580 if (!exists $metainfo{$full_rev}) {
3581 $metainfo{$full_rev} = {};
3583 my $meta = $metainfo{$full_rev};
3586 if (/^(\S+) (.*)$/) {
3592 my $rev = substr($full_rev, 0, 8);
3593 my $author = $meta->{'author'};
3594 my %date = parse_date
($meta->{'author-time'},
3595 $meta->{'author-tz'});
3596 my $date = $date{'iso-tz'};
3598 $current_color = ++$current_color % $num_colors;
3600 print "<tr class=\"$rev_color[$current_color]\">\n";
3602 print "<td class=\"sha1\"";
3603 print " title=\"". esc_html
($author) . ", $date\"";
3604 print " rowspan=\"$group_size\"" if ($group_size > 1);
3606 print $cgi->a({-href
=> href
(action
=>"commit",
3608 file_name
=>$file_name)},
3612 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3613 or die_error
(undef, "Open git-rev-parse failed");
3614 my $parent_commit = <$dd>;
3616 chomp($parent_commit);
3617 my $blamed = href
(action
=> 'blame',
3618 file_name
=> $meta->{'filename'},
3619 hash_base
=> $parent_commit);
3620 print "<td class=\"linenr\">";
3621 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3623 -class => "linenr" },
3626 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3632 or print "Reading blob failed\n";
3639 my ($have_blame) = gitweb_check_feature
('blame');
3641 die_error
('403 Permission denied', "Permission denied");
3643 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3644 $hash_base ||= git_get_head_hash
($project);
3645 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3646 my %co = parse_commit
($hash_base)
3647 or die_error
(undef, "Reading commit failed");
3648 if (!defined $hash) {
3649 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3650 or die_error
(undef, "Error lookup file");
3652 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3653 or die_error
(undef, "Open git-annotate failed");
3656 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3659 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3662 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3664 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3665 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3666 git_print_page_path
($file_name, 'blob', $hash_base);
3667 print "<div class=\"page_body\">\n";
3669 <table class="blame">
3678 my @line_class = (qw(light dark));
3679 my $line_class_len = scalar (@line_class);
3680 my $line_class_num = $#line_class;
3681 while (my $line = <$fd>) {
3693 $line_class_num = ($line_class_num + 1) % $line_class_len;
3695 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3702 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3705 $short_rev = substr ($long_rev, 0, 8);
3706 $age = time () - $time;
3707 $age_str = age_string
($age);
3708 $age_str =~ s/ / /g;
3709 $age_class = age_class
($age);
3710 $author = esc_html
($author);
3711 $author =~ s/ / /g;
3713 $data = untabify
($data);
3714 $data = esc_html
($data);
3717 <tr class="$line_class[$line_class_num]">
3718 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3719 <td class="$age_class">$age_str</td>
3721 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3722 <td class="pre">$data</td>
3725 } # while (my $line = <$fd>)
3726 print "</table>\n\n";
3728 or print "Reading blob failed.\n";
3734 my $head = git_get_head_hash
($project);
3736 git_print_page_nav
('','', $head,undef,$head);
3737 git_print_header_div
('summary', $project);
3739 my @tagslist = git_get_tags_list
();
3741 git_tags_body
(\
@tagslist);
3747 my $head = git_get_head_hash
($project);
3749 git_print_page_nav
('','', $head,undef,$head);
3750 git_print_header_div
('summary', $project);
3752 my @headslist = git_get_heads_list
();
3754 git_heads_body
(\
@headslist, $head);
3759 sub git_blob_plain
{
3762 if (!defined $hash) {
3763 if (defined $file_name) {
3764 my $base = $hash_base || git_get_head_hash
($project);
3765 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3766 or die_error
(undef, "Error lookup file");
3768 die_error
(undef, "No file name defined");
3770 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3771 # blobs defined by non-textual hash id's can be cached
3776 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3777 or die_error
(undef, "Couldn't cat $file_name, $hash");
3779 $type ||= blob_mimetype
($fd, $file_name);
3781 # save as filename, even when no $file_name is given
3782 my $save_as = "$hash";
3783 if (defined $file_name) {
3784 $save_as = $file_name;
3785 } elsif ($type =~ m/^text\//) {
3792 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3794 binmode STDOUT
, ':raw';
3796 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3804 if (!defined $hash) {
3805 if (defined $file_name) {
3806 my $base = $hash_base || git_get_head_hash
($project);
3807 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3808 or die_error
(undef, "Error lookup file");
3810 die_error
(undef, "No file name defined");
3812 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3813 # blobs defined by non-textual hash id's can be cached
3817 my ($have_blame) = gitweb_check_feature
('blame');
3818 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3819 or die_error
(undef, "Couldn't cat $file_name, $hash");
3820 my $mimetype = blob_mimetype
($fd, $file_name);
3821 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3823 return git_blob_plain
($mimetype);
3825 # we can have blame only for text/* mimetype
3826 $have_blame &&= ($mimetype =~ m!^text/!);
3828 git_header_html
(undef, $expires);
3829 my $formats_nav = '';
3830 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3831 if (defined $file_name) {
3834 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3835 hash
=>$hash, file_name
=>$file_name)},
3840 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3841 hash
=>$hash, file_name
=>$file_name)},
3844 $cgi->a({-href
=> href
(action
=>"blob_plain",
3845 hash
=>$hash, file_name
=>$file_name)},
3848 $cgi->a({-href
=> href
(action
=>"blob",
3849 hash_base
=>"HEAD", file_name
=>$file_name)},
3853 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3855 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3856 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3858 print "<div class=\"page_nav\">\n" .
3859 "<br/><br/></div>\n" .
3860 "<div class=\"title\">$hash</div>\n";
3862 git_print_page_path
($file_name, "blob", $hash_base);
3863 print "<div class=\"page_body\">\n";
3864 if ($mimetype =~ m!^text/!) {
3866 while (my $line = <$fd>) {
3869 $line = untabify
($line);
3870 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3871 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3873 } elsif ($mimetype =~ m!^image/!) {
3874 print qq
!<img type
="$mimetype"!;
3876 print qq
! alt
="$file_name" title
="$file_name"!;
3879 href(action=>"blob_plain
", hash=>$hash,
3880 hash_base=>$hash_base, file_name=>$file_name) .
3884 or print "Reading blob failed.\n";
3890 my $have_snapshot = gitweb_have_snapshot
();
3892 if (!defined $hash_base) {
3893 $hash_base = "HEAD";
3895 if (!defined $hash) {
3896 if (defined $file_name) {
3897 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3903 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3904 or die_error
(undef, "Open git-ls-tree failed");
3905 my @entries = map { chomp; $_ } <$fd>;
3906 close $fd or die_error
(undef, "Reading tree failed");
3909 my $refs = git_get_references
();
3910 my $ref = format_ref_marker
($refs, $hash_base);
3913 my ($have_blame) = gitweb_check_feature
('blame');
3914 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3916 if (defined $file_name) {
3918 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3919 hash
=>$hash, file_name
=>$file_name)},
3921 $cgi->a({-href
=> href
(action
=>"tree",
3922 hash_base
=>"HEAD", file_name
=>$file_name)},
3925 if ($have_snapshot) {
3926 # FIXME: Should be available when we have no hash base as well.
3928 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3931 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3932 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3935 print "<div class=\"page_nav\">\n";
3936 print "<br/><br/></div>\n";
3937 print "<div class=\"title\">$hash</div>\n";
3939 if (defined $file_name) {
3940 $basedir = $file_name;
3941 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3945 git_print_page_path
($file_name, 'tree', $hash_base);
3946 print "<div class=\"page_body\">\n";
3947 print "<table cellspacing=\"0\">\n";
3949 # '..' (top directory) link if possible
3950 if (defined $hash_base &&
3951 defined $file_name && $file_name =~ m![^/]+$!) {
3953 print "<tr class=\"dark\">\n";
3955 print "<tr class=\"light\">\n";
3959 my $up = $file_name;
3960 $up =~ s!/?[^/]+$!!;
3961 undef $up unless $up;
3962 # based on git_print_tree_entry
3963 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3964 print '<td class="list">';
3965 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3969 print "<td class=\"link\"></td>\n";
3973 foreach my $line (@entries) {
3974 my %t = parse_ls_tree_line
($line, -z
=> 1);
3977 print "<tr class=\"dark\">\n";
3979 print "<tr class=\"light\">\n";
3983 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3987 print "</table>\n" .
3993 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3994 my $have_snapshot = (defined $ctype && defined $suffix);
3995 if (!$have_snapshot) {
3996 die_error
('403 Permission denied', "Permission denied");
3999 if (!defined $hash) {
4000 $hash = git_get_head_hash
($project);
4003 my $git = git_cmd_str
();
4004 my $name = $project;
4005 $name =~ s/\047/\047\\\047\047/g;
4006 my $filename = to_utf8
(basename
($project));
4008 if ($suffix eq 'zip') {
4009 $filename .= "-$hash.$suffix";
4010 $cmd = "$git archive --format=zip --prefix=\'$name\'/ $hash";
4012 $filename .= "-$hash.tar.$suffix";
4013 $cmd = "$git archive --format=tar --prefix=\'$name\'/ $hash | $command";
4017 -type
=> "application/$ctype",
4018 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4019 -status
=> '200 OK');
4021 open my $fd, "-|", $cmd
4022 or die_error
(undef, "Execute git-archive failed");
4023 binmode STDOUT
, ':raw';
4025 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4031 my $head = git_get_head_hash
($project);
4032 if (!defined $hash) {
4035 if (!defined $page) {
4038 my $refs = git_get_references
();
4040 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4042 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4045 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4048 my %co = parse_commit
($hash);
4050 git_print_header_div
('summary', $project);
4051 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4053 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4054 for (my $i = 0; $i <= $to; $i++) {
4055 my %co = %{$commitlist[$i]};
4057 my $commit = $co{'id'};
4058 my $ref = format_ref_marker
($refs, $commit);
4059 my %ad = parse_date
($co{'author_epoch'});
4060 git_print_header_div
('commit',
4061 "<span class=\"age\">$co{'age_string'}</span>" .
4062 esc_html
($co{'title'}) . $ref,
4064 print "<div class=\"title_text\">\n" .
4065 "<div class=\"log_link\">\n" .
4066 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4068 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4070 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4073 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4076 print "<div class=\"log_body\">\n";
4077 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4080 if ($#commitlist >= 100) {
4081 print "<div class=\"page_nav\">\n";
4082 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4083 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4090 $hash ||= $hash_base || "HEAD";
4091 my %co = parse_commit
($hash);
4093 die_error
(undef, "Unknown commit object");
4095 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4096 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4098 my $parent = $co{'parent'};
4099 my $parents = $co{'parents'}; # listref
4101 # we need to prepare $formats_nav before any parameter munging
4103 if (!defined $parent) {
4105 $formats_nav .= '(initial)';
4106 } elsif (@$parents == 1) {
4107 # single parent commit
4110 $cgi->a({-href
=> href
(action
=>"commit",
4112 esc_html
(substr($parent, 0, 7))) .
4119 $cgi->a({-href
=> href
(action
=>"commit",
4121 esc_html
(substr($_, 0, 7)));
4126 if (!defined $parent) {
4130 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4132 (@$parents <= 1 ? $parent : '-c'),
4134 or die_error
(undef, "Open git-diff-tree failed");
4135 @difftree = map { chomp; $_ } <$fd>;
4136 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4138 # non-textual hash id's can be cached
4140 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4143 my $refs = git_get_references
();
4144 my $ref = format_ref_marker
($refs, $co{'id'});
4146 my $have_snapshot = gitweb_have_snapshot
();
4148 git_header_html
(undef, $expires);
4149 git_print_page_nav
('commit', '',
4150 $hash, $co{'tree'}, $hash,
4153 if (defined $co{'parent'}) {
4154 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4156 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4158 print "<div class=\"title_text\">\n" .
4159 "<table cellspacing=\"0\">\n";
4160 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4162 "<td></td><td> $ad{'rfc2822'}";
4163 if ($ad{'hour_local'} < 6) {
4164 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4165 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4167 printf(" (%02d:%02d %s)",
4168 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4172 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4173 print "<tr><td></td><td> $cd{'rfc2822'}" .
4174 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4176 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4179 "<td class=\"sha1\">" .
4180 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4181 class => "list"}, $co{'tree'}) .
4183 "<td class=\"link\">" .
4184 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4186 if ($have_snapshot) {
4188 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
4193 foreach my $par (@$parents) {
4196 "<td class=\"sha1\">" .
4197 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4198 class => "list"}, $par) .
4200 "<td class=\"link\">" .
4201 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4203 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4210 print "<div class=\"page_body\">\n";
4211 git_print_log
($co{'comment'});
4214 git_difftree_body
(\
@difftree, $hash, @$parents);
4220 # object is defined by:
4221 # - hash or hash_base alone
4222 # - hash_base and file_name
4225 # - hash or hash_base alone
4226 if ($hash || ($hash_base && !defined $file_name)) {
4227 my $object_id = $hash || $hash_base;
4229 my $git_command = git_cmd_str
();
4230 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4231 or die_error
('404 Not Found', "Object does not exist");
4235 or die_error
('404 Not Found', "Object does not exist");
4237 # - hash_base and file_name
4238 } elsif ($hash_base && defined $file_name) {
4239 $file_name =~ s
,/+$,,;
4241 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4242 or die_error
('404 Not Found', "Base object does not exist");
4244 # here errors should not hapen
4245 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4246 or die_error
(undef, "Open git-ls-tree failed");
4250 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4251 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4252 die_error
('404 Not Found', "File or directory for given base does not exist");
4257 die_error
('404 Not Found', "Not enough information to find object");
4260 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4261 hash
=>$hash, hash_base
=>$hash_base,
4262 file_name
=>$file_name),
4263 -status
=> '302 Found');
4267 my $format = shift || 'html';
4274 # preparing $fd and %diffinfo for git_patchset_body
4276 if (defined $hash_base && defined $hash_parent_base) {
4277 if (defined $file_name) {
4279 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4280 $hash_parent_base, $hash_base,
4281 "--", (defined $file_parent ? $file_parent : ()), $file_name
4282 or die_error
(undef, "Open git-diff-tree failed");
4283 @difftree = map { chomp; $_ } <$fd>;
4285 or die_error
(undef, "Reading git-diff-tree failed");
4287 or die_error
('404 Not Found', "Blob diff not found");
4289 } elsif (defined $hash &&
4290 $hash =~ /[0-9a-fA-F]{40}/) {
4291 # try to find filename from $hash
4293 # read filtered raw output
4294 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4295 $hash_parent_base, $hash_base, "--"
4296 or die_error
(undef, "Open git-diff-tree failed");
4298 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4300 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4301 map { chomp; $_ } <$fd>;
4303 or die_error
(undef, "Reading git-diff-tree failed");
4305 or die_error
('404 Not Found', "Blob diff not found");
4308 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4311 if (@difftree > 1) {
4312 die_error
('404 Not Found', "Ambiguous blob diff specification");
4315 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4316 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4317 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4319 $hash_parent ||= $diffinfo{'from_id'};
4320 $hash ||= $diffinfo{'to_id'};
4322 # non-textual hash id's can be cached
4323 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4324 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4329 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4330 '-p', ($format eq 'html' ? "--full-index" : ()),
4331 $hash_parent_base, $hash_base,
4332 "--", (defined $file_parent ? $file_parent : ()), $file_name
4333 or die_error
(undef, "Open git-diff-tree failed");
4336 # old/legacy style URI
4337 if (!%diffinfo && # if new style URI failed
4338 defined $hash && defined $hash_parent) {
4339 # fake git-diff-tree raw output
4340 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4341 $diffinfo{'from_id'} = $hash_parent;
4342 $diffinfo{'to_id'} = $hash;
4343 if (defined $file_name) {
4344 if (defined $file_parent) {
4345 $diffinfo{'status'} = '2';
4346 $diffinfo{'from_file'} = $file_parent;
4347 $diffinfo{'to_file'} = $file_name;
4348 } else { # assume not renamed
4349 $diffinfo{'status'} = '1';
4350 $diffinfo{'from_file'} = $file_name;
4351 $diffinfo{'to_file'} = $file_name;
4353 } else { # no filename given
4354 $diffinfo{'status'} = '2';
4355 $diffinfo{'from_file'} = $hash_parent;
4356 $diffinfo{'to_file'} = $hash;
4359 # non-textual hash id's can be cached
4360 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4361 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4366 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4367 '-p', ($format eq 'html' ? "--full-index" : ()),
4368 $hash_parent, $hash, "--"
4369 or die_error
(undef, "Open git-diff failed");
4371 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4376 if ($format eq 'html') {
4378 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4379 hash
=>$hash, hash_parent
=>$hash_parent,
4380 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4381 file_name
=>$file_name, file_parent
=>$file_parent)},
4383 git_header_html
(undef, $expires);
4384 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4385 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4386 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4388 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4389 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4391 if (defined $file_name) {
4392 git_print_page_path
($file_name, "blob", $hash_base);
4394 print "<div class=\"page_path\"></div>\n";
4397 } elsif ($format eq 'plain') {
4399 -type
=> 'text/plain',
4400 -charset
=> 'utf-8',
4401 -expires
=> $expires,
4402 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4404 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4407 die_error
(undef, "Unknown blobdiff format");
4411 if ($format eq 'html') {
4412 print "<div class=\"page_body\">\n";
4414 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4417 print "</div>\n"; # class="page_body"
4421 while (my $line = <$fd>) {
4422 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4423 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4427 last if $line =~ m!^\+\+\+!;
4435 sub git_blobdiff_plain
{
4436 git_blobdiff
('plain');
4439 sub git_commitdiff
{
4440 my $format = shift || 'html';
4441 $hash ||= $hash_base || "HEAD";
4442 my %co = parse_commit
($hash);
4444 die_error
(undef, "Unknown commit object");
4447 # we need to prepare $formats_nav before any parameter munging
4449 if ($format eq 'html') {
4451 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4452 hash
=>$hash, hash_parent
=>$hash_parent)},
4455 if (defined $hash_parent) {
4456 # commitdiff with two commits given
4457 my $hash_parent_short = $hash_parent;
4458 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4459 $hash_parent_short = substr($hash_parent, 0, 7);
4463 $cgi->a({-href
=> href
(action
=>"commitdiff",
4464 hash
=>$hash_parent)},
4465 esc_html
($hash_parent_short)) .
4467 } elsif (!$co{'parent'}) {
4469 $formats_nav .= ' (initial)';
4470 } elsif (scalar @{$co{'parents'}} == 1) {
4471 # single parent commit
4474 $cgi->a({-href
=> href
(action
=>"commitdiff",
4475 hash
=>$co{'parent'})},
4476 esc_html
(substr($co{'parent'}, 0, 7))) .
4483 $cgi->a({-href
=> href
(action
=>"commitdiff",
4485 esc_html
(substr($_, 0, 7)));
4486 } @{$co{'parents'}} ) .
4491 my $hash_parent_param = $hash_parent;
4492 if (!defined $hash_parent) {
4493 $hash_parent_param =
4494 @{$co{'parents'}} > 1 ? '-c' : $co{'parent'} || '--root';
4500 if ($format eq 'html') {
4501 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4502 "--no-commit-id", "--patch-with-raw", "--full-index",
4503 $hash_parent_param, $hash, "--"
4504 or die_error
(undef, "Open git-diff-tree failed");
4506 while (my $line = <$fd>) {
4508 # empty line ends raw part of diff-tree output
4510 push @difftree, scalar parse_difftree_raw_line
($line);
4513 } elsif ($format eq 'plain') {
4514 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4515 '-p', $hash_parent_param, $hash, "--"
4516 or die_error
(undef, "Open git-diff-tree failed");
4519 die_error
(undef, "Unknown commitdiff format");
4522 # non-textual hash id's can be cached
4524 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4528 # write commit message
4529 if ($format eq 'html') {
4530 my $refs = git_get_references
();
4531 my $ref = format_ref_marker
($refs, $co{'id'});
4533 git_header_html
(undef, $expires);
4534 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4535 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4536 git_print_authorship
(\
%co);
4537 print "<div class=\"page_body\">\n";
4538 if (@{$co{'comment'}} > 1) {
4539 print "<div class=\"log\">\n";
4540 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4541 print "</div>\n"; # class="log"
4544 } elsif ($format eq 'plain') {
4545 my $refs = git_get_references
("tags");
4546 my $tagname = git_get_rev_name_tags
($hash);
4547 my $filename = basename
($project) . "-$hash.patch";
4550 -type
=> 'text/plain',
4551 -charset
=> 'utf-8',
4552 -expires
=> $expires,
4553 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4554 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4557 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4558 Subject: $co{'title'}
4560 print "X-Git-Tag: $tagname\n" if $tagname;
4561 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4563 foreach my $line (@{$co{'comment'}}) {
4570 if ($format eq 'html') {
4571 git_difftree_body
(\
@difftree, $hash, $hash_parent || @{$co{'parents'}});
4574 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent || @{$co{'parents'}});
4576 print "</div>\n"; # class="page_body"
4579 } elsif ($format eq 'plain') {
4583 or print "Reading git-diff-tree failed\n";
4587 sub git_commitdiff_plain
{
4588 git_commitdiff
('plain');
4592 if (!defined $hash_base) {
4593 $hash_base = git_get_head_hash
($project);
4595 if (!defined $page) {
4599 my %co = parse_commit
($hash_base);
4601 die_error
(undef, "Unknown commit object");
4604 my $refs = git_get_references
();
4605 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4607 if (!defined $hash && defined $file_name) {
4608 $hash = git_get_hash_by_path
($hash_base, $file_name);
4610 if (defined $hash) {
4611 $ftype = git_get_type
($hash);
4614 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4616 my $paging_nav = '';
4619 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4620 file_name
=>$file_name)},
4622 $paging_nav .= " ⋅ " .
4623 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4624 file_name
=>$file_name, page
=>$page-1),
4625 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4627 $paging_nav .= "first";
4628 $paging_nav .= " ⋅ prev";
4630 if ($#commitlist >= 100) {
4631 $paging_nav .= " ⋅ " .
4632 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4633 file_name
=>$file_name, page
=>$page+1),
4634 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4636 $paging_nav .= " ⋅ next";
4639 if ($#commitlist >= 100) {
4641 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4642 file_name
=>$file_name, page
=>$page+1),
4643 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4647 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4648 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4649 git_print_page_path
($file_name, $ftype, $hash_base);
4651 git_history_body
(\
@commitlist, 0, 99,
4652 $refs, $hash_base, $ftype, $next_link);
4658 my ($have_search) = gitweb_check_feature
('search');
4659 if (!$have_search) {
4660 die_error
('403 Permission denied', "Permission denied");
4662 if (!defined $searchtext) {
4663 die_error
(undef, "Text field empty");
4665 if (!defined $hash) {
4666 $hash = git_get_head_hash
($project);
4668 my %co = parse_commit
($hash);
4670 die_error
(undef, "Unknown commit object");
4672 if (!defined $page) {
4676 $searchtype ||= 'commit';
4677 if ($searchtype eq 'pickaxe') {
4678 # pickaxe may take all resources of your box and run for several minutes
4679 # with every query - so decide by yourself how public you make this feature
4680 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4681 if (!$have_pickaxe) {
4682 die_error
('403 Permission denied', "Permission denied");
4685 if ($searchtype eq 'grep') {
4686 my ($have_grep) = gitweb_check_feature
('grep');
4688 die_error
('403 Permission denied', "Permission denied");
4694 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4696 if ($searchtype eq 'commit') {
4697 $greptype = "--grep=";
4698 } elsif ($searchtype eq 'author') {
4699 $greptype = "--author=";
4700 } elsif ($searchtype eq 'committer') {
4701 $greptype = "--committer=";
4703 $greptype .= $search_regexp;
4704 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4706 my $paging_nav = '';
4709 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4710 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4712 $paging_nav .= " ⋅ " .
4713 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4714 searchtext
=>$searchtext, searchtype
=>$searchtype,
4716 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4718 $paging_nav .= "first";
4719 $paging_nav .= " ⋅ prev";
4721 if ($#commitlist >= 100) {
4722 $paging_nav .= " ⋅ " .
4723 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4724 searchtext
=>$searchtext, searchtype
=>$searchtype,
4726 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4728 $paging_nav .= " ⋅ next";
4731 if ($#commitlist >= 100) {
4733 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4734 searchtext
=>$searchtext, searchtype
=>$searchtype,
4736 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4739 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4740 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4741 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4744 if ($searchtype eq 'pickaxe') {
4745 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4746 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4748 print "<table cellspacing=\"0\">\n";
4751 my $git_command = git_cmd_str
();
4752 my $searchqtext = $searchtext;
4753 $searchqtext =~ s/'/'\\''/;
4754 open my $fd, "-|", "$git_command rev-list $hash | " .
4755 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
4758 while (my $line = <$fd>) {
4759 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4762 $set{'from_id'} = $3;
4764 $set{'id'} = $set{'to_id'};
4765 if ($set{'id'} =~ m/0{40}/) {
4766 $set{'id'} = $set{'from_id'};
4768 if ($set{'id'} =~ m/0{40}/) {
4772 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4775 print "<tr class=\"dark\">\n";
4777 print "<tr class=\"light\">\n";
4780 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4781 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4783 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4784 -class => "list subject"},
4785 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4786 while (my $setref = shift @files) {
4788 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4789 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4791 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4795 "<td class=\"link\">" .
4796 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4798 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4802 %co = parse_commit
($1);
4810 if ($searchtype eq 'grep') {
4811 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4812 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4814 print "<table cellspacing=\"0\">\n";
4818 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
4820 while (my $line = <$fd>) {
4822 my ($file, $lno, $ltext, $binary);
4823 last if ($matches++ > 1000);
4824 if ($line =~ /^Binary file (.+) matches$/) {
4828 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
4830 if ($file ne $lastfile) {
4831 $lastfile and print "</td></tr>\n";
4833 print "<tr class=\"dark\">\n";
4835 print "<tr class=\"light\">\n";
4837 print "<td class=\"list\">".
4838 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
4839 file_name
=>"$file"),
4840 -class => "list"}, esc_path
($file));
4841 print "</td><td>\n";
4845 print "<div class=\"binary\">Binary file</div>\n";
4847 $ltext = untabify
($ltext);
4848 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
4849 $ltext = esc_html
($1, -nbsp
=>1);
4850 $ltext .= '<span class="match">';
4851 $ltext .= esc_html
($2, -nbsp
=>1);
4852 $ltext .= '</span>';
4853 $ltext .= esc_html
($3, -nbsp
=>1);
4855 $ltext = esc_html
($ltext, -nbsp
=>1);
4857 print "<div class=\"pre\">" .
4858 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
4859 file_name
=>"$file").'#l'.$lno,
4860 -class => "linenr"}, sprintf('%4i', $lno))
4861 . ' ' . $ltext . "</div>\n";
4865 print "</td></tr>\n";
4866 if ($matches > 1000) {
4867 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
4870 print "<div class=\"diff nodifferences\">No matches found</div>\n";
4879 sub git_search_help
{
4881 git_print_page_nav
('','', $hash,$hash,$hash);
4884 <dt><b>commit</b></dt>
4885 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4887 my ($have_grep) = gitweb_check_feature
('grep');
4890 <dt><b>grep</b></dt>
4891 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
4892 a different one) are searched for the given
4893 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
4894 (POSIX extended) and the matches are listed. On large
4895 trees, this search can take a while and put some strain on the server, so please use it with
4896 some consideration.</dd>
4900 <dt><b>author</b></dt>
4901 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4902 <dt><b>committer</b></dt>
4903 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4905 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4906 if ($have_pickaxe) {
4908 <dt><b>pickaxe</b></dt>
4909 <dd>All commits that caused the string to appear or disappear from any file (changes that
4910 added, removed or "modified" the string) will be listed. This search can take a while and
4911 takes a lot of strain on the server, so please use it wisely.</dd>
4919 my $head = git_get_head_hash
($project);
4920 if (!defined $hash) {
4923 if (!defined $page) {
4926 my $refs = git_get_references
();
4928 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4930 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
4932 if ($#commitlist >= 100) {
4934 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4935 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4939 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4940 git_print_header_div
('summary', $project);
4942 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
4947 ## ......................................................................
4948 ## feeds (RSS, Atom; OPML)
4951 my $format = shift || 'atom';
4952 my ($have_blame) = gitweb_check_feature
('blame');
4954 # Atom: http://www.atomenabled.org/developers/syndication/
4955 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4956 if ($format ne 'rss' && $format ne 'atom') {
4957 die_error
(undef, "Unknown web feed format");
4960 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4961 my $head = $hash || 'HEAD';
4962 my @commitlist = parse_commits
($head, 150);
4966 my $content_type = "application/$format+xml";
4967 if (defined $cgi->http('HTTP_ACCEPT') &&
4968 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4969 # browser (feed reader) prefers text/xml
4970 $content_type = 'text/xml';
4972 if (defined($commitlist[0])) {
4973 %latest_commit = %{$commitlist[0]};
4974 %latest_date = parse_date
($latest_commit{'author_epoch'});
4976 -type
=> $content_type,
4977 -charset
=> 'utf-8',
4978 -last_modified
=> $latest_date{'rfc2822'});
4981 -type
=> $content_type,
4982 -charset
=> 'utf-8');
4985 # Optimization: skip generating the body if client asks only
4986 # for Last-Modified date.
4987 return if ($cgi->request_method() eq 'HEAD');
4990 my $title = "$site_name - $project/$action";
4991 my $feed_type = 'log';
4992 if (defined $hash) {
4993 $title .= " - '$hash'";
4994 $feed_type = 'branch log';
4995 if (defined $file_name) {
4996 $title .= " :: $file_name";
4997 $feed_type = 'history';
4999 } elsif (defined $file_name) {
5000 $title .= " - $file_name";
5001 $feed_type = 'history';
5003 $title .= " $feed_type";
5004 my $descr = git_get_project_description
($project);
5005 if (defined $descr) {
5006 $descr = esc_html
($descr);
5008 $descr = "$project " .
5009 ($format eq 'rss' ? 'RSS' : 'Atom') .
5012 my $owner = git_get_project_owner
($project);
5013 $owner = esc_html
($owner);
5017 if (defined $file_name) {
5018 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5019 } elsif (defined $hash) {
5020 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5022 $alt_url = href
(-full
=>1, action
=>"summary");
5024 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5025 if ($format eq 'rss') {
5027 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5030 print "<title>$title</title>\n" .
5031 "<link>$alt_url</link>\n" .
5032 "<description>$descr</description>\n" .
5033 "<language>en</language>\n";
5034 } elsif ($format eq 'atom') {
5036 <feed xmlns="http://www.w3.org/2005/Atom">
5038 print "<title>$title</title>\n" .
5039 "<subtitle>$descr</subtitle>\n" .
5040 '<link rel="alternate" type="text/html" href="' .
5041 $alt_url . '" />' . "\n" .
5042 '<link rel="self" type="' . $content_type . '" href="' .
5043 $cgi->self_url() . '" />' . "\n" .
5044 "<id>" . href
(-full
=>1) . "</id>\n" .
5045 # use project owner for feed author
5046 "<author><name>$owner</name></author>\n";
5047 if (defined $favicon) {
5048 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5050 if (defined $logo_url) {
5051 # not twice as wide as tall: 72 x 27 pixels
5052 print "<logo>" . esc_url
($logo) . "</logo>\n";
5054 if (! %latest_date) {
5055 # dummy date to keep the feed valid until commits trickle in:
5056 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5058 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5063 for (my $i = 0; $i <= $#commitlist; $i++) {
5064 my %co = %{$commitlist[$i]};
5065 my $commit = $co{'id'};
5066 # we read 150, we always show 30 and the ones more recent than 48 hours
5067 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5070 my %cd = parse_date
($co{'author_epoch'});
5072 # get list of changed files
5073 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5074 $co{'parent'} || "--root",
5075 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5077 my @difftree = map { chomp; $_ } <$fd>;
5081 # print element (entry, item)
5082 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5083 if ($format eq 'rss') {
5085 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5086 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5087 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5088 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5089 "<link>$co_url</link>\n" .
5090 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5091 "<content:encoded>" .
5093 } elsif ($format eq 'atom') {
5095 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5096 "<updated>$cd{'iso-8601'}</updated>\n" .
5098 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5099 if ($co{'author_email'}) {
5100 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5102 print "</author>\n" .
5103 # use committer for contributor
5105 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5106 if ($co{'committer_email'}) {
5107 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5109 print "</contributor>\n" .
5110 "<published>$cd{'iso-8601'}</published>\n" .
5111 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5112 "<id>$co_url</id>\n" .
5113 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5114 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5116 my $comment = $co{'comment'};
5118 foreach my $line (@$comment) {
5119 $line = esc_html
($line);
5122 print "</pre><ul>\n";
5123 foreach my $difftree_line (@difftree) {
5124 my %difftree = parse_difftree_raw_line
($difftree_line);
5125 next if !$difftree{'from_id'};
5127 my $file = $difftree{'file'} || $difftree{'to_file'};
5131 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5132 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5133 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5134 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5135 -title
=> "diff"}, 'D');
5137 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5138 file_name
=>$file, hash_base
=>$commit),
5139 -title
=> "blame"}, 'B');
5141 # if this is not a feed of a file history
5142 if (!defined $file_name || $file_name ne $file) {
5143 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5144 file_name
=>$file, hash
=>$commit),
5145 -title
=> "history"}, 'H');
5147 $file = esc_path
($file);
5151 if ($format eq 'rss') {
5152 print "</ul>]]>\n" .
5153 "</content:encoded>\n" .
5155 } elsif ($format eq 'atom') {
5156 print "</ul>\n</div>\n" .
5163 if ($format eq 'rss') {
5164 print "</channel>\n</rss>\n";
5165 } elsif ($format eq 'atom') {
5179 my @list = git_get_projects_list
();
5181 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5183 <?xml version="1.0" encoding="utf-8"?>
5184 <opml version="1.0">
5186 <title>$site_name OPML Export</title>
5189 <outline text="git RSS feeds">
5192 foreach my $pr (@list) {
5194 my $head = git_get_head_hash
($proj{'path'});
5195 if (!defined $head) {
5198 $git_dir = "$projectroot/$proj{'path'}";
5199 my %co = parse_commit
($head);
5204 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5205 my $rss = "$my_url?p=$proj{'path'};a=rss";
5206 my $html = "$my_url?p=$proj{'path'};a=summary";
5207 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";