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
576 $str = to_utf8
($str);
577 $str = escapeHTML
($str);
578 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
579 $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1)
583 # git may return quoted and escaped filenames
586 if ($str =~ m/^"(.*)"$/) {
588 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
593 # escape tabs (convert tabs to spaces)
597 while ((my $pos = index($line, "\t")) != -1) {
598 if (my $count = (8 - ($pos % 8))) {
599 my $spaces = ' ' x
$count;
600 $line =~ s/\t/$spaces/;
607 sub project_in_list
{
609 my @list = git_get_projects_list
();
610 return @list && scalar(grep { $_->{'path'} eq $project } @list);
613 ## ----------------------------------------------------------------------
614 ## HTML aware string manipulation
619 my $add_len = shift || 10;
621 # allow only $len chars, but don't cut a word if it would fit in $add_len
622 # if it doesn't fit, cut it if it's still longer than the dots we would add
623 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
626 if (length($tail) > 4) {
628 $body =~ s/&[^;]*$//; # remove chopped character entities
633 ## ----------------------------------------------------------------------
634 ## functions returning short strings
636 # CSS class for given age value (in seconds)
640 if ($age < 60*60*2) {
642 } elsif ($age < 60*60*24*2) {
649 # convert age in seconds to "nn units ago" string
654 if ($age > 60*60*24*365*2) {
655 $age_str = (int $age/60/60/24/365);
656 $age_str .= " years ago";
657 } elsif ($age > 60*60*24*(365/12)*2) {
658 $age_str = int $age/60/60/24/(365/12);
659 $age_str .= " months ago";
660 } elsif ($age > 60*60*24*7*2) {
661 $age_str = int $age/60/60/24/7;
662 $age_str .= " weeks ago";
663 } elsif ($age > 60*60*24*2) {
664 $age_str = int $age/60/60/24;
665 $age_str .= " days ago";
666 } elsif ($age > 60*60*2) {
667 $age_str = int $age/60/60;
668 $age_str .= " hours ago";
669 } elsif ($age > 60*2) {
670 $age_str = int $age/60;
671 $age_str .= " min ago";
674 $age_str .= " sec ago";
676 $age_str .= " right now";
681 # convert file mode in octal to symbolic file mode string
683 my $mode = oct shift;
685 if (S_ISDIR
($mode & S_IFMT
)) {
687 } elsif (S_ISLNK
($mode)) {
689 } elsif (S_ISREG
($mode)) {
690 # git cares only about the executable bit
691 if ($mode & S_IXUSR
) {
701 # convert file mode in octal to file type string
705 if ($mode !~ m/^[0-7]+$/) {
711 if (S_ISDIR
($mode & S_IFMT
)) {
713 } elsif (S_ISLNK
($mode)) {
715 } elsif (S_ISREG
($mode)) {
722 ## ----------------------------------------------------------------------
723 ## functions returning short HTML fragments, or transforming HTML fragments
724 ## which don't beling to other sections
726 # format line of commit message or tag comment
727 sub format_log_line_html
{
730 $line = esc_html
($line);
731 $line =~ s/ / /g;
732 if ($line =~ m/([0-9a-fA-F]{40})/) {
734 if (git_get_type
($hash_text) eq "commit") {
736 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
737 -class => "text"}, $hash_text);
738 $line =~ s/$hash_text/$link/;
744 # format marker of refs pointing to given object
745 sub format_ref_marker
{
746 my ($refs, $id) = @_;
749 if (defined $refs->{$id}) {
750 foreach my $ref (@{$refs->{$id}}) {
751 my ($type, $name) = qw();
752 # e.g. tags/v2.6.11 or heads/next
753 if ($ref =~ m!^(.*?)s?/(.*)$!) {
761 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
766 return ' <span class="refs">'. $markers . '</span>';
772 # format, perhaps shortened and with markers, title line
773 sub format_subject_html
{
774 my ($long, $short, $href, $extra) = @_;
775 $extra = '' unless defined($extra);
777 if (length($short) < length($long)) {
778 return $cgi->a({-href
=> $href, -class => "list subject",
779 -title
=> to_utf8
($long)},
780 esc_html
($short) . $extra);
782 return $cgi->a({-href
=> $href, -class => "list subject"},
783 esc_html
($long) . $extra);
787 sub format_diff_line
{
789 my $char = substr($line, 0, 1);
795 $diff_class = " add";
796 } elsif ($char eq "-") {
797 $diff_class = " rem";
798 } elsif ($char eq "@") {
799 $diff_class = " chunk_header";
800 } elsif ($char eq "\\") {
801 $diff_class = " incomplete";
803 $line = untabify
($line);
804 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
807 ## ----------------------------------------------------------------------
808 ## git utility subroutines, invoking git commands
810 # returns path to the core git executable and the --git-dir parameter as list
812 return $GIT, '--git-dir='.$git_dir;
815 # returns path to the core git executable and the --git-dir parameter as string
817 return join(' ', git_cmd
());
820 # get HEAD ref of given project as hash
821 sub git_get_head_hash
{
823 my $o_git_dir = $git_dir;
825 $git_dir = "$projectroot/$project";
826 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
829 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
833 if (defined $o_git_dir) {
834 $git_dir = $o_git_dir;
839 # get type of given object
843 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
850 sub git_get_project_config
{
851 my ($key, $type) = @_;
853 return unless ($key);
854 $key =~ s/^gitweb\.//;
855 return if ($key =~ m/\W/);
857 my @x = (git_cmd
(), 'repo-config');
858 if (defined $type) { push @x, $type; }
860 push @x, "gitweb.$key";
866 # get hash of given path at given ref
867 sub git_get_hash_by_path
{
869 my $path = shift || return undef;
874 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
875 or die_error
(undef, "Open git-ls-tree failed");
877 close $fd or return undef;
879 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
880 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
881 if (defined $type && $type ne $2) {
888 ## ......................................................................
889 ## git utility functions, directly accessing git repository
891 sub git_get_project_description
{
894 open my $fd, "$projectroot/$path/description" or return undef;
901 sub git_get_project_url_list
{
904 open my $fd, "$projectroot/$path/cloneurl" or return;
905 my @git_project_url_list = map { chomp; $_ } <$fd>;
908 return wantarray ? @git_project_url_list : \
@git_project_url_list;
911 sub git_get_projects_list
{
916 $filter =~ s/\.git$//;
918 if (-d
$projects_list) {
919 # search in directory
920 my $dir = $projects_list . ($filter ? "/$filter" : '');
921 my $pfxlen = length("$dir");
923 my $check_forks = gitweb_check_feature
('forks');
926 follow_fast
=> 1, # follow symbolic links
927 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
929 # skip project-list toplevel, if we get it.
930 return if (m!^[/.]$!);
931 # only directories can be git repositories
932 return unless (-d
$_);
934 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
935 # we check related file in $projectroot
936 if ($check_forks and $subdir =~ m
#/.#) {
937 $File::Find
::prune
= 1;
938 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
939 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
940 $File::Find
::prune
= 1;
945 } elsif (-f
$projects_list) {
946 # read from file(url-encoded):
947 # 'git%2Fgit.git Linus+Torvalds'
948 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
949 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
950 open my ($fd), $projects_list or return;
951 while (my $line = <$fd>) {
953 my ($path, $owner) = split ' ', $line;
954 $path = unescape
($path);
955 $owner = unescape
($owner);
956 if (!defined $path) {
959 if (check_export_ok
("$projectroot/$path")) {
962 owner
=> to_utf8
($owner),
969 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
973 sub git_get_project_owner
{
977 return undef unless $project;
979 # read from file (url-encoded):
980 # 'git%2Fgit.git Linus+Torvalds'
981 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
982 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
983 if (-f
$projects_list) {
984 open (my $fd , $projects_list);
985 while (my $line = <$fd>) {
987 my ($pr, $ow) = split ' ', $line;
990 if ($pr eq $project) {
991 $owner = to_utf8
($ow);
997 if (!defined $owner) {
998 $owner = get_file_owner
("$projectroot/$project");
1004 sub git_get_last_activity
{
1008 $git_dir = "$projectroot/$path";
1009 open($fd, "-|", git_cmd
(), 'for-each-ref',
1010 '--format=%(refname) %(committer)',
1011 '--sort=-committerdate',
1012 'refs/heads') or return;
1013 my $most_recent = <$fd>;
1014 close $fd or return;
1015 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1017 my $age = time - $timestamp;
1018 return ($age, age_string
($age));
1022 sub git_get_references
{
1023 my $type = shift || "";
1025 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1026 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1027 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1030 while (my $line = <$fd>) {
1032 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
1033 if (defined $refs{$1}) {
1034 push @{$refs{$1}}, $2;
1040 close $fd or return;
1044 sub git_get_rev_name_tags
{
1045 my $hash = shift || return undef;
1047 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1049 my $name_rev = <$fd>;
1052 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1055 # catches also '$hash undefined' output
1060 ## ----------------------------------------------------------------------
1061 ## parse to hash functions
1065 my $tz = shift || "-0000";
1068 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1069 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1070 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1071 $date{'hour'} = $hour;
1072 $date{'minute'} = $min;
1073 $date{'mday'} = $mday;
1074 $date{'day'} = $days[$wday];
1075 $date{'month'} = $months[$mon];
1076 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1077 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1078 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1079 $mday, $months[$mon], $hour ,$min;
1081 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1082 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1083 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1084 $date{'hour_local'} = $hour;
1085 $date{'minute_local'} = $min;
1086 $date{'tz_local'} = $tz;
1087 $date{'iso-tz'} = sprintf ("%04d-%02d-%02d %02d:%02d:%02d %s",
1088 1900+$year, $mon+1, $mday,
1089 $hour, $min, $sec, $tz);
1098 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1099 $tag{'id'} = $tag_id;
1100 while (my $line = <$fd>) {
1102 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1103 $tag{'object'} = $1;
1104 } elsif ($line =~ m/^type (.+)$/) {
1106 } elsif ($line =~ m/^tag (.+)$/) {
1108 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1109 $tag{'author'} = $1;
1112 } elsif ($line =~ m/--BEGIN/) {
1113 push @comment, $line;
1115 } elsif ($line eq "") {
1119 push @comment, <$fd>;
1120 $tag{'comment'} = \
@comment;
1121 close $fd or return;
1122 if (!defined $tag{'name'}) {
1129 my $commit_id = shift;
1130 my $commit_text = shift;
1135 if (defined $commit_text) {
1136 @commit_lines = @$commit_text;
1139 open my $fd, "-|", git_cmd
(), "rev-list",
1140 "--header", "--parents", "--max-count=1",
1143 @commit_lines = split '\n', <$fd>;
1144 close $fd or return;
1147 my $header = shift @commit_lines;
1148 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1151 ($co{'id'}, my @parents) = split ' ', $header;
1152 $co{'parents'} = \
@parents;
1153 $co{'parent'} = $parents[0];
1154 while (my $line = shift @commit_lines) {
1155 last if $line eq "\n";
1156 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1158 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1160 $co{'author_epoch'} = $2;
1161 $co{'author_tz'} = $3;
1162 if ($co{'author'} =~ m/^([^<]+) </) {
1163 $co{'author_name'} = $1;
1165 $co{'author_name'} = $co{'author'};
1167 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1168 $co{'committer'} = $1;
1169 $co{'committer_epoch'} = $2;
1170 $co{'committer_tz'} = $3;
1171 $co{'committer_name'} = $co{'committer'};
1172 $co{'committer_name'} =~ s/ <.*//;
1175 if (!defined $co{'tree'}) {
1179 foreach my $title (@commit_lines) {
1182 $co{'title'} = chop_str
($title, 80, 5);
1183 # remove leading stuff of merges to make the interesting part visible
1184 if (length($title) > 50) {
1185 $title =~ s/^Automatic //;
1186 $title =~ s/^merge (of|with) /Merge ... /i;
1187 if (length($title) > 50) {
1188 $title =~ s/(http|rsync):\/\///;
1190 if (length($title) > 50) {
1191 $title =~ s/(master|www|rsync)\.//;
1193 if (length($title) > 50) {
1194 $title =~ s/kernel.org:?//;
1196 if (length($title) > 50) {
1197 $title =~ s/\/pub\/scm//;
1200 $co{'title_short'} = chop_str
($title, 50, 5);
1204 if ($co{'title'} eq "") {
1205 $co{'title'} = $co{'title_short'} = '(no commit message)';
1207 # remove added spaces
1208 foreach my $line (@commit_lines) {
1211 $co{'comment'} = \
@commit_lines;
1213 my $age = time - $co{'committer_epoch'};
1215 $co{'age_string'} = age_string
($age);
1216 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1217 if ($age > 60*60*24*7*2) {
1218 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1219 $co{'age_string_age'} = $co{'age_string'};
1221 $co{'age_string_date'} = $co{'age_string'};
1222 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1227 # parse ref from ref_file, given by ref_id, with given type
1229 my $ref_file = shift;
1231 my $type = shift || git_get_type
($ref_id);
1234 $ref_item{'type'} = $type;
1235 $ref_item{'id'} = $ref_id;
1236 $ref_item{'epoch'} = 0;
1237 $ref_item{'age'} = "unknown";
1238 if ($type eq "tag") {
1239 my %tag = parse_tag
($ref_id);
1240 $ref_item{'comment'} = $tag{'comment'};
1241 if ($tag{'type'} eq "commit") {
1242 my %co = parse_commit
($tag{'object'});
1243 $ref_item{'epoch'} = $co{'committer_epoch'};
1244 $ref_item{'age'} = $co{'age_string'};
1245 } elsif (defined($tag{'epoch'})) {
1246 my $age = time - $tag{'epoch'};
1247 $ref_item{'epoch'} = $tag{'epoch'};
1248 $ref_item{'age'} = age_string
($age);
1250 $ref_item{'reftype'} = $tag{'type'};
1251 $ref_item{'name'} = $tag{'name'};
1252 $ref_item{'refid'} = $tag{'object'};
1253 } elsif ($type eq "commit"){
1254 my %co = parse_commit
($ref_id);
1255 $ref_item{'reftype'} = "commit";
1256 $ref_item{'name'} = $ref_file;
1257 $ref_item{'title'} = $co{'title'};
1258 $ref_item{'refid'} = $ref_id;
1259 $ref_item{'epoch'} = $co{'committer_epoch'};
1260 $ref_item{'age'} = $co{'age_string'};
1262 $ref_item{'reftype'} = $type;
1263 $ref_item{'name'} = $ref_file;
1264 $ref_item{'refid'} = $ref_id;
1270 # parse line of git-diff-tree "raw" output
1271 sub parse_difftree_raw_line
{
1275 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1276 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1277 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1278 $res{'from_mode'} = $1;
1279 $res{'to_mode'} = $2;
1280 $res{'from_id'} = $3;
1282 $res{'status'} = $5;
1283 $res{'similarity'} = $6;
1284 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1285 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1287 $res{'file'} = unquote
($7);
1290 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1291 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1292 $res{'commit'} = $1;
1295 return wantarray ? %res : \
%res;
1298 # parse line of git-ls-tree output
1299 sub parse_ls_tree_line
($;%) {
1304 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1305 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1313 $res{'name'} = unquote
($4);
1316 return wantarray ? %res : \
%res;
1319 ## ......................................................................
1320 ## parse to array of hashes functions
1322 sub git_get_heads_list
{
1326 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1327 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1328 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1331 while (my $line = <$fd>) {
1335 my ($refinfo, $committerinfo) = split(/\0/, $line);
1336 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1337 my ($committer, $epoch, $tz) =
1338 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1339 $name =~ s!^refs/heads/!!;
1341 $ref_item{'name'} = $name;
1342 $ref_item{'id'} = $hash;
1343 $ref_item{'title'} = $title || '(no commit message)';
1344 $ref_item{'epoch'} = $epoch;
1346 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1348 $ref_item{'age'} = "unknown";
1351 push @headslist, \
%ref_item;
1355 return wantarray ? @headslist : \
@headslist;
1358 sub git_get_tags_list
{
1362 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1363 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1364 '--format=%(objectname) %(objecttype) %(refname) '.
1365 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1368 while (my $line = <$fd>) {
1372 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1373 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1374 my ($creator, $epoch, $tz) =
1375 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1376 $name =~ s!^refs/tags/!!;
1378 $ref_item{'type'} = $type;
1379 $ref_item{'id'} = $id;
1380 $ref_item{'name'} = $name;
1381 if ($type eq "tag") {
1382 $ref_item{'subject'} = $title;
1383 $ref_item{'reftype'} = $reftype;
1384 $ref_item{'refid'} = $refid;
1386 $ref_item{'reftype'} = $type;
1387 $ref_item{'refid'} = $id;
1390 if ($type eq "tag" || $type eq "commit") {
1391 $ref_item{'epoch'} = $epoch;
1393 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1395 $ref_item{'age'} = "unknown";
1399 push @tagslist, \
%ref_item;
1403 return wantarray ? @tagslist : \
@tagslist;
1406 ## ----------------------------------------------------------------------
1407 ## filesystem-related functions
1409 sub get_file_owner
{
1412 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1413 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1414 if (!defined $gcos) {
1418 $owner =~ s/[,;].*$//;
1419 return to_utf8
($owner);
1422 ## ......................................................................
1423 ## mimetype related functions
1425 sub mimetype_guess_file
{
1426 my $filename = shift;
1427 my $mimemap = shift;
1428 -r
$mimemap or return undef;
1431 open(MIME
, $mimemap) or return undef;
1433 next if m/^#/; # skip comments
1434 my ($mime, $exts) = split(/\t+/);
1435 if (defined $exts) {
1436 my @exts = split(/\s+/, $exts);
1437 foreach my $ext (@exts) {
1438 $mimemap{$ext} = $mime;
1444 $filename =~ /\.([^.]*)$/;
1445 return $mimemap{$1};
1448 sub mimetype_guess
{
1449 my $filename = shift;
1451 $filename =~ /\./ or return undef;
1453 if ($mimetypes_file) {
1454 my $file = $mimetypes_file;
1455 if ($file !~ m!^/!) { # if it is relative path
1456 # it is relative to project
1457 $file = "$projectroot/$project/$file";
1459 $mime = mimetype_guess_file
($filename, $file);
1461 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1467 my $filename = shift;
1470 my $mime = mimetype_guess
($filename);
1471 $mime and return $mime;
1475 return $default_blob_plain_mimetype unless $fd;
1478 return 'text/plain' .
1479 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1480 } elsif (! $filename) {
1481 return 'application/octet-stream';
1482 } elsif ($filename =~ m/\.png$/i) {
1484 } elsif ($filename =~ m/\.gif$/i) {
1486 } elsif ($filename =~ m/\.jpe?g$/i) {
1487 return 'image/jpeg';
1489 return 'application/octet-stream';
1493 ## ======================================================================
1494 ## functions printing HTML: header, footer, error page
1496 sub git_header_html
{
1497 my $status = shift || "200 OK";
1498 my $expires = shift;
1500 my $title = "$site_name";
1501 if (defined $project) {
1502 $title .= " - $project";
1503 if (defined $action) {
1504 $title .= "/$action";
1505 if (defined $file_name) {
1506 $title .= " - " . esc_html
($file_name);
1507 if ($action eq "tree" && $file_name !~ m
|/$|) {
1514 # require explicit support from the UA if we are to send the page as
1515 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1516 # we have to do this because MSIE sometimes globs '*/*', pretending to
1517 # support xhtml+xml but choking when it gets what it asked for.
1518 if (defined $cgi->http('HTTP_ACCEPT') &&
1519 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1520 $cgi->Accept('application/xhtml+xml') != 0) {
1521 $content_type = 'application/xhtml+xml';
1523 $content_type = 'text/html';
1525 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1526 -status
=> $status, -expires
=> $expires);
1528 <?xml version="1.0" encoding="utf-8"?>
1529 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1530 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1531 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1532 <!-- git core binaries version $git_version -->
1534 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1535 <meta name="generator" content="gitweb/$version git/$git_version"/>
1536 <meta name="robots" content="index, nofollow"/>
1537 <title>$title</title>
1539 # print out each stylesheet that exist
1540 if (defined $stylesheet) {
1541 #provides backwards capability for those people who define style sheet in a config file
1542 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1544 foreach my $stylesheet (@stylesheets) {
1545 next unless $stylesheet;
1546 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1549 if (defined $project) {
1550 printf('<link rel="alternate" title="%s log" '.
1551 'href="%s" type="application/rss+xml"/>'."\n",
1552 esc_param
($project), href
(action
=>"rss"));
1554 printf('<link rel="alternate" title="%s projects list" '.
1555 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1556 $site_name, href
(project
=>undef, action
=>"project_index"));
1557 printf('<link rel="alternate" title="%s projects logs" '.
1558 'href="%s" type="text/x-opml"/>'."\n",
1559 $site_name, href
(project
=>undef, action
=>"opml"));
1561 if (defined $favicon) {
1562 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1568 if (-f
$site_header) {
1569 open (my $fd, $site_header);
1574 print "<div class=\"page_header\">\n" .
1575 $cgi->a({-href
=> esc_url
($logo_url),
1576 -title
=> $logo_label},
1577 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1578 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1579 if (defined $project) {
1580 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1581 if (defined $action) {
1585 if (!defined $searchtext) {
1589 if (defined $hash_base) {
1590 $search_hash = $hash_base;
1591 } elsif (defined $hash) {
1592 $search_hash = $hash;
1594 $search_hash = "HEAD";
1596 $cgi->param("a", "search");
1597 $cgi->param("h", $search_hash);
1598 $cgi->param("p", $project);
1599 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1600 "<div class=\"search\">\n" .
1601 $cgi->hidden(-name
=> "p") . "\n" .
1602 $cgi->hidden(-name
=> "a") . "\n" .
1603 $cgi->hidden(-name
=> "h") . "\n" .
1604 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1605 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1606 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1608 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1610 $cgi->end_form() . "\n";
1615 sub git_footer_html
{
1616 print "<div class=\"page_footer\">\n";
1617 if (defined $project) {
1618 my $descr = git_get_project_description
($project);
1619 if (defined $descr) {
1620 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1622 print $cgi->a({-href
=> href
(action
=>"rss"),
1623 -class => "rss_logo"}, "RSS") . "\n";
1625 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1626 -class => "rss_logo"}, "OPML") . " ";
1627 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1628 -class => "rss_logo"}, "TXT") . "\n";
1632 if (-f
$site_footer) {
1633 open (my $fd, $site_footer);
1643 my $status = shift || "403 Forbidden";
1644 my $error = shift || "Malformed query, file missing or permission denied";
1646 git_header_html
($status);
1648 <div class="page_body">
1658 ## ----------------------------------------------------------------------
1659 ## functions printing or outputting HTML: navigation
1661 sub git_print_page_nav
{
1662 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1663 $extra = '' if !defined $extra; # pager or formats
1665 my @navs = qw(summary shortlog log commit commitdiff tree);
1667 @navs = grep { $_ ne $suppress } @navs;
1670 my %arg = map { $_ => {action
=>$_} } @navs;
1671 if (defined $head) {
1672 for (qw(commit commitdiff)) {
1673 $arg{$_}{hash
} = $head;
1675 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1676 for (qw(shortlog log)) {
1677 $arg{$_}{hash
} = $head;
1681 $arg{tree
}{hash
} = $treehead if defined $treehead;
1682 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1684 print "<div class=\"page_nav\">\n" .
1686 map { $_ eq $current ?
1687 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1689 print "<br/>\n$extra<br/>\n" .
1693 sub format_paging_nav
{
1694 my ($action, $hash, $head, $page, $nrevs) = @_;
1698 if ($hash ne $head || $page) {
1699 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1701 $paging_nav .= "HEAD";
1705 $paging_nav .= " ⋅ " .
1706 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1707 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1709 $paging_nav .= " ⋅ prev";
1712 if ($nrevs >= (100 * ($page+1)-1)) {
1713 $paging_nav .= " ⋅ " .
1714 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1715 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1717 $paging_nav .= " ⋅ next";
1723 ## ......................................................................
1724 ## functions printing or outputting HTML: div
1726 sub git_print_header_div
{
1727 my ($action, $title, $hash, $hash_base) = @_;
1730 $args{action
} = $action;
1731 $args{hash
} = $hash if $hash;
1732 $args{hash_base
} = $hash_base if $hash_base;
1734 print "<div class=\"header\">\n" .
1735 $cgi->a({-href
=> href
(%args), -class => "title"},
1736 $title ? $title : $action) .
1740 #sub git_print_authorship (\%) {
1741 sub git_print_authorship
{
1744 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1745 print "<div class=\"author_date\">" .
1746 esc_html
($co->{'author_name'}) .
1748 if ($ad{'hour_local'} < 6) {
1749 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1750 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1752 printf(" (%02d:%02d %s)",
1753 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1758 sub git_print_page_path
{
1764 print "<div class=\"page_path\">";
1765 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1766 -title
=> 'tree root'}, "[$project]");
1768 if (defined $name) {
1769 my @dirname = split '/', $name;
1770 my $basename = pop @dirname;
1773 foreach my $dir (@dirname) {
1774 $fullname .= ($fullname ? '/' : '') . $dir;
1775 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1777 -title
=> $fullname}, esc_html
($dir));
1780 if (defined $type && $type eq 'blob') {
1781 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1783 -title
=> $name}, esc_html
($basename));
1784 } elsif (defined $type && $type eq 'tree') {
1785 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1787 -title
=> $name}, esc_html
($basename));
1790 print esc_html
($basename);
1793 print "<br/></div>\n";
1796 # sub git_print_log (\@;%) {
1797 sub git_print_log
($;%) {
1801 if ($opts{'-remove_title'}) {
1802 # remove title, i.e. first line of log
1805 # remove leading empty lines
1806 while (defined $log->[0] && $log->[0] eq "") {
1813 foreach my $line (@$log) {
1814 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1817 if (! $opts{'-remove_signoff'}) {
1818 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1821 # remove signoff lines
1828 # print only one empty line
1829 # do not print empty line after signoff
1831 next if ($empty || $signoff);
1837 print format_log_line_html
($line) . "<br/>\n";
1840 if ($opts{'-final_empty_line'}) {
1841 # end with single empty line
1842 print "<br/>\n" unless $empty;
1846 # print tree entry (row of git_tree), but without encompassing <tr> element
1847 sub git_print_tree_entry
{
1848 my ($t, $basedir, $hash_base, $have_blame) = @_;
1851 $base_key{hash_base
} = $hash_base if defined $hash_base;
1853 # The format of a table row is: mode list link. Where mode is
1854 # the mode of the entry, list is the name of the entry, an href,
1855 # and link is the action links of the entry.
1857 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1858 if ($t->{'type'} eq "blob") {
1859 print "<td class=\"list\">" .
1860 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1861 file_name
=>"$basedir$t->{'name'}", %base_key),
1862 -class => "list"}, esc_html
($t->{'name'})) . "</td>\n";
1863 print "<td class=\"link\">";
1864 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1865 file_name
=>"$basedir$t->{'name'}", %base_key)},
1869 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1870 file_name
=>"$basedir$t->{'name'}", %base_key)},
1873 if (defined $hash_base) {
1875 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1876 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1880 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
1881 file_name
=>"$basedir$t->{'name'}")},
1885 } elsif ($t->{'type'} eq "tree") {
1886 print "<td class=\"list\">";
1887 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1888 file_name
=>"$basedir$t->{'name'}", %base_key)},
1889 esc_html
($t->{'name'}));
1891 print "<td class=\"link\">";
1892 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1893 file_name
=>"$basedir$t->{'name'}", %base_key)},
1895 if (defined $hash_base) {
1897 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1898 file_name
=>"$basedir$t->{'name'}")},
1905 ## ......................................................................
1906 ## functions printing large fragments of HTML
1908 sub git_difftree_body
{
1909 my ($difftree, $hash, $parent) = @_;
1911 print "<div class=\"list_head\">\n";
1912 if ($#{$difftree} > 10) {
1913 print(($#{$difftree} + 1) . " files changed:\n");
1917 print "<table class=\"diff_tree\">\n";
1920 foreach my $line (@{$difftree}) {
1921 my %diff = parse_difftree_raw_line
($line);
1924 print "<tr class=\"dark\">\n";
1926 print "<tr class=\"light\">\n";
1930 my ($to_mode_oct, $to_mode_str, $to_file_type);
1931 my ($from_mode_oct, $from_mode_str, $from_file_type);
1932 if ($diff{'to_mode'} ne ('0' x
6)) {
1933 $to_mode_oct = oct $diff{'to_mode'};
1934 if (S_ISREG
($to_mode_oct)) { # only for regular file
1935 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1937 $to_file_type = file_type
($diff{'to_mode'});
1939 if ($diff{'from_mode'} ne ('0' x
6)) {
1940 $from_mode_oct = oct $diff{'from_mode'};
1941 if (S_ISREG
($to_mode_oct)) { # only for regular file
1942 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1944 $from_file_type = file_type
($diff{'from_mode'});
1947 if ($diff{'status'} eq "A") { # created
1948 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1949 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1950 $mode_chng .= "]</span>";
1952 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1953 hash_base
=>$hash, file_name
=>$diff{'file'}),
1954 -class => "list"}, esc_html
($diff{'file'}));
1956 print "<td>$mode_chng</td>\n";
1957 print "<td class=\"link\">";
1958 if ($action eq 'commitdiff') {
1961 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1965 } elsif ($diff{'status'} eq "D") { # deleted
1966 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1968 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1969 hash_base
=>$parent, file_name
=>$diff{'file'}),
1970 -class => "list"}, esc_html
($diff{'file'}));
1972 print "<td>$mode_chng</td>\n";
1973 print "<td class=\"link\">";
1974 if ($action eq 'commitdiff') {
1977 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1980 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1981 hash_base
=>$parent, file_name
=>$diff{'file'})},
1983 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1984 file_name
=>$diff{'file'})},
1986 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1987 file_name
=>$diff{'file'})},
1991 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1992 my $mode_chnge = "";
1993 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1994 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1995 if ($from_file_type != $to_file_type) {
1996 $mode_chnge .= " from $from_file_type to $to_file_type";
1998 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1999 if ($from_mode_str && $to_mode_str) {
2000 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2001 } elsif ($to_mode_str) {
2002 $mode_chnge .= " mode: $to_mode_str";
2005 $mode_chnge .= "]</span>\n";
2008 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2009 hash_base
=>$hash, file_name
=>$diff{'file'}),
2010 -class => "list"}, esc_html
($diff{'file'}));
2012 print "<td>$mode_chnge</td>\n";
2013 print "<td class=\"link\">";
2014 if ($action eq 'commitdiff') {
2017 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2019 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2020 # "commit" view and modified file (not onlu mode changed)
2021 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2022 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2023 hash_base
=>$hash, hash_parent_base
=>$parent,
2024 file_name
=>$diff{'file'})},
2028 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2029 hash_base
=>$hash, file_name
=>$diff{'file'})},
2031 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2032 file_name
=>$diff{'file'})},
2034 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2035 file_name
=>$diff{'file'})},
2039 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
2040 my %status_name = ('R' => 'moved', 'C' => 'copied');
2041 my $nstatus = $status_name{$diff{'status'}};
2043 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2044 # mode also for directories, so we cannot use $to_mode_str
2045 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2048 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2049 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
2050 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
2051 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2052 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2053 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
2054 -class => "list"}, esc_html
($diff{'from_file'})) .
2055 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2056 "<td class=\"link\">";
2057 if ($action eq 'commitdiff') {
2060 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2062 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2063 # "commit" view and modified file (not only pure rename or copy)
2064 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2065 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2066 hash_base
=>$hash, hash_parent_base
=>$parent,
2067 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
2071 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2072 hash_base
=>$parent, file_name
=>$diff{'from_file'})},
2074 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2075 file_name
=>$diff{'from_file'})},
2077 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2078 file_name
=>$diff{'from_file'})},
2082 } # we should not encounter Unmerged (U) or Unknown (X) status
2088 sub git_patchset_body
{
2089 my ($fd, $difftree, $hash, $hash_parent) = @_;
2093 my $patch_found = 0;
2096 print "<div class=\"patchset\">\n";
2099 while (my $patch_line = <$fd>) {
2102 if ($patch_line =~ m/^diff /) { # "git diff" header
2103 # beginning of patch (in patchset)
2105 # close previous patch
2106 print "</div>\n"; # class="patch"
2108 # first patch in patchset
2111 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2113 if (ref($difftree->[$patch_idx]) eq "HASH") {
2114 $diffinfo = $difftree->[$patch_idx];
2116 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2120 if ($diffinfo->{'status'} eq "A") { # added
2121 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
2122 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2123 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2124 $diffinfo->{'to_id'}) . " (new)" .
2125 "</div>\n"; # class="diff_info"
2127 } elsif ($diffinfo->{'status'} eq "D") { # deleted
2128 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
2129 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2130 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2131 $diffinfo->{'from_id'}) . " (deleted)" .
2132 "</div>\n"; # class="diff_info"
2134 } elsif ($diffinfo->{'status'} eq "R" || # renamed
2135 $diffinfo->{'status'} eq "C" || # copied
2136 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
2137 print "<div class=\"diff_info\">" .
2138 file_type
($diffinfo->{'from_mode'}) . ":" .
2139 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2140 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
2141 $diffinfo->{'from_id'}) .
2143 file_type
($diffinfo->{'to_mode'}) . ":" .
2144 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2145 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
2146 $diffinfo->{'to_id'});
2147 print "</div>\n"; # class="diff_info"
2149 } else { # modified, mode changed, ...
2150 print "<div class=\"diff_info\">" .
2151 file_type
($diffinfo->{'from_mode'}) . ":" .
2152 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2153 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2154 $diffinfo->{'from_id'}) .
2156 file_type
($diffinfo->{'to_mode'}) . ":" .
2157 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2158 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2159 $diffinfo->{'to_id'});
2160 print "</div>\n"; # class="diff_info"
2163 #print "<div class=\"diff extended_header\">\n";
2166 } # start of patch in patchset
2169 if ($in_header && $patch_line =~ m/^---/) {
2170 #print "</div>\n"; # class="diff extended_header"
2173 my $file = $diffinfo->{'from_file'};
2174 $file ||= $diffinfo->{'file'};
2175 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2176 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
2177 -class => "list"}, esc_html
($file));
2178 $patch_line =~ s
|a
/.*$|a/$file|g
;
2179 print "<div class=\"diff from_file\">$patch_line</div>\n";
2181 $patch_line = <$fd>;
2184 #$patch_line =~ m/^+++/;
2185 $file = $diffinfo->{'to_file'};
2186 $file ||= $diffinfo->{'file'};
2187 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2188 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
2189 -class => "list"}, esc_html
($file));
2190 $patch_line =~ s
|b
/.*|b/$file|g
;
2191 print "<div class=\"diff to_file\">$patch_line</div>\n";
2195 next LINE
if $in_header;
2197 print format_diff_line
($patch_line);
2199 print "</div>\n" if $patch_found; # class="patch"
2201 print "</div>\n"; # class="patchset"
2204 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2206 sub git_project_list_body
{
2207 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2209 my $check_forks = gitweb_check_feature
('forks');
2212 foreach my $pr (@$projlist) {
2213 my (@aa) = git_get_last_activity
($pr->{'path'});
2217 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2218 if (!defined $pr->{'descr'}) {
2219 my $descr = git_get_project_description
($pr->{'path'}) || "";
2220 $pr->{'descr'} = chop_str
($descr, 25, 5);
2222 if (!defined $pr->{'owner'}) {
2223 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2226 my $pname = $pr->{'path'};
2227 $pname =~ s/\.git$//;
2228 $pr->{'forks'} = -d
"$projectroot/$pname";
2230 push @projects, $pr;
2233 $order ||= "project";
2234 $from = 0 unless defined $from;
2235 $to = $#projects if (!defined $to || $#projects < $to);
2237 print "<table class=\"project_list\">\n";
2238 unless ($no_header) {
2241 print "<th></th>\n";
2243 if ($order eq "project") {
2244 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2245 print "<th>Project</th>\n";
2248 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2249 -class => "header"}, "Project") .
2252 if ($order eq "descr") {
2253 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2254 print "<th>Description</th>\n";
2257 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2258 -class => "header"}, "Description") .
2261 if ($order eq "owner") {
2262 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2263 print "<th>Owner</th>\n";
2266 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2267 -class => "header"}, "Owner") .
2270 if ($order eq "age") {
2271 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2272 print "<th>Last Change</th>\n";
2275 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2276 -class => "header"}, "Last Change") .
2279 print "<th></th>\n" .
2283 for (my $i = $from; $i <= $to; $i++) {
2284 my $pr = $projects[$i];
2286 print "<tr class=\"dark\">\n";
2288 print "<tr class=\"light\">\n";
2293 if ($pr->{'forks'}) {
2294 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2298 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2299 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2300 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2301 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2302 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2303 $pr->{'age_string'} . "</td>\n" .
2304 "<td class=\"link\">" .
2305 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2306 $cgi->a({-href
=> '/git-browser/by-commit.html?r='.$pr->{'path'}}, "graphiclog") . " | " .
2307 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2308 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2309 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
2313 if (defined $extra) {
2316 print "<td></td>\n";
2318 print "<td colspan=\"5\">$extra</td>\n" .
2324 sub git_shortlog_body
{
2325 # uses global variable $project
2326 my ($revlist, $from, $to, $refs, $extra) = @_;
2328 $from = 0 unless defined $from;
2329 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2331 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2333 for (my $i = $from; $i <= $to; $i++) {
2334 my $commit = $revlist->[$i];
2335 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2336 my $ref = format_ref_marker
($refs, $commit);
2337 my %co = parse_commit
($commit);
2339 print "<tr class=\"dark\">\n";
2341 print "<tr class=\"light\">\n";
2344 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2345 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2346 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2348 print format_subject_html
($co{'title'}, $co{'title_short'},
2349 href
(action
=>"commit", hash
=>$commit), $ref);
2351 "<td class=\"link\">" .
2352 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
2353 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2354 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2355 if (gitweb_have_snapshot
()) {
2356 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2361 if (defined $extra) {
2363 "<td colspan=\"4\">$extra</td>\n" .
2369 sub git_history_body
{
2370 # Warning: assumes constant type (blob or tree) during history
2371 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2373 $from = 0 unless defined $from;
2374 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2376 print "<table class=\"history\" cellspacing=\"0\">\n";
2378 for (my $i = $from; $i <= $to; $i++) {
2379 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2384 my %co = parse_commit
($commit);
2389 my $ref = format_ref_marker
($refs, $commit);
2392 print "<tr class=\"dark\">\n";
2394 print "<tr class=\"light\">\n";
2397 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2398 # shortlog uses chop_str($co{'author_name'}, 10)
2399 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2401 # originally git_history used chop_str($co{'title'}, 50)
2402 print format_subject_html
($co{'title'}, $co{'title_short'},
2403 href
(action
=>"commit", hash
=>$commit), $ref);
2405 "<td class=\"link\">" .
2406 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2407 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2409 if ($ftype eq 'blob') {
2410 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2411 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2412 if (defined $blob_current && defined $blob_parent &&
2413 $blob_current ne $blob_parent) {
2415 $cgi->a({-href
=> href
(action
=>"blobdiff",
2416 hash
=>$blob_current, hash_parent
=>$blob_parent,
2417 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2418 file_name
=>$file_name)},
2425 if (defined $extra) {
2427 "<td colspan=\"4\">$extra</td>\n" .
2434 # uses global variable $project
2435 my ($taglist, $from, $to, $extra) = @_;
2436 $from = 0 unless defined $from;
2437 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2439 print "<table class=\"tags\" cellspacing=\"0\">\n";
2441 for (my $i = $from; $i <= $to; $i++) {
2442 my $entry = $taglist->[$i];
2444 my $comment = $tag{'subject'};
2446 if (defined $comment) {
2447 $comment_short = chop_str
($comment, 30, 5);
2450 print "<tr class=\"dark\">\n";
2452 print "<tr class=\"light\">\n";
2455 print "<td><i>$tag{'age'}</i></td>\n" .
2457 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2458 -class => "list name"}, esc_html
($tag{'name'})) .
2461 if (defined $comment) {
2462 print format_subject_html
($comment, $comment_short,
2463 href
(action
=>"tag", hash
=>$tag{'id'}));
2466 "<td class=\"selflink\">";
2467 if ($tag{'type'} eq "tag") {
2468 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2473 "<td class=\"link\">" . " | " .
2474 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2475 if ($tag{'reftype'} eq "commit") {
2476 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2477 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
2478 } elsif ($tag{'reftype'} eq "blob") {
2479 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2484 if (defined $extra) {
2486 "<td colspan=\"5\">$extra</td>\n" .
2492 sub git_heads_body
{
2493 # uses global variable $project
2494 my ($headlist, $head, $from, $to, $extra) = @_;
2495 $from = 0 unless defined $from;
2496 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2498 print "<table class=\"heads\" cellspacing=\"0\">\n";
2500 for (my $i = $from; $i <= $to; $i++) {
2501 my $entry = $headlist->[$i];
2503 my $curr = $ref{'id'} eq $head;
2505 print "<tr class=\"dark\">\n";
2507 print "<tr class=\"light\">\n";
2510 print "<td><i>$ref{'age'}</i></td>\n" .
2511 ($curr ? "<td class=\"current_head\">" : "<td>") .
2512 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
2513 -class => "list name"},esc_html
($ref{'name'})) .
2515 "<td class=\"link\">" .
2516 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
2517 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
2518 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
2522 if (defined $extra) {
2524 "<td colspan=\"3\">$extra</td>\n" .
2530 ## ======================================================================
2531 ## ======================================================================
2534 sub git_project_list
{
2535 my $order = $cgi->param('o');
2536 if (defined $order && $order !~ m/project|descr|owner|age/) {
2537 die_error
(undef, "Unknown order parameter");
2540 my @list = git_get_projects_list
();
2542 die_error
(undef, "No projects found");
2546 if (-f
$home_text) {
2547 print "<div class=\"index_include\">\n";
2548 open (my $fd, $home_text);
2553 git_project_list_body
(\
@list, $order);
2558 my $order = $cgi->param('o');
2559 if (defined $order && $order !~ m/project|descr|owner|age/) {
2560 die_error
(undef, "Unknown order parameter");
2563 my @list = git_get_projects_list
($project);
2565 die_error
(undef, "No forks found");
2569 git_print_page_nav
('','');
2570 git_print_header_div
('summary', "$project forks");
2571 git_project_list_body
(\
@list, $order);
2575 sub git_project_index
{
2576 my @projects = git_get_projects_list
($project);
2579 -type
=> 'text/plain',
2580 -charset
=> 'utf-8',
2581 -content_disposition
=> 'inline; filename="index.aux"');
2583 foreach my $pr (@projects) {
2584 if (!exists $pr->{'owner'}) {
2585 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2588 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2589 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2590 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2591 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2595 print "$path $owner\n";
2600 my $descr = git_get_project_description
($project) || "none";
2601 my $head = git_get_head_hash
($project);
2602 my %co = parse_commit
($head);
2603 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2605 my $owner = git_get_project_owner
($project);
2607 my $refs = git_get_references
();
2608 my @taglist = git_get_tags_list
(15);
2609 my @headlist = git_get_heads_list
(15);
2611 if (gitweb_check_feature
('forks')) {
2612 @forklist = git_get_projects_list
($project);
2616 git_print_page_nav
('summary','', $head);
2618 print "<div class=\"title\"> </div>\n";
2619 print "<table cellspacing=\"0\">\n" .
2620 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2621 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2622 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2623 # use per project git URL list in $projectroot/$project/cloneurl
2624 # or make project git URL from git base URL and project name
2625 my $url_tag = "URL";
2626 my @url_list = git_get_project_url_list
($project);
2627 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2628 foreach my $git_url (@url_list) {
2629 next unless $git_url;
2630 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2635 if (-s
"$projectroot/$project/README.html") {
2636 if (open my $fd, "$projectroot/$project/README.html") {
2637 print "<div class=\"title\">readme</div>\n";
2638 print $_ while (<$fd>);
2643 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2644 git_get_head_hash
($project), "--"
2645 or die_error
(undef, "Open git-rev-list failed");
2646 my @revlist = map { chomp; $_ } <$fd>;
2648 git_print_header_div
('shortlog');
2649 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2650 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2653 git_print_header_div
('tags');
2654 git_tags_body
(\
@taglist, 0, 15,
2655 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2659 git_print_header_div
('heads');
2660 git_heads_body
(\
@headlist, $head, 0, 15,
2661 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2665 git_print_header_div
('forks');
2666 git_project_list_body
(\
@forklist, undef, 0, 15,
2667 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
2675 my $head = git_get_head_hash
($project);
2677 git_print_page_nav
('','', $head,undef,$head);
2678 my %tag = parse_tag
($hash);
2679 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2680 print "<div class=\"title_text\">\n" .
2681 "<table cellspacing=\"0\">\n" .
2683 "<td>object</td>\n" .
2684 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2685 $tag{'object'}) . "</td>\n" .
2686 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2687 $tag{'type'}) . "</td>\n" .
2689 if (defined($tag{'author'})) {
2690 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2691 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2692 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2693 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2696 print "</table>\n\n" .
2698 print "<div class=\"page_body\">";
2699 my $comment = $tag{'comment'};
2700 foreach my $line (@$comment) {
2701 print esc_html
($line) . "<br/>\n";
2711 my ($have_blame) = gitweb_check_feature
('blame');
2713 die_error
('403 Permission denied', "Permission denied");
2715 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2716 $hash_base ||= git_get_head_hash
($project);
2717 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2718 my %co = parse_commit
($hash_base)
2719 or die_error
(undef, "Reading commit failed");
2720 if (!defined $hash) {
2721 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2722 or die_error
(undef, "Error looking up file");
2724 $ftype = git_get_type
($hash);
2725 if ($ftype !~ "blob") {
2726 die_error
("400 Bad Request", "Object is not a blob");
2728 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
2729 $file_name, $hash_base)
2730 or die_error
(undef, "Open git-blame failed");
2733 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2736 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2739 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2741 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2742 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2743 git_print_page_path
($file_name, $ftype, $hash_base);
2744 my @rev_color = (qw(light2 dark2));
2745 my $num_colors = scalar(@rev_color);
2746 my $current_color = 0;
2749 <div class="page_body">
2750 <table class="blame">
2751 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2756 last unless defined $_;
2757 my ($full_rev, $orig_lineno, $lineno, $group_size) =
2758 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
2759 if (!exists $metainfo{$full_rev}) {
2760 $metainfo{$full_rev} = {};
2762 my $meta = $metainfo{$full_rev};
2765 if (/^(\S+) (.*)$/) {
2770 my $rev = substr($full_rev, 0, 8);
2771 my $author = $meta->{'author'};
2772 my %date = parse_date
($meta->{'author-time'},
2773 $meta->{'author-tz'});
2774 my $date = $date{'iso-tz'};
2776 $current_color = ++$current_color % $num_colors;
2778 print "<tr class=\"$rev_color[$current_color]\">\n";
2780 print "<td class=\"sha1\"";
2781 print " title=\"". esc_html
($author) . ", $date\"";
2782 print " rowspan=\"$group_size\"" if ($group_size > 1);
2784 print $cgi->a({-href
=> href
(action
=>"commit",
2786 file_name
=>$file_name)},
2790 my $blamed = href
(action
=> 'blame',
2791 file_name
=> $meta->{'filename'},
2792 hash_base
=> $full_rev);
2793 print "<td class=\"linenr\">";
2794 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
2796 -class => "linenr" },
2799 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2805 or print "Reading blob failed\n";
2812 my ($have_blame) = gitweb_check_feature
('blame');
2814 die_error
('403 Permission denied', "Permission denied");
2816 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2817 $hash_base ||= git_get_head_hash
($project);
2818 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2819 my %co = parse_commit
($hash_base)
2820 or die_error
(undef, "Reading commit failed");
2821 if (!defined $hash) {
2822 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2823 or die_error
(undef, "Error lookup file");
2825 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2826 or die_error
(undef, "Open git-annotate failed");
2829 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2832 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2835 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2837 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2838 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2839 git_print_page_path
($file_name, 'blob', $hash_base);
2840 print "<div class=\"page_body\">\n";
2842 <table class="blame">
2851 my @line_class = (qw(light dark));
2852 my $line_class_len = scalar (@line_class);
2853 my $line_class_num = $#line_class;
2854 while (my $line = <$fd>) {
2866 $line_class_num = ($line_class_num + 1) % $line_class_len;
2868 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2875 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
2878 $short_rev = substr ($long_rev, 0, 8);
2879 $age = time () - $time;
2880 $age_str = age_string
($age);
2881 $age_str =~ s/ / /g;
2882 $age_class = age_class
($age);
2883 $author = esc_html
($author);
2884 $author =~ s/ / /g;
2886 $data = untabify
($data);
2887 $data = esc_html
($data);
2890 <tr class="$line_class[$line_class_num]">
2891 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2892 <td class="$age_class">$age_str</td>
2894 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2895 <td class="pre">$data</td>
2898 } # while (my $line = <$fd>)
2899 print "</table>\n\n";
2901 or print "Reading blob failed.\n";
2907 my $head = git_get_head_hash
($project);
2909 git_print_page_nav
('','', $head,undef,$head);
2910 git_print_header_div
('summary', $project);
2912 my @tagslist = git_get_tags_list
();
2914 git_tags_body
(\
@tagslist);
2920 my $head = git_get_head_hash
($project);
2922 git_print_page_nav
('','', $head,undef,$head);
2923 git_print_header_div
('summary', $project);
2925 my @headslist = git_get_heads_list
();
2927 git_heads_body
(\
@headslist, $head);
2932 sub git_blob_plain
{
2935 if (!defined $hash) {
2936 if (defined $file_name) {
2937 my $base = $hash_base || git_get_head_hash
($project);
2938 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2939 or die_error
(undef, "Error lookup file");
2941 die_error
(undef, "No file name defined");
2943 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2944 # blobs defined by non-textual hash id's can be cached
2949 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2950 or die_error
(undef, "Couldn't cat $file_name, $hash");
2952 $type ||= blob_mimetype
($fd, $file_name);
2954 # save as filename, even when no $file_name is given
2955 my $save_as = "$hash";
2956 if (defined $file_name) {
2957 $save_as = $file_name;
2958 } elsif ($type =~ m/^text\//) {
2965 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
2967 binmode STDOUT
, ':raw';
2969 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2977 if (!defined $hash) {
2978 if (defined $file_name) {
2979 my $base = $hash_base || git_get_head_hash
($project);
2980 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2981 or die_error
(undef, "Error lookup file");
2983 die_error
(undef, "No file name defined");
2985 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2986 # blobs defined by non-textual hash id's can be cached
2990 my ($have_blame) = gitweb_check_feature
('blame');
2991 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2992 or die_error
(undef, "Couldn't cat $file_name, $hash");
2993 my $mimetype = blob_mimetype
($fd, $file_name);
2994 if ($mimetype !~ m/^text\//) {
2996 return git_blob_plain
($mimetype);
2998 git_header_html
(undef, $expires);
2999 my $formats_nav = '';
3000 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3001 if (defined $file_name) {
3004 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3005 hash
=>$hash, file_name
=>$file_name)},
3010 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3011 hash
=>$hash, file_name
=>$file_name)},
3014 $cgi->a({-href
=> href
(action
=>"blob_plain",
3015 hash
=>$hash, file_name
=>$file_name)},
3018 $cgi->a({-href
=> href
(action
=>"blob",
3019 hash_base
=>"HEAD", file_name
=>$file_name)},
3023 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3025 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3026 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3028 print "<div class=\"page_nav\">\n" .
3029 "<br/><br/></div>\n" .
3030 "<div class=\"title\">$hash</div>\n";
3032 git_print_page_path
($file_name, "blob", $hash_base);
3033 print "<div class=\"page_body\">\n";
3035 while (my $line = <$fd>) {
3038 $line = untabify
($line);
3039 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3040 $nr, $nr, $nr, esc_html
($line);
3043 or print "Reading blob failed.\n";
3049 my $have_snapshot = gitweb_have_snapshot
();
3051 if (!defined $hash_base) {
3052 $hash_base = "HEAD";
3054 if (!defined $hash) {
3055 if (defined $file_name) {
3056 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3062 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3063 or die_error
(undef, "Open git-ls-tree failed");
3064 my @entries = map { chomp; $_ } <$fd>;
3065 close $fd or die_error
(undef, "Reading tree failed");
3068 my $refs = git_get_references
();
3069 my $ref = format_ref_marker
($refs, $hash_base);
3072 my ($have_blame) = gitweb_check_feature
('blame');
3073 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3075 if (defined $file_name) {
3077 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3078 hash
=>$hash, file_name
=>$file_name)},
3080 $cgi->a({-href
=> href
(action
=>"tree",
3081 hash_base
=>"HEAD", file_name
=>$file_name)},
3084 if ($have_snapshot) {
3085 # FIXME: Should be available when we have no hash base as well.
3087 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3090 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3091 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3094 print "<div class=\"page_nav\">\n";
3095 print "<br/><br/></div>\n";
3096 print "<div class=\"title\">$hash</div>\n";
3098 if (defined $file_name) {
3099 $basedir = $file_name;
3100 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3104 git_print_page_path
($file_name, 'tree', $hash_base);
3105 print "<div class=\"page_body\">\n";
3106 print "<table cellspacing=\"0\">\n";
3108 # '..' (top directory) link if possible
3109 if (defined $hash_base &&
3110 defined $file_name && $file_name =~ m![^/]+$!) {
3112 print "<tr class=\"dark\">\n";
3114 print "<tr class=\"light\">\n";
3118 my $up = $file_name;
3119 $up =~ s!/?[^/]+$!!;
3120 undef $up unless $up;
3121 # based on git_print_tree_entry
3122 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3123 print '<td class="list">';
3124 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3128 print "<td class=\"link\"></td>\n";
3132 foreach my $line (@entries) {
3133 my %t = parse_ls_tree_line
($line, -z
=> 1);
3136 print "<tr class=\"dark\">\n";
3138 print "<tr class=\"light\">\n";
3142 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3146 print "</table>\n" .
3152 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3153 my $have_snapshot = (defined $ctype && defined $suffix);
3154 if (!$have_snapshot) {
3155 die_error
('403 Permission denied', "Permission denied");
3158 if (!defined $hash) {
3159 $hash = git_get_head_hash
($project);
3162 my $filename = basename
($project) . "-$hash.tar.$suffix";
3165 -type
=> 'application/x-tar',
3166 -content_encoding
=> $ctype,
3167 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3168 -status
=> '200 OK');
3170 my $git = git_cmd_str
();
3171 my $name = $project;
3172 $name =~ s/\047/\047\\\047\047/g;
3174 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3175 or die_error
(undef, "Execute git-tar-tree failed.");
3176 binmode STDOUT
, ':raw';
3178 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3184 my $head = git_get_head_hash
($project);
3185 if (!defined $hash) {
3188 if (!defined $page) {
3191 my $refs = git_get_references
();
3193 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3194 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash, "--"
3195 or die_error
(undef, "Open git-rev-list failed");
3196 my @revlist = map { chomp; $_ } <$fd>;
3199 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
3202 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3205 my %co = parse_commit
($hash);
3207 git_print_header_div
('summary', $project);
3208 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3210 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
3211 my $commit = $revlist[$i];
3212 my $ref = format_ref_marker
($refs, $commit);
3213 my %co = parse_commit
($commit);
3215 my %ad = parse_date
($co{'author_epoch'});
3216 git_print_header_div
('commit',
3217 "<span class=\"age\">$co{'age_string'}</span>" .
3218 esc_html
($co{'title'}) . $ref,
3220 print "<div class=\"title_text\">\n" .
3221 "<div class=\"log_link\">\n" .
3222 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3224 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3226 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3229 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3232 print "<div class=\"log_body\">\n";
3233 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
3240 my %co = parse_commit
($hash);
3242 die_error
(undef, "Unknown commit object");
3244 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3245 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3247 my $parent = $co{'parent'};
3248 if (!defined $parent) {
3251 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
3252 @diff_opts, $parent, $hash, "--"
3253 or die_error
(undef, "Open git-diff-tree failed");
3254 my @difftree = map { chomp; $_ } <$fd>;
3255 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3257 # non-textual hash id's can be cached
3259 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3262 my $refs = git_get_references
();
3263 my $ref = format_ref_marker
($refs, $co{'id'});
3265 my $have_snapshot = gitweb_have_snapshot
();
3268 if (defined $file_name && defined $co{'parent'}) {
3270 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
3273 git_header_html
(undef, $expires);
3274 git_print_page_nav
('commit', '',
3275 $hash, $co{'tree'}, $hash,
3276 join (' | ', @views_nav));
3278 if (defined $co{'parent'}) {
3279 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3281 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3283 print "<div class=\"title_text\">\n" .
3284 "<table cellspacing=\"0\">\n";
3285 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3287 "<td></td><td> $ad{'rfc2822'}";
3288 if ($ad{'hour_local'} < 6) {
3289 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3290 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3292 printf(" (%02d:%02d %s)",
3293 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3297 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3298 print "<tr><td></td><td> $cd{'rfc2822'}" .
3299 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3301 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3304 "<td class=\"sha1\">" .
3305 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3306 class => "list"}, $co{'tree'}) .
3308 "<td class=\"link\">" .
3309 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3311 if ($have_snapshot) {
3313 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3317 my $parents = $co{'parents'};
3318 foreach my $par (@$parents) {
3321 "<td class=\"sha1\">" .
3322 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3323 class => "list"}, $par) .
3325 "<td class=\"link\">" .
3326 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3328 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3335 print "<div class=\"page_body\">\n";
3336 git_print_log
($co{'comment'});
3339 git_difftree_body
(\
@difftree, $hash, $parent);
3345 my $format = shift || 'html';
3352 # preparing $fd and %diffinfo for git_patchset_body
3354 if (defined $hash_base && defined $hash_parent_base) {
3355 if (defined $file_name) {
3357 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3358 $hash_parent_base, $hash_base,
3360 or die_error
(undef, "Open git-diff-tree failed");
3361 @difftree = map { chomp; $_ } <$fd>;
3363 or die_error
(undef, "Reading git-diff-tree failed");
3365 or die_error
('404 Not Found', "Blob diff not found");
3367 } elsif (defined $hash &&
3368 $hash =~ /[0-9a-fA-F]{40}/) {
3369 # try to find filename from $hash
3371 # read filtered raw output
3372 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3373 $hash_parent_base, $hash_base, "--"
3374 or die_error
(undef, "Open git-diff-tree failed");
3376 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3378 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3379 map { chomp; $_ } <$fd>;
3381 or die_error
(undef, "Reading git-diff-tree failed");
3383 or die_error
('404 Not Found', "Blob diff not found");
3386 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3389 if (@difftree > 1) {
3390 die_error
('404 Not Found', "Ambiguous blob diff specification");
3393 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3394 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3395 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3397 $hash_parent ||= $diffinfo{'from_id'};
3398 $hash ||= $diffinfo{'to_id'};
3400 # non-textual hash id's can be cached
3401 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3402 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3407 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3408 '-p', $hash_parent_base, $hash_base,
3410 or die_error
(undef, "Open git-diff-tree failed");
3413 # old/legacy style URI
3414 if (!%diffinfo && # if new style URI failed
3415 defined $hash && defined $hash_parent) {
3416 # fake git-diff-tree raw output
3417 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3418 $diffinfo{'from_id'} = $hash_parent;
3419 $diffinfo{'to_id'} = $hash;
3420 if (defined $file_name) {
3421 if (defined $file_parent) {
3422 $diffinfo{'status'} = '2';
3423 $diffinfo{'from_file'} = $file_parent;
3424 $diffinfo{'to_file'} = $file_name;
3425 } else { # assume not renamed
3426 $diffinfo{'status'} = '1';
3427 $diffinfo{'from_file'} = $file_name;
3428 $diffinfo{'to_file'} = $file_name;
3430 } else { # no filename given
3431 $diffinfo{'status'} = '2';
3432 $diffinfo{'from_file'} = $hash_parent;
3433 $diffinfo{'to_file'} = $hash;
3436 # non-textual hash id's can be cached
3437 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3438 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3443 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts,
3444 $hash_parent, $hash, "--"
3445 or die_error
(undef, "Open git-diff failed");
3447 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3452 if ($format eq 'html') {
3454 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3455 hash
=>$hash, hash_parent
=>$hash_parent,
3456 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3457 file_name
=>$file_name, file_parent
=>$file_parent)},
3459 git_header_html
(undef, $expires);
3460 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3461 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3462 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3464 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3465 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3467 if (defined $file_name) {
3468 git_print_page_path
($file_name, "blob", $hash_base);
3470 print "<div class=\"page_path\"></div>\n";
3473 } elsif ($format eq 'plain') {
3475 -type
=> 'text/plain',
3476 -charset
=> 'utf-8',
3477 -expires
=> $expires,
3478 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3480 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3483 die_error
(undef, "Unknown blobdiff format");
3487 if ($format eq 'html') {
3488 print "<div class=\"page_body\">\n";
3490 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3493 print "</div>\n"; # class="page_body"
3497 while (my $line = <$fd>) {
3498 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_html($diffinfo{'from_file'})!eg;
3499 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_html($diffinfo{'to_file'})!eg;
3503 last if $line =~ m!^\+\+\+!;
3511 sub git_blobdiff_plain
{
3512 git_blobdiff
('plain');
3515 sub git_commitdiff
{
3516 my $format = shift || 'html';
3517 my %co = parse_commit
($hash);
3519 die_error
(undef, "Unknown commit object");
3522 # we need to prepare $formats_nav before any parameter munging
3524 if ($format eq 'html') {
3526 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3527 hash
=>$hash, hash_parent
=>$hash_parent)},
3530 if (defined $hash_parent) {
3531 # commitdiff with two commits given
3532 my $hash_parent_short = $hash_parent;
3533 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3534 $hash_parent_short = substr($hash_parent, 0, 7);
3538 $cgi->a({-href
=> href
(action
=>"commitdiff",
3539 hash
=>$hash_parent)},
3540 esc_html
($hash_parent_short)) .
3542 } elsif (!$co{'parent'}) {
3544 $formats_nav .= ' (initial)';
3545 } elsif (scalar @{$co{'parents'}} == 1) {
3546 # single parent commit
3549 $cgi->a({-href
=> href
(action
=>"commitdiff",
3550 hash
=>$co{'parent'})},
3551 esc_html
(substr($co{'parent'}, 0, 7))) .
3558 $cgi->a({-href
=> href
(action
=>"commitdiff",
3560 esc_html
(substr($_, 0, 7)));
3561 } @{$co{'parents'}} ) .
3566 if (!defined $hash_parent) {
3567 $hash_parent = $co{'parent'} || '--root';
3573 if ($format eq 'html') {
3574 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3575 "--no-commit-id", "--patch-with-raw", "--full-index",
3576 $hash_parent, $hash, "--"
3577 or die_error
(undef, "Open git-diff-tree failed");
3579 while (chomp(my $line = <$fd>)) {
3580 # empty line ends raw part of diff-tree output
3582 push @difftree, $line;
3585 } elsif ($format eq 'plain') {
3586 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3587 '-p', $hash_parent, $hash, "--"
3588 or die_error
(undef, "Open git-diff-tree failed");
3591 die_error
(undef, "Unknown commitdiff format");
3594 # non-textual hash id's can be cached
3596 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3600 # write commit message
3601 if ($format eq 'html') {
3602 my $refs = git_get_references
();
3603 my $ref = format_ref_marker
($refs, $co{'id'});
3605 git_header_html
(undef, $expires);
3606 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3607 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3608 git_print_authorship
(\
%co);
3609 print "<div class=\"page_body\">\n";
3610 if (@{$co{'comment'}} > 1) {
3611 print "<div class=\"log\">\n";
3612 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
3613 print "</div>\n"; # class="log"
3616 } elsif ($format eq 'plain') {
3617 my $refs = git_get_references
("tags");
3618 my $tagname = git_get_rev_name_tags
($hash);
3619 my $filename = basename
($project) . "-$hash.patch";
3622 -type
=> 'text/plain',
3623 -charset
=> 'utf-8',
3624 -expires
=> $expires,
3625 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3626 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3629 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3630 Subject: $co{'title'}
3632 print "X-Git-Tag: $tagname\n" if $tagname;
3633 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3635 foreach my $line (@{$co{'comment'}}) {
3642 if ($format eq 'html') {
3643 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3646 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3648 print "</div>\n"; # class="page_body"
3651 } elsif ($format eq 'plain') {
3655 or print "Reading git-diff-tree failed\n";
3659 sub git_commitdiff_plain
{
3660 git_commitdiff
('plain');
3664 if (!defined $hash_base) {
3665 $hash_base = git_get_head_hash
($project);
3667 if (!defined $page) {
3671 my %co = parse_commit
($hash_base);
3673 die_error
(undef, "Unknown commit object");
3676 my $refs = git_get_references
();
3677 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3679 if (!defined $hash && defined $file_name) {
3680 $hash = git_get_hash_by_path
($hash_base, $file_name);
3682 if (defined $hash) {
3683 $ftype = git_get_type
($hash);
3687 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3688 or die_error
(undef, "Open git-rev-list-failed");
3689 my @revlist = map { chomp; $_ } <$fd>;
3691 or die_error
(undef, "Reading git-rev-list failed");
3693 my $paging_nav = '';
3696 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3697 file_name
=>$file_name)},
3699 $paging_nav .= " ⋅ " .
3700 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3701 file_name
=>$file_name, page
=>$page-1),
3702 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3704 $paging_nav .= "first";
3705 $paging_nav .= " ⋅ prev";
3707 if ($#revlist >= (100 * ($page+1)-1)) {
3708 $paging_nav .= " ⋅ " .
3709 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3710 file_name
=>$file_name, page
=>$page+1),
3711 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3713 $paging_nav .= " ⋅ next";
3716 if ($#revlist >= (100 * ($page+1)-1)) {
3718 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3719 file_name
=>$file_name, page
=>$page+1),
3720 -title
=> "Alt-n"}, "next");
3724 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3725 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3726 git_print_page_path
($file_name, $ftype, $hash_base);
3728 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3729 $refs, $hash_base, $ftype, $next_link);
3735 if (!defined $searchtext) {
3736 die_error
(undef, "Text field empty");
3738 if (!defined $hash) {
3739 $hash = git_get_head_hash
($project);
3741 my %co = parse_commit
($hash);
3743 die_error
(undef, "Unknown commit object");
3746 $searchtype ||= 'commit';
3747 if ($searchtype eq 'pickaxe') {
3748 # pickaxe may take all resources of your box and run for several minutes
3749 # with every query - so decide by yourself how public you make this feature
3750 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3751 if (!$have_pickaxe) {
3752 die_error
('403 Permission denied', "Permission denied");
3757 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3758 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3760 print "<table cellspacing=\"0\">\n";
3762 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
3764 open my $fd, "-|", git_cmd
(), "rev-list",
3765 "--header", "--parents", $hash, "--"
3767 while (my $commit_text = <$fd>) {
3768 if (!grep m/$searchtext/i, $commit_text) {
3771 if ($searchtype eq 'author' && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3774 if ($searchtype eq 'committer' && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3777 my @commit_lines = split "\n", $commit_text;
3778 my %co = parse_commit
(undef, \
@commit_lines);
3783 print "<tr class=\"dark\">\n";
3785 print "<tr class=\"light\">\n";
3788 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3789 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3791 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3792 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3793 my $comment = $co{'comment'};
3794 foreach my $line (@$comment) {
3795 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3796 my $lead = esc_html
($1) || "";
3797 $lead = chop_str
($lead, 30, 10);
3798 my $match = esc_html
($2) || "";
3799 my $trail = esc_html
($3) || "";
3800 $trail = chop_str
($trail, 30, 10);
3801 my $text = "$lead<span class=\"match\">$match</span>$trail";
3802 print chop_str
($text, 80, 5) . "<br/>\n";
3806 "<td class=\"link\">" .
3807 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3809 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3816 if ($searchtype eq 'pickaxe') {
3818 my $git_command = git_cmd_str
();
3819 open my $fd, "-|", "$git_command rev-list $hash | " .
3820 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3823 while (my $line = <$fd>) {
3824 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3827 $set{'from_id'} = $3;
3829 $set{'id'} = $set{'to_id'};
3830 if ($set{'id'} =~ m/0{40}/) {
3831 $set{'id'} = $set{'from_id'};
3833 if ($set{'id'} =~ m/0{40}/) {
3837 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3840 print "<tr class=\"dark\">\n";
3842 print "<tr class=\"light\">\n";
3845 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3846 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3848 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3849 -class => "list subject"},
3850 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3851 while (my $setref = shift @files) {
3853 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3854 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3856 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3860 "<td class=\"link\">" .
3861 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3863 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3867 %co = parse_commit
($1);
3876 sub git_search_help
{
3878 git_print_page_nav
('','', $hash,$hash,$hash);
3881 <dt><b>commit</b></dt>
3882 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
3883 <dt><b>author</b></dt>
3884 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
3885 <dt><b>committer</b></dt>
3886 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
3888 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3889 if ($have_pickaxe) {
3891 <dt><b>pickaxe</b></dt>
3892 <dd>All commits that caused the string to appear or disappear from any file (changes that
3893 added, removed or "modified" the string) will be listed. This search can take a while and
3894 takes a lot of strain on the server, so please use it wisely.</dd>
3902 my $head = git_get_head_hash
($project);
3903 if (!defined $hash) {
3906 if (!defined $page) {
3909 my $refs = git_get_references
();
3911 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3912 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash, "--"
3913 or die_error
(undef, "Open git-rev-list failed");
3914 my @revlist = map { chomp; $_ } <$fd>;
3917 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3919 if ($#revlist >= (100 * ($page+1)-1)) {
3921 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3922 -title
=> "Alt-n"}, "next");
3927 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3928 git_print_header_div
('summary', $project);
3930 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3935 ## ......................................................................
3936 ## feeds (RSS, OPML)
3939 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3940 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150",
3941 git_get_head_hash
($project), "--"
3942 or die_error
(undef, "Open git-rev-list failed");
3943 my @revlist = map { chomp; $_ } <$fd>;
3944 close $fd or die_error
(undef, "Reading git-rev-list failed");
3945 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3947 <?xml version="1.0" encoding="utf-8"?>
3948 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3950 <title>$project $my_uri $my_url</title>
3951 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3952 <description>$project log</description>
3953 <language>en</language>
3956 for (my $i = 0; $i <= $#revlist; $i++) {
3957 my $commit = $revlist[$i];
3958 my %co = parse_commit
($commit);
3959 # we read 150, we always show 30 and the ones more recent than 48 hours
3960 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3963 my %cd = parse_date
($co{'committer_epoch'});
3964 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3965 $co{'parent'}, $co{'id'}, "--"
3967 my @difftree = map { chomp; $_ } <$fd>;
3972 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3974 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3975 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3976 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3977 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3978 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3979 "<content:encoded>" .
3981 my $comment = $co{'comment'};
3982 foreach my $line (@$comment) {
3983 $line = to_utf8
($line);
3984 print "$line<br/>\n";
3987 foreach my $line (@difftree) {
3988 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3991 my $file = esc_html
(unquote
($7));
3992 $file = to_utf8
($file);
3993 print "$file<br/>\n";
3996 "</content:encoded>\n" .
3999 print "</channel></rss>";
4003 my @list = git_get_projects_list
();
4005 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
4007 <?xml version="1.0" encoding="utf-8"?>
4008 <opml version="1.0">
4010 <title>$site_name OPML Export</title>
4013 <outline text="git RSS feeds">
4016 foreach my $pr (@list) {
4018 my $head = git_get_head_hash
($proj{'path'});
4019 if (!defined $head) {
4022 $git_dir = "$projectroot/$proj{'path'}";
4023 my %co = parse_commit
($head);
4028 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
4029 my $rss = "$my_url?p=$proj{'path'};a=rss";
4030 my $html = "$my_url?p=$proj{'path'};a=summary";
4031 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";