3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI qw(:standard :escapeHTML -nosticky);
13 use CGI::Util qw(unescape);
14 use CGI::Carp qw(fatalsToBrowser);
18 use File::Basename qw(basename);
19 binmode STDOUT, ':utf8';
22 CGI->compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute => 1);
30 # core git executable to use
31 # this can just be "git" if your webserver has a sensible PATH
32 our $GIT = "++GIT_BINDIR++/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "++GITWEB_PROJECTROOT++";
38 # target of the home link on top of all pages
39 our $home_link = $my_uri || "/";
41 # string of the home link on top of all pages
42 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
44 # name of your site or organization to appear in page titles
45 # replace this with something more descriptive for clearer bookmarks
46 our $site_name = "++GITWEB_SITENAME++"
47 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
49 # filename of html text to include at top of each page
50 our $site_header = "++GITWEB_SITE_HEADER++";
51 # html text to include at home page
52 our $home_text = "++GITWEB_HOMETEXT++";
53 # filename of html text to include at bottom of each page
54 our $site_footer = "++GITWEB_SITE_FOOTER++";
57 our @stylesheets = ("++GITWEB_CSS++");
58 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
59 our $stylesheet = undef;
60 # URI of GIT logo (72x27 size)
61 our $logo = "++GITWEB_LOGO++";
62 # URI of GIT favicon, assumed to be image/png type
63 our $favicon = "++GITWEB_FAVICON++";
65 # URI and label (title) of GIT logo link
66 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
67 #our $logo_label = "git documentation";
68 our $logo_url = "http://git.or.cz/";
69 our $logo_label = "git homepage";
71 # source of projects list
72 our $projects_list = "++GITWEB_LIST++";
74 # default order of projects list
75 # valid values are none, project, descr, owner, and age
76 our $default_projects_order = "project";
78 # show repository only if this file exists
79 # (only effective if this variable evaluates to true)
80 our $export_ok = "++GITWEB_EXPORT_OK++";
82 # only allow viewing of repositories also shown on the overview page
83 our $strict_export = "++GITWEB_STRICT_EXPORT++";
85 # list of git base URLs used for URL to where fetch project from,
86 # i.e. full URL is "$git_base_url/$project"
87 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
89 # default blob_plain mimetype and default charset for text/plain blob
90 our $default_blob_plain_mimetype = 'text/plain';
91 our $default_text_plain_charset = undef;
93 # file to use for guessing MIME types before trying /etc/mime.types
94 # (relative to the current git repository)
95 our $mimetypes_file = undef;
97 # You define site-wide feature defaults here; override them with
98 # $GITWEB_CONFIG as necessary.
101 # 'sub' => feature-sub (subroutine),
102 # 'override' => allow-override (boolean),
103 # 'default' => [ default options...] (array reference)}
105 # if feature is overridable (it means that allow-override has true value),
106 # then feature-sub will be called with default options as parameters;
107 # return value of feature-sub indicates if to enable specified feature
109 # if there is no 'sub' key (no feature-sub), then feature cannot be
112 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
114 # Enable the 'blame' blob view, showing the last commit that modified
115 # each line in the file. This can be very CPU-intensive.
117 # To enable system wide have in $GITWEB_CONFIG
118 # $feature{'blame'}{'default'} = [1];
119 # To have project specific config enable override in $GITWEB_CONFIG
120 # $feature{'blame'}{'override'} = 1;
121 # and in project config gitweb.blame = 0|1;
123 'sub' => \&feature_blame,
127 # Enable the 'snapshot' link, providing a compressed tarball of any
128 # tree. This can potentially generate high traffic if you have large
131 # To disable system wide have in $GITWEB_CONFIG
132 # $feature{'snapshot'}{'default'} = [undef];
133 # To have project specific config enable override in $GITWEB_CONFIG
134 # $feature{'snapshot'}{'override'} = 1;
135 # and in project config gitweb.snapshot = none|gzip|bzip2;
137 'sub' => \&feature_snapshot,
139 # => [content-encoding, suffix, program]
140 'default' => ['x-gzip', 'gz', 'gzip']},
142 # Enable text search, which will list the commits which match author,
143 # committer or commit text to a given string. Enabled by default.
144 # Project specific override is not supported.
149 # Enable the pickaxe search, which will list the commits that modified
150 # a given string in a file. This can be practical and quite faster
151 # alternative to 'blame', but still potentially CPU-intensive.
153 # To enable system wide have in $GITWEB_CONFIG
154 # $feature{'pickaxe'}{'default'} = [1];
155 # To have project specific config enable override in $GITWEB_CONFIG
156 # $feature{'pickaxe'}{'override'} = 1;
157 # and in project config gitweb.pickaxe = 0|1;
159 'sub' => \&feature_pickaxe,
163 # Make gitweb use an alternative format of the URLs which can be
164 # more readable and natural-looking: project name is embedded
165 # directly in the path and the query string contains other
166 # auxiliary information. All gitweb installations recognize
167 # URL in either format; this configures in which formats gitweb
170 # To enable system wide have in $GITWEB_CONFIG
171 # $feature{'pathinfo'}{'default'} = [1];
172 # Project specific override is not supported.
174 # Note that you will need to change the default location of CSS,
175 # favicon, logo and possibly other files to an absolute URL. Also,
176 # if gitweb.cgi serves as your indexfile, you will need to force
177 # $my_uri to contain the script name in your $GITWEB_CONFIG.
182 # Make gitweb consider projects in project root subdirectories
183 # to be forks of existing projects. Given project $projname.git,
184 # projects matching $projname/*.git will not be shown in the main
185 # projects list, instead a '+' mark will be added to $projname
186 # there and a 'forks' view will be enabled for the project, listing
187 # all the forks. If project list is taken from a file, forks have
188 # to be listed after the main project.
190 # To enable system wide have in $GITWEB_CONFIG
191 # $feature{'forks'}{'default'} = [1];
192 # Project specific override is not supported.
198 sub gitweb_check_feature {
200 return unless exists $feature{$name};
201 my ($sub, $override, @defaults) = (
202 $feature{$name}{'sub'},
203 $feature{$name}{'override'},
204 @{$feature{$name}{'default'}});
205 if (!$override) { return @defaults; }
207 warn "feature $name is not overrideable";
210 return $sub->(@defaults);
214 my ($val) = git_get_project_config('blame', '--bool');
216 if ($val eq 'true') {
218 } elsif ($val eq 'false') {
225 sub feature_snapshot {
226 my ($ctype, $suffix, $command) = @_;
228 my ($val) = git_get_project_config('snapshot');
230 if ($val eq 'gzip') {
231 return ('x-gzip', 'gz', 'gzip');
232 } elsif ($val eq 'bzip2') {
233 return ('x-bzip2', 'bz2', 'bzip2');
234 } elsif ($val eq 'none') {
238 return ($ctype, $suffix, $command);
241 sub gitweb_have_snapshot {
242 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
243 my $have_snapshot = (defined $ctype && defined $suffix);
245 return $have_snapshot;
248 sub feature_pickaxe {
249 my ($val) = git_get_project_config('pickaxe', '--bool');
251 if ($val eq 'true') {
253 } elsif ($val eq 'false') {
260 # checking HEAD file with -e is fragile if the repository was
261 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
263 sub check_head_link {
265 my $headfile = "$dir/HEAD";
266 return ((-e $headfile) ||
267 (-l $headfile && readlink($headfile) =~ /^refs\/heads\//));
270 sub check_export_ok {
272 return (check_head_link($dir) &&
273 (!$export_ok || -e "$dir/$export_ok"));
276 # rename detection options for git-diff and git-diff-tree
277 # - default is '-M', with the cost proportional to
278 # (number of removed files) * (number of new files).
279 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
280 # (number of changed files + number of removed files) * (number of new files)
281 # - even more costly is '-C', '--find-copies-harder' with cost
282 # (number of files in the original tree) * (number of new files)
283 # - one might want to include '-B' option, e.g. '-B', '-M'
284 our @diff_opts = ('-M'); # taken from git_commit
286 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
287 do $GITWEB_CONFIG if -e $GITWEB_CONFIG;
289 # version of the core git binary
290 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
292 $projects_list ||= $projectroot;
294 # ======================================================================
295 # input validation and dispatch
296 our $action = $cgi->param('a');
297 if (defined $action) {
298 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
299 die_error(undef, "Invalid action parameter");
303 # parameters which are pathnames
304 our $project = $cgi->param('p');
305 if (defined $project) {
306 if (!validate_pathname($project) ||
307 !(-d "$projectroot/$project") ||
308 !check_head_link("$projectroot/$project") ||
309 ($export_ok && !(-e "$projectroot/$project/$export_ok")) ||
310 ($strict_export && !project_in_list($project))) {
312 die_error(undef, "No such project");
316 our $file_name = $cgi->param('f');
317 if (defined $file_name) {
318 if (!validate_pathname($file_name)) {
319 die_error(undef, "Invalid file parameter");
323 our $file_parent = $cgi->param('fp');
324 if (defined $file_parent) {
325 if (!validate_pathname($file_parent)) {
326 die_error(undef, "Invalid file parent parameter");
330 # parameters which are refnames
331 our $hash = $cgi->param('h');
333 if (!validate_refname($hash)) {
334 die_error(undef, "Invalid hash parameter");
338 our $hash_parent = $cgi->param('hp');
339 if (defined $hash_parent) {
340 if (!validate_refname($hash_parent)) {
341 die_error(undef, "Invalid hash parent parameter");
345 our $hash_base = $cgi->param('hb');
346 if (defined $hash_base) {
347 if (!validate_refname($hash_base)) {
348 die_error(undef, "Invalid hash base parameter");
352 our $hash_parent_base = $cgi->param('hpb');
353 if (defined $hash_parent_base) {
354 if (!validate_refname($hash_parent_base)) {
355 die_error(undef, "Invalid hash parent base parameter");
360 our $page = $cgi->param('pg');
362 if ($page =~ m/[^0-9]/) {
363 die_error(undef, "Invalid page parameter");
367 our $searchtext = $cgi->param('s');
369 if (defined $searchtext) {
370 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) {
371 die_error(undef, "Invalid search parameter");
373 if (length($searchtext) < 2) {
374 die_error(undef, "At least two characters are required for search parameter");
376 $search_regexp = quotemeta $searchtext;
379 our $searchtype = $cgi->param('st');
380 if (defined $searchtype) {
381 if ($searchtype =~ m/[^a-z]/) {
382 die_error(undef, "Invalid searchtype parameter");
386 # now read PATH_INFO and use it as alternative to parameters
387 sub evaluate_path_info {
388 return if defined $project;
389 my $path_info = $ENV{"PATH_INFO"};
390 return if !$path_info;
391 $path_info =~ s,^/+,,;
392 return if !$path_info;
393 # find which part of PATH_INFO is project
394 $project = $path_info;
396 while ($project && !check_head_link("$projectroot/$project")) {
397 $project =~ s,/*[^/]*$,,;
400 $project = validate_pathname($project);
402 ($export_ok && !-e "$projectroot/$project/$export_ok") ||
403 ($strict_export && !project_in_list($project))) {
407 # do not change any parameters if an action is given using the query string
409 $path_info =~ s,^$project/*,,;
410 my ($refname, $pathname) = split(/:/, $path_info, 2);
411 if (defined $pathname) {
412 # we got "project.git/branch:filename" or "project.git/branch:dir/"
413 # we could use git_get_type(branch:pathname), but it needs $git_dir
414 $pathname =~ s,^/+,,;
415 if (!$pathname || substr($pathname, -1) eq "/") {
419 $action ||= "blob_plain";
421 $hash_base ||= validate_refname($refname);
422 $file_name ||= validate_pathname($pathname);
423 } elsif (defined $refname) {
424 # we got "project.git/branch"
425 $action ||= "shortlog";
426 $hash ||= validate_refname($refname);
429 evaluate_path_info();
431 # path to the current git repository
433 $git_dir = "$projectroot/$project" if $project;
437 "blame" => \&git_blame2,
438 "blobdiff" => \&git_blobdiff,
439 "blobdiff_plain" => \&git_blobdiff_plain,
440 "blob" => \&git_blob,
441 "blob_plain" => \&git_blob_plain,
442 "commitdiff" => \&git_commitdiff,
443 "commitdiff_plain" => \&git_commitdiff_plain,
444 "commit" => \&git_commit,
445 "forks" => \&git_forks,
446 "heads" => \&git_heads,
447 "history" => \&git_history,
450 "atom" => \&git_atom,
451 "search" => \&git_search,
452 "search_help" => \&git_search_help,
453 "shortlog" => \&git_shortlog,
454 "summary" => \&git_summary,
456 "tags" => \&git_tags,
457 "tree" => \&git_tree,
458 "snapshot" => \&git_snapshot,
459 "object" => \&git_object,
460 # those below don't need $project
461 "opml" => \&git_opml,
462 "project_list" => \&git_project_list,
463 "project_index" => \&git_project_index,
466 if (!defined $action) {
468 $action = git_get_type($hash);
469 } elsif (defined $hash_base && defined $file_name) {
470 $action = git_get_type("$hash_base:$file_name");
471 } elsif (defined $project) {
474 $action = 'project_list';
477 if (!defined($actions{$action})) {
478 die_error(undef, "Unknown action");
480 if ($action !~ m/^(opml|project_list|project_index)$/ &&
482 die_error(undef, "Project needed");
484 $actions{$action}->();
487 ## ======================================================================
492 # default is to use -absolute url() i.e. $my_uri
493 my $href = $params{-full} ? $my_url : $my_uri;
495 # XXX: Warning: If you touch this, check the search form for updating,
506 hash_parent_base => "hpb",
512 my %mapping = @mapping;
514 $params{'project'} = $project unless exists $params{'project'};
516 my ($use_pathinfo) = gitweb_check_feature('pathinfo');
518 # use PATH_INFO for project name
519 $href .= "/$params{'project'}" if defined $params{'project'};
520 delete $params{'project'};
522 # Summary just uses the project path URL
523 if (defined $params{'action'} && $params{'action'} eq 'summary') {
524 delete $params{'action'};
528 # now encode the parameters explicitly
530 for (my $i = 0; $i < @mapping; $i += 2) {
531 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
532 if (defined $params{$name}) {
533 push @result, $symbol . "=" . esc_param($params{$name});
536 $href .= "?" . join(';', @result) if scalar @result;
542 ## ======================================================================
543 ## validation, quoting/unquoting and escaping
545 sub validate_pathname {
546 my $input = shift || return undef;
548 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
549 # at the beginning, at the end, and between slashes.
550 # also this catches doubled slashes
551 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
555 if ($input =~ m!\0!) {
561 sub validate_refname {
562 my $input = shift || return undef;
564 # textual hashes are O.K.
565 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
568 # it must be correct pathname
569 $input = validate_pathname($input)
571 # restrictions on ref name according to git-check-ref-format
572 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
578 # quote unsafe chars, but keep the slash, even when it's not
579 # correct, but quoted slashes look too horrible in bookmarks
582 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf("%%%02X", ord($1))/eg;
588 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
591 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
597 # replace invalid utf8 character with SUBSTITUTION sequence
602 $str = decode_utf8($str);
603 $str = $cgi->escapeHTML($str);
604 if ($opts{'-nbsp'}) {
605 $str =~ s/ / /g;
607 $str =~ s|([[:cntrl:]])|(($1 ne "\t") ? quot_cec($1) : $1)|eg;
611 # quote control characters and escape filename to HTML
616 $str = decode_utf8($str);
617 $str = $cgi->escapeHTML($str);
618 if ($opts{'-nbsp'}) {
619 $str =~ s/ / /g;
621 $str =~ s|([[:cntrl:]])|quot_cec($1)|eg;
625 # Make control characters "printable", using character escape codes (CEC)
628 my %es = ( # character escape codes, aka escape sequences
629 "\t" => '\t', # tab (HT)
630 "\n" => '\n', # line feed (LF)
631 "\r" => '\r', # carrige return (CR)
632 "\f" => '\f', # form feed (FF)
633 "\b" => '\b', # backspace (BS)
634 "\a" => '\a', # alarm (bell) (BEL)
635 "\e" => '\e', # escape (ESC)
636 "\013" => '\v', # vertical tab (VT)
637 "\000" => '\0', # nul character (NUL)
639 my $chr = ( (exists $es{$cntrl})
641 : sprintf('\%03o', ord($cntrl)) );
642 return "<span class=\"cntrl\">$chr</span>";
645 # Alternatively use unicode control pictures codepoints,
646 # Unicode "printable representation" (PR)
649 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
650 return "<span class=\"cntrl\">$chr</span>";
653 # git may return quoted and escaped filenames
659 my %es = ( # character escape codes, aka escape sequences
660 't' => "\t", # tab (HT, TAB)
661 'n' => "\n", # newline (NL)
662 'r' => "\r", # return (CR)
663 'f' => "\f", # form feed (FF)
664 'b' => "\b", # backspace (BS)
665 'a' => "\a", # alarm (bell) (BEL)
666 'e' => "\e", # escape (ESC)
667 'v' => "\013", # vertical tab (VT)
670 if ($seq =~ m/^[0-7]{1,3}$/) {
671 # octal char sequence
672 return chr(oct($seq));
673 } elsif (exists $es{$seq}) {
674 # C escape sequence, aka character escape code
677 # quoted ordinary character
681 if ($str =~ m/^"(.*)"$/) {
684 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
689 # escape tabs (convert tabs to spaces)
693 while ((my $pos = index($line, "\t")) != -1) {
694 if (my $count = (8 - ($pos % 8))) {
695 my $spaces = ' ' x $count;
696 $line =~ s/\t/$spaces/;
703 sub project_in_list {
705 my @list = git_get_projects_list();
706 return @list && scalar(grep { $_->{'path'} eq $project } @list);
709 ## ----------------------------------------------------------------------
710 ## HTML aware string manipulation
715 my $add_len = shift || 10;
717 # allow only $len chars, but don't cut a word if it would fit in $add_len
718 # if it doesn't fit, cut it if it's still longer than the dots we would add
719 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
722 if (length($tail) > 4) {
724 $body =~ s/&[^;]*$//; # remove chopped character entities
729 ## ----------------------------------------------------------------------
730 ## functions returning short strings
732 # CSS class for given age value (in seconds)
738 } elsif ($age < 60*60*2) {
740 } elsif ($age < 60*60*24*2) {
747 # convert age in seconds to "nn units ago" string
752 if ($age > 60*60*24*365*2) {
753 $age_str = (int $age/60/60/24/365);
754 $age_str .= " years ago";
755 } elsif ($age > 60*60*24*(365/12)*2) {
756 $age_str = int $age/60/60/24/(365/12);
757 $age_str .= " months ago";
758 } elsif ($age > 60*60*24*7*2) {
759 $age_str = int $age/60/60/24/7;
760 $age_str .= " weeks ago";
761 } elsif ($age > 60*60*24*2) {
762 $age_str = int $age/60/60/24;
763 $age_str .= " days ago";
764 } elsif ($age > 60*60*2) {
765 $age_str = int $age/60/60;
766 $age_str .= " hours ago";
767 } elsif ($age > 60*2) {
768 $age_str = int $age/60;
769 $age_str .= " min ago";
772 $age_str .= " sec ago";
774 $age_str .= " right now";
779 # convert file mode in octal to symbolic file mode string
781 my $mode = oct shift;
783 if (S_ISDIR($mode & S_IFMT)) {
785 } elsif (S_ISLNK($mode)) {
787 } elsif (S_ISREG($mode)) {
788 # git cares only about the executable bit
789 if ($mode & S_IXUSR) {
799 # convert file mode in octal to file type string
803 if ($mode !~ m/^[0-7]+$/) {
809 if (S_ISDIR($mode & S_IFMT)) {
811 } elsif (S_ISLNK($mode)) {
813 } elsif (S_ISREG($mode)) {
820 # convert file mode in octal to file type description string
824 if ($mode !~ m/^[0-7]+$/) {
830 if (S_ISDIR($mode & S_IFMT)) {
832 } elsif (S_ISLNK($mode)) {
834 } elsif (S_ISREG($mode)) {
835 if ($mode & S_IXUSR) {
846 ## ----------------------------------------------------------------------
847 ## functions returning short HTML fragments, or transforming HTML fragments
848 ## which don't belong to other sections
850 # format line of commit message.
851 sub format_log_line_html {
854 $line = esc_html($line, -nbsp=>1);
855 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
858 $cgi->a({-href => href(action=>"object", hash=>$hash_text),
859 -class => "text"}, $hash_text);
860 $line =~ s/$hash_text/$link/;
865 # format marker of refs pointing to given object
866 sub format_ref_marker {
867 my ($refs, $id) = @_;
870 if (defined $refs->{$id}) {
871 foreach my $ref (@{$refs->{$id}}) {
872 my ($type, $name) = qw();
873 # e.g. tags/v2.6.11 or heads/next
874 if ($ref =~ m!^(.*?)s?/(.*)$!) {
882 $markers .= " <span class=\"$type\" title=\"$ref\">" .
883 esc_html($name) . "</span>";
888 return ' <span class="refs">'. $markers . '</span>';
894 # format, perhaps shortened and with markers, title line
895 sub format_subject_html {
896 my ($long, $short, $href, $extra) = @_;
897 $extra = '' unless defined($extra);
899 if (length($short) < length($long)) {
900 return $cgi->a({-href => $href, -class => "list subject",
901 -title => decode_utf8($long)},
902 esc_html($short) . $extra);
904 return $cgi->a({-href => $href, -class => "list subject"},
905 esc_html($long) . $extra);
909 # format patch (diff) line (rather not to be used for diff headers)
910 sub format_diff_line {
912 my ($from, $to) = @_;
917 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
919 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
920 if ($line =~ m/^\@{3}/) {
921 $diff_class = " chunk_header";
922 } elsif ($line =~ m/^\\/) {
923 $diff_class = " incomplete";
924 } elsif ($prefix =~ tr/+/+/) {
925 $diff_class = " add";
926 } elsif ($prefix =~ tr/-/-/) {
927 $diff_class = " rem";
930 # assume ordinary diff
931 my $char = substr($line, 0, 1);
933 $diff_class = " add";
934 } elsif ($char eq '-') {
935 $diff_class = " rem";
936 } elsif ($char eq '@') {
937 $diff_class = " chunk_header";
938 } elsif ($char eq "\\") {
939 $diff_class = " incomplete";
942 $line = untabify($line);
943 if ($from && $to && $line =~ m/^\@{2} /) {
944 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
945 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
947 $from_lines = 0 unless defined $from_lines;
948 $to_lines = 0 unless defined $to_lines;
950 if ($from->{'href'}) {
951 $from_text = $cgi->a({-href=>"$from->{'href'}#l$from_start",
952 -class=>"list"}, $from_text);
955 $to_text = $cgi->a({-href=>"$to->{'href'}#l$to_start",
956 -class=>"list"}, $to_text);
958 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
959 "<span class=\"section\">" . esc_html($section, -nbsp=>1) . "</span>";
960 return "<div class=\"diff$diff_class\">$line</div>\n";
961 } elsif ($from && $to && $line =~ m/^\@{3}/) {
962 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
963 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
965 @from_text = split(' ', $ranges);
966 for (my $i = 0; $i < @from_text; ++$i) {
967 ($from_start[$i], $from_nlines[$i]) =
968 (split(',', substr($from_text[$i], 1)), 0);
971 $to_text = pop @from_text;
972 $to_start = pop @from_start;
973 $to_nlines = pop @from_nlines;
975 $line = "<span class=\"chunk_info\">$prefix ";
976 for (my $i = 0; $i < @from_text; ++$i) {
977 if ($from->{'href'}[$i]) {
978 $line .= $cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",
979 -class=>"list"}, $from_text[$i]);
981 $line .= $from_text[$i];
986 $line .= $cgi->a({-href=>"$to->{'href'}#l$to_start",
987 -class=>"list"}, $to_text);
991 $line .= " $prefix</span>" .
992 "<span class=\"section\">" . esc_html($section, -nbsp=>1) . "</span>";
993 return "<div class=\"diff$diff_class\">$line</div>\n";
995 return "<div class=\"diff$diff_class\">" . esc_html($line, -nbsp=>1) . "</div>\n";
998 ## ----------------------------------------------------------------------
999 ## git utility subroutines, invoking git commands
1001 # returns path to the core git executable and the --git-dir parameter as list
1003 return $GIT, '--git-dir='.$git_dir;
1006 # returns path to the core git executable and the --git-dir parameter as string
1008 return join(' ', git_cmd());
1011 # get HEAD ref of given project as hash
1012 sub git_get_head_hash {
1013 my $project = shift;
1014 my $o_git_dir = $git_dir;
1016 $git_dir = "$projectroot/$project";
1017 if (open my $fd, "-|", git_cmd(), "rev-parse", "--verify", "HEAD") {
1020 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1024 if (defined $o_git_dir) {
1025 $git_dir = $o_git_dir;
1030 # get type of given object
1034 open my $fd, "-|", git_cmd(), "cat-file", '-t', $hash or return;
1036 close $fd or return;
1041 sub git_get_project_config {
1042 my ($key, $type) = @_;
1044 return unless ($key);
1045 $key =~ s/^gitweb\.//;
1046 return if ($key =~ m/\W/);
1048 my @x = (git_cmd(), 'config');
1049 if (defined $type) { push @x, $type; }
1051 push @x, "gitweb.$key";
1057 # get hash of given path at given ref
1058 sub git_get_hash_by_path {
1060 my $path = shift || return undef;
1065 open my $fd, "-|", git_cmd(), "ls-tree", $base, "--", $path
1066 or die_error(undef, "Open git-ls-tree failed");
1068 close $fd or return undef;
1070 if (!defined $line) {
1071 # there is no tree or hash given by $path at $base
1075 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1076 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1077 if (defined $type && $type ne $2) {
1078 # type doesn't match
1084 # get path of entry with given hash at given tree-ish (ref)
1085 # used to get 'from' filename for combined diff (merge commit) for renames
1086 sub git_get_path_by_hash {
1087 my $base = shift || return;
1088 my $hash = shift || return;
1092 open my $fd, "-|", git_cmd(), "ls-tree", '-r', '-t', '-z', $base
1094 while (my $line = <$fd>) {
1097 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1098 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1099 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1108 ## ......................................................................
1109 ## git utility functions, directly accessing git repository
1111 sub git_get_project_description {
1114 open my $fd, "$projectroot/$path/description" or return undef;
1121 sub git_get_project_url_list {
1124 open my $fd, "$projectroot/$path/cloneurl" or return;
1125 my @git_project_url_list = map { chomp; $_ } <$fd>;
1128 return wantarray ? @git_project_url_list : \@git_project_url_list;
1131 sub git_get_projects_list {
1136 $filter =~ s/\.git$//;
1138 my ($check_forks) = gitweb_check_feature('forks');
1140 if (-d $projects_list) {
1141 # search in directory
1142 my $dir = $projects_list . ($filter ? "/$filter" : '');
1143 # remove the trailing "/"
1145 my $pfxlen = length("$dir");
1148 follow_fast => 1, # follow symbolic links
1149 dangling_symlinks => 0, # ignore dangling symlinks, silently
1151 # skip project-list toplevel, if we get it.
1152 return if (m!^[/.]$!);
1153 # only directories can be git repositories
1154 return unless (-d $_);
1156 my $subdir = substr($File::Find::name, $pfxlen + 1);
1157 # we check related file in $projectroot
1158 if ($check_forks and $subdir =~ m#/.#) {
1159 $File::Find::prune = 1;
1160 } elsif (check_export_ok("$projectroot/$filter/$subdir")) {
1161 push @list, { path => ($filter ? "$filter/" : '') . $subdir };
1162 $File::Find::prune = 1;
1167 } elsif (-f $projects_list) {
1168 # read from file(url-encoded):
1169 # 'git%2Fgit.git Linus+Torvalds'
1170 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1171 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1173 open my ($fd), $projects_list or return;
1175 while (my $line = <$fd>) {
1177 my ($path, $owner) = split ' ', $line;
1178 $path = unescape($path);
1179 $owner = unescape($owner);
1180 if (!defined $path) {
1183 if ($filter ne '') {
1184 # looking for forks;
1185 my $pfx = substr($path, 0, length($filter));
1186 if ($pfx ne $filter) {
1189 my $sfx = substr($path, length($filter));
1190 if ($sfx !~ /^\/.*\.git$/) {
1193 } elsif ($check_forks) {
1195 foreach my $filter (keys %paths) {
1196 # looking for forks;
1197 my $pfx = substr($path, 0, length($filter));
1198 if ($pfx ne $filter) {
1201 my $sfx = substr($path, length($filter));
1202 if ($sfx !~ /^\/.*\.git$/) {
1205 # is a fork, don't include it in
1210 if (check_export_ok("$projectroot/$path")) {
1213 owner => decode_utf8($owner),
1216 (my $forks_path = $path) =~ s/\.git$//;
1217 $paths{$forks_path}++;
1225 sub git_get_project_owner {
1226 my $project = shift;
1229 return undef unless $project;
1231 # read from file (url-encoded):
1232 # 'git%2Fgit.git Linus+Torvalds'
1233 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1234 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1235 if (-f $projects_list) {
1236 open (my $fd , $projects_list);
1237 while (my $line = <$fd>) {
1239 my ($pr, $ow) = split ' ', $line;
1240 $pr = unescape($pr);
1241 $ow = unescape($ow);
1242 if ($pr eq $project) {
1243 $owner = decode_utf8($ow);
1249 if (!defined $owner) {
1250 $owner = get_file_owner("$projectroot/$project");
1256 sub git_get_last_activity {
1260 $git_dir = "$projectroot/$path";
1261 open($fd, "-|", git_cmd(), 'for-each-ref',
1262 '--format=%(committer)',
1263 '--sort=-committerdate',
1265 'refs/heads') or return;
1266 my $most_recent = <$fd>;
1267 close $fd or return;
1268 if (defined $most_recent &&
1269 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1271 my $age = time - $timestamp;
1272 return ($age, age_string($age));
1276 sub git_get_references {
1277 my $type = shift || "";
1279 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1280 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1281 open my $fd, "-|", git_cmd(), "show-ref", "--dereference",
1282 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1285 while (my $line = <$fd>) {
1287 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1288 if (defined $refs{$1}) {
1289 push @{$refs{$1}}, $2;
1295 close $fd or return;
1299 sub git_get_rev_name_tags {
1300 my $hash = shift || return undef;
1302 open my $fd, "-|", git_cmd(), "name-rev", "--tags", $hash
1304 my $name_rev = <$fd>;
1307 if ($name_rev =~ m|^$hash tags/(.*)$|) {
1310 # catches also '$hash undefined' output
1315 ## ----------------------------------------------------------------------
1316 ## parse to hash functions
1320 my $tz = shift || "-0000";
1323 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1324 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1325 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1326 $date{'hour'} = $hour;
1327 $date{'minute'} = $min;
1328 $date{'mday'} = $mday;
1329 $date{'day'} = $days[$wday];
1330 $date{'month'} = $months[$mon];
1331 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1332 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1333 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1334 $mday, $months[$mon], $hour ,$min;
1335 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1336 1900+$year, $mon, $mday, $hour ,$min, $sec;
1338 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1339 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1340 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1341 $date{'hour_local'} = $hour;
1342 $date{'minute_local'} = $min;
1343 $date{'tz_local'} = $tz;
1344 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1345 1900+$year, $mon+1, $mday,
1346 $hour, $min, $sec, $tz);
1355 open my $fd, "-|", git_cmd(), "cat-file", "tag", $tag_id or return;
1356 $tag{'id'} = $tag_id;
1357 while (my $line = <$fd>) {
1359 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1360 $tag{'object'} = $1;
1361 } elsif ($line =~ m/^type (.+)$/) {
1363 } elsif ($line =~ m/^tag (.+)$/) {
1365 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1366 $tag{'author'} = $1;
1369 } elsif ($line =~ m/--BEGIN/) {
1370 push @comment, $line;
1372 } elsif ($line eq "") {
1376 push @comment, <$fd>;
1377 $tag{'comment'} = \@comment;
1378 close $fd or return;
1379 if (!defined $tag{'name'}) {
1385 sub parse_commit_text {
1386 my ($commit_text, $withparents) = @_;
1387 my @commit_lines = split '\n', $commit_text;
1390 pop @commit_lines; # Remove '\0'
1392 if (! @commit_lines) {
1396 my $header = shift @commit_lines;
1397 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1400 ($co{'id'}, my @parents) = split ' ', $header;
1401 while (my $line = shift @commit_lines) {
1402 last if $line eq "\n";
1403 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1405 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1407 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1409 $co{'author_epoch'} = $2;
1410 $co{'author_tz'} = $3;
1411 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1412 $co{'author_name'} = $1;
1413 $co{'author_email'} = $2;
1415 $co{'author_name'} = $co{'author'};
1417 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1418 $co{'committer'} = $1;
1419 $co{'committer_epoch'} = $2;
1420 $co{'committer_tz'} = $3;
1421 $co{'committer_name'} = $co{'committer'};
1422 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1423 $co{'committer_name'} = $1;
1424 $co{'committer_email'} = $2;
1426 $co{'committer_name'} = $co{'committer'};
1430 if (!defined $co{'tree'}) {
1433 $co{'parents'} = \@parents;
1434 $co{'parent'} = $parents[0];
1436 foreach my $title (@commit_lines) {
1439 $co{'title'} = chop_str($title, 80, 5);
1440 # remove leading stuff of merges to make the interesting part visible
1441 if (length($title) > 50) {
1442 $title =~ s/^Automatic //;
1443 $title =~ s/^merge (of|with) /Merge ... /i;
1444 if (length($title) > 50) {
1445 $title =~ s/(http|rsync):\/\///;
1447 if (length($title) > 50) {
1448 $title =~ s/(master|www|rsync)\.//;
1450 if (length($title) > 50) {
1451 $title =~ s/kernel.org:?//;
1453 if (length($title) > 50) {
1454 $title =~ s/\/pub\/scm//;
1457 $co{'title_short'} = chop_str($title, 50, 5);
1461 if ($co{'title'} eq "") {
1462 $co{'title'} = $co{'title_short'} = '(no commit message)';
1464 # remove added spaces
1465 foreach my $line (@commit_lines) {
1468 $co{'comment'} = \@commit_lines;
1470 my $age = time - $co{'committer_epoch'};
1472 $co{'age_string'} = age_string($age);
1473 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1474 if ($age > 60*60*24*7*2) {
1475 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1476 $co{'age_string_age'} = $co{'age_string'};
1478 $co{'age_string_date'} = $co{'age_string'};
1479 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1485 my ($commit_id) = @_;
1490 open my $fd, "-|", git_cmd(), "rev-list",
1496 or die_error(undef, "Open git-rev-list failed");
1497 %co = parse_commit_text(<$fd>, 1);
1504 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1512 open my $fd, "-|", git_cmd(), "rev-list",
1514 ($arg ? ($arg) : ()),
1515 ("--max-count=" . $maxcount),
1516 ("--skip=" . $skip),
1519 ($filename ? ($filename) : ())
1520 or die_error(undef, "Open git-rev-list failed");
1521 while (my $line = <$fd>) {
1522 my %co = parse_commit_text($line);
1527 return wantarray ? @cos : \@cos;
1530 # parse ref from ref_file, given by ref_id, with given type
1532 my $ref_file = shift;
1534 my $type = shift || git_get_type($ref_id);
1537 $ref_item{'type'} = $type;
1538 $ref_item{'id'} = $ref_id;
1539 $ref_item{'epoch'} = 0;
1540 $ref_item{'age'} = "unknown";
1541 if ($type eq "tag") {
1542 my %tag = parse_tag($ref_id);
1543 $ref_item{'comment'} = $tag{'comment'};
1544 if ($tag{'type'} eq "commit") {
1545 my %co = parse_commit($tag{'object'});
1546 $ref_item{'epoch'} = $co{'committer_epoch'};
1547 $ref_item{'age'} = $co{'age_string'};
1548 } elsif (defined($tag{'epoch'})) {
1549 my $age = time - $tag{'epoch'};
1550 $ref_item{'epoch'} = $tag{'epoch'};
1551 $ref_item{'age'} = age_string($age);
1553 $ref_item{'reftype'} = $tag{'type'};
1554 $ref_item{'name'} = $tag{'name'};
1555 $ref_item{'refid'} = $tag{'object'};
1556 } elsif ($type eq "commit"){
1557 my %co = parse_commit($ref_id);
1558 $ref_item{'reftype'} = "commit";
1559 $ref_item{'name'} = $ref_file;
1560 $ref_item{'title'} = $co{'title'};
1561 $ref_item{'refid'} = $ref_id;
1562 $ref_item{'epoch'} = $co{'committer_epoch'};
1563 $ref_item{'age'} = $co{'age_string'};
1565 $ref_item{'reftype'} = $type;
1566 $ref_item{'name'} = $ref_file;
1567 $ref_item{'refid'} = $ref_id;
1573 # parse line of git-diff-tree "raw" output
1574 sub parse_difftree_raw_line {
1578 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1579 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1580 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1581 $res{'from_mode'} = $1;
1582 $res{'to_mode'} = $2;
1583 $res{'from_id'} = $3;
1585 $res{'status'} = $5;
1586 $res{'similarity'} = $6;
1587 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1588 ($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
1590 $res{'file'} = unquote($7);
1593 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1594 # combined diff (for merge commit)
1595 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1596 $res{'nparents'} = length($1);
1597 $res{'from_mode'} = [ split(' ', $2) ];
1598 $res{'to_mode'} = pop @{$res{'from_mode'}};
1599 $res{'from_id'} = [ split(' ', $3) ];
1600 $res{'to_id'} = pop @{$res{'from_id'}};
1601 $res{'status'} = [ split('', $4) ];
1602 $res{'to_file'} = unquote($5);
1604 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1605 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1606 $res{'commit'} = $1;
1609 return wantarray ? %res : \%res;
1612 # parse line of git-ls-tree output
1613 sub parse_ls_tree_line ($;%) {
1618 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1619 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1627 $res{'name'} = unquote($4);
1630 return wantarray ? %res : \%res;
1633 ## ......................................................................
1634 ## parse to array of hashes functions
1636 sub git_get_heads_list {
1640 open my $fd, '-|', git_cmd(), 'for-each-ref',
1641 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1642 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1645 while (my $line = <$fd>) {
1649 my ($refinfo, $committerinfo) = split(/\0/, $line);
1650 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1651 my ($committer, $epoch, $tz) =
1652 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1653 $name =~ s!^refs/heads/!!;
1655 $ref_item{'name'} = $name;
1656 $ref_item{'id'} = $hash;
1657 $ref_item{'title'} = $title || '(no commit message)';
1658 $ref_item{'epoch'} = $epoch;
1660 $ref_item{'age'} = age_string(time - $ref_item{'epoch'});
1662 $ref_item{'age'} = "unknown";
1665 push @headslist, \%ref_item;
1669 return wantarray ? @headslist : \@headslist;
1672 sub git_get_tags_list {
1676 open my $fd, '-|', git_cmd(), 'for-each-ref',
1677 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1678 '--format=%(objectname) %(objecttype) %(refname) '.
1679 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1682 while (my $line = <$fd>) {
1686 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1687 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1688 my ($creator, $epoch, $tz) =
1689 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1690 $name =~ s!^refs/tags/!!;
1692 $ref_item{'type'} = $type;
1693 $ref_item{'id'} = $id;
1694 $ref_item{'name'} = $name;
1695 if ($type eq "tag") {
1696 $ref_item{'subject'} = $title;
1697 $ref_item{'reftype'} = $reftype;
1698 $ref_item{'refid'} = $refid;
1700 $ref_item{'reftype'} = $type;
1701 $ref_item{'refid'} = $id;
1704 if ($type eq "tag" || $type eq "commit") {
1705 $ref_item{'epoch'} = $epoch;
1707 $ref_item{'age'} = age_string(time - $ref_item{'epoch'});
1709 $ref_item{'age'} = "unknown";
1713 push @tagslist, \%ref_item;
1717 return wantarray ? @tagslist : \@tagslist;
1720 ## ----------------------------------------------------------------------
1721 ## filesystem-related functions
1723 sub get_file_owner {
1726 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1727 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1728 if (!defined $gcos) {
1732 $owner =~ s/[,;].*$//;
1733 return decode_utf8($owner);
1736 ## ......................................................................
1737 ## mimetype related functions
1739 sub mimetype_guess_file {
1740 my $filename = shift;
1741 my $mimemap = shift;
1742 -r $mimemap or return undef;
1745 open(MIME, $mimemap) or return undef;
1747 next if m/^#/; # skip comments
1748 my ($mime, $exts) = split(/\t+/);
1749 if (defined $exts) {
1750 my @exts = split(/\s+/, $exts);
1751 foreach my $ext (@exts) {
1752 $mimemap{$ext} = $mime;
1758 $filename =~ /\.([^.]*)$/;
1759 return $mimemap{$1};
1762 sub mimetype_guess {
1763 my $filename = shift;
1765 $filename =~ /\./ or return undef;
1767 if ($mimetypes_file) {
1768 my $file = $mimetypes_file;
1769 if ($file !~ m!^/!) { # if it is relative path
1770 # it is relative to project
1771 $file = "$projectroot/$project/$file";
1773 $mime = mimetype_guess_file($filename, $file);
1775 $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
1781 my $filename = shift;
1784 my $mime = mimetype_guess($filename);
1785 $mime and return $mime;
1789 return $default_blob_plain_mimetype unless $fd;
1792 return 'text/plain' .
1793 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1794 } elsif (! $filename) {
1795 return 'application/octet-stream';
1796 } elsif ($filename =~ m/\.png$/i) {
1798 } elsif ($filename =~ m/\.gif$/i) {
1800 } elsif ($filename =~ m/\.jpe?g$/i) {
1801 return 'image/jpeg';
1803 return 'application/octet-stream';
1807 ## ======================================================================
1808 ## functions printing HTML: header, footer, error page
1810 sub git_header_html {
1811 my $status = shift || "200 OK";
1812 my $expires = shift;
1814 my $title = "$site_name";
1815 if (defined $project) {
1816 $title .= " - " . decode_utf8($project);
1817 if (defined $action) {
1818 $title .= "/$action";
1819 if (defined $file_name) {
1820 $title .= " - " . esc_path($file_name);
1821 if ($action eq "tree" && $file_name !~ m|/$|) {
1828 # require explicit support from the UA if we are to send the page as
1829 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1830 # we have to do this because MSIE sometimes globs '*/*', pretending to
1831 # support xhtml+xml but choking when it gets what it asked for.
1832 if (defined $cgi->http('HTTP_ACCEPT') &&
1833 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&
1834 $cgi->Accept('application/xhtml+xml') != 0) {
1835 $content_type = 'application/xhtml+xml';
1837 $content_type = 'text/html';
1839 print $cgi->header(-type=>$content_type, -charset => 'utf-8',
1840 -status=> $status, -expires => $expires);
1841 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
1843 <?xml version="1.0" encoding="utf-8"?>
1844 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1845 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1846 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1847 <!-- git core binaries version $git_version -->
1849 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1850 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
1851 <meta name="robots" content="index, nofollow"/>
1852 <title>$title</title>
1854 # print out each stylesheet that exist
1855 if (defined $stylesheet) {
1856 #provides backwards capability for those people who define style sheet in a config file
1857 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1859 foreach my $stylesheet (@stylesheets) {
1860 next unless $stylesheet;
1861 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1864 if (defined $project) {
1865 printf('<link rel="alternate" title="%s log RSS feed" '.
1866 'href="%s" type="application/rss+xml" />'."\n",
1867 esc_param($project), href(action=>"rss"));
1868 printf('<link rel="alternate" title="%s log Atom feed" '.
1869 'href="%s" type="application/atom+xml" />'."\n",
1870 esc_param($project), href(action=>"atom"));
1872 printf('<link rel="alternate" title="%s projects list" '.
1873 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1874 $site_name, href(project=>undef, action=>"project_index"));
1875 printf('<link rel="alternate" title="%s projects feeds" '.
1876 'href="%s" type="text/x-opml"/>'."\n",
1877 $site_name, href(project=>undef, action=>"opml"));
1879 if (defined $favicon) {
1880 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1886 if (-f $site_header) {
1887 open (my $fd, $site_header);
1892 print "<div class=\"page_header\">\n" .
1893 $cgi->a({-href => esc_url($logo_url),
1894 -title => $logo_label},
1895 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1896 print $cgi->a({-href => esc_url($home_link)}, $home_link_str) . " / ";
1897 if (defined $project) {
1898 print $cgi->a({-href => href(action=>"summary")}, esc_html($project));
1899 if (defined $action) {
1904 my ($have_search) = gitweb_check_feature('search');
1905 if ((defined $project) && ($have_search)) {
1906 if (!defined $searchtext) {
1910 if (defined $hash_base) {
1911 $search_hash = $hash_base;
1912 } elsif (defined $hash) {
1913 $search_hash = $hash;
1915 $search_hash = "HEAD";
1917 $cgi->param("a", "search");
1918 $cgi->param("h", $search_hash);
1919 $cgi->param("p", $project);
1920 print $cgi->startform(-method => "get", -action => $my_uri) .
1921 "<div class=\"search\">\n" .
1922 $cgi->hidden(-name => "p") . "\n" .
1923 $cgi->hidden(-name => "a") . "\n" .
1924 $cgi->hidden(-name => "h") . "\n" .
1925 $cgi->popup_menu(-name => 'st', -default => 'commit',
1926 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1927 $cgi->sup($cgi->a({-href => href(action=>"search_help")}, "?")) .
1929 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
1931 $cgi->end_form() . "\n";
1936 sub git_footer_html {
1937 print "<div class=\"page_footer\">\n";
1938 if (defined $project) {
1939 my $descr = git_get_project_description($project);
1940 if (defined $descr) {
1941 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
1943 print $cgi->a({-href => href(action=>"rss"),
1944 -class => "rss_logo"}, "RSS") . " ";
1945 print $cgi->a({-href => href(action=>"atom"),
1946 -class => "rss_logo"}, "Atom") . "\n";
1948 print $cgi->a({-href => href(project=>undef, action=>"opml"),
1949 -class => "rss_logo"}, "OPML") . " ";
1950 print $cgi->a({-href => href(project=>undef, action=>"project_index"),
1951 -class => "rss_logo"}, "TXT") . "\n";
1955 if (-f $site_footer) {
1956 open (my $fd, $site_footer);
1966 my $status = shift || "403 Forbidden";
1967 my $error = shift || "Malformed query, file missing or permission denied";
1969 git_header_html($status);
1971 <div class="page_body">
1981 ## ----------------------------------------------------------------------
1982 ## functions printing or outputting HTML: navigation
1984 sub git_print_page_nav {
1985 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1986 $extra = '' if !defined $extra; # pager or formats
1988 my @navs = qw(summary shortlog log commit commitdiff tree);
1990 @navs = grep { $_ ne $suppress } @navs;
1993 my %arg = map { $_ => {action=>$_} } @navs;
1994 if (defined $head) {
1995 for (qw(commit commitdiff)) {
1996 $arg{$_}{'hash'} = $head;
1998 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1999 for (qw(shortlog log)) {
2000 $arg{$_}{'hash'} = $head;
2004 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2005 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2007 print "<div class=\"page_nav\">\n" .
2009 map { $_ eq $current ?
2010 $_ : $cgi->a({-href => href(%{$arg{$_}})}, "$_")
2012 print "<br/>\n$extra<br/>\n" .
2016 sub format_paging_nav {
2017 my ($action, $hash, $head, $page, $nrevs) = @_;
2021 if ($hash ne $head || $page) {
2022 $paging_nav .= $cgi->a({-href => href(action=>$action)}, "HEAD");
2024 $paging_nav .= "HEAD";
2028 $paging_nav .= " ⋅ " .
2029 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page-1),
2030 -accesskey => "p", -title => "Alt-p"}, "prev");
2032 $paging_nav .= " ⋅ prev";
2035 if ($nrevs >= (100 * ($page+1)-1)) {
2036 $paging_nav .= " ⋅ " .
2037 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page+1),
2038 -accesskey => "n", -title => "Alt-n"}, "next");
2040 $paging_nav .= " ⋅ next";
2046 ## ......................................................................
2047 ## functions printing or outputting HTML: div
2049 sub git_print_header_div {
2050 my ($action, $title, $hash, $hash_base) = @_;
2053 $args{'action'} = $action;
2054 $args{'hash'} = $hash if $hash;
2055 $args{'hash_base'} = $hash_base if $hash_base;
2057 print "<div class=\"header\">\n" .
2058 $cgi->a({-href => href(%args), -class => "title"},
2059 $title ? $title : $action) .
2063 #sub git_print_authorship (\%) {
2064 sub git_print_authorship {
2067 my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
2068 print "<div class=\"author_date\">" .
2069 esc_html($co->{'author_name'}) .
2071 if ($ad{'hour_local'} < 6) {
2072 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2073 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2075 printf(" (%02d:%02d %s)",
2076 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2081 sub git_print_page_path {
2087 print "<div class=\"page_path\">";
2088 print $cgi->a({-href => href(action=>"tree", hash_base=>$hb),
2089 -title => 'tree root'}, decode_utf8("[$project]"));
2091 if (defined $name) {
2092 my @dirname = split '/', $name;
2093 my $basename = pop @dirname;
2096 foreach my $dir (@dirname) {
2097 $fullname .= ($fullname ? '/' : '') . $dir;
2098 print $cgi->a({-href => href(action=>"tree", file_name=>$fullname,
2100 -title => $fullname}, esc_path($dir));
2103 if (defined $type && $type eq 'blob') {
2104 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,
2106 -title => $name}, esc_path($basename));
2107 } elsif (defined $type && $type eq 'tree') {
2108 print $cgi->a({-href => href(action=>"tree", file_name=>$file_name,
2110 -title => $name}, esc_path($basename));
2113 print esc_path($basename);
2116 print "<br/></div>\n";
2119 # sub git_print_log (\@;%) {
2120 sub git_print_log ($;%) {
2124 if ($opts{'-remove_title'}) {
2125 # remove title, i.e. first line of log
2128 # remove leading empty lines
2129 while (defined $log->[0] && $log->[0] eq "") {
2136 foreach my $line (@$log) {
2137 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2140 if (! $opts{'-remove_signoff'}) {
2141 print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
2144 # remove signoff lines
2151 # print only one empty line
2152 # do not print empty line after signoff
2154 next if ($empty || $signoff);
2160 print format_log_line_html($line) . "<br/>\n";
2163 if ($opts{'-final_empty_line'}) {
2164 # end with single empty line
2165 print "<br/>\n" unless $empty;
2169 # return link target (what link points to)
2170 sub git_get_link_target {
2175 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
2179 $link_target = <$fd>;
2184 return $link_target;
2187 # given link target, and the directory (basedir) the link is in,
2188 # return target of link relative to top directory (top tree);
2189 # return undef if it is not possible (including absolute links).
2190 sub normalize_link_target {
2191 my ($link_target, $basedir, $hash_base) = @_;
2193 # we can normalize symlink target only if $hash_base is provided
2194 return unless $hash_base;
2196 # absolute symlinks (beginning with '/') cannot be normalized
2197 return if (substr($link_target, 0, 1) eq '/');
2199 # normalize link target to path from top (root) tree (dir)
2202 $path = $basedir . '/' . $link_target;
2204 # we are in top (root) tree (dir)
2205 $path = $link_target;
2208 # remove //, /./, and /../
2210 foreach my $part (split('/', $path)) {
2211 # discard '.' and ''
2212 next if (!$part || $part eq '.');
2214 if ($part eq '..') {
2218 # link leads outside repository (outside top dir)
2222 push @path_parts, $part;
2225 $path = join('/', @path_parts);
2230 # print tree entry (row of git_tree), but without encompassing <tr> element
2231 sub git_print_tree_entry {
2232 my ($t, $basedir, $hash_base, $have_blame) = @_;
2235 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2237 # The format of a table row is: mode list link. Where mode is
2238 # the mode of the entry, list is the name of the entry, an href,
2239 # and link is the action links of the entry.
2241 print "<td class=\"mode\">" . mode_str($t->{'mode'}) . "</td>\n";
2242 if ($t->{'type'} eq "blob") {
2243 print "<td class=\"list\">" .
2244 $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
2245 file_name=>"$basedir$t->{'name'}", %base_key),
2246 -class => "list"}, esc_path($t->{'name'}));
2247 if (S_ISLNK(oct $t->{'mode'})) {
2248 my $link_target = git_get_link_target($t->{'hash'});
2250 my $norm_target = normalize_link_target($link_target, $basedir, $hash_base);
2251 if (defined $norm_target) {
2253 $cgi->a({-href => href(action=>"object", hash_base=>$hash_base,
2254 file_name=>$norm_target),
2255 -title => $norm_target}, esc_path($link_target));
2257 print " -> " . esc_path($link_target);
2262 print "<td class=\"link\">";
2263 print $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
2264 file_name=>"$basedir$t->{'name'}", %base_key)},
2268 $cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},
2269 file_name=>"$basedir$t->{'name'}", %base_key)},
2272 if (defined $hash_base) {
2274 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
2275 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},
2279 $cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,
2280 file_name=>"$basedir$t->{'name'}")},
2284 } elsif ($t->{'type'} eq "tree") {
2285 print "<td class=\"list\">";
2286 print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
2287 file_name=>"$basedir$t->{'name'}", %base_key)},
2288 esc_path($t->{'name'}));
2290 print "<td class=\"link\">";
2291 print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
2292 file_name=>"$basedir$t->{'name'}", %base_key)},
2294 if (defined $hash_base) {
2296 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
2297 file_name=>"$basedir$t->{'name'}")},
2304 ## ......................................................................
2305 ## functions printing large fragments of HTML
2307 sub fill_from_file_info {
2308 my ($diff, @parents) = @_;
2310 $diff->{'from_file'} = [ ];
2311 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2312 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2313 if ($diff->{'status'}[$i] eq 'R' ||
2314 $diff->{'status'}[$i] eq 'C') {
2315 $diff->{'from_file'}[$i] =
2316 git_get_path_by_hash($parents[$i], $diff->{'from_id'}[$i]);
2323 # parameters can be strings, or references to arrays of strings
2327 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @$a == @$b) {
2328 for (my $i = 0; $i < @$a; ++$i) {
2329 return 0 unless ($a->[$i] eq $b->[$i]);
2332 } elsif (!ref($a) && !ref($b)) {
2340 sub git_difftree_body {
2341 my ($difftree, $hash, @parents) = @_;
2342 my ($parent) = $parents[0];
2343 my ($have_blame) = gitweb_check_feature('blame');
2344 print "<div class=\"list_head\">\n";
2345 if ($#{$difftree} > 10) {
2346 print(($#{$difftree} + 1) . " files changed:\n");
2350 print "<table class=\"" .
2351 (@parents > 1 ? "combined " : "") .
2355 foreach my $line (@{$difftree}) {
2357 if (ref($line) eq "HASH") {
2358 # pre-parsed (or generated by hand)
2361 $diff = parse_difftree_raw_line($line);
2365 print "<tr class=\"dark\">\n";
2367 print "<tr class=\"light\">\n";
2371 if (exists $diff->{'nparents'}) { # combined diff
2373 fill_from_file_info($diff, @parents)
2374 unless exists $diff->{'from_file'};
2376 if ($diff->{'to_id'} ne ('0' x 40)) {
2377 # file exists in the result (child) commit
2379 $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
2380 file_name=>$diff->{'to_file'},
2382 -class => "list"}, esc_path($diff->{'to_file'})) .
2386 esc_path($diff->{'to_file'}) .
2390 if ($action eq 'commitdiff') {
2393 print "<td class=\"link\">" .
2394 $cgi->a({-href => "#patch$patchno"}, "patch") .
2399 my $has_history = 0;
2400 my $not_deleted = 0;
2401 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2402 my $hash_parent = $parents[$i];
2403 my $from_hash = $diff->{'from_id'}[$i];
2404 my $from_path = $diff->{'from_file'}[$i];
2405 my $status = $diff->{'status'}[$i];
2407 $has_history ||= ($status ne 'A');
2408 $not_deleted ||= ($status ne 'D');
2410 if ($status eq 'A') {
2411 print "<td class=\"link\" align=\"right\"> | </td>\n";
2412 } elsif ($status eq 'D') {
2413 print "<td class=\"link\">" .
2414 $cgi->a({-href => href(action=>"blob",
2417 file_name=>$from_path)},
2421 if ($diff->{'to_id'} eq $from_hash) {
2422 print "<td class=\"link nochange\">";
2424 print "<td class=\"link\">";
2426 print $cgi->a({-href => href(action=>"blobdiff",
2427 hash=>$diff->{'to_id'},
2428 hash_parent=>$from_hash,
2430 hash_parent_base=>$hash_parent,
2431 file_name=>$diff->{'to_file'},
2432 file_parent=>$from_path)},
2438 print "<td class=\"link\">";
2440 print $cgi->a({-href => href(action=>"blob",
2441 hash=>$diff->{'to_id'},
2442 file_name=>$diff->{'to_file'},
2445 print " | " if ($has_history);
2448 print $cgi->a({-href => href(action=>"history",
2449 file_name=>$diff->{'to_file'},
2456 next; # instead of 'else' clause, to avoid extra indent
2458 # else ordinary diff
2460 my ($to_mode_oct, $to_mode_str, $to_file_type);
2461 my ($from_mode_oct, $from_mode_str, $from_file_type);
2462 if ($diff->{'to_mode'} ne ('0' x 6)) {
2463 $to_mode_oct = oct $diff->{'to_mode'};
2464 if (S_ISREG($to_mode_oct)) { # only for regular file
2465 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2467 $to_file_type = file_type($diff->{'to_mode'});
2469 if ($diff->{'from_mode'} ne ('0' x 6)) {
2470 $from_mode_oct = oct $diff->{'from_mode'};
2471 if (S_ISREG($to_mode_oct)) { # only for regular file
2472 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2474 $from_file_type = file_type($diff->{'from_mode'});
2477 if ($diff->{'status'} eq "A") { # created
2478 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2479 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2480 $mode_chng .= "]</span>";
2482 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
2483 hash_base=>$hash, file_name=>$diff->{'file'}),
2484 -class => "list"}, esc_path($diff->{'file'}));
2486 print "<td>$mode_chng</td>\n";
2487 print "<td class=\"link\">";
2488 if ($action eq 'commitdiff') {
2491 print $cgi->a({-href => "#patch$patchno"}, "patch");
2494 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
2495 hash_base=>$hash, file_name=>$diff->{'file'})},
2499 } elsif ($diff->{'status'} eq "D") { # deleted
2500 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2502 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},
2503 hash_base=>$parent, file_name=>$diff->{'file'}),
2504 -class => "list"}, esc_path($diff->{'file'}));
2506 print "<td>$mode_chng</td>\n";
2507 print "<td class=\"link\">";
2508 if ($action eq 'commitdiff') {
2511 print $cgi->a({-href => "#patch$patchno"}, "patch");
2514 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},
2515 hash_base=>$parent, file_name=>$diff->{'file'})},
2518 print $cgi->a({-href => href(action=>"blame", hash_base=>$parent,
2519 file_name=>$diff->{'file'})},
2522 print $cgi->a({-href => href(action=>"history", hash_base=>$parent,
2523 file_name=>$diff->{'file'})},
2527 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2528 my $mode_chnge = "";
2529 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2530 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2531 if ($from_file_type ne $to_file_type) {
2532 $mode_chnge .= " from $from_file_type to $to_file_type";
2534 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2535 if ($from_mode_str && $to_mode_str) {
2536 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2537 } elsif ($to_mode_str) {
2538 $mode_chnge .= " mode: $to_mode_str";
2541 $mode_chnge .= "]</span>\n";
2544 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
2545 hash_base=>$hash, file_name=>$diff->{'file'}),
2546 -class => "list"}, esc_path($diff->{'file'}));
2548 print "<td>$mode_chnge</td>\n";
2549 print "<td class=\"link\">";
2550 if ($action eq 'commitdiff') {
2553 print $cgi->a({-href => "#patch$patchno"}, "patch") .
2555 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2556 # "commit" view and modified file (not onlu mode changed)
2557 print $cgi->a({-href => href(action=>"blobdiff",
2558 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},
2559 hash_base=>$hash, hash_parent_base=>$parent,
2560 file_name=>$diff->{'file'})},
2564 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
2565 hash_base=>$hash, file_name=>$diff->{'file'})},
2568 print $cgi->a({-href => href(action=>"blame", hash_base=>$hash,
2569 file_name=>$diff->{'file'})},
2572 print $cgi->a({-href => href(action=>"history", hash_base=>$hash,
2573 file_name=>$diff->{'file'})},
2577 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
2578 my %status_name = ('R' => 'moved', 'C' => 'copied');
2579 my $nstatus = $status_name{$diff->{'status'}};
2581 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2582 # mode also for directories, so we cannot use $to_mode_str
2583 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2586 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
2587 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),
2588 -class => "list"}, esc_path($diff->{'to_file'})) . "</td>\n" .
2589 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2590 $cgi->a({-href => href(action=>"blob", hash_base=>$parent,
2591 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),
2592 -class => "list"}, esc_path($diff->{'from_file'})) .
2593 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2594 "<td class=\"link\">";
2595 if ($action eq 'commitdiff') {
2598 print $cgi->a({-href => "#patch$patchno"}, "patch") .
2600 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2601 # "commit" view and modified file (not only pure rename or copy)
2602 print $cgi->a({-href => href(action=>"blobdiff",
2603 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},
2604 hash_base=>$hash, hash_parent_base=>$parent,
2605 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},
2609 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
2610 hash_base=>$parent, file_name=>$diff->{'to_file'})},
2613 print $cgi->a({-href => href(action=>"blame", hash_base=>$hash,
2614 file_name=>$diff->{'to_file'})},
2617 print $cgi->a({-href => href(action=>"history", hash_base=>$hash,
2618 file_name=>$diff->{'to_file'})},
2622 } # we should not encounter Unmerged (U) or Unknown (X) status
2628 sub git_patchset_body {
2629 my ($fd, $difftree, $hash, @hash_parents) = @_;
2630 my ($hash_parent) = $hash_parents[0];
2633 my $patch_number = 0;
2638 print "<div class=\"patchset\">\n";
2640 # skip to first patch
2641 while ($patch_line = <$fd>) {
2644 last if ($patch_line =~ m/^diff /);
2648 while ($patch_line) {
2650 my ($from_id, $to_id);
2653 #assert($patch_line =~ m/^diff /) if DEBUG;
2654 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2656 push @diff_header, $patch_line;
2658 # extended diff header
2660 while ($patch_line = <$fd>) {
2663 last EXTENDED_HEADER if ($patch_line =~ m/^--- |^diff /);
2665 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2668 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2669 $from_id = [ split(',', $1) ];
2673 push @diff_header, $patch_line;
2675 my $last_patch_line = $patch_line;
2677 # check if current patch belong to current raw line
2678 # and parse raw git-diff line if needed
2679 if (defined $diffinfo &&
2680 defined $from_id && defined $to_id &&
2681 from_ids_eq($diffinfo->{'from_id'}, $from_id) &&
2682 $diffinfo->{'to_id'} eq $to_id) {
2683 # this is continuation of a split patch
2684 print "<div class=\"patch cont\">\n";
2686 # advance raw git-diff output if needed
2687 $patch_idx++ if defined $diffinfo;
2689 # read and prepare patch information
2690 if (ref($difftree->[$patch_idx]) eq "HASH") {
2691 # pre-parsed (or generated by hand)
2692 $diffinfo = $difftree->[$patch_idx];
2694 $diffinfo = parse_difftree_raw_line($difftree->[$patch_idx]);
2696 if ($diffinfo->{'nparents'}) {
2700 fill_from_file_info($diffinfo, @hash_parents)
2701 unless exists $diffinfo->{'from_file'};
2702 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2703 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2704 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2705 $from{'href'}[$i] = href(action=>"blob",
2706 hash_base=>$hash_parents[$i],
2707 hash=>$diffinfo->{'from_id'}[$i],
2708 file_name=>$from{'file'}[$i]);
2710 $from{'href'}[$i] = undef;
2714 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2715 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2716 $from{'href'} = href(action=>"blob", hash_base=>$hash_parent,
2717 hash=>$diffinfo->{'from_id'},
2718 file_name=>$from{'file'});
2720 delete $from{'href'};
2723 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2724 if ($diffinfo->{'status'} ne "D") { # not deleted file
2725 $to{'href'} = href(action=>"blob", hash_base=>$hash,
2726 hash=>$diffinfo->{'to_id'},
2727 file_name=>$to{'file'});
2731 # this is first patch for raw difftree line with $patch_idx index
2732 # we index @$difftree array from 0, but number patches from 1
2733 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2736 # print "git diff" header
2737 $patch_line = shift @diff_header;
2738 if ($diffinfo->{'nparents'}) {
2741 $patch_line =~ s!^(diff (.*?) )"?.*$!$1!;
2743 $patch_line .= $cgi->a({-href => $to{'href'}, -class => "path"},
2744 esc_path($to{'file'}));
2745 } else { # file was deleted
2746 $patch_line .= esc_path($to{'file'});
2751 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2752 if ($from{'href'}) {
2753 $patch_line .= $cgi->a({-href => $from{'href'}, -class => "path"},
2754 'a/' . esc_path($from{'file'}));
2755 } else { # file was added
2756 $patch_line .= 'a/' . esc_path($from{'file'});
2760 $patch_line .= $cgi->a({-href => $to{'href'}, -class => "path"},
2761 'b/' . esc_path($to{'file'}));
2762 } else { # file was deleted
2763 $patch_line .= 'b/' . esc_path($to{'file'});
2767 print "<div class=\"diff header\">$patch_line</div>\n";
2769 # print extended diff header
2770 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2772 foreach $patch_line (@diff_header) {
2774 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2775 $patch_line .= $cgi->a({-href=>$from{'href'}, -class=>"path"},
2776 esc_path($from{'file'}));
2778 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2779 $patch_line .= $cgi->a({-href=>$to{'href'}, -class=>"path"},
2780 esc_path($to{'file'}));
2782 # match single <mode>
2783 if ($patch_line =~ m/\s(\d{6})$/) {
2784 $patch_line .= '<span class="info"> (' .
2785 file_type_long($1) .
2789 if ($patch_line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
2790 # can match only for combined diff
2791 $patch_line = 'index ';
2792 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2793 if ($from{'href'}[$i]) {
2794 $patch_line .= $cgi->a({-href=>$from{'href'}[$i],
2796 substr($diffinfo->{'from_id'}[$i],0,7));
2798 $patch_line .= '0' x 7;
2801 $patch_line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
2803 $patch_line .= '..';
2805 $patch_line .= $cgi->a({-href=>$to{'href'}, -class=>"hash"},
2806 substr($diffinfo->{'to_id'},0,7));
2808 $patch_line .= '0' x 7;
2811 } elsif ($patch_line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
2812 # can match only for ordinary diff
2813 my ($from_link, $to_link);
2814 if ($from{'href'}) {
2815 $from_link = $cgi->a({-href=>$from{'href'}, -class=>"hash"},
2816 substr($diffinfo->{'from_id'},0,7));
2818 $from_link = '0' x 7;
2821 $to_link = $cgi->a({-href=>$to{'href'}, -class=>"hash"},
2822 substr($diffinfo->{'to_id'},0,7));
2827 # my ($from_hash, $to_hash) =
2828 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2829 # my ($from_id, $to_id) =
2830 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2831 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2833 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2834 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2836 print $patch_line . "<br/>\n";
2838 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2840 # from-file/to-file diff header
2841 $patch_line = $last_patch_line;
2842 if (! $patch_line) {
2843 print "</div>\n"; # class="patch"
2846 next PATCH if ($patch_line =~ m/^diff /);
2847 #assert($patch_line =~ m/^---/) if DEBUG;
2848 if (!$diffinfo->{'nparents'} && # not from-file line for combined diff
2849 $from{'href'} && $patch_line =~ m!^--- "?a/!) {
2850 $patch_line = '--- a/' .
2851 $cgi->a({-href=>$from{'href'}, -class=>"path"},
2852 esc_path($from{'file'}));
2854 print "<div class=\"diff from_file\">$patch_line</div>\n";
2856 $patch_line = <$fd>;
2859 #assert($patch_line =~ m/^+++/) if DEBUG;
2860 if ($to{'href'} && $patch_line =~ m!^\+\+\+ "?b/!) {
2861 $patch_line = '+++ b/' .
2862 $cgi->a({-href=>$to{'href'}, -class=>"path"},
2863 esc_path($to{'file'}));
2865 print "<div class=\"diff to_file\">$patch_line</div>\n";
2869 while ($patch_line = <$fd>) {
2872 next PATCH if ($patch_line =~ m/^diff /);
2874 print format_diff_line($patch_line, \%from, \%to);
2878 print "</div>\n"; # class="patch"
2880 print "<div class=\"diff nodifferences\">No differences found</div>\n" if (!$patch_number);
2882 print "</div>\n"; # class="patchset"
2885 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2887 sub git_project_list_body {
2888 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2890 my ($check_forks) = gitweb_check_feature('forks');
2893 foreach my $pr (@$projlist) {
2894 my (@aa) = git_get_last_activity($pr->{'path'});
2898 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2899 if (!defined $pr->{'descr'}) {
2900 my $descr = git_get_project_description($pr->{'path'}) || "";
2901 $pr->{'descr_long'} = decode_utf8($descr);
2902 $pr->{'descr'} = chop_str($descr, 25, 5);
2904 if (!defined $pr->{'owner'}) {
2905 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
2908 my $pname = $pr->{'path'};
2909 if (($pname =~ s/\.git$//) &&
2910 ($pname !~ /\/$/) &&
2911 (-d "$projectroot/$pname")) {
2912 $pr->{'forks'} = "-d $projectroot/$pname";
2918 push @projects, $pr;
2921 $order ||= $default_projects_order;
2922 $from = 0 unless defined $from;
2923 $to = $#projects if (!defined $to || $#projects < $to);
2925 print "<table class=\"project_list\">\n";
2926 unless ($no_header) {
2929 print "<th></th>\n";
2931 if ($order eq "project") {
2932 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2933 print "<th>Project</th>\n";
2936 $cgi->a({-href => href(project=>undef, order=>'project'),
2937 -class => "header"}, "Project") .
2940 if ($order eq "descr") {
2941 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2942 print "<th>Description</th>\n";
2945 $cgi->a({-href => href(project=>undef, order=>'descr'),
2946 -class => "header"}, "Description") .
2949 if ($order eq "owner") {
2950 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2951 print "<th>Owner</th>\n";
2954 $cgi->a({-href => href(project=>undef, order=>'owner'),
2955 -class => "header"}, "Owner") .
2958 if ($order eq "age") {
2959 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2960 print "<th>Last Change</th>\n";
2963 $cgi->a({-href => href(project=>undef, order=>'age'),
2964 -class => "header"}, "Last Change") .
2967 print "<th></th>\n" .
2971 for (my $i = $from; $i <= $to; $i++) {
2972 my $pr = $projects[$i];
2974 print "<tr class=\"dark\">\n";
2976 print "<tr class=\"light\">\n";
2981 if ($pr->{'forks'}) {
2982 print "<!-- $pr->{'forks'} -->\n";
2983 print $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "+");
2987 print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
2988 -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
2989 "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
2990 -class => "list", -title => $pr->{'descr_long'}},
2991 esc_html($pr->{'descr'})) . "</td>\n" .
2992 "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
2993 print "<td class=\"". age_class($pr->{'age'}) . "\">" .
2994 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
2995 "<td class=\"link\">" .
2996 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
2997 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
2998 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") . " | " .
2999 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")}, "tree") .
3000 ($pr->{'forks'} ? " | " . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "forks") : '') .
3004 if (defined $extra) {
3007 print "<td></td>\n";
3009 print "<td colspan=\"5\">$extra</td>\n" .
3015 sub git_shortlog_body {
3016 # uses global variable $project
3017 my ($commitlist, $from, $to, $refs, $extra) = @_;
3019 my $have_snapshot = gitweb_have_snapshot();
3021 $from = 0 unless defined $from;
3022 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3024 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3026 for (my $i = $from; $i <= $to; $i++) {
3027 my %co = %{$commitlist->[$i]};
3028 my $commit = $co{'id'};
3029 my $ref = format_ref_marker($refs, $commit);
3031 print "<tr class=\"dark\">\n";
3033 print "<tr class=\"light\">\n";
3036 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3037 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3038 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
3040 print format_subject_html($co{'title'}, $co{'title_short'},
3041 href(action=>"commit", hash=>$commit), $ref);
3043 "<td class=\"link\">" .
3044 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
3045 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
3046 $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree");
3047 if ($have_snapshot) {
3048 print " | " . $cgi->a({-href => href(action=>"snapshot", hash=>$commit)}, "snapshot");
3053 if (defined $extra) {
3055 "<td colspan=\"4\">$extra</td>\n" .
3061 sub git_history_body {
3062 # Warning: assumes constant type (blob or tree) during history
3063 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3065 $from = 0 unless defined $from;
3066 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3068 print "<table class=\"history\" cellspacing=\"0\">\n";
3070 for (my $i = $from; $i <= $to; $i++) {
3071 my %co = %{$commitlist->[$i]};
3075 my $commit = $co{'id'};
3077 my $ref = format_ref_marker($refs, $commit);
3080 print "<tr class=\"dark\">\n";
3082 print "<tr class=\"light\">\n";
3085 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3086 # shortlog uses chop_str($co{'author_name'}, 10)
3087 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3089 # originally git_history used chop_str($co{'title'}, 50)
3090 print format_subject_html($co{'title'}, $co{'title_short'},
3091 href(action=>"commit", hash=>$commit), $ref);
3093 "<td class=\"link\">" .
3094 $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype) . " | " .
3095 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff");
3097 if ($ftype eq 'blob') {
3098 my $blob_current = git_get_hash_by_path($hash_base, $file_name);
3099 my $blob_parent = git_get_hash_by_path($commit, $file_name);
3100 if (defined $blob_current && defined $blob_parent &&
3101 $blob_current ne $blob_parent) {
3103 $cgi->a({-href => href(action=>"blobdiff",
3104 hash=>$blob_current, hash_parent=>$blob_parent,
3105 hash_base=>$hash_base, hash_parent_base=>$commit,
3106 file_name=>$file_name)},
3113 if (defined $extra) {
3115 "<td colspan=\"4\">$extra</td>\n" .
3122 # uses global variable $project
3123 my ($taglist, $from, $to, $extra) = @_;
3124 $from = 0 unless defined $from;
3125 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3127 print "<table class=\"tags\" cellspacing=\"0\">\n";
3129 for (my $i = $from; $i <= $to; $i++) {
3130 my $entry = $taglist->[$i];
3132 my $comment = $tag{'subject'};
3134 if (defined $comment) {
3135 $comment_short = chop_str($comment, 30, 5);
3138 print "<tr class=\"dark\">\n";
3140 print "<tr class=\"light\">\n";
3143 if (defined $tag{'age'}) {
3144 print "<td><i>$tag{'age'}</i></td>\n";
3146 print "<td></td>\n";
3149 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),
3150 -class => "list name"}, esc_html($tag{'name'})) .
3153 if (defined $comment) {
3154 print format_subject_html($comment, $comment_short,
3155 href(action=>"tag", hash=>$tag{'id'}));
3158 "<td class=\"selflink\">";
3159 if ($tag{'type'} eq "tag") {
3160 print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag");
3165 "<td class=\"link\">" . " | " .
3166 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'});
3167 if ($tag{'reftype'} eq "commit") {
3168 print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") .
3169 " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'name'})}, "log");
3170 } elsif ($tag{'reftype'} eq "blob") {
3171 print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw");
3176 if (defined $extra) {
3178 "<td colspan=\"5\">$extra</td>\n" .
3184 sub git_heads_body {
3185 # uses global variable $project
3186 my ($headlist, $head, $from, $to, $extra) = @_;
3187 $from = 0 unless defined $from;
3188 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3190 print "<table class=\"heads\" cellspacing=\"0\">\n";
3192 for (my $i = $from; $i <= $to; $i++) {
3193 my $entry = $headlist->[$i];
3195 my $curr = $ref{'id'} eq $head;
3197 print "<tr class=\"dark\">\n";
3199 print "<tr class=\"light\">\n";
3202 print "<td><i>$ref{'age'}</i></td>\n" .
3203 ($curr ? "<td class=\"current_head\">" : "<td>") .
3204 $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'name'}),
3205 -class => "list name"},esc_html($ref{'name'})) .
3207 "<td class=\"link\">" .
3208 $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'name'})}, "shortlog") . " | " .
3209 $cgi->a({-href => href(action=>"log", hash=>$ref{'name'})}, "log") . " | " .
3210 $cgi->a({-href => href(action=>"tree", hash=>$ref{'name'}, hash_base=>$ref{'name'})}, "tree") .
3214 if (defined $extra) {
3216 "<td colspan=\"3\">$extra</td>\n" .
3222 sub git_search_grep_body {
3223 my ($commitlist, $from, $to, $extra) = @_;
3224 $from = 0 unless defined $from;
3225 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3227 print "<table class=\"grep\" cellspacing=\"0\">\n";
3229 for (my $i = $from; $i <= $to; $i++) {
3230 my %co = %{$commitlist->[$i]};
3234 my $commit = $co{'id'};
3236 print "<tr class=\"dark\">\n";
3238 print "<tr class=\"light\">\n";
3241 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3242 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3244 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"},
3245 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
3246 my $comment = $co{'comment'};
3247 foreach my $line (@$comment) {
3248 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3249 my $lead = esc_html($1) || "";
3250 $lead = chop_str($lead, 30, 10);
3251 my $match = esc_html($2) || "";
3252 my $trail = esc_html($3) || "";
3253 $trail = chop_str($trail, 30, 10);
3254 my $text = "$lead<span class=\"match\">$match</span>$trail";
3255 print chop_str($text, 80, 5) . "<br/>\n";
3259 "<td class=\"link\">" .
3260 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
3262 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
3266 if (defined $extra) {
3268 "<td colspan=\"3\">$extra</td>\n" .
3274 ## ======================================================================
3275 ## ======================================================================
3278 sub git_project_list {
3279 my $order = $cgi->param('o');
3280 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3281 die_error(undef, "Unknown order parameter");
3284 my @list = git_get_projects_list();
3286 die_error(undef, "No projects found");
3290 if (-f $home_text) {
3291 print "<div class=\"index_include\">\n";
3292 open (my $fd, $home_text);
3297 git_project_list_body(\@list, $order);
3302 my $order = $cgi->param('o');
3303 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3304 die_error(undef, "Unknown order parameter");
3307 my @list = git_get_projects_list($project);
3309 die_error(undef, "No forks found");
3313 git_print_page_nav('','');
3314 git_print_header_div('summary', "$project forks");
3315 git_project_list_body(\@list, $order);
3319 sub git_project_index {
3320 my @projects = git_get_projects_list($project);
3323 -type => 'text/plain',
3324 -charset => 'utf-8',
3325 -content_disposition => 'inline; filename="index.aux"');
3327 foreach my $pr (@projects) {
3328 if (!exists $pr->{'owner'}) {
3329 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}");
3332 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3333 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3334 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
3335 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
3339 print "$path $owner\n";
3344 my $descr = git_get_project_description($project) || "none";
3345 my %co = parse_commit("HEAD");
3346 my %cd = %co ? parse_date($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3347 my $head = $co{'id'};
3349 my $owner = git_get_project_owner($project);
3351 my $refs = git_get_references();
3352 # These get_*_list functions return one more to allow us to see if
3353 # there are more ...
3354 my @taglist = git_get_tags_list(16);
3355 my @headlist = git_get_heads_list(16);
3357 my ($check_forks) = gitweb_check_feature('forks');
3360 @forklist = git_get_projects_list($project);
3364 git_print_page_nav('summary','', $head);
3366 print "<div class=\"title\"> </div>\n";
3367 print "<table cellspacing=\"0\">\n" .
3368 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
3369 "<tr><td>owner</td><td>$owner</td></tr>\n";
3370 if (defined $cd{'rfc2822'}) {
3371 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3374 # use per project git URL list in $projectroot/$project/cloneurl
3375 # or make project git URL from git base URL and project name
3376 my $url_tag = "URL";
3377 my @url_list = git_get_project_url_list($project);
3378 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3379 foreach my $git_url (@url_list) {
3380 next unless $git_url;
3381 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3386 if (-s "$projectroot/$project/README.html") {
3387 if (open my $fd, "$projectroot/$project/README.html") {
3388 print "<div class=\"title\">readme</div>\n";
3389 print $_ while (<$fd>);
3394 # we need to request one more than 16 (0..15) to check if
3396 my @commitlist = $head ? parse_commits($head, 17) : ();
3398 git_print_header_div('shortlog');
3399 git_shortlog_body(\@commitlist, 0, 15, $refs,
3400 $#commitlist <= 15 ? undef :
3401 $cgi->a({-href => href(action=>"shortlog")}, "..."));
3405 git_print_header_div('tags');
3406 git_tags_body(\@taglist, 0, 15,
3407 $#taglist <= 15 ? undef :
3408 $cgi->a({-href => href(action=>"tags")}, "..."));
3412 git_print_header_div('heads');
3413 git_heads_body(\@headlist, $head, 0, 15,
3414 $#headlist <= 15 ? undef :
3415 $cgi->a({-href => href(action=>"heads")}, "..."));
3419 git_print_header_div('forks');
3420 git_project_list_body(\@forklist, undef, 0, 15,
3421 $#forklist <= 15 ? undef :
3422 $cgi->a({-href => href(action=>"forks")}, "..."),
3430 my $head = git_get_head_hash($project);
3432 git_print_page_nav('','', $head,undef,$head);
3433 my %tag = parse_tag($hash);
3436 die_error(undef, "Unknown tag object");
3439 git_print_header_div('commit', esc_html($tag{'name'}), $hash);
3440 print "<div class=\"title_text\">\n" .
3441 "<table cellspacing=\"0\">\n" .
3443 "<td>object</td>\n" .
3444 "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
3445 $tag{'object'}) . "</td>\n" .
3446 "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
3447 $tag{'type'}) . "</td>\n" .
3449 if (defined($tag{'author'})) {
3450 my %ad = parse_date($tag{'epoch'}, $tag{'tz'});
3451 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
3452 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3453 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3456 print "</table>\n\n" .
3458 print "<div class=\"page_body\">";
3459 my $comment = $tag{'comment'};
3460 foreach my $line (@$comment) {
3462 print esc_html($line, -nbsp=>1) . "<br/>\n";
3472 my ($have_blame) = gitweb_check_feature('blame');
3474 die_error('403 Permission denied', "Permission denied");
3476 die_error('404 Not Found', "File name not defined") if (!$file_name);
3477 $hash_base ||= git_get_head_hash($project);
3478 die_error(undef, "Couldn't find base commit") unless ($hash_base);
3479 my %co = parse_commit($hash_base)
3480 or die_error(undef, "Reading commit failed");
3481 if (!defined $hash) {
3482 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
3483 or die_error(undef, "Error looking up file");
3485 $ftype = git_get_type($hash);
3486 if ($ftype !~ "blob") {
3487 die_error('400 Bad Request', "Object is not a blob");
3489 open ($fd, "-|", git_cmd(), "blame", '-p', '--',
3490 $file_name, $hash_base)
3491 or die_error(undef, "Open git-blame failed");
3494 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
3497 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
3500 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
3502 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3503 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
3504 git_print_page_path($file_name, $ftype, $hash_base);
3505 my @rev_color = (qw(light2 dark2));
3506 my $num_colors = scalar(@rev_color);
3507 my $current_color = 0;
3510 <div class="page_body">
3511 <table class="blame">
3512 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3517 last unless defined $_;
3518 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3519 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3520 if (!exists $metainfo{$full_rev}) {
3521 $metainfo{$full_rev} = {};
3523 my $meta = $metainfo{$full_rev};
3526 if (/^(\S+) (.*)$/) {
3532 my $rev = substr($full_rev, 0, 8);
3533 my $author = $meta->{'author'};
3534 my %date = parse_date($meta->{'author-time'},
3535 $meta->{'author-tz'});
3536 my $date = $date{'iso-tz'};
3538 $current_color = ++$current_color % $num_colors;
3540 print "<tr class=\"$rev_color[$current_color]\">\n";
3542 print "<td class=\"sha1\"";
3543 print " title=\"". esc_html($author) . ", $date\"";
3544 print " rowspan=\"$group_size\"" if ($group_size > 1);
3546 print $cgi->a({-href => href(action=>"commit",
3548 file_name=>$file_name)},
3552 open (my $dd, "-|", git_cmd(), "rev-parse", "$full_rev^")
3553 or die_error(undef, "Open git-rev-parse failed");
3554 my $parent_commit = <$dd>;
3556 chomp($parent_commit);
3557 my $blamed = href(action => 'blame',
3558 file_name => $meta->{'filename'},
3559 hash_base => $parent_commit);
3560 print "<td class=\"linenr\">";
3561 print $cgi->a({ -href => "$blamed#l$orig_lineno",
3563 -class => "linenr" },
3566 print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
3572 or print "Reading blob failed\n";
3579 my ($have_blame) = gitweb_check_feature('blame');
3581 die_error('403 Permission denied', "Permission denied");
3583 die_error('404 Not Found', "File name not defined") if (!$file_name);
3584 $hash_base ||= git_get_head_hash($project);
3585 die_error(undef, "Couldn't find base commit") unless ($hash_base);
3586 my %co = parse_commit($hash_base)
3587 or die_error(undef, "Reading commit failed");
3588 if (!defined $hash) {
3589 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
3590 or die_error(undef, "Error lookup file");
3592 open ($fd, "-|", git_cmd(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3593 or die_error(undef, "Open git-annotate failed");
3596 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
3599 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
3602 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
3604 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3605 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
3606 git_print_page_path($file_name, 'blob', $hash_base);
3607 print "<div class=\"page_body\">\n";
3609 <table class="blame">
3618 my @line_class = (qw(light dark));
3619 my $line_class_len = scalar (@line_class);
3620 my $line_class_num = $#line_class;
3621 while (my $line = <$fd>) {
3633 $line_class_num = ($line_class_num + 1) % $line_class_len;
3635 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3642 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3645 $short_rev = substr ($long_rev, 0, 8);
3646 $age = time () - $time;
3647 $age_str = age_string ($age);
3648 $age_str =~ s/ / /g;
3649 $age_class = age_class($age);
3650 $author = esc_html ($author);
3651 $author =~ s/ / /g;
3653 $data = untabify($data);
3654 $data = esc_html ($data);
3657 <tr class="$line_class[$line_class_num]">
3658 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3659 <td class="$age_class">$age_str</td>
3661 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3662 <td class="pre">$data</td>
3665 } # while (my $line = <$fd>)
3666 print "</table>\n\n";
3668 or print "Reading blob failed.\n";
3674 my $head = git_get_head_hash($project);
3676 git_print_page_nav('','', $head,undef,$head);
3677 git_print_header_div('summary', $project);
3679 my @tagslist = git_get_tags_list();
3681 git_tags_body(\@tagslist);
3687 my $head = git_get_head_hash($project);
3689 git_print_page_nav('','', $head,undef,$head);
3690 git_print_header_div('summary', $project);
3692 my @headslist = git_get_heads_list();
3694 git_heads_body(\@headslist, $head);
3699 sub git_blob_plain {
3702 if (!defined $hash) {
3703 if (defined $file_name) {
3704 my $base = $hash_base || git_get_head_hash($project);
3705 $hash = git_get_hash_by_path($base, $file_name, "blob")
3706 or die_error(undef, "Error lookup file");
3708 die_error(undef, "No file name defined");
3710 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3711 # blobs defined by non-textual hash id's can be cached
3716 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
3717 or die_error(undef, "Couldn't cat $file_name, $hash");
3719 $type ||= blob_mimetype($fd, $file_name);
3721 # save as filename, even when no $file_name is given
3722 my $save_as = "$hash";
3723 if (defined $file_name) {
3724 $save_as = $file_name;
3725 } elsif ($type =~ m/^text\//) {
3732 -content_disposition => 'inline; filename="' . "$save_as" . '"');
3734 binmode STDOUT, ':raw';
3736 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
3744 if (!defined $hash) {
3745 if (defined $file_name) {
3746 my $base = $hash_base || git_get_head_hash($project);
3747 $hash = git_get_hash_by_path($base, $file_name, "blob")
3748 or die_error(undef, "Error lookup file");
3750 die_error(undef, "No file name defined");
3752 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3753 # blobs defined by non-textual hash id's can be cached
3757 my ($have_blame) = gitweb_check_feature('blame');
3758 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
3759 or die_error(undef, "Couldn't cat $file_name, $hash");
3760 my $mimetype = blob_mimetype($fd, $file_name);
3761 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3763 return git_blob_plain($mimetype);
3765 # we can have blame only for text/* mimetype
3766 $have_blame &&= ($mimetype =~ m!^text/!);
3768 git_header_html(undef, $expires);
3769 my $formats_nav = '';
3770 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
3771 if (defined $file_name) {
3774 $cgi->a({-href => href(action=>"blame", hash_base=>$hash_base,
3775 hash=>$hash, file_name=>$file_name)},
3780 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
3781 hash=>$hash, file_name=>$file_name)},
3784 $cgi->a({-href => href(action=>"blob_plain",
3785 hash=>$hash, file_name=>$file_name)},
3788 $cgi->a({-href => href(action=>"blob",
3789 hash_base=>"HEAD", file_name=>$file_name)},
3793 $cgi->a({-href => href(action=>"blob_plain", hash=>$hash)}, "raw");
3795 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3796 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
3798 print "<div class=\"page_nav\">\n" .
3799 "<br/><br/></div>\n" .
3800 "<div class=\"title\">$hash</div>\n";
3802 git_print_page_path($file_name, "blob", $hash_base);
3803 print "<div class=\"page_body\">\n";
3804 if ($mimetype =~ m!^text/!) {
3806 while (my $line = <$fd>) {
3809 $line = untabify($line);
3810 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3811 $nr, $nr, $nr, esc_html($line, -nbsp=>1);
3813 } elsif ($mimetype =~ m!^image/!) {
3814 print qq!<img type="$mimetype"!;
3816 print qq! alt="$file_name" title="$file_name"!;
3819 href(action=>"blob_plain", hash=>$hash,
3820 hash_base=>$hash_base, file_name=>$file_name) .
3824 or print "Reading blob failed.\n";
3830 my $have_snapshot = gitweb_have_snapshot();
3832 if (!defined $hash_base) {
3833 $hash_base = "HEAD";
3835 if (!defined $hash) {
3836 if (defined $file_name) {
3837 $hash = git_get_hash_by_path($hash_base, $file_name, "tree");
3843 open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
3844 or die_error(undef, "Open git-ls-tree failed");
3845 my @entries = map { chomp; $_ } <$fd>;
3846 close $fd or die_error(undef, "Reading tree failed");
3849 my $refs = git_get_references();
3850 my $ref = format_ref_marker($refs, $hash_base);
3853 my ($have_blame) = gitweb_check_feature('blame');
3854 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
3856 if (defined $file_name) {
3858 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
3859 hash=>$hash, file_name=>$file_name)},
3861 $cgi->a({-href => href(action=>"tree",
3862 hash_base=>"HEAD", file_name=>$file_name)},
3865 if ($have_snapshot) {
3866 # FIXME: Should be available when we have no hash base as well.
3868 $cgi->a({-href => href(action=>"snapshot", hash=>$hash)},
3871 git_print_page_nav('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3872 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
3875 print "<div class=\"page_nav\">\n";
3876 print "<br/><br/></div>\n";
3877 print "<div class=\"title\">$hash</div>\n";
3879 if (defined $file_name) {
3880 $basedir = $file_name;
3881 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3885 git_print_page_path($file_name, 'tree', $hash_base);
3886 print "<div class=\"page_body\">\n";
3887 print "<table cellspacing=\"0\">\n";
3889 # '..' (top directory) link if possible
3890 if (defined $hash_base &&
3891 defined $file_name && $file_name =~ m![^/]+$!) {
3893 print "<tr class=\"dark\">\n";
3895 print "<tr class=\"light\">\n";
3899 my $up = $file_name;
3900 $up =~ s!/?[^/]+$!!;
3901 undef $up unless $up;
3902 # based on git_print_tree_entry
3903 print '<td class="mode">' . mode_str('040000') . "</td>\n";
3904 print '<td class="list">';
3905 print $cgi->a({-href => href(action=>"tree", hash_base=>$hash_base,
3909 print "<td class=\"link\"></td>\n";
3913 foreach my $line (@entries) {
3914 my %t = parse_ls_tree_line($line, -z => 1);
3917 print "<tr class=\"dark\">\n";
3919 print "<tr class=\"light\">\n";
3923 git_print_tree_entry(\%t, $basedir, $hash_base, $have_blame);
3927 print "</table>\n" .
3933 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
3934 my $have_snapshot = (defined $ctype && defined $suffix);
3935 if (!$have_snapshot) {
3936 die_error('403 Permission denied', "Permission denied");
3939 if (!defined $hash) {
3940 $hash = git_get_head_hash($project);
3943 my $filename = decode_utf8(basename($project)) . "-$hash.tar.$suffix";
3946 -type => "application/$ctype",
3947 -content_disposition => 'inline; filename="' . "$filename" . '"',
3948 -status => '200 OK');
3950 my $git = git_cmd_str();
3951 my $name = $project;
3952 $name =~ s/\047/\047\\\047\047/g;
3954 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3955 or die_error(undef, "Execute git-tar-tree failed");
3956 binmode STDOUT, ':raw';
3958 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
3964 my $head = git_get_head_hash($project);
3965 if (!defined $hash) {
3968 if (!defined $page) {
3971 my $refs = git_get_references();
3973 my @commitlist = parse_commits($hash, 101, (100 * $page));
3975 my $paging_nav = format_paging_nav('log', $hash, $head, $page, (100 * ($page+1)));
3978 git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
3981 my %co = parse_commit($hash);
3983 git_print_header_div('summary', $project);
3984 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3986 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
3987 for (my $i = 0; $i <= $to; $i++) {
3988 my %co = %{$commitlist[$i]};
3990 my $commit = $co{'id'};
3991 my $ref = format_ref_marker($refs, $commit);
3992 my %ad = parse_date($co{'author_epoch'});
3993 git_print_header_div('commit',
3994 "<span class=\"age\">$co{'age_string'}</span>" .
3995 esc_html($co{'title'}) . $ref,
3997 print "<div class=\"title_text\">\n" .
3998 "<div class=\"log_link\">\n" .
3999 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
4001 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
4003 $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree") .
4006 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4009 print "<div class=\"log_body\">\n";
4010 git_print_log($co{'comment'}, -final_empty_line=> 1);
4013 if ($#commitlist >= 100) {
4014 print "<div class=\"page_nav\">\n";
4015 print $cgi->a({-href => href(action=>"log", hash=>$hash, page=>$page+1),
4016 -accesskey => "n", -title => "Alt-n"}, "next");
4023 $hash ||= $hash_base || "HEAD";
4024 my %co = parse_commit($hash);
4026 die_error(undef, "Unknown commit object");
4028 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
4029 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
4031 my $parent = $co{'parent'};
4032 my $parents = $co{'parents'}; # listref
4034 # we need to prepare $formats_nav before any parameter munging
4036 if (!defined $parent) {
4038 $formats_nav .= '(initial)';
4039 } elsif (@$parents == 1) {
4040 # single parent commit
4043 $cgi->a({-href => href(action=>"commit",
4045 esc_html(substr($parent, 0, 7))) .
4052 $cgi->a({-href => href(action=>"commit",
4054 esc_html(substr($_, 0, 7)));
4059 if (!defined $parent) {
4063 open my $fd, "-|", git_cmd(), "diff-tree", '-r', "--no-commit-id",
4065 (@$parents <= 1 ? $parent : '-c'),
4067 or die_error(undef, "Open git-diff-tree failed");
4068 @difftree = map { chomp; $_ } <$fd>;
4069 close $fd or die_error(undef, "Reading git-diff-tree failed");
4071 # non-textual hash id's can be cached
4073 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4076 my $refs = git_get_references();
4077 my $ref = format_ref_marker($refs, $co{'id'});
4079 my $have_snapshot = gitweb_have_snapshot();
4081 git_header_html(undef, $expires);
4082 git_print_page_nav('commit', '',
4083 $hash, $co{'tree'}, $hash,
4086 if (defined $co{'parent'}) {
4087 git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash);
4089 git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash);
4091 print "<div class=\"title_text\">\n" .
4092 "<table cellspacing=\"0\">\n";
4093 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
4095 "<td></td><td> $ad{'rfc2822'}";
4096 if ($ad{'hour_local'} < 6) {
4097 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4098 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4100 printf(" (%02d:%02d %s)",
4101 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4105 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
4106 print "<tr><td></td><td> $cd{'rfc2822'}" .
4107 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4109 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4112 "<td class=\"sha1\">" .
4113 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),
4114 class => "list"}, $co{'tree'}) .
4116 "<td class=\"link\">" .
4117 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},
4119 if ($have_snapshot) {
4121 $cgi->a({-href => href(action=>"snapshot", hash=>$hash)}, "snapshot");
4126 foreach my $par (@$parents) {
4129 "<td class=\"sha1\">" .
4130 $cgi->a({-href => href(action=>"commit", hash=>$par),
4131 class => "list"}, $par) .
4133 "<td class=\"link\">" .
4134 $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") .
4136 $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "diff") .
4143 print "<div class=\"page_body\">\n";
4144 git_print_log($co{'comment'});
4147 git_difftree_body(\@difftree, $hash, @$parents);
4153 # object is defined by:
4154 # - hash or hash_base alone
4155 # - hash_base and file_name
4158 # - hash or hash_base alone
4159 if ($hash || ($hash_base && !defined $file_name)) {
4160 my $object_id = $hash || $hash_base;
4162 my $git_command = git_cmd_str();
4163 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4164 or die_error('404 Not Found', "Object does not exist");
4168 or die_error('404 Not Found', "Object does not exist");
4170 # - hash_base and file_name
4171 } elsif ($hash_base && defined $file_name) {
4172 $file_name =~ s,/+$,,;
4174 system(git_cmd(), "cat-file", '-e', $hash_base) == 0
4175 or die_error('404 Not Found', "Base object does not exist");
4177 # here errors should not hapen
4178 open my $fd, "-|", git_cmd(), "ls-tree", $hash_base, "--", $file_name
4179 or die_error(undef, "Open git-ls-tree failed");
4183 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4184 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4185 die_error('404 Not Found', "File or directory for given base does not exist");
4190 die_error('404 Not Found', "Not enough information to find object");
4193 print $cgi->redirect(-uri => href(action=>$type, -full=>1,
4194 hash=>$hash, hash_base=>$hash_base,
4195 file_name=>$file_name),
4196 -status => '302 Found');
4200 my $format = shift || 'html';
4207 # preparing $fd and %diffinfo for git_patchset_body
4209 if (defined $hash_base && defined $hash_parent_base) {
4210 if (defined $file_name) {
4212 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
4213 $hash_parent_base, $hash_base,
4214 "--", (defined $file_parent ? $file_parent : ()), $file_name
4215 or die_error(undef, "Open git-diff-tree failed");
4216 @difftree = map { chomp; $_ } <$fd>;
4218 or die_error(undef, "Reading git-diff-tree failed");
4220 or die_error('404 Not Found', "Blob diff not found");
4222 } elsif (defined $hash &&
4223 $hash =~ /[0-9a-fA-F]{40}/) {
4224 # try to find filename from $hash
4226 # read filtered raw output
4227 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
4228 $hash_parent_base, $hash_base, "--"
4229 or die_error(undef, "Open git-diff-tree failed");
4231 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4233 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4234 map { chomp; $_ } <$fd>;
4236 or die_error(undef, "Reading git-diff-tree failed");
4238 or die_error('404 Not Found', "Blob diff not found");
4241 die_error('404 Not Found', "Missing one of the blob diff parameters");
4244 if (@difftree > 1) {
4245 die_error('404 Not Found', "Ambiguous blob diff specification");
4248 %diffinfo = parse_difftree_raw_line($difftree[0]);
4249 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4250 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4252 $hash_parent ||= $diffinfo{'from_id'};
4253 $hash ||= $diffinfo{'to_id'};
4255 # non-textual hash id's can be cached
4256 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4257 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4262 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
4263 '-p', ($format eq 'html' ? "--full-index" : ()),
4264 $hash_parent_base, $hash_base,
4265 "--", (defined $file_parent ? $file_parent : ()), $file_name
4266 or die_error(undef, "Open git-diff-tree failed");
4269 # old/legacy style URI
4270 if (!%diffinfo && # if new style URI failed
4271 defined $hash && defined $hash_parent) {
4272 # fake git-diff-tree raw output
4273 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4274 $diffinfo{'from_id'} = $hash_parent;
4275 $diffinfo{'to_id'} = $hash;
4276 if (defined $file_name) {
4277 if (defined $file_parent) {
4278 $diffinfo{'status'} = '2';
4279 $diffinfo{'from_file'} = $file_parent;
4280 $diffinfo{'to_file'} = $file_name;
4281 } else { # assume not renamed
4282 $diffinfo{'status'} = '1';
4283 $diffinfo{'from_file'} = $file_name;
4284 $diffinfo{'to_file'} = $file_name;
4286 } else { # no filename given
4287 $diffinfo{'status'} = '2';
4288 $diffinfo{'from_file'} = $hash_parent;
4289 $diffinfo{'to_file'} = $hash;
4292 # non-textual hash id's can be cached
4293 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4294 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4299 open $fd, "-|", git_cmd(), "diff", @diff_opts,
4300 '-p', ($format eq 'html' ? "--full-index" : ()),
4301 $hash_parent, $hash, "--"
4302 or die_error(undef, "Open git-diff failed");
4304 die_error('404 Not Found', "Missing one of the blob diff parameters")
4309 if ($format eq 'html') {
4311 $cgi->a({-href => href(action=>"blobdiff_plain",
4312 hash=>$hash, hash_parent=>$hash_parent,
4313 hash_base=>$hash_base, hash_parent_base=>$hash_parent_base,
4314 file_name=>$file_name, file_parent=>$file_parent)},
4316 git_header_html(undef, $expires);
4317 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
4318 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4319 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
4321 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4322 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4324 if (defined $file_name) {
4325 git_print_page_path($file_name, "blob", $hash_base);
4327 print "<div class=\"page_path\"></div>\n";
4330 } elsif ($format eq 'plain') {
4332 -type => 'text/plain',
4333 -charset => 'utf-8',
4334 -expires => $expires,
4335 -content_disposition => 'inline; filename="' . "$file_name" . '.patch"');
4337 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4340 die_error(undef, "Unknown blobdiff format");
4344 if ($format eq 'html') {
4345 print "<div class=\"page_body\">\n";
4347 git_patchset_body($fd, [ \%diffinfo ], $hash_base, $hash_parent_base);
4350 print "</div>\n"; # class="page_body"
4354 while (my $line = <$fd>) {
4355 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4356 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4360 last if $line =~ m!^\+\+\+!;
4368 sub git_blobdiff_plain {
4369 git_blobdiff('plain');
4372 sub git_commitdiff {
4373 my $format = shift || 'html';
4374 $hash ||= $hash_base || "HEAD";
4375 my %co = parse_commit($hash);
4377 die_error(undef, "Unknown commit object");
4380 # we need to prepare $formats_nav before any parameter munging
4382 if ($format eq 'html') {
4384 $cgi->a({-href => href(action=>"commitdiff_plain",
4385 hash=>$hash, hash_parent=>$hash_parent)},
4388 if (defined $hash_parent) {
4389 # commitdiff with two commits given
4390 my $hash_parent_short = $hash_parent;
4391 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4392 $hash_parent_short = substr($hash_parent, 0, 7);
4396 $cgi->a({-href => href(action=>"commitdiff",
4397 hash=>$hash_parent)},
4398 esc_html($hash_parent_short)) .
4400 } elsif (!$co{'parent'}) {
4402 $formats_nav .= ' (initial)';
4403 } elsif (scalar @{$co{'parents'}} == 1) {
4404 # single parent commit
4407 $cgi->a({-href => href(action=>"commitdiff",
4408 hash=>$co{'parent'})},
4409 esc_html(substr($co{'parent'}, 0, 7))) .
4416 $cgi->a({-href => href(action=>"commitdiff",
4418 esc_html(substr($_, 0, 7)));
4419 } @{$co{'parents'}} ) .
4424 my $hash_parent_param = $hash_parent;
4425 if (!defined $hash_parent) {
4426 $hash_parent_param =
4427 @{$co{'parents'}} > 1 ? '-c' : $co{'parent'} || '--root';
4433 if ($format eq 'html') {
4434 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
4435 "--no-commit-id", "--patch-with-raw", "--full-index",
4436 $hash_parent_param, $hash, "--"
4437 or die_error(undef, "Open git-diff-tree failed");
4439 while (my $line = <$fd>) {
4441 # empty line ends raw part of diff-tree output
4443 push @difftree, scalar parse_difftree_raw_line($line);
4446 } elsif ($format eq 'plain') {
4447 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
4448 '-p', $hash_parent_param, $hash, "--"
4449 or die_error(undef, "Open git-diff-tree failed");
4452 die_error(undef, "Unknown commitdiff format");
4455 # non-textual hash id's can be cached
4457 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4461 # write commit message
4462 if ($format eq 'html') {
4463 my $refs = git_get_references();
4464 my $ref = format_ref_marker($refs, $co{'id'});
4466 git_header_html(undef, $expires);
4467 git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4468 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
4469 git_print_authorship(\%co);
4470 print "<div class=\"page_body\">\n";
4471 if (@{$co{'comment'}} > 1) {
4472 print "<div class=\"log\">\n";
4473 git_print_log($co{'comment'}, -final_empty_line=> 1, -remove_title => 1);
4474 print "</div>\n"; # class="log"
4477 } elsif ($format eq 'plain') {
4478 my $refs = git_get_references("tags");
4479 my $tagname = git_get_rev_name_tags($hash);
4480 my $filename = basename($project) . "-$hash.patch";
4483 -type => 'text/plain',
4484 -charset => 'utf-8',
4485 -expires => $expires,
4486 -content_disposition => 'inline; filename="' . "$filename" . '"');
4487 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
4490 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4491 Subject: $co{'title'}
4493 print "X-Git-Tag: $tagname\n" if $tagname;
4494 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4496 foreach my $line (@{$co{'comment'}}) {
4503 if ($format eq 'html') {
4504 git_difftree_body(\@difftree, $hash, $hash_parent || @{$co{'parents'}});
4507 git_patchset_body($fd, \@difftree, $hash, $hash_parent || @{$co{'parents'}});
4509 print "</div>\n"; # class="page_body"
4512 } elsif ($format eq 'plain') {
4516 or print "Reading git-diff-tree failed\n";
4520 sub git_commitdiff_plain {
4521 git_commitdiff('plain');
4525 if (!defined $hash_base) {
4526 $hash_base = git_get_head_hash($project);
4528 if (!defined $page) {
4532 my %co = parse_commit($hash_base);
4534 die_error(undef, "Unknown commit object");
4537 my $refs = git_get_references();
4538 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4540 if (!defined $hash && defined $file_name) {
4541 $hash = git_get_hash_by_path($hash_base, $file_name);
4543 if (defined $hash) {
4544 $ftype = git_get_type($hash);
4547 my @commitlist = parse_commits($hash_base, 101, (100 * $page), "--full-history", $file_name);
4549 my $paging_nav = '';
4552 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
4553 file_name=>$file_name)},
4555 $paging_nav .= " ⋅ " .
4556 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
4557 file_name=>$file_name, page=>$page-1),
4558 -accesskey => "p", -title => "Alt-p"}, "prev");
4560 $paging_nav .= "first";
4561 $paging_nav .= " ⋅ prev";
4563 if ($#commitlist >= 100) {
4564 $paging_nav .= " ⋅ " .
4565 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
4566 file_name=>$file_name, page=>$page+1),
4567 -accesskey => "n", -title => "Alt-n"}, "next");
4569 $paging_nav .= " ⋅ next";
4572 if ($#commitlist >= 100) {
4574 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
4575 file_name=>$file_name, page=>$page+1),
4576 -accesskey => "n", -title => "Alt-n"}, "next");
4580 git_print_page_nav('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4581 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
4582 git_print_page_path($file_name, $ftype, $hash_base);
4584 git_history_body(\@commitlist, 0, 99,
4585 $refs, $hash_base, $ftype, $next_link);
4591 my ($have_search) = gitweb_check_feature('search');
4592 if (!$have_search) {
4593 die_error('403 Permission denied', "Permission denied");
4595 if (!defined $searchtext) {
4596 die_error(undef, "Text field empty");
4598 if (!defined $hash) {
4599 $hash = git_get_head_hash($project);
4601 my %co = parse_commit($hash);
4603 die_error(undef, "Unknown commit object");
4605 if (!defined $page) {
4609 $searchtype ||= 'commit';
4610 if ($searchtype eq 'pickaxe') {
4611 # pickaxe may take all resources of your box and run for several minutes
4612 # with every query - so decide by yourself how public you make this feature
4613 my ($have_pickaxe) = gitweb_check_feature('pickaxe');
4614 if (!$have_pickaxe) {
4615 die_error('403 Permission denied', "Permission denied");
4621 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4623 if ($searchtype eq 'commit') {
4624 $greptype = "--grep=";
4625 } elsif ($searchtype eq 'author') {
4626 $greptype = "--author=";
4627 } elsif ($searchtype eq 'committer') {
4628 $greptype = "--committer=";
4630 $greptype .= $search_regexp;
4631 my @commitlist = parse_commits($hash, 101, (100 * $page), $greptype);
4633 my $paging_nav = '';
4636 $cgi->a({-href => href(action=>"search", hash=>$hash,
4637 searchtext=>$searchtext, searchtype=>$searchtype)},
4639 $paging_nav .= " ⋅ " .
4640 $cgi->a({-href => href(action=>"search", hash=>$hash,
4641 searchtext=>$searchtext, searchtype=>$searchtype,
4643 -accesskey => "p", -title => "Alt-p"}, "prev");
4645 $paging_nav .= "first";
4646 $paging_nav .= " ⋅ prev";
4648 if ($#commitlist >= 100) {
4649 $paging_nav .= " ⋅ " .
4650 $cgi->a({-href => href(action=>"search", hash=>$hash,
4651 searchtext=>$searchtext, searchtype=>$searchtype,
4653 -accesskey => "n", -title => "Alt-n"}, "next");
4655 $paging_nav .= " ⋅ next";
4658 if ($#commitlist >= 100) {
4660 $cgi->a({-href => href(action=>"search", hash=>$hash,
4661 searchtext=>$searchtext, searchtype=>$searchtype,
4663 -accesskey => "n", -title => "Alt-n"}, "next");
4666 git_print_page_nav('','', $hash,$co{'tree'},$hash, $paging_nav);
4667 git_print_header_div('commit', esc_html($co{'title'}), $hash);
4668 git_search_grep_body(\@commitlist, 0, 99, $next_link);
4671 if ($searchtype eq 'pickaxe') {
4672 git_print_page_nav('','', $hash,$co{'tree'},$hash);
4673 git_print_header_div('commit', esc_html($co{'title'}), $hash);
4675 print "<table cellspacing=\"0\">\n";
4678 my $git_command = git_cmd_str();
4679 open my $fd, "-|", "$git_command rev-list $hash | " .
4680 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
4683 while (my $line = <$fd>) {
4684 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4687 $set{'from_id'} = $3;
4689 $set{'id'} = $set{'to_id'};
4690 if ($set{'id'} =~ m/0{40}/) {
4691 $set{'id'} = $set{'from_id'};
4693 if ($set{'id'} =~ m/0{40}/) {
4697 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4700 print "<tr class=\"dark\">\n";
4702 print "<tr class=\"light\">\n";
4705 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4706 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4708 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
4709 -class => "list subject"},
4710 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
4711 while (my $setref = shift @files) {
4713 print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},
4714 hash=>$set{'id'}, file_name=>$set{'file'}),
4716 "<span class=\"match\">" . esc_path($set{'file'}) . "</span>") .
4720 "<td class=\"link\">" .
4721 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
4723 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
4727 %co = parse_commit($1);
4737 sub git_search_help {
4739 git_print_page_nav('','', $hash,$hash,$hash);
4742 <dt><b>commit</b></dt>
4743 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4744 <dt><b>author</b></dt>
4745 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4746 <dt><b>committer</b></dt>
4747 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4749 my ($have_pickaxe) = gitweb_check_feature('pickaxe');
4750 if ($have_pickaxe) {
4752 <dt><b>pickaxe</b></dt>
4753 <dd>All commits that caused the string to appear or disappear from any file (changes that
4754 added, removed or "modified" the string) will be listed. This search can take a while and
4755 takes a lot of strain on the server, so please use it wisely.</dd>
4763 my $head = git_get_head_hash($project);
4764 if (!defined $hash) {
4767 if (!defined $page) {
4770 my $refs = git_get_references();
4772 my @commitlist = parse_commits($hash, 101, (100 * $page));
4774 my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, (100 * ($page+1)));
4776 if ($#commitlist >= 100) {
4778 $cgi->a({-href => href(action=>"shortlog", hash=>$hash, page=>$page+1),
4779 -accesskey => "n", -title => "Alt-n"}, "next");
4783 git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);
4784 git_print_header_div('summary', $project);
4786 git_shortlog_body(\@commitlist, 0, 99, $refs, $next_link);
4791 ## ......................................................................
4792 ## feeds (RSS, Atom; OPML)
4795 my $format = shift || 'atom';
4796 my ($have_blame) = gitweb_check_feature('blame');
4798 # Atom: http://www.atomenabled.org/developers/syndication/
4799 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4800 if ($format ne 'rss' && $format ne 'atom') {
4801 die_error(undef, "Unknown web feed format");
4804 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4805 my $head = $hash || 'HEAD';
4806 my @commitlist = parse_commits($head, 150);
4810 my $content_type = "application/$format+xml";
4811 if (defined $cgi->http('HTTP_ACCEPT') &&
4812 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4813 # browser (feed reader) prefers text/xml
4814 $content_type = 'text/xml';
4816 if (defined($commitlist[0])) {
4817 %latest_commit = %{$commitlist[0]};
4818 %latest_date = parse_date($latest_commit{'author_epoch'});
4820 -type => $content_type,
4821 -charset => 'utf-8',
4822 -last_modified => $latest_date{'rfc2822'});
4825 -type => $content_type,
4826 -charset => 'utf-8');
4829 # Optimization: skip generating the body if client asks only
4830 # for Last-Modified date.
4831 return if ($cgi->request_method() eq 'HEAD');
4834 my $title = "$site_name - $project/$action";
4835 my $feed_type = 'log';
4836 if (defined $hash) {
4837 $title .= " - '$hash'";
4838 $feed_type = 'branch log';
4839 if (defined $file_name) {
4840 $title .= " :: $file_name";
4841 $feed_type = 'history';
4843 } elsif (defined $file_name) {
4844 $title .= " - $file_name";
4845 $feed_type = 'history';
4847 $title .= " $feed_type";
4848 my $descr = git_get_project_description($project);
4849 if (defined $descr) {
4850 $descr = esc_html($descr);
4852 $descr = "$project " .
4853 ($format eq 'rss' ? 'RSS' : 'Atom') .
4856 my $owner = git_get_project_owner($project);
4857 $owner = esc_html($owner);
4861 if (defined $file_name) {
4862 $alt_url = href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);
4863 } elsif (defined $hash) {
4864 $alt_url = href(-full=>1, action=>"log", hash=>$hash);
4866 $alt_url = href(-full=>1, action=>"summary");
4868 print qq!<?xml version="1.0" encoding="utf-8"?>\n!;
4869 if ($format eq 'rss') {
4871 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
4874 print "<title>$title</title>\n" .
4875 "<link>$alt_url</link>\n" .
4876 "<description>$descr</description>\n" .
4877 "<language>en</language>\n";
4878 } elsif ($format eq 'atom') {
4880 <feed xmlns="http://www.w3.org/2005/Atom">
4882 print "<title>$title</title>\n" .
4883 "<subtitle>$descr</subtitle>\n" .
4884 '<link rel="alternate" type="text/html" href="' .
4885 $alt_url . '" />' . "\n" .
4886 '<link rel="self" type="' . $content_type . '" href="' .
4887 $cgi->self_url() . '" />' . "\n" .
4888 "<id>" . href(-full=>1) . "</id>\n" .
4889 # use project owner for feed author
4890 "<author><name>$owner</name></author>\n";
4891 if (defined $favicon) {
4892 print "<icon>" . esc_url($favicon) . "</icon>\n";
4894 if (defined $logo_url) {
4895 # not twice as wide as tall: 72 x 27 pixels
4896 print "<logo>" . esc_url($logo) . "</logo>\n";
4898 if (! %latest_date) {
4899 # dummy date to keep the feed valid until commits trickle in:
4900 print "<updated>1970-01-01T00:00:00Z</updated>\n";
4902 print "<updated>$latest_date{'iso-8601'}</updated>\n";
4907 for (my $i = 0; $i <= $#commitlist; $i++) {
4908 my %co = %{$commitlist[$i]};
4909 my $commit = $co{'id'};
4910 # we read 150, we always show 30 and the ones more recent than 48 hours
4911 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
4914 my %cd = parse_date($co{'author_epoch'});
4916 # get list of changed files
4917 open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
4918 $co{'parent'}, $co{'id'}, "--", (defined $file_name ? $file_name : ())
4920 my @difftree = map { chomp; $_ } <$fd>;
4924 # print element (entry, item)
4925 my $co_url = href(-full=>1, action=>"commit", hash=>$commit);
4926 if ($format eq 'rss') {
4928 "<title>" . esc_html($co{'title'}) . "</title>\n" .
4929 "<author>" . esc_html($co{'author'}) . "</author>\n" .
4930 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
4931 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
4932 "<link>$co_url</link>\n" .
4933 "<description>" . esc_html($co{'title'}) . "</description>\n" .
4934 "<content:encoded>" .
4936 } elsif ($format eq 'atom') {
4938 "<title type=\"html\">" . esc_html($co{'title'}) . "</title>\n" .
4939 "<updated>$cd{'iso-8601'}</updated>\n" .
4941 " <name>" . esc_html($co{'author_name'}) . "</name>\n";
4942 if ($co{'author_email'}) {
4943 print " <email>" . esc_html($co{'author_email'}) . "</email>\n";
4945 print "</author>\n" .
4946 # use committer for contributor
4948 " <name>" . esc_html($co{'committer_name'}) . "</name>\n";
4949 if ($co{'committer_email'}) {
4950 print " <email>" . esc_html($co{'committer_email'}) . "</email>\n";
4952 print "</contributor>\n" .
4953 "<published>$cd{'iso-8601'}</published>\n" .
4954 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
4955 "<id>$co_url</id>\n" .
4956 "<content type=\"xhtml\" xml:base=\"" . esc_url($my_url) . "\">\n" .
4957 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
4959 my $comment = $co{'comment'};
4961 foreach my $line (@$comment) {
4962 $line = esc_html($line);
4965 print "</pre><ul>\n";
4966 foreach my $difftree_line (@difftree) {
4967 my %difftree = parse_difftree_raw_line($difftree_line);
4968 next if !$difftree{'from_id'};
4970 my $file = $difftree{'file'} || $difftree{'to_file'};
4974 $cgi->a({-href => href(-full=>1, action=>"blobdiff",
4975 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},
4976 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},
4977 file_name=>$file, file_parent=>$difftree{'from_file'}),
4978 -title => "diff"}, 'D');
4980 print $cgi->a({-href => href(-full=>1, action=>"blame",
4981 file_name=>$file, hash_base=>$commit),
4982 -title => "blame"}, 'B');
4984 # if this is not a feed of a file history
4985 if (!defined $file_name || $file_name ne $file) {
4986 print $cgi->a({-href => href(-full=>1, action=>"history",
4987 file_name=>$file, hash=>$commit),
4988 -title => "history"}, 'H');
4990 $file = esc_path($file);
4994 if ($format eq 'rss') {
4995 print "</ul>]]>\n" .
4996 "</content:encoded>\n" .
4998 } elsif ($format eq 'atom') {
4999 print "</ul>\n</div>\n" .
5006 if ($format eq 'rss') {
5007 print "</channel>\n</rss>\n";
5008 } elsif ($format eq 'atom') {
5022 my @list = git_get_projects_list();
5024 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
5026 <?xml version="1.0" encoding="utf-8"?>
5027 <opml version="1.0">
5029 <title>$site_name OPML Export</title>
5032 <outline text="git RSS feeds">
5035 foreach my $pr (@list) {
5037 my $head = git_get_head_hash($proj{'path'});
5038 if (!defined $head) {
5041 $git_dir = "$projectroot/$proj{'path'}";
5042 my %co = parse_commit($head);
5047 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
5048 my $rss = "$my_url?p=$proj{'path'};a=rss";
5049 my $html = "$my_url?p=$proj{'path'};a=summary";
5050 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";