3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI-
>compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # core git executable to use
31 # this can just be "git" if your webserver has a sensible PATH
32 our $GIT = "++GIT_BINDIR++/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "++GITWEB_PROJECTROOT++";
38 # target of the home link on top of all pages
39 our $home_link = $my_uri || "/";
41 # string of the home link on top of all pages
42 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
44 # name of your site or organization to appear in page titles
45 # replace this with something more descriptive for clearer bookmarks
46 our $site_name = "++GITWEB_SITENAME++"
47 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
49 # filename of html text to include at top of each page
50 our $site_header = "++GITWEB_SITE_HEADER++";
51 # html text to include at home page
52 our $home_text = "++GITWEB_HOMETEXT++";
53 # filename of html text to include at bottom of each page
54 our $site_footer = "++GITWEB_SITE_FOOTER++";
57 our @stylesheets = ("++GITWEB_CSS++");
58 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
59 our $stylesheet = undef;
61 # URI of GIT logo (72x27 size)
62 our $logo = "++GITWEB_LOGO++";
63 # URI of GIT favicon, assumed to be image/png type
64 our $favicon = "++GITWEB_FAVICON++";
66 # URI and label (title) of GIT logo link
67 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
68 #our $logo_label = "git documentation";
69 our $logo_url = "http://git.or.cz/";
70 our $logo_label = "git homepage";
72 # source of projects list
73 our $projects_list = "++GITWEB_LIST++";
75 # default order of projects list
76 # valid values are none, project, descr, owner, and age
77 our $default_projects_order = "project";
79 # show repository only if this file exists
80 # (only effective if this variable evaluates to true)
81 our $export_ok = "++GITWEB_EXPORT_OK++";
83 # only allow viewing of repositories also shown on the overview page
84 our $strict_export = "++GITWEB_STRICT_EXPORT++";
86 # list of git base URLs used for URL to where fetch project from,
87 # i.e. full URL is "$git_base_url/$project"
88 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
90 # default blob_plain mimetype and default charset for text/plain blob
91 our $default_blob_plain_mimetype = 'text/plain';
92 our $default_text_plain_charset = undef;
94 # file to use for guessing MIME types before trying /etc/mime.types
95 # (relative to the current git repository)
96 our $mimetypes_file = undef;
98 # You define site-wide feature defaults here; override them with
99 # $GITWEB_CONFIG as necessary.
102 # 'sub' => feature-sub (subroutine),
103 # 'override' => allow-override (boolean),
104 # 'default' => [ default options...] (array reference)}
106 # if feature is overridable (it means that allow-override has true value),
107 # then feature-sub will be called with default options as parameters;
108 # return value of feature-sub indicates if to enable specified feature
110 # if there is no 'sub' key (no feature-sub), then feature cannot be
113 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
115 # Enable the 'blame' blob view, showing the last commit that modified
116 # each line in the file. This can be very CPU-intensive.
118 # To enable system wide have in $GITWEB_CONFIG
119 # $feature{'blame'}{'default'} = [1];
120 # To have project specific config enable override in $GITWEB_CONFIG
121 # $feature{'blame'}{'override'} = 1;
122 # and in project config gitweb.blame = 0|1;
124 'sub' => \
&feature_blame
,
128 # Enable the 'snapshot' link, providing a compressed tarball of any
129 # tree. This can potentially generate high traffic if you have large
132 # To disable system wide have in $GITWEB_CONFIG
133 # $feature{'snapshot'}{'default'} = [undef];
134 # To have project specific config enable override in $GITWEB_CONFIG
135 # $feature{'snapshot'}{'override'} = 1;
136 # and in project config gitweb.snapshot = none|gzip|bzip2;
138 'sub' => \
&feature_snapshot
,
140 # => [content-encoding, suffix, program]
141 'default' => ['x-gzip', 'gz', 'gzip']},
143 # Enable text search, which will list the commits which match author,
144 # committer or commit text to a given string. Enabled by default.
145 # Project specific override is not supported.
150 # Enable grep search, which will list the files in currently selected
151 # tree containing the given string. Enabled by default. This can be
152 # potentially CPU-intensive, of course.
154 # To enable system wide have in $GITWEB_CONFIG
155 # $feature{'grep'}{'default'} = [1];
156 # To have project specific config enable override in $GITWEB_CONFIG
157 # $feature{'grep'}{'override'} = 1;
158 # and in project config gitweb.grep = 0|1;
163 # Enable the pickaxe search, which will list the commits that modified
164 # a given string in a file. This can be practical and quite faster
165 # alternative to 'blame', but still potentially CPU-intensive.
167 # To enable system wide have in $GITWEB_CONFIG
168 # $feature{'pickaxe'}{'default'} = [1];
169 # To have project specific config enable override in $GITWEB_CONFIG
170 # $feature{'pickaxe'}{'override'} = 1;
171 # and in project config gitweb.pickaxe = 0|1;
173 'sub' => \
&feature_pickaxe
,
177 # Make gitweb use an alternative format of the URLs which can be
178 # more readable and natural-looking: project name is embedded
179 # directly in the path and the query string contains other
180 # auxiliary information. All gitweb installations recognize
181 # URL in either format; this configures in which formats gitweb
184 # To enable system wide have in $GITWEB_CONFIG
185 # $feature{'pathinfo'}{'default'} = [1];
186 # Project specific override is not supported.
188 # Note that you will need to change the default location of CSS,
189 # favicon, logo and possibly other files to an absolute URL. Also,
190 # if gitweb.cgi serves as your indexfile, you will need to force
191 # $my_uri to contain the script name in your $GITWEB_CONFIG.
196 # Make gitweb consider projects in project root subdirectories
197 # to be forks of existing projects. Given project $projname.git,
198 # projects matching $projname/*.git will not be shown in the main
199 # projects list, instead a '+' mark will be added to $projname
200 # there and a 'forks' view will be enabled for the project, listing
201 # all the forks. If project list is taken from a file, forks have
202 # to be listed after the main project.
204 # To enable system wide have in $GITWEB_CONFIG
205 # $feature{'forks'}{'default'} = [1];
206 # Project specific override is not supported.
212 sub gitweb_check_feature
{
214 return unless exists $feature{$name};
215 my ($sub, $override, @defaults) = (
216 $feature{$name}{'sub'},
217 $feature{$name}{'override'},
218 @{$feature{$name}{'default'}});
219 if (!$override) { return @defaults; }
221 warn "feature $name is not overrideable";
224 return $sub->(@defaults);
228 my ($val) = git_get_project_config
('blame', '--bool');
230 if ($val eq 'true') {
232 } elsif ($val eq 'false') {
239 sub feature_snapshot
{
240 my ($ctype, $suffix, $command) = @_;
242 my ($val) = git_get_project_config
('snapshot');
244 if ($val eq 'gzip') {
245 return ('x-gzip', 'gz', 'gzip');
246 } elsif ($val eq 'bzip2') {
247 return ('x-bzip2', 'bz2', 'bzip2');
248 } elsif ($val eq 'none') {
252 return ($ctype, $suffix, $command);
255 sub gitweb_have_snapshot
{
256 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
257 my $have_snapshot = (defined $ctype && defined $suffix);
259 return $have_snapshot;
263 my ($val) = git_get_project_config
('grep', '--bool');
265 if ($val eq 'true') {
267 } elsif ($val eq 'false') {
274 sub feature_pickaxe
{
275 my ($val) = git_get_project_config
('pickaxe', '--bool');
277 if ($val eq 'true') {
279 } elsif ($val eq 'false') {
286 # checking HEAD file with -e is fragile if the repository was
287 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
289 sub check_head_link
{
291 my $headfile = "$dir/HEAD";
292 return ((-e
$headfile) ||
293 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
296 sub check_export_ok
{
298 return (check_head_link
($dir) &&
299 (!$export_ok || -e
"$dir/$export_ok"));
302 # rename detection options for git-diff and git-diff-tree
303 # - default is '-M', with the cost proportional to
304 # (number of removed files) * (number of new files).
305 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
306 # (number of changed files + number of removed files) * (number of new files)
307 # - even more costly is '-C', '--find-copies-harder' with cost
308 # (number of files in the original tree) * (number of new files)
309 # - one might want to include '-B' option, e.g. '-B', '-M'
310 our @diff_opts = ('-M'); # taken from git_commit
312 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
313 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
315 # version of the core git binary
316 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
318 $projects_list ||= $projectroot;
320 # ======================================================================
321 # input validation and dispatch
322 our $action = $cgi->param('a');
323 if (defined $action) {
324 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
325 die_error
(undef, "Invalid action parameter");
329 # parameters which are pathnames
330 our $project = $cgi->param('p');
331 if (defined $project) {
332 if (!validate_pathname
($project) ||
333 !(-d
"$projectroot/$project") ||
334 !check_head_link
("$projectroot/$project") ||
335 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
336 ($strict_export && !project_in_list
($project))) {
338 die_error
(undef, "No such project");
342 our $file_name = $cgi->param('f');
343 if (defined $file_name) {
344 if (!validate_pathname
($file_name)) {
345 die_error
(undef, "Invalid file parameter");
349 our $file_parent = $cgi->param('fp');
350 if (defined $file_parent) {
351 if (!validate_pathname
($file_parent)) {
352 die_error
(undef, "Invalid file parent parameter");
356 # parameters which are refnames
357 our $hash = $cgi->param('h');
359 if (!validate_refname
($hash)) {
360 die_error
(undef, "Invalid hash parameter");
364 our $hash_parent = $cgi->param('hp');
365 if (defined $hash_parent) {
366 if (!validate_refname
($hash_parent)) {
367 die_error
(undef, "Invalid hash parent parameter");
371 our $hash_base = $cgi->param('hb');
372 if (defined $hash_base) {
373 if (!validate_refname
($hash_base)) {
374 die_error
(undef, "Invalid hash base parameter");
378 our $hash_parent_base = $cgi->param('hpb');
379 if (defined $hash_parent_base) {
380 if (!validate_refname
($hash_parent_base)) {
381 die_error
(undef, "Invalid hash parent base parameter");
386 our $page = $cgi->param('pg');
388 if ($page =~ m/[^0-9]/) {
389 die_error
(undef, "Invalid page parameter");
393 our $searchtype = $cgi->param('st');
394 if (defined $searchtype) {
395 if ($searchtype =~ m/[^a-z]/) {
396 die_error
(undef, "Invalid searchtype parameter");
400 our $searchtext = $cgi->param('s');
402 if (defined $searchtext) {
403 if ($searchtype ne 'grep' and $searchtype ne 'pickaxe' and $searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
404 die_error
(undef, "Invalid search parameter");
406 if (length($searchtext) < 2) {
407 die_error
(undef, "At least two characters are required for search parameter");
409 $search_regexp = quotemeta $searchtext;
412 # now read PATH_INFO and use it as alternative to parameters
413 sub evaluate_path_info
{
414 return if defined $project;
415 my $path_info = $ENV{"PATH_INFO"};
416 return if !$path_info;
417 $path_info =~ s
,^/+,,;
418 return if !$path_info;
419 # find which part of PATH_INFO is project
420 $project = $path_info;
422 while ($project && !check_head_link
("$projectroot/$project")) {
423 $project =~ s
,/*[^/]*$,,;
426 $project = validate_pathname
($project);
428 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
429 ($strict_export && !project_in_list
($project))) {
433 # do not change any parameters if an action is given using the query string
435 $path_info =~ s
,^$project/*,,;
436 my ($refname, $pathname) = split(/:/, $path_info, 2);
437 if (defined $pathname) {
438 # we got "project.git/branch:filename" or "project.git/branch:dir/"
439 # we could use git_get_type(branch:pathname), but it needs $git_dir
440 $pathname =~ s
,^/+,,;
441 if (!$pathname || substr($pathname, -1) eq "/") {
445 $action ||= "blob_plain";
447 $hash_base ||= validate_refname
($refname);
448 $file_name ||= validate_pathname
($pathname);
449 } elsif (defined $refname) {
450 # we got "project.git/branch"
451 $action ||= "shortlog";
452 $hash ||= validate_refname
($refname);
455 evaluate_path_info
();
457 # path to the current git repository
459 $git_dir = "$projectroot/$project" if $project;
463 "blame" => \
&git_blame2
,
464 "blobdiff" => \
&git_blobdiff
,
465 "blobdiff_plain" => \
&git_blobdiff_plain
,
466 "blob" => \
&git_blob
,
467 "blob_plain" => \
&git_blob_plain
,
468 "commitdiff" => \
&git_commitdiff
,
469 "commitdiff_plain" => \
&git_commitdiff_plain
,
470 "commit" => \
&git_commit
,
471 "forks" => \
&git_forks
,
472 "heads" => \
&git_heads
,
473 "history" => \
&git_history
,
476 "atom" => \
&git_atom
,
477 "search" => \
&git_search
,
478 "search_help" => \
&git_search_help
,
479 "shortlog" => \
&git_shortlog
,
480 "summary" => \
&git_summary
,
482 "tags" => \
&git_tags
,
483 "tree" => \
&git_tree
,
484 "snapshot" => \
&git_snapshot
,
485 "object" => \
&git_object
,
486 # those below don't need $project
487 "opml" => \
&git_opml
,
488 "project_list" => \
&git_project_list
,
489 "project_index" => \
&git_project_index
,
492 if (!defined $action) {
494 $action = git_get_type
($hash);
495 } elsif (defined $hash_base && defined $file_name) {
496 $action = git_get_type
("$hash_base:$file_name");
497 } elsif (defined $project) {
500 $action = 'project_list';
503 if (!defined($actions{$action})) {
504 die_error
(undef, "Unknown action");
506 if ($action !~ m/^(opml|project_list|project_index)$/ &&
508 die_error
(undef, "Project needed");
510 $actions{$action}->();
513 ## ======================================================================
518 # default is to use -absolute url() i.e. $my_uri
519 my $href = $params{-full
} ? $my_url : $my_uri;
521 # XXX: Warning: If you touch this, check the search form for updating,
532 hash_parent_base
=> "hpb",
538 my %mapping = @mapping;
540 $params{'project'} = $project unless exists $params{'project'};
542 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
544 # use PATH_INFO for project name
545 $href .= "/$params{'project'}" if defined $params{'project'};
546 delete $params{'project'};
548 # Summary just uses the project path URL
549 if (defined $params{'action'} && $params{'action'} eq 'summary') {
550 delete $params{'action'};
554 # now encode the parameters explicitly
556 for (my $i = 0; $i < @mapping; $i += 2) {
557 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
558 if (defined $params{$name}) {
559 push @result, $symbol . "=" . esc_param
($params{$name});
562 $href .= "?" . join(';', @result) if scalar @result;
568 ## ======================================================================
569 ## validation, quoting/unquoting and escaping
571 sub validate_pathname
{
572 my $input = shift || return undef;
574 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
575 # at the beginning, at the end, and between slashes.
576 # also this catches doubled slashes
577 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
581 if ($input =~ m!\0!) {
587 sub validate_refname
{
588 my $input = shift || return undef;
590 # textual hashes are O.K.
591 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
594 # it must be correct pathname
595 $input = validate_pathname
($input)
597 # restrictions on ref name according to git-check-ref-format
598 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
604 # quote unsafe chars, but keep the slash, even when it's not
605 # correct, but quoted slashes look too horrible in bookmarks
608 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
614 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
617 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
623 # replace invalid utf8 character with SUBSTITUTION sequence
628 $str = decode_utf8
($str);
629 $str = $cgi->escapeHTML($str);
630 if ($opts{'-nbsp'}) {
631 $str =~ s/ / /g;
633 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
637 # quote control characters and escape filename to HTML
642 $str = decode_utf8
($str);
643 $str = $cgi->escapeHTML($str);
644 if ($opts{'-nbsp'}) {
645 $str =~ s/ / /g;
647 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
651 # Make control characters "printable", using character escape codes (CEC)
654 my %es = ( # character escape codes, aka escape sequences
655 "\t" => '\t', # tab (HT)
656 "\n" => '\n', # line feed (LF)
657 "\r" => '\r', # carrige return (CR)
658 "\f" => '\f', # form feed (FF)
659 "\b" => '\b', # backspace (BS)
660 "\a" => '\a', # alarm (bell) (BEL)
661 "\e" => '\e', # escape (ESC)
662 "\013" => '\v', # vertical tab (VT)
663 "\000" => '\0', # nul character (NUL)
665 my $chr = ( (exists $es{$cntrl})
667 : sprintf('\%03o', ord($cntrl)) );
668 return "<span class=\"cntrl\">$chr</span>";
671 # Alternatively use unicode control pictures codepoints,
672 # Unicode "printable representation" (PR)
675 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
676 return "<span class=\"cntrl\">$chr</span>";
679 # git may return quoted and escaped filenames
685 my %es = ( # character escape codes, aka escape sequences
686 't' => "\t", # tab (HT, TAB)
687 'n' => "\n", # newline (NL)
688 'r' => "\r", # return (CR)
689 'f' => "\f", # form feed (FF)
690 'b' => "\b", # backspace (BS)
691 'a' => "\a", # alarm (bell) (BEL)
692 'e' => "\e", # escape (ESC)
693 'v' => "\013", # vertical tab (VT)
696 if ($seq =~ m/^[0-7]{1,3}$/) {
697 # octal char sequence
698 return chr(oct($seq));
699 } elsif (exists $es{$seq}) {
700 # C escape sequence, aka character escape code
703 # quoted ordinary character
707 if ($str =~ m/^"(.*)"$/) {
710 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
715 # escape tabs (convert tabs to spaces)
719 while ((my $pos = index($line, "\t")) != -1) {
720 if (my $count = (8 - ($pos % 8))) {
721 my $spaces = ' ' x
$count;
722 $line =~ s/\t/$spaces/;
729 sub project_in_list
{
731 my @list = git_get_projects_list
();
732 return @list && scalar(grep { $_->{'path'} eq $project } @list);
735 ## ----------------------------------------------------------------------
736 ## HTML aware string manipulation
741 my $add_len = shift || 10;
743 # allow only $len chars, but don't cut a word if it would fit in $add_len
744 # if it doesn't fit, cut it if it's still longer than the dots we would add
745 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
748 if (length($tail) > 4) {
750 $body =~ s/&[^;]*$//; # remove chopped character entities
755 ## ----------------------------------------------------------------------
756 ## functions returning short strings
758 # CSS class for given age value (in seconds)
764 } elsif ($age < 60*60*2) {
766 } elsif ($age < 60*60*24*2) {
773 # convert age in seconds to "nn units ago" string
778 if ($age > 60*60*24*365*2) {
779 $age_str = (int $age/60/60/24/365);
780 $age_str .= " years ago";
781 } elsif ($age > 60*60*24*(365/12)*2) {
782 $age_str = int $age/60/60/24/(365/12);
783 $age_str .= " months ago";
784 } elsif ($age > 60*60*24*7*2) {
785 $age_str = int $age/60/60/24/7;
786 $age_str .= " weeks ago";
787 } elsif ($age > 60*60*24*2) {
788 $age_str = int $age/60/60/24;
789 $age_str .= " days ago";
790 } elsif ($age > 60*60*2) {
791 $age_str = int $age/60/60;
792 $age_str .= " hours ago";
793 } elsif ($age > 60*2) {
794 $age_str = int $age/60;
795 $age_str .= " min ago";
798 $age_str .= " sec ago";
800 $age_str .= " right now";
805 # convert file mode in octal to symbolic file mode string
807 my $mode = oct shift;
809 if (S_ISDIR
($mode & S_IFMT
)) {
811 } elsif (S_ISLNK
($mode)) {
813 } elsif (S_ISREG
($mode)) {
814 # git cares only about the executable bit
815 if ($mode & S_IXUSR
) {
825 # convert file mode in octal to file type string
829 if ($mode !~ m/^[0-7]+$/) {
835 if (S_ISDIR
($mode & S_IFMT
)) {
837 } elsif (S_ISLNK
($mode)) {
839 } elsif (S_ISREG
($mode)) {
846 # convert file mode in octal to file type description string
850 if ($mode !~ m/^[0-7]+$/) {
856 if (S_ISDIR
($mode & S_IFMT
)) {
858 } elsif (S_ISLNK
($mode)) {
860 } elsif (S_ISREG
($mode)) {
861 if ($mode & S_IXUSR
) {
872 ## ----------------------------------------------------------------------
873 ## functions returning short HTML fragments, or transforming HTML fragments
874 ## which don't belong to other sections
876 # format line of commit message.
877 sub format_log_line_html
{
880 $line = esc_html
($line, -nbsp
=>1);
881 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
884 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
885 -class => "text"}, $hash_text);
886 $line =~ s/$hash_text/$link/;
891 # format marker of refs pointing to given object
892 sub format_ref_marker
{
893 my ($refs, $id) = @_;
896 if (defined $refs->{$id}) {
897 foreach my $ref (@{$refs->{$id}}) {
898 my ($type, $name) = qw();
899 # e.g. tags/v2.6.11 or heads/next
900 if ($ref =~ m!^(.*?)s?/(.*)$!) {
908 $markers .= " <span class=\"$type\" title=\"$ref\">" .
909 esc_html
($name) . "</span>";
914 return ' <span class="refs">'. $markers . '</span>';
920 # format, perhaps shortened and with markers, title line
921 sub format_subject_html
{
922 my ($long, $short, $href, $extra) = @_;
923 $extra = '' unless defined($extra);
925 if (length($short) < length($long)) {
926 return $cgi->a({-href
=> $href, -class => "list subject",
927 -title
=> decode_utf8
($long)},
928 esc_html
($short) . $extra);
930 return $cgi->a({-href
=> $href, -class => "list subject"},
931 esc_html
($long) . $extra);
935 # format patch (diff) line (rather not to be used for diff headers)
936 sub format_diff_line
{
938 my ($from, $to) = @_;
943 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
945 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
946 if ($line =~ m/^\@{3}/) {
947 $diff_class = " chunk_header";
948 } elsif ($line =~ m/^\\/) {
949 $diff_class = " incomplete";
950 } elsif ($prefix =~ tr/+/+/) {
951 $diff_class = " add";
952 } elsif ($prefix =~ tr/-/-/) {
953 $diff_class = " rem";
956 # assume ordinary diff
957 my $char = substr($line, 0, 1);
959 $diff_class = " add";
960 } elsif ($char eq '-') {
961 $diff_class = " rem";
962 } elsif ($char eq '@') {
963 $diff_class = " chunk_header";
964 } elsif ($char eq "\\") {
965 $diff_class = " incomplete";
968 $line = untabify
($line);
969 if ($from && $to && $line =~ m/^\@{2} /) {
970 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
971 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
973 $from_lines = 0 unless defined $from_lines;
974 $to_lines = 0 unless defined $to_lines;
976 if ($from->{'href'}) {
977 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
978 -class=>"list"}, $from_text);
981 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
982 -class=>"list"}, $to_text);
984 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
985 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
986 return "<div class=\"diff$diff_class\">$line</div>\n";
987 } elsif ($from && $to && $line =~ m/^\@{3}/) {
988 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
989 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
991 @from_text = split(' ', $ranges);
992 for (my $i = 0; $i < @from_text; ++$i) {
993 ($from_start[$i], $from_nlines[$i]) =
994 (split(',', substr($from_text[$i], 1)), 0);
997 $to_text = pop @from_text;
998 $to_start = pop @from_start;
999 $to_nlines = pop @from_nlines;
1001 $line = "<span class=\"chunk_info\">$prefix ";
1002 for (my $i = 0; $i < @from_text; ++$i) {
1003 if ($from->{'href'}[$i]) {
1004 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1005 -class=>"list"}, $from_text[$i]);
1007 $line .= $from_text[$i];
1011 if ($to->{'href'}) {
1012 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1013 -class=>"list"}, $to_text);
1017 $line .= " $prefix</span>" .
1018 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1019 return "<div class=\"diff$diff_class\">$line</div>\n";
1021 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1024 ## ----------------------------------------------------------------------
1025 ## git utility subroutines, invoking git commands
1027 # returns path to the core git executable and the --git-dir parameter as list
1029 return $GIT, '--git-dir='.$git_dir;
1032 # returns path to the core git executable and the --git-dir parameter as string
1034 return join(' ', git_cmd
());
1037 # get HEAD ref of given project as hash
1038 sub git_get_head_hash
{
1039 my $project = shift;
1040 my $o_git_dir = $git_dir;
1042 $git_dir = "$projectroot/$project";
1043 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1046 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1050 if (defined $o_git_dir) {
1051 $git_dir = $o_git_dir;
1056 # get type of given object
1060 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1062 close $fd or return;
1067 sub git_get_project_config
{
1068 my ($key, $type) = @_;
1070 return unless ($key);
1071 $key =~ s/^gitweb\.//;
1072 return if ($key =~ m/\W/);
1074 my @x = (git_cmd
(), 'config');
1075 if (defined $type) { push @x, $type; }
1077 push @x, "gitweb.$key";
1083 # get hash of given path at given ref
1084 sub git_get_hash_by_path
{
1086 my $path = shift || return undef;
1091 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1092 or die_error
(undef, "Open git-ls-tree failed");
1094 close $fd or return undef;
1096 if (!defined $line) {
1097 # there is no tree or hash given by $path at $base
1101 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1102 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1103 if (defined $type && $type ne $2) {
1104 # type doesn't match
1110 # get path of entry with given hash at given tree-ish (ref)
1111 # used to get 'from' filename for combined diff (merge commit) for renames
1112 sub git_get_path_by_hash
{
1113 my $base = shift || return;
1114 my $hash = shift || return;
1118 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1120 while (my $line = <$fd>) {
1123 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1124 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1125 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1134 ## ......................................................................
1135 ## git utility functions, directly accessing git repository
1137 sub git_get_project_description
{
1140 open my $fd, "$projectroot/$path/description" or return undef;
1143 if (defined $descr) {
1149 sub git_get_project_url_list
{
1152 open my $fd, "$projectroot/$path/cloneurl" or return;
1153 my @git_project_url_list = map { chomp; $_ } <$fd>;
1156 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1159 sub git_get_projects_list
{
1164 $filter =~ s/\.git$//;
1166 my ($check_forks) = gitweb_check_feature
('forks');
1168 if (-d
$projects_list) {
1169 # search in directory
1170 my $dir = $projects_list . ($filter ? "/$filter" : '');
1171 # remove the trailing "/"
1173 my $pfxlen = length("$dir");
1176 follow_fast
=> 1, # follow symbolic links
1177 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1179 # skip project-list toplevel, if we get it.
1180 return if (m!^[/.]$!);
1181 # only directories can be git repositories
1182 return unless (-d
$_);
1184 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1185 # we check related file in $projectroot
1186 if ($check_forks and $subdir =~ m
#/.#) {
1187 $File::Find
::prune
= 1;
1188 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1189 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1190 $File::Find
::prune
= 1;
1195 } elsif (-f
$projects_list) {
1196 # read from file(url-encoded):
1197 # 'git%2Fgit.git Linus+Torvalds'
1198 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1199 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1201 open my ($fd), $projects_list or return;
1203 while (my $line = <$fd>) {
1205 my ($path, $owner) = split ' ', $line;
1206 $path = unescape
($path);
1207 $owner = unescape
($owner);
1208 if (!defined $path) {
1211 if ($filter ne '') {
1212 # looking for forks;
1213 my $pfx = substr($path, 0, length($filter));
1214 if ($pfx ne $filter) {
1217 my $sfx = substr($path, length($filter));
1218 if ($sfx !~ /^\/.*\
.git
$/) {
1221 } elsif ($check_forks) {
1223 foreach my $filter (keys %paths) {
1224 # looking for forks;
1225 my $pfx = substr($path, 0, length($filter));
1226 if ($pfx ne $filter) {
1229 my $sfx = substr($path, length($filter));
1230 if ($sfx !~ /^\/.*\
.git
$/) {
1233 # is a fork, don't include it in
1238 if (check_export_ok
("$projectroot/$path")) {
1241 owner
=> decode_utf8
($owner),
1244 (my $forks_path = $path) =~ s/\.git$//;
1245 $paths{$forks_path}++;
1253 sub git_get_project_owner
{
1254 my $project = shift;
1257 return undef unless $project;
1259 # read from file (url-encoded):
1260 # 'git%2Fgit.git Linus+Torvalds'
1261 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1262 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1263 if (-f
$projects_list) {
1264 open (my $fd , $projects_list);
1265 while (my $line = <$fd>) {
1267 my ($pr, $ow) = split ' ', $line;
1268 $pr = unescape
($pr);
1269 $ow = unescape
($ow);
1270 if ($pr eq $project) {
1271 $owner = decode_utf8
($ow);
1277 if (!defined $owner) {
1278 $owner = get_file_owner
("$projectroot/$project");
1284 sub git_get_last_activity
{
1288 $git_dir = "$projectroot/$path";
1289 open($fd, "-|", git_cmd
(), 'for-each-ref',
1290 '--format=%(committer)',
1291 '--sort=-committerdate',
1293 'refs/heads') or return;
1294 my $most_recent = <$fd>;
1295 close $fd or return;
1296 if (defined $most_recent &&
1297 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1299 my $age = time - $timestamp;
1300 return ($age, age_string
($age));
1304 sub git_get_references
{
1305 my $type = shift || "";
1307 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1308 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1309 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1310 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1313 while (my $line = <$fd>) {
1315 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1316 if (defined $refs{$1}) {
1317 push @{$refs{$1}}, $2;
1323 close $fd or return;
1327 sub git_get_rev_name_tags
{
1328 my $hash = shift || return undef;
1330 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1332 my $name_rev = <$fd>;
1335 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1338 # catches also '$hash undefined' output
1343 ## ----------------------------------------------------------------------
1344 ## parse to hash functions
1348 my $tz = shift || "-0000";
1351 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1352 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1353 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1354 $date{'hour'} = $hour;
1355 $date{'minute'} = $min;
1356 $date{'mday'} = $mday;
1357 $date{'day'} = $days[$wday];
1358 $date{'month'} = $months[$mon];
1359 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1360 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1361 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1362 $mday, $months[$mon], $hour ,$min;
1363 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1364 1900+$year, $mon, $mday, $hour ,$min, $sec;
1366 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1367 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1368 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1369 $date{'hour_local'} = $hour;
1370 $date{'minute_local'} = $min;
1371 $date{'tz_local'} = $tz;
1372 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1373 1900+$year, $mon+1, $mday,
1374 $hour, $min, $sec, $tz);
1383 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1384 $tag{'id'} = $tag_id;
1385 while (my $line = <$fd>) {
1387 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1388 $tag{'object'} = $1;
1389 } elsif ($line =~ m/^type (.+)$/) {
1391 } elsif ($line =~ m/^tag (.+)$/) {
1393 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1394 $tag{'author'} = $1;
1397 } elsif ($line =~ m/--BEGIN/) {
1398 push @comment, $line;
1400 } elsif ($line eq "") {
1404 push @comment, <$fd>;
1405 $tag{'comment'} = \
@comment;
1406 close $fd or return;
1407 if (!defined $tag{'name'}) {
1413 sub parse_commit_text
{
1414 my ($commit_text, $withparents) = @_;
1415 my @commit_lines = split '\n', $commit_text;
1418 pop @commit_lines; # Remove '\0'
1420 if (! @commit_lines) {
1424 my $header = shift @commit_lines;
1425 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1428 ($co{'id'}, my @parents) = split ' ', $header;
1429 while (my $line = shift @commit_lines) {
1430 last if $line eq "\n";
1431 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1433 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1435 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1437 $co{'author_epoch'} = $2;
1438 $co{'author_tz'} = $3;
1439 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1440 $co{'author_name'} = $1;
1441 $co{'author_email'} = $2;
1443 $co{'author_name'} = $co{'author'};
1445 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1446 $co{'committer'} = $1;
1447 $co{'committer_epoch'} = $2;
1448 $co{'committer_tz'} = $3;
1449 $co{'committer_name'} = $co{'committer'};
1450 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1451 $co{'committer_name'} = $1;
1452 $co{'committer_email'} = $2;
1454 $co{'committer_name'} = $co{'committer'};
1458 if (!defined $co{'tree'}) {
1461 $co{'parents'} = \
@parents;
1462 $co{'parent'} = $parents[0];
1464 foreach my $title (@commit_lines) {
1467 $co{'title'} = chop_str
($title, 80, 5);
1468 # remove leading stuff of merges to make the interesting part visible
1469 if (length($title) > 50) {
1470 $title =~ s/^Automatic //;
1471 $title =~ s/^merge (of|with) /Merge ... /i;
1472 if (length($title) > 50) {
1473 $title =~ s/(http|rsync):\/\///;
1475 if (length($title) > 50) {
1476 $title =~ s/(master|www|rsync)\.//;
1478 if (length($title) > 50) {
1479 $title =~ s/kernel.org:?//;
1481 if (length($title) > 50) {
1482 $title =~ s/\/pub\/scm//;
1485 $co{'title_short'} = chop_str
($title, 50, 5);
1489 if ($co{'title'} eq "") {
1490 $co{'title'} = $co{'title_short'} = '(no commit message)';
1492 # remove added spaces
1493 foreach my $line (@commit_lines) {
1496 $co{'comment'} = \
@commit_lines;
1498 my $age = time - $co{'committer_epoch'};
1500 $co{'age_string'} = age_string
($age);
1501 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1502 if ($age > 60*60*24*7*2) {
1503 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1504 $co{'age_string_age'} = $co{'age_string'};
1506 $co{'age_string_date'} = $co{'age_string'};
1507 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1513 my ($commit_id) = @_;
1518 open my $fd, "-|", git_cmd
(), "rev-list",
1524 or die_error
(undef, "Open git-rev-list failed");
1525 %co = parse_commit_text
(<$fd>, 1);
1532 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1540 open my $fd, "-|", git_cmd
(), "rev-list",
1542 ($arg ? ($arg) : ()),
1543 ("--max-count=" . $maxcount),
1544 ("--skip=" . $skip),
1547 ($filename ? ($filename) : ())
1548 or die_error
(undef, "Open git-rev-list failed");
1549 while (my $line = <$fd>) {
1550 my %co = parse_commit_text
($line);
1555 return wantarray ? @cos : \
@cos;
1558 # parse ref from ref_file, given by ref_id, with given type
1560 my $ref_file = shift;
1562 my $type = shift || git_get_type
($ref_id);
1565 $ref_item{'type'} = $type;
1566 $ref_item{'id'} = $ref_id;
1567 $ref_item{'epoch'} = 0;
1568 $ref_item{'age'} = "unknown";
1569 if ($type eq "tag") {
1570 my %tag = parse_tag
($ref_id);
1571 $ref_item{'comment'} = $tag{'comment'};
1572 if ($tag{'type'} eq "commit") {
1573 my %co = parse_commit
($tag{'object'});
1574 $ref_item{'epoch'} = $co{'committer_epoch'};
1575 $ref_item{'age'} = $co{'age_string'};
1576 } elsif (defined($tag{'epoch'})) {
1577 my $age = time - $tag{'epoch'};
1578 $ref_item{'epoch'} = $tag{'epoch'};
1579 $ref_item{'age'} = age_string
($age);
1581 $ref_item{'reftype'} = $tag{'type'};
1582 $ref_item{'name'} = $tag{'name'};
1583 $ref_item{'refid'} = $tag{'object'};
1584 } elsif ($type eq "commit"){
1585 my %co = parse_commit
($ref_id);
1586 $ref_item{'reftype'} = "commit";
1587 $ref_item{'name'} = $ref_file;
1588 $ref_item{'title'} = $co{'title'};
1589 $ref_item{'refid'} = $ref_id;
1590 $ref_item{'epoch'} = $co{'committer_epoch'};
1591 $ref_item{'age'} = $co{'age_string'};
1593 $ref_item{'reftype'} = $type;
1594 $ref_item{'name'} = $ref_file;
1595 $ref_item{'refid'} = $ref_id;
1601 # parse line of git-diff-tree "raw" output
1602 sub parse_difftree_raw_line
{
1606 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1607 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1608 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1609 $res{'from_mode'} = $1;
1610 $res{'to_mode'} = $2;
1611 $res{'from_id'} = $3;
1613 $res{'status'} = $5;
1614 $res{'similarity'} = $6;
1615 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1616 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1618 $res{'file'} = unquote
($7);
1621 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1622 # combined diff (for merge commit)
1623 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1624 $res{'nparents'} = length($1);
1625 $res{'from_mode'} = [ split(' ', $2) ];
1626 $res{'to_mode'} = pop @{$res{'from_mode'}};
1627 $res{'from_id'} = [ split(' ', $3) ];
1628 $res{'to_id'} = pop @{$res{'from_id'}};
1629 $res{'status'} = [ split('', $4) ];
1630 $res{'to_file'} = unquote
($5);
1632 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1633 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1634 $res{'commit'} = $1;
1637 return wantarray ? %res : \
%res;
1640 # parse line of git-ls-tree output
1641 sub parse_ls_tree_line
($;%) {
1646 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1647 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1655 $res{'name'} = unquote
($4);
1658 return wantarray ? %res : \
%res;
1661 ## ......................................................................
1662 ## parse to array of hashes functions
1664 sub git_get_heads_list
{
1668 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1669 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1670 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1673 while (my $line = <$fd>) {
1677 my ($refinfo, $committerinfo) = split(/\0/, $line);
1678 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1679 my ($committer, $epoch, $tz) =
1680 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1681 $name =~ s!^refs/heads/!!;
1683 $ref_item{'name'} = $name;
1684 $ref_item{'id'} = $hash;
1685 $ref_item{'title'} = $title || '(no commit message)';
1686 $ref_item{'epoch'} = $epoch;
1688 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1690 $ref_item{'age'} = "unknown";
1693 push @headslist, \
%ref_item;
1697 return wantarray ? @headslist : \
@headslist;
1700 sub git_get_tags_list
{
1704 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1705 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1706 '--format=%(objectname) %(objecttype) %(refname) '.
1707 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1710 while (my $line = <$fd>) {
1714 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1715 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1716 my ($creator, $epoch, $tz) =
1717 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1718 $name =~ s!^refs/tags/!!;
1720 $ref_item{'type'} = $type;
1721 $ref_item{'id'} = $id;
1722 $ref_item{'name'} = $name;
1723 if ($type eq "tag") {
1724 $ref_item{'subject'} = $title;
1725 $ref_item{'reftype'} = $reftype;
1726 $ref_item{'refid'} = $refid;
1728 $ref_item{'reftype'} = $type;
1729 $ref_item{'refid'} = $id;
1732 if ($type eq "tag" || $type eq "commit") {
1733 $ref_item{'epoch'} = $epoch;
1735 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1737 $ref_item{'age'} = "unknown";
1741 push @tagslist, \
%ref_item;
1745 return wantarray ? @tagslist : \
@tagslist;
1748 ## ----------------------------------------------------------------------
1749 ## filesystem-related functions
1751 sub get_file_owner
{
1754 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1755 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1756 if (!defined $gcos) {
1760 $owner =~ s/[,;].*$//;
1761 return decode_utf8
($owner);
1764 ## ......................................................................
1765 ## mimetype related functions
1767 sub mimetype_guess_file
{
1768 my $filename = shift;
1769 my $mimemap = shift;
1770 -r
$mimemap or return undef;
1773 open(MIME
, $mimemap) or return undef;
1775 next if m/^#/; # skip comments
1776 my ($mime, $exts) = split(/\t+/);
1777 if (defined $exts) {
1778 my @exts = split(/\s+/, $exts);
1779 foreach my $ext (@exts) {
1780 $mimemap{$ext} = $mime;
1786 $filename =~ /\.([^.]*)$/;
1787 return $mimemap{$1};
1790 sub mimetype_guess
{
1791 my $filename = shift;
1793 $filename =~ /\./ or return undef;
1795 if ($mimetypes_file) {
1796 my $file = $mimetypes_file;
1797 if ($file !~ m!^/!) { # if it is relative path
1798 # it is relative to project
1799 $file = "$projectroot/$project/$file";
1801 $mime = mimetype_guess_file
($filename, $file);
1803 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1809 my $filename = shift;
1812 my $mime = mimetype_guess
($filename);
1813 $mime and return $mime;
1817 return $default_blob_plain_mimetype unless $fd;
1820 return 'text/plain' .
1821 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1822 } elsif (! $filename) {
1823 return 'application/octet-stream';
1824 } elsif ($filename =~ m/\.png$/i) {
1826 } elsif ($filename =~ m/\.gif$/i) {
1828 } elsif ($filename =~ m/\.jpe?g$/i) {
1829 return 'image/jpeg';
1831 return 'application/octet-stream';
1835 ## ======================================================================
1836 ## functions printing HTML: header, footer, error page
1838 sub git_header_html
{
1839 my $status = shift || "200 OK";
1840 my $expires = shift;
1842 my $title = "$site_name";
1843 if (defined $project) {
1844 $title .= " - " . decode_utf8
($project);
1845 if (defined $action) {
1846 $title .= "/$action";
1847 if (defined $file_name) {
1848 $title .= " - " . esc_path
($file_name);
1849 if ($action eq "tree" && $file_name !~ m
|/$|) {
1856 # require explicit support from the UA if we are to send the page as
1857 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1858 # we have to do this because MSIE sometimes globs '*/*', pretending to
1859 # support xhtml+xml but choking when it gets what it asked for.
1860 if (defined $cgi->http('HTTP_ACCEPT') &&
1861 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1862 $cgi->Accept('application/xhtml+xml') != 0) {
1863 $content_type = 'application/xhtml+xml';
1865 $content_type = 'text/html';
1867 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1868 -status
=> $status, -expires
=> $expires);
1869 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
1871 <?xml version="1.0" encoding="utf-8"?>
1872 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1873 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1874 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1875 <!-- git core binaries version $git_version -->
1877 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1878 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
1879 <meta name="robots" content="index, nofollow"/>
1880 <title>$title</title>
1882 # print out each stylesheet that exist
1883 if (defined $stylesheet) {
1884 #provides backwards capability for those people who define style sheet in a config file
1885 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1887 foreach my $stylesheet (@stylesheets) {
1888 next unless $stylesheet;
1889 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1892 if (defined $project) {
1893 printf('<link rel="alternate" title="%s log RSS feed" '.
1894 'href="%s" type="application/rss+xml" />'."\n",
1895 esc_param
($project), href
(action
=>"rss"));
1896 printf('<link rel="alternate" title="%s log Atom feed" '.
1897 'href="%s" type="application/atom+xml" />'."\n",
1898 esc_param
($project), href
(action
=>"atom"));
1900 printf('<link rel="alternate" title="%s projects list" '.
1901 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1902 $site_name, href
(project
=>undef, action
=>"project_index"));
1903 printf('<link rel="alternate" title="%s projects feeds" '.
1904 'href="%s" type="text/x-opml"/>'."\n",
1905 $site_name, href
(project
=>undef, action
=>"opml"));
1907 if (defined $favicon) {
1908 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1914 if (-f
$site_header) {
1915 open (my $fd, $site_header);
1920 print "<div class=\"page_header\">\n" .
1921 $cgi->a({-href
=> esc_url
($logo_url),
1922 -title
=> $logo_label},
1923 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1924 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1925 if (defined $project) {
1926 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1927 if (defined $action) {
1934 my ($have_search) = gitweb_check_feature
('search');
1935 if ((defined $project) && ($have_search)) {
1936 if (!defined $searchtext) {
1940 if (defined $hash_base) {
1941 $search_hash = $hash_base;
1942 } elsif (defined $hash) {
1943 $search_hash = $hash;
1945 $search_hash = "HEAD";
1947 $cgi->param("a", "search");
1948 $cgi->param("h", $search_hash);
1949 $cgi->param("p", $project);
1950 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1951 "<div class=\"search\">\n" .
1952 $cgi->hidden(-name
=> "p") . "\n" .
1953 $cgi->hidden(-name
=> "a") . "\n" .
1954 $cgi->hidden(-name
=> "h") . "\n" .
1955 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1956 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
1957 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1959 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1961 $cgi->end_form() . "\n";
1965 sub git_footer_html
{
1966 print "<div class=\"page_footer\">\n";
1967 if (defined $project) {
1968 my $descr = git_get_project_description
($project);
1969 if (defined $descr) {
1970 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1972 print $cgi->a({-href
=> href
(action
=>"rss"),
1973 -class => "rss_logo"}, "RSS") . " ";
1974 print $cgi->a({-href
=> href
(action
=>"atom"),
1975 -class => "rss_logo"}, "Atom") . "\n";
1977 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1978 -class => "rss_logo"}, "OPML") . " ";
1979 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1980 -class => "rss_logo"}, "TXT") . "\n";
1984 if (-f
$site_footer) {
1985 open (my $fd, $site_footer);
1995 my $status = shift || "403 Forbidden";
1996 my $error = shift || "Malformed query, file missing or permission denied";
1998 git_header_html
($status);
2000 <div class="page_body">
2010 ## ----------------------------------------------------------------------
2011 ## functions printing or outputting HTML: navigation
2013 sub git_print_page_nav
{
2014 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2015 $extra = '' if !defined $extra; # pager or formats
2017 my @navs = qw(summary shortlog log commit commitdiff tree);
2019 @navs = grep { $_ ne $suppress } @navs;
2022 my %arg = map { $_ => {action
=>$_} } @navs;
2023 if (defined $head) {
2024 for (qw(commit commitdiff)) {
2025 $arg{$_}{'hash'} = $head;
2027 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2028 for (qw(shortlog log)) {
2029 $arg{$_}{'hash'} = $head;
2033 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2034 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2036 print "<div class=\"page_nav\">\n" .
2038 map { $_ eq $current ?
2039 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2041 print "<br/>\n$extra<br/>\n" .
2045 sub format_paging_nav
{
2046 my ($action, $hash, $head, $page, $nrevs) = @_;
2050 if ($hash ne $head || $page) {
2051 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2053 $paging_nav .= "HEAD";
2057 $paging_nav .= " ⋅ " .
2058 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2059 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2061 $paging_nav .= " ⋅ prev";
2064 if ($nrevs >= (100 * ($page+1)-1)) {
2065 $paging_nav .= " ⋅ " .
2066 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2067 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2069 $paging_nav .= " ⋅ next";
2075 ## ......................................................................
2076 ## functions printing or outputting HTML: div
2078 sub git_print_header_div
{
2079 my ($action, $title, $hash, $hash_base) = @_;
2082 $args{'action'} = $action;
2083 $args{'hash'} = $hash if $hash;
2084 $args{'hash_base'} = $hash_base if $hash_base;
2086 print "<div class=\"header\">\n" .
2087 $cgi->a({-href
=> href
(%args), -class => "title"},
2088 $title ? $title : $action) .
2092 #sub git_print_authorship (\%) {
2093 sub git_print_authorship
{
2096 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2097 print "<div class=\"author_date\">" .
2098 esc_html
($co->{'author_name'}) .
2100 if ($ad{'hour_local'} < 6) {
2101 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2102 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2104 printf(" (%02d:%02d %s)",
2105 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2110 sub git_print_page_path
{
2116 print "<div class=\"page_path\">";
2117 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2118 -title
=> 'tree root'}, decode_utf8
("[$project]"));
2120 if (defined $name) {
2121 my @dirname = split '/', $name;
2122 my $basename = pop @dirname;
2125 foreach my $dir (@dirname) {
2126 $fullname .= ($fullname ? '/' : '') . $dir;
2127 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2129 -title
=> $fullname}, esc_path
($dir));
2132 if (defined $type && $type eq 'blob') {
2133 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2135 -title
=> $name}, esc_path
($basename));
2136 } elsif (defined $type && $type eq 'tree') {
2137 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2139 -title
=> $name}, esc_path
($basename));
2142 print esc_path
($basename);
2145 print "<br/></div>\n";
2148 # sub git_print_log (\@;%) {
2149 sub git_print_log
($;%) {
2153 if ($opts{'-remove_title'}) {
2154 # remove title, i.e. first line of log
2157 # remove leading empty lines
2158 while (defined $log->[0] && $log->[0] eq "") {
2165 foreach my $line (@$log) {
2166 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2169 if (! $opts{'-remove_signoff'}) {
2170 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2173 # remove signoff lines
2180 # print only one empty line
2181 # do not print empty line after signoff
2183 next if ($empty || $signoff);
2189 print format_log_line_html
($line) . "<br/>\n";
2192 if ($opts{'-final_empty_line'}) {
2193 # end with single empty line
2194 print "<br/>\n" unless $empty;
2198 # return link target (what link points to)
2199 sub git_get_link_target
{
2204 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2208 $link_target = <$fd>;
2213 return $link_target;
2216 # given link target, and the directory (basedir) the link is in,
2217 # return target of link relative to top directory (top tree);
2218 # return undef if it is not possible (including absolute links).
2219 sub normalize_link_target
{
2220 my ($link_target, $basedir, $hash_base) = @_;
2222 # we can normalize symlink target only if $hash_base is provided
2223 return unless $hash_base;
2225 # absolute symlinks (beginning with '/') cannot be normalized
2226 return if (substr($link_target, 0, 1) eq '/');
2228 # normalize link target to path from top (root) tree (dir)
2231 $path = $basedir . '/' . $link_target;
2233 # we are in top (root) tree (dir)
2234 $path = $link_target;
2237 # remove //, /./, and /../
2239 foreach my $part (split('/', $path)) {
2240 # discard '.' and ''
2241 next if (!$part || $part eq '.');
2243 if ($part eq '..') {
2247 # link leads outside repository (outside top dir)
2251 push @path_parts, $part;
2254 $path = join('/', @path_parts);
2259 # print tree entry (row of git_tree), but without encompassing <tr> element
2260 sub git_print_tree_entry
{
2261 my ($t, $basedir, $hash_base, $have_blame) = @_;
2264 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2266 # The format of a table row is: mode list link. Where mode is
2267 # the mode of the entry, list is the name of the entry, an href,
2268 # and link is the action links of the entry.
2270 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2271 if ($t->{'type'} eq "blob") {
2272 print "<td class=\"list\">" .
2273 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2274 file_name
=>"$basedir$t->{'name'}", %base_key),
2275 -class => "list"}, esc_path
($t->{'name'}));
2276 if (S_ISLNK
(oct $t->{'mode'})) {
2277 my $link_target = git_get_link_target
($t->{'hash'});
2279 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2280 if (defined $norm_target) {
2282 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2283 file_name
=>$norm_target),
2284 -title
=> $norm_target}, esc_path
($link_target));
2286 print " -> " . esc_path
($link_target);
2291 print "<td class=\"link\">";
2292 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2293 file_name
=>"$basedir$t->{'name'}", %base_key)},
2297 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2298 file_name
=>"$basedir$t->{'name'}", %base_key)},
2301 if (defined $hash_base) {
2303 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2304 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2308 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2309 file_name
=>"$basedir$t->{'name'}")},
2313 } elsif ($t->{'type'} eq "tree") {
2314 print "<td class=\"list\">";
2315 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2316 file_name
=>"$basedir$t->{'name'}", %base_key)},
2317 esc_path
($t->{'name'}));
2319 print "<td class=\"link\">";
2320 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2321 file_name
=>"$basedir$t->{'name'}", %base_key)},
2323 if (defined $hash_base) {
2325 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2326 file_name
=>"$basedir$t->{'name'}")},
2333 ## ......................................................................
2334 ## functions printing large fragments of HTML
2336 sub fill_from_file_info
{
2337 my ($diff, @parents) = @_;
2339 $diff->{'from_file'} = [ ];
2340 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2341 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2342 if ($diff->{'status'}[$i] eq 'R' ||
2343 $diff->{'status'}[$i] eq 'C') {
2344 $diff->{'from_file'}[$i] =
2345 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2352 # parameters can be strings, or references to arrays of strings
2356 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @$a == @$b) {
2357 for (my $i = 0; $i < @$a; ++$i) {
2358 return 0 unless ($a->[$i] eq $b->[$i]);
2361 } elsif (!ref($a) && !ref($b)) {
2369 sub git_difftree_body
{
2370 my ($difftree, $hash, @parents) = @_;
2371 my ($parent) = $parents[0];
2372 my ($have_blame) = gitweb_check_feature
('blame');
2373 print "<div class=\"list_head\">\n";
2374 if ($#{$difftree} > 10) {
2375 print(($#{$difftree} + 1) . " files changed:\n");
2379 print "<table class=\"" .
2380 (@parents > 1 ? "combined " : "") .
2384 foreach my $line (@{$difftree}) {
2386 if (ref($line) eq "HASH") {
2387 # pre-parsed (or generated by hand)
2390 $diff = parse_difftree_raw_line
($line);
2394 print "<tr class=\"dark\">\n";
2396 print "<tr class=\"light\">\n";
2400 if (exists $diff->{'nparents'}) { # combined diff
2402 fill_from_file_info
($diff, @parents)
2403 unless exists $diff->{'from_file'};
2405 if ($diff->{'to_id'} ne ('0' x
40)) {
2406 # file exists in the result (child) commit
2408 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2409 file_name
=>$diff->{'to_file'},
2411 -class => "list"}, esc_path
($diff->{'to_file'})) .
2415 esc_path
($diff->{'to_file'}) .
2419 if ($action eq 'commitdiff') {
2422 print "<td class=\"link\">" .
2423 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2428 my $has_history = 0;
2429 my $not_deleted = 0;
2430 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2431 my $hash_parent = $parents[$i];
2432 my $from_hash = $diff->{'from_id'}[$i];
2433 my $from_path = $diff->{'from_file'}[$i];
2434 my $status = $diff->{'status'}[$i];
2436 $has_history ||= ($status ne 'A');
2437 $not_deleted ||= ($status ne 'D');
2439 if ($status eq 'A') {
2440 print "<td class=\"link\" align=\"right\"> | </td>\n";
2441 } elsif ($status eq 'D') {
2442 print "<td class=\"link\">" .
2443 $cgi->a({-href
=> href
(action
=>"blob",
2446 file_name
=>$from_path)},
2450 if ($diff->{'to_id'} eq $from_hash) {
2451 print "<td class=\"link nochange\">";
2453 print "<td class=\"link\">";
2455 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2456 hash
=>$diff->{'to_id'},
2457 hash_parent
=>$from_hash,
2459 hash_parent_base
=>$hash_parent,
2460 file_name
=>$diff->{'to_file'},
2461 file_parent
=>$from_path)},
2467 print "<td class=\"link\">";
2469 print $cgi->a({-href
=> href
(action
=>"blob",
2470 hash
=>$diff->{'to_id'},
2471 file_name
=>$diff->{'to_file'},
2474 print " | " if ($has_history);
2477 print $cgi->a({-href
=> href
(action
=>"history",
2478 file_name
=>$diff->{'to_file'},
2485 next; # instead of 'else' clause, to avoid extra indent
2487 # else ordinary diff
2489 my ($to_mode_oct, $to_mode_str, $to_file_type);
2490 my ($from_mode_oct, $from_mode_str, $from_file_type);
2491 if ($diff->{'to_mode'} ne ('0' x
6)) {
2492 $to_mode_oct = oct $diff->{'to_mode'};
2493 if (S_ISREG
($to_mode_oct)) { # only for regular file
2494 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2496 $to_file_type = file_type
($diff->{'to_mode'});
2498 if ($diff->{'from_mode'} ne ('0' x
6)) {
2499 $from_mode_oct = oct $diff->{'from_mode'};
2500 if (S_ISREG
($to_mode_oct)) { # only for regular file
2501 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2503 $from_file_type = file_type
($diff->{'from_mode'});
2506 if ($diff->{'status'} eq "A") { # created
2507 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2508 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2509 $mode_chng .= "]</span>";
2511 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2512 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2513 -class => "list"}, esc_path
($diff->{'file'}));
2515 print "<td>$mode_chng</td>\n";
2516 print "<td class=\"link\">";
2517 if ($action eq 'commitdiff') {
2520 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2523 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2524 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2528 } elsif ($diff->{'status'} eq "D") { # deleted
2529 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2531 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2532 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2533 -class => "list"}, esc_path
($diff->{'file'}));
2535 print "<td>$mode_chng</td>\n";
2536 print "<td class=\"link\">";
2537 if ($action eq 'commitdiff') {
2540 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2543 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2544 hash_base
=>$parent, file_name
=>$diff->{'file'})},
2547 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2548 file_name
=>$diff->{'file'})},
2551 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2552 file_name
=>$diff->{'file'})},
2556 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2557 my $mode_chnge = "";
2558 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2559 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2560 if ($from_file_type ne $to_file_type) {
2561 $mode_chnge .= " from $from_file_type to $to_file_type";
2563 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2564 if ($from_mode_str && $to_mode_str) {
2565 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2566 } elsif ($to_mode_str) {
2567 $mode_chnge .= " mode: $to_mode_str";
2570 $mode_chnge .= "]</span>\n";
2573 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2574 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2575 -class => "list"}, esc_path
($diff->{'file'}));
2577 print "<td>$mode_chnge</td>\n";
2578 print "<td class=\"link\">";
2579 if ($action eq 'commitdiff') {
2582 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2584 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2585 # "commit" view and modified file (not onlu mode changed)
2586 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2587 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2588 hash_base
=>$hash, hash_parent_base
=>$parent,
2589 file_name
=>$diff->{'file'})},
2593 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2594 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2597 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2598 file_name
=>$diff->{'file'})},
2601 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2602 file_name
=>$diff->{'file'})},
2606 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
2607 my %status_name = ('R' => 'moved', 'C' => 'copied');
2608 my $nstatus = $status_name{$diff->{'status'}};
2610 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2611 # mode also for directories, so we cannot use $to_mode_str
2612 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2615 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2616 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
2617 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
2618 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2619 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2620 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
2621 -class => "list"}, esc_path
($diff->{'from_file'})) .
2622 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2623 "<td class=\"link\">";
2624 if ($action eq 'commitdiff') {
2627 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2629 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2630 # "commit" view and modified file (not only pure rename or copy)
2631 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2632 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2633 hash_base
=>$hash, hash_parent_base
=>$parent,
2634 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
2638 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2639 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
2642 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2643 file_name
=>$diff->{'to_file'})},
2646 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2647 file_name
=>$diff->{'to_file'})},
2651 } # we should not encounter Unmerged (U) or Unknown (X) status
2657 sub git_patchset_body
{
2658 my ($fd, $difftree, $hash, @hash_parents) = @_;
2659 my ($hash_parent) = $hash_parents[0];
2662 my $patch_number = 0;
2667 print "<div class=\"patchset\">\n";
2669 # skip to first patch
2670 while ($patch_line = <$fd>) {
2673 last if ($patch_line =~ m/^diff /);
2677 while ($patch_line) {
2679 my ($from_id, $to_id);
2682 #assert($patch_line =~ m/^diff /) if DEBUG;
2683 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2685 push @diff_header, $patch_line;
2687 # extended diff header
2689 while ($patch_line = <$fd>) {
2692 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2694 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2697 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2698 $from_id = [ split(',', $1) ];
2702 push @diff_header, $patch_line;
2704 my $last_patch_line = $patch_line;
2706 # check if current patch belong to current raw line
2707 # and parse raw git-diff line if needed
2708 if (defined $diffinfo &&
2709 defined $from_id && defined $to_id &&
2710 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
2711 $diffinfo->{'to_id'} eq $to_id) {
2712 # this is continuation of a split patch
2713 print "<div class=\"patch cont\">\n";
2715 # advance raw git-diff output if needed
2716 $patch_idx++ if defined $diffinfo;
2718 # read and prepare patch information
2719 if (ref($difftree->[$patch_idx]) eq "HASH") {
2720 # pre-parsed (or generated by hand)
2721 $diffinfo = $difftree->[$patch_idx];
2723 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2725 if ($diffinfo->{'nparents'}) {
2729 fill_from_file_info
($diffinfo, @hash_parents)
2730 unless exists $diffinfo->{'from_file'};
2731 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2732 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2733 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2734 $from{'href'}[$i] = href
(action
=>"blob",
2735 hash_base
=>$hash_parents[$i],
2736 hash
=>$diffinfo->{'from_id'}[$i],
2737 file_name
=>$from{'file'}[$i]);
2739 $from{'href'}[$i] = undef;
2743 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2744 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2745 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2746 hash
=>$diffinfo->{'from_id'},
2747 file_name
=>$from{'file'});
2749 delete $from{'href'};
2753 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2754 if ($diffinfo->{'to_id'} ne ('0' x
40)) { # file exists in result
2755 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2756 hash
=>$diffinfo->{'to_id'},
2757 file_name
=>$to{'file'});
2761 # this is first patch for raw difftree line with $patch_idx index
2762 # we index @$difftree array from 0, but number patches from 1
2763 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2766 # print "git diff" header
2767 $patch_line = shift @diff_header;
2768 if ($diffinfo->{'nparents'}) {
2771 $patch_line =~ s!^(diff (.*?) )"?.*$!$1!;
2773 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2774 esc_path
($to{'file'}));
2775 } else { # file was deleted
2776 $patch_line .= esc_path
($to{'file'});
2781 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2782 if ($from{'href'}) {
2783 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2784 'a/' . esc_path
($from{'file'}));
2785 } else { # file was added
2786 $patch_line .= 'a/' . esc_path
($from{'file'});
2790 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2791 'b/' . esc_path
($to{'file'}));
2792 } else { # file was deleted
2793 $patch_line .= 'b/' . esc_path
($to{'file'});
2797 print "<div class=\"diff header\">$patch_line</div>\n";
2799 # print extended diff header
2800 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2802 foreach $patch_line (@diff_header) {
2804 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2805 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2806 esc_path
($from{'file'}));
2808 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2809 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2810 esc_path
($to{'file'}));
2812 # match single <mode>
2813 if ($patch_line =~ m/\s(\d{6})$/) {
2814 $patch_line .= '<span class="info"> (' .
2815 file_type_long
($1) .
2819 if ($patch_line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
2820 # can match only for combined diff
2821 $patch_line = 'index ';
2822 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2823 if ($from{'href'}[$i]) {
2824 $patch_line .= $cgi->a({-href
=>$from{'href'}[$i],
2826 substr($diffinfo->{'from_id'}[$i],0,7));
2828 $patch_line .= '0' x
7;
2831 $patch_line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
2833 $patch_line .= '..';
2835 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2836 substr($diffinfo->{'to_id'},0,7));
2838 $patch_line .= '0' x
7;
2841 } elsif ($patch_line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
2842 # can match only for ordinary diff
2843 my ($from_link, $to_link);
2844 if ($from{'href'}) {
2845 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2846 substr($diffinfo->{'from_id'},0,7));
2848 $from_link = '0' x
7;
2851 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2852 substr($diffinfo->{'to_id'},0,7));
2857 # my ($from_hash, $to_hash) =
2858 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2859 # my ($from_id, $to_id) =
2860 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2861 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2863 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2864 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2866 print $patch_line . "<br/>\n";
2868 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2870 # from-file/to-file diff header
2871 $patch_line = $last_patch_line;
2872 if (! $patch_line) {
2873 print "</div>\n"; # class="patch"
2876 next PATCH
if ($patch_line =~ m/^diff /);
2877 #assert($patch_line =~ m/^---/) if DEBUG;
2878 if (!$diffinfo->{'nparents'} && # not from-file line for combined diff
2879 $from{'href'} && $patch_line =~ m!^--- "?a/!) {
2880 $patch_line = '--- a/' .
2881 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2882 esc_path
($from{'file'}));
2884 print "<div class=\"diff from_file\">$patch_line</div>\n";
2886 $patch_line = <$fd>;
2889 #assert($patch_line =~ m/^+++/) if DEBUG;
2890 if ($to{'href'} && $patch_line =~ m!^\+\+\+ "?b/!) {
2891 $patch_line = '+++ b/' .
2892 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2893 esc_path
($to{'file'}));
2895 print "<div class=\"diff to_file\">$patch_line</div>\n";
2899 while ($patch_line = <$fd>) {
2902 next PATCH
if ($patch_line =~ m/^diff /);
2904 print format_diff_line
($patch_line, \
%from, \
%to);
2908 print "</div>\n"; # class="patch"
2911 if ($patch_number == 0) {
2912 if (@hash_parents > 1) {
2913 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
2915 print "<div class=\"diff nodifferences\">No differences found</div>\n";
2919 print "</div>\n"; # class="patchset"
2922 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2924 sub git_project_list_body
{
2925 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2927 my ($check_forks) = gitweb_check_feature
('forks');
2930 foreach my $pr (@$projlist) {
2931 my (@aa) = git_get_last_activity
($pr->{'path'});
2935 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2936 if (!defined $pr->{'descr'}) {
2937 my $descr = git_get_project_description
($pr->{'path'}) || "";
2938 $pr->{'descr_long'} = decode_utf8
($descr);
2939 $pr->{'descr'} = chop_str
($descr, 25, 5);
2941 if (!defined $pr->{'owner'}) {
2942 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2945 my $pname = $pr->{'path'};
2946 if (($pname =~ s/\.git$//) &&
2947 ($pname !~ /\/$/) &&
2948 (-d
"$projectroot/$pname")) {
2949 $pr->{'forks'} = "-d $projectroot/$pname";
2955 push @projects, $pr;
2958 $order ||= $default_projects_order;
2959 $from = 0 unless defined $from;
2960 $to = $#projects if (!defined $to || $#projects < $to);
2962 print "<table class=\"project_list\">\n";
2963 unless ($no_header) {
2966 print "<th></th>\n";
2968 if ($order eq "project") {
2969 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2970 print "<th>Project</th>\n";
2973 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2974 -class => "header"}, "Project") .
2977 if ($order eq "descr") {
2978 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2979 print "<th>Description</th>\n";
2982 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2983 -class => "header"}, "Description") .
2986 if ($order eq "owner") {
2987 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2988 print "<th>Owner</th>\n";
2991 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2992 -class => "header"}, "Owner") .
2995 if ($order eq "age") {
2996 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2997 print "<th>Last Change</th>\n";
3000 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3001 -class => "header"}, "Last Change") .
3004 print "<th></th>\n" .
3008 for (my $i = $from; $i <= $to; $i++) {
3009 my $pr = $projects[$i];
3011 print "<tr class=\"dark\">\n";
3013 print "<tr class=\"light\">\n";
3018 if ($pr->{'forks'}) {
3019 print "<!-- $pr->{'forks'} -->\n";
3020 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3024 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3025 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3026 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3027 -class => "list", -title
=> $pr->{'descr_long'}},
3028 esc_html
($pr->{'descr'})) . "</td>\n" .
3029 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
3030 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3031 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3032 "<td class=\"link\">" .
3033 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3034 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3035 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3036 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3037 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3041 if (defined $extra) {
3044 print "<td></td>\n";
3046 print "<td colspan=\"5\">$extra</td>\n" .
3052 sub git_shortlog_body
{
3053 # uses global variable $project
3054 my ($commitlist, $from, $to, $refs, $extra) = @_;
3056 my $have_snapshot = gitweb_have_snapshot
();
3058 $from = 0 unless defined $from;
3059 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3061 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3063 for (my $i = $from; $i <= $to; $i++) {
3064 my %co = %{$commitlist->[$i]};
3065 my $commit = $co{'id'};
3066 my $ref = format_ref_marker
($refs, $commit);
3068 print "<tr class=\"dark\">\n";
3070 print "<tr class=\"light\">\n";
3073 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3074 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3075 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3077 print format_subject_html
($co{'title'}, $co{'title_short'},
3078 href
(action
=>"commit", hash
=>$commit), $ref);
3080 "<td class=\"link\">" .
3081 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3082 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3083 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3084 if ($have_snapshot) {
3085 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
3090 if (defined $extra) {
3092 "<td colspan=\"4\">$extra</td>\n" .
3098 sub git_history_body
{
3099 # Warning: assumes constant type (blob or tree) during history
3100 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3102 $from = 0 unless defined $from;
3103 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3105 print "<table class=\"history\" cellspacing=\"0\">\n";
3107 for (my $i = $from; $i <= $to; $i++) {
3108 my %co = %{$commitlist->[$i]};
3112 my $commit = $co{'id'};
3114 my $ref = format_ref_marker
($refs, $commit);
3117 print "<tr class=\"dark\">\n";
3119 print "<tr class=\"light\">\n";
3122 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3123 # shortlog uses chop_str($co{'author_name'}, 10)
3124 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3126 # originally git_history used chop_str($co{'title'}, 50)
3127 print format_subject_html
($co{'title'}, $co{'title_short'},
3128 href
(action
=>"commit", hash
=>$commit), $ref);
3130 "<td class=\"link\">" .
3131 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3132 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3134 if ($ftype eq 'blob') {
3135 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3136 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3137 if (defined $blob_current && defined $blob_parent &&
3138 $blob_current ne $blob_parent) {
3140 $cgi->a({-href
=> href
(action
=>"blobdiff",
3141 hash
=>$blob_current, hash_parent
=>$blob_parent,
3142 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3143 file_name
=>$file_name)},
3150 if (defined $extra) {
3152 "<td colspan=\"4\">$extra</td>\n" .
3159 # uses global variable $project
3160 my ($taglist, $from, $to, $extra) = @_;
3161 $from = 0 unless defined $from;
3162 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3164 print "<table class=\"tags\" cellspacing=\"0\">\n";
3166 for (my $i = $from; $i <= $to; $i++) {
3167 my $entry = $taglist->[$i];
3169 my $comment = $tag{'subject'};
3171 if (defined $comment) {
3172 $comment_short = chop_str
($comment, 30, 5);
3175 print "<tr class=\"dark\">\n";
3177 print "<tr class=\"light\">\n";
3180 if (defined $tag{'age'}) {
3181 print "<td><i>$tag{'age'}</i></td>\n";
3183 print "<td></td>\n";
3186 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3187 -class => "list name"}, esc_html
($tag{'name'})) .
3190 if (defined $comment) {
3191 print format_subject_html
($comment, $comment_short,
3192 href
(action
=>"tag", hash
=>$tag{'id'}));
3195 "<td class=\"selflink\">";
3196 if ($tag{'type'} eq "tag") {
3197 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3202 "<td class=\"link\">" . " | " .
3203 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3204 if ($tag{'reftype'} eq "commit") {
3205 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3206 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3207 } elsif ($tag{'reftype'} eq "blob") {
3208 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3213 if (defined $extra) {
3215 "<td colspan=\"5\">$extra</td>\n" .
3221 sub git_heads_body
{
3222 # uses global variable $project
3223 my ($headlist, $head, $from, $to, $extra) = @_;
3224 $from = 0 unless defined $from;
3225 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3227 print "<table class=\"heads\" cellspacing=\"0\">\n";
3229 for (my $i = $from; $i <= $to; $i++) {
3230 my $entry = $headlist->[$i];
3232 my $curr = $ref{'id'} eq $head;
3234 print "<tr class=\"dark\">\n";
3236 print "<tr class=\"light\">\n";
3239 print "<td><i>$ref{'age'}</i></td>\n" .
3240 ($curr ? "<td class=\"current_head\">" : "<td>") .
3241 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3242 -class => "list name"},esc_html
($ref{'name'})) .
3244 "<td class=\"link\">" .
3245 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3246 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3247 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3251 if (defined $extra) {
3253 "<td colspan=\"3\">$extra</td>\n" .
3259 sub git_search_grep_body
{
3260 my ($commitlist, $from, $to, $extra) = @_;
3261 $from = 0 unless defined $from;
3262 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3264 print "<table class=\"grep\" cellspacing=\"0\">\n";
3266 for (my $i = $from; $i <= $to; $i++) {
3267 my %co = %{$commitlist->[$i]};
3271 my $commit = $co{'id'};
3273 print "<tr class=\"dark\">\n";
3275 print "<tr class=\"light\">\n";
3278 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3279 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3281 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3282 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3283 my $comment = $co{'comment'};
3284 foreach my $line (@$comment) {
3285 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3286 my $lead = esc_html
($1) || "";
3287 $lead = chop_str
($lead, 30, 10);
3288 my $match = esc_html
($2) || "";
3289 my $trail = esc_html
($3) || "";
3290 $trail = chop_str
($trail, 30, 10);
3291 my $text = "$lead<span class=\"match\">$match</span>$trail";
3292 print chop_str
($text, 80, 5) . "<br/>\n";
3296 "<td class=\"link\">" .
3297 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3299 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3303 if (defined $extra) {
3305 "<td colspan=\"3\">$extra</td>\n" .
3311 ## ======================================================================
3312 ## ======================================================================
3315 sub git_project_list
{
3316 my $order = $cgi->param('o');
3317 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3318 die_error
(undef, "Unknown order parameter");
3321 my @list = git_get_projects_list
();
3323 die_error
(undef, "No projects found");
3327 if (-f
$home_text) {
3328 print "<div class=\"index_include\">\n";
3329 open (my $fd, $home_text);
3334 git_project_list_body
(\
@list, $order);
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
($project);
3346 die_error
(undef, "No forks found");
3350 git_print_page_nav
('','');
3351 git_print_header_div
('summary', "$project forks");
3352 git_project_list_body
(\
@list, $order);
3356 sub git_project_index
{
3357 my @projects = git_get_projects_list
($project);
3360 -type
=> 'text/plain',
3361 -charset
=> 'utf-8',
3362 -content_disposition
=> 'inline; filename="index.aux"');
3364 foreach my $pr (@projects) {
3365 if (!exists $pr->{'owner'}) {
3366 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3369 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3370 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3371 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3372 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3376 print "$path $owner\n";
3381 my $descr = git_get_project_description
($project) || "none";
3382 my %co = parse_commit
("HEAD");
3383 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3384 my $head = $co{'id'};
3386 my $owner = git_get_project_owner
($project);
3388 my $refs = git_get_references
();
3389 # These get_*_list functions return one more to allow us to see if
3390 # there are more ...
3391 my @taglist = git_get_tags_list
(16);
3392 my @headlist = git_get_heads_list
(16);
3394 my ($check_forks) = gitweb_check_feature
('forks');
3397 @forklist = git_get_projects_list
($project);
3401 git_print_page_nav
('summary','', $head);
3403 print "<div class=\"title\"> </div>\n";
3404 print "<table cellspacing=\"0\">\n" .
3405 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3406 "<tr><td>owner</td><td>$owner</td></tr>\n";
3407 if (defined $cd{'rfc2822'}) {
3408 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3411 # use per project git URL list in $projectroot/$project/cloneurl
3412 # or make project git URL from git base URL and project name
3413 my $url_tag = "URL";
3414 my @url_list = git_get_project_url_list
($project);
3415 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3416 foreach my $git_url (@url_list) {
3417 next unless $git_url;
3418 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3423 if (-s
"$projectroot/$project/README.html") {
3424 if (open my $fd, "$projectroot/$project/README.html") {
3425 print "<div class=\"title\">readme</div>\n";
3426 print $_ while (<$fd>);
3431 # we need to request one more than 16 (0..15) to check if
3433 my @commitlist = $head ? parse_commits
($head, 17) : ();
3435 git_print_header_div
('shortlog');
3436 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3437 $#commitlist <= 15 ? undef :
3438 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3442 git_print_header_div
('tags');
3443 git_tags_body
(\
@taglist, 0, 15,
3444 $#taglist <= 15 ? undef :
3445 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3449 git_print_header_div
('heads');
3450 git_heads_body
(\
@headlist, $head, 0, 15,
3451 $#headlist <= 15 ? undef :
3452 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3456 git_print_header_div
('forks');
3457 git_project_list_body
(\
@forklist, undef, 0, 15,
3458 $#forklist <= 15 ? undef :
3459 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3467 my $head = git_get_head_hash
($project);
3469 git_print_page_nav
('','', $head,undef,$head);
3470 my %tag = parse_tag
($hash);
3473 die_error
(undef, "Unknown tag object");
3476 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3477 print "<div class=\"title_text\">\n" .
3478 "<table cellspacing=\"0\">\n" .
3480 "<td>object</td>\n" .
3481 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3482 $tag{'object'}) . "</td>\n" .
3483 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3484 $tag{'type'}) . "</td>\n" .
3486 if (defined($tag{'author'})) {
3487 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3488 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3489 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3490 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3493 print "</table>\n\n" .
3495 print "<div class=\"page_body\">";
3496 my $comment = $tag{'comment'};
3497 foreach my $line (@$comment) {
3499 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3509 my ($have_blame) = gitweb_check_feature
('blame');
3511 die_error
('403 Permission denied', "Permission denied");
3513 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3514 $hash_base ||= git_get_head_hash
($project);
3515 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3516 my %co = parse_commit
($hash_base)
3517 or die_error
(undef, "Reading commit failed");
3518 if (!defined $hash) {
3519 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3520 or die_error
(undef, "Error looking up file");
3522 $ftype = git_get_type
($hash);
3523 if ($ftype !~ "blob") {
3524 die_error
('400 Bad Request', "Object is not a blob");
3526 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3527 $file_name, $hash_base)
3528 or die_error
(undef, "Open git-blame failed");
3531 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3534 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3537 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3539 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3540 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3541 git_print_page_path
($file_name, $ftype, $hash_base);
3542 my @rev_color = (qw(light2 dark2));
3543 my $num_colors = scalar(@rev_color);
3544 my $current_color = 0;
3547 <div class="page_body">
3548 <table class="blame">
3549 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3554 last unless defined $_;
3555 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3556 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3557 if (!exists $metainfo{$full_rev}) {
3558 $metainfo{$full_rev} = {};
3560 my $meta = $metainfo{$full_rev};
3563 if (/^(\S+) (.*)$/) {
3569 my $rev = substr($full_rev, 0, 8);
3570 my $author = $meta->{'author'};
3571 my %date = parse_date
($meta->{'author-time'},
3572 $meta->{'author-tz'});
3573 my $date = $date{'iso-tz'};
3575 $current_color = ++$current_color % $num_colors;
3577 print "<tr class=\"$rev_color[$current_color]\">\n";
3579 print "<td class=\"sha1\"";
3580 print " title=\"". esc_html
($author) . ", $date\"";
3581 print " rowspan=\"$group_size\"" if ($group_size > 1);
3583 print $cgi->a({-href
=> href
(action
=>"commit",
3585 file_name
=>$file_name)},
3589 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3590 or die_error
(undef, "Open git-rev-parse failed");
3591 my $parent_commit = <$dd>;
3593 chomp($parent_commit);
3594 my $blamed = href
(action
=> 'blame',
3595 file_name
=> $meta->{'filename'},
3596 hash_base
=> $parent_commit);
3597 print "<td class=\"linenr\">";
3598 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3600 -class => "linenr" },
3603 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3609 or print "Reading blob failed\n";
3616 my ($have_blame) = gitweb_check_feature
('blame');
3618 die_error
('403 Permission denied', "Permission denied");
3620 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3621 $hash_base ||= git_get_head_hash
($project);
3622 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3623 my %co = parse_commit
($hash_base)
3624 or die_error
(undef, "Reading commit failed");
3625 if (!defined $hash) {
3626 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3627 or die_error
(undef, "Error lookup file");
3629 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3630 or die_error
(undef, "Open git-annotate failed");
3633 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3636 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3639 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3641 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3642 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3643 git_print_page_path
($file_name, 'blob', $hash_base);
3644 print "<div class=\"page_body\">\n";
3646 <table class="blame">
3655 my @line_class = (qw(light dark));
3656 my $line_class_len = scalar (@line_class);
3657 my $line_class_num = $#line_class;
3658 while (my $line = <$fd>) {
3670 $line_class_num = ($line_class_num + 1) % $line_class_len;
3672 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3679 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3682 $short_rev = substr ($long_rev, 0, 8);
3683 $age = time () - $time;
3684 $age_str = age_string
($age);
3685 $age_str =~ s/ / /g;
3686 $age_class = age_class
($age);
3687 $author = esc_html
($author);
3688 $author =~ s/ / /g;
3690 $data = untabify
($data);
3691 $data = esc_html
($data);
3694 <tr class="$line_class[$line_class_num]">
3695 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3696 <td class="$age_class">$age_str</td>
3698 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3699 <td class="pre">$data</td>
3702 } # while (my $line = <$fd>)
3703 print "</table>\n\n";
3705 or print "Reading blob failed.\n";
3711 my $head = git_get_head_hash
($project);
3713 git_print_page_nav
('','', $head,undef,$head);
3714 git_print_header_div
('summary', $project);
3716 my @tagslist = git_get_tags_list
();
3718 git_tags_body
(\
@tagslist);
3724 my $head = git_get_head_hash
($project);
3726 git_print_page_nav
('','', $head,undef,$head);
3727 git_print_header_div
('summary', $project);
3729 my @headslist = git_get_heads_list
();
3731 git_heads_body
(\
@headslist, $head);
3736 sub git_blob_plain
{
3739 if (!defined $hash) {
3740 if (defined $file_name) {
3741 my $base = $hash_base || git_get_head_hash
($project);
3742 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3743 or die_error
(undef, "Error lookup file");
3745 die_error
(undef, "No file name defined");
3747 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3748 # blobs defined by non-textual hash id's can be cached
3753 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3754 or die_error
(undef, "Couldn't cat $file_name, $hash");
3756 $type ||= blob_mimetype
($fd, $file_name);
3758 # save as filename, even when no $file_name is given
3759 my $save_as = "$hash";
3760 if (defined $file_name) {
3761 $save_as = $file_name;
3762 } elsif ($type =~ m/^text\//) {
3769 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3771 binmode STDOUT
, ':raw';
3773 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3781 if (!defined $hash) {
3782 if (defined $file_name) {
3783 my $base = $hash_base || git_get_head_hash
($project);
3784 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3785 or die_error
(undef, "Error lookup file");
3787 die_error
(undef, "No file name defined");
3789 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3790 # blobs defined by non-textual hash id's can be cached
3794 my ($have_blame) = gitweb_check_feature
('blame');
3795 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3796 or die_error
(undef, "Couldn't cat $file_name, $hash");
3797 my $mimetype = blob_mimetype
($fd, $file_name);
3798 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3800 return git_blob_plain
($mimetype);
3802 # we can have blame only for text/* mimetype
3803 $have_blame &&= ($mimetype =~ m!^text/!);
3805 git_header_html
(undef, $expires);
3806 my $formats_nav = '';
3807 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3808 if (defined $file_name) {
3811 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3812 hash
=>$hash, file_name
=>$file_name)},
3817 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3818 hash
=>$hash, file_name
=>$file_name)},
3821 $cgi->a({-href
=> href
(action
=>"blob_plain",
3822 hash
=>$hash, file_name
=>$file_name)},
3825 $cgi->a({-href
=> href
(action
=>"blob",
3826 hash_base
=>"HEAD", file_name
=>$file_name)},
3830 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3832 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3833 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3835 print "<div class=\"page_nav\">\n" .
3836 "<br/><br/></div>\n" .
3837 "<div class=\"title\">$hash</div>\n";
3839 git_print_page_path
($file_name, "blob", $hash_base);
3840 print "<div class=\"page_body\">\n";
3841 if ($mimetype =~ m!^text/!) {
3843 while (my $line = <$fd>) {
3846 $line = untabify
($line);
3847 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3848 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3850 } elsif ($mimetype =~ m!^image/!) {
3851 print qq
!<img type
="$mimetype"!;
3853 print qq
! alt
="$file_name" title
="$file_name"!;
3856 href(action=>"blob_plain
", hash=>$hash,
3857 hash_base=>$hash_base, file_name=>$file_name) .
3861 or print "Reading blob failed.\n";
3867 my $have_snapshot = gitweb_have_snapshot
();
3869 if (!defined $hash_base) {
3870 $hash_base = "HEAD";
3872 if (!defined $hash) {
3873 if (defined $file_name) {
3874 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3880 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3881 or die_error
(undef, "Open git-ls-tree failed");
3882 my @entries = map { chomp; $_ } <$fd>;
3883 close $fd or die_error
(undef, "Reading tree failed");
3886 my $refs = git_get_references
();
3887 my $ref = format_ref_marker
($refs, $hash_base);
3890 my ($have_blame) = gitweb_check_feature
('blame');
3891 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3893 if (defined $file_name) {
3895 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3896 hash
=>$hash, file_name
=>$file_name)},
3898 $cgi->a({-href
=> href
(action
=>"tree",
3899 hash_base
=>"HEAD", file_name
=>$file_name)},
3902 if ($have_snapshot) {
3903 # FIXME: Should be available when we have no hash base as well.
3905 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3908 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3909 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3912 print "<div class=\"page_nav\">\n";
3913 print "<br/><br/></div>\n";
3914 print "<div class=\"title\">$hash</div>\n";
3916 if (defined $file_name) {
3917 $basedir = $file_name;
3918 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3922 git_print_page_path
($file_name, 'tree', $hash_base);
3923 print "<div class=\"page_body\">\n";
3924 print "<table cellspacing=\"0\">\n";
3926 # '..' (top directory) link if possible
3927 if (defined $hash_base &&
3928 defined $file_name && $file_name =~ m![^/]+$!) {
3930 print "<tr class=\"dark\">\n";
3932 print "<tr class=\"light\">\n";
3936 my $up = $file_name;
3937 $up =~ s!/?[^/]+$!!;
3938 undef $up unless $up;
3939 # based on git_print_tree_entry
3940 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3941 print '<td class="list">';
3942 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3946 print "<td class=\"link\"></td>\n";
3950 foreach my $line (@entries) {
3951 my %t = parse_ls_tree_line
($line, -z
=> 1);
3954 print "<tr class=\"dark\">\n";
3956 print "<tr class=\"light\">\n";
3960 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3964 print "</table>\n" .
3970 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3971 my $have_snapshot = (defined $ctype && defined $suffix);
3972 if (!$have_snapshot) {
3973 die_error
('403 Permission denied', "Permission denied");
3976 if (!defined $hash) {
3977 $hash = git_get_head_hash
($project);
3980 my $filename = decode_utf8
(basename
($project)) . "-$hash.tar.$suffix";
3983 -type
=> "application/$ctype",
3984 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3985 -status
=> '200 OK');
3987 my $git = git_cmd_str
();
3988 my $name = $project;
3989 $name =~ s/\047/\047\\\047\047/g;
3991 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3992 or die_error
(undef, "Execute git-tar-tree failed");
3993 binmode STDOUT
, ':raw';
3995 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4001 my $head = git_get_head_hash
($project);
4002 if (!defined $hash) {
4005 if (!defined $page) {
4008 my $refs = git_get_references
();
4010 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4012 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4015 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4018 my %co = parse_commit
($hash);
4020 git_print_header_div
('summary', $project);
4021 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4023 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4024 for (my $i = 0; $i <= $to; $i++) {
4025 my %co = %{$commitlist[$i]};
4027 my $commit = $co{'id'};
4028 my $ref = format_ref_marker
($refs, $commit);
4029 my %ad = parse_date
($co{'author_epoch'});
4030 git_print_header_div
('commit',
4031 "<span class=\"age\">$co{'age_string'}</span>" .
4032 esc_html
($co{'title'}) . $ref,
4034 print "<div class=\"title_text\">\n" .
4035 "<div class=\"log_link\">\n" .
4036 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4038 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4040 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4043 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4046 print "<div class=\"log_body\">\n";
4047 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4050 if ($#commitlist >= 100) {
4051 print "<div class=\"page_nav\">\n";
4052 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4053 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4060 $hash ||= $hash_base || "HEAD";
4061 my %co = parse_commit
($hash);
4063 die_error
(undef, "Unknown commit object");
4065 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4066 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4068 my $parent = $co{'parent'};
4069 my $parents = $co{'parents'}; # listref
4071 # we need to prepare $formats_nav before any parameter munging
4073 if (!defined $parent) {
4075 $formats_nav .= '(initial)';
4076 } elsif (@$parents == 1) {
4077 # single parent commit
4080 $cgi->a({-href
=> href
(action
=>"commit",
4082 esc_html
(substr($parent, 0, 7))) .
4089 $cgi->a({-href
=> href
(action
=>"commit",
4091 esc_html
(substr($_, 0, 7)));
4096 if (!defined $parent) {
4100 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4102 (@$parents <= 1 ? $parent : '-c'),
4104 or die_error
(undef, "Open git-diff-tree failed");
4105 @difftree = map { chomp; $_ } <$fd>;
4106 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4108 # non-textual hash id's can be cached
4110 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4113 my $refs = git_get_references
();
4114 my $ref = format_ref_marker
($refs, $co{'id'});
4116 my $have_snapshot = gitweb_have_snapshot
();
4118 git_header_html
(undef, $expires);
4119 git_print_page_nav
('commit', '',
4120 $hash, $co{'tree'}, $hash,
4123 if (defined $co{'parent'}) {
4124 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4126 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4128 print "<div class=\"title_text\">\n" .
4129 "<table cellspacing=\"0\">\n";
4130 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4132 "<td></td><td> $ad{'rfc2822'}";
4133 if ($ad{'hour_local'} < 6) {
4134 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4135 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4137 printf(" (%02d:%02d %s)",
4138 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4142 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4143 print "<tr><td></td><td> $cd{'rfc2822'}" .
4144 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4146 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4149 "<td class=\"sha1\">" .
4150 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4151 class => "list"}, $co{'tree'}) .
4153 "<td class=\"link\">" .
4154 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4156 if ($have_snapshot) {
4158 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
4163 foreach my $par (@$parents) {
4166 "<td class=\"sha1\">" .
4167 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4168 class => "list"}, $par) .
4170 "<td class=\"link\">" .
4171 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4173 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4180 print "<div class=\"page_body\">\n";
4181 git_print_log
($co{'comment'});
4184 git_difftree_body
(\
@difftree, $hash, @$parents);
4190 # object is defined by:
4191 # - hash or hash_base alone
4192 # - hash_base and file_name
4195 # - hash or hash_base alone
4196 if ($hash || ($hash_base && !defined $file_name)) {
4197 my $object_id = $hash || $hash_base;
4199 my $git_command = git_cmd_str
();
4200 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4201 or die_error
('404 Not Found', "Object does not exist");
4205 or die_error
('404 Not Found', "Object does not exist");
4207 # - hash_base and file_name
4208 } elsif ($hash_base && defined $file_name) {
4209 $file_name =~ s
,/+$,,;
4211 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4212 or die_error
('404 Not Found', "Base object does not exist");
4214 # here errors should not hapen
4215 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4216 or die_error
(undef, "Open git-ls-tree failed");
4220 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4221 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4222 die_error
('404 Not Found', "File or directory for given base does not exist");
4227 die_error
('404 Not Found', "Not enough information to find object");
4230 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4231 hash
=>$hash, hash_base
=>$hash_base,
4232 file_name
=>$file_name),
4233 -status
=> '302 Found');
4237 my $format = shift || 'html';
4244 # preparing $fd and %diffinfo for git_patchset_body
4246 if (defined $hash_base && defined $hash_parent_base) {
4247 if (defined $file_name) {
4249 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4250 $hash_parent_base, $hash_base,
4251 "--", (defined $file_parent ? $file_parent : ()), $file_name
4252 or die_error
(undef, "Open git-diff-tree failed");
4253 @difftree = map { chomp; $_ } <$fd>;
4255 or die_error
(undef, "Reading git-diff-tree failed");
4257 or die_error
('404 Not Found', "Blob diff not found");
4259 } elsif (defined $hash &&
4260 $hash =~ /[0-9a-fA-F]{40}/) {
4261 # try to find filename from $hash
4263 # read filtered raw output
4264 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4265 $hash_parent_base, $hash_base, "--"
4266 or die_error
(undef, "Open git-diff-tree failed");
4268 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4270 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4271 map { chomp; $_ } <$fd>;
4273 or die_error
(undef, "Reading git-diff-tree failed");
4275 or die_error
('404 Not Found', "Blob diff not found");
4278 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4281 if (@difftree > 1) {
4282 die_error
('404 Not Found', "Ambiguous blob diff specification");
4285 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4286 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4287 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4289 $hash_parent ||= $diffinfo{'from_id'};
4290 $hash ||= $diffinfo{'to_id'};
4292 # non-textual hash id's can be cached
4293 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4294 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4299 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4300 '-p', ($format eq 'html' ? "--full-index" : ()),
4301 $hash_parent_base, $hash_base,
4302 "--", (defined $file_parent ? $file_parent : ()), $file_name
4303 or die_error
(undef, "Open git-diff-tree failed");
4306 # old/legacy style URI
4307 if (!%diffinfo && # if new style URI failed
4308 defined $hash && defined $hash_parent) {
4309 # fake git-diff-tree raw output
4310 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4311 $diffinfo{'from_id'} = $hash_parent;
4312 $diffinfo{'to_id'} = $hash;
4313 if (defined $file_name) {
4314 if (defined $file_parent) {
4315 $diffinfo{'status'} = '2';
4316 $diffinfo{'from_file'} = $file_parent;
4317 $diffinfo{'to_file'} = $file_name;
4318 } else { # assume not renamed
4319 $diffinfo{'status'} = '1';
4320 $diffinfo{'from_file'} = $file_name;
4321 $diffinfo{'to_file'} = $file_name;
4323 } else { # no filename given
4324 $diffinfo{'status'} = '2';
4325 $diffinfo{'from_file'} = $hash_parent;
4326 $diffinfo{'to_file'} = $hash;
4329 # non-textual hash id's can be cached
4330 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4331 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4336 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4337 '-p', ($format eq 'html' ? "--full-index" : ()),
4338 $hash_parent, $hash, "--"
4339 or die_error
(undef, "Open git-diff failed");
4341 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4346 if ($format eq 'html') {
4348 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4349 hash
=>$hash, hash_parent
=>$hash_parent,
4350 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4351 file_name
=>$file_name, file_parent
=>$file_parent)},
4353 git_header_html
(undef, $expires);
4354 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4355 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4356 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4358 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4359 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4361 if (defined $file_name) {
4362 git_print_page_path
($file_name, "blob", $hash_base);
4364 print "<div class=\"page_path\"></div>\n";
4367 } elsif ($format eq 'plain') {
4369 -type
=> 'text/plain',
4370 -charset
=> 'utf-8',
4371 -expires
=> $expires,
4372 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4374 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4377 die_error
(undef, "Unknown blobdiff format");
4381 if ($format eq 'html') {
4382 print "<div class=\"page_body\">\n";
4384 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4387 print "</div>\n"; # class="page_body"
4391 while (my $line = <$fd>) {
4392 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4393 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4397 last if $line =~ m!^\+\+\+!;
4405 sub git_blobdiff_plain
{
4406 git_blobdiff
('plain');
4409 sub git_commitdiff
{
4410 my $format = shift || 'html';
4411 $hash ||= $hash_base || "HEAD";
4412 my %co = parse_commit
($hash);
4414 die_error
(undef, "Unknown commit object");
4417 # we need to prepare $formats_nav before any parameter munging
4419 if ($format eq 'html') {
4421 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4422 hash
=>$hash, hash_parent
=>$hash_parent)},
4425 if (defined $hash_parent) {
4426 # commitdiff with two commits given
4427 my $hash_parent_short = $hash_parent;
4428 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4429 $hash_parent_short = substr($hash_parent, 0, 7);
4433 $cgi->a({-href
=> href
(action
=>"commitdiff",
4434 hash
=>$hash_parent)},
4435 esc_html
($hash_parent_short)) .
4437 } elsif (!$co{'parent'}) {
4439 $formats_nav .= ' (initial)';
4440 } elsif (scalar @{$co{'parents'}} == 1) {
4441 # single parent commit
4444 $cgi->a({-href
=> href
(action
=>"commitdiff",
4445 hash
=>$co{'parent'})},
4446 esc_html
(substr($co{'parent'}, 0, 7))) .
4453 $cgi->a({-href
=> href
(action
=>"commitdiff",
4455 esc_html
(substr($_, 0, 7)));
4456 } @{$co{'parents'}} ) .
4461 my $hash_parent_param = $hash_parent;
4462 if (!defined $hash_parent) {
4463 $hash_parent_param =
4464 @{$co{'parents'}} > 1 ? '-c' : $co{'parent'} || '--root';
4470 if ($format eq 'html') {
4471 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4472 "--no-commit-id", "--patch-with-raw", "--full-index",
4473 $hash_parent_param, $hash, "--"
4474 or die_error
(undef, "Open git-diff-tree failed");
4476 while (my $line = <$fd>) {
4478 # empty line ends raw part of diff-tree output
4480 push @difftree, scalar parse_difftree_raw_line
($line);
4483 } elsif ($format eq 'plain') {
4484 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4485 '-p', $hash_parent_param, $hash, "--"
4486 or die_error
(undef, "Open git-diff-tree failed");
4489 die_error
(undef, "Unknown commitdiff format");
4492 # non-textual hash id's can be cached
4494 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4498 # write commit message
4499 if ($format eq 'html') {
4500 my $refs = git_get_references
();
4501 my $ref = format_ref_marker
($refs, $co{'id'});
4503 git_header_html
(undef, $expires);
4504 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4505 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4506 git_print_authorship
(\
%co);
4507 print "<div class=\"page_body\">\n";
4508 if (@{$co{'comment'}} > 1) {
4509 print "<div class=\"log\">\n";
4510 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4511 print "</div>\n"; # class="log"
4514 } elsif ($format eq 'plain') {
4515 my $refs = git_get_references
("tags");
4516 my $tagname = git_get_rev_name_tags
($hash);
4517 my $filename = basename
($project) . "-$hash.patch";
4520 -type
=> 'text/plain',
4521 -charset
=> 'utf-8',
4522 -expires
=> $expires,
4523 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4524 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4527 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4528 Subject: $co{'title'}
4530 print "X-Git-Tag: $tagname\n" if $tagname;
4531 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4533 foreach my $line (@{$co{'comment'}}) {
4540 if ($format eq 'html') {
4541 git_difftree_body
(\
@difftree, $hash, $hash_parent || @{$co{'parents'}});
4544 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent || @{$co{'parents'}});
4546 print "</div>\n"; # class="page_body"
4549 } elsif ($format eq 'plain') {
4553 or print "Reading git-diff-tree failed\n";
4557 sub git_commitdiff_plain
{
4558 git_commitdiff
('plain');
4562 if (!defined $hash_base) {
4563 $hash_base = git_get_head_hash
($project);
4565 if (!defined $page) {
4569 my %co = parse_commit
($hash_base);
4571 die_error
(undef, "Unknown commit object");
4574 my $refs = git_get_references
();
4575 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4577 if (!defined $hash && defined $file_name) {
4578 $hash = git_get_hash_by_path
($hash_base, $file_name);
4580 if (defined $hash) {
4581 $ftype = git_get_type
($hash);
4584 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4586 my $paging_nav = '';
4589 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4590 file_name
=>$file_name)},
4592 $paging_nav .= " ⋅ " .
4593 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4594 file_name
=>$file_name, page
=>$page-1),
4595 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4597 $paging_nav .= "first";
4598 $paging_nav .= " ⋅ prev";
4600 if ($#commitlist >= 100) {
4601 $paging_nav .= " ⋅ " .
4602 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4603 file_name
=>$file_name, page
=>$page+1),
4604 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4606 $paging_nav .= " ⋅ next";
4609 if ($#commitlist >= 100) {
4611 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4612 file_name
=>$file_name, page
=>$page+1),
4613 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4617 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4618 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4619 git_print_page_path
($file_name, $ftype, $hash_base);
4621 git_history_body
(\
@commitlist, 0, 99,
4622 $refs, $hash_base, $ftype, $next_link);
4628 my ($have_search) = gitweb_check_feature
('search');
4629 if (!$have_search) {
4630 die_error
('403 Permission denied', "Permission denied");
4632 if (!defined $searchtext) {
4633 die_error
(undef, "Text field empty");
4635 if (!defined $hash) {
4636 $hash = git_get_head_hash
($project);
4638 my %co = parse_commit
($hash);
4640 die_error
(undef, "Unknown commit object");
4642 if (!defined $page) {
4646 $searchtype ||= 'commit';
4647 if ($searchtype eq 'pickaxe') {
4648 # pickaxe may take all resources of your box and run for several minutes
4649 # with every query - so decide by yourself how public you make this feature
4650 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4651 if (!$have_pickaxe) {
4652 die_error
('403 Permission denied', "Permission denied");
4655 if ($searchtype eq 'grep') {
4656 my ($have_grep) = gitweb_check_feature
('grep');
4658 die_error
('403 Permission denied', "Permission denied");
4664 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4666 if ($searchtype eq 'commit') {
4667 $greptype = "--grep=";
4668 } elsif ($searchtype eq 'author') {
4669 $greptype = "--author=";
4670 } elsif ($searchtype eq 'committer') {
4671 $greptype = "--committer=";
4673 $greptype .= $search_regexp;
4674 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4676 my $paging_nav = '';
4679 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4680 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4682 $paging_nav .= " ⋅ " .
4683 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4684 searchtext
=>$searchtext, searchtype
=>$searchtype,
4686 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4688 $paging_nav .= "first";
4689 $paging_nav .= " ⋅ prev";
4691 if ($#commitlist >= 100) {
4692 $paging_nav .= " ⋅ " .
4693 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4694 searchtext
=>$searchtext, searchtype
=>$searchtype,
4696 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4698 $paging_nav .= " ⋅ next";
4701 if ($#commitlist >= 100) {
4703 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4704 searchtext
=>$searchtext, searchtype
=>$searchtype,
4706 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4709 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4710 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4711 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4714 if ($searchtype eq 'pickaxe') {
4715 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4716 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4718 print "<table cellspacing=\"0\">\n";
4721 my $git_command = git_cmd_str
();
4722 my $searchqtext = $searchtext;
4723 $searchqtext =~ s/'/'\\''/;
4724 open my $fd, "-|", "$git_command rev-list $hash | " .
4725 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
4728 while (my $line = <$fd>) {
4729 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4732 $set{'from_id'} = $3;
4734 $set{'id'} = $set{'to_id'};
4735 if ($set{'id'} =~ m/0{40}/) {
4736 $set{'id'} = $set{'from_id'};
4738 if ($set{'id'} =~ m/0{40}/) {
4742 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4745 print "<tr class=\"dark\">\n";
4747 print "<tr class=\"light\">\n";
4750 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4751 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4753 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4754 -class => "list subject"},
4755 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4756 while (my $setref = shift @files) {
4758 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4759 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4761 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4765 "<td class=\"link\">" .
4766 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4768 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4772 %co = parse_commit
($1);
4780 if ($searchtype eq 'grep') {
4781 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4782 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4784 print "<table cellspacing=\"0\">\n";
4788 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
4790 while (my $line = <$fd>) {
4792 my ($file, $lno, $ltext, $binary);
4793 last if ($matches++ > 1000);
4794 if ($line =~ /^Binary file (.+) matches$/) {
4798 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
4800 if ($file ne $lastfile) {
4801 $lastfile and print "</td></tr>\n";
4803 print "<tr class=\"dark\">\n";
4805 print "<tr class=\"light\">\n";
4807 print "<td class=\"list\">".
4808 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
4809 file_name
=>"$file"),
4810 -class => "list"}, esc_path
($file));
4811 print "</td><td>\n";
4815 print "<div class=\"binary\">Binary file</div>\n";
4817 $ltext = untabify
($ltext);
4818 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
4819 $ltext = esc_html
($1, -nbsp
=>1);
4820 $ltext .= '<span class="match">';
4821 $ltext .= esc_html
($2, -nbsp
=>1);
4822 $ltext .= '</span>';
4823 $ltext .= esc_html
($3, -nbsp
=>1);
4825 $ltext = esc_html
($ltext, -nbsp
=>1);
4827 print "<div class=\"pre\">" .
4828 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
4829 file_name
=>"$file").'#l'.$lno,
4830 -class => "linenr"}, sprintf('%4i', $lno))
4831 . ' ' . $ltext . "</div>\n";
4835 print "</td></tr>\n";
4836 if ($matches > 1000) {
4837 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
4840 print "<div class=\"diff nodifferences\">No matches found</div>\n";
4849 sub git_search_help
{
4851 git_print_page_nav
('','', $hash,$hash,$hash);
4854 <dt><b>commit</b></dt>
4855 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4857 my ($have_grep) = gitweb_check_feature
('grep');
4860 <dt><b>grep</b></dt>
4861 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
4862 a different one) are searched for the given
4863 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
4864 (POSIX extended) and the matches are listed. On large
4865 trees, this search can take a while and put some strain on the server, so please use it with
4866 some consideration.</dd>
4870 <dt><b>author</b></dt>
4871 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4872 <dt><b>committer</b></dt>
4873 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4875 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4876 if ($have_pickaxe) {
4878 <dt><b>pickaxe</b></dt>
4879 <dd>All commits that caused the string to appear or disappear from any file (changes that
4880 added, removed or "modified" the string) will be listed. This search can take a while and
4881 takes a lot of strain on the server, so please use it wisely.</dd>
4889 my $head = git_get_head_hash
($project);
4890 if (!defined $hash) {
4893 if (!defined $page) {
4896 my $refs = git_get_references
();
4898 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4900 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
4902 if ($#commitlist >= 100) {
4904 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4905 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4909 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4910 git_print_header_div
('summary', $project);
4912 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
4917 ## ......................................................................
4918 ## feeds (RSS, Atom; OPML)
4921 my $format = shift || 'atom';
4922 my ($have_blame) = gitweb_check_feature
('blame');
4924 # Atom: http://www.atomenabled.org/developers/syndication/
4925 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4926 if ($format ne 'rss' && $format ne 'atom') {
4927 die_error
(undef, "Unknown web feed format");
4930 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4931 my $head = $hash || 'HEAD';
4932 my @commitlist = parse_commits
($head, 150);
4936 my $content_type = "application/$format+xml";
4937 if (defined $cgi->http('HTTP_ACCEPT') &&
4938 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4939 # browser (feed reader) prefers text/xml
4940 $content_type = 'text/xml';
4942 if (defined($commitlist[0])) {
4943 %latest_commit = %{$commitlist[0]};
4944 %latest_date = parse_date
($latest_commit{'author_epoch'});
4946 -type
=> $content_type,
4947 -charset
=> 'utf-8',
4948 -last_modified
=> $latest_date{'rfc2822'});
4951 -type
=> $content_type,
4952 -charset
=> 'utf-8');
4955 # Optimization: skip generating the body if client asks only
4956 # for Last-Modified date.
4957 return if ($cgi->request_method() eq 'HEAD');
4960 my $title = "$site_name - $project/$action";
4961 my $feed_type = 'log';
4962 if (defined $hash) {
4963 $title .= " - '$hash'";
4964 $feed_type = 'branch log';
4965 if (defined $file_name) {
4966 $title .= " :: $file_name";
4967 $feed_type = 'history';
4969 } elsif (defined $file_name) {
4970 $title .= " - $file_name";
4971 $feed_type = 'history';
4973 $title .= " $feed_type";
4974 my $descr = git_get_project_description
($project);
4975 if (defined $descr) {
4976 $descr = esc_html
($descr);
4978 $descr = "$project " .
4979 ($format eq 'rss' ? 'RSS' : 'Atom') .
4982 my $owner = git_get_project_owner
($project);
4983 $owner = esc_html
($owner);
4987 if (defined $file_name) {
4988 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
4989 } elsif (defined $hash) {
4990 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
4992 $alt_url = href
(-full
=>1, action
=>"summary");
4994 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
4995 if ($format eq 'rss') {
4997 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5000 print "<title>$title</title>\n" .
5001 "<link>$alt_url</link>\n" .
5002 "<description>$descr</description>\n" .
5003 "<language>en</language>\n";
5004 } elsif ($format eq 'atom') {
5006 <feed xmlns="http://www.w3.org/2005/Atom">
5008 print "<title>$title</title>\n" .
5009 "<subtitle>$descr</subtitle>\n" .
5010 '<link rel="alternate" type="text/html" href="' .
5011 $alt_url . '" />' . "\n" .
5012 '<link rel="self" type="' . $content_type . '" href="' .
5013 $cgi->self_url() . '" />' . "\n" .
5014 "<id>" . href
(-full
=>1) . "</id>\n" .
5015 # use project owner for feed author
5016 "<author><name>$owner</name></author>\n";
5017 if (defined $favicon) {
5018 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5020 if (defined $logo_url) {
5021 # not twice as wide as tall: 72 x 27 pixels
5022 print "<logo>" . esc_url
($logo) . "</logo>\n";
5024 if (! %latest_date) {
5025 # dummy date to keep the feed valid until commits trickle in:
5026 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5028 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5033 for (my $i = 0; $i <= $#commitlist; $i++) {
5034 my %co = %{$commitlist[$i]};
5035 my $commit = $co{'id'};
5036 # we read 150, we always show 30 and the ones more recent than 48 hours
5037 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5040 my %cd = parse_date
($co{'author_epoch'});
5042 # get list of changed files
5043 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5044 $co{'parent'}, $co{'id'}, "--", (defined $file_name ? $file_name : ())
5046 my @difftree = map { chomp; $_ } <$fd>;
5050 # print element (entry, item)
5051 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5052 if ($format eq 'rss') {
5054 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5055 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5056 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5057 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5058 "<link>$co_url</link>\n" .
5059 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5060 "<content:encoded>" .
5062 } elsif ($format eq 'atom') {
5064 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5065 "<updated>$cd{'iso-8601'}</updated>\n" .
5067 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5068 if ($co{'author_email'}) {
5069 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5071 print "</author>\n" .
5072 # use committer for contributor
5074 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5075 if ($co{'committer_email'}) {
5076 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5078 print "</contributor>\n" .
5079 "<published>$cd{'iso-8601'}</published>\n" .
5080 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5081 "<id>$co_url</id>\n" .
5082 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5083 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5085 my $comment = $co{'comment'};
5087 foreach my $line (@$comment) {
5088 $line = esc_html
($line);
5091 print "</pre><ul>\n";
5092 foreach my $difftree_line (@difftree) {
5093 my %difftree = parse_difftree_raw_line
($difftree_line);
5094 next if !$difftree{'from_id'};
5096 my $file = $difftree{'file'} || $difftree{'to_file'};
5100 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5101 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5102 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5103 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5104 -title
=> "diff"}, 'D');
5106 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5107 file_name
=>$file, hash_base
=>$commit),
5108 -title
=> "blame"}, 'B');
5110 # if this is not a feed of a file history
5111 if (!defined $file_name || $file_name ne $file) {
5112 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5113 file_name
=>$file, hash
=>$commit),
5114 -title
=> "history"}, 'H');
5116 $file = esc_path
($file);
5120 if ($format eq 'rss') {
5121 print "</ul>]]>\n" .
5122 "</content:encoded>\n" .
5124 } elsif ($format eq 'atom') {
5125 print "</ul>\n</div>\n" .
5132 if ($format eq 'rss') {
5133 print "</channel>\n</rss>\n";
5134 } elsif ($format eq 'atom') {
5148 my @list = git_get_projects_list
();
5150 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5152 <?xml version="1.0" encoding="utf-8"?>
5153 <opml version="1.0">
5155 <title>$site_name OPML Export</title>
5158 <outline text="git RSS feeds">
5161 foreach my $pr (@list) {
5163 my $head = git_get_head_hash
($proj{'path'});
5164 if (!defined $head) {
5167 $git_dir = "$projectroot/$proj{'path'}";
5168 my %co = parse_commit
($head);
5173 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5174 my $rss = "$my_url?p=$proj{'path'};a=rss";
5175 my $html = "$my_url?p=$proj{'path'};a=summary";
5176 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";