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;
57 # URI of GIT logo (72x27 size)
58 our $logo = "++GITWEB_LOGO++";
59 # URI of GIT favicon, assumed to be image/png type
60 our $favicon = "++GITWEB_FAVICON++";
62 # URI and label (title) of GIT logo link
63 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
64 #our $logo_label = "git documentation";
65 our $logo_url = "http://git.or.cz/";
66 our $logo_label = "git homepage";
68 # source of projects list
69 our $projects_list = "++GITWEB_LIST++";
71 # show repository only if this file exists
72 # (only effective if this variable evaluates to true)
73 our $export_ok = "++GITWEB_EXPORT_OK++";
75 # only allow viewing of repositories also shown on the overview page
76 our $strict_export = "++GITWEB_STRICT_EXPORT++";
78 # list of git base URLs used for URL to where fetch project from,
79 # i.e. full URL is "$git_base_url/$project"
80 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
82 # default blob_plain mimetype and default charset for text/plain blob
83 our $default_blob_plain_mimetype = 'text/plain';
84 our $default_text_plain_charset = undef;
86 # file to use for guessing MIME types before trying /etc/mime.types
87 # (relative to the current git repository)
88 our $mimetypes_file = undef;
90 # You define site-wide feature defaults here; override them with
91 # $GITWEB_CONFIG as necessary.
94 # 'sub' => feature-sub (subroutine),
95 # 'override' => allow-override (boolean),
96 # 'default' => [ default options...] (array reference)}
98 # if feature is overridable (it means that allow-override has true value,
99 # then feature-sub will be called with default options as parameters;
100 # return value of feature-sub indicates if to enable specified feature
102 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
104 # Enable the 'blame' blob view, showing the last commit that modified
105 # each line in the file. This can be very CPU-intensive.
107 # To enable system wide have in $GITWEB_CONFIG
108 # $feature{'blame'}{'default'} = [1];
109 # To have project specific config enable override in $GITWEB_CONFIG
110 # $feature{'blame'}{'override'} = 1;
111 # and in project config gitweb.blame = 0|1;
113 'sub' => \
&feature_blame
,
117 # Enable the 'snapshot' link, providing a compressed tarball of any
118 # tree. This can potentially generate high traffic if you have large
121 # To disable system wide have in $GITWEB_CONFIG
122 # $feature{'snapshot'}{'default'} = [undef];
123 # To have project specific config enable override in $GITWEB_CONFIG
124 # $feature{'snapshot'}{'override'} = 1;
125 # and in project config gitweb.snapshot = none|gzip|bzip2;
127 'sub' => \
&feature_snapshot
,
129 # => [content-encoding, suffix, program]
130 'default' => ['x-gzip', 'gz', 'gzip']},
132 # Enable the pickaxe search, which will list the commits that modified
133 # a given string in a file. This can be practical and quite faster
134 # alternative to 'blame', but still potentially CPU-intensive.
136 # To enable system wide have in $GITWEB_CONFIG
137 # $feature{'pickaxe'}{'default'} = [1];
138 # To have project specific config enable override in $GITWEB_CONFIG
139 # $feature{'pickaxe'}{'override'} = 1;
140 # and in project config gitweb.pickaxe = 0|1;
142 'sub' => \
&feature_pickaxe
,
146 # Make gitweb use an alternative format of the URLs which can be
147 # more readable and natural-looking: project name is embedded
148 # directly in the path and the query string contains other
149 # auxiliary information. All gitweb installations recognize
150 # URL in either format; this configures in which formats gitweb
153 # To enable system wide have in $GITWEB_CONFIG
154 # $feature{'pathinfo'}{'default'} = [1];
155 # Project specific override is not supported.
157 # Note that you will need to change the default location of CSS,
158 # favicon, logo and possibly other files to an absolute URL. Also,
159 # if gitweb.cgi serves as your indexfile, you will need to force
160 # $my_uri to contain the script name in your $GITWEB_CONFIG.
165 # Make gitweb consider projects in project root subdirectories
166 # to be forks of existing projects. Given project $projname.git,
167 # projects matching $projname/*.git will not be shown in the main
168 # projects list, instead a '+' mark will be added to $projname
169 # there and a 'forks' view will be enabled for the project, listing
170 # all the forks. This feature is supported only if project list
171 # is taken from a directory, not file.
173 # To enable system wide have in $GITWEB_CONFIG
174 # $feature{'forks'}{'default'} = [1];
175 # Project specific override is not supported.
181 sub gitweb_check_feature
{
183 return unless exists $feature{$name};
184 my ($sub, $override, @defaults) = (
185 $feature{$name}{'sub'},
186 $feature{$name}{'override'},
187 @{$feature{$name}{'default'}});
188 if (!$override) { return @defaults; }
190 warn "feature $name is not overrideable";
193 return $sub->(@defaults);
197 my ($val) = git_get_project_config
('blame', '--bool');
199 if ($val eq 'true') {
201 } elsif ($val eq 'false') {
208 sub feature_snapshot
{
209 my ($ctype, $suffix, $command) = @_;
211 my ($val) = git_get_project_config
('snapshot');
213 if ($val eq 'gzip') {
214 return ('x-gzip', 'gz', 'gzip');
215 } elsif ($val eq 'bzip2') {
216 return ('x-bzip2', 'bz2', 'bzip2');
217 } elsif ($val eq 'none') {
221 return ($ctype, $suffix, $command);
224 sub gitweb_have_snapshot
{
225 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
226 my $have_snapshot = (defined $ctype && defined $suffix);
228 return $have_snapshot;
231 sub feature_pickaxe
{
232 my ($val) = git_get_project_config
('pickaxe', '--bool');
234 if ($val eq 'true') {
236 } elsif ($val eq 'false') {
243 # checking HEAD file with -e is fragile if the repository was
244 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
246 sub check_head_link
{
248 my $headfile = "$dir/HEAD";
249 return ((-e
$headfile) ||
250 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
253 sub check_export_ok
{
255 return (check_head_link
($dir) &&
256 (!$export_ok || -e
"$dir/$export_ok"));
259 # rename detection options for git-diff and git-diff-tree
260 # - default is '-M', with the cost proportional to
261 # (number of removed files) * (number of new files).
262 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
263 # (number of changed files + number of removed files) * (number of new files)
264 # - even more costly is '-C', '--find-copies-harder' with cost
265 # (number of files in the original tree) * (number of new files)
266 # - one might want to include '-B' option, e.g. '-B', '-M'
267 our @diff_opts = ('-M'); # taken from git_commit
269 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
270 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
272 # version of the core git binary
273 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
275 $projects_list ||= $projectroot;
277 # ======================================================================
278 # input validation and dispatch
279 our $action = $cgi->param('a');
280 if (defined $action) {
281 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
282 die_error
(undef, "Invalid action parameter");
286 # parameters which are pathnames
287 our $project = $cgi->param('p');
288 if (defined $project) {
289 if (!validate_pathname
($project) ||
290 !(-d
"$projectroot/$project") ||
291 !check_head_link
("$projectroot/$project") ||
292 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
293 ($strict_export && !project_in_list
($project))) {
295 die_error
(undef, "No such project");
299 our $file_name = $cgi->param('f');
300 if (defined $file_name) {
301 if (!validate_pathname
($file_name)) {
302 die_error
(undef, "Invalid file parameter");
306 our $file_parent = $cgi->param('fp');
307 if (defined $file_parent) {
308 if (!validate_pathname
($file_parent)) {
309 die_error
(undef, "Invalid file parent parameter");
313 # parameters which are refnames
314 our $hash = $cgi->param('h');
316 if (!validate_refname
($hash)) {
317 die_error
(undef, "Invalid hash parameter");
321 our $hash_parent = $cgi->param('hp');
322 if (defined $hash_parent) {
323 if (!validate_refname
($hash_parent)) {
324 die_error
(undef, "Invalid hash parent parameter");
328 our $hash_base = $cgi->param('hb');
329 if (defined $hash_base) {
330 if (!validate_refname
($hash_base)) {
331 die_error
(undef, "Invalid hash base parameter");
335 our $hash_parent_base = $cgi->param('hpb');
336 if (defined $hash_parent_base) {
337 if (!validate_refname
($hash_parent_base)) {
338 die_error
(undef, "Invalid hash parent base parameter");
343 our $page = $cgi->param('pg');
345 if ($page =~ m/[^0-9]/) {
346 die_error
(undef, "Invalid page parameter");
350 our $searchtext = $cgi->param('s');
351 if (defined $searchtext) {
352 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
353 die_error
(undef, "Invalid search parameter");
355 $searchtext = quotemeta $searchtext;
358 our $searchtype = $cgi->param('st');
359 if (defined $searchtype) {
360 if ($searchtype =~ m/[^a-z]/) {
361 die_error
(undef, "Invalid searchtype parameter");
365 # now read PATH_INFO and use it as alternative to parameters
366 sub evaluate_path_info
{
367 return if defined $project;
368 my $path_info = $ENV{"PATH_INFO"};
369 return if !$path_info;
370 $path_info =~ s
,^/+,,;
371 return if !$path_info;
372 # find which part of PATH_INFO is project
373 $project = $path_info;
375 while ($project && !check_head_link
("$projectroot/$project")) {
376 $project =~ s
,/*[^/]*$,,;
379 $project = validate_pathname
($project);
381 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
382 ($strict_export && !project_in_list
($project))) {
386 # do not change any parameters if an action is given using the query string
388 $path_info =~ s
,^$project/*,,;
389 my ($refname, $pathname) = split(/:/, $path_info, 2);
390 if (defined $pathname) {
391 # we got "project.git/branch:filename" or "project.git/branch:dir/"
392 # we could use git_get_type(branch:pathname), but it needs $git_dir
393 $pathname =~ s
,^/+,,;
394 if (!$pathname || substr($pathname, -1) eq "/") {
398 $action ||= "blob_plain";
400 $hash_base ||= validate_refname
($refname);
401 $file_name ||= validate_pathname
($pathname);
402 } elsif (defined $refname) {
403 # we got "project.git/branch"
404 $action ||= "shortlog";
405 $hash ||= validate_refname
($refname);
408 evaluate_path_info
();
410 # path to the current git repository
412 $git_dir = "$projectroot/$project" if $project;
416 "blame" => \
&git_blame2
,
417 "blobdiff" => \
&git_blobdiff
,
418 "blobdiff_plain" => \
&git_blobdiff_plain
,
419 "blob" => \
&git_blob
,
420 "blob_plain" => \
&git_blob_plain
,
421 "commitdiff" => \
&git_commitdiff
,
422 "commitdiff_plain" => \
&git_commitdiff_plain
,
423 "commit" => \
&git_commit
,
424 "forks" => \
&git_forks
,
425 "heads" => \
&git_heads
,
426 "history" => \
&git_history
,
429 "atom" => \
&git_atom
,
430 "search" => \
&git_search
,
431 "search_help" => \
&git_search_help
,
432 "shortlog" => \
&git_shortlog
,
433 "summary" => \
&git_summary
,
435 "tags" => \
&git_tags
,
436 "tree" => \
&git_tree
,
437 "snapshot" => \
&git_snapshot
,
438 "object" => \
&git_object
,
439 # those below don't need $project
440 "opml" => \
&git_opml
,
441 "project_list" => \
&git_project_list
,
442 "project_index" => \
&git_project_index
,
445 if (defined $project) {
446 $action ||= 'summary';
448 $action ||= 'project_list';
450 if (!defined($actions{$action})) {
451 die_error
(undef, "Unknown action");
453 if ($action !~ m/^(opml|project_list|project_index)$/ &&
455 die_error
(undef, "Project needed");
457 $actions{$action}->();
460 ## ======================================================================
465 # default is to use -absolute url() i.e. $my_uri
466 my $href = $params{-full
} ? $my_url : $my_uri;
468 # XXX: Warning: If you touch this, check the search form for updating,
479 hash_parent_base
=> "hpb",
485 my %mapping = @mapping;
487 $params{'project'} = $project unless exists $params{'project'};
489 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
491 # use PATH_INFO for project name
492 $href .= "/$params{'project'}" if defined $params{'project'};
493 delete $params{'project'};
495 # Summary just uses the project path URL
496 if (defined $params{'action'} && $params{'action'} eq 'summary') {
497 delete $params{'action'};
501 # now encode the parameters explicitly
503 for (my $i = 0; $i < @mapping; $i += 2) {
504 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
505 if (defined $params{$name}) {
506 push @result, $symbol . "=" . esc_param
($params{$name});
509 $href .= "?" . join(';', @result) if scalar @result;
515 ## ======================================================================
516 ## validation, quoting/unquoting and escaping
518 sub validate_pathname
{
519 my $input = shift || return undef;
521 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
522 # at the beginning, at the end, and between slashes.
523 # also this catches doubled slashes
524 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
528 if ($input =~ m!\0!) {
534 sub validate_refname
{
535 my $input = shift || return undef;
537 # textual hashes are O.K.
538 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
541 # it must be correct pathname
542 $input = validate_pathname
($input)
544 # restrictions on ref name according to git-check-ref-format
545 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
551 # very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT);
554 return decode
("utf8", $str, Encode
::FB_DEFAULT
);
557 # quote unsafe chars, but keep the slash, even when it's not
558 # correct, but quoted slashes look too horrible in bookmarks
561 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
567 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
570 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
576 # replace invalid utf8 character with SUBSTITUTION sequence
581 $str = to_utf8
($str);
582 $str = escapeHTML
($str);
583 if ($opts{'-nbsp'}) {
584 $str =~ s/ / /g;
586 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
590 # quote control characters and escape filename to HTML
595 $str = to_utf8
($str);
596 $str = escapeHTML
($str);
597 if ($opts{'-nbsp'}) {
598 $str =~ s/ / /g;
600 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
604 # Make control characters "printable", using character escape codes (CEC)
607 my %es = ( # character escape codes, aka escape sequences
608 "\t" => '\t', # tab (HT)
609 "\n" => '\n', # line feed (LF)
610 "\r" => '\r', # carrige return (CR)
611 "\f" => '\f', # form feed (FF)
612 "\b" => '\b', # backspace (BS)
613 "\a" => '\a', # alarm (bell) (BEL)
614 "\e" => '\e', # escape (ESC)
615 "\013" => '\v', # vertical tab (VT)
616 "\000" => '\0', # nul character (NUL)
618 my $chr = ( (exists $es{$cntrl})
620 : sprintf('\%03o', ord($cntrl)) );
621 return "<span class=\"cntrl\">$chr</span>";
624 # Alternatively use unicode control pictures codepoints,
625 # Unicode "printable representation" (PR)
628 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
629 return "<span class=\"cntrl\">$chr</span>";
632 # git may return quoted and escaped filenames
638 my %es = ( # character escape codes, aka escape sequences
639 't' => "\t", # tab (HT, TAB)
640 'n' => "\n", # newline (NL)
641 'r' => "\r", # return (CR)
642 'f' => "\f", # form feed (FF)
643 'b' => "\b", # backspace (BS)
644 'a' => "\a", # alarm (bell) (BEL)
645 'e' => "\e", # escape (ESC)
646 'v' => "\013", # vertical tab (VT)
649 if ($seq =~ m/^[0-7]{1,3}$/) {
650 # octal char sequence
651 return chr(oct($seq));
652 } elsif (exists $es{$seq}) {
653 # C escape sequence, aka character escape code
656 # quoted ordinary character
660 if ($str =~ m/^"(.*)"$/) {
663 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
668 # escape tabs (convert tabs to spaces)
672 while ((my $pos = index($line, "\t")) != -1) {
673 if (my $count = (8 - ($pos % 8))) {
674 my $spaces = ' ' x
$count;
675 $line =~ s/\t/$spaces/;
682 sub project_in_list
{
684 my @list = git_get_projects_list
();
685 return @list && scalar(grep { $_->{'path'} eq $project } @list);
688 ## ----------------------------------------------------------------------
689 ## HTML aware string manipulation
694 my $add_len = shift || 10;
696 # allow only $len chars, but don't cut a word if it would fit in $add_len
697 # if it doesn't fit, cut it if it's still longer than the dots we would add
698 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
701 if (length($tail) > 4) {
703 $body =~ s/&[^;]*$//; # remove chopped character entities
708 ## ----------------------------------------------------------------------
709 ## functions returning short strings
711 # CSS class for given age value (in seconds)
715 if ($age < 60*60*2) {
717 } elsif ($age < 60*60*24*2) {
724 # convert age in seconds to "nn units ago" string
729 if ($age > 60*60*24*365*2) {
730 $age_str = (int $age/60/60/24/365);
731 $age_str .= " years ago";
732 } elsif ($age > 60*60*24*(365/12)*2) {
733 $age_str = int $age/60/60/24/(365/12);
734 $age_str .= " months ago";
735 } elsif ($age > 60*60*24*7*2) {
736 $age_str = int $age/60/60/24/7;
737 $age_str .= " weeks ago";
738 } elsif ($age > 60*60*24*2) {
739 $age_str = int $age/60/60/24;
740 $age_str .= " days ago";
741 } elsif ($age > 60*60*2) {
742 $age_str = int $age/60/60;
743 $age_str .= " hours ago";
744 } elsif ($age > 60*2) {
745 $age_str = int $age/60;
746 $age_str .= " min ago";
749 $age_str .= " sec ago";
751 $age_str .= " right now";
756 # convert file mode in octal to symbolic file mode string
758 my $mode = oct shift;
760 if (S_ISDIR
($mode & S_IFMT
)) {
762 } elsif (S_ISLNK
($mode)) {
764 } elsif (S_ISREG
($mode)) {
765 # git cares only about the executable bit
766 if ($mode & S_IXUSR
) {
776 # convert file mode in octal to file type string
780 if ($mode !~ m/^[0-7]+$/) {
786 if (S_ISDIR
($mode & S_IFMT
)) {
788 } elsif (S_ISLNK
($mode)) {
790 } elsif (S_ISREG
($mode)) {
797 # convert file mode in octal to file type description string
801 if ($mode !~ m/^[0-7]+$/) {
807 if (S_ISDIR
($mode & S_IFMT
)) {
809 } elsif (S_ISLNK
($mode)) {
811 } elsif (S_ISREG
($mode)) {
812 if ($mode & S_IXUSR
) {
823 ## ----------------------------------------------------------------------
824 ## functions returning short HTML fragments, or transforming HTML fragments
825 ## which don't beling to other sections
827 # format line of commit message.
828 sub format_log_line_html
{
831 $line = esc_html
($line, -nbsp
=>1);
832 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
835 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
836 -class => "text"}, $hash_text);
837 $line =~ s/$hash_text/$link/;
842 # format marker of refs pointing to given object
843 sub format_ref_marker
{
844 my ($refs, $id) = @_;
847 if (defined $refs->{$id}) {
848 foreach my $ref (@{$refs->{$id}}) {
849 my ($type, $name) = qw();
850 # e.g. tags/v2.6.11 or heads/next
851 if ($ref =~ m!^(.*?)s?/(.*)$!) {
859 $markers .= " <span class=\"$type\" title=\"$ref\">" .
860 esc_html
($name) . "</span>";
865 return ' <span class="refs">'. $markers . '</span>';
871 # format, perhaps shortened and with markers, title line
872 sub format_subject_html
{
873 my ($long, $short, $href, $extra) = @_;
874 $extra = '' unless defined($extra);
876 if (length($short) < length($long)) {
877 return $cgi->a({-href
=> $href, -class => "list subject",
878 -title
=> to_utf8
($long)},
879 esc_html
($short) . $extra);
881 return $cgi->a({-href
=> $href, -class => "list subject"},
882 esc_html
($long) . $extra);
886 # format patch (diff) line (rather not to be used for diff headers)
887 sub format_diff_line
{
889 my ($from, $to) = @_;
890 my $char = substr($line, 0, 1);
896 $diff_class = " add";
897 } elsif ($char eq "-") {
898 $diff_class = " rem";
899 } elsif ($char eq "@") {
900 $diff_class = " chunk_header";
901 } elsif ($char eq "\\") {
902 $diff_class = " incomplete";
904 $line = untabify
($line);
905 if ($from && $to && $line =~ m/^\@{2} /) {
906 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
907 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
909 $from_lines = 0 unless defined $from_lines;
910 $to_lines = 0 unless defined $to_lines;
912 if ($from->{'href'}) {
913 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
914 -class=>"list"}, $from_text);
917 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
918 -class=>"list"}, $to_text);
920 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
921 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
922 return "<div class=\"diff$diff_class\">$line</div>\n";
924 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
927 ## ----------------------------------------------------------------------
928 ## git utility subroutines, invoking git commands
930 # returns path to the core git executable and the --git-dir parameter as list
932 return $GIT, '--git-dir='.$git_dir;
935 # returns path to the core git executable and the --git-dir parameter as string
937 return join(' ', git_cmd
());
940 # get HEAD ref of given project as hash
941 sub git_get_head_hash
{
943 my $o_git_dir = $git_dir;
945 $git_dir = "$projectroot/$project";
946 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
949 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
953 if (defined $o_git_dir) {
954 $git_dir = $o_git_dir;
959 # get type of given object
963 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
970 sub git_get_project_config
{
971 my ($key, $type) = @_;
973 return unless ($key);
974 $key =~ s/^gitweb\.//;
975 return if ($key =~ m/\W/);
977 my @x = (git_cmd
(), 'repo-config');
978 if (defined $type) { push @x, $type; }
980 push @x, "gitweb.$key";
986 # get hash of given path at given ref
987 sub git_get_hash_by_path
{
989 my $path = shift || return undef;
994 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
995 or die_error
(undef, "Open git-ls-tree failed");
997 close $fd or return undef;
999 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1000 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1001 if (defined $type && $type ne $2) {
1002 # type doesn't match
1008 ## ......................................................................
1009 ## git utility functions, directly accessing git repository
1011 sub git_get_project_description
{
1014 open my $fd, "$projectroot/$path/description" or return undef;
1021 sub git_get_project_url_list
{
1024 open my $fd, "$projectroot/$path/cloneurl" or return;
1025 my @git_project_url_list = map { chomp; $_ } <$fd>;
1028 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1031 sub git_get_projects_list
{
1036 $filter =~ s/\.git$//;
1038 if (-d
$projects_list) {
1039 # search in directory
1040 my $dir = $projects_list . ($filter ? "/$filter" : '');
1041 # remove the trailing "/"
1043 my $pfxlen = length("$dir");
1045 my ($check_forks) = gitweb_check_feature
('forks');
1048 follow_fast
=> 1, # follow symbolic links
1049 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1051 # skip project-list toplevel, if we get it.
1052 return if (m!^[/.]$!);
1053 # only directories can be git repositories
1054 return unless (-d
$_);
1056 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1057 # we check related file in $projectroot
1058 if ($check_forks and $subdir =~ m
#/.#) {
1059 $File::Find
::prune
= 1;
1060 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1061 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1062 $File::Find
::prune
= 1;
1067 } elsif (-f
$projects_list) {
1068 # read from file(url-encoded):
1069 # 'git%2Fgit.git Linus+Torvalds'
1070 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1071 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1072 open my ($fd), $projects_list or return;
1073 while (my $line = <$fd>) {
1075 my ($path, $owner) = split ' ', $line;
1076 $path = unescape
($path);
1077 $owner = unescape
($owner);
1078 if (!defined $path) {
1081 if ($filter ne '') {
1082 # looking for forks;
1083 my $pfx = substr($path, 0, length($filter));
1084 if ($pfx ne $filter) {
1087 my $sfx = substr($path, length($filter));
1088 if ($sfx !~ /^\/.*\
.git
$/) {
1092 if (check_export_ok
("$projectroot/$path")) {
1095 owner
=> to_utf8
($owner),
1102 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
1106 sub git_get_project_owner
{
1107 my $project = shift;
1110 return undef unless $project;
1112 # read from file (url-encoded):
1113 # 'git%2Fgit.git Linus+Torvalds'
1114 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1115 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1116 if (-f
$projects_list) {
1117 open (my $fd , $projects_list);
1118 while (my $line = <$fd>) {
1120 my ($pr, $ow) = split ' ', $line;
1121 $pr = unescape
($pr);
1122 $ow = unescape
($ow);
1123 if ($pr eq $project) {
1124 $owner = to_utf8
($ow);
1130 if (!defined $owner) {
1131 $owner = get_file_owner
("$projectroot/$project");
1137 sub git_get_last_activity
{
1141 $git_dir = "$projectroot/$path";
1142 open($fd, "-|", git_cmd
(), 'for-each-ref',
1143 '--format=%(committer)',
1144 '--sort=-committerdate',
1146 'refs/heads') or return;
1147 my $most_recent = <$fd>;
1148 close $fd or return;
1149 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1151 my $age = time - $timestamp;
1152 return ($age, age_string
($age));
1156 sub git_get_references
{
1157 my $type = shift || "";
1159 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1160 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1161 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1162 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1165 while (my $line = <$fd>) {
1167 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1168 if (defined $refs{$1}) {
1169 push @{$refs{$1}}, $2;
1175 close $fd or return;
1179 sub git_get_rev_name_tags
{
1180 my $hash = shift || return undef;
1182 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1184 my $name_rev = <$fd>;
1187 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1190 # catches also '$hash undefined' output
1195 ## ----------------------------------------------------------------------
1196 ## parse to hash functions
1200 my $tz = shift || "-0000";
1203 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1204 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1205 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1206 $date{'hour'} = $hour;
1207 $date{'minute'} = $min;
1208 $date{'mday'} = $mday;
1209 $date{'day'} = $days[$wday];
1210 $date{'month'} = $months[$mon];
1211 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1212 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1213 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1214 $mday, $months[$mon], $hour ,$min;
1215 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1216 1900+$year, $mon, $mday, $hour ,$min, $sec;
1218 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1219 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1220 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1221 $date{'hour_local'} = $hour;
1222 $date{'minute_local'} = $min;
1223 $date{'tz_local'} = $tz;
1224 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1225 1900+$year, $mon+1, $mday,
1226 $hour, $min, $sec, $tz);
1235 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1236 $tag{'id'} = $tag_id;
1237 while (my $line = <$fd>) {
1239 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1240 $tag{'object'} = $1;
1241 } elsif ($line =~ m/^type (.+)$/) {
1243 } elsif ($line =~ m/^tag (.+)$/) {
1245 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1246 $tag{'author'} = $1;
1249 } elsif ($line =~ m/--BEGIN/) {
1250 push @comment, $line;
1252 } elsif ($line eq "") {
1256 push @comment, <$fd>;
1257 $tag{'comment'} = \
@comment;
1258 close $fd or return;
1259 if (!defined $tag{'name'}) {
1266 my $commit_id = shift;
1267 my $commit_text = shift;
1272 if (defined $commit_text) {
1273 @commit_lines = @$commit_text;
1276 open my $fd, "-|", git_cmd
(), "rev-list",
1277 "--header", "--parents", "--max-count=1",
1280 @commit_lines = split '\n', <$fd>;
1281 close $fd or return;
1284 my $header = shift @commit_lines;
1285 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1288 ($co{'id'}, my @parents) = split ' ', $header;
1289 $co{'parents'} = \
@parents;
1290 $co{'parent'} = $parents[0];
1291 while (my $line = shift @commit_lines) {
1292 last if $line eq "\n";
1293 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1295 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1297 $co{'author_epoch'} = $2;
1298 $co{'author_tz'} = $3;
1299 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1300 $co{'author_name'} = $1;
1301 $co{'author_email'} = $2;
1303 $co{'author_name'} = $co{'author'};
1305 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1306 $co{'committer'} = $1;
1307 $co{'committer_epoch'} = $2;
1308 $co{'committer_tz'} = $3;
1309 $co{'committer_name'} = $co{'committer'};
1310 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1311 $co{'committer_name'} = $1;
1312 $co{'committer_email'} = $2;
1314 $co{'committer_name'} = $co{'committer'};
1318 if (!defined $co{'tree'}) {
1322 foreach my $title (@commit_lines) {
1325 $co{'title'} = chop_str
($title, 80, 5);
1326 # remove leading stuff of merges to make the interesting part visible
1327 if (length($title) > 50) {
1328 $title =~ s/^Automatic //;
1329 $title =~ s/^merge (of|with) /Merge ... /i;
1330 if (length($title) > 50) {
1331 $title =~ s/(http|rsync):\/\///;
1333 if (length($title) > 50) {
1334 $title =~ s/(master|www|rsync)\.//;
1336 if (length($title) > 50) {
1337 $title =~ s/kernel.org:?//;
1339 if (length($title) > 50) {
1340 $title =~ s/\/pub\/scm//;
1343 $co{'title_short'} = chop_str
($title, 50, 5);
1347 if ($co{'title'} eq "") {
1348 $co{'title'} = $co{'title_short'} = '(no commit message)';
1350 # remove added spaces
1351 foreach my $line (@commit_lines) {
1354 $co{'comment'} = \
@commit_lines;
1356 my $age = time - $co{'committer_epoch'};
1358 $co{'age_string'} = age_string
($age);
1359 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1360 if ($age > 60*60*24*7*2) {
1361 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1362 $co{'age_string_age'} = $co{'age_string'};
1364 $co{'age_string_date'} = $co{'age_string'};
1365 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1370 # parse ref from ref_file, given by ref_id, with given type
1372 my $ref_file = shift;
1374 my $type = shift || git_get_type
($ref_id);
1377 $ref_item{'type'} = $type;
1378 $ref_item{'id'} = $ref_id;
1379 $ref_item{'epoch'} = 0;
1380 $ref_item{'age'} = "unknown";
1381 if ($type eq "tag") {
1382 my %tag = parse_tag
($ref_id);
1383 $ref_item{'comment'} = $tag{'comment'};
1384 if ($tag{'type'} eq "commit") {
1385 my %co = parse_commit
($tag{'object'});
1386 $ref_item{'epoch'} = $co{'committer_epoch'};
1387 $ref_item{'age'} = $co{'age_string'};
1388 } elsif (defined($tag{'epoch'})) {
1389 my $age = time - $tag{'epoch'};
1390 $ref_item{'epoch'} = $tag{'epoch'};
1391 $ref_item{'age'} = age_string
($age);
1393 $ref_item{'reftype'} = $tag{'type'};
1394 $ref_item{'name'} = $tag{'name'};
1395 $ref_item{'refid'} = $tag{'object'};
1396 } elsif ($type eq "commit"){
1397 my %co = parse_commit
($ref_id);
1398 $ref_item{'reftype'} = "commit";
1399 $ref_item{'name'} = $ref_file;
1400 $ref_item{'title'} = $co{'title'};
1401 $ref_item{'refid'} = $ref_id;
1402 $ref_item{'epoch'} = $co{'committer_epoch'};
1403 $ref_item{'age'} = $co{'age_string'};
1405 $ref_item{'reftype'} = $type;
1406 $ref_item{'name'} = $ref_file;
1407 $ref_item{'refid'} = $ref_id;
1413 # parse line of git-diff-tree "raw" output
1414 sub parse_difftree_raw_line
{
1418 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1419 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1420 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1421 $res{'from_mode'} = $1;
1422 $res{'to_mode'} = $2;
1423 $res{'from_id'} = $3;
1425 $res{'status'} = $5;
1426 $res{'similarity'} = $6;
1427 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1428 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1430 $res{'file'} = unquote
($7);
1433 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1434 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1435 $res{'commit'} = $1;
1438 return wantarray ? %res : \
%res;
1441 # parse line of git-ls-tree output
1442 sub parse_ls_tree_line
($;%) {
1447 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1448 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1456 $res{'name'} = unquote
($4);
1459 return wantarray ? %res : \
%res;
1462 ## ......................................................................
1463 ## parse to array of hashes functions
1465 sub git_get_heads_list
{
1469 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1470 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1471 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1474 while (my $line = <$fd>) {
1478 my ($refinfo, $committerinfo) = split(/\0/, $line);
1479 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1480 my ($committer, $epoch, $tz) =
1481 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1482 $name =~ s!^refs/heads/!!;
1484 $ref_item{'name'} = $name;
1485 $ref_item{'id'} = $hash;
1486 $ref_item{'title'} = $title || '(no commit message)';
1487 $ref_item{'epoch'} = $epoch;
1489 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1491 $ref_item{'age'} = "unknown";
1494 push @headslist, \
%ref_item;
1498 return wantarray ? @headslist : \
@headslist;
1501 sub git_get_tags_list
{
1505 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1506 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1507 '--format=%(objectname) %(objecttype) %(refname) '.
1508 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1511 while (my $line = <$fd>) {
1515 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1516 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1517 my ($creator, $epoch, $tz) =
1518 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1519 $name =~ s!^refs/tags/!!;
1521 $ref_item{'type'} = $type;
1522 $ref_item{'id'} = $id;
1523 $ref_item{'name'} = $name;
1524 if ($type eq "tag") {
1525 $ref_item{'subject'} = $title;
1526 $ref_item{'reftype'} = $reftype;
1527 $ref_item{'refid'} = $refid;
1529 $ref_item{'reftype'} = $type;
1530 $ref_item{'refid'} = $id;
1533 if ($type eq "tag" || $type eq "commit") {
1534 $ref_item{'epoch'} = $epoch;
1536 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1538 $ref_item{'age'} = "unknown";
1542 push @tagslist, \
%ref_item;
1546 return wantarray ? @tagslist : \
@tagslist;
1549 ## ----------------------------------------------------------------------
1550 ## filesystem-related functions
1552 sub get_file_owner
{
1555 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1556 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1557 if (!defined $gcos) {
1561 $owner =~ s/[,;].*$//;
1562 return to_utf8
($owner);
1565 ## ......................................................................
1566 ## mimetype related functions
1568 sub mimetype_guess_file
{
1569 my $filename = shift;
1570 my $mimemap = shift;
1571 -r
$mimemap or return undef;
1574 open(MIME
, $mimemap) or return undef;
1576 next if m/^#/; # skip comments
1577 my ($mime, $exts) = split(/\t+/);
1578 if (defined $exts) {
1579 my @exts = split(/\s+/, $exts);
1580 foreach my $ext (@exts) {
1581 $mimemap{$ext} = $mime;
1587 $filename =~ /\.([^.]*)$/;
1588 return $mimemap{$1};
1591 sub mimetype_guess
{
1592 my $filename = shift;
1594 $filename =~ /\./ or return undef;
1596 if ($mimetypes_file) {
1597 my $file = $mimetypes_file;
1598 if ($file !~ m!^/!) { # if it is relative path
1599 # it is relative to project
1600 $file = "$projectroot/$project/$file";
1602 $mime = mimetype_guess_file
($filename, $file);
1604 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1610 my $filename = shift;
1613 my $mime = mimetype_guess
($filename);
1614 $mime and return $mime;
1618 return $default_blob_plain_mimetype unless $fd;
1621 return 'text/plain' .
1622 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1623 } elsif (! $filename) {
1624 return 'application/octet-stream';
1625 } elsif ($filename =~ m/\.png$/i) {
1627 } elsif ($filename =~ m/\.gif$/i) {
1629 } elsif ($filename =~ m/\.jpe?g$/i) {
1630 return 'image/jpeg';
1632 return 'application/octet-stream';
1636 ## ======================================================================
1637 ## functions printing HTML: header, footer, error page
1639 sub git_header_html
{
1640 my $status = shift || "200 OK";
1641 my $expires = shift;
1643 my $title = "$site_name";
1644 if (defined $project) {
1645 $title .= " - $project";
1646 if (defined $action) {
1647 $title .= "/$action";
1648 if (defined $file_name) {
1649 $title .= " - " . esc_path
($file_name);
1650 if ($action eq "tree" && $file_name !~ m
|/$|) {
1657 # require explicit support from the UA if we are to send the page as
1658 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1659 # we have to do this because MSIE sometimes globs '*/*', pretending to
1660 # support xhtml+xml but choking when it gets what it asked for.
1661 if (defined $cgi->http('HTTP_ACCEPT') &&
1662 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1663 $cgi->Accept('application/xhtml+xml') != 0) {
1664 $content_type = 'application/xhtml+xml';
1666 $content_type = 'text/html';
1668 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1669 -status
=> $status, -expires
=> $expires);
1671 <?xml version="1.0" encoding="utf-8"?>
1672 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1673 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1674 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1675 <!-- git core binaries version $git_version -->
1677 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1678 <meta name="generator" content="gitweb/$version git/$git_version"/>
1679 <meta name="robots" content="index, nofollow"/>
1680 <title>$title</title>
1682 # print out each stylesheet that exist
1683 if (defined $stylesheet) {
1684 #provides backwards capability for those people who define style sheet in a config file
1685 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1687 foreach my $stylesheet (@stylesheets) {
1688 next unless $stylesheet;
1689 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1692 if (defined $project) {
1693 printf('<link rel="alternate" title="%s log RSS feed" '.
1694 'href="%s" type="application/rss+xml" />'."\n",
1695 esc_param
($project), href
(action
=>"rss"));
1696 printf('<link rel="alternate" title="%s log Atom feed" '.
1697 'href="%s" type="application/atom+xml" />'."\n",
1698 esc_param
($project), href
(action
=>"atom"));
1700 printf('<link rel="alternate" title="%s projects list" '.
1701 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1702 $site_name, href
(project
=>undef, action
=>"project_index"));
1703 printf('<link rel="alternate" title="%s projects feeds" '.
1704 'href="%s" type="text/x-opml"/>'."\n",
1705 $site_name, href
(project
=>undef, action
=>"opml"));
1707 if (defined $favicon) {
1708 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1714 if (-f
$site_header) {
1715 open (my $fd, $site_header);
1720 print "<div class=\"page_header\">\n" .
1721 $cgi->a({-href
=> esc_url
($logo_url),
1722 -title
=> $logo_label},
1723 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1724 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1725 if (defined $project) {
1726 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1727 if (defined $action) {
1731 if (!defined $searchtext) {
1735 if (defined $hash_base) {
1736 $search_hash = $hash_base;
1737 } elsif (defined $hash) {
1738 $search_hash = $hash;
1740 $search_hash = "HEAD";
1742 $cgi->param("a", "search");
1743 $cgi->param("h", $search_hash);
1744 $cgi->param("p", $project);
1745 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1746 "<div class=\"search\">\n" .
1747 $cgi->hidden(-name
=> "p") . "\n" .
1748 $cgi->hidden(-name
=> "a") . "\n" .
1749 $cgi->hidden(-name
=> "h") . "\n" .
1750 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1751 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1752 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1754 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1756 $cgi->end_form() . "\n";
1761 sub git_footer_html
{
1762 print "<div class=\"page_footer\">\n";
1763 if (defined $project) {
1764 my $descr = git_get_project_description
($project);
1765 if (defined $descr) {
1766 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1768 print $cgi->a({-href
=> href
(action
=>"rss"),
1769 -class => "rss_logo"}, "RSS") . " ";
1770 print $cgi->a({-href
=> href
(action
=>"atom"),
1771 -class => "rss_logo"}, "Atom") . "\n";
1773 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1774 -class => "rss_logo"}, "OPML") . " ";
1775 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1776 -class => "rss_logo"}, "TXT") . "\n";
1780 if (-f
$site_footer) {
1781 open (my $fd, $site_footer);
1791 my $status = shift || "403 Forbidden";
1792 my $error = shift || "Malformed query, file missing or permission denied";
1794 git_header_html
($status);
1796 <div class="page_body">
1806 ## ----------------------------------------------------------------------
1807 ## functions printing or outputting HTML: navigation
1809 sub git_print_page_nav
{
1810 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1811 $extra = '' if !defined $extra; # pager or formats
1813 my @navs = qw(summary shortlog log commit commitdiff tree);
1815 @navs = grep { $_ ne $suppress } @navs;
1818 my %arg = map { $_ => {action
=>$_} } @navs;
1819 if (defined $head) {
1820 for (qw(commit commitdiff)) {
1821 $arg{$_}{hash
} = $head;
1823 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1824 for (qw(shortlog log)) {
1825 $arg{$_}{hash
} = $head;
1829 $arg{tree
}{hash
} = $treehead if defined $treehead;
1830 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1832 print "<div class=\"page_nav\">\n" .
1834 map { $_ eq $current ?
1835 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1837 print "<br/>\n$extra<br/>\n" .
1841 sub format_paging_nav
{
1842 my ($action, $hash, $head, $page, $nrevs) = @_;
1846 if ($hash ne $head || $page) {
1847 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1849 $paging_nav .= "HEAD";
1853 $paging_nav .= " ⋅ " .
1854 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1855 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1857 $paging_nav .= " ⋅ prev";
1860 if ($nrevs >= (100 * ($page+1)-1)) {
1861 $paging_nav .= " ⋅ " .
1862 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1863 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1865 $paging_nav .= " ⋅ next";
1871 ## ......................................................................
1872 ## functions printing or outputting HTML: div
1874 sub git_print_header_div
{
1875 my ($action, $title, $hash, $hash_base) = @_;
1878 $args{action
} = $action;
1879 $args{hash
} = $hash if $hash;
1880 $args{hash_base
} = $hash_base if $hash_base;
1882 print "<div class=\"header\">\n" .
1883 $cgi->a({-href
=> href
(%args), -class => "title"},
1884 $title ? $title : $action) .
1888 #sub git_print_authorship (\%) {
1889 sub git_print_authorship
{
1892 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1893 print "<div class=\"author_date\">" .
1894 esc_html
($co->{'author_name'}) .
1896 if ($ad{'hour_local'} < 6) {
1897 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1898 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1900 printf(" (%02d:%02d %s)",
1901 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1906 sub git_print_page_path
{
1912 print "<div class=\"page_path\">";
1913 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1914 -title
=> 'tree root'}, "[$project]");
1916 if (defined $name) {
1917 my @dirname = split '/', $name;
1918 my $basename = pop @dirname;
1921 foreach my $dir (@dirname) {
1922 $fullname .= ($fullname ? '/' : '') . $dir;
1923 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1925 -title
=> esc_html
($fullname)}, esc_path
($dir));
1928 if (defined $type && $type eq 'blob') {
1929 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1931 -title
=> esc_html
($name)}, esc_path
($basename));
1932 } elsif (defined $type && $type eq 'tree') {
1933 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1935 -title
=> esc_html
($name)}, esc_path
($basename));
1938 print esc_path
($basename);
1941 print "<br/></div>\n";
1944 # sub git_print_log (\@;%) {
1945 sub git_print_log
($;%) {
1949 if ($opts{'-remove_title'}) {
1950 # remove title, i.e. first line of log
1953 # remove leading empty lines
1954 while (defined $log->[0] && $log->[0] eq "") {
1961 foreach my $line (@$log) {
1962 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1965 if (! $opts{'-remove_signoff'}) {
1966 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1969 # remove signoff lines
1976 # print only one empty line
1977 # do not print empty line after signoff
1979 next if ($empty || $signoff);
1985 print format_log_line_html
($line) . "<br/>\n";
1988 if ($opts{'-final_empty_line'}) {
1989 # end with single empty line
1990 print "<br/>\n" unless $empty;
1994 # return link target (what link points to)
1995 sub git_get_link_target
{
2000 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2004 $link_target = <$fd>;
2009 return $link_target;
2012 # given link target, and the directory (basedir) the link is in,
2013 # return target of link relative to top directory (top tree);
2014 # return undef if it is not possible (including absolute links).
2015 sub normalize_link_target
{
2016 my ($link_target, $basedir, $hash_base) = @_;
2018 # we can normalize symlink target only if $hash_base is provided
2019 return unless $hash_base;
2021 # absolute symlinks (beginning with '/') cannot be normalized
2022 return if (substr($link_target, 0, 1) eq '/');
2024 # normalize link target to path from top (root) tree (dir)
2027 $path = $basedir . '/' . $link_target;
2029 # we are in top (root) tree (dir)
2030 $path = $link_target;
2033 # remove //, /./, and /../
2035 foreach my $part (split('/', $path)) {
2036 # discard '.' and ''
2037 next if (!$part || $part eq '.');
2039 if ($part eq '..') {
2043 # link leads outside repository (outside top dir)
2047 push @path_parts, $part;
2050 $path = join('/', @path_parts);
2055 # print tree entry (row of git_tree), but without encompassing <tr> element
2056 sub git_print_tree_entry
{
2057 my ($t, $basedir, $hash_base, $have_blame) = @_;
2060 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2062 # The format of a table row is: mode list link. Where mode is
2063 # the mode of the entry, list is the name of the entry, an href,
2064 # and link is the action links of the entry.
2066 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2067 if ($t->{'type'} eq "blob") {
2068 print "<td class=\"list\">" .
2069 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2070 file_name
=>"$basedir$t->{'name'}", %base_key),
2071 -class => "list"}, esc_path
($t->{'name'}));
2072 if (S_ISLNK
(oct $t->{'mode'})) {
2073 my $link_target = git_get_link_target
($t->{'hash'});
2075 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2076 if (defined $norm_target) {
2078 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2079 file_name
=>$norm_target),
2080 -title
=> $norm_target}, esc_path
($link_target));
2082 print " -> " . esc_path
($link_target);
2087 print "<td class=\"link\">";
2088 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2089 file_name
=>"$basedir$t->{'name'}", %base_key)},
2093 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2094 file_name
=>"$basedir$t->{'name'}", %base_key)},
2097 if (defined $hash_base) {
2099 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2100 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2104 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2105 file_name
=>"$basedir$t->{'name'}")},
2109 } elsif ($t->{'type'} eq "tree") {
2110 print "<td class=\"list\">";
2111 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2112 file_name
=>"$basedir$t->{'name'}", %base_key)},
2113 esc_path
($t->{'name'}));
2115 print "<td class=\"link\">";
2116 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2117 file_name
=>"$basedir$t->{'name'}", %base_key)},
2119 if (defined $hash_base) {
2121 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2122 file_name
=>"$basedir$t->{'name'}")},
2129 ## ......................................................................
2130 ## functions printing large fragments of HTML
2132 sub git_difftree_body
{
2133 my ($difftree, $hash, $parent) = @_;
2134 my ($have_blame) = gitweb_check_feature
('blame');
2135 print "<div class=\"list_head\">\n";
2136 if ($#{$difftree} > 10) {
2137 print(($#{$difftree} + 1) . " files changed:\n");
2141 print "<table class=\"diff_tree\">\n";
2144 foreach my $line (@{$difftree}) {
2145 my %diff = parse_difftree_raw_line
($line);
2148 print "<tr class=\"dark\">\n";
2150 print "<tr class=\"light\">\n";
2154 my ($to_mode_oct, $to_mode_str, $to_file_type);
2155 my ($from_mode_oct, $from_mode_str, $from_file_type);
2156 if ($diff{'to_mode'} ne ('0' x
6)) {
2157 $to_mode_oct = oct $diff{'to_mode'};
2158 if (S_ISREG
($to_mode_oct)) { # only for regular file
2159 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2161 $to_file_type = file_type
($diff{'to_mode'});
2163 if ($diff{'from_mode'} ne ('0' x
6)) {
2164 $from_mode_oct = oct $diff{'from_mode'};
2165 if (S_ISREG
($to_mode_oct)) { # only for regular file
2166 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2168 $from_file_type = file_type
($diff{'from_mode'});
2171 if ($diff{'status'} eq "A") { # created
2172 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2173 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2174 $mode_chng .= "]</span>";
2176 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2177 hash_base
=>$hash, file_name
=>$diff{'file'}),
2178 -class => "list"}, esc_path
($diff{'file'}));
2180 print "<td>$mode_chng</td>\n";
2181 print "<td class=\"link\">";
2182 if ($action eq 'commitdiff') {
2185 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2188 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2189 hash_base
=>$hash, file_name
=>$diff{'file'})},
2193 } elsif ($diff{'status'} eq "D") { # deleted
2194 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2196 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2197 hash_base
=>$parent, file_name
=>$diff{'file'}),
2198 -class => "list"}, esc_path
($diff{'file'}));
2200 print "<td>$mode_chng</td>\n";
2201 print "<td class=\"link\">";
2202 if ($action eq 'commitdiff') {
2205 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2208 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2209 hash_base
=>$parent, file_name
=>$diff{'file'})},
2212 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2213 file_name
=>$diff{'file'})},
2216 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2217 file_name
=>$diff{'file'})},
2221 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
2222 my $mode_chnge = "";
2223 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2224 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2225 if ($from_file_type != $to_file_type) {
2226 $mode_chnge .= " from $from_file_type to $to_file_type";
2228 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2229 if ($from_mode_str && $to_mode_str) {
2230 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2231 } elsif ($to_mode_str) {
2232 $mode_chnge .= " mode: $to_mode_str";
2235 $mode_chnge .= "]</span>\n";
2238 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2239 hash_base
=>$hash, file_name
=>$diff{'file'}),
2240 -class => "list"}, esc_path
($diff{'file'}));
2242 print "<td>$mode_chnge</td>\n";
2243 print "<td class=\"link\">";
2244 if ($action eq 'commitdiff') {
2247 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2249 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2250 # "commit" view and modified file (not onlu mode changed)
2251 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2252 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2253 hash_base
=>$hash, hash_parent_base
=>$parent,
2254 file_name
=>$diff{'file'})},
2258 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2259 hash_base
=>$hash, file_name
=>$diff{'file'})},
2262 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2263 file_name
=>$diff{'file'})},
2266 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2267 file_name
=>$diff{'file'})},
2271 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
2272 my %status_name = ('R' => 'moved', 'C' => 'copied');
2273 my $nstatus = $status_name{$diff{'status'}};
2275 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2276 # mode also for directories, so we cannot use $to_mode_str
2277 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2280 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2281 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
2282 -class => "list"}, esc_path
($diff{'to_file'})) . "</td>\n" .
2283 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2284 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2285 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
2286 -class => "list"}, esc_path
($diff{'from_file'})) .
2287 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2288 "<td class=\"link\">";
2289 if ($action eq 'commitdiff') {
2292 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2294 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2295 # "commit" view and modified file (not only pure rename or copy)
2296 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2297 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2298 hash_base
=>$hash, hash_parent_base
=>$parent,
2299 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
2303 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2304 hash_base
=>$parent, file_name
=>$diff{'to_file'})},
2307 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2308 file_name
=>$diff{'to_file'})},
2311 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2312 file_name
=>$diff{'to_file'})},
2316 } # we should not encounter Unmerged (U) or Unknown (X) status
2322 sub git_patchset_body
{
2323 my ($fd, $difftree, $hash, $hash_parent) = @_;
2329 my ($from_id, $to_id);
2331 print "<div class=\"patchset\">\n";
2333 # skip to first patch
2334 while ($patch_line = <$fd>) {
2337 last if ($patch_line =~ m/^diff /);
2341 while ($patch_line) {
2345 #assert($patch_line =~ m/^diff /) if DEBUG;
2346 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2347 push @diff_header, $patch_line;
2349 # extended diff header
2351 while ($patch_line = <$fd>) {
2354 last EXTENDED_HEADER
if ($patch_line =~ m/^--- /);
2356 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2361 push @diff_header, $patch_line;
2363 #last PATCH unless $patch_line;
2364 my $last_patch_line = $patch_line;
2366 # check if current patch belong to current raw line
2367 # and parse raw git-diff line if needed
2368 if (defined $diffinfo &&
2369 $diffinfo->{'from_id'} eq $from_id &&
2370 $diffinfo->{'to_id'} eq $to_id) {
2371 # this is split patch
2372 print "<div class=\"patch cont\">\n";
2374 # advance raw git-diff output if needed
2375 $patch_idx++ if defined $diffinfo;
2377 # read and prepare patch information
2378 if (ref($difftree->[$patch_idx]) eq "HASH") {
2379 # pre-parsed (or generated by hand)
2380 $diffinfo = $difftree->[$patch_idx];
2382 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2384 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2385 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2386 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2387 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2388 hash
=>$diffinfo->{'from_id'},
2389 file_name
=>$from{'file'});
2391 if ($diffinfo->{'status'} ne "D") { # not deleted file
2392 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2393 hash
=>$diffinfo->{'to_id'},
2394 file_name
=>$to{'file'});
2396 # this is first patch for raw difftree line with $patch_idx index
2397 # we index @$difftree array from 0, but number patches from 1
2398 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2401 # print "git diff" header
2402 $patch_line = shift @diff_header;
2403 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2404 if ($from{'href'}) {
2405 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2406 'a/' . esc_path
($from{'file'}));
2407 } else { # file was added
2408 $patch_line .= 'a/' . esc_path
($from{'file'});
2412 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2413 'b/' . esc_path
($to{'file'}));
2414 } else { # file was deleted
2415 $patch_line .= 'b/' . esc_path
($to{'file'});
2417 print "<div class=\"diff header\">$patch_line</div>\n";
2419 # print extended diff header
2420 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2422 foreach $patch_line (@diff_header) {
2424 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2425 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2426 esc_path
($from{'file'}));
2428 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2429 $patch_line = $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2430 esc_path
($to{'file'}));
2433 if ($patch_line =~ m/\s(\d{6})$/) {
2434 $patch_line .= '<span class="info"> (' .
2435 file_type_long
($1) .
2439 if ($patch_line =~ m/^index/) {
2440 my ($from_link, $to_link);
2441 if ($from{'href'}) {
2442 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2443 substr($diffinfo->{'from_id'},0,7));
2445 $from_link = '0' x
7;
2448 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2449 substr($diffinfo->{'to_id'},0,7));
2454 # my ($from_hash, $to_hash) =
2455 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2456 # my ($from_id, $to_id) =
2457 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2458 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2460 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2461 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2463 print $patch_line . "<br/>\n";
2465 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2467 # from-file/to-file diff header
2468 $patch_line = $last_patch_line;
2469 #assert($patch_line =~ m/^---/) if DEBUG;
2470 if ($from{'href'}) {
2471 $patch_line = '--- a/' .
2472 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2473 esc_path
($from{'file'}));
2475 print "<div class=\"diff from_file\">$patch_line</div>\n";
2477 $patch_line = <$fd>;
2478 #last PATCH unless $patch_line;
2481 #assert($patch_line =~ m/^+++/) if DEBUG;
2483 $patch_line = '+++ b/' .
2484 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2485 esc_path
($to{'file'}));
2487 print "<div class=\"diff to_file\">$patch_line</div>\n";
2491 while ($patch_line = <$fd>) {
2494 next PATCH
if ($patch_line =~ m/^diff /);
2496 print format_diff_line
($patch_line, \
%from, \
%to);
2500 print "</div>\n"; # class="patch"
2503 print "</div>\n"; # class="patchset"
2506 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2508 sub git_project_list_body
{
2509 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2511 my ($check_forks) = gitweb_check_feature
('forks');
2514 foreach my $pr (@$projlist) {
2515 my (@aa) = git_get_last_activity
($pr->{'path'});
2519 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2520 if (!defined $pr->{'descr'}) {
2521 my $descr = git_get_project_description
($pr->{'path'}) || "";
2522 $pr->{'descr_long'} = to_utf8
($descr);
2523 $pr->{'descr'} = chop_str
($descr, 25, 5);
2525 if (!defined $pr->{'owner'}) {
2526 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2529 my $pname = $pr->{'path'};
2530 if (($pname =~ s/\.git$//) &&
2531 ($pname !~ /\/$/) &&
2532 (-d
"$projectroot/$pname")) {
2533 $pr->{'forks'} = "-d $projectroot/$pname";
2539 push @projects, $pr;
2542 $order ||= "project";
2543 $from = 0 unless defined $from;
2544 $to = $#projects if (!defined $to || $#projects < $to);
2546 print "<table class=\"project_list\">\n";
2547 unless ($no_header) {
2550 print "<th></th>\n";
2552 if ($order eq "project") {
2553 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2554 print "<th>Project</th>\n";
2557 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2558 -class => "header"}, "Project") .
2561 if ($order eq "descr") {
2562 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2563 print "<th>Description</th>\n";
2566 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2567 -class => "header"}, "Description") .
2570 if ($order eq "owner") {
2571 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2572 print "<th>Owner</th>\n";
2575 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2576 -class => "header"}, "Owner") .
2579 if ($order eq "age") {
2580 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2581 print "<th>Last Change</th>\n";
2584 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2585 -class => "header"}, "Last Change") .
2588 print "<th></th>\n" .
2592 for (my $i = $from; $i <= $to; $i++) {
2593 my $pr = $projects[$i];
2595 print "<tr class=\"dark\">\n";
2597 print "<tr class=\"light\">\n";
2602 if ($pr->{'forks'}) {
2603 print "<!-- $pr->{'forks'} -->\n";
2604 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2608 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2609 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2610 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2611 -class => "list", -title
=> $pr->{'descr_long'}},
2612 esc_html
($pr->{'descr'})) . "</td>\n" .
2613 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2614 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2615 $pr->{'age_string'} . "</td>\n" .
2616 "<td class=\"link\">" .
2617 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2618 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2619 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2620 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2621 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
2625 if (defined $extra) {
2628 print "<td></td>\n";
2630 print "<td colspan=\"5\">$extra</td>\n" .
2636 sub git_shortlog_body
{
2637 # uses global variable $project
2638 my ($revlist, $from, $to, $refs, $extra) = @_;
2640 my $have_snapshot = gitweb_have_snapshot
();
2642 $from = 0 unless defined $from;
2643 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2645 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2647 for (my $i = $from; $i <= $to; $i++) {
2648 my $commit = $revlist->[$i];
2649 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2650 my $ref = format_ref_marker
($refs, $commit);
2651 my %co = parse_commit
($commit);
2653 print "<tr class=\"dark\">\n";
2655 print "<tr class=\"light\">\n";
2658 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2659 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2660 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2662 print format_subject_html
($co{'title'}, $co{'title_short'},
2663 href
(action
=>"commit", hash
=>$commit), $ref);
2665 "<td class=\"link\">" .
2666 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
2667 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2668 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2669 if ($have_snapshot) {
2670 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2675 if (defined $extra) {
2677 "<td colspan=\"4\">$extra</td>\n" .
2683 sub git_history_body
{
2684 # Warning: assumes constant type (blob or tree) during history
2685 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2687 $from = 0 unless defined $from;
2688 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2690 print "<table class=\"history\" cellspacing=\"0\">\n";
2692 for (my $i = $from; $i <= $to; $i++) {
2693 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2698 my %co = parse_commit
($commit);
2703 my $ref = format_ref_marker
($refs, $commit);
2706 print "<tr class=\"dark\">\n";
2708 print "<tr class=\"light\">\n";
2711 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2712 # shortlog uses chop_str($co{'author_name'}, 10)
2713 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2715 # originally git_history used chop_str($co{'title'}, 50)
2716 print format_subject_html
($co{'title'}, $co{'title_short'},
2717 href
(action
=>"commit", hash
=>$commit), $ref);
2719 "<td class=\"link\">" .
2720 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2721 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2723 if ($ftype eq 'blob') {
2724 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2725 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2726 if (defined $blob_current && defined $blob_parent &&
2727 $blob_current ne $blob_parent) {
2729 $cgi->a({-href
=> href
(action
=>"blobdiff",
2730 hash
=>$blob_current, hash_parent
=>$blob_parent,
2731 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2732 file_name
=>$file_name)},
2739 if (defined $extra) {
2741 "<td colspan=\"4\">$extra</td>\n" .
2748 # uses global variable $project
2749 my ($taglist, $from, $to, $extra) = @_;
2750 $from = 0 unless defined $from;
2751 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2753 print "<table class=\"tags\" cellspacing=\"0\">\n";
2755 for (my $i = $from; $i <= $to; $i++) {
2756 my $entry = $taglist->[$i];
2758 my $comment = $tag{'subject'};
2760 if (defined $comment) {
2761 $comment_short = chop_str
($comment, 30, 5);
2764 print "<tr class=\"dark\">\n";
2766 print "<tr class=\"light\">\n";
2769 print "<td><i>$tag{'age'}</i></td>\n" .
2771 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2772 -class => "list name"}, esc_html
($tag{'name'})) .
2775 if (defined $comment) {
2776 print format_subject_html
($comment, $comment_short,
2777 href
(action
=>"tag", hash
=>$tag{'id'}));
2780 "<td class=\"selflink\">";
2781 if ($tag{'type'} eq "tag") {
2782 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2787 "<td class=\"link\">" . " | " .
2788 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2789 if ($tag{'reftype'} eq "commit") {
2790 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2791 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
2792 } elsif ($tag{'reftype'} eq "blob") {
2793 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2798 if (defined $extra) {
2800 "<td colspan=\"5\">$extra</td>\n" .
2806 sub git_heads_body
{
2807 # uses global variable $project
2808 my ($headlist, $head, $from, $to, $extra) = @_;
2809 $from = 0 unless defined $from;
2810 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2812 print "<table class=\"heads\" cellspacing=\"0\">\n";
2814 for (my $i = $from; $i <= $to; $i++) {
2815 my $entry = $headlist->[$i];
2817 my $curr = $ref{'id'} eq $head;
2819 print "<tr class=\"dark\">\n";
2821 print "<tr class=\"light\">\n";
2824 print "<td><i>$ref{'age'}</i></td>\n" .
2825 ($curr ? "<td class=\"current_head\">" : "<td>") .
2826 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
2827 -class => "list name"},esc_html
($ref{'name'})) .
2829 "<td class=\"link\">" .
2830 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
2831 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
2832 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
2836 if (defined $extra) {
2838 "<td colspan=\"3\">$extra</td>\n" .
2844 ## ======================================================================
2845 ## ======================================================================
2848 sub git_project_list
{
2849 my $order = $cgi->param('o');
2850 if (defined $order && $order !~ m/project|descr|owner|age/) {
2851 die_error
(undef, "Unknown order parameter");
2854 my @list = git_get_projects_list
();
2856 die_error
(undef, "No projects found");
2860 if (-f
$home_text) {
2861 print "<div class=\"index_include\">\n";
2862 open (my $fd, $home_text);
2867 git_project_list_body
(\
@list, $order);
2872 my $order = $cgi->param('o');
2873 if (defined $order && $order !~ m/project|descr|owner|age/) {
2874 die_error
(undef, "Unknown order parameter");
2877 my @list = git_get_projects_list
($project);
2879 die_error
(undef, "No forks found");
2883 git_print_page_nav
('','');
2884 git_print_header_div
('summary', "$project forks");
2885 git_project_list_body
(\
@list, $order);
2889 sub git_project_index
{
2890 my @projects = git_get_projects_list
($project);
2893 -type
=> 'text/plain',
2894 -charset
=> 'utf-8',
2895 -content_disposition
=> 'inline; filename="index.aux"');
2897 foreach my $pr (@projects) {
2898 if (!exists $pr->{'owner'}) {
2899 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2902 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2903 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2904 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2905 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2909 print "$path $owner\n";
2914 my $descr = git_get_project_description
($project) || "none";
2915 my $head = git_get_head_hash
($project);
2916 my %co = parse_commit
($head);
2917 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2919 my $owner = git_get_project_owner
($project);
2921 my $refs = git_get_references
();
2922 # These get_*_list functions return one more to allow us to see if
2923 # there are more ...
2924 my @taglist = git_get_tags_list
(16);
2925 my @headlist = git_get_heads_list
(16);
2927 my ($check_forks) = gitweb_check_feature
('forks');
2930 @forklist = git_get_projects_list
($project);
2934 git_print_page_nav
('summary','', $head);
2936 print "<div class=\"title\"> </div>\n";
2937 print "<table cellspacing=\"0\">\n" .
2938 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2939 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2940 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2941 # use per project git URL list in $projectroot/$project/cloneurl
2942 # or make project git URL from git base URL and project name
2943 my $url_tag = "URL";
2944 my @url_list = git_get_project_url_list
($project);
2945 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2946 foreach my $git_url (@url_list) {
2947 next unless $git_url;
2948 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2953 if (-s
"$projectroot/$project/README.html") {
2954 if (open my $fd, "$projectroot/$project/README.html") {
2955 print "<div class=\"title\">readme</div>\n";
2956 print $_ while (<$fd>);
2961 # we need to request one more than 16 (0..15) to check if
2963 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2964 git_get_head_hash
($project), "--"
2965 or die_error
(undef, "Open git-rev-list failed");
2966 my @revlist = map { chomp; $_ } <$fd>;
2968 git_print_header_div
('shortlog');
2969 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2970 $#revlist <= 15 ? undef :
2971 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2974 git_print_header_div
('tags');
2975 git_tags_body
(\
@taglist, 0, 15,
2976 $#taglist <= 15 ? undef :
2977 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2981 git_print_header_div
('heads');
2982 git_heads_body
(\
@headlist, $head, 0, 15,
2983 $#headlist <= 15 ? undef :
2984 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2988 git_print_header_div
('forks');
2989 git_project_list_body
(\
@forklist, undef, 0, 15,
2990 $#forklist <= 15 ? undef :
2991 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
2999 my $head = git_get_head_hash
($project);
3001 git_print_page_nav
('','', $head,undef,$head);
3002 my %tag = parse_tag
($hash);
3003 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3004 print "<div class=\"title_text\">\n" .
3005 "<table cellspacing=\"0\">\n" .
3007 "<td>object</td>\n" .
3008 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3009 $tag{'object'}) . "</td>\n" .
3010 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3011 $tag{'type'}) . "</td>\n" .
3013 if (defined($tag{'author'})) {
3014 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3015 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3016 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3017 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3020 print "</table>\n\n" .
3022 print "<div class=\"page_body\">";
3023 my $comment = $tag{'comment'};
3024 foreach my $line (@$comment) {
3026 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3036 my ($have_blame) = gitweb_check_feature
('blame');
3038 die_error
('403 Permission denied', "Permission denied");
3040 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3041 $hash_base ||= git_get_head_hash
($project);
3042 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3043 my %co = parse_commit
($hash_base)
3044 or die_error
(undef, "Reading commit failed");
3045 if (!defined $hash) {
3046 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3047 or die_error
(undef, "Error looking up file");
3049 $ftype = git_get_type
($hash);
3050 if ($ftype !~ "blob") {
3051 die_error
("400 Bad Request", "Object is not a blob");
3053 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3054 $file_name, $hash_base)
3055 or die_error
(undef, "Open git-blame failed");
3058 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3061 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3064 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3066 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3067 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3068 git_print_page_path
($file_name, $ftype, $hash_base);
3069 my @rev_color = (qw(light2 dark2));
3070 my $num_colors = scalar(@rev_color);
3071 my $current_color = 0;
3074 <div class="page_body">
3075 <table class="blame">
3076 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3081 last unless defined $_;
3082 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3083 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3084 if (!exists $metainfo{$full_rev}) {
3085 $metainfo{$full_rev} = {};
3087 my $meta = $metainfo{$full_rev};
3090 if (/^(\S+) (.*)$/) {
3096 my $rev = substr($full_rev, 0, 8);
3097 my $author = $meta->{'author'};
3098 my %date = parse_date
($meta->{'author-time'},
3099 $meta->{'author-tz'});
3100 my $date = $date{'iso-tz'};
3102 $current_color = ++$current_color % $num_colors;
3104 print "<tr class=\"$rev_color[$current_color]\">\n";
3106 print "<td class=\"sha1\"";
3107 print " title=\"". esc_html
($author) . ", $date\"";
3108 print " rowspan=\"$group_size\"" if ($group_size > 1);
3110 print $cgi->a({-href
=> href
(action
=>"commit",
3112 file_name
=>$file_name)},
3116 my $blamed = href
(action
=> 'blame',
3117 file_name
=> $meta->{'filename'},
3118 hash_base
=> $full_rev);
3119 print "<td class=\"linenr\">";
3120 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3122 -class => "linenr" },
3125 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3131 or print "Reading blob failed\n";
3138 my ($have_blame) = gitweb_check_feature
('blame');
3140 die_error
('403 Permission denied', "Permission denied");
3142 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3143 $hash_base ||= git_get_head_hash
($project);
3144 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3145 my %co = parse_commit
($hash_base)
3146 or die_error
(undef, "Reading commit failed");
3147 if (!defined $hash) {
3148 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3149 or die_error
(undef, "Error lookup file");
3151 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3152 or die_error
(undef, "Open git-annotate failed");
3155 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3158 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3161 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3163 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3164 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3165 git_print_page_path
($file_name, 'blob', $hash_base);
3166 print "<div class=\"page_body\">\n";
3168 <table class="blame">
3177 my @line_class = (qw(light dark));
3178 my $line_class_len = scalar (@line_class);
3179 my $line_class_num = $#line_class;
3180 while (my $line = <$fd>) {
3192 $line_class_num = ($line_class_num + 1) % $line_class_len;
3194 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3201 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3204 $short_rev = substr ($long_rev, 0, 8);
3205 $age = time () - $time;
3206 $age_str = age_string
($age);
3207 $age_str =~ s/ / /g;
3208 $age_class = age_class
($age);
3209 $author = esc_html
($author);
3210 $author =~ s/ / /g;
3212 $data = untabify
($data);
3213 $data = esc_html
($data);
3216 <tr class="$line_class[$line_class_num]">
3217 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3218 <td class="$age_class">$age_str</td>
3220 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3221 <td class="pre">$data</td>
3224 } # while (my $line = <$fd>)
3225 print "</table>\n\n";
3227 or print "Reading blob failed.\n";
3233 my $head = git_get_head_hash
($project);
3235 git_print_page_nav
('','', $head,undef,$head);
3236 git_print_header_div
('summary', $project);
3238 my @tagslist = git_get_tags_list
();
3240 git_tags_body
(\
@tagslist);
3246 my $head = git_get_head_hash
($project);
3248 git_print_page_nav
('','', $head,undef,$head);
3249 git_print_header_div
('summary', $project);
3251 my @headslist = git_get_heads_list
();
3253 git_heads_body
(\
@headslist, $head);
3258 sub git_blob_plain
{
3261 if (!defined $hash) {
3262 if (defined $file_name) {
3263 my $base = $hash_base || git_get_head_hash
($project);
3264 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3265 or die_error
(undef, "Error lookup file");
3267 die_error
(undef, "No file name defined");
3269 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3270 # blobs defined by non-textual hash id's can be cached
3275 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3276 or die_error
(undef, "Couldn't cat $file_name, $hash");
3278 $type ||= blob_mimetype
($fd, $file_name);
3280 # save as filename, even when no $file_name is given
3281 my $save_as = "$hash";
3282 if (defined $file_name) {
3283 $save_as = $file_name;
3284 } elsif ($type =~ m/^text\//) {
3291 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3293 binmode STDOUT
, ':raw';
3295 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3303 if (!defined $hash) {
3304 if (defined $file_name) {
3305 my $base = $hash_base || git_get_head_hash
($project);
3306 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3307 or die_error
(undef, "Error lookup file");
3309 die_error
(undef, "No file name defined");
3311 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3312 # blobs defined by non-textual hash id's can be cached
3316 my ($have_blame) = gitweb_check_feature
('blame');
3317 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3318 or die_error
(undef, "Couldn't cat $file_name, $hash");
3319 my $mimetype = blob_mimetype
($fd, $file_name);
3320 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3322 return git_blob_plain
($mimetype);
3324 # we can have blame only for text/* mimetype
3325 $have_blame &&= ($mimetype =~ m!^text/!);
3327 git_header_html
(undef, $expires);
3328 my $formats_nav = '';
3329 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3330 if (defined $file_name) {
3333 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3334 hash
=>$hash, file_name
=>$file_name)},
3339 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3340 hash
=>$hash, file_name
=>$file_name)},
3343 $cgi->a({-href
=> href
(action
=>"blob_plain",
3344 hash
=>$hash, file_name
=>$file_name)},
3347 $cgi->a({-href
=> href
(action
=>"blob",
3348 hash_base
=>"HEAD", file_name
=>$file_name)},
3352 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3354 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3355 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3357 print "<div class=\"page_nav\">\n" .
3358 "<br/><br/></div>\n" .
3359 "<div class=\"title\">$hash</div>\n";
3361 git_print_page_path
($file_name, "blob", $hash_base);
3362 print "<div class=\"page_body\">\n";
3363 if ($mimetype =~ m!^text/!) {
3365 while (my $line = <$fd>) {
3368 $line = untabify
($line);
3369 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3370 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3372 } elsif ($mimetype =~ m!^image/!) {
3373 print qq
!<img type
="$mimetype"!;
3375 print qq
! alt
="$file_name" title
="$file_name"!;
3378 href(action=>"blob_plain
", hash=>$hash,
3379 hash_base=>$hash_base, file_name=>$file_name) .
3383 or print "Reading blob failed.\n";
3389 my $have_snapshot = gitweb_have_snapshot
();
3391 if (!defined $hash_base) {
3392 $hash_base = "HEAD";
3394 if (!defined $hash) {
3395 if (defined $file_name) {
3396 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3402 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3403 or die_error
(undef, "Open git-ls-tree failed");
3404 my @entries = map { chomp; $_ } <$fd>;
3405 close $fd or die_error
(undef, "Reading tree failed");
3408 my $refs = git_get_references
();
3409 my $ref = format_ref_marker
($refs, $hash_base);
3412 my ($have_blame) = gitweb_check_feature
('blame');
3413 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3415 if (defined $file_name) {
3417 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3418 hash
=>$hash, file_name
=>$file_name)},
3420 $cgi->a({-href
=> href
(action
=>"tree",
3421 hash_base
=>"HEAD", file_name
=>$file_name)},
3424 if ($have_snapshot) {
3425 # FIXME: Should be available when we have no hash base as well.
3427 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3430 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3431 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3434 print "<div class=\"page_nav\">\n";
3435 print "<br/><br/></div>\n";
3436 print "<div class=\"title\">$hash</div>\n";
3438 if (defined $file_name) {
3439 $basedir = $file_name;
3440 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3444 git_print_page_path
($file_name, 'tree', $hash_base);
3445 print "<div class=\"page_body\">\n";
3446 print "<table cellspacing=\"0\">\n";
3448 # '..' (top directory) link if possible
3449 if (defined $hash_base &&
3450 defined $file_name && $file_name =~ m![^/]+$!) {
3452 print "<tr class=\"dark\">\n";
3454 print "<tr class=\"light\">\n";
3458 my $up = $file_name;
3459 $up =~ s!/?[^/]+$!!;
3460 undef $up unless $up;
3461 # based on git_print_tree_entry
3462 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3463 print '<td class="list">';
3464 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3468 print "<td class=\"link\"></td>\n";
3472 foreach my $line (@entries) {
3473 my %t = parse_ls_tree_line
($line, -z
=> 1);
3476 print "<tr class=\"dark\">\n";
3478 print "<tr class=\"light\">\n";
3482 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3486 print "</table>\n" .
3492 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3493 my $have_snapshot = (defined $ctype && defined $suffix);
3494 if (!$have_snapshot) {
3495 die_error
('403 Permission denied', "Permission denied");
3498 if (!defined $hash) {
3499 $hash = git_get_head_hash
($project);
3502 my $filename = basename
($project) . "-$hash.tar.$suffix";
3505 -type
=> "application/$ctype",
3506 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3507 -status
=> '200 OK');
3509 my $git = git_cmd_str
();
3510 my $name = $project;
3511 $name =~ s/\047/\047\\\047\047/g;
3513 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3514 or die_error
(undef, "Execute git-tar-tree failed.");
3515 binmode STDOUT
, ':raw';
3517 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3523 my $head = git_get_head_hash
($project);
3524 if (!defined $hash) {
3527 if (!defined $page) {
3530 my $refs = git_get_references
();
3532 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3533 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash, "--"
3534 or die_error
(undef, "Open git-rev-list failed");
3535 my @revlist = map { chomp; $_ } <$fd>;
3538 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
3541 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3544 my %co = parse_commit
($hash);
3546 git_print_header_div
('summary', $project);
3547 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3549 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
3550 my $commit = $revlist[$i];
3551 my $ref = format_ref_marker
($refs, $commit);
3552 my %co = parse_commit
($commit);
3554 my %ad = parse_date
($co{'author_epoch'});
3555 git_print_header_div
('commit',
3556 "<span class=\"age\">$co{'age_string'}</span>" .
3557 esc_html
($co{'title'}) . $ref,
3559 print "<div class=\"title_text\">\n" .
3560 "<div class=\"log_link\">\n" .
3561 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3563 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3565 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3568 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3571 print "<div class=\"log_body\">\n";
3572 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
3579 $hash ||= $hash_base || "HEAD";
3580 my %co = parse_commit
($hash);
3582 die_error
(undef, "Unknown commit object");
3584 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3585 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3587 my $parent = $co{'parent'};
3588 my $parents = $co{'parents'}; # listref
3590 # we need to prepare $formats_nav before any parameter munging
3592 if (!defined $parent) {
3594 $formats_nav .= '(initial)';
3595 } elsif (@$parents == 1) {
3596 # single parent commit
3599 $cgi->a({-href
=> href
(action
=>"commit",
3601 esc_html
(substr($parent, 0, 7))) .
3608 $cgi->a({-href
=> href
(action
=>"commitdiff",
3610 esc_html
(substr($_, 0, 7)));
3615 if (!defined $parent) {
3619 if (@$parents <= 1) {
3620 # difftree output is not printed for merges
3621 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
3622 @diff_opts, $parent, $hash, "--"
3623 or die_error
(undef, "Open git-diff-tree failed");
3624 @difftree = map { chomp; $_ } <$fd>;
3625 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3628 # non-textual hash id's can be cached
3630 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3633 my $refs = git_get_references
();
3634 my $ref = format_ref_marker
($refs, $co{'id'});
3636 my $have_snapshot = gitweb_have_snapshot
();
3638 git_header_html
(undef, $expires);
3639 git_print_page_nav
('commit', '',
3640 $hash, $co{'tree'}, $hash,
3643 if (defined $co{'parent'}) {
3644 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3646 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3648 print "<div class=\"title_text\">\n" .
3649 "<table cellspacing=\"0\">\n";
3650 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3652 "<td></td><td> $ad{'rfc2822'}";
3653 if ($ad{'hour_local'} < 6) {
3654 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3655 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3657 printf(" (%02d:%02d %s)",
3658 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3662 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3663 print "<tr><td></td><td> $cd{'rfc2822'}" .
3664 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3666 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3669 "<td class=\"sha1\">" .
3670 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3671 class => "list"}, $co{'tree'}) .
3673 "<td class=\"link\">" .
3674 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3676 if ($have_snapshot) {
3678 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3683 foreach my $par (@$parents) {
3686 "<td class=\"sha1\">" .
3687 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3688 class => "list"}, $par) .
3690 "<td class=\"link\">" .
3691 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3693 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3700 print "<div class=\"page_body\">\n";
3701 git_print_log
($co{'comment'});
3704 if (@$parents <= 1) {
3705 # do not output difftree/whatchanged for merges
3706 git_difftree_body
(\
@difftree, $hash, $parent);
3713 # object is defined by:
3714 # - hash or hash_base alone
3715 # - hash_base and file_name
3718 # - hash or hash_base alone
3719 if ($hash || ($hash_base && !defined $file_name)) {
3720 my $object_id = $hash || $hash_base;
3722 my $git_command = git_cmd_str
();
3723 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
3724 or die_error
('404 Not Found', "Object does not exist");
3728 or die_error
('404 Not Found', "Object does not exist");
3730 # - hash_base and file_name
3731 } elsif ($hash_base && defined $file_name) {
3732 $file_name =~ s
,/+$,,;
3734 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
3735 or die_error
('404 Not Found', "Base object does not exist");
3737 # here errors should not hapen
3738 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
3739 or die_error
(undef, "Open git-ls-tree failed");
3743 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
3744 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
3745 die_error
('404 Not Found', "File or directory for given base does not exist");
3750 die_error
('404 Not Found', "Not enough information to find object");
3753 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
3754 hash
=>$hash, hash_base
=>$hash_base,
3755 file_name
=>$file_name),
3756 -status
=> '302 Found');
3760 my $format = shift || 'html';
3767 # preparing $fd and %diffinfo for git_patchset_body
3769 if (defined $hash_base && defined $hash_parent_base) {
3770 if (defined $file_name) {
3772 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3773 $hash_parent_base, $hash_base,
3775 or die_error
(undef, "Open git-diff-tree failed");
3776 @difftree = map { chomp; $_ } <$fd>;
3778 or die_error
(undef, "Reading git-diff-tree failed");
3780 or die_error
('404 Not Found', "Blob diff not found");
3782 } elsif (defined $hash &&
3783 $hash =~ /[0-9a-fA-F]{40}/) {
3784 # try to find filename from $hash
3786 # read filtered raw output
3787 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3788 $hash_parent_base, $hash_base, "--"
3789 or die_error
(undef, "Open git-diff-tree failed");
3791 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3793 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3794 map { chomp; $_ } <$fd>;
3796 or die_error
(undef, "Reading git-diff-tree failed");
3798 or die_error
('404 Not Found', "Blob diff not found");
3801 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3804 if (@difftree > 1) {
3805 die_error
('404 Not Found', "Ambiguous blob diff specification");
3808 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3809 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3810 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3812 $hash_parent ||= $diffinfo{'from_id'};
3813 $hash ||= $diffinfo{'to_id'};
3815 # non-textual hash id's can be cached
3816 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3817 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3822 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3823 '-p', $hash_parent_base, $hash_base,
3825 or die_error
(undef, "Open git-diff-tree failed");
3828 # old/legacy style URI
3829 if (!%diffinfo && # if new style URI failed
3830 defined $hash && defined $hash_parent) {
3831 # fake git-diff-tree raw output
3832 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3833 $diffinfo{'from_id'} = $hash_parent;
3834 $diffinfo{'to_id'} = $hash;
3835 if (defined $file_name) {
3836 if (defined $file_parent) {
3837 $diffinfo{'status'} = '2';
3838 $diffinfo{'from_file'} = $file_parent;
3839 $diffinfo{'to_file'} = $file_name;
3840 } else { # assume not renamed
3841 $diffinfo{'status'} = '1';
3842 $diffinfo{'from_file'} = $file_name;
3843 $diffinfo{'to_file'} = $file_name;
3845 } else { # no filename given
3846 $diffinfo{'status'} = '2';
3847 $diffinfo{'from_file'} = $hash_parent;
3848 $diffinfo{'to_file'} = $hash;
3851 # non-textual hash id's can be cached
3852 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3853 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3858 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts,
3859 $hash_parent, $hash, "--"
3860 or die_error
(undef, "Open git-diff failed");
3862 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3867 if ($format eq 'html') {
3869 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3870 hash
=>$hash, hash_parent
=>$hash_parent,
3871 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3872 file_name
=>$file_name, file_parent
=>$file_parent)},
3874 git_header_html
(undef, $expires);
3875 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3876 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3877 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3879 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3880 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3882 if (defined $file_name) {
3883 git_print_page_path
($file_name, "blob", $hash_base);
3885 print "<div class=\"page_path\"></div>\n";
3888 } elsif ($format eq 'plain') {
3890 -type
=> 'text/plain',
3891 -charset
=> 'utf-8',
3892 -expires
=> $expires,
3893 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3895 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3898 die_error
(undef, "Unknown blobdiff format");
3902 if ($format eq 'html') {
3903 print "<div class=\"page_body\">\n";
3905 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3908 print "</div>\n"; # class="page_body"
3912 while (my $line = <$fd>) {
3913 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
3914 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
3918 last if $line =~ m!^\+\+\+!;
3926 sub git_blobdiff_plain
{
3927 git_blobdiff
('plain');
3930 sub git_commitdiff
{
3931 my $format = shift || 'html';
3932 $hash ||= $hash_base || "HEAD";
3933 my %co = parse_commit
($hash);
3935 die_error
(undef, "Unknown commit object");
3938 # we need to prepare $formats_nav before any parameter munging
3940 if ($format eq 'html') {
3942 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3943 hash
=>$hash, hash_parent
=>$hash_parent)},
3946 if (defined $hash_parent) {
3947 # commitdiff with two commits given
3948 my $hash_parent_short = $hash_parent;
3949 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3950 $hash_parent_short = substr($hash_parent, 0, 7);
3954 $cgi->a({-href
=> href
(action
=>"commitdiff",
3955 hash
=>$hash_parent)},
3956 esc_html
($hash_parent_short)) .
3958 } elsif (!$co{'parent'}) {
3960 $formats_nav .= ' (initial)';
3961 } elsif (scalar @{$co{'parents'}} == 1) {
3962 # single parent commit
3965 $cgi->a({-href
=> href
(action
=>"commitdiff",
3966 hash
=>$co{'parent'})},
3967 esc_html
(substr($co{'parent'}, 0, 7))) .
3974 $cgi->a({-href
=> href
(action
=>"commitdiff",
3976 esc_html
(substr($_, 0, 7)));
3977 } @{$co{'parents'}} ) .
3982 if (!defined $hash_parent) {
3983 $hash_parent = $co{'parent'} || '--root';
3989 if ($format eq 'html') {
3990 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3991 "--no-commit-id", "--patch-with-raw", "--full-index",
3992 $hash_parent, $hash, "--"
3993 or die_error
(undef, "Open git-diff-tree failed");
3995 while (my $line = <$fd>) {
3997 # empty line ends raw part of diff-tree output
3999 push @difftree, $line;
4002 } elsif ($format eq 'plain') {
4003 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4004 '-p', $hash_parent, $hash, "--"
4005 or die_error
(undef, "Open git-diff-tree failed");
4008 die_error
(undef, "Unknown commitdiff format");
4011 # non-textual hash id's can be cached
4013 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4017 # write commit message
4018 if ($format eq 'html') {
4019 my $refs = git_get_references
();
4020 my $ref = format_ref_marker
($refs, $co{'id'});
4022 git_header_html
(undef, $expires);
4023 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4024 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4025 git_print_authorship
(\
%co);
4026 print "<div class=\"page_body\">\n";
4027 if (@{$co{'comment'}} > 1) {
4028 print "<div class=\"log\">\n";
4029 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4030 print "</div>\n"; # class="log"
4033 } elsif ($format eq 'plain') {
4034 my $refs = git_get_references
("tags");
4035 my $tagname = git_get_rev_name_tags
($hash);
4036 my $filename = basename
($project) . "-$hash.patch";
4039 -type
=> 'text/plain',
4040 -charset
=> 'utf-8',
4041 -expires
=> $expires,
4042 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4043 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4046 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4047 Subject: $co{'title'}
4049 print "X-Git-Tag: $tagname\n" if $tagname;
4050 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4052 foreach my $line (@{$co{'comment'}}) {
4059 if ($format eq 'html') {
4060 git_difftree_body
(\
@difftree, $hash, $hash_parent);
4063 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
4065 print "</div>\n"; # class="page_body"
4068 } elsif ($format eq 'plain') {
4072 or print "Reading git-diff-tree failed\n";
4076 sub git_commitdiff_plain
{
4077 git_commitdiff
('plain');
4081 if (!defined $hash_base) {
4082 $hash_base = git_get_head_hash
($project);
4084 if (!defined $page) {
4088 my %co = parse_commit
($hash_base);
4090 die_error
(undef, "Unknown commit object");
4093 my $refs = git_get_references
();
4094 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4096 if (!defined $hash && defined $file_name) {
4097 $hash = git_get_hash_by_path
($hash_base, $file_name);
4099 if (defined $hash) {
4100 $ftype = git_get_type
($hash);
4104 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
4105 or die_error
(undef, "Open git-rev-list-failed");
4106 my @revlist = map { chomp; $_ } <$fd>;
4108 or die_error
(undef, "Reading git-rev-list failed");
4110 my $paging_nav = '';
4113 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4114 file_name
=>$file_name)},
4116 $paging_nav .= " ⋅ " .
4117 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4118 file_name
=>$file_name, page
=>$page-1),
4119 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4121 $paging_nav .= "first";
4122 $paging_nav .= " ⋅ prev";
4124 if ($#revlist >= (100 * ($page+1)-1)) {
4125 $paging_nav .= " ⋅ " .
4126 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4127 file_name
=>$file_name, page
=>$page+1),
4128 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4130 $paging_nav .= " ⋅ next";
4133 if ($#revlist >= (100 * ($page+1)-1)) {
4135 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4136 file_name
=>$file_name, page
=>$page+1),
4137 -title
=> "Alt-n"}, "next");
4141 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4142 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4143 git_print_page_path
($file_name, $ftype, $hash_base);
4145 git_history_body
(\
@revlist, ($page * 100), $#revlist,
4146 $refs, $hash_base, $ftype, $next_link);
4152 if (!defined $searchtext) {
4153 die_error
(undef, "Text field empty");
4155 if (!defined $hash) {
4156 $hash = git_get_head_hash
($project);
4158 my %co = parse_commit
($hash);
4160 die_error
(undef, "Unknown commit object");
4163 $searchtype ||= 'commit';
4164 if ($searchtype eq 'pickaxe') {
4165 # pickaxe may take all resources of your box and run for several minutes
4166 # with every query - so decide by yourself how public you make this feature
4167 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4168 if (!$have_pickaxe) {
4169 die_error
('403 Permission denied', "Permission denied");
4174 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4175 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4177 print "<table cellspacing=\"0\">\n";
4179 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4181 open my $fd, "-|", git_cmd
(), "rev-list",
4182 "--header", "--parents", $hash, "--"
4184 while (my $commit_text = <$fd>) {
4185 if (!grep m/$searchtext/i, $commit_text) {
4188 if ($searchtype eq 'author' && !grep m/\nauthor .*$searchtext/i, $commit_text) {
4191 if ($searchtype eq 'committer' && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
4194 my @commit_lines = split "\n", $commit_text;
4195 my %co = parse_commit
(undef, \
@commit_lines);
4200 print "<tr class=\"dark\">\n";
4202 print "<tr class=\"light\">\n";
4205 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4206 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4208 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
4209 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4210 my $comment = $co{'comment'};
4211 foreach my $line (@$comment) {
4212 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
4213 my $lead = esc_html
($1) || "";
4214 $lead = chop_str
($lead, 30, 10);
4215 my $match = esc_html
($2) || "";
4216 my $trail = esc_html
($3) || "";
4217 $trail = chop_str
($trail, 30, 10);
4218 my $text = "$lead<span class=\"match\">$match</span>$trail";
4219 print chop_str
($text, 80, 5) . "<br/>\n";
4223 "<td class=\"link\">" .
4224 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4226 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4233 if ($searchtype eq 'pickaxe') {
4235 my $git_command = git_cmd_str
();
4236 open my $fd, "-|", "$git_command rev-list $hash | " .
4237 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
4240 while (my $line = <$fd>) {
4241 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4244 $set{'from_id'} = $3;
4246 $set{'id'} = $set{'to_id'};
4247 if ($set{'id'} =~ m/0{40}/) {
4248 $set{'id'} = $set{'from_id'};
4250 if ($set{'id'} =~ m/0{40}/) {
4254 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4257 print "<tr class=\"dark\">\n";
4259 print "<tr class=\"light\">\n";
4262 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4263 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4265 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4266 -class => "list subject"},
4267 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4268 while (my $setref = shift @files) {
4270 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4271 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4273 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4277 "<td class=\"link\">" .
4278 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4280 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4284 %co = parse_commit
($1);
4293 sub git_search_help
{
4295 git_print_page_nav
('','', $hash,$hash,$hash);
4298 <dt><b>commit</b></dt>
4299 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4300 <dt><b>author</b></dt>
4301 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4302 <dt><b>committer</b></dt>
4303 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4305 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4306 if ($have_pickaxe) {
4308 <dt><b>pickaxe</b></dt>
4309 <dd>All commits that caused the string to appear or disappear from any file (changes that
4310 added, removed or "modified" the string) will be listed. This search can take a while and
4311 takes a lot of strain on the server, so please use it wisely.</dd>
4319 my $head = git_get_head_hash
($project);
4320 if (!defined $hash) {
4323 if (!defined $page) {
4326 my $refs = git_get_references
();
4328 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4329 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash, "--"
4330 or die_error
(undef, "Open git-rev-list failed");
4331 my @revlist = map { chomp; $_ } <$fd>;
4334 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
4336 if ($#revlist >= (100 * ($page+1)-1)) {
4338 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4339 -title
=> "Alt-n"}, "next");
4344 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4345 git_print_header_div
('summary', $project);
4347 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
4352 ## ......................................................................
4353 ## feeds (RSS, Atom; OPML)
4356 my $format = shift || 'atom';
4357 my ($have_blame) = gitweb_check_feature
('blame');
4359 # Atom: http://www.atomenabled.org/developers/syndication/
4360 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4361 if ($format ne 'rss' && $format ne 'atom') {
4362 die_error
(undef, "Unknown web feed format");
4365 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4366 my $head = $hash || 'HEAD';
4367 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150",
4368 $head, "--", (defined $file_name ? $file_name : ())
4369 or die_error
(undef, "Open git-rev-list failed");
4370 my @revlist = map { chomp; $_ } <$fd>;
4371 close $fd or die_error
(undef, "Reading git-rev-list failed");
4375 my $content_type = "application/$format+xml";
4376 if (defined $cgi->http('HTTP_ACCEPT') &&
4377 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4378 # browser (feed reader) prefers text/xml
4379 $content_type = 'text/xml';
4381 if (defined($revlist[0])) {
4382 %latest_commit = parse_commit
($revlist[0]);
4383 %latest_date = parse_date
($latest_commit{'author_epoch'});
4385 -type
=> $content_type,
4386 -charset
=> 'utf-8',
4387 -last_modified
=> $latest_date{'rfc2822'});
4390 -type
=> $content_type,
4391 -charset
=> 'utf-8');
4394 # Optimization: skip generating the body if client asks only
4395 # for Last-Modified date.
4396 return if ($cgi->request_method() eq 'HEAD');
4399 my $title = "$site_name - $project/$action";
4400 my $feed_type = 'log';
4401 if (defined $hash) {
4402 $title .= " - '$hash'";
4403 $feed_type = 'branch log';
4404 if (defined $file_name) {
4405 $title .= " :: $file_name";
4406 $feed_type = 'history';
4408 } elsif (defined $file_name) {
4409 $title .= " - $file_name";
4410 $feed_type = 'history';
4412 $title .= " $feed_type";
4413 my $descr = git_get_project_description
($project);
4414 if (defined $descr) {
4415 $descr = esc_html
($descr);
4417 $descr = "$project " .
4418 ($format eq 'rss' ? 'RSS' : 'Atom') .
4421 my $owner = git_get_project_owner
($project);
4422 $owner = esc_html
($owner);
4426 if (defined $file_name) {
4427 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
4428 } elsif (defined $hash) {
4429 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
4431 $alt_url = href
(-full
=>1, action
=>"summary");
4433 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
4434 if ($format eq 'rss') {
4436 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
4439 print "<title>$title</title>\n" .
4440 "<link>$alt_url</link>\n" .
4441 "<description>$descr</description>\n" .
4442 "<language>en</language>\n";
4443 } elsif ($format eq 'atom') {
4445 <feed xmlns="http://www.w3.org/2005/Atom">
4447 print "<title>$title</title>\n" .
4448 "<subtitle>$descr</subtitle>\n" .
4449 '<link rel="alternate" type="text/html" href="' .
4450 $alt_url . '" />' . "\n" .
4451 '<link rel="self" type="' . $content_type . '" href="' .
4452 $cgi->self_url() . '" />' . "\n" .
4453 "<id>" . href
(-full
=>1) . "</id>\n" .
4454 # use project owner for feed author
4455 "<author><name>$owner</name></author>\n";
4456 if (defined $favicon) {
4457 print "<icon>" . esc_url
($favicon) . "</icon>\n";
4459 if (defined $logo_url) {
4460 # not twice as wide as tall: 72 x 27 pixels
4461 print "<logo>" . esc_url
($logo) . "</logo>\n";
4463 if (! %latest_date) {
4464 # dummy date to keep the feed valid until commits trickle in:
4465 print "<updated>1970-01-01T00:00:00Z</updated>\n";
4467 print "<updated>$latest_date{'iso-8601'}</updated>\n";
4472 for (my $i = 0; $i <= $#revlist; $i++) {
4473 my $commit = $revlist[$i];
4474 my %co = parse_commit
($commit);
4475 # we read 150, we always show 30 and the ones more recent than 48 hours
4476 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
4479 my %cd = parse_date
($co{'author_epoch'});
4481 # get list of changed files
4482 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4483 $co{'parent'}, $co{'id'}, "--", (defined $file_name ? $file_name : ())
4485 my @difftree = map { chomp; $_ } <$fd>;
4489 # print element (entry, item)
4490 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
4491 if ($format eq 'rss') {
4493 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
4494 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
4495 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
4496 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
4497 "<link>$co_url</link>\n" .
4498 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
4499 "<content:encoded>" .
4501 } elsif ($format eq 'atom') {
4503 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
4504 "<updated>$cd{'iso-8601'}</updated>\n" .
4506 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
4507 if ($co{'author_email'}) {
4508 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
4510 print "</author>\n" .
4511 # use committer for contributor
4513 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
4514 if ($co{'committer_email'}) {
4515 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
4517 print "</contributor>\n" .
4518 "<published>$cd{'iso-8601'}</published>\n" .
4519 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
4520 "<id>$co_url</id>\n" .
4521 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
4522 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
4524 my $comment = $co{'comment'};
4526 foreach my $line (@$comment) {
4527 $line = esc_html
($line);
4530 print "</pre><ul>\n";
4531 foreach my $difftree_line (@difftree) {
4532 my %difftree = parse_difftree_raw_line
($difftree_line);
4533 next if !$difftree{'from_id'};
4535 my $file = $difftree{'file'} || $difftree{'to_file'};
4539 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
4540 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
4541 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
4542 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
4543 -title
=> "diff"}, 'D');
4545 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
4546 file_name
=>$file, hash_base
=>$commit),
4547 -title
=> "blame"}, 'B');
4549 # if this is not a feed of a file history
4550 if (!defined $file_name || $file_name ne $file) {
4551 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
4552 file_name
=>$file, hash
=>$commit),
4553 -title
=> "history"}, 'H');
4555 $file = esc_path
($file);
4559 if ($format eq 'rss') {
4560 print "</ul>]]>\n" .
4561 "</content:encoded>\n" .
4563 } elsif ($format eq 'atom') {
4564 print "</ul>\n</div>\n" .
4571 if ($format eq 'rss') {
4572 print "</channel>\n</rss>\n";
4573 } elsif ($format eq 'atom') {
4587 my @list = git_get_projects_list
();
4589 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
4591 <?xml version="1.0" encoding="utf-8"?>
4592 <opml version="1.0">
4594 <title>$site_name OPML Export</title>
4597 <outline text="git RSS feeds">
4600 foreach my $pr (@list) {
4602 my $head = git_get_head_hash
($proj{'path'});
4603 if (!defined $head) {
4606 $git_dir = "$projectroot/$proj{'path'}";
4607 my %co = parse_commit
($head);
4612 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
4613 my $rss = "$my_url?p=$proj{'path'};a=rss";
4614 my $html = "$my_url?p=$proj{'path'};a=summary";
4615 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";