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|zip;
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 'zip') {
249 return ('x-zip', 'zip', '');
250 } elsif ($val eq 'none') {
254 return ($ctype, $suffix, $command);
257 sub gitweb_have_snapshot
{
258 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
259 my $have_snapshot = (defined $ctype && defined $suffix);
261 return $have_snapshot;
265 my ($val) = git_get_project_config
('grep', '--bool');
267 if ($val eq 'true') {
269 } elsif ($val eq 'false') {
276 sub feature_pickaxe
{
277 my ($val) = git_get_project_config
('pickaxe', '--bool');
279 if ($val eq 'true') {
281 } elsif ($val eq 'false') {
288 # checking HEAD file with -e is fragile if the repository was
289 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
291 sub check_head_link
{
293 my $headfile = "$dir/HEAD";
294 return ((-e
$headfile) ||
295 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
298 sub check_export_ok
{
300 return (check_head_link
($dir) &&
301 (!$export_ok || -e
"$dir/$export_ok"));
304 # rename detection options for git-diff and git-diff-tree
305 # - default is '-M', with the cost proportional to
306 # (number of removed files) * (number of new files).
307 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
308 # (number of changed files + number of removed files) * (number of new files)
309 # - even more costly is '-C', '--find-copies-harder' with cost
310 # (number of files in the original tree) * (number of new files)
311 # - one might want to include '-B' option, e.g. '-B', '-M'
312 our @diff_opts = ('-M'); # taken from git_commit
314 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
315 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
317 # version of the core git binary
318 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
320 $projects_list ||= $projectroot;
322 # ======================================================================
323 # input validation and dispatch
324 our $action = $cgi->param('a');
325 if (defined $action) {
326 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
327 die_error
(undef, "Invalid action parameter");
331 # parameters which are pathnames
332 our $project = $cgi->param('p');
333 if (defined $project) {
334 if (!validate_pathname
($project) ||
335 !(-d
"$projectroot/$project") ||
336 !check_head_link
("$projectroot/$project") ||
337 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
338 ($strict_export && !project_in_list
($project))) {
340 die_error
(undef, "No such project");
344 our $file_name = $cgi->param('f');
345 if (defined $file_name) {
346 if (!validate_pathname
($file_name)) {
347 die_error
(undef, "Invalid file parameter");
351 our $file_parent = $cgi->param('fp');
352 if (defined $file_parent) {
353 if (!validate_pathname
($file_parent)) {
354 die_error
(undef, "Invalid file parent parameter");
358 # parameters which are refnames
359 our $hash = $cgi->param('h');
361 if (!validate_refname
($hash)) {
362 die_error
(undef, "Invalid hash parameter");
366 our $hash_parent = $cgi->param('hp');
367 if (defined $hash_parent) {
368 if (!validate_refname
($hash_parent)) {
369 die_error
(undef, "Invalid hash parent parameter");
373 our $hash_base = $cgi->param('hb');
374 if (defined $hash_base) {
375 if (!validate_refname
($hash_base)) {
376 die_error
(undef, "Invalid hash base parameter");
380 our $hash_parent_base = $cgi->param('hpb');
381 if (defined $hash_parent_base) {
382 if (!validate_refname
($hash_parent_base)) {
383 die_error
(undef, "Invalid hash parent base parameter");
388 our $page = $cgi->param('pg');
390 if ($page =~ m/[^0-9]/) {
391 die_error
(undef, "Invalid page parameter");
395 our $searchtype = $cgi->param('st');
396 if (defined $searchtype) {
397 if ($searchtype =~ m/[^a-z]/) {
398 die_error
(undef, "Invalid searchtype parameter");
402 our $searchtext = $cgi->param('s');
404 if (defined $searchtext) {
405 if ($searchtype ne 'grep' and $searchtype ne 'pickaxe' and $searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
406 die_error
(undef, "Invalid search parameter");
408 if (length($searchtext) < 2) {
409 die_error
(undef, "At least two characters are required for search parameter");
411 $search_regexp = quotemeta $searchtext;
414 # now read PATH_INFO and use it as alternative to parameters
415 sub evaluate_path_info
{
416 return if defined $project;
417 my $path_info = $ENV{"PATH_INFO"};
418 return if !$path_info;
419 $path_info =~ s
,^/+,,;
420 return if !$path_info;
421 # find which part of PATH_INFO is project
422 $project = $path_info;
424 while ($project && !check_head_link
("$projectroot/$project")) {
425 $project =~ s
,/*[^/]*$,,;
428 $project = validate_pathname
($project);
430 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
431 ($strict_export && !project_in_list
($project))) {
435 # do not change any parameters if an action is given using the query string
437 $path_info =~ s
,^$project/*,,;
438 my ($refname, $pathname) = split(/:/, $path_info, 2);
439 if (defined $pathname) {
440 # we got "project.git/branch:filename" or "project.git/branch:dir/"
441 # we could use git_get_type(branch:pathname), but it needs $git_dir
442 $pathname =~ s
,^/+,,;
443 if (!$pathname || substr($pathname, -1) eq "/") {
447 $action ||= "blob_plain";
449 $hash_base ||= validate_refname
($refname);
450 $file_name ||= validate_pathname
($pathname);
451 } elsif (defined $refname) {
452 # we got "project.git/branch"
453 $action ||= "shortlog";
454 $hash ||= validate_refname
($refname);
457 evaluate_path_info
();
459 # path to the current git repository
461 $git_dir = "$projectroot/$project" if $project;
465 "blame" => \
&git_blame2
,
466 "blobdiff" => \
&git_blobdiff
,
467 "blobdiff_plain" => \
&git_blobdiff_plain
,
468 "blob" => \
&git_blob
,
469 "blob_plain" => \
&git_blob_plain
,
470 "commitdiff" => \
&git_commitdiff
,
471 "commitdiff_plain" => \
&git_commitdiff_plain
,
472 "commit" => \
&git_commit
,
473 "forks" => \
&git_forks
,
474 "heads" => \
&git_heads
,
475 "history" => \
&git_history
,
478 "atom" => \
&git_atom
,
479 "search" => \
&git_search
,
480 "search_help" => \
&git_search_help
,
481 "shortlog" => \
&git_shortlog
,
482 "summary" => \
&git_summary
,
484 "tags" => \
&git_tags
,
485 "tree" => \
&git_tree
,
486 "snapshot" => \
&git_snapshot
,
487 "object" => \
&git_object
,
488 # those below don't need $project
489 "opml" => \
&git_opml
,
490 "project_list" => \
&git_project_list
,
491 "project_index" => \
&git_project_index
,
494 if (!defined $action) {
496 $action = git_get_type
($hash);
497 } elsif (defined $hash_base && defined $file_name) {
498 $action = git_get_type
("$hash_base:$file_name");
499 } elsif (defined $project) {
502 $action = 'project_list';
505 if (!defined($actions{$action})) {
506 die_error
(undef, "Unknown action");
508 if ($action !~ m/^(opml|project_list|project_index)$/ &&
510 die_error
(undef, "Project needed");
512 $actions{$action}->();
515 ## ======================================================================
520 # default is to use -absolute url() i.e. $my_uri
521 my $href = $params{-full
} ? $my_url : $my_uri;
523 # XXX: Warning: If you touch this, check the search form for updating,
534 hash_parent_base
=> "hpb",
540 my %mapping = @mapping;
542 $params{'project'} = $project unless exists $params{'project'};
544 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
546 # use PATH_INFO for project name
547 $href .= "/$params{'project'}" if defined $params{'project'};
548 delete $params{'project'};
550 # Summary just uses the project path URL
551 if (defined $params{'action'} && $params{'action'} eq 'summary') {
552 delete $params{'action'};
556 # now encode the parameters explicitly
558 for (my $i = 0; $i < @mapping; $i += 2) {
559 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
560 if (defined $params{$name}) {
561 push @result, $symbol . "=" . esc_param
($params{$name});
564 $href .= "?" . join(';', @result) if scalar @result;
570 ## ======================================================================
571 ## validation, quoting/unquoting and escaping
573 sub validate_pathname
{
574 my $input = shift || return undef;
576 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
577 # at the beginning, at the end, and between slashes.
578 # also this catches doubled slashes
579 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
583 if ($input =~ m!\0!) {
589 sub validate_refname
{
590 my $input = shift || return undef;
592 # textual hashes are O.K.
593 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
596 # it must be correct pathname
597 $input = validate_pathname
($input)
599 # restrictions on ref name according to git-check-ref-format
600 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
606 # quote unsafe chars, but keep the slash, even when it's not
607 # correct, but quoted slashes look too horrible in bookmarks
610 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
616 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
619 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
625 # replace invalid utf8 character with SUBSTITUTION sequence
630 $str = decode_utf8
($str);
631 $str = $cgi->escapeHTML($str);
632 if ($opts{'-nbsp'}) {
633 $str =~ s/ / /g;
635 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
639 # quote control characters and escape filename to HTML
644 $str = decode_utf8
($str);
645 $str = $cgi->escapeHTML($str);
646 if ($opts{'-nbsp'}) {
647 $str =~ s/ / /g;
649 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
653 # Make control characters "printable", using character escape codes (CEC)
656 my %es = ( # character escape codes, aka escape sequences
657 "\t" => '\t', # tab (HT)
658 "\n" => '\n', # line feed (LF)
659 "\r" => '\r', # carrige return (CR)
660 "\f" => '\f', # form feed (FF)
661 "\b" => '\b', # backspace (BS)
662 "\a" => '\a', # alarm (bell) (BEL)
663 "\e" => '\e', # escape (ESC)
664 "\013" => '\v', # vertical tab (VT)
665 "\000" => '\0', # nul character (NUL)
667 my $chr = ( (exists $es{$cntrl})
669 : sprintf('\%03o', ord($cntrl)) );
670 return "<span class=\"cntrl\">$chr</span>";
673 # Alternatively use unicode control pictures codepoints,
674 # Unicode "printable representation" (PR)
677 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
678 return "<span class=\"cntrl\">$chr</span>";
681 # git may return quoted and escaped filenames
687 my %es = ( # character escape codes, aka escape sequences
688 't' => "\t", # tab (HT, TAB)
689 'n' => "\n", # newline (NL)
690 'r' => "\r", # return (CR)
691 'f' => "\f", # form feed (FF)
692 'b' => "\b", # backspace (BS)
693 'a' => "\a", # alarm (bell) (BEL)
694 'e' => "\e", # escape (ESC)
695 'v' => "\013", # vertical tab (VT)
698 if ($seq =~ m/^[0-7]{1,3}$/) {
699 # octal char sequence
700 return chr(oct($seq));
701 } elsif (exists $es{$seq}) {
702 # C escape sequence, aka character escape code
705 # quoted ordinary character
709 if ($str =~ m/^"(.*)"$/) {
712 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
717 # escape tabs (convert tabs to spaces)
721 while ((my $pos = index($line, "\t")) != -1) {
722 if (my $count = (8 - ($pos % 8))) {
723 my $spaces = ' ' x
$count;
724 $line =~ s/\t/$spaces/;
731 sub project_in_list
{
733 my @list = git_get_projects_list
();
734 return @list && scalar(grep { $_->{'path'} eq $project } @list);
737 ## ----------------------------------------------------------------------
738 ## HTML aware string manipulation
743 my $add_len = shift || 10;
745 # allow only $len chars, but don't cut a word if it would fit in $add_len
746 # if it doesn't fit, cut it if it's still longer than the dots we would add
747 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
750 if (length($tail) > 4) {
752 $body =~ s/&[^;]*$//; # remove chopped character entities
757 ## ----------------------------------------------------------------------
758 ## functions returning short strings
760 # CSS class for given age value (in seconds)
766 } elsif ($age < 60*60*2) {
768 } elsif ($age < 60*60*24*2) {
775 # convert age in seconds to "nn units ago" string
780 if ($age > 60*60*24*365*2) {
781 $age_str = (int $age/60/60/24/365);
782 $age_str .= " years ago";
783 } elsif ($age > 60*60*24*(365/12)*2) {
784 $age_str = int $age/60/60/24/(365/12);
785 $age_str .= " months ago";
786 } elsif ($age > 60*60*24*7*2) {
787 $age_str = int $age/60/60/24/7;
788 $age_str .= " weeks ago";
789 } elsif ($age > 60*60*24*2) {
790 $age_str = int $age/60/60/24;
791 $age_str .= " days ago";
792 } elsif ($age > 60*60*2) {
793 $age_str = int $age/60/60;
794 $age_str .= " hours ago";
795 } elsif ($age > 60*2) {
796 $age_str = int $age/60;
797 $age_str .= " min ago";
800 $age_str .= " sec ago";
802 $age_str .= " right now";
807 # convert file mode in octal to symbolic file mode string
809 my $mode = oct shift;
811 if (S_ISDIR
($mode & S_IFMT
)) {
813 } elsif (S_ISLNK
($mode)) {
815 } elsif (S_ISREG
($mode)) {
816 # git cares only about the executable bit
817 if ($mode & S_IXUSR
) {
827 # convert file mode in octal to file type string
831 if ($mode !~ m/^[0-7]+$/) {
837 if (S_ISDIR
($mode & S_IFMT
)) {
839 } elsif (S_ISLNK
($mode)) {
841 } elsif (S_ISREG
($mode)) {
848 # convert file mode in octal to file type description string
852 if ($mode !~ m/^[0-7]+$/) {
858 if (S_ISDIR
($mode & S_IFMT
)) {
860 } elsif (S_ISLNK
($mode)) {
862 } elsif (S_ISREG
($mode)) {
863 if ($mode & S_IXUSR
) {
874 ## ----------------------------------------------------------------------
875 ## functions returning short HTML fragments, or transforming HTML fragments
876 ## which don't belong to other sections
878 # format line of commit message.
879 sub format_log_line_html
{
882 $line = esc_html
($line, -nbsp
=>1);
883 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
886 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
887 -class => "text"}, $hash_text);
888 $line =~ s/$hash_text/$link/;
893 # format marker of refs pointing to given object
894 sub format_ref_marker
{
895 my ($refs, $id) = @_;
898 if (defined $refs->{$id}) {
899 foreach my $ref (@{$refs->{$id}}) {
900 my ($type, $name) = qw();
901 # e.g. tags/v2.6.11 or heads/next
902 if ($ref =~ m!^(.*?)s?/(.*)$!) {
910 $markers .= " <span class=\"$type\" title=\"$ref\">" .
911 esc_html
($name) . "</span>";
916 return ' <span class="refs">'. $markers . '</span>';
922 # format, perhaps shortened and with markers, title line
923 sub format_subject_html
{
924 my ($long, $short, $href, $extra) = @_;
925 $extra = '' unless defined($extra);
927 if (length($short) < length($long)) {
928 return $cgi->a({-href
=> $href, -class => "list subject",
929 -title
=> decode_utf8
($long)},
930 esc_html
($short) . $extra);
932 return $cgi->a({-href
=> $href, -class => "list subject"},
933 esc_html
($long) . $extra);
937 # format patch (diff) line (rather not to be used for diff headers)
938 sub format_diff_line
{
940 my ($from, $to) = @_;
945 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
947 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
948 if ($line =~ m/^\@{3}/) {
949 $diff_class = " chunk_header";
950 } elsif ($line =~ m/^\\/) {
951 $diff_class = " incomplete";
952 } elsif ($prefix =~ tr/+/+/) {
953 $diff_class = " add";
954 } elsif ($prefix =~ tr/-/-/) {
955 $diff_class = " rem";
958 # assume ordinary diff
959 my $char = substr($line, 0, 1);
961 $diff_class = " add";
962 } elsif ($char eq '-') {
963 $diff_class = " rem";
964 } elsif ($char eq '@') {
965 $diff_class = " chunk_header";
966 } elsif ($char eq "\\") {
967 $diff_class = " incomplete";
970 $line = untabify
($line);
971 if ($from && $to && $line =~ m/^\@{2} /) {
972 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
973 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
975 $from_lines = 0 unless defined $from_lines;
976 $to_lines = 0 unless defined $to_lines;
978 if ($from->{'href'}) {
979 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
980 -class=>"list"}, $from_text);
983 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
984 -class=>"list"}, $to_text);
986 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
987 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
988 return "<div class=\"diff$diff_class\">$line</div>\n";
989 } elsif ($from && $to && $line =~ m/^\@{3}/) {
990 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
991 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
993 @from_text = split(' ', $ranges);
994 for (my $i = 0; $i < @from_text; ++$i) {
995 ($from_start[$i], $from_nlines[$i]) =
996 (split(',', substr($from_text[$i], 1)), 0);
999 $to_text = pop @from_text;
1000 $to_start = pop @from_start;
1001 $to_nlines = pop @from_nlines;
1003 $line = "<span class=\"chunk_info\">$prefix ";
1004 for (my $i = 0; $i < @from_text; ++$i) {
1005 if ($from->{'href'}[$i]) {
1006 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1007 -class=>"list"}, $from_text[$i]);
1009 $line .= $from_text[$i];
1013 if ($to->{'href'}) {
1014 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1015 -class=>"list"}, $to_text);
1019 $line .= " $prefix</span>" .
1020 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1021 return "<div class=\"diff$diff_class\">$line</div>\n";
1023 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1026 ## ----------------------------------------------------------------------
1027 ## git utility subroutines, invoking git commands
1029 # returns path to the core git executable and the --git-dir parameter as list
1031 return $GIT, '--git-dir='.$git_dir;
1034 # returns path to the core git executable and the --git-dir parameter as string
1036 return join(' ', git_cmd
());
1039 # get HEAD ref of given project as hash
1040 sub git_get_head_hash
{
1041 my $project = shift;
1042 my $o_git_dir = $git_dir;
1044 $git_dir = "$projectroot/$project";
1045 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1048 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1052 if (defined $o_git_dir) {
1053 $git_dir = $o_git_dir;
1058 # get type of given object
1062 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1064 close $fd or return;
1069 sub git_get_project_config
{
1070 my ($key, $type) = @_;
1072 return unless ($key);
1073 $key =~ s/^gitweb\.//;
1074 return if ($key =~ m/\W/);
1076 my @x = (git_cmd
(), 'config');
1077 if (defined $type) { push @x, $type; }
1079 push @x, "gitweb.$key";
1085 # get hash of given path at given ref
1086 sub git_get_hash_by_path
{
1088 my $path = shift || return undef;
1093 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1094 or die_error
(undef, "Open git-ls-tree failed");
1096 close $fd or return undef;
1098 if (!defined $line) {
1099 # there is no tree or hash given by $path at $base
1103 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1104 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1105 if (defined $type && $type ne $2) {
1106 # type doesn't match
1112 # get path of entry with given hash at given tree-ish (ref)
1113 # used to get 'from' filename for combined diff (merge commit) for renames
1114 sub git_get_path_by_hash
{
1115 my $base = shift || return;
1116 my $hash = shift || return;
1120 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1122 while (my $line = <$fd>) {
1125 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1126 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1127 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1136 ## ......................................................................
1137 ## git utility functions, directly accessing git repository
1139 sub git_get_project_description
{
1142 open my $fd, "$projectroot/$path/description" or return undef;
1145 if (defined $descr) {
1151 sub git_get_project_url_list
{
1154 open my $fd, "$projectroot/$path/cloneurl" or return;
1155 my @git_project_url_list = map { chomp; $_ } <$fd>;
1158 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1161 sub git_get_projects_list
{
1166 $filter =~ s/\.git$//;
1168 my ($check_forks) = gitweb_check_feature
('forks');
1170 if (-d
$projects_list) {
1171 # search in directory
1172 my $dir = $projects_list . ($filter ? "/$filter" : '');
1173 # remove the trailing "/"
1175 my $pfxlen = length("$dir");
1178 follow_fast
=> 1, # follow symbolic links
1179 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1181 # skip project-list toplevel, if we get it.
1182 return if (m!^[/.]$!);
1183 # only directories can be git repositories
1184 return unless (-d
$_);
1186 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1187 # we check related file in $projectroot
1188 if ($check_forks and $subdir =~ m
#/.#) {
1189 $File::Find
::prune
= 1;
1190 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1191 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1192 $File::Find
::prune
= 1;
1197 } elsif (-f
$projects_list) {
1198 # read from file(url-encoded):
1199 # 'git%2Fgit.git Linus+Torvalds'
1200 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1201 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1203 open my ($fd), $projects_list or return;
1205 while (my $line = <$fd>) {
1207 my ($path, $owner) = split ' ', $line;
1208 $path = unescape
($path);
1209 $owner = unescape
($owner);
1210 if (!defined $path) {
1213 if ($filter ne '') {
1214 # looking for forks;
1215 my $pfx = substr($path, 0, length($filter));
1216 if ($pfx ne $filter) {
1219 my $sfx = substr($path, length($filter));
1220 if ($sfx !~ /^\/.*\
.git
$/) {
1223 } elsif ($check_forks) {
1225 foreach my $filter (keys %paths) {
1226 # looking for forks;
1227 my $pfx = substr($path, 0, length($filter));
1228 if ($pfx ne $filter) {
1231 my $sfx = substr($path, length($filter));
1232 if ($sfx !~ /^\/.*\
.git
$/) {
1235 # is a fork, don't include it in
1240 if (check_export_ok
("$projectroot/$path")) {
1243 owner
=> decode_utf8
($owner),
1246 (my $forks_path = $path) =~ s/\.git$//;
1247 $paths{$forks_path}++;
1255 sub git_get_project_owner
{
1256 my $project = shift;
1259 return undef unless $project;
1261 # read from file (url-encoded):
1262 # 'git%2Fgit.git Linus+Torvalds'
1263 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1264 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1265 if (-f
$projects_list) {
1266 open (my $fd , $projects_list);
1267 while (my $line = <$fd>) {
1269 my ($pr, $ow) = split ' ', $line;
1270 $pr = unescape
($pr);
1271 $ow = unescape
($ow);
1272 if ($pr eq $project) {
1273 $owner = decode_utf8
($ow);
1279 if (!defined $owner) {
1280 $owner = get_file_owner
("$projectroot/$project");
1286 sub git_get_last_activity
{
1290 $git_dir = "$projectroot/$path";
1291 open($fd, "-|", git_cmd
(), 'for-each-ref',
1292 '--format=%(committer)',
1293 '--sort=-committerdate',
1295 'refs/heads') or return;
1296 my $most_recent = <$fd>;
1297 close $fd or return;
1298 if (defined $most_recent &&
1299 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1301 my $age = time - $timestamp;
1302 return ($age, age_string
($age));
1306 sub git_get_references
{
1307 my $type = shift || "";
1309 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1310 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1311 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1312 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1315 while (my $line = <$fd>) {
1317 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1318 if (defined $refs{$1}) {
1319 push @{$refs{$1}}, $2;
1325 close $fd or return;
1329 sub git_get_rev_name_tags
{
1330 my $hash = shift || return undef;
1332 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1334 my $name_rev = <$fd>;
1337 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1340 # catches also '$hash undefined' output
1345 ## ----------------------------------------------------------------------
1346 ## parse to hash functions
1350 my $tz = shift || "-0000";
1353 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1354 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1355 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1356 $date{'hour'} = $hour;
1357 $date{'minute'} = $min;
1358 $date{'mday'} = $mday;
1359 $date{'day'} = $days[$wday];
1360 $date{'month'} = $months[$mon];
1361 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1362 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1363 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1364 $mday, $months[$mon], $hour ,$min;
1365 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1366 1900+$year, $mon, $mday, $hour ,$min, $sec;
1368 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1369 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1370 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1371 $date{'hour_local'} = $hour;
1372 $date{'minute_local'} = $min;
1373 $date{'tz_local'} = $tz;
1374 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1375 1900+$year, $mon+1, $mday,
1376 $hour, $min, $sec, $tz);
1385 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1386 $tag{'id'} = $tag_id;
1387 while (my $line = <$fd>) {
1389 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1390 $tag{'object'} = $1;
1391 } elsif ($line =~ m/^type (.+)$/) {
1393 } elsif ($line =~ m/^tag (.+)$/) {
1395 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1396 $tag{'author'} = $1;
1399 } elsif ($line =~ m/--BEGIN/) {
1400 push @comment, $line;
1402 } elsif ($line eq "") {
1406 push @comment, <$fd>;
1407 $tag{'comment'} = \
@comment;
1408 close $fd or return;
1409 if (!defined $tag{'name'}) {
1415 sub parse_commit_text
{
1416 my ($commit_text, $withparents) = @_;
1417 my @commit_lines = split '\n', $commit_text;
1420 pop @commit_lines; # Remove '\0'
1422 if (! @commit_lines) {
1426 my $header = shift @commit_lines;
1427 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1430 ($co{'id'}, my @parents) = split ' ', $header;
1431 while (my $line = shift @commit_lines) {
1432 last if $line eq "\n";
1433 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1435 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1437 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1439 $co{'author_epoch'} = $2;
1440 $co{'author_tz'} = $3;
1441 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1442 $co{'author_name'} = $1;
1443 $co{'author_email'} = $2;
1445 $co{'author_name'} = $co{'author'};
1447 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1448 $co{'committer'} = $1;
1449 $co{'committer_epoch'} = $2;
1450 $co{'committer_tz'} = $3;
1451 $co{'committer_name'} = $co{'committer'};
1452 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1453 $co{'committer_name'} = $1;
1454 $co{'committer_email'} = $2;
1456 $co{'committer_name'} = $co{'committer'};
1460 if (!defined $co{'tree'}) {
1463 $co{'parents'} = \
@parents;
1464 $co{'parent'} = $parents[0];
1466 foreach my $title (@commit_lines) {
1469 $co{'title'} = chop_str
($title, 80, 5);
1470 # remove leading stuff of merges to make the interesting part visible
1471 if (length($title) > 50) {
1472 $title =~ s/^Automatic //;
1473 $title =~ s/^merge (of|with) /Merge ... /i;
1474 if (length($title) > 50) {
1475 $title =~ s/(http|rsync):\/\///;
1477 if (length($title) > 50) {
1478 $title =~ s/(master|www|rsync)\.//;
1480 if (length($title) > 50) {
1481 $title =~ s/kernel.org:?//;
1483 if (length($title) > 50) {
1484 $title =~ s/\/pub\/scm//;
1487 $co{'title_short'} = chop_str
($title, 50, 5);
1491 if ($co{'title'} eq "") {
1492 $co{'title'} = $co{'title_short'} = '(no commit message)';
1494 # remove added spaces
1495 foreach my $line (@commit_lines) {
1498 $co{'comment'} = \
@commit_lines;
1500 my $age = time - $co{'committer_epoch'};
1502 $co{'age_string'} = age_string
($age);
1503 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1504 if ($age > 60*60*24*7*2) {
1505 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1506 $co{'age_string_age'} = $co{'age_string'};
1508 $co{'age_string_date'} = $co{'age_string'};
1509 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1515 my ($commit_id) = @_;
1520 open my $fd, "-|", git_cmd
(), "rev-list",
1526 or die_error
(undef, "Open git-rev-list failed");
1527 %co = parse_commit_text
(<$fd>, 1);
1534 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1542 open my $fd, "-|", git_cmd
(), "rev-list",
1544 ($arg ? ($arg) : ()),
1545 ("--max-count=" . $maxcount),
1546 ("--skip=" . $skip),
1549 ($filename ? ($filename) : ())
1550 or die_error
(undef, "Open git-rev-list failed");
1551 while (my $line = <$fd>) {
1552 my %co = parse_commit_text
($line);
1557 return wantarray ? @cos : \
@cos;
1560 # parse ref from ref_file, given by ref_id, with given type
1562 my $ref_file = shift;
1564 my $type = shift || git_get_type
($ref_id);
1567 $ref_item{'type'} = $type;
1568 $ref_item{'id'} = $ref_id;
1569 $ref_item{'epoch'} = 0;
1570 $ref_item{'age'} = "unknown";
1571 if ($type eq "tag") {
1572 my %tag = parse_tag
($ref_id);
1573 $ref_item{'comment'} = $tag{'comment'};
1574 if ($tag{'type'} eq "commit") {
1575 my %co = parse_commit
($tag{'object'});
1576 $ref_item{'epoch'} = $co{'committer_epoch'};
1577 $ref_item{'age'} = $co{'age_string'};
1578 } elsif (defined($tag{'epoch'})) {
1579 my $age = time - $tag{'epoch'};
1580 $ref_item{'epoch'} = $tag{'epoch'};
1581 $ref_item{'age'} = age_string
($age);
1583 $ref_item{'reftype'} = $tag{'type'};
1584 $ref_item{'name'} = $tag{'name'};
1585 $ref_item{'refid'} = $tag{'object'};
1586 } elsif ($type eq "commit"){
1587 my %co = parse_commit
($ref_id);
1588 $ref_item{'reftype'} = "commit";
1589 $ref_item{'name'} = $ref_file;
1590 $ref_item{'title'} = $co{'title'};
1591 $ref_item{'refid'} = $ref_id;
1592 $ref_item{'epoch'} = $co{'committer_epoch'};
1593 $ref_item{'age'} = $co{'age_string'};
1595 $ref_item{'reftype'} = $type;
1596 $ref_item{'name'} = $ref_file;
1597 $ref_item{'refid'} = $ref_id;
1603 # parse line of git-diff-tree "raw" output
1604 sub parse_difftree_raw_line
{
1608 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1609 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1610 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1611 $res{'from_mode'} = $1;
1612 $res{'to_mode'} = $2;
1613 $res{'from_id'} = $3;
1615 $res{'status'} = $5;
1616 $res{'similarity'} = $6;
1617 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1618 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1620 $res{'file'} = unquote
($7);
1623 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1624 # combined diff (for merge commit)
1625 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1626 $res{'nparents'} = length($1);
1627 $res{'from_mode'} = [ split(' ', $2) ];
1628 $res{'to_mode'} = pop @{$res{'from_mode'}};
1629 $res{'from_id'} = [ split(' ', $3) ];
1630 $res{'to_id'} = pop @{$res{'from_id'}};
1631 $res{'status'} = [ split('', $4) ];
1632 $res{'to_file'} = unquote
($5);
1634 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1635 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1636 $res{'commit'} = $1;
1639 return wantarray ? %res : \
%res;
1642 # parse line of git-ls-tree output
1643 sub parse_ls_tree_line
($;%) {
1648 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1649 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1657 $res{'name'} = unquote
($4);
1660 return wantarray ? %res : \
%res;
1663 ## ......................................................................
1664 ## parse to array of hashes functions
1666 sub git_get_heads_list
{
1670 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1671 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1672 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1675 while (my $line = <$fd>) {
1679 my ($refinfo, $committerinfo) = split(/\0/, $line);
1680 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1681 my ($committer, $epoch, $tz) =
1682 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1683 $name =~ s!^refs/heads/!!;
1685 $ref_item{'name'} = $name;
1686 $ref_item{'id'} = $hash;
1687 $ref_item{'title'} = $title || '(no commit message)';
1688 $ref_item{'epoch'} = $epoch;
1690 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1692 $ref_item{'age'} = "unknown";
1695 push @headslist, \
%ref_item;
1699 return wantarray ? @headslist : \
@headslist;
1702 sub git_get_tags_list
{
1706 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1707 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1708 '--format=%(objectname) %(objecttype) %(refname) '.
1709 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1712 while (my $line = <$fd>) {
1716 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1717 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1718 my ($creator, $epoch, $tz) =
1719 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1720 $name =~ s!^refs/tags/!!;
1722 $ref_item{'type'} = $type;
1723 $ref_item{'id'} = $id;
1724 $ref_item{'name'} = $name;
1725 if ($type eq "tag") {
1726 $ref_item{'subject'} = $title;
1727 $ref_item{'reftype'} = $reftype;
1728 $ref_item{'refid'} = $refid;
1730 $ref_item{'reftype'} = $type;
1731 $ref_item{'refid'} = $id;
1734 if ($type eq "tag" || $type eq "commit") {
1735 $ref_item{'epoch'} = $epoch;
1737 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1739 $ref_item{'age'} = "unknown";
1743 push @tagslist, \
%ref_item;
1747 return wantarray ? @tagslist : \
@tagslist;
1750 ## ----------------------------------------------------------------------
1751 ## filesystem-related functions
1753 sub get_file_owner
{
1756 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1757 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1758 if (!defined $gcos) {
1762 $owner =~ s/[,;].*$//;
1763 return decode_utf8
($owner);
1766 ## ......................................................................
1767 ## mimetype related functions
1769 sub mimetype_guess_file
{
1770 my $filename = shift;
1771 my $mimemap = shift;
1772 -r
$mimemap or return undef;
1775 open(MIME
, $mimemap) or return undef;
1777 next if m/^#/; # skip comments
1778 my ($mime, $exts) = split(/\t+/);
1779 if (defined $exts) {
1780 my @exts = split(/\s+/, $exts);
1781 foreach my $ext (@exts) {
1782 $mimemap{$ext} = $mime;
1788 $filename =~ /\.([^.]*)$/;
1789 return $mimemap{$1};
1792 sub mimetype_guess
{
1793 my $filename = shift;
1795 $filename =~ /\./ or return undef;
1797 if ($mimetypes_file) {
1798 my $file = $mimetypes_file;
1799 if ($file !~ m!^/!) { # if it is relative path
1800 # it is relative to project
1801 $file = "$projectroot/$project/$file";
1803 $mime = mimetype_guess_file
($filename, $file);
1805 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1811 my $filename = shift;
1814 my $mime = mimetype_guess
($filename);
1815 $mime and return $mime;
1819 return $default_blob_plain_mimetype unless $fd;
1822 return 'text/plain' .
1823 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1824 } elsif (! $filename) {
1825 return 'application/octet-stream';
1826 } elsif ($filename =~ m/\.png$/i) {
1828 } elsif ($filename =~ m/\.gif$/i) {
1830 } elsif ($filename =~ m/\.jpe?g$/i) {
1831 return 'image/jpeg';
1833 return 'application/octet-stream';
1837 ## ======================================================================
1838 ## functions printing HTML: header, footer, error page
1840 sub git_header_html
{
1841 my $status = shift || "200 OK";
1842 my $expires = shift;
1844 my $title = "$site_name";
1845 if (defined $project) {
1846 $title .= " - " . decode_utf8
($project);
1847 if (defined $action) {
1848 $title .= "/$action";
1849 if (defined $file_name) {
1850 $title .= " - " . esc_path
($file_name);
1851 if ($action eq "tree" && $file_name !~ m
|/$|) {
1858 # require explicit support from the UA if we are to send the page as
1859 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1860 # we have to do this because MSIE sometimes globs '*/*', pretending to
1861 # support xhtml+xml but choking when it gets what it asked for.
1862 if (defined $cgi->http('HTTP_ACCEPT') &&
1863 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1864 $cgi->Accept('application/xhtml+xml') != 0) {
1865 $content_type = 'application/xhtml+xml';
1867 $content_type = 'text/html';
1869 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1870 -status
=> $status, -expires
=> $expires);
1871 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
1873 <?xml version="1.0" encoding="utf-8"?>
1874 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1875 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1876 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1877 <!-- git core binaries version $git_version -->
1879 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1880 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
1881 <meta name="robots" content="index, nofollow"/>
1882 <title>$title</title>
1884 # print out each stylesheet that exist
1885 if (defined $stylesheet) {
1886 #provides backwards capability for those people who define style sheet in a config file
1887 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1889 foreach my $stylesheet (@stylesheets) {
1890 next unless $stylesheet;
1891 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1894 if (defined $project) {
1895 printf('<link rel="alternate" title="%s log RSS feed" '.
1896 'href="%s" type="application/rss+xml" />'."\n",
1897 esc_param
($project), href
(action
=>"rss"));
1898 printf('<link rel="alternate" title="%s log Atom feed" '.
1899 'href="%s" type="application/atom+xml" />'."\n",
1900 esc_param
($project), href
(action
=>"atom"));
1902 printf('<link rel="alternate" title="%s projects list" '.
1903 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1904 $site_name, href
(project
=>undef, action
=>"project_index"));
1905 printf('<link rel="alternate" title="%s projects feeds" '.
1906 'href="%s" type="text/x-opml"/>'."\n",
1907 $site_name, href
(project
=>undef, action
=>"opml"));
1909 if (defined $favicon) {
1910 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1916 if (-f
$site_header) {
1917 open (my $fd, $site_header);
1922 print "<div class=\"page_header\">\n" .
1923 $cgi->a({-href
=> esc_url
($logo_url),
1924 -title
=> $logo_label},
1925 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1926 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1927 if (defined $project) {
1928 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1929 if (defined $action) {
1936 my ($have_search) = gitweb_check_feature
('search');
1937 if ((defined $project) && ($have_search)) {
1938 if (!defined $searchtext) {
1942 if (defined $hash_base) {
1943 $search_hash = $hash_base;
1944 } elsif (defined $hash) {
1945 $search_hash = $hash;
1947 $search_hash = "HEAD";
1949 $cgi->param("a", "search");
1950 $cgi->param("h", $search_hash);
1951 $cgi->param("p", $project);
1952 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1953 "<div class=\"search\">\n" .
1954 $cgi->hidden(-name
=> "p") . "\n" .
1955 $cgi->hidden(-name
=> "a") . "\n" .
1956 $cgi->hidden(-name
=> "h") . "\n" .
1957 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1958 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
1959 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1961 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1963 $cgi->end_form() . "\n";
1967 sub git_footer_html
{
1968 print "<div class=\"page_footer\">\n";
1969 if (defined $project) {
1970 my $descr = git_get_project_description
($project);
1971 if (defined $descr) {
1972 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1974 print $cgi->a({-href
=> href
(action
=>"rss"),
1975 -class => "rss_logo"}, "RSS") . " ";
1976 print $cgi->a({-href
=> href
(action
=>"atom"),
1977 -class => "rss_logo"}, "Atom") . "\n";
1979 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1980 -class => "rss_logo"}, "OPML") . " ";
1981 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1982 -class => "rss_logo"}, "TXT") . "\n";
1986 if (-f
$site_footer) {
1987 open (my $fd, $site_footer);
1997 my $status = shift || "403 Forbidden";
1998 my $error = shift || "Malformed query, file missing or permission denied";
2000 git_header_html
($status);
2002 <div class="page_body">
2012 ## ----------------------------------------------------------------------
2013 ## functions printing or outputting HTML: navigation
2015 sub git_print_page_nav
{
2016 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2017 $extra = '' if !defined $extra; # pager or formats
2019 my @navs = qw(summary shortlog log commit commitdiff tree);
2021 @navs = grep { $_ ne $suppress } @navs;
2024 my %arg = map { $_ => {action
=>$_} } @navs;
2025 if (defined $head) {
2026 for (qw(commit commitdiff)) {
2027 $arg{$_}{'hash'} = $head;
2029 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2030 for (qw(shortlog log)) {
2031 $arg{$_}{'hash'} = $head;
2035 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2036 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2038 print "<div class=\"page_nav\">\n" .
2040 map { $_ eq $current ?
2041 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2043 print "<br/>\n$extra<br/>\n" .
2047 sub format_paging_nav
{
2048 my ($action, $hash, $head, $page, $nrevs) = @_;
2052 if ($hash ne $head || $page) {
2053 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2055 $paging_nav .= "HEAD";
2059 $paging_nav .= " ⋅ " .
2060 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2061 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2063 $paging_nav .= " ⋅ prev";
2066 if ($nrevs >= (100 * ($page+1)-1)) {
2067 $paging_nav .= " ⋅ " .
2068 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2069 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2071 $paging_nav .= " ⋅ next";
2077 ## ......................................................................
2078 ## functions printing or outputting HTML: div
2080 sub git_print_header_div
{
2081 my ($action, $title, $hash, $hash_base) = @_;
2084 $args{'action'} = $action;
2085 $args{'hash'} = $hash if $hash;
2086 $args{'hash_base'} = $hash_base if $hash_base;
2088 print "<div class=\"header\">\n" .
2089 $cgi->a({-href
=> href
(%args), -class => "title"},
2090 $title ? $title : $action) .
2094 #sub git_print_authorship (\%) {
2095 sub git_print_authorship
{
2098 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2099 print "<div class=\"author_date\">" .
2100 esc_html
($co->{'author_name'}) .
2102 if ($ad{'hour_local'} < 6) {
2103 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2104 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2106 printf(" (%02d:%02d %s)",
2107 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2112 sub git_print_page_path
{
2118 print "<div class=\"page_path\">";
2119 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2120 -title
=> 'tree root'}, decode_utf8
("[$project]"));
2122 if (defined $name) {
2123 my @dirname = split '/', $name;
2124 my $basename = pop @dirname;
2127 foreach my $dir (@dirname) {
2128 $fullname .= ($fullname ? '/' : '') . $dir;
2129 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2131 -title
=> $fullname}, esc_path
($dir));
2134 if (defined $type && $type eq 'blob') {
2135 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2137 -title
=> $name}, esc_path
($basename));
2138 } elsif (defined $type && $type eq 'tree') {
2139 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2141 -title
=> $name}, esc_path
($basename));
2144 print esc_path
($basename);
2147 print "<br/></div>\n";
2150 # sub git_print_log (\@;%) {
2151 sub git_print_log
($;%) {
2155 if ($opts{'-remove_title'}) {
2156 # remove title, i.e. first line of log
2159 # remove leading empty lines
2160 while (defined $log->[0] && $log->[0] eq "") {
2167 foreach my $line (@$log) {
2168 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2171 if (! $opts{'-remove_signoff'}) {
2172 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2175 # remove signoff lines
2182 # print only one empty line
2183 # do not print empty line after signoff
2185 next if ($empty || $signoff);
2191 print format_log_line_html
($line) . "<br/>\n";
2194 if ($opts{'-final_empty_line'}) {
2195 # end with single empty line
2196 print "<br/>\n" unless $empty;
2200 # return link target (what link points to)
2201 sub git_get_link_target
{
2206 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2210 $link_target = <$fd>;
2215 return $link_target;
2218 # given link target, and the directory (basedir) the link is in,
2219 # return target of link relative to top directory (top tree);
2220 # return undef if it is not possible (including absolute links).
2221 sub normalize_link_target
{
2222 my ($link_target, $basedir, $hash_base) = @_;
2224 # we can normalize symlink target only if $hash_base is provided
2225 return unless $hash_base;
2227 # absolute symlinks (beginning with '/') cannot be normalized
2228 return if (substr($link_target, 0, 1) eq '/');
2230 # normalize link target to path from top (root) tree (dir)
2233 $path = $basedir . '/' . $link_target;
2235 # we are in top (root) tree (dir)
2236 $path = $link_target;
2239 # remove //, /./, and /../
2241 foreach my $part (split('/', $path)) {
2242 # discard '.' and ''
2243 next if (!$part || $part eq '.');
2245 if ($part eq '..') {
2249 # link leads outside repository (outside top dir)
2253 push @path_parts, $part;
2256 $path = join('/', @path_parts);
2261 # print tree entry (row of git_tree), but without encompassing <tr> element
2262 sub git_print_tree_entry
{
2263 my ($t, $basedir, $hash_base, $have_blame) = @_;
2266 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2268 # The format of a table row is: mode list link. Where mode is
2269 # the mode of the entry, list is the name of the entry, an href,
2270 # and link is the action links of the entry.
2272 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2273 if ($t->{'type'} eq "blob") {
2274 print "<td class=\"list\">" .
2275 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2276 file_name
=>"$basedir$t->{'name'}", %base_key),
2277 -class => "list"}, esc_path
($t->{'name'}));
2278 if (S_ISLNK
(oct $t->{'mode'})) {
2279 my $link_target = git_get_link_target
($t->{'hash'});
2281 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2282 if (defined $norm_target) {
2284 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2285 file_name
=>$norm_target),
2286 -title
=> $norm_target}, esc_path
($link_target));
2288 print " -> " . esc_path
($link_target);
2293 print "<td class=\"link\">";
2294 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2295 file_name
=>"$basedir$t->{'name'}", %base_key)},
2299 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2300 file_name
=>"$basedir$t->{'name'}", %base_key)},
2303 if (defined $hash_base) {
2305 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2306 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2310 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2311 file_name
=>"$basedir$t->{'name'}")},
2315 } elsif ($t->{'type'} eq "tree") {
2316 print "<td class=\"list\">";
2317 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2318 file_name
=>"$basedir$t->{'name'}", %base_key)},
2319 esc_path
($t->{'name'}));
2321 print "<td class=\"link\">";
2322 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2323 file_name
=>"$basedir$t->{'name'}", %base_key)},
2325 if (defined $hash_base) {
2327 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2328 file_name
=>"$basedir$t->{'name'}")},
2335 ## ......................................................................
2336 ## functions printing large fragments of HTML
2338 sub fill_from_file_info
{
2339 my ($diff, @parents) = @_;
2341 $diff->{'from_file'} = [ ];
2342 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2343 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2344 if ($diff->{'status'}[$i] eq 'R' ||
2345 $diff->{'status'}[$i] eq 'C') {
2346 $diff->{'from_file'}[$i] =
2347 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2354 # parameters can be strings, or references to arrays of strings
2358 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @$a == @$b) {
2359 for (my $i = 0; $i < @$a; ++$i) {
2360 return 0 unless ($a->[$i] eq $b->[$i]);
2363 } elsif (!ref($a) && !ref($b)) {
2371 sub git_difftree_body
{
2372 my ($difftree, $hash, @parents) = @_;
2373 my ($parent) = $parents[0];
2374 my ($have_blame) = gitweb_check_feature
('blame');
2375 print "<div class=\"list_head\">\n";
2376 if ($#{$difftree} > 10) {
2377 print(($#{$difftree} + 1) . " files changed:\n");
2381 print "<table class=\"" .
2382 (@parents > 1 ? "combined " : "") .
2386 foreach my $line (@{$difftree}) {
2388 if (ref($line) eq "HASH") {
2389 # pre-parsed (or generated by hand)
2392 $diff = parse_difftree_raw_line
($line);
2396 print "<tr class=\"dark\">\n";
2398 print "<tr class=\"light\">\n";
2402 if (exists $diff->{'nparents'}) { # combined diff
2404 fill_from_file_info
($diff, @parents)
2405 unless exists $diff->{'from_file'};
2407 if ($diff->{'to_id'} ne ('0' x
40)) {
2408 # file exists in the result (child) commit
2410 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2411 file_name
=>$diff->{'to_file'},
2413 -class => "list"}, esc_path
($diff->{'to_file'})) .
2417 esc_path
($diff->{'to_file'}) .
2421 if ($action eq 'commitdiff') {
2424 print "<td class=\"link\">" .
2425 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2430 my $has_history = 0;
2431 my $not_deleted = 0;
2432 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2433 my $hash_parent = $parents[$i];
2434 my $from_hash = $diff->{'from_id'}[$i];
2435 my $from_path = $diff->{'from_file'}[$i];
2436 my $status = $diff->{'status'}[$i];
2438 $has_history ||= ($status ne 'A');
2439 $not_deleted ||= ($status ne 'D');
2441 if ($status eq 'A') {
2442 print "<td class=\"link\" align=\"right\"> | </td>\n";
2443 } elsif ($status eq 'D') {
2444 print "<td class=\"link\">" .
2445 $cgi->a({-href
=> href
(action
=>"blob",
2448 file_name
=>$from_path)},
2452 if ($diff->{'to_id'} eq $from_hash) {
2453 print "<td class=\"link nochange\">";
2455 print "<td class=\"link\">";
2457 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2458 hash
=>$diff->{'to_id'},
2459 hash_parent
=>$from_hash,
2461 hash_parent_base
=>$hash_parent,
2462 file_name
=>$diff->{'to_file'},
2463 file_parent
=>$from_path)},
2469 print "<td class=\"link\">";
2471 print $cgi->a({-href
=> href
(action
=>"blob",
2472 hash
=>$diff->{'to_id'},
2473 file_name
=>$diff->{'to_file'},
2476 print " | " if ($has_history);
2479 print $cgi->a({-href
=> href
(action
=>"history",
2480 file_name
=>$diff->{'to_file'},
2487 next; # instead of 'else' clause, to avoid extra indent
2489 # else ordinary diff
2491 my ($to_mode_oct, $to_mode_str, $to_file_type);
2492 my ($from_mode_oct, $from_mode_str, $from_file_type);
2493 if ($diff->{'to_mode'} ne ('0' x
6)) {
2494 $to_mode_oct = oct $diff->{'to_mode'};
2495 if (S_ISREG
($to_mode_oct)) { # only for regular file
2496 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2498 $to_file_type = file_type
($diff->{'to_mode'});
2500 if ($diff->{'from_mode'} ne ('0' x
6)) {
2501 $from_mode_oct = oct $diff->{'from_mode'};
2502 if (S_ISREG
($to_mode_oct)) { # only for regular file
2503 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2505 $from_file_type = file_type
($diff->{'from_mode'});
2508 if ($diff->{'status'} eq "A") { # created
2509 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2510 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2511 $mode_chng .= "]</span>";
2513 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2514 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2515 -class => "list"}, esc_path
($diff->{'file'}));
2517 print "<td>$mode_chng</td>\n";
2518 print "<td class=\"link\">";
2519 if ($action eq 'commitdiff') {
2522 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2525 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2526 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2530 } elsif ($diff->{'status'} eq "D") { # deleted
2531 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2533 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2534 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2535 -class => "list"}, esc_path
($diff->{'file'}));
2537 print "<td>$mode_chng</td>\n";
2538 print "<td class=\"link\">";
2539 if ($action eq 'commitdiff') {
2542 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2545 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2546 hash_base
=>$parent, file_name
=>$diff->{'file'})},
2549 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2550 file_name
=>$diff->{'file'})},
2553 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2554 file_name
=>$diff->{'file'})},
2558 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2559 my $mode_chnge = "";
2560 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2561 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2562 if ($from_file_type ne $to_file_type) {
2563 $mode_chnge .= " from $from_file_type to $to_file_type";
2565 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2566 if ($from_mode_str && $to_mode_str) {
2567 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2568 } elsif ($to_mode_str) {
2569 $mode_chnge .= " mode: $to_mode_str";
2572 $mode_chnge .= "]</span>\n";
2575 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2576 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2577 -class => "list"}, esc_path
($diff->{'file'}));
2579 print "<td>$mode_chnge</td>\n";
2580 print "<td class=\"link\">";
2581 if ($action eq 'commitdiff') {
2584 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2586 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2587 # "commit" view and modified file (not onlu mode changed)
2588 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2589 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2590 hash_base
=>$hash, hash_parent_base
=>$parent,
2591 file_name
=>$diff->{'file'})},
2595 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2596 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2599 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2600 file_name
=>$diff->{'file'})},
2603 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2604 file_name
=>$diff->{'file'})},
2608 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
2609 my %status_name = ('R' => 'moved', 'C' => 'copied');
2610 my $nstatus = $status_name{$diff->{'status'}};
2612 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2613 # mode also for directories, so we cannot use $to_mode_str
2614 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2617 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2618 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
2619 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
2620 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2621 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2622 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
2623 -class => "list"}, esc_path
($diff->{'from_file'})) .
2624 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2625 "<td class=\"link\">";
2626 if ($action eq 'commitdiff') {
2629 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2631 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2632 # "commit" view and modified file (not only pure rename or copy)
2633 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2634 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2635 hash_base
=>$hash, hash_parent_base
=>$parent,
2636 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
2640 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2641 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
2644 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2645 file_name
=>$diff->{'to_file'})},
2648 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2649 file_name
=>$diff->{'to_file'})},
2653 } # we should not encounter Unmerged (U) or Unknown (X) status
2659 sub git_patchset_body
{
2660 my ($fd, $difftree, $hash, @hash_parents) = @_;
2661 my ($hash_parent) = $hash_parents[0];
2664 my $patch_number = 0;
2669 print "<div class=\"patchset\">\n";
2671 # skip to first patch
2672 while ($patch_line = <$fd>) {
2675 last if ($patch_line =~ m/^diff /);
2679 while ($patch_line) {
2681 my ($from_id, $to_id);
2684 #assert($patch_line =~ m/^diff /) if DEBUG;
2685 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2687 push @diff_header, $patch_line;
2689 # extended diff header
2691 while ($patch_line = <$fd>) {
2694 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2696 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2699 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2700 $from_id = [ split(',', $1) ];
2704 push @diff_header, $patch_line;
2706 my $last_patch_line = $patch_line;
2708 # check if current patch belong to current raw line
2709 # and parse raw git-diff line if needed
2710 if (defined $diffinfo &&
2711 defined $from_id && defined $to_id &&
2712 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
2713 $diffinfo->{'to_id'} eq $to_id) {
2714 # this is continuation of a split patch
2715 print "<div class=\"patch cont\">\n";
2717 # advance raw git-diff output if needed
2718 $patch_idx++ if defined $diffinfo;
2720 # read and prepare patch information
2721 if (ref($difftree->[$patch_idx]) eq "HASH") {
2722 # pre-parsed (or generated by hand)
2723 $diffinfo = $difftree->[$patch_idx];
2725 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2727 if ($diffinfo->{'nparents'}) {
2731 fill_from_file_info
($diffinfo, @hash_parents)
2732 unless exists $diffinfo->{'from_file'};
2733 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2734 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2735 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2736 $from{'href'}[$i] = href
(action
=>"blob",
2737 hash_base
=>$hash_parents[$i],
2738 hash
=>$diffinfo->{'from_id'}[$i],
2739 file_name
=>$from{'file'}[$i]);
2741 $from{'href'}[$i] = undef;
2745 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2746 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2747 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2748 hash
=>$diffinfo->{'from_id'},
2749 file_name
=>$from{'file'});
2751 delete $from{'href'};
2755 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2756 if ($diffinfo->{'to_id'} ne ('0' x
40)) { # file exists in result
2757 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2758 hash
=>$diffinfo->{'to_id'},
2759 file_name
=>$to{'file'});
2763 # this is first patch for raw difftree line with $patch_idx index
2764 # we index @$difftree array from 0, but number patches from 1
2765 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2768 # print "git diff" header
2769 $patch_line = shift @diff_header;
2770 if ($diffinfo->{'nparents'}) {
2773 $patch_line =~ s!^(diff (.*?) )"?.*$!$1!;
2775 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2776 esc_path
($to{'file'}));
2777 } else { # file was deleted
2778 $patch_line .= esc_path
($to{'file'});
2783 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2784 if ($from{'href'}) {
2785 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2786 'a/' . esc_path
($from{'file'}));
2787 } else { # file was added
2788 $patch_line .= 'a/' . esc_path
($from{'file'});
2792 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2793 'b/' . esc_path
($to{'file'}));
2794 } else { # file was deleted
2795 $patch_line .= 'b/' . esc_path
($to{'file'});
2799 print "<div class=\"diff header\">$patch_line</div>\n";
2801 # print extended diff header
2802 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2804 foreach $patch_line (@diff_header) {
2806 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2807 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2808 esc_path
($from{'file'}));
2810 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2811 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2812 esc_path
($to{'file'}));
2814 # match single <mode>
2815 if ($patch_line =~ m/\s(\d{6})$/) {
2816 $patch_line .= '<span class="info"> (' .
2817 file_type_long
($1) .
2821 if ($patch_line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
2822 # can match only for combined diff
2823 $patch_line = 'index ';
2824 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2825 if ($from{'href'}[$i]) {
2826 $patch_line .= $cgi->a({-href
=>$from{'href'}[$i],
2828 substr($diffinfo->{'from_id'}[$i],0,7));
2830 $patch_line .= '0' x
7;
2833 $patch_line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
2835 $patch_line .= '..';
2837 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2838 substr($diffinfo->{'to_id'},0,7));
2840 $patch_line .= '0' x
7;
2843 } elsif ($patch_line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
2844 # can match only for ordinary diff
2845 my ($from_link, $to_link);
2846 if ($from{'href'}) {
2847 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2848 substr($diffinfo->{'from_id'},0,7));
2850 $from_link = '0' x
7;
2853 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2854 substr($diffinfo->{'to_id'},0,7));
2859 # my ($from_hash, $to_hash) =
2860 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2861 # my ($from_id, $to_id) =
2862 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2863 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2865 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2866 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2868 print $patch_line . "<br/>\n";
2870 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2872 # from-file/to-file diff header
2873 $patch_line = $last_patch_line;
2874 if (! $patch_line) {
2875 print "</div>\n"; # class="patch"
2878 next PATCH
if ($patch_line =~ m/^diff /);
2879 #assert($patch_line =~ m/^---/) if DEBUG;
2880 if (!$diffinfo->{'nparents'} && # not from-file line for combined diff
2881 $from{'href'} && $patch_line =~ m!^--- "?a/!) {
2882 $patch_line = '--- a/' .
2883 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2884 esc_path
($from{'file'}));
2886 print "<div class=\"diff from_file\">$patch_line</div>\n";
2888 $patch_line = <$fd>;
2891 #assert($patch_line =~ m/^+++/) if DEBUG;
2892 if ($to{'href'} && $patch_line =~ m!^\+\+\+ "?b/!) {
2893 $patch_line = '+++ b/' .
2894 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2895 esc_path
($to{'file'}));
2897 print "<div class=\"diff to_file\">$patch_line</div>\n";
2901 while ($patch_line = <$fd>) {
2904 next PATCH
if ($patch_line =~ m/^diff /);
2906 print format_diff_line
($patch_line, \
%from, \
%to);
2910 print "</div>\n"; # class="patch"
2913 if ($patch_number == 0) {
2914 if (@hash_parents > 1) {
2915 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
2917 print "<div class=\"diff nodifferences\">No differences found</div>\n";
2921 print "</div>\n"; # class="patchset"
2924 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2926 sub git_project_list_body
{
2927 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2929 my ($check_forks) = gitweb_check_feature
('forks');
2932 foreach my $pr (@$projlist) {
2933 my (@aa) = git_get_last_activity
($pr->{'path'});
2937 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2938 if (!defined $pr->{'descr'}) {
2939 my $descr = git_get_project_description
($pr->{'path'}) || "";
2940 $pr->{'descr_long'} = decode_utf8
($descr);
2941 $pr->{'descr'} = chop_str
($descr, 25, 5);
2943 if (!defined $pr->{'owner'}) {
2944 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2947 my $pname = $pr->{'path'};
2948 if (($pname =~ s/\.git$//) &&
2949 ($pname !~ /\/$/) &&
2950 (-d
"$projectroot/$pname")) {
2951 $pr->{'forks'} = "-d $projectroot/$pname";
2957 push @projects, $pr;
2960 $order ||= $default_projects_order;
2961 $from = 0 unless defined $from;
2962 $to = $#projects if (!defined $to || $#projects < $to);
2964 print "<table class=\"project_list\">\n";
2965 unless ($no_header) {
2968 print "<th></th>\n";
2970 if ($order eq "project") {
2971 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2972 print "<th>Project</th>\n";
2975 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2976 -class => "header"}, "Project") .
2979 if ($order eq "descr") {
2980 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2981 print "<th>Description</th>\n";
2984 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2985 -class => "header"}, "Description") .
2988 if ($order eq "owner") {
2989 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2990 print "<th>Owner</th>\n";
2993 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2994 -class => "header"}, "Owner") .
2997 if ($order eq "age") {
2998 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2999 print "<th>Last Change</th>\n";
3002 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3003 -class => "header"}, "Last Change") .
3006 print "<th></th>\n" .
3010 for (my $i = $from; $i <= $to; $i++) {
3011 my $pr = $projects[$i];
3013 print "<tr class=\"dark\">\n";
3015 print "<tr class=\"light\">\n";
3020 if ($pr->{'forks'}) {
3021 print "<!-- $pr->{'forks'} -->\n";
3022 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3026 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3027 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3028 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3029 -class => "list", -title
=> $pr->{'descr_long'}},
3030 esc_html
($pr->{'descr'})) . "</td>\n" .
3031 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
3032 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3033 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3034 "<td class=\"link\">" .
3035 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3036 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3037 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3038 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3039 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3043 if (defined $extra) {
3046 print "<td></td>\n";
3048 print "<td colspan=\"5\">$extra</td>\n" .
3054 sub git_shortlog_body
{
3055 # uses global variable $project
3056 my ($commitlist, $from, $to, $refs, $extra) = @_;
3058 my $have_snapshot = gitweb_have_snapshot
();
3060 $from = 0 unless defined $from;
3061 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3063 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3065 for (my $i = $from; $i <= $to; $i++) {
3066 my %co = %{$commitlist->[$i]};
3067 my $commit = $co{'id'};
3068 my $ref = format_ref_marker
($refs, $commit);
3070 print "<tr class=\"dark\">\n";
3072 print "<tr class=\"light\">\n";
3075 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3076 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3077 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3079 print format_subject_html
($co{'title'}, $co{'title_short'},
3080 href
(action
=>"commit", hash
=>$commit), $ref);
3082 "<td class=\"link\">" .
3083 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3084 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3085 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3086 if ($have_snapshot) {
3087 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
3092 if (defined $extra) {
3094 "<td colspan=\"4\">$extra</td>\n" .
3100 sub git_history_body
{
3101 # Warning: assumes constant type (blob or tree) during history
3102 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3104 $from = 0 unless defined $from;
3105 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3107 print "<table class=\"history\" cellspacing=\"0\">\n";
3109 for (my $i = $from; $i <= $to; $i++) {
3110 my %co = %{$commitlist->[$i]};
3114 my $commit = $co{'id'};
3116 my $ref = format_ref_marker
($refs, $commit);
3119 print "<tr class=\"dark\">\n";
3121 print "<tr class=\"light\">\n";
3124 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3125 # shortlog uses chop_str($co{'author_name'}, 10)
3126 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3128 # originally git_history used chop_str($co{'title'}, 50)
3129 print format_subject_html
($co{'title'}, $co{'title_short'},
3130 href
(action
=>"commit", hash
=>$commit), $ref);
3132 "<td class=\"link\">" .
3133 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3134 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3136 if ($ftype eq 'blob') {
3137 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3138 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3139 if (defined $blob_current && defined $blob_parent &&
3140 $blob_current ne $blob_parent) {
3142 $cgi->a({-href
=> href
(action
=>"blobdiff",
3143 hash
=>$blob_current, hash_parent
=>$blob_parent,
3144 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3145 file_name
=>$file_name)},
3152 if (defined $extra) {
3154 "<td colspan=\"4\">$extra</td>\n" .
3161 # uses global variable $project
3162 my ($taglist, $from, $to, $extra) = @_;
3163 $from = 0 unless defined $from;
3164 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3166 print "<table class=\"tags\" cellspacing=\"0\">\n";
3168 for (my $i = $from; $i <= $to; $i++) {
3169 my $entry = $taglist->[$i];
3171 my $comment = $tag{'subject'};
3173 if (defined $comment) {
3174 $comment_short = chop_str
($comment, 30, 5);
3177 print "<tr class=\"dark\">\n";
3179 print "<tr class=\"light\">\n";
3182 if (defined $tag{'age'}) {
3183 print "<td><i>$tag{'age'}</i></td>\n";
3185 print "<td></td>\n";
3188 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3189 -class => "list name"}, esc_html
($tag{'name'})) .
3192 if (defined $comment) {
3193 print format_subject_html
($comment, $comment_short,
3194 href
(action
=>"tag", hash
=>$tag{'id'}));
3197 "<td class=\"selflink\">";
3198 if ($tag{'type'} eq "tag") {
3199 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3204 "<td class=\"link\">" . " | " .
3205 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3206 if ($tag{'reftype'} eq "commit") {
3207 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3208 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3209 } elsif ($tag{'reftype'} eq "blob") {
3210 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3215 if (defined $extra) {
3217 "<td colspan=\"5\">$extra</td>\n" .
3223 sub git_heads_body
{
3224 # uses global variable $project
3225 my ($headlist, $head, $from, $to, $extra) = @_;
3226 $from = 0 unless defined $from;
3227 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3229 print "<table class=\"heads\" cellspacing=\"0\">\n";
3231 for (my $i = $from; $i <= $to; $i++) {
3232 my $entry = $headlist->[$i];
3234 my $curr = $ref{'id'} eq $head;
3236 print "<tr class=\"dark\">\n";
3238 print "<tr class=\"light\">\n";
3241 print "<td><i>$ref{'age'}</i></td>\n" .
3242 ($curr ? "<td class=\"current_head\">" : "<td>") .
3243 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3244 -class => "list name"},esc_html
($ref{'name'})) .
3246 "<td class=\"link\">" .
3247 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3248 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3249 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3253 if (defined $extra) {
3255 "<td colspan=\"3\">$extra</td>\n" .
3261 sub git_search_grep_body
{
3262 my ($commitlist, $from, $to, $extra) = @_;
3263 $from = 0 unless defined $from;
3264 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3266 print "<table class=\"grep\" cellspacing=\"0\">\n";
3268 for (my $i = $from; $i <= $to; $i++) {
3269 my %co = %{$commitlist->[$i]};
3273 my $commit = $co{'id'};
3275 print "<tr class=\"dark\">\n";
3277 print "<tr class=\"light\">\n";
3280 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3281 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3283 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3284 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3285 my $comment = $co{'comment'};
3286 foreach my $line (@$comment) {
3287 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3288 my $lead = esc_html
($1) || "";
3289 $lead = chop_str
($lead, 30, 10);
3290 my $match = esc_html
($2) || "";
3291 my $trail = esc_html
($3) || "";
3292 $trail = chop_str
($trail, 30, 10);
3293 my $text = "$lead<span class=\"match\">$match</span>$trail";
3294 print chop_str
($text, 80, 5) . "<br/>\n";
3298 "<td class=\"link\">" .
3299 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3301 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3305 if (defined $extra) {
3307 "<td colspan=\"3\">$extra</td>\n" .
3313 ## ======================================================================
3314 ## ======================================================================
3317 sub git_project_list
{
3318 my $order = $cgi->param('o');
3319 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3320 die_error
(undef, "Unknown order parameter");
3323 my @list = git_get_projects_list
();
3325 die_error
(undef, "No projects found");
3329 if (-f
$home_text) {
3330 print "<div class=\"index_include\">\n";
3331 open (my $fd, $home_text);
3336 git_project_list_body
(\
@list, $order);
3341 my $order = $cgi->param('o');
3342 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3343 die_error
(undef, "Unknown order parameter");
3346 my @list = git_get_projects_list
($project);
3348 die_error
(undef, "No forks found");
3352 git_print_page_nav
('','');
3353 git_print_header_div
('summary', "$project forks");
3354 git_project_list_body
(\
@list, $order);
3358 sub git_project_index
{
3359 my @projects = git_get_projects_list
($project);
3362 -type
=> 'text/plain',
3363 -charset
=> 'utf-8',
3364 -content_disposition
=> 'inline; filename="index.aux"');
3366 foreach my $pr (@projects) {
3367 if (!exists $pr->{'owner'}) {
3368 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3371 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3372 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3373 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3374 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3378 print "$path $owner\n";
3383 my $descr = git_get_project_description
($project) || "none";
3384 my %co = parse_commit
("HEAD");
3385 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3386 my $head = $co{'id'};
3388 my $owner = git_get_project_owner
($project);
3390 my $refs = git_get_references
();
3391 # These get_*_list functions return one more to allow us to see if
3392 # there are more ...
3393 my @taglist = git_get_tags_list
(16);
3394 my @headlist = git_get_heads_list
(16);
3396 my ($check_forks) = gitweb_check_feature
('forks');
3399 @forklist = git_get_projects_list
($project);
3403 git_print_page_nav
('summary','', $head);
3405 print "<div class=\"title\"> </div>\n";
3406 print "<table cellspacing=\"0\">\n" .
3407 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3408 "<tr><td>owner</td><td>$owner</td></tr>\n";
3409 if (defined $cd{'rfc2822'}) {
3410 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3413 # use per project git URL list in $projectroot/$project/cloneurl
3414 # or make project git URL from git base URL and project name
3415 my $url_tag = "URL";
3416 my @url_list = git_get_project_url_list
($project);
3417 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3418 foreach my $git_url (@url_list) {
3419 next unless $git_url;
3420 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3425 if (-s
"$projectroot/$project/README.html") {
3426 if (open my $fd, "$projectroot/$project/README.html") {
3427 print "<div class=\"title\">readme</div>\n";
3428 print $_ while (<$fd>);
3433 # we need to request one more than 16 (0..15) to check if
3435 my @commitlist = $head ? parse_commits
($head, 17) : ();
3437 git_print_header_div
('shortlog');
3438 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3439 $#commitlist <= 15 ? undef :
3440 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3444 git_print_header_div
('tags');
3445 git_tags_body
(\
@taglist, 0, 15,
3446 $#taglist <= 15 ? undef :
3447 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3451 git_print_header_div
('heads');
3452 git_heads_body
(\
@headlist, $head, 0, 15,
3453 $#headlist <= 15 ? undef :
3454 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3458 git_print_header_div
('forks');
3459 git_project_list_body
(\
@forklist, undef, 0, 15,
3460 $#forklist <= 15 ? undef :
3461 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3469 my $head = git_get_head_hash
($project);
3471 git_print_page_nav
('','', $head,undef,$head);
3472 my %tag = parse_tag
($hash);
3475 die_error
(undef, "Unknown tag object");
3478 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3479 print "<div class=\"title_text\">\n" .
3480 "<table cellspacing=\"0\">\n" .
3482 "<td>object</td>\n" .
3483 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3484 $tag{'object'}) . "</td>\n" .
3485 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3486 $tag{'type'}) . "</td>\n" .
3488 if (defined($tag{'author'})) {
3489 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3490 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3491 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3492 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3495 print "</table>\n\n" .
3497 print "<div class=\"page_body\">";
3498 my $comment = $tag{'comment'};
3499 foreach my $line (@$comment) {
3501 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3511 my ($have_blame) = gitweb_check_feature
('blame');
3513 die_error
('403 Permission denied', "Permission denied");
3515 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3516 $hash_base ||= git_get_head_hash
($project);
3517 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3518 my %co = parse_commit
($hash_base)
3519 or die_error
(undef, "Reading commit failed");
3520 if (!defined $hash) {
3521 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3522 or die_error
(undef, "Error looking up file");
3524 $ftype = git_get_type
($hash);
3525 if ($ftype !~ "blob") {
3526 die_error
('400 Bad Request', "Object is not a blob");
3528 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3529 $file_name, $hash_base)
3530 or die_error
(undef, "Open git-blame failed");
3533 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3536 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3539 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3541 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3542 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3543 git_print_page_path
($file_name, $ftype, $hash_base);
3544 my @rev_color = (qw(light2 dark2));
3545 my $num_colors = scalar(@rev_color);
3546 my $current_color = 0;
3549 <div class="page_body">
3550 <table class="blame">
3551 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3556 last unless defined $_;
3557 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3558 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3559 if (!exists $metainfo{$full_rev}) {
3560 $metainfo{$full_rev} = {};
3562 my $meta = $metainfo{$full_rev};
3565 if (/^(\S+) (.*)$/) {
3571 my $rev = substr($full_rev, 0, 8);
3572 my $author = $meta->{'author'};
3573 my %date = parse_date
($meta->{'author-time'},
3574 $meta->{'author-tz'});
3575 my $date = $date{'iso-tz'};
3577 $current_color = ++$current_color % $num_colors;
3579 print "<tr class=\"$rev_color[$current_color]\">\n";
3581 print "<td class=\"sha1\"";
3582 print " title=\"". esc_html
($author) . ", $date\"";
3583 print " rowspan=\"$group_size\"" if ($group_size > 1);
3585 print $cgi->a({-href
=> href
(action
=>"commit",
3587 file_name
=>$file_name)},
3591 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3592 or die_error
(undef, "Open git-rev-parse failed");
3593 my $parent_commit = <$dd>;
3595 chomp($parent_commit);
3596 my $blamed = href
(action
=> 'blame',
3597 file_name
=> $meta->{'filename'},
3598 hash_base
=> $parent_commit);
3599 print "<td class=\"linenr\">";
3600 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3602 -class => "linenr" },
3605 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3611 or print "Reading blob failed\n";
3618 my ($have_blame) = gitweb_check_feature
('blame');
3620 die_error
('403 Permission denied', "Permission denied");
3622 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3623 $hash_base ||= git_get_head_hash
($project);
3624 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3625 my %co = parse_commit
($hash_base)
3626 or die_error
(undef, "Reading commit failed");
3627 if (!defined $hash) {
3628 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3629 or die_error
(undef, "Error lookup file");
3631 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3632 or die_error
(undef, "Open git-annotate failed");
3635 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3638 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3641 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3643 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3644 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3645 git_print_page_path
($file_name, 'blob', $hash_base);
3646 print "<div class=\"page_body\">\n";
3648 <table class="blame">
3657 my @line_class = (qw(light dark));
3658 my $line_class_len = scalar (@line_class);
3659 my $line_class_num = $#line_class;
3660 while (my $line = <$fd>) {
3672 $line_class_num = ($line_class_num + 1) % $line_class_len;
3674 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3681 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3684 $short_rev = substr ($long_rev, 0, 8);
3685 $age = time () - $time;
3686 $age_str = age_string
($age);
3687 $age_str =~ s/ / /g;
3688 $age_class = age_class
($age);
3689 $author = esc_html
($author);
3690 $author =~ s/ / /g;
3692 $data = untabify
($data);
3693 $data = esc_html
($data);
3696 <tr class="$line_class[$line_class_num]">
3697 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3698 <td class="$age_class">$age_str</td>
3700 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3701 <td class="pre">$data</td>
3704 } # while (my $line = <$fd>)
3705 print "</table>\n\n";
3707 or print "Reading blob failed.\n";
3713 my $head = git_get_head_hash
($project);
3715 git_print_page_nav
('','', $head,undef,$head);
3716 git_print_header_div
('summary', $project);
3718 my @tagslist = git_get_tags_list
();
3720 git_tags_body
(\
@tagslist);
3726 my $head = git_get_head_hash
($project);
3728 git_print_page_nav
('','', $head,undef,$head);
3729 git_print_header_div
('summary', $project);
3731 my @headslist = git_get_heads_list
();
3733 git_heads_body
(\
@headslist, $head);
3738 sub git_blob_plain
{
3741 if (!defined $hash) {
3742 if (defined $file_name) {
3743 my $base = $hash_base || git_get_head_hash
($project);
3744 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3745 or die_error
(undef, "Error lookup file");
3747 die_error
(undef, "No file name defined");
3749 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3750 # blobs defined by non-textual hash id's can be cached
3755 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3756 or die_error
(undef, "Couldn't cat $file_name, $hash");
3758 $type ||= blob_mimetype
($fd, $file_name);
3760 # save as filename, even when no $file_name is given
3761 my $save_as = "$hash";
3762 if (defined $file_name) {
3763 $save_as = $file_name;
3764 } elsif ($type =~ m/^text\//) {
3771 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3773 binmode STDOUT
, ':raw';
3775 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3783 if (!defined $hash) {
3784 if (defined $file_name) {
3785 my $base = $hash_base || git_get_head_hash
($project);
3786 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3787 or die_error
(undef, "Error lookup file");
3789 die_error
(undef, "No file name defined");
3791 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3792 # blobs defined by non-textual hash id's can be cached
3796 my ($have_blame) = gitweb_check_feature
('blame');
3797 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3798 or die_error
(undef, "Couldn't cat $file_name, $hash");
3799 my $mimetype = blob_mimetype
($fd, $file_name);
3800 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3802 return git_blob_plain
($mimetype);
3804 # we can have blame only for text/* mimetype
3805 $have_blame &&= ($mimetype =~ m!^text/!);
3807 git_header_html
(undef, $expires);
3808 my $formats_nav = '';
3809 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3810 if (defined $file_name) {
3813 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3814 hash
=>$hash, file_name
=>$file_name)},
3819 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3820 hash
=>$hash, file_name
=>$file_name)},
3823 $cgi->a({-href
=> href
(action
=>"blob_plain",
3824 hash
=>$hash, file_name
=>$file_name)},
3827 $cgi->a({-href
=> href
(action
=>"blob",
3828 hash_base
=>"HEAD", file_name
=>$file_name)},
3832 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3834 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3835 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3837 print "<div class=\"page_nav\">\n" .
3838 "<br/><br/></div>\n" .
3839 "<div class=\"title\">$hash</div>\n";
3841 git_print_page_path
($file_name, "blob", $hash_base);
3842 print "<div class=\"page_body\">\n";
3843 if ($mimetype =~ m!^text/!) {
3845 while (my $line = <$fd>) {
3848 $line = untabify
($line);
3849 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3850 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3852 } elsif ($mimetype =~ m!^image/!) {
3853 print qq
!<img type
="$mimetype"!;
3855 print qq
! alt
="$file_name" title
="$file_name"!;
3858 href(action=>"blob_plain
", hash=>$hash,
3859 hash_base=>$hash_base, file_name=>$file_name) .
3863 or print "Reading blob failed.\n";
3869 my $have_snapshot = gitweb_have_snapshot
();
3871 if (!defined $hash_base) {
3872 $hash_base = "HEAD";
3874 if (!defined $hash) {
3875 if (defined $file_name) {
3876 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3882 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3883 or die_error
(undef, "Open git-ls-tree failed");
3884 my @entries = map { chomp; $_ } <$fd>;
3885 close $fd or die_error
(undef, "Reading tree failed");
3888 my $refs = git_get_references
();
3889 my $ref = format_ref_marker
($refs, $hash_base);
3892 my ($have_blame) = gitweb_check_feature
('blame');
3893 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3895 if (defined $file_name) {
3897 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3898 hash
=>$hash, file_name
=>$file_name)},
3900 $cgi->a({-href
=> href
(action
=>"tree",
3901 hash_base
=>"HEAD", file_name
=>$file_name)},
3904 if ($have_snapshot) {
3905 # FIXME: Should be available when we have no hash base as well.
3907 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3910 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3911 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3914 print "<div class=\"page_nav\">\n";
3915 print "<br/><br/></div>\n";
3916 print "<div class=\"title\">$hash</div>\n";
3918 if (defined $file_name) {
3919 $basedir = $file_name;
3920 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3924 git_print_page_path
($file_name, 'tree', $hash_base);
3925 print "<div class=\"page_body\">\n";
3926 print "<table cellspacing=\"0\">\n";
3928 # '..' (top directory) link if possible
3929 if (defined $hash_base &&
3930 defined $file_name && $file_name =~ m![^/]+$!) {
3932 print "<tr class=\"dark\">\n";
3934 print "<tr class=\"light\">\n";
3938 my $up = $file_name;
3939 $up =~ s!/?[^/]+$!!;
3940 undef $up unless $up;
3941 # based on git_print_tree_entry
3942 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3943 print '<td class="list">';
3944 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3948 print "<td class=\"link\"></td>\n";
3952 foreach my $line (@entries) {
3953 my %t = parse_ls_tree_line
($line, -z
=> 1);
3956 print "<tr class=\"dark\">\n";
3958 print "<tr class=\"light\">\n";
3962 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3966 print "</table>\n" .
3972 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3973 my $have_snapshot = (defined $ctype && defined $suffix);
3974 if (!$have_snapshot) {
3975 die_error
('403 Permission denied', "Permission denied");
3978 if (!defined $hash) {
3979 $hash = git_get_head_hash
($project);
3982 my $git = git_cmd_str
();
3983 my $name = $project;
3984 $name =~ s/\047/\047\\\047\047/g;
3985 my $filename = decode_utf8
(basename
($project));
3987 if ($suffix eq 'zip') {
3988 $filename .= "-$hash.$suffix";
3989 $cmd = "$git archive --format=zip --prefix=\'$name\'/ $hash";
3991 $filename .= "-$hash.tar.$suffix";
3992 $cmd = "$git archive --format=tar --prefix=\'$name\'/ $hash | $command";
3996 -type
=> "application/$ctype",
3997 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3998 -status
=> '200 OK');
4000 open my $fd, "-|", $cmd
4001 or die_error
(undef, "Execute git-archive failed");
4002 binmode STDOUT
, ':raw';
4004 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4010 my $head = git_get_head_hash
($project);
4011 if (!defined $hash) {
4014 if (!defined $page) {
4017 my $refs = git_get_references
();
4019 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4021 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4024 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4027 my %co = parse_commit
($hash);
4029 git_print_header_div
('summary', $project);
4030 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4032 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4033 for (my $i = 0; $i <= $to; $i++) {
4034 my %co = %{$commitlist[$i]};
4036 my $commit = $co{'id'};
4037 my $ref = format_ref_marker
($refs, $commit);
4038 my %ad = parse_date
($co{'author_epoch'});
4039 git_print_header_div
('commit',
4040 "<span class=\"age\">$co{'age_string'}</span>" .
4041 esc_html
($co{'title'}) . $ref,
4043 print "<div class=\"title_text\">\n" .
4044 "<div class=\"log_link\">\n" .
4045 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4047 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4049 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4052 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4055 print "<div class=\"log_body\">\n";
4056 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4059 if ($#commitlist >= 100) {
4060 print "<div class=\"page_nav\">\n";
4061 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4062 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4069 $hash ||= $hash_base || "HEAD";
4070 my %co = parse_commit
($hash);
4072 die_error
(undef, "Unknown commit object");
4074 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4075 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4077 my $parent = $co{'parent'};
4078 my $parents = $co{'parents'}; # listref
4080 # we need to prepare $formats_nav before any parameter munging
4082 if (!defined $parent) {
4084 $formats_nav .= '(initial)';
4085 } elsif (@$parents == 1) {
4086 # single parent commit
4089 $cgi->a({-href
=> href
(action
=>"commit",
4091 esc_html
(substr($parent, 0, 7))) .
4098 $cgi->a({-href
=> href
(action
=>"commit",
4100 esc_html
(substr($_, 0, 7)));
4105 if (!defined $parent) {
4109 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4111 (@$parents <= 1 ? $parent : '-c'),
4113 or die_error
(undef, "Open git-diff-tree failed");
4114 @difftree = map { chomp; $_ } <$fd>;
4115 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4117 # non-textual hash id's can be cached
4119 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4122 my $refs = git_get_references
();
4123 my $ref = format_ref_marker
($refs, $co{'id'});
4125 my $have_snapshot = gitweb_have_snapshot
();
4127 git_header_html
(undef, $expires);
4128 git_print_page_nav
('commit', '',
4129 $hash, $co{'tree'}, $hash,
4132 if (defined $co{'parent'}) {
4133 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4135 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4137 print "<div class=\"title_text\">\n" .
4138 "<table cellspacing=\"0\">\n";
4139 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4141 "<td></td><td> $ad{'rfc2822'}";
4142 if ($ad{'hour_local'} < 6) {
4143 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4144 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4146 printf(" (%02d:%02d %s)",
4147 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4151 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4152 print "<tr><td></td><td> $cd{'rfc2822'}" .
4153 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4155 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4158 "<td class=\"sha1\">" .
4159 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4160 class => "list"}, $co{'tree'}) .
4162 "<td class=\"link\">" .
4163 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4165 if ($have_snapshot) {
4167 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
4172 foreach my $par (@$parents) {
4175 "<td class=\"sha1\">" .
4176 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4177 class => "list"}, $par) .
4179 "<td class=\"link\">" .
4180 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4182 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4189 print "<div class=\"page_body\">\n";
4190 git_print_log
($co{'comment'});
4193 git_difftree_body
(\
@difftree, $hash, @$parents);
4199 # object is defined by:
4200 # - hash or hash_base alone
4201 # - hash_base and file_name
4204 # - hash or hash_base alone
4205 if ($hash || ($hash_base && !defined $file_name)) {
4206 my $object_id = $hash || $hash_base;
4208 my $git_command = git_cmd_str
();
4209 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4210 or die_error
('404 Not Found', "Object does not exist");
4214 or die_error
('404 Not Found', "Object does not exist");
4216 # - hash_base and file_name
4217 } elsif ($hash_base && defined $file_name) {
4218 $file_name =~ s
,/+$,,;
4220 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4221 or die_error
('404 Not Found', "Base object does not exist");
4223 # here errors should not hapen
4224 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4225 or die_error
(undef, "Open git-ls-tree failed");
4229 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4230 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4231 die_error
('404 Not Found', "File or directory for given base does not exist");
4236 die_error
('404 Not Found', "Not enough information to find object");
4239 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4240 hash
=>$hash, hash_base
=>$hash_base,
4241 file_name
=>$file_name),
4242 -status
=> '302 Found');
4246 my $format = shift || 'html';
4253 # preparing $fd and %diffinfo for git_patchset_body
4255 if (defined $hash_base && defined $hash_parent_base) {
4256 if (defined $file_name) {
4258 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4259 $hash_parent_base, $hash_base,
4260 "--", (defined $file_parent ? $file_parent : ()), $file_name
4261 or die_error
(undef, "Open git-diff-tree failed");
4262 @difftree = map { chomp; $_ } <$fd>;
4264 or die_error
(undef, "Reading git-diff-tree failed");
4266 or die_error
('404 Not Found', "Blob diff not found");
4268 } elsif (defined $hash &&
4269 $hash =~ /[0-9a-fA-F]{40}/) {
4270 # try to find filename from $hash
4272 # read filtered raw output
4273 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4274 $hash_parent_base, $hash_base, "--"
4275 or die_error
(undef, "Open git-diff-tree failed");
4277 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4279 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4280 map { chomp; $_ } <$fd>;
4282 or die_error
(undef, "Reading git-diff-tree failed");
4284 or die_error
('404 Not Found', "Blob diff not found");
4287 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4290 if (@difftree > 1) {
4291 die_error
('404 Not Found', "Ambiguous blob diff specification");
4294 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4295 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4296 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4298 $hash_parent ||= $diffinfo{'from_id'};
4299 $hash ||= $diffinfo{'to_id'};
4301 # non-textual hash id's can be cached
4302 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4303 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4308 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4309 '-p', ($format eq 'html' ? "--full-index" : ()),
4310 $hash_parent_base, $hash_base,
4311 "--", (defined $file_parent ? $file_parent : ()), $file_name
4312 or die_error
(undef, "Open git-diff-tree failed");
4315 # old/legacy style URI
4316 if (!%diffinfo && # if new style URI failed
4317 defined $hash && defined $hash_parent) {
4318 # fake git-diff-tree raw output
4319 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4320 $diffinfo{'from_id'} = $hash_parent;
4321 $diffinfo{'to_id'} = $hash;
4322 if (defined $file_name) {
4323 if (defined $file_parent) {
4324 $diffinfo{'status'} = '2';
4325 $diffinfo{'from_file'} = $file_parent;
4326 $diffinfo{'to_file'} = $file_name;
4327 } else { # assume not renamed
4328 $diffinfo{'status'} = '1';
4329 $diffinfo{'from_file'} = $file_name;
4330 $diffinfo{'to_file'} = $file_name;
4332 } else { # no filename given
4333 $diffinfo{'status'} = '2';
4334 $diffinfo{'from_file'} = $hash_parent;
4335 $diffinfo{'to_file'} = $hash;
4338 # non-textual hash id's can be cached
4339 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4340 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4345 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4346 '-p', ($format eq 'html' ? "--full-index" : ()),
4347 $hash_parent, $hash, "--"
4348 or die_error
(undef, "Open git-diff failed");
4350 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4355 if ($format eq 'html') {
4357 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4358 hash
=>$hash, hash_parent
=>$hash_parent,
4359 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4360 file_name
=>$file_name, file_parent
=>$file_parent)},
4362 git_header_html
(undef, $expires);
4363 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4364 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4365 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4367 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4368 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4370 if (defined $file_name) {
4371 git_print_page_path
($file_name, "blob", $hash_base);
4373 print "<div class=\"page_path\"></div>\n";
4376 } elsif ($format eq 'plain') {
4378 -type
=> 'text/plain',
4379 -charset
=> 'utf-8',
4380 -expires
=> $expires,
4381 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4383 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4386 die_error
(undef, "Unknown blobdiff format");
4390 if ($format eq 'html') {
4391 print "<div class=\"page_body\">\n";
4393 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4396 print "</div>\n"; # class="page_body"
4400 while (my $line = <$fd>) {
4401 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4402 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4406 last if $line =~ m!^\+\+\+!;
4414 sub git_blobdiff_plain
{
4415 git_blobdiff
('plain');
4418 sub git_commitdiff
{
4419 my $format = shift || 'html';
4420 $hash ||= $hash_base || "HEAD";
4421 my %co = parse_commit
($hash);
4423 die_error
(undef, "Unknown commit object");
4426 # we need to prepare $formats_nav before any parameter munging
4428 if ($format eq 'html') {
4430 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4431 hash
=>$hash, hash_parent
=>$hash_parent)},
4434 if (defined $hash_parent) {
4435 # commitdiff with two commits given
4436 my $hash_parent_short = $hash_parent;
4437 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4438 $hash_parent_short = substr($hash_parent, 0, 7);
4442 $cgi->a({-href
=> href
(action
=>"commitdiff",
4443 hash
=>$hash_parent)},
4444 esc_html
($hash_parent_short)) .
4446 } elsif (!$co{'parent'}) {
4448 $formats_nav .= ' (initial)';
4449 } elsif (scalar @{$co{'parents'}} == 1) {
4450 # single parent commit
4453 $cgi->a({-href
=> href
(action
=>"commitdiff",
4454 hash
=>$co{'parent'})},
4455 esc_html
(substr($co{'parent'}, 0, 7))) .
4462 $cgi->a({-href
=> href
(action
=>"commitdiff",
4464 esc_html
(substr($_, 0, 7)));
4465 } @{$co{'parents'}} ) .
4470 my $hash_parent_param = $hash_parent;
4471 if (!defined $hash_parent) {
4472 $hash_parent_param =
4473 @{$co{'parents'}} > 1 ? '-c' : $co{'parent'} || '--root';
4479 if ($format eq 'html') {
4480 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4481 "--no-commit-id", "--patch-with-raw", "--full-index",
4482 $hash_parent_param, $hash, "--"
4483 or die_error
(undef, "Open git-diff-tree failed");
4485 while (my $line = <$fd>) {
4487 # empty line ends raw part of diff-tree output
4489 push @difftree, scalar parse_difftree_raw_line
($line);
4492 } elsif ($format eq 'plain') {
4493 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4494 '-p', $hash_parent_param, $hash, "--"
4495 or die_error
(undef, "Open git-diff-tree failed");
4498 die_error
(undef, "Unknown commitdiff format");
4501 # non-textual hash id's can be cached
4503 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4507 # write commit message
4508 if ($format eq 'html') {
4509 my $refs = git_get_references
();
4510 my $ref = format_ref_marker
($refs, $co{'id'});
4512 git_header_html
(undef, $expires);
4513 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4514 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4515 git_print_authorship
(\
%co);
4516 print "<div class=\"page_body\">\n";
4517 if (@{$co{'comment'}} > 1) {
4518 print "<div class=\"log\">\n";
4519 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4520 print "</div>\n"; # class="log"
4523 } elsif ($format eq 'plain') {
4524 my $refs = git_get_references
("tags");
4525 my $tagname = git_get_rev_name_tags
($hash);
4526 my $filename = basename
($project) . "-$hash.patch";
4529 -type
=> 'text/plain',
4530 -charset
=> 'utf-8',
4531 -expires
=> $expires,
4532 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4533 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4536 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4537 Subject: $co{'title'}
4539 print "X-Git-Tag: $tagname\n" if $tagname;
4540 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4542 foreach my $line (@{$co{'comment'}}) {
4549 if ($format eq 'html') {
4550 git_difftree_body
(\
@difftree, $hash, $hash_parent || @{$co{'parents'}});
4553 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent || @{$co{'parents'}});
4555 print "</div>\n"; # class="page_body"
4558 } elsif ($format eq 'plain') {
4562 or print "Reading git-diff-tree failed\n";
4566 sub git_commitdiff_plain
{
4567 git_commitdiff
('plain');
4571 if (!defined $hash_base) {
4572 $hash_base = git_get_head_hash
($project);
4574 if (!defined $page) {
4578 my %co = parse_commit
($hash_base);
4580 die_error
(undef, "Unknown commit object");
4583 my $refs = git_get_references
();
4584 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4586 if (!defined $hash && defined $file_name) {
4587 $hash = git_get_hash_by_path
($hash_base, $file_name);
4589 if (defined $hash) {
4590 $ftype = git_get_type
($hash);
4593 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4595 my $paging_nav = '';
4598 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4599 file_name
=>$file_name)},
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
=> "p", -title
=> "Alt-p"}, "prev");
4606 $paging_nav .= "first";
4607 $paging_nav .= " ⋅ prev";
4609 if ($#commitlist >= 100) {
4610 $paging_nav .= " ⋅ " .
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");
4615 $paging_nav .= " ⋅ next";
4618 if ($#commitlist >= 100) {
4620 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4621 file_name
=>$file_name, page
=>$page+1),
4622 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4626 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4627 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4628 git_print_page_path
($file_name, $ftype, $hash_base);
4630 git_history_body
(\
@commitlist, 0, 99,
4631 $refs, $hash_base, $ftype, $next_link);
4637 my ($have_search) = gitweb_check_feature
('search');
4638 if (!$have_search) {
4639 die_error
('403 Permission denied', "Permission denied");
4641 if (!defined $searchtext) {
4642 die_error
(undef, "Text field empty");
4644 if (!defined $hash) {
4645 $hash = git_get_head_hash
($project);
4647 my %co = parse_commit
($hash);
4649 die_error
(undef, "Unknown commit object");
4651 if (!defined $page) {
4655 $searchtype ||= 'commit';
4656 if ($searchtype eq 'pickaxe') {
4657 # pickaxe may take all resources of your box and run for several minutes
4658 # with every query - so decide by yourself how public you make this feature
4659 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4660 if (!$have_pickaxe) {
4661 die_error
('403 Permission denied', "Permission denied");
4664 if ($searchtype eq 'grep') {
4665 my ($have_grep) = gitweb_check_feature
('grep');
4667 die_error
('403 Permission denied', "Permission denied");
4673 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4675 if ($searchtype eq 'commit') {
4676 $greptype = "--grep=";
4677 } elsif ($searchtype eq 'author') {
4678 $greptype = "--author=";
4679 } elsif ($searchtype eq 'committer') {
4680 $greptype = "--committer=";
4682 $greptype .= $search_regexp;
4683 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4685 my $paging_nav = '';
4688 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4689 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4691 $paging_nav .= " ⋅ " .
4692 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4693 searchtext
=>$searchtext, searchtype
=>$searchtype,
4695 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4697 $paging_nav .= "first";
4698 $paging_nav .= " ⋅ prev";
4700 if ($#commitlist >= 100) {
4701 $paging_nav .= " ⋅ " .
4702 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4703 searchtext
=>$searchtext, searchtype
=>$searchtype,
4705 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4707 $paging_nav .= " ⋅ next";
4710 if ($#commitlist >= 100) {
4712 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4713 searchtext
=>$searchtext, searchtype
=>$searchtype,
4715 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4718 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4719 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4720 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4723 if ($searchtype eq 'pickaxe') {
4724 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4725 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4727 print "<table cellspacing=\"0\">\n";
4730 my $git_command = git_cmd_str
();
4731 my $searchqtext = $searchtext;
4732 $searchqtext =~ s/'/'\\''/;
4733 open my $fd, "-|", "$git_command rev-list $hash | " .
4734 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
4737 while (my $line = <$fd>) {
4738 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4741 $set{'from_id'} = $3;
4743 $set{'id'} = $set{'to_id'};
4744 if ($set{'id'} =~ m/0{40}/) {
4745 $set{'id'} = $set{'from_id'};
4747 if ($set{'id'} =~ m/0{40}/) {
4751 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4754 print "<tr class=\"dark\">\n";
4756 print "<tr class=\"light\">\n";
4759 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4760 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4762 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4763 -class => "list subject"},
4764 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4765 while (my $setref = shift @files) {
4767 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4768 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4770 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4774 "<td class=\"link\">" .
4775 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4777 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4781 %co = parse_commit
($1);
4789 if ($searchtype eq 'grep') {
4790 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4791 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4793 print "<table cellspacing=\"0\">\n";
4797 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
4799 while (my $line = <$fd>) {
4801 my ($file, $lno, $ltext, $binary);
4802 last if ($matches++ > 1000);
4803 if ($line =~ /^Binary file (.+) matches$/) {
4807 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
4809 if ($file ne $lastfile) {
4810 $lastfile and print "</td></tr>\n";
4812 print "<tr class=\"dark\">\n";
4814 print "<tr class=\"light\">\n";
4816 print "<td class=\"list\">".
4817 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
4818 file_name
=>"$file"),
4819 -class => "list"}, esc_path
($file));
4820 print "</td><td>\n";
4824 print "<div class=\"binary\">Binary file</div>\n";
4826 $ltext = untabify
($ltext);
4827 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
4828 $ltext = esc_html
($1, -nbsp
=>1);
4829 $ltext .= '<span class="match">';
4830 $ltext .= esc_html
($2, -nbsp
=>1);
4831 $ltext .= '</span>';
4832 $ltext .= esc_html
($3, -nbsp
=>1);
4834 $ltext = esc_html
($ltext, -nbsp
=>1);
4836 print "<div class=\"pre\">" .
4837 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
4838 file_name
=>"$file").'#l'.$lno,
4839 -class => "linenr"}, sprintf('%4i', $lno))
4840 . ' ' . $ltext . "</div>\n";
4844 print "</td></tr>\n";
4845 if ($matches > 1000) {
4846 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
4849 print "<div class=\"diff nodifferences\">No matches found</div>\n";
4858 sub git_search_help
{
4860 git_print_page_nav
('','', $hash,$hash,$hash);
4863 <dt><b>commit</b></dt>
4864 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4866 my ($have_grep) = gitweb_check_feature
('grep');
4869 <dt><b>grep</b></dt>
4870 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
4871 a different one) are searched for the given
4872 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
4873 (POSIX extended) and the matches are listed. On large
4874 trees, this search can take a while and put some strain on the server, so please use it with
4875 some consideration.</dd>
4879 <dt><b>author</b></dt>
4880 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4881 <dt><b>committer</b></dt>
4882 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4884 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4885 if ($have_pickaxe) {
4887 <dt><b>pickaxe</b></dt>
4888 <dd>All commits that caused the string to appear or disappear from any file (changes that
4889 added, removed or "modified" the string) will be listed. This search can take a while and
4890 takes a lot of strain on the server, so please use it wisely.</dd>
4898 my $head = git_get_head_hash
($project);
4899 if (!defined $hash) {
4902 if (!defined $page) {
4905 my $refs = git_get_references
();
4907 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4909 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
4911 if ($#commitlist >= 100) {
4913 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4914 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4918 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4919 git_print_header_div
('summary', $project);
4921 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
4926 ## ......................................................................
4927 ## feeds (RSS, Atom; OPML)
4930 my $format = shift || 'atom';
4931 my ($have_blame) = gitweb_check_feature
('blame');
4933 # Atom: http://www.atomenabled.org/developers/syndication/
4934 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4935 if ($format ne 'rss' && $format ne 'atom') {
4936 die_error
(undef, "Unknown web feed format");
4939 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4940 my $head = $hash || 'HEAD';
4941 my @commitlist = parse_commits
($head, 150);
4945 my $content_type = "application/$format+xml";
4946 if (defined $cgi->http('HTTP_ACCEPT') &&
4947 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4948 # browser (feed reader) prefers text/xml
4949 $content_type = 'text/xml';
4951 if (defined($commitlist[0])) {
4952 %latest_commit = %{$commitlist[0]};
4953 %latest_date = parse_date
($latest_commit{'author_epoch'});
4955 -type
=> $content_type,
4956 -charset
=> 'utf-8',
4957 -last_modified
=> $latest_date{'rfc2822'});
4960 -type
=> $content_type,
4961 -charset
=> 'utf-8');
4964 # Optimization: skip generating the body if client asks only
4965 # for Last-Modified date.
4966 return if ($cgi->request_method() eq 'HEAD');
4969 my $title = "$site_name - $project/$action";
4970 my $feed_type = 'log';
4971 if (defined $hash) {
4972 $title .= " - '$hash'";
4973 $feed_type = 'branch log';
4974 if (defined $file_name) {
4975 $title .= " :: $file_name";
4976 $feed_type = 'history';
4978 } elsif (defined $file_name) {
4979 $title .= " - $file_name";
4980 $feed_type = 'history';
4982 $title .= " $feed_type";
4983 my $descr = git_get_project_description
($project);
4984 if (defined $descr) {
4985 $descr = esc_html
($descr);
4987 $descr = "$project " .
4988 ($format eq 'rss' ? 'RSS' : 'Atom') .
4991 my $owner = git_get_project_owner
($project);
4992 $owner = esc_html
($owner);
4996 if (defined $file_name) {
4997 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
4998 } elsif (defined $hash) {
4999 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5001 $alt_url = href
(-full
=>1, action
=>"summary");
5003 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5004 if ($format eq 'rss') {
5006 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5009 print "<title>$title</title>\n" .
5010 "<link>$alt_url</link>\n" .
5011 "<description>$descr</description>\n" .
5012 "<language>en</language>\n";
5013 } elsif ($format eq 'atom') {
5015 <feed xmlns="http://www.w3.org/2005/Atom">
5017 print "<title>$title</title>\n" .
5018 "<subtitle>$descr</subtitle>\n" .
5019 '<link rel="alternate" type="text/html" href="' .
5020 $alt_url . '" />' . "\n" .
5021 '<link rel="self" type="' . $content_type . '" href="' .
5022 $cgi->self_url() . '" />' . "\n" .
5023 "<id>" . href
(-full
=>1) . "</id>\n" .
5024 # use project owner for feed author
5025 "<author><name>$owner</name></author>\n";
5026 if (defined $favicon) {
5027 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5029 if (defined $logo_url) {
5030 # not twice as wide as tall: 72 x 27 pixels
5031 print "<logo>" . esc_url
($logo) . "</logo>\n";
5033 if (! %latest_date) {
5034 # dummy date to keep the feed valid until commits trickle in:
5035 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5037 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5042 for (my $i = 0; $i <= $#commitlist; $i++) {
5043 my %co = %{$commitlist[$i]};
5044 my $commit = $co{'id'};
5045 # we read 150, we always show 30 and the ones more recent than 48 hours
5046 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5049 my %cd = parse_date
($co{'author_epoch'});
5051 # get list of changed files
5052 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5053 $co{'parent'} || "--root",
5054 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5056 my @difftree = map { chomp; $_ } <$fd>;
5060 # print element (entry, item)
5061 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5062 if ($format eq 'rss') {
5064 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5065 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5066 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5067 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5068 "<link>$co_url</link>\n" .
5069 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5070 "<content:encoded>" .
5072 } elsif ($format eq 'atom') {
5074 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5075 "<updated>$cd{'iso-8601'}</updated>\n" .
5077 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5078 if ($co{'author_email'}) {
5079 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5081 print "</author>\n" .
5082 # use committer for contributor
5084 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5085 if ($co{'committer_email'}) {
5086 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5088 print "</contributor>\n" .
5089 "<published>$cd{'iso-8601'}</published>\n" .
5090 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5091 "<id>$co_url</id>\n" .
5092 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5093 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5095 my $comment = $co{'comment'};
5097 foreach my $line (@$comment) {
5098 $line = esc_html
($line);
5101 print "</pre><ul>\n";
5102 foreach my $difftree_line (@difftree) {
5103 my %difftree = parse_difftree_raw_line
($difftree_line);
5104 next if !$difftree{'from_id'};
5106 my $file = $difftree{'file'} || $difftree{'to_file'};
5110 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5111 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5112 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5113 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5114 -title
=> "diff"}, 'D');
5116 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5117 file_name
=>$file, hash_base
=>$commit),
5118 -title
=> "blame"}, 'B');
5120 # if this is not a feed of a file history
5121 if (!defined $file_name || $file_name ne $file) {
5122 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5123 file_name
=>$file, hash
=>$commit),
5124 -title
=> "history"}, 'H');
5126 $file = esc_path
($file);
5130 if ($format eq 'rss') {
5131 print "</ul>]]>\n" .
5132 "</content:encoded>\n" .
5134 } elsif ($format eq 'atom') {
5135 print "</ul>\n</div>\n" .
5142 if ($format eq 'rss') {
5143 print "</channel>\n</rss>\n";
5144 } elsif ($format eq 'atom') {
5158 my @list = git_get_projects_list
();
5160 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5162 <?xml version="1.0" encoding="utf-8"?>
5163 <opml version="1.0">
5165 <title>$site_name OPML Export</title>
5168 <outline text="git RSS feeds">
5171 foreach my $pr (@list) {
5173 my $head = git_get_head_hash
($proj{'path'});
5174 if (!defined $head) {
5177 $git_dir = "$projectroot/$proj{'path'}";
5178 my %co = parse_commit
($head);
5183 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5184 my $rss = "$my_url?p=$proj{'path'};a=rss";
5185 my $html = "$my_url?p=$proj{'path'};a=summary";
5186 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";