3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 our $version = "++GIT_VERSION++";
23 our $my_url = $cgi->url();
24 our $my_uri = $cgi->url(-absolute
=> 1);
26 # core git executable to use
27 # this can just be "git" if your webserver has a sensible PATH
28 our $GIT = "++GIT_BINDIR++/git";
30 # absolute fs-path which will be prepended to the project path
31 #our $projectroot = "/pub/scm";
32 our $projectroot = "++GITWEB_PROJECTROOT++";
34 # target of the home link on top of all pages
35 our $home_link = $my_uri || "/";
37 # string of the home link on top of all pages
38 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
40 # name of your site or organization to appear in page titles
41 # replace this with something more descriptive for clearer bookmarks
42 our $site_name = "++GITWEB_SITENAME++"
43 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
45 # filename of html text to include at top of each page
46 our $site_header = "++GITWEB_SITE_HEADER++";
47 # html text to include at home page
48 our $home_text = "++GITWEB_HOMETEXT++";
49 # filename of html text to include at bottom of each page
50 our $site_footer = "++GITWEB_SITE_FOOTER++";
53 our @stylesheets = ("++GITWEB_CSS++");
54 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
55 our $stylesheet = undef;
56 # URI of GIT logo (72x27 size)
57 our $logo = "++GITWEB_LOGO++";
58 # URI of GIT favicon, assumed to be image/png type
59 our $favicon = "++GITWEB_FAVICON++";
61 # URI and label (title) of GIT logo link
62 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
63 #our $logo_label = "git documentation";
64 our $logo_url = "http://git.or.cz/";
65 our $logo_label = "git homepage";
67 # source of projects list
68 our $projects_list = "++GITWEB_LIST++";
70 # show repository only if this file exists
71 # (only effective if this variable evaluates to true)
72 our $export_ok = "++GITWEB_EXPORT_OK++";
74 # only allow viewing of repositories also shown on the overview page
75 our $strict_export = "++GITWEB_STRICT_EXPORT++";
77 # list of git base URLs used for URL to where fetch project from,
78 # i.e. full URL is "$git_base_url/$project"
79 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
81 # default blob_plain mimetype and default charset for text/plain blob
82 our $default_blob_plain_mimetype = 'text/plain';
83 our $default_text_plain_charset = undef;
85 # file to use for guessing MIME types before trying /etc/mime.types
86 # (relative to the current git repository)
87 our $mimetypes_file = undef;
89 # You define site-wide feature defaults here; override them with
90 # $GITWEB_CONFIG as necessary.
93 # 'sub' => feature-sub (subroutine),
94 # 'override' => allow-override (boolean),
95 # 'default' => [ default options...] (array reference)}
97 # if feature is overridable (it means that allow-override has true value,
98 # then feature-sub will be called with default options as parameters;
99 # return value of feature-sub indicates if to enable specified feature
101 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
103 # Enable the 'blame' blob view, showing the last commit that modified
104 # each line in the file. This can be very CPU-intensive.
106 # To enable system wide have in $GITWEB_CONFIG
107 # $feature{'blame'}{'default'} = [1];
108 # To have project specific config enable override in $GITWEB_CONFIG
109 # $feature{'blame'}{'override'} = 1;
110 # and in project config gitweb.blame = 0|1;
112 'sub' => \
&feature_blame
,
116 # Enable the 'snapshot' link, providing a compressed tarball of any
117 # tree. This can potentially generate high traffic if you have large
120 # To disable system wide have in $GITWEB_CONFIG
121 # $feature{'snapshot'}{'default'} = [undef];
122 # To have project specific config enable override in $GITWEB_CONFIG
123 # $feature{'blame'}{'override'} = 1;
124 # and in project config gitweb.snapshot = none|gzip|bzip2;
126 'sub' => \
&feature_snapshot
,
128 # => [content-encoding, suffix, program]
129 'default' => ['x-gzip', 'gz', 'gzip']},
131 # Enable the pickaxe search, which will list the commits that modified
132 # a given string in a file. This can be practical and quite faster
133 # alternative to 'blame', but still potentially CPU-intensive.
135 # To enable system wide have in $GITWEB_CONFIG
136 # $feature{'pickaxe'}{'default'} = [1];
137 # To have project specific config enable override in $GITWEB_CONFIG
138 # $feature{'pickaxe'}{'override'} = 1;
139 # and in project config gitweb.pickaxe = 0|1;
141 'sub' => \
&feature_pickaxe
,
145 # Make gitweb use an alternative format of the URLs which can be
146 # more readable and natural-looking: project name is embedded
147 # directly in the path and the query string contains other
148 # auxiliary information. All gitweb installations recognize
149 # URL in either format; this configures in which formats gitweb
152 # To enable system wide have in $GITWEB_CONFIG
153 # $feature{'pathinfo'}{'default'} = [1];
154 # Project specific override is not supported.
156 # Note that you will need to change the default location of CSS,
157 # favicon, logo and possibly other files to an absolute URL. Also,
158 # if gitweb.cgi serves as your indexfile, you will need to force
159 # $my_uri to contain the script name in your $GITWEB_CONFIG.
164 # Make gitweb consider projects in project root subdirectories
165 # to be forks of existing projects. Given project $projname.git,
166 # projects matching $projname/*.git will not be shown in the main
167 # projects list, instead a '+' mark will be added to $projname
168 # there and a 'forks' view will be enabled for the project, listing
169 # all the forks. This feature is supported only if project list
170 # is taken from a directory, not file.
172 # To enable system wide have in $GITWEB_CONFIG
173 # $feature{'forks'}{'default'} = [1];
174 # Project specific override is not supported.
180 sub gitweb_check_feature
{
182 return unless exists $feature{$name};
183 my ($sub, $override, @defaults) = (
184 $feature{$name}{'sub'},
185 $feature{$name}{'override'},
186 @
{$feature{$name}{'default'}});
187 if (!$override) { return @defaults; }
189 warn "feature $name is not overrideable";
192 return $sub->(@defaults);
196 my ($val) = git_get_project_config
('blame', '--bool');
198 if ($val eq 'true') {
200 } elsif ($val eq 'false') {
207 sub feature_snapshot
{
208 my ($ctype, $suffix, $command) = @_;
210 my ($val) = git_get_project_config
('snapshot');
212 if ($val eq 'gzip') {
213 return ('x-gzip', 'gz', 'gzip');
214 } elsif ($val eq 'bzip2') {
215 return ('x-bzip2', 'bz2', 'bzip2');
216 } elsif ($val eq 'none') {
220 return ($ctype, $suffix, $command);
223 sub gitweb_have_snapshot
{
224 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
225 my $have_snapshot = (defined $ctype && defined $suffix);
227 return $have_snapshot;
230 sub feature_pickaxe
{
231 my ($val) = git_get_project_config
('pickaxe', '--bool');
233 if ($val eq 'true') {
235 } elsif ($val eq 'false') {
242 # checking HEAD file with -e is fragile if the repository was
243 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
245 sub check_head_link
{
247 my $headfile = "$dir/HEAD";
248 return ((-e
$headfile) ||
249 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
252 sub check_export_ok
{
254 return (check_head_link
($dir) &&
255 (!$export_ok || -e
"$dir/$export_ok"));
258 # rename detection options for git-diff and git-diff-tree
259 # - default is '-M', with the cost proportional to
260 # (number of removed files) * (number of new files).
261 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
262 # (number of changed files + number of removed files) * (number of new files)
263 # - even more costly is '-C', '--find-copies-harder' with cost
264 # (number of files in the original tree) * (number of new files)
265 # - one might want to include '-B' option, e.g. '-B', '-M'
266 our @diff_opts = ('-M'); # taken from git_commit
268 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
269 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
271 # version of the core git binary
272 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
274 $projects_list ||= $projectroot;
276 # ======================================================================
277 # input validation and dispatch
278 our $action = $cgi->param('a');
279 if (defined $action) {
280 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
281 die_error
(undef, "Invalid action parameter");
285 # parameters which are pathnames
286 our $project = $cgi->param('p');
287 if (defined $project) {
288 if (!validate_pathname
($project) ||
289 !(-d
"$projectroot/$project") ||
290 !check_head_link
("$projectroot/$project") ||
291 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
292 ($strict_export && !project_in_list
($project))) {
294 die_error
(undef, "No such project");
298 our $file_name = $cgi->param('f');
299 if (defined $file_name) {
300 if (!validate_pathname
($file_name)) {
301 die_error
(undef, "Invalid file parameter");
305 our $file_parent = $cgi->param('fp');
306 if (defined $file_parent) {
307 if (!validate_pathname
($file_parent)) {
308 die_error
(undef, "Invalid file parent parameter");
312 # parameters which are refnames
313 our $hash = $cgi->param('h');
315 if (!validate_refname
($hash)) {
316 die_error
(undef, "Invalid hash parameter");
320 our $hash_parent = $cgi->param('hp');
321 if (defined $hash_parent) {
322 if (!validate_refname
($hash_parent)) {
323 die_error
(undef, "Invalid hash parent parameter");
327 our $hash_base = $cgi->param('hb');
328 if (defined $hash_base) {
329 if (!validate_refname
($hash_base)) {
330 die_error
(undef, "Invalid hash base parameter");
334 our $hash_parent_base = $cgi->param('hpb');
335 if (defined $hash_parent_base) {
336 if (!validate_refname
($hash_parent_base)) {
337 die_error
(undef, "Invalid hash parent base parameter");
342 our $page = $cgi->param('pg');
344 if ($page =~ m/[^0-9]/) {
345 die_error
(undef, "Invalid page parameter");
349 our $searchtext = $cgi->param('s');
350 if (defined $searchtext) {
351 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
352 die_error
(undef, "Invalid search parameter");
354 $searchtext = quotemeta $searchtext;
357 our $searchtype = $cgi->param('st');
358 if (defined $searchtype) {
359 if ($searchtype =~ m/[^a-z]/) {
360 die_error
(undef, "Invalid searchtype parameter");
364 # now read PATH_INFO and use it as alternative to parameters
365 sub evaluate_path_info
{
366 return if defined $project;
367 my $path_info = $ENV{"PATH_INFO"};
368 return if !$path_info;
369 $path_info =~ s
,^/+,,;
370 return if !$path_info;
371 # find which part of PATH_INFO is project
372 $project = $path_info;
374 while ($project && !check_head_link
("$projectroot/$project")) {
375 $project =~ s
,/*[^/]*$,,;
378 $project = validate_pathname
($project);
380 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
381 ($strict_export && !project_in_list
($project))) {
385 # do not change any parameters if an action is given using the query string
387 $path_info =~ s
,^$project/*,,;
388 my ($refname, $pathname) = split(/:/, $path_info, 2);
389 if (defined $pathname) {
390 # we got "project.git/branch:filename" or "project.git/branch:dir/"
391 # we could use git_get_type(branch:pathname), but it needs $git_dir
392 $pathname =~ s
,^/+,,;
393 if (!$pathname || substr($pathname, -1) eq "/") {
397 $action ||= "blob_plain";
399 $hash_base ||= validate_refname
($refname);
400 $file_name ||= validate_pathname
($pathname);
401 } elsif (defined $refname) {
402 # we got "project.git/branch"
403 $action ||= "shortlog";
404 $hash ||= validate_refname
($refname);
407 evaluate_path_info
();
409 # path to the current git repository
411 $git_dir = "$projectroot/$project" if $project;
415 "blame" => \
&git_blame2
,
416 "blobdiff" => \
&git_blobdiff
,
417 "blobdiff_plain" => \
&git_blobdiff_plain
,
418 "blob" => \
&git_blob
,
419 "blob_plain" => \
&git_blob_plain
,
420 "commitdiff" => \
&git_commitdiff
,
421 "commitdiff_plain" => \
&git_commitdiff_plain
,
422 "commit" => \
&git_commit
,
423 "forks" => \
&git_forks
,
424 "heads" => \
&git_heads
,
425 "history" => \
&git_history
,
428 "search" => \
&git_search
,
429 "search_help" => \
&git_search_help
,
430 "shortlog" => \
&git_shortlog
,
431 "summary" => \
&git_summary
,
433 "tags" => \
&git_tags
,
434 "tree" => \
&git_tree
,
435 "snapshot" => \
&git_snapshot
,
436 # those below don't need $project
437 "opml" => \
&git_opml
,
438 "project_list" => \
&git_project_list
,
439 "project_index" => \
&git_project_index
,
442 if (defined $project) {
443 $action ||= 'summary';
445 $action ||= 'project_list';
447 if (!defined($actions{$action})) {
448 die_error
(undef, "Unknown action");
450 if ($action !~ m/^(opml|project_list|project_index)$/ &&
452 die_error
(undef, "Project needed");
454 $actions{$action}->();
457 ## ======================================================================
464 # XXX: Warning: If you touch this, check the search form for updating,
475 hash_parent_base
=> "hpb",
481 my %mapping = @mapping;
483 $params{'project'} = $project unless exists $params{'project'};
485 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
487 # use PATH_INFO for project name
488 $href .= "/$params{'project'}" if defined $params{'project'};
489 delete $params{'project'};
491 # Summary just uses the project path URL
492 if (defined $params{'action'} && $params{'action'} eq 'summary') {
493 delete $params{'action'};
497 # now encode the parameters explicitly
499 for (my $i = 0; $i < @mapping; $i += 2) {
500 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
501 if (defined $params{$name}) {
502 push @result, $symbol . "=" . esc_param
($params{$name});
505 $href .= "?" . join(';', @result) if scalar @result;
511 ## ======================================================================
512 ## validation, quoting/unquoting and escaping
514 sub validate_pathname
{
515 my $input = shift || return undef;
517 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
518 # at the beginning, at the end, and between slashes.
519 # also this catches doubled slashes
520 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
524 if ($input =~ m!\0!) {
530 sub validate_refname
{
531 my $input = shift || return undef;
533 # textual hashes are O.K.
534 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
537 # it must be correct pathname
538 $input = validate_pathname
($input)
540 # restrictions on ref name according to git-check-ref-format
541 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
547 # very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT);
550 return decode
("utf8", $str, Encode
::FB_DEFAULT
);
553 # quote unsafe chars, but keep the slash, even when it's not
554 # correct, but quoted slashes look too horrible in bookmarks
557 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
563 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
566 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
572 # replace invalid utf8 character with SUBSTITUTION sequence
577 $str = to_utf8
($str);
578 $str = escapeHTML
($str);
579 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
580 $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1)
581 if ($opts{'-nbsp'}) {
582 $str =~ s/ / /g;
587 # quote control characters and escape filename to HTML
590 $str = esc_html
($str);
591 $str =~ s
|([[:cntrl
:]])|<span
class="cntrl">?
</span
>|g
;
595 # git may return quoted and escaped filenames
601 my %es = ( # character escape codes, aka escape sequences
602 't' => "\t", # tab (HT, TAB)
603 'n' => "\n", # newline (NL)
604 'r' => "\r", # return (CR)
605 'f' => "\f", # form feed (FF)
606 'b' => "\b", # backspace (BS)
607 'a' => "\a", # alarm (bell) (BEL)
608 'e' => "\e", # escape (ESC)
609 'v' => "\013", # vertical tab (VT)
612 if ($seq =~ m/^[0-7]{1,3}$/) {
613 # octal char sequence
614 return chr(oct($seq));
615 } elsif (exists $es{$seq}) {
616 # C escape sequence, aka character escape code
619 # quoted ordinary character
623 if ($str =~ m/^"(.*)"$/) {
626 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
631 # escape tabs (convert tabs to spaces)
635 while ((my $pos = index($line, "\t")) != -1) {
636 if (my $count = (8 - ($pos % 8))) {
637 my $spaces = ' ' x
$count;
638 $line =~ s/\t/$spaces/;
645 sub project_in_list
{
647 my @list = git_get_projects_list
();
648 return @list && scalar(grep { $_->{'path'} eq $project } @list);
651 ## ----------------------------------------------------------------------
652 ## HTML aware string manipulation
657 my $add_len = shift || 10;
659 # allow only $len chars, but don't cut a word if it would fit in $add_len
660 # if it doesn't fit, cut it if it's still longer than the dots we would add
661 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
664 if (length($tail) > 4) {
666 $body =~ s/&[^;]*$//; # remove chopped character entities
671 ## ----------------------------------------------------------------------
672 ## functions returning short strings
674 # CSS class for given age value (in seconds)
678 if ($age < 60*60*2) {
680 } elsif ($age < 60*60*24*2) {
687 # convert age in seconds to "nn units ago" string
692 if ($age > 60*60*24*365*2) {
693 $age_str = (int $age/60/60/24/365);
694 $age_str .= " years ago";
695 } elsif ($age > 60*60*24*(365/12)*2) {
696 $age_str = int $age/60/60/24/(365/12);
697 $age_str .= " months ago";
698 } elsif ($age > 60*60*24*7*2) {
699 $age_str = int $age/60/60/24/7;
700 $age_str .= " weeks ago";
701 } elsif ($age > 60*60*24*2) {
702 $age_str = int $age/60/60/24;
703 $age_str .= " days ago";
704 } elsif ($age > 60*60*2) {
705 $age_str = int $age/60/60;
706 $age_str .= " hours ago";
707 } elsif ($age > 60*2) {
708 $age_str = int $age/60;
709 $age_str .= " min ago";
712 $age_str .= " sec ago";
714 $age_str .= " right now";
719 # convert file mode in octal to symbolic file mode string
721 my $mode = oct shift;
723 if (S_ISDIR
($mode & S_IFMT
)) {
725 } elsif (S_ISLNK
($mode)) {
727 } elsif (S_ISREG
($mode)) {
728 # git cares only about the executable bit
729 if ($mode & S_IXUSR
) {
739 # convert file mode in octal to file type string
743 if ($mode !~ m/^[0-7]+$/) {
749 if (S_ISDIR
($mode & S_IFMT
)) {
751 } elsif (S_ISLNK
($mode)) {
753 } elsif (S_ISREG
($mode)) {
760 ## ----------------------------------------------------------------------
761 ## functions returning short HTML fragments, or transforming HTML fragments
762 ## which don't beling to other sections
764 # format line of commit message or tag comment
765 sub format_log_line_html
{
768 $line = esc_html
($line);
769 $line =~ s/ / /g;
770 if ($line =~ m/([0-9a-fA-F]{40})/) {
772 if (git_get_type
($hash_text) eq "commit") {
774 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
775 -class => "text"}, $hash_text);
776 $line =~ s/$hash_text/$link/;
782 # format marker of refs pointing to given object
783 sub format_ref_marker
{
784 my ($refs, $id) = @_;
787 if (defined $refs->{$id}) {
788 foreach my $ref (@
{$refs->{$id}}) {
789 my ($type, $name) = qw();
790 # e.g. tags/v2.6.11 or heads/next
791 if ($ref =~ m!^(.*?)s?/(.*)$!) {
799 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
804 return ' <span class="refs">'. $markers . '</span>';
810 # format, perhaps shortened and with markers, title line
811 sub format_subject_html
{
812 my ($long, $short, $href, $extra) = @_;
813 $extra = '' unless defined($extra);
815 if (length($short) < length($long)) {
816 return $cgi->a({-href
=> $href, -class => "list subject",
817 -title
=> to_utf8
($long)},
818 esc_html
($short) . $extra);
820 return $cgi->a({-href
=> $href, -class => "list subject"},
821 esc_html
($long) . $extra);
825 sub format_diff_line
{
827 my $char = substr($line, 0, 1);
833 $diff_class = " add";
834 } elsif ($char eq "-") {
835 $diff_class = " rem";
836 } elsif ($char eq "@") {
837 $diff_class = " chunk_header";
838 } elsif ($char eq "\\") {
839 $diff_class = " incomplete";
841 $line = untabify
($line);
842 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
845 ## ----------------------------------------------------------------------
846 ## git utility subroutines, invoking git commands
848 # returns path to the core git executable and the --git-dir parameter as list
850 return $GIT, '--git-dir='.$git_dir;
853 # returns path to the core git executable and the --git-dir parameter as string
855 return join(' ', git_cmd
());
858 # get HEAD ref of given project as hash
859 sub git_get_head_hash
{
861 my $o_git_dir = $git_dir;
863 $git_dir = "$projectroot/$project";
864 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
867 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
871 if (defined $o_git_dir) {
872 $git_dir = $o_git_dir;
877 # get type of given object
881 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
888 sub git_get_project_config
{
889 my ($key, $type) = @_;
891 return unless ($key);
892 $key =~ s/^gitweb\.//;
893 return if ($key =~ m/\W/);
895 my @x = (git_cmd
(), 'repo-config');
896 if (defined $type) { push @x, $type; }
898 push @x, "gitweb.$key";
904 # get hash of given path at given ref
905 sub git_get_hash_by_path
{
907 my $path = shift || return undef;
912 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
913 or die_error
(undef, "Open git-ls-tree failed");
915 close $fd or return undef;
917 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
918 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
919 if (defined $type && $type ne $2) {
926 ## ......................................................................
927 ## git utility functions, directly accessing git repository
929 sub git_get_project_description
{
932 open my $fd, "$projectroot/$path/description" or return undef;
939 sub git_get_project_url_list
{
942 open my $fd, "$projectroot/$path/cloneurl" or return;
943 my @git_project_url_list = map { chomp; $_ } <$fd>;
946 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
949 sub git_get_projects_list
{
954 $filter =~ s/\.git$//;
956 if (-d
$projects_list) {
957 # search in directory
958 my $dir = $projects_list . ($filter ?
"/$filter" : '');
959 # remove the trailing "/"
961 my $pfxlen = length("$dir");
963 my ($check_forks) = gitweb_check_feature
('forks');
966 follow_fast
=> 1, # follow symbolic links
967 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
969 # skip project-list toplevel, if we get it.
970 return if (m!^[/.]$!);
971 # only directories can be git repositories
972 return unless (-d
$_);
974 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
975 # we check related file in $projectroot
976 if ($check_forks and $subdir =~ m
#/.#) {
977 $File::Find
::prune
= 1;
978 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
979 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
980 $File::Find
::prune
= 1;
985 } elsif (-f
$projects_list) {
986 # read from file(url-encoded):
987 # 'git%2Fgit.git Linus+Torvalds'
988 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
989 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
990 open my ($fd), $projects_list or return;
991 while (my $line = <$fd>) {
993 my ($path, $owner) = split ' ', $line;
994 $path = unescape
($path);
995 $owner = unescape
($owner);
996 if (!defined $path) {
1000 # looking for forks;
1001 my $pfx = substr($path, 0, length($filter));
1002 if ($pfx ne $filter) {
1005 my $sfx = substr($path, length($filter));
1006 if ($sfx !~ /^\/.*\
.git
$/) {
1010 if (check_export_ok
("$projectroot/$path")) {
1013 owner
=> to_utf8
($owner),
1020 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
1024 sub git_get_project_owner
{
1025 my $project = shift;
1028 return undef unless $project;
1030 # read from file (url-encoded):
1031 # 'git%2Fgit.git Linus+Torvalds'
1032 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1033 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1034 if (-f
$projects_list) {
1035 open (my $fd , $projects_list);
1036 while (my $line = <$fd>) {
1038 my ($pr, $ow) = split ' ', $line;
1039 $pr = unescape
($pr);
1040 $ow = unescape
($ow);
1041 if ($pr eq $project) {
1042 $owner = to_utf8
($ow);
1048 if (!defined $owner) {
1049 $owner = get_file_owner
("$projectroot/$project");
1055 sub git_get_last_activity
{
1059 $git_dir = "$projectroot/$path";
1060 open($fd, "-|", git_cmd
(), 'for-each-ref',
1061 '--format=%(refname) %(committer)',
1062 '--sort=-committerdate',
1063 'refs/heads') or return;
1064 my $most_recent = <$fd>;
1065 close $fd or return;
1066 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1068 my $age = time - $timestamp;
1069 return ($age, age_string
($age));
1073 sub git_get_references
{
1074 my $type = shift || "";
1076 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1077 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1078 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1081 while (my $line = <$fd>) {
1083 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
1084 if (defined $refs{$1}) {
1085 push @
{$refs{$1}}, $2;
1091 close $fd or return;
1095 sub git_get_rev_name_tags
{
1096 my $hash = shift || return undef;
1098 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1100 my $name_rev = <$fd>;
1103 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1106 # catches also '$hash undefined' output
1111 ## ----------------------------------------------------------------------
1112 ## parse to hash functions
1116 my $tz = shift || "-0000";
1119 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1120 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1121 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1122 $date{'hour'} = $hour;
1123 $date{'minute'} = $min;
1124 $date{'mday'} = $mday;
1125 $date{'day'} = $days[$wday];
1126 $date{'month'} = $months[$mon];
1127 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1128 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1129 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1130 $mday, $months[$mon], $hour ,$min;
1132 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1133 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1134 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1135 $date{'hour_local'} = $hour;
1136 $date{'minute_local'} = $min;
1137 $date{'tz_local'} = $tz;
1138 $date{'iso-tz'} = sprintf ("%04d-%02d-%02d %02d:%02d:%02d %s",
1139 1900+$year, $mon+1, $mday,
1140 $hour, $min, $sec, $tz);
1149 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1150 $tag{'id'} = $tag_id;
1151 while (my $line = <$fd>) {
1153 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1154 $tag{'object'} = $1;
1155 } elsif ($line =~ m/^type (.+)$/) {
1157 } elsif ($line =~ m/^tag (.+)$/) {
1159 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1160 $tag{'author'} = $1;
1163 } elsif ($line =~ m/--BEGIN/) {
1164 push @comment, $line;
1166 } elsif ($line eq "") {
1170 push @comment, <$fd>;
1171 $tag{'comment'} = \
@comment;
1172 close $fd or return;
1173 if (!defined $tag{'name'}) {
1180 my $commit_id = shift;
1181 my $commit_text = shift;
1186 if (defined $commit_text) {
1187 @commit_lines = @
$commit_text;
1190 open my $fd, "-|", git_cmd
(), "rev-list",
1191 "--header", "--parents", "--max-count=1",
1194 @commit_lines = split '\n', <$fd>;
1195 close $fd or return;
1198 my $header = shift @commit_lines;
1199 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1202 ($co{'id'}, my @parents) = split ' ', $header;
1203 $co{'parents'} = \
@parents;
1204 $co{'parent'} = $parents[0];
1205 while (my $line = shift @commit_lines) {
1206 last if $line eq "\n";
1207 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1209 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1211 $co{'author_epoch'} = $2;
1212 $co{'author_tz'} = $3;
1213 if ($co{'author'} =~ m/^([^<]+) </) {
1214 $co{'author_name'} = $1;
1216 $co{'author_name'} = $co{'author'};
1218 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1219 $co{'committer'} = $1;
1220 $co{'committer_epoch'} = $2;
1221 $co{'committer_tz'} = $3;
1222 $co{'committer_name'} = $co{'committer'};
1223 $co{'committer_name'} =~ s/ <.*//;
1226 if (!defined $co{'tree'}) {
1230 foreach my $title (@commit_lines) {
1233 $co{'title'} = chop_str
($title, 80, 5);
1234 # remove leading stuff of merges to make the interesting part visible
1235 if (length($title) > 50) {
1236 $title =~ s/^Automatic //;
1237 $title =~ s/^merge (of|with) /Merge ... /i;
1238 if (length($title) > 50) {
1239 $title =~ s/(http|rsync):\/\///;
1241 if (length($title) > 50) {
1242 $title =~ s/(master|www|rsync)\.//;
1244 if (length($title) > 50) {
1245 $title =~ s/kernel.org:?//;
1247 if (length($title) > 50) {
1248 $title =~ s/\/pub\/scm//;
1251 $co{'title_short'} = chop_str
($title, 50, 5);
1255 if ($co{'title'} eq "") {
1256 $co{'title'} = $co{'title_short'} = '(no commit message)';
1258 # remove added spaces
1259 foreach my $line (@commit_lines) {
1262 $co{'comment'} = \
@commit_lines;
1264 my $age = time - $co{'committer_epoch'};
1266 $co{'age_string'} = age_string
($age);
1267 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1268 if ($age > 60*60*24*7*2) {
1269 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1270 $co{'age_string_age'} = $co{'age_string'};
1272 $co{'age_string_date'} = $co{'age_string'};
1273 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1278 # parse ref from ref_file, given by ref_id, with given type
1280 my $ref_file = shift;
1282 my $type = shift || git_get_type
($ref_id);
1285 $ref_item{'type'} = $type;
1286 $ref_item{'id'} = $ref_id;
1287 $ref_item{'epoch'} = 0;
1288 $ref_item{'age'} = "unknown";
1289 if ($type eq "tag") {
1290 my %tag = parse_tag
($ref_id);
1291 $ref_item{'comment'} = $tag{'comment'};
1292 if ($tag{'type'} eq "commit") {
1293 my %co = parse_commit
($tag{'object'});
1294 $ref_item{'epoch'} = $co{'committer_epoch'};
1295 $ref_item{'age'} = $co{'age_string'};
1296 } elsif (defined($tag{'epoch'})) {
1297 my $age = time - $tag{'epoch'};
1298 $ref_item{'epoch'} = $tag{'epoch'};
1299 $ref_item{'age'} = age_string
($age);
1301 $ref_item{'reftype'} = $tag{'type'};
1302 $ref_item{'name'} = $tag{'name'};
1303 $ref_item{'refid'} = $tag{'object'};
1304 } elsif ($type eq "commit"){
1305 my %co = parse_commit
($ref_id);
1306 $ref_item{'reftype'} = "commit";
1307 $ref_item{'name'} = $ref_file;
1308 $ref_item{'title'} = $co{'title'};
1309 $ref_item{'refid'} = $ref_id;
1310 $ref_item{'epoch'} = $co{'committer_epoch'};
1311 $ref_item{'age'} = $co{'age_string'};
1313 $ref_item{'reftype'} = $type;
1314 $ref_item{'name'} = $ref_file;
1315 $ref_item{'refid'} = $ref_id;
1321 # parse line of git-diff-tree "raw" output
1322 sub parse_difftree_raw_line
{
1326 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1327 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1328 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1329 $res{'from_mode'} = $1;
1330 $res{'to_mode'} = $2;
1331 $res{'from_id'} = $3;
1333 $res{'status'} = $5;
1334 $res{'similarity'} = $6;
1335 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1336 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1338 $res{'file'} = unquote
($7);
1341 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1342 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1343 $res{'commit'} = $1;
1346 return wantarray ?
%res : \
%res;
1349 # parse line of git-ls-tree output
1350 sub parse_ls_tree_line
($;%) {
1355 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1356 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1364 $res{'name'} = unquote
($4);
1367 return wantarray ?
%res : \
%res;
1370 ## ......................................................................
1371 ## parse to array of hashes functions
1373 sub git_get_heads_list
{
1377 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1378 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
1379 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1382 while (my $line = <$fd>) {
1386 my ($refinfo, $committerinfo) = split(/\0/, $line);
1387 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1388 my ($committer, $epoch, $tz) =
1389 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1390 $name =~ s!^refs/heads/!!;
1392 $ref_item{'name'} = $name;
1393 $ref_item{'id'} = $hash;
1394 $ref_item{'title'} = $title || '(no commit message)';
1395 $ref_item{'epoch'} = $epoch;
1397 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1399 $ref_item{'age'} = "unknown";
1402 push @headslist, \
%ref_item;
1406 return wantarray ?
@headslist : \
@headslist;
1409 sub git_get_tags_list
{
1413 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1414 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
1415 '--format=%(objectname) %(objecttype) %(refname) '.
1416 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1419 while (my $line = <$fd>) {
1423 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1424 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1425 my ($creator, $epoch, $tz) =
1426 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1427 $name =~ s!^refs/tags/!!;
1429 $ref_item{'type'} = $type;
1430 $ref_item{'id'} = $id;
1431 $ref_item{'name'} = $name;
1432 if ($type eq "tag") {
1433 $ref_item{'subject'} = $title;
1434 $ref_item{'reftype'} = $reftype;
1435 $ref_item{'refid'} = $refid;
1437 $ref_item{'reftype'} = $type;
1438 $ref_item{'refid'} = $id;
1441 if ($type eq "tag" || $type eq "commit") {
1442 $ref_item{'epoch'} = $epoch;
1444 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1446 $ref_item{'age'} = "unknown";
1450 push @tagslist, \
%ref_item;
1454 return wantarray ?
@tagslist : \
@tagslist;
1457 ## ----------------------------------------------------------------------
1458 ## filesystem-related functions
1460 sub get_file_owner
{
1463 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1464 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1465 if (!defined $gcos) {
1469 $owner =~ s/[,;].*$//;
1470 return to_utf8
($owner);
1473 ## ......................................................................
1474 ## mimetype related functions
1476 sub mimetype_guess_file
{
1477 my $filename = shift;
1478 my $mimemap = shift;
1479 -r
$mimemap or return undef;
1482 open(MIME
, $mimemap) or return undef;
1484 next if m/^#/; # skip comments
1485 my ($mime, $exts) = split(/\t+/);
1486 if (defined $exts) {
1487 my @exts = split(/\s+/, $exts);
1488 foreach my $ext (@exts) {
1489 $mimemap{$ext} = $mime;
1495 $filename =~ /\.([^.]*)$/;
1496 return $mimemap{$1};
1499 sub mimetype_guess
{
1500 my $filename = shift;
1502 $filename =~ /\./ or return undef;
1504 if ($mimetypes_file) {
1505 my $file = $mimetypes_file;
1506 if ($file !~ m!^/!) { # if it is relative path
1507 # it is relative to project
1508 $file = "$projectroot/$project/$file";
1510 $mime = mimetype_guess_file
($filename, $file);
1512 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1518 my $filename = shift;
1521 my $mime = mimetype_guess
($filename);
1522 $mime and return $mime;
1526 return $default_blob_plain_mimetype unless $fd;
1529 return 'text/plain' .
1530 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1531 } elsif (! $filename) {
1532 return 'application/octet-stream';
1533 } elsif ($filename =~ m/\.png$/i) {
1535 } elsif ($filename =~ m/\.gif$/i) {
1537 } elsif ($filename =~ m/\.jpe?g$/i) {
1538 return 'image/jpeg';
1540 return 'application/octet-stream';
1544 ## ======================================================================
1545 ## functions printing HTML: header, footer, error page
1547 sub git_header_html
{
1548 my $status = shift || "200 OK";
1549 my $expires = shift;
1551 my $title = "$site_name";
1552 if (defined $project) {
1553 $title .= " - $project";
1554 if (defined $action) {
1555 $title .= "/$action";
1556 if (defined $file_name) {
1557 $title .= " - " . esc_path
($file_name);
1558 if ($action eq "tree" && $file_name !~ m
|/$|) {
1565 # require explicit support from the UA if we are to send the page as
1566 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1567 # we have to do this because MSIE sometimes globs '*/*', pretending to
1568 # support xhtml+xml but choking when it gets what it asked for.
1569 if (defined $cgi->http('HTTP_ACCEPT') &&
1570 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1571 $cgi->Accept('application/xhtml+xml') != 0) {
1572 $content_type = 'application/xhtml+xml';
1574 $content_type = 'text/html';
1576 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1577 -status
=> $status, -expires
=> $expires);
1579 <?xml version="1.0" encoding="utf-8"?>
1580 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1581 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1582 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1583 <!-- git core binaries version $git_version -->
1585 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1586 <meta name="generator" content="gitweb/$version git/$git_version"/>
1587 <meta name="robots" content="index, nofollow"/>
1588 <title>$title</title>
1590 # print out each stylesheet that exist
1591 if (defined $stylesheet) {
1592 #provides backwards capability for those people who define style sheet in a config file
1593 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1595 foreach my $stylesheet (@stylesheets) {
1596 next unless $stylesheet;
1597 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1600 if (defined $project) {
1601 printf('<link rel="alternate" title="%s log" '.
1602 'href="%s" type="application/rss+xml"/>'."\n",
1603 esc_param
($project), href
(action
=>"rss"));
1605 printf('<link rel="alternate" title="%s projects list" '.
1606 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1607 $site_name, href
(project
=>undef, action
=>"project_index"));
1608 printf('<link rel="alternate" title="%s projects logs" '.
1609 'href="%s" type="text/x-opml"/>'."\n",
1610 $site_name, href
(project
=>undef, action
=>"opml"));
1612 if (defined $favicon) {
1613 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
1619 if (-f
$site_header) {
1620 open (my $fd, $site_header);
1625 print "<div class=\"page_header\">\n" .
1626 $cgi->a({-href
=> esc_url
($logo_url),
1627 -title
=> $logo_label},
1628 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
1629 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1630 if (defined $project) {
1631 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1632 if (defined $action) {
1636 if (!defined $searchtext) {
1640 if (defined $hash_base) {
1641 $search_hash = $hash_base;
1642 } elsif (defined $hash) {
1643 $search_hash = $hash;
1645 $search_hash = "HEAD";
1647 $cgi->param("a", "search");
1648 $cgi->param("h", $search_hash);
1649 $cgi->param("p", $project);
1650 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1651 "<div class=\"search\">\n" .
1652 $cgi->hidden(-name
=> "p") . "\n" .
1653 $cgi->hidden(-name
=> "a") . "\n" .
1654 $cgi->hidden(-name
=> "h") . "\n" .
1655 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1656 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1657 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1659 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1661 $cgi->end_form() . "\n";
1666 sub git_footer_html
{
1667 print "<div class=\"page_footer\">\n";
1668 if (defined $project) {
1669 my $descr = git_get_project_description
($project);
1670 if (defined $descr) {
1671 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1673 print $cgi->a({-href
=> href
(action
=>"rss"),
1674 -class => "rss_logo"}, "RSS") . "\n";
1676 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1677 -class => "rss_logo"}, "OPML") . " ";
1678 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1679 -class => "rss_logo"}, "TXT") . "\n";
1683 if (-f
$site_footer) {
1684 open (my $fd, $site_footer);
1694 my $status = shift || "403 Forbidden";
1695 my $error = shift || "Malformed query, file missing or permission denied";
1697 git_header_html
($status);
1699 <div class="page_body">
1709 ## ----------------------------------------------------------------------
1710 ## functions printing or outputting HTML: navigation
1712 sub git_print_page_nav
{
1713 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1714 $extra = '' if !defined $extra; # pager or formats
1716 my @navs = qw(summary shortlog log commit commitdiff tree);
1718 @navs = grep { $_ ne $suppress } @navs;
1721 my %arg = map { $_ => {action
=>$_} } @navs;
1722 if (defined $head) {
1723 for (qw(commit commitdiff)) {
1724 $arg{$_}{hash
} = $head;
1726 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1727 for (qw(shortlog log)) {
1728 $arg{$_}{hash
} = $head;
1732 $arg{tree
}{hash
} = $treehead if defined $treehead;
1733 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1735 print "<div class=\"page_nav\">\n" .
1737 map { $_ eq $current ?
1738 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1740 print "<br/>\n$extra<br/>\n" .
1744 sub format_paging_nav
{
1745 my ($action, $hash, $head, $page, $nrevs) = @_;
1749 if ($hash ne $head || $page) {
1750 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1752 $paging_nav .= "HEAD";
1756 $paging_nav .= " ⋅ " .
1757 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1758 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1760 $paging_nav .= " ⋅ prev";
1763 if ($nrevs >= (100 * ($page+1)-1)) {
1764 $paging_nav .= " ⋅ " .
1765 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1766 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1768 $paging_nav .= " ⋅ next";
1774 ## ......................................................................
1775 ## functions printing or outputting HTML: div
1777 sub git_print_header_div
{
1778 my ($action, $title, $hash, $hash_base) = @_;
1781 $args{action
} = $action;
1782 $args{hash
} = $hash if $hash;
1783 $args{hash_base
} = $hash_base if $hash_base;
1785 print "<div class=\"header\">\n" .
1786 $cgi->a({-href
=> href
(%args), -class => "title"},
1787 $title ?
$title : $action) .
1791 #sub git_print_authorship (\%) {
1792 sub git_print_authorship
{
1795 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1796 print "<div class=\"author_date\">" .
1797 esc_html
($co->{'author_name'}) .
1799 if ($ad{'hour_local'} < 6) {
1800 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1801 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1803 printf(" (%02d:%02d %s)",
1804 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1809 sub git_print_page_path
{
1815 print "<div class=\"page_path\">";
1816 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1817 -title
=> 'tree root'}, "[$project]");
1819 if (defined $name) {
1820 my @dirname = split '/', $name;
1821 my $basename = pop @dirname;
1824 foreach my $dir (@dirname) {
1825 $fullname .= ($fullname ?
'/' : '') . $dir;
1826 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1828 -title
=> $fullname}, esc_path
($dir));
1831 if (defined $type && $type eq 'blob') {
1832 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1834 -title
=> $name}, esc_path
($basename));
1835 } elsif (defined $type && $type eq 'tree') {
1836 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1838 -title
=> $name}, esc_path
($basename));
1841 print esc_path
($basename);
1844 print "<br/></div>\n";
1847 # sub git_print_log (\@;%) {
1848 sub git_print_log
($;%) {
1852 if ($opts{'-remove_title'}) {
1853 # remove title, i.e. first line of log
1856 # remove leading empty lines
1857 while (defined $log->[0] && $log->[0] eq "") {
1864 foreach my $line (@
$log) {
1865 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1868 if (! $opts{'-remove_signoff'}) {
1869 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1872 # remove signoff lines
1879 # print only one empty line
1880 # do not print empty line after signoff
1882 next if ($empty || $signoff);
1888 print format_log_line_html
($line) . "<br/>\n";
1891 if ($opts{'-final_empty_line'}) {
1892 # end with single empty line
1893 print "<br/>\n" unless $empty;
1897 # print tree entry (row of git_tree), but without encompassing <tr> element
1898 sub git_print_tree_entry
{
1899 my ($t, $basedir, $hash_base, $have_blame) = @_;
1902 $base_key{hash_base
} = $hash_base if defined $hash_base;
1904 # The format of a table row is: mode list link. Where mode is
1905 # the mode of the entry, list is the name of the entry, an href,
1906 # and link is the action links of the entry.
1908 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1909 if ($t->{'type'} eq "blob") {
1910 print "<td class=\"list\">" .
1911 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1912 file_name
=>"$basedir$t->{'name'}", %base_key),
1913 -class => "list"}, esc_path
($t->{'name'})) . "</td>\n";
1914 print "<td class=\"link\">";
1915 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1916 file_name
=>"$basedir$t->{'name'}", %base_key)},
1920 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1921 file_name
=>"$basedir$t->{'name'}", %base_key)},
1924 if (defined $hash_base) {
1926 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1927 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1931 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
1932 file_name
=>"$basedir$t->{'name'}")},
1936 } elsif ($t->{'type'} eq "tree") {
1937 print "<td class=\"list\">";
1938 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1939 file_name
=>"$basedir$t->{'name'}", %base_key)},
1940 esc_path
($t->{'name'}));
1942 print "<td class=\"link\">";
1943 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1944 file_name
=>"$basedir$t->{'name'}", %base_key)},
1946 if (defined $hash_base) {
1948 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1949 file_name
=>"$basedir$t->{'name'}")},
1956 ## ......................................................................
1957 ## functions printing large fragments of HTML
1959 sub git_difftree_body
{
1960 my ($difftree, $hash, $parent) = @_;
1962 print "<div class=\"list_head\">\n";
1963 if ($#{$difftree} > 10) {
1964 print(($#{$difftree} + 1) . " files changed:\n");
1968 print "<table class=\"diff_tree\">\n";
1971 foreach my $line (@
{$difftree}) {
1972 my %diff = parse_difftree_raw_line
($line);
1975 print "<tr class=\"dark\">\n";
1977 print "<tr class=\"light\">\n";
1981 my ($to_mode_oct, $to_mode_str, $to_file_type);
1982 my ($from_mode_oct, $from_mode_str, $from_file_type);
1983 if ($diff{'to_mode'} ne ('0' x
6)) {
1984 $to_mode_oct = oct $diff{'to_mode'};
1985 if (S_ISREG
($to_mode_oct)) { # only for regular file
1986 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1988 $to_file_type = file_type
($diff{'to_mode'});
1990 if ($diff{'from_mode'} ne ('0' x
6)) {
1991 $from_mode_oct = oct $diff{'from_mode'};
1992 if (S_ISREG
($to_mode_oct)) { # only for regular file
1993 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1995 $from_file_type = file_type
($diff{'from_mode'});
1998 if ($diff{'status'} eq "A") { # created
1999 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2000 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2001 $mode_chng .= "]</span>";
2003 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2004 hash_base
=>$hash, file_name
=>$diff{'file'}),
2005 -class => "list"}, esc_path
($diff{'file'}));
2007 print "<td>$mode_chng</td>\n";
2008 print "<td class=\"link\">";
2009 if ($action eq 'commitdiff') {
2012 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2016 } elsif ($diff{'status'} eq "D") { # deleted
2017 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2019 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2020 hash_base
=>$parent, file_name
=>$diff{'file'}),
2021 -class => "list"}, esc_path
($diff{'file'}));
2023 print "<td>$mode_chng</td>\n";
2024 print "<td class=\"link\">";
2025 if ($action eq 'commitdiff') {
2028 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2031 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2032 hash_base
=>$parent, file_name
=>$diff{'file'})},
2034 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2035 file_name
=>$diff{'file'})},
2037 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2038 file_name
=>$diff{'file'})},
2042 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
2043 my $mode_chnge = "";
2044 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2045 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2046 if ($from_file_type != $to_file_type) {
2047 $mode_chnge .= " from $from_file_type to $to_file_type";
2049 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2050 if ($from_mode_str && $to_mode_str) {
2051 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2052 } elsif ($to_mode_str) {
2053 $mode_chnge .= " mode: $to_mode_str";
2056 $mode_chnge .= "]</span>\n";
2059 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2060 hash_base
=>$hash, file_name
=>$diff{'file'}),
2061 -class => "list"}, esc_path
($diff{'file'}));
2063 print "<td>$mode_chnge</td>\n";
2064 print "<td class=\"link\">";
2065 if ($action eq 'commitdiff') {
2068 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2070 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2071 # "commit" view and modified file (not onlu mode changed)
2072 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2073 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2074 hash_base
=>$hash, hash_parent_base
=>$parent,
2075 file_name
=>$diff{'file'})},
2079 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2080 hash_base
=>$hash, file_name
=>$diff{'file'})},
2082 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2083 file_name
=>$diff{'file'})},
2085 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2086 file_name
=>$diff{'file'})},
2090 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
2091 my %status_name = ('R' => 'moved', 'C' => 'copied');
2092 my $nstatus = $status_name{$diff{'status'}};
2094 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2095 # mode also for directories, so we cannot use $to_mode_str
2096 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2099 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2100 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
2101 -class => "list"}, esc_path
($diff{'to_file'})) . "</td>\n" .
2102 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2103 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2104 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
2105 -class => "list"}, esc_path
($diff{'from_file'})) .
2106 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2107 "<td class=\"link\">";
2108 if ($action eq 'commitdiff') {
2111 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2113 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2114 # "commit" view and modified file (not only pure rename or copy)
2115 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2116 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2117 hash_base
=>$hash, hash_parent_base
=>$parent,
2118 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
2122 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2123 hash_base
=>$parent, file_name
=>$diff{'from_file'})},
2125 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2126 file_name
=>$diff{'from_file'})},
2128 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2129 file_name
=>$diff{'from_file'})},
2133 } # we should not encounter Unmerged (U) or Unknown (X) status
2139 sub git_patchset_body
{
2140 my ($fd, $difftree, $hash, $hash_parent) = @_;
2144 my $patch_found = 0;
2147 print "<div class=\"patchset\">\n";
2150 while (my $patch_line = <$fd>) {
2153 if ($patch_line =~ m/^diff /) { # "git diff" header
2154 # beginning of patch (in patchset)
2156 # close previous patch
2157 print "</div>\n"; # class="patch"
2159 # first patch in patchset
2162 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2164 if (ref($difftree->[$patch_idx]) eq "HASH") {
2165 $diffinfo = $difftree->[$patch_idx];
2167 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2171 if ($diffinfo->{'status'} eq "A") { # added
2172 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
2173 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2174 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2175 $diffinfo->{'to_id'}) . " (new)" .
2176 "</div>\n"; # class="diff_info"
2178 } elsif ($diffinfo->{'status'} eq "D") { # deleted
2179 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
2180 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2181 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2182 $diffinfo->{'from_id'}) . " (deleted)" .
2183 "</div>\n"; # class="diff_info"
2185 } elsif ($diffinfo->{'status'} eq "R" || # renamed
2186 $diffinfo->{'status'} eq "C" || # copied
2187 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
2188 print "<div class=\"diff_info\">" .
2189 file_type
($diffinfo->{'from_mode'}) . ":" .
2190 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2191 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
2192 $diffinfo->{'from_id'}) .
2194 file_type
($diffinfo->{'to_mode'}) . ":" .
2195 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2196 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
2197 $diffinfo->{'to_id'});
2198 print "</div>\n"; # class="diff_info"
2200 } else { # modified, mode changed, ...
2201 print "<div class=\"diff_info\">" .
2202 file_type
($diffinfo->{'from_mode'}) . ":" .
2203 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2204 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2205 $diffinfo->{'from_id'}) .
2207 file_type
($diffinfo->{'to_mode'}) . ":" .
2208 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2209 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2210 $diffinfo->{'to_id'});
2211 print "</div>\n"; # class="diff_info"
2214 #print "<div class=\"diff extended_header\">\n";
2217 } # start of patch in patchset
2220 if ($in_header && $patch_line =~ m/^---/) {
2221 #print "</div>\n"; # class="diff extended_header"
2224 my $file = $diffinfo->{'from_file'};
2225 $file ||= $diffinfo->{'file'};
2226 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2227 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
2228 -class => "list"}, esc_path
($file));
2229 $patch_line =~ s
|a
/.*$|a/$file|g
;
2230 print "<div class=\"diff from_file\">$patch_line</div>\n";
2232 $patch_line = <$fd>;
2235 #$patch_line =~ m/^+++/;
2236 $file = $diffinfo->{'to_file'};
2237 $file ||= $diffinfo->{'file'};
2238 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2239 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
2240 -class => "list"}, esc_path
($file));
2241 $patch_line =~ s
|b
/.*|b/$file|g
;
2242 print "<div class=\"diff to_file\">$patch_line</div>\n";
2246 next LINE
if $in_header;
2248 print format_diff_line
($patch_line);
2250 print "</div>\n" if $patch_found; # class="patch"
2252 print "</div>\n"; # class="patchset"
2255 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2257 sub git_project_list_body
{
2258 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2260 my ($check_forks) = gitweb_check_feature
('forks');
2263 foreach my $pr (@
$projlist) {
2264 my (@aa) = git_get_last_activity
($pr->{'path'});
2268 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2269 if (!defined $pr->{'descr'}) {
2270 my $descr = git_get_project_description
($pr->{'path'}) || "";
2271 $pr->{'descr'} = chop_str
($descr, 25, 5);
2273 if (!defined $pr->{'owner'}) {
2274 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2277 my $pname = $pr->{'path'};
2278 if (($pname =~ s/\.git$//) &&
2279 ($pname !~ /\/$/) &&
2280 (-d
"$projectroot/$pname")) {
2281 $pr->{'forks'} = "-d $projectroot/$pname";
2287 push @projects, $pr;
2290 $order ||= "project";
2291 $from = 0 unless defined $from;
2292 $to = $#projects if (!defined $to || $#projects < $to);
2294 print "<table class=\"project_list\">\n";
2295 unless ($no_header) {
2298 print "<th></th>\n";
2300 if ($order eq "project") {
2301 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2302 print "<th>Project</th>\n";
2305 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2306 -class => "header"}, "Project") .
2309 if ($order eq "descr") {
2310 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2311 print "<th>Description</th>\n";
2314 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2315 -class => "header"}, "Description") .
2318 if ($order eq "owner") {
2319 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2320 print "<th>Owner</th>\n";
2323 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2324 -class => "header"}, "Owner") .
2327 if ($order eq "age") {
2328 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2329 print "<th>Last Change</th>\n";
2332 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2333 -class => "header"}, "Last Change") .
2336 print "<th></th>\n" .
2340 for (my $i = $from; $i <= $to; $i++) {
2341 my $pr = $projects[$i];
2343 print "<tr class=\"dark\">\n";
2345 print "<tr class=\"light\">\n";
2350 if ($pr->{'forks'}) {
2351 print "<!-- $pr->{'forks'} -->\n";
2352 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2356 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2357 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2358 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2359 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2360 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2361 $pr->{'age_string'} . "</td>\n" .
2362 "<td class=\"link\">" .
2363 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2364 $cgi->a({-href
=> '/git-browser/by-commit.html?r='.$pr->{'path'}}, "graphiclog") . " | " .
2365 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2366 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2367 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
2371 if (defined $extra) {
2374 print "<td></td>\n";
2376 print "<td colspan=\"5\">$extra</td>\n" .
2382 sub git_shortlog_body
{
2383 # uses global variable $project
2384 my ($revlist, $from, $to, $refs, $extra) = @_;
2386 $from = 0 unless defined $from;
2387 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2389 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2391 for (my $i = $from; $i <= $to; $i++) {
2392 my $commit = $revlist->[$i];
2393 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2394 my $ref = format_ref_marker
($refs, $commit);
2395 my %co = parse_commit
($commit);
2397 print "<tr class=\"dark\">\n";
2399 print "<tr class=\"light\">\n";
2402 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2403 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2404 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2406 print format_subject_html
($co{'title'}, $co{'title_short'},
2407 href
(action
=>"commit", hash
=>$commit), $ref);
2409 "<td class=\"link\">" .
2410 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
2411 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2412 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2413 if (gitweb_have_snapshot
()) {
2414 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2419 if (defined $extra) {
2421 "<td colspan=\"4\">$extra</td>\n" .
2427 sub git_history_body
{
2428 # Warning: assumes constant type (blob or tree) during history
2429 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2431 $from = 0 unless defined $from;
2432 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2434 print "<table class=\"history\" cellspacing=\"0\">\n";
2436 for (my $i = $from; $i <= $to; $i++) {
2437 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2442 my %co = parse_commit
($commit);
2447 my $ref = format_ref_marker
($refs, $commit);
2450 print "<tr class=\"dark\">\n";
2452 print "<tr class=\"light\">\n";
2455 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2456 # shortlog uses chop_str($co{'author_name'}, 10)
2457 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2459 # originally git_history used chop_str($co{'title'}, 50)
2460 print format_subject_html
($co{'title'}, $co{'title_short'},
2461 href
(action
=>"commit", hash
=>$commit), $ref);
2463 "<td class=\"link\">" .
2464 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2465 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2467 if ($ftype eq 'blob') {
2468 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2469 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2470 if (defined $blob_current && defined $blob_parent &&
2471 $blob_current ne $blob_parent) {
2473 $cgi->a({-href
=> href
(action
=>"blobdiff",
2474 hash
=>$blob_current, hash_parent
=>$blob_parent,
2475 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2476 file_name
=>$file_name)},
2483 if (defined $extra) {
2485 "<td colspan=\"4\">$extra</td>\n" .
2492 # uses global variable $project
2493 my ($taglist, $from, $to, $extra) = @_;
2494 $from = 0 unless defined $from;
2495 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2497 print "<table class=\"tags\" cellspacing=\"0\">\n";
2499 for (my $i = $from; $i <= $to; $i++) {
2500 my $entry = $taglist->[$i];
2502 my $comment = $tag{'subject'};
2504 if (defined $comment) {
2505 $comment_short = chop_str
($comment, 30, 5);
2508 print "<tr class=\"dark\">\n";
2510 print "<tr class=\"light\">\n";
2513 print "<td><i>$tag{'age'}</i></td>\n" .
2515 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2516 -class => "list name"}, esc_html
($tag{'name'})) .
2519 if (defined $comment) {
2520 print format_subject_html
($comment, $comment_short,
2521 href
(action
=>"tag", hash
=>$tag{'id'}));
2524 "<td class=\"selflink\">";
2525 if ($tag{'type'} eq "tag") {
2526 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2531 "<td class=\"link\">" . " | " .
2532 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2533 if ($tag{'reftype'} eq "commit") {
2534 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2535 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
2536 } elsif ($tag{'reftype'} eq "blob") {
2537 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2542 if (defined $extra) {
2544 "<td colspan=\"5\">$extra</td>\n" .
2550 sub git_heads_body
{
2551 # uses global variable $project
2552 my ($headlist, $head, $from, $to, $extra) = @_;
2553 $from = 0 unless defined $from;
2554 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2556 print "<table class=\"heads\" cellspacing=\"0\">\n";
2558 for (my $i = $from; $i <= $to; $i++) {
2559 my $entry = $headlist->[$i];
2561 my $curr = $ref{'id'} eq $head;
2563 print "<tr class=\"dark\">\n";
2565 print "<tr class=\"light\">\n";
2568 print "<td><i>$ref{'age'}</i></td>\n" .
2569 ($curr ?
"<td class=\"current_head\">" : "<td>") .
2570 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
2571 -class => "list name"},esc_html
($ref{'name'})) .
2573 "<td class=\"link\">" .
2574 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
2575 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
2576 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
2580 if (defined $extra) {
2582 "<td colspan=\"3\">$extra</td>\n" .
2588 ## ======================================================================
2589 ## ======================================================================
2592 sub git_project_list
{
2593 my $order = $cgi->param('o');
2594 if (defined $order && $order !~ m/project|descr|owner|age/) {
2595 die_error
(undef, "Unknown order parameter");
2598 my @list = git_get_projects_list
();
2600 die_error
(undef, "No projects found");
2604 if (-f
$home_text) {
2605 print "<div class=\"index_include\">\n";
2606 open (my $fd, $home_text);
2611 git_project_list_body
(\
@list, $order);
2616 my $order = $cgi->param('o');
2617 if (defined $order && $order !~ m/project|descr|owner|age/) {
2618 die_error
(undef, "Unknown order parameter");
2621 my @list = git_get_projects_list
($project);
2623 die_error
(undef, "No forks found");
2627 git_print_page_nav
('','');
2628 git_print_header_div
('summary', "$project forks");
2629 git_project_list_body
(\
@list, $order);
2633 sub git_project_index
{
2634 my @projects = git_get_projects_list
($project);
2637 -type
=> 'text/plain',
2638 -charset
=> 'utf-8',
2639 -content_disposition
=> 'inline; filename="index.aux"');
2641 foreach my $pr (@projects) {
2642 if (!exists $pr->{'owner'}) {
2643 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2646 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2647 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2648 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2649 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2653 print "$path $owner\n";
2658 my $descr = git_get_project_description
($project) || "none";
2659 my $head = git_get_head_hash
($project);
2660 my %co = parse_commit
($head);
2661 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2663 my $owner = git_get_project_owner
($project);
2665 my $refs = git_get_references
();
2666 my @taglist = git_get_tags_list
(15);
2667 my @headlist = git_get_heads_list
(15);
2669 my ($check_forks) = gitweb_check_feature
('forks');
2672 @forklist = git_get_projects_list
($project);
2676 git_print_page_nav
('summary','', $head);
2678 print "<div class=\"title\"> </div>\n";
2679 print "<table cellspacing=\"0\">\n" .
2680 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2681 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2682 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2683 # use per project git URL list in $projectroot/$project/cloneurl
2684 # or make project git URL from git base URL and project name
2685 my $url_tag = "URL";
2686 my @url_list = git_get_project_url_list
($project);
2687 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2688 foreach my $git_url (@url_list) {
2689 next unless $git_url;
2690 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2695 if (-s
"$projectroot/$project/README.html") {
2696 if (open my $fd, "$projectroot/$project/README.html") {
2697 print "<div class=\"title\">readme</div>\n";
2698 print $_ while (<$fd>);
2703 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2704 git_get_head_hash
($project), "--"
2705 or die_error
(undef, "Open git-rev-list failed");
2706 my @revlist = map { chomp; $_ } <$fd>;
2708 git_print_header_div
('shortlog');
2709 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2710 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2713 git_print_header_div
('tags');
2714 git_tags_body
(\
@taglist, 0, 15,
2715 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2719 git_print_header_div
('heads');
2720 git_heads_body
(\
@headlist, $head, 0, 15,
2721 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2725 git_print_header_div
('forks');
2726 git_project_list_body
(\
@forklist, undef, 0, 15,
2727 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
2735 my $head = git_get_head_hash
($project);
2737 git_print_page_nav
('','', $head,undef,$head);
2738 my %tag = parse_tag
($hash);
2739 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2740 print "<div class=\"title_text\">\n" .
2741 "<table cellspacing=\"0\">\n" .
2743 "<td>object</td>\n" .
2744 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2745 $tag{'object'}) . "</td>\n" .
2746 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2747 $tag{'type'}) . "</td>\n" .
2749 if (defined($tag{'author'})) {
2750 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2751 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2752 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2753 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2756 print "</table>\n\n" .
2758 print "<div class=\"page_body\">";
2759 my $comment = $tag{'comment'};
2760 foreach my $line (@
$comment) {
2761 print esc_html
($line) . "<br/>\n";
2771 my ($have_blame) = gitweb_check_feature
('blame');
2773 die_error
('403 Permission denied', "Permission denied");
2775 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2776 $hash_base ||= git_get_head_hash
($project);
2777 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2778 my %co = parse_commit
($hash_base)
2779 or die_error
(undef, "Reading commit failed");
2780 if (!defined $hash) {
2781 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2782 or die_error
(undef, "Error looking up file");
2784 $ftype = git_get_type
($hash);
2785 if ($ftype !~ "blob") {
2786 die_error
("400 Bad Request", "Object is not a blob");
2788 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
2789 $file_name, $hash_base)
2790 or die_error
(undef, "Open git-blame failed");
2793 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2796 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2799 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2801 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2802 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2803 git_print_page_path
($file_name, $ftype, $hash_base);
2804 my @rev_color = (qw(light2 dark2));
2805 my $num_colors = scalar(@rev_color);
2806 my $current_color = 0;
2809 <div class="page_body">
2810 <table class="blame">
2811 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2816 last unless defined $_;
2817 my ($full_rev, $orig_lineno, $lineno, $group_size) =
2818 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
2819 if (!exists $metainfo{$full_rev}) {
2820 $metainfo{$full_rev} = {};
2822 my $meta = $metainfo{$full_rev};
2825 if (/^(\S+) (.*)$/) {
2830 my $rev = substr($full_rev, 0, 8);
2831 my $author = $meta->{'author'};
2832 my %date = parse_date
($meta->{'author-time'},
2833 $meta->{'author-tz'});
2834 my $date = $date{'iso-tz'};
2836 $current_color = ++$current_color % $num_colors;
2838 print "<tr class=\"$rev_color[$current_color]\">\n";
2840 print "<td class=\"sha1\"";
2841 print " title=\"". esc_html
($author) . ", $date\"";
2842 print " rowspan=\"$group_size\"" if ($group_size > 1);
2844 print $cgi->a({-href
=> href
(action
=>"commit",
2846 file_name
=>$file_name)},
2850 my $blamed = href
(action
=> 'blame',
2851 file_name
=> $meta->{'filename'},
2852 hash_base
=> $full_rev);
2853 print "<td class=\"linenr\">";
2854 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
2856 -class => "linenr" },
2859 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2865 or print "Reading blob failed\n";
2872 my ($have_blame) = gitweb_check_feature
('blame');
2874 die_error
('403 Permission denied', "Permission denied");
2876 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2877 $hash_base ||= git_get_head_hash
($project);
2878 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2879 my %co = parse_commit
($hash_base)
2880 or die_error
(undef, "Reading commit failed");
2881 if (!defined $hash) {
2882 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2883 or die_error
(undef, "Error lookup file");
2885 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2886 or die_error
(undef, "Open git-annotate failed");
2889 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2892 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2895 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2897 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2898 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2899 git_print_page_path
($file_name, 'blob', $hash_base);
2900 print "<div class=\"page_body\">\n";
2902 <table class="blame">
2911 my @line_class = (qw(light dark));
2912 my $line_class_len = scalar (@line_class);
2913 my $line_class_num = $#line_class;
2914 while (my $line = <$fd>) {
2926 $line_class_num = ($line_class_num + 1) % $line_class_len;
2928 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2935 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2938 $short_rev = substr ($long_rev, 0, 8);
2939 $age = time () - $time;
2940 $age_str = age_string
($age);
2941 $age_str =~ s/ / /g;
2942 $age_class = age_class
($age);
2943 $author = esc_html
($author);
2944 $author =~ s/ / /g;
2946 $data = untabify
($data);
2947 $data = esc_html
($data);
2950 <tr class="$line_class[$line_class_num]">
2951 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2952 <td class="$age_class">$age_str</td>
2954 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2955 <td class="pre">$data</td>
2958 } # while (my $line = <$fd>)
2959 print "</table>\n\n";
2961 or print "Reading blob failed.\n";
2967 my $head = git_get_head_hash
($project);
2969 git_print_page_nav
('','', $head,undef,$head);
2970 git_print_header_div
('summary', $project);
2972 my @tagslist = git_get_tags_list
();
2974 git_tags_body
(\
@tagslist);
2980 my $head = git_get_head_hash
($project);
2982 git_print_page_nav
('','', $head,undef,$head);
2983 git_print_header_div
('summary', $project);
2985 my @headslist = git_get_heads_list
();
2987 git_heads_body
(\
@headslist, $head);
2992 sub git_blob_plain
{
2995 if (!defined $hash) {
2996 if (defined $file_name) {
2997 my $base = $hash_base || git_get_head_hash
($project);
2998 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2999 or die_error
(undef, "Error lookup file");
3001 die_error
(undef, "No file name defined");
3003 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3004 # blobs defined by non-textual hash id's can be cached
3009 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3010 or die_error
(undef, "Couldn't cat $file_name, $hash");
3012 $type ||= blob_mimetype
($fd, $file_name);
3014 # save as filename, even when no $file_name is given
3015 my $save_as = "$hash";
3016 if (defined $file_name) {
3017 $save_as = $file_name;
3018 } elsif ($type =~ m/^text\//) {
3025 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3027 binmode STDOUT
, ':raw';
3029 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3037 if (!defined $hash) {
3038 if (defined $file_name) {
3039 my $base = $hash_base || git_get_head_hash
($project);
3040 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3041 or die_error
(undef, "Error lookup file");
3043 die_error
(undef, "No file name defined");
3045 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3046 # blobs defined by non-textual hash id's can be cached
3050 my ($have_blame) = gitweb_check_feature
('blame');
3051 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3052 or die_error
(undef, "Couldn't cat $file_name, $hash");
3053 my $mimetype = blob_mimetype
($fd, $file_name);
3054 if ($mimetype !~ m/^text\//) {
3056 return git_blob_plain
($mimetype);
3058 git_header_html
(undef, $expires);
3059 my $formats_nav = '';
3060 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3061 if (defined $file_name) {
3064 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3065 hash
=>$hash, file_name
=>$file_name)},
3070 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3071 hash
=>$hash, file_name
=>$file_name)},
3074 $cgi->a({-href
=> href
(action
=>"blob_plain",
3075 hash
=>$hash, file_name
=>$file_name)},
3078 $cgi->a({-href
=> href
(action
=>"blob",
3079 hash_base
=>"HEAD", file_name
=>$file_name)},
3083 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3085 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3086 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3088 print "<div class=\"page_nav\">\n" .
3089 "<br/><br/></div>\n" .
3090 "<div class=\"title\">$hash</div>\n";
3092 git_print_page_path
($file_name, "blob", $hash_base);
3093 print "<div class=\"page_body\">\n";
3095 while (my $line = <$fd>) {
3098 $line = untabify
($line);
3099 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3100 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3103 or print "Reading blob failed.\n";
3109 my $have_snapshot = gitweb_have_snapshot
();
3111 if (!defined $hash_base) {
3112 $hash_base = "HEAD";
3114 if (!defined $hash) {
3115 if (defined $file_name) {
3116 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3122 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3123 or die_error
(undef, "Open git-ls-tree failed");
3124 my @entries = map { chomp; $_ } <$fd>;
3125 close $fd or die_error
(undef, "Reading tree failed");
3128 my $refs = git_get_references
();
3129 my $ref = format_ref_marker
($refs, $hash_base);
3132 my ($have_blame) = gitweb_check_feature
('blame');
3133 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3135 if (defined $file_name) {
3137 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3138 hash
=>$hash, file_name
=>$file_name)},
3140 $cgi->a({-href
=> href
(action
=>"tree",
3141 hash_base
=>"HEAD", file_name
=>$file_name)},
3144 if ($have_snapshot) {
3145 # FIXME: Should be available when we have no hash base as well.
3147 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3150 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3151 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3154 print "<div class=\"page_nav\">\n";
3155 print "<br/><br/></div>\n";
3156 print "<div class=\"title\">$hash</div>\n";
3158 if (defined $file_name) {
3159 $basedir = $file_name;
3160 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3164 git_print_page_path
($file_name, 'tree', $hash_base);
3165 print "<div class=\"page_body\">\n";
3166 print "<table cellspacing=\"0\">\n";
3168 # '..' (top directory) link if possible
3169 if (defined $hash_base &&
3170 defined $file_name && $file_name =~ m![^/]+$!) {
3172 print "<tr class=\"dark\">\n";
3174 print "<tr class=\"light\">\n";
3178 my $up = $file_name;
3179 $up =~ s!/?[^/]+$!!;
3180 undef $up unless $up;
3181 # based on git_print_tree_entry
3182 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3183 print '<td class="list">';
3184 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3188 print "<td class=\"link\"></td>\n";
3192 foreach my $line (@entries) {
3193 my %t = parse_ls_tree_line
($line, -z
=> 1);
3196 print "<tr class=\"dark\">\n";
3198 print "<tr class=\"light\">\n";
3202 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3206 print "</table>\n" .
3212 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3213 my $have_snapshot = (defined $ctype && defined $suffix);
3214 if (!$have_snapshot) {
3215 die_error
('403 Permission denied', "Permission denied");
3218 if (!defined $hash) {
3219 $hash = git_get_head_hash
($project);
3222 my $filename = basename
($project) . "-$hash.tar.$suffix";
3225 -type
=> 'application/x-tar',
3226 -content_encoding
=> $ctype,
3227 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3228 -status
=> '200 OK');
3230 my $git = git_cmd_str
();
3231 my $name = $project;
3232 $name =~ s/\047/\047\\\047\047/g;
3234 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3235 or die_error
(undef, "Execute git-tar-tree failed.");
3236 binmode STDOUT
, ':raw';
3238 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3244 my $head = git_get_head_hash
($project);
3245 if (!defined $hash) {
3248 if (!defined $page) {
3251 my $refs = git_get_references
();
3253 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3254 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash, "--"
3255 or die_error
(undef, "Open git-rev-list failed");
3256 my @revlist = map { chomp; $_ } <$fd>;
3259 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
3262 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3265 my %co = parse_commit
($hash);
3267 git_print_header_div
('summary', $project);
3268 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3270 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
3271 my $commit = $revlist[$i];
3272 my $ref = format_ref_marker
($refs, $commit);
3273 my %co = parse_commit
($commit);
3275 my %ad = parse_date
($co{'author_epoch'});
3276 git_print_header_div
('commit',
3277 "<span class=\"age\">$co{'age_string'}</span>" .
3278 esc_html
($co{'title'}) . $ref,
3280 print "<div class=\"title_text\">\n" .
3281 "<div class=\"log_link\">\n" .
3282 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3284 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3286 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3289 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3292 print "<div class=\"log_body\">\n";
3293 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
3300 my %co = parse_commit
($hash);
3302 die_error
(undef, "Unknown commit object");
3304 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3305 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3307 my $parent = $co{'parent'};
3308 if (!defined $parent) {
3311 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
3312 @diff_opts, $parent, $hash, "--"
3313 or die_error
(undef, "Open git-diff-tree failed");
3314 my @difftree = map { chomp; $_ } <$fd>;
3315 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3317 # non-textual hash id's can be cached
3319 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3322 my $refs = git_get_references
();
3323 my $ref = format_ref_marker
($refs, $co{'id'});
3325 my $have_snapshot = gitweb_have_snapshot
();
3328 if (defined $file_name && defined $co{'parent'}) {
3330 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
3333 git_header_html
(undef, $expires);
3334 git_print_page_nav
('commit', '',
3335 $hash, $co{'tree'}, $hash,
3336 join (' | ', @views_nav));
3338 if (defined $co{'parent'}) {
3339 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3341 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3343 print "<div class=\"title_text\">\n" .
3344 "<table cellspacing=\"0\">\n";
3345 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3347 "<td></td><td> $ad{'rfc2822'}";
3348 if ($ad{'hour_local'} < 6) {
3349 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3350 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3352 printf(" (%02d:%02d %s)",
3353 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3357 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3358 print "<tr><td></td><td> $cd{'rfc2822'}" .
3359 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3361 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3364 "<td class=\"sha1\">" .
3365 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3366 class => "list"}, $co{'tree'}) .
3368 "<td class=\"link\">" .
3369 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3371 if ($have_snapshot) {
3373 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3377 my $parents = $co{'parents'};
3378 foreach my $par (@
$parents) {
3381 "<td class=\"sha1\">" .
3382 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3383 class => "list"}, $par) .
3385 "<td class=\"link\">" .
3386 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3388 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3395 print "<div class=\"page_body\">\n";
3396 git_print_log
($co{'comment'});
3399 git_difftree_body
(\
@difftree, $hash, $parent);
3405 my $format = shift || 'html';
3412 # preparing $fd and %diffinfo for git_patchset_body
3414 if (defined $hash_base && defined $hash_parent_base) {
3415 if (defined $file_name) {
3417 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3418 $hash_parent_base, $hash_base,
3420 or die_error
(undef, "Open git-diff-tree failed");
3421 @difftree = map { chomp; $_ } <$fd>;
3423 or die_error
(undef, "Reading git-diff-tree failed");
3425 or die_error
('404 Not Found', "Blob diff not found");
3427 } elsif (defined $hash &&
3428 $hash =~ /[0-9a-fA-F]{40}/) {
3429 # try to find filename from $hash
3431 # read filtered raw output
3432 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3433 $hash_parent_base, $hash_base, "--"
3434 or die_error
(undef, "Open git-diff-tree failed");
3436 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3438 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3439 map { chomp; $_ } <$fd>;
3441 or die_error
(undef, "Reading git-diff-tree failed");
3443 or die_error
('404 Not Found', "Blob diff not found");
3446 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3449 if (@difftree > 1) {
3450 die_error
('404 Not Found', "Ambiguous blob diff specification");
3453 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3454 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3455 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3457 $hash_parent ||= $diffinfo{'from_id'};
3458 $hash ||= $diffinfo{'to_id'};
3460 # non-textual hash id's can be cached
3461 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3462 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3467 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3468 '-p', $hash_parent_base, $hash_base,
3470 or die_error
(undef, "Open git-diff-tree failed");
3473 # old/legacy style URI
3474 if (!%diffinfo && # if new style URI failed
3475 defined $hash && defined $hash_parent) {
3476 # fake git-diff-tree raw output
3477 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3478 $diffinfo{'from_id'} = $hash_parent;
3479 $diffinfo{'to_id'} = $hash;
3480 if (defined $file_name) {
3481 if (defined $file_parent) {
3482 $diffinfo{'status'} = '2';
3483 $diffinfo{'from_file'} = $file_parent;
3484 $diffinfo{'to_file'} = $file_name;
3485 } else { # assume not renamed
3486 $diffinfo{'status'} = '1';
3487 $diffinfo{'from_file'} = $file_name;
3488 $diffinfo{'to_file'} = $file_name;
3490 } else { # no filename given
3491 $diffinfo{'status'} = '2';
3492 $diffinfo{'from_file'} = $hash_parent;
3493 $diffinfo{'to_file'} = $hash;
3496 # non-textual hash id's can be cached
3497 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3498 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3503 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts,
3504 $hash_parent, $hash, "--"
3505 or die_error
(undef, "Open git-diff failed");
3507 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3512 if ($format eq 'html') {
3514 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3515 hash
=>$hash, hash_parent
=>$hash_parent,
3516 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3517 file_name
=>$file_name, file_parent
=>$file_parent)},
3519 git_header_html
(undef, $expires);
3520 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3521 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3522 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3524 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3525 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3527 if (defined $file_name) {
3528 git_print_page_path
($file_name, "blob", $hash_base);
3530 print "<div class=\"page_path\"></div>\n";
3533 } elsif ($format eq 'plain') {
3535 -type
=> 'text/plain',
3536 -charset
=> 'utf-8',
3537 -expires
=> $expires,
3538 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3540 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3543 die_error
(undef, "Unknown blobdiff format");
3547 if ($format eq 'html') {
3548 print "<div class=\"page_body\">\n";
3550 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3553 print "</div>\n"; # class="page_body"
3557 while (my $line = <$fd>) {
3558 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
3559 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
3563 last if $line =~ m!^\+\+\+!;
3571 sub git_blobdiff_plain
{
3572 git_blobdiff
('plain');
3575 sub git_commitdiff
{
3576 my $format = shift || 'html';
3577 my %co = parse_commit
($hash);
3579 die_error
(undef, "Unknown commit object");
3582 # we need to prepare $formats_nav before any parameter munging
3584 if ($format eq 'html') {
3586 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3587 hash
=>$hash, hash_parent
=>$hash_parent)},
3590 if (defined $hash_parent) {
3591 # commitdiff with two commits given
3592 my $hash_parent_short = $hash_parent;
3593 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3594 $hash_parent_short = substr($hash_parent, 0, 7);
3598 $cgi->a({-href
=> href
(action
=>"commitdiff",
3599 hash
=>$hash_parent)},
3600 esc_html
($hash_parent_short)) .
3602 } elsif (!$co{'parent'}) {
3604 $formats_nav .= ' (initial)';
3605 } elsif (scalar @
{$co{'parents'}} == 1) {
3606 # single parent commit
3609 $cgi->a({-href
=> href
(action
=>"commitdiff",
3610 hash
=>$co{'parent'})},
3611 esc_html
(substr($co{'parent'}, 0, 7))) .
3618 $cgi->a({-href
=> href
(action
=>"commitdiff",
3620 esc_html
(substr($_, 0, 7)));
3621 } @
{$co{'parents'}} ) .
3626 if (!defined $hash_parent) {
3627 $hash_parent = $co{'parent'} || '--root';
3633 if ($format eq 'html') {
3634 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3635 "--no-commit-id", "--patch-with-raw", "--full-index",
3636 $hash_parent, $hash, "--"
3637 or die_error
(undef, "Open git-diff-tree failed");
3639 while (chomp(my $line = <$fd>)) {
3640 # empty line ends raw part of diff-tree output
3642 push @difftree, $line;
3645 } elsif ($format eq 'plain') {
3646 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3647 '-p', $hash_parent, $hash, "--"
3648 or die_error
(undef, "Open git-diff-tree failed");
3651 die_error
(undef, "Unknown commitdiff format");
3654 # non-textual hash id's can be cached
3656 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3660 # write commit message
3661 if ($format eq 'html') {
3662 my $refs = git_get_references
();
3663 my $ref = format_ref_marker
($refs, $co{'id'});
3665 git_header_html
(undef, $expires);
3666 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3667 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3668 git_print_authorship
(\
%co);
3669 print "<div class=\"page_body\">\n";
3670 if (@
{$co{'comment'}} > 1) {
3671 print "<div class=\"log\">\n";
3672 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
3673 print "</div>\n"; # class="log"
3676 } elsif ($format eq 'plain') {
3677 my $refs = git_get_references
("tags");
3678 my $tagname = git_get_rev_name_tags
($hash);
3679 my $filename = basename
($project) . "-$hash.patch";
3682 -type
=> 'text/plain',
3683 -charset
=> 'utf-8',
3684 -expires
=> $expires,
3685 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3686 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3689 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3690 Subject: $co{'title'}
3692 print "X-Git-Tag: $tagname\n" if $tagname;
3693 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3695 foreach my $line (@
{$co{'comment'}}) {
3702 if ($format eq 'html') {
3703 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3706 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3708 print "</div>\n"; # class="page_body"
3711 } elsif ($format eq 'plain') {
3715 or print "Reading git-diff-tree failed\n";
3719 sub git_commitdiff_plain
{
3720 git_commitdiff
('plain');
3724 if (!defined $hash_base) {
3725 $hash_base = git_get_head_hash
($project);
3727 if (!defined $page) {
3731 my %co = parse_commit
($hash_base);
3733 die_error
(undef, "Unknown commit object");
3736 my $refs = git_get_references
();
3737 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3739 if (!defined $hash && defined $file_name) {
3740 $hash = git_get_hash_by_path
($hash_base, $file_name);
3742 if (defined $hash) {
3743 $ftype = git_get_type
($hash);
3747 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3748 or die_error
(undef, "Open git-rev-list-failed");
3749 my @revlist = map { chomp; $_ } <$fd>;
3751 or die_error
(undef, "Reading git-rev-list failed");
3753 my $paging_nav = '';
3756 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3757 file_name
=>$file_name)},
3759 $paging_nav .= " ⋅ " .
3760 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3761 file_name
=>$file_name, page
=>$page-1),
3762 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3764 $paging_nav .= "first";
3765 $paging_nav .= " ⋅ prev";
3767 if ($#revlist >= (100 * ($page+1)-1)) {
3768 $paging_nav .= " ⋅ " .
3769 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3770 file_name
=>$file_name, page
=>$page+1),
3771 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3773 $paging_nav .= " ⋅ next";
3776 if ($#revlist >= (100 * ($page+1)-1)) {
3778 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3779 file_name
=>$file_name, page
=>$page+1),
3780 -title
=> "Alt-n"}, "next");
3784 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3785 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3786 git_print_page_path
($file_name, $ftype, $hash_base);
3788 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3789 $refs, $hash_base, $ftype, $next_link);
3795 if (!defined $searchtext) {
3796 die_error
(undef, "Text field empty");
3798 if (!defined $hash) {
3799 $hash = git_get_head_hash
($project);
3801 my %co = parse_commit
($hash);
3803 die_error
(undef, "Unknown commit object");
3806 $searchtype ||= 'commit';
3807 if ($searchtype eq 'pickaxe') {
3808 # pickaxe may take all resources of your box and run for several minutes
3809 # with every query - so decide by yourself how public you make this feature
3810 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3811 if (!$have_pickaxe) {
3812 die_error
('403 Permission denied', "Permission denied");
3817 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3818 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3820 print "<table cellspacing=\"0\">\n";
3822 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
3824 open my $fd, "-|", git_cmd
(), "rev-list",
3825 "--header", "--parents", $hash, "--"
3827 while (my $commit_text = <$fd>) {
3828 if (!grep m/$searchtext/i, $commit_text) {
3831 if ($searchtype eq 'author' && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3834 if ($searchtype eq 'committer' && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3837 my @commit_lines = split "\n", $commit_text;
3838 my %co = parse_commit
(undef, \
@commit_lines);
3843 print "<tr class=\"dark\">\n";
3845 print "<tr class=\"light\">\n";
3848 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3849 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3851 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3852 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3853 my $comment = $co{'comment'};
3854 foreach my $line (@
$comment) {
3855 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3856 my $lead = esc_html
($1) || "";
3857 $lead = chop_str
($lead, 30, 10);
3858 my $match = esc_html
($2) || "";
3859 my $trail = esc_html
($3) || "";
3860 $trail = chop_str
($trail, 30, 10);
3861 my $text = "$lead<span class=\"match\">$match</span>$trail";
3862 print chop_str
($text, 80, 5) . "<br/>\n";
3866 "<td class=\"link\">" .
3867 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3869 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3876 if ($searchtype eq 'pickaxe') {
3878 my $git_command = git_cmd_str
();
3879 open my $fd, "-|", "$git_command rev-list $hash | " .
3880 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3883 while (my $line = <$fd>) {
3884 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3887 $set{'from_id'} = $3;
3889 $set{'id'} = $set{'to_id'};
3890 if ($set{'id'} =~ m/0{40}/) {
3891 $set{'id'} = $set{'from_id'};
3893 if ($set{'id'} =~ m/0{40}/) {
3897 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3900 print "<tr class=\"dark\">\n";
3902 print "<tr class=\"light\">\n";
3905 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3906 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3908 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3909 -class => "list subject"},
3910 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3911 while (my $setref = shift @files) {
3913 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3914 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3916 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
3920 "<td class=\"link\">" .
3921 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3923 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3927 %co = parse_commit
($1);
3936 sub git_search_help
{
3938 git_print_page_nav
('','', $hash,$hash,$hash);
3941 <dt><b>commit</b></dt>
3942 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
3943 <dt><b>author</b></dt>
3944 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
3945 <dt><b>committer</b></dt>
3946 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
3948 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3949 if ($have_pickaxe) {
3951 <dt><b>pickaxe</b></dt>
3952 <dd>All commits that caused the string to appear or disappear from any file (changes that
3953 added, removed or "modified" the string) will be listed. This search can take a while and
3954 takes a lot of strain on the server, so please use it wisely.</dd>
3962 my $head = git_get_head_hash
($project);
3963 if (!defined $hash) {
3966 if (!defined $page) {
3969 my $refs = git_get_references
();
3971 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3972 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash, "--"
3973 or die_error
(undef, "Open git-rev-list failed");
3974 my @revlist = map { chomp; $_ } <$fd>;
3977 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3979 if ($#revlist >= (100 * ($page+1)-1)) {
3981 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3982 -title
=> "Alt-n"}, "next");
3987 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3988 git_print_header_div
('summary', $project);
3990 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3995 ## ......................................................................
3996 ## feeds (RSS, OPML)
3999 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4000 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150",
4001 git_get_head_hash
($project), "--"
4002 or die_error
(undef, "Open git-rev-list failed");
4003 my @revlist = map { chomp; $_ } <$fd>;
4004 close $fd or die_error
(undef, "Reading git-rev-list failed");
4005 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
4007 <?xml version="1.0" encoding="utf-8"?>
4008 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
4010 <title>$project $my_uri $my_url</title>
4011 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
4012 <description>$project log</description>
4013 <language>en</language>
4016 for (my $i = 0; $i <= $#revlist; $i++) {
4017 my $commit = $revlist[$i];
4018 my %co = parse_commit
($commit);
4019 # we read 150, we always show 30 and the ones more recent than 48 hours
4020 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
4023 my %cd = parse_date
($co{'committer_epoch'});
4024 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4025 $co{'parent'}, $co{'id'}, "--"
4027 my @difftree = map { chomp; $_ } <$fd>;
4032 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
4034 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
4035 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
4036 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
4037 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
4038 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
4039 "<content:encoded>" .
4041 my $comment = $co{'comment'};
4042 foreach my $line (@
$comment) {
4043 $line = to_utf8
($line);
4044 print "$line<br/>\n";
4047 foreach my $line (@difftree) {
4048 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
4051 my $file = esc_path
(unquote
($7));
4052 $file = to_utf8
($file);
4053 print "$file<br/>\n";
4056 "</content:encoded>\n" .
4059 print "</channel></rss>";
4063 my @list = git_get_projects_list
();
4065 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
4067 <?xml version="1.0" encoding="utf-8"?>
4068 <opml version="1.0">
4070 <title>$site_name OPML Export</title>
4073 <outline text="git RSS feeds">
4076 foreach my $pr (@list) {
4078 my $head = git_get_head_hash
($proj{'path'});
4079 if (!defined $head) {
4082 $git_dir = "$projectroot/$proj{'path'}";
4083 my %co = parse_commit
($head);
4088 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
4089 my $rss = "$my_url?p=$proj{'path'};a=rss";
4090 my $html = "$my_url?p=$proj{'path'};a=summary";
4091 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";