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|zip;
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 'zip') {
248 return ('x-zip', 'zip', '');
249 } elsif ($val eq 'none') {
253 return ($ctype, $suffix, $command);
256 sub gitweb_have_snapshot
{
257 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
258 my $have_snapshot = (defined $ctype && defined $suffix);
260 return $have_snapshot;
264 my ($val) = git_get_project_config
('grep', '--bool');
266 if ($val eq 'true') {
268 } elsif ($val eq 'false') {
275 sub feature_pickaxe
{
276 my ($val) = git_get_project_config
('pickaxe', '--bool');
278 if ($val eq 'true') {
280 } elsif ($val eq 'false') {
287 # checking HEAD file with -e is fragile if the repository was
288 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
290 sub check_head_link
{
292 my $headfile = "$dir/HEAD";
293 return ((-e
$headfile) ||
294 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
297 sub check_export_ok
{
299 return (check_head_link
($dir) &&
300 (!$export_ok || -e
"$dir/$export_ok"));
303 # rename detection options for git-diff and git-diff-tree
304 # - default is '-M', with the cost proportional to
305 # (number of removed files) * (number of new files).
306 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
307 # (number of changed files + number of removed files) * (number of new files)
308 # - even more costly is '-C', '--find-copies-harder' with cost
309 # (number of files in the original tree) * (number of new files)
310 # - one might want to include '-B' option, e.g. '-B', '-M'
311 our @diff_opts = ('-M'); # taken from git_commit
313 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
314 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
316 # version of the core git binary
317 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
319 $projects_list ||= $projectroot;
321 # ======================================================================
322 # input validation and dispatch
323 our $action = $cgi->param('a');
324 if (defined $action) {
325 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
326 die_error
(undef, "Invalid action parameter");
330 # parameters which are pathnames
331 our $project = $cgi->param('p');
332 if (defined $project) {
333 if (!validate_pathname
($project) ||
334 !(-d
"$projectroot/$project") ||
335 !check_head_link
("$projectroot/$project") ||
336 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
337 ($strict_export && !project_in_list
($project))) {
339 die_error
(undef, "No such project");
343 our $file_name = $cgi->param('f');
344 if (defined $file_name) {
345 if (!validate_pathname
($file_name)) {
346 die_error
(undef, "Invalid file parameter");
350 our $file_parent = $cgi->param('fp');
351 if (defined $file_parent) {
352 if (!validate_pathname
($file_parent)) {
353 die_error
(undef, "Invalid file parent parameter");
357 # parameters which are refnames
358 our $hash = $cgi->param('h');
360 if (!validate_refname
($hash)) {
361 die_error
(undef, "Invalid hash parameter");
365 our $hash_parent = $cgi->param('hp');
366 if (defined $hash_parent) {
367 if (!validate_refname
($hash_parent)) {
368 die_error
(undef, "Invalid hash parent parameter");
372 our $hash_base = $cgi->param('hb');
373 if (defined $hash_base) {
374 if (!validate_refname
($hash_base)) {
375 die_error
(undef, "Invalid hash base parameter");
379 our $hash_parent_base = $cgi->param('hpb');
380 if (defined $hash_parent_base) {
381 if (!validate_refname
($hash_parent_base)) {
382 die_error
(undef, "Invalid hash parent base parameter");
387 our $page = $cgi->param('pg');
389 if ($page =~ m/[^0-9]/) {
390 die_error
(undef, "Invalid page parameter");
394 our $searchtype = $cgi->param('st');
395 if (defined $searchtype) {
396 if ($searchtype =~ m/[^a-z]/) {
397 die_error
(undef, "Invalid searchtype parameter");
401 our $searchtext = $cgi->param('s');
403 if (defined $searchtext) {
404 if ($searchtype ne 'grep' and $searchtype ne 'pickaxe' and $searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
405 die_error
(undef, "Invalid search parameter");
407 if (length($searchtext) < 2) {
408 die_error
(undef, "At least two characters are required for search parameter");
410 $search_regexp = quotemeta $searchtext;
413 # now read PATH_INFO and use it as alternative to parameters
414 sub evaluate_path_info
{
415 return if defined $project;
416 my $path_info = $ENV{"PATH_INFO"};
417 return if !$path_info;
418 $path_info =~ s
,^/+,,;
419 return if !$path_info;
420 # find which part of PATH_INFO is project
421 $project = $path_info;
423 while ($project && !check_head_link
("$projectroot/$project")) {
424 $project =~ s
,/*[^/]*$,,;
427 $project = validate_pathname
($project);
429 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
430 ($strict_export && !project_in_list
($project))) {
434 # do not change any parameters if an action is given using the query string
436 $path_info =~ s
,^$project/*,,;
437 my ($refname, $pathname) = split(/:/, $path_info, 2);
438 if (defined $pathname) {
439 # we got "project.git/branch:filename" or "project.git/branch:dir/"
440 # we could use git_get_type(branch:pathname), but it needs $git_dir
441 $pathname =~ s
,^/+,,;
442 if (!$pathname || substr($pathname, -1) eq "/") {
446 $action ||= "blob_plain";
448 $hash_base ||= validate_refname
($refname);
449 $file_name ||= validate_pathname
($pathname);
450 } elsif (defined $refname) {
451 # we got "project.git/branch"
452 $action ||= "shortlog";
453 $hash ||= validate_refname
($refname);
456 evaluate_path_info
();
458 # path to the current git repository
460 $git_dir = "$projectroot/$project" if $project;
464 "blame" => \
&git_blame2
,
465 "blobdiff" => \
&git_blobdiff
,
466 "blobdiff_plain" => \
&git_blobdiff_plain
,
467 "blob" => \
&git_blob
,
468 "blob_plain" => \
&git_blob_plain
,
469 "commitdiff" => \
&git_commitdiff
,
470 "commitdiff_plain" => \
&git_commitdiff_plain
,
471 "commit" => \
&git_commit
,
472 "forks" => \
&git_forks
,
473 "heads" => \
&git_heads
,
474 "history" => \
&git_history
,
477 "atom" => \
&git_atom
,
478 "search" => \
&git_search
,
479 "search_help" => \
&git_search_help
,
480 "shortlog" => \
&git_shortlog
,
481 "summary" => \
&git_summary
,
483 "tags" => \
&git_tags
,
484 "tree" => \
&git_tree
,
485 "snapshot" => \
&git_snapshot
,
486 "object" => \
&git_object
,
487 # those below don't need $project
488 "opml" => \
&git_opml
,
489 "project_list" => \
&git_project_list
,
490 "project_index" => \
&git_project_index
,
493 if (!defined $action) {
495 $action = git_get_type
($hash);
496 } elsif (defined $hash_base && defined $file_name) {
497 $action = git_get_type
("$hash_base:$file_name");
498 } elsif (defined $project) {
501 $action = 'project_list';
504 if (!defined($actions{$action})) {
505 die_error
(undef, "Unknown action");
507 if ($action !~ m/^(opml|project_list|project_index)$/ &&
509 die_error
(undef, "Project needed");
511 $actions{$action}->();
514 ## ======================================================================
519 # default is to use -absolute url() i.e. $my_uri
520 my $href = $params{-full
} ?
$my_url : $my_uri;
522 # XXX: Warning: If you touch this, check the search form for updating,
533 hash_parent_base
=> "hpb",
539 my %mapping = @mapping;
541 $params{'project'} = $project unless exists $params{'project'};
543 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
545 # use PATH_INFO for project name
546 $href .= "/$params{'project'}" if defined $params{'project'};
547 delete $params{'project'};
549 # Summary just uses the project path URL
550 if (defined $params{'action'} && $params{'action'} eq 'summary') {
551 delete $params{'action'};
555 # now encode the parameters explicitly
557 for (my $i = 0; $i < @mapping; $i += 2) {
558 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
559 if (defined $params{$name}) {
560 push @result, $symbol . "=" . esc_param
($params{$name});
563 $href .= "?" . join(';', @result) if scalar @result;
569 ## ======================================================================
570 ## validation, quoting/unquoting and escaping
572 sub validate_pathname
{
573 my $input = shift || return undef;
575 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
576 # at the beginning, at the end, and between slashes.
577 # also this catches doubled slashes
578 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
582 if ($input =~ m!\0!) {
588 sub validate_refname
{
589 my $input = shift || return undef;
591 # textual hashes are O.K.
592 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
595 # it must be correct pathname
596 $input = validate_pathname
($input)
598 # restrictions on ref name according to git-check-ref-format
599 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
605 # quote unsafe chars, but keep the slash, even when it's not
606 # correct, but quoted slashes look too horrible in bookmarks
609 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
615 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
618 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
624 # replace invalid utf8 character with SUBSTITUTION sequence
629 $str = decode_utf8
($str);
630 $str = $cgi->escapeHTML($str);
631 if ($opts{'-nbsp'}) {
632 $str =~ s/ / /g;
634 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
638 # quote control characters and escape filename to HTML
643 $str = decode_utf8
($str);
644 $str = $cgi->escapeHTML($str);
645 if ($opts{'-nbsp'}) {
646 $str =~ s/ / /g;
648 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
652 # Make control characters "printable", using character escape codes (CEC)
655 my %es = ( # character escape codes, aka escape sequences
656 "\t" => '\t', # tab (HT)
657 "\n" => '\n', # line feed (LF)
658 "\r" => '\r', # carrige return (CR)
659 "\f" => '\f', # form feed (FF)
660 "\b" => '\b', # backspace (BS)
661 "\a" => '\a', # alarm (bell) (BEL)
662 "\e" => '\e', # escape (ESC)
663 "\013" => '\v', # vertical tab (VT)
664 "\000" => '\0', # nul character (NUL)
666 my $chr = ( (exists $es{$cntrl})
668 : sprintf('\%03o', ord($cntrl)) );
669 return "<span class=\"cntrl\">$chr</span>";
672 # Alternatively use unicode control pictures codepoints,
673 # Unicode "printable representation" (PR)
676 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
677 return "<span class=\"cntrl\">$chr</span>";
680 # git may return quoted and escaped filenames
686 my %es = ( # character escape codes, aka escape sequences
687 't' => "\t", # tab (HT, TAB)
688 'n' => "\n", # newline (NL)
689 'r' => "\r", # return (CR)
690 'f' => "\f", # form feed (FF)
691 'b' => "\b", # backspace (BS)
692 'a' => "\a", # alarm (bell) (BEL)
693 'e' => "\e", # escape (ESC)
694 'v' => "\013", # vertical tab (VT)
697 if ($seq =~ m/^[0-7]{1,3}$/) {
698 # octal char sequence
699 return chr(oct($seq));
700 } elsif (exists $es{$seq}) {
701 # C escape sequence, aka character escape code
704 # quoted ordinary character
708 if ($str =~ m/^"(.*)"$/) {
711 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
716 # escape tabs (convert tabs to spaces)
720 while ((my $pos = index($line, "\t")) != -1) {
721 if (my $count = (8 - ($pos % 8))) {
722 my $spaces = ' ' x
$count;
723 $line =~ s/\t/$spaces/;
730 sub project_in_list
{
732 my @list = git_get_projects_list
();
733 return @list && scalar(grep { $_->{'path'} eq $project } @list);
736 ## ----------------------------------------------------------------------
737 ## HTML aware string manipulation
742 my $add_len = shift || 10;
744 # allow only $len chars, but don't cut a word if it would fit in $add_len
745 # if it doesn't fit, cut it if it's still longer than the dots we would add
746 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
749 if (length($tail) > 4) {
751 $body =~ s/&[^;]*$//; # remove chopped character entities
756 ## ----------------------------------------------------------------------
757 ## functions returning short strings
759 # CSS class for given age value (in seconds)
765 } elsif ($age < 60*60*2) {
767 } elsif ($age < 60*60*24*2) {
774 # convert age in seconds to "nn units ago" string
779 if ($age > 60*60*24*365*2) {
780 $age_str = (int $age/60/60/24/365);
781 $age_str .= " years ago";
782 } elsif ($age > 60*60*24*(365/12)*2) {
783 $age_str = int $age/60/60/24/(365/12);
784 $age_str .= " months ago";
785 } elsif ($age > 60*60*24*7*2) {
786 $age_str = int $age/60/60/24/7;
787 $age_str .= " weeks ago";
788 } elsif ($age > 60*60*24*2) {
789 $age_str = int $age/60/60/24;
790 $age_str .= " days ago";
791 } elsif ($age > 60*60*2) {
792 $age_str = int $age/60/60;
793 $age_str .= " hours ago";
794 } elsif ($age > 60*2) {
795 $age_str = int $age/60;
796 $age_str .= " min ago";
799 $age_str .= " sec ago";
801 $age_str .= " right now";
806 # convert file mode in octal to symbolic file mode string
808 my $mode = oct shift;
810 if (S_ISDIR
($mode & S_IFMT
)) {
812 } elsif (S_ISLNK
($mode)) {
814 } elsif (S_ISREG
($mode)) {
815 # git cares only about the executable bit
816 if ($mode & S_IXUSR
) {
826 # convert file mode in octal to file type string
830 if ($mode !~ m/^[0-7]+$/) {
836 if (S_ISDIR
($mode & S_IFMT
)) {
838 } elsif (S_ISLNK
($mode)) {
840 } elsif (S_ISREG
($mode)) {
847 # convert file mode in octal to file type description string
851 if ($mode !~ m/^[0-7]+$/) {
857 if (S_ISDIR
($mode & S_IFMT
)) {
859 } elsif (S_ISLNK
($mode)) {
861 } elsif (S_ISREG
($mode)) {
862 if ($mode & S_IXUSR
) {
873 ## ----------------------------------------------------------------------
874 ## functions returning short HTML fragments, or transforming HTML fragments
875 ## which don't belong to other sections
877 # format line of commit message.
878 sub format_log_line_html
{
881 $line = esc_html
($line, -nbsp
=>1);
882 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
885 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
886 -class => "text"}, $hash_text);
887 $line =~ s/$hash_text/$link/;
892 # format marker of refs pointing to given object
893 sub format_ref_marker
{
894 my ($refs, $id) = @_;
897 if (defined $refs->{$id}) {
898 foreach my $ref (@
{$refs->{$id}}) {
899 my ($type, $name) = qw();
900 # e.g. tags/v2.6.11 or heads/next
901 if ($ref =~ m!^(.*?)s?/(.*)$!) {
909 $markers .= " <span class=\"$type\" title=\"$ref\">" .
910 esc_html
($name) . "</span>";
915 return ' <span class="refs">'. $markers . '</span>';
921 # format, perhaps shortened and with markers, title line
922 sub format_subject_html
{
923 my ($long, $short, $href, $extra) = @_;
924 $extra = '' unless defined($extra);
926 if (length($short) < length($long)) {
927 return $cgi->a({-href
=> $href, -class => "list subject",
928 -title
=> decode_utf8
($long)},
929 esc_html
($short) . $extra);
931 return $cgi->a({-href
=> $href, -class => "list subject"},
932 esc_html
($long) . $extra);
936 # format patch (diff) line (rather not to be used for diff headers)
937 sub format_diff_line
{
939 my ($from, $to) = @_;
944 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
946 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
947 if ($line =~ m/^\@{3}/) {
948 $diff_class = " chunk_header";
949 } elsif ($line =~ m/^\\/) {
950 $diff_class = " incomplete";
951 } elsif ($prefix =~ tr/+/+/) {
952 $diff_class = " add";
953 } elsif ($prefix =~ tr/-/-/) {
954 $diff_class = " rem";
957 # assume ordinary diff
958 my $char = substr($line, 0, 1);
960 $diff_class = " add";
961 } elsif ($char eq '-') {
962 $diff_class = " rem";
963 } elsif ($char eq '@') {
964 $diff_class = " chunk_header";
965 } elsif ($char eq "\\") {
966 $diff_class = " incomplete";
969 $line = untabify
($line);
970 if ($from && $to && $line =~ m/^\@{2} /) {
971 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
972 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
974 $from_lines = 0 unless defined $from_lines;
975 $to_lines = 0 unless defined $to_lines;
977 if ($from->{'href'}) {
978 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
979 -class=>"list"}, $from_text);
982 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
983 -class=>"list"}, $to_text);
985 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
986 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
987 return "<div class=\"diff$diff_class\">$line</div>\n";
988 } elsif ($from && $to && $line =~ m/^\@{3}/) {
989 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
990 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
992 @from_text = split(' ', $ranges);
993 for (my $i = 0; $i < @from_text; ++$i) {
994 ($from_start[$i], $from_nlines[$i]) =
995 (split(',', substr($from_text[$i], 1)), 0);
998 $to_text = pop @from_text;
999 $to_start = pop @from_start;
1000 $to_nlines = pop @from_nlines;
1002 $line = "<span class=\"chunk_info\">$prefix ";
1003 for (my $i = 0; $i < @from_text; ++$i) {
1004 if ($from->{'href'}[$i]) {
1005 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1006 -class=>"list"}, $from_text[$i]);
1008 $line .= $from_text[$i];
1012 if ($to->{'href'}) {
1013 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1014 -class=>"list"}, $to_text);
1018 $line .= " $prefix</span>" .
1019 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1020 return "<div class=\"diff$diff_class\">$line</div>\n";
1022 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1025 ## ----------------------------------------------------------------------
1026 ## git utility subroutines, invoking git commands
1028 # returns path to the core git executable and the --git-dir parameter as list
1030 return $GIT, '--git-dir='.$git_dir;
1033 # returns path to the core git executable and the --git-dir parameter as string
1035 return join(' ', git_cmd
());
1038 # get HEAD ref of given project as hash
1039 sub git_get_head_hash
{
1040 my $project = shift;
1041 my $o_git_dir = $git_dir;
1043 $git_dir = "$projectroot/$project";
1044 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1047 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1051 if (defined $o_git_dir) {
1052 $git_dir = $o_git_dir;
1057 # get type of given object
1061 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1063 close $fd or return;
1068 sub git_get_project_config
{
1069 my ($key, $type) = @_;
1071 return unless ($key);
1072 $key =~ s/^gitweb\.//;
1073 return if ($key =~ m/\W/);
1075 my @x = (git_cmd
(), 'config');
1076 if (defined $type) { push @x, $type; }
1078 push @x, "gitweb.$key";
1084 # get hash of given path at given ref
1085 sub git_get_hash_by_path
{
1087 my $path = shift || return undef;
1092 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1093 or die_error
(undef, "Open git-ls-tree failed");
1095 close $fd or return undef;
1097 if (!defined $line) {
1098 # there is no tree or hash given by $path at $base
1102 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1103 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1104 if (defined $type && $type ne $2) {
1105 # type doesn't match
1111 # get path of entry with given hash at given tree-ish (ref)
1112 # used to get 'from' filename for combined diff (merge commit) for renames
1113 sub git_get_path_by_hash
{
1114 my $base = shift || return;
1115 my $hash = shift || return;
1119 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1121 while (my $line = <$fd>) {
1124 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1125 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1126 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1135 ## ......................................................................
1136 ## git utility functions, directly accessing git repository
1138 sub git_get_project_description
{
1141 open my $fd, "$projectroot/$path/description" or return undef;
1144 if (defined $descr) {
1150 sub git_get_project_url_list
{
1153 open my $fd, "$projectroot/$path/cloneurl" or return;
1154 my @git_project_url_list = map { chomp; $_ } <$fd>;
1157 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
1160 sub git_get_projects_list
{
1165 $filter =~ s/\.git$//;
1167 my ($check_forks) = gitweb_check_feature
('forks');
1169 if (-d
$projects_list) {
1170 # search in directory
1171 my $dir = $projects_list . ($filter ?
"/$filter" : '');
1172 # remove the trailing "/"
1174 my $pfxlen = length("$dir");
1177 follow_fast
=> 1, # follow symbolic links
1178 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1180 # skip project-list toplevel, if we get it.
1181 return if (m!^[/.]$!);
1182 # only directories can be git repositories
1183 return unless (-d
$_);
1185 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1186 # we check related file in $projectroot
1187 if ($check_forks and $subdir =~ m
#/.#) {
1188 $File::Find
::prune
= 1;
1189 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1190 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
1191 $File::Find
::prune
= 1;
1196 } elsif (-f
$projects_list) {
1197 # read from file(url-encoded):
1198 # 'git%2Fgit.git Linus+Torvalds'
1199 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1200 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1202 open my ($fd), $projects_list or return;
1204 while (my $line = <$fd>) {
1206 my ($path, $owner) = split ' ', $line;
1207 $path = unescape
($path);
1208 $owner = unescape
($owner);
1209 if (!defined $path) {
1212 if ($filter ne '') {
1213 # looking for forks;
1214 my $pfx = substr($path, 0, length($filter));
1215 if ($pfx ne $filter) {
1218 my $sfx = substr($path, length($filter));
1219 if ($sfx !~ /^\/.*\
.git
$/) {
1222 } elsif ($check_forks) {
1224 foreach my $filter (keys %paths) {
1225 # looking for forks;
1226 my $pfx = substr($path, 0, length($filter));
1227 if ($pfx ne $filter) {
1230 my $sfx = substr($path, length($filter));
1231 if ($sfx !~ /^\/.*\
.git
$/) {
1234 # is a fork, don't include it in
1239 if (check_export_ok
("$projectroot/$path")) {
1242 owner
=> decode_utf8
($owner),
1245 (my $forks_path = $path) =~ s/\.git$//;
1246 $paths{$forks_path}++;
1254 sub git_get_project_owner
{
1255 my $project = shift;
1258 return undef unless $project;
1260 # read from file (url-encoded):
1261 # 'git%2Fgit.git Linus+Torvalds'
1262 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1263 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1264 if (-f
$projects_list) {
1265 open (my $fd , $projects_list);
1266 while (my $line = <$fd>) {
1268 my ($pr, $ow) = split ' ', $line;
1269 $pr = unescape
($pr);
1270 $ow = unescape
($ow);
1271 if ($pr eq $project) {
1272 $owner = decode_utf8
($ow);
1278 if (!defined $owner) {
1279 $owner = get_file_owner
("$projectroot/$project");
1285 sub git_get_last_activity
{
1289 $git_dir = "$projectroot/$path";
1290 open($fd, "-|", git_cmd
(), 'for-each-ref',
1291 '--format=%(committer)',
1292 '--sort=-committerdate',
1294 'refs/heads') or return;
1295 my $most_recent = <$fd>;
1296 close $fd or return;
1297 if (defined $most_recent &&
1298 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1300 my $age = time - $timestamp;
1301 return ($age, age_string
($age));
1305 sub git_get_references
{
1306 my $type = shift || "";
1308 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1309 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1310 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1311 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
1314 while (my $line = <$fd>) {
1316 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1317 if (defined $refs{$1}) {
1318 push @
{$refs{$1}}, $2;
1324 close $fd or return;
1328 sub git_get_rev_name_tags
{
1329 my $hash = shift || return undef;
1331 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1333 my $name_rev = <$fd>;
1336 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1339 # catches also '$hash undefined' output
1344 ## ----------------------------------------------------------------------
1345 ## parse to hash functions
1349 my $tz = shift || "-0000";
1352 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1353 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1354 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1355 $date{'hour'} = $hour;
1356 $date{'minute'} = $min;
1357 $date{'mday'} = $mday;
1358 $date{'day'} = $days[$wday];
1359 $date{'month'} = $months[$mon];
1360 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1361 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1362 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1363 $mday, $months[$mon], $hour ,$min;
1364 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1365 1900+$year, $mon, $mday, $hour ,$min, $sec;
1367 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1368 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1369 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1370 $date{'hour_local'} = $hour;
1371 $date{'minute_local'} = $min;
1372 $date{'tz_local'} = $tz;
1373 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1374 1900+$year, $mon+1, $mday,
1375 $hour, $min, $sec, $tz);
1384 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1385 $tag{'id'} = $tag_id;
1386 while (my $line = <$fd>) {
1388 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1389 $tag{'object'} = $1;
1390 } elsif ($line =~ m/^type (.+)$/) {
1392 } elsif ($line =~ m/^tag (.+)$/) {
1394 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1395 $tag{'author'} = $1;
1398 } elsif ($line =~ m/--BEGIN/) {
1399 push @comment, $line;
1401 } elsif ($line eq "") {
1405 push @comment, <$fd>;
1406 $tag{'comment'} = \
@comment;
1407 close $fd or return;
1408 if (!defined $tag{'name'}) {
1414 sub parse_commit_text
{
1415 my ($commit_text, $withparents) = @_;
1416 my @commit_lines = split '\n', $commit_text;
1419 pop @commit_lines; # Remove '\0'
1421 if (! @commit_lines) {
1425 my $header = shift @commit_lines;
1426 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1429 ($co{'id'}, my @parents) = split ' ', $header;
1430 while (my $line = shift @commit_lines) {
1431 last if $line eq "\n";
1432 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1434 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1436 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1438 $co{'author_epoch'} = $2;
1439 $co{'author_tz'} = $3;
1440 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1441 $co{'author_name'} = $1;
1442 $co{'author_email'} = $2;
1444 $co{'author_name'} = $co{'author'};
1446 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1447 $co{'committer'} = $1;
1448 $co{'committer_epoch'} = $2;
1449 $co{'committer_tz'} = $3;
1450 $co{'committer_name'} = $co{'committer'};
1451 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1452 $co{'committer_name'} = $1;
1453 $co{'committer_email'} = $2;
1455 $co{'committer_name'} = $co{'committer'};
1459 if (!defined $co{'tree'}) {
1462 $co{'parents'} = \
@parents;
1463 $co{'parent'} = $parents[0];
1465 foreach my $title (@commit_lines) {
1468 $co{'title'} = chop_str
($title, 80, 5);
1469 # remove leading stuff of merges to make the interesting part visible
1470 if (length($title) > 50) {
1471 $title =~ s/^Automatic //;
1472 $title =~ s/^merge (of|with) /Merge ... /i;
1473 if (length($title) > 50) {
1474 $title =~ s/(http|rsync):\/\///;
1476 if (length($title) > 50) {
1477 $title =~ s/(master|www|rsync)\.//;
1479 if (length($title) > 50) {
1480 $title =~ s/kernel.org:?//;
1482 if (length($title) > 50) {
1483 $title =~ s/\/pub\/scm//;
1486 $co{'title_short'} = chop_str
($title, 50, 5);
1490 if ($co{'title'} eq "") {
1491 $co{'title'} = $co{'title_short'} = '(no commit message)';
1493 # remove added spaces
1494 foreach my $line (@commit_lines) {
1497 $co{'comment'} = \
@commit_lines;
1499 my $age = time - $co{'committer_epoch'};
1501 $co{'age_string'} = age_string
($age);
1502 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1503 if ($age > 60*60*24*7*2) {
1504 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1505 $co{'age_string_age'} = $co{'age_string'};
1507 $co{'age_string_date'} = $co{'age_string'};
1508 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1514 my ($commit_id) = @_;
1519 open my $fd, "-|", git_cmd
(), "rev-list",
1525 or die_error
(undef, "Open git-rev-list failed");
1526 %co = parse_commit_text
(<$fd>, 1);
1533 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1541 open my $fd, "-|", git_cmd
(), "rev-list",
1543 ($arg ?
($arg) : ()),
1544 ("--max-count=" . $maxcount),
1545 ("--skip=" . $skip),
1548 ($filename ?
($filename) : ())
1549 or die_error
(undef, "Open git-rev-list failed");
1550 while (my $line = <$fd>) {
1551 my %co = parse_commit_text
($line);
1556 return wantarray ?
@cos : \
@cos;
1559 # parse ref from ref_file, given by ref_id, with given type
1561 my $ref_file = shift;
1563 my $type = shift || git_get_type
($ref_id);
1566 $ref_item{'type'} = $type;
1567 $ref_item{'id'} = $ref_id;
1568 $ref_item{'epoch'} = 0;
1569 $ref_item{'age'} = "unknown";
1570 if ($type eq "tag") {
1571 my %tag = parse_tag
($ref_id);
1572 $ref_item{'comment'} = $tag{'comment'};
1573 if ($tag{'type'} eq "commit") {
1574 my %co = parse_commit
($tag{'object'});
1575 $ref_item{'epoch'} = $co{'committer_epoch'};
1576 $ref_item{'age'} = $co{'age_string'};
1577 } elsif (defined($tag{'epoch'})) {
1578 my $age = time - $tag{'epoch'};
1579 $ref_item{'epoch'} = $tag{'epoch'};
1580 $ref_item{'age'} = age_string
($age);
1582 $ref_item{'reftype'} = $tag{'type'};
1583 $ref_item{'name'} = $tag{'name'};
1584 $ref_item{'refid'} = $tag{'object'};
1585 } elsif ($type eq "commit"){
1586 my %co = parse_commit
($ref_id);
1587 $ref_item{'reftype'} = "commit";
1588 $ref_item{'name'} = $ref_file;
1589 $ref_item{'title'} = $co{'title'};
1590 $ref_item{'refid'} = $ref_id;
1591 $ref_item{'epoch'} = $co{'committer_epoch'};
1592 $ref_item{'age'} = $co{'age_string'};
1594 $ref_item{'reftype'} = $type;
1595 $ref_item{'name'} = $ref_file;
1596 $ref_item{'refid'} = $ref_id;
1602 # parse line of git-diff-tree "raw" output
1603 sub parse_difftree_raw_line
{
1607 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1608 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1609 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1610 $res{'from_mode'} = $1;
1611 $res{'to_mode'} = $2;
1612 $res{'from_id'} = $3;
1614 $res{'status'} = $5;
1615 $res{'similarity'} = $6;
1616 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1617 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1619 $res{'file'} = unquote
($7);
1622 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1623 # combined diff (for merge commit)
1624 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1625 $res{'nparents'} = length($1);
1626 $res{'from_mode'} = [ split(' ', $2) ];
1627 $res{'to_mode'} = pop @
{$res{'from_mode'}};
1628 $res{'from_id'} = [ split(' ', $3) ];
1629 $res{'to_id'} = pop @
{$res{'from_id'}};
1630 $res{'status'} = [ split('', $4) ];
1631 $res{'to_file'} = unquote
($5);
1633 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1634 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1635 $res{'commit'} = $1;
1638 return wantarray ?
%res : \
%res;
1641 # parse line of git-ls-tree output
1642 sub parse_ls_tree_line
($;%) {
1647 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1648 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1656 $res{'name'} = unquote
($4);
1659 return wantarray ?
%res : \
%res;
1662 ## ......................................................................
1663 ## parse to array of hashes functions
1665 sub git_get_heads_list
{
1669 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1670 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
1671 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1674 while (my $line = <$fd>) {
1678 my ($refinfo, $committerinfo) = split(/\0/, $line);
1679 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1680 my ($committer, $epoch, $tz) =
1681 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1682 $name =~ s!^refs/heads/!!;
1684 $ref_item{'name'} = $name;
1685 $ref_item{'id'} = $hash;
1686 $ref_item{'title'} = $title || '(no commit message)';
1687 $ref_item{'epoch'} = $epoch;
1689 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1691 $ref_item{'age'} = "unknown";
1694 push @headslist, \
%ref_item;
1698 return wantarray ?
@headslist : \
@headslist;
1701 sub git_get_tags_list
{
1705 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1706 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
1707 '--format=%(objectname) %(objecttype) %(refname) '.
1708 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1711 while (my $line = <$fd>) {
1715 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1716 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1717 my ($creator, $epoch, $tz) =
1718 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1719 $name =~ s!^refs/tags/!!;
1721 $ref_item{'type'} = $type;
1722 $ref_item{'id'} = $id;
1723 $ref_item{'name'} = $name;
1724 if ($type eq "tag") {
1725 $ref_item{'subject'} = $title;
1726 $ref_item{'reftype'} = $reftype;
1727 $ref_item{'refid'} = $refid;
1729 $ref_item{'reftype'} = $type;
1730 $ref_item{'refid'} = $id;
1733 if ($type eq "tag" || $type eq "commit") {
1734 $ref_item{'epoch'} = $epoch;
1736 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1738 $ref_item{'age'} = "unknown";
1742 push @tagslist, \
%ref_item;
1746 return wantarray ?
@tagslist : \
@tagslist;
1749 ## ----------------------------------------------------------------------
1750 ## filesystem-related functions
1752 sub get_file_owner
{
1755 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1756 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1757 if (!defined $gcos) {
1761 $owner =~ s/[,;].*$//;
1762 return decode_utf8
($owner);
1765 ## ......................................................................
1766 ## mimetype related functions
1768 sub mimetype_guess_file
{
1769 my $filename = shift;
1770 my $mimemap = shift;
1771 -r
$mimemap or return undef;
1774 open(MIME
, $mimemap) or return undef;
1776 next if m/^#/; # skip comments
1777 my ($mime, $exts) = split(/\t+/);
1778 if (defined $exts) {
1779 my @exts = split(/\s+/, $exts);
1780 foreach my $ext (@exts) {
1781 $mimemap{$ext} = $mime;
1787 $filename =~ /\.([^.]*)$/;
1788 return $mimemap{$1};
1791 sub mimetype_guess
{
1792 my $filename = shift;
1794 $filename =~ /\./ or return undef;
1796 if ($mimetypes_file) {
1797 my $file = $mimetypes_file;
1798 if ($file !~ m!^/!) { # if it is relative path
1799 # it is relative to project
1800 $file = "$projectroot/$project/$file";
1802 $mime = mimetype_guess_file
($filename, $file);
1804 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1810 my $filename = shift;
1813 my $mime = mimetype_guess
($filename);
1814 $mime and return $mime;
1818 return $default_blob_plain_mimetype unless $fd;
1821 return 'text/plain' .
1822 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1823 } elsif (! $filename) {
1824 return 'application/octet-stream';
1825 } elsif ($filename =~ m/\.png$/i) {
1827 } elsif ($filename =~ m/\.gif$/i) {
1829 } elsif ($filename =~ m/\.jpe?g$/i) {
1830 return 'image/jpeg';
1832 return 'application/octet-stream';
1836 ## ======================================================================
1837 ## functions printing HTML: header, footer, error page
1839 sub git_header_html
{
1840 my $status = shift || "200 OK";
1841 my $expires = shift;
1843 my $title = "$site_name";
1844 if (defined $project) {
1845 $title .= " - " . decode_utf8
($project);
1846 if (defined $action) {
1847 $title .= "/$action";
1848 if (defined $file_name) {
1849 $title .= " - " . esc_path
($file_name);
1850 if ($action eq "tree" && $file_name !~ m
|/$|) {
1857 # require explicit support from the UA if we are to send the page as
1858 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1859 # we have to do this because MSIE sometimes globs '*/*', pretending to
1860 # support xhtml+xml but choking when it gets what it asked for.
1861 if (defined $cgi->http('HTTP_ACCEPT') &&
1862 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1863 $cgi->Accept('application/xhtml+xml') != 0) {
1864 $content_type = 'application/xhtml+xml';
1866 $content_type = 'text/html';
1868 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1869 -status
=> $status, -expires
=> $expires);
1870 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
1872 <?xml version="1.0" encoding="utf-8"?>
1873 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1874 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1875 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1876 <!-- git core binaries version $git_version -->
1878 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1879 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
1880 <meta name="robots" content="index, nofollow"/>
1881 <title>$title</title>
1883 # print out each stylesheet that exist
1884 if (defined $stylesheet) {
1885 #provides backwards capability for those people who define style sheet in a config file
1886 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1888 foreach my $stylesheet (@stylesheets) {
1889 next unless $stylesheet;
1890 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1893 if (defined $project) {
1894 printf('<link rel="alternate" title="%s log RSS feed" '.
1895 'href="%s" type="application/rss+xml" />'."\n",
1896 esc_param
($project), href
(action
=>"rss"));
1897 printf('<link rel="alternate" title="%s log Atom feed" '.
1898 'href="%s" type="application/atom+xml" />'."\n",
1899 esc_param
($project), href
(action
=>"atom"));
1901 printf('<link rel="alternate" title="%s projects list" '.
1902 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1903 $site_name, href
(project
=>undef, action
=>"project_index"));
1904 printf('<link rel="alternate" title="%s projects feeds" '.
1905 'href="%s" type="text/x-opml"/>'."\n",
1906 $site_name, href
(project
=>undef, action
=>"opml"));
1908 if (defined $favicon) {
1909 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
1915 if (-f
$site_header) {
1916 open (my $fd, $site_header);
1921 print "<div class=\"page_header\">\n" .
1922 $cgi->a({-href
=> esc_url
($logo_url),
1923 -title
=> $logo_label},
1924 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
1925 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1926 if (defined $project) {
1927 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1928 if (defined $action) {
1935 my ($have_search) = gitweb_check_feature
('search');
1936 if ((defined $project) && ($have_search)) {
1937 if (!defined $searchtext) {
1941 if (defined $hash_base) {
1942 $search_hash = $hash_base;
1943 } elsif (defined $hash) {
1944 $search_hash = $hash;
1946 $search_hash = "HEAD";
1948 $cgi->param("a", "search");
1949 $cgi->param("h", $search_hash);
1950 $cgi->param("p", $project);
1951 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1952 "<div class=\"search\">\n" .
1953 $cgi->hidden(-name
=> "p") . "\n" .
1954 $cgi->hidden(-name
=> "a") . "\n" .
1955 $cgi->hidden(-name
=> "h") . "\n" .
1956 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1957 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
1958 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1960 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1962 $cgi->end_form() . "\n";
1966 sub git_footer_html
{
1967 print "<div class=\"page_footer\">\n";
1968 if (defined $project) {
1969 my $descr = git_get_project_description
($project);
1970 if (defined $descr) {
1971 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1973 print $cgi->a({-href
=> href
(action
=>"rss"),
1974 -class => "rss_logo"}, "RSS") . " ";
1975 print $cgi->a({-href
=> href
(action
=>"atom"),
1976 -class => "rss_logo"}, "Atom") . "\n";
1978 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1979 -class => "rss_logo"}, "OPML") . " ";
1980 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1981 -class => "rss_logo"}, "TXT") . "\n";
1985 if (-f
$site_footer) {
1986 open (my $fd, $site_footer);
1996 my $status = shift || "403 Forbidden";
1997 my $error = shift || "Malformed query, file missing or permission denied";
1999 git_header_html
($status);
2001 <div class="page_body">
2011 ## ----------------------------------------------------------------------
2012 ## functions printing or outputting HTML: navigation
2014 sub git_print_page_nav
{
2015 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2016 $extra = '' if !defined $extra; # pager or formats
2018 my @navs = qw(summary shortlog log commit commitdiff tree);
2020 @navs = grep { $_ ne $suppress } @navs;
2023 my %arg = map { $_ => {action
=>$_} } @navs;
2024 if (defined $head) {
2025 for (qw(commit commitdiff)) {
2026 $arg{$_}{'hash'} = $head;
2028 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2029 for (qw(shortlog log)) {
2030 $arg{$_}{'hash'} = $head;
2034 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2035 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2037 print "<div class=\"page_nav\">\n" .
2039 map { $_ eq $current ?
2040 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2042 print "<br/>\n$extra<br/>\n" .
2046 sub format_paging_nav
{
2047 my ($action, $hash, $head, $page, $nrevs) = @_;
2051 if ($hash ne $head || $page) {
2052 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2054 $paging_nav .= "HEAD";
2058 $paging_nav .= " ⋅ " .
2059 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2060 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2062 $paging_nav .= " ⋅ prev";
2065 if ($nrevs >= (100 * ($page+1)-1)) {
2066 $paging_nav .= " ⋅ " .
2067 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2068 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2070 $paging_nav .= " ⋅ next";
2076 ## ......................................................................
2077 ## functions printing or outputting HTML: div
2079 sub git_print_header_div
{
2080 my ($action, $title, $hash, $hash_base) = @_;
2083 $args{'action'} = $action;
2084 $args{'hash'} = $hash if $hash;
2085 $args{'hash_base'} = $hash_base if $hash_base;
2087 print "<div class=\"header\">\n" .
2088 $cgi->a({-href
=> href
(%args), -class => "title"},
2089 $title ?
$title : $action) .
2093 #sub git_print_authorship (\%) {
2094 sub git_print_authorship
{
2097 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2098 print "<div class=\"author_date\">" .
2099 esc_html
($co->{'author_name'}) .
2101 if ($ad{'hour_local'} < 6) {
2102 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2103 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2105 printf(" (%02d:%02d %s)",
2106 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2111 sub git_print_page_path
{
2117 print "<div class=\"page_path\">";
2118 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2119 -title
=> 'tree root'}, decode_utf8
("[$project]"));
2121 if (defined $name) {
2122 my @dirname = split '/', $name;
2123 my $basename = pop @dirname;
2126 foreach my $dir (@dirname) {
2127 $fullname .= ($fullname ?
'/' : '') . $dir;
2128 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2130 -title
=> $fullname}, esc_path
($dir));
2133 if (defined $type && $type eq 'blob') {
2134 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2136 -title
=> $name}, esc_path
($basename));
2137 } elsif (defined $type && $type eq 'tree') {
2138 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2140 -title
=> $name}, esc_path
($basename));
2143 print esc_path
($basename);
2146 print "<br/></div>\n";
2149 # sub git_print_log (\@;%) {
2150 sub git_print_log
($;%) {
2154 if ($opts{'-remove_title'}) {
2155 # remove title, i.e. first line of log
2158 # remove leading empty lines
2159 while (defined $log->[0] && $log->[0] eq "") {
2166 foreach my $line (@
$log) {
2167 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2170 if (! $opts{'-remove_signoff'}) {
2171 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2174 # remove signoff lines
2181 # print only one empty line
2182 # do not print empty line after signoff
2184 next if ($empty || $signoff);
2190 print format_log_line_html
($line) . "<br/>\n";
2193 if ($opts{'-final_empty_line'}) {
2194 # end with single empty line
2195 print "<br/>\n" unless $empty;
2199 # return link target (what link points to)
2200 sub git_get_link_target
{
2205 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2209 $link_target = <$fd>;
2214 return $link_target;
2217 # given link target, and the directory (basedir) the link is in,
2218 # return target of link relative to top directory (top tree);
2219 # return undef if it is not possible (including absolute links).
2220 sub normalize_link_target
{
2221 my ($link_target, $basedir, $hash_base) = @_;
2223 # we can normalize symlink target only if $hash_base is provided
2224 return unless $hash_base;
2226 # absolute symlinks (beginning with '/') cannot be normalized
2227 return if (substr($link_target, 0, 1) eq '/');
2229 # normalize link target to path from top (root) tree (dir)
2232 $path = $basedir . '/' . $link_target;
2234 # we are in top (root) tree (dir)
2235 $path = $link_target;
2238 # remove //, /./, and /../
2240 foreach my $part (split('/', $path)) {
2241 # discard '.' and ''
2242 next if (!$part || $part eq '.');
2244 if ($part eq '..') {
2248 # link leads outside repository (outside top dir)
2252 push @path_parts, $part;
2255 $path = join('/', @path_parts);
2260 # print tree entry (row of git_tree), but without encompassing <tr> element
2261 sub git_print_tree_entry
{
2262 my ($t, $basedir, $hash_base, $have_blame) = @_;
2265 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2267 # The format of a table row is: mode list link. Where mode is
2268 # the mode of the entry, list is the name of the entry, an href,
2269 # and link is the action links of the entry.
2271 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2272 if ($t->{'type'} eq "blob") {
2273 print "<td class=\"list\">" .
2274 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2275 file_name
=>"$basedir$t->{'name'}", %base_key),
2276 -class => "list"}, esc_path
($t->{'name'}));
2277 if (S_ISLNK
(oct $t->{'mode'})) {
2278 my $link_target = git_get_link_target
($t->{'hash'});
2280 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2281 if (defined $norm_target) {
2283 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2284 file_name
=>$norm_target),
2285 -title
=> $norm_target}, esc_path
($link_target));
2287 print " -> " . esc_path
($link_target);
2292 print "<td class=\"link\">";
2293 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2294 file_name
=>"$basedir$t->{'name'}", %base_key)},
2298 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2299 file_name
=>"$basedir$t->{'name'}", %base_key)},
2302 if (defined $hash_base) {
2304 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2305 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2309 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2310 file_name
=>"$basedir$t->{'name'}")},
2314 } elsif ($t->{'type'} eq "tree") {
2315 print "<td class=\"list\">";
2316 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2317 file_name
=>"$basedir$t->{'name'}", %base_key)},
2318 esc_path
($t->{'name'}));
2320 print "<td class=\"link\">";
2321 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2322 file_name
=>"$basedir$t->{'name'}", %base_key)},
2324 if (defined $hash_base) {
2326 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2327 file_name
=>"$basedir$t->{'name'}")},
2334 ## ......................................................................
2335 ## functions printing large fragments of HTML
2337 sub fill_from_file_info
{
2338 my ($diff, @parents) = @_;
2340 $diff->{'from_file'} = [ ];
2341 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2342 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2343 if ($diff->{'status'}[$i] eq 'R' ||
2344 $diff->{'status'}[$i] eq 'C') {
2345 $diff->{'from_file'}[$i] =
2346 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2353 # parameters can be strings, or references to arrays of strings
2357 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @
$a == @
$b) {
2358 for (my $i = 0; $i < @
$a; ++$i) {
2359 return 0 unless ($a->[$i] eq $b->[$i]);
2362 } elsif (!ref($a) && !ref($b)) {
2370 sub git_difftree_body
{
2371 my ($difftree, $hash, @parents) = @_;
2372 my ($parent) = $parents[0];
2373 my ($have_blame) = gitweb_check_feature
('blame');
2374 print "<div class=\"list_head\">\n";
2375 if ($#{$difftree} > 10) {
2376 print(($#{$difftree} + 1) . " files changed:\n");
2380 print "<table class=\"" .
2381 (@parents > 1 ?
"combined " : "") .
2385 foreach my $line (@
{$difftree}) {
2387 if (ref($line) eq "HASH") {
2388 # pre-parsed (or generated by hand)
2391 $diff = parse_difftree_raw_line
($line);
2395 print "<tr class=\"dark\">\n";
2397 print "<tr class=\"light\">\n";
2401 if (exists $diff->{'nparents'}) { # combined diff
2403 fill_from_file_info
($diff, @parents)
2404 unless exists $diff->{'from_file'};
2406 if ($diff->{'to_id'} ne ('0' x
40)) {
2407 # file exists in the result (child) commit
2409 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2410 file_name
=>$diff->{'to_file'},
2412 -class => "list"}, esc_path
($diff->{'to_file'})) .
2416 esc_path
($diff->{'to_file'}) .
2420 if ($action eq 'commitdiff') {
2423 print "<td class=\"link\">" .
2424 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2429 my $has_history = 0;
2430 my $not_deleted = 0;
2431 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2432 my $hash_parent = $parents[$i];
2433 my $from_hash = $diff->{'from_id'}[$i];
2434 my $from_path = $diff->{'from_file'}[$i];
2435 my $status = $diff->{'status'}[$i];
2437 $has_history ||= ($status ne 'A');
2438 $not_deleted ||= ($status ne 'D');
2440 if ($status eq 'A') {
2441 print "<td class=\"link\" align=\"right\"> | </td>\n";
2442 } elsif ($status eq 'D') {
2443 print "<td class=\"link\">" .
2444 $cgi->a({-href
=> href
(action
=>"blob",
2447 file_name
=>$from_path)},
2451 if ($diff->{'to_id'} eq $from_hash) {
2452 print "<td class=\"link nochange\">";
2454 print "<td class=\"link\">";
2456 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2457 hash
=>$diff->{'to_id'},
2458 hash_parent
=>$from_hash,
2460 hash_parent_base
=>$hash_parent,
2461 file_name
=>$diff->{'to_file'},
2462 file_parent
=>$from_path)},
2468 print "<td class=\"link\">";
2470 print $cgi->a({-href
=> href
(action
=>"blob",
2471 hash
=>$diff->{'to_id'},
2472 file_name
=>$diff->{'to_file'},
2475 print " | " if ($has_history);
2478 print $cgi->a({-href
=> href
(action
=>"history",
2479 file_name
=>$diff->{'to_file'},
2486 next; # instead of 'else' clause, to avoid extra indent
2488 # else ordinary diff
2490 my ($to_mode_oct, $to_mode_str, $to_file_type);
2491 my ($from_mode_oct, $from_mode_str, $from_file_type);
2492 if ($diff->{'to_mode'} ne ('0' x
6)) {
2493 $to_mode_oct = oct $diff->{'to_mode'};
2494 if (S_ISREG
($to_mode_oct)) { # only for regular file
2495 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2497 $to_file_type = file_type
($diff->{'to_mode'});
2499 if ($diff->{'from_mode'} ne ('0' x
6)) {
2500 $from_mode_oct = oct $diff->{'from_mode'};
2501 if (S_ISREG
($to_mode_oct)) { # only for regular file
2502 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2504 $from_file_type = file_type
($diff->{'from_mode'});
2507 if ($diff->{'status'} eq "A") { # created
2508 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2509 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2510 $mode_chng .= "]</span>";
2512 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2513 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2514 -class => "list"}, esc_path
($diff->{'file'}));
2516 print "<td>$mode_chng</td>\n";
2517 print "<td class=\"link\">";
2518 if ($action eq 'commitdiff') {
2521 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2524 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2525 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2529 } elsif ($diff->{'status'} eq "D") { # deleted
2530 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2532 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2533 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2534 -class => "list"}, esc_path
($diff->{'file'}));
2536 print "<td>$mode_chng</td>\n";
2537 print "<td class=\"link\">";
2538 if ($action eq 'commitdiff') {
2541 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2544 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2545 hash_base
=>$parent, file_name
=>$diff->{'file'})},
2548 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2549 file_name
=>$diff->{'file'})},
2552 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2553 file_name
=>$diff->{'file'})},
2557 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2558 my $mode_chnge = "";
2559 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2560 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2561 if ($from_file_type ne $to_file_type) {
2562 $mode_chnge .= " from $from_file_type to $to_file_type";
2564 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2565 if ($from_mode_str && $to_mode_str) {
2566 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2567 } elsif ($to_mode_str) {
2568 $mode_chnge .= " mode: $to_mode_str";
2571 $mode_chnge .= "]</span>\n";
2574 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2575 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2576 -class => "list"}, esc_path
($diff->{'file'}));
2578 print "<td>$mode_chnge</td>\n";
2579 print "<td class=\"link\">";
2580 if ($action eq 'commitdiff') {
2583 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2585 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2586 # "commit" view and modified file (not onlu mode changed)
2587 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2588 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2589 hash_base
=>$hash, hash_parent_base
=>$parent,
2590 file_name
=>$diff->{'file'})},
2594 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2595 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2598 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2599 file_name
=>$diff->{'file'})},
2602 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2603 file_name
=>$diff->{'file'})},
2607 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
2608 my %status_name = ('R' => 'moved', 'C' => 'copied');
2609 my $nstatus = $status_name{$diff->{'status'}};
2611 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2612 # mode also for directories, so we cannot use $to_mode_str
2613 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2616 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2617 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
2618 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
2619 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2620 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2621 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
2622 -class => "list"}, esc_path
($diff->{'from_file'})) .
2623 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2624 "<td class=\"link\">";
2625 if ($action eq 'commitdiff') {
2628 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2630 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2631 # "commit" view and modified file (not only pure rename or copy)
2632 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2633 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2634 hash_base
=>$hash, hash_parent_base
=>$parent,
2635 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
2639 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2640 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
2643 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2644 file_name
=>$diff->{'to_file'})},
2647 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2648 file_name
=>$diff->{'to_file'})},
2652 } # we should not encounter Unmerged (U) or Unknown (X) status
2658 sub git_patchset_body
{
2659 my ($fd, $difftree, $hash, @hash_parents) = @_;
2660 my ($hash_parent) = $hash_parents[0];
2663 my $patch_number = 0;
2668 print "<div class=\"patchset\">\n";
2670 # skip to first patch
2671 while ($patch_line = <$fd>) {
2674 last if ($patch_line =~ m/^diff /);
2678 while ($patch_line) {
2680 my ($from_id, $to_id);
2683 #assert($patch_line =~ m/^diff /) if DEBUG;
2684 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2686 push @diff_header, $patch_line;
2688 # extended diff header
2690 while ($patch_line = <$fd>) {
2693 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2695 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2698 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2699 $from_id = [ split(',', $1) ];
2703 push @diff_header, $patch_line;
2705 my $last_patch_line = $patch_line;
2707 # check if current patch belong to current raw line
2708 # and parse raw git-diff line if needed
2709 if (defined $diffinfo &&
2710 defined $from_id && defined $to_id &&
2711 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
2712 $diffinfo->{'to_id'} eq $to_id) {
2713 # this is continuation of a split patch
2714 print "<div class=\"patch cont\">\n";
2716 # advance raw git-diff output if needed
2717 $patch_idx++ if defined $diffinfo;
2719 # read and prepare patch information
2720 if (ref($difftree->[$patch_idx]) eq "HASH") {
2721 # pre-parsed (or generated by hand)
2722 $diffinfo = $difftree->[$patch_idx];
2724 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2726 if ($diffinfo->{'nparents'}) {
2730 fill_from_file_info
($diffinfo, @hash_parents)
2731 unless exists $diffinfo->{'from_file'};
2732 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2733 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2734 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2735 $from{'href'}[$i] = href
(action
=>"blob",
2736 hash_base
=>$hash_parents[$i],
2737 hash
=>$diffinfo->{'from_id'}[$i],
2738 file_name
=>$from{'file'}[$i]);
2740 $from{'href'}[$i] = undef;
2744 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2745 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2746 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2747 hash
=>$diffinfo->{'from_id'},
2748 file_name
=>$from{'file'});
2750 delete $from{'href'};
2754 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2755 if ($diffinfo->{'to_id'} ne ('0' x
40)) { # file exists in result
2756 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2757 hash
=>$diffinfo->{'to_id'},
2758 file_name
=>$to{'file'});
2762 # this is first patch for raw difftree line with $patch_idx index
2763 # we index @$difftree array from 0, but number patches from 1
2764 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2767 # print "git diff" header
2768 $patch_line = shift @diff_header;
2769 if ($diffinfo->{'nparents'}) {
2772 $patch_line =~ s!^(diff (.*?) )"?.*$!$1!;
2774 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2775 esc_path
($to{'file'}));
2776 } else { # file was deleted
2777 $patch_line .= esc_path
($to{'file'});
2782 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2783 if ($from{'href'}) {
2784 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2785 'a/' . esc_path
($from{'file'}));
2786 } else { # file was added
2787 $patch_line .= 'a/' . esc_path
($from{'file'});
2791 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2792 'b/' . esc_path
($to{'file'}));
2793 } else { # file was deleted
2794 $patch_line .= 'b/' . esc_path
($to{'file'});
2798 print "<div class=\"diff header\">$patch_line</div>\n";
2800 # print extended diff header
2801 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2803 foreach $patch_line (@diff_header) {
2805 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2806 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2807 esc_path
($from{'file'}));
2809 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2810 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2811 esc_path
($to{'file'}));
2813 # match single <mode>
2814 if ($patch_line =~ m/\s(\d{6})$/) {
2815 $patch_line .= '<span class="info"> (' .
2816 file_type_long
($1) .
2820 if ($patch_line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
2821 # can match only for combined diff
2822 $patch_line = 'index ';
2823 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2824 if ($from{'href'}[$i]) {
2825 $patch_line .= $cgi->a({-href
=>$from{'href'}[$i],
2827 substr($diffinfo->{'from_id'}[$i],0,7));
2829 $patch_line .= '0' x
7;
2832 $patch_line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
2834 $patch_line .= '..';
2836 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2837 substr($diffinfo->{'to_id'},0,7));
2839 $patch_line .= '0' x
7;
2842 } elsif ($patch_line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
2843 # can match only for ordinary diff
2844 my ($from_link, $to_link);
2845 if ($from{'href'}) {
2846 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2847 substr($diffinfo->{'from_id'},0,7));
2849 $from_link = '0' x
7;
2852 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2853 substr($diffinfo->{'to_id'},0,7));
2858 # my ($from_hash, $to_hash) =
2859 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2860 # my ($from_id, $to_id) =
2861 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2862 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2864 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2865 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2867 print $patch_line . "<br/>\n";
2869 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2871 # from-file/to-file diff header
2872 $patch_line = $last_patch_line;
2873 if (! $patch_line) {
2874 print "</div>\n"; # class="patch"
2877 next PATCH
if ($patch_line =~ m/^diff /);
2878 #assert($patch_line =~ m/^---/) if DEBUG;
2879 if (!$diffinfo->{'nparents'} && # not from-file line for combined diff
2880 $from{'href'} && $patch_line =~ m!^--- "?a/!) {
2881 $patch_line = '--- a/' .
2882 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2883 esc_path
($from{'file'}));
2885 print "<div class=\"diff from_file\">$patch_line</div>\n";
2887 $patch_line = <$fd>;
2890 #assert($patch_line =~ m/^+++/) if DEBUG;
2891 if ($to{'href'} && $patch_line =~ m!^\+\+\+ "?b/!) {
2892 $patch_line = '+++ b/' .
2893 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2894 esc_path
($to{'file'}));
2896 print "<div class=\"diff to_file\">$patch_line</div>\n";
2900 while ($patch_line = <$fd>) {
2903 next PATCH
if ($patch_line =~ m/^diff /);
2905 print format_diff_line
($patch_line, \
%from, \
%to);
2909 print "</div>\n"; # class="patch"
2912 if ($patch_number == 0) {
2913 if (@hash_parents > 1) {
2914 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
2916 print "<div class=\"diff nodifferences\">No differences found</div>\n";
2920 print "</div>\n"; # class="patchset"
2923 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2925 sub git_project_list_body
{
2926 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2928 my ($check_forks) = gitweb_check_feature
('forks');
2931 foreach my $pr (@
$projlist) {
2932 my (@aa) = git_get_last_activity
($pr->{'path'});
2936 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2937 if (!defined $pr->{'descr'}) {
2938 my $descr = git_get_project_description
($pr->{'path'}) || "";
2939 $pr->{'descr_long'} = decode_utf8
($descr);
2940 $pr->{'descr'} = chop_str
($descr, 25, 5);
2942 if (!defined $pr->{'owner'}) {
2943 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2946 my $pname = $pr->{'path'};
2947 if (($pname =~ s/\.git$//) &&
2948 ($pname !~ /\/$/) &&
2949 (-d
"$projectroot/$pname")) {
2950 $pr->{'forks'} = "-d $projectroot/$pname";
2956 push @projects, $pr;
2959 $order ||= $default_projects_order;
2960 $from = 0 unless defined $from;
2961 $to = $#projects if (!defined $to || $#projects < $to);
2963 print "<table class=\"project_list\">\n";
2964 unless ($no_header) {
2967 print "<th></th>\n";
2969 if ($order eq "project") {
2970 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2971 print "<th>Project</th>\n";
2974 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2975 -class => "header"}, "Project") .
2978 if ($order eq "descr") {
2979 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2980 print "<th>Description</th>\n";
2983 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2984 -class => "header"}, "Description") .
2987 if ($order eq "owner") {
2988 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2989 print "<th>Owner</th>\n";
2992 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2993 -class => "header"}, "Owner") .
2996 if ($order eq "age") {
2997 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2998 print "<th>Last Change</th>\n";
3001 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3002 -class => "header"}, "Last Change") .
3005 print "<th></th>\n" .
3009 for (my $i = $from; $i <= $to; $i++) {
3010 my $pr = $projects[$i];
3012 print "<tr class=\"dark\">\n";
3014 print "<tr class=\"light\">\n";
3019 if ($pr->{'forks'}) {
3020 print "<!-- $pr->{'forks'} -->\n";
3021 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3025 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3026 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3027 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3028 -class => "list", -title
=> $pr->{'descr_long'}},
3029 esc_html
($pr->{'descr'})) . "</td>\n" .
3030 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
3031 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3032 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
3033 "<td class=\"link\">" .
3034 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3035 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3036 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3037 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3038 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3042 if (defined $extra) {
3045 print "<td></td>\n";
3047 print "<td colspan=\"5\">$extra</td>\n" .
3053 sub git_shortlog_body
{
3054 # uses global variable $project
3055 my ($commitlist, $from, $to, $refs, $extra) = @_;
3057 my $have_snapshot = gitweb_have_snapshot
();
3059 $from = 0 unless defined $from;
3060 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3062 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3064 for (my $i = $from; $i <= $to; $i++) {
3065 my %co = %{$commitlist->[$i]};
3066 my $commit = $co{'id'};
3067 my $ref = format_ref_marker
($refs, $commit);
3069 print "<tr class=\"dark\">\n";
3071 print "<tr class=\"light\">\n";
3074 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3075 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3076 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3078 print format_subject_html
($co{'title'}, $co{'title_short'},
3079 href
(action
=>"commit", hash
=>$commit), $ref);
3081 "<td class=\"link\">" .
3082 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3083 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3084 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3085 if ($have_snapshot) {
3086 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
3091 if (defined $extra) {
3093 "<td colspan=\"4\">$extra</td>\n" .
3099 sub git_history_body
{
3100 # Warning: assumes constant type (blob or tree) during history
3101 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3103 $from = 0 unless defined $from;
3104 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3106 print "<table class=\"history\" cellspacing=\"0\">\n";
3108 for (my $i = $from; $i <= $to; $i++) {
3109 my %co = %{$commitlist->[$i]};
3113 my $commit = $co{'id'};
3115 my $ref = format_ref_marker
($refs, $commit);
3118 print "<tr class=\"dark\">\n";
3120 print "<tr class=\"light\">\n";
3123 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3124 # shortlog uses chop_str($co{'author_name'}, 10)
3125 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3127 # originally git_history used chop_str($co{'title'}, 50)
3128 print format_subject_html
($co{'title'}, $co{'title_short'},
3129 href
(action
=>"commit", hash
=>$commit), $ref);
3131 "<td class=\"link\">" .
3132 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3133 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3135 if ($ftype eq 'blob') {
3136 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3137 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3138 if (defined $blob_current && defined $blob_parent &&
3139 $blob_current ne $blob_parent) {
3141 $cgi->a({-href
=> href
(action
=>"blobdiff",
3142 hash
=>$blob_current, hash_parent
=>$blob_parent,
3143 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3144 file_name
=>$file_name)},
3151 if (defined $extra) {
3153 "<td colspan=\"4\">$extra</td>\n" .
3160 # uses global variable $project
3161 my ($taglist, $from, $to, $extra) = @_;
3162 $from = 0 unless defined $from;
3163 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3165 print "<table class=\"tags\" cellspacing=\"0\">\n";
3167 for (my $i = $from; $i <= $to; $i++) {
3168 my $entry = $taglist->[$i];
3170 my $comment = $tag{'subject'};
3172 if (defined $comment) {
3173 $comment_short = chop_str
($comment, 30, 5);
3176 print "<tr class=\"dark\">\n";
3178 print "<tr class=\"light\">\n";
3181 if (defined $tag{'age'}) {
3182 print "<td><i>$tag{'age'}</i></td>\n";
3184 print "<td></td>\n";
3187 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3188 -class => "list name"}, esc_html
($tag{'name'})) .
3191 if (defined $comment) {
3192 print format_subject_html
($comment, $comment_short,
3193 href
(action
=>"tag", hash
=>$tag{'id'}));
3196 "<td class=\"selflink\">";
3197 if ($tag{'type'} eq "tag") {
3198 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3203 "<td class=\"link\">" . " | " .
3204 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3205 if ($tag{'reftype'} eq "commit") {
3206 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3207 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3208 } elsif ($tag{'reftype'} eq "blob") {
3209 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3214 if (defined $extra) {
3216 "<td colspan=\"5\">$extra</td>\n" .
3222 sub git_heads_body
{
3223 # uses global variable $project
3224 my ($headlist, $head, $from, $to, $extra) = @_;
3225 $from = 0 unless defined $from;
3226 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3228 print "<table class=\"heads\" cellspacing=\"0\">\n";
3230 for (my $i = $from; $i <= $to; $i++) {
3231 my $entry = $headlist->[$i];
3233 my $curr = $ref{'id'} eq $head;
3235 print "<tr class=\"dark\">\n";
3237 print "<tr class=\"light\">\n";
3240 print "<td><i>$ref{'age'}</i></td>\n" .
3241 ($curr ?
"<td class=\"current_head\">" : "<td>") .
3242 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3243 -class => "list name"},esc_html
($ref{'name'})) .
3245 "<td class=\"link\">" .
3246 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3247 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3248 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3252 if (defined $extra) {
3254 "<td colspan=\"3\">$extra</td>\n" .
3260 sub git_search_grep_body
{
3261 my ($commitlist, $from, $to, $extra) = @_;
3262 $from = 0 unless defined $from;
3263 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3265 print "<table class=\"grep\" cellspacing=\"0\">\n";
3267 for (my $i = $from; $i <= $to; $i++) {
3268 my %co = %{$commitlist->[$i]};
3272 my $commit = $co{'id'};
3274 print "<tr class=\"dark\">\n";
3276 print "<tr class=\"light\">\n";
3279 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3280 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3282 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3283 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3284 my $comment = $co{'comment'};
3285 foreach my $line (@
$comment) {
3286 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3287 my $lead = esc_html
($1) || "";
3288 $lead = chop_str
($lead, 30, 10);
3289 my $match = esc_html
($2) || "";
3290 my $trail = esc_html
($3) || "";
3291 $trail = chop_str
($trail, 30, 10);
3292 my $text = "$lead<span class=\"match\">$match</span>$trail";
3293 print chop_str
($text, 80, 5) . "<br/>\n";
3297 "<td class=\"link\">" .
3298 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3300 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3304 if (defined $extra) {
3306 "<td colspan=\"3\">$extra</td>\n" .
3312 ## ======================================================================
3313 ## ======================================================================
3316 sub git_project_list
{
3317 my $order = $cgi->param('o');
3318 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3319 die_error
(undef, "Unknown order parameter");
3322 my @list = git_get_projects_list
();
3324 die_error
(undef, "No projects found");
3328 if (-f
$home_text) {
3329 print "<div class=\"index_include\">\n";
3330 open (my $fd, $home_text);
3335 git_project_list_body
(\
@list, $order);
3340 my $order = $cgi->param('o');
3341 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3342 die_error
(undef, "Unknown order parameter");
3345 my @list = git_get_projects_list
($project);
3347 die_error
(undef, "No forks found");
3351 git_print_page_nav
('','');
3352 git_print_header_div
('summary', "$project forks");
3353 git_project_list_body
(\
@list, $order);
3357 sub git_project_index
{
3358 my @projects = git_get_projects_list
($project);
3361 -type
=> 'text/plain',
3362 -charset
=> 'utf-8',
3363 -content_disposition
=> 'inline; filename="index.aux"');
3365 foreach my $pr (@projects) {
3366 if (!exists $pr->{'owner'}) {
3367 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3370 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3371 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3372 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3373 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3377 print "$path $owner\n";
3382 my $descr = git_get_project_description
($project) || "none";
3383 my %co = parse_commit
("HEAD");
3384 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3385 my $head = $co{'id'};
3387 my $owner = git_get_project_owner
($project);
3389 my $refs = git_get_references
();
3390 # These get_*_list functions return one more to allow us to see if
3391 # there are more ...
3392 my @taglist = git_get_tags_list
(16);
3393 my @headlist = git_get_heads_list
(16);
3395 my ($check_forks) = gitweb_check_feature
('forks');
3398 @forklist = git_get_projects_list
($project);
3402 git_print_page_nav
('summary','', $head);
3404 print "<div class=\"title\"> </div>\n";
3405 print "<table cellspacing=\"0\">\n" .
3406 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3407 "<tr><td>owner</td><td>$owner</td></tr>\n";
3408 if (defined $cd{'rfc2822'}) {
3409 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3412 # use per project git URL list in $projectroot/$project/cloneurl
3413 # or make project git URL from git base URL and project name
3414 my $url_tag = "URL";
3415 my @url_list = git_get_project_url_list
($project);
3416 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3417 foreach my $git_url (@url_list) {
3418 next unless $git_url;
3419 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3424 if (-s
"$projectroot/$project/README.html") {
3425 if (open my $fd, "$projectroot/$project/README.html") {
3426 print "<div class=\"title\">readme</div>\n";
3427 print $_ while (<$fd>);
3432 # we need to request one more than 16 (0..15) to check if
3434 my @commitlist = $head ? parse_commits
($head, 17) : ();
3436 git_print_header_div
('shortlog');
3437 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3438 $#commitlist <= 15 ?
undef :
3439 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3443 git_print_header_div
('tags');
3444 git_tags_body
(\
@taglist, 0, 15,
3445 $#taglist <= 15 ?
undef :
3446 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3450 git_print_header_div
('heads');
3451 git_heads_body
(\
@headlist, $head, 0, 15,
3452 $#headlist <= 15 ?
undef :
3453 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3457 git_print_header_div
('forks');
3458 git_project_list_body
(\
@forklist, undef, 0, 15,
3459 $#forklist <= 15 ?
undef :
3460 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3468 my $head = git_get_head_hash
($project);
3470 git_print_page_nav
('','', $head,undef,$head);
3471 my %tag = parse_tag
($hash);
3474 die_error
(undef, "Unknown tag object");
3477 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3478 print "<div class=\"title_text\">\n" .
3479 "<table cellspacing=\"0\">\n" .
3481 "<td>object</td>\n" .
3482 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3483 $tag{'object'}) . "</td>\n" .
3484 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3485 $tag{'type'}) . "</td>\n" .
3487 if (defined($tag{'author'})) {
3488 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3489 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3490 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3491 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3494 print "</table>\n\n" .
3496 print "<div class=\"page_body\">";
3497 my $comment = $tag{'comment'};
3498 foreach my $line (@
$comment) {
3500 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3510 my ($have_blame) = gitweb_check_feature
('blame');
3512 die_error
('403 Permission denied', "Permission denied");
3514 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3515 $hash_base ||= git_get_head_hash
($project);
3516 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3517 my %co = parse_commit
($hash_base)
3518 or die_error
(undef, "Reading commit failed");
3519 if (!defined $hash) {
3520 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3521 or die_error
(undef, "Error looking up file");
3523 $ftype = git_get_type
($hash);
3524 if ($ftype !~ "blob") {
3525 die_error
('400 Bad Request', "Object is not a blob");
3527 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3528 $file_name, $hash_base)
3529 or die_error
(undef, "Open git-blame failed");
3532 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3535 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3538 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3540 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3541 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3542 git_print_page_path
($file_name, $ftype, $hash_base);
3543 my @rev_color = (qw(light2 dark2));
3544 my $num_colors = scalar(@rev_color);
3545 my $current_color = 0;
3548 <div class="page_body">
3549 <table class="blame">
3550 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3555 last unless defined $_;
3556 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3557 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3558 if (!exists $metainfo{$full_rev}) {
3559 $metainfo{$full_rev} = {};
3561 my $meta = $metainfo{$full_rev};
3564 if (/^(\S+) (.*)$/) {
3570 my $rev = substr($full_rev, 0, 8);
3571 my $author = $meta->{'author'};
3572 my %date = parse_date
($meta->{'author-time'},
3573 $meta->{'author-tz'});
3574 my $date = $date{'iso-tz'};
3576 $current_color = ++$current_color % $num_colors;
3578 print "<tr class=\"$rev_color[$current_color]\">\n";
3580 print "<td class=\"sha1\"";
3581 print " title=\"". esc_html
($author) . ", $date\"";
3582 print " rowspan=\"$group_size\"" if ($group_size > 1);
3584 print $cgi->a({-href
=> href
(action
=>"commit",
3586 file_name
=>$file_name)},
3590 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3591 or die_error
(undef, "Open git-rev-parse failed");
3592 my $parent_commit = <$dd>;
3594 chomp($parent_commit);
3595 my $blamed = href
(action
=> 'blame',
3596 file_name
=> $meta->{'filename'},
3597 hash_base
=> $parent_commit);
3598 print "<td class=\"linenr\">";
3599 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3601 -class => "linenr" },
3604 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3610 or print "Reading blob failed\n";
3617 my ($have_blame) = gitweb_check_feature
('blame');
3619 die_error
('403 Permission denied', "Permission denied");
3621 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3622 $hash_base ||= git_get_head_hash
($project);
3623 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3624 my %co = parse_commit
($hash_base)
3625 or die_error
(undef, "Reading commit failed");
3626 if (!defined $hash) {
3627 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3628 or die_error
(undef, "Error lookup file");
3630 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3631 or die_error
(undef, "Open git-annotate failed");
3634 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3637 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3640 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3642 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3643 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3644 git_print_page_path
($file_name, 'blob', $hash_base);
3645 print "<div class=\"page_body\">\n";
3647 <table class="blame">
3656 my @line_class = (qw(light dark));
3657 my $line_class_len = scalar (@line_class);
3658 my $line_class_num = $#line_class;
3659 while (my $line = <$fd>) {
3671 $line_class_num = ($line_class_num + 1) % $line_class_len;
3673 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3680 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
3683 $short_rev = substr ($long_rev, 0, 8);
3684 $age = time () - $time;
3685 $age_str = age_string
($age);
3686 $age_str =~ s/ / /g;
3687 $age_class = age_class
($age);
3688 $author = esc_html
($author);
3689 $author =~ s/ / /g;
3691 $data = untabify
($data);
3692 $data = esc_html
($data);
3695 <tr class="$line_class[$line_class_num]">
3696 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3697 <td class="$age_class">$age_str</td>
3699 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3700 <td class="pre">$data</td>
3703 } # while (my $line = <$fd>)
3704 print "</table>\n\n";
3706 or print "Reading blob failed.\n";
3712 my $head = git_get_head_hash
($project);
3714 git_print_page_nav
('','', $head,undef,$head);
3715 git_print_header_div
('summary', $project);
3717 my @tagslist = git_get_tags_list
();
3719 git_tags_body
(\
@tagslist);
3725 my $head = git_get_head_hash
($project);
3727 git_print_page_nav
('','', $head,undef,$head);
3728 git_print_header_div
('summary', $project);
3730 my @headslist = git_get_heads_list
();
3732 git_heads_body
(\
@headslist, $head);
3737 sub git_blob_plain
{
3740 if (!defined $hash) {
3741 if (defined $file_name) {
3742 my $base = $hash_base || git_get_head_hash
($project);
3743 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3744 or die_error
(undef, "Error lookup file");
3746 die_error
(undef, "No file name defined");
3748 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3749 # blobs defined by non-textual hash id's can be cached
3754 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3755 or die_error
(undef, "Couldn't cat $file_name, $hash");
3757 $type ||= blob_mimetype
($fd, $file_name);
3759 # save as filename, even when no $file_name is given
3760 my $save_as = "$hash";
3761 if (defined $file_name) {
3762 $save_as = $file_name;
3763 } elsif ($type =~ m/^text\//) {
3770 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3772 binmode STDOUT
, ':raw';
3774 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3782 if (!defined $hash) {
3783 if (defined $file_name) {
3784 my $base = $hash_base || git_get_head_hash
($project);
3785 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3786 or die_error
(undef, "Error lookup file");
3788 die_error
(undef, "No file name defined");
3790 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3791 # blobs defined by non-textual hash id's can be cached
3795 my ($have_blame) = gitweb_check_feature
('blame');
3796 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3797 or die_error
(undef, "Couldn't cat $file_name, $hash");
3798 my $mimetype = blob_mimetype
($fd, $file_name);
3799 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3801 return git_blob_plain
($mimetype);
3803 # we can have blame only for text/* mimetype
3804 $have_blame &&= ($mimetype =~ m!^text/!);
3806 git_header_html
(undef, $expires);
3807 my $formats_nav = '';
3808 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3809 if (defined $file_name) {
3812 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3813 hash
=>$hash, file_name
=>$file_name)},
3818 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3819 hash
=>$hash, file_name
=>$file_name)},
3822 $cgi->a({-href
=> href
(action
=>"blob_plain",
3823 hash
=>$hash, file_name
=>$file_name)},
3826 $cgi->a({-href
=> href
(action
=>"blob",
3827 hash_base
=>"HEAD", file_name
=>$file_name)},
3831 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3833 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3834 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3836 print "<div class=\"page_nav\">\n" .
3837 "<br/><br/></div>\n" .
3838 "<div class=\"title\">$hash</div>\n";
3840 git_print_page_path
($file_name, "blob", $hash_base);
3841 print "<div class=\"page_body\">\n";
3842 if ($mimetype =~ m!^text/!) {
3844 while (my $line = <$fd>) {
3847 $line = untabify
($line);
3848 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3849 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3851 } elsif ($mimetype =~ m!^image/!) {
3852 print qq!<img type
="$mimetype"!;
3854 print qq! alt
="$file_name" title
="$file_name"!;
3857 href(action=>"blob_plain
", hash=>$hash,
3858 hash_base=>$hash_base, file_name=>$file_name) .
3862 or print "Reading blob failed.\n";
3868 my $have_snapshot = gitweb_have_snapshot
();
3870 if (!defined $hash_base) {
3871 $hash_base = "HEAD";
3873 if (!defined $hash) {
3874 if (defined $file_name) {
3875 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3881 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3882 or die_error
(undef, "Open git-ls-tree failed");
3883 my @entries = map { chomp; $_ } <$fd>;
3884 close $fd or die_error
(undef, "Reading tree failed");
3887 my $refs = git_get_references
();
3888 my $ref = format_ref_marker
($refs, $hash_base);
3891 my ($have_blame) = gitweb_check_feature
('blame');
3892 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3894 if (defined $file_name) {
3896 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3897 hash
=>$hash, file_name
=>$file_name)},
3899 $cgi->a({-href
=> href
(action
=>"tree",
3900 hash_base
=>"HEAD", file_name
=>$file_name)},
3903 if ($have_snapshot) {
3904 # FIXME: Should be available when we have no hash base as well.
3906 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3909 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3910 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3913 print "<div class=\"page_nav\">\n";
3914 print "<br/><br/></div>\n";
3915 print "<div class=\"title\">$hash</div>\n";
3917 if (defined $file_name) {
3918 $basedir = $file_name;
3919 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3923 git_print_page_path
($file_name, 'tree', $hash_base);
3924 print "<div class=\"page_body\">\n";
3925 print "<table cellspacing=\"0\">\n";
3927 # '..' (top directory) link if possible
3928 if (defined $hash_base &&
3929 defined $file_name && $file_name =~ m![^/]+$!) {
3931 print "<tr class=\"dark\">\n";
3933 print "<tr class=\"light\">\n";
3937 my $up = $file_name;
3938 $up =~ s!/?[^/]+$!!;
3939 undef $up unless $up;
3940 # based on git_print_tree_entry
3941 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3942 print '<td class="list">';
3943 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3947 print "<td class=\"link\"></td>\n";
3951 foreach my $line (@entries) {
3952 my %t = parse_ls_tree_line
($line, -z
=> 1);
3955 print "<tr class=\"dark\">\n";
3957 print "<tr class=\"light\">\n";
3961 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3965 print "</table>\n" .
3971 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3972 my $have_snapshot = (defined $ctype && defined $suffix);
3973 if (!$have_snapshot) {
3974 die_error
('403 Permission denied', "Permission denied");
3977 if (!defined $hash) {
3978 $hash = git_get_head_hash
($project);
3981 my $git = git_cmd_str
();
3982 my $name = $project;
3983 $name =~ s/\047/\047\\\047\047/g;
3984 my $filename = decode_utf8
(basename
($project));
3986 if ($suffix eq 'zip') {
3987 $filename .= "-$hash.$suffix";
3988 $cmd = "$git archive --format=zip --prefix=\'$name\'/ $hash";
3990 $filename .= "-$hash.tar.$suffix";
3991 $cmd = "$git archive --format=tar --prefix=\'$name\'/ $hash | $command";
3995 -type
=> "application/$ctype",
3996 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3997 -status
=> '200 OK');
3999 open my $fd, "-|", $cmd
4000 or die_error
(undef, "Execute git-archive failed");
4001 binmode STDOUT
, ':raw';
4003 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4009 my $head = git_get_head_hash
($project);
4010 if (!defined $hash) {
4013 if (!defined $page) {
4016 my $refs = git_get_references
();
4018 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4020 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4023 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4026 my %co = parse_commit
($hash);
4028 git_print_header_div
('summary', $project);
4029 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4031 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
4032 for (my $i = 0; $i <= $to; $i++) {
4033 my %co = %{$commitlist[$i]};
4035 my $commit = $co{'id'};
4036 my $ref = format_ref_marker
($refs, $commit);
4037 my %ad = parse_date
($co{'author_epoch'});
4038 git_print_header_div
('commit',
4039 "<span class=\"age\">$co{'age_string'}</span>" .
4040 esc_html
($co{'title'}) . $ref,
4042 print "<div class=\"title_text\">\n" .
4043 "<div class=\"log_link\">\n" .
4044 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4046 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4048 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4051 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4054 print "<div class=\"log_body\">\n";
4055 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4058 if ($#commitlist >= 100) {
4059 print "<div class=\"page_nav\">\n";
4060 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4061 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4068 $hash ||= $hash_base || "HEAD";
4069 my %co = parse_commit
($hash);
4071 die_error
(undef, "Unknown commit object");
4073 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4074 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4076 my $parent = $co{'parent'};
4077 my $parents = $co{'parents'}; # listref
4079 # we need to prepare $formats_nav before any parameter munging
4081 if (!defined $parent) {
4083 $formats_nav .= '(initial)';
4084 } elsif (@
$parents == 1) {
4085 # single parent commit
4088 $cgi->a({-href
=> href
(action
=>"commit",
4090 esc_html
(substr($parent, 0, 7))) .
4097 $cgi->a({-href
=> href
(action
=>"commit",
4099 esc_html
(substr($_, 0, 7)));
4104 if (!defined $parent) {
4108 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4110 (@
$parents <= 1 ?
$parent : '-c'),
4112 or die_error
(undef, "Open git-diff-tree failed");
4113 @difftree = map { chomp; $_ } <$fd>;
4114 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4116 # non-textual hash id's can be cached
4118 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4121 my $refs = git_get_references
();
4122 my $ref = format_ref_marker
($refs, $co{'id'});
4124 my $have_snapshot = gitweb_have_snapshot
();
4126 git_header_html
(undef, $expires);
4127 git_print_page_nav
('commit', '',
4128 $hash, $co{'tree'}, $hash,
4131 if (defined $co{'parent'}) {
4132 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4134 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4136 print "<div class=\"title_text\">\n" .
4137 "<table cellspacing=\"0\">\n";
4138 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4140 "<td></td><td> $ad{'rfc2822'}";
4141 if ($ad{'hour_local'} < 6) {
4142 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4143 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4145 printf(" (%02d:%02d %s)",
4146 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4150 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4151 print "<tr><td></td><td> $cd{'rfc2822'}" .
4152 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4154 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4157 "<td class=\"sha1\">" .
4158 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4159 class => "list"}, $co{'tree'}) .
4161 "<td class=\"link\">" .
4162 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4164 if ($have_snapshot) {
4166 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
4171 foreach my $par (@
$parents) {
4174 "<td class=\"sha1\">" .
4175 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4176 class => "list"}, $par) .
4178 "<td class=\"link\">" .
4179 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4181 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4188 print "<div class=\"page_body\">\n";
4189 git_print_log
($co{'comment'});
4192 git_difftree_body
(\
@difftree, $hash, @
$parents);
4198 # object is defined by:
4199 # - hash or hash_base alone
4200 # - hash_base and file_name
4203 # - hash or hash_base alone
4204 if ($hash || ($hash_base && !defined $file_name)) {
4205 my $object_id = $hash || $hash_base;
4207 my $git_command = git_cmd_str
();
4208 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4209 or die_error
('404 Not Found', "Object does not exist");
4213 or die_error
('404 Not Found', "Object does not exist");
4215 # - hash_base and file_name
4216 } elsif ($hash_base && defined $file_name) {
4217 $file_name =~ s
,/+$,,;
4219 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4220 or die_error
('404 Not Found', "Base object does not exist");
4222 # here errors should not hapen
4223 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4224 or die_error
(undef, "Open git-ls-tree failed");
4228 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4229 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4230 die_error
('404 Not Found', "File or directory for given base does not exist");
4235 die_error
('404 Not Found', "Not enough information to find object");
4238 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4239 hash
=>$hash, hash_base
=>$hash_base,
4240 file_name
=>$file_name),
4241 -status
=> '302 Found');
4245 my $format = shift || 'html';
4252 # preparing $fd and %diffinfo for git_patchset_body
4254 if (defined $hash_base && defined $hash_parent_base) {
4255 if (defined $file_name) {
4257 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4258 $hash_parent_base, $hash_base,
4259 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4260 or die_error
(undef, "Open git-diff-tree failed");
4261 @difftree = map { chomp; $_ } <$fd>;
4263 or die_error
(undef, "Reading git-diff-tree failed");
4265 or die_error
('404 Not Found', "Blob diff not found");
4267 } elsif (defined $hash &&
4268 $hash =~ /[0-9a-fA-F]{40}/) {
4269 # try to find filename from $hash
4271 # read filtered raw output
4272 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4273 $hash_parent_base, $hash_base, "--"
4274 or die_error
(undef, "Open git-diff-tree failed");
4276 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4278 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4279 map { chomp; $_ } <$fd>;
4281 or die_error
(undef, "Reading git-diff-tree failed");
4283 or die_error
('404 Not Found', "Blob diff not found");
4286 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4289 if (@difftree > 1) {
4290 die_error
('404 Not Found', "Ambiguous blob diff specification");
4293 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4294 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4295 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4297 $hash_parent ||= $diffinfo{'from_id'};
4298 $hash ||= $diffinfo{'to_id'};
4300 # non-textual hash id's can be cached
4301 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4302 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4307 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4308 '-p', ($format eq 'html' ?
"--full-index" : ()),
4309 $hash_parent_base, $hash_base,
4310 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4311 or die_error
(undef, "Open git-diff-tree failed");
4314 # old/legacy style URI
4315 if (!%diffinfo && # if new style URI failed
4316 defined $hash && defined $hash_parent) {
4317 # fake git-diff-tree raw output
4318 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4319 $diffinfo{'from_id'} = $hash_parent;
4320 $diffinfo{'to_id'} = $hash;
4321 if (defined $file_name) {
4322 if (defined $file_parent) {
4323 $diffinfo{'status'} = '2';
4324 $diffinfo{'from_file'} = $file_parent;
4325 $diffinfo{'to_file'} = $file_name;
4326 } else { # assume not renamed
4327 $diffinfo{'status'} = '1';
4328 $diffinfo{'from_file'} = $file_name;
4329 $diffinfo{'to_file'} = $file_name;
4331 } else { # no filename given
4332 $diffinfo{'status'} = '2';
4333 $diffinfo{'from_file'} = $hash_parent;
4334 $diffinfo{'to_file'} = $hash;
4337 # non-textual hash id's can be cached
4338 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4339 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4344 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4345 '-p', ($format eq 'html' ?
"--full-index" : ()),
4346 $hash_parent, $hash, "--"
4347 or die_error
(undef, "Open git-diff failed");
4349 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4354 if ($format eq 'html') {
4356 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4357 hash
=>$hash, hash_parent
=>$hash_parent,
4358 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4359 file_name
=>$file_name, file_parent
=>$file_parent)},
4361 git_header_html
(undef, $expires);
4362 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4363 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4364 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4366 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4367 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4369 if (defined $file_name) {
4370 git_print_page_path
($file_name, "blob", $hash_base);
4372 print "<div class=\"page_path\"></div>\n";
4375 } elsif ($format eq 'plain') {
4377 -type
=> 'text/plain',
4378 -charset
=> 'utf-8',
4379 -expires
=> $expires,
4380 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4382 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4385 die_error
(undef, "Unknown blobdiff format");
4389 if ($format eq 'html') {
4390 print "<div class=\"page_body\">\n";
4392 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4395 print "</div>\n"; # class="page_body"
4399 while (my $line = <$fd>) {
4400 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4401 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4405 last if $line =~ m!^\+\+\+!;
4413 sub git_blobdiff_plain
{
4414 git_blobdiff
('plain');
4417 sub git_commitdiff
{
4418 my $format = shift || 'html';
4419 $hash ||= $hash_base || "HEAD";
4420 my %co = parse_commit
($hash);
4422 die_error
(undef, "Unknown commit object");
4425 # we need to prepare $formats_nav before any parameter munging
4427 if ($format eq 'html') {
4429 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4430 hash
=>$hash, hash_parent
=>$hash_parent)},
4433 if (defined $hash_parent) {
4434 # commitdiff with two commits given
4435 my $hash_parent_short = $hash_parent;
4436 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4437 $hash_parent_short = substr($hash_parent, 0, 7);
4441 $cgi->a({-href
=> href
(action
=>"commitdiff",
4442 hash
=>$hash_parent)},
4443 esc_html
($hash_parent_short)) .
4445 } elsif (!$co{'parent'}) {
4447 $formats_nav .= ' (initial)';
4448 } elsif (scalar @
{$co{'parents'}} == 1) {
4449 # single parent commit
4452 $cgi->a({-href
=> href
(action
=>"commitdiff",
4453 hash
=>$co{'parent'})},
4454 esc_html
(substr($co{'parent'}, 0, 7))) .
4461 $cgi->a({-href
=> href
(action
=>"commitdiff",
4463 esc_html
(substr($_, 0, 7)));
4464 } @
{$co{'parents'}} ) .
4469 my $hash_parent_param = $hash_parent;
4470 if (!defined $hash_parent) {
4471 $hash_parent_param =
4472 @
{$co{'parents'}} > 1 ?
'-c' : $co{'parent'} || '--root';
4478 if ($format eq 'html') {
4479 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4480 "--no-commit-id", "--patch-with-raw", "--full-index",
4481 $hash_parent_param, $hash, "--"
4482 or die_error
(undef, "Open git-diff-tree failed");
4484 while (my $line = <$fd>) {
4486 # empty line ends raw part of diff-tree output
4488 push @difftree, scalar parse_difftree_raw_line
($line);
4491 } elsif ($format eq 'plain') {
4492 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4493 '-p', $hash_parent_param, $hash, "--"
4494 or die_error
(undef, "Open git-diff-tree failed");
4497 die_error
(undef, "Unknown commitdiff format");
4500 # non-textual hash id's can be cached
4502 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4506 # write commit message
4507 if ($format eq 'html') {
4508 my $refs = git_get_references
();
4509 my $ref = format_ref_marker
($refs, $co{'id'});
4511 git_header_html
(undef, $expires);
4512 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4513 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4514 git_print_authorship
(\
%co);
4515 print "<div class=\"page_body\">\n";
4516 if (@
{$co{'comment'}} > 1) {
4517 print "<div class=\"log\">\n";
4518 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4519 print "</div>\n"; # class="log"
4522 } elsif ($format eq 'plain') {
4523 my $refs = git_get_references
("tags");
4524 my $tagname = git_get_rev_name_tags
($hash);
4525 my $filename = basename
($project) . "-$hash.patch";
4528 -type
=> 'text/plain',
4529 -charset
=> 'utf-8',
4530 -expires
=> $expires,
4531 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4532 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4535 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4536 Subject: $co{'title'}
4538 print "X-Git-Tag: $tagname\n" if $tagname;
4539 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4541 foreach my $line (@
{$co{'comment'}}) {
4548 if ($format eq 'html') {
4549 git_difftree_body
(\
@difftree, $hash, $hash_parent || @
{$co{'parents'}});
4552 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent || @
{$co{'parents'}});
4554 print "</div>\n"; # class="page_body"
4557 } elsif ($format eq 'plain') {
4561 or print "Reading git-diff-tree failed\n";
4565 sub git_commitdiff_plain
{
4566 git_commitdiff
('plain');
4570 if (!defined $hash_base) {
4571 $hash_base = git_get_head_hash
($project);
4573 if (!defined $page) {
4577 my %co = parse_commit
($hash_base);
4579 die_error
(undef, "Unknown commit object");
4582 my $refs = git_get_references
();
4583 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4585 if (!defined $hash && defined $file_name) {
4586 $hash = git_get_hash_by_path
($hash_base, $file_name);
4588 if (defined $hash) {
4589 $ftype = git_get_type
($hash);
4592 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4594 my $paging_nav = '';
4597 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4598 file_name
=>$file_name)},
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
=> "p", -title
=> "Alt-p"}, "prev");
4605 $paging_nav .= "first";
4606 $paging_nav .= " ⋅ prev";
4608 if ($#commitlist >= 100) {
4609 $paging_nav .= " ⋅ " .
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");
4614 $paging_nav .= " ⋅ next";
4617 if ($#commitlist >= 100) {
4619 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4620 file_name
=>$file_name, page
=>$page+1),
4621 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4625 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4626 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4627 git_print_page_path
($file_name, $ftype, $hash_base);
4629 git_history_body
(\
@commitlist, 0, 99,
4630 $refs, $hash_base, $ftype, $next_link);
4636 my ($have_search) = gitweb_check_feature
('search');
4637 if (!$have_search) {
4638 die_error
('403 Permission denied', "Permission denied");
4640 if (!defined $searchtext) {
4641 die_error
(undef, "Text field empty");
4643 if (!defined $hash) {
4644 $hash = git_get_head_hash
($project);
4646 my %co = parse_commit
($hash);
4648 die_error
(undef, "Unknown commit object");
4650 if (!defined $page) {
4654 $searchtype ||= 'commit';
4655 if ($searchtype eq 'pickaxe') {
4656 # pickaxe may take all resources of your box and run for several minutes
4657 # with every query - so decide by yourself how public you make this feature
4658 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4659 if (!$have_pickaxe) {
4660 die_error
('403 Permission denied', "Permission denied");
4663 if ($searchtype eq 'grep') {
4664 my ($have_grep) = gitweb_check_feature
('grep');
4666 die_error
('403 Permission denied', "Permission denied");
4672 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4674 if ($searchtype eq 'commit') {
4675 $greptype = "--grep=";
4676 } elsif ($searchtype eq 'author') {
4677 $greptype = "--author=";
4678 } elsif ($searchtype eq 'committer') {
4679 $greptype = "--committer=";
4681 $greptype .= $search_regexp;
4682 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4684 my $paging_nav = '';
4687 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4688 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4690 $paging_nav .= " ⋅ " .
4691 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4692 searchtext
=>$searchtext, searchtype
=>$searchtype,
4694 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4696 $paging_nav .= "first";
4697 $paging_nav .= " ⋅ prev";
4699 if ($#commitlist >= 100) {
4700 $paging_nav .= " ⋅ " .
4701 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4702 searchtext
=>$searchtext, searchtype
=>$searchtype,
4704 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4706 $paging_nav .= " ⋅ next";
4709 if ($#commitlist >= 100) {
4711 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4712 searchtext
=>$searchtext, searchtype
=>$searchtype,
4714 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4717 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4718 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4719 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4722 if ($searchtype eq 'pickaxe') {
4723 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4724 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4726 print "<table cellspacing=\"0\">\n";
4729 my $git_command = git_cmd_str
();
4730 my $searchqtext = $searchtext;
4731 $searchqtext =~ s/'/'\\''/;
4732 open my $fd, "-|", "$git_command rev-list $hash | " .
4733 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
4736 while (my $line = <$fd>) {
4737 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4740 $set{'from_id'} = $3;
4742 $set{'id'} = $set{'to_id'};
4743 if ($set{'id'} =~ m/0{40}/) {
4744 $set{'id'} = $set{'from_id'};
4746 if ($set{'id'} =~ m/0{40}/) {
4750 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4753 print "<tr class=\"dark\">\n";
4755 print "<tr class=\"light\">\n";
4758 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4759 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4761 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4762 -class => "list subject"},
4763 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4764 while (my $setref = shift @files) {
4766 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4767 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4769 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4773 "<td class=\"link\">" .
4774 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4776 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4780 %co = parse_commit
($1);
4788 if ($searchtype eq 'grep') {
4789 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4790 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4792 print "<table cellspacing=\"0\">\n";
4796 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
4798 while (my $line = <$fd>) {
4800 my ($file, $lno, $ltext, $binary);
4801 last if ($matches++ > 1000);
4802 if ($line =~ /^Binary file (.+) matches$/) {
4806 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
4808 if ($file ne $lastfile) {
4809 $lastfile and print "</td></tr>\n";
4811 print "<tr class=\"dark\">\n";
4813 print "<tr class=\"light\">\n";
4815 print "<td class=\"list\">".
4816 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
4817 file_name
=>"$file"),
4818 -class => "list"}, esc_path
($file));
4819 print "</td><td>\n";
4823 print "<div class=\"binary\">Binary file</div>\n";
4825 $ltext = untabify
($ltext);
4826 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
4827 $ltext = esc_html
($1, -nbsp
=>1);
4828 $ltext .= '<span class="match">';
4829 $ltext .= esc_html
($2, -nbsp
=>1);
4830 $ltext .= '</span>';
4831 $ltext .= esc_html
($3, -nbsp
=>1);
4833 $ltext = esc_html
($ltext, -nbsp
=>1);
4835 print "<div class=\"pre\">" .
4836 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
4837 file_name
=>"$file").'#l'.$lno,
4838 -class => "linenr"}, sprintf('%4i', $lno))
4839 . ' ' . $ltext . "</div>\n";
4843 print "</td></tr>\n";
4844 if ($matches > 1000) {
4845 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
4848 print "<div class=\"diff nodifferences\">No matches found</div>\n";
4857 sub git_search_help
{
4859 git_print_page_nav
('','', $hash,$hash,$hash);
4862 <dt><b>commit</b></dt>
4863 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4865 my ($have_grep) = gitweb_check_feature
('grep');
4868 <dt><b>grep</b></dt>
4869 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
4870 a different one) are searched for the given
4871 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
4872 (POSIX extended) and the matches are listed. On large
4873 trees, this search can take a while and put some strain on the server, so please use it with
4874 some consideration.</dd>
4878 <dt><b>author</b></dt>
4879 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4880 <dt><b>committer</b></dt>
4881 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4883 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4884 if ($have_pickaxe) {
4886 <dt><b>pickaxe</b></dt>
4887 <dd>All commits that caused the string to appear or disappear from any file (changes that
4888 added, removed or "modified" the string) will be listed. This search can take a while and
4889 takes a lot of strain on the server, so please use it wisely.</dd>
4897 my $head = git_get_head_hash
($project);
4898 if (!defined $hash) {
4901 if (!defined $page) {
4904 my $refs = git_get_references
();
4906 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4908 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
4910 if ($#commitlist >= 100) {
4912 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4913 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4917 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4918 git_print_header_div
('summary', $project);
4920 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
4925 ## ......................................................................
4926 ## feeds (RSS, Atom; OPML)
4929 my $format = shift || 'atom';
4930 my ($have_blame) = gitweb_check_feature
('blame');
4932 # Atom: http://www.atomenabled.org/developers/syndication/
4933 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4934 if ($format ne 'rss' && $format ne 'atom') {
4935 die_error
(undef, "Unknown web feed format");
4938 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4939 my $head = $hash || 'HEAD';
4940 my @commitlist = parse_commits
($head, 150);
4944 my $content_type = "application/$format+xml";
4945 if (defined $cgi->http('HTTP_ACCEPT') &&
4946 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4947 # browser (feed reader) prefers text/xml
4948 $content_type = 'text/xml';
4950 if (defined($commitlist[0])) {
4951 %latest_commit = %{$commitlist[0]};
4952 %latest_date = parse_date
($latest_commit{'author_epoch'});
4954 -type
=> $content_type,
4955 -charset
=> 'utf-8',
4956 -last_modified
=> $latest_date{'rfc2822'});
4959 -type
=> $content_type,
4960 -charset
=> 'utf-8');
4963 # Optimization: skip generating the body if client asks only
4964 # for Last-Modified date.
4965 return if ($cgi->request_method() eq 'HEAD');
4968 my $title = "$site_name - $project/$action";
4969 my $feed_type = 'log';
4970 if (defined $hash) {
4971 $title .= " - '$hash'";
4972 $feed_type = 'branch log';
4973 if (defined $file_name) {
4974 $title .= " :: $file_name";
4975 $feed_type = 'history';
4977 } elsif (defined $file_name) {
4978 $title .= " - $file_name";
4979 $feed_type = 'history';
4981 $title .= " $feed_type";
4982 my $descr = git_get_project_description
($project);
4983 if (defined $descr) {
4984 $descr = esc_html
($descr);
4986 $descr = "$project " .
4987 ($format eq 'rss' ?
'RSS' : 'Atom') .
4990 my $owner = git_get_project_owner
($project);
4991 $owner = esc_html
($owner);
4995 if (defined $file_name) {
4996 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
4997 } elsif (defined $hash) {
4998 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5000 $alt_url = href
(-full
=>1, action
=>"summary");
5002 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
5003 if ($format eq 'rss') {
5005 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5008 print "<title>$title</title>\n" .
5009 "<link>$alt_url</link>\n" .
5010 "<description>$descr</description>\n" .
5011 "<language>en</language>\n";
5012 } elsif ($format eq 'atom') {
5014 <feed xmlns="http://www.w3.org/2005/Atom">
5016 print "<title>$title</title>\n" .
5017 "<subtitle>$descr</subtitle>\n" .
5018 '<link rel="alternate" type="text/html" href="' .
5019 $alt_url . '" />' . "\n" .
5020 '<link rel="self" type="' . $content_type . '" href="' .
5021 $cgi->self_url() . '" />' . "\n" .
5022 "<id>" . href
(-full
=>1) . "</id>\n" .
5023 # use project owner for feed author
5024 "<author><name>$owner</name></author>\n";
5025 if (defined $favicon) {
5026 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5028 if (defined $logo_url) {
5029 # not twice as wide as tall: 72 x 27 pixels
5030 print "<logo>" . esc_url
($logo) . "</logo>\n";
5032 if (! %latest_date) {
5033 # dummy date to keep the feed valid until commits trickle in:
5034 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5036 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5041 for (my $i = 0; $i <= $#commitlist; $i++) {
5042 my %co = %{$commitlist[$i]};
5043 my $commit = $co{'id'};
5044 # we read 150, we always show 30 and the ones more recent than 48 hours
5045 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5048 my %cd = parse_date
($co{'author_epoch'});
5050 # get list of changed files
5051 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5052 $co{'parent'} || "--root",
5053 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
5055 my @difftree = map { chomp; $_ } <$fd>;
5059 # print element (entry, item)
5060 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5061 if ($format eq 'rss') {
5063 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5064 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5065 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5066 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5067 "<link>$co_url</link>\n" .
5068 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5069 "<content:encoded>" .
5071 } elsif ($format eq 'atom') {
5073 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5074 "<updated>$cd{'iso-8601'}</updated>\n" .
5076 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5077 if ($co{'author_email'}) {
5078 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5080 print "</author>\n" .
5081 # use committer for contributor
5083 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5084 if ($co{'committer_email'}) {
5085 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5087 print "</contributor>\n" .
5088 "<published>$cd{'iso-8601'}</published>\n" .
5089 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5090 "<id>$co_url</id>\n" .
5091 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5092 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5094 my $comment = $co{'comment'};
5096 foreach my $line (@
$comment) {
5097 $line = esc_html
($line);
5100 print "</pre><ul>\n";
5101 foreach my $difftree_line (@difftree) {
5102 my %difftree = parse_difftree_raw_line
($difftree_line);
5103 next if !$difftree{'from_id'};
5105 my $file = $difftree{'file'} || $difftree{'to_file'};
5109 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5110 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5111 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5112 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5113 -title
=> "diff"}, 'D');
5115 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5116 file_name
=>$file, hash_base
=>$commit),
5117 -title
=> "blame"}, 'B');
5119 # if this is not a feed of a file history
5120 if (!defined $file_name || $file_name ne $file) {
5121 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5122 file_name
=>$file, hash
=>$commit),
5123 -title
=> "history"}, 'H');
5125 $file = esc_path
($file);
5129 if ($format eq 'rss') {
5130 print "</ul>]]>\n" .
5131 "</content:encoded>\n" .
5133 } elsif ($format eq 'atom') {
5134 print "</ul>\n</div>\n" .
5141 if ($format eq 'rss') {
5142 print "</channel>\n</rss>\n";
5143 } elsif ($format eq 'atom') {
5157 my @list = git_get_projects_list
();
5159 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5161 <?xml version="1.0" encoding="utf-8"?>
5162 <opml version="1.0">
5164 <title>$site_name OPML Export</title>
5167 <outline text="git RSS feeds">
5170 foreach my $pr (@list) {
5172 my $head = git_get_head_hash
($proj{'path'});
5173 if (!defined $head) {
5176 $git_dir = "$projectroot/$proj{'path'}";
5177 my %co = parse_commit
($head);
5182 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5183 my $rss = "$my_url?p=$proj{'path'};a=rss";
5184 my $html = "$my_url?p=$proj{'path'};a=summary";
5185 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";