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 our $version = "++GIT_VERSION++";
23 our $my_url = $cgi->url();
24 our $my_uri = $cgi->url(-absolute
=> 1);
26 # core git executable to use
27 # this can just be "git" if your webserver has a sensible PATH
28 our $GIT = "++GIT_BINDIR++/git";
30 # absolute fs-path which will be prepended to the project path
31 #our $projectroot = "/pub/scm";
32 our $projectroot = "++GITWEB_PROJECTROOT++";
34 # target of the home link on top of all pages
35 our $home_link = $my_uri || "/";
37 # string of the home link on top of all pages
38 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
40 # name of your site or organization to appear in page titles
41 # replace this with something more descriptive for clearer bookmarks
42 our $site_name = "++GITWEB_SITENAME++"
43 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
45 # filename of html text to include at top of each page
46 our $site_header = "++GITWEB_SITE_HEADER++";
47 # html text to include at home page
48 our $home_text = "++GITWEB_HOMETEXT++";
49 # filename of html text to include at bottom of each page
50 our $site_footer = "++GITWEB_SITE_FOOTER++";
53 our @stylesheets = ("++GITWEB_CSS++");
54 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
55 our $stylesheet = undef;
56 # URI of GIT logo (72x27 size)
57 our $logo = "++GITWEB_LOGO++";
58 # URI of GIT favicon, assumed to be image/png type
59 our $favicon = "++GITWEB_FAVICON++";
61 # URI and label (title) of GIT logo link
62 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
63 #our $logo_label = "git documentation";
64 our $logo_url = "http://git.or.cz/";
65 our $logo_label = "git homepage";
67 # source of projects list
68 our $projects_list = "++GITWEB_LIST++";
70 # show repository only if this file exists
71 # (only effective if this variable evaluates to true)
72 our $export_ok = "++GITWEB_EXPORT_OK++";
74 # only allow viewing of repositories also shown on the overview page
75 our $strict_export = "++GITWEB_STRICT_EXPORT++";
77 # list of git base URLs used for URL to where fetch project from,
78 # i.e. full URL is "$git_base_url/$project"
79 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
81 # default blob_plain mimetype and default charset for text/plain blob
82 our $default_blob_plain_mimetype = 'text/plain';
83 our $default_text_plain_charset = undef;
85 # file to use for guessing MIME types before trying /etc/mime.types
86 # (relative to the current git repository)
87 our $mimetypes_file = undef;
89 # You define site-wide feature defaults here; override them with
90 # $GITWEB_CONFIG as necessary.
93 # 'sub' => feature-sub (subroutine),
94 # 'override' => allow-override (boolean),
95 # 'default' => [ default options...] (array reference)}
97 # if feature is overridable (it means that allow-override has true value,
98 # then feature-sub will be called with default options as parameters;
99 # return value of feature-sub indicates if to enable specified feature
101 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
103 # Enable the 'blame' blob view, showing the last commit that modified
104 # each line in the file. This can be very CPU-intensive.
106 # To enable system wide have in $GITWEB_CONFIG
107 # $feature{'blame'}{'default'} = [1];
108 # To have project specific config enable override in $GITWEB_CONFIG
109 # $feature{'blame'}{'override'} = 1;
110 # and in project config gitweb.blame = 0|1;
112 'sub' => \
&feature_blame
,
116 # Enable the 'snapshot' link, providing a compressed tarball of any
117 # tree. This can potentially generate high traffic if you have large
120 # To disable system wide have in $GITWEB_CONFIG
121 # $feature{'snapshot'}{'default'} = [undef];
122 # To have project specific config enable override in $GITWEB_CONFIG
123 # $feature{'snapshot'}{'override'} = 1;
124 # and in project config gitweb.snapshot = none|gzip|bzip2;
126 'sub' => \
&feature_snapshot
,
128 # => [content-encoding, suffix, program]
129 'default' => ['x-gzip', 'gz', 'gzip']},
131 # Enable text search, which will list the commits which match author,
132 # committer or commit text to a given string. Enabled by default.
137 # Enable the pickaxe search, which will list the commits that modified
138 # a given string in a file. This can be practical and quite faster
139 # alternative to 'blame', but still potentially CPU-intensive.
141 # To enable system wide have in $GITWEB_CONFIG
142 # $feature{'pickaxe'}{'default'} = [1];
143 # To have project specific config enable override in $GITWEB_CONFIG
144 # $feature{'pickaxe'}{'override'} = 1;
145 # and in project config gitweb.pickaxe = 0|1;
147 'sub' => \
&feature_pickaxe
,
151 # Make gitweb use an alternative format of the URLs which can be
152 # more readable and natural-looking: project name is embedded
153 # directly in the path and the query string contains other
154 # auxiliary information. All gitweb installations recognize
155 # URL in either format; this configures in which formats gitweb
158 # To enable system wide have in $GITWEB_CONFIG
159 # $feature{'pathinfo'}{'default'} = [1];
160 # Project specific override is not supported.
162 # Note that you will need to change the default location of CSS,
163 # favicon, logo and possibly other files to an absolute URL. Also,
164 # if gitweb.cgi serves as your indexfile, you will need to force
165 # $my_uri to contain the script name in your $GITWEB_CONFIG.
170 # Make gitweb consider projects in project root subdirectories
171 # to be forks of existing projects. Given project $projname.git,
172 # projects matching $projname/*.git will not be shown in the main
173 # projects list, instead a '+' mark will be added to $projname
174 # there and a 'forks' view will be enabled for the project, listing
175 # all the forks. This feature is supported only if project list
176 # is taken from a directory, not file.
178 # To enable system wide have in $GITWEB_CONFIG
179 # $feature{'forks'}{'default'} = [1];
180 # Project specific override is not supported.
186 sub gitweb_check_feature
{
188 return unless exists $feature{$name};
189 my ($sub, $override, @defaults) = (
190 $feature{$name}{'sub'},
191 $feature{$name}{'override'},
192 @
{$feature{$name}{'default'}});
193 if (!$override) { return @defaults; }
195 warn "feature $name is not overrideable";
198 return $sub->(@defaults);
202 my ($val) = git_get_project_config
('blame', '--bool');
204 if ($val eq 'true') {
206 } elsif ($val eq 'false') {
213 sub feature_snapshot
{
214 my ($ctype, $suffix, $command) = @_;
216 my ($val) = git_get_project_config
('snapshot');
218 if ($val eq 'gzip') {
219 return ('x-gzip', 'gz', 'gzip');
220 } elsif ($val eq 'bzip2') {
221 return ('x-bzip2', 'bz2', 'bzip2');
222 } elsif ($val eq 'none') {
226 return ($ctype, $suffix, $command);
229 sub gitweb_have_snapshot
{
230 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
231 my $have_snapshot = (defined $ctype && defined $suffix);
233 return $have_snapshot;
236 sub feature_pickaxe
{
237 my ($val) = git_get_project_config
('pickaxe', '--bool');
239 if ($val eq 'true') {
241 } elsif ($val eq 'false') {
248 # checking HEAD file with -e is fragile if the repository was
249 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
251 sub check_head_link
{
253 my $headfile = "$dir/HEAD";
254 return ((-e
$headfile) ||
255 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
258 sub check_export_ok
{
260 return (check_head_link
($dir) &&
261 (!$export_ok || -e
"$dir/$export_ok"));
264 # rename detection options for git-diff and git-diff-tree
265 # - default is '-M', with the cost proportional to
266 # (number of removed files) * (number of new files).
267 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
268 # (number of changed files + number of removed files) * (number of new files)
269 # - even more costly is '-C', '--find-copies-harder' with cost
270 # (number of files in the original tree) * (number of new files)
271 # - one might want to include '-B' option, e.g. '-B', '-M'
272 our @diff_opts = ('-M'); # taken from git_commit
274 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
275 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
277 # version of the core git binary
278 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
280 $projects_list ||= $projectroot;
282 # ======================================================================
283 # input validation and dispatch
284 our $action = $cgi->param('a');
285 if (defined $action) {
286 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
287 die_error
(undef, "Invalid action parameter");
291 # parameters which are pathnames
292 our $project = $cgi->param('p');
293 if (defined $project) {
294 if (!validate_pathname
($project) ||
295 !(-d
"$projectroot/$project") ||
296 !check_head_link
("$projectroot/$project") ||
297 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
298 ($strict_export && !project_in_list
($project))) {
300 die_error
(undef, "No such project");
304 our $file_name = $cgi->param('f');
305 if (defined $file_name) {
306 if (!validate_pathname
($file_name)) {
307 die_error
(undef, "Invalid file parameter");
311 our $file_parent = $cgi->param('fp');
312 if (defined $file_parent) {
313 if (!validate_pathname
($file_parent)) {
314 die_error
(undef, "Invalid file parent parameter");
318 # parameters which are refnames
319 our $hash = $cgi->param('h');
321 if (!validate_refname
($hash)) {
322 die_error
(undef, "Invalid hash parameter");
326 our $hash_parent = $cgi->param('hp');
327 if (defined $hash_parent) {
328 if (!validate_refname
($hash_parent)) {
329 die_error
(undef, "Invalid hash parent parameter");
333 our $hash_base = $cgi->param('hb');
334 if (defined $hash_base) {
335 if (!validate_refname
($hash_base)) {
336 die_error
(undef, "Invalid hash base parameter");
340 our $hash_parent_base = $cgi->param('hpb');
341 if (defined $hash_parent_base) {
342 if (!validate_refname
($hash_parent_base)) {
343 die_error
(undef, "Invalid hash parent base parameter");
348 our $page = $cgi->param('pg');
350 if ($page =~ m/[^0-9]/) {
351 die_error
(undef, "Invalid page parameter");
355 our $searchtext = $cgi->param('s');
356 if (defined $searchtext) {
357 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
358 die_error
(undef, "Invalid search parameter");
360 if (length($searchtext) < 2) {
361 die_error
(undef, "At least two characters are required for search parameter");
363 $searchtext = quotemeta $searchtext;
366 our $searchtype = $cgi->param('st');
367 if (defined $searchtype) {
368 if ($searchtype =~ m/[^a-z]/) {
369 die_error
(undef, "Invalid searchtype parameter");
373 # now read PATH_INFO and use it as alternative to parameters
374 sub evaluate_path_info
{
375 return if defined $project;
376 my $path_info = $ENV{"PATH_INFO"};
377 return if !$path_info;
378 $path_info =~ s
,^/+,,;
379 return if !$path_info;
380 # find which part of PATH_INFO is project
381 $project = $path_info;
383 while ($project && !check_head_link
("$projectroot/$project")) {
384 $project =~ s
,/*[^/]*$,,;
387 $project = validate_pathname
($project);
389 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
390 ($strict_export && !project_in_list
($project))) {
394 # do not change any parameters if an action is given using the query string
396 $path_info =~ s
,^$project/*,,;
397 my ($refname, $pathname) = split(/:/, $path_info, 2);
398 if (defined $pathname) {
399 # we got "project.git/branch:filename" or "project.git/branch:dir/"
400 # we could use git_get_type(branch:pathname), but it needs $git_dir
401 $pathname =~ s
,^/+,,;
402 if (!$pathname || substr($pathname, -1) eq "/") {
406 $action ||= "blob_plain";
408 $hash_base ||= validate_refname
($refname);
409 $file_name ||= validate_pathname
($pathname);
410 } elsif (defined $refname) {
411 # we got "project.git/branch"
412 $action ||= "shortlog";
413 $hash ||= validate_refname
($refname);
416 evaluate_path_info
();
418 # path to the current git repository
420 $git_dir = "$projectroot/$project" if $project;
424 "blame" => \
&git_blame2
,
425 "blobdiff" => \
&git_blobdiff
,
426 "blobdiff_plain" => \
&git_blobdiff_plain
,
427 "blob" => \
&git_blob
,
428 "blob_plain" => \
&git_blob_plain
,
429 "commitdiff" => \
&git_commitdiff
,
430 "commitdiff_plain" => \
&git_commitdiff_plain
,
431 "commit" => \
&git_commit
,
432 "forks" => \
&git_forks
,
433 "heads" => \
&git_heads
,
434 "history" => \
&git_history
,
437 "atom" => \
&git_atom
,
438 "search" => \
&git_search
,
439 "search_help" => \
&git_search_help
,
440 "shortlog" => \
&git_shortlog
,
441 "summary" => \
&git_summary
,
443 "tags" => \
&git_tags
,
444 "tree" => \
&git_tree
,
445 "snapshot" => \
&git_snapshot
,
446 "object" => \
&git_object
,
447 # those below don't need $project
448 "opml" => \
&git_opml
,
449 "project_list" => \
&git_project_list
,
450 "project_index" => \
&git_project_index
,
453 if (defined $project) {
454 $action ||= 'summary';
456 $action ||= 'project_list';
458 if (!defined($actions{$action})) {
459 die_error
(undef, "Unknown action");
461 if ($action !~ m/^(opml|project_list|project_index)$/ &&
463 die_error
(undef, "Project needed");
465 $actions{$action}->();
468 ## ======================================================================
473 # default is to use -absolute url() i.e. $my_uri
474 my $href = $params{-full
} ?
$my_url : $my_uri;
476 # XXX: Warning: If you touch this, check the search form for updating,
487 hash_parent_base
=> "hpb",
493 my %mapping = @mapping;
495 $params{'project'} = $project unless exists $params{'project'};
497 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
499 # use PATH_INFO for project name
500 $href .= "/$params{'project'}" if defined $params{'project'};
501 delete $params{'project'};
503 # Summary just uses the project path URL
504 if (defined $params{'action'} && $params{'action'} eq 'summary') {
505 delete $params{'action'};
509 # now encode the parameters explicitly
511 for (my $i = 0; $i < @mapping; $i += 2) {
512 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
513 if (defined $params{$name}) {
514 push @result, $symbol . "=" . esc_param
($params{$name});
517 $href .= "?" . join(';', @result) if scalar @result;
523 ## ======================================================================
524 ## validation, quoting/unquoting and escaping
526 sub validate_pathname
{
527 my $input = shift || return undef;
529 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
530 # at the beginning, at the end, and between slashes.
531 # also this catches doubled slashes
532 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
536 if ($input =~ m!\0!) {
542 sub validate_refname
{
543 my $input = shift || return undef;
545 # textual hashes are O.K.
546 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
549 # it must be correct pathname
550 $input = validate_pathname
($input)
552 # restrictions on ref name according to git-check-ref-format
553 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
559 # very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT);
562 return decode
("utf8", $str, Encode
::FB_DEFAULT
);
565 # quote unsafe chars, but keep the slash, even when it's not
566 # correct, but quoted slashes look too horrible in bookmarks
569 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
575 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
578 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
584 # replace invalid utf8 character with SUBSTITUTION sequence
589 $str = to_utf8
($str);
590 $str = escapeHTML
($str);
591 if ($opts{'-nbsp'}) {
592 $str =~ s/ / /g;
594 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
598 # quote control characters and escape filename to HTML
603 $str = to_utf8
($str);
604 $str = escapeHTML
($str);
605 if ($opts{'-nbsp'}) {
606 $str =~ s/ / /g;
608 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
612 # Make control characters "printable", using character escape codes (CEC)
615 my %es = ( # character escape codes, aka escape sequences
616 "\t" => '\t', # tab (HT)
617 "\n" => '\n', # line feed (LF)
618 "\r" => '\r', # carrige return (CR)
619 "\f" => '\f', # form feed (FF)
620 "\b" => '\b', # backspace (BS)
621 "\a" => '\a', # alarm (bell) (BEL)
622 "\e" => '\e', # escape (ESC)
623 "\013" => '\v', # vertical tab (VT)
624 "\000" => '\0', # nul character (NUL)
626 my $chr = ( (exists $es{$cntrl})
628 : sprintf('\%03o', ord($cntrl)) );
629 return "<span class=\"cntrl\">$chr</span>";
632 # Alternatively use unicode control pictures codepoints,
633 # Unicode "printable representation" (PR)
636 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
637 return "<span class=\"cntrl\">$chr</span>";
640 # git may return quoted and escaped filenames
646 my %es = ( # character escape codes, aka escape sequences
647 't' => "\t", # tab (HT, TAB)
648 'n' => "\n", # newline (NL)
649 'r' => "\r", # return (CR)
650 'f' => "\f", # form feed (FF)
651 'b' => "\b", # backspace (BS)
652 'a' => "\a", # alarm (bell) (BEL)
653 'e' => "\e", # escape (ESC)
654 'v' => "\013", # vertical tab (VT)
657 if ($seq =~ m/^[0-7]{1,3}$/) {
658 # octal char sequence
659 return chr(oct($seq));
660 } elsif (exists $es{$seq}) {
661 # C escape sequence, aka character escape code
664 # quoted ordinary character
668 if ($str =~ m/^"(.*)"$/) {
671 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
676 # escape tabs (convert tabs to spaces)
680 while ((my $pos = index($line, "\t")) != -1) {
681 if (my $count = (8 - ($pos % 8))) {
682 my $spaces = ' ' x
$count;
683 $line =~ s/\t/$spaces/;
690 sub project_in_list
{
692 my @list = git_get_projects_list
();
693 return @list && scalar(grep { $_->{'path'} eq $project } @list);
696 ## ----------------------------------------------------------------------
697 ## HTML aware string manipulation
702 my $add_len = shift || 10;
704 # allow only $len chars, but don't cut a word if it would fit in $add_len
705 # if it doesn't fit, cut it if it's still longer than the dots we would add
706 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
709 if (length($tail) > 4) {
711 $body =~ s/&[^;]*$//; # remove chopped character entities
716 ## ----------------------------------------------------------------------
717 ## functions returning short strings
719 # CSS class for given age value (in seconds)
723 if ($age < 60*60*2) {
725 } elsif ($age < 60*60*24*2) {
732 # convert age in seconds to "nn units ago" string
737 if ($age > 60*60*24*365*2) {
738 $age_str = (int $age/60/60/24/365);
739 $age_str .= " years ago";
740 } elsif ($age > 60*60*24*(365/12)*2) {
741 $age_str = int $age/60/60/24/(365/12);
742 $age_str .= " months ago";
743 } elsif ($age > 60*60*24*7*2) {
744 $age_str = int $age/60/60/24/7;
745 $age_str .= " weeks ago";
746 } elsif ($age > 60*60*24*2) {
747 $age_str = int $age/60/60/24;
748 $age_str .= " days ago";
749 } elsif ($age > 60*60*2) {
750 $age_str = int $age/60/60;
751 $age_str .= " hours ago";
752 } elsif ($age > 60*2) {
753 $age_str = int $age/60;
754 $age_str .= " min ago";
757 $age_str .= " sec ago";
759 $age_str .= " right now";
764 # convert file mode in octal to symbolic file mode string
766 my $mode = oct shift;
768 if (S_ISDIR
($mode & S_IFMT
)) {
770 } elsif (S_ISLNK
($mode)) {
772 } elsif (S_ISREG
($mode)) {
773 # git cares only about the executable bit
774 if ($mode & S_IXUSR
) {
784 # convert file mode in octal to file type string
788 if ($mode !~ m/^[0-7]+$/) {
794 if (S_ISDIR
($mode & S_IFMT
)) {
796 } elsif (S_ISLNK
($mode)) {
798 } elsif (S_ISREG
($mode)) {
805 # convert file mode in octal to file type description string
809 if ($mode !~ m/^[0-7]+$/) {
815 if (S_ISDIR
($mode & S_IFMT
)) {
817 } elsif (S_ISLNK
($mode)) {
819 } elsif (S_ISREG
($mode)) {
820 if ($mode & S_IXUSR
) {
831 ## ----------------------------------------------------------------------
832 ## functions returning short HTML fragments, or transforming HTML fragments
833 ## which don't beling to other sections
835 # format line of commit message.
836 sub format_log_line_html
{
839 $line = esc_html
($line, -nbsp
=>1);
840 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
843 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
844 -class => "text"}, $hash_text);
845 $line =~ s/$hash_text/$link/;
850 # format marker of refs pointing to given object
851 sub format_ref_marker
{
852 my ($refs, $id) = @_;
855 if (defined $refs->{$id}) {
856 foreach my $ref (@
{$refs->{$id}}) {
857 my ($type, $name) = qw();
858 # e.g. tags/v2.6.11 or heads/next
859 if ($ref =~ m!^(.*?)s?/(.*)$!) {
867 $markers .= " <span class=\"$type\" title=\"$ref\">" .
868 esc_html
($name) . "</span>";
873 return ' <span class="refs">'. $markers . '</span>';
879 # format, perhaps shortened and with markers, title line
880 sub format_subject_html
{
881 my ($long, $short, $href, $extra) = @_;
882 $extra = '' unless defined($extra);
884 if (length($short) < length($long)) {
885 return $cgi->a({-href
=> $href, -class => "list subject",
886 -title
=> to_utf8
($long)},
887 esc_html
($short) . $extra);
889 return $cgi->a({-href
=> $href, -class => "list subject"},
890 esc_html
($long) . $extra);
894 # format patch (diff) line (rather not to be used for diff headers)
895 sub format_diff_line
{
897 my ($from, $to) = @_;
898 my $char = substr($line, 0, 1);
904 $diff_class = " add";
905 } elsif ($char eq "-") {
906 $diff_class = " rem";
907 } elsif ($char eq "@") {
908 $diff_class = " chunk_header";
909 } elsif ($char eq "\\") {
910 $diff_class = " incomplete";
912 $line = untabify
($line);
913 if ($from && $to && $line =~ m/^\@{2} /) {
914 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
915 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
917 $from_lines = 0 unless defined $from_lines;
918 $to_lines = 0 unless defined $to_lines;
920 if ($from->{'href'}) {
921 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
922 -class=>"list"}, $from_text);
925 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
926 -class=>"list"}, $to_text);
928 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
929 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
930 return "<div class=\"diff$diff_class\">$line</div>\n";
932 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
935 ## ----------------------------------------------------------------------
936 ## git utility subroutines, invoking git commands
938 # returns path to the core git executable and the --git-dir parameter as list
940 return $GIT, '--git-dir='.$git_dir;
943 # returns path to the core git executable and the --git-dir parameter as string
945 return join(' ', git_cmd
());
948 # get HEAD ref of given project as hash
949 sub git_get_head_hash
{
951 my $o_git_dir = $git_dir;
953 $git_dir = "$projectroot/$project";
954 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
957 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
961 if (defined $o_git_dir) {
962 $git_dir = $o_git_dir;
967 # get type of given object
971 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
978 sub git_get_project_config
{
979 my ($key, $type) = @_;
981 return unless ($key);
982 $key =~ s/^gitweb\.//;
983 return if ($key =~ m/\W/);
985 my @x = (git_cmd
(), 'repo-config');
986 if (defined $type) { push @x, $type; }
988 push @x, "gitweb.$key";
994 # get hash of given path at given ref
995 sub git_get_hash_by_path
{
997 my $path = shift || return undef;
1002 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1003 or die_error
(undef, "Open git-ls-tree failed");
1005 close $fd or return undef;
1007 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1008 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1009 if (defined $type && $type ne $2) {
1010 # type doesn't match
1016 ## ......................................................................
1017 ## git utility functions, directly accessing git repository
1019 sub git_get_project_description
{
1022 open my $fd, "$projectroot/$path/description" or return undef;
1029 sub git_get_project_url_list
{
1032 open my $fd, "$projectroot/$path/cloneurl" or return;
1033 my @git_project_url_list = map { chomp; $_ } <$fd>;
1036 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
1039 sub git_get_projects_list
{
1044 $filter =~ s/\.git$//;
1046 if (-d
$projects_list) {
1047 # search in directory
1048 my $dir = $projects_list . ($filter ?
"/$filter" : '');
1049 # remove the trailing "/"
1051 my $pfxlen = length("$dir");
1053 my ($check_forks) = gitweb_check_feature
('forks');
1056 follow_fast
=> 1, # follow symbolic links
1057 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1059 # skip project-list toplevel, if we get it.
1060 return if (m!^[/.]$!);
1061 # only directories can be git repositories
1062 return unless (-d
$_);
1064 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1065 # we check related file in $projectroot
1066 if ($check_forks and $subdir =~ m
#/.#) {
1067 $File::Find
::prune
= 1;
1068 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1069 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
1070 $File::Find
::prune
= 1;
1075 } elsif (-f
$projects_list) {
1076 # read from file(url-encoded):
1077 # 'git%2Fgit.git Linus+Torvalds'
1078 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1079 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1080 open my ($fd), $projects_list or return;
1081 while (my $line = <$fd>) {
1083 my ($path, $owner) = split ' ', $line;
1084 $path = unescape
($path);
1085 $owner = unescape
($owner);
1086 if (!defined $path) {
1089 if ($filter ne '') {
1090 # looking for forks;
1091 my $pfx = substr($path, 0, length($filter));
1092 if ($pfx ne $filter) {
1095 my $sfx = substr($path, length($filter));
1096 if ($sfx !~ /^\/.*\
.git
$/) {
1100 if (check_export_ok
("$projectroot/$path")) {
1103 owner
=> to_utf8
($owner),
1110 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
1114 sub git_get_project_owner
{
1115 my $project = shift;
1118 return undef unless $project;
1120 # read from file (url-encoded):
1121 # 'git%2Fgit.git Linus+Torvalds'
1122 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1123 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1124 if (-f
$projects_list) {
1125 open (my $fd , $projects_list);
1126 while (my $line = <$fd>) {
1128 my ($pr, $ow) = split ' ', $line;
1129 $pr = unescape
($pr);
1130 $ow = unescape
($ow);
1131 if ($pr eq $project) {
1132 $owner = to_utf8
($ow);
1138 if (!defined $owner) {
1139 $owner = get_file_owner
("$projectroot/$project");
1145 sub git_get_last_activity
{
1149 $git_dir = "$projectroot/$path";
1150 open($fd, "-|", git_cmd
(), 'for-each-ref',
1151 '--format=%(committer)',
1152 '--sort=-committerdate',
1154 'refs/heads') or return;
1155 my $most_recent = <$fd>;
1156 close $fd or return;
1157 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1159 my $age = time - $timestamp;
1160 return ($age, age_string
($age));
1164 sub git_get_references
{
1165 my $type = shift || "";
1167 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1168 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1169 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1170 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
1173 while (my $line = <$fd>) {
1175 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1176 if (defined $refs{$1}) {
1177 push @
{$refs{$1}}, $2;
1183 close $fd or return;
1187 sub git_get_rev_name_tags
{
1188 my $hash = shift || return undef;
1190 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1192 my $name_rev = <$fd>;
1195 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1198 # catches also '$hash undefined' output
1203 ## ----------------------------------------------------------------------
1204 ## parse to hash functions
1208 my $tz = shift || "-0000";
1211 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1212 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1213 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1214 $date{'hour'} = $hour;
1215 $date{'minute'} = $min;
1216 $date{'mday'} = $mday;
1217 $date{'day'} = $days[$wday];
1218 $date{'month'} = $months[$mon];
1219 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1220 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1221 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1222 $mday, $months[$mon], $hour ,$min;
1223 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1224 1900+$year, $mon, $mday, $hour ,$min, $sec;
1226 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1227 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1228 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1229 $date{'hour_local'} = $hour;
1230 $date{'minute_local'} = $min;
1231 $date{'tz_local'} = $tz;
1232 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1233 1900+$year, $mon+1, $mday,
1234 $hour, $min, $sec, $tz);
1243 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1244 $tag{'id'} = $tag_id;
1245 while (my $line = <$fd>) {
1247 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1248 $tag{'object'} = $1;
1249 } elsif ($line =~ m/^type (.+)$/) {
1251 } elsif ($line =~ m/^tag (.+)$/) {
1253 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1254 $tag{'author'} = $1;
1257 } elsif ($line =~ m/--BEGIN/) {
1258 push @comment, $line;
1260 } elsif ($line eq "") {
1264 push @comment, <$fd>;
1265 $tag{'comment'} = \
@comment;
1266 close $fd or return;
1267 if (!defined $tag{'name'}) {
1273 sub parse_commit_text
{
1274 my ($commit_text) = @_;
1275 my @commit_lines = split '\n', $commit_text;
1278 pop @commit_lines; # Remove '\0'
1280 my $header = shift @commit_lines;
1281 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1284 $co{'id'} = $header;
1286 while (my $line = shift @commit_lines) {
1287 last if $line eq "\n";
1288 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1290 } elsif ($line =~ m/^parent ([0-9a-fA-F]{40})$/) {
1292 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1294 $co{'author_epoch'} = $2;
1295 $co{'author_tz'} = $3;
1296 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1297 $co{'author_name'} = $1;
1298 $co{'author_email'} = $2;
1300 $co{'author_name'} = $co{'author'};
1302 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1303 $co{'committer'} = $1;
1304 $co{'committer_epoch'} = $2;
1305 $co{'committer_tz'} = $3;
1306 $co{'committer_name'} = $co{'committer'};
1307 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1308 $co{'committer_name'} = $1;
1309 $co{'committer_email'} = $2;
1311 $co{'committer_name'} = $co{'committer'};
1315 if (!defined $co{'tree'}) {
1318 $co{'parents'} = \
@parents;
1319 $co{'parent'} = $parents[0];
1321 foreach my $title (@commit_lines) {
1324 $co{'title'} = chop_str
($title, 80, 5);
1325 # remove leading stuff of merges to make the interesting part visible
1326 if (length($title) > 50) {
1327 $title =~ s/^Automatic //;
1328 $title =~ s/^merge (of|with) /Merge ... /i;
1329 if (length($title) > 50) {
1330 $title =~ s/(http|rsync):\/\///;
1332 if (length($title) > 50) {
1333 $title =~ s/(master|www|rsync)\.//;
1335 if (length($title) > 50) {
1336 $title =~ s/kernel.org:?//;
1338 if (length($title) > 50) {
1339 $title =~ s/\/pub\/scm//;
1342 $co{'title_short'} = chop_str
($title, 50, 5);
1346 if ($co{'title'} eq "") {
1347 $co{'title'} = $co{'title_short'} = '(no commit message)';
1349 # remove added spaces
1350 foreach my $line (@commit_lines) {
1353 $co{'comment'} = \
@commit_lines;
1355 my $age = time - $co{'committer_epoch'};
1357 $co{'age_string'} = age_string
($age);
1358 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1359 if ($age > 60*60*24*7*2) {
1360 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1361 $co{'age_string_age'} = $co{'age_string'};
1363 $co{'age_string_date'} = $co{'age_string'};
1364 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1370 my ($commit_id) = @_;
1375 open my $fd, "-|", git_cmd
(), "rev-list",
1380 or die_error
(undef, "Open git-rev-list failed");
1381 %co = parse_commit_text
(<$fd>);
1388 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1396 open my $fd, "-|", git_cmd
(), "rev-list",
1398 ($arg ?
($arg) : ()),
1399 ("--max-count=" . $maxcount),
1400 ("--skip=" . $skip),
1403 ($filename ?
($filename) : ())
1404 or die_error
(undef, "Open git-rev-list failed");
1405 while (my $line = <$fd>) {
1406 my %co = parse_commit_text
($line);
1411 return wantarray ?
@cos : \
@cos;
1414 # parse ref from ref_file, given by ref_id, with given type
1416 my $ref_file = shift;
1418 my $type = shift || git_get_type
($ref_id);
1421 $ref_item{'type'} = $type;
1422 $ref_item{'id'} = $ref_id;
1423 $ref_item{'epoch'} = 0;
1424 $ref_item{'age'} = "unknown";
1425 if ($type eq "tag") {
1426 my %tag = parse_tag
($ref_id);
1427 $ref_item{'comment'} = $tag{'comment'};
1428 if ($tag{'type'} eq "commit") {
1429 my %co = parse_commit
($tag{'object'});
1430 $ref_item{'epoch'} = $co{'committer_epoch'};
1431 $ref_item{'age'} = $co{'age_string'};
1432 } elsif (defined($tag{'epoch'})) {
1433 my $age = time - $tag{'epoch'};
1434 $ref_item{'epoch'} = $tag{'epoch'};
1435 $ref_item{'age'} = age_string
($age);
1437 $ref_item{'reftype'} = $tag{'type'};
1438 $ref_item{'name'} = $tag{'name'};
1439 $ref_item{'refid'} = $tag{'object'};
1440 } elsif ($type eq "commit"){
1441 my %co = parse_commit
($ref_id);
1442 $ref_item{'reftype'} = "commit";
1443 $ref_item{'name'} = $ref_file;
1444 $ref_item{'title'} = $co{'title'};
1445 $ref_item{'refid'} = $ref_id;
1446 $ref_item{'epoch'} = $co{'committer_epoch'};
1447 $ref_item{'age'} = $co{'age_string'};
1449 $ref_item{'reftype'} = $type;
1450 $ref_item{'name'} = $ref_file;
1451 $ref_item{'refid'} = $ref_id;
1457 # parse line of git-diff-tree "raw" output
1458 sub parse_difftree_raw_line
{
1462 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1463 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1464 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1465 $res{'from_mode'} = $1;
1466 $res{'to_mode'} = $2;
1467 $res{'from_id'} = $3;
1469 $res{'status'} = $5;
1470 $res{'similarity'} = $6;
1471 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1472 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1474 $res{'file'} = unquote
($7);
1477 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1478 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1479 $res{'commit'} = $1;
1482 return wantarray ?
%res : \
%res;
1485 # parse line of git-ls-tree output
1486 sub parse_ls_tree_line
($;%) {
1491 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1492 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1500 $res{'name'} = unquote
($4);
1503 return wantarray ?
%res : \
%res;
1506 ## ......................................................................
1507 ## parse to array of hashes functions
1509 sub git_get_heads_list
{
1513 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1514 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
1515 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1518 while (my $line = <$fd>) {
1522 my ($refinfo, $committerinfo) = split(/\0/, $line);
1523 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1524 my ($committer, $epoch, $tz) =
1525 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1526 $name =~ s!^refs/heads/!!;
1528 $ref_item{'name'} = $name;
1529 $ref_item{'id'} = $hash;
1530 $ref_item{'title'} = $title || '(no commit message)';
1531 $ref_item{'epoch'} = $epoch;
1533 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1535 $ref_item{'age'} = "unknown";
1538 push @headslist, \
%ref_item;
1542 return wantarray ?
@headslist : \
@headslist;
1545 sub git_get_tags_list
{
1549 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1550 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
1551 '--format=%(objectname) %(objecttype) %(refname) '.
1552 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1555 while (my $line = <$fd>) {
1559 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1560 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1561 my ($creator, $epoch, $tz) =
1562 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1563 $name =~ s!^refs/tags/!!;
1565 $ref_item{'type'} = $type;
1566 $ref_item{'id'} = $id;
1567 $ref_item{'name'} = $name;
1568 if ($type eq "tag") {
1569 $ref_item{'subject'} = $title;
1570 $ref_item{'reftype'} = $reftype;
1571 $ref_item{'refid'} = $refid;
1573 $ref_item{'reftype'} = $type;
1574 $ref_item{'refid'} = $id;
1577 if ($type eq "tag" || $type eq "commit") {
1578 $ref_item{'epoch'} = $epoch;
1580 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1582 $ref_item{'age'} = "unknown";
1586 push @tagslist, \
%ref_item;
1590 return wantarray ?
@tagslist : \
@tagslist;
1593 ## ----------------------------------------------------------------------
1594 ## filesystem-related functions
1596 sub get_file_owner
{
1599 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1600 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1601 if (!defined $gcos) {
1605 $owner =~ s/[,;].*$//;
1606 return to_utf8
($owner);
1609 ## ......................................................................
1610 ## mimetype related functions
1612 sub mimetype_guess_file
{
1613 my $filename = shift;
1614 my $mimemap = shift;
1615 -r
$mimemap or return undef;
1618 open(MIME
, $mimemap) or return undef;
1620 next if m/^#/; # skip comments
1621 my ($mime, $exts) = split(/\t+/);
1622 if (defined $exts) {
1623 my @exts = split(/\s+/, $exts);
1624 foreach my $ext (@exts) {
1625 $mimemap{$ext} = $mime;
1631 $filename =~ /\.([^.]*)$/;
1632 return $mimemap{$1};
1635 sub mimetype_guess
{
1636 my $filename = shift;
1638 $filename =~ /\./ or return undef;
1640 if ($mimetypes_file) {
1641 my $file = $mimetypes_file;
1642 if ($file !~ m!^/!) { # if it is relative path
1643 # it is relative to project
1644 $file = "$projectroot/$project/$file";
1646 $mime = mimetype_guess_file
($filename, $file);
1648 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1654 my $filename = shift;
1657 my $mime = mimetype_guess
($filename);
1658 $mime and return $mime;
1662 return $default_blob_plain_mimetype unless $fd;
1665 return 'text/plain' .
1666 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1667 } elsif (! $filename) {
1668 return 'application/octet-stream';
1669 } elsif ($filename =~ m/\.png$/i) {
1671 } elsif ($filename =~ m/\.gif$/i) {
1673 } elsif ($filename =~ m/\.jpe?g$/i) {
1674 return 'image/jpeg';
1676 return 'application/octet-stream';
1680 ## ======================================================================
1681 ## functions printing HTML: header, footer, error page
1683 sub git_header_html
{
1684 my $status = shift || "200 OK";
1685 my $expires = shift;
1687 my $title = "$site_name";
1688 if (defined $project) {
1689 $title .= " - $project";
1690 if (defined $action) {
1691 $title .= "/$action";
1692 if (defined $file_name) {
1693 $title .= " - " . esc_path
($file_name);
1694 if ($action eq "tree" && $file_name !~ m
|/$|) {
1701 # require explicit support from the UA if we are to send the page as
1702 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1703 # we have to do this because MSIE sometimes globs '*/*', pretending to
1704 # support xhtml+xml but choking when it gets what it asked for.
1705 if (defined $cgi->http('HTTP_ACCEPT') &&
1706 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1707 $cgi->Accept('application/xhtml+xml') != 0) {
1708 $content_type = 'application/xhtml+xml';
1710 $content_type = 'text/html';
1712 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1713 -status
=> $status, -expires
=> $expires);
1715 <?xml version="1.0" encoding="utf-8"?>
1716 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1717 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1718 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1719 <!-- git core binaries version $git_version -->
1721 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1722 <meta name="generator" content="gitweb/$version git/$git_version"/>
1723 <meta name="robots" content="index, nofollow"/>
1724 <title>$title</title>
1726 # print out each stylesheet that exist
1727 if (defined $stylesheet) {
1728 #provides backwards capability for those people who define style sheet in a config file
1729 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1731 foreach my $stylesheet (@stylesheets) {
1732 next unless $stylesheet;
1733 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1736 if (defined $project) {
1737 printf('<link rel="alternate" title="%s log RSS feed" '.
1738 'href="%s" type="application/rss+xml" />'."\n",
1739 esc_param
($project), href
(action
=>"rss"));
1740 printf('<link rel="alternate" title="%s log Atom feed" '.
1741 'href="%s" type="application/atom+xml" />'."\n",
1742 esc_param
($project), href
(action
=>"atom"));
1744 printf('<link rel="alternate" title="%s projects list" '.
1745 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1746 $site_name, href
(project
=>undef, action
=>"project_index"));
1747 printf('<link rel="alternate" title="%s projects feeds" '.
1748 'href="%s" type="text/x-opml"/>'."\n",
1749 $site_name, href
(project
=>undef, action
=>"opml"));
1751 if (defined $favicon) {
1752 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
1758 if (-f
$site_header) {
1759 open (my $fd, $site_header);
1764 print "<div class=\"page_header\">\n" .
1765 $cgi->a({-href
=> esc_url
($logo_url),
1766 -title
=> $logo_label},
1767 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
1768 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1769 if (defined $project) {
1770 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1771 if (defined $action) {
1776 my ($have_search) = gitweb_check_feature
('search');
1777 if ((defined $project) && ($have_search)) {
1778 if (!defined $searchtext) {
1782 if (defined $hash_base) {
1783 $search_hash = $hash_base;
1784 } elsif (defined $hash) {
1785 $search_hash = $hash;
1787 $search_hash = "HEAD";
1789 $cgi->param("a", "search");
1790 $cgi->param("h", $search_hash);
1791 $cgi->param("p", $project);
1792 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1793 "<div class=\"search\">\n" .
1794 $cgi->hidden(-name
=> "p") . "\n" .
1795 $cgi->hidden(-name
=> "a") . "\n" .
1796 $cgi->hidden(-name
=> "h") . "\n" .
1797 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1798 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1799 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1801 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1803 $cgi->end_form() . "\n";
1808 sub git_footer_html
{
1809 print "<div class=\"page_footer\">\n";
1810 if (defined $project) {
1811 my $descr = git_get_project_description
($project);
1812 if (defined $descr) {
1813 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1815 print $cgi->a({-href
=> href
(action
=>"rss"),
1816 -class => "rss_logo"}, "RSS") . " ";
1817 print $cgi->a({-href
=> href
(action
=>"atom"),
1818 -class => "rss_logo"}, "Atom") . "\n";
1820 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1821 -class => "rss_logo"}, "OPML") . " ";
1822 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1823 -class => "rss_logo"}, "TXT") . "\n";
1827 if (-f
$site_footer) {
1828 open (my $fd, $site_footer);
1838 my $status = shift || "403 Forbidden";
1839 my $error = shift || "Malformed query, file missing or permission denied";
1841 git_header_html
($status);
1843 <div class="page_body">
1853 ## ----------------------------------------------------------------------
1854 ## functions printing or outputting HTML: navigation
1856 sub git_print_page_nav
{
1857 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1858 $extra = '' if !defined $extra; # pager or formats
1860 my @navs = qw(summary shortlog log commit commitdiff tree);
1862 @navs = grep { $_ ne $suppress } @navs;
1865 my %arg = map { $_ => {action
=>$_} } @navs;
1866 if (defined $head) {
1867 for (qw(commit commitdiff)) {
1868 $arg{$_}{hash
} = $head;
1870 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1871 for (qw(shortlog log)) {
1872 $arg{$_}{hash
} = $head;
1876 $arg{tree
}{hash
} = $treehead if defined $treehead;
1877 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1879 print "<div class=\"page_nav\">\n" .
1881 map { $_ eq $current ?
1882 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1884 print "<br/>\n$extra<br/>\n" .
1888 sub format_paging_nav
{
1889 my ($action, $hash, $head, $page, $nrevs) = @_;
1893 if ($hash ne $head || $page) {
1894 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1896 $paging_nav .= "HEAD";
1900 $paging_nav .= " ⋅ " .
1901 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1902 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1904 $paging_nav .= " ⋅ prev";
1907 if ($nrevs >= (100 * ($page+1)-1)) {
1908 $paging_nav .= " ⋅ " .
1909 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1910 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1912 $paging_nav .= " ⋅ next";
1918 ## ......................................................................
1919 ## functions printing or outputting HTML: div
1921 sub git_print_header_div
{
1922 my ($action, $title, $hash, $hash_base) = @_;
1925 $args{action
} = $action;
1926 $args{hash
} = $hash if $hash;
1927 $args{hash_base
} = $hash_base if $hash_base;
1929 print "<div class=\"header\">\n" .
1930 $cgi->a({-href
=> href
(%args), -class => "title"},
1931 $title ?
$title : $action) .
1935 #sub git_print_authorship (\%) {
1936 sub git_print_authorship
{
1939 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1940 print "<div class=\"author_date\">" .
1941 esc_html
($co->{'author_name'}) .
1943 if ($ad{'hour_local'} < 6) {
1944 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1945 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1947 printf(" (%02d:%02d %s)",
1948 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1953 sub git_print_page_path
{
1959 print "<div class=\"page_path\">";
1960 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1961 -title
=> 'tree root'}, "[$project]");
1963 if (defined $name) {
1964 my @dirname = split '/', $name;
1965 my $basename = pop @dirname;
1968 foreach my $dir (@dirname) {
1969 $fullname .= ($fullname ?
'/' : '') . $dir;
1970 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1972 -title
=> esc_html
($fullname)}, esc_path
($dir));
1975 if (defined $type && $type eq 'blob') {
1976 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1978 -title
=> esc_html
($name)}, esc_path
($basename));
1979 } elsif (defined $type && $type eq 'tree') {
1980 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1982 -title
=> esc_html
($name)}, esc_path
($basename));
1985 print esc_path
($basename);
1988 print "<br/></div>\n";
1991 # sub git_print_log (\@;%) {
1992 sub git_print_log
($;%) {
1996 if ($opts{'-remove_title'}) {
1997 # remove title, i.e. first line of log
2000 # remove leading empty lines
2001 while (defined $log->[0] && $log->[0] eq "") {
2008 foreach my $line (@
$log) {
2009 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2012 if (! $opts{'-remove_signoff'}) {
2013 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2016 # remove signoff lines
2023 # print only one empty line
2024 # do not print empty line after signoff
2026 next if ($empty || $signoff);
2032 print format_log_line_html
($line) . "<br/>\n";
2035 if ($opts{'-final_empty_line'}) {
2036 # end with single empty line
2037 print "<br/>\n" unless $empty;
2041 # return link target (what link points to)
2042 sub git_get_link_target
{
2047 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2051 $link_target = <$fd>;
2056 return $link_target;
2059 # given link target, and the directory (basedir) the link is in,
2060 # return target of link relative to top directory (top tree);
2061 # return undef if it is not possible (including absolute links).
2062 sub normalize_link_target
{
2063 my ($link_target, $basedir, $hash_base) = @_;
2065 # we can normalize symlink target only if $hash_base is provided
2066 return unless $hash_base;
2068 # absolute symlinks (beginning with '/') cannot be normalized
2069 return if (substr($link_target, 0, 1) eq '/');
2071 # normalize link target to path from top (root) tree (dir)
2074 $path = $basedir . '/' . $link_target;
2076 # we are in top (root) tree (dir)
2077 $path = $link_target;
2080 # remove //, /./, and /../
2082 foreach my $part (split('/', $path)) {
2083 # discard '.' and ''
2084 next if (!$part || $part eq '.');
2086 if ($part eq '..') {
2090 # link leads outside repository (outside top dir)
2094 push @path_parts, $part;
2097 $path = join('/', @path_parts);
2102 # print tree entry (row of git_tree), but without encompassing <tr> element
2103 sub git_print_tree_entry
{
2104 my ($t, $basedir, $hash_base, $have_blame) = @_;
2107 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2109 # The format of a table row is: mode list link. Where mode is
2110 # the mode of the entry, list is the name of the entry, an href,
2111 # and link is the action links of the entry.
2113 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2114 if ($t->{'type'} eq "blob") {
2115 print "<td class=\"list\">" .
2116 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2117 file_name
=>"$basedir$t->{'name'}", %base_key),
2118 -class => "list"}, esc_path
($t->{'name'}));
2119 if (S_ISLNK
(oct $t->{'mode'})) {
2120 my $link_target = git_get_link_target
($t->{'hash'});
2122 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2123 if (defined $norm_target) {
2125 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2126 file_name
=>$norm_target),
2127 -title
=> $norm_target}, esc_path
($link_target));
2129 print " -> " . esc_path
($link_target);
2134 print "<td class=\"link\">";
2135 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2136 file_name
=>"$basedir$t->{'name'}", %base_key)},
2140 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2141 file_name
=>"$basedir$t->{'name'}", %base_key)},
2144 if (defined $hash_base) {
2146 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2147 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2151 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2152 file_name
=>"$basedir$t->{'name'}")},
2156 } elsif ($t->{'type'} eq "tree") {
2157 print "<td class=\"list\">";
2158 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2159 file_name
=>"$basedir$t->{'name'}", %base_key)},
2160 esc_path
($t->{'name'}));
2162 print "<td class=\"link\">";
2163 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2164 file_name
=>"$basedir$t->{'name'}", %base_key)},
2166 if (defined $hash_base) {
2168 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2169 file_name
=>"$basedir$t->{'name'}")},
2176 ## ......................................................................
2177 ## functions printing large fragments of HTML
2179 sub git_difftree_body
{
2180 my ($difftree, $hash, $parent) = @_;
2181 my ($have_blame) = gitweb_check_feature
('blame');
2182 print "<div class=\"list_head\">\n";
2183 if ($#{$difftree} > 10) {
2184 print(($#{$difftree} + 1) . " files changed:\n");
2188 print "<table class=\"diff_tree\">\n";
2191 foreach my $line (@
{$difftree}) {
2192 my %diff = parse_difftree_raw_line
($line);
2195 print "<tr class=\"dark\">\n";
2197 print "<tr class=\"light\">\n";
2201 my ($to_mode_oct, $to_mode_str, $to_file_type);
2202 my ($from_mode_oct, $from_mode_str, $from_file_type);
2203 if ($diff{'to_mode'} ne ('0' x
6)) {
2204 $to_mode_oct = oct $diff{'to_mode'};
2205 if (S_ISREG
($to_mode_oct)) { # only for regular file
2206 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2208 $to_file_type = file_type
($diff{'to_mode'});
2210 if ($diff{'from_mode'} ne ('0' x
6)) {
2211 $from_mode_oct = oct $diff{'from_mode'};
2212 if (S_ISREG
($to_mode_oct)) { # only for regular file
2213 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2215 $from_file_type = file_type
($diff{'from_mode'});
2218 if ($diff{'status'} eq "A") { # created
2219 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2220 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2221 $mode_chng .= "]</span>";
2223 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2224 hash_base
=>$hash, file_name
=>$diff{'file'}),
2225 -class => "list"}, esc_path
($diff{'file'}));
2227 print "<td>$mode_chng</td>\n";
2228 print "<td class=\"link\">";
2229 if ($action eq 'commitdiff') {
2232 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2235 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2236 hash_base
=>$hash, file_name
=>$diff{'file'})},
2240 } elsif ($diff{'status'} eq "D") { # deleted
2241 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2243 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2244 hash_base
=>$parent, file_name
=>$diff{'file'}),
2245 -class => "list"}, esc_path
($diff{'file'}));
2247 print "<td>$mode_chng</td>\n";
2248 print "<td class=\"link\">";
2249 if ($action eq 'commitdiff') {
2252 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2255 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2256 hash_base
=>$parent, file_name
=>$diff{'file'})},
2259 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2260 file_name
=>$diff{'file'})},
2263 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2264 file_name
=>$diff{'file'})},
2268 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
2269 my $mode_chnge = "";
2270 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2271 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2272 if ($from_file_type != $to_file_type) {
2273 $mode_chnge .= " from $from_file_type to $to_file_type";
2275 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2276 if ($from_mode_str && $to_mode_str) {
2277 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2278 } elsif ($to_mode_str) {
2279 $mode_chnge .= " mode: $to_mode_str";
2282 $mode_chnge .= "]</span>\n";
2285 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2286 hash_base
=>$hash, file_name
=>$diff{'file'}),
2287 -class => "list"}, esc_path
($diff{'file'}));
2289 print "<td>$mode_chnge</td>\n";
2290 print "<td class=\"link\">";
2291 if ($action eq 'commitdiff') {
2294 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2296 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2297 # "commit" view and modified file (not onlu mode changed)
2298 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2299 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2300 hash_base
=>$hash, hash_parent_base
=>$parent,
2301 file_name
=>$diff{'file'})},
2305 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2306 hash_base
=>$hash, file_name
=>$diff{'file'})},
2309 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2310 file_name
=>$diff{'file'})},
2313 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2314 file_name
=>$diff{'file'})},
2318 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
2319 my %status_name = ('R' => 'moved', 'C' => 'copied');
2320 my $nstatus = $status_name{$diff{'status'}};
2322 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2323 # mode also for directories, so we cannot use $to_mode_str
2324 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2327 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2328 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
2329 -class => "list"}, esc_path
($diff{'to_file'})) . "</td>\n" .
2330 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2331 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2332 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
2333 -class => "list"}, esc_path
($diff{'from_file'})) .
2334 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2335 "<td class=\"link\">";
2336 if ($action eq 'commitdiff') {
2339 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2341 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2342 # "commit" view and modified file (not only pure rename or copy)
2343 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2344 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2345 hash_base
=>$hash, hash_parent_base
=>$parent,
2346 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
2350 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2351 hash_base
=>$parent, file_name
=>$diff{'to_file'})},
2354 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2355 file_name
=>$diff{'to_file'})},
2358 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2359 file_name
=>$diff{'to_file'})},
2363 } # we should not encounter Unmerged (U) or Unknown (X) status
2369 sub git_patchset_body
{
2370 my ($fd, $difftree, $hash, $hash_parent) = @_;
2376 my ($from_id, $to_id);
2378 print "<div class=\"patchset\">\n";
2380 # skip to first patch
2381 while ($patch_line = <$fd>) {
2384 last if ($patch_line =~ m/^diff /);
2388 while ($patch_line) {
2392 #assert($patch_line =~ m/^diff /) if DEBUG;
2393 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2394 push @diff_header, $patch_line;
2396 # extended diff header
2398 while ($patch_line = <$fd>) {
2401 last EXTENDED_HEADER
if ($patch_line =~ m/^--- /);
2403 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2408 push @diff_header, $patch_line;
2410 #last PATCH unless $patch_line;
2411 my $last_patch_line = $patch_line;
2413 # check if current patch belong to current raw line
2414 # and parse raw git-diff line if needed
2415 if (defined $diffinfo &&
2416 $diffinfo->{'from_id'} eq $from_id &&
2417 $diffinfo->{'to_id'} eq $to_id) {
2418 # this is split patch
2419 print "<div class=\"patch cont\">\n";
2421 # advance raw git-diff output if needed
2422 $patch_idx++ if defined $diffinfo;
2424 # read and prepare patch information
2425 if (ref($difftree->[$patch_idx]) eq "HASH") {
2426 # pre-parsed (or generated by hand)
2427 $diffinfo = $difftree->[$patch_idx];
2429 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2431 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2432 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2433 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2434 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2435 hash
=>$diffinfo->{'from_id'},
2436 file_name
=>$from{'file'});
2438 if ($diffinfo->{'status'} ne "D") { # not deleted file
2439 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2440 hash
=>$diffinfo->{'to_id'},
2441 file_name
=>$to{'file'});
2443 # this is first patch for raw difftree line with $patch_idx index
2444 # we index @$difftree array from 0, but number patches from 1
2445 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2448 # print "git diff" header
2449 $patch_line = shift @diff_header;
2450 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2451 if ($from{'href'}) {
2452 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2453 'a/' . esc_path
($from{'file'}));
2454 } else { # file was added
2455 $patch_line .= 'a/' . esc_path
($from{'file'});
2459 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2460 'b/' . esc_path
($to{'file'}));
2461 } else { # file was deleted
2462 $patch_line .= 'b/' . esc_path
($to{'file'});
2464 print "<div class=\"diff header\">$patch_line</div>\n";
2466 # print extended diff header
2467 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2469 foreach $patch_line (@diff_header) {
2471 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2472 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2473 esc_path
($from{'file'}));
2475 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2476 $patch_line = $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2477 esc_path
($to{'file'}));
2480 if ($patch_line =~ m/\s(\d{6})$/) {
2481 $patch_line .= '<span class="info"> (' .
2482 file_type_long
($1) .
2486 if ($patch_line =~ m/^index/) {
2487 my ($from_link, $to_link);
2488 if ($from{'href'}) {
2489 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2490 substr($diffinfo->{'from_id'},0,7));
2492 $from_link = '0' x
7;
2495 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2496 substr($diffinfo->{'to_id'},0,7));
2501 # my ($from_hash, $to_hash) =
2502 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2503 # my ($from_id, $to_id) =
2504 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2505 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2507 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2508 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2510 print $patch_line . "<br/>\n";
2512 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2514 # from-file/to-file diff header
2515 $patch_line = $last_patch_line;
2516 #assert($patch_line =~ m/^---/) if DEBUG;
2517 if ($from{'href'}) {
2518 $patch_line = '--- a/' .
2519 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2520 esc_path
($from{'file'}));
2522 print "<div class=\"diff from_file\">$patch_line</div>\n";
2524 $patch_line = <$fd>;
2525 #last PATCH unless $patch_line;
2528 #assert($patch_line =~ m/^+++/) if DEBUG;
2530 $patch_line = '+++ b/' .
2531 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2532 esc_path
($to{'file'}));
2534 print "<div class=\"diff to_file\">$patch_line</div>\n";
2538 while ($patch_line = <$fd>) {
2541 next PATCH
if ($patch_line =~ m/^diff /);
2543 print format_diff_line
($patch_line, \
%from, \
%to);
2547 print "</div>\n"; # class="patch"
2550 print "</div>\n"; # class="patchset"
2553 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2555 sub git_project_list_body
{
2556 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2558 my ($check_forks) = gitweb_check_feature
('forks');
2561 foreach my $pr (@
$projlist) {
2562 my (@aa) = git_get_last_activity
($pr->{'path'});
2566 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2567 if (!defined $pr->{'descr'}) {
2568 my $descr = git_get_project_description
($pr->{'path'}) || "";
2569 $pr->{'descr_long'} = to_utf8
($descr);
2570 $pr->{'descr'} = chop_str
($descr, 25, 5);
2572 if (!defined $pr->{'owner'}) {
2573 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2576 my $pname = $pr->{'path'};
2577 if (($pname =~ s/\.git$//) &&
2578 ($pname !~ /\/$/) &&
2579 (-d
"$projectroot/$pname")) {
2580 $pr->{'forks'} = "-d $projectroot/$pname";
2586 push @projects, $pr;
2589 $order ||= "project";
2590 $from = 0 unless defined $from;
2591 $to = $#projects if (!defined $to || $#projects < $to);
2593 print "<table class=\"project_list\">\n";
2594 unless ($no_header) {
2597 print "<th></th>\n";
2599 if ($order eq "project") {
2600 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2601 print "<th>Project</th>\n";
2604 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2605 -class => "header"}, "Project") .
2608 if ($order eq "descr") {
2609 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2610 print "<th>Description</th>\n";
2613 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2614 -class => "header"}, "Description") .
2617 if ($order eq "owner") {
2618 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2619 print "<th>Owner</th>\n";
2622 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2623 -class => "header"}, "Owner") .
2626 if ($order eq "age") {
2627 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2628 print "<th>Last Change</th>\n";
2631 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2632 -class => "header"}, "Last Change") .
2635 print "<th></th>\n" .
2639 for (my $i = $from; $i <= $to; $i++) {
2640 my $pr = $projects[$i];
2642 print "<tr class=\"dark\">\n";
2644 print "<tr class=\"light\">\n";
2649 if ($pr->{'forks'}) {
2650 print "<!-- $pr->{'forks'} -->\n";
2651 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2655 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2656 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2657 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2658 -class => "list", -title
=> $pr->{'descr_long'}},
2659 esc_html
($pr->{'descr'})) . "</td>\n" .
2660 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2661 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2662 $pr->{'age_string'} . "</td>\n" .
2663 "<td class=\"link\">" .
2664 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2665 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2666 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2667 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2668 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
2672 if (defined $extra) {
2675 print "<td></td>\n";
2677 print "<td colspan=\"5\">$extra</td>\n" .
2683 sub git_shortlog_body
{
2684 # uses global variable $project
2685 my ($commitlist, $from, $to, $refs, $extra) = @_;
2687 my $have_snapshot = gitweb_have_snapshot
();
2689 $from = 0 unless defined $from;
2690 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
2692 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2694 for (my $i = $from; $i <= $to; $i++) {
2695 my %co = %{$commitlist->[$i]};
2696 my $commit = $co{'id'};
2697 my $ref = format_ref_marker
($refs, $commit);
2699 print "<tr class=\"dark\">\n";
2701 print "<tr class=\"light\">\n";
2704 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2705 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2706 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2708 print format_subject_html
($co{'title'}, $co{'title_short'},
2709 href
(action
=>"commit", hash
=>$commit), $ref);
2711 "<td class=\"link\">" .
2712 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
2713 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2714 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2715 if ($have_snapshot) {
2716 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2721 if (defined $extra) {
2723 "<td colspan=\"4\">$extra</td>\n" .
2729 sub git_history_body
{
2730 # Warning: assumes constant type (blob or tree) during history
2731 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2733 $from = 0 unless defined $from;
2734 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
2736 print "<table class=\"history\" cellspacing=\"0\">\n";
2738 for (my $i = $from; $i <= $to; $i++) {
2739 my %co = %{$commitlist->[$i]};
2743 my $commit = $co{'id'};
2745 my $ref = format_ref_marker
($refs, $commit);
2748 print "<tr class=\"dark\">\n";
2750 print "<tr class=\"light\">\n";
2753 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2754 # shortlog uses chop_str($co{'author_name'}, 10)
2755 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2757 # originally git_history used chop_str($co{'title'}, 50)
2758 print format_subject_html
($co{'title'}, $co{'title_short'},
2759 href
(action
=>"commit", hash
=>$commit), $ref);
2761 "<td class=\"link\">" .
2762 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2763 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2765 if ($ftype eq 'blob') {
2766 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2767 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2768 if (defined $blob_current && defined $blob_parent &&
2769 $blob_current ne $blob_parent) {
2771 $cgi->a({-href
=> href
(action
=>"blobdiff",
2772 hash
=>$blob_current, hash_parent
=>$blob_parent,
2773 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2774 file_name
=>$file_name)},
2781 if (defined $extra) {
2783 "<td colspan=\"4\">$extra</td>\n" .
2790 # uses global variable $project
2791 my ($taglist, $from, $to, $extra) = @_;
2792 $from = 0 unless defined $from;
2793 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2795 print "<table class=\"tags\" cellspacing=\"0\">\n";
2797 for (my $i = $from; $i <= $to; $i++) {
2798 my $entry = $taglist->[$i];
2800 my $comment = $tag{'subject'};
2802 if (defined $comment) {
2803 $comment_short = chop_str
($comment, 30, 5);
2806 print "<tr class=\"dark\">\n";
2808 print "<tr class=\"light\">\n";
2811 print "<td><i>$tag{'age'}</i></td>\n" .
2813 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2814 -class => "list name"}, esc_html
($tag{'name'})) .
2817 if (defined $comment) {
2818 print format_subject_html
($comment, $comment_short,
2819 href
(action
=>"tag", hash
=>$tag{'id'}));
2822 "<td class=\"selflink\">";
2823 if ($tag{'type'} eq "tag") {
2824 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2829 "<td class=\"link\">" . " | " .
2830 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2831 if ($tag{'reftype'} eq "commit") {
2832 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2833 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
2834 } elsif ($tag{'reftype'} eq "blob") {
2835 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2840 if (defined $extra) {
2842 "<td colspan=\"5\">$extra</td>\n" .
2848 sub git_heads_body
{
2849 # uses global variable $project
2850 my ($headlist, $head, $from, $to, $extra) = @_;
2851 $from = 0 unless defined $from;
2852 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2854 print "<table class=\"heads\" cellspacing=\"0\">\n";
2856 for (my $i = $from; $i <= $to; $i++) {
2857 my $entry = $headlist->[$i];
2859 my $curr = $ref{'id'} eq $head;
2861 print "<tr class=\"dark\">\n";
2863 print "<tr class=\"light\">\n";
2866 print "<td><i>$ref{'age'}</i></td>\n" .
2867 ($curr ?
"<td class=\"current_head\">" : "<td>") .
2868 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
2869 -class => "list name"},esc_html
($ref{'name'})) .
2871 "<td class=\"link\">" .
2872 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
2873 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
2874 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
2878 if (defined $extra) {
2880 "<td colspan=\"3\">$extra</td>\n" .
2886 sub git_search_grep_body
{
2887 my ($commitlist, $from, $to, $extra) = @_;
2888 $from = 0 unless defined $from;
2889 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
2891 print "<table class=\"grep\" cellspacing=\"0\">\n";
2893 for (my $i = $from; $i <= $to; $i++) {
2894 my %co = %{$commitlist->[$i]};
2898 my $commit = $co{'id'};
2900 print "<tr class=\"dark\">\n";
2902 print "<tr class=\"light\">\n";
2905 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2906 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2908 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
2909 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
2910 my $comment = $co{'comment'};
2911 foreach my $line (@
$comment) {
2912 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2913 my $lead = esc_html
($1) || "";
2914 $lead = chop_str
($lead, 30, 10);
2915 my $match = esc_html
($2) || "";
2916 my $trail = esc_html
($3) || "";
2917 $trail = chop_str
($trail, 30, 10);
2918 my $text = "$lead<span class=\"match\">$match</span>$trail";
2919 print chop_str
($text, 80, 5) . "<br/>\n";
2923 "<td class=\"link\">" .
2924 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
2926 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
2930 if (defined $extra) {
2932 "<td colspan=\"3\">$extra</td>\n" .
2938 ## ======================================================================
2939 ## ======================================================================
2942 sub git_project_list
{
2943 my $order = $cgi->param('o');
2944 if (defined $order && $order !~ m/project|descr|owner|age/) {
2945 die_error
(undef, "Unknown order parameter");
2948 my @list = git_get_projects_list
();
2950 die_error
(undef, "No projects found");
2954 if (-f
$home_text) {
2955 print "<div class=\"index_include\">\n";
2956 open (my $fd, $home_text);
2961 git_project_list_body
(\
@list, $order);
2966 my $order = $cgi->param('o');
2967 if (defined $order && $order !~ m/project|descr|owner|age/) {
2968 die_error
(undef, "Unknown order parameter");
2971 my @list = git_get_projects_list
($project);
2973 die_error
(undef, "No forks found");
2977 git_print_page_nav
('','');
2978 git_print_header_div
('summary', "$project forks");
2979 git_project_list_body
(\
@list, $order);
2983 sub git_project_index
{
2984 my @projects = git_get_projects_list
($project);
2987 -type
=> 'text/plain',
2988 -charset
=> 'utf-8',
2989 -content_disposition
=> 'inline; filename="index.aux"');
2991 foreach my $pr (@projects) {
2992 if (!exists $pr->{'owner'}) {
2993 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2996 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2997 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2998 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2999 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3003 print "$path $owner\n";
3008 my $descr = git_get_project_description
($project) || "none";
3009 my %co = parse_commit
("HEAD");
3010 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3011 my $head = $co{'id'};
3013 my $owner = git_get_project_owner
($project);
3015 my $refs = git_get_references
();
3016 # These get_*_list functions return one more to allow us to see if
3017 # there are more ...
3018 my @taglist = git_get_tags_list
(16);
3019 my @headlist = git_get_heads_list
(16);
3021 my ($check_forks) = gitweb_check_feature
('forks');
3024 @forklist = git_get_projects_list
($project);
3028 git_print_page_nav
('summary','', $head);
3030 print "<div class=\"title\"> </div>\n";
3031 print "<table cellspacing=\"0\">\n" .
3032 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3033 "<tr><td>owner</td><td>$owner</td></tr>\n" .
3034 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3035 # use per project git URL list in $projectroot/$project/cloneurl
3036 # or make project git URL from git base URL and project name
3037 my $url_tag = "URL";
3038 my @url_list = git_get_project_url_list
($project);
3039 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3040 foreach my $git_url (@url_list) {
3041 next unless $git_url;
3042 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3047 if (-s
"$projectroot/$project/README.html") {
3048 if (open my $fd, "$projectroot/$project/README.html") {
3049 print "<div class=\"title\">readme</div>\n";
3050 print $_ while (<$fd>);
3055 # we need to request one more than 16 (0..15) to check if
3057 my @commitlist = parse_commits
($head, 17);
3058 git_print_header_div
('shortlog');
3059 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3060 $#commitlist <= 15 ?
undef :
3061 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3064 git_print_header_div
('tags');
3065 git_tags_body
(\
@taglist, 0, 15,
3066 $#taglist <= 15 ?
undef :
3067 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3071 git_print_header_div
('heads');
3072 git_heads_body
(\
@headlist, $head, 0, 15,
3073 $#headlist <= 15 ?
undef :
3074 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3078 git_print_header_div
('forks');
3079 git_project_list_body
(\
@forklist, undef, 0, 15,
3080 $#forklist <= 15 ?
undef :
3081 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3089 my $head = git_get_head_hash
($project);
3091 git_print_page_nav
('','', $head,undef,$head);
3092 my %tag = parse_tag
($hash);
3093 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3094 print "<div class=\"title_text\">\n" .
3095 "<table cellspacing=\"0\">\n" .
3097 "<td>object</td>\n" .
3098 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3099 $tag{'object'}) . "</td>\n" .
3100 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3101 $tag{'type'}) . "</td>\n" .
3103 if (defined($tag{'author'})) {
3104 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3105 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3106 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3107 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3110 print "</table>\n\n" .
3112 print "<div class=\"page_body\">";
3113 my $comment = $tag{'comment'};
3114 foreach my $line (@
$comment) {
3116 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3126 my ($have_blame) = gitweb_check_feature
('blame');
3128 die_error
('403 Permission denied', "Permission denied");
3130 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3131 $hash_base ||= git_get_head_hash
($project);
3132 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3133 my %co = parse_commit
($hash_base)
3134 or die_error
(undef, "Reading commit failed");
3135 if (!defined $hash) {
3136 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3137 or die_error
(undef, "Error looking up file");
3139 $ftype = git_get_type
($hash);
3140 if ($ftype !~ "blob") {
3141 die_error
("400 Bad Request", "Object is not a blob");
3143 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3144 $file_name, $hash_base)
3145 or die_error
(undef, "Open git-blame failed");
3148 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3151 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3154 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3156 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3157 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3158 git_print_page_path
($file_name, $ftype, $hash_base);
3159 my @rev_color = (qw(light2 dark2));
3160 my $num_colors = scalar(@rev_color);
3161 my $current_color = 0;
3164 <div class="page_body">
3165 <table class="blame">
3166 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3171 last unless defined $_;
3172 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3173 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3174 if (!exists $metainfo{$full_rev}) {
3175 $metainfo{$full_rev} = {};
3177 my $meta = $metainfo{$full_rev};
3180 if (/^(\S+) (.*)$/) {
3186 my $rev = substr($full_rev, 0, 8);
3187 my $author = $meta->{'author'};
3188 my %date = parse_date
($meta->{'author-time'},
3189 $meta->{'author-tz'});
3190 my $date = $date{'iso-tz'};
3192 $current_color = ++$current_color % $num_colors;
3194 print "<tr class=\"$rev_color[$current_color]\">\n";
3196 print "<td class=\"sha1\"";
3197 print " title=\"". esc_html
($author) . ", $date\"";
3198 print " rowspan=\"$group_size\"" if ($group_size > 1);
3200 print $cgi->a({-href
=> href
(action
=>"commit",
3202 file_name
=>$file_name)},
3206 my $blamed = href
(action
=> 'blame',
3207 file_name
=> $meta->{'filename'},
3208 hash_base
=> $full_rev);
3209 print "<td class=\"linenr\">";
3210 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3212 -class => "linenr" },
3215 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3221 or print "Reading blob failed\n";
3228 my ($have_blame) = gitweb_check_feature
('blame');
3230 die_error
('403 Permission denied', "Permission denied");
3232 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3233 $hash_base ||= git_get_head_hash
($project);
3234 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3235 my %co = parse_commit
($hash_base)
3236 or die_error
(undef, "Reading commit failed");
3237 if (!defined $hash) {
3238 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3239 or die_error
(undef, "Error lookup file");
3241 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3242 or die_error
(undef, "Open git-annotate failed");
3245 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3248 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3251 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3253 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3254 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3255 git_print_page_path
($file_name, 'blob', $hash_base);
3256 print "<div class=\"page_body\">\n";
3258 <table class="blame">
3267 my @line_class = (qw(light dark));
3268 my $line_class_len = scalar (@line_class);
3269 my $line_class_num = $#line_class;
3270 while (my $line = <$fd>) {
3282 $line_class_num = ($line_class_num + 1) % $line_class_len;
3284 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3291 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
3294 $short_rev = substr ($long_rev, 0, 8);
3295 $age = time () - $time;
3296 $age_str = age_string
($age);
3297 $age_str =~ s/ / /g;
3298 $age_class = age_class
($age);
3299 $author = esc_html
($author);
3300 $author =~ s/ / /g;
3302 $data = untabify
($data);
3303 $data = esc_html
($data);
3306 <tr class="$line_class[$line_class_num]">
3307 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3308 <td class="$age_class">$age_str</td>
3310 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3311 <td class="pre">$data</td>
3314 } # while (my $line = <$fd>)
3315 print "</table>\n\n";
3317 or print "Reading blob failed.\n";
3323 my $head = git_get_head_hash
($project);
3325 git_print_page_nav
('','', $head,undef,$head);
3326 git_print_header_div
('summary', $project);
3328 my @tagslist = git_get_tags_list
();
3330 git_tags_body
(\
@tagslist);
3336 my $head = git_get_head_hash
($project);
3338 git_print_page_nav
('','', $head,undef,$head);
3339 git_print_header_div
('summary', $project);
3341 my @headslist = git_get_heads_list
();
3343 git_heads_body
(\
@headslist, $head);
3348 sub git_blob_plain
{
3351 if (!defined $hash) {
3352 if (defined $file_name) {
3353 my $base = $hash_base || git_get_head_hash
($project);
3354 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3355 or die_error
(undef, "Error lookup file");
3357 die_error
(undef, "No file name defined");
3359 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3360 # blobs defined by non-textual hash id's can be cached
3365 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3366 or die_error
(undef, "Couldn't cat $file_name, $hash");
3368 $type ||= blob_mimetype
($fd, $file_name);
3370 # save as filename, even when no $file_name is given
3371 my $save_as = "$hash";
3372 if (defined $file_name) {
3373 $save_as = $file_name;
3374 } elsif ($type =~ m/^text\//) {
3381 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3383 binmode STDOUT
, ':raw';
3385 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3393 if (!defined $hash) {
3394 if (defined $file_name) {
3395 my $base = $hash_base || git_get_head_hash
($project);
3396 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3397 or die_error
(undef, "Error lookup file");
3399 die_error
(undef, "No file name defined");
3401 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3402 # blobs defined by non-textual hash id's can be cached
3406 my ($have_blame) = gitweb_check_feature
('blame');
3407 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3408 or die_error
(undef, "Couldn't cat $file_name, $hash");
3409 my $mimetype = blob_mimetype
($fd, $file_name);
3410 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3412 return git_blob_plain
($mimetype);
3414 # we can have blame only for text/* mimetype
3415 $have_blame &&= ($mimetype =~ m!^text/!);
3417 git_header_html
(undef, $expires);
3418 my $formats_nav = '';
3419 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3420 if (defined $file_name) {
3423 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3424 hash
=>$hash, file_name
=>$file_name)},
3429 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3430 hash
=>$hash, file_name
=>$file_name)},
3433 $cgi->a({-href
=> href
(action
=>"blob_plain",
3434 hash
=>$hash, file_name
=>$file_name)},
3437 $cgi->a({-href
=> href
(action
=>"blob",
3438 hash_base
=>"HEAD", file_name
=>$file_name)},
3442 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3444 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3445 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3447 print "<div class=\"page_nav\">\n" .
3448 "<br/><br/></div>\n" .
3449 "<div class=\"title\">$hash</div>\n";
3451 git_print_page_path
($file_name, "blob", $hash_base);
3452 print "<div class=\"page_body\">\n";
3453 if ($mimetype =~ m!^text/!) {
3455 while (my $line = <$fd>) {
3458 $line = untabify
($line);
3459 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3460 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3462 } elsif ($mimetype =~ m!^image/!) {
3463 print qq!<img type
="$mimetype"!;
3465 print qq! alt
="$file_name" title
="$file_name"!;
3468 href(action=>"blob_plain
", hash=>$hash,
3469 hash_base=>$hash_base, file_name=>$file_name) .
3473 or print "Reading blob failed.\n";
3479 my $have_snapshot = gitweb_have_snapshot
();
3481 if (!defined $hash_base) {
3482 $hash_base = "HEAD";
3484 if (!defined $hash) {
3485 if (defined $file_name) {
3486 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3492 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3493 or die_error
(undef, "Open git-ls-tree failed");
3494 my @entries = map { chomp; $_ } <$fd>;
3495 close $fd or die_error
(undef, "Reading tree failed");
3498 my $refs = git_get_references
();
3499 my $ref = format_ref_marker
($refs, $hash_base);
3502 my ($have_blame) = gitweb_check_feature
('blame');
3503 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3505 if (defined $file_name) {
3507 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3508 hash
=>$hash, file_name
=>$file_name)},
3510 $cgi->a({-href
=> href
(action
=>"tree",
3511 hash_base
=>"HEAD", file_name
=>$file_name)},
3514 if ($have_snapshot) {
3515 # FIXME: Should be available when we have no hash base as well.
3517 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3520 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3521 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3524 print "<div class=\"page_nav\">\n";
3525 print "<br/><br/></div>\n";
3526 print "<div class=\"title\">$hash</div>\n";
3528 if (defined $file_name) {
3529 $basedir = $file_name;
3530 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3534 git_print_page_path
($file_name, 'tree', $hash_base);
3535 print "<div class=\"page_body\">\n";
3536 print "<table cellspacing=\"0\">\n";
3538 # '..' (top directory) link if possible
3539 if (defined $hash_base &&
3540 defined $file_name && $file_name =~ m![^/]+$!) {
3542 print "<tr class=\"dark\">\n";
3544 print "<tr class=\"light\">\n";
3548 my $up = $file_name;
3549 $up =~ s!/?[^/]+$!!;
3550 undef $up unless $up;
3551 # based on git_print_tree_entry
3552 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3553 print '<td class="list">';
3554 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3558 print "<td class=\"link\"></td>\n";
3562 foreach my $line (@entries) {
3563 my %t = parse_ls_tree_line
($line, -z
=> 1);
3566 print "<tr class=\"dark\">\n";
3568 print "<tr class=\"light\">\n";
3572 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3576 print "</table>\n" .
3582 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3583 my $have_snapshot = (defined $ctype && defined $suffix);
3584 if (!$have_snapshot) {
3585 die_error
('403 Permission denied', "Permission denied");
3588 if (!defined $hash) {
3589 $hash = git_get_head_hash
($project);
3592 my $filename = basename
($project) . "-$hash.tar.$suffix";
3595 -type
=> "application/$ctype",
3596 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3597 -status
=> '200 OK');
3599 my $git = git_cmd_str
();
3600 my $name = $project;
3601 $name =~ s/\047/\047\\\047\047/g;
3603 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3604 or die_error
(undef, "Execute git-tar-tree failed.");
3605 binmode STDOUT
, ':raw';
3607 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3613 my $head = git_get_head_hash
($project);
3614 if (!defined $hash) {
3617 if (!defined $page) {
3620 my $refs = git_get_references
();
3622 my @commitlist = parse_commits
($hash, 101, (100 * $page));
3624 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
3627 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3630 my %co = parse_commit
($hash);
3632 git_print_header_div
('summary', $project);
3633 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3635 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
3636 for (my $i = 0; $i <= $to; $i++) {
3637 my %co = %{$commitlist[$i]};
3639 my $commit = $co{'id'};
3640 my $ref = format_ref_marker
($refs, $commit);
3641 my %ad = parse_date
($co{'author_epoch'});
3642 git_print_header_div
('commit',
3643 "<span class=\"age\">$co{'age_string'}</span>" .
3644 esc_html
($co{'title'}) . $ref,
3646 print "<div class=\"title_text\">\n" .
3647 "<div class=\"log_link\">\n" .
3648 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3650 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3652 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3655 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3658 print "<div class=\"log_body\">\n";
3659 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
3662 if ($#commitlist >= 100) {
3663 print "<div class=\"page_nav\">\n";
3664 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
3665 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3672 $hash ||= $hash_base || "HEAD";
3673 my %co = parse_commit
($hash);
3675 die_error
(undef, "Unknown commit object");
3677 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3678 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3680 my $parent = $co{'parent'};
3681 my $parents = $co{'parents'}; # listref
3683 # we need to prepare $formats_nav before any parameter munging
3685 if (!defined $parent) {
3687 $formats_nav .= '(initial)';
3688 } elsif (@
$parents == 1) {
3689 # single parent commit
3692 $cgi->a({-href
=> href
(action
=>"commit",
3694 esc_html
(substr($parent, 0, 7))) .
3701 $cgi->a({-href
=> href
(action
=>"commitdiff",
3703 esc_html
(substr($_, 0, 7)));
3708 if (!defined $parent) {
3712 if (@
$parents <= 1) {
3713 # difftree output is not printed for merges
3714 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
3715 @diff_opts, $parent, $hash, "--"
3716 or die_error
(undef, "Open git-diff-tree failed");
3717 @difftree = map { chomp; $_ } <$fd>;
3718 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3721 # non-textual hash id's can be cached
3723 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3726 my $refs = git_get_references
();
3727 my $ref = format_ref_marker
($refs, $co{'id'});
3729 my $have_snapshot = gitweb_have_snapshot
();
3731 git_header_html
(undef, $expires);
3732 git_print_page_nav
('commit', '',
3733 $hash, $co{'tree'}, $hash,
3736 if (defined $co{'parent'}) {
3737 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3739 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3741 print "<div class=\"title_text\">\n" .
3742 "<table cellspacing=\"0\">\n";
3743 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3745 "<td></td><td> $ad{'rfc2822'}";
3746 if ($ad{'hour_local'} < 6) {
3747 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3748 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3750 printf(" (%02d:%02d %s)",
3751 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3755 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3756 print "<tr><td></td><td> $cd{'rfc2822'}" .
3757 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3759 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3762 "<td class=\"sha1\">" .
3763 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3764 class => "list"}, $co{'tree'}) .
3766 "<td class=\"link\">" .
3767 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3769 if ($have_snapshot) {
3771 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3776 foreach my $par (@
$parents) {
3779 "<td class=\"sha1\">" .
3780 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3781 class => "list"}, $par) .
3783 "<td class=\"link\">" .
3784 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3786 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3793 print "<div class=\"page_body\">\n";
3794 git_print_log
($co{'comment'});
3797 if (@
$parents <= 1) {
3798 # do not output difftree/whatchanged for merges
3799 git_difftree_body
(\
@difftree, $hash, $parent);
3806 # object is defined by:
3807 # - hash or hash_base alone
3808 # - hash_base and file_name
3811 # - hash or hash_base alone
3812 if ($hash || ($hash_base && !defined $file_name)) {
3813 my $object_id = $hash || $hash_base;
3815 my $git_command = git_cmd_str
();
3816 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
3817 or die_error
('404 Not Found', "Object does not exist");
3821 or die_error
('404 Not Found', "Object does not exist");
3823 # - hash_base and file_name
3824 } elsif ($hash_base && defined $file_name) {
3825 $file_name =~ s
,/+$,,;
3827 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
3828 or die_error
('404 Not Found', "Base object does not exist");
3830 # here errors should not hapen
3831 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
3832 or die_error
(undef, "Open git-ls-tree failed");
3836 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
3837 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
3838 die_error
('404 Not Found', "File or directory for given base does not exist");
3843 die_error
('404 Not Found', "Not enough information to find object");
3846 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
3847 hash
=>$hash, hash_base
=>$hash_base,
3848 file_name
=>$file_name),
3849 -status
=> '302 Found');
3853 my $format = shift || 'html';
3860 # preparing $fd and %diffinfo for git_patchset_body
3862 if (defined $hash_base && defined $hash_parent_base) {
3863 if (defined $file_name) {
3865 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3866 $hash_parent_base, $hash_base,
3868 or die_error
(undef, "Open git-diff-tree failed");
3869 @difftree = map { chomp; $_ } <$fd>;
3871 or die_error
(undef, "Reading git-diff-tree failed");
3873 or die_error
('404 Not Found', "Blob diff not found");
3875 } elsif (defined $hash &&
3876 $hash =~ /[0-9a-fA-F]{40}/) {
3877 # try to find filename from $hash
3879 # read filtered raw output
3880 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3881 $hash_parent_base, $hash_base, "--"
3882 or die_error
(undef, "Open git-diff-tree failed");
3884 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3886 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3887 map { chomp; $_ } <$fd>;
3889 or die_error
(undef, "Reading git-diff-tree failed");
3891 or die_error
('404 Not Found', "Blob diff not found");
3894 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3897 if (@difftree > 1) {
3898 die_error
('404 Not Found', "Ambiguous blob diff specification");
3901 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3902 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3903 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3905 $hash_parent ||= $diffinfo{'from_id'};
3906 $hash ||= $diffinfo{'to_id'};
3908 # non-textual hash id's can be cached
3909 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3910 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3915 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3916 '-p', $hash_parent_base, $hash_base,
3918 or die_error
(undef, "Open git-diff-tree failed");
3921 # old/legacy style URI
3922 if (!%diffinfo && # if new style URI failed
3923 defined $hash && defined $hash_parent) {
3924 # fake git-diff-tree raw output
3925 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3926 $diffinfo{'from_id'} = $hash_parent;
3927 $diffinfo{'to_id'} = $hash;
3928 if (defined $file_name) {
3929 if (defined $file_parent) {
3930 $diffinfo{'status'} = '2';
3931 $diffinfo{'from_file'} = $file_parent;
3932 $diffinfo{'to_file'} = $file_name;
3933 } else { # assume not renamed
3934 $diffinfo{'status'} = '1';
3935 $diffinfo{'from_file'} = $file_name;
3936 $diffinfo{'to_file'} = $file_name;
3938 } else { # no filename given
3939 $diffinfo{'status'} = '2';
3940 $diffinfo{'from_file'} = $hash_parent;
3941 $diffinfo{'to_file'} = $hash;
3944 # non-textual hash id's can be cached
3945 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3946 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3951 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts,
3952 $hash_parent, $hash, "--"
3953 or die_error
(undef, "Open git-diff failed");
3955 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3960 if ($format eq 'html') {
3962 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3963 hash
=>$hash, hash_parent
=>$hash_parent,
3964 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3965 file_name
=>$file_name, file_parent
=>$file_parent)},
3967 git_header_html
(undef, $expires);
3968 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3969 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3970 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3972 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3973 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3975 if (defined $file_name) {
3976 git_print_page_path
($file_name, "blob", $hash_base);
3978 print "<div class=\"page_path\"></div>\n";
3981 } elsif ($format eq 'plain') {
3983 -type
=> 'text/plain',
3984 -charset
=> 'utf-8',
3985 -expires
=> $expires,
3986 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3988 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3991 die_error
(undef, "Unknown blobdiff format");
3995 if ($format eq 'html') {
3996 print "<div class=\"page_body\">\n";
3998 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4001 print "</div>\n"; # class="page_body"
4005 while (my $line = <$fd>) {
4006 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4007 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4011 last if $line =~ m!^\+\+\+!;
4019 sub git_blobdiff_plain
{
4020 git_blobdiff
('plain');
4023 sub git_commitdiff
{
4024 my $format = shift || 'html';
4025 $hash ||= $hash_base || "HEAD";
4026 my %co = parse_commit
($hash);
4028 die_error
(undef, "Unknown commit object");
4031 # we need to prepare $formats_nav before any parameter munging
4033 if ($format eq 'html') {
4035 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4036 hash
=>$hash, hash_parent
=>$hash_parent)},
4039 if (defined $hash_parent) {
4040 # commitdiff with two commits given
4041 my $hash_parent_short = $hash_parent;
4042 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4043 $hash_parent_short = substr($hash_parent, 0, 7);
4047 $cgi->a({-href
=> href
(action
=>"commitdiff",
4048 hash
=>$hash_parent)},
4049 esc_html
($hash_parent_short)) .
4051 } elsif (!$co{'parent'}) {
4053 $formats_nav .= ' (initial)';
4054 } elsif (scalar @
{$co{'parents'}} == 1) {
4055 # single parent commit
4058 $cgi->a({-href
=> href
(action
=>"commitdiff",
4059 hash
=>$co{'parent'})},
4060 esc_html
(substr($co{'parent'}, 0, 7))) .
4067 $cgi->a({-href
=> href
(action
=>"commitdiff",
4069 esc_html
(substr($_, 0, 7)));
4070 } @
{$co{'parents'}} ) .
4075 if (!defined $hash_parent) {
4076 $hash_parent = $co{'parent'} || '--root';
4082 if ($format eq 'html') {
4083 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4084 "--no-commit-id", "--patch-with-raw", "--full-index",
4085 $hash_parent, $hash, "--"
4086 or die_error
(undef, "Open git-diff-tree failed");
4088 while (my $line = <$fd>) {
4090 # empty line ends raw part of diff-tree output
4092 push @difftree, $line;
4095 } elsif ($format eq 'plain') {
4096 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4097 '-p', $hash_parent, $hash, "--"
4098 or die_error
(undef, "Open git-diff-tree failed");
4101 die_error
(undef, "Unknown commitdiff format");
4104 # non-textual hash id's can be cached
4106 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4110 # write commit message
4111 if ($format eq 'html') {
4112 my $refs = git_get_references
();
4113 my $ref = format_ref_marker
($refs, $co{'id'});
4115 git_header_html
(undef, $expires);
4116 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4117 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4118 git_print_authorship
(\
%co);
4119 print "<div class=\"page_body\">\n";
4120 if (@
{$co{'comment'}} > 1) {
4121 print "<div class=\"log\">\n";
4122 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4123 print "</div>\n"; # class="log"
4126 } elsif ($format eq 'plain') {
4127 my $refs = git_get_references
("tags");
4128 my $tagname = git_get_rev_name_tags
($hash);
4129 my $filename = basename
($project) . "-$hash.patch";
4132 -type
=> 'text/plain',
4133 -charset
=> 'utf-8',
4134 -expires
=> $expires,
4135 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4136 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4139 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4140 Subject: $co{'title'}
4142 print "X-Git-Tag: $tagname\n" if $tagname;
4143 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4145 foreach my $line (@
{$co{'comment'}}) {
4152 if ($format eq 'html') {
4153 git_difftree_body
(\
@difftree, $hash, $hash_parent);
4156 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
4158 print "</div>\n"; # class="page_body"
4161 } elsif ($format eq 'plain') {
4165 or print "Reading git-diff-tree failed\n";
4169 sub git_commitdiff_plain
{
4170 git_commitdiff
('plain');
4174 if (!defined $hash_base) {
4175 $hash_base = git_get_head_hash
($project);
4177 if (!defined $page) {
4181 my %co = parse_commit
($hash_base);
4183 die_error
(undef, "Unknown commit object");
4186 my $refs = git_get_references
();
4187 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4189 if (!defined $hash && defined $file_name) {
4190 $hash = git_get_hash_by_path
($hash_base, $file_name);
4192 if (defined $hash) {
4193 $ftype = git_get_type
($hash);
4196 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4198 my $paging_nav = '';
4201 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4202 file_name
=>$file_name)},
4204 $paging_nav .= " ⋅ " .
4205 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4206 file_name
=>$file_name, page
=>$page-1),
4207 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4209 $paging_nav .= "first";
4210 $paging_nav .= " ⋅ prev";
4212 if ($#commitlist >= 100) {
4213 $paging_nav .= " ⋅ " .
4214 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4215 file_name
=>$file_name, page
=>$page+1),
4216 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4218 $paging_nav .= " ⋅ next";
4221 if ($#commitlist >= 100) {
4223 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4224 file_name
=>$file_name, page
=>$page+1),
4225 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4229 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4230 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4231 git_print_page_path
($file_name, $ftype, $hash_base);
4233 git_history_body
(\
@commitlist, 0, 99,
4234 $refs, $hash_base, $ftype, $next_link);
4240 my ($have_search) = gitweb_check_feature
('search');
4241 if (!$have_search) {
4242 die_error
('403 Permission denied', "Permission denied");
4244 if (!defined $searchtext) {
4245 die_error
(undef, "Text field empty");
4247 if (!defined $hash) {
4248 $hash = git_get_head_hash
($project);
4250 my %co = parse_commit
($hash);
4252 die_error
(undef, "Unknown commit object");
4254 if (!defined $page) {
4258 $searchtype ||= 'commit';
4259 if ($searchtype eq 'pickaxe') {
4260 # pickaxe may take all resources of your box and run for several minutes
4261 # with every query - so decide by yourself how public you make this feature
4262 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4263 if (!$have_pickaxe) {
4264 die_error
('403 Permission denied', "Permission denied");
4270 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4272 if ($searchtype eq 'commit') {
4273 $greptype = "--grep=";
4274 } elsif ($searchtype eq 'author') {
4275 $greptype = "--author=";
4276 } elsif ($searchtype eq 'committer') {
4277 $greptype = "--committer=";
4279 $greptype .= $searchtext;
4280 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4282 my $paging_nav = '';
4285 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4286 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4288 $paging_nav .= " ⋅ " .
4289 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4290 searchtext
=>$searchtext, searchtype
=>$searchtype,
4292 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4294 $paging_nav .= "first";
4295 $paging_nav .= " ⋅ prev";
4297 if ($#commitlist >= 100) {
4298 $paging_nav .= " ⋅ " .
4299 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4300 searchtext
=>$searchtext, searchtype
=>$searchtype,
4302 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4304 $paging_nav .= " ⋅ next";
4307 if ($#commitlist >= 100) {
4309 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4310 searchtext
=>$searchtext, searchtype
=>$searchtype,
4312 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4315 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4316 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4317 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4320 if ($searchtype eq 'pickaxe') {
4321 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4322 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4324 print "<table cellspacing=\"0\">\n";
4327 my $git_command = git_cmd_str
();
4328 open my $fd, "-|", "$git_command rev-list $hash | " .
4329 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
4332 while (my $line = <$fd>) {
4333 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4336 $set{'from_id'} = $3;
4338 $set{'id'} = $set{'to_id'};
4339 if ($set{'id'} =~ m/0{40}/) {
4340 $set{'id'} = $set{'from_id'};
4342 if ($set{'id'} =~ m/0{40}/) {
4346 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4349 print "<tr class=\"dark\">\n";
4351 print "<tr class=\"light\">\n";
4354 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4355 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4357 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4358 -class => "list subject"},
4359 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4360 while (my $setref = shift @files) {
4362 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4363 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4365 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4369 "<td class=\"link\">" .
4370 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4372 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4376 %co = parse_commit
($1);
4386 sub git_search_help
{
4388 git_print_page_nav
('','', $hash,$hash,$hash);
4391 <dt><b>commit</b></dt>
4392 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4393 <dt><b>author</b></dt>
4394 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4395 <dt><b>committer</b></dt>
4396 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4398 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4399 if ($have_pickaxe) {
4401 <dt><b>pickaxe</b></dt>
4402 <dd>All commits that caused the string to appear or disappear from any file (changes that
4403 added, removed or "modified" the string) will be listed. This search can take a while and
4404 takes a lot of strain on the server, so please use it wisely.</dd>
4412 my $head = git_get_head_hash
($project);
4413 if (!defined $hash) {
4416 if (!defined $page) {
4419 my $refs = git_get_references
();
4421 my @commitlist = parse_commits
($head, 101, (100 * $page));
4423 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
4425 if ($#commitlist >= 100) {
4427 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4428 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4432 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4433 git_print_header_div
('summary', $project);
4435 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
4440 ## ......................................................................
4441 ## feeds (RSS, Atom; OPML)
4444 my $format = shift || 'atom';
4445 my ($have_blame) = gitweb_check_feature
('blame');
4447 # Atom: http://www.atomenabled.org/developers/syndication/
4448 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4449 if ($format ne 'rss' && $format ne 'atom') {
4450 die_error
(undef, "Unknown web feed format");
4453 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4454 my $head = $hash || 'HEAD';
4455 my @commitlist = parse_commits
($head, 150);
4459 my $content_type = "application/$format+xml";
4460 if (defined $cgi->http('HTTP_ACCEPT') &&
4461 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4462 # browser (feed reader) prefers text/xml
4463 $content_type = 'text/xml';
4465 if (defined($commitlist[0])) {
4466 %latest_commit = %{$commitlist[0]};
4467 %latest_date = parse_date
($latest_commit{'author_epoch'});
4469 -type
=> $content_type,
4470 -charset
=> 'utf-8',
4471 -last_modified
=> $latest_date{'rfc2822'});
4474 -type
=> $content_type,
4475 -charset
=> 'utf-8');
4478 # Optimization: skip generating the body if client asks only
4479 # for Last-Modified date.
4480 return if ($cgi->request_method() eq 'HEAD');
4483 my $title = "$site_name - $project/$action";
4484 my $feed_type = 'log';
4485 if (defined $hash) {
4486 $title .= " - '$hash'";
4487 $feed_type = 'branch log';
4488 if (defined $file_name) {
4489 $title .= " :: $file_name";
4490 $feed_type = 'history';
4492 } elsif (defined $file_name) {
4493 $title .= " - $file_name";
4494 $feed_type = 'history';
4496 $title .= " $feed_type";
4497 my $descr = git_get_project_description
($project);
4498 if (defined $descr) {
4499 $descr = esc_html
($descr);
4501 $descr = "$project " .
4502 ($format eq 'rss' ?
'RSS' : 'Atom') .
4505 my $owner = git_get_project_owner
($project);
4506 $owner = esc_html
($owner);
4510 if (defined $file_name) {
4511 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
4512 } elsif (defined $hash) {
4513 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
4515 $alt_url = href
(-full
=>1, action
=>"summary");
4517 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
4518 if ($format eq 'rss') {
4520 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
4523 print "<title>$title</title>\n" .
4524 "<link>$alt_url</link>\n" .
4525 "<description>$descr</description>\n" .
4526 "<language>en</language>\n";
4527 } elsif ($format eq 'atom') {
4529 <feed xmlns="http://www.w3.org/2005/Atom">
4531 print "<title>$title</title>\n" .
4532 "<subtitle>$descr</subtitle>\n" .
4533 '<link rel="alternate" type="text/html" href="' .
4534 $alt_url . '" />' . "\n" .
4535 '<link rel="self" type="' . $content_type . '" href="' .
4536 $cgi->self_url() . '" />' . "\n" .
4537 "<id>" . href
(-full
=>1) . "</id>\n" .
4538 # use project owner for feed author
4539 "<author><name>$owner</name></author>\n";
4540 if (defined $favicon) {
4541 print "<icon>" . esc_url
($favicon) . "</icon>\n";
4543 if (defined $logo_url) {
4544 # not twice as wide as tall: 72 x 27 pixels
4545 print "<logo>" . esc_url
($logo) . "</logo>\n";
4547 if (! %latest_date) {
4548 # dummy date to keep the feed valid until commits trickle in:
4549 print "<updated>1970-01-01T00:00:00Z</updated>\n";
4551 print "<updated>$latest_date{'iso-8601'}</updated>\n";
4556 for (my $i = 0; $i <= $#commitlist; $i++) {
4557 my %co = %{$commitlist[$i]};
4558 my $commit = $co{'id'};
4559 # we read 150, we always show 30 and the ones more recent than 48 hours
4560 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
4563 my %cd = parse_date
($co{'author_epoch'});
4565 # get list of changed files
4566 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4567 $co{'parent'}, $co{'id'}, "--", (defined $file_name ?
$file_name : ())
4569 my @difftree = map { chomp; $_ } <$fd>;
4573 # print element (entry, item)
4574 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
4575 if ($format eq 'rss') {
4577 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
4578 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
4579 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
4580 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
4581 "<link>$co_url</link>\n" .
4582 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
4583 "<content:encoded>" .
4585 } elsif ($format eq 'atom') {
4587 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
4588 "<updated>$cd{'iso-8601'}</updated>\n" .
4590 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
4591 if ($co{'author_email'}) {
4592 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
4594 print "</author>\n" .
4595 # use committer for contributor
4597 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
4598 if ($co{'committer_email'}) {
4599 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
4601 print "</contributor>\n" .
4602 "<published>$cd{'iso-8601'}</published>\n" .
4603 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
4604 "<id>$co_url</id>\n" .
4605 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
4606 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
4608 my $comment = $co{'comment'};
4610 foreach my $line (@
$comment) {
4611 $line = esc_html
($line);
4614 print "</pre><ul>\n";
4615 foreach my $difftree_line (@difftree) {
4616 my %difftree = parse_difftree_raw_line
($difftree_line);
4617 next if !$difftree{'from_id'};
4619 my $file = $difftree{'file'} || $difftree{'to_file'};
4623 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
4624 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
4625 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
4626 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
4627 -title
=> "diff"}, 'D');
4629 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
4630 file_name
=>$file, hash_base
=>$commit),
4631 -title
=> "blame"}, 'B');
4633 # if this is not a feed of a file history
4634 if (!defined $file_name || $file_name ne $file) {
4635 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
4636 file_name
=>$file, hash
=>$commit),
4637 -title
=> "history"}, 'H');
4639 $file = esc_path
($file);
4643 if ($format eq 'rss') {
4644 print "</ul>]]>\n" .
4645 "</content:encoded>\n" .
4647 } elsif ($format eq 'atom') {
4648 print "</ul>\n</div>\n" .
4655 if ($format eq 'rss') {
4656 print "</channel>\n</rss>\n";
4657 } elsif ($format eq 'atom') {
4671 my @list = git_get_projects_list
();
4673 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
4675 <?xml version="1.0" encoding="utf-8"?>
4676 <opml version="1.0">
4678 <title>$site_name OPML Export</title>
4681 <outline text="git RSS feeds">
4684 foreach my $pr (@list) {
4686 my $head = git_get_head_hash
($proj{'path'});
4687 if (!defined $head) {
4690 $git_dir = "$projectroot/$proj{'path'}";
4691 my %co = parse_commit
($head);
4696 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
4697 my $rss = "$my_url?p=$proj{'path'};a=rss";
4698 my $html = "$my_url?p=$proj{'path'};a=summary";
4699 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";