3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 our $version = "++GIT_VERSION++";
23 our $my_url = $cgi->url();
24 our $my_uri = $cgi->url(-absolute
=> 1);
26 # core git executable to use
27 # this can just be "git" if your webserver has a sensible PATH
28 our $GIT = "++GIT_BINDIR++/git";
30 # absolute fs-path which will be prepended to the project path
31 #our $projectroot = "/pub/scm";
32 our $projectroot = "++GITWEB_PROJECTROOT++";
34 # target of the home link on top of all pages
35 our $home_link = $my_uri || "/";
37 # string of the home link on top of all pages
38 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
40 # name of your site or organization to appear in page titles
41 # replace this with something more descriptive for clearer bookmarks
42 our $site_name = "++GITWEB_SITENAME++"
43 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
45 # filename of html text to include at top of each page
46 our $site_header = "++GITWEB_SITE_HEADER++";
47 # html text to include at home page
48 our $home_text = "++GITWEB_HOMETEXT++";
49 # filename of html text to include at bottom of each page
50 our $site_footer = "++GITWEB_SITE_FOOTER++";
53 our @stylesheets = ("++GITWEB_CSS++");
54 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
55 our $stylesheet = undef;
57 # URI of GIT logo (72x27 size)
58 our $logo = "++GITWEB_LOGO++";
59 # URI of GIT favicon, assumed to be image/png type
60 our $favicon = "++GITWEB_FAVICON++";
62 # URI and label (title) of GIT logo link
63 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
64 #our $logo_label = "git documentation";
65 our $logo_url = "http://git.or.cz/";
66 our $logo_label = "git homepage";
68 # source of projects list
69 our $projects_list = "++GITWEB_LIST++";
71 # show repository only if this file exists
72 # (only effective if this variable evaluates to true)
73 our $export_ok = "++GITWEB_EXPORT_OK++";
75 # only allow viewing of repositories also shown on the overview page
76 our $strict_export = "++GITWEB_STRICT_EXPORT++";
78 # list of git base URLs used for URL to where fetch project from,
79 # i.e. full URL is "$git_base_url/$project"
80 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
82 # default blob_plain mimetype and default charset for text/plain blob
83 our $default_blob_plain_mimetype = 'text/plain';
84 our $default_text_plain_charset = undef;
86 # file to use for guessing MIME types before trying /etc/mime.types
87 # (relative to the current git repository)
88 our $mimetypes_file = undef;
90 # You define site-wide feature defaults here; override them with
91 # $GITWEB_CONFIG as necessary.
94 # 'sub' => feature-sub (subroutine),
95 # 'override' => allow-override (boolean),
96 # 'default' => [ default options...] (array reference)}
98 # if feature is overridable (it means that allow-override has true value,
99 # then feature-sub will be called with default options as parameters;
100 # return value of feature-sub indicates if to enable specified feature
102 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
104 # Enable the 'blame' blob view, showing the last commit that modified
105 # each line in the file. This can be very CPU-intensive.
107 # To enable system wide have in $GITWEB_CONFIG
108 # $feature{'blame'}{'default'} = [1];
109 # To have project specific config enable override in $GITWEB_CONFIG
110 # $feature{'blame'}{'override'} = 1;
111 # and in project config gitweb.blame = 0|1;
113 'sub' => \
&feature_blame
,
117 # Enable the 'snapshot' link, providing a compressed tarball of any
118 # tree. This can potentially generate high traffic if you have large
121 # To disable system wide have in $GITWEB_CONFIG
122 # $feature{'snapshot'}{'default'} = [undef];
123 # To have project specific config enable override in $GITWEB_CONFIG
124 # $feature{'blame'}{'override'} = 1;
125 # and in project config gitweb.snapshot = none|gzip|bzip2;
127 'sub' => \
&feature_snapshot
,
129 # => [content-encoding, suffix, program]
130 'default' => ['x-gzip', 'gz', 'gzip']},
132 # Enable the pickaxe search, which will list the commits that modified
133 # a given string in a file. This can be practical and quite faster
134 # alternative to 'blame', but still potentially CPU-intensive.
136 # To enable system wide have in $GITWEB_CONFIG
137 # $feature{'pickaxe'}{'default'} = [1];
138 # To have project specific config enable override in $GITWEB_CONFIG
139 # $feature{'pickaxe'}{'override'} = 1;
140 # and in project config gitweb.pickaxe = 0|1;
142 'sub' => \
&feature_pickaxe
,
146 # Make gitweb use an alternative format of the URLs which can be
147 # more readable and natural-looking: project name is embedded
148 # directly in the path and the query string contains other
149 # auxiliary information. All gitweb installations recognize
150 # URL in either format; this configures in which formats gitweb
153 # To enable system wide have in $GITWEB_CONFIG
154 # $feature{'pathinfo'}{'default'} = [1];
155 # Project specific override is not supported.
157 # Note that you will need to change the default location of CSS,
158 # favicon, logo and possibly other files to an absolute URL. Also,
159 # if gitweb.cgi serves as your indexfile, you will need to force
160 # $my_uri to contain the script name in your $GITWEB_CONFIG.
165 # Make gitweb consider projects in project root subdirectories
166 # to be forks of existing projects. Given project $projname.git,
167 # projects matching $projname/*.git will not be shown in the main
168 # projects list, instead a '+' mark will be added to $projname
169 # there and a 'forks' view will be enabled for the project, listing
170 # all the forks. This feature is supported only if project list
171 # is taken from a directory, not file.
173 # To enable system wide have in $GITWEB_CONFIG
174 # $feature{'forks'}{'default'} = [1];
175 # Project specific override is not supported.
181 sub gitweb_check_feature
{
183 return unless exists $feature{$name};
184 my ($sub, $override, @defaults) = (
185 $feature{$name}{'sub'},
186 $feature{$name}{'override'},
187 @{$feature{$name}{'default'}});
188 if (!$override) { return @defaults; }
190 warn "feature $name is not overrideable";
193 return $sub->(@defaults);
197 my ($val) = git_get_project_config
('blame', '--bool');
199 if ($val eq 'true') {
201 } elsif ($val eq 'false') {
208 sub feature_snapshot
{
209 my ($ctype, $suffix, $command) = @_;
211 my ($val) = git_get_project_config
('snapshot');
213 if ($val eq 'gzip') {
214 return ('x-gzip', 'gz', 'gzip');
215 } elsif ($val eq 'bzip2') {
216 return ('x-bzip2', 'bz2', 'bzip2');
217 } elsif ($val eq 'none') {
221 return ($ctype, $suffix, $command);
224 sub gitweb_have_snapshot
{
225 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
226 my $have_snapshot = (defined $ctype && defined $suffix);
228 return $have_snapshot;
231 sub feature_pickaxe
{
232 my ($val) = git_get_project_config
('pickaxe', '--bool');
234 if ($val eq 'true') {
236 } elsif ($val eq 'false') {
243 # checking HEAD file with -e is fragile if the repository was
244 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
246 sub check_head_link
{
248 my $headfile = "$dir/HEAD";
249 return ((-e
$headfile) ||
250 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
253 sub check_export_ok
{
255 return (check_head_link
($dir) &&
256 (!$export_ok || -e
"$dir/$export_ok"));
259 # rename detection options for git-diff and git-diff-tree
260 # - default is '-M', with the cost proportional to
261 # (number of removed files) * (number of new files).
262 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
263 # (number of changed files + number of removed files) * (number of new files)
264 # - even more costly is '-C', '--find-copies-harder' with cost
265 # (number of files in the original tree) * (number of new files)
266 # - one might want to include '-B' option, e.g. '-B', '-M'
267 our @diff_opts = ('-M'); # taken from git_commit
269 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
270 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
272 # version of the core git binary
273 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
275 $projects_list ||= $projectroot;
277 # ======================================================================
278 # input validation and dispatch
279 our $action = $cgi->param('a');
280 if (defined $action) {
281 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
282 die_error
(undef, "Invalid action parameter");
286 # parameters which are pathnames
287 our $project = $cgi->param('p');
288 if (defined $project) {
289 if (!validate_pathname
($project) ||
290 !(-d
"$projectroot/$project") ||
291 !check_head_link
("$projectroot/$project") ||
292 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
293 ($strict_export && !project_in_list
($project))) {
295 die_error
(undef, "No such project");
299 our $file_name = $cgi->param('f');
300 if (defined $file_name) {
301 if (!validate_pathname
($file_name)) {
302 die_error
(undef, "Invalid file parameter");
306 our $file_parent = $cgi->param('fp');
307 if (defined $file_parent) {
308 if (!validate_pathname
($file_parent)) {
309 die_error
(undef, "Invalid file parent parameter");
313 # parameters which are refnames
314 our $hash = $cgi->param('h');
316 if (!validate_refname
($hash)) {
317 die_error
(undef, "Invalid hash parameter");
321 our $hash_parent = $cgi->param('hp');
322 if (defined $hash_parent) {
323 if (!validate_refname
($hash_parent)) {
324 die_error
(undef, "Invalid hash parent parameter");
328 our $hash_base = $cgi->param('hb');
329 if (defined $hash_base) {
330 if (!validate_refname
($hash_base)) {
331 die_error
(undef, "Invalid hash base parameter");
335 our $hash_parent_base = $cgi->param('hpb');
336 if (defined $hash_parent_base) {
337 if (!validate_refname
($hash_parent_base)) {
338 die_error
(undef, "Invalid hash parent base parameter");
343 our $page = $cgi->param('pg');
345 if ($page =~ m/[^0-9]/) {
346 die_error
(undef, "Invalid page parameter");
350 our $searchtext = $cgi->param('s');
351 if (defined $searchtext) {
352 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
353 die_error
(undef, "Invalid search parameter");
355 $searchtext = quotemeta $searchtext;
358 our $searchtype = $cgi->param('st');
359 if (defined $searchtype) {
360 if ($searchtype =~ m/[^a-z]/) {
361 die_error
(undef, "Invalid searchtype parameter");
365 # now read PATH_INFO and use it as alternative to parameters
366 sub evaluate_path_info
{
367 return if defined $project;
368 my $path_info = $ENV{"PATH_INFO"};
369 return if !$path_info;
370 $path_info =~ s
,^/+,,;
371 return if !$path_info;
372 # find which part of PATH_INFO is project
373 $project = $path_info;
375 while ($project && !check_head_link
("$projectroot/$project")) {
376 $project =~ s
,/*[^/]*$,,;
379 $project = validate_pathname
($project);
381 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
382 ($strict_export && !project_in_list
($project))) {
386 # do not change any parameters if an action is given using the query string
388 $path_info =~ s
,^$project/*,,;
389 my ($refname, $pathname) = split(/:/, $path_info, 2);
390 if (defined $pathname) {
391 # we got "project.git/branch:filename" or "project.git/branch:dir/"
392 # we could use git_get_type(branch:pathname), but it needs $git_dir
393 $pathname =~ s
,^/+,,;
394 if (!$pathname || substr($pathname, -1) eq "/") {
398 $action ||= "blob_plain";
400 $hash_base ||= validate_refname
($refname);
401 $file_name ||= validate_pathname
($pathname);
402 } elsif (defined $refname) {
403 # we got "project.git/branch"
404 $action ||= "shortlog";
405 $hash ||= validate_refname
($refname);
408 evaluate_path_info
();
410 # path to the current git repository
412 $git_dir = "$projectroot/$project" if $project;
416 "blame" => \
&git_blame2
,
417 "blobdiff" => \
&git_blobdiff
,
418 "blobdiff_plain" => \
&git_blobdiff_plain
,
419 "blob" => \
&git_blob
,
420 "blob_plain" => \
&git_blob_plain
,
421 "commitdiff" => \
&git_commitdiff
,
422 "commitdiff_plain" => \
&git_commitdiff_plain
,
423 "commit" => \
&git_commit
,
424 "forks" => \
&git_forks
,
425 "heads" => \
&git_heads
,
426 "history" => \
&git_history
,
429 "search" => \
&git_search
,
430 "search_help" => \
&git_search_help
,
431 "shortlog" => \
&git_shortlog
,
432 "summary" => \
&git_summary
,
434 "tags" => \
&git_tags
,
435 "tree" => \
&git_tree
,
436 "snapshot" => \
&git_snapshot
,
437 # those below don't need $project
438 "opml" => \
&git_opml
,
439 "project_list" => \
&git_project_list
,
440 "project_index" => \
&git_project_index
,
443 if (defined $project) {
444 $action ||= 'summary';
446 $action ||= 'project_list';
448 if (!defined($actions{$action})) {
449 die_error
(undef, "Unknown action");
451 if ($action !~ m/^(opml|project_list|project_index)$/ &&
453 die_error
(undef, "Project needed");
455 $actions{$action}->();
458 ## ======================================================================
465 # XXX: Warning: If you touch this, check the search form for updating,
476 hash_parent_base
=> "hpb",
482 my %mapping = @mapping;
484 $params{'project'} = $project unless exists $params{'project'};
486 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
488 # use PATH_INFO for project name
489 $href .= "/$params{'project'}" if defined $params{'project'};
490 delete $params{'project'};
492 # Summary just uses the project path URL
493 if (defined $params{'action'} && $params{'action'} eq 'summary') {
494 delete $params{'action'};
498 # now encode the parameters explicitly
500 for (my $i = 0; $i < @mapping; $i += 2) {
501 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
502 if (defined $params{$name}) {
503 push @result, $symbol . "=" . esc_param
($params{$name});
506 $href .= "?" . join(';', @result) if scalar @result;
512 ## ======================================================================
513 ## validation, quoting/unquoting and escaping
515 sub validate_pathname
{
516 my $input = shift || return undef;
518 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
519 # at the beginning, at the end, and between slashes.
520 # also this catches doubled slashes
521 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
525 if ($input =~ m!\0!) {
531 sub validate_refname
{
532 my $input = shift || return undef;
534 # textual hashes are O.K.
535 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
538 # it must be correct pathname
539 $input = validate_pathname
($input)
541 # restrictions on ref name according to git-check-ref-format
542 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
548 # very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT);
551 return decode
("utf8", $str, Encode
::FB_DEFAULT
);
554 # quote unsafe chars, but keep the slash, even when it's not
555 # correct, but quoted slashes look too horrible in bookmarks
558 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
564 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
567 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
573 # replace invalid utf8 character with SUBSTITUTION sequence
578 $str = to_utf8
($str);
579 $str = escapeHTML
($str);
580 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
581 $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1)
582 if ($opts{'-nbsp'}) {
583 $str =~ s/ / /g;
588 # quote control characters and escape filename to HTML
591 $str = esc_html
($str);
592 $str =~ s
|([[:cntrl
:]])|<span
class="cntrl">?</span
>|g
;
596 # git may return quoted and escaped filenames
602 my %es = ( # character escape codes, aka escape sequences
603 't' => "\t", # tab (HT, TAB)
604 'n' => "\n", # newline (NL)
605 'r' => "\r", # return (CR)
606 'f' => "\f", # form feed (FF)
607 'b' => "\b", # backspace (BS)
608 'a' => "\a", # alarm (bell) (BEL)
609 'e' => "\e", # escape (ESC)
610 'v' => "\013", # vertical tab (VT)
613 if ($seq =~ m/^[0-7]{1,3}$/) {
614 # octal char sequence
615 return chr(oct($seq));
616 } elsif (exists $es{$seq}) {
617 # C escape sequence, aka character escape code
620 # quoted ordinary character
624 if ($str =~ m/^"(.*)"$/) {
627 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
632 # escape tabs (convert tabs to spaces)
636 while ((my $pos = index($line, "\t")) != -1) {
637 if (my $count = (8 - ($pos % 8))) {
638 my $spaces = ' ' x
$count;
639 $line =~ s/\t/$spaces/;
646 sub project_in_list
{
648 my @list = git_get_projects_list
();
649 return @list && scalar(grep { $_->{'path'} eq $project } @list);
652 ## ----------------------------------------------------------------------
653 ## HTML aware string manipulation
658 my $add_len = shift || 10;
660 # allow only $len chars, but don't cut a word if it would fit in $add_len
661 # if it doesn't fit, cut it if it's still longer than the dots we would add
662 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
665 if (length($tail) > 4) {
667 $body =~ s/&[^;]*$//; # remove chopped character entities
672 ## ----------------------------------------------------------------------
673 ## functions returning short strings
675 # CSS class for given age value (in seconds)
679 if ($age < 60*60*2) {
681 } elsif ($age < 60*60*24*2) {
688 # convert age in seconds to "nn units ago" string
693 if ($age > 60*60*24*365*2) {
694 $age_str = (int $age/60/60/24/365);
695 $age_str .= " years ago";
696 } elsif ($age > 60*60*24*(365/12)*2) {
697 $age_str = int $age/60/60/24/(365/12);
698 $age_str .= " months ago";
699 } elsif ($age > 60*60*24*7*2) {
700 $age_str = int $age/60/60/24/7;
701 $age_str .= " weeks ago";
702 } elsif ($age > 60*60*24*2) {
703 $age_str = int $age/60/60/24;
704 $age_str .= " days ago";
705 } elsif ($age > 60*60*2) {
706 $age_str = int $age/60/60;
707 $age_str .= " hours ago";
708 } elsif ($age > 60*2) {
709 $age_str = int $age/60;
710 $age_str .= " min ago";
713 $age_str .= " sec ago";
715 $age_str .= " right now";
720 # convert file mode in octal to symbolic file mode string
722 my $mode = oct shift;
724 if (S_ISDIR
($mode & S_IFMT
)) {
726 } elsif (S_ISLNK
($mode)) {
728 } elsif (S_ISREG
($mode)) {
729 # git cares only about the executable bit
730 if ($mode & S_IXUSR
) {
740 # convert file mode in octal to file type string
744 if ($mode !~ m/^[0-7]+$/) {
750 if (S_ISDIR
($mode & S_IFMT
)) {
752 } elsif (S_ISLNK
($mode)) {
754 } elsif (S_ISREG
($mode)) {
761 ## ----------------------------------------------------------------------
762 ## functions returning short HTML fragments, or transforming HTML fragments
763 ## which don't beling to other sections
765 # format line of commit message or tag comment
766 sub format_log_line_html
{
769 $line = esc_html
($line);
770 $line =~ s/ / /g;
771 if ($line =~ m/([0-9a-fA-F]{40})/) {
773 if (git_get_type
($hash_text) eq "commit") {
775 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
776 -class => "text"}, $hash_text);
777 $line =~ s/$hash_text/$link/;
783 # format marker of refs pointing to given object
784 sub format_ref_marker
{
785 my ($refs, $id) = @_;
788 if (defined $refs->{$id}) {
789 foreach my $ref (@{$refs->{$id}}) {
790 my ($type, $name) = qw();
791 # e.g. tags/v2.6.11 or heads/next
792 if ($ref =~ m!^(.*?)s?/(.*)$!) {
800 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
805 return ' <span class="refs">'. $markers . '</span>';
811 # format, perhaps shortened and with markers, title line
812 sub format_subject_html
{
813 my ($long, $short, $href, $extra) = @_;
814 $extra = '' unless defined($extra);
816 if (length($short) < length($long)) {
817 return $cgi->a({-href
=> $href, -class => "list subject",
818 -title
=> to_utf8
($long)},
819 esc_html
($short) . $extra);
821 return $cgi->a({-href
=> $href, -class => "list subject"},
822 esc_html
($long) . $extra);
826 sub format_diff_line
{
828 my $char = substr($line, 0, 1);
834 $diff_class = " add";
835 } elsif ($char eq "-") {
836 $diff_class = " rem";
837 } elsif ($char eq "@") {
838 $diff_class = " chunk_header";
839 } elsif ($char eq "\\") {
840 $diff_class = " incomplete";
842 $line = untabify
($line);
843 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
846 ## ----------------------------------------------------------------------
847 ## git utility subroutines, invoking git commands
849 # returns path to the core git executable and the --git-dir parameter as list
851 return $GIT, '--git-dir='.$git_dir;
854 # returns path to the core git executable and the --git-dir parameter as string
856 return join(' ', git_cmd
());
859 # get HEAD ref of given project as hash
860 sub git_get_head_hash
{
862 my $o_git_dir = $git_dir;
864 $git_dir = "$projectroot/$project";
865 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
868 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
872 if (defined $o_git_dir) {
873 $git_dir = $o_git_dir;
878 # get type of given object
882 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
889 sub git_get_project_config
{
890 my ($key, $type) = @_;
892 return unless ($key);
893 $key =~ s/^gitweb\.//;
894 return if ($key =~ m/\W/);
896 my @x = (git_cmd
(), 'repo-config');
897 if (defined $type) { push @x, $type; }
899 push @x, "gitweb.$key";
905 # get hash of given path at given ref
906 sub git_get_hash_by_path
{
908 my $path = shift || return undef;
913 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
914 or die_error
(undef, "Open git-ls-tree failed");
916 close $fd or return undef;
918 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
919 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
920 if (defined $type && $type ne $2) {
927 ## ......................................................................
928 ## git utility functions, directly accessing git repository
930 sub git_get_project_description
{
933 open my $fd, "$projectroot/$path/description" or return undef;
940 sub git_get_project_url_list
{
943 open my $fd, "$projectroot/$path/cloneurl" or return;
944 my @git_project_url_list = map { chomp; $_ } <$fd>;
947 return wantarray ? @git_project_url_list : \
@git_project_url_list;
950 sub git_get_projects_list
{
955 $filter =~ s/\.git$//;
957 if (-d
$projects_list) {
958 # search in directory
959 my $dir = $projects_list . ($filter ? "/$filter" : '');
960 # remove the trailing "/"
962 my $pfxlen = length("$dir");
964 my ($check_forks) = gitweb_check_feature
('forks');
967 follow_fast
=> 1, # follow symbolic links
968 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
970 # skip project-list toplevel, if we get it.
971 return if (m!^[/.]$!);
972 # only directories can be git repositories
973 return unless (-d
$_);
975 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
976 # we check related file in $projectroot
977 if ($check_forks and $subdir =~ m
#/.#) {
978 $File::Find
::prune
= 1;
979 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
980 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
981 $File::Find
::prune
= 1;
986 } elsif (-f
$projects_list) {
987 # read from file(url-encoded):
988 # 'git%2Fgit.git Linus+Torvalds'
989 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
990 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
991 open my ($fd), $projects_list or return;
992 while (my $line = <$fd>) {
994 my ($path, $owner) = split ' ', $line;
995 $path = unescape
($path);
996 $owner = unescape
($owner);
997 if (!defined $path) {
1000 if ($filter ne '') {
1001 # looking for forks;
1002 my $pfx = substr($path, 0, length($filter));
1003 if ($pfx ne $filter) {
1006 my $sfx = substr($path, length($filter));
1007 if ($sfx !~ /^\/.*\
.git
$/) {
1011 if (check_export_ok
("$projectroot/$path")) {
1014 owner
=> to_utf8
($owner),
1021 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
1025 sub git_get_project_owner
{
1026 my $project = shift;
1029 return undef unless $project;
1031 # read from file (url-encoded):
1032 # 'git%2Fgit.git Linus+Torvalds'
1033 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1034 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1035 if (-f
$projects_list) {
1036 open (my $fd , $projects_list);
1037 while (my $line = <$fd>) {
1039 my ($pr, $ow) = split ' ', $line;
1040 $pr = unescape
($pr);
1041 $ow = unescape
($ow);
1042 if ($pr eq $project) {
1043 $owner = to_utf8
($ow);
1049 if (!defined $owner) {
1050 $owner = get_file_owner
("$projectroot/$project");
1056 sub git_get_last_activity
{
1060 $git_dir = "$projectroot/$path";
1061 open($fd, "-|", git_cmd
(), 'for-each-ref',
1062 '--format=%(refname) %(committer)',
1063 '--sort=-committerdate',
1064 'refs/heads') or return;
1065 my $most_recent = <$fd>;
1066 close $fd or return;
1067 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1069 my $age = time - $timestamp;
1070 return ($age, age_string
($age));
1074 sub git_get_references
{
1075 my $type = shift || "";
1077 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1078 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1079 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1082 while (my $line = <$fd>) {
1084 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
1085 if (defined $refs{$1}) {
1086 push @{$refs{$1}}, $2;
1092 close $fd or return;
1096 sub git_get_rev_name_tags
{
1097 my $hash = shift || return undef;
1099 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1101 my $name_rev = <$fd>;
1104 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1107 # catches also '$hash undefined' output
1112 ## ----------------------------------------------------------------------
1113 ## parse to hash functions
1117 my $tz = shift || "-0000";
1120 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1121 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1122 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1123 $date{'hour'} = $hour;
1124 $date{'minute'} = $min;
1125 $date{'mday'} = $mday;
1126 $date{'day'} = $days[$wday];
1127 $date{'month'} = $months[$mon];
1128 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1129 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1130 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1131 $mday, $months[$mon], $hour ,$min;
1133 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1134 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1135 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1136 $date{'hour_local'} = $hour;
1137 $date{'minute_local'} = $min;
1138 $date{'tz_local'} = $tz;
1139 $date{'iso-tz'} = sprintf ("%04d-%02d-%02d %02d:%02d:%02d %s",
1140 1900+$year, $mon+1, $mday,
1141 $hour, $min, $sec, $tz);
1150 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1151 $tag{'id'} = $tag_id;
1152 while (my $line = <$fd>) {
1154 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1155 $tag{'object'} = $1;
1156 } elsif ($line =~ m/^type (.+)$/) {
1158 } elsif ($line =~ m/^tag (.+)$/) {
1160 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1161 $tag{'author'} = $1;
1164 } elsif ($line =~ m/--BEGIN/) {
1165 push @comment, $line;
1167 } elsif ($line eq "") {
1171 push @comment, <$fd>;
1172 $tag{'comment'} = \
@comment;
1173 close $fd or return;
1174 if (!defined $tag{'name'}) {
1181 my $commit_id = shift;
1182 my $commit_text = shift;
1187 if (defined $commit_text) {
1188 @commit_lines = @$commit_text;
1191 open my $fd, "-|", git_cmd
(), "rev-list",
1192 "--header", "--parents", "--max-count=1",
1195 @commit_lines = split '\n', <$fd>;
1196 close $fd or return;
1199 my $header = shift @commit_lines;
1200 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1203 ($co{'id'}, my @parents) = split ' ', $header;
1204 $co{'parents'} = \
@parents;
1205 $co{'parent'} = $parents[0];
1206 while (my $line = shift @commit_lines) {
1207 last if $line eq "\n";
1208 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1210 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1212 $co{'author_epoch'} = $2;
1213 $co{'author_tz'} = $3;
1214 if ($co{'author'} =~ m/^([^<]+) </) {
1215 $co{'author_name'} = $1;
1217 $co{'author_name'} = $co{'author'};
1219 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1220 $co{'committer'} = $1;
1221 $co{'committer_epoch'} = $2;
1222 $co{'committer_tz'} = $3;
1223 $co{'committer_name'} = $co{'committer'};
1224 $co{'committer_name'} =~ s/ <.*//;
1227 if (!defined $co{'tree'}) {
1231 foreach my $title (@commit_lines) {
1234 $co{'title'} = chop_str
($title, 80, 5);
1235 # remove leading stuff of merges to make the interesting part visible
1236 if (length($title) > 50) {
1237 $title =~ s/^Automatic //;
1238 $title =~ s/^merge (of|with) /Merge ... /i;
1239 if (length($title) > 50) {
1240 $title =~ s/(http|rsync):\/\///;
1242 if (length($title) > 50) {
1243 $title =~ s/(master|www|rsync)\.//;
1245 if (length($title) > 50) {
1246 $title =~ s/kernel.org:?//;
1248 if (length($title) > 50) {
1249 $title =~ s/\/pub\/scm//;
1252 $co{'title_short'} = chop_str
($title, 50, 5);
1256 if ($co{'title'} eq "") {
1257 $co{'title'} = $co{'title_short'} = '(no commit message)';
1259 # remove added spaces
1260 foreach my $line (@commit_lines) {
1263 $co{'comment'} = \
@commit_lines;
1265 my $age = time - $co{'committer_epoch'};
1267 $co{'age_string'} = age_string
($age);
1268 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1269 if ($age > 60*60*24*7*2) {
1270 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1271 $co{'age_string_age'} = $co{'age_string'};
1273 $co{'age_string_date'} = $co{'age_string'};
1274 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1279 # parse ref from ref_file, given by ref_id, with given type
1281 my $ref_file = shift;
1283 my $type = shift || git_get_type
($ref_id);
1286 $ref_item{'type'} = $type;
1287 $ref_item{'id'} = $ref_id;
1288 $ref_item{'epoch'} = 0;
1289 $ref_item{'age'} = "unknown";
1290 if ($type eq "tag") {
1291 my %tag = parse_tag
($ref_id);
1292 $ref_item{'comment'} = $tag{'comment'};
1293 if ($tag{'type'} eq "commit") {
1294 my %co = parse_commit
($tag{'object'});
1295 $ref_item{'epoch'} = $co{'committer_epoch'};
1296 $ref_item{'age'} = $co{'age_string'};
1297 } elsif (defined($tag{'epoch'})) {
1298 my $age = time - $tag{'epoch'};
1299 $ref_item{'epoch'} = $tag{'epoch'};
1300 $ref_item{'age'} = age_string
($age);
1302 $ref_item{'reftype'} = $tag{'type'};
1303 $ref_item{'name'} = $tag{'name'};
1304 $ref_item{'refid'} = $tag{'object'};
1305 } elsif ($type eq "commit"){
1306 my %co = parse_commit
($ref_id);
1307 $ref_item{'reftype'} = "commit";
1308 $ref_item{'name'} = $ref_file;
1309 $ref_item{'title'} = $co{'title'};
1310 $ref_item{'refid'} = $ref_id;
1311 $ref_item{'epoch'} = $co{'committer_epoch'};
1312 $ref_item{'age'} = $co{'age_string'};
1314 $ref_item{'reftype'} = $type;
1315 $ref_item{'name'} = $ref_file;
1316 $ref_item{'refid'} = $ref_id;
1322 # parse line of git-diff-tree "raw" output
1323 sub parse_difftree_raw_line
{
1327 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1328 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1329 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1330 $res{'from_mode'} = $1;
1331 $res{'to_mode'} = $2;
1332 $res{'from_id'} = $3;
1334 $res{'status'} = $5;
1335 $res{'similarity'} = $6;
1336 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1337 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1339 $res{'file'} = unquote
($7);
1342 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1343 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1344 $res{'commit'} = $1;
1347 return wantarray ? %res : \
%res;
1350 # parse line of git-ls-tree output
1351 sub parse_ls_tree_line
($;%) {
1356 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1357 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1365 $res{'name'} = unquote
($4);
1368 return wantarray ? %res : \
%res;
1371 ## ......................................................................
1372 ## parse to array of hashes functions
1374 sub git_get_heads_list
{
1378 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1379 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1380 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1383 while (my $line = <$fd>) {
1387 my ($refinfo, $committerinfo) = split(/\0/, $line);
1388 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1389 my ($committer, $epoch, $tz) =
1390 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1391 $name =~ s!^refs/heads/!!;
1393 $ref_item{'name'} = $name;
1394 $ref_item{'id'} = $hash;
1395 $ref_item{'title'} = $title || '(no commit message)';
1396 $ref_item{'epoch'} = $epoch;
1398 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1400 $ref_item{'age'} = "unknown";
1403 push @headslist, \
%ref_item;
1407 return wantarray ? @headslist : \
@headslist;
1410 sub git_get_tags_list
{
1414 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1415 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1416 '--format=%(objectname) %(objecttype) %(refname) '.
1417 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1420 while (my $line = <$fd>) {
1424 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1425 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1426 my ($creator, $epoch, $tz) =
1427 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1428 $name =~ s!^refs/tags/!!;
1430 $ref_item{'type'} = $type;
1431 $ref_item{'id'} = $id;
1432 $ref_item{'name'} = $name;
1433 if ($type eq "tag") {
1434 $ref_item{'subject'} = $title;
1435 $ref_item{'reftype'} = $reftype;
1436 $ref_item{'refid'} = $refid;
1438 $ref_item{'reftype'} = $type;
1439 $ref_item{'refid'} = $id;
1442 if ($type eq "tag" || $type eq "commit") {
1443 $ref_item{'epoch'} = $epoch;
1445 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1447 $ref_item{'age'} = "unknown";
1451 push @tagslist, \
%ref_item;
1455 return wantarray ? @tagslist : \
@tagslist;
1458 ## ----------------------------------------------------------------------
1459 ## filesystem-related functions
1461 sub get_file_owner
{
1464 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1465 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1466 if (!defined $gcos) {
1470 $owner =~ s/[,;].*$//;
1471 return to_utf8
($owner);
1474 ## ......................................................................
1475 ## mimetype related functions
1477 sub mimetype_guess_file
{
1478 my $filename = shift;
1479 my $mimemap = shift;
1480 -r
$mimemap or return undef;
1483 open(MIME
, $mimemap) or return undef;
1485 next if m/^#/; # skip comments
1486 my ($mime, $exts) = split(/\t+/);
1487 if (defined $exts) {
1488 my @exts = split(/\s+/, $exts);
1489 foreach my $ext (@exts) {
1490 $mimemap{$ext} = $mime;
1496 $filename =~ /\.([^.]*)$/;
1497 return $mimemap{$1};
1500 sub mimetype_guess
{
1501 my $filename = shift;
1503 $filename =~ /\./ or return undef;
1505 if ($mimetypes_file) {
1506 my $file = $mimetypes_file;
1507 if ($file !~ m!^/!) { # if it is relative path
1508 # it is relative to project
1509 $file = "$projectroot/$project/$file";
1511 $mime = mimetype_guess_file
($filename, $file);
1513 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1519 my $filename = shift;
1522 my $mime = mimetype_guess
($filename);
1523 $mime and return $mime;
1527 return $default_blob_plain_mimetype unless $fd;
1530 return 'text/plain' .
1531 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1532 } elsif (! $filename) {
1533 return 'application/octet-stream';
1534 } elsif ($filename =~ m/\.png$/i) {
1536 } elsif ($filename =~ m/\.gif$/i) {
1538 } elsif ($filename =~ m/\.jpe?g$/i) {
1539 return 'image/jpeg';
1541 return 'application/octet-stream';
1545 ## ======================================================================
1546 ## functions printing HTML: header, footer, error page
1548 sub git_header_html
{
1549 my $status = shift || "200 OK";
1550 my $expires = shift;
1552 my $title = "$site_name";
1553 if (defined $project) {
1554 $title .= " - $project";
1555 if (defined $action) {
1556 $title .= "/$action";
1557 if (defined $file_name) {
1558 $title .= " - " . esc_path
($file_name);
1559 if ($action eq "tree" && $file_name !~ m
|/$|) {
1566 # require explicit support from the UA if we are to send the page as
1567 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1568 # we have to do this because MSIE sometimes globs '*/*', pretending to
1569 # support xhtml+xml but choking when it gets what it asked for.
1570 if (defined $cgi->http('HTTP_ACCEPT') &&
1571 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1572 $cgi->Accept('application/xhtml+xml') != 0) {
1573 $content_type = 'application/xhtml+xml';
1575 $content_type = 'text/html';
1577 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1578 -status
=> $status, -expires
=> $expires);
1580 <?xml version="1.0" encoding="utf-8"?>
1581 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1582 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1583 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1584 <!-- git core binaries version $git_version -->
1586 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1587 <meta name="generator" content="gitweb/$version git/$git_version"/>
1588 <meta name="robots" content="index, nofollow"/>
1589 <title>$title</title>
1591 # print out each stylesheet that exist
1592 if (defined $stylesheet) {
1593 #provides backwards capability for those people who define style sheet in a config file
1594 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1596 foreach my $stylesheet (@stylesheets) {
1597 next unless $stylesheet;
1598 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1601 if (defined $project) {
1602 printf('<link rel="alternate" title="%s log" '.
1603 'href="%s" type="application/rss+xml"/>'."\n",
1604 esc_param
($project), href
(action
=>"rss"));
1606 printf('<link rel="alternate" title="%s projects list" '.
1607 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1608 $site_name, href
(project
=>undef, action
=>"project_index"));
1609 printf('<link rel="alternate" title="%s projects logs" '.
1610 'href="%s" type="text/x-opml"/>'."\n",
1611 $site_name, href
(project
=>undef, action
=>"opml"));
1613 if (defined $favicon) {
1614 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1620 if (-f
$site_header) {
1621 open (my $fd, $site_header);
1626 print "<div class=\"page_header\">\n" .
1627 $cgi->a({-href
=> esc_url
($logo_url),
1628 -title
=> $logo_label},
1629 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1630 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1631 if (defined $project) {
1632 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1633 if (defined $action) {
1637 if (!defined $searchtext) {
1641 if (defined $hash_base) {
1642 $search_hash = $hash_base;
1643 } elsif (defined $hash) {
1644 $search_hash = $hash;
1646 $search_hash = "HEAD";
1648 $cgi->param("a", "search");
1649 $cgi->param("h", $search_hash);
1650 $cgi->param("p", $project);
1651 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1652 "<div class=\"search\">\n" .
1653 $cgi->hidden(-name
=> "p") . "\n" .
1654 $cgi->hidden(-name
=> "a") . "\n" .
1655 $cgi->hidden(-name
=> "h") . "\n" .
1656 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1657 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1658 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1660 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1662 $cgi->end_form() . "\n";
1667 sub git_footer_html
{
1668 print "<div class=\"page_footer\">\n";
1669 if (defined $project) {
1670 my $descr = git_get_project_description
($project);
1671 if (defined $descr) {
1672 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1674 print $cgi->a({-href
=> href
(action
=>"rss"),
1675 -class => "rss_logo"}, "RSS") . "\n";
1677 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1678 -class => "rss_logo"}, "OPML") . " ";
1679 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1680 -class => "rss_logo"}, "TXT") . "\n";
1684 if (-f
$site_footer) {
1685 open (my $fd, $site_footer);
1695 my $status = shift || "403 Forbidden";
1696 my $error = shift || "Malformed query, file missing or permission denied";
1698 git_header_html
($status);
1700 <div class="page_body">
1710 ## ----------------------------------------------------------------------
1711 ## functions printing or outputting HTML: navigation
1713 sub git_print_page_nav
{
1714 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1715 $extra = '' if !defined $extra; # pager or formats
1717 my @navs = qw(summary shortlog log commit commitdiff tree);
1719 @navs = grep { $_ ne $suppress } @navs;
1722 my %arg = map { $_ => {action
=>$_} } @navs;
1723 if (defined $head) {
1724 for (qw(commit commitdiff)) {
1725 $arg{$_}{hash
} = $head;
1727 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1728 for (qw(shortlog log)) {
1729 $arg{$_}{hash
} = $head;
1733 $arg{tree
}{hash
} = $treehead if defined $treehead;
1734 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1736 print "<div class=\"page_nav\">\n" .
1738 map { $_ eq $current ?
1739 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1741 print "<br/>\n$extra<br/>\n" .
1745 sub format_paging_nav
{
1746 my ($action, $hash, $head, $page, $nrevs) = @_;
1750 if ($hash ne $head || $page) {
1751 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1753 $paging_nav .= "HEAD";
1757 $paging_nav .= " ⋅ " .
1758 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1759 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1761 $paging_nav .= " ⋅ prev";
1764 if ($nrevs >= (100 * ($page+1)-1)) {
1765 $paging_nav .= " ⋅ " .
1766 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1767 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1769 $paging_nav .= " ⋅ next";
1775 ## ......................................................................
1776 ## functions printing or outputting HTML: div
1778 sub git_print_header_div
{
1779 my ($action, $title, $hash, $hash_base) = @_;
1782 $args{action
} = $action;
1783 $args{hash
} = $hash if $hash;
1784 $args{hash_base
} = $hash_base if $hash_base;
1786 print "<div class=\"header\">\n" .
1787 $cgi->a({-href
=> href
(%args), -class => "title"},
1788 $title ? $title : $action) .
1792 #sub git_print_authorship (\%) {
1793 sub git_print_authorship
{
1796 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1797 print "<div class=\"author_date\">" .
1798 esc_html
($co->{'author_name'}) .
1800 if ($ad{'hour_local'} < 6) {
1801 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1802 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1804 printf(" (%02d:%02d %s)",
1805 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1810 sub git_print_page_path
{
1816 print "<div class=\"page_path\">";
1817 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1818 -title
=> 'tree root'}, "[$project]");
1820 if (defined $name) {
1821 my @dirname = split '/', $name;
1822 my $basename = pop @dirname;
1825 foreach my $dir (@dirname) {
1826 $fullname .= ($fullname ? '/' : '') . $dir;
1827 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1829 -title
=> $fullname}, esc_path
($dir));
1832 if (defined $type && $type eq 'blob') {
1833 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1835 -title
=> $name}, esc_path
($basename));
1836 } elsif (defined $type && $type eq 'tree') {
1837 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1839 -title
=> $name}, esc_path
($basename));
1842 print esc_path
($basename);
1845 print "<br/></div>\n";
1848 # sub git_print_log (\@;%) {
1849 sub git_print_log
($;%) {
1853 if ($opts{'-remove_title'}) {
1854 # remove title, i.e. first line of log
1857 # remove leading empty lines
1858 while (defined $log->[0] && $log->[0] eq "") {
1865 foreach my $line (@$log) {
1866 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1869 if (! $opts{'-remove_signoff'}) {
1870 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1873 # remove signoff lines
1880 # print only one empty line
1881 # do not print empty line after signoff
1883 next if ($empty || $signoff);
1889 print format_log_line_html
($line) . "<br/>\n";
1892 if ($opts{'-final_empty_line'}) {
1893 # end with single empty line
1894 print "<br/>\n" unless $empty;
1898 # print tree entry (row of git_tree), but without encompassing <tr> element
1899 sub git_print_tree_entry
{
1900 my ($t, $basedir, $hash_base, $have_blame) = @_;
1903 $base_key{hash_base
} = $hash_base if defined $hash_base;
1905 # The format of a table row is: mode list link. Where mode is
1906 # the mode of the entry, list is the name of the entry, an href,
1907 # and link is the action links of the entry.
1909 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1910 if ($t->{'type'} eq "blob") {
1911 print "<td class=\"list\">" .
1912 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1913 file_name
=>"$basedir$t->{'name'}", %base_key),
1914 -class => "list"}, esc_path
($t->{'name'})) . "</td>\n";
1915 print "<td class=\"link\">";
1916 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1917 file_name
=>"$basedir$t->{'name'}", %base_key)},
1921 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1922 file_name
=>"$basedir$t->{'name'}", %base_key)},
1925 if (defined $hash_base) {
1927 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1928 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1932 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
1933 file_name
=>"$basedir$t->{'name'}")},
1937 } elsif ($t->{'type'} eq "tree") {
1938 print "<td class=\"list\">";
1939 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1940 file_name
=>"$basedir$t->{'name'}", %base_key)},
1941 esc_path
($t->{'name'}));
1943 print "<td class=\"link\">";
1944 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1945 file_name
=>"$basedir$t->{'name'}", %base_key)},
1947 if (defined $hash_base) {
1949 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1950 file_name
=>"$basedir$t->{'name'}")},
1957 ## ......................................................................
1958 ## functions printing large fragments of HTML
1960 sub git_difftree_body
{
1961 my ($difftree, $hash, $parent) = @_;
1963 print "<div class=\"list_head\">\n";
1964 if ($#{$difftree} > 10) {
1965 print(($#{$difftree} + 1) . " files changed:\n");
1969 print "<table class=\"diff_tree\">\n";
1972 foreach my $line (@{$difftree}) {
1973 my %diff = parse_difftree_raw_line
($line);
1976 print "<tr class=\"dark\">\n";
1978 print "<tr class=\"light\">\n";
1982 my ($to_mode_oct, $to_mode_str, $to_file_type);
1983 my ($from_mode_oct, $from_mode_str, $from_file_type);
1984 if ($diff{'to_mode'} ne ('0' x
6)) {
1985 $to_mode_oct = oct $diff{'to_mode'};
1986 if (S_ISREG
($to_mode_oct)) { # only for regular file
1987 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1989 $to_file_type = file_type
($diff{'to_mode'});
1991 if ($diff{'from_mode'} ne ('0' x
6)) {
1992 $from_mode_oct = oct $diff{'from_mode'};
1993 if (S_ISREG
($to_mode_oct)) { # only for regular file
1994 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1996 $from_file_type = file_type
($diff{'from_mode'});
1999 if ($diff{'status'} eq "A") { # created
2000 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2001 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2002 $mode_chng .= "]</span>";
2004 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2005 hash_base
=>$hash, file_name
=>$diff{'file'}),
2006 -class => "list"}, esc_path
($diff{'file'}));
2008 print "<td>$mode_chng</td>\n";
2009 print "<td class=\"link\">";
2010 if ($action eq 'commitdiff') {
2013 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2017 } elsif ($diff{'status'} eq "D") { # deleted
2018 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2020 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2021 hash_base
=>$parent, file_name
=>$diff{'file'}),
2022 -class => "list"}, esc_path
($diff{'file'}));
2024 print "<td>$mode_chng</td>\n";
2025 print "<td class=\"link\">";
2026 if ($action eq 'commitdiff') {
2029 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2032 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2033 hash_base
=>$parent, file_name
=>$diff{'file'})},
2035 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2036 file_name
=>$diff{'file'})},
2038 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2039 file_name
=>$diff{'file'})},
2043 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
2044 my $mode_chnge = "";
2045 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2046 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2047 if ($from_file_type != $to_file_type) {
2048 $mode_chnge .= " from $from_file_type to $to_file_type";
2050 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2051 if ($from_mode_str && $to_mode_str) {
2052 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2053 } elsif ($to_mode_str) {
2054 $mode_chnge .= " mode: $to_mode_str";
2057 $mode_chnge .= "]</span>\n";
2060 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2061 hash_base
=>$hash, file_name
=>$diff{'file'}),
2062 -class => "list"}, esc_path
($diff{'file'}));
2064 print "<td>$mode_chnge</td>\n";
2065 print "<td class=\"link\">";
2066 if ($action eq 'commitdiff') {
2069 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2071 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2072 # "commit" view and modified file (not onlu mode changed)
2073 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2074 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2075 hash_base
=>$hash, hash_parent_base
=>$parent,
2076 file_name
=>$diff{'file'})},
2080 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2081 hash_base
=>$hash, file_name
=>$diff{'file'})},
2083 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2084 file_name
=>$diff{'file'})},
2086 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2087 file_name
=>$diff{'file'})},
2091 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
2092 my %status_name = ('R' => 'moved', 'C' => 'copied');
2093 my $nstatus = $status_name{$diff{'status'}};
2095 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2096 # mode also for directories, so we cannot use $to_mode_str
2097 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2100 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2101 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
2102 -class => "list"}, esc_path
($diff{'to_file'})) . "</td>\n" .
2103 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2104 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2105 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
2106 -class => "list"}, esc_path
($diff{'from_file'})) .
2107 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2108 "<td class=\"link\">";
2109 if ($action eq 'commitdiff') {
2112 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2114 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2115 # "commit" view and modified file (not only pure rename or copy)
2116 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2117 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2118 hash_base
=>$hash, hash_parent_base
=>$parent,
2119 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
2123 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2124 hash_base
=>$parent, file_name
=>$diff{'from_file'})},
2126 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2127 file_name
=>$diff{'from_file'})},
2129 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2130 file_name
=>$diff{'from_file'})},
2134 } # we should not encounter Unmerged (U) or Unknown (X) status
2140 sub git_patchset_body
{
2141 my ($fd, $difftree, $hash, $hash_parent) = @_;
2145 my $patch_found = 0;
2148 print "<div class=\"patchset\">\n";
2151 while (my $patch_line = <$fd>) {
2154 if ($patch_line =~ m/^diff /) { # "git diff" header
2155 # beginning of patch (in patchset)
2157 # close previous patch
2158 print "</div>\n"; # class="patch"
2160 # first patch in patchset
2163 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2165 if (ref($difftree->[$patch_idx]) eq "HASH") {
2166 $diffinfo = $difftree->[$patch_idx];
2168 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2172 if ($diffinfo->{'status'} eq "A") { # added
2173 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
2174 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2175 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2176 $diffinfo->{'to_id'}) . " (new)" .
2177 "</div>\n"; # class="diff_info"
2179 } elsif ($diffinfo->{'status'} eq "D") { # deleted
2180 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
2181 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2182 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2183 $diffinfo->{'from_id'}) . " (deleted)" .
2184 "</div>\n"; # class="diff_info"
2186 } elsif ($diffinfo->{'status'} eq "R" || # renamed
2187 $diffinfo->{'status'} eq "C" || # copied
2188 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
2189 print "<div class=\"diff_info\">" .
2190 file_type
($diffinfo->{'from_mode'}) . ":" .
2191 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2192 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
2193 $diffinfo->{'from_id'}) .
2195 file_type
($diffinfo->{'to_mode'}) . ":" .
2196 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2197 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
2198 $diffinfo->{'to_id'});
2199 print "</div>\n"; # class="diff_info"
2201 } else { # modified, mode changed, ...
2202 print "<div class=\"diff_info\">" .
2203 file_type
($diffinfo->{'from_mode'}) . ":" .
2204 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2205 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2206 $diffinfo->{'from_id'}) .
2208 file_type
($diffinfo->{'to_mode'}) . ":" .
2209 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2210 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2211 $diffinfo->{'to_id'});
2212 print "</div>\n"; # class="diff_info"
2215 #print "<div class=\"diff extended_header\">\n";
2218 } # start of patch in patchset
2221 if ($in_header && $patch_line =~ m/^---/) {
2222 #print "</div>\n"; # class="diff extended_header"
2225 my $file = $diffinfo->{'from_file'};
2226 $file ||= $diffinfo->{'file'};
2227 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2228 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
2229 -class => "list"}, esc_path
($file));
2230 $patch_line =~ s
|a
/.*$|a/$file|g
;
2231 print "<div class=\"diff from_file\">$patch_line</div>\n";
2233 $patch_line = <$fd>;
2236 #$patch_line =~ m/^+++/;
2237 $file = $diffinfo->{'to_file'};
2238 $file ||= $diffinfo->{'file'};
2239 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2240 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
2241 -class => "list"}, esc_path
($file));
2242 $patch_line =~ s
|b
/.*|b/$file|g
;
2243 print "<div class=\"diff to_file\">$patch_line</div>\n";
2247 next LINE
if $in_header;
2249 print format_diff_line
($patch_line);
2251 print "</div>\n" if $patch_found; # class="patch"
2253 print "</div>\n"; # class="patchset"
2256 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2258 sub git_project_list_body
{
2259 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2261 my ($check_forks) = gitweb_check_feature
('forks');
2264 foreach my $pr (@$projlist) {
2265 my (@aa) = git_get_last_activity
($pr->{'path'});
2269 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2270 if (!defined $pr->{'descr'}) {
2271 my $descr = git_get_project_description
($pr->{'path'}) || "";
2272 $pr->{'descr'} = chop_str
($descr, 25, 5);
2274 if (!defined $pr->{'owner'}) {
2275 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2278 my $pname = $pr->{'path'};
2279 if (($pname =~ s/\.git$//) &&
2280 ($pname !~ /\/$/) &&
2281 (-d
"$projectroot/$pname")) {
2282 $pr->{'forks'} = "-d $projectroot/$pname";
2288 push @projects, $pr;
2291 $order ||= "project";
2292 $from = 0 unless defined $from;
2293 $to = $#projects if (!defined $to || $#projects < $to);
2295 print "<table class=\"project_list\">\n";
2296 unless ($no_header) {
2299 print "<th></th>\n";
2301 if ($order eq "project") {
2302 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2303 print "<th>Project</th>\n";
2306 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2307 -class => "header"}, "Project") .
2310 if ($order eq "descr") {
2311 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2312 print "<th>Description</th>\n";
2315 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2316 -class => "header"}, "Description") .
2319 if ($order eq "owner") {
2320 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2321 print "<th>Owner</th>\n";
2324 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2325 -class => "header"}, "Owner") .
2328 if ($order eq "age") {
2329 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2330 print "<th>Last Change</th>\n";
2333 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2334 -class => "header"}, "Last Change") .
2337 print "<th></th>\n" .
2341 for (my $i = $from; $i <= $to; $i++) {
2342 my $pr = $projects[$i];
2344 print "<tr class=\"dark\">\n";
2346 print "<tr class=\"light\">\n";
2351 if ($pr->{'forks'}) {
2352 print "<!-- $pr->{'forks'} -->\n";
2353 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2357 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2358 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2359 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2360 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2361 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2362 $pr->{'age_string'} . "</td>\n" .
2363 "<td class=\"link\">" .
2364 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2365 $cgi->a({-href
=> '/git-browser/by-commit.html?r='.$pr->{'path'}}, "graphiclog") . " | " .
2366 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2367 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2368 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
2372 if (defined $extra) {
2375 print "<td></td>\n";
2377 print "<td colspan=\"5\">$extra</td>\n" .
2383 sub git_shortlog_body
{
2384 # uses global variable $project
2385 my ($revlist, $from, $to, $refs, $extra) = @_;
2387 $from = 0 unless defined $from;
2388 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2390 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2392 for (my $i = $from; $i <= $to; $i++) {
2393 my $commit = $revlist->[$i];
2394 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2395 my $ref = format_ref_marker
($refs, $commit);
2396 my %co = parse_commit
($commit);
2398 print "<tr class=\"dark\">\n";
2400 print "<tr class=\"light\">\n";
2403 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2404 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2405 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2407 print format_subject_html
($co{'title'}, $co{'title_short'},
2408 href
(action
=>"commit", hash
=>$commit), $ref);
2410 "<td class=\"link\">" .
2411 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
2412 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2413 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2414 if (gitweb_have_snapshot
()) {
2415 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2420 if (defined $extra) {
2422 "<td colspan=\"4\">$extra</td>\n" .
2428 sub git_history_body
{
2429 # Warning: assumes constant type (blob or tree) during history
2430 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2432 $from = 0 unless defined $from;
2433 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2435 print "<table class=\"history\" cellspacing=\"0\">\n";
2437 for (my $i = $from; $i <= $to; $i++) {
2438 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2443 my %co = parse_commit
($commit);
2448 my $ref = format_ref_marker
($refs, $commit);
2451 print "<tr class=\"dark\">\n";
2453 print "<tr class=\"light\">\n";
2456 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2457 # shortlog uses chop_str($co{'author_name'}, 10)
2458 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2460 # originally git_history used chop_str($co{'title'}, 50)
2461 print format_subject_html
($co{'title'}, $co{'title_short'},
2462 href
(action
=>"commit", hash
=>$commit), $ref);
2464 "<td class=\"link\">" .
2465 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2466 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2468 if ($ftype eq 'blob') {
2469 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2470 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2471 if (defined $blob_current && defined $blob_parent &&
2472 $blob_current ne $blob_parent) {
2474 $cgi->a({-href
=> href
(action
=>"blobdiff",
2475 hash
=>$blob_current, hash_parent
=>$blob_parent,
2476 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2477 file_name
=>$file_name)},
2484 if (defined $extra) {
2486 "<td colspan=\"4\">$extra</td>\n" .
2493 # uses global variable $project
2494 my ($taglist, $from, $to, $extra) = @_;
2495 $from = 0 unless defined $from;
2496 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2498 print "<table class=\"tags\" cellspacing=\"0\">\n";
2500 for (my $i = $from; $i <= $to; $i++) {
2501 my $entry = $taglist->[$i];
2503 my $comment = $tag{'subject'};
2505 if (defined $comment) {
2506 $comment_short = chop_str
($comment, 30, 5);
2509 print "<tr class=\"dark\">\n";
2511 print "<tr class=\"light\">\n";
2514 print "<td><i>$tag{'age'}</i></td>\n" .
2516 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2517 -class => "list name"}, esc_html
($tag{'name'})) .
2520 if (defined $comment) {
2521 print format_subject_html
($comment, $comment_short,
2522 href
(action
=>"tag", hash
=>$tag{'id'}));
2525 "<td class=\"selflink\">";
2526 if ($tag{'type'} eq "tag") {
2527 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2532 "<td class=\"link\">" . " | " .
2533 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2534 if ($tag{'reftype'} eq "commit") {
2535 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2536 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
2537 } elsif ($tag{'reftype'} eq "blob") {
2538 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2543 if (defined $extra) {
2545 "<td colspan=\"5\">$extra</td>\n" .
2551 sub git_heads_body
{
2552 # uses global variable $project
2553 my ($headlist, $head, $from, $to, $extra) = @_;
2554 $from = 0 unless defined $from;
2555 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2557 print "<table class=\"heads\" cellspacing=\"0\">\n";
2559 for (my $i = $from; $i <= $to; $i++) {
2560 my $entry = $headlist->[$i];
2562 my $curr = $ref{'id'} eq $head;
2564 print "<tr class=\"dark\">\n";
2566 print "<tr class=\"light\">\n";
2569 print "<td><i>$ref{'age'}</i></td>\n" .
2570 ($curr ? "<td class=\"current_head\">" : "<td>") .
2571 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
2572 -class => "list name"},esc_html
($ref{'name'})) .
2574 "<td class=\"link\">" .
2575 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
2576 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
2577 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
2581 if (defined $extra) {
2583 "<td colspan=\"3\">$extra</td>\n" .
2589 ## ======================================================================
2590 ## ======================================================================
2593 sub git_project_list
{
2594 my $order = $cgi->param('o');
2595 if (defined $order && $order !~ m/project|descr|owner|age/) {
2596 die_error
(undef, "Unknown order parameter");
2599 my @list = git_get_projects_list
();
2601 die_error
(undef, "No projects found");
2605 if (-f
$home_text) {
2606 print "<div class=\"index_include\">\n";
2607 open (my $fd, $home_text);
2612 git_project_list_body
(\
@list, $order);
2617 my $order = $cgi->param('o');
2618 if (defined $order && $order !~ m/project|descr|owner|age/) {
2619 die_error
(undef, "Unknown order parameter");
2622 my @list = git_get_projects_list
($project);
2624 die_error
(undef, "No forks found");
2628 git_print_page_nav
('','');
2629 git_print_header_div
('summary', "$project forks");
2630 git_project_list_body
(\
@list, $order);
2634 sub git_project_index
{
2635 my @projects = git_get_projects_list
($project);
2638 -type
=> 'text/plain',
2639 -charset
=> 'utf-8',
2640 -content_disposition
=> 'inline; filename="index.aux"');
2642 foreach my $pr (@projects) {
2643 if (!exists $pr->{'owner'}) {
2644 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2647 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2648 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2649 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2650 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2654 print "$path $owner\n";
2659 my $descr = git_get_project_description
($project) || "none";
2660 my $head = git_get_head_hash
($project);
2661 my %co = parse_commit
($head);
2662 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2664 my $owner = git_get_project_owner
($project);
2666 my $refs = git_get_references
();
2667 my @taglist = git_get_tags_list
(15);
2668 my @headlist = git_get_heads_list
(15);
2670 my ($check_forks) = gitweb_check_feature
('forks');
2673 @forklist = git_get_projects_list
($project);
2677 git_print_page_nav
('summary','', $head);
2679 print "<div class=\"title\"> </div>\n";
2680 print "<table cellspacing=\"0\">\n" .
2681 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2682 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2683 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2684 # use per project git URL list in $projectroot/$project/cloneurl
2685 # or make project git URL from git base URL and project name
2686 my $url_tag = "URL";
2687 my @url_list = git_get_project_url_list
($project);
2688 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2689 foreach my $git_url (@url_list) {
2690 next unless $git_url;
2691 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2696 if (-s
"$projectroot/$project/README.html") {
2697 if (open my $fd, "$projectroot/$project/README.html") {
2698 print "<div class=\"title\">readme</div>\n";
2699 print $_ while (<$fd>);
2704 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2705 git_get_head_hash
($project), "--"
2706 or die_error
(undef, "Open git-rev-list failed");
2707 my @revlist = map { chomp; $_ } <$fd>;
2709 git_print_header_div
('shortlog');
2710 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2711 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2714 git_print_header_div
('tags');
2715 git_tags_body
(\
@taglist, 0, 15,
2716 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2720 git_print_header_div
('heads');
2721 git_heads_body
(\
@headlist, $head, 0, 15,
2722 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2726 git_print_header_div
('forks');
2727 git_project_list_body
(\
@forklist, undef, 0, 15,
2728 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
2736 my $head = git_get_head_hash
($project);
2738 git_print_page_nav
('','', $head,undef,$head);
2739 my %tag = parse_tag
($hash);
2740 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2741 print "<div class=\"title_text\">\n" .
2742 "<table cellspacing=\"0\">\n" .
2744 "<td>object</td>\n" .
2745 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2746 $tag{'object'}) . "</td>\n" .
2747 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2748 $tag{'type'}) . "</td>\n" .
2750 if (defined($tag{'author'})) {
2751 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2752 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2753 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2754 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2757 print "</table>\n\n" .
2759 print "<div class=\"page_body\">";
2760 my $comment = $tag{'comment'};
2761 foreach my $line (@$comment) {
2762 print esc_html
($line) . "<br/>\n";
2772 my ($have_blame) = gitweb_check_feature
('blame');
2774 die_error
('403 Permission denied', "Permission denied");
2776 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2777 $hash_base ||= git_get_head_hash
($project);
2778 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2779 my %co = parse_commit
($hash_base)
2780 or die_error
(undef, "Reading commit failed");
2781 if (!defined $hash) {
2782 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2783 or die_error
(undef, "Error looking up file");
2785 $ftype = git_get_type
($hash);
2786 if ($ftype !~ "blob") {
2787 die_error
("400 Bad Request", "Object is not a blob");
2789 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
2790 $file_name, $hash_base)
2791 or die_error
(undef, "Open git-blame failed");
2794 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2797 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2800 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2802 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2803 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2804 git_print_page_path
($file_name, $ftype, $hash_base);
2805 my @rev_color = (qw(light2 dark2));
2806 my $num_colors = scalar(@rev_color);
2807 my $current_color = 0;
2810 <div class="page_body">
2811 <table class="blame">
2812 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2817 last unless defined $_;
2818 my ($full_rev, $orig_lineno, $lineno, $group_size) =
2819 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
2820 if (!exists $metainfo{$full_rev}) {
2821 $metainfo{$full_rev} = {};
2823 my $meta = $metainfo{$full_rev};
2826 if (/^(\S+) (.*)$/) {
2831 my $rev = substr($full_rev, 0, 8);
2832 my $author = $meta->{'author'};
2833 my %date = parse_date
($meta->{'author-time'},
2834 $meta->{'author-tz'});
2835 my $date = $date{'iso-tz'};
2837 $current_color = ++$current_color % $num_colors;
2839 print "<tr class=\"$rev_color[$current_color]\">\n";
2841 print "<td class=\"sha1\"";
2842 print " title=\"". esc_html
($author) . ", $date\"";
2843 print " rowspan=\"$group_size\"" if ($group_size > 1);
2845 print $cgi->a({-href
=> href
(action
=>"commit",
2847 file_name
=>$file_name)},
2851 my $blamed = href
(action
=> 'blame',
2852 file_name
=> $meta->{'filename'},
2853 hash_base
=> $full_rev);
2854 print "<td class=\"linenr\">";
2855 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
2857 -class => "linenr" },
2860 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2866 or print "Reading blob failed\n";
2873 my ($have_blame) = gitweb_check_feature
('blame');
2875 die_error
('403 Permission denied', "Permission denied");
2877 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2878 $hash_base ||= git_get_head_hash
($project);
2879 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2880 my %co = parse_commit
($hash_base)
2881 or die_error
(undef, "Reading commit failed");
2882 if (!defined $hash) {
2883 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2884 or die_error
(undef, "Error lookup file");
2886 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2887 or die_error
(undef, "Open git-annotate failed");
2890 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2893 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2896 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2898 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2899 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2900 git_print_page_path
($file_name, 'blob', $hash_base);
2901 print "<div class=\"page_body\">\n";
2903 <table class="blame">
2912 my @line_class = (qw(light dark));
2913 my $line_class_len = scalar (@line_class);
2914 my $line_class_num = $#line_class;
2915 while (my $line = <$fd>) {
2927 $line_class_num = ($line_class_num + 1) % $line_class_len;
2929 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2936 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
2939 $short_rev = substr ($long_rev, 0, 8);
2940 $age = time () - $time;
2941 $age_str = age_string
($age);
2942 $age_str =~ s/ / /g;
2943 $age_class = age_class
($age);
2944 $author = esc_html
($author);
2945 $author =~ s/ / /g;
2947 $data = untabify
($data);
2948 $data = esc_html
($data);
2951 <tr class="$line_class[$line_class_num]">
2952 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2953 <td class="$age_class">$age_str</td>
2955 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2956 <td class="pre">$data</td>
2959 } # while (my $line = <$fd>)
2960 print "</table>\n\n";
2962 or print "Reading blob failed.\n";
2968 my $head = git_get_head_hash
($project);
2970 git_print_page_nav
('','', $head,undef,$head);
2971 git_print_header_div
('summary', $project);
2973 my @tagslist = git_get_tags_list
();
2975 git_tags_body
(\
@tagslist);
2981 my $head = git_get_head_hash
($project);
2983 git_print_page_nav
('','', $head,undef,$head);
2984 git_print_header_div
('summary', $project);
2986 my @headslist = git_get_heads_list
();
2988 git_heads_body
(\
@headslist, $head);
2993 sub git_blob_plain
{
2996 if (!defined $hash) {
2997 if (defined $file_name) {
2998 my $base = $hash_base || git_get_head_hash
($project);
2999 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3000 or die_error
(undef, "Error lookup file");
3002 die_error
(undef, "No file name defined");
3004 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3005 # blobs defined by non-textual hash id's can be cached
3010 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3011 or die_error
(undef, "Couldn't cat $file_name, $hash");
3013 $type ||= blob_mimetype
($fd, $file_name);
3015 # save as filename, even when no $file_name is given
3016 my $save_as = "$hash";
3017 if (defined $file_name) {
3018 $save_as = $file_name;
3019 } elsif ($type =~ m/^text\//) {
3026 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3028 binmode STDOUT
, ':raw';
3030 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3038 if (!defined $hash) {
3039 if (defined $file_name) {
3040 my $base = $hash_base || git_get_head_hash
($project);
3041 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3042 or die_error
(undef, "Error lookup file");
3044 die_error
(undef, "No file name defined");
3046 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3047 # blobs defined by non-textual hash id's can be cached
3051 my ($have_blame) = gitweb_check_feature
('blame');
3052 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3053 or die_error
(undef, "Couldn't cat $file_name, $hash");
3054 my $mimetype = blob_mimetype
($fd, $file_name);
3055 if ($mimetype !~ m/^text\//) {
3057 return git_blob_plain
($mimetype);
3059 git_header_html
(undef, $expires);
3060 my $formats_nav = '';
3061 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3062 if (defined $file_name) {
3065 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3066 hash
=>$hash, file_name
=>$file_name)},
3071 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3072 hash
=>$hash, file_name
=>$file_name)},
3075 $cgi->a({-href
=> href
(action
=>"blob_plain",
3076 hash
=>$hash, file_name
=>$file_name)},
3079 $cgi->a({-href
=> href
(action
=>"blob",
3080 hash_base
=>"HEAD", file_name
=>$file_name)},
3084 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3086 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3087 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3089 print "<div class=\"page_nav\">\n" .
3090 "<br/><br/></div>\n" .
3091 "<div class=\"title\">$hash</div>\n";
3093 git_print_page_path
($file_name, "blob", $hash_base);
3094 print "<div class=\"page_body\">\n";
3096 while (my $line = <$fd>) {
3099 $line = untabify
($line);
3100 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3101 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3104 or print "Reading blob failed.\n";
3110 my $have_snapshot = gitweb_have_snapshot
();
3112 if (!defined $hash_base) {
3113 $hash_base = "HEAD";
3115 if (!defined $hash) {
3116 if (defined $file_name) {
3117 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3123 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3124 or die_error
(undef, "Open git-ls-tree failed");
3125 my @entries = map { chomp; $_ } <$fd>;
3126 close $fd or die_error
(undef, "Reading tree failed");
3129 my $refs = git_get_references
();
3130 my $ref = format_ref_marker
($refs, $hash_base);
3133 my ($have_blame) = gitweb_check_feature
('blame');
3134 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3136 if (defined $file_name) {
3138 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3139 hash
=>$hash, file_name
=>$file_name)},
3141 $cgi->a({-href
=> href
(action
=>"tree",
3142 hash_base
=>"HEAD", file_name
=>$file_name)},
3145 if ($have_snapshot) {
3146 # FIXME: Should be available when we have no hash base as well.
3148 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3151 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3152 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3155 print "<div class=\"page_nav\">\n";
3156 print "<br/><br/></div>\n";
3157 print "<div class=\"title\">$hash</div>\n";
3159 if (defined $file_name) {
3160 $basedir = $file_name;
3161 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3165 git_print_page_path
($file_name, 'tree', $hash_base);
3166 print "<div class=\"page_body\">\n";
3167 print "<table cellspacing=\"0\">\n";
3169 # '..' (top directory) link if possible
3170 if (defined $hash_base &&
3171 defined $file_name && $file_name =~ m![^/]+$!) {
3173 print "<tr class=\"dark\">\n";
3175 print "<tr class=\"light\">\n";
3179 my $up = $file_name;
3180 $up =~ s!/?[^/]+$!!;
3181 undef $up unless $up;
3182 # based on git_print_tree_entry
3183 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3184 print '<td class="list">';
3185 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3189 print "<td class=\"link\"></td>\n";
3193 foreach my $line (@entries) {
3194 my %t = parse_ls_tree_line
($line, -z
=> 1);
3197 print "<tr class=\"dark\">\n";
3199 print "<tr class=\"light\">\n";
3203 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3207 print "</table>\n" .
3213 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3214 my $have_snapshot = (defined $ctype && defined $suffix);
3215 if (!$have_snapshot) {
3216 die_error
('403 Permission denied', "Permission denied");
3219 if (!defined $hash) {
3220 $hash = git_get_head_hash
($project);
3223 my $filename = basename
($project) . "-$hash.tar.$suffix";
3226 -type
=> 'application/x-tar',
3227 -content_encoding
=> $ctype,
3228 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3229 -status
=> '200 OK');
3231 my $git = git_cmd_str
();
3232 my $name = $project;
3233 $name =~ s/\047/\047\\\047\047/g;
3235 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3236 or die_error
(undef, "Execute git-tar-tree failed.");
3237 binmode STDOUT
, ':raw';
3239 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3245 my $head = git_get_head_hash
($project);
3246 if (!defined $hash) {
3249 if (!defined $page) {
3252 my $refs = git_get_references
();
3254 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3255 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash, "--"
3256 or die_error
(undef, "Open git-rev-list failed");
3257 my @revlist = map { chomp; $_ } <$fd>;
3260 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
3263 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3266 my %co = parse_commit
($hash);
3268 git_print_header_div
('summary', $project);
3269 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3271 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
3272 my $commit = $revlist[$i];
3273 my $ref = format_ref_marker
($refs, $commit);
3274 my %co = parse_commit
($commit);
3276 my %ad = parse_date
($co{'author_epoch'});
3277 git_print_header_div
('commit',
3278 "<span class=\"age\">$co{'age_string'}</span>" .
3279 esc_html
($co{'title'}) . $ref,
3281 print "<div class=\"title_text\">\n" .
3282 "<div class=\"log_link\">\n" .
3283 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3285 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3287 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3290 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3293 print "<div class=\"log_body\">\n";
3294 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
3301 my %co = parse_commit
($hash);
3303 die_error
(undef, "Unknown commit object");
3305 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3306 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3308 my $parent = $co{'parent'};
3309 if (!defined $parent) {
3312 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
3313 @diff_opts, $parent, $hash, "--"
3314 or die_error
(undef, "Open git-diff-tree failed");
3315 my @difftree = map { chomp; $_ } <$fd>;
3316 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3318 # non-textual hash id's can be cached
3320 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3323 my $refs = git_get_references
();
3324 my $ref = format_ref_marker
($refs, $co{'id'});
3326 my $have_snapshot = gitweb_have_snapshot
();
3329 if (defined $file_name && defined $co{'parent'}) {
3331 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
3334 git_header_html
(undef, $expires);
3335 git_print_page_nav
('commit', '',
3336 $hash, $co{'tree'}, $hash,
3337 join (' | ', @views_nav));
3339 if (defined $co{'parent'}) {
3340 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3342 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3344 print "<div class=\"title_text\">\n" .
3345 "<table cellspacing=\"0\">\n";
3346 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3348 "<td></td><td> $ad{'rfc2822'}";
3349 if ($ad{'hour_local'} < 6) {
3350 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3351 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3353 printf(" (%02d:%02d %s)",
3354 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3358 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3359 print "<tr><td></td><td> $cd{'rfc2822'}" .
3360 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3362 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3365 "<td class=\"sha1\">" .
3366 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3367 class => "list"}, $co{'tree'}) .
3369 "<td class=\"link\">" .
3370 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3372 if ($have_snapshot) {
3374 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3378 my $parents = $co{'parents'};
3379 foreach my $par (@$parents) {
3382 "<td class=\"sha1\">" .
3383 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3384 class => "list"}, $par) .
3386 "<td class=\"link\">" .
3387 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3389 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3396 print "<div class=\"page_body\">\n";
3397 git_print_log
($co{'comment'});
3400 git_difftree_body
(\
@difftree, $hash, $parent);
3406 my $format = shift || 'html';
3413 # preparing $fd and %diffinfo for git_patchset_body
3415 if (defined $hash_base && defined $hash_parent_base) {
3416 if (defined $file_name) {
3418 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3419 $hash_parent_base, $hash_base,
3421 or die_error
(undef, "Open git-diff-tree failed");
3422 @difftree = map { chomp; $_ } <$fd>;
3424 or die_error
(undef, "Reading git-diff-tree failed");
3426 or die_error
('404 Not Found', "Blob diff not found");
3428 } elsif (defined $hash &&
3429 $hash =~ /[0-9a-fA-F]{40}/) {
3430 # try to find filename from $hash
3432 # read filtered raw output
3433 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3434 $hash_parent_base, $hash_base, "--"
3435 or die_error
(undef, "Open git-diff-tree failed");
3437 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3439 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3440 map { chomp; $_ } <$fd>;
3442 or die_error
(undef, "Reading git-diff-tree failed");
3444 or die_error
('404 Not Found', "Blob diff not found");
3447 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3450 if (@difftree > 1) {
3451 die_error
('404 Not Found', "Ambiguous blob diff specification");
3454 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3455 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3456 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3458 $hash_parent ||= $diffinfo{'from_id'};
3459 $hash ||= $diffinfo{'to_id'};
3461 # non-textual hash id's can be cached
3462 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3463 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3468 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3469 '-p', $hash_parent_base, $hash_base,
3471 or die_error
(undef, "Open git-diff-tree failed");
3474 # old/legacy style URI
3475 if (!%diffinfo && # if new style URI failed
3476 defined $hash && defined $hash_parent) {
3477 # fake git-diff-tree raw output
3478 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3479 $diffinfo{'from_id'} = $hash_parent;
3480 $diffinfo{'to_id'} = $hash;
3481 if (defined $file_name) {
3482 if (defined $file_parent) {
3483 $diffinfo{'status'} = '2';
3484 $diffinfo{'from_file'} = $file_parent;
3485 $diffinfo{'to_file'} = $file_name;
3486 } else { # assume not renamed
3487 $diffinfo{'status'} = '1';
3488 $diffinfo{'from_file'} = $file_name;
3489 $diffinfo{'to_file'} = $file_name;
3491 } else { # no filename given
3492 $diffinfo{'status'} = '2';
3493 $diffinfo{'from_file'} = $hash_parent;
3494 $diffinfo{'to_file'} = $hash;
3497 # non-textual hash id's can be cached
3498 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3499 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3504 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts,
3505 $hash_parent, $hash, "--"
3506 or die_error
(undef, "Open git-diff failed");
3508 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3513 if ($format eq 'html') {
3515 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3516 hash
=>$hash, hash_parent
=>$hash_parent,
3517 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3518 file_name
=>$file_name, file_parent
=>$file_parent)},
3520 git_header_html
(undef, $expires);
3521 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3522 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3523 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3525 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3526 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3528 if (defined $file_name) {
3529 git_print_page_path
($file_name, "blob", $hash_base);
3531 print "<div class=\"page_path\"></div>\n";
3534 } elsif ($format eq 'plain') {
3536 -type
=> 'text/plain',
3537 -charset
=> 'utf-8',
3538 -expires
=> $expires,
3539 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3541 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3544 die_error
(undef, "Unknown blobdiff format");
3548 if ($format eq 'html') {
3549 print "<div class=\"page_body\">\n";
3551 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3554 print "</div>\n"; # class="page_body"
3558 while (my $line = <$fd>) {
3559 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
3560 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
3564 last if $line =~ m!^\+\+\+!;
3572 sub git_blobdiff_plain
{
3573 git_blobdiff
('plain');
3576 sub git_commitdiff
{
3577 my $format = shift || 'html';
3578 my %co = parse_commit
($hash);
3580 die_error
(undef, "Unknown commit object");
3583 # we need to prepare $formats_nav before any parameter munging
3585 if ($format eq 'html') {
3587 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3588 hash
=>$hash, hash_parent
=>$hash_parent)},
3591 if (defined $hash_parent) {
3592 # commitdiff with two commits given
3593 my $hash_parent_short = $hash_parent;
3594 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3595 $hash_parent_short = substr($hash_parent, 0, 7);
3599 $cgi->a({-href
=> href
(action
=>"commitdiff",
3600 hash
=>$hash_parent)},
3601 esc_html
($hash_parent_short)) .
3603 } elsif (!$co{'parent'}) {
3605 $formats_nav .= ' (initial)';
3606 } elsif (scalar @{$co{'parents'}} == 1) {
3607 # single parent commit
3610 $cgi->a({-href
=> href
(action
=>"commitdiff",
3611 hash
=>$co{'parent'})},
3612 esc_html
(substr($co{'parent'}, 0, 7))) .
3619 $cgi->a({-href
=> href
(action
=>"commitdiff",
3621 esc_html
(substr($_, 0, 7)));
3622 } @{$co{'parents'}} ) .
3627 if (!defined $hash_parent) {
3628 $hash_parent = $co{'parent'} || '--root';
3634 if ($format eq 'html') {
3635 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3636 "--no-commit-id", "--patch-with-raw", "--full-index",
3637 $hash_parent, $hash, "--"
3638 or die_error
(undef, "Open git-diff-tree failed");
3640 while (chomp(my $line = <$fd>)) {
3641 # empty line ends raw part of diff-tree output
3643 push @difftree, $line;
3646 } elsif ($format eq 'plain') {
3647 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3648 '-p', $hash_parent, $hash, "--"
3649 or die_error
(undef, "Open git-diff-tree failed");
3652 die_error
(undef, "Unknown commitdiff format");
3655 # non-textual hash id's can be cached
3657 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3661 # write commit message
3662 if ($format eq 'html') {
3663 my $refs = git_get_references
();
3664 my $ref = format_ref_marker
($refs, $co{'id'});
3666 git_header_html
(undef, $expires);
3667 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3668 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3669 git_print_authorship
(\
%co);
3670 print "<div class=\"page_body\">\n";
3671 if (@{$co{'comment'}} > 1) {
3672 print "<div class=\"log\">\n";
3673 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
3674 print "</div>\n"; # class="log"
3677 } elsif ($format eq 'plain') {
3678 my $refs = git_get_references
("tags");
3679 my $tagname = git_get_rev_name_tags
($hash);
3680 my $filename = basename
($project) . "-$hash.patch";
3683 -type
=> 'text/plain',
3684 -charset
=> 'utf-8',
3685 -expires
=> $expires,
3686 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3687 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3690 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3691 Subject: $co{'title'}
3693 print "X-Git-Tag: $tagname\n" if $tagname;
3694 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3696 foreach my $line (@{$co{'comment'}}) {
3703 if ($format eq 'html') {
3704 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3707 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3709 print "</div>\n"; # class="page_body"
3712 } elsif ($format eq 'plain') {
3716 or print "Reading git-diff-tree failed\n";
3720 sub git_commitdiff_plain
{
3721 git_commitdiff
('plain');
3725 if (!defined $hash_base) {
3726 $hash_base = git_get_head_hash
($project);
3728 if (!defined $page) {
3732 my %co = parse_commit
($hash_base);
3734 die_error
(undef, "Unknown commit object");
3737 my $refs = git_get_references
();
3738 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3740 if (!defined $hash && defined $file_name) {
3741 $hash = git_get_hash_by_path
($hash_base, $file_name);
3743 if (defined $hash) {
3744 $ftype = git_get_type
($hash);
3748 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3749 or die_error
(undef, "Open git-rev-list-failed");
3750 my @revlist = map { chomp; $_ } <$fd>;
3752 or die_error
(undef, "Reading git-rev-list failed");
3754 my $paging_nav = '';
3757 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3758 file_name
=>$file_name)},
3760 $paging_nav .= " ⋅ " .
3761 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3762 file_name
=>$file_name, page
=>$page-1),
3763 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3765 $paging_nav .= "first";
3766 $paging_nav .= " ⋅ prev";
3768 if ($#revlist >= (100 * ($page+1)-1)) {
3769 $paging_nav .= " ⋅ " .
3770 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3771 file_name
=>$file_name, page
=>$page+1),
3772 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3774 $paging_nav .= " ⋅ next";
3777 if ($#revlist >= (100 * ($page+1)-1)) {
3779 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3780 file_name
=>$file_name, page
=>$page+1),
3781 -title
=> "Alt-n"}, "next");
3785 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3786 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3787 git_print_page_path
($file_name, $ftype, $hash_base);
3789 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3790 $refs, $hash_base, $ftype, $next_link);
3796 if (!defined $searchtext) {
3797 die_error
(undef, "Text field empty");
3799 if (!defined $hash) {
3800 $hash = git_get_head_hash
($project);
3802 my %co = parse_commit
($hash);
3804 die_error
(undef, "Unknown commit object");
3807 $searchtype ||= 'commit';
3808 if ($searchtype eq 'pickaxe') {
3809 # pickaxe may take all resources of your box and run for several minutes
3810 # with every query - so decide by yourself how public you make this feature
3811 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3812 if (!$have_pickaxe) {
3813 die_error
('403 Permission denied', "Permission denied");
3818 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3819 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3821 print "<table cellspacing=\"0\">\n";
3823 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
3825 open my $fd, "-|", git_cmd
(), "rev-list",
3826 "--header", "--parents", $hash, "--"
3828 while (my $commit_text = <$fd>) {
3829 if (!grep m/$searchtext/i, $commit_text) {
3832 if ($searchtype eq 'author' && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3835 if ($searchtype eq 'committer' && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3838 my @commit_lines = split "\n", $commit_text;
3839 my %co = parse_commit
(undef, \
@commit_lines);
3844 print "<tr class=\"dark\">\n";
3846 print "<tr class=\"light\">\n";
3849 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3850 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3852 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3853 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3854 my $comment = $co{'comment'};
3855 foreach my $line (@$comment) {
3856 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3857 my $lead = esc_html
($1) || "";
3858 $lead = chop_str
($lead, 30, 10);
3859 my $match = esc_html
($2) || "";
3860 my $trail = esc_html
($3) || "";
3861 $trail = chop_str
($trail, 30, 10);
3862 my $text = "$lead<span class=\"match\">$match</span>$trail";
3863 print chop_str
($text, 80, 5) . "<br/>\n";
3867 "<td class=\"link\">" .
3868 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3870 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3877 if ($searchtype eq 'pickaxe') {
3879 my $git_command = git_cmd_str
();
3880 open my $fd, "-|", "$git_command rev-list $hash | " .
3881 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3884 while (my $line = <$fd>) {
3885 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3888 $set{'from_id'} = $3;
3890 $set{'id'} = $set{'to_id'};
3891 if ($set{'id'} =~ m/0{40}/) {
3892 $set{'id'} = $set{'from_id'};
3894 if ($set{'id'} =~ m/0{40}/) {
3898 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3901 print "<tr class=\"dark\">\n";
3903 print "<tr class=\"light\">\n";
3906 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3907 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3909 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3910 -class => "list subject"},
3911 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3912 while (my $setref = shift @files) {
3914 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3915 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3917 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
3921 "<td class=\"link\">" .
3922 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3924 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3928 %co = parse_commit
($1);
3937 sub git_search_help
{
3939 git_print_page_nav
('','', $hash,$hash,$hash);
3942 <dt><b>commit</b></dt>
3943 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
3944 <dt><b>author</b></dt>
3945 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
3946 <dt><b>committer</b></dt>
3947 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
3949 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3950 if ($have_pickaxe) {
3952 <dt><b>pickaxe</b></dt>
3953 <dd>All commits that caused the string to appear or disappear from any file (changes that
3954 added, removed or "modified" the string) will be listed. This search can take a while and
3955 takes a lot of strain on the server, so please use it wisely.</dd>
3963 my $head = git_get_head_hash
($project);
3964 if (!defined $hash) {
3967 if (!defined $page) {
3970 my $refs = git_get_references
();
3972 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3973 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash, "--"
3974 or die_error
(undef, "Open git-rev-list failed");
3975 my @revlist = map { chomp; $_ } <$fd>;
3978 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3980 if ($#revlist >= (100 * ($page+1)-1)) {
3982 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3983 -title
=> "Alt-n"}, "next");
3988 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3989 git_print_header_div
('summary', $project);
3991 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3996 ## ......................................................................
3997 ## feeds (RSS, OPML)
4000 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4001 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150",
4002 git_get_head_hash
($project), "--"
4003 or die_error
(undef, "Open git-rev-list failed");
4004 my @revlist = map { chomp; $_ } <$fd>;
4005 close $fd or die_error
(undef, "Reading git-rev-list failed");
4006 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
4008 <?xml version="1.0" encoding="utf-8"?>
4009 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
4011 <title>$project $my_uri $my_url</title>
4012 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
4013 <description>$project log</description>
4014 <language>en</language>
4017 for (my $i = 0; $i <= $#revlist; $i++) {
4018 my $commit = $revlist[$i];
4019 my %co = parse_commit
($commit);
4020 # we read 150, we always show 30 and the ones more recent than 48 hours
4021 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
4024 my %cd = parse_date
($co{'committer_epoch'});
4025 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4026 $co{'parent'}, $co{'id'}, "--"
4028 my @difftree = map { chomp; $_ } <$fd>;
4033 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
4035 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
4036 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
4037 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
4038 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
4039 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
4040 "<content:encoded>" .
4042 my $comment = $co{'comment'};
4043 foreach my $line (@$comment) {
4044 $line = to_utf8
($line);
4045 print "$line<br/>\n";
4048 foreach my $line (@difftree) {
4049 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
4052 my $file = esc_path
(unquote
($7));
4053 $file = to_utf8
($file);
4054 print "$file<br/>\n";
4057 "</content:encoded>\n" .
4060 print "</channel></rss>";
4064 my @list = git_get_projects_list
();
4066 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
4068 <?xml version="1.0" encoding="utf-8"?>
4069 <opml version="1.0">
4071 <title>$site_name OPML Export</title>
4074 <outline text="git RSS feeds">
4077 foreach my $pr (@list) {
4079 my $head = git_get_head_hash
($proj{'path'});
4080 if (!defined $head) {
4083 $git_dir = "$projectroot/$proj{'path'}";
4084 my %co = parse_commit
($head);
4089 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
4090 my $rss = "$my_url?p=$proj{'path'};a=rss";
4091 my $html = "$my_url?p=$proj{'path'};a=summary";
4092 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";