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 # assume this charset if line contains non-UTF-8 characters;
98 # it should be valid encoding (see Encoding::Supported(3pm) for list),
99 # for which encoding all byte sequences are valid, for example
100 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
101 # could be even 'utf-8' for the old behavior)
102 our $fallback_encoding = 'latin1';
104 # You define site-wide feature defaults here; override them with
105 # $GITWEB_CONFIG as necessary.
108 # 'sub' => feature-sub (subroutine),
109 # 'override' => allow-override (boolean),
110 # 'default' => [ default options...] (array reference)}
112 # if feature is overridable (it means that allow-override has true value),
113 # then feature-sub will be called with default options as parameters;
114 # return value of feature-sub indicates if to enable specified feature
116 # if there is no 'sub' key (no feature-sub), then feature cannot be
119 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
121 # Enable the 'blame' blob view, showing the last commit that modified
122 # each line in the file. This can be very CPU-intensive.
124 # To enable system wide have in $GITWEB_CONFIG
125 # $feature{'blame'}{'default'} = [1];
126 # To have project specific config enable override in $GITWEB_CONFIG
127 # $feature{'blame'}{'override'} = 1;
128 # and in project config gitweb.blame = 0|1;
130 'sub' => \
&feature_blame
,
134 # Enable the 'snapshot' link, providing a compressed tarball of any
135 # tree. This can potentially generate high traffic if you have large
138 # To disable system wide have in $GITWEB_CONFIG
139 # $feature{'snapshot'}{'default'} = [undef];
140 # To have project specific config enable override in $GITWEB_CONFIG
141 # $feature{'snapshot'}{'override'} = 1;
142 # and in project config gitweb.snapshot = none|gzip|bzip2|zip;
144 'sub' => \
&feature_snapshot
,
146 # => [content-encoding, suffix, program]
147 'default' => ['x-gzip', 'gz', 'gzip']},
149 # Enable text search, which will list the commits which match author,
150 # committer or commit text to a given string. Enabled by default.
151 # Project specific override is not supported.
156 # Enable grep search, which will list the files in currently selected
157 # tree containing the given string. Enabled by default. This can be
158 # potentially CPU-intensive, of course.
160 # To enable system wide have in $GITWEB_CONFIG
161 # $feature{'grep'}{'default'} = [1];
162 # To have project specific config enable override in $GITWEB_CONFIG
163 # $feature{'grep'}{'override'} = 1;
164 # and in project config gitweb.grep = 0|1;
169 # Enable the pickaxe search, which will list the commits that modified
170 # a given string in a file. This can be practical and quite faster
171 # alternative to 'blame', but still potentially CPU-intensive.
173 # To enable system wide have in $GITWEB_CONFIG
174 # $feature{'pickaxe'}{'default'} = [1];
175 # To have project specific config enable override in $GITWEB_CONFIG
176 # $feature{'pickaxe'}{'override'} = 1;
177 # and in project config gitweb.pickaxe = 0|1;
179 'sub' => \
&feature_pickaxe
,
183 # Make gitweb use an alternative format of the URLs which can be
184 # more readable and natural-looking: project name is embedded
185 # directly in the path and the query string contains other
186 # auxiliary information. All gitweb installations recognize
187 # URL in either format; this configures in which formats gitweb
190 # To enable system wide have in $GITWEB_CONFIG
191 # $feature{'pathinfo'}{'default'} = [1];
192 # Project specific override is not supported.
194 # Note that you will need to change the default location of CSS,
195 # favicon, logo and possibly other files to an absolute URL. Also,
196 # if gitweb.cgi serves as your indexfile, you will need to force
197 # $my_uri to contain the script name in your $GITWEB_CONFIG.
202 # Make gitweb consider projects in project root subdirectories
203 # to be forks of existing projects. Given project $projname.git,
204 # projects matching $projname/*.git will not be shown in the main
205 # projects list, instead a '+' mark will be added to $projname
206 # there and a 'forks' view will be enabled for the project, listing
207 # all the forks. If project list is taken from a file, forks have
208 # to be listed after the main project.
210 # To enable system wide have in $GITWEB_CONFIG
211 # $feature{'forks'}{'default'} = [1];
212 # Project specific override is not supported.
218 sub gitweb_check_feature
{
220 return unless exists $feature{$name};
221 my ($sub, $override, @defaults) = (
222 $feature{$name}{'sub'},
223 $feature{$name}{'override'},
224 @
{$feature{$name}{'default'}});
225 if (!$override) { return @defaults; }
227 warn "feature $name is not overrideable";
230 return $sub->(@defaults);
234 my ($val) = git_get_project_config
('blame', '--bool');
236 if ($val eq 'true') {
238 } elsif ($val eq 'false') {
245 sub feature_snapshot
{
246 my ($ctype, $suffix, $command) = @_;
248 my ($val) = git_get_project_config
('snapshot');
250 if ($val eq 'gzip') {
251 return ('x-gzip', 'gz', 'gzip');
252 } elsif ($val eq 'bzip2') {
253 return ('x-bzip2', 'bz2', 'bzip2');
254 } elsif ($val eq 'zip') {
255 return ('x-zip', 'zip', '');
256 } elsif ($val eq 'none') {
260 return ($ctype, $suffix, $command);
263 sub gitweb_have_snapshot
{
264 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
265 my $have_snapshot = (defined $ctype && defined $suffix);
267 return $have_snapshot;
271 my ($val) = git_get_project_config
('grep', '--bool');
273 if ($val eq 'true') {
275 } elsif ($val eq 'false') {
282 sub feature_pickaxe
{
283 my ($val) = git_get_project_config
('pickaxe', '--bool');
285 if ($val eq 'true') {
287 } elsif ($val eq 'false') {
294 # checking HEAD file with -e is fragile if the repository was
295 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
297 sub check_head_link
{
299 my $headfile = "$dir/HEAD";
300 return ((-e
$headfile) ||
301 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
304 sub check_export_ok
{
306 return (check_head_link
($dir) &&
307 (!$export_ok || -e
"$dir/$export_ok"));
310 # rename detection options for git-diff and git-diff-tree
311 # - default is '-M', with the cost proportional to
312 # (number of removed files) * (number of new files).
313 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
314 # (number of changed files + number of removed files) * (number of new files)
315 # - even more costly is '-C', '--find-copies-harder' with cost
316 # (number of files in the original tree) * (number of new files)
317 # - one might want to include '-B' option, e.g. '-B', '-M'
318 our @diff_opts = ('-M'); # taken from git_commit
320 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
321 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
323 # version of the core git binary
324 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
326 $projects_list ||= $projectroot;
328 # ======================================================================
329 # input validation and dispatch
330 our $action = $cgi->param('a');
331 if (defined $action) {
332 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
333 die_error
(undef, "Invalid action parameter");
337 # parameters which are pathnames
338 our $project = $cgi->param('p');
339 if (defined $project) {
340 if (!validate_pathname
($project) ||
341 !(-d
"$projectroot/$project") ||
342 !check_head_link
("$projectroot/$project") ||
343 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
344 ($strict_export && !project_in_list
($project))) {
346 die_error
(undef, "No such project");
350 our $file_name = $cgi->param('f');
351 if (defined $file_name) {
352 if (!validate_pathname
($file_name)) {
353 die_error
(undef, "Invalid file parameter");
357 our $file_parent = $cgi->param('fp');
358 if (defined $file_parent) {
359 if (!validate_pathname
($file_parent)) {
360 die_error
(undef, "Invalid file parent parameter");
364 # parameters which are refnames
365 our $hash = $cgi->param('h');
367 if (!validate_refname
($hash)) {
368 die_error
(undef, "Invalid hash parameter");
372 our $hash_parent = $cgi->param('hp');
373 if (defined $hash_parent) {
374 if (!validate_refname
($hash_parent)) {
375 die_error
(undef, "Invalid hash parent parameter");
379 our $hash_base = $cgi->param('hb');
380 if (defined $hash_base) {
381 if (!validate_refname
($hash_base)) {
382 die_error
(undef, "Invalid hash base parameter");
386 our $hash_parent_base = $cgi->param('hpb');
387 if (defined $hash_parent_base) {
388 if (!validate_refname
($hash_parent_base)) {
389 die_error
(undef, "Invalid hash parent base parameter");
394 our $page = $cgi->param('pg');
396 if ($page =~ m/[^0-9]/) {
397 die_error
(undef, "Invalid page parameter");
401 our $searchtype = $cgi->param('st');
402 if (defined $searchtype) {
403 if ($searchtype =~ m/[^a-z]/) {
404 die_error
(undef, "Invalid searchtype parameter");
408 our $searchtext = $cgi->param('s');
410 if (defined $searchtext) {
411 if ($searchtype ne 'grep' and $searchtype ne 'pickaxe' and $searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
412 die_error
(undef, "Invalid search parameter");
414 if (length($searchtext) < 2) {
415 die_error
(undef, "At least two characters are required for search parameter");
417 $search_regexp = quotemeta $searchtext;
420 # now read PATH_INFO and use it as alternative to parameters
421 sub evaluate_path_info
{
422 return if defined $project;
423 my $path_info = $ENV{"PATH_INFO"};
424 return if !$path_info;
425 $path_info =~ s
,^/+,,;
426 return if !$path_info;
427 # find which part of PATH_INFO is project
428 $project = $path_info;
430 while ($project && !check_head_link
("$projectroot/$project")) {
431 $project =~ s
,/*[^/]*$,,;
434 $project = validate_pathname
($project);
436 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
437 ($strict_export && !project_in_list
($project))) {
441 # do not change any parameters if an action is given using the query string
443 $path_info =~ s
,^$project/*,,;
444 my ($refname, $pathname) = split(/:/, $path_info, 2);
445 if (defined $pathname) {
446 # we got "project.git/branch:filename" or "project.git/branch:dir/"
447 # we could use git_get_type(branch:pathname), but it needs $git_dir
448 $pathname =~ s
,^/+,,;
449 if (!$pathname || substr($pathname, -1) eq "/") {
453 $action ||= "blob_plain";
455 $hash_base ||= validate_refname
($refname);
456 $file_name ||= validate_pathname
($pathname);
457 } elsif (defined $refname) {
458 # we got "project.git/branch"
459 $action ||= "shortlog";
460 $hash ||= validate_refname
($refname);
463 evaluate_path_info
();
465 # path to the current git repository
467 $git_dir = "$projectroot/$project" if $project;
471 "blame" => \
&git_blame2
,
472 "blobdiff" => \
&git_blobdiff
,
473 "blobdiff_plain" => \
&git_blobdiff_plain
,
474 "blob" => \
&git_blob
,
475 "blob_plain" => \
&git_blob_plain
,
476 "commitdiff" => \
&git_commitdiff
,
477 "commitdiff_plain" => \
&git_commitdiff_plain
,
478 "commit" => \
&git_commit
,
479 "forks" => \
&git_forks
,
480 "heads" => \
&git_heads
,
481 "history" => \
&git_history
,
484 "atom" => \
&git_atom
,
485 "search" => \
&git_search
,
486 "search_help" => \
&git_search_help
,
487 "shortlog" => \
&git_shortlog
,
488 "summary" => \
&git_summary
,
490 "tags" => \
&git_tags
,
491 "tree" => \
&git_tree
,
492 "snapshot" => \
&git_snapshot
,
493 "object" => \
&git_object
,
494 # those below don't need $project
495 "opml" => \
&git_opml
,
496 "project_list" => \
&git_project_list
,
497 "project_index" => \
&git_project_index
,
500 if (!defined $action) {
502 $action = git_get_type
($hash);
503 } elsif (defined $hash_base && defined $file_name) {
504 $action = git_get_type
("$hash_base:$file_name");
505 } elsif (defined $project) {
508 $action = 'project_list';
511 if (!defined($actions{$action})) {
512 die_error
(undef, "Unknown action");
514 if ($action !~ m/^(opml|project_list|project_index)$/ &&
516 die_error
(undef, "Project needed");
518 $actions{$action}->();
521 ## ======================================================================
526 # default is to use -absolute url() i.e. $my_uri
527 my $href = $params{-full
} ?
$my_url : $my_uri;
529 # XXX: Warning: If you touch this, check the search form for updating,
540 hash_parent_base
=> "hpb",
546 my %mapping = @mapping;
548 $params{'project'} = $project unless exists $params{'project'};
550 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
552 # use PATH_INFO for project name
553 $href .= "/$params{'project'}" if defined $params{'project'};
554 delete $params{'project'};
556 # Summary just uses the project path URL
557 if (defined $params{'action'} && $params{'action'} eq 'summary') {
558 delete $params{'action'};
562 # now encode the parameters explicitly
564 for (my $i = 0; $i < @mapping; $i += 2) {
565 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
566 if (defined $params{$name}) {
567 push @result, $symbol . "=" . esc_param
($params{$name});
570 $href .= "?" . join(';', @result) if scalar @result;
576 ## ======================================================================
577 ## validation, quoting/unquoting and escaping
579 sub validate_pathname
{
580 my $input = shift || return undef;
582 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
583 # at the beginning, at the end, and between slashes.
584 # also this catches doubled slashes
585 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
589 if ($input =~ m!\0!) {
595 sub validate_refname
{
596 my $input = shift || return undef;
598 # textual hashes are O.K.
599 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
602 # it must be correct pathname
603 $input = validate_pathname
($input)
605 # restrictions on ref name according to git-check-ref-format
606 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
612 # decode sequences of octets in utf8 into Perl's internal form,
613 # which is utf-8 with utf8 flag set if needed. gitweb writes out
614 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
618 eval { $res = decode_utf8
($str, Encode
::FB_CROAK
); };
622 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
626 # quote unsafe chars, but keep the slash, even when it's not
627 # correct, but quoted slashes look too horrible in bookmarks
630 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
636 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
639 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
645 # replace invalid utf8 character with SUBSTITUTION sequence
650 $str = to_utf8
($str);
651 $str = $cgi->escapeHTML($str);
652 if ($opts{'-nbsp'}) {
653 $str =~ s/ / /g;
655 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
659 # quote control characters and escape filename to HTML
664 $str = to_utf8
($str);
665 $str = $cgi->escapeHTML($str);
666 if ($opts{'-nbsp'}) {
667 $str =~ s/ / /g;
669 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
673 # Make control characters "printable", using character escape codes (CEC)
676 my %es = ( # character escape codes, aka escape sequences
677 "\t" => '\t', # tab (HT)
678 "\n" => '\n', # line feed (LF)
679 "\r" => '\r', # carrige return (CR)
680 "\f" => '\f', # form feed (FF)
681 "\b" => '\b', # backspace (BS)
682 "\a" => '\a', # alarm (bell) (BEL)
683 "\e" => '\e', # escape (ESC)
684 "\013" => '\v', # vertical tab (VT)
685 "\000" => '\0', # nul character (NUL)
687 my $chr = ( (exists $es{$cntrl})
689 : sprintf('\%03o', ord($cntrl)) );
690 return "<span class=\"cntrl\">$chr</span>";
693 # Alternatively use unicode control pictures codepoints,
694 # Unicode "printable representation" (PR)
697 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
698 return "<span class=\"cntrl\">$chr</span>";
701 # git may return quoted and escaped filenames
707 my %es = ( # character escape codes, aka escape sequences
708 't' => "\t", # tab (HT, TAB)
709 'n' => "\n", # newline (NL)
710 'r' => "\r", # return (CR)
711 'f' => "\f", # form feed (FF)
712 'b' => "\b", # backspace (BS)
713 'a' => "\a", # alarm (bell) (BEL)
714 'e' => "\e", # escape (ESC)
715 'v' => "\013", # vertical tab (VT)
718 if ($seq =~ m/^[0-7]{1,3}$/) {
719 # octal char sequence
720 return chr(oct($seq));
721 } elsif (exists $es{$seq}) {
722 # C escape sequence, aka character escape code
725 # quoted ordinary character
729 if ($str =~ m/^"(.*)"$/) {
732 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
737 # escape tabs (convert tabs to spaces)
741 while ((my $pos = index($line, "\t")) != -1) {
742 if (my $count = (8 - ($pos % 8))) {
743 my $spaces = ' ' x
$count;
744 $line =~ s/\t/$spaces/;
751 sub project_in_list
{
753 my @list = git_get_projects_list
();
754 return @list && scalar(grep { $_->{'path'} eq $project } @list);
757 ## ----------------------------------------------------------------------
758 ## HTML aware string manipulation
763 my $add_len = shift || 10;
765 # allow only $len chars, but don't cut a word if it would fit in $add_len
766 # if it doesn't fit, cut it if it's still longer than the dots we would add
767 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
770 if (length($tail) > 4) {
772 $body =~ s/&[^;]*$//; # remove chopped character entities
777 ## ----------------------------------------------------------------------
778 ## functions returning short strings
780 # CSS class for given age value (in seconds)
786 } elsif ($age < 60*60*2) {
788 } elsif ($age < 60*60*24*2) {
795 # convert age in seconds to "nn units ago" string
800 if ($age > 60*60*24*365*2) {
801 $age_str = (int $age/60/60/24/365);
802 $age_str .= " years ago";
803 } elsif ($age > 60*60*24*(365/12)*2) {
804 $age_str = int $age/60/60/24/(365/12);
805 $age_str .= " months ago";
806 } elsif ($age > 60*60*24*7*2) {
807 $age_str = int $age/60/60/24/7;
808 $age_str .= " weeks ago";
809 } elsif ($age > 60*60*24*2) {
810 $age_str = int $age/60/60/24;
811 $age_str .= " days ago";
812 } elsif ($age > 60*60*2) {
813 $age_str = int $age/60/60;
814 $age_str .= " hours ago";
815 } elsif ($age > 60*2) {
816 $age_str = int $age/60;
817 $age_str .= " min ago";
820 $age_str .= " sec ago";
822 $age_str .= " right now";
827 # convert file mode in octal to symbolic file mode string
829 my $mode = oct shift;
831 if (S_ISDIR
($mode & S_IFMT
)) {
833 } elsif (S_ISLNK
($mode)) {
835 } elsif (S_ISREG
($mode)) {
836 # git cares only about the executable bit
837 if ($mode & S_IXUSR
) {
847 # convert file mode in octal to file type string
851 if ($mode !~ m/^[0-7]+$/) {
857 if (S_ISDIR
($mode & S_IFMT
)) {
859 } elsif (S_ISLNK
($mode)) {
861 } elsif (S_ISREG
($mode)) {
868 # convert file mode in octal to file type description string
872 if ($mode !~ m/^[0-7]+$/) {
878 if (S_ISDIR
($mode & S_IFMT
)) {
880 } elsif (S_ISLNK
($mode)) {
882 } elsif (S_ISREG
($mode)) {
883 if ($mode & S_IXUSR
) {
894 ## ----------------------------------------------------------------------
895 ## functions returning short HTML fragments, or transforming HTML fragments
896 ## which don't belong to other sections
898 # format line of commit message.
899 sub format_log_line_html
{
902 $line = esc_html
($line, -nbsp
=>1);
903 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
906 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
907 -class => "text"}, $hash_text);
908 $line =~ s/$hash_text/$link/;
913 # format marker of refs pointing to given object
914 sub format_ref_marker
{
915 my ($refs, $id) = @_;
918 if (defined $refs->{$id}) {
919 foreach my $ref (@
{$refs->{$id}}) {
920 my ($type, $name) = qw();
921 # e.g. tags/v2.6.11 or heads/next
922 if ($ref =~ m!^(.*?)s?/(.*)$!) {
930 $markers .= " <span class=\"$type\" title=\"$ref\">" .
931 esc_html
($name) . "</span>";
936 return ' <span class="refs">'. $markers . '</span>';
942 # format, perhaps shortened and with markers, title line
943 sub format_subject_html
{
944 my ($long, $short, $href, $extra) = @_;
945 $extra = '' unless defined($extra);
947 if (length($short) < length($long)) {
948 return $cgi->a({-href
=> $href, -class => "list subject",
949 -title
=> to_utf8
($long)},
950 esc_html
($short) . $extra);
952 return $cgi->a({-href
=> $href, -class => "list subject"},
953 esc_html
($long) . $extra);
957 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
958 sub format_git_diff_header_line
{
960 my $diffinfo = shift;
961 my ($from, $to) = @_;
963 if ($diffinfo->{'nparents'}) {
965 $line =~ s!^(diff (.*?) )"?.*$!$1!;
967 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
968 esc_path
($to->{'file'}));
969 } else { # file was deleted (no href)
970 $line .= esc_path
($to->{'file'});
974 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
975 if ($from->{'href'}) {
976 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
977 'a/' . esc_path
($from->{'file'}));
978 } else { # file was added (no href)
979 $line .= 'a/' . esc_path
($from->{'file'});
983 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
984 'b/' . esc_path
($to->{'file'}));
985 } else { # file was deleted
986 $line .= 'b/' . esc_path
($to->{'file'});
990 return "<div class=\"diff header\">$line</div>\n";
993 # format extended diff header line, before patch itself
994 sub format_extended_diff_header_line
{
996 my $diffinfo = shift;
997 my ($from, $to) = @_;
1000 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1001 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1002 esc_path
($from->{'file'}));
1004 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1005 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1006 esc_path
($to->{'file'}));
1008 # match single <mode>
1009 if ($line =~ m/\s(\d{6})$/) {
1010 $line .= '<span class="info"> (' .
1011 file_type_long
($1) .
1015 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1016 # can match only for combined diff
1018 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1019 if ($from->{'href'}[$i]) {
1020 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1022 substr($diffinfo->{'from_id'}[$i],0,7));
1027 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1030 if ($to->{'href'}) {
1031 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1032 substr($diffinfo->{'to_id'},0,7));
1037 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1038 # can match only for ordinary diff
1039 my ($from_link, $to_link);
1040 if ($from->{'href'}) {
1041 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1042 substr($diffinfo->{'from_id'},0,7));
1044 $from_link = '0' x
7;
1046 if ($to->{'href'}) {
1047 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1048 substr($diffinfo->{'to_id'},0,7));
1052 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1053 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1056 return $line . "<br/>\n";
1059 # format from-file/to-file diff header
1060 sub format_diff_from_to_header
{
1061 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1066 #assert($line =~ m/^---/) if DEBUG;
1067 # no extra formatting for "^--- /dev/null"
1068 if (! $diffinfo->{'nparents'}) {
1069 # ordinary (single parent) diff
1070 if ($line =~ m!^--- "?a/!) {
1071 if ($from->{'href'}) {
1073 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1074 esc_path
($from->{'file'}));
1077 esc_path
($from->{'file'});
1080 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1083 # combined diff (merge commit)
1084 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1085 if ($from->{'href'}[$i]) {
1087 $cgi->a({-href
=>href
(action
=>"blobdiff",
1088 hash_parent
=>$diffinfo->{'from_id'}[$i],
1089 hash_parent_base
=>$parents[$i],
1090 file_parent
=>$from->{'file'}[$i],
1091 hash
=>$diffinfo->{'to_id'},
1093 file_name
=>$to->{'file'}),
1095 -title
=>"diff" . ($i+1)},
1098 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1099 esc_path
($from->{'file'}[$i]));
1101 $line = '--- /dev/null';
1103 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1108 #assert($line =~ m/^\+\+\+/) if DEBUG;
1109 # no extra formatting for "^+++ /dev/null"
1110 if ($line =~ m!^\+\+\+ "?b/!) {
1111 if ($to->{'href'}) {
1113 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1114 esc_path
($to->{'file'}));
1117 esc_path
($to->{'file'});
1120 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1125 # format patch (diff) line (not to be used for diff headers)
1126 sub format_diff_line
{
1128 my ($from, $to) = @_;
1129 my $diff_class = "";
1133 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1135 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1136 if ($line =~ m/^\@{3}/) {
1137 $diff_class = " chunk_header";
1138 } elsif ($line =~ m/^\\/) {
1139 $diff_class = " incomplete";
1140 } elsif ($prefix =~ tr/+/+/) {
1141 $diff_class = " add";
1142 } elsif ($prefix =~ tr/-/-/) {
1143 $diff_class = " rem";
1146 # assume ordinary diff
1147 my $char = substr($line, 0, 1);
1149 $diff_class = " add";
1150 } elsif ($char eq '-') {
1151 $diff_class = " rem";
1152 } elsif ($char eq '@') {
1153 $diff_class = " chunk_header";
1154 } elsif ($char eq "\\") {
1155 $diff_class = " incomplete";
1158 $line = untabify
($line);
1159 if ($from && $to && $line =~ m/^\@{2} /) {
1160 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1161 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1163 $from_lines = 0 unless defined $from_lines;
1164 $to_lines = 0 unless defined $to_lines;
1166 if ($from->{'href'}) {
1167 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1168 -class=>"list"}, $from_text);
1170 if ($to->{'href'}) {
1171 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1172 -class=>"list"}, $to_text);
1174 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1175 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1176 return "<div class=\"diff$diff_class\">$line</div>\n";
1177 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1178 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1179 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1181 @from_text = split(' ', $ranges);
1182 for (my $i = 0; $i < @from_text; ++$i) {
1183 ($from_start[$i], $from_nlines[$i]) =
1184 (split(',', substr($from_text[$i], 1)), 0);
1187 $to_text = pop @from_text;
1188 $to_start = pop @from_start;
1189 $to_nlines = pop @from_nlines;
1191 $line = "<span class=\"chunk_info\">$prefix ";
1192 for (my $i = 0; $i < @from_text; ++$i) {
1193 if ($from->{'href'}[$i]) {
1194 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1195 -class=>"list"}, $from_text[$i]);
1197 $line .= $from_text[$i];
1201 if ($to->{'href'}) {
1202 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1203 -class=>"list"}, $to_text);
1207 $line .= " $prefix</span>" .
1208 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1209 return "<div class=\"diff$diff_class\">$line</div>\n";
1211 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1214 ## ----------------------------------------------------------------------
1215 ## git utility subroutines, invoking git commands
1217 # returns path to the core git executable and the --git-dir parameter as list
1219 return $GIT, '--git-dir='.$git_dir;
1222 # returns path to the core git executable and the --git-dir parameter as string
1224 return join(' ', git_cmd
());
1227 # get HEAD ref of given project as hash
1228 sub git_get_head_hash
{
1229 my $project = shift;
1230 my $o_git_dir = $git_dir;
1232 $git_dir = "$projectroot/$project";
1233 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1236 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1240 if (defined $o_git_dir) {
1241 $git_dir = $o_git_dir;
1246 # get type of given object
1250 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1252 close $fd or return;
1257 sub git_get_project_config
{
1258 my ($key, $type) = @_;
1260 return unless ($key);
1261 $key =~ s/^gitweb\.//;
1262 return if ($key =~ m/\W/);
1264 my @x = (git_cmd
(), 'config');
1265 if (defined $type) { push @x, $type; }
1267 push @x, "gitweb.$key";
1273 # get hash of given path at given ref
1274 sub git_get_hash_by_path
{
1276 my $path = shift || return undef;
1281 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1282 or die_error
(undef, "Open git-ls-tree failed");
1284 close $fd or return undef;
1286 if (!defined $line) {
1287 # there is no tree or hash given by $path at $base
1291 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1292 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1293 if (defined $type && $type ne $2) {
1294 # type doesn't match
1300 # get path of entry with given hash at given tree-ish (ref)
1301 # used to get 'from' filename for combined diff (merge commit) for renames
1302 sub git_get_path_by_hash
{
1303 my $base = shift || return;
1304 my $hash = shift || return;
1308 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1310 while (my $line = <$fd>) {
1313 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1314 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1315 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1324 ## ......................................................................
1325 ## git utility functions, directly accessing git repository
1327 sub git_get_project_description
{
1330 open my $fd, "$projectroot/$path/description" or return undef;
1333 if (defined $descr) {
1339 sub git_get_project_url_list
{
1342 open my $fd, "$projectroot/$path/cloneurl" or return;
1343 my @git_project_url_list = map { chomp; $_ } <$fd>;
1346 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
1349 sub git_get_projects_list
{
1354 $filter =~ s/\.git$//;
1356 my ($check_forks) = gitweb_check_feature
('forks');
1358 if (-d
$projects_list) {
1359 # search in directory
1360 my $dir = $projects_list . ($filter ?
"/$filter" : '');
1361 # remove the trailing "/"
1363 my $pfxlen = length("$dir");
1366 follow_fast
=> 1, # follow symbolic links
1367 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1369 # skip project-list toplevel, if we get it.
1370 return if (m!^[/.]$!);
1371 # only directories can be git repositories
1372 return unless (-d
$_);
1374 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1375 # we check related file in $projectroot
1376 if ($check_forks and $subdir =~ m
#/.#) {
1377 $File::Find
::prune
= 1;
1378 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1379 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
1380 $File::Find
::prune
= 1;
1385 } elsif (-f
$projects_list) {
1386 # read from file(url-encoded):
1387 # 'git%2Fgit.git Linus+Torvalds'
1388 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1389 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1391 open my ($fd), $projects_list or return;
1393 while (my $line = <$fd>) {
1395 my ($path, $owner) = split ' ', $line;
1396 $path = unescape
($path);
1397 $owner = unescape
($owner);
1398 if (!defined $path) {
1401 if ($filter ne '') {
1402 # looking for forks;
1403 my $pfx = substr($path, 0, length($filter));
1404 if ($pfx ne $filter) {
1407 my $sfx = substr($path, length($filter));
1408 if ($sfx !~ /^\/.*\
.git
$/) {
1411 } elsif ($check_forks) {
1413 foreach my $filter (keys %paths) {
1414 # looking for forks;
1415 my $pfx = substr($path, 0, length($filter));
1416 if ($pfx ne $filter) {
1419 my $sfx = substr($path, length($filter));
1420 if ($sfx !~ /^\/.*\
.git
$/) {
1423 # is a fork, don't include it in
1428 if (check_export_ok
("$projectroot/$path")) {
1431 owner
=> to_utf8
($owner),
1434 (my $forks_path = $path) =~ s/\.git$//;
1435 $paths{$forks_path}++;
1443 sub git_get_project_owner
{
1444 my $project = shift;
1447 return undef unless $project;
1449 # read from file (url-encoded):
1450 # 'git%2Fgit.git Linus+Torvalds'
1451 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1452 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1453 if (-f
$projects_list) {
1454 open (my $fd , $projects_list);
1455 while (my $line = <$fd>) {
1457 my ($pr, $ow) = split ' ', $line;
1458 $pr = unescape
($pr);
1459 $ow = unescape
($ow);
1460 if ($pr eq $project) {
1461 $owner = to_utf8
($ow);
1467 if (!defined $owner) {
1468 $owner = get_file_owner
("$projectroot/$project");
1474 sub git_get_last_activity
{
1478 $git_dir = "$projectroot/$path";
1479 open($fd, "-|", git_cmd
(), 'for-each-ref',
1480 '--format=%(committer)',
1481 '--sort=-committerdate',
1483 'refs/heads') or return;
1484 my $most_recent = <$fd>;
1485 close $fd or return;
1486 if (defined $most_recent &&
1487 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1489 my $age = time - $timestamp;
1490 return ($age, age_string
($age));
1494 sub git_get_references
{
1495 my $type = shift || "";
1497 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1498 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1499 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1500 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
1503 while (my $line = <$fd>) {
1505 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1506 if (defined $refs{$1}) {
1507 push @
{$refs{$1}}, $2;
1513 close $fd or return;
1517 sub git_get_rev_name_tags
{
1518 my $hash = shift || return undef;
1520 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1522 my $name_rev = <$fd>;
1525 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1528 # catches also '$hash undefined' output
1533 ## ----------------------------------------------------------------------
1534 ## parse to hash functions
1538 my $tz = shift || "-0000";
1541 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1542 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1543 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1544 $date{'hour'} = $hour;
1545 $date{'minute'} = $min;
1546 $date{'mday'} = $mday;
1547 $date{'day'} = $days[$wday];
1548 $date{'month'} = $months[$mon];
1549 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1550 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1551 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1552 $mday, $months[$mon], $hour ,$min;
1553 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1554 1900+$year, $mon, $mday, $hour ,$min, $sec;
1556 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1557 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1558 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1559 $date{'hour_local'} = $hour;
1560 $date{'minute_local'} = $min;
1561 $date{'tz_local'} = $tz;
1562 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1563 1900+$year, $mon+1, $mday,
1564 $hour, $min, $sec, $tz);
1573 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1574 $tag{'id'} = $tag_id;
1575 while (my $line = <$fd>) {
1577 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1578 $tag{'object'} = $1;
1579 } elsif ($line =~ m/^type (.+)$/) {
1581 } elsif ($line =~ m/^tag (.+)$/) {
1583 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1584 $tag{'author'} = $1;
1587 } elsif ($line =~ m/--BEGIN/) {
1588 push @comment, $line;
1590 } elsif ($line eq "") {
1594 push @comment, <$fd>;
1595 $tag{'comment'} = \
@comment;
1596 close $fd or return;
1597 if (!defined $tag{'name'}) {
1603 sub parse_commit_text
{
1604 my ($commit_text, $withparents) = @_;
1605 my @commit_lines = split '\n', $commit_text;
1608 pop @commit_lines; # Remove '\0'
1610 if (! @commit_lines) {
1614 my $header = shift @commit_lines;
1615 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1618 ($co{'id'}, my @parents) = split ' ', $header;
1619 while (my $line = shift @commit_lines) {
1620 last if $line eq "\n";
1621 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1623 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1625 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1627 $co{'author_epoch'} = $2;
1628 $co{'author_tz'} = $3;
1629 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1630 $co{'author_name'} = $1;
1631 $co{'author_email'} = $2;
1633 $co{'author_name'} = $co{'author'};
1635 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1636 $co{'committer'} = $1;
1637 $co{'committer_epoch'} = $2;
1638 $co{'committer_tz'} = $3;
1639 $co{'committer_name'} = $co{'committer'};
1640 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1641 $co{'committer_name'} = $1;
1642 $co{'committer_email'} = $2;
1644 $co{'committer_name'} = $co{'committer'};
1648 if (!defined $co{'tree'}) {
1651 $co{'parents'} = \
@parents;
1652 $co{'parent'} = $parents[0];
1654 foreach my $title (@commit_lines) {
1657 $co{'title'} = chop_str
($title, 80, 5);
1658 # remove leading stuff of merges to make the interesting part visible
1659 if (length($title) > 50) {
1660 $title =~ s/^Automatic //;
1661 $title =~ s/^merge (of|with) /Merge ... /i;
1662 if (length($title) > 50) {
1663 $title =~ s/(http|rsync):\/\///;
1665 if (length($title) > 50) {
1666 $title =~ s/(master|www|rsync)\.//;
1668 if (length($title) > 50) {
1669 $title =~ s/kernel.org:?//;
1671 if (length($title) > 50) {
1672 $title =~ s/\/pub\/scm//;
1675 $co{'title_short'} = chop_str
($title, 50, 5);
1679 if ($co{'title'} eq "") {
1680 $co{'title'} = $co{'title_short'} = '(no commit message)';
1682 # remove added spaces
1683 foreach my $line (@commit_lines) {
1686 $co{'comment'} = \
@commit_lines;
1688 my $age = time - $co{'committer_epoch'};
1690 $co{'age_string'} = age_string
($age);
1691 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1692 if ($age > 60*60*24*7*2) {
1693 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1694 $co{'age_string_age'} = $co{'age_string'};
1696 $co{'age_string_date'} = $co{'age_string'};
1697 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1703 my ($commit_id) = @_;
1708 open my $fd, "-|", git_cmd
(), "rev-list",
1714 or die_error
(undef, "Open git-rev-list failed");
1715 %co = parse_commit_text
(<$fd>, 1);
1722 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1730 open my $fd, "-|", git_cmd
(), "rev-list",
1732 ($arg ?
($arg) : ()),
1733 ("--max-count=" . $maxcount),
1734 ("--skip=" . $skip),
1737 ($filename ?
($filename) : ())
1738 or die_error
(undef, "Open git-rev-list failed");
1739 while (my $line = <$fd>) {
1740 my %co = parse_commit_text
($line);
1745 return wantarray ?
@cos : \
@cos;
1748 # parse ref from ref_file, given by ref_id, with given type
1750 my $ref_file = shift;
1752 my $type = shift || git_get_type
($ref_id);
1755 $ref_item{'type'} = $type;
1756 $ref_item{'id'} = $ref_id;
1757 $ref_item{'epoch'} = 0;
1758 $ref_item{'age'} = "unknown";
1759 if ($type eq "tag") {
1760 my %tag = parse_tag
($ref_id);
1761 $ref_item{'comment'} = $tag{'comment'};
1762 if ($tag{'type'} eq "commit") {
1763 my %co = parse_commit
($tag{'object'});
1764 $ref_item{'epoch'} = $co{'committer_epoch'};
1765 $ref_item{'age'} = $co{'age_string'};
1766 } elsif (defined($tag{'epoch'})) {
1767 my $age = time - $tag{'epoch'};
1768 $ref_item{'epoch'} = $tag{'epoch'};
1769 $ref_item{'age'} = age_string
($age);
1771 $ref_item{'reftype'} = $tag{'type'};
1772 $ref_item{'name'} = $tag{'name'};
1773 $ref_item{'refid'} = $tag{'object'};
1774 } elsif ($type eq "commit"){
1775 my %co = parse_commit
($ref_id);
1776 $ref_item{'reftype'} = "commit";
1777 $ref_item{'name'} = $ref_file;
1778 $ref_item{'title'} = $co{'title'};
1779 $ref_item{'refid'} = $ref_id;
1780 $ref_item{'epoch'} = $co{'committer_epoch'};
1781 $ref_item{'age'} = $co{'age_string'};
1783 $ref_item{'reftype'} = $type;
1784 $ref_item{'name'} = $ref_file;
1785 $ref_item{'refid'} = $ref_id;
1791 # parse line of git-diff-tree "raw" output
1792 sub parse_difftree_raw_line
{
1796 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1797 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1798 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1799 $res{'from_mode'} = $1;
1800 $res{'to_mode'} = $2;
1801 $res{'from_id'} = $3;
1803 $res{'status'} = $5;
1804 $res{'similarity'} = $6;
1805 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1806 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1808 $res{'file'} = unquote
($7);
1811 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1812 # combined diff (for merge commit)
1813 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1814 $res{'nparents'} = length($1);
1815 $res{'from_mode'} = [ split(' ', $2) ];
1816 $res{'to_mode'} = pop @
{$res{'from_mode'}};
1817 $res{'from_id'} = [ split(' ', $3) ];
1818 $res{'to_id'} = pop @
{$res{'from_id'}};
1819 $res{'status'} = [ split('', $4) ];
1820 $res{'to_file'} = unquote
($5);
1822 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1823 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1824 $res{'commit'} = $1;
1827 return wantarray ?
%res : \
%res;
1830 # parse line of git-ls-tree output
1831 sub parse_ls_tree_line
($;%) {
1836 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1837 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1845 $res{'name'} = unquote
($4);
1848 return wantarray ?
%res : \
%res;
1851 # generates _two_ hashes, references to which are passed as 2 and 3 argument
1852 sub parse_from_to_diffinfo
{
1853 my ($diffinfo, $from, $to, @parents) = @_;
1855 if ($diffinfo->{'nparents'}) {
1857 $from->{'file'} = [];
1858 $from->{'href'} = [];
1859 fill_from_file_info
($diffinfo, @parents)
1860 unless exists $diffinfo->{'from_file'};
1861 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1862 $from->{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
1863 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
1864 $from->{'href'}[$i] = href
(action
=>"blob",
1865 hash_base
=>$parents[$i],
1866 hash
=>$diffinfo->{'from_id'}[$i],
1867 file_name
=>$from->{'file'}[$i]);
1869 $from->{'href'}[$i] = undef;
1873 $from->{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
1874 if ($diffinfo->{'status'} ne "A") { # not new (added) file
1875 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
1876 hash
=>$diffinfo->{'from_id'},
1877 file_name
=>$from->{'file'});
1879 delete $from->{'href'};
1883 $to->{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
1884 if (!is_deleted
($diffinfo)) { # file exists in result
1885 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
1886 hash
=>$diffinfo->{'to_id'},
1887 file_name
=>$to->{'file'});
1889 delete $to->{'href'};
1893 ## ......................................................................
1894 ## parse to array of hashes functions
1896 sub git_get_heads_list
{
1900 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1901 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
1902 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1905 while (my $line = <$fd>) {
1909 my ($refinfo, $committerinfo) = split(/\0/, $line);
1910 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1911 my ($committer, $epoch, $tz) =
1912 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1913 $name =~ s!^refs/heads/!!;
1915 $ref_item{'name'} = $name;
1916 $ref_item{'id'} = $hash;
1917 $ref_item{'title'} = $title || '(no commit message)';
1918 $ref_item{'epoch'} = $epoch;
1920 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1922 $ref_item{'age'} = "unknown";
1925 push @headslist, \
%ref_item;
1929 return wantarray ?
@headslist : \
@headslist;
1932 sub git_get_tags_list
{
1936 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1937 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
1938 '--format=%(objectname) %(objecttype) %(refname) '.
1939 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1942 while (my $line = <$fd>) {
1946 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1947 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1948 my ($creator, $epoch, $tz) =
1949 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1950 $name =~ s!^refs/tags/!!;
1952 $ref_item{'type'} = $type;
1953 $ref_item{'id'} = $id;
1954 $ref_item{'name'} = $name;
1955 if ($type eq "tag") {
1956 $ref_item{'subject'} = $title;
1957 $ref_item{'reftype'} = $reftype;
1958 $ref_item{'refid'} = $refid;
1960 $ref_item{'reftype'} = $type;
1961 $ref_item{'refid'} = $id;
1964 if ($type eq "tag" || $type eq "commit") {
1965 $ref_item{'epoch'} = $epoch;
1967 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1969 $ref_item{'age'} = "unknown";
1973 push @tagslist, \
%ref_item;
1977 return wantarray ?
@tagslist : \
@tagslist;
1980 ## ----------------------------------------------------------------------
1981 ## filesystem-related functions
1983 sub get_file_owner
{
1986 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1987 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1988 if (!defined $gcos) {
1992 $owner =~ s/[,;].*$//;
1993 return to_utf8
($owner);
1996 ## ......................................................................
1997 ## mimetype related functions
1999 sub mimetype_guess_file
{
2000 my $filename = shift;
2001 my $mimemap = shift;
2002 -r
$mimemap or return undef;
2005 open(MIME
, $mimemap) or return undef;
2007 next if m/^#/; # skip comments
2008 my ($mime, $exts) = split(/\t+/);
2009 if (defined $exts) {
2010 my @exts = split(/\s+/, $exts);
2011 foreach my $ext (@exts) {
2012 $mimemap{$ext} = $mime;
2018 $filename =~ /\.([^.]*)$/;
2019 return $mimemap{$1};
2022 sub mimetype_guess
{
2023 my $filename = shift;
2025 $filename =~ /\./ or return undef;
2027 if ($mimetypes_file) {
2028 my $file = $mimetypes_file;
2029 if ($file !~ m!^/!) { # if it is relative path
2030 # it is relative to project
2031 $file = "$projectroot/$project/$file";
2033 $mime = mimetype_guess_file
($filename, $file);
2035 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2041 my $filename = shift;
2044 my $mime = mimetype_guess
($filename);
2045 $mime and return $mime;
2049 return $default_blob_plain_mimetype unless $fd;
2052 return 'text/plain' .
2053 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
2054 } elsif (! $filename) {
2055 return 'application/octet-stream';
2056 } elsif ($filename =~ m/\.png$/i) {
2058 } elsif ($filename =~ m/\.gif$/i) {
2060 } elsif ($filename =~ m/\.jpe?g$/i) {
2061 return 'image/jpeg';
2063 return 'application/octet-stream';
2067 ## ======================================================================
2068 ## functions printing HTML: header, footer, error page
2070 sub git_header_html
{
2071 my $status = shift || "200 OK";
2072 my $expires = shift;
2074 my $title = "$site_name";
2075 if (defined $project) {
2076 $title .= " - " . to_utf8
($project);
2077 if (defined $action) {
2078 $title .= "/$action";
2079 if (defined $file_name) {
2080 $title .= " - " . esc_path
($file_name);
2081 if ($action eq "tree" && $file_name !~ m
|/$|) {
2088 # require explicit support from the UA if we are to send the page as
2089 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2090 # we have to do this because MSIE sometimes globs '*/*', pretending to
2091 # support xhtml+xml but choking when it gets what it asked for.
2092 if (defined $cgi->http('HTTP_ACCEPT') &&
2093 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2094 $cgi->Accept('application/xhtml+xml') != 0) {
2095 $content_type = 'application/xhtml+xml';
2097 $content_type = 'text/html';
2099 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2100 -status
=> $status, -expires
=> $expires);
2101 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
2103 <?xml version="1.0" encoding="utf-8"?>
2104 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2105 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2106 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2107 <!-- git core binaries version $git_version -->
2109 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2110 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2111 <meta name="robots" content="index, nofollow"/>
2112 <title>$title</title>
2114 # print out each stylesheet that exist
2115 if (defined $stylesheet) {
2116 #provides backwards capability for those people who define style sheet in a config file
2117 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2119 foreach my $stylesheet (@stylesheets) {
2120 next unless $stylesheet;
2121 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2124 if (defined $project) {
2125 printf('<link rel="alternate" title="%s log RSS feed" '.
2126 'href="%s" type="application/rss+xml" />'."\n",
2127 esc_param
($project), href
(action
=>"rss"));
2128 printf('<link rel="alternate" title="%s log Atom feed" '.
2129 'href="%s" type="application/atom+xml" />'."\n",
2130 esc_param
($project), href
(action
=>"atom"));
2132 printf('<link rel="alternate" title="%s projects list" '.
2133 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2134 $site_name, href
(project
=>undef, action
=>"project_index"));
2135 printf('<link rel="alternate" title="%s projects feeds" '.
2136 'href="%s" type="text/x-opml"/>'."\n",
2137 $site_name, href
(project
=>undef, action
=>"opml"));
2139 if (defined $favicon) {
2140 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
2146 if (-f
$site_header) {
2147 open (my $fd, $site_header);
2152 print "<div class=\"page_header\">\n" .
2153 $cgi->a({-href
=> esc_url
($logo_url),
2154 -title
=> $logo_label},
2155 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
2156 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2157 if (defined $project) {
2158 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2159 if (defined $action) {
2166 my ($have_search) = gitweb_check_feature
('search');
2167 if ((defined $project) && ($have_search)) {
2168 if (!defined $searchtext) {
2172 if (defined $hash_base) {
2173 $search_hash = $hash_base;
2174 } elsif (defined $hash) {
2175 $search_hash = $hash;
2177 $search_hash = "HEAD";
2179 $cgi->param("a", "search");
2180 $cgi->param("h", $search_hash);
2181 $cgi->param("p", $project);
2182 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
2183 "<div class=\"search\">\n" .
2184 $cgi->hidden(-name
=> "p") . "\n" .
2185 $cgi->hidden(-name
=> "a") . "\n" .
2186 $cgi->hidden(-name
=> "h") . "\n" .
2187 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2188 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2189 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2191 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2193 $cgi->end_form() . "\n";
2197 sub git_footer_html
{
2198 print "<div class=\"page_footer\">\n";
2199 if (defined $project) {
2200 my $descr = git_get_project_description
($project);
2201 if (defined $descr) {
2202 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2204 print $cgi->a({-href
=> href
(action
=>"rss"),
2205 -class => "rss_logo"}, "RSS") . " ";
2206 print $cgi->a({-href
=> href
(action
=>"atom"),
2207 -class => "rss_logo"}, "Atom") . "\n";
2209 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2210 -class => "rss_logo"}, "OPML") . " ";
2211 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2212 -class => "rss_logo"}, "TXT") . "\n";
2216 if (-f
$site_footer) {
2217 open (my $fd, $site_footer);
2227 my $status = shift || "403 Forbidden";
2228 my $error = shift || "Malformed query, file missing or permission denied";
2230 git_header_html
($status);
2232 <div class="page_body">
2242 ## ----------------------------------------------------------------------
2243 ## functions printing or outputting HTML: navigation
2245 sub git_print_page_nav
{
2246 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2247 $extra = '' if !defined $extra; # pager or formats
2249 my @navs = qw(summary shortlog log commit commitdiff tree);
2251 @navs = grep { $_ ne $suppress } @navs;
2254 my %arg = map { $_ => {action
=>$_} } @navs;
2255 if (defined $head) {
2256 for (qw(commit commitdiff)) {
2257 $arg{$_}{'hash'} = $head;
2259 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2260 for (qw(shortlog log)) {
2261 $arg{$_}{'hash'} = $head;
2265 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2266 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2268 print "<div class=\"page_nav\">\n" .
2270 map { $_ eq $current ?
2271 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2273 print "<br/>\n$extra<br/>\n" .
2277 sub format_paging_nav
{
2278 my ($action, $hash, $head, $page, $nrevs) = @_;
2282 if ($hash ne $head || $page) {
2283 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2285 $paging_nav .= "HEAD";
2289 $paging_nav .= " ⋅ " .
2290 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2291 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2293 $paging_nav .= " ⋅ prev";
2296 if ($nrevs >= (100 * ($page+1)-1)) {
2297 $paging_nav .= " ⋅ " .
2298 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2299 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2301 $paging_nav .= " ⋅ next";
2307 ## ......................................................................
2308 ## functions printing or outputting HTML: div
2310 sub git_print_header_div
{
2311 my ($action, $title, $hash, $hash_base) = @_;
2314 $args{'action'} = $action;
2315 $args{'hash'} = $hash if $hash;
2316 $args{'hash_base'} = $hash_base if $hash_base;
2318 print "<div class=\"header\">\n" .
2319 $cgi->a({-href
=> href
(%args), -class => "title"},
2320 $title ?
$title : $action) .
2324 #sub git_print_authorship (\%) {
2325 sub git_print_authorship
{
2328 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2329 print "<div class=\"author_date\">" .
2330 esc_html
($co->{'author_name'}) .
2332 if ($ad{'hour_local'} < 6) {
2333 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2334 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2336 printf(" (%02d:%02d %s)",
2337 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2342 sub git_print_page_path
{
2348 print "<div class=\"page_path\">";
2349 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2350 -title
=> 'tree root'}, to_utf8
("[$project]"));
2352 if (defined $name) {
2353 my @dirname = split '/', $name;
2354 my $basename = pop @dirname;
2357 foreach my $dir (@dirname) {
2358 $fullname .= ($fullname ?
'/' : '') . $dir;
2359 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2361 -title
=> $fullname}, esc_path
($dir));
2364 if (defined $type && $type eq 'blob') {
2365 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2367 -title
=> $name}, esc_path
($basename));
2368 } elsif (defined $type && $type eq 'tree') {
2369 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2371 -title
=> $name}, esc_path
($basename));
2374 print esc_path
($basename);
2377 print "<br/></div>\n";
2380 # sub git_print_log (\@;%) {
2381 sub git_print_log
($;%) {
2385 if ($opts{'-remove_title'}) {
2386 # remove title, i.e. first line of log
2389 # remove leading empty lines
2390 while (defined $log->[0] && $log->[0] eq "") {
2397 foreach my $line (@
$log) {
2398 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2401 if (! $opts{'-remove_signoff'}) {
2402 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2405 # remove signoff lines
2412 # print only one empty line
2413 # do not print empty line after signoff
2415 next if ($empty || $signoff);
2421 print format_log_line_html
($line) . "<br/>\n";
2424 if ($opts{'-final_empty_line'}) {
2425 # end with single empty line
2426 print "<br/>\n" unless $empty;
2430 # return link target (what link points to)
2431 sub git_get_link_target
{
2436 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2440 $link_target = <$fd>;
2445 return $link_target;
2448 # given link target, and the directory (basedir) the link is in,
2449 # return target of link relative to top directory (top tree);
2450 # return undef if it is not possible (including absolute links).
2451 sub normalize_link_target
{
2452 my ($link_target, $basedir, $hash_base) = @_;
2454 # we can normalize symlink target only if $hash_base is provided
2455 return unless $hash_base;
2457 # absolute symlinks (beginning with '/') cannot be normalized
2458 return if (substr($link_target, 0, 1) eq '/');
2460 # normalize link target to path from top (root) tree (dir)
2463 $path = $basedir . '/' . $link_target;
2465 # we are in top (root) tree (dir)
2466 $path = $link_target;
2469 # remove //, /./, and /../
2471 foreach my $part (split('/', $path)) {
2472 # discard '.' and ''
2473 next if (!$part || $part eq '.');
2475 if ($part eq '..') {
2479 # link leads outside repository (outside top dir)
2483 push @path_parts, $part;
2486 $path = join('/', @path_parts);
2491 # print tree entry (row of git_tree), but without encompassing <tr> element
2492 sub git_print_tree_entry
{
2493 my ($t, $basedir, $hash_base, $have_blame) = @_;
2496 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2498 # The format of a table row is: mode list link. Where mode is
2499 # the mode of the entry, list is the name of the entry, an href,
2500 # and link is the action links of the entry.
2502 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2503 if ($t->{'type'} eq "blob") {
2504 print "<td class=\"list\">" .
2505 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2506 file_name
=>"$basedir$t->{'name'}", %base_key),
2507 -class => "list"}, esc_path
($t->{'name'}));
2508 if (S_ISLNK
(oct $t->{'mode'})) {
2509 my $link_target = git_get_link_target
($t->{'hash'});
2511 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2512 if (defined $norm_target) {
2514 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2515 file_name
=>$norm_target),
2516 -title
=> $norm_target}, esc_path
($link_target));
2518 print " -> " . esc_path
($link_target);
2523 print "<td class=\"link\">";
2524 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2525 file_name
=>"$basedir$t->{'name'}", %base_key)},
2529 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2530 file_name
=>"$basedir$t->{'name'}", %base_key)},
2533 if (defined $hash_base) {
2535 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2536 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2540 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2541 file_name
=>"$basedir$t->{'name'}")},
2545 } elsif ($t->{'type'} eq "tree") {
2546 print "<td class=\"list\">";
2547 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2548 file_name
=>"$basedir$t->{'name'}", %base_key)},
2549 esc_path
($t->{'name'}));
2551 print "<td class=\"link\">";
2552 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2553 file_name
=>"$basedir$t->{'name'}", %base_key)},
2555 if (defined $hash_base) {
2557 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2558 file_name
=>"$basedir$t->{'name'}")},
2565 ## ......................................................................
2566 ## functions printing large fragments of HTML
2568 sub fill_from_file_info
{
2569 my ($diff, @parents) = @_;
2571 $diff->{'from_file'} = [ ];
2572 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2573 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2574 if ($diff->{'status'}[$i] eq 'R' ||
2575 $diff->{'status'}[$i] eq 'C') {
2576 $diff->{'from_file'}[$i] =
2577 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2584 # parameters can be strings, or references to arrays of strings
2588 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @
$a == @
$b) {
2589 for (my $i = 0; $i < @
$a; ++$i) {
2590 return 0 unless ($a->[$i] eq $b->[$i]);
2593 } elsif (!ref($a) && !ref($b)) {
2601 my $diffinfo = shift;
2603 return $diffinfo->{'to_id'} eq ('0' x
40);
2606 sub git_difftree_body
{
2607 my ($difftree, $hash, @parents) = @_;
2608 my ($parent) = $parents[0];
2609 my ($have_blame) = gitweb_check_feature
('blame');
2610 print "<div class=\"list_head\">\n";
2611 if ($#{$difftree} > 10) {
2612 print(($#{$difftree} + 1) . " files changed:\n");
2616 print "<table class=\"" .
2617 (@parents > 1 ?
"combined " : "") .
2620 # header only for combined diff in 'commitdiff' view
2621 my $has_header = @parents > 1 && $action eq 'commitdiff';
2624 print "<thead><tr>\n" .
2625 "<th></th><th></th>\n"; # filename, patchN link
2626 for (my $i = 0; $i < @parents; $i++) {
2627 my $par = $parents[$i];
2629 $cgi->a({-href
=> href
(action
=>"commitdiff",
2630 hash
=>$hash, hash_parent
=>$par),
2631 -title
=> 'commitdiff to parent number ' .
2632 ($i+1) . ': ' . substr($par,0,7)},
2636 print "</tr></thead>\n<tbody>\n";
2641 foreach my $line (@
{$difftree}) {
2643 if (ref($line) eq "HASH") {
2644 # pre-parsed (or generated by hand)
2647 $diff = parse_difftree_raw_line
($line);
2651 print "<tr class=\"dark\">\n";
2653 print "<tr class=\"light\">\n";
2657 if (exists $diff->{'nparents'}) { # combined diff
2659 fill_from_file_info
($diff, @parents)
2660 unless exists $diff->{'from_file'};
2662 if (!is_deleted
($diff)) {
2663 # file exists in the result (child) commit
2665 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2666 file_name
=>$diff->{'to_file'},
2668 -class => "list"}, esc_path
($diff->{'to_file'})) .
2672 esc_path
($diff->{'to_file'}) .
2676 if ($action eq 'commitdiff') {
2679 print "<td class=\"link\">" .
2680 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2685 my $has_history = 0;
2686 my $not_deleted = 0;
2687 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2688 my $hash_parent = $parents[$i];
2689 my $from_hash = $diff->{'from_id'}[$i];
2690 my $from_path = $diff->{'from_file'}[$i];
2691 my $status = $diff->{'status'}[$i];
2693 $has_history ||= ($status ne 'A');
2694 $not_deleted ||= ($status ne 'D');
2696 if ($status eq 'A') {
2697 print "<td class=\"link\" align=\"right\"> | </td>\n";
2698 } elsif ($status eq 'D') {
2699 print "<td class=\"link\">" .
2700 $cgi->a({-href
=> href
(action
=>"blob",
2703 file_name
=>$from_path)},
2707 if ($diff->{'to_id'} eq $from_hash) {
2708 print "<td class=\"link nochange\">";
2710 print "<td class=\"link\">";
2712 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2713 hash
=>$diff->{'to_id'},
2714 hash_parent
=>$from_hash,
2716 hash_parent_base
=>$hash_parent,
2717 file_name
=>$diff->{'to_file'},
2718 file_parent
=>$from_path)},
2724 print "<td class=\"link\">";
2726 print $cgi->a({-href
=> href
(action
=>"blob",
2727 hash
=>$diff->{'to_id'},
2728 file_name
=>$diff->{'to_file'},
2731 print " | " if ($has_history);
2734 print $cgi->a({-href
=> href
(action
=>"history",
2735 file_name
=>$diff->{'to_file'},
2742 next; # instead of 'else' clause, to avoid extra indent
2744 # else ordinary diff
2746 my ($to_mode_oct, $to_mode_str, $to_file_type);
2747 my ($from_mode_oct, $from_mode_str, $from_file_type);
2748 if ($diff->{'to_mode'} ne ('0' x
6)) {
2749 $to_mode_oct = oct $diff->{'to_mode'};
2750 if (S_ISREG
($to_mode_oct)) { # only for regular file
2751 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2753 $to_file_type = file_type
($diff->{'to_mode'});
2755 if ($diff->{'from_mode'} ne ('0' x
6)) {
2756 $from_mode_oct = oct $diff->{'from_mode'};
2757 if (S_ISREG
($to_mode_oct)) { # only for regular file
2758 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2760 $from_file_type = file_type
($diff->{'from_mode'});
2763 if ($diff->{'status'} eq "A") { # created
2764 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2765 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2766 $mode_chng .= "]</span>";
2768 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2769 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2770 -class => "list"}, esc_path
($diff->{'file'}));
2772 print "<td>$mode_chng</td>\n";
2773 print "<td class=\"link\">";
2774 if ($action eq 'commitdiff') {
2777 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2780 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2781 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2785 } elsif ($diff->{'status'} eq "D") { # deleted
2786 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2788 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2789 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2790 -class => "list"}, esc_path
($diff->{'file'}));
2792 print "<td>$mode_chng</td>\n";
2793 print "<td class=\"link\">";
2794 if ($action eq 'commitdiff') {
2797 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2800 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2801 hash_base
=>$parent, file_name
=>$diff->{'file'})},
2804 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2805 file_name
=>$diff->{'file'})},
2808 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2809 file_name
=>$diff->{'file'})},
2813 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2814 my $mode_chnge = "";
2815 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2816 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2817 if ($from_file_type ne $to_file_type) {
2818 $mode_chnge .= " from $from_file_type to $to_file_type";
2820 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2821 if ($from_mode_str && $to_mode_str) {
2822 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2823 } elsif ($to_mode_str) {
2824 $mode_chnge .= " mode: $to_mode_str";
2827 $mode_chnge .= "]</span>\n";
2830 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2831 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2832 -class => "list"}, esc_path
($diff->{'file'}));
2834 print "<td>$mode_chnge</td>\n";
2835 print "<td class=\"link\">";
2836 if ($action eq 'commitdiff') {
2839 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2841 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2842 # "commit" view and modified file (not onlu mode changed)
2843 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2844 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2845 hash_base
=>$hash, hash_parent_base
=>$parent,
2846 file_name
=>$diff->{'file'})},
2850 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2851 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2854 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2855 file_name
=>$diff->{'file'})},
2858 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2859 file_name
=>$diff->{'file'})},
2863 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
2864 my %status_name = ('R' => 'moved', 'C' => 'copied');
2865 my $nstatus = $status_name{$diff->{'status'}};
2867 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2868 # mode also for directories, so we cannot use $to_mode_str
2869 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2872 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2873 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
2874 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
2875 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2876 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2877 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
2878 -class => "list"}, esc_path
($diff->{'from_file'})) .
2879 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2880 "<td class=\"link\">";
2881 if ($action eq 'commitdiff') {
2884 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2886 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2887 # "commit" view and modified file (not only pure rename or copy)
2888 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2889 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2890 hash_base
=>$hash, hash_parent_base
=>$parent,
2891 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
2895 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2896 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
2899 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2900 file_name
=>$diff->{'to_file'})},
2903 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2904 file_name
=>$diff->{'to_file'})},
2908 } # we should not encounter Unmerged (U) or Unknown (X) status
2911 print "</tbody>" if $has_header;
2915 sub git_patchset_body
{
2916 my ($fd, $difftree, $hash, @hash_parents) = @_;
2917 my ($hash_parent) = $hash_parents[0];
2920 my $patch_number = 0;
2925 print "<div class=\"patchset\">\n";
2927 # skip to first patch
2928 while ($patch_line = <$fd>) {
2931 last if ($patch_line =~ m/^diff /);
2935 while ($patch_line) {
2937 my ($from_id, $to_id);
2940 #assert($patch_line =~ m/^diff /) if DEBUG;
2941 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2943 push @diff_header, $patch_line;
2945 # extended diff header
2947 while ($patch_line = <$fd>) {
2950 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2952 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2955 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2956 $from_id = [ split(',', $1) ];
2960 push @diff_header, $patch_line;
2962 my $last_patch_line = $patch_line;
2964 # check if current patch belong to current raw line
2965 # and parse raw git-diff line if needed
2966 if (defined $diffinfo &&
2967 defined $from_id && defined $to_id &&
2968 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
2969 $diffinfo->{'to_id'} eq $to_id) {
2970 # this is continuation of a split patch
2971 print "<div class=\"patch cont\">\n";
2973 # advance raw git-diff output if needed
2974 $patch_idx++ if defined $diffinfo;
2976 # read and prepare patch information
2977 if (ref($difftree->[$patch_idx]) eq "HASH") {
2978 # pre-parsed (or generated by hand)
2979 $diffinfo = $difftree->[$patch_idx];
2981 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2983 # modifies %from, %to hashes
2984 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
2985 if ($diffinfo->{'nparents'}) {
2989 fill_from_file_info
($diffinfo, @hash_parents)
2990 unless exists $diffinfo->{'from_file'};
2991 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2992 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2993 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2994 $from{'href'}[$i] = href
(action
=>"blob",
2995 hash_base
=>$hash_parents[$i],
2996 hash
=>$diffinfo->{'from_id'}[$i],
2997 file_name
=>$from{'file'}[$i]);
2999 $from{'href'}[$i] = undef;
3003 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
3004 if ($diffinfo->{'status'} ne "A") { # not new (added) file
3005 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
3006 hash
=>$diffinfo->{'from_id'},
3007 file_name
=>$from{'file'});
3009 delete $from{'href'};
3013 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
3014 if (!is_deleted
($diffinfo)) { # file exists in result
3015 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
3016 hash
=>$diffinfo->{'to_id'},
3017 file_name
=>$to{'file'});
3021 # this is first patch for raw difftree line with $patch_idx index
3022 # we index @$difftree array from 0, but number patches from 1
3023 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3026 # print "git diff" header
3027 $patch_line = shift @diff_header;
3028 print format_git_diff_header_line
($patch_line, $diffinfo,
3031 # print extended diff header
3032 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
3034 foreach $patch_line (@diff_header) {
3035 print format_extended_diff_header_line
($patch_line, $diffinfo,
3038 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
3040 # from-file/to-file diff header
3041 $patch_line = $last_patch_line;
3042 if (! $patch_line) {
3043 print "</div>\n"; # class="patch"
3046 next PATCH
if ($patch_line =~ m/^diff /);
3047 #assert($patch_line =~ m/^---/) if DEBUG;
3048 #assert($patch_line eq $last_patch_line) if DEBUG;
3050 $patch_line = <$fd>;
3052 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3054 print format_diff_from_to_header
($last_patch_line, $patch_line,
3055 $diffinfo, \
%from, \
%to,
3060 while ($patch_line = <$fd>) {
3063 next PATCH
if ($patch_line =~ m/^diff /);
3065 print format_diff_line
($patch_line, \
%from, \
%to);
3069 print "</div>\n"; # class="patch"
3072 if ($patch_number == 0) {
3073 if (@hash_parents > 1) {
3074 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3076 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3080 print "</div>\n"; # class="patchset"
3083 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3085 sub git_project_list_body
{
3086 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3088 my ($check_forks) = gitweb_check_feature
('forks');
3091 foreach my $pr (@
$projlist) {
3092 my (@aa) = git_get_last_activity
($pr->{'path'});
3096 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3097 if (!defined $pr->{'descr'}) {
3098 my $descr = git_get_project_description
($pr->{'path'}) || "";
3099 $pr->{'descr_long'} = to_utf8
($descr);
3100 $pr->{'descr'} = chop_str
($descr, 25, 5);
3102 if (!defined $pr->{'owner'}) {
3103 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
3106 my $pname = $pr->{'path'};
3107 if (($pname =~ s/\.git$//) &&
3108 ($pname !~ /\/$/) &&
3109 (-d
"$projectroot/$pname")) {
3110 $pr->{'forks'} = "-d $projectroot/$pname";
3116 push @projects, $pr;
3119 $order ||= $default_projects_order;
3120 $from = 0 unless defined $from;
3121 $to = $#projects if (!defined $to || $#projects < $to);
3123 print "<table class=\"project_list\">\n";
3124 unless ($no_header) {
3127 print "<th></th>\n";
3129 if ($order eq "project") {
3130 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3131 print "<th>Project</th>\n";
3134 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3135 -class => "header"}, "Project") .
3138 if ($order eq "descr") {
3139 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3140 print "<th>Description</th>\n";
3143 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3144 -class => "header"}, "Description") .
3147 if ($order eq "owner") {
3148 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3149 print "<th>Owner</th>\n";
3152 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3153 -class => "header"}, "Owner") .
3156 if ($order eq "age") {
3157 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3158 print "<th>Last Change</th>\n";
3161 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3162 -class => "header"}, "Last Change") .
3165 print "<th></th>\n" .
3169 for (my $i = $from; $i <= $to; $i++) {
3170 my $pr = $projects[$i];
3172 print "<tr class=\"dark\">\n";
3174 print "<tr class=\"light\">\n";
3179 if ($pr->{'forks'}) {
3180 print "<!-- $pr->{'forks'} -->\n";
3181 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3185 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3186 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3187 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3188 -class => "list", -title
=> $pr->{'descr_long'}},
3189 esc_html
($pr->{'descr'})) . "</td>\n" .
3190 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
3191 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3192 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
3193 "<td class=\"link\">" .
3194 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3195 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3196 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3197 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3198 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3202 if (defined $extra) {
3205 print "<td></td>\n";
3207 print "<td colspan=\"5\">$extra</td>\n" .
3213 sub git_shortlog_body
{
3214 # uses global variable $project
3215 my ($commitlist, $from, $to, $refs, $extra) = @_;
3217 my $have_snapshot = gitweb_have_snapshot
();
3219 $from = 0 unless defined $from;
3220 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3222 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3224 for (my $i = $from; $i <= $to; $i++) {
3225 my %co = %{$commitlist->[$i]};
3226 my $commit = $co{'id'};
3227 my $ref = format_ref_marker
($refs, $commit);
3229 print "<tr class=\"dark\">\n";
3231 print "<tr class=\"light\">\n";
3234 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3235 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3236 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3238 print format_subject_html
($co{'title'}, $co{'title_short'},
3239 href
(action
=>"commit", hash
=>$commit), $ref);
3241 "<td class=\"link\">" .
3242 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3243 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3244 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3245 if ($have_snapshot) {
3246 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
3251 if (defined $extra) {
3253 "<td colspan=\"4\">$extra</td>\n" .
3259 sub git_history_body
{
3260 # Warning: assumes constant type (blob or tree) during history
3261 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3263 $from = 0 unless defined $from;
3264 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3266 print "<table class=\"history\" cellspacing=\"0\">\n";
3268 for (my $i = $from; $i <= $to; $i++) {
3269 my %co = %{$commitlist->[$i]};
3273 my $commit = $co{'id'};
3275 my $ref = format_ref_marker
($refs, $commit);
3278 print "<tr class=\"dark\">\n";
3280 print "<tr class=\"light\">\n";
3283 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3284 # shortlog uses chop_str($co{'author_name'}, 10)
3285 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3287 # originally git_history used chop_str($co{'title'}, 50)
3288 print format_subject_html
($co{'title'}, $co{'title_short'},
3289 href
(action
=>"commit", hash
=>$commit), $ref);
3291 "<td class=\"link\">" .
3292 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3293 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3295 if ($ftype eq 'blob') {
3296 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3297 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3298 if (defined $blob_current && defined $blob_parent &&
3299 $blob_current ne $blob_parent) {
3301 $cgi->a({-href
=> href
(action
=>"blobdiff",
3302 hash
=>$blob_current, hash_parent
=>$blob_parent,
3303 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3304 file_name
=>$file_name)},
3311 if (defined $extra) {
3313 "<td colspan=\"4\">$extra</td>\n" .
3320 # uses global variable $project
3321 my ($taglist, $from, $to, $extra) = @_;
3322 $from = 0 unless defined $from;
3323 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3325 print "<table class=\"tags\" cellspacing=\"0\">\n";
3327 for (my $i = $from; $i <= $to; $i++) {
3328 my $entry = $taglist->[$i];
3330 my $comment = $tag{'subject'};
3332 if (defined $comment) {
3333 $comment_short = chop_str
($comment, 30, 5);
3336 print "<tr class=\"dark\">\n";
3338 print "<tr class=\"light\">\n";
3341 if (defined $tag{'age'}) {
3342 print "<td><i>$tag{'age'}</i></td>\n";
3344 print "<td></td>\n";
3347 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3348 -class => "list name"}, esc_html
($tag{'name'})) .
3351 if (defined $comment) {
3352 print format_subject_html
($comment, $comment_short,
3353 href
(action
=>"tag", hash
=>$tag{'id'}));
3356 "<td class=\"selflink\">";
3357 if ($tag{'type'} eq "tag") {
3358 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3363 "<td class=\"link\">" . " | " .
3364 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3365 if ($tag{'reftype'} eq "commit") {
3366 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3367 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3368 } elsif ($tag{'reftype'} eq "blob") {
3369 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3374 if (defined $extra) {
3376 "<td colspan=\"5\">$extra</td>\n" .
3382 sub git_heads_body
{
3383 # uses global variable $project
3384 my ($headlist, $head, $from, $to, $extra) = @_;
3385 $from = 0 unless defined $from;
3386 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3388 print "<table class=\"heads\" cellspacing=\"0\">\n";
3390 for (my $i = $from; $i <= $to; $i++) {
3391 my $entry = $headlist->[$i];
3393 my $curr = $ref{'id'} eq $head;
3395 print "<tr class=\"dark\">\n";
3397 print "<tr class=\"light\">\n";
3400 print "<td><i>$ref{'age'}</i></td>\n" .
3401 ($curr ?
"<td class=\"current_head\">" : "<td>") .
3402 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3403 -class => "list name"},esc_html
($ref{'name'})) .
3405 "<td class=\"link\">" .
3406 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3407 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3408 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3412 if (defined $extra) {
3414 "<td colspan=\"3\">$extra</td>\n" .
3420 sub git_search_grep_body
{
3421 my ($commitlist, $from, $to, $extra) = @_;
3422 $from = 0 unless defined $from;
3423 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3425 print "<table class=\"grep\" cellspacing=\"0\">\n";
3427 for (my $i = $from; $i <= $to; $i++) {
3428 my %co = %{$commitlist->[$i]};
3432 my $commit = $co{'id'};
3434 print "<tr class=\"dark\">\n";
3436 print "<tr class=\"light\">\n";
3439 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3440 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3442 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3443 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3444 my $comment = $co{'comment'};
3445 foreach my $line (@
$comment) {
3446 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3447 my $lead = esc_html
($1) || "";
3448 $lead = chop_str
($lead, 30, 10);
3449 my $match = esc_html
($2) || "";
3450 my $trail = esc_html
($3) || "";
3451 $trail = chop_str
($trail, 30, 10);
3452 my $text = "$lead<span class=\"match\">$match</span>$trail";
3453 print chop_str
($text, 80, 5) . "<br/>\n";
3457 "<td class=\"link\">" .
3458 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3460 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3464 if (defined $extra) {
3466 "<td colspan=\"3\">$extra</td>\n" .
3472 ## ======================================================================
3473 ## ======================================================================
3476 sub git_project_list
{
3477 my $order = $cgi->param('o');
3478 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3479 die_error
(undef, "Unknown order parameter");
3482 my @list = git_get_projects_list
();
3484 die_error
(undef, "No projects found");
3488 if (-f
$home_text) {
3489 print "<div class=\"index_include\">\n";
3490 open (my $fd, $home_text);
3495 git_project_list_body
(\
@list, $order);
3500 my $order = $cgi->param('o');
3501 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3502 die_error
(undef, "Unknown order parameter");
3505 my @list = git_get_projects_list
($project);
3507 die_error
(undef, "No forks found");
3511 git_print_page_nav
('','');
3512 git_print_header_div
('summary', "$project forks");
3513 git_project_list_body
(\
@list, $order);
3517 sub git_project_index
{
3518 my @projects = git_get_projects_list
($project);
3521 -type
=> 'text/plain',
3522 -charset
=> 'utf-8',
3523 -content_disposition
=> 'inline; filename="index.aux"');
3525 foreach my $pr (@projects) {
3526 if (!exists $pr->{'owner'}) {
3527 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3530 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3531 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3532 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3533 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3537 print "$path $owner\n";
3542 my $descr = git_get_project_description
($project) || "none";
3543 my %co = parse_commit
("HEAD");
3544 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3545 my $head = $co{'id'};
3547 my $owner = git_get_project_owner
($project);
3549 my $refs = git_get_references
();
3550 # These get_*_list functions return one more to allow us to see if
3551 # there are more ...
3552 my @taglist = git_get_tags_list
(16);
3553 my @headlist = git_get_heads_list
(16);
3555 my ($check_forks) = gitweb_check_feature
('forks');
3558 @forklist = git_get_projects_list
($project);
3562 git_print_page_nav
('summary','', $head);
3564 print "<div class=\"title\"> </div>\n";
3565 print "<table cellspacing=\"0\">\n" .
3566 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3567 "<tr><td>owner</td><td>$owner</td></tr>\n";
3568 if (defined $cd{'rfc2822'}) {
3569 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3572 # use per project git URL list in $projectroot/$project/cloneurl
3573 # or make project git URL from git base URL and project name
3574 my $url_tag = "URL";
3575 my @url_list = git_get_project_url_list
($project);
3576 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3577 foreach my $git_url (@url_list) {
3578 next unless $git_url;
3579 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3584 if (-s
"$projectroot/$project/README.html") {
3585 if (open my $fd, "$projectroot/$project/README.html") {
3586 print "<div class=\"title\">readme</div>\n";
3587 print $_ while (<$fd>);
3592 # we need to request one more than 16 (0..15) to check if
3594 my @commitlist = $head ? parse_commits
($head, 17) : ();
3596 git_print_header_div
('shortlog');
3597 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3598 $#commitlist <= 15 ?
undef :
3599 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3603 git_print_header_div
('tags');
3604 git_tags_body
(\
@taglist, 0, 15,
3605 $#taglist <= 15 ?
undef :
3606 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3610 git_print_header_div
('heads');
3611 git_heads_body
(\
@headlist, $head, 0, 15,
3612 $#headlist <= 15 ?
undef :
3613 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3617 git_print_header_div
('forks');
3618 git_project_list_body
(\
@forklist, undef, 0, 15,
3619 $#forklist <= 15 ?
undef :
3620 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3628 my $head = git_get_head_hash
($project);
3630 git_print_page_nav
('','', $head,undef,$head);
3631 my %tag = parse_tag
($hash);
3634 die_error
(undef, "Unknown tag object");
3637 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3638 print "<div class=\"title_text\">\n" .
3639 "<table cellspacing=\"0\">\n" .
3641 "<td>object</td>\n" .
3642 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3643 $tag{'object'}) . "</td>\n" .
3644 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3645 $tag{'type'}) . "</td>\n" .
3647 if (defined($tag{'author'})) {
3648 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3649 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3650 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3651 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3654 print "</table>\n\n" .
3656 print "<div class=\"page_body\">";
3657 my $comment = $tag{'comment'};
3658 foreach my $line (@
$comment) {
3660 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3670 my ($have_blame) = gitweb_check_feature
('blame');
3672 die_error
('403 Permission denied', "Permission denied");
3674 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3675 $hash_base ||= git_get_head_hash
($project);
3676 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3677 my %co = parse_commit
($hash_base)
3678 or die_error
(undef, "Reading commit failed");
3679 if (!defined $hash) {
3680 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3681 or die_error
(undef, "Error looking up file");
3683 $ftype = git_get_type
($hash);
3684 if ($ftype !~ "blob") {
3685 die_error
('400 Bad Request', "Object is not a blob");
3687 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3688 $file_name, $hash_base)
3689 or die_error
(undef, "Open git-blame failed");
3692 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3695 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3698 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3700 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3701 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3702 git_print_page_path
($file_name, $ftype, $hash_base);
3703 my @rev_color = (qw(light2 dark2));
3704 my $num_colors = scalar(@rev_color);
3705 my $current_color = 0;
3708 <div class="page_body">
3709 <table class="blame">
3710 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3715 last unless defined $_;
3716 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3717 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3718 if (!exists $metainfo{$full_rev}) {
3719 $metainfo{$full_rev} = {};
3721 my $meta = $metainfo{$full_rev};
3724 if (/^(\S+) (.*)$/) {
3730 my $rev = substr($full_rev, 0, 8);
3731 my $author = $meta->{'author'};
3732 my %date = parse_date
($meta->{'author-time'},
3733 $meta->{'author-tz'});
3734 my $date = $date{'iso-tz'};
3736 $current_color = ++$current_color % $num_colors;
3738 print "<tr class=\"$rev_color[$current_color]\">\n";
3740 print "<td class=\"sha1\"";
3741 print " title=\"". esc_html
($author) . ", $date\"";
3742 print " rowspan=\"$group_size\"" if ($group_size > 1);
3744 print $cgi->a({-href
=> href
(action
=>"commit",
3746 file_name
=>$file_name)},
3750 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3751 or die_error
(undef, "Open git-rev-parse failed");
3752 my $parent_commit = <$dd>;
3754 chomp($parent_commit);
3755 my $blamed = href
(action
=> 'blame',
3756 file_name
=> $meta->{'filename'},
3757 hash_base
=> $parent_commit);
3758 print "<td class=\"linenr\">";
3759 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3761 -class => "linenr" },
3764 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3770 or print "Reading blob failed\n";
3777 my ($have_blame) = gitweb_check_feature
('blame');
3779 die_error
('403 Permission denied', "Permission denied");
3781 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3782 $hash_base ||= git_get_head_hash
($project);
3783 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3784 my %co = parse_commit
($hash_base)
3785 or die_error
(undef, "Reading commit failed");
3786 if (!defined $hash) {
3787 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3788 or die_error
(undef, "Error lookup file");
3790 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3791 or die_error
(undef, "Open git-annotate failed");
3794 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3797 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3800 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3802 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3803 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3804 git_print_page_path
($file_name, 'blob', $hash_base);
3805 print "<div class=\"page_body\">\n";
3807 <table class="blame">
3816 my @line_class = (qw(light dark));
3817 my $line_class_len = scalar (@line_class);
3818 my $line_class_num = $#line_class;
3819 while (my $line = <$fd>) {
3831 $line_class_num = ($line_class_num + 1) % $line_class_len;
3833 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3840 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
3843 $short_rev = substr ($long_rev, 0, 8);
3844 $age = time () - $time;
3845 $age_str = age_string
($age);
3846 $age_str =~ s/ / /g;
3847 $age_class = age_class
($age);
3848 $author = esc_html
($author);
3849 $author =~ s/ / /g;
3851 $data = untabify
($data);
3852 $data = esc_html
($data);
3855 <tr class="$line_class[$line_class_num]">
3856 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3857 <td class="$age_class">$age_str</td>
3859 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3860 <td class="pre">$data</td>
3863 } # while (my $line = <$fd>)
3864 print "</table>\n\n";
3866 or print "Reading blob failed.\n";
3872 my $head = git_get_head_hash
($project);
3874 git_print_page_nav
('','', $head,undef,$head);
3875 git_print_header_div
('summary', $project);
3877 my @tagslist = git_get_tags_list
();
3879 git_tags_body
(\
@tagslist);
3885 my $head = git_get_head_hash
($project);
3887 git_print_page_nav
('','', $head,undef,$head);
3888 git_print_header_div
('summary', $project);
3890 my @headslist = git_get_heads_list
();
3892 git_heads_body
(\
@headslist, $head);
3897 sub git_blob_plain
{
3900 if (!defined $hash) {
3901 if (defined $file_name) {
3902 my $base = $hash_base || git_get_head_hash
($project);
3903 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3904 or die_error
(undef, "Error lookup file");
3906 die_error
(undef, "No file name defined");
3908 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3909 # blobs defined by non-textual hash id's can be cached
3914 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3915 or die_error
(undef, "Couldn't cat $file_name, $hash");
3917 $type ||= blob_mimetype
($fd, $file_name);
3919 # save as filename, even when no $file_name is given
3920 my $save_as = "$hash";
3921 if (defined $file_name) {
3922 $save_as = $file_name;
3923 } elsif ($type =~ m/^text\//) {
3930 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3932 binmode STDOUT
, ':raw';
3934 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3942 if (!defined $hash) {
3943 if (defined $file_name) {
3944 my $base = $hash_base || git_get_head_hash
($project);
3945 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3946 or die_error
(undef, "Error lookup file");
3948 die_error
(undef, "No file name defined");
3950 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3951 # blobs defined by non-textual hash id's can be cached
3955 my ($have_blame) = gitweb_check_feature
('blame');
3956 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3957 or die_error
(undef, "Couldn't cat $file_name, $hash");
3958 my $mimetype = blob_mimetype
($fd, $file_name);
3959 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3961 return git_blob_plain
($mimetype);
3963 # we can have blame only for text/* mimetype
3964 $have_blame &&= ($mimetype =~ m!^text/!);
3966 git_header_html
(undef, $expires);
3967 my $formats_nav = '';
3968 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3969 if (defined $file_name) {
3972 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3973 hash
=>$hash, file_name
=>$file_name)},
3978 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3979 hash
=>$hash, file_name
=>$file_name)},
3982 $cgi->a({-href
=> href
(action
=>"blob_plain",
3983 hash
=>$hash, file_name
=>$file_name)},
3986 $cgi->a({-href
=> href
(action
=>"blob",
3987 hash_base
=>"HEAD", file_name
=>$file_name)},
3991 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3993 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3994 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3996 print "<div class=\"page_nav\">\n" .
3997 "<br/><br/></div>\n" .
3998 "<div class=\"title\">$hash</div>\n";
4000 git_print_page_path
($file_name, "blob", $hash_base);
4001 print "<div class=\"page_body\">\n";
4002 if ($mimetype =~ m!^text/!) {
4004 while (my $line = <$fd>) {
4007 $line = untabify
($line);
4008 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4009 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4011 } elsif ($mimetype =~ m!^image/!) {
4012 print qq!<img type
="$mimetype"!;
4014 print qq! alt
="$file_name" title
="$file_name"!;
4017 href(action=>"blob_plain
", hash=>$hash,
4018 hash_base=>$hash_base, file_name=>$file_name) .
4022 or print "Reading blob failed.\n";
4028 my $have_snapshot = gitweb_have_snapshot
();
4030 if (!defined $hash_base) {
4031 $hash_base = "HEAD";
4033 if (!defined $hash) {
4034 if (defined $file_name) {
4035 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4041 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4042 or die_error
(undef, "Open git-ls-tree failed");
4043 my @entries = map { chomp; $_ } <$fd>;
4044 close $fd or die_error
(undef, "Reading tree failed");
4047 my $refs = git_get_references
();
4048 my $ref = format_ref_marker
($refs, $hash_base);
4051 my ($have_blame) = gitweb_check_feature
('blame');
4052 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4054 if (defined $file_name) {
4056 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4057 hash
=>$hash, file_name
=>$file_name)},
4059 $cgi->a({-href
=> href
(action
=>"tree",
4060 hash_base
=>"HEAD", file_name
=>$file_name)},
4063 if ($have_snapshot) {
4064 # FIXME: Should be available when we have no hash base as well.
4066 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
4069 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4070 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4073 print "<div class=\"page_nav\">\n";
4074 print "<br/><br/></div>\n";
4075 print "<div class=\"title\">$hash</div>\n";
4077 if (defined $file_name) {
4078 $basedir = $file_name;
4079 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4083 git_print_page_path
($file_name, 'tree', $hash_base);
4084 print "<div class=\"page_body\">\n";
4085 print "<table cellspacing=\"0\">\n";
4087 # '..' (top directory) link if possible
4088 if (defined $hash_base &&
4089 defined $file_name && $file_name =~ m![^/]+$!) {
4091 print "<tr class=\"dark\">\n";
4093 print "<tr class=\"light\">\n";
4097 my $up = $file_name;
4098 $up =~ s!/?[^/]+$!!;
4099 undef $up unless $up;
4100 # based on git_print_tree_entry
4101 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4102 print '<td class="list">';
4103 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4107 print "<td class=\"link\"></td>\n";
4111 foreach my $line (@entries) {
4112 my %t = parse_ls_tree_line
($line, -z
=> 1);
4115 print "<tr class=\"dark\">\n";
4117 print "<tr class=\"light\">\n";
4121 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4125 print "</table>\n" .
4131 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
4132 my $have_snapshot = (defined $ctype && defined $suffix);
4133 if (!$have_snapshot) {
4134 die_error
('403 Permission denied', "Permission denied");
4137 if (!defined $hash) {
4138 $hash = git_get_head_hash
($project);
4141 my $git = git_cmd_str
();
4142 my $name = $project;
4143 $name =~ s/\047/\047\\\047\047/g;
4144 my $filename = to_utf8
(basename
($project));
4146 if ($suffix eq 'zip') {
4147 $filename .= "-$hash.$suffix";
4148 $cmd = "$git archive --format=zip --prefix=\'$name\'/ $hash";
4150 $filename .= "-$hash.tar.$suffix";
4151 $cmd = "$git archive --format=tar --prefix=\'$name\'/ $hash | $command";
4155 -type
=> "application/$ctype",
4156 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4157 -status
=> '200 OK');
4159 open my $fd, "-|", $cmd
4160 or die_error
(undef, "Execute git-archive failed");
4161 binmode STDOUT
, ':raw';
4163 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4169 my $head = git_get_head_hash
($project);
4170 if (!defined $hash) {
4173 if (!defined $page) {
4176 my $refs = git_get_references
();
4178 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4180 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4183 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4186 my %co = parse_commit
($hash);
4188 git_print_header_div
('summary', $project);
4189 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4191 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
4192 for (my $i = 0; $i <= $to; $i++) {
4193 my %co = %{$commitlist[$i]};
4195 my $commit = $co{'id'};
4196 my $ref = format_ref_marker
($refs, $commit);
4197 my %ad = parse_date
($co{'author_epoch'});
4198 git_print_header_div
('commit',
4199 "<span class=\"age\">$co{'age_string'}</span>" .
4200 esc_html
($co{'title'}) . $ref,
4202 print "<div class=\"title_text\">\n" .
4203 "<div class=\"log_link\">\n" .
4204 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4206 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4208 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4211 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4214 print "<div class=\"log_body\">\n";
4215 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4218 if ($#commitlist >= 100) {
4219 print "<div class=\"page_nav\">\n";
4220 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4221 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4228 $hash ||= $hash_base || "HEAD";
4229 my %co = parse_commit
($hash);
4231 die_error
(undef, "Unknown commit object");
4233 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4234 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4236 my $parent = $co{'parent'};
4237 my $parents = $co{'parents'}; # listref
4239 # we need to prepare $formats_nav before any parameter munging
4241 if (!defined $parent) {
4243 $formats_nav .= '(initial)';
4244 } elsif (@
$parents == 1) {
4245 # single parent commit
4248 $cgi->a({-href
=> href
(action
=>"commit",
4250 esc_html
(substr($parent, 0, 7))) .
4257 $cgi->a({-href
=> href
(action
=>"commit",
4259 esc_html
(substr($_, 0, 7)));
4264 if (!defined $parent) {
4268 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4270 (@
$parents <= 1 ?
$parent : '-c'),
4272 or die_error
(undef, "Open git-diff-tree failed");
4273 @difftree = map { chomp; $_ } <$fd>;
4274 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4276 # non-textual hash id's can be cached
4278 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4281 my $refs = git_get_references
();
4282 my $ref = format_ref_marker
($refs, $co{'id'});
4284 my $have_snapshot = gitweb_have_snapshot
();
4286 git_header_html
(undef, $expires);
4287 git_print_page_nav
('commit', '',
4288 $hash, $co{'tree'}, $hash,
4291 if (defined $co{'parent'}) {
4292 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4294 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4296 print "<div class=\"title_text\">\n" .
4297 "<table cellspacing=\"0\">\n";
4298 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4300 "<td></td><td> $ad{'rfc2822'}";
4301 if ($ad{'hour_local'} < 6) {
4302 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4303 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4305 printf(" (%02d:%02d %s)",
4306 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4310 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4311 print "<tr><td></td><td> $cd{'rfc2822'}" .
4312 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4314 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4317 "<td class=\"sha1\">" .
4318 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4319 class => "list"}, $co{'tree'}) .
4321 "<td class=\"link\">" .
4322 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4324 if ($have_snapshot) {
4326 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
4331 foreach my $par (@
$parents) {
4334 "<td class=\"sha1\">" .
4335 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4336 class => "list"}, $par) .
4338 "<td class=\"link\">" .
4339 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4341 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4348 print "<div class=\"page_body\">\n";
4349 git_print_log
($co{'comment'});
4352 git_difftree_body
(\
@difftree, $hash, @
$parents);
4358 # object is defined by:
4359 # - hash or hash_base alone
4360 # - hash_base and file_name
4363 # - hash or hash_base alone
4364 if ($hash || ($hash_base && !defined $file_name)) {
4365 my $object_id = $hash || $hash_base;
4367 my $git_command = git_cmd_str
();
4368 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4369 or die_error
('404 Not Found', "Object does not exist");
4373 or die_error
('404 Not Found', "Object does not exist");
4375 # - hash_base and file_name
4376 } elsif ($hash_base && defined $file_name) {
4377 $file_name =~ s
,/+$,,;
4379 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4380 or die_error
('404 Not Found', "Base object does not exist");
4382 # here errors should not hapen
4383 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4384 or die_error
(undef, "Open git-ls-tree failed");
4388 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4389 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4390 die_error
('404 Not Found', "File or directory for given base does not exist");
4395 die_error
('404 Not Found', "Not enough information to find object");
4398 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4399 hash
=>$hash, hash_base
=>$hash_base,
4400 file_name
=>$file_name),
4401 -status
=> '302 Found');
4405 my $format = shift || 'html';
4412 # preparing $fd and %diffinfo for git_patchset_body
4414 if (defined $hash_base && defined $hash_parent_base) {
4415 if (defined $file_name) {
4417 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4418 $hash_parent_base, $hash_base,
4419 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4420 or die_error
(undef, "Open git-diff-tree failed");
4421 @difftree = map { chomp; $_ } <$fd>;
4423 or die_error
(undef, "Reading git-diff-tree failed");
4425 or die_error
('404 Not Found', "Blob diff not found");
4427 } elsif (defined $hash &&
4428 $hash =~ /[0-9a-fA-F]{40}/) {
4429 # try to find filename from $hash
4431 # read filtered raw output
4432 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4433 $hash_parent_base, $hash_base, "--"
4434 or die_error
(undef, "Open git-diff-tree failed");
4436 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4438 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4439 map { chomp; $_ } <$fd>;
4441 or die_error
(undef, "Reading git-diff-tree failed");
4443 or die_error
('404 Not Found', "Blob diff not found");
4446 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4449 if (@difftree > 1) {
4450 die_error
('404 Not Found', "Ambiguous blob diff specification");
4453 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4454 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4455 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4457 $hash_parent ||= $diffinfo{'from_id'};
4458 $hash ||= $diffinfo{'to_id'};
4460 # non-textual hash id's can be cached
4461 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4462 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4467 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4468 '-p', ($format eq 'html' ?
"--full-index" : ()),
4469 $hash_parent_base, $hash_base,
4470 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4471 or die_error
(undef, "Open git-diff-tree failed");
4474 # old/legacy style URI
4475 if (!%diffinfo && # if new style URI failed
4476 defined $hash && defined $hash_parent) {
4477 # fake git-diff-tree raw output
4478 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4479 $diffinfo{'from_id'} = $hash_parent;
4480 $diffinfo{'to_id'} = $hash;
4481 if (defined $file_name) {
4482 if (defined $file_parent) {
4483 $diffinfo{'status'} = '2';
4484 $diffinfo{'from_file'} = $file_parent;
4485 $diffinfo{'to_file'} = $file_name;
4486 } else { # assume not renamed
4487 $diffinfo{'status'} = '1';
4488 $diffinfo{'from_file'} = $file_name;
4489 $diffinfo{'to_file'} = $file_name;
4491 } else { # no filename given
4492 $diffinfo{'status'} = '2';
4493 $diffinfo{'from_file'} = $hash_parent;
4494 $diffinfo{'to_file'} = $hash;
4497 # non-textual hash id's can be cached
4498 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4499 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4504 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4505 '-p', ($format eq 'html' ?
"--full-index" : ()),
4506 $hash_parent, $hash, "--"
4507 or die_error
(undef, "Open git-diff failed");
4509 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4514 if ($format eq 'html') {
4516 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4517 hash
=>$hash, hash_parent
=>$hash_parent,
4518 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4519 file_name
=>$file_name, file_parent
=>$file_parent)},
4521 git_header_html
(undef, $expires);
4522 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4523 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4524 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4526 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4527 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4529 if (defined $file_name) {
4530 git_print_page_path
($file_name, "blob", $hash_base);
4532 print "<div class=\"page_path\"></div>\n";
4535 } elsif ($format eq 'plain') {
4537 -type
=> 'text/plain',
4538 -charset
=> 'utf-8',
4539 -expires
=> $expires,
4540 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4542 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4545 die_error
(undef, "Unknown blobdiff format");
4549 if ($format eq 'html') {
4550 print "<div class=\"page_body\">\n";
4552 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4555 print "</div>\n"; # class="page_body"
4559 while (my $line = <$fd>) {
4560 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4561 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4565 last if $line =~ m!^\+\+\+!;
4573 sub git_blobdiff_plain
{
4574 git_blobdiff
('plain');
4577 sub git_commitdiff
{
4578 my $format = shift || 'html';
4579 $hash ||= $hash_base || "HEAD";
4580 my %co = parse_commit
($hash);
4582 die_error
(undef, "Unknown commit object");
4585 # we need to prepare $formats_nav before any parameter munging
4587 if ($format eq 'html') {
4589 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4590 hash
=>$hash, hash_parent
=>$hash_parent)},
4593 if (defined $hash_parent) {
4594 # commitdiff with two commits given
4595 my $hash_parent_short = $hash_parent;
4596 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4597 $hash_parent_short = substr($hash_parent, 0, 7);
4601 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
4602 if ($co{'parents'}[$i] eq $hash_parent) {
4603 $formats_nav .= ' parent ' . ($i+1);
4607 $formats_nav .= ': ' .
4608 $cgi->a({-href
=> href
(action
=>"commitdiff",
4609 hash
=>$hash_parent)},
4610 esc_html
($hash_parent_short)) .
4612 } elsif (!$co{'parent'}) {
4614 $formats_nav .= ' (initial)';
4615 } elsif (scalar @
{$co{'parents'}} == 1) {
4616 # single parent commit
4619 $cgi->a({-href
=> href
(action
=>"commitdiff",
4620 hash
=>$co{'parent'})},
4621 esc_html
(substr($co{'parent'}, 0, 7))) .
4628 $cgi->a({-href
=> href
(action
=>"commitdiff",
4630 esc_html
(substr($_, 0, 7)));
4631 } @
{$co{'parents'}} ) .
4636 my $hash_parent_param = $hash_parent;
4637 if (!defined $hash_parent) {
4638 $hash_parent_param =
4639 @
{$co{'parents'}} > 1 ?
'-c' : $co{'parent'} || '--root';
4645 if ($format eq 'html') {
4646 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4647 "--no-commit-id", "--patch-with-raw", "--full-index",
4648 $hash_parent_param, $hash, "--"
4649 or die_error
(undef, "Open git-diff-tree failed");
4651 while (my $line = <$fd>) {
4653 # empty line ends raw part of diff-tree output
4655 push @difftree, scalar parse_difftree_raw_line
($line);
4658 } elsif ($format eq 'plain') {
4659 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4660 '-p', $hash_parent_param, $hash, "--"
4661 or die_error
(undef, "Open git-diff-tree failed");
4664 die_error
(undef, "Unknown commitdiff format");
4667 # non-textual hash id's can be cached
4669 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4673 # write commit message
4674 if ($format eq 'html') {
4675 my $refs = git_get_references
();
4676 my $ref = format_ref_marker
($refs, $co{'id'});
4678 git_header_html
(undef, $expires);
4679 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4680 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4681 git_print_authorship
(\
%co);
4682 print "<div class=\"page_body\">\n";
4683 if (@
{$co{'comment'}} > 1) {
4684 print "<div class=\"log\">\n";
4685 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4686 print "</div>\n"; # class="log"
4689 } elsif ($format eq 'plain') {
4690 my $refs = git_get_references
("tags");
4691 my $tagname = git_get_rev_name_tags
($hash);
4692 my $filename = basename
($project) . "-$hash.patch";
4695 -type
=> 'text/plain',
4696 -charset
=> 'utf-8',
4697 -expires
=> $expires,
4698 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4699 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4702 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4703 Subject: $co{'title'}
4705 print "X-Git-Tag: $tagname\n" if $tagname;
4706 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4708 foreach my $line (@
{$co{'comment'}}) {
4715 if ($format eq 'html') {
4716 git_difftree_body
(\
@difftree, $hash, $hash_parent || @
{$co{'parents'}});
4719 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent || @
{$co{'parents'}});
4721 print "</div>\n"; # class="page_body"
4724 } elsif ($format eq 'plain') {
4728 or print "Reading git-diff-tree failed\n";
4732 sub git_commitdiff_plain
{
4733 git_commitdiff
('plain');
4737 if (!defined $hash_base) {
4738 $hash_base = git_get_head_hash
($project);
4740 if (!defined $page) {
4744 my %co = parse_commit
($hash_base);
4746 die_error
(undef, "Unknown commit object");
4749 my $refs = git_get_references
();
4750 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4752 if (!defined $hash && defined $file_name) {
4753 $hash = git_get_hash_by_path
($hash_base, $file_name);
4755 if (defined $hash) {
4756 $ftype = git_get_type
($hash);
4759 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4761 my $paging_nav = '';
4764 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4765 file_name
=>$file_name)},
4767 $paging_nav .= " ⋅ " .
4768 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4769 file_name
=>$file_name, page
=>$page-1),
4770 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4772 $paging_nav .= "first";
4773 $paging_nav .= " ⋅ prev";
4775 if ($#commitlist >= 100) {
4776 $paging_nav .= " ⋅ " .
4777 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4778 file_name
=>$file_name, page
=>$page+1),
4779 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4781 $paging_nav .= " ⋅ next";
4784 if ($#commitlist >= 100) {
4786 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4787 file_name
=>$file_name, page
=>$page+1),
4788 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4792 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4793 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4794 git_print_page_path
($file_name, $ftype, $hash_base);
4796 git_history_body
(\
@commitlist, 0, 99,
4797 $refs, $hash_base, $ftype, $next_link);
4803 my ($have_search) = gitweb_check_feature
('search');
4804 if (!$have_search) {
4805 die_error
('403 Permission denied', "Permission denied");
4807 if (!defined $searchtext) {
4808 die_error
(undef, "Text field empty");
4810 if (!defined $hash) {
4811 $hash = git_get_head_hash
($project);
4813 my %co = parse_commit
($hash);
4815 die_error
(undef, "Unknown commit object");
4817 if (!defined $page) {
4821 $searchtype ||= 'commit';
4822 if ($searchtype eq 'pickaxe') {
4823 # pickaxe may take all resources of your box and run for several minutes
4824 # with every query - so decide by yourself how public you make this feature
4825 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4826 if (!$have_pickaxe) {
4827 die_error
('403 Permission denied', "Permission denied");
4830 if ($searchtype eq 'grep') {
4831 my ($have_grep) = gitweb_check_feature
('grep');
4833 die_error
('403 Permission denied', "Permission denied");
4839 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4841 if ($searchtype eq 'commit') {
4842 $greptype = "--grep=";
4843 } elsif ($searchtype eq 'author') {
4844 $greptype = "--author=";
4845 } elsif ($searchtype eq 'committer') {
4846 $greptype = "--committer=";
4848 $greptype .= $search_regexp;
4849 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4851 my $paging_nav = '';
4854 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4855 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4857 $paging_nav .= " ⋅ " .
4858 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4859 searchtext
=>$searchtext, searchtype
=>$searchtype,
4861 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4863 $paging_nav .= "first";
4864 $paging_nav .= " ⋅ prev";
4866 if ($#commitlist >= 100) {
4867 $paging_nav .= " ⋅ " .
4868 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4869 searchtext
=>$searchtext, searchtype
=>$searchtype,
4871 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4873 $paging_nav .= " ⋅ next";
4876 if ($#commitlist >= 100) {
4878 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4879 searchtext
=>$searchtext, searchtype
=>$searchtype,
4881 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4884 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4885 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4886 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4889 if ($searchtype eq 'pickaxe') {
4890 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4891 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4893 print "<table cellspacing=\"0\">\n";
4896 my $git_command = git_cmd_str
();
4897 my $searchqtext = $searchtext;
4898 $searchqtext =~ s/'/'\\''/;
4899 open my $fd, "-|", "$git_command rev-list $hash | " .
4900 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
4903 while (my $line = <$fd>) {
4904 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4907 $set{'from_id'} = $3;
4909 $set{'id'} = $set{'to_id'};
4910 if ($set{'id'} =~ m/0{40}/) {
4911 $set{'id'} = $set{'from_id'};
4913 if ($set{'id'} =~ m/0{40}/) {
4917 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4920 print "<tr class=\"dark\">\n";
4922 print "<tr class=\"light\">\n";
4925 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4926 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4928 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4929 -class => "list subject"},
4930 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4931 while (my $setref = shift @files) {
4933 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4934 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4936 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4940 "<td class=\"link\">" .
4941 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4943 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4947 %co = parse_commit
($1);
4955 if ($searchtype eq 'grep') {
4956 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4957 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4959 print "<table cellspacing=\"0\">\n";
4963 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
4965 while (my $line = <$fd>) {
4967 my ($file, $lno, $ltext, $binary);
4968 last if ($matches++ > 1000);
4969 if ($line =~ /^Binary file (.+) matches$/) {
4973 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
4975 if ($file ne $lastfile) {
4976 $lastfile and print "</td></tr>\n";
4978 print "<tr class=\"dark\">\n";
4980 print "<tr class=\"light\">\n";
4982 print "<td class=\"list\">".
4983 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
4984 file_name
=>"$file"),
4985 -class => "list"}, esc_path
($file));
4986 print "</td><td>\n";
4990 print "<div class=\"binary\">Binary file</div>\n";
4992 $ltext = untabify
($ltext);
4993 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
4994 $ltext = esc_html
($1, -nbsp
=>1);
4995 $ltext .= '<span class="match">';
4996 $ltext .= esc_html
($2, -nbsp
=>1);
4997 $ltext .= '</span>';
4998 $ltext .= esc_html
($3, -nbsp
=>1);
5000 $ltext = esc_html
($ltext, -nbsp
=>1);
5002 print "<div class=\"pre\">" .
5003 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5004 file_name
=>"$file").'#l'.$lno,
5005 -class => "linenr"}, sprintf('%4i', $lno))
5006 . ' ' . $ltext . "</div>\n";
5010 print "</td></tr>\n";
5011 if ($matches > 1000) {
5012 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5015 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5024 sub git_search_help
{
5026 git_print_page_nav
('','', $hash,$hash,$hash);
5029 <dt><b>commit</b></dt>
5030 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
5032 my ($have_grep) = gitweb_check_feature
('grep');
5035 <dt><b>grep</b></dt>
5036 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5037 a different one) are searched for the given
5038 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5039 (POSIX extended) and the matches are listed. On large
5040 trees, this search can take a while and put some strain on the server, so please use it with
5041 some consideration.</dd>
5045 <dt><b>author</b></dt>
5046 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5047 <dt><b>committer</b></dt>
5048 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5050 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5051 if ($have_pickaxe) {
5053 <dt><b>pickaxe</b></dt>
5054 <dd>All commits that caused the string to appear or disappear from any file (changes that
5055 added, removed or "modified" the string) will be listed. This search can take a while and
5056 takes a lot of strain on the server, so please use it wisely.</dd>
5064 my $head = git_get_head_hash
($project);
5065 if (!defined $hash) {
5068 if (!defined $page) {
5071 my $refs = git_get_references
();
5073 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5075 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
5077 if ($#commitlist >= 100) {
5079 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
5080 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5084 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5085 git_print_header_div
('summary', $project);
5087 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5092 ## ......................................................................
5093 ## feeds (RSS, Atom; OPML)
5096 my $format = shift || 'atom';
5097 my ($have_blame) = gitweb_check_feature
('blame');
5099 # Atom: http://www.atomenabled.org/developers/syndication/
5100 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5101 if ($format ne 'rss' && $format ne 'atom') {
5102 die_error
(undef, "Unknown web feed format");
5105 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5106 my $head = $hash || 'HEAD';
5107 my @commitlist = parse_commits
($head, 150);
5111 my $content_type = "application/$format+xml";
5112 if (defined $cgi->http('HTTP_ACCEPT') &&
5113 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5114 # browser (feed reader) prefers text/xml
5115 $content_type = 'text/xml';
5117 if (defined($commitlist[0])) {
5118 %latest_commit = %{$commitlist[0]};
5119 %latest_date = parse_date
($latest_commit{'author_epoch'});
5121 -type
=> $content_type,
5122 -charset
=> 'utf-8',
5123 -last_modified
=> $latest_date{'rfc2822'});
5126 -type
=> $content_type,
5127 -charset
=> 'utf-8');
5130 # Optimization: skip generating the body if client asks only
5131 # for Last-Modified date.
5132 return if ($cgi->request_method() eq 'HEAD');
5135 my $title = "$site_name - $project/$action";
5136 my $feed_type = 'log';
5137 if (defined $hash) {
5138 $title .= " - '$hash'";
5139 $feed_type = 'branch log';
5140 if (defined $file_name) {
5141 $title .= " :: $file_name";
5142 $feed_type = 'history';
5144 } elsif (defined $file_name) {
5145 $title .= " - $file_name";
5146 $feed_type = 'history';
5148 $title .= " $feed_type";
5149 my $descr = git_get_project_description
($project);
5150 if (defined $descr) {
5151 $descr = esc_html
($descr);
5153 $descr = "$project " .
5154 ($format eq 'rss' ?
'RSS' : 'Atom') .
5157 my $owner = git_get_project_owner
($project);
5158 $owner = esc_html
($owner);
5162 if (defined $file_name) {
5163 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5164 } elsif (defined $hash) {
5165 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5167 $alt_url = href
(-full
=>1, action
=>"summary");
5169 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
5170 if ($format eq 'rss') {
5172 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5175 print "<title>$title</title>\n" .
5176 "<link>$alt_url</link>\n" .
5177 "<description>$descr</description>\n" .
5178 "<language>en</language>\n";
5179 } elsif ($format eq 'atom') {
5181 <feed xmlns="http://www.w3.org/2005/Atom">
5183 print "<title>$title</title>\n" .
5184 "<subtitle>$descr</subtitle>\n" .
5185 '<link rel="alternate" type="text/html" href="' .
5186 $alt_url . '" />' . "\n" .
5187 '<link rel="self" type="' . $content_type . '" href="' .
5188 $cgi->self_url() . '" />' . "\n" .
5189 "<id>" . href
(-full
=>1) . "</id>\n" .
5190 # use project owner for feed author
5191 "<author><name>$owner</name></author>\n";
5192 if (defined $favicon) {
5193 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5195 if (defined $logo_url) {
5196 # not twice as wide as tall: 72 x 27 pixels
5197 print "<logo>" . esc_url
($logo) . "</logo>\n";
5199 if (! %latest_date) {
5200 # dummy date to keep the feed valid until commits trickle in:
5201 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5203 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5208 for (my $i = 0; $i <= $#commitlist; $i++) {
5209 my %co = %{$commitlist[$i]};
5210 my $commit = $co{'id'};
5211 # we read 150, we always show 30 and the ones more recent than 48 hours
5212 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5215 my %cd = parse_date
($co{'author_epoch'});
5217 # get list of changed files
5218 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5219 $co{'parent'} || "--root",
5220 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
5222 my @difftree = map { chomp; $_ } <$fd>;
5226 # print element (entry, item)
5227 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5228 if ($format eq 'rss') {
5230 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5231 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5232 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5233 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5234 "<link>$co_url</link>\n" .
5235 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5236 "<content:encoded>" .
5238 } elsif ($format eq 'atom') {
5240 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5241 "<updated>$cd{'iso-8601'}</updated>\n" .
5243 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5244 if ($co{'author_email'}) {
5245 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5247 print "</author>\n" .
5248 # use committer for contributor
5250 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5251 if ($co{'committer_email'}) {
5252 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5254 print "</contributor>\n" .
5255 "<published>$cd{'iso-8601'}</published>\n" .
5256 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5257 "<id>$co_url</id>\n" .
5258 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5259 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5261 my $comment = $co{'comment'};
5263 foreach my $line (@
$comment) {
5264 $line = esc_html
($line);
5267 print "</pre><ul>\n";
5268 foreach my $difftree_line (@difftree) {
5269 my %difftree = parse_difftree_raw_line
($difftree_line);
5270 next if !$difftree{'from_id'};
5272 my $file = $difftree{'file'} || $difftree{'to_file'};
5276 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5277 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5278 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5279 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5280 -title
=> "diff"}, 'D');
5282 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5283 file_name
=>$file, hash_base
=>$commit),
5284 -title
=> "blame"}, 'B');
5286 # if this is not a feed of a file history
5287 if (!defined $file_name || $file_name ne $file) {
5288 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5289 file_name
=>$file, hash
=>$commit),
5290 -title
=> "history"}, 'H');
5292 $file = esc_path
($file);
5296 if ($format eq 'rss') {
5297 print "</ul>]]>\n" .
5298 "</content:encoded>\n" .
5300 } elsif ($format eq 'atom') {
5301 print "</ul>\n</div>\n" .
5308 if ($format eq 'rss') {
5309 print "</channel>\n</rss>\n";
5310 } elsif ($format eq 'atom') {
5324 my @list = git_get_projects_list
();
5326 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5328 <?xml version="1.0" encoding="utf-8"?>
5329 <opml version="1.0">
5331 <title>$site_name OPML Export</title>
5334 <outline text="git RSS feeds">
5337 foreach my $pr (@list) {
5339 my $head = git_get_head_hash
($proj{'path'});
5340 if (!defined $head) {
5343 $git_dir = "$projectroot/$proj{'path'}";
5344 my %co = parse_commit
($head);
5349 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5350 my $rss = "$my_url?p=$proj{'path'};a=rss";
5351 my $html = "$my_url?p=$proj{'path'};a=summary";
5352 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";