3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI-
>compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # core git executable to use
31 # this can just be "git" if your webserver has a sensible PATH
32 our $GIT = "++GIT_BINDIR++/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "++GITWEB_PROJECTROOT++";
38 # target of the home link on top of all pages
39 our $home_link = $my_uri || "/";
41 # string of the home link on top of all pages
42 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
44 # name of your site or organization to appear in page titles
45 # replace this with something more descriptive for clearer bookmarks
46 our $site_name = "++GITWEB_SITENAME++"
47 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
49 # filename of html text to include at top of each page
50 our $site_header = "++GITWEB_SITE_HEADER++";
51 # html text to include at home page
52 our $home_text = "++GITWEB_HOMETEXT++";
53 # filename of html text to include at bottom of each page
54 our $site_footer = "++GITWEB_SITE_FOOTER++";
57 our @stylesheets = ("++GITWEB_CSS++");
58 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
59 our $stylesheet = undef;
61 # URI of GIT logo (72x27 size)
62 our $logo = "++GITWEB_LOGO++";
63 # URI of GIT favicon, assumed to be image/png type
64 our $favicon = "++GITWEB_FAVICON++";
66 # URI and label (title) of GIT logo link
67 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
68 #our $logo_label = "git documentation";
69 our $logo_url = "http://git.or.cz/";
70 our $logo_label = "git homepage";
72 # source of projects list
73 our $projects_list = "++GITWEB_LIST++";
75 # default order of projects list
76 # valid values are none, project, descr, owner, and age
77 our $default_projects_order = "project";
79 # show repository only if this file exists
80 # (only effective if this variable evaluates to true)
81 our $export_ok = "++GITWEB_EXPORT_OK++";
83 # only allow viewing of repositories also shown on the overview page
84 our $strict_export = "++GITWEB_STRICT_EXPORT++";
86 # list of git base URLs used for URL to where fetch project from,
87 # i.e. full URL is "$git_base_url/$project"
88 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
90 # default blob_plain mimetype and default charset for text/plain blob
91 our $default_blob_plain_mimetype = 'text/plain';
92 our $default_text_plain_charset = undef;
94 # file to use for guessing MIME types before trying /etc/mime.types
95 # (relative to the current git repository)
96 our $mimetypes_file = undef;
98 # You define site-wide feature defaults here; override them with
99 # $GITWEB_CONFIG as necessary.
102 # 'sub' => feature-sub (subroutine),
103 # 'override' => allow-override (boolean),
104 # 'default' => [ default options...] (array reference)}
106 # if feature is overridable (it means that allow-override has true value,
107 # then feature-sub will be called with default options as parameters;
108 # return value of feature-sub indicates if to enable specified feature
110 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
112 # Enable the 'blame' blob view, showing the last commit that modified
113 # each line in the file. This can be very CPU-intensive.
115 # To enable system wide have in $GITWEB_CONFIG
116 # $feature{'blame'}{'default'} = [1];
117 # To have project specific config enable override in $GITWEB_CONFIG
118 # $feature{'blame'}{'override'} = 1;
119 # and in project config gitweb.blame = 0|1;
121 'sub' => \
&feature_blame
,
125 # Enable the 'snapshot' link, providing a compressed tarball of any
126 # tree. This can potentially generate high traffic if you have large
129 # To disable system wide have in $GITWEB_CONFIG
130 # $feature{'snapshot'}{'default'} = [undef];
131 # To have project specific config enable override in $GITWEB_CONFIG
132 # $feature{'snapshot'}{'override'} = 1;
133 # and in project config gitweb.snapshot = none|gzip|bzip2;
135 'sub' => \
&feature_snapshot
,
137 # => [content-encoding, suffix, program]
138 'default' => ['x-gzip', 'gz', 'gzip']},
140 # Enable text search, which will list the commits which match author,
141 # committer or commit text to a given string. Enabled by default.
146 # Enable the pickaxe search, which will list the commits that modified
147 # a given string in a file. This can be practical and quite faster
148 # alternative to 'blame', but still potentially CPU-intensive.
150 # To enable system wide have in $GITWEB_CONFIG
151 # $feature{'pickaxe'}{'default'} = [1];
152 # To have project specific config enable override in $GITWEB_CONFIG
153 # $feature{'pickaxe'}{'override'} = 1;
154 # and in project config gitweb.pickaxe = 0|1;
156 'sub' => \
&feature_pickaxe
,
160 # Make gitweb use an alternative format of the URLs which can be
161 # more readable and natural-looking: project name is embedded
162 # directly in the path and the query string contains other
163 # auxiliary information. All gitweb installations recognize
164 # URL in either format; this configures in which formats gitweb
167 # To enable system wide have in $GITWEB_CONFIG
168 # $feature{'pathinfo'}{'default'} = [1];
169 # Project specific override is not supported.
171 # Note that you will need to change the default location of CSS,
172 # favicon, logo and possibly other files to an absolute URL. Also,
173 # if gitweb.cgi serves as your indexfile, you will need to force
174 # $my_uri to contain the script name in your $GITWEB_CONFIG.
179 # Make gitweb consider projects in project root subdirectories
180 # to be forks of existing projects. Given project $projname.git,
181 # projects matching $projname/*.git will not be shown in the main
182 # projects list, instead a '+' mark will be added to $projname
183 # there and a 'forks' view will be enabled for the project, listing
184 # all the forks. If project list is taken from a file, forks have
185 # to be listed after the main project.
187 # To enable system wide have in $GITWEB_CONFIG
188 # $feature{'forks'}{'default'} = [1];
189 # Project specific override is not supported.
195 sub gitweb_check_feature
{
197 return unless exists $feature{$name};
198 my ($sub, $override, @defaults) = (
199 $feature{$name}{'sub'},
200 $feature{$name}{'override'},
201 @{$feature{$name}{'default'}});
202 if (!$override) { return @defaults; }
204 warn "feature $name is not overrideable";
207 return $sub->(@defaults);
211 my ($val) = git_get_project_config
('blame', '--bool');
213 if ($val eq 'true') {
215 } elsif ($val eq 'false') {
222 sub feature_snapshot
{
223 my ($ctype, $suffix, $command) = @_;
225 my ($val) = git_get_project_config
('snapshot');
227 if ($val eq 'gzip') {
228 return ('x-gzip', 'gz', 'gzip');
229 } elsif ($val eq 'bzip2') {
230 return ('x-bzip2', 'bz2', 'bzip2');
231 } elsif ($val eq 'none') {
235 return ($ctype, $suffix, $command);
238 sub gitweb_have_snapshot
{
239 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
240 my $have_snapshot = (defined $ctype && defined $suffix);
242 return $have_snapshot;
245 sub feature_pickaxe
{
246 my ($val) = git_get_project_config
('pickaxe', '--bool');
248 if ($val eq 'true') {
250 } elsif ($val eq 'false') {
257 # checking HEAD file with -e is fragile if the repository was
258 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
260 sub check_head_link
{
262 my $headfile = "$dir/HEAD";
263 return ((-e
$headfile) ||
264 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
267 sub check_export_ok
{
269 return (check_head_link
($dir) &&
270 (!$export_ok || -e
"$dir/$export_ok"));
273 # rename detection options for git-diff and git-diff-tree
274 # - default is '-M', with the cost proportional to
275 # (number of removed files) * (number of new files).
276 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
277 # (number of changed files + number of removed files) * (number of new files)
278 # - even more costly is '-C', '--find-copies-harder' with cost
279 # (number of files in the original tree) * (number of new files)
280 # - one might want to include '-B' option, e.g. '-B', '-M'
281 our @diff_opts = ('-M'); # taken from git_commit
283 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
284 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
286 # version of the core git binary
287 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
289 $projects_list ||= $projectroot;
291 # ======================================================================
292 # input validation and dispatch
293 our $action = $cgi->param('a');
294 if (defined $action) {
295 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
296 die_error
(undef, "Invalid action parameter");
300 # parameters which are pathnames
301 our $project = $cgi->param('p');
302 if (defined $project) {
303 if (!validate_pathname
($project) ||
304 !(-d
"$projectroot/$project") ||
305 !check_head_link
("$projectroot/$project") ||
306 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
307 ($strict_export && !project_in_list
($project))) {
309 die_error
(undef, "No such project");
313 our $file_name = $cgi->param('f');
314 if (defined $file_name) {
315 if (!validate_pathname
($file_name)) {
316 die_error
(undef, "Invalid file parameter");
320 our $file_parent = $cgi->param('fp');
321 if (defined $file_parent) {
322 if (!validate_pathname
($file_parent)) {
323 die_error
(undef, "Invalid file parent parameter");
327 # parameters which are refnames
328 our $hash = $cgi->param('h');
330 if (!validate_refname
($hash)) {
331 die_error
(undef, "Invalid hash parameter");
335 our $hash_parent = $cgi->param('hp');
336 if (defined $hash_parent) {
337 if (!validate_refname
($hash_parent)) {
338 die_error
(undef, "Invalid hash parent parameter");
342 our $hash_base = $cgi->param('hb');
343 if (defined $hash_base) {
344 if (!validate_refname
($hash_base)) {
345 die_error
(undef, "Invalid hash base parameter");
349 our $hash_parent_base = $cgi->param('hpb');
350 if (defined $hash_parent_base) {
351 if (!validate_refname
($hash_parent_base)) {
352 die_error
(undef, "Invalid hash parent base parameter");
357 our $page = $cgi->param('pg');
359 if ($page =~ m/[^0-9]/) {
360 die_error
(undef, "Invalid page parameter");
364 our $searchtext = $cgi->param('s');
365 if (defined $searchtext) {
366 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
367 die_error
(undef, "Invalid search parameter");
369 if (length($searchtext) < 2) {
370 die_error
(undef, "At least two characters are required for search parameter");
372 $searchtext = quotemeta $searchtext;
375 our $searchtype = $cgi->param('st');
376 if (defined $searchtype) {
377 if ($searchtype =~ m/[^a-z]/) {
378 die_error
(undef, "Invalid searchtype parameter");
382 # now read PATH_INFO and use it as alternative to parameters
383 sub evaluate_path_info
{
384 return if defined $project;
385 my $path_info = $ENV{"PATH_INFO"};
386 return if !$path_info;
387 $path_info =~ s
,^/+,,;
388 return if !$path_info;
389 # find which part of PATH_INFO is project
390 $project = $path_info;
392 while ($project && !check_head_link
("$projectroot/$project")) {
393 $project =~ s
,/*[^/]*$,,;
396 $project = validate_pathname
($project);
398 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
399 ($strict_export && !project_in_list
($project))) {
403 # do not change any parameters if an action is given using the query string
405 $path_info =~ s
,^$project/*,,;
406 my ($refname, $pathname) = split(/:/, $path_info, 2);
407 if (defined $pathname) {
408 # we got "project.git/branch:filename" or "project.git/branch:dir/"
409 # we could use git_get_type(branch:pathname), but it needs $git_dir
410 $pathname =~ s
,^/+,,;
411 if (!$pathname || substr($pathname, -1) eq "/") {
415 $action ||= "blob_plain";
417 $hash_base ||= validate_refname
($refname);
418 $file_name ||= validate_pathname
($pathname);
419 } elsif (defined $refname) {
420 # we got "project.git/branch"
421 $action ||= "shortlog";
422 $hash ||= validate_refname
($refname);
425 evaluate_path_info
();
427 # path to the current git repository
429 $git_dir = "$projectroot/$project" if $project;
433 "blame" => \
&git_blame2
,
434 "blobdiff" => \
&git_blobdiff
,
435 "blobdiff_plain" => \
&git_blobdiff_plain
,
436 "blob" => \
&git_blob
,
437 "blob_plain" => \
&git_blob_plain
,
438 "commitdiff" => \
&git_commitdiff
,
439 "commitdiff_plain" => \
&git_commitdiff_plain
,
440 "commit" => \
&git_commit
,
441 "forks" => \
&git_forks
,
442 "heads" => \
&git_heads
,
443 "history" => \
&git_history
,
446 "atom" => \
&git_atom
,
447 "search" => \
&git_search
,
448 "search_help" => \
&git_search_help
,
449 "shortlog" => \
&git_shortlog
,
450 "summary" => \
&git_summary
,
452 "tags" => \
&git_tags
,
453 "tree" => \
&git_tree
,
454 "snapshot" => \
&git_snapshot
,
455 "object" => \
&git_object
,
456 # those below don't need $project
457 "opml" => \
&git_opml
,
458 "project_list" => \
&git_project_list
,
459 "project_index" => \
&git_project_index
,
462 if (defined $project) {
463 $action ||= 'summary';
465 $action ||= 'project_list';
467 if (!defined($actions{$action})) {
468 die_error
(undef, "Unknown action");
470 if ($action !~ m/^(opml|project_list|project_index)$/ &&
472 die_error
(undef, "Project needed");
474 $actions{$action}->();
477 ## ======================================================================
482 # default is to use -absolute url() i.e. $my_uri
483 my $href = $params{-full
} ? $my_url : $my_uri;
485 # XXX: Warning: If you touch this, check the search form for updating,
496 hash_parent_base
=> "hpb",
502 my %mapping = @mapping;
504 $params{'project'} = $project unless exists $params{'project'};
506 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
508 # use PATH_INFO for project name
509 $href .= "/$params{'project'}" if defined $params{'project'};
510 delete $params{'project'};
512 # Summary just uses the project path URL
513 if (defined $params{'action'} && $params{'action'} eq 'summary') {
514 delete $params{'action'};
518 # now encode the parameters explicitly
520 for (my $i = 0; $i < @mapping; $i += 2) {
521 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
522 if (defined $params{$name}) {
523 push @result, $symbol . "=" . esc_param
($params{$name});
526 $href .= "?" . join(';', @result) if scalar @result;
532 ## ======================================================================
533 ## validation, quoting/unquoting and escaping
535 sub validate_pathname
{
536 my $input = shift || return undef;
538 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
539 # at the beginning, at the end, and between slashes.
540 # also this catches doubled slashes
541 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
545 if ($input =~ m!\0!) {
551 sub validate_refname
{
552 my $input = shift || return undef;
554 # textual hashes are O.K.
555 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
558 # it must be correct pathname
559 $input = validate_pathname
($input)
561 # restrictions on ref name according to git-check-ref-format
562 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
568 # very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT);
571 return decode
("utf8", $str, Encode
::FB_DEFAULT
);
574 # quote unsafe chars, but keep the slash, even when it's not
575 # correct, but quoted slashes look too horrible in bookmarks
578 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
584 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
587 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
593 # replace invalid utf8 character with SUBSTITUTION sequence
598 $str = to_utf8
($str);
599 $str = $cgi->escapeHTML($str);
600 if ($opts{'-nbsp'}) {
601 $str =~ s/ / /g;
603 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
607 # quote control characters and escape filename to HTML
612 $str = to_utf8
($str);
613 $str = $cgi->escapeHTML($str);
614 if ($opts{'-nbsp'}) {
615 $str =~ s/ / /g;
617 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
621 # Make control characters "printable", using character escape codes (CEC)
624 my %es = ( # character escape codes, aka escape sequences
625 "\t" => '\t', # tab (HT)
626 "\n" => '\n', # line feed (LF)
627 "\r" => '\r', # carrige return (CR)
628 "\f" => '\f', # form feed (FF)
629 "\b" => '\b', # backspace (BS)
630 "\a" => '\a', # alarm (bell) (BEL)
631 "\e" => '\e', # escape (ESC)
632 "\013" => '\v', # vertical tab (VT)
633 "\000" => '\0', # nul character (NUL)
635 my $chr = ( (exists $es{$cntrl})
637 : sprintf('\%03o', ord($cntrl)) );
638 return "<span class=\"cntrl\">$chr</span>";
641 # Alternatively use unicode control pictures codepoints,
642 # Unicode "printable representation" (PR)
645 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
646 return "<span class=\"cntrl\">$chr</span>";
649 # git may return quoted and escaped filenames
655 my %es = ( # character escape codes, aka escape sequences
656 't' => "\t", # tab (HT, TAB)
657 'n' => "\n", # newline (NL)
658 'r' => "\r", # return (CR)
659 'f' => "\f", # form feed (FF)
660 'b' => "\b", # backspace (BS)
661 'a' => "\a", # alarm (bell) (BEL)
662 'e' => "\e", # escape (ESC)
663 'v' => "\013", # vertical tab (VT)
666 if ($seq =~ m/^[0-7]{1,3}$/) {
667 # octal char sequence
668 return chr(oct($seq));
669 } elsif (exists $es{$seq}) {
670 # C escape sequence, aka character escape code
673 # quoted ordinary character
677 if ($str =~ m/^"(.*)"$/) {
680 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
685 # escape tabs (convert tabs to spaces)
689 while ((my $pos = index($line, "\t")) != -1) {
690 if (my $count = (8 - ($pos % 8))) {
691 my $spaces = ' ' x
$count;
692 $line =~ s/\t/$spaces/;
699 sub project_in_list
{
701 my @list = git_get_projects_list
();
702 return @list && scalar(grep { $_->{'path'} eq $project } @list);
705 ## ----------------------------------------------------------------------
706 ## HTML aware string manipulation
711 my $add_len = shift || 10;
713 # allow only $len chars, but don't cut a word if it would fit in $add_len
714 # if it doesn't fit, cut it if it's still longer than the dots we would add
715 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
718 if (length($tail) > 4) {
720 $body =~ s/&[^;]*$//; # remove chopped character entities
725 ## ----------------------------------------------------------------------
726 ## functions returning short strings
728 # CSS class for given age value (in seconds)
732 if ($age < 60*60*2) {
734 } elsif ($age < 60*60*24*2) {
741 # convert age in seconds to "nn units ago" string
746 if ($age > 60*60*24*365*2) {
747 $age_str = (int $age/60/60/24/365);
748 $age_str .= " years ago";
749 } elsif ($age > 60*60*24*(365/12)*2) {
750 $age_str = int $age/60/60/24/(365/12);
751 $age_str .= " months ago";
752 } elsif ($age > 60*60*24*7*2) {
753 $age_str = int $age/60/60/24/7;
754 $age_str .= " weeks ago";
755 } elsif ($age > 60*60*24*2) {
756 $age_str = int $age/60/60/24;
757 $age_str .= " days ago";
758 } elsif ($age > 60*60*2) {
759 $age_str = int $age/60/60;
760 $age_str .= " hours ago";
761 } elsif ($age > 60*2) {
762 $age_str = int $age/60;
763 $age_str .= " min ago";
766 $age_str .= " sec ago";
768 $age_str .= " right now";
773 # convert file mode in octal to symbolic file mode string
775 my $mode = oct shift;
777 if (S_ISDIR
($mode & S_IFMT
)) {
779 } elsif (S_ISLNK
($mode)) {
781 } elsif (S_ISREG
($mode)) {
782 # git cares only about the executable bit
783 if ($mode & S_IXUSR
) {
793 # convert file mode in octal to file type string
797 if ($mode !~ m/^[0-7]+$/) {
803 if (S_ISDIR
($mode & S_IFMT
)) {
805 } elsif (S_ISLNK
($mode)) {
807 } elsif (S_ISREG
($mode)) {
814 # convert file mode in octal to file type description string
818 if ($mode !~ m/^[0-7]+$/) {
824 if (S_ISDIR
($mode & S_IFMT
)) {
826 } elsif (S_ISLNK
($mode)) {
828 } elsif (S_ISREG
($mode)) {
829 if ($mode & S_IXUSR
) {
840 ## ----------------------------------------------------------------------
841 ## functions returning short HTML fragments, or transforming HTML fragments
842 ## which don't belong to other sections
844 # format line of commit message.
845 sub format_log_line_html
{
848 $line = esc_html
($line, -nbsp
=>1);
849 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
852 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
853 -class => "text"}, $hash_text);
854 $line =~ s/$hash_text/$link/;
859 # format marker of refs pointing to given object
860 sub format_ref_marker
{
861 my ($refs, $id) = @_;
864 if (defined $refs->{$id}) {
865 foreach my $ref (@{$refs->{$id}}) {
866 my ($type, $name) = qw();
867 # e.g. tags/v2.6.11 or heads/next
868 if ($ref =~ m!^(.*?)s?/(.*)$!) {
876 $markers .= " <span class=\"$type\" title=\"$ref\">" .
877 esc_html
($name) . "</span>";
882 return ' <span class="refs">'. $markers . '</span>';
888 # format, perhaps shortened and with markers, title line
889 sub format_subject_html
{
890 my ($long, $short, $href, $extra) = @_;
891 $extra = '' unless defined($extra);
893 if (length($short) < length($long)) {
894 return $cgi->a({-href
=> $href, -class => "list subject",
895 -title
=> to_utf8
($long)},
896 esc_html
($short) . $extra);
898 return $cgi->a({-href
=> $href, -class => "list subject"},
899 esc_html
($long) . $extra);
903 # format patch (diff) line (rather not to be used for diff headers)
904 sub format_diff_line
{
906 my ($from, $to) = @_;
907 my $char = substr($line, 0, 1);
913 $diff_class = " add";
914 } elsif ($char eq "-") {
915 $diff_class = " rem";
916 } elsif ($char eq "@") {
917 $diff_class = " chunk_header";
918 } elsif ($char eq "\\") {
919 $diff_class = " incomplete";
921 $line = untabify
($line);
922 if ($from && $to && $line =~ m/^\@{2} /) {
923 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
924 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
926 $from_lines = 0 unless defined $from_lines;
927 $to_lines = 0 unless defined $to_lines;
929 if ($from->{'href'}) {
930 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
931 -class=>"list"}, $from_text);
934 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
935 -class=>"list"}, $to_text);
937 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
938 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
939 return "<div class=\"diff$diff_class\">$line</div>\n";
941 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
944 ## ----------------------------------------------------------------------
945 ## git utility subroutines, invoking git commands
947 # returns path to the core git executable and the --git-dir parameter as list
949 return $GIT, '--git-dir='.$git_dir;
952 # returns path to the core git executable and the --git-dir parameter as string
954 return join(' ', git_cmd
());
957 # get HEAD ref of given project as hash
958 sub git_get_head_hash
{
960 my $o_git_dir = $git_dir;
962 $git_dir = "$projectroot/$project";
963 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
966 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
970 if (defined $o_git_dir) {
971 $git_dir = $o_git_dir;
976 # get type of given object
980 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
987 sub git_get_project_config
{
988 my ($key, $type) = @_;
990 return unless ($key);
991 $key =~ s/^gitweb\.//;
992 return if ($key =~ m/\W/);
994 my @x = (git_cmd
(), 'config');
995 if (defined $type) { push @x, $type; }
997 push @x, "gitweb.$key";
1003 # get hash of given path at given ref
1004 sub git_get_hash_by_path
{
1006 my $path = shift || return undef;
1011 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1012 or die_error
(undef, "Open git-ls-tree failed");
1014 close $fd or return undef;
1016 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1017 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1018 if (defined $type && $type ne $2) {
1019 # type doesn't match
1025 ## ......................................................................
1026 ## git utility functions, directly accessing git repository
1028 sub git_get_project_description
{
1031 open my $fd, "$projectroot/$path/description" or return undef;
1038 sub git_get_project_url_list
{
1041 open my $fd, "$projectroot/$path/cloneurl" or return;
1042 my @git_project_url_list = map { chomp; $_ } <$fd>;
1045 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1048 sub git_get_projects_list
{
1053 $filter =~ s/\.git$//;
1055 my ($check_forks) = gitweb_check_feature
('forks');
1057 if (-d
$projects_list) {
1058 # search in directory
1059 my $dir = $projects_list . ($filter ? "/$filter" : '');
1060 # remove the trailing "/"
1062 my $pfxlen = length("$dir");
1065 follow_fast
=> 1, # follow symbolic links
1066 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1068 # skip project-list toplevel, if we get it.
1069 return if (m!^[/.]$!);
1070 # only directories can be git repositories
1071 return unless (-d
$_);
1073 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1074 # we check related file in $projectroot
1075 if ($check_forks and $subdir =~ m
#/.#) {
1076 $File::Find
::prune
= 1;
1077 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1078 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1079 $File::Find
::prune
= 1;
1084 } elsif (-f
$projects_list) {
1085 # read from file(url-encoded):
1086 # 'git%2Fgit.git Linus+Torvalds'
1087 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1088 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1090 open my ($fd), $projects_list or return;
1092 while (my $line = <$fd>) {
1094 my ($path, $owner) = split ' ', $line;
1095 $path = unescape
($path);
1096 $owner = unescape
($owner);
1097 if (!defined $path) {
1100 if ($filter ne '') {
1101 # looking for forks;
1102 my $pfx = substr($path, 0, length($filter));
1103 if ($pfx ne $filter) {
1106 my $sfx = substr($path, length($filter));
1107 if ($sfx !~ /^\/.*\
.git
$/) {
1110 } elsif ($check_forks) {
1112 foreach my $filter (keys %paths) {
1113 # looking for forks;
1114 my $pfx = substr($path, 0, length($filter));
1115 if ($pfx ne $filter) {
1118 my $sfx = substr($path, length($filter));
1119 if ($sfx !~ /^\/.*\
.git
$/) {
1122 # is a fork, don't include it in
1127 if (check_export_ok
("$projectroot/$path")) {
1130 owner
=> to_utf8
($owner),
1133 (my $forks_path = $path) =~ s/\.git$//;
1134 $paths{$forks_path}++;
1142 sub git_get_project_owner
{
1143 my $project = shift;
1146 return undef unless $project;
1148 # read from file (url-encoded):
1149 # 'git%2Fgit.git Linus+Torvalds'
1150 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1151 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1152 if (-f
$projects_list) {
1153 open (my $fd , $projects_list);
1154 while (my $line = <$fd>) {
1156 my ($pr, $ow) = split ' ', $line;
1157 $pr = unescape
($pr);
1158 $ow = unescape
($ow);
1159 if ($pr eq $project) {
1160 $owner = to_utf8
($ow);
1166 if (!defined $owner) {
1167 $owner = get_file_owner
("$projectroot/$project");
1173 sub git_get_last_activity
{
1177 $git_dir = "$projectroot/$path";
1178 open($fd, "-|", git_cmd
(), 'for-each-ref',
1179 '--format=%(committer)',
1180 '--sort=-committerdate',
1182 'refs/heads') or return;
1183 my $most_recent = <$fd>;
1184 close $fd or return;
1185 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1187 my $age = time - $timestamp;
1188 return ($age, age_string
($age));
1192 sub git_get_references
{
1193 my $type = shift || "";
1195 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1196 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1197 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1198 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1201 while (my $line = <$fd>) {
1203 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1204 if (defined $refs{$1}) {
1205 push @{$refs{$1}}, $2;
1211 close $fd or return;
1215 sub git_get_rev_name_tags
{
1216 my $hash = shift || return undef;
1218 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1220 my $name_rev = <$fd>;
1223 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1226 # catches also '$hash undefined' output
1231 ## ----------------------------------------------------------------------
1232 ## parse to hash functions
1236 my $tz = shift || "-0000";
1239 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1240 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1241 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1242 $date{'hour'} = $hour;
1243 $date{'minute'} = $min;
1244 $date{'mday'} = $mday;
1245 $date{'day'} = $days[$wday];
1246 $date{'month'} = $months[$mon];
1247 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1248 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1249 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1250 $mday, $months[$mon], $hour ,$min;
1251 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1252 1900+$year, $mon, $mday, $hour ,$min, $sec;
1254 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1255 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1256 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1257 $date{'hour_local'} = $hour;
1258 $date{'minute_local'} = $min;
1259 $date{'tz_local'} = $tz;
1260 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1261 1900+$year, $mon+1, $mday,
1262 $hour, $min, $sec, $tz);
1271 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1272 $tag{'id'} = $tag_id;
1273 while (my $line = <$fd>) {
1275 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1276 $tag{'object'} = $1;
1277 } elsif ($line =~ m/^type (.+)$/) {
1279 } elsif ($line =~ m/^tag (.+)$/) {
1281 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1282 $tag{'author'} = $1;
1285 } elsif ($line =~ m/--BEGIN/) {
1286 push @comment, $line;
1288 } elsif ($line eq "") {
1292 push @comment, <$fd>;
1293 $tag{'comment'} = \
@comment;
1294 close $fd or return;
1295 if (!defined $tag{'name'}) {
1301 sub parse_commit_text
{
1302 my ($commit_text, $withparents) = @_;
1303 my @commit_lines = split '\n', $commit_text;
1306 pop @commit_lines; # Remove '\0'
1308 my $header = shift @commit_lines;
1309 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1312 ($co{'id'}, my @parents) = split ' ', $header;
1313 while (my $line = shift @commit_lines) {
1314 last if $line eq "\n";
1315 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1317 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1319 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1321 $co{'author_epoch'} = $2;
1322 $co{'author_tz'} = $3;
1323 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1324 $co{'author_name'} = $1;
1325 $co{'author_email'} = $2;
1327 $co{'author_name'} = $co{'author'};
1329 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1330 $co{'committer'} = $1;
1331 $co{'committer_epoch'} = $2;
1332 $co{'committer_tz'} = $3;
1333 $co{'committer_name'} = $co{'committer'};
1334 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1335 $co{'committer_name'} = $1;
1336 $co{'committer_email'} = $2;
1338 $co{'committer_name'} = $co{'committer'};
1342 if (!defined $co{'tree'}) {
1345 $co{'parents'} = \
@parents;
1346 $co{'parent'} = $parents[0];
1348 foreach my $title (@commit_lines) {
1351 $co{'title'} = chop_str
($title, 80, 5);
1352 # remove leading stuff of merges to make the interesting part visible
1353 if (length($title) > 50) {
1354 $title =~ s/^Automatic //;
1355 $title =~ s/^merge (of|with) /Merge ... /i;
1356 if (length($title) > 50) {
1357 $title =~ s/(http|rsync):\/\///;
1359 if (length($title) > 50) {
1360 $title =~ s/(master|www|rsync)\.//;
1362 if (length($title) > 50) {
1363 $title =~ s/kernel.org:?//;
1365 if (length($title) > 50) {
1366 $title =~ s/\/pub\/scm//;
1369 $co{'title_short'} = chop_str
($title, 50, 5);
1373 if ($co{'title'} eq "") {
1374 $co{'title'} = $co{'title_short'} = '(no commit message)';
1376 # remove added spaces
1377 foreach my $line (@commit_lines) {
1380 $co{'comment'} = \
@commit_lines;
1382 my $age = time - $co{'committer_epoch'};
1384 $co{'age_string'} = age_string
($age);
1385 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1386 if ($age > 60*60*24*7*2) {
1387 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1388 $co{'age_string_age'} = $co{'age_string'};
1390 $co{'age_string_date'} = $co{'age_string'};
1391 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1397 my ($commit_id) = @_;
1402 open my $fd, "-|", git_cmd
(), "rev-list",
1408 or die_error
(undef, "Open git-rev-list failed");
1409 %co = parse_commit_text
(<$fd>, 1);
1416 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1424 open my $fd, "-|", git_cmd
(), "rev-list",
1426 ($arg ? ($arg) : ()),
1427 ("--max-count=" . $maxcount),
1428 ("--skip=" . $skip),
1431 ($filename ? ($filename) : ())
1432 or die_error
(undef, "Open git-rev-list failed");
1433 while (my $line = <$fd>) {
1434 my %co = parse_commit_text
($line);
1439 return wantarray ? @cos : \
@cos;
1442 # parse ref from ref_file, given by ref_id, with given type
1444 my $ref_file = shift;
1446 my $type = shift || git_get_type
($ref_id);
1449 $ref_item{'type'} = $type;
1450 $ref_item{'id'} = $ref_id;
1451 $ref_item{'epoch'} = 0;
1452 $ref_item{'age'} = "unknown";
1453 if ($type eq "tag") {
1454 my %tag = parse_tag
($ref_id);
1455 $ref_item{'comment'} = $tag{'comment'};
1456 if ($tag{'type'} eq "commit") {
1457 my %co = parse_commit
($tag{'object'});
1458 $ref_item{'epoch'} = $co{'committer_epoch'};
1459 $ref_item{'age'} = $co{'age_string'};
1460 } elsif (defined($tag{'epoch'})) {
1461 my $age = time - $tag{'epoch'};
1462 $ref_item{'epoch'} = $tag{'epoch'};
1463 $ref_item{'age'} = age_string
($age);
1465 $ref_item{'reftype'} = $tag{'type'};
1466 $ref_item{'name'} = $tag{'name'};
1467 $ref_item{'refid'} = $tag{'object'};
1468 } elsif ($type eq "commit"){
1469 my %co = parse_commit
($ref_id);
1470 $ref_item{'reftype'} = "commit";
1471 $ref_item{'name'} = $ref_file;
1472 $ref_item{'title'} = $co{'title'};
1473 $ref_item{'refid'} = $ref_id;
1474 $ref_item{'epoch'} = $co{'committer_epoch'};
1475 $ref_item{'age'} = $co{'age_string'};
1477 $ref_item{'reftype'} = $type;
1478 $ref_item{'name'} = $ref_file;
1479 $ref_item{'refid'} = $ref_id;
1485 # parse line of git-diff-tree "raw" output
1486 sub parse_difftree_raw_line
{
1490 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1491 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1492 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1493 $res{'from_mode'} = $1;
1494 $res{'to_mode'} = $2;
1495 $res{'from_id'} = $3;
1497 $res{'status'} = $5;
1498 $res{'similarity'} = $6;
1499 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1500 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1502 $res{'file'} = unquote
($7);
1505 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1506 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1507 $res{'commit'} = $1;
1510 return wantarray ? %res : \
%res;
1513 # parse line of git-ls-tree output
1514 sub parse_ls_tree_line
($;%) {
1519 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1520 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1528 $res{'name'} = unquote
($4);
1531 return wantarray ? %res : \
%res;
1534 ## ......................................................................
1535 ## parse to array of hashes functions
1537 sub git_get_heads_list
{
1541 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1542 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1543 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1546 while (my $line = <$fd>) {
1550 my ($refinfo, $committerinfo) = split(/\0/, $line);
1551 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1552 my ($committer, $epoch, $tz) =
1553 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1554 $name =~ s!^refs/heads/!!;
1556 $ref_item{'name'} = $name;
1557 $ref_item{'id'} = $hash;
1558 $ref_item{'title'} = $title || '(no commit message)';
1559 $ref_item{'epoch'} = $epoch;
1561 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1563 $ref_item{'age'} = "unknown";
1566 push @headslist, \
%ref_item;
1570 return wantarray ? @headslist : \
@headslist;
1573 sub git_get_tags_list
{
1577 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1578 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1579 '--format=%(objectname) %(objecttype) %(refname) '.
1580 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1583 while (my $line = <$fd>) {
1587 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1588 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1589 my ($creator, $epoch, $tz) =
1590 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1591 $name =~ s!^refs/tags/!!;
1593 $ref_item{'type'} = $type;
1594 $ref_item{'id'} = $id;
1595 $ref_item{'name'} = $name;
1596 if ($type eq "tag") {
1597 $ref_item{'subject'} = $title;
1598 $ref_item{'reftype'} = $reftype;
1599 $ref_item{'refid'} = $refid;
1601 $ref_item{'reftype'} = $type;
1602 $ref_item{'refid'} = $id;
1605 if ($type eq "tag" || $type eq "commit") {
1606 $ref_item{'epoch'} = $epoch;
1608 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1610 $ref_item{'age'} = "unknown";
1614 push @tagslist, \
%ref_item;
1618 return wantarray ? @tagslist : \
@tagslist;
1621 ## ----------------------------------------------------------------------
1622 ## filesystem-related functions
1624 sub get_file_owner
{
1627 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1628 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1629 if (!defined $gcos) {
1633 $owner =~ s/[,;].*$//;
1634 return to_utf8
($owner);
1637 ## ......................................................................
1638 ## mimetype related functions
1640 sub mimetype_guess_file
{
1641 my $filename = shift;
1642 my $mimemap = shift;
1643 -r
$mimemap or return undef;
1646 open(MIME
, $mimemap) or return undef;
1648 next if m/^#/; # skip comments
1649 my ($mime, $exts) = split(/\t+/);
1650 if (defined $exts) {
1651 my @exts = split(/\s+/, $exts);
1652 foreach my $ext (@exts) {
1653 $mimemap{$ext} = $mime;
1659 $filename =~ /\.([^.]*)$/;
1660 return $mimemap{$1};
1663 sub mimetype_guess
{
1664 my $filename = shift;
1666 $filename =~ /\./ or return undef;
1668 if ($mimetypes_file) {
1669 my $file = $mimetypes_file;
1670 if ($file !~ m!^/!) { # if it is relative path
1671 # it is relative to project
1672 $file = "$projectroot/$project/$file";
1674 $mime = mimetype_guess_file
($filename, $file);
1676 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1682 my $filename = shift;
1685 my $mime = mimetype_guess
($filename);
1686 $mime and return $mime;
1690 return $default_blob_plain_mimetype unless $fd;
1693 return 'text/plain' .
1694 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1695 } elsif (! $filename) {
1696 return 'application/octet-stream';
1697 } elsif ($filename =~ m/\.png$/i) {
1699 } elsif ($filename =~ m/\.gif$/i) {
1701 } elsif ($filename =~ m/\.jpe?g$/i) {
1702 return 'image/jpeg';
1704 return 'application/octet-stream';
1708 ## ======================================================================
1709 ## functions printing HTML: header, footer, error page
1711 sub git_header_html
{
1712 my $status = shift || "200 OK";
1713 my $expires = shift;
1715 my $title = "$site_name";
1716 if (defined $project) {
1717 $title .= " - " . to_utf8
($project);
1718 if (defined $action) {
1719 $title .= "/$action";
1720 if (defined $file_name) {
1721 $title .= " - " . esc_path
($file_name);
1722 if ($action eq "tree" && $file_name !~ m
|/$|) {
1729 # require explicit support from the UA if we are to send the page as
1730 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1731 # we have to do this because MSIE sometimes globs '*/*', pretending to
1732 # support xhtml+xml but choking when it gets what it asked for.
1733 if (defined $cgi->http('HTTP_ACCEPT') &&
1734 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1735 $cgi->Accept('application/xhtml+xml') != 0) {
1736 $content_type = 'application/xhtml+xml';
1738 $content_type = 'text/html';
1740 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1741 -status
=> $status, -expires
=> $expires);
1742 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
1744 <?xml version="1.0" encoding="utf-8"?>
1745 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1746 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1747 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1748 <!-- git core binaries version $git_version -->
1750 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1751 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
1752 <meta name="robots" content="index, nofollow"/>
1753 <title>$title</title>
1755 # print out each stylesheet that exist
1756 if (defined $stylesheet) {
1757 #provides backwards capability for those people who define style sheet in a config file
1758 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1760 foreach my $stylesheet (@stylesheets) {
1761 next unless $stylesheet;
1762 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1765 if (defined $project) {
1766 printf('<link rel="alternate" title="%s log RSS feed" '.
1767 'href="%s" type="application/rss+xml" />'."\n",
1768 esc_param
($project), href
(action
=>"rss"));
1769 printf('<link rel="alternate" title="%s log Atom feed" '.
1770 'href="%s" type="application/atom+xml" />'."\n",
1771 esc_param
($project), href
(action
=>"atom"));
1773 printf('<link rel="alternate" title="%s projects list" '.
1774 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1775 $site_name, href
(project
=>undef, action
=>"project_index"));
1776 printf('<link rel="alternate" title="%s projects feeds" '.
1777 'href="%s" type="text/x-opml"/>'."\n",
1778 $site_name, href
(project
=>undef, action
=>"opml"));
1780 if (defined $favicon) {
1781 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1787 if (-f
$site_header) {
1788 open (my $fd, $site_header);
1793 print "<div class=\"page_header\">\n" .
1794 $cgi->a({-href
=> esc_url
($logo_url),
1795 -title
=> $logo_label},
1796 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1797 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1798 if (defined $project) {
1799 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1800 if (defined $action) {
1805 my ($have_search) = gitweb_check_feature
('search');
1806 if ((defined $project) && ($have_search)) {
1807 if (!defined $searchtext) {
1811 if (defined $hash_base) {
1812 $search_hash = $hash_base;
1813 } elsif (defined $hash) {
1814 $search_hash = $hash;
1816 $search_hash = "HEAD";
1818 $cgi->param("a", "search");
1819 $cgi->param("h", $search_hash);
1820 $cgi->param("p", $project);
1821 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1822 "<div class=\"search\">\n" .
1823 $cgi->hidden(-name
=> "p") . "\n" .
1824 $cgi->hidden(-name
=> "a") . "\n" .
1825 $cgi->hidden(-name
=> "h") . "\n" .
1826 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1827 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1828 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1830 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1832 $cgi->end_form() . "\n";
1837 sub git_footer_html
{
1838 print "<div class=\"page_footer\">\n";
1839 if (defined $project) {
1840 my $descr = git_get_project_description
($project);
1841 if (defined $descr) {
1842 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1844 print $cgi->a({-href
=> href
(action
=>"rss"),
1845 -class => "rss_logo"}, "RSS") . " ";
1846 print $cgi->a({-href
=> href
(action
=>"atom"),
1847 -class => "rss_logo"}, "Atom") . "\n";
1849 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1850 -class => "rss_logo"}, "OPML") . " ";
1851 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1852 -class => "rss_logo"}, "TXT") . "\n";
1856 if (-f
$site_footer) {
1857 open (my $fd, $site_footer);
1867 my $status = shift || "403 Forbidden";
1868 my $error = shift || "Malformed query, file missing or permission denied";
1870 git_header_html
($status);
1872 <div class="page_body">
1882 ## ----------------------------------------------------------------------
1883 ## functions printing or outputting HTML: navigation
1885 sub git_print_page_nav
{
1886 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1887 $extra = '' if !defined $extra; # pager or formats
1889 my @navs = qw(summary shortlog log commit commitdiff tree);
1891 @navs = grep { $_ ne $suppress } @navs;
1894 my %arg = map { $_ => {action
=>$_} } @navs;
1895 if (defined $head) {
1896 for (qw(commit commitdiff)) {
1897 $arg{$_}{'hash'} = $head;
1899 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1900 for (qw(shortlog log)) {
1901 $arg{$_}{'hash'} = $head;
1905 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
1906 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
1908 print "<div class=\"page_nav\">\n" .
1910 map { $_ eq $current ?
1911 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1913 print "<br/>\n$extra<br/>\n" .
1917 sub format_paging_nav
{
1918 my ($action, $hash, $head, $page, $nrevs) = @_;
1922 if ($hash ne $head || $page) {
1923 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1925 $paging_nav .= "HEAD";
1929 $paging_nav .= " ⋅ " .
1930 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1931 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1933 $paging_nav .= " ⋅ prev";
1936 if ($nrevs >= (100 * ($page+1)-1)) {
1937 $paging_nav .= " ⋅ " .
1938 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1939 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1941 $paging_nav .= " ⋅ next";
1947 ## ......................................................................
1948 ## functions printing or outputting HTML: div
1950 sub git_print_header_div
{
1951 my ($action, $title, $hash, $hash_base) = @_;
1954 $args{'action'} = $action;
1955 $args{'hash'} = $hash if $hash;
1956 $args{'hash_base'} = $hash_base if $hash_base;
1958 print "<div class=\"header\">\n" .
1959 $cgi->a({-href
=> href
(%args), -class => "title"},
1960 $title ? $title : $action) .
1964 #sub git_print_authorship (\%) {
1965 sub git_print_authorship
{
1968 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1969 print "<div class=\"author_date\">" .
1970 esc_html
($co->{'author_name'}) .
1972 if ($ad{'hour_local'} < 6) {
1973 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1974 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1976 printf(" (%02d:%02d %s)",
1977 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1982 sub git_print_page_path
{
1988 print "<div class=\"page_path\">";
1989 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1990 -title
=> 'tree root'}, to_utf8
("[$project]"));
1992 if (defined $name) {
1993 my @dirname = split '/', $name;
1994 my $basename = pop @dirname;
1997 foreach my $dir (@dirname) {
1998 $fullname .= ($fullname ? '/' : '') . $dir;
1999 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2001 -title
=> $fullname}, esc_path
($dir));
2004 if (defined $type && $type eq 'blob') {
2005 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2007 -title
=> $name}, esc_path
($basename));
2008 } elsif (defined $type && $type eq 'tree') {
2009 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2011 -title
=> $name}, esc_path
($basename));
2014 print esc_path
($basename);
2017 print "<br/></div>\n";
2020 # sub git_print_log (\@;%) {
2021 sub git_print_log
($;%) {
2025 if ($opts{'-remove_title'}) {
2026 # remove title, i.e. first line of log
2029 # remove leading empty lines
2030 while (defined $log->[0] && $log->[0] eq "") {
2037 foreach my $line (@$log) {
2038 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2041 if (! $opts{'-remove_signoff'}) {
2042 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2045 # remove signoff lines
2052 # print only one empty line
2053 # do not print empty line after signoff
2055 next if ($empty || $signoff);
2061 print format_log_line_html
($line) . "<br/>\n";
2064 if ($opts{'-final_empty_line'}) {
2065 # end with single empty line
2066 print "<br/>\n" unless $empty;
2070 # return link target (what link points to)
2071 sub git_get_link_target
{
2076 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2080 $link_target = <$fd>;
2085 return $link_target;
2088 # given link target, and the directory (basedir) the link is in,
2089 # return target of link relative to top directory (top tree);
2090 # return undef if it is not possible (including absolute links).
2091 sub normalize_link_target
{
2092 my ($link_target, $basedir, $hash_base) = @_;
2094 # we can normalize symlink target only if $hash_base is provided
2095 return unless $hash_base;
2097 # absolute symlinks (beginning with '/') cannot be normalized
2098 return if (substr($link_target, 0, 1) eq '/');
2100 # normalize link target to path from top (root) tree (dir)
2103 $path = $basedir . '/' . $link_target;
2105 # we are in top (root) tree (dir)
2106 $path = $link_target;
2109 # remove //, /./, and /../
2111 foreach my $part (split('/', $path)) {
2112 # discard '.' and ''
2113 next if (!$part || $part eq '.');
2115 if ($part eq '..') {
2119 # link leads outside repository (outside top dir)
2123 push @path_parts, $part;
2126 $path = join('/', @path_parts);
2131 # print tree entry (row of git_tree), but without encompassing <tr> element
2132 sub git_print_tree_entry
{
2133 my ($t, $basedir, $hash_base, $have_blame) = @_;
2136 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2138 # The format of a table row is: mode list link. Where mode is
2139 # the mode of the entry, list is the name of the entry, an href,
2140 # and link is the action links of the entry.
2142 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2143 if ($t->{'type'} eq "blob") {
2144 print "<td class=\"list\">" .
2145 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2146 file_name
=>"$basedir$t->{'name'}", %base_key),
2147 -class => "list"}, esc_path
($t->{'name'}));
2148 if (S_ISLNK
(oct $t->{'mode'})) {
2149 my $link_target = git_get_link_target
($t->{'hash'});
2151 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2152 if (defined $norm_target) {
2154 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2155 file_name
=>$norm_target),
2156 -title
=> $norm_target}, esc_path
($link_target));
2158 print " -> " . esc_path
($link_target);
2163 print "<td class=\"link\">";
2164 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2165 file_name
=>"$basedir$t->{'name'}", %base_key)},
2169 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2170 file_name
=>"$basedir$t->{'name'}", %base_key)},
2173 if (defined $hash_base) {
2175 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2176 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2180 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2181 file_name
=>"$basedir$t->{'name'}")},
2185 } elsif ($t->{'type'} eq "tree") {
2186 print "<td class=\"list\">";
2187 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2188 file_name
=>"$basedir$t->{'name'}", %base_key)},
2189 esc_path
($t->{'name'}));
2191 print "<td class=\"link\">";
2192 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2193 file_name
=>"$basedir$t->{'name'}", %base_key)},
2195 if (defined $hash_base) {
2197 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2198 file_name
=>"$basedir$t->{'name'}")},
2205 ## ......................................................................
2206 ## functions printing large fragments of HTML
2208 sub git_difftree_body
{
2209 my ($difftree, $hash, $parent) = @_;
2210 my ($have_blame) = gitweb_check_feature
('blame');
2211 print "<div class=\"list_head\">\n";
2212 if ($#{$difftree} > 10) {
2213 print(($#{$difftree} + 1) . " files changed:\n");
2217 print "<table class=\"diff_tree\">\n";
2220 foreach my $line (@{$difftree}) {
2221 my %diff = parse_difftree_raw_line
($line);
2224 print "<tr class=\"dark\">\n";
2226 print "<tr class=\"light\">\n";
2230 my ($to_mode_oct, $to_mode_str, $to_file_type);
2231 my ($from_mode_oct, $from_mode_str, $from_file_type);
2232 if ($diff{'to_mode'} ne ('0' x
6)) {
2233 $to_mode_oct = oct $diff{'to_mode'};
2234 if (S_ISREG
($to_mode_oct)) { # only for regular file
2235 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2237 $to_file_type = file_type
($diff{'to_mode'});
2239 if ($diff{'from_mode'} ne ('0' x
6)) {
2240 $from_mode_oct = oct $diff{'from_mode'};
2241 if (S_ISREG
($to_mode_oct)) { # only for regular file
2242 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2244 $from_file_type = file_type
($diff{'from_mode'});
2247 if ($diff{'status'} eq "A") { # created
2248 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2249 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2250 $mode_chng .= "]</span>";
2252 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2253 hash_base
=>$hash, file_name
=>$diff{'file'}),
2254 -class => "list"}, esc_path
($diff{'file'}));
2256 print "<td>$mode_chng</td>\n";
2257 print "<td class=\"link\">";
2258 if ($action eq 'commitdiff') {
2261 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2264 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2265 hash_base
=>$hash, file_name
=>$diff{'file'})},
2269 } elsif ($diff{'status'} eq "D") { # deleted
2270 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2272 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2273 hash_base
=>$parent, file_name
=>$diff{'file'}),
2274 -class => "list"}, esc_path
($diff{'file'}));
2276 print "<td>$mode_chng</td>\n";
2277 print "<td class=\"link\">";
2278 if ($action eq 'commitdiff') {
2281 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2284 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2285 hash_base
=>$parent, file_name
=>$diff{'file'})},
2288 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2289 file_name
=>$diff{'file'})},
2292 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2293 file_name
=>$diff{'file'})},
2297 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
2298 my $mode_chnge = "";
2299 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2300 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2301 if ($from_file_type ne $to_file_type) {
2302 $mode_chnge .= " from $from_file_type to $to_file_type";
2304 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2305 if ($from_mode_str && $to_mode_str) {
2306 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2307 } elsif ($to_mode_str) {
2308 $mode_chnge .= " mode: $to_mode_str";
2311 $mode_chnge .= "]</span>\n";
2314 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2315 hash_base
=>$hash, file_name
=>$diff{'file'}),
2316 -class => "list"}, esc_path
($diff{'file'}));
2318 print "<td>$mode_chnge</td>\n";
2319 print "<td class=\"link\">";
2320 if ($action eq 'commitdiff') {
2323 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2325 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2326 # "commit" view and modified file (not onlu mode changed)
2327 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2328 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2329 hash_base
=>$hash, hash_parent_base
=>$parent,
2330 file_name
=>$diff{'file'})},
2334 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2335 hash_base
=>$hash, file_name
=>$diff{'file'})},
2338 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2339 file_name
=>$diff{'file'})},
2342 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2343 file_name
=>$diff{'file'})},
2347 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
2348 my %status_name = ('R' => 'moved', 'C' => 'copied');
2349 my $nstatus = $status_name{$diff{'status'}};
2351 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2352 # mode also for directories, so we cannot use $to_mode_str
2353 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2356 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2357 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
2358 -class => "list"}, esc_path
($diff{'to_file'})) . "</td>\n" .
2359 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2360 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2361 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
2362 -class => "list"}, esc_path
($diff{'from_file'})) .
2363 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2364 "<td class=\"link\">";
2365 if ($action eq 'commitdiff') {
2368 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2370 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2371 # "commit" view and modified file (not only pure rename or copy)
2372 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2373 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2374 hash_base
=>$hash, hash_parent_base
=>$parent,
2375 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
2379 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2380 hash_base
=>$parent, file_name
=>$diff{'to_file'})},
2383 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2384 file_name
=>$diff{'to_file'})},
2387 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2388 file_name
=>$diff{'to_file'})},
2392 } # we should not encounter Unmerged (U) or Unknown (X) status
2398 sub git_patchset_body
{
2399 my ($fd, $difftree, $hash, $hash_parent) = @_;
2402 my $patch_number = 0;
2407 print "<div class=\"patchset\">\n";
2409 # skip to first patch
2410 while ($patch_line = <$fd>) {
2413 last if ($patch_line =~ m/^diff /);
2417 while ($patch_line) {
2419 my ($from_id, $to_id);
2422 #assert($patch_line =~ m/^diff /) if DEBUG;
2423 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2425 push @diff_header, $patch_line;
2427 # extended diff header
2429 while ($patch_line = <$fd>) {
2432 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2434 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2439 push @diff_header, $patch_line;
2441 my $last_patch_line = $patch_line;
2443 # check if current patch belong to current raw line
2444 # and parse raw git-diff line if needed
2445 if (defined $diffinfo &&
2446 $diffinfo->{'from_id'} eq $from_id &&
2447 $diffinfo->{'to_id'} eq $to_id) {
2448 # this is split patch
2449 print "<div class=\"patch cont\">\n";
2451 # advance raw git-diff output if needed
2452 $patch_idx++ if defined $diffinfo;
2454 # read and prepare patch information
2455 if (ref($difftree->[$patch_idx]) eq "HASH") {
2456 # pre-parsed (or generated by hand)
2457 $diffinfo = $difftree->[$patch_idx];
2459 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2461 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2462 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2463 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2464 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2465 hash
=>$diffinfo->{'from_id'},
2466 file_name
=>$from{'file'});
2468 delete $from{'href'};
2470 if ($diffinfo->{'status'} ne "D") { # not deleted file
2471 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2472 hash
=>$diffinfo->{'to_id'},
2473 file_name
=>$to{'file'});
2477 # this is first patch for raw difftree line with $patch_idx index
2478 # we index @$difftree array from 0, but number patches from 1
2479 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2482 # print "git diff" header
2483 $patch_line = shift @diff_header;
2484 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2485 if ($from{'href'}) {
2486 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2487 'a/' . esc_path
($from{'file'}));
2488 } else { # file was added
2489 $patch_line .= 'a/' . esc_path
($from{'file'});
2493 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2494 'b/' . esc_path
($to{'file'}));
2495 } else { # file was deleted
2496 $patch_line .= 'b/' . esc_path
($to{'file'});
2498 print "<div class=\"diff header\">$patch_line</div>\n";
2500 # print extended diff header
2501 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2503 foreach $patch_line (@diff_header) {
2505 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2506 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2507 esc_path
($from{'file'}));
2509 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2510 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2511 esc_path
($to{'file'}));
2514 if ($patch_line =~ m/\s(\d{6})$/) {
2515 $patch_line .= '<span class="info"> (' .
2516 file_type_long
($1) .
2520 if ($patch_line =~ m/^index/) {
2521 my ($from_link, $to_link);
2522 if ($from{'href'}) {
2523 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2524 substr($diffinfo->{'from_id'},0,7));
2526 $from_link = '0' x
7;
2529 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2530 substr($diffinfo->{'to_id'},0,7));
2535 # my ($from_hash, $to_hash) =
2536 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2537 # my ($from_id, $to_id) =
2538 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2539 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2541 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2542 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2544 print $patch_line . "<br/>\n";
2546 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2548 # from-file/to-file diff header
2549 $patch_line = $last_patch_line;
2550 if (! $patch_line) {
2551 print "</div>\n"; # class="patch"
2554 next PATCH
if ($patch_line =~ m/^diff /);
2555 #assert($patch_line =~ m/^---/) if DEBUG;
2556 if ($from{'href'} && $patch_line =~ m!^--- "?a/!) {
2557 $patch_line = '--- a/' .
2558 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2559 esc_path
($from{'file'}));
2561 print "<div class=\"diff from_file\">$patch_line</div>\n";
2563 $patch_line = <$fd>;
2566 #assert($patch_line =~ m/^+++/) if DEBUG;
2567 if ($to{'href'} && $patch_line =~ m!^\+\+\+ "?b/!) {
2568 $patch_line = '+++ b/' .
2569 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2570 esc_path
($to{'file'}));
2572 print "<div class=\"diff to_file\">$patch_line</div>\n";
2576 while ($patch_line = <$fd>) {
2579 next PATCH
if ($patch_line =~ m/^diff /);
2581 print format_diff_line
($patch_line, \
%from, \
%to);
2585 print "</div>\n"; # class="patch"
2587 print "<div class=\"diff nodifferences\">No differences found</div>\n" if (!$patch_number);
2589 print "</div>\n"; # class="patchset"
2592 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2594 sub git_project_list_body
{
2595 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2597 my ($check_forks) = gitweb_check_feature
('forks');
2600 foreach my $pr (@$projlist) {
2601 my (@aa) = git_get_last_activity
($pr->{'path'});
2605 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2606 if (!defined $pr->{'descr'}) {
2607 my $descr = git_get_project_description
($pr->{'path'}) || "";
2608 $pr->{'descr_long'} = to_utf8
($descr);
2609 $pr->{'descr'} = chop_str
($descr, 25, 5);
2611 if (!defined $pr->{'owner'}) {
2612 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2615 my $pname = $pr->{'path'};
2616 if (($pname =~ s/\.git$//) &&
2617 ($pname !~ /\/$/) &&
2618 (-d
"$projectroot/$pname")) {
2619 $pr->{'forks'} = "-d $projectroot/$pname";
2625 push @projects, $pr;
2628 $order ||= $default_projects_order;
2629 $from = 0 unless defined $from;
2630 $to = $#projects if (!defined $to || $#projects < $to);
2632 print "<table class=\"project_list\">\n";
2633 unless ($no_header) {
2636 print "<th></th>\n";
2638 if ($order eq "project") {
2639 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2640 print "<th>Project</th>\n";
2643 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2644 -class => "header"}, "Project") .
2647 if ($order eq "descr") {
2648 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2649 print "<th>Description</th>\n";
2652 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2653 -class => "header"}, "Description") .
2656 if ($order eq "owner") {
2657 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2658 print "<th>Owner</th>\n";
2661 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2662 -class => "header"}, "Owner") .
2665 if ($order eq "age") {
2666 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2667 print "<th>Last Change</th>\n";
2670 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2671 -class => "header"}, "Last Change") .
2674 print "<th></th>\n" .
2678 for (my $i = $from; $i <= $to; $i++) {
2679 my $pr = $projects[$i];
2681 print "<tr class=\"dark\">\n";
2683 print "<tr class=\"light\">\n";
2688 if ($pr->{'forks'}) {
2689 print "<!-- $pr->{'forks'} -->\n";
2690 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2694 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2695 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2696 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2697 -class => "list", -title
=> $pr->{'descr_long'}},
2698 esc_html
($pr->{'descr'})) . "</td>\n" .
2699 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2700 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2701 $pr->{'age_string'} . "</td>\n" .
2702 "<td class=\"link\">" .
2703 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2704 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2705 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2706 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2707 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
2711 if (defined $extra) {
2714 print "<td></td>\n";
2716 print "<td colspan=\"5\">$extra</td>\n" .
2722 sub git_shortlog_body
{
2723 # uses global variable $project
2724 my ($commitlist, $from, $to, $refs, $extra) = @_;
2726 my $have_snapshot = gitweb_have_snapshot
();
2728 $from = 0 unless defined $from;
2729 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
2731 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2733 for (my $i = $from; $i <= $to; $i++) {
2734 my %co = %{$commitlist->[$i]};
2735 my $commit = $co{'id'};
2736 my $ref = format_ref_marker
($refs, $commit);
2738 print "<tr class=\"dark\">\n";
2740 print "<tr class=\"light\">\n";
2743 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2744 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2745 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2747 print format_subject_html
($co{'title'}, $co{'title_short'},
2748 href
(action
=>"commit", hash
=>$commit), $ref);
2750 "<td class=\"link\">" .
2751 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
2752 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2753 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2754 if ($have_snapshot) {
2755 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2760 if (defined $extra) {
2762 "<td colspan=\"4\">$extra</td>\n" .
2768 sub git_history_body
{
2769 # Warning: assumes constant type (blob or tree) during history
2770 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2772 $from = 0 unless defined $from;
2773 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
2775 print "<table class=\"history\" cellspacing=\"0\">\n";
2777 for (my $i = $from; $i <= $to; $i++) {
2778 my %co = %{$commitlist->[$i]};
2782 my $commit = $co{'id'};
2784 my $ref = format_ref_marker
($refs, $commit);
2787 print "<tr class=\"dark\">\n";
2789 print "<tr class=\"light\">\n";
2792 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2793 # shortlog uses chop_str($co{'author_name'}, 10)
2794 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2796 # originally git_history used chop_str($co{'title'}, 50)
2797 print format_subject_html
($co{'title'}, $co{'title_short'},
2798 href
(action
=>"commit", hash
=>$commit), $ref);
2800 "<td class=\"link\">" .
2801 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2802 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2804 if ($ftype eq 'blob') {
2805 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2806 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2807 if (defined $blob_current && defined $blob_parent &&
2808 $blob_current ne $blob_parent) {
2810 $cgi->a({-href
=> href
(action
=>"blobdiff",
2811 hash
=>$blob_current, hash_parent
=>$blob_parent,
2812 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2813 file_name
=>$file_name)},
2820 if (defined $extra) {
2822 "<td colspan=\"4\">$extra</td>\n" .
2829 # uses global variable $project
2830 my ($taglist, $from, $to, $extra) = @_;
2831 $from = 0 unless defined $from;
2832 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2834 print "<table class=\"tags\" cellspacing=\"0\">\n";
2836 for (my $i = $from; $i <= $to; $i++) {
2837 my $entry = $taglist->[$i];
2839 my $comment = $tag{'subject'};
2841 if (defined $comment) {
2842 $comment_short = chop_str
($comment, 30, 5);
2845 print "<tr class=\"dark\">\n";
2847 print "<tr class=\"light\">\n";
2850 if (defined $tag{'age'}) {
2851 print "<td><i>$tag{'age'}</i></td>\n";
2853 print "<td></td>\n";
2856 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2857 -class => "list name"}, esc_html
($tag{'name'})) .
2860 if (defined $comment) {
2861 print format_subject_html
($comment, $comment_short,
2862 href
(action
=>"tag", hash
=>$tag{'id'}));
2865 "<td class=\"selflink\">";
2866 if ($tag{'type'} eq "tag") {
2867 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2872 "<td class=\"link\">" . " | " .
2873 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2874 if ($tag{'reftype'} eq "commit") {
2875 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2876 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
2877 } elsif ($tag{'reftype'} eq "blob") {
2878 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2883 if (defined $extra) {
2885 "<td colspan=\"5\">$extra</td>\n" .
2891 sub git_heads_body
{
2892 # uses global variable $project
2893 my ($headlist, $head, $from, $to, $extra) = @_;
2894 $from = 0 unless defined $from;
2895 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2897 print "<table class=\"heads\" cellspacing=\"0\">\n";
2899 for (my $i = $from; $i <= $to; $i++) {
2900 my $entry = $headlist->[$i];
2902 my $curr = $ref{'id'} eq $head;
2904 print "<tr class=\"dark\">\n";
2906 print "<tr class=\"light\">\n";
2909 print "<td><i>$ref{'age'}</i></td>\n" .
2910 ($curr ? "<td class=\"current_head\">" : "<td>") .
2911 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
2912 -class => "list name"},esc_html
($ref{'name'})) .
2914 "<td class=\"link\">" .
2915 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
2916 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
2917 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
2921 if (defined $extra) {
2923 "<td colspan=\"3\">$extra</td>\n" .
2929 sub git_search_grep_body
{
2930 my ($commitlist, $from, $to, $extra) = @_;
2931 $from = 0 unless defined $from;
2932 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
2934 print "<table class=\"grep\" cellspacing=\"0\">\n";
2936 for (my $i = $from; $i <= $to; $i++) {
2937 my %co = %{$commitlist->[$i]};
2941 my $commit = $co{'id'};
2943 print "<tr class=\"dark\">\n";
2945 print "<tr class=\"light\">\n";
2948 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2949 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2951 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
2952 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
2953 my $comment = $co{'comment'};
2954 foreach my $line (@$comment) {
2955 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2956 my $lead = esc_html
($1) || "";
2957 $lead = chop_str
($lead, 30, 10);
2958 my $match = esc_html
($2) || "";
2959 my $trail = esc_html
($3) || "";
2960 $trail = chop_str
($trail, 30, 10);
2961 my $text = "$lead<span class=\"match\">$match</span>$trail";
2962 print chop_str
($text, 80, 5) . "<br/>\n";
2966 "<td class=\"link\">" .
2967 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
2969 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
2973 if (defined $extra) {
2975 "<td colspan=\"3\">$extra</td>\n" .
2981 ## ======================================================================
2982 ## ======================================================================
2985 sub git_project_list
{
2986 my $order = $cgi->param('o');
2987 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
2988 die_error
(undef, "Unknown order parameter");
2991 my @list = git_get_projects_list
();
2993 die_error
(undef, "No projects found");
2997 if (-f
$home_text) {
2998 print "<div class=\"index_include\">\n";
2999 open (my $fd, $home_text);
3004 git_project_list_body
(\
@list, $order);
3009 my $order = $cgi->param('o');
3010 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3011 die_error
(undef, "Unknown order parameter");
3014 my @list = git_get_projects_list
($project);
3016 die_error
(undef, "No forks found");
3020 git_print_page_nav
('','');
3021 git_print_header_div
('summary', "$project forks");
3022 git_project_list_body
(\
@list, $order);
3026 sub git_project_index
{
3027 my @projects = git_get_projects_list
($project);
3030 -type
=> 'text/plain',
3031 -charset
=> 'utf-8',
3032 -content_disposition
=> 'inline; filename="index.aux"');
3034 foreach my $pr (@projects) {
3035 if (!exists $pr->{'owner'}) {
3036 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3039 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3040 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3041 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3042 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3046 print "$path $owner\n";
3051 my $descr = git_get_project_description
($project) || "none";
3052 my %co = parse_commit
("HEAD");
3053 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3054 my $head = $co{'id'};
3056 my $owner = git_get_project_owner
($project);
3058 my $refs = git_get_references
();
3059 # These get_*_list functions return one more to allow us to see if
3060 # there are more ...
3061 my @taglist = git_get_tags_list
(16);
3062 my @headlist = git_get_heads_list
(16);
3064 my ($check_forks) = gitweb_check_feature
('forks');
3067 @forklist = git_get_projects_list
($project);
3071 git_print_page_nav
('summary','', $head);
3073 print "<div class=\"title\"> </div>\n";
3074 print "<table cellspacing=\"0\">\n" .
3075 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3076 "<tr><td>owner</td><td>$owner</td></tr>\n" .
3077 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3078 # use per project git URL list in $projectroot/$project/cloneurl
3079 # or make project git URL from git base URL and project name
3080 my $url_tag = "URL";
3081 my @url_list = git_get_project_url_list
($project);
3082 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3083 foreach my $git_url (@url_list) {
3084 next unless $git_url;
3085 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3090 if (-s
"$projectroot/$project/README.html") {
3091 if (open my $fd, "$projectroot/$project/README.html") {
3092 print "<div class=\"title\">readme</div>\n";
3093 print $_ while (<$fd>);
3098 # we need to request one more than 16 (0..15) to check if
3100 my @commitlist = parse_commits
($head, 17);
3101 git_print_header_div
('shortlog');
3102 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3103 $#commitlist <= 15 ? undef :
3104 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3107 git_print_header_div
('tags');
3108 git_tags_body
(\
@taglist, 0, 15,
3109 $#taglist <= 15 ? undef :
3110 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3114 git_print_header_div
('heads');
3115 git_heads_body
(\
@headlist, $head, 0, 15,
3116 $#headlist <= 15 ? undef :
3117 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3121 git_print_header_div
('forks');
3122 git_project_list_body
(\
@forklist, undef, 0, 15,
3123 $#forklist <= 15 ? undef :
3124 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3132 my $head = git_get_head_hash
($project);
3134 git_print_page_nav
('','', $head,undef,$head);
3135 my %tag = parse_tag
($hash);
3136 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3137 print "<div class=\"title_text\">\n" .
3138 "<table cellspacing=\"0\">\n" .
3140 "<td>object</td>\n" .
3141 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3142 $tag{'object'}) . "</td>\n" .
3143 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3144 $tag{'type'}) . "</td>\n" .
3146 if (defined($tag{'author'})) {
3147 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3148 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3149 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3150 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3153 print "</table>\n\n" .
3155 print "<div class=\"page_body\">";
3156 my $comment = $tag{'comment'};
3157 foreach my $line (@$comment) {
3159 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3169 my ($have_blame) = gitweb_check_feature
('blame');
3171 die_error
('403 Permission denied', "Permission denied");
3173 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3174 $hash_base ||= git_get_head_hash
($project);
3175 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3176 my %co = parse_commit
($hash_base)
3177 or die_error
(undef, "Reading commit failed");
3178 if (!defined $hash) {
3179 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3180 or die_error
(undef, "Error looking up file");
3182 $ftype = git_get_type
($hash);
3183 if ($ftype !~ "blob") {
3184 die_error
('400 Bad Request', "Object is not a blob");
3186 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3187 $file_name, $hash_base)
3188 or die_error
(undef, "Open git-blame failed");
3191 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3194 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3197 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3199 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3200 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3201 git_print_page_path
($file_name, $ftype, $hash_base);
3202 my @rev_color = (qw(light2 dark2));
3203 my $num_colors = scalar(@rev_color);
3204 my $current_color = 0;
3207 <div class="page_body">
3208 <table class="blame">
3209 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3214 last unless defined $_;
3215 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3216 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3217 if (!exists $metainfo{$full_rev}) {
3218 $metainfo{$full_rev} = {};
3220 my $meta = $metainfo{$full_rev};
3223 if (/^(\S+) (.*)$/) {
3229 my $rev = substr($full_rev, 0, 8);
3230 my $author = $meta->{'author'};
3231 my %date = parse_date
($meta->{'author-time'},
3232 $meta->{'author-tz'});
3233 my $date = $date{'iso-tz'};
3235 $current_color = ++$current_color % $num_colors;
3237 print "<tr class=\"$rev_color[$current_color]\">\n";
3239 print "<td class=\"sha1\"";
3240 print " title=\"". esc_html
($author) . ", $date\"";
3241 print " rowspan=\"$group_size\"" if ($group_size > 1);
3243 print $cgi->a({-href
=> href
(action
=>"commit",
3245 file_name
=>$file_name)},
3249 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3250 or die_error
(undef, "Open git-rev-parse failed");
3251 my $parent_commit = <$dd>;
3253 chomp($parent_commit);
3254 my $blamed = href
(action
=> 'blame',
3255 file_name
=> $meta->{'filename'},
3256 hash_base
=> $parent_commit);
3257 print "<td class=\"linenr\">";
3258 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3260 -class => "linenr" },
3263 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3269 or print "Reading blob failed\n";
3276 my ($have_blame) = gitweb_check_feature
('blame');
3278 die_error
('403 Permission denied', "Permission denied");
3280 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3281 $hash_base ||= git_get_head_hash
($project);
3282 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3283 my %co = parse_commit
($hash_base)
3284 or die_error
(undef, "Reading commit failed");
3285 if (!defined $hash) {
3286 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3287 or die_error
(undef, "Error lookup file");
3289 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3290 or die_error
(undef, "Open git-annotate failed");
3293 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3296 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3299 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3301 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3302 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3303 git_print_page_path
($file_name, 'blob', $hash_base);
3304 print "<div class=\"page_body\">\n";
3306 <table class="blame">
3315 my @line_class = (qw(light dark));
3316 my $line_class_len = scalar (@line_class);
3317 my $line_class_num = $#line_class;
3318 while (my $line = <$fd>) {
3330 $line_class_num = ($line_class_num + 1) % $line_class_len;
3332 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3339 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3342 $short_rev = substr ($long_rev, 0, 8);
3343 $age = time () - $time;
3344 $age_str = age_string
($age);
3345 $age_str =~ s/ / /g;
3346 $age_class = age_class
($age);
3347 $author = esc_html
($author);
3348 $author =~ s/ / /g;
3350 $data = untabify
($data);
3351 $data = esc_html
($data);
3354 <tr class="$line_class[$line_class_num]">
3355 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3356 <td class="$age_class">$age_str</td>
3358 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3359 <td class="pre">$data</td>
3362 } # while (my $line = <$fd>)
3363 print "</table>\n\n";
3365 or print "Reading blob failed.\n";
3371 my $head = git_get_head_hash
($project);
3373 git_print_page_nav
('','', $head,undef,$head);
3374 git_print_header_div
('summary', $project);
3376 my @tagslist = git_get_tags_list
();
3378 git_tags_body
(\
@tagslist);
3384 my $head = git_get_head_hash
($project);
3386 git_print_page_nav
('','', $head,undef,$head);
3387 git_print_header_div
('summary', $project);
3389 my @headslist = git_get_heads_list
();
3391 git_heads_body
(\
@headslist, $head);
3396 sub git_blob_plain
{
3399 if (!defined $hash) {
3400 if (defined $file_name) {
3401 my $base = $hash_base || git_get_head_hash
($project);
3402 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3403 or die_error
(undef, "Error lookup file");
3405 die_error
(undef, "No file name defined");
3407 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3408 # blobs defined by non-textual hash id's can be cached
3413 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3414 or die_error
(undef, "Couldn't cat $file_name, $hash");
3416 $type ||= blob_mimetype
($fd, $file_name);
3418 # save as filename, even when no $file_name is given
3419 my $save_as = "$hash";
3420 if (defined $file_name) {
3421 $save_as = $file_name;
3422 } elsif ($type =~ m/^text\//) {
3429 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3431 binmode STDOUT
, ':raw';
3433 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3441 if (!defined $hash) {
3442 if (defined $file_name) {
3443 my $base = $hash_base || git_get_head_hash
($project);
3444 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3445 or die_error
(undef, "Error lookup file");
3447 die_error
(undef, "No file name defined");
3449 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3450 # blobs defined by non-textual hash id's can be cached
3454 my ($have_blame) = gitweb_check_feature
('blame');
3455 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3456 or die_error
(undef, "Couldn't cat $file_name, $hash");
3457 my $mimetype = blob_mimetype
($fd, $file_name);
3458 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3460 return git_blob_plain
($mimetype);
3462 # we can have blame only for text/* mimetype
3463 $have_blame &&= ($mimetype =~ m!^text/!);
3465 git_header_html
(undef, $expires);
3466 my $formats_nav = '';
3467 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3468 if (defined $file_name) {
3471 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3472 hash
=>$hash, file_name
=>$file_name)},
3477 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3478 hash
=>$hash, file_name
=>$file_name)},
3481 $cgi->a({-href
=> href
(action
=>"blob_plain",
3482 hash
=>$hash, file_name
=>$file_name)},
3485 $cgi->a({-href
=> href
(action
=>"blob",
3486 hash_base
=>"HEAD", file_name
=>$file_name)},
3490 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3492 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3493 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3495 print "<div class=\"page_nav\">\n" .
3496 "<br/><br/></div>\n" .
3497 "<div class=\"title\">$hash</div>\n";
3499 git_print_page_path
($file_name, "blob", $hash_base);
3500 print "<div class=\"page_body\">\n";
3501 if ($mimetype =~ m!^text/!) {
3503 while (my $line = <$fd>) {
3506 $line = untabify
($line);
3507 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3508 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3510 } elsif ($mimetype =~ m!^image/!) {
3511 print qq
!<img type
="$mimetype"!;
3513 print qq
! alt
="$file_name" title
="$file_name"!;
3516 href(action=>"blob_plain
", hash=>$hash,
3517 hash_base=>$hash_base, file_name=>$file_name) .
3521 or print "Reading blob failed.\n";
3527 my $have_snapshot = gitweb_have_snapshot
();
3529 if (!defined $hash_base) {
3530 $hash_base = "HEAD";
3532 if (!defined $hash) {
3533 if (defined $file_name) {
3534 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3540 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3541 or die_error
(undef, "Open git-ls-tree failed");
3542 my @entries = map { chomp; $_ } <$fd>;
3543 close $fd or die_error
(undef, "Reading tree failed");
3546 my $refs = git_get_references
();
3547 my $ref = format_ref_marker
($refs, $hash_base);
3550 my ($have_blame) = gitweb_check_feature
('blame');
3551 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3553 if (defined $file_name) {
3555 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3556 hash
=>$hash, file_name
=>$file_name)},
3558 $cgi->a({-href
=> href
(action
=>"tree",
3559 hash_base
=>"HEAD", file_name
=>$file_name)},
3562 if ($have_snapshot) {
3563 # FIXME: Should be available when we have no hash base as well.
3565 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3568 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3569 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3572 print "<div class=\"page_nav\">\n";
3573 print "<br/><br/></div>\n";
3574 print "<div class=\"title\">$hash</div>\n";
3576 if (defined $file_name) {
3577 $basedir = $file_name;
3578 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3582 git_print_page_path
($file_name, 'tree', $hash_base);
3583 print "<div class=\"page_body\">\n";
3584 print "<table cellspacing=\"0\">\n";
3586 # '..' (top directory) link if possible
3587 if (defined $hash_base &&
3588 defined $file_name && $file_name =~ m![^/]+$!) {
3590 print "<tr class=\"dark\">\n";
3592 print "<tr class=\"light\">\n";
3596 my $up = $file_name;
3597 $up =~ s!/?[^/]+$!!;
3598 undef $up unless $up;
3599 # based on git_print_tree_entry
3600 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3601 print '<td class="list">';
3602 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3606 print "<td class=\"link\"></td>\n";
3610 foreach my $line (@entries) {
3611 my %t = parse_ls_tree_line
($line, -z
=> 1);
3614 print "<tr class=\"dark\">\n";
3616 print "<tr class=\"light\">\n";
3620 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3624 print "</table>\n" .
3630 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3631 my $have_snapshot = (defined $ctype && defined $suffix);
3632 if (!$have_snapshot) {
3633 die_error
('403 Permission denied', "Permission denied");
3636 if (!defined $hash) {
3637 $hash = git_get_head_hash
($project);
3640 my $filename = to_utf8
(basename
($project)) . "-$hash.tar.$suffix";
3643 -type
=> "application/$ctype",
3644 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3645 -status
=> '200 OK');
3647 my $git = git_cmd_str
();
3648 my $name = $project;
3649 $name =~ s/\047/\047\\\047\047/g;
3651 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3652 or die_error
(undef, "Execute git-tar-tree failed");
3653 binmode STDOUT
, ':raw';
3655 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3661 my $head = git_get_head_hash
($project);
3662 if (!defined $hash) {
3665 if (!defined $page) {
3668 my $refs = git_get_references
();
3670 my @commitlist = parse_commits
($hash, 101, (100 * $page));
3672 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
3675 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3678 my %co = parse_commit
($hash);
3680 git_print_header_div
('summary', $project);
3681 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3683 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
3684 for (my $i = 0; $i <= $to; $i++) {
3685 my %co = %{$commitlist[$i]};
3687 my $commit = $co{'id'};
3688 my $ref = format_ref_marker
($refs, $commit);
3689 my %ad = parse_date
($co{'author_epoch'});
3690 git_print_header_div
('commit',
3691 "<span class=\"age\">$co{'age_string'}</span>" .
3692 esc_html
($co{'title'}) . $ref,
3694 print "<div class=\"title_text\">\n" .
3695 "<div class=\"log_link\">\n" .
3696 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3698 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3700 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3703 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3706 print "<div class=\"log_body\">\n";
3707 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
3710 if ($#commitlist >= 100) {
3711 print "<div class=\"page_nav\">\n";
3712 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
3713 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3720 $hash ||= $hash_base || "HEAD";
3721 my %co = parse_commit
($hash);
3723 die_error
(undef, "Unknown commit object");
3725 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3726 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3728 my $parent = $co{'parent'};
3729 my $parents = $co{'parents'}; # listref
3731 # we need to prepare $formats_nav before any parameter munging
3733 if (!defined $parent) {
3735 $formats_nav .= '(initial)';
3736 } elsif (@$parents == 1) {
3737 # single parent commit
3740 $cgi->a({-href
=> href
(action
=>"commit",
3742 esc_html
(substr($parent, 0, 7))) .
3749 $cgi->a({-href
=> href
(action
=>"commit",
3751 esc_html
(substr($_, 0, 7)));
3756 if (!defined $parent) {
3760 if (@$parents <= 1) {
3761 # difftree output is not printed for merges
3762 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
3763 @diff_opts, $parent, $hash, "--"
3764 or die_error
(undef, "Open git-diff-tree failed");
3765 @difftree = map { chomp; $_ } <$fd>;
3766 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3769 # non-textual hash id's can be cached
3771 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3774 my $refs = git_get_references
();
3775 my $ref = format_ref_marker
($refs, $co{'id'});
3777 my $have_snapshot = gitweb_have_snapshot
();
3779 git_header_html
(undef, $expires);
3780 git_print_page_nav
('commit', '',
3781 $hash, $co{'tree'}, $hash,
3784 if (defined $co{'parent'}) {
3785 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3787 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3789 print "<div class=\"title_text\">\n" .
3790 "<table cellspacing=\"0\">\n";
3791 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3793 "<td></td><td> $ad{'rfc2822'}";
3794 if ($ad{'hour_local'} < 6) {
3795 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3796 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3798 printf(" (%02d:%02d %s)",
3799 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3803 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3804 print "<tr><td></td><td> $cd{'rfc2822'}" .
3805 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3807 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3810 "<td class=\"sha1\">" .
3811 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3812 class => "list"}, $co{'tree'}) .
3814 "<td class=\"link\">" .
3815 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3817 if ($have_snapshot) {
3819 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3824 foreach my $par (@$parents) {
3827 "<td class=\"sha1\">" .
3828 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3829 class => "list"}, $par) .
3831 "<td class=\"link\">" .
3832 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3834 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3841 print "<div class=\"page_body\">\n";
3842 git_print_log
($co{'comment'});
3845 if (@$parents <= 1) {
3846 # do not output difftree/whatchanged for merges
3847 git_difftree_body
(\
@difftree, $hash, $parent);
3854 # object is defined by:
3855 # - hash or hash_base alone
3856 # - hash_base and file_name
3859 # - hash or hash_base alone
3860 if ($hash || ($hash_base && !defined $file_name)) {
3861 my $object_id = $hash || $hash_base;
3863 my $git_command = git_cmd_str
();
3864 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
3865 or die_error
('404 Not Found', "Object does not exist");
3869 or die_error
('404 Not Found', "Object does not exist");
3871 # - hash_base and file_name
3872 } elsif ($hash_base && defined $file_name) {
3873 $file_name =~ s
,/+$,,;
3875 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
3876 or die_error
('404 Not Found', "Base object does not exist");
3878 # here errors should not hapen
3879 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
3880 or die_error
(undef, "Open git-ls-tree failed");
3884 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
3885 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
3886 die_error
('404 Not Found', "File or directory for given base does not exist");
3891 die_error
('404 Not Found', "Not enough information to find object");
3894 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
3895 hash
=>$hash, hash_base
=>$hash_base,
3896 file_name
=>$file_name),
3897 -status
=> '302 Found');
3901 my $format = shift || 'html';
3908 # preparing $fd and %diffinfo for git_patchset_body
3910 if (defined $hash_base && defined $hash_parent_base) {
3911 if (defined $file_name) {
3913 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3914 $hash_parent_base, $hash_base,
3915 "--", (defined $file_parent ? $file_parent : ()), $file_name
3916 or die_error
(undef, "Open git-diff-tree failed");
3917 @difftree = map { chomp; $_ } <$fd>;
3919 or die_error
(undef, "Reading git-diff-tree failed");
3921 or die_error
('404 Not Found', "Blob diff not found");
3923 } elsif (defined $hash &&
3924 $hash =~ /[0-9a-fA-F]{40}/) {
3925 # try to find filename from $hash
3927 # read filtered raw output
3928 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3929 $hash_parent_base, $hash_base, "--"
3930 or die_error
(undef, "Open git-diff-tree failed");
3932 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3934 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3935 map { chomp; $_ } <$fd>;
3937 or die_error
(undef, "Reading git-diff-tree failed");
3939 or die_error
('404 Not Found', "Blob diff not found");
3942 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3945 if (@difftree > 1) {
3946 die_error
('404 Not Found', "Ambiguous blob diff specification");
3949 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3950 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3951 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3953 $hash_parent ||= $diffinfo{'from_id'};
3954 $hash ||= $diffinfo{'to_id'};
3956 # non-textual hash id's can be cached
3957 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3958 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3963 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3964 '-p', ($format eq 'html' ? "--full-index" : ()),
3965 $hash_parent_base, $hash_base,
3966 "--", (defined $file_parent ? $file_parent : ()), $file_name
3967 or die_error
(undef, "Open git-diff-tree failed");
3970 # old/legacy style URI
3971 if (!%diffinfo && # if new style URI failed
3972 defined $hash && defined $hash_parent) {
3973 # fake git-diff-tree raw output
3974 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3975 $diffinfo{'from_id'} = $hash_parent;
3976 $diffinfo{'to_id'} = $hash;
3977 if (defined $file_name) {
3978 if (defined $file_parent) {
3979 $diffinfo{'status'} = '2';
3980 $diffinfo{'from_file'} = $file_parent;
3981 $diffinfo{'to_file'} = $file_name;
3982 } else { # assume not renamed
3983 $diffinfo{'status'} = '1';
3984 $diffinfo{'from_file'} = $file_name;
3985 $diffinfo{'to_file'} = $file_name;
3987 } else { # no filename given
3988 $diffinfo{'status'} = '2';
3989 $diffinfo{'from_file'} = $hash_parent;
3990 $diffinfo{'to_file'} = $hash;
3993 # non-textual hash id's can be cached
3994 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3995 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4000 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4001 '-p', ($format eq 'html' ? "--full-index" : ()),
4002 $hash_parent, $hash, "--"
4003 or die_error
(undef, "Open git-diff failed");
4005 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4010 if ($format eq 'html') {
4012 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4013 hash
=>$hash, hash_parent
=>$hash_parent,
4014 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4015 file_name
=>$file_name, file_parent
=>$file_parent)},
4017 git_header_html
(undef, $expires);
4018 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4019 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4020 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4022 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4023 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4025 if (defined $file_name) {
4026 git_print_page_path
($file_name, "blob", $hash_base);
4028 print "<div class=\"page_path\"></div>\n";
4031 } elsif ($format eq 'plain') {
4033 -type
=> 'text/plain',
4034 -charset
=> 'utf-8',
4035 -expires
=> $expires,
4036 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4038 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4041 die_error
(undef, "Unknown blobdiff format");
4045 if ($format eq 'html') {
4046 print "<div class=\"page_body\">\n";
4048 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4051 print "</div>\n"; # class="page_body"
4055 while (my $line = <$fd>) {
4056 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4057 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4061 last if $line =~ m!^\+\+\+!;
4069 sub git_blobdiff_plain
{
4070 git_blobdiff
('plain');
4073 sub git_commitdiff
{
4074 my $format = shift || 'html';
4075 $hash ||= $hash_base || "HEAD";
4076 my %co = parse_commit
($hash);
4078 die_error
(undef, "Unknown commit object");
4081 # we need to prepare $formats_nav before any parameter munging
4083 if ($format eq 'html') {
4085 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4086 hash
=>$hash, hash_parent
=>$hash_parent)},
4089 if (defined $hash_parent) {
4090 # commitdiff with two commits given
4091 my $hash_parent_short = $hash_parent;
4092 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4093 $hash_parent_short = substr($hash_parent, 0, 7);
4097 $cgi->a({-href
=> href
(action
=>"commitdiff",
4098 hash
=>$hash_parent)},
4099 esc_html
($hash_parent_short)) .
4101 } elsif (!$co{'parent'}) {
4103 $formats_nav .= ' (initial)';
4104 } elsif (scalar @{$co{'parents'}} == 1) {
4105 # single parent commit
4108 $cgi->a({-href
=> href
(action
=>"commitdiff",
4109 hash
=>$co{'parent'})},
4110 esc_html
(substr($co{'parent'}, 0, 7))) .
4117 $cgi->a({-href
=> href
(action
=>"commitdiff",
4119 esc_html
(substr($_, 0, 7)));
4120 } @{$co{'parents'}} ) .
4125 if (!defined $hash_parent) {
4126 $hash_parent = $co{'parent'} || '--root';
4132 if ($format eq 'html') {
4133 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4134 "--no-commit-id", "--patch-with-raw", "--full-index",
4135 $hash_parent, $hash, "--"
4136 or die_error
(undef, "Open git-diff-tree failed");
4138 while (my $line = <$fd>) {
4140 # empty line ends raw part of diff-tree output
4142 push @difftree, $line;
4145 } elsif ($format eq 'plain') {
4146 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4147 '-p', $hash_parent, $hash, "--"
4148 or die_error
(undef, "Open git-diff-tree failed");
4151 die_error
(undef, "Unknown commitdiff format");
4154 # non-textual hash id's can be cached
4156 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4160 # write commit message
4161 if ($format eq 'html') {
4162 my $refs = git_get_references
();
4163 my $ref = format_ref_marker
($refs, $co{'id'});
4165 git_header_html
(undef, $expires);
4166 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4167 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4168 git_print_authorship
(\
%co);
4169 print "<div class=\"page_body\">\n";
4170 if (@{$co{'comment'}} > 1) {
4171 print "<div class=\"log\">\n";
4172 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4173 print "</div>\n"; # class="log"
4176 } elsif ($format eq 'plain') {
4177 my $refs = git_get_references
("tags");
4178 my $tagname = git_get_rev_name_tags
($hash);
4179 my $filename = basename
($project) . "-$hash.patch";
4182 -type
=> 'text/plain',
4183 -charset
=> 'utf-8',
4184 -expires
=> $expires,
4185 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4186 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4189 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4190 Subject: $co{'title'}
4192 print "X-Git-Tag: $tagname\n" if $tagname;
4193 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4195 foreach my $line (@{$co{'comment'}}) {
4202 if ($format eq 'html') {
4203 git_difftree_body
(\
@difftree, $hash, $hash_parent);
4206 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
4208 print "</div>\n"; # class="page_body"
4211 } elsif ($format eq 'plain') {
4215 or print "Reading git-diff-tree failed\n";
4219 sub git_commitdiff_plain
{
4220 git_commitdiff
('plain');
4224 if (!defined $hash_base) {
4225 $hash_base = git_get_head_hash
($project);
4227 if (!defined $page) {
4231 my %co = parse_commit
($hash_base);
4233 die_error
(undef, "Unknown commit object");
4236 my $refs = git_get_references
();
4237 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4239 if (!defined $hash && defined $file_name) {
4240 $hash = git_get_hash_by_path
($hash_base, $file_name);
4242 if (defined $hash) {
4243 $ftype = git_get_type
($hash);
4246 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4248 my $paging_nav = '';
4251 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4252 file_name
=>$file_name)},
4254 $paging_nav .= " ⋅ " .
4255 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4256 file_name
=>$file_name, page
=>$page-1),
4257 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4259 $paging_nav .= "first";
4260 $paging_nav .= " ⋅ prev";
4262 if ($#commitlist >= 100) {
4263 $paging_nav .= " ⋅ " .
4264 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4265 file_name
=>$file_name, page
=>$page+1),
4266 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4268 $paging_nav .= " ⋅ next";
4271 if ($#commitlist >= 100) {
4273 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4274 file_name
=>$file_name, page
=>$page+1),
4275 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4279 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4280 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4281 git_print_page_path
($file_name, $ftype, $hash_base);
4283 git_history_body
(\
@commitlist, 0, 99,
4284 $refs, $hash_base, $ftype, $next_link);
4290 my ($have_search) = gitweb_check_feature
('search');
4291 if (!$have_search) {
4292 die_error
('403 Permission denied', "Permission denied");
4294 if (!defined $searchtext) {
4295 die_error
(undef, "Text field empty");
4297 if (!defined $hash) {
4298 $hash = git_get_head_hash
($project);
4300 my %co = parse_commit
($hash);
4302 die_error
(undef, "Unknown commit object");
4304 if (!defined $page) {
4308 $searchtype ||= 'commit';
4309 if ($searchtype eq 'pickaxe') {
4310 # pickaxe may take all resources of your box and run for several minutes
4311 # with every query - so decide by yourself how public you make this feature
4312 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4313 if (!$have_pickaxe) {
4314 die_error
('403 Permission denied', "Permission denied");
4320 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4322 if ($searchtype eq 'commit') {
4323 $greptype = "--grep=";
4324 } elsif ($searchtype eq 'author') {
4325 $greptype = "--author=";
4326 } elsif ($searchtype eq 'committer') {
4327 $greptype = "--committer=";
4329 $greptype .= $searchtext;
4330 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4332 my $paging_nav = '';
4335 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4336 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4338 $paging_nav .= " ⋅ " .
4339 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4340 searchtext
=>$searchtext, searchtype
=>$searchtype,
4342 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4344 $paging_nav .= "first";
4345 $paging_nav .= " ⋅ prev";
4347 if ($#commitlist >= 100) {
4348 $paging_nav .= " ⋅ " .
4349 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4350 searchtext
=>$searchtext, searchtype
=>$searchtype,
4352 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4354 $paging_nav .= " ⋅ next";
4357 if ($#commitlist >= 100) {
4359 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4360 searchtext
=>$searchtext, searchtype
=>$searchtype,
4362 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4365 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4366 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4367 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4370 if ($searchtype eq 'pickaxe') {
4371 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4372 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4374 print "<table cellspacing=\"0\">\n";
4377 my $git_command = git_cmd_str
();
4378 open my $fd, "-|", "$git_command rev-list $hash | " .
4379 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
4382 while (my $line = <$fd>) {
4383 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4386 $set{'from_id'} = $3;
4388 $set{'id'} = $set{'to_id'};
4389 if ($set{'id'} =~ m/0{40}/) {
4390 $set{'id'} = $set{'from_id'};
4392 if ($set{'id'} =~ m/0{40}/) {
4396 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4399 print "<tr class=\"dark\">\n";
4401 print "<tr class=\"light\">\n";
4404 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4405 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4407 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4408 -class => "list subject"},
4409 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4410 while (my $setref = shift @files) {
4412 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4413 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4415 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4419 "<td class=\"link\">" .
4420 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4422 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4426 %co = parse_commit
($1);
4436 sub git_search_help
{
4438 git_print_page_nav
('','', $hash,$hash,$hash);
4441 <dt><b>commit</b></dt>
4442 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4443 <dt><b>author</b></dt>
4444 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4445 <dt><b>committer</b></dt>
4446 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4448 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4449 if ($have_pickaxe) {
4451 <dt><b>pickaxe</b></dt>
4452 <dd>All commits that caused the string to appear or disappear from any file (changes that
4453 added, removed or "modified" the string) will be listed. This search can take a while and
4454 takes a lot of strain on the server, so please use it wisely.</dd>
4462 my $head = git_get_head_hash
($project);
4463 if (!defined $hash) {
4466 if (!defined $page) {
4469 my $refs = git_get_references
();
4471 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4473 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
4475 if ($#commitlist >= 100) {
4477 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4478 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4482 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4483 git_print_header_div
('summary', $project);
4485 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
4490 ## ......................................................................
4491 ## feeds (RSS, Atom; OPML)
4494 my $format = shift || 'atom';
4495 my ($have_blame) = gitweb_check_feature
('blame');
4497 # Atom: http://www.atomenabled.org/developers/syndication/
4498 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4499 if ($format ne 'rss' && $format ne 'atom') {
4500 die_error
(undef, "Unknown web feed format");
4503 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4504 my $head = $hash || 'HEAD';
4505 my @commitlist = parse_commits
($head, 150);
4509 my $content_type = "application/$format+xml";
4510 if (defined $cgi->http('HTTP_ACCEPT') &&
4511 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4512 # browser (feed reader) prefers text/xml
4513 $content_type = 'text/xml';
4515 if (defined($commitlist[0])) {
4516 %latest_commit = %{$commitlist[0]};
4517 %latest_date = parse_date
($latest_commit{'author_epoch'});
4519 -type
=> $content_type,
4520 -charset
=> 'utf-8',
4521 -last_modified
=> $latest_date{'rfc2822'});
4524 -type
=> $content_type,
4525 -charset
=> 'utf-8');
4528 # Optimization: skip generating the body if client asks only
4529 # for Last-Modified date.
4530 return if ($cgi->request_method() eq 'HEAD');
4533 my $title = "$site_name - $project/$action";
4534 my $feed_type = 'log';
4535 if (defined $hash) {
4536 $title .= " - '$hash'";
4537 $feed_type = 'branch log';
4538 if (defined $file_name) {
4539 $title .= " :: $file_name";
4540 $feed_type = 'history';
4542 } elsif (defined $file_name) {
4543 $title .= " - $file_name";
4544 $feed_type = 'history';
4546 $title .= " $feed_type";
4547 my $descr = git_get_project_description
($project);
4548 if (defined $descr) {
4549 $descr = esc_html
($descr);
4551 $descr = "$project " .
4552 ($format eq 'rss' ? 'RSS' : 'Atom') .
4555 my $owner = git_get_project_owner
($project);
4556 $owner = esc_html
($owner);
4560 if (defined $file_name) {
4561 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
4562 } elsif (defined $hash) {
4563 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
4565 $alt_url = href
(-full
=>1, action
=>"summary");
4567 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
4568 if ($format eq 'rss') {
4570 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
4573 print "<title>$title</title>\n" .
4574 "<link>$alt_url</link>\n" .
4575 "<description>$descr</description>\n" .
4576 "<language>en</language>\n";
4577 } elsif ($format eq 'atom') {
4579 <feed xmlns="http://www.w3.org/2005/Atom">
4581 print "<title>$title</title>\n" .
4582 "<subtitle>$descr</subtitle>\n" .
4583 '<link rel="alternate" type="text/html" href="' .
4584 $alt_url . '" />' . "\n" .
4585 '<link rel="self" type="' . $content_type . '" href="' .
4586 $cgi->self_url() . '" />' . "\n" .
4587 "<id>" . href
(-full
=>1) . "</id>\n" .
4588 # use project owner for feed author
4589 "<author><name>$owner</name></author>\n";
4590 if (defined $favicon) {
4591 print "<icon>" . esc_url
($favicon) . "</icon>\n";
4593 if (defined $logo_url) {
4594 # not twice as wide as tall: 72 x 27 pixels
4595 print "<logo>" . esc_url
($logo) . "</logo>\n";
4597 if (! %latest_date) {
4598 # dummy date to keep the feed valid until commits trickle in:
4599 print "<updated>1970-01-01T00:00:00Z</updated>\n";
4601 print "<updated>$latest_date{'iso-8601'}</updated>\n";
4606 for (my $i = 0; $i <= $#commitlist; $i++) {
4607 my %co = %{$commitlist[$i]};
4608 my $commit = $co{'id'};
4609 # we read 150, we always show 30 and the ones more recent than 48 hours
4610 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
4613 my %cd = parse_date
($co{'author_epoch'});
4615 # get list of changed files
4616 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4617 $co{'parent'}, $co{'id'}, "--", (defined $file_name ? $file_name : ())
4619 my @difftree = map { chomp; $_ } <$fd>;
4623 # print element (entry, item)
4624 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
4625 if ($format eq 'rss') {
4627 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
4628 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
4629 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
4630 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
4631 "<link>$co_url</link>\n" .
4632 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
4633 "<content:encoded>" .
4635 } elsif ($format eq 'atom') {
4637 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
4638 "<updated>$cd{'iso-8601'}</updated>\n" .
4640 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
4641 if ($co{'author_email'}) {
4642 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
4644 print "</author>\n" .
4645 # use committer for contributor
4647 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
4648 if ($co{'committer_email'}) {
4649 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
4651 print "</contributor>\n" .
4652 "<published>$cd{'iso-8601'}</published>\n" .
4653 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
4654 "<id>$co_url</id>\n" .
4655 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
4656 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
4658 my $comment = $co{'comment'};
4660 foreach my $line (@$comment) {
4661 $line = esc_html
($line);
4664 print "</pre><ul>\n";
4665 foreach my $difftree_line (@difftree) {
4666 my %difftree = parse_difftree_raw_line
($difftree_line);
4667 next if !$difftree{'from_id'};
4669 my $file = $difftree{'file'} || $difftree{'to_file'};
4673 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
4674 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
4675 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
4676 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
4677 -title
=> "diff"}, 'D');
4679 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
4680 file_name
=>$file, hash_base
=>$commit),
4681 -title
=> "blame"}, 'B');
4683 # if this is not a feed of a file history
4684 if (!defined $file_name || $file_name ne $file) {
4685 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
4686 file_name
=>$file, hash
=>$commit),
4687 -title
=> "history"}, 'H');
4689 $file = esc_path
($file);
4693 if ($format eq 'rss') {
4694 print "</ul>]]>\n" .
4695 "</content:encoded>\n" .
4697 } elsif ($format eq 'atom') {
4698 print "</ul>\n</div>\n" .
4705 if ($format eq 'rss') {
4706 print "</channel>\n</rss>\n";
4707 } elsif ($format eq 'atom') {
4721 my @list = git_get_projects_list
();
4723 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
4725 <?xml version="1.0" encoding="utf-8"?>
4726 <opml version="1.0">
4728 <title>$site_name OPML Export</title>
4731 <outline text="git RSS feeds">
4734 foreach my $pr (@list) {
4736 my $head = git_get_head_hash
($proj{'path'});
4737 if (!defined $head) {
4740 $git_dir = "$projectroot/$proj{'path'}";
4741 my %co = parse_commit
($head);
4746 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
4747 my $rss = "$my_url?p=$proj{'path'};a=rss";
4748 my $html = "$my_url?p=$proj{'path'};a=summary";
4749 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";