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;
60 # URI of GIT logo (72x27 size)
61 our $logo = "++GITWEB_LOGO++";
62 # URI of GIT favicon, assumed to be image/png type
63 our $favicon = "++GITWEB_FAVICON++";
65 # URI and label (title) of GIT logo link
66 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
67 #our $logo_label = "git documentation";
68 our $logo_url = "http://git.or.cz/";
69 our $logo_label = "git homepage";
71 # source of projects list
72 our $projects_list = "++GITWEB_LIST++";
74 # default order of projects list
75 # valid values are none, project, descr, owner, and age
76 our $default_projects_order = "project";
78 # show repository only if this file exists
79 # (only effective if this variable evaluates to true)
80 our $export_ok = "++GITWEB_EXPORT_OK++";
82 # only allow viewing of repositories also shown on the overview page
83 our $strict_export = "++GITWEB_STRICT_EXPORT++";
85 # list of git base URLs used for URL to where fetch project from,
86 # i.e. full URL is "$git_base_url/$project"
87 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
89 # default blob_plain mimetype and default charset for text/plain blob
90 our $default_blob_plain_mimetype = 'text/plain';
91 our $default_text_plain_charset = undef;
93 # file to use for guessing MIME types before trying /etc/mime.types
94 # (relative to the current git repository)
95 our $mimetypes_file = undef;
97 # You define site-wide feature defaults here; override them with
98 # $GITWEB_CONFIG as necessary.
101 # 'sub' => feature-sub (subroutine),
102 # 'override' => allow-override (boolean),
103 # 'default' => [ default options...] (array reference)}
105 # if feature is overridable (it means that allow-override has true value),
106 # then feature-sub will be called with default options as parameters;
107 # return value of feature-sub indicates if to enable specified feature
109 # if there is no 'sub' key (no feature-sub), then feature cannot be
112 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
114 # Enable the 'blame' blob view, showing the last commit that modified
115 # each line in the file. This can be very CPU-intensive.
117 # To enable system wide have in $GITWEB_CONFIG
118 # $feature{'blame'}{'default'} = [1];
119 # To have project specific config enable override in $GITWEB_CONFIG
120 # $feature{'blame'}{'override'} = 1;
121 # and in project config gitweb.blame = 0|1;
123 'sub' => \
&feature_blame
,
127 # Enable the 'snapshot' link, providing a compressed tarball of any
128 # tree. This can potentially generate high traffic if you have large
131 # To disable system wide have in $GITWEB_CONFIG
132 # $feature{'snapshot'}{'default'} = [undef];
133 # To have project specific config enable override in $GITWEB_CONFIG
134 # $feature{'snapshot'}{'override'} = 1;
135 # and in project config gitweb.snapshot = none|gzip|bzip2;
137 'sub' => \
&feature_snapshot
,
139 # => [content-encoding, suffix, program]
140 'default' => ['x-gzip', 'gz', 'gzip']},
142 # Enable text search, which will list the commits which match author,
143 # committer or commit text to a given string. Enabled by default.
144 # Project specific override is not supported.
149 # Enable grep search, which will list the files in currently selected
150 # tree containing the given string. Enabled by default. This can be
151 # potentially CPU-intensive, of course.
153 # To enable system wide have in $GITWEB_CONFIG
154 # $feature{'grep'}{'default'} = [1];
155 # To have project specific config enable override in $GITWEB_CONFIG
156 # $feature{'grep'}{'override'} = 1;
157 # and in project config gitweb.grep = 0|1;
162 # Enable the pickaxe search, which will list the commits that modified
163 # a given string in a file. This can be practical and quite faster
164 # alternative to 'blame', but still potentially CPU-intensive.
166 # To enable system wide have in $GITWEB_CONFIG
167 # $feature{'pickaxe'}{'default'} = [1];
168 # To have project specific config enable override in $GITWEB_CONFIG
169 # $feature{'pickaxe'}{'override'} = 1;
170 # and in project config gitweb.pickaxe = 0|1;
172 'sub' => \
&feature_pickaxe
,
176 # Make gitweb use an alternative format of the URLs which can be
177 # more readable and natural-looking: project name is embedded
178 # directly in the path and the query string contains other
179 # auxiliary information. All gitweb installations recognize
180 # URL in either format; this configures in which formats gitweb
183 # To enable system wide have in $GITWEB_CONFIG
184 # $feature{'pathinfo'}{'default'} = [1];
185 # Project specific override is not supported.
187 # Note that you will need to change the default location of CSS,
188 # favicon, logo and possibly other files to an absolute URL. Also,
189 # if gitweb.cgi serves as your indexfile, you will need to force
190 # $my_uri to contain the script name in your $GITWEB_CONFIG.
195 # Make gitweb consider projects in project root subdirectories
196 # to be forks of existing projects. Given project $projname.git,
197 # projects matching $projname/*.git will not be shown in the main
198 # projects list, instead a '+' mark will be added to $projname
199 # there and a 'forks' view will be enabled for the project, listing
200 # all the forks. If project list is taken from a file, forks have
201 # to be listed after the main project.
203 # To enable system wide have in $GITWEB_CONFIG
204 # $feature{'forks'}{'default'} = [1];
205 # Project specific override is not supported.
211 sub gitweb_check_feature
{
213 return unless exists $feature{$name};
214 my ($sub, $override, @defaults) = (
215 $feature{$name}{'sub'},
216 $feature{$name}{'override'},
217 @
{$feature{$name}{'default'}});
218 if (!$override) { return @defaults; }
220 warn "feature $name is not overrideable";
223 return $sub->(@defaults);
227 my ($val) = git_get_project_config
('blame', '--bool');
229 if ($val eq 'true') {
231 } elsif ($val eq 'false') {
238 sub feature_snapshot
{
239 my ($ctype, $suffix, $command) = @_;
241 my ($val) = git_get_project_config
('snapshot');
243 if ($val eq 'gzip') {
244 return ('x-gzip', 'gz', 'gzip');
245 } elsif ($val eq 'bzip2') {
246 return ('x-bzip2', 'bz2', 'bzip2');
247 } elsif ($val eq 'none') {
251 return ($ctype, $suffix, $command);
254 sub gitweb_have_snapshot
{
255 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
256 my $have_snapshot = (defined $ctype && defined $suffix);
258 return $have_snapshot;
262 my ($val) = git_get_project_config
('grep', '--bool');
264 if ($val eq 'true') {
266 } elsif ($val eq 'false') {
273 sub feature_pickaxe
{
274 my ($val) = git_get_project_config
('pickaxe', '--bool');
276 if ($val eq 'true') {
278 } elsif ($val eq 'false') {
285 # checking HEAD file with -e is fragile if the repository was
286 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
288 sub check_head_link
{
290 my $headfile = "$dir/HEAD";
291 return ((-e
$headfile) ||
292 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
295 sub check_export_ok
{
297 return (check_head_link
($dir) &&
298 (!$export_ok || -e
"$dir/$export_ok"));
301 # rename detection options for git-diff and git-diff-tree
302 # - default is '-M', with the cost proportional to
303 # (number of removed files) * (number of new files).
304 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
305 # (number of changed files + number of removed files) * (number of new files)
306 # - even more costly is '-C', '--find-copies-harder' with cost
307 # (number of files in the original tree) * (number of new files)
308 # - one might want to include '-B' option, e.g. '-B', '-M'
309 our @diff_opts = ('-M'); # taken from git_commit
311 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
312 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
314 # version of the core git binary
315 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
317 $projects_list ||= $projectroot;
319 # ======================================================================
320 # input validation and dispatch
321 our $action = $cgi->param('a');
322 if (defined $action) {
323 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
324 die_error
(undef, "Invalid action parameter");
328 # parameters which are pathnames
329 our $project = $cgi->param('p');
330 if (defined $project) {
331 if (!validate_pathname
($project) ||
332 !(-d
"$projectroot/$project") ||
333 !check_head_link
("$projectroot/$project") ||
334 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
335 ($strict_export && !project_in_list
($project))) {
337 die_error
(undef, "No such project");
341 our $file_name = $cgi->param('f');
342 if (defined $file_name) {
343 if (!validate_pathname
($file_name)) {
344 die_error
(undef, "Invalid file parameter");
348 our $file_parent = $cgi->param('fp');
349 if (defined $file_parent) {
350 if (!validate_pathname
($file_parent)) {
351 die_error
(undef, "Invalid file parent parameter");
355 # parameters which are refnames
356 our $hash = $cgi->param('h');
358 if (!validate_refname
($hash)) {
359 die_error
(undef, "Invalid hash parameter");
363 our $hash_parent = $cgi->param('hp');
364 if (defined $hash_parent) {
365 if (!validate_refname
($hash_parent)) {
366 die_error
(undef, "Invalid hash parent parameter");
370 our $hash_base = $cgi->param('hb');
371 if (defined $hash_base) {
372 if (!validate_refname
($hash_base)) {
373 die_error
(undef, "Invalid hash base parameter");
377 our $hash_parent_base = $cgi->param('hpb');
378 if (defined $hash_parent_base) {
379 if (!validate_refname
($hash_parent_base)) {
380 die_error
(undef, "Invalid hash parent base parameter");
385 our $page = $cgi->param('pg');
387 if ($page =~ m/[^0-9]/) {
388 die_error
(undef, "Invalid page parameter");
392 our $searchtype = $cgi->param('st');
393 if (defined $searchtype) {
394 if ($searchtype =~ m/[^a-z]/) {
395 die_error
(undef, "Invalid searchtype parameter");
399 our $searchtext = $cgi->param('s');
401 if (defined $searchtext) {
402 if ($searchtype ne 'grep' and $searchtype ne 'pickaxe' and $searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
403 die_error
(undef, "Invalid search parameter");
405 if (length($searchtext) < 2) {
406 die_error
(undef, "At least two characters are required for search parameter");
408 $search_regexp = quotemeta $searchtext;
411 # now read PATH_INFO and use it as alternative to parameters
412 sub evaluate_path_info
{
413 return if defined $project;
414 my $path_info = $ENV{"PATH_INFO"};
415 return if !$path_info;
416 $path_info =~ s
,^/+,,;
417 return if !$path_info;
418 # find which part of PATH_INFO is project
419 $project = $path_info;
421 while ($project && !check_head_link
("$projectroot/$project")) {
422 $project =~ s
,/*[^/]*$,,;
425 $project = validate_pathname
($project);
427 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
428 ($strict_export && !project_in_list
($project))) {
432 # do not change any parameters if an action is given using the query string
434 $path_info =~ s
,^$project/*,,;
435 my ($refname, $pathname) = split(/:/, $path_info, 2);
436 if (defined $pathname) {
437 # we got "project.git/branch:filename" or "project.git/branch:dir/"
438 # we could use git_get_type(branch:pathname), but it needs $git_dir
439 $pathname =~ s
,^/+,,;
440 if (!$pathname || substr($pathname, -1) eq "/") {
444 $action ||= "blob_plain";
446 $hash_base ||= validate_refname
($refname);
447 $file_name ||= validate_pathname
($pathname);
448 } elsif (defined $refname) {
449 # we got "project.git/branch"
450 $action ||= "shortlog";
451 $hash ||= validate_refname
($refname);
454 evaluate_path_info
();
456 # path to the current git repository
458 $git_dir = "$projectroot/$project" if $project;
462 "blame" => \
&git_blame2
,
463 "blobdiff" => \
&git_blobdiff
,
464 "blobdiff_plain" => \
&git_blobdiff_plain
,
465 "blob" => \
&git_blob
,
466 "blob_plain" => \
&git_blob_plain
,
467 "commitdiff" => \
&git_commitdiff
,
468 "commitdiff_plain" => \
&git_commitdiff_plain
,
469 "commit" => \
&git_commit
,
470 "forks" => \
&git_forks
,
471 "heads" => \
&git_heads
,
472 "history" => \
&git_history
,
475 "atom" => \
&git_atom
,
476 "search" => \
&git_search
,
477 "search_help" => \
&git_search_help
,
478 "shortlog" => \
&git_shortlog
,
479 "summary" => \
&git_summary
,
481 "tags" => \
&git_tags
,
482 "tree" => \
&git_tree
,
483 "snapshot" => \
&git_snapshot
,
484 "object" => \
&git_object
,
485 # those below don't need $project
486 "opml" => \
&git_opml
,
487 "project_list" => \
&git_project_list
,
488 "project_index" => \
&git_project_index
,
491 if (!defined $action) {
493 $action = git_get_type
($hash);
494 } elsif (defined $hash_base && defined $file_name) {
495 $action = git_get_type
("$hash_base:$file_name");
496 } elsif (defined $project) {
499 $action = 'project_list';
502 if (!defined($actions{$action})) {
503 die_error
(undef, "Unknown action");
505 if ($action !~ m/^(opml|project_list|project_index)$/ &&
507 die_error
(undef, "Project needed");
509 $actions{$action}->();
512 ## ======================================================================
517 # default is to use -absolute url() i.e. $my_uri
518 my $href = $params{-full
} ?
$my_url : $my_uri;
520 # XXX: Warning: If you touch this, check the search form for updating,
531 hash_parent_base
=> "hpb",
537 my %mapping = @mapping;
539 $params{'project'} = $project unless exists $params{'project'};
541 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
543 # use PATH_INFO for project name
544 $href .= "/$params{'project'}" if defined $params{'project'};
545 delete $params{'project'};
547 # Summary just uses the project path URL
548 if (defined $params{'action'} && $params{'action'} eq 'summary') {
549 delete $params{'action'};
553 # now encode the parameters explicitly
555 for (my $i = 0; $i < @mapping; $i += 2) {
556 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
557 if (defined $params{$name}) {
558 push @result, $symbol . "=" . esc_param
($params{$name});
561 $href .= "?" . join(';', @result) if scalar @result;
567 ## ======================================================================
568 ## validation, quoting/unquoting and escaping
570 sub validate_pathname
{
571 my $input = shift || return undef;
573 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
574 # at the beginning, at the end, and between slashes.
575 # also this catches doubled slashes
576 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
580 if ($input =~ m!\0!) {
586 sub validate_refname
{
587 my $input = shift || return undef;
589 # textual hashes are O.K.
590 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
593 # it must be correct pathname
594 $input = validate_pathname
($input)
596 # restrictions on ref name according to git-check-ref-format
597 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
603 # quote unsafe chars, but keep the slash, even when it's not
604 # correct, but quoted slashes look too horrible in bookmarks
607 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
613 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
616 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
622 # replace invalid utf8 character with SUBSTITUTION sequence
627 $str = decode_utf8
($str);
628 $str = $cgi->escapeHTML($str);
629 if ($opts{'-nbsp'}) {
630 $str =~ s/ / /g;
632 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
636 # quote control characters and escape filename to HTML
641 $str = decode_utf8
($str);
642 $str = $cgi->escapeHTML($str);
643 if ($opts{'-nbsp'}) {
644 $str =~ s/ / /g;
646 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
650 # Make control characters "printable", using character escape codes (CEC)
653 my %es = ( # character escape codes, aka escape sequences
654 "\t" => '\t', # tab (HT)
655 "\n" => '\n', # line feed (LF)
656 "\r" => '\r', # carrige return (CR)
657 "\f" => '\f', # form feed (FF)
658 "\b" => '\b', # backspace (BS)
659 "\a" => '\a', # alarm (bell) (BEL)
660 "\e" => '\e', # escape (ESC)
661 "\013" => '\v', # vertical tab (VT)
662 "\000" => '\0', # nul character (NUL)
664 my $chr = ( (exists $es{$cntrl})
666 : sprintf('\%03o', ord($cntrl)) );
667 return "<span class=\"cntrl\">$chr</span>";
670 # Alternatively use unicode control pictures codepoints,
671 # Unicode "printable representation" (PR)
674 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
675 return "<span class=\"cntrl\">$chr</span>";
678 # git may return quoted and escaped filenames
684 my %es = ( # character escape codes, aka escape sequences
685 't' => "\t", # tab (HT, TAB)
686 'n' => "\n", # newline (NL)
687 'r' => "\r", # return (CR)
688 'f' => "\f", # form feed (FF)
689 'b' => "\b", # backspace (BS)
690 'a' => "\a", # alarm (bell) (BEL)
691 'e' => "\e", # escape (ESC)
692 'v' => "\013", # vertical tab (VT)
695 if ($seq =~ m/^[0-7]{1,3}$/) {
696 # octal char sequence
697 return chr(oct($seq));
698 } elsif (exists $es{$seq}) {
699 # C escape sequence, aka character escape code
702 # quoted ordinary character
706 if ($str =~ m/^"(.*)"$/) {
709 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
714 # escape tabs (convert tabs to spaces)
718 while ((my $pos = index($line, "\t")) != -1) {
719 if (my $count = (8 - ($pos % 8))) {
720 my $spaces = ' ' x
$count;
721 $line =~ s/\t/$spaces/;
728 sub project_in_list
{
730 my @list = git_get_projects_list
();
731 return @list && scalar(grep { $_->{'path'} eq $project } @list);
734 ## ----------------------------------------------------------------------
735 ## HTML aware string manipulation
740 my $add_len = shift || 10;
742 # allow only $len chars, but don't cut a word if it would fit in $add_len
743 # if it doesn't fit, cut it if it's still longer than the dots we would add
744 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
747 if (length($tail) > 4) {
749 $body =~ s/&[^;]*$//; # remove chopped character entities
754 ## ----------------------------------------------------------------------
755 ## functions returning short strings
757 # CSS class for given age value (in seconds)
763 } elsif ($age < 60*60*2) {
765 } elsif ($age < 60*60*24*2) {
772 # convert age in seconds to "nn units ago" string
777 if ($age > 60*60*24*365*2) {
778 $age_str = (int $age/60/60/24/365);
779 $age_str .= " years ago";
780 } elsif ($age > 60*60*24*(365/12)*2) {
781 $age_str = int $age/60/60/24/(365/12);
782 $age_str .= " months ago";
783 } elsif ($age > 60*60*24*7*2) {
784 $age_str = int $age/60/60/24/7;
785 $age_str .= " weeks ago";
786 } elsif ($age > 60*60*24*2) {
787 $age_str = int $age/60/60/24;
788 $age_str .= " days ago";
789 } elsif ($age > 60*60*2) {
790 $age_str = int $age/60/60;
791 $age_str .= " hours ago";
792 } elsif ($age > 60*2) {
793 $age_str = int $age/60;
794 $age_str .= " min ago";
797 $age_str .= " sec ago";
799 $age_str .= " right now";
804 # convert file mode in octal to symbolic file mode string
806 my $mode = oct shift;
808 if (S_ISDIR
($mode & S_IFMT
)) {
810 } elsif (S_ISLNK
($mode)) {
812 } elsif (S_ISREG
($mode)) {
813 # git cares only about the executable bit
814 if ($mode & S_IXUSR
) {
824 # convert file mode in octal to file type string
828 if ($mode !~ m/^[0-7]+$/) {
834 if (S_ISDIR
($mode & S_IFMT
)) {
836 } elsif (S_ISLNK
($mode)) {
838 } elsif (S_ISREG
($mode)) {
845 # convert file mode in octal to file type description string
849 if ($mode !~ m/^[0-7]+$/) {
855 if (S_ISDIR
($mode & S_IFMT
)) {
857 } elsif (S_ISLNK
($mode)) {
859 } elsif (S_ISREG
($mode)) {
860 if ($mode & S_IXUSR
) {
871 ## ----------------------------------------------------------------------
872 ## functions returning short HTML fragments, or transforming HTML fragments
873 ## which don't belong to other sections
875 # format line of commit message.
876 sub format_log_line_html
{
879 $line = esc_html
($line, -nbsp
=>1);
880 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
883 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
884 -class => "text"}, $hash_text);
885 $line =~ s/$hash_text/$link/;
890 # format marker of refs pointing to given object
891 sub format_ref_marker
{
892 my ($refs, $id) = @_;
895 if (defined $refs->{$id}) {
896 foreach my $ref (@
{$refs->{$id}}) {
897 my ($type, $name) = qw();
898 # e.g. tags/v2.6.11 or heads/next
899 if ($ref =~ m!^(.*?)s?/(.*)$!) {
907 $markers .= " <span class=\"$type\" title=\"$ref\">" .
908 esc_html
($name) . "</span>";
913 return ' <span class="refs">'. $markers . '</span>';
919 # format, perhaps shortened and with markers, title line
920 sub format_subject_html
{
921 my ($long, $short, $href, $extra) = @_;
922 $extra = '' unless defined($extra);
924 if (length($short) < length($long)) {
925 return $cgi->a({-href
=> $href, -class => "list subject",
926 -title
=> decode_utf8
($long)},
927 esc_html
($short) . $extra);
929 return $cgi->a({-href
=> $href, -class => "list subject"},
930 esc_html
($long) . $extra);
934 # format patch (diff) line (rather not to be used for diff headers)
935 sub format_diff_line
{
937 my ($from, $to) = @_;
942 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
944 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
945 if ($line =~ m/^\@{3}/) {
946 $diff_class = " chunk_header";
947 } elsif ($line =~ m/^\\/) {
948 $diff_class = " incomplete";
949 } elsif ($prefix =~ tr/+/+/) {
950 $diff_class = " add";
951 } elsif ($prefix =~ tr/-/-/) {
952 $diff_class = " rem";
955 # assume ordinary diff
956 my $char = substr($line, 0, 1);
958 $diff_class = " add";
959 } elsif ($char eq '-') {
960 $diff_class = " rem";
961 } elsif ($char eq '@') {
962 $diff_class = " chunk_header";
963 } elsif ($char eq "\\") {
964 $diff_class = " incomplete";
967 $line = untabify
($line);
968 if ($from && $to && $line =~ m/^\@{2} /) {
969 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
970 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
972 $from_lines = 0 unless defined $from_lines;
973 $to_lines = 0 unless defined $to_lines;
975 if ($from->{'href'}) {
976 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
977 -class=>"list"}, $from_text);
980 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
981 -class=>"list"}, $to_text);
983 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
984 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
985 return "<div class=\"diff$diff_class\">$line</div>\n";
986 } elsif ($from && $to && $line =~ m/^\@{3}/) {
987 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
988 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
990 @from_text = split(' ', $ranges);
991 for (my $i = 0; $i < @from_text; ++$i) {
992 ($from_start[$i], $from_nlines[$i]) =
993 (split(',', substr($from_text[$i], 1)), 0);
996 $to_text = pop @from_text;
997 $to_start = pop @from_start;
998 $to_nlines = pop @from_nlines;
1000 $line = "<span class=\"chunk_info\">$prefix ";
1001 for (my $i = 0; $i < @from_text; ++$i) {
1002 if ($from->{'href'}[$i]) {
1003 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1004 -class=>"list"}, $from_text[$i]);
1006 $line .= $from_text[$i];
1010 if ($to->{'href'}) {
1011 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1012 -class=>"list"}, $to_text);
1016 $line .= " $prefix</span>" .
1017 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1018 return "<div class=\"diff$diff_class\">$line</div>\n";
1020 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1023 ## ----------------------------------------------------------------------
1024 ## git utility subroutines, invoking git commands
1026 # returns path to the core git executable and the --git-dir parameter as list
1028 return $GIT, '--git-dir='.$git_dir;
1031 # returns path to the core git executable and the --git-dir parameter as string
1033 return join(' ', git_cmd
());
1036 # get HEAD ref of given project as hash
1037 sub git_get_head_hash
{
1038 my $project = shift;
1039 my $o_git_dir = $git_dir;
1041 $git_dir = "$projectroot/$project";
1042 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1045 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1049 if (defined $o_git_dir) {
1050 $git_dir = $o_git_dir;
1055 # get type of given object
1059 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1061 close $fd or return;
1066 sub git_get_project_config
{
1067 my ($key, $type) = @_;
1069 return unless ($key);
1070 $key =~ s/^gitweb\.//;
1071 return if ($key =~ m/\W/);
1073 my @x = (git_cmd
(), 'config');
1074 if (defined $type) { push @x, $type; }
1076 push @x, "gitweb.$key";
1082 # get hash of given path at given ref
1083 sub git_get_hash_by_path
{
1085 my $path = shift || return undef;
1090 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1091 or die_error
(undef, "Open git-ls-tree failed");
1093 close $fd or return undef;
1095 if (!defined $line) {
1096 # there is no tree or hash given by $path at $base
1100 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1101 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1102 if (defined $type && $type ne $2) {
1103 # type doesn't match
1109 # get path of entry with given hash at given tree-ish (ref)
1110 # used to get 'from' filename for combined diff (merge commit) for renames
1111 sub git_get_path_by_hash
{
1112 my $base = shift || return;
1113 my $hash = shift || return;
1117 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1119 while (my $line = <$fd>) {
1122 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1123 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1124 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1133 ## ......................................................................
1134 ## git utility functions, directly accessing git repository
1136 sub git_get_project_description
{
1139 open my $fd, "$projectroot/$path/description" or return undef;
1142 if (defined $descr) {
1148 sub git_get_project_url_list
{
1151 open my $fd, "$projectroot/$path/cloneurl" or return;
1152 my @git_project_url_list = map { chomp; $_ } <$fd>;
1155 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
1158 sub git_get_projects_list
{
1163 $filter =~ s/\.git$//;
1165 my ($check_forks) = gitweb_check_feature
('forks');
1167 if (-d
$projects_list) {
1168 # search in directory
1169 my $dir = $projects_list . ($filter ?
"/$filter" : '');
1170 # remove the trailing "/"
1172 my $pfxlen = length("$dir");
1175 follow_fast
=> 1, # follow symbolic links
1176 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1178 # skip project-list toplevel, if we get it.
1179 return if (m!^[/.]$!);
1180 # only directories can be git repositories
1181 return unless (-d
$_);
1183 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1184 # we check related file in $projectroot
1185 if ($check_forks and $subdir =~ m
#/.#) {
1186 $File::Find
::prune
= 1;
1187 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1188 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
1189 $File::Find
::prune
= 1;
1194 } elsif (-f
$projects_list) {
1195 # read from file(url-encoded):
1196 # 'git%2Fgit.git Linus+Torvalds'
1197 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1198 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1200 open my ($fd), $projects_list or return;
1202 while (my $line = <$fd>) {
1204 my ($path, $owner) = split ' ', $line;
1205 $path = unescape
($path);
1206 $owner = unescape
($owner);
1207 if (!defined $path) {
1210 if ($filter ne '') {
1211 # looking for forks;
1212 my $pfx = substr($path, 0, length($filter));
1213 if ($pfx ne $filter) {
1216 my $sfx = substr($path, length($filter));
1217 if ($sfx !~ /^\/.*\
.git
$/) {
1220 } elsif ($check_forks) {
1222 foreach my $filter (keys %paths) {
1223 # looking for forks;
1224 my $pfx = substr($path, 0, length($filter));
1225 if ($pfx ne $filter) {
1228 my $sfx = substr($path, length($filter));
1229 if ($sfx !~ /^\/.*\
.git
$/) {
1232 # is a fork, don't include it in
1237 if (check_export_ok
("$projectroot/$path")) {
1240 owner
=> decode_utf8
($owner),
1243 (my $forks_path = $path) =~ s/\.git$//;
1244 $paths{$forks_path}++;
1252 sub git_get_project_owner
{
1253 my $project = shift;
1256 return undef unless $project;
1258 # read from file (url-encoded):
1259 # 'git%2Fgit.git Linus+Torvalds'
1260 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1261 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1262 if (-f
$projects_list) {
1263 open (my $fd , $projects_list);
1264 while (my $line = <$fd>) {
1266 my ($pr, $ow) = split ' ', $line;
1267 $pr = unescape
($pr);
1268 $ow = unescape
($ow);
1269 if ($pr eq $project) {
1270 $owner = decode_utf8
($ow);
1276 if (!defined $owner) {
1277 $owner = get_file_owner
("$projectroot/$project");
1283 sub git_get_last_activity
{
1287 $git_dir = "$projectroot/$path";
1288 open($fd, "-|", git_cmd
(), 'for-each-ref',
1289 '--format=%(committer)',
1290 '--sort=-committerdate',
1292 'refs/heads') or return;
1293 my $most_recent = <$fd>;
1294 close $fd or return;
1295 if (defined $most_recent &&
1296 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1298 my $age = time - $timestamp;
1299 return ($age, age_string
($age));
1303 sub git_get_references
{
1304 my $type = shift || "";
1306 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1307 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1308 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1309 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
1312 while (my $line = <$fd>) {
1314 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1315 if (defined $refs{$1}) {
1316 push @
{$refs{$1}}, $2;
1322 close $fd or return;
1326 sub git_get_rev_name_tags
{
1327 my $hash = shift || return undef;
1329 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1331 my $name_rev = <$fd>;
1334 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1337 # catches also '$hash undefined' output
1342 ## ----------------------------------------------------------------------
1343 ## parse to hash functions
1347 my $tz = shift || "-0000";
1350 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1351 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1352 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1353 $date{'hour'} = $hour;
1354 $date{'minute'} = $min;
1355 $date{'mday'} = $mday;
1356 $date{'day'} = $days[$wday];
1357 $date{'month'} = $months[$mon];
1358 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1359 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1360 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1361 $mday, $months[$mon], $hour ,$min;
1362 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1363 1900+$year, $mon, $mday, $hour ,$min, $sec;
1365 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1366 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1367 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1368 $date{'hour_local'} = $hour;
1369 $date{'minute_local'} = $min;
1370 $date{'tz_local'} = $tz;
1371 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1372 1900+$year, $mon+1, $mday,
1373 $hour, $min, $sec, $tz);
1382 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1383 $tag{'id'} = $tag_id;
1384 while (my $line = <$fd>) {
1386 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1387 $tag{'object'} = $1;
1388 } elsif ($line =~ m/^type (.+)$/) {
1390 } elsif ($line =~ m/^tag (.+)$/) {
1392 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1393 $tag{'author'} = $1;
1396 } elsif ($line =~ m/--BEGIN/) {
1397 push @comment, $line;
1399 } elsif ($line eq "") {
1403 push @comment, <$fd>;
1404 $tag{'comment'} = \
@comment;
1405 close $fd or return;
1406 if (!defined $tag{'name'}) {
1412 sub parse_commit_text
{
1413 my ($commit_text, $withparents) = @_;
1414 my @commit_lines = split '\n', $commit_text;
1417 pop @commit_lines; # Remove '\0'
1419 if (! @commit_lines) {
1423 my $header = shift @commit_lines;
1424 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1427 ($co{'id'}, my @parents) = split ' ', $header;
1428 while (my $line = shift @commit_lines) {
1429 last if $line eq "\n";
1430 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1432 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1434 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1436 $co{'author_epoch'} = $2;
1437 $co{'author_tz'} = $3;
1438 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1439 $co{'author_name'} = $1;
1440 $co{'author_email'} = $2;
1442 $co{'author_name'} = $co{'author'};
1444 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1445 $co{'committer'} = $1;
1446 $co{'committer_epoch'} = $2;
1447 $co{'committer_tz'} = $3;
1448 $co{'committer_name'} = $co{'committer'};
1449 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1450 $co{'committer_name'} = $1;
1451 $co{'committer_email'} = $2;
1453 $co{'committer_name'} = $co{'committer'};
1457 if (!defined $co{'tree'}) {
1460 $co{'parents'} = \
@parents;
1461 $co{'parent'} = $parents[0];
1463 foreach my $title (@commit_lines) {
1466 $co{'title'} = chop_str
($title, 80, 5);
1467 # remove leading stuff of merges to make the interesting part visible
1468 if (length($title) > 50) {
1469 $title =~ s/^Automatic //;
1470 $title =~ s/^merge (of|with) /Merge ... /i;
1471 if (length($title) > 50) {
1472 $title =~ s/(http|rsync):\/\///;
1474 if (length($title) > 50) {
1475 $title =~ s/(master|www|rsync)\.//;
1477 if (length($title) > 50) {
1478 $title =~ s/kernel.org:?//;
1480 if (length($title) > 50) {
1481 $title =~ s/\/pub\/scm//;
1484 $co{'title_short'} = chop_str
($title, 50, 5);
1488 if ($co{'title'} eq "") {
1489 $co{'title'} = $co{'title_short'} = '(no commit message)';
1491 # remove added spaces
1492 foreach my $line (@commit_lines) {
1495 $co{'comment'} = \
@commit_lines;
1497 my $age = time - $co{'committer_epoch'};
1499 $co{'age_string'} = age_string
($age);
1500 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1501 if ($age > 60*60*24*7*2) {
1502 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1503 $co{'age_string_age'} = $co{'age_string'};
1505 $co{'age_string_date'} = $co{'age_string'};
1506 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1512 my ($commit_id) = @_;
1517 open my $fd, "-|", git_cmd
(), "rev-list",
1523 or die_error
(undef, "Open git-rev-list failed");
1524 %co = parse_commit_text
(<$fd>, 1);
1531 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1539 open my $fd, "-|", git_cmd
(), "rev-list",
1541 ($arg ?
($arg) : ()),
1542 ("--max-count=" . $maxcount),
1543 ("--skip=" . $skip),
1546 ($filename ?
($filename) : ())
1547 or die_error
(undef, "Open git-rev-list failed");
1548 while (my $line = <$fd>) {
1549 my %co = parse_commit_text
($line);
1554 return wantarray ?
@cos : \
@cos;
1557 # parse ref from ref_file, given by ref_id, with given type
1559 my $ref_file = shift;
1561 my $type = shift || git_get_type
($ref_id);
1564 $ref_item{'type'} = $type;
1565 $ref_item{'id'} = $ref_id;
1566 $ref_item{'epoch'} = 0;
1567 $ref_item{'age'} = "unknown";
1568 if ($type eq "tag") {
1569 my %tag = parse_tag
($ref_id);
1570 $ref_item{'comment'} = $tag{'comment'};
1571 if ($tag{'type'} eq "commit") {
1572 my %co = parse_commit
($tag{'object'});
1573 $ref_item{'epoch'} = $co{'committer_epoch'};
1574 $ref_item{'age'} = $co{'age_string'};
1575 } elsif (defined($tag{'epoch'})) {
1576 my $age = time - $tag{'epoch'};
1577 $ref_item{'epoch'} = $tag{'epoch'};
1578 $ref_item{'age'} = age_string
($age);
1580 $ref_item{'reftype'} = $tag{'type'};
1581 $ref_item{'name'} = $tag{'name'};
1582 $ref_item{'refid'} = $tag{'object'};
1583 } elsif ($type eq "commit"){
1584 my %co = parse_commit
($ref_id);
1585 $ref_item{'reftype'} = "commit";
1586 $ref_item{'name'} = $ref_file;
1587 $ref_item{'title'} = $co{'title'};
1588 $ref_item{'refid'} = $ref_id;
1589 $ref_item{'epoch'} = $co{'committer_epoch'};
1590 $ref_item{'age'} = $co{'age_string'};
1592 $ref_item{'reftype'} = $type;
1593 $ref_item{'name'} = $ref_file;
1594 $ref_item{'refid'} = $ref_id;
1600 # parse line of git-diff-tree "raw" output
1601 sub parse_difftree_raw_line
{
1605 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1606 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1607 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1608 $res{'from_mode'} = $1;
1609 $res{'to_mode'} = $2;
1610 $res{'from_id'} = $3;
1612 $res{'status'} = $5;
1613 $res{'similarity'} = $6;
1614 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1615 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1617 $res{'file'} = unquote
($7);
1620 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1621 # combined diff (for merge commit)
1622 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1623 $res{'nparents'} = length($1);
1624 $res{'from_mode'} = [ split(' ', $2) ];
1625 $res{'to_mode'} = pop @
{$res{'from_mode'}};
1626 $res{'from_id'} = [ split(' ', $3) ];
1627 $res{'to_id'} = pop @
{$res{'from_id'}};
1628 $res{'status'} = [ split('', $4) ];
1629 $res{'to_file'} = unquote
($5);
1631 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1632 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1633 $res{'commit'} = $1;
1636 return wantarray ?
%res : \
%res;
1639 # parse line of git-ls-tree output
1640 sub parse_ls_tree_line
($;%) {
1645 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1646 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1654 $res{'name'} = unquote
($4);
1657 return wantarray ?
%res : \
%res;
1660 ## ......................................................................
1661 ## parse to array of hashes functions
1663 sub git_get_heads_list
{
1667 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1668 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
1669 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1672 while (my $line = <$fd>) {
1676 my ($refinfo, $committerinfo) = split(/\0/, $line);
1677 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1678 my ($committer, $epoch, $tz) =
1679 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1680 $name =~ s!^refs/heads/!!;
1682 $ref_item{'name'} = $name;
1683 $ref_item{'id'} = $hash;
1684 $ref_item{'title'} = $title || '(no commit message)';
1685 $ref_item{'epoch'} = $epoch;
1687 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1689 $ref_item{'age'} = "unknown";
1692 push @headslist, \
%ref_item;
1696 return wantarray ?
@headslist : \
@headslist;
1699 sub git_get_tags_list
{
1703 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1704 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
1705 '--format=%(objectname) %(objecttype) %(refname) '.
1706 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1709 while (my $line = <$fd>) {
1713 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1714 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1715 my ($creator, $epoch, $tz) =
1716 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1717 $name =~ s!^refs/tags/!!;
1719 $ref_item{'type'} = $type;
1720 $ref_item{'id'} = $id;
1721 $ref_item{'name'} = $name;
1722 if ($type eq "tag") {
1723 $ref_item{'subject'} = $title;
1724 $ref_item{'reftype'} = $reftype;
1725 $ref_item{'refid'} = $refid;
1727 $ref_item{'reftype'} = $type;
1728 $ref_item{'refid'} = $id;
1731 if ($type eq "tag" || $type eq "commit") {
1732 $ref_item{'epoch'} = $epoch;
1734 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1736 $ref_item{'age'} = "unknown";
1740 push @tagslist, \
%ref_item;
1744 return wantarray ?
@tagslist : \
@tagslist;
1747 ## ----------------------------------------------------------------------
1748 ## filesystem-related functions
1750 sub get_file_owner
{
1753 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1754 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1755 if (!defined $gcos) {
1759 $owner =~ s/[,;].*$//;
1760 return decode_utf8
($owner);
1763 ## ......................................................................
1764 ## mimetype related functions
1766 sub mimetype_guess_file
{
1767 my $filename = shift;
1768 my $mimemap = shift;
1769 -r
$mimemap or return undef;
1772 open(MIME
, $mimemap) or return undef;
1774 next if m/^#/; # skip comments
1775 my ($mime, $exts) = split(/\t+/);
1776 if (defined $exts) {
1777 my @exts = split(/\s+/, $exts);
1778 foreach my $ext (@exts) {
1779 $mimemap{$ext} = $mime;
1785 $filename =~ /\.([^.]*)$/;
1786 return $mimemap{$1};
1789 sub mimetype_guess
{
1790 my $filename = shift;
1792 $filename =~ /\./ or return undef;
1794 if ($mimetypes_file) {
1795 my $file = $mimetypes_file;
1796 if ($file !~ m!^/!) { # if it is relative path
1797 # it is relative to project
1798 $file = "$projectroot/$project/$file";
1800 $mime = mimetype_guess_file
($filename, $file);
1802 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1808 my $filename = shift;
1811 my $mime = mimetype_guess
($filename);
1812 $mime and return $mime;
1816 return $default_blob_plain_mimetype unless $fd;
1819 return 'text/plain' .
1820 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1821 } elsif (! $filename) {
1822 return 'application/octet-stream';
1823 } elsif ($filename =~ m/\.png$/i) {
1825 } elsif ($filename =~ m/\.gif$/i) {
1827 } elsif ($filename =~ m/\.jpe?g$/i) {
1828 return 'image/jpeg';
1830 return 'application/octet-stream';
1834 ## ======================================================================
1835 ## functions printing HTML: header, footer, error page
1837 sub git_header_html
{
1838 my $status = shift || "200 OK";
1839 my $expires = shift;
1841 my $title = "$site_name";
1842 if (defined $project) {
1843 $title .= " - " . decode_utf8
($project);
1844 if (defined $action) {
1845 $title .= "/$action";
1846 if (defined $file_name) {
1847 $title .= " - " . esc_path
($file_name);
1848 if ($action eq "tree" && $file_name !~ m
|/$|) {
1855 # require explicit support from the UA if we are to send the page as
1856 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1857 # we have to do this because MSIE sometimes globs '*/*', pretending to
1858 # support xhtml+xml but choking when it gets what it asked for.
1859 if (defined $cgi->http('HTTP_ACCEPT') &&
1860 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1861 $cgi->Accept('application/xhtml+xml') != 0) {
1862 $content_type = 'application/xhtml+xml';
1864 $content_type = 'text/html';
1866 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1867 -status
=> $status, -expires
=> $expires);
1868 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
1870 <?xml version="1.0" encoding="utf-8"?>
1871 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1872 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1873 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1874 <!-- git core binaries version $git_version -->
1876 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1877 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
1878 <meta name="robots" content="index, nofollow"/>
1879 <title>$title</title>
1881 # print out each stylesheet that exist
1882 if (defined $stylesheet) {
1883 #provides backwards capability for those people who define style sheet in a config file
1884 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1886 foreach my $stylesheet (@stylesheets) {
1887 next unless $stylesheet;
1888 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1891 if (defined $project) {
1892 printf('<link rel="alternate" title="%s log RSS feed" '.
1893 'href="%s" type="application/rss+xml" />'."\n",
1894 esc_param
($project), href
(action
=>"rss"));
1895 printf('<link rel="alternate" title="%s log Atom feed" '.
1896 'href="%s" type="application/atom+xml" />'."\n",
1897 esc_param
($project), href
(action
=>"atom"));
1899 printf('<link rel="alternate" title="%s projects list" '.
1900 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1901 $site_name, href
(project
=>undef, action
=>"project_index"));
1902 printf('<link rel="alternate" title="%s projects feeds" '.
1903 'href="%s" type="text/x-opml"/>'."\n",
1904 $site_name, href
(project
=>undef, action
=>"opml"));
1906 if (defined $favicon) {
1907 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
1913 if (-f
$site_header) {
1914 open (my $fd, $site_header);
1919 print "<div class=\"page_header\">\n" .
1920 $cgi->a({-href
=> esc_url
($logo_url),
1921 -title
=> $logo_label},
1922 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
1923 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1924 if (defined $project) {
1925 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1926 if (defined $action) {
1933 my ($have_search) = gitweb_check_feature
('search');
1934 if ((defined $project) && ($have_search)) {
1935 if (!defined $searchtext) {
1939 if (defined $hash_base) {
1940 $search_hash = $hash_base;
1941 } elsif (defined $hash) {
1942 $search_hash = $hash;
1944 $search_hash = "HEAD";
1946 $cgi->param("a", "search");
1947 $cgi->param("h", $search_hash);
1948 $cgi->param("p", $project);
1949 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1950 "<div class=\"search\">\n" .
1951 $cgi->hidden(-name
=> "p") . "\n" .
1952 $cgi->hidden(-name
=> "a") . "\n" .
1953 $cgi->hidden(-name
=> "h") . "\n" .
1954 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1955 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
1956 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1958 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1960 $cgi->end_form() . "\n";
1964 sub git_footer_html
{
1965 print "<div class=\"page_footer\">\n";
1966 if (defined $project) {
1967 my $descr = git_get_project_description
($project);
1968 if (defined $descr) {
1969 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1971 print $cgi->a({-href
=> href
(action
=>"rss"),
1972 -class => "rss_logo"}, "RSS") . " ";
1973 print $cgi->a({-href
=> href
(action
=>"atom"),
1974 -class => "rss_logo"}, "Atom") . "\n";
1976 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1977 -class => "rss_logo"}, "OPML") . " ";
1978 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1979 -class => "rss_logo"}, "TXT") . "\n";
1983 if (-f
$site_footer) {
1984 open (my $fd, $site_footer);
1994 my $status = shift || "403 Forbidden";
1995 my $error = shift || "Malformed query, file missing or permission denied";
1997 git_header_html
($status);
1999 <div class="page_body">
2009 ## ----------------------------------------------------------------------
2010 ## functions printing or outputting HTML: navigation
2012 sub git_print_page_nav
{
2013 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2014 $extra = '' if !defined $extra; # pager or formats
2016 my @navs = qw(summary shortlog log commit commitdiff tree);
2018 @navs = grep { $_ ne $suppress } @navs;
2021 my %arg = map { $_ => {action
=>$_} } @navs;
2022 if (defined $head) {
2023 for (qw(commit commitdiff)) {
2024 $arg{$_}{'hash'} = $head;
2026 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2027 for (qw(shortlog log)) {
2028 $arg{$_}{'hash'} = $head;
2032 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2033 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2035 print "<div class=\"page_nav\">\n" .
2037 map { $_ eq $current ?
2038 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2040 print "<br/>\n$extra<br/>\n" .
2044 sub format_paging_nav
{
2045 my ($action, $hash, $head, $page, $nrevs) = @_;
2049 if ($hash ne $head || $page) {
2050 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2052 $paging_nav .= "HEAD";
2056 $paging_nav .= " ⋅ " .
2057 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2058 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2060 $paging_nav .= " ⋅ prev";
2063 if ($nrevs >= (100 * ($page+1)-1)) {
2064 $paging_nav .= " ⋅ " .
2065 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2066 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2068 $paging_nav .= " ⋅ next";
2074 ## ......................................................................
2075 ## functions printing or outputting HTML: div
2077 sub git_print_header_div
{
2078 my ($action, $title, $hash, $hash_base) = @_;
2081 $args{'action'} = $action;
2082 $args{'hash'} = $hash if $hash;
2083 $args{'hash_base'} = $hash_base if $hash_base;
2085 print "<div class=\"header\">\n" .
2086 $cgi->a({-href
=> href
(%args), -class => "title"},
2087 $title ?
$title : $action) .
2091 #sub git_print_authorship (\%) {
2092 sub git_print_authorship
{
2095 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2096 print "<div class=\"author_date\">" .
2097 esc_html
($co->{'author_name'}) .
2099 if ($ad{'hour_local'} < 6) {
2100 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2101 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2103 printf(" (%02d:%02d %s)",
2104 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2109 sub git_print_page_path
{
2115 print "<div class=\"page_path\">";
2116 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2117 -title
=> 'tree root'}, decode_utf8
("[$project]"));
2119 if (defined $name) {
2120 my @dirname = split '/', $name;
2121 my $basename = pop @dirname;
2124 foreach my $dir (@dirname) {
2125 $fullname .= ($fullname ?
'/' : '') . $dir;
2126 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2128 -title
=> $fullname}, esc_path
($dir));
2131 if (defined $type && $type eq 'blob') {
2132 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2134 -title
=> $name}, esc_path
($basename));
2135 } elsif (defined $type && $type eq 'tree') {
2136 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2138 -title
=> $name}, esc_path
($basename));
2141 print esc_path
($basename);
2144 print "<br/></div>\n";
2147 # sub git_print_log (\@;%) {
2148 sub git_print_log
($;%) {
2152 if ($opts{'-remove_title'}) {
2153 # remove title, i.e. first line of log
2156 # remove leading empty lines
2157 while (defined $log->[0] && $log->[0] eq "") {
2164 foreach my $line (@
$log) {
2165 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2168 if (! $opts{'-remove_signoff'}) {
2169 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2172 # remove signoff lines
2179 # print only one empty line
2180 # do not print empty line after signoff
2182 next if ($empty || $signoff);
2188 print format_log_line_html
($line) . "<br/>\n";
2191 if ($opts{'-final_empty_line'}) {
2192 # end with single empty line
2193 print "<br/>\n" unless $empty;
2197 # return link target (what link points to)
2198 sub git_get_link_target
{
2203 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2207 $link_target = <$fd>;
2212 return $link_target;
2215 # given link target, and the directory (basedir) the link is in,
2216 # return target of link relative to top directory (top tree);
2217 # return undef if it is not possible (including absolute links).
2218 sub normalize_link_target
{
2219 my ($link_target, $basedir, $hash_base) = @_;
2221 # we can normalize symlink target only if $hash_base is provided
2222 return unless $hash_base;
2224 # absolute symlinks (beginning with '/') cannot be normalized
2225 return if (substr($link_target, 0, 1) eq '/');
2227 # normalize link target to path from top (root) tree (dir)
2230 $path = $basedir . '/' . $link_target;
2232 # we are in top (root) tree (dir)
2233 $path = $link_target;
2236 # remove //, /./, and /../
2238 foreach my $part (split('/', $path)) {
2239 # discard '.' and ''
2240 next if (!$part || $part eq '.');
2242 if ($part eq '..') {
2246 # link leads outside repository (outside top dir)
2250 push @path_parts, $part;
2253 $path = join('/', @path_parts);
2258 # print tree entry (row of git_tree), but without encompassing <tr> element
2259 sub git_print_tree_entry
{
2260 my ($t, $basedir, $hash_base, $have_blame) = @_;
2263 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2265 # The format of a table row is: mode list link. Where mode is
2266 # the mode of the entry, list is the name of the entry, an href,
2267 # and link is the action links of the entry.
2269 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2270 if ($t->{'type'} eq "blob") {
2271 print "<td class=\"list\">" .
2272 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2273 file_name
=>"$basedir$t->{'name'}", %base_key),
2274 -class => "list"}, esc_path
($t->{'name'}));
2275 if (S_ISLNK
(oct $t->{'mode'})) {
2276 my $link_target = git_get_link_target
($t->{'hash'});
2278 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2279 if (defined $norm_target) {
2281 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2282 file_name
=>$norm_target),
2283 -title
=> $norm_target}, esc_path
($link_target));
2285 print " -> " . esc_path
($link_target);
2290 print "<td class=\"link\">";
2291 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2292 file_name
=>"$basedir$t->{'name'}", %base_key)},
2296 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2297 file_name
=>"$basedir$t->{'name'}", %base_key)},
2300 if (defined $hash_base) {
2302 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2303 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2307 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2308 file_name
=>"$basedir$t->{'name'}")},
2312 } elsif ($t->{'type'} eq "tree") {
2313 print "<td class=\"list\">";
2314 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2315 file_name
=>"$basedir$t->{'name'}", %base_key)},
2316 esc_path
($t->{'name'}));
2318 print "<td class=\"link\">";
2319 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2320 file_name
=>"$basedir$t->{'name'}", %base_key)},
2322 if (defined $hash_base) {
2324 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2325 file_name
=>"$basedir$t->{'name'}")},
2332 ## ......................................................................
2333 ## functions printing large fragments of HTML
2335 sub fill_from_file_info
{
2336 my ($diff, @parents) = @_;
2338 $diff->{'from_file'} = [ ];
2339 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2340 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2341 if ($diff->{'status'}[$i] eq 'R' ||
2342 $diff->{'status'}[$i] eq 'C') {
2343 $diff->{'from_file'}[$i] =
2344 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2351 # parameters can be strings, or references to arrays of strings
2355 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @
$a == @
$b) {
2356 for (my $i = 0; $i < @
$a; ++$i) {
2357 return 0 unless ($a->[$i] eq $b->[$i]);
2360 } elsif (!ref($a) && !ref($b)) {
2368 sub git_difftree_body
{
2369 my ($difftree, $hash, @parents) = @_;
2370 my ($parent) = $parents[0];
2371 my ($have_blame) = gitweb_check_feature
('blame');
2372 print "<div class=\"list_head\">\n";
2373 if ($#{$difftree} > 10) {
2374 print(($#{$difftree} + 1) . " files changed:\n");
2378 print "<table class=\"" .
2379 (@parents > 1 ?
"combined " : "") .
2383 foreach my $line (@
{$difftree}) {
2385 if (ref($line) eq "HASH") {
2386 # pre-parsed (or generated by hand)
2389 $diff = parse_difftree_raw_line
($line);
2393 print "<tr class=\"dark\">\n";
2395 print "<tr class=\"light\">\n";
2399 if (exists $diff->{'nparents'}) { # combined diff
2401 fill_from_file_info
($diff, @parents)
2402 unless exists $diff->{'from_file'};
2404 if ($diff->{'to_id'} ne ('0' x
40)) {
2405 # file exists in the result (child) commit
2407 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2408 file_name
=>$diff->{'to_file'},
2410 -class => "list"}, esc_path
($diff->{'to_file'})) .
2414 esc_path
($diff->{'to_file'}) .
2418 if ($action eq 'commitdiff') {
2421 print "<td class=\"link\">" .
2422 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2427 my $has_history = 0;
2428 my $not_deleted = 0;
2429 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2430 my $hash_parent = $parents[$i];
2431 my $from_hash = $diff->{'from_id'}[$i];
2432 my $from_path = $diff->{'from_file'}[$i];
2433 my $status = $diff->{'status'}[$i];
2435 $has_history ||= ($status ne 'A');
2436 $not_deleted ||= ($status ne 'D');
2438 if ($status eq 'A') {
2439 print "<td class=\"link\" align=\"right\"> | </td>\n";
2440 } elsif ($status eq 'D') {
2441 print "<td class=\"link\">" .
2442 $cgi->a({-href
=> href
(action
=>"blob",
2445 file_name
=>$from_path)},
2449 if ($diff->{'to_id'} eq $from_hash) {
2450 print "<td class=\"link nochange\">";
2452 print "<td class=\"link\">";
2454 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2455 hash
=>$diff->{'to_id'},
2456 hash_parent
=>$from_hash,
2458 hash_parent_base
=>$hash_parent,
2459 file_name
=>$diff->{'to_file'},
2460 file_parent
=>$from_path)},
2466 print "<td class=\"link\">";
2468 print $cgi->a({-href
=> href
(action
=>"blob",
2469 hash
=>$diff->{'to_id'},
2470 file_name
=>$diff->{'to_file'},
2473 print " | " if ($has_history);
2476 print $cgi->a({-href
=> href
(action
=>"history",
2477 file_name
=>$diff->{'to_file'},
2484 next; # instead of 'else' clause, to avoid extra indent
2486 # else ordinary diff
2488 my ($to_mode_oct, $to_mode_str, $to_file_type);
2489 my ($from_mode_oct, $from_mode_str, $from_file_type);
2490 if ($diff->{'to_mode'} ne ('0' x
6)) {
2491 $to_mode_oct = oct $diff->{'to_mode'};
2492 if (S_ISREG
($to_mode_oct)) { # only for regular file
2493 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2495 $to_file_type = file_type
($diff->{'to_mode'});
2497 if ($diff->{'from_mode'} ne ('0' x
6)) {
2498 $from_mode_oct = oct $diff->{'from_mode'};
2499 if (S_ISREG
($to_mode_oct)) { # only for regular file
2500 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2502 $from_file_type = file_type
($diff->{'from_mode'});
2505 if ($diff->{'status'} eq "A") { # created
2506 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2507 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2508 $mode_chng .= "]</span>";
2510 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2511 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2512 -class => "list"}, esc_path
($diff->{'file'}));
2514 print "<td>$mode_chng</td>\n";
2515 print "<td class=\"link\">";
2516 if ($action eq 'commitdiff') {
2519 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2522 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2523 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2527 } elsif ($diff->{'status'} eq "D") { # deleted
2528 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2530 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2531 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2532 -class => "list"}, esc_path
($diff->{'file'}));
2534 print "<td>$mode_chng</td>\n";
2535 print "<td class=\"link\">";
2536 if ($action eq 'commitdiff') {
2539 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2542 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2543 hash_base
=>$parent, file_name
=>$diff->{'file'})},
2546 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2547 file_name
=>$diff->{'file'})},
2550 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2551 file_name
=>$diff->{'file'})},
2555 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2556 my $mode_chnge = "";
2557 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2558 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2559 if ($from_file_type ne $to_file_type) {
2560 $mode_chnge .= " from $from_file_type to $to_file_type";
2562 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2563 if ($from_mode_str && $to_mode_str) {
2564 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2565 } elsif ($to_mode_str) {
2566 $mode_chnge .= " mode: $to_mode_str";
2569 $mode_chnge .= "]</span>\n";
2572 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2573 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2574 -class => "list"}, esc_path
($diff->{'file'}));
2576 print "<td>$mode_chnge</td>\n";
2577 print "<td class=\"link\">";
2578 if ($action eq 'commitdiff') {
2581 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2583 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2584 # "commit" view and modified file (not onlu mode changed)
2585 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2586 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2587 hash_base
=>$hash, hash_parent_base
=>$parent,
2588 file_name
=>$diff->{'file'})},
2592 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2593 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2596 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2597 file_name
=>$diff->{'file'})},
2600 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2601 file_name
=>$diff->{'file'})},
2605 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
2606 my %status_name = ('R' => 'moved', 'C' => 'copied');
2607 my $nstatus = $status_name{$diff->{'status'}};
2609 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2610 # mode also for directories, so we cannot use $to_mode_str
2611 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2614 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2615 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
2616 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
2617 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2618 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2619 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
2620 -class => "list"}, esc_path
($diff->{'from_file'})) .
2621 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2622 "<td class=\"link\">";
2623 if ($action eq 'commitdiff') {
2626 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2628 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2629 # "commit" view and modified file (not only pure rename or copy)
2630 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2631 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2632 hash_base
=>$hash, hash_parent_base
=>$parent,
2633 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
2637 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2638 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
2641 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2642 file_name
=>$diff->{'to_file'})},
2645 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2646 file_name
=>$diff->{'to_file'})},
2650 } # we should not encounter Unmerged (U) or Unknown (X) status
2656 sub git_patchset_body
{
2657 my ($fd, $difftree, $hash, @hash_parents) = @_;
2658 my ($hash_parent) = $hash_parents[0];
2661 my $patch_number = 0;
2666 print "<div class=\"patchset\">\n";
2668 # skip to first patch
2669 while ($patch_line = <$fd>) {
2672 last if ($patch_line =~ m/^diff /);
2676 while ($patch_line) {
2678 my ($from_id, $to_id);
2681 #assert($patch_line =~ m/^diff /) if DEBUG;
2682 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2684 push @diff_header, $patch_line;
2686 # extended diff header
2688 while ($patch_line = <$fd>) {
2691 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2693 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2696 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2697 $from_id = [ split(',', $1) ];
2701 push @diff_header, $patch_line;
2703 my $last_patch_line = $patch_line;
2705 # check if current patch belong to current raw line
2706 # and parse raw git-diff line if needed
2707 if (defined $diffinfo &&
2708 defined $from_id && defined $to_id &&
2709 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
2710 $diffinfo->{'to_id'} eq $to_id) {
2711 # this is continuation of a split patch
2712 print "<div class=\"patch cont\">\n";
2714 # advance raw git-diff output if needed
2715 $patch_idx++ if defined $diffinfo;
2717 # read and prepare patch information
2718 if (ref($difftree->[$patch_idx]) eq "HASH") {
2719 # pre-parsed (or generated by hand)
2720 $diffinfo = $difftree->[$patch_idx];
2722 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2724 if ($diffinfo->{'nparents'}) {
2728 fill_from_file_info
($diffinfo, @hash_parents)
2729 unless exists $diffinfo->{'from_file'};
2730 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2731 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2732 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2733 $from{'href'}[$i] = href
(action
=>"blob",
2734 hash_base
=>$hash_parents[$i],
2735 hash
=>$diffinfo->{'from_id'}[$i],
2736 file_name
=>$from{'file'}[$i]);
2738 $from{'href'}[$i] = undef;
2742 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2743 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2744 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2745 hash
=>$diffinfo->{'from_id'},
2746 file_name
=>$from{'file'});
2748 delete $from{'href'};
2752 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2753 if ($diffinfo->{'to_id'} ne ('0' x
40)) { # file exists in result
2754 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2755 hash
=>$diffinfo->{'to_id'},
2756 file_name
=>$to{'file'});
2760 # this is first patch for raw difftree line with $patch_idx index
2761 # we index @$difftree array from 0, but number patches from 1
2762 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2765 # print "git diff" header
2766 $patch_line = shift @diff_header;
2767 if ($diffinfo->{'nparents'}) {
2770 $patch_line =~ s!^(diff (.*?) )"?.*$!$1!;
2772 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2773 esc_path
($to{'file'}));
2774 } else { # file was deleted
2775 $patch_line .= esc_path
($to{'file'});
2780 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2781 if ($from{'href'}) {
2782 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2783 'a/' . esc_path
($from{'file'}));
2784 } else { # file was added
2785 $patch_line .= 'a/' . esc_path
($from{'file'});
2789 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2790 'b/' . esc_path
($to{'file'}));
2791 } else { # file was deleted
2792 $patch_line .= 'b/' . esc_path
($to{'file'});
2796 print "<div class=\"diff header\">$patch_line</div>\n";
2798 # print extended diff header
2799 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2801 foreach $patch_line (@diff_header) {
2803 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2804 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2805 esc_path
($from{'file'}));
2807 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2808 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2809 esc_path
($to{'file'}));
2811 # match single <mode>
2812 if ($patch_line =~ m/\s(\d{6})$/) {
2813 $patch_line .= '<span class="info"> (' .
2814 file_type_long
($1) .
2818 if ($patch_line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
2819 # can match only for combined diff
2820 $patch_line = 'index ';
2821 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2822 if ($from{'href'}[$i]) {
2823 $patch_line .= $cgi->a({-href
=>$from{'href'}[$i],
2825 substr($diffinfo->{'from_id'}[$i],0,7));
2827 $patch_line .= '0' x
7;
2830 $patch_line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
2832 $patch_line .= '..';
2834 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2835 substr($diffinfo->{'to_id'},0,7));
2837 $patch_line .= '0' x
7;
2840 } elsif ($patch_line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
2841 # can match only for ordinary diff
2842 my ($from_link, $to_link);
2843 if ($from{'href'}) {
2844 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2845 substr($diffinfo->{'from_id'},0,7));
2847 $from_link = '0' x
7;
2850 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2851 substr($diffinfo->{'to_id'},0,7));
2856 # my ($from_hash, $to_hash) =
2857 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2858 # my ($from_id, $to_id) =
2859 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2860 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2862 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2863 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2865 print $patch_line . "<br/>\n";
2867 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2869 # from-file/to-file diff header
2870 $patch_line = $last_patch_line;
2871 if (! $patch_line) {
2872 print "</div>\n"; # class="patch"
2875 next PATCH
if ($patch_line =~ m/^diff /);
2876 #assert($patch_line =~ m/^---/) if DEBUG;
2877 if (!$diffinfo->{'nparents'} && # not from-file line for combined diff
2878 $from{'href'} && $patch_line =~ m!^--- "?a/!) {
2879 $patch_line = '--- a/' .
2880 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2881 esc_path
($from{'file'}));
2883 print "<div class=\"diff from_file\">$patch_line</div>\n";
2885 $patch_line = <$fd>;
2888 #assert($patch_line =~ m/^+++/) if DEBUG;
2889 if ($to{'href'} && $patch_line =~ m!^\+\+\+ "?b/!) {
2890 $patch_line = '+++ b/' .
2891 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2892 esc_path
($to{'file'}));
2894 print "<div class=\"diff to_file\">$patch_line</div>\n";
2898 while ($patch_line = <$fd>) {
2901 next PATCH
if ($patch_line =~ m/^diff /);
2903 print format_diff_line
($patch_line, \
%from, \
%to);
2907 print "</div>\n"; # class="patch"
2910 if ($patch_number == 0) {
2911 if (@hash_parents > 1) {
2912 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
2914 print "<div class=\"diff nodifferences\">No differences found</div>\n";
2918 print "</div>\n"; # class="patchset"
2921 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2923 sub git_project_list_body
{
2924 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2926 my ($check_forks) = gitweb_check_feature
('forks');
2929 foreach my $pr (@
$projlist) {
2930 my (@aa) = git_get_last_activity
($pr->{'path'});
2934 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2935 if (!defined $pr->{'descr'}) {
2936 my $descr = git_get_project_description
($pr->{'path'}) || "";
2937 $pr->{'descr_long'} = decode_utf8
($descr);
2938 $pr->{'descr'} = chop_str
($descr, 25, 5);
2940 if (!defined $pr->{'owner'}) {
2941 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2944 my $pname = $pr->{'path'};
2945 if (($pname =~ s/\.git$//) &&
2946 ($pname !~ /\/$/) &&
2947 (-d
"$projectroot/$pname")) {
2948 $pr->{'forks'} = "-d $projectroot/$pname";
2954 push @projects, $pr;
2957 $order ||= $default_projects_order;
2958 $from = 0 unless defined $from;
2959 $to = $#projects if (!defined $to || $#projects < $to);
2961 print "<table class=\"project_list\">\n";
2962 unless ($no_header) {
2965 print "<th></th>\n";
2967 if ($order eq "project") {
2968 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2969 print "<th>Project</th>\n";
2972 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2973 -class => "header"}, "Project") .
2976 if ($order eq "descr") {
2977 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2978 print "<th>Description</th>\n";
2981 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2982 -class => "header"}, "Description") .
2985 if ($order eq "owner") {
2986 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2987 print "<th>Owner</th>\n";
2990 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2991 -class => "header"}, "Owner") .
2994 if ($order eq "age") {
2995 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2996 print "<th>Last Change</th>\n";
2999 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3000 -class => "header"}, "Last Change") .
3003 print "<th></th>\n" .
3007 for (my $i = $from; $i <= $to; $i++) {
3008 my $pr = $projects[$i];
3010 print "<tr class=\"dark\">\n";
3012 print "<tr class=\"light\">\n";
3017 if ($pr->{'forks'}) {
3018 print "<!-- $pr->{'forks'} -->\n";
3019 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3023 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3024 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3025 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3026 -class => "list", -title
=> $pr->{'descr_long'}},
3027 esc_html
($pr->{'descr'})) . "</td>\n" .
3028 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
3029 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3030 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
3031 "<td class=\"link\">" .
3032 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3033 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3034 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3035 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3036 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3040 if (defined $extra) {
3043 print "<td></td>\n";
3045 print "<td colspan=\"5\">$extra</td>\n" .
3051 sub git_shortlog_body
{
3052 # uses global variable $project
3053 my ($commitlist, $from, $to, $refs, $extra) = @_;
3055 my $have_snapshot = gitweb_have_snapshot
();
3057 $from = 0 unless defined $from;
3058 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3060 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3062 for (my $i = $from; $i <= $to; $i++) {
3063 my %co = %{$commitlist->[$i]};
3064 my $commit = $co{'id'};
3065 my $ref = format_ref_marker
($refs, $commit);
3067 print "<tr class=\"dark\">\n";
3069 print "<tr class=\"light\">\n";
3072 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3073 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3074 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3076 print format_subject_html
($co{'title'}, $co{'title_short'},
3077 href
(action
=>"commit", hash
=>$commit), $ref);
3079 "<td class=\"link\">" .
3080 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3081 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3082 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3083 if ($have_snapshot) {
3084 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
3089 if (defined $extra) {
3091 "<td colspan=\"4\">$extra</td>\n" .
3097 sub git_history_body
{
3098 # Warning: assumes constant type (blob or tree) during history
3099 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3101 $from = 0 unless defined $from;
3102 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3104 print "<table class=\"history\" cellspacing=\"0\">\n";
3106 for (my $i = $from; $i <= $to; $i++) {
3107 my %co = %{$commitlist->[$i]};
3111 my $commit = $co{'id'};
3113 my $ref = format_ref_marker
($refs, $commit);
3116 print "<tr class=\"dark\">\n";
3118 print "<tr class=\"light\">\n";
3121 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3122 # shortlog uses chop_str($co{'author_name'}, 10)
3123 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3125 # originally git_history used chop_str($co{'title'}, 50)
3126 print format_subject_html
($co{'title'}, $co{'title_short'},
3127 href
(action
=>"commit", hash
=>$commit), $ref);
3129 "<td class=\"link\">" .
3130 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3131 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3133 if ($ftype eq 'blob') {
3134 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3135 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3136 if (defined $blob_current && defined $blob_parent &&
3137 $blob_current ne $blob_parent) {
3139 $cgi->a({-href
=> href
(action
=>"blobdiff",
3140 hash
=>$blob_current, hash_parent
=>$blob_parent,
3141 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3142 file_name
=>$file_name)},
3149 if (defined $extra) {
3151 "<td colspan=\"4\">$extra</td>\n" .
3158 # uses global variable $project
3159 my ($taglist, $from, $to, $extra) = @_;
3160 $from = 0 unless defined $from;
3161 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3163 print "<table class=\"tags\" cellspacing=\"0\">\n";
3165 for (my $i = $from; $i <= $to; $i++) {
3166 my $entry = $taglist->[$i];
3168 my $comment = $tag{'subject'};
3170 if (defined $comment) {
3171 $comment_short = chop_str
($comment, 30, 5);
3174 print "<tr class=\"dark\">\n";
3176 print "<tr class=\"light\">\n";
3179 if (defined $tag{'age'}) {
3180 print "<td><i>$tag{'age'}</i></td>\n";
3182 print "<td></td>\n";
3185 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3186 -class => "list name"}, esc_html
($tag{'name'})) .
3189 if (defined $comment) {
3190 print format_subject_html
($comment, $comment_short,
3191 href
(action
=>"tag", hash
=>$tag{'id'}));
3194 "<td class=\"selflink\">";
3195 if ($tag{'type'} eq "tag") {
3196 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3201 "<td class=\"link\">" . " | " .
3202 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3203 if ($tag{'reftype'} eq "commit") {
3204 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3205 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3206 } elsif ($tag{'reftype'} eq "blob") {
3207 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3212 if (defined $extra) {
3214 "<td colspan=\"5\">$extra</td>\n" .
3220 sub git_heads_body
{
3221 # uses global variable $project
3222 my ($headlist, $head, $from, $to, $extra) = @_;
3223 $from = 0 unless defined $from;
3224 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3226 print "<table class=\"heads\" cellspacing=\"0\">\n";
3228 for (my $i = $from; $i <= $to; $i++) {
3229 my $entry = $headlist->[$i];
3231 my $curr = $ref{'id'} eq $head;
3233 print "<tr class=\"dark\">\n";
3235 print "<tr class=\"light\">\n";
3238 print "<td><i>$ref{'age'}</i></td>\n" .
3239 ($curr ?
"<td class=\"current_head\">" : "<td>") .
3240 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3241 -class => "list name"},esc_html
($ref{'name'})) .
3243 "<td class=\"link\">" .
3244 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3245 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3246 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3250 if (defined $extra) {
3252 "<td colspan=\"3\">$extra</td>\n" .
3258 sub git_search_grep_body
{
3259 my ($commitlist, $from, $to, $extra) = @_;
3260 $from = 0 unless defined $from;
3261 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3263 print "<table class=\"grep\" cellspacing=\"0\">\n";
3265 for (my $i = $from; $i <= $to; $i++) {
3266 my %co = %{$commitlist->[$i]};
3270 my $commit = $co{'id'};
3272 print "<tr class=\"dark\">\n";
3274 print "<tr class=\"light\">\n";
3277 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3278 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3280 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3281 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3282 my $comment = $co{'comment'};
3283 foreach my $line (@
$comment) {
3284 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3285 my $lead = esc_html
($1) || "";
3286 $lead = chop_str
($lead, 30, 10);
3287 my $match = esc_html
($2) || "";
3288 my $trail = esc_html
($3) || "";
3289 $trail = chop_str
($trail, 30, 10);
3290 my $text = "$lead<span class=\"match\">$match</span>$trail";
3291 print chop_str
($text, 80, 5) . "<br/>\n";
3295 "<td class=\"link\">" .
3296 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3298 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3302 if (defined $extra) {
3304 "<td colspan=\"3\">$extra</td>\n" .
3310 ## ======================================================================
3311 ## ======================================================================
3314 sub git_project_list
{
3315 my $order = $cgi->param('o');
3316 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3317 die_error
(undef, "Unknown order parameter");
3320 my @list = git_get_projects_list
();
3322 die_error
(undef, "No projects found");
3326 if (-f
$home_text) {
3327 print "<div class=\"index_include\">\n";
3328 open (my $fd, $home_text);
3333 git_project_list_body
(\
@list, $order);
3338 my $order = $cgi->param('o');
3339 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3340 die_error
(undef, "Unknown order parameter");
3343 my @list = git_get_projects_list
($project);
3345 die_error
(undef, "No forks found");
3349 git_print_page_nav
('','');
3350 git_print_header_div
('summary', "$project forks");
3351 git_project_list_body
(\
@list, $order);
3355 sub git_project_index
{
3356 my @projects = git_get_projects_list
($project);
3359 -type
=> 'text/plain',
3360 -charset
=> 'utf-8',
3361 -content_disposition
=> 'inline; filename="index.aux"');
3363 foreach my $pr (@projects) {
3364 if (!exists $pr->{'owner'}) {
3365 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3368 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3369 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3370 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3371 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3375 print "$path $owner\n";
3380 my $descr = git_get_project_description
($project) || "none";
3381 my %co = parse_commit
("HEAD");
3382 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3383 my $head = $co{'id'};
3385 my $owner = git_get_project_owner
($project);
3387 my $refs = git_get_references
();
3388 # These get_*_list functions return one more to allow us to see if
3389 # there are more ...
3390 my @taglist = git_get_tags_list
(16);
3391 my @headlist = git_get_heads_list
(16);
3393 my ($check_forks) = gitweb_check_feature
('forks');
3396 @forklist = git_get_projects_list
($project);
3400 git_print_page_nav
('summary','', $head);
3402 print "<div class=\"title\"> </div>\n";
3403 print "<table cellspacing=\"0\">\n" .
3404 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3405 "<tr><td>owner</td><td>$owner</td></tr>\n";
3406 if (defined $cd{'rfc2822'}) {
3407 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3410 # use per project git URL list in $projectroot/$project/cloneurl
3411 # or make project git URL from git base URL and project name
3412 my $url_tag = "URL";
3413 my @url_list = git_get_project_url_list
($project);
3414 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3415 foreach my $git_url (@url_list) {
3416 next unless $git_url;
3417 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3422 if (-s
"$projectroot/$project/README.html") {
3423 if (open my $fd, "$projectroot/$project/README.html") {
3424 print "<div class=\"title\">readme</div>\n";
3425 print $_ while (<$fd>);
3430 # we need to request one more than 16 (0..15) to check if
3432 my @commitlist = $head ? parse_commits
($head, 17) : ();
3434 git_print_header_div
('shortlog');
3435 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3436 $#commitlist <= 15 ?
undef :
3437 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3441 git_print_header_div
('tags');
3442 git_tags_body
(\
@taglist, 0, 15,
3443 $#taglist <= 15 ?
undef :
3444 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3448 git_print_header_div
('heads');
3449 git_heads_body
(\
@headlist, $head, 0, 15,
3450 $#headlist <= 15 ?
undef :
3451 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3455 git_print_header_div
('forks');
3456 git_project_list_body
(\
@forklist, undef, 0, 15,
3457 $#forklist <= 15 ?
undef :
3458 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3466 my $head = git_get_head_hash
($project);
3468 git_print_page_nav
('','', $head,undef,$head);
3469 my %tag = parse_tag
($hash);
3472 die_error
(undef, "Unknown tag object");
3475 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3476 print "<div class=\"title_text\">\n" .
3477 "<table cellspacing=\"0\">\n" .
3479 "<td>object</td>\n" .
3480 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3481 $tag{'object'}) . "</td>\n" .
3482 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3483 $tag{'type'}) . "</td>\n" .
3485 if (defined($tag{'author'})) {
3486 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3487 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3488 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3489 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3492 print "</table>\n\n" .
3494 print "<div class=\"page_body\">";
3495 my $comment = $tag{'comment'};
3496 foreach my $line (@
$comment) {
3498 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3508 my ($have_blame) = gitweb_check_feature
('blame');
3510 die_error
('403 Permission denied', "Permission denied");
3512 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3513 $hash_base ||= git_get_head_hash
($project);
3514 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3515 my %co = parse_commit
($hash_base)
3516 or die_error
(undef, "Reading commit failed");
3517 if (!defined $hash) {
3518 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3519 or die_error
(undef, "Error looking up file");
3521 $ftype = git_get_type
($hash);
3522 if ($ftype !~ "blob") {
3523 die_error
('400 Bad Request', "Object is not a blob");
3525 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3526 $file_name, $hash_base)
3527 or die_error
(undef, "Open git-blame failed");
3530 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3533 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3536 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3538 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3539 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3540 git_print_page_path
($file_name, $ftype, $hash_base);
3541 my @rev_color = (qw(light2 dark2));
3542 my $num_colors = scalar(@rev_color);
3543 my $current_color = 0;
3546 <div class="page_body">
3547 <table class="blame">
3548 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3553 last unless defined $_;
3554 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3555 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3556 if (!exists $metainfo{$full_rev}) {
3557 $metainfo{$full_rev} = {};
3559 my $meta = $metainfo{$full_rev};
3562 if (/^(\S+) (.*)$/) {
3568 my $rev = substr($full_rev, 0, 8);
3569 my $author = $meta->{'author'};
3570 my %date = parse_date
($meta->{'author-time'},
3571 $meta->{'author-tz'});
3572 my $date = $date{'iso-tz'};
3574 $current_color = ++$current_color % $num_colors;
3576 print "<tr class=\"$rev_color[$current_color]\">\n";
3578 print "<td class=\"sha1\"";
3579 print " title=\"". esc_html
($author) . ", $date\"";
3580 print " rowspan=\"$group_size\"" if ($group_size > 1);
3582 print $cgi->a({-href
=> href
(action
=>"commit",
3584 file_name
=>$file_name)},
3588 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3589 or die_error
(undef, "Open git-rev-parse failed");
3590 my $parent_commit = <$dd>;
3592 chomp($parent_commit);
3593 my $blamed = href
(action
=> 'blame',
3594 file_name
=> $meta->{'filename'},
3595 hash_base
=> $parent_commit);
3596 print "<td class=\"linenr\">";
3597 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3599 -class => "linenr" },
3602 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3608 or print "Reading blob failed\n";
3615 my ($have_blame) = gitweb_check_feature
('blame');
3617 die_error
('403 Permission denied', "Permission denied");
3619 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3620 $hash_base ||= git_get_head_hash
($project);
3621 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3622 my %co = parse_commit
($hash_base)
3623 or die_error
(undef, "Reading commit failed");
3624 if (!defined $hash) {
3625 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3626 or die_error
(undef, "Error lookup file");
3628 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3629 or die_error
(undef, "Open git-annotate failed");
3632 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3635 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3638 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3640 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3641 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3642 git_print_page_path
($file_name, 'blob', $hash_base);
3643 print "<div class=\"page_body\">\n";
3645 <table class="blame">
3654 my @line_class = (qw(light dark));
3655 my $line_class_len = scalar (@line_class);
3656 my $line_class_num = $#line_class;
3657 while (my $line = <$fd>) {
3669 $line_class_num = ($line_class_num + 1) % $line_class_len;
3671 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3678 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
3681 $short_rev = substr ($long_rev, 0, 8);
3682 $age = time () - $time;
3683 $age_str = age_string
($age);
3684 $age_str =~ s/ / /g;
3685 $age_class = age_class
($age);
3686 $author = esc_html
($author);
3687 $author =~ s/ / /g;
3689 $data = untabify
($data);
3690 $data = esc_html
($data);
3693 <tr class="$line_class[$line_class_num]">
3694 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3695 <td class="$age_class">$age_str</td>
3697 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3698 <td class="pre">$data</td>
3701 } # while (my $line = <$fd>)
3702 print "</table>\n\n";
3704 or print "Reading blob failed.\n";
3710 my $head = git_get_head_hash
($project);
3712 git_print_page_nav
('','', $head,undef,$head);
3713 git_print_header_div
('summary', $project);
3715 my @tagslist = git_get_tags_list
();
3717 git_tags_body
(\
@tagslist);
3723 my $head = git_get_head_hash
($project);
3725 git_print_page_nav
('','', $head,undef,$head);
3726 git_print_header_div
('summary', $project);
3728 my @headslist = git_get_heads_list
();
3730 git_heads_body
(\
@headslist, $head);
3735 sub git_blob_plain
{
3738 if (!defined $hash) {
3739 if (defined $file_name) {
3740 my $base = $hash_base || git_get_head_hash
($project);
3741 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3742 or die_error
(undef, "Error lookup file");
3744 die_error
(undef, "No file name defined");
3746 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3747 # blobs defined by non-textual hash id's can be cached
3752 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3753 or die_error
(undef, "Couldn't cat $file_name, $hash");
3755 $type ||= blob_mimetype
($fd, $file_name);
3757 # save as filename, even when no $file_name is given
3758 my $save_as = "$hash";
3759 if (defined $file_name) {
3760 $save_as = $file_name;
3761 } elsif ($type =~ m/^text\//) {
3768 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3770 binmode STDOUT
, ':raw';
3772 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3780 if (!defined $hash) {
3781 if (defined $file_name) {
3782 my $base = $hash_base || git_get_head_hash
($project);
3783 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3784 or die_error
(undef, "Error lookup file");
3786 die_error
(undef, "No file name defined");
3788 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3789 # blobs defined by non-textual hash id's can be cached
3793 my ($have_blame) = gitweb_check_feature
('blame');
3794 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3795 or die_error
(undef, "Couldn't cat $file_name, $hash");
3796 my $mimetype = blob_mimetype
($fd, $file_name);
3797 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3799 return git_blob_plain
($mimetype);
3801 # we can have blame only for text/* mimetype
3802 $have_blame &&= ($mimetype =~ m!^text/!);
3804 git_header_html
(undef, $expires);
3805 my $formats_nav = '';
3806 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3807 if (defined $file_name) {
3810 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3811 hash
=>$hash, file_name
=>$file_name)},
3816 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3817 hash
=>$hash, file_name
=>$file_name)},
3820 $cgi->a({-href
=> href
(action
=>"blob_plain",
3821 hash
=>$hash, file_name
=>$file_name)},
3824 $cgi->a({-href
=> href
(action
=>"blob",
3825 hash_base
=>"HEAD", file_name
=>$file_name)},
3829 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3831 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3832 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3834 print "<div class=\"page_nav\">\n" .
3835 "<br/><br/></div>\n" .
3836 "<div class=\"title\">$hash</div>\n";
3838 git_print_page_path
($file_name, "blob", $hash_base);
3839 print "<div class=\"page_body\">\n";
3840 if ($mimetype =~ m!^text/!) {
3842 while (my $line = <$fd>) {
3845 $line = untabify
($line);
3846 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3847 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3849 } elsif ($mimetype =~ m!^image/!) {
3850 print qq!<img type
="$mimetype"!;
3852 print qq! alt
="$file_name" title
="$file_name"!;
3855 href(action=>"blob_plain
", hash=>$hash,
3856 hash_base=>$hash_base, file_name=>$file_name) .
3860 or print "Reading blob failed.\n";
3866 my $have_snapshot = gitweb_have_snapshot
();
3868 if (!defined $hash_base) {
3869 $hash_base = "HEAD";
3871 if (!defined $hash) {
3872 if (defined $file_name) {
3873 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3879 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3880 or die_error
(undef, "Open git-ls-tree failed");
3881 my @entries = map { chomp; $_ } <$fd>;
3882 close $fd or die_error
(undef, "Reading tree failed");
3885 my $refs = git_get_references
();
3886 my $ref = format_ref_marker
($refs, $hash_base);
3889 my ($have_blame) = gitweb_check_feature
('blame');
3890 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3892 if (defined $file_name) {
3894 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3895 hash
=>$hash, file_name
=>$file_name)},
3897 $cgi->a({-href
=> href
(action
=>"tree",
3898 hash_base
=>"HEAD", file_name
=>$file_name)},
3901 if ($have_snapshot) {
3902 # FIXME: Should be available when we have no hash base as well.
3904 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3907 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3908 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3911 print "<div class=\"page_nav\">\n";
3912 print "<br/><br/></div>\n";
3913 print "<div class=\"title\">$hash</div>\n";
3915 if (defined $file_name) {
3916 $basedir = $file_name;
3917 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3921 git_print_page_path
($file_name, 'tree', $hash_base);
3922 print "<div class=\"page_body\">\n";
3923 print "<table cellspacing=\"0\">\n";
3925 # '..' (top directory) link if possible
3926 if (defined $hash_base &&
3927 defined $file_name && $file_name =~ m![^/]+$!) {
3929 print "<tr class=\"dark\">\n";
3931 print "<tr class=\"light\">\n";
3935 my $up = $file_name;
3936 $up =~ s!/?[^/]+$!!;
3937 undef $up unless $up;
3938 # based on git_print_tree_entry
3939 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3940 print '<td class="list">';
3941 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3945 print "<td class=\"link\"></td>\n";
3949 foreach my $line (@entries) {
3950 my %t = parse_ls_tree_line
($line, -z
=> 1);
3953 print "<tr class=\"dark\">\n";
3955 print "<tr class=\"light\">\n";
3959 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3963 print "</table>\n" .
3969 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3970 my $have_snapshot = (defined $ctype && defined $suffix);
3971 if (!$have_snapshot) {
3972 die_error
('403 Permission denied', "Permission denied");
3975 if (!defined $hash) {
3976 $hash = git_get_head_hash
($project);
3979 my $filename = decode_utf8
(basename
($project)) . "-$hash.tar.$suffix";
3982 -type
=> "application/$ctype",
3983 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3984 -status
=> '200 OK');
3986 my $git = git_cmd_str
();
3987 my $name = $project;
3988 $name =~ s/\047/\047\\\047\047/g;
3990 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3991 or die_error
(undef, "Execute git-tar-tree failed");
3992 binmode STDOUT
, ':raw';
3994 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4000 my $head = git_get_head_hash
($project);
4001 if (!defined $hash) {
4004 if (!defined $page) {
4007 my $refs = git_get_references
();
4009 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4011 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4014 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4017 my %co = parse_commit
($hash);
4019 git_print_header_div
('summary', $project);
4020 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4022 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
4023 for (my $i = 0; $i <= $to; $i++) {
4024 my %co = %{$commitlist[$i]};
4026 my $commit = $co{'id'};
4027 my $ref = format_ref_marker
($refs, $commit);
4028 my %ad = parse_date
($co{'author_epoch'});
4029 git_print_header_div
('commit',
4030 "<span class=\"age\">$co{'age_string'}</span>" .
4031 esc_html
($co{'title'}) . $ref,
4033 print "<div class=\"title_text\">\n" .
4034 "<div class=\"log_link\">\n" .
4035 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4037 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4039 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4042 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4045 print "<div class=\"log_body\">\n";
4046 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4049 if ($#commitlist >= 100) {
4050 print "<div class=\"page_nav\">\n";
4051 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4052 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4059 $hash ||= $hash_base || "HEAD";
4060 my %co = parse_commit
($hash);
4062 die_error
(undef, "Unknown commit object");
4064 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4065 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4067 my $parent = $co{'parent'};
4068 my $parents = $co{'parents'}; # listref
4070 # we need to prepare $formats_nav before any parameter munging
4072 if (!defined $parent) {
4074 $formats_nav .= '(initial)';
4075 } elsif (@
$parents == 1) {
4076 # single parent commit
4079 $cgi->a({-href
=> href
(action
=>"commit",
4081 esc_html
(substr($parent, 0, 7))) .
4088 $cgi->a({-href
=> href
(action
=>"commit",
4090 esc_html
(substr($_, 0, 7)));
4095 if (!defined $parent) {
4099 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4101 (@
$parents <= 1 ?
$parent : '-c'),
4103 or die_error
(undef, "Open git-diff-tree failed");
4104 @difftree = map { chomp; $_ } <$fd>;
4105 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4107 # non-textual hash id's can be cached
4109 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4112 my $refs = git_get_references
();
4113 my $ref = format_ref_marker
($refs, $co{'id'});
4115 my $have_snapshot = gitweb_have_snapshot
();
4117 git_header_html
(undef, $expires);
4118 git_print_page_nav
('commit', '',
4119 $hash, $co{'tree'}, $hash,
4122 if (defined $co{'parent'}) {
4123 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4125 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4127 print "<div class=\"title_text\">\n" .
4128 "<table cellspacing=\"0\">\n";
4129 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4131 "<td></td><td> $ad{'rfc2822'}";
4132 if ($ad{'hour_local'} < 6) {
4133 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4134 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4136 printf(" (%02d:%02d %s)",
4137 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4141 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4142 print "<tr><td></td><td> $cd{'rfc2822'}" .
4143 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4145 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4148 "<td class=\"sha1\">" .
4149 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4150 class => "list"}, $co{'tree'}) .
4152 "<td class=\"link\">" .
4153 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4155 if ($have_snapshot) {
4157 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
4162 foreach my $par (@
$parents) {
4165 "<td class=\"sha1\">" .
4166 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4167 class => "list"}, $par) .
4169 "<td class=\"link\">" .
4170 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4172 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4179 print "<div class=\"page_body\">\n";
4180 git_print_log
($co{'comment'});
4183 git_difftree_body
(\
@difftree, $hash, @
$parents);
4189 # object is defined by:
4190 # - hash or hash_base alone
4191 # - hash_base and file_name
4194 # - hash or hash_base alone
4195 if ($hash || ($hash_base && !defined $file_name)) {
4196 my $object_id = $hash || $hash_base;
4198 my $git_command = git_cmd_str
();
4199 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4200 or die_error
('404 Not Found', "Object does not exist");
4204 or die_error
('404 Not Found', "Object does not exist");
4206 # - hash_base and file_name
4207 } elsif ($hash_base && defined $file_name) {
4208 $file_name =~ s
,/+$,,;
4210 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4211 or die_error
('404 Not Found', "Base object does not exist");
4213 # here errors should not hapen
4214 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4215 or die_error
(undef, "Open git-ls-tree failed");
4219 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4220 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4221 die_error
('404 Not Found', "File or directory for given base does not exist");
4226 die_error
('404 Not Found', "Not enough information to find object");
4229 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4230 hash
=>$hash, hash_base
=>$hash_base,
4231 file_name
=>$file_name),
4232 -status
=> '302 Found');
4236 my $format = shift || 'html';
4243 # preparing $fd and %diffinfo for git_patchset_body
4245 if (defined $hash_base && defined $hash_parent_base) {
4246 if (defined $file_name) {
4248 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4249 $hash_parent_base, $hash_base,
4250 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4251 or die_error
(undef, "Open git-diff-tree failed");
4252 @difftree = map { chomp; $_ } <$fd>;
4254 or die_error
(undef, "Reading git-diff-tree failed");
4256 or die_error
('404 Not Found', "Blob diff not found");
4258 } elsif (defined $hash &&
4259 $hash =~ /[0-9a-fA-F]{40}/) {
4260 # try to find filename from $hash
4262 # read filtered raw output
4263 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4264 $hash_parent_base, $hash_base, "--"
4265 or die_error
(undef, "Open git-diff-tree failed");
4267 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4269 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4270 map { chomp; $_ } <$fd>;
4272 or die_error
(undef, "Reading git-diff-tree failed");
4274 or die_error
('404 Not Found', "Blob diff not found");
4277 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4280 if (@difftree > 1) {
4281 die_error
('404 Not Found', "Ambiguous blob diff specification");
4284 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4285 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4286 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4288 $hash_parent ||= $diffinfo{'from_id'};
4289 $hash ||= $diffinfo{'to_id'};
4291 # non-textual hash id's can be cached
4292 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4293 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4298 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4299 '-p', ($format eq 'html' ?
"--full-index" : ()),
4300 $hash_parent_base, $hash_base,
4301 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4302 or die_error
(undef, "Open git-diff-tree failed");
4305 # old/legacy style URI
4306 if (!%diffinfo && # if new style URI failed
4307 defined $hash && defined $hash_parent) {
4308 # fake git-diff-tree raw output
4309 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4310 $diffinfo{'from_id'} = $hash_parent;
4311 $diffinfo{'to_id'} = $hash;
4312 if (defined $file_name) {
4313 if (defined $file_parent) {
4314 $diffinfo{'status'} = '2';
4315 $diffinfo{'from_file'} = $file_parent;
4316 $diffinfo{'to_file'} = $file_name;
4317 } else { # assume not renamed
4318 $diffinfo{'status'} = '1';
4319 $diffinfo{'from_file'} = $file_name;
4320 $diffinfo{'to_file'} = $file_name;
4322 } else { # no filename given
4323 $diffinfo{'status'} = '2';
4324 $diffinfo{'from_file'} = $hash_parent;
4325 $diffinfo{'to_file'} = $hash;
4328 # non-textual hash id's can be cached
4329 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4330 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4335 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4336 '-p', ($format eq 'html' ?
"--full-index" : ()),
4337 $hash_parent, $hash, "--"
4338 or die_error
(undef, "Open git-diff failed");
4340 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4345 if ($format eq 'html') {
4347 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4348 hash
=>$hash, hash_parent
=>$hash_parent,
4349 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4350 file_name
=>$file_name, file_parent
=>$file_parent)},
4352 git_header_html
(undef, $expires);
4353 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4354 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4355 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4357 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4358 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4360 if (defined $file_name) {
4361 git_print_page_path
($file_name, "blob", $hash_base);
4363 print "<div class=\"page_path\"></div>\n";
4366 } elsif ($format eq 'plain') {
4368 -type
=> 'text/plain',
4369 -charset
=> 'utf-8',
4370 -expires
=> $expires,
4371 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4373 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4376 die_error
(undef, "Unknown blobdiff format");
4380 if ($format eq 'html') {
4381 print "<div class=\"page_body\">\n";
4383 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4386 print "</div>\n"; # class="page_body"
4390 while (my $line = <$fd>) {
4391 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4392 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4396 last if $line =~ m!^\+\+\+!;
4404 sub git_blobdiff_plain
{
4405 git_blobdiff
('plain');
4408 sub git_commitdiff
{
4409 my $format = shift || 'html';
4410 $hash ||= $hash_base || "HEAD";
4411 my %co = parse_commit
($hash);
4413 die_error
(undef, "Unknown commit object");
4416 # we need to prepare $formats_nav before any parameter munging
4418 if ($format eq 'html') {
4420 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4421 hash
=>$hash, hash_parent
=>$hash_parent)},
4424 if (defined $hash_parent) {
4425 # commitdiff with two commits given
4426 my $hash_parent_short = $hash_parent;
4427 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4428 $hash_parent_short = substr($hash_parent, 0, 7);
4432 $cgi->a({-href
=> href
(action
=>"commitdiff",
4433 hash
=>$hash_parent)},
4434 esc_html
($hash_parent_short)) .
4436 } elsif (!$co{'parent'}) {
4438 $formats_nav .= ' (initial)';
4439 } elsif (scalar @
{$co{'parents'}} == 1) {
4440 # single parent commit
4443 $cgi->a({-href
=> href
(action
=>"commitdiff",
4444 hash
=>$co{'parent'})},
4445 esc_html
(substr($co{'parent'}, 0, 7))) .
4452 $cgi->a({-href
=> href
(action
=>"commitdiff",
4454 esc_html
(substr($_, 0, 7)));
4455 } @
{$co{'parents'}} ) .
4460 my $hash_parent_param = $hash_parent;
4461 if (!defined $hash_parent) {
4462 $hash_parent_param =
4463 @
{$co{'parents'}} > 1 ?
'-c' : $co{'parent'} || '--root';
4469 if ($format eq 'html') {
4470 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4471 "--no-commit-id", "--patch-with-raw", "--full-index",
4472 $hash_parent_param, $hash, "--"
4473 or die_error
(undef, "Open git-diff-tree failed");
4475 while (my $line = <$fd>) {
4477 # empty line ends raw part of diff-tree output
4479 push @difftree, scalar parse_difftree_raw_line
($line);
4482 } elsif ($format eq 'plain') {
4483 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4484 '-p', $hash_parent_param, $hash, "--"
4485 or die_error
(undef, "Open git-diff-tree failed");
4488 die_error
(undef, "Unknown commitdiff format");
4491 # non-textual hash id's can be cached
4493 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4497 # write commit message
4498 if ($format eq 'html') {
4499 my $refs = git_get_references
();
4500 my $ref = format_ref_marker
($refs, $co{'id'});
4502 git_header_html
(undef, $expires);
4503 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4504 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4505 git_print_authorship
(\
%co);
4506 print "<div class=\"page_body\">\n";
4507 if (@
{$co{'comment'}} > 1) {
4508 print "<div class=\"log\">\n";
4509 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4510 print "</div>\n"; # class="log"
4513 } elsif ($format eq 'plain') {
4514 my $refs = git_get_references
("tags");
4515 my $tagname = git_get_rev_name_tags
($hash);
4516 my $filename = basename
($project) . "-$hash.patch";
4519 -type
=> 'text/plain',
4520 -charset
=> 'utf-8',
4521 -expires
=> $expires,
4522 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4523 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4526 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4527 Subject: $co{'title'}
4529 print "X-Git-Tag: $tagname\n" if $tagname;
4530 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4532 foreach my $line (@
{$co{'comment'}}) {
4539 if ($format eq 'html') {
4540 git_difftree_body
(\
@difftree, $hash, $hash_parent || @
{$co{'parents'}});
4543 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent || @
{$co{'parents'}});
4545 print "</div>\n"; # class="page_body"
4548 } elsif ($format eq 'plain') {
4552 or print "Reading git-diff-tree failed\n";
4556 sub git_commitdiff_plain
{
4557 git_commitdiff
('plain');
4561 if (!defined $hash_base) {
4562 $hash_base = git_get_head_hash
($project);
4564 if (!defined $page) {
4568 my %co = parse_commit
($hash_base);
4570 die_error
(undef, "Unknown commit object");
4573 my $refs = git_get_references
();
4574 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4576 if (!defined $hash && defined $file_name) {
4577 $hash = git_get_hash_by_path
($hash_base, $file_name);
4579 if (defined $hash) {
4580 $ftype = git_get_type
($hash);
4583 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4585 my $paging_nav = '';
4588 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4589 file_name
=>$file_name)},
4591 $paging_nav .= " ⋅ " .
4592 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4593 file_name
=>$file_name, page
=>$page-1),
4594 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4596 $paging_nav .= "first";
4597 $paging_nav .= " ⋅ prev";
4599 if ($#commitlist >= 100) {
4600 $paging_nav .= " ⋅ " .
4601 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4602 file_name
=>$file_name, page
=>$page+1),
4603 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4605 $paging_nav .= " ⋅ next";
4608 if ($#commitlist >= 100) {
4610 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4611 file_name
=>$file_name, page
=>$page+1),
4612 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4616 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4617 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4618 git_print_page_path
($file_name, $ftype, $hash_base);
4620 git_history_body
(\
@commitlist, 0, 99,
4621 $refs, $hash_base, $ftype, $next_link);
4627 my ($have_search) = gitweb_check_feature
('search');
4628 if (!$have_search) {
4629 die_error
('403 Permission denied', "Permission denied");
4631 if (!defined $searchtext) {
4632 die_error
(undef, "Text field empty");
4634 if (!defined $hash) {
4635 $hash = git_get_head_hash
($project);
4637 my %co = parse_commit
($hash);
4639 die_error
(undef, "Unknown commit object");
4641 if (!defined $page) {
4645 $searchtype ||= 'commit';
4646 if ($searchtype eq 'pickaxe') {
4647 # pickaxe may take all resources of your box and run for several minutes
4648 # with every query - so decide by yourself how public you make this feature
4649 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4650 if (!$have_pickaxe) {
4651 die_error
('403 Permission denied', "Permission denied");
4654 if ($searchtype eq 'grep') {
4655 my ($have_grep) = gitweb_check_feature
('grep');
4657 die_error
('403 Permission denied', "Permission denied");
4663 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4665 if ($searchtype eq 'commit') {
4666 $greptype = "--grep=";
4667 } elsif ($searchtype eq 'author') {
4668 $greptype = "--author=";
4669 } elsif ($searchtype eq 'committer') {
4670 $greptype = "--committer=";
4672 $greptype .= $search_regexp;
4673 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4675 my $paging_nav = '';
4678 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4679 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4681 $paging_nav .= " ⋅ " .
4682 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4683 searchtext
=>$searchtext, searchtype
=>$searchtype,
4685 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4687 $paging_nav .= "first";
4688 $paging_nav .= " ⋅ prev";
4690 if ($#commitlist >= 100) {
4691 $paging_nav .= " ⋅ " .
4692 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4693 searchtext
=>$searchtext, searchtype
=>$searchtype,
4695 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4697 $paging_nav .= " ⋅ next";
4700 if ($#commitlist >= 100) {
4702 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4703 searchtext
=>$searchtext, searchtype
=>$searchtype,
4705 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4708 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4709 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4710 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4713 if ($searchtype eq 'pickaxe') {
4714 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4715 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4717 print "<table cellspacing=\"0\">\n";
4720 my $git_command = git_cmd_str
();
4721 my $searchqtext = $searchtext;
4722 $searchqtext =~ s/'/'\\''/;
4723 open my $fd, "-|", "$git_command rev-list $hash | " .
4724 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
4727 while (my $line = <$fd>) {
4728 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4731 $set{'from_id'} = $3;
4733 $set{'id'} = $set{'to_id'};
4734 if ($set{'id'} =~ m/0{40}/) {
4735 $set{'id'} = $set{'from_id'};
4737 if ($set{'id'} =~ m/0{40}/) {
4741 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4744 print "<tr class=\"dark\">\n";
4746 print "<tr class=\"light\">\n";
4749 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4750 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4752 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4753 -class => "list subject"},
4754 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4755 while (my $setref = shift @files) {
4757 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4758 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4760 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4764 "<td class=\"link\">" .
4765 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4767 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4771 %co = parse_commit
($1);
4779 if ($searchtype eq 'grep') {
4780 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4781 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4783 print "<table cellspacing=\"0\">\n";
4787 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
4789 while (my $line = <$fd>) {
4791 my ($file, $lno, $ltext, $binary);
4792 last if ($matches++ > 1000);
4793 if ($line =~ /^Binary file (.+) matches$/) {
4797 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
4799 if ($file ne $lastfile) {
4800 $lastfile and print "</td></tr>\n";
4802 print "<tr class=\"dark\">\n";
4804 print "<tr class=\"light\">\n";
4806 print "<td class=\"list\">".
4807 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
4808 file_name
=>"$file"),
4809 -class => "list"}, esc_path
($file));
4810 print "</td><td>\n";
4814 print "<div class=\"binary\">Binary file</div>\n";
4816 $ltext = untabify
($ltext);
4817 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
4818 $ltext = esc_html
($1, -nbsp
=>1);
4819 $ltext .= '<span class="match">';
4820 $ltext .= esc_html
($2, -nbsp
=>1);
4821 $ltext .= '</span>';
4822 $ltext .= esc_html
($3, -nbsp
=>1);
4824 $ltext = esc_html
($ltext, -nbsp
=>1);
4826 print "<div class=\"pre\">" .
4827 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
4828 file_name
=>"$file").'#l'.$lno,
4829 -class => "linenr"}, sprintf('%4i', $lno))
4830 . ' ' . $ltext . "</div>\n";
4834 print "</td></tr>\n";
4835 if ($matches > 1000) {
4836 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
4839 print "<div class=\"diff nodifferences\">No matches found</div>\n";
4848 sub git_search_help
{
4850 git_print_page_nav
('','', $hash,$hash,$hash);
4853 <dt><b>commit</b></dt>
4854 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4856 my ($have_grep) = gitweb_check_feature
('grep');
4859 <dt><b>grep</b></dt>
4860 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
4861 a different one) are searched for the given
4862 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
4863 (POSIX extended) and the matches are listed. On large
4864 trees, this search can take a while and put some strain on the server, so please use it with
4865 some consideration.</dd>
4869 <dt><b>author</b></dt>
4870 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4871 <dt><b>committer</b></dt>
4872 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4874 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4875 if ($have_pickaxe) {
4877 <dt><b>pickaxe</b></dt>
4878 <dd>All commits that caused the string to appear or disappear from any file (changes that
4879 added, removed or "modified" the string) will be listed. This search can take a while and
4880 takes a lot of strain on the server, so please use it wisely.</dd>
4888 my $head = git_get_head_hash
($project);
4889 if (!defined $hash) {
4892 if (!defined $page) {
4895 my $refs = git_get_references
();
4897 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4899 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
4901 if ($#commitlist >= 100) {
4903 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4904 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4908 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4909 git_print_header_div
('summary', $project);
4911 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
4916 ## ......................................................................
4917 ## feeds (RSS, Atom; OPML)
4920 my $format = shift || 'atom';
4921 my ($have_blame) = gitweb_check_feature
('blame');
4923 # Atom: http://www.atomenabled.org/developers/syndication/
4924 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4925 if ($format ne 'rss' && $format ne 'atom') {
4926 die_error
(undef, "Unknown web feed format");
4929 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4930 my $head = $hash || 'HEAD';
4931 my @commitlist = parse_commits
($head, 150);
4935 my $content_type = "application/$format+xml";
4936 if (defined $cgi->http('HTTP_ACCEPT') &&
4937 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4938 # browser (feed reader) prefers text/xml
4939 $content_type = 'text/xml';
4941 if (defined($commitlist[0])) {
4942 %latest_commit = %{$commitlist[0]};
4943 %latest_date = parse_date
($latest_commit{'author_epoch'});
4945 -type
=> $content_type,
4946 -charset
=> 'utf-8',
4947 -last_modified
=> $latest_date{'rfc2822'});
4950 -type
=> $content_type,
4951 -charset
=> 'utf-8');
4954 # Optimization: skip generating the body if client asks only
4955 # for Last-Modified date.
4956 return if ($cgi->request_method() eq 'HEAD');
4959 my $title = "$site_name - $project/$action";
4960 my $feed_type = 'log';
4961 if (defined $hash) {
4962 $title .= " - '$hash'";
4963 $feed_type = 'branch log';
4964 if (defined $file_name) {
4965 $title .= " :: $file_name";
4966 $feed_type = 'history';
4968 } elsif (defined $file_name) {
4969 $title .= " - $file_name";
4970 $feed_type = 'history';
4972 $title .= " $feed_type";
4973 my $descr = git_get_project_description
($project);
4974 if (defined $descr) {
4975 $descr = esc_html
($descr);
4977 $descr = "$project " .
4978 ($format eq 'rss' ?
'RSS' : 'Atom') .
4981 my $owner = git_get_project_owner
($project);
4982 $owner = esc_html
($owner);
4986 if (defined $file_name) {
4987 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
4988 } elsif (defined $hash) {
4989 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
4991 $alt_url = href
(-full
=>1, action
=>"summary");
4993 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
4994 if ($format eq 'rss') {
4996 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
4999 print "<title>$title</title>\n" .
5000 "<link>$alt_url</link>\n" .
5001 "<description>$descr</description>\n" .
5002 "<language>en</language>\n";
5003 } elsif ($format eq 'atom') {
5005 <feed xmlns="http://www.w3.org/2005/Atom">
5007 print "<title>$title</title>\n" .
5008 "<subtitle>$descr</subtitle>\n" .
5009 '<link rel="alternate" type="text/html" href="' .
5010 $alt_url . '" />' . "\n" .
5011 '<link rel="self" type="' . $content_type . '" href="' .
5012 $cgi->self_url() . '" />' . "\n" .
5013 "<id>" . href
(-full
=>1) . "</id>\n" .
5014 # use project owner for feed author
5015 "<author><name>$owner</name></author>\n";
5016 if (defined $favicon) {
5017 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5019 if (defined $logo_url) {
5020 # not twice as wide as tall: 72 x 27 pixels
5021 print "<logo>" . esc_url
($logo) . "</logo>\n";
5023 if (! %latest_date) {
5024 # dummy date to keep the feed valid until commits trickle in:
5025 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5027 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5032 for (my $i = 0; $i <= $#commitlist; $i++) {
5033 my %co = %{$commitlist[$i]};
5034 my $commit = $co{'id'};
5035 # we read 150, we always show 30 and the ones more recent than 48 hours
5036 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5039 my %cd = parse_date
($co{'author_epoch'});
5041 # get list of changed files
5042 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5043 $co{'parent'} || "--root",
5044 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
5046 my @difftree = map { chomp; $_ } <$fd>;
5050 # print element (entry, item)
5051 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5052 if ($format eq 'rss') {
5054 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5055 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5056 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5057 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5058 "<link>$co_url</link>\n" .
5059 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5060 "<content:encoded>" .
5062 } elsif ($format eq 'atom') {
5064 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5065 "<updated>$cd{'iso-8601'}</updated>\n" .
5067 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5068 if ($co{'author_email'}) {
5069 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5071 print "</author>\n" .
5072 # use committer for contributor
5074 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5075 if ($co{'committer_email'}) {
5076 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5078 print "</contributor>\n" .
5079 "<published>$cd{'iso-8601'}</published>\n" .
5080 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5081 "<id>$co_url</id>\n" .
5082 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5083 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5085 my $comment = $co{'comment'};
5087 foreach my $line (@
$comment) {
5088 $line = esc_html
($line);
5091 print "</pre><ul>\n";
5092 foreach my $difftree_line (@difftree) {
5093 my %difftree = parse_difftree_raw_line
($difftree_line);
5094 next if !$difftree{'from_id'};
5096 my $file = $difftree{'file'} || $difftree{'to_file'};
5100 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5101 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5102 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5103 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5104 -title
=> "diff"}, 'D');
5106 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5107 file_name
=>$file, hash_base
=>$commit),
5108 -title
=> "blame"}, 'B');
5110 # if this is not a feed of a file history
5111 if (!defined $file_name || $file_name ne $file) {
5112 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5113 file_name
=>$file, hash
=>$commit),
5114 -title
=> "history"}, 'H');
5116 $file = esc_path
($file);
5120 if ($format eq 'rss') {
5121 print "</ul>]]>\n" .
5122 "</content:encoded>\n" .
5124 } elsif ($format eq 'atom') {
5125 print "</ul>\n</div>\n" .
5132 if ($format eq 'rss') {
5133 print "</channel>\n</rss>\n";
5134 } elsif ($format eq 'atom') {
5148 my @list = git_get_projects_list
();
5150 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5152 <?xml version="1.0" encoding="utf-8"?>
5153 <opml version="1.0">
5155 <title>$site_name OPML Export</title>
5158 <outline text="git RSS feeds">
5161 foreach my $pr (@list) {
5163 my $head = git_get_head_hash
($proj{'path'});
5164 if (!defined $head) {
5167 $git_dir = "$projectroot/$proj{'path'}";
5168 my %co = parse_commit
($head);
5173 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5174 my $rss = "$my_url?p=$proj{'path'};a=rss";
5175 my $html = "$my_url?p=$proj{'path'};a=summary";
5176 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";