3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 our $version = "++GIT_VERSION++";
23 our $my_url = $cgi->url();
24 our $my_uri = $cgi->url(-absolute
=> 1);
26 # core git executable to use
27 # this can just be "git" if your webserver has a sensible PATH
28 our $GIT = "++GIT_BINDIR++/git";
30 # absolute fs-path which will be prepended to the project path
31 #our $projectroot = "/pub/scm";
32 our $projectroot = "++GITWEB_PROJECTROOT++";
34 # target of the home link on top of all pages
35 our $home_link = $my_uri || "/";
37 # string of the home link on top of all pages
38 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
40 # name of your site or organization to appear in page titles
41 # replace this with something more descriptive for clearer bookmarks
42 our $site_name = "++GITWEB_SITENAME++"
43 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
45 # filename of html text to include at top of each page
46 our $site_header = "++GITWEB_SITE_HEADER++";
47 # html text to include at home page
48 our $home_text = "++GITWEB_HOMETEXT++";
49 # filename of html text to include at bottom of each page
50 our $site_footer = "++GITWEB_SITE_FOOTER++";
53 our @stylesheets = ("++GITWEB_CSS++");
54 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
55 our $stylesheet = undef;
57 # URI of GIT logo (72x27 size)
58 our $logo = "++GITWEB_LOGO++";
59 # URI of GIT favicon, assumed to be image/png type
60 our $favicon = "++GITWEB_FAVICON++";
62 # URI and label (title) of GIT logo link
63 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
64 #our $logo_label = "git documentation";
65 our $logo_url = "http://git.or.cz/";
66 our $logo_label = "git homepage";
68 # source of projects list
69 our $projects_list = "++GITWEB_LIST++";
71 # show repository only if this file exists
72 # (only effective if this variable evaluates to true)
73 our $export_ok = "++GITWEB_EXPORT_OK++";
75 # only allow viewing of repositories also shown on the overview page
76 our $strict_export = "++GITWEB_STRICT_EXPORT++";
78 # list of git base URLs used for URL to where fetch project from,
79 # i.e. full URL is "$git_base_url/$project"
80 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
82 # default blob_plain mimetype and default charset for text/plain blob
83 our $default_blob_plain_mimetype = 'text/plain';
84 our $default_text_plain_charset = undef;
86 # file to use for guessing MIME types before trying /etc/mime.types
87 # (relative to the current git repository)
88 our $mimetypes_file = undef;
90 # You define site-wide feature defaults here; override them with
91 # $GITWEB_CONFIG as necessary.
94 # 'sub' => feature-sub (subroutine),
95 # 'override' => allow-override (boolean),
96 # 'default' => [ default options...] (array reference)}
98 # if feature is overridable (it means that allow-override has true value,
99 # then feature-sub will be called with default options as parameters;
100 # return value of feature-sub indicates if to enable specified feature
102 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
104 # Enable the 'blame' blob view, showing the last commit that modified
105 # each line in the file. This can be very CPU-intensive.
107 # To enable system wide have in $GITWEB_CONFIG
108 # $feature{'blame'}{'default'} = [1];
109 # To have project specific config enable override in $GITWEB_CONFIG
110 # $feature{'blame'}{'override'} = 1;
111 # and in project config gitweb.blame = 0|1;
113 'sub' => \
&feature_blame
,
117 # Enable the 'snapshot' link, providing a compressed tarball of any
118 # tree. This can potentially generate high traffic if you have large
121 # To disable system wide have in $GITWEB_CONFIG
122 # $feature{'snapshot'}{'default'} = [undef];
123 # To have project specific config enable override in $GITWEB_CONFIG
124 # $feature{'blame'}{'override'} = 1;
125 # and in project config gitweb.snapshot = none|gzip|bzip2;
127 'sub' => \
&feature_snapshot
,
129 # => [content-encoding, suffix, program]
130 'default' => ['x-gzip', 'gz', 'gzip']},
132 # Enable the pickaxe search, which will list the commits that modified
133 # a given string in a file. This can be practical and quite faster
134 # alternative to 'blame', but still potentially CPU-intensive.
136 # To enable system wide have in $GITWEB_CONFIG
137 # $feature{'pickaxe'}{'default'} = [1];
138 # To have project specific config enable override in $GITWEB_CONFIG
139 # $feature{'pickaxe'}{'override'} = 1;
140 # and in project config gitweb.pickaxe = 0|1;
142 'sub' => \
&feature_pickaxe
,
146 # Make gitweb use an alternative format of the URLs which can be
147 # more readable and natural-looking: project name is embedded
148 # directly in the path and the query string contains other
149 # auxiliary information. All gitweb installations recognize
150 # URL in either format; this configures in which formats gitweb
153 # To enable system wide have in $GITWEB_CONFIG
154 # $feature{'pathinfo'}{'default'} = [1];
155 # Project specific override is not supported.
157 # Note that you will need to change the default location of CSS,
158 # favicon, logo and possibly other files to an absolute URL. Also,
159 # if gitweb.cgi serves as your indexfile, you will need to force
160 # $my_uri to contain the script name in your $GITWEB_CONFIG.
165 # Make gitweb consider projects in project root subdirectories
166 # to be forks of existing projects. Given project $projname.git,
167 # projects matching $projname/*.git will not be shown in the main
168 # projects list, instead a '+' mark will be added to $projname
169 # there and a 'forks' view will be enabled for the project, listing
170 # all the forks. This feature is supported only if project list
171 # is taken from a directory, not file.
173 # To enable system wide have in $GITWEB_CONFIG
174 # $feature{'forks'}{'default'} = [1];
175 # Project specific override is not supported.
181 sub gitweb_check_feature
{
183 return unless exists $feature{$name};
184 my ($sub, $override, @defaults) = (
185 $feature{$name}{'sub'},
186 $feature{$name}{'override'},
187 @{$feature{$name}{'default'}});
188 if (!$override) { return @defaults; }
190 warn "feature $name is not overrideable";
193 return $sub->(@defaults);
197 my ($val) = git_get_project_config
('blame', '--bool');
199 if ($val eq 'true') {
201 } elsif ($val eq 'false') {
208 sub feature_snapshot
{
209 my ($ctype, $suffix, $command) = @_;
211 my ($val) = git_get_project_config
('snapshot');
213 if ($val eq 'gzip') {
214 return ('x-gzip', 'gz', 'gzip');
215 } elsif ($val eq 'bzip2') {
216 return ('x-bzip2', 'bz2', 'bzip2');
217 } elsif ($val eq 'none') {
221 return ($ctype, $suffix, $command);
224 sub gitweb_have_snapshot
{
225 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
226 my $have_snapshot = (defined $ctype && defined $suffix);
228 return $have_snapshot;
231 sub feature_pickaxe
{
232 my ($val) = git_get_project_config
('pickaxe', '--bool');
234 if ($val eq 'true') {
236 } elsif ($val eq 'false') {
243 # checking HEAD file with -e is fragile if the repository was
244 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
246 sub check_head_link
{
248 my $headfile = "$dir/HEAD";
249 return ((-e
$headfile) ||
250 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
253 sub check_export_ok
{
255 return (check_head_link
($dir) &&
256 (!$export_ok || -e
"$dir/$export_ok"));
259 # rename detection options for git-diff and git-diff-tree
260 # - default is '-M', with the cost proportional to
261 # (number of removed files) * (number of new files).
262 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
263 # (number of changed files + number of removed files) * (number of new files)
264 # - even more costly is '-C', '--find-copies-harder' with cost
265 # (number of files in the original tree) * (number of new files)
266 # - one might want to include '-B' option, e.g. '-B', '-M'
267 our @diff_opts = ('-M'); # taken from git_commit
269 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
270 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
272 # version of the core git binary
273 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
275 $projects_list ||= $projectroot;
277 # ======================================================================
278 # input validation and dispatch
279 our $action = $cgi->param('a');
280 if (defined $action) {
281 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
282 die_error
(undef, "Invalid action parameter");
286 # parameters which are pathnames
287 our $project = $cgi->param('p');
288 if (defined $project) {
289 if (!validate_pathname
($project) ||
290 !(-d
"$projectroot/$project") ||
291 !check_head_link
("$projectroot/$project") ||
292 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
293 ($strict_export && !project_in_list
($project))) {
295 die_error
(undef, "No such project");
299 our $file_name = $cgi->param('f');
300 if (defined $file_name) {
301 if (!validate_pathname
($file_name)) {
302 die_error
(undef, "Invalid file parameter");
306 our $file_parent = $cgi->param('fp');
307 if (defined $file_parent) {
308 if (!validate_pathname
($file_parent)) {
309 die_error
(undef, "Invalid file parent parameter");
313 # parameters which are refnames
314 our $hash = $cgi->param('h');
316 if (!validate_refname
($hash)) {
317 die_error
(undef, "Invalid hash parameter");
321 our $hash_parent = $cgi->param('hp');
322 if (defined $hash_parent) {
323 if (!validate_refname
($hash_parent)) {
324 die_error
(undef, "Invalid hash parent parameter");
328 our $hash_base = $cgi->param('hb');
329 if (defined $hash_base) {
330 if (!validate_refname
($hash_base)) {
331 die_error
(undef, "Invalid hash base parameter");
335 our $hash_parent_base = $cgi->param('hpb');
336 if (defined $hash_parent_base) {
337 if (!validate_refname
($hash_parent_base)) {
338 die_error
(undef, "Invalid hash parent base parameter");
343 our $page = $cgi->param('pg');
345 if ($page =~ m/[^0-9]/) {
346 die_error
(undef, "Invalid page parameter");
350 our $searchtext = $cgi->param('s');
351 if (defined $searchtext) {
352 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
353 die_error
(undef, "Invalid search parameter");
355 $searchtext = quotemeta $searchtext;
358 our $searchtype = $cgi->param('st');
359 if (defined $searchtype) {
360 if ($searchtype =~ m/[^a-z]/) {
361 die_error
(undef, "Invalid searchtype parameter");
365 # now read PATH_INFO and use it as alternative to parameters
366 sub evaluate_path_info
{
367 return if defined $project;
368 my $path_info = $ENV{"PATH_INFO"};
369 return if !$path_info;
370 $path_info =~ s
,^/+,,;
371 return if !$path_info;
372 # find which part of PATH_INFO is project
373 $project = $path_info;
375 while ($project && !check_head_link
("$projectroot/$project")) {
376 $project =~ s
,/*[^/]*$,,;
379 $project = validate_pathname
($project);
381 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
382 ($strict_export && !project_in_list
($project))) {
386 # do not change any parameters if an action is given using the query string
388 $path_info =~ s
,^$project/*,,;
389 my ($refname, $pathname) = split(/:/, $path_info, 2);
390 if (defined $pathname) {
391 # we got "project.git/branch:filename" or "project.git/branch:dir/"
392 # we could use git_get_type(branch:pathname), but it needs $git_dir
393 $pathname =~ s
,^/+,,;
394 if (!$pathname || substr($pathname, -1) eq "/") {
398 $action ||= "blob_plain";
400 $hash_base ||= validate_refname
($refname);
401 $file_name ||= validate_pathname
($pathname);
402 } elsif (defined $refname) {
403 # we got "project.git/branch"
404 $action ||= "shortlog";
405 $hash ||= validate_refname
($refname);
408 evaluate_path_info
();
410 # path to the current git repository
412 $git_dir = "$projectroot/$project" if $project;
416 "blame" => \
&git_blame2
,
417 "blobdiff" => \
&git_blobdiff
,
418 "blobdiff_plain" => \
&git_blobdiff_plain
,
419 "blob" => \
&git_blob
,
420 "blob_plain" => \
&git_blob_plain
,
421 "commitdiff" => \
&git_commitdiff
,
422 "commitdiff_plain" => \
&git_commitdiff_plain
,
423 "commit" => \
&git_commit
,
424 "forks" => \
&git_forks
,
425 "heads" => \
&git_heads
,
426 "history" => \
&git_history
,
429 "search" => \
&git_search
,
430 "search_help" => \
&git_search_help
,
431 "shortlog" => \
&git_shortlog
,
432 "summary" => \
&git_summary
,
434 "tags" => \
&git_tags
,
435 "tree" => \
&git_tree
,
436 "snapshot" => \
&git_snapshot
,
437 # those below don't need $project
438 "opml" => \
&git_opml
,
439 "project_list" => \
&git_project_list
,
440 "project_index" => \
&git_project_index
,
443 if (defined $project) {
444 $action ||= 'summary';
446 $action ||= 'project_list';
448 if (!defined($actions{$action})) {
449 die_error
(undef, "Unknown action");
451 if ($action !~ m/^(opml|project_list|project_index)$/ &&
453 die_error
(undef, "Project needed");
455 $actions{$action}->();
458 ## ======================================================================
465 # XXX: Warning: If you touch this, check the search form for updating,
476 hash_parent_base
=> "hpb",
482 my %mapping = @mapping;
484 $params{'project'} = $project unless exists $params{'project'};
486 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
488 # use PATH_INFO for project name
489 $href .= "/$params{'project'}" if defined $params{'project'};
490 delete $params{'project'};
492 # Summary just uses the project path URL
493 if (defined $params{'action'} && $params{'action'} eq 'summary') {
494 delete $params{'action'};
498 # now encode the parameters explicitly
500 for (my $i = 0; $i < @mapping; $i += 2) {
501 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
502 if (defined $params{$name}) {
503 push @result, $symbol . "=" . esc_param
($params{$name});
506 $href .= "?" . join(';', @result) if scalar @result;
512 ## ======================================================================
513 ## validation, quoting/unquoting and escaping
515 sub validate_pathname
{
516 my $input = shift || return undef;
518 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
519 # at the beginning, at the end, and between slashes.
520 # also this catches doubled slashes
521 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
525 if ($input =~ m!\0!) {
531 sub validate_refname
{
532 my $input = shift || return undef;
534 # textual hashes are O.K.
535 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
538 # it must be correct pathname
539 $input = validate_pathname
($input)
541 # restrictions on ref name according to git-check-ref-format
542 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
548 # very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT);
551 return decode
("utf8", $str, Encode
::FB_DEFAULT
);
554 # quote unsafe chars, but keep the slash, even when it's not
555 # correct, but quoted slashes look too horrible in bookmarks
558 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
564 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
567 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
573 # replace invalid utf8 character with SUBSTITUTION sequence
578 $str = to_utf8
($str);
579 $str = escapeHTML
($str);
580 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
581 $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1)
582 if ($opts{'-nbsp'}) {
583 $str =~ s/ / /g;
588 # git may return quoted and escaped filenames
591 if ($str =~ m/^"(.*)"$/) {
593 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
598 # escape tabs (convert tabs to spaces)
602 while ((my $pos = index($line, "\t")) != -1) {
603 if (my $count = (8 - ($pos % 8))) {
604 my $spaces = ' ' x
$count;
605 $line =~ s/\t/$spaces/;
612 sub project_in_list
{
614 my @list = git_get_projects_list
();
615 return @list && scalar(grep { $_->{'path'} eq $project } @list);
618 ## ----------------------------------------------------------------------
619 ## HTML aware string manipulation
624 my $add_len = shift || 10;
626 # allow only $len chars, but don't cut a word if it would fit in $add_len
627 # if it doesn't fit, cut it if it's still longer than the dots we would add
628 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
631 if (length($tail) > 4) {
633 $body =~ s/&[^;]*$//; # remove chopped character entities
638 ## ----------------------------------------------------------------------
639 ## functions returning short strings
641 # CSS class for given age value (in seconds)
645 if ($age < 60*60*2) {
647 } elsif ($age < 60*60*24*2) {
654 # convert age in seconds to "nn units ago" string
659 if ($age > 60*60*24*365*2) {
660 $age_str = (int $age/60/60/24/365);
661 $age_str .= " years ago";
662 } elsif ($age > 60*60*24*(365/12)*2) {
663 $age_str = int $age/60/60/24/(365/12);
664 $age_str .= " months ago";
665 } elsif ($age > 60*60*24*7*2) {
666 $age_str = int $age/60/60/24/7;
667 $age_str .= " weeks ago";
668 } elsif ($age > 60*60*24*2) {
669 $age_str = int $age/60/60/24;
670 $age_str .= " days ago";
671 } elsif ($age > 60*60*2) {
672 $age_str = int $age/60/60;
673 $age_str .= " hours ago";
674 } elsif ($age > 60*2) {
675 $age_str = int $age/60;
676 $age_str .= " min ago";
679 $age_str .= " sec ago";
681 $age_str .= " right now";
686 # convert file mode in octal to symbolic file mode string
688 my $mode = oct shift;
690 if (S_ISDIR
($mode & S_IFMT
)) {
692 } elsif (S_ISLNK
($mode)) {
694 } elsif (S_ISREG
($mode)) {
695 # git cares only about the executable bit
696 if ($mode & S_IXUSR
) {
706 # convert file mode in octal to file type string
710 if ($mode !~ m/^[0-7]+$/) {
716 if (S_ISDIR
($mode & S_IFMT
)) {
718 } elsif (S_ISLNK
($mode)) {
720 } elsif (S_ISREG
($mode)) {
727 ## ----------------------------------------------------------------------
728 ## functions returning short HTML fragments, or transforming HTML fragments
729 ## which don't beling to other sections
731 # format line of commit message or tag comment
732 sub format_log_line_html
{
735 $line = esc_html
($line);
736 $line =~ s/ / /g;
737 if ($line =~ m/([0-9a-fA-F]{40})/) {
739 if (git_get_type
($hash_text) eq "commit") {
741 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
742 -class => "text"}, $hash_text);
743 $line =~ s/$hash_text/$link/;
749 # format marker of refs pointing to given object
750 sub format_ref_marker
{
751 my ($refs, $id) = @_;
754 if (defined $refs->{$id}) {
755 foreach my $ref (@{$refs->{$id}}) {
756 my ($type, $name) = qw();
757 # e.g. tags/v2.6.11 or heads/next
758 if ($ref =~ m!^(.*?)s?/(.*)$!) {
766 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
771 return ' <span class="refs">'. $markers . '</span>';
777 # format, perhaps shortened and with markers, title line
778 sub format_subject_html
{
779 my ($long, $short, $href, $extra) = @_;
780 $extra = '' unless defined($extra);
782 if (length($short) < length($long)) {
783 return $cgi->a({-href
=> $href, -class => "list subject",
784 -title
=> to_utf8
($long)},
785 esc_html
($short) . $extra);
787 return $cgi->a({-href
=> $href, -class => "list subject"},
788 esc_html
($long) . $extra);
792 sub format_diff_line
{
794 my $char = substr($line, 0, 1);
800 $diff_class = " add";
801 } elsif ($char eq "-") {
802 $diff_class = " rem";
803 } elsif ($char eq "@") {
804 $diff_class = " chunk_header";
805 } elsif ($char eq "\\") {
806 $diff_class = " incomplete";
808 $line = untabify
($line);
809 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
812 ## ----------------------------------------------------------------------
813 ## git utility subroutines, invoking git commands
815 # returns path to the core git executable and the --git-dir parameter as list
817 return $GIT, '--git-dir='.$git_dir;
820 # returns path to the core git executable and the --git-dir parameter as string
822 return join(' ', git_cmd
());
825 # get HEAD ref of given project as hash
826 sub git_get_head_hash
{
828 my $o_git_dir = $git_dir;
830 $git_dir = "$projectroot/$project";
831 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
834 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
838 if (defined $o_git_dir) {
839 $git_dir = $o_git_dir;
844 # get type of given object
848 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
855 sub git_get_project_config
{
856 my ($key, $type) = @_;
858 return unless ($key);
859 $key =~ s/^gitweb\.//;
860 return if ($key =~ m/\W/);
862 my @x = (git_cmd
(), 'repo-config');
863 if (defined $type) { push @x, $type; }
865 push @x, "gitweb.$key";
871 # get hash of given path at given ref
872 sub git_get_hash_by_path
{
874 my $path = shift || return undef;
879 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
880 or die_error
(undef, "Open git-ls-tree failed");
882 close $fd or return undef;
884 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
885 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
886 if (defined $type && $type ne $2) {
893 ## ......................................................................
894 ## git utility functions, directly accessing git repository
896 sub git_get_project_description
{
899 open my $fd, "$projectroot/$path/description" or return undef;
906 sub git_get_project_url_list
{
909 open my $fd, "$projectroot/$path/cloneurl" or return;
910 my @git_project_url_list = map { chomp; $_ } <$fd>;
913 return wantarray ? @git_project_url_list : \
@git_project_url_list;
916 sub git_get_projects_list
{
921 $filter =~ s/\.git$//;
923 if (-d
$projects_list) {
924 # search in directory
925 my $dir = $projects_list . ($filter ? "/$filter" : '');
926 # remove the trailing "/"
928 my $pfxlen = length("$dir");
930 my ($check_forks) = gitweb_check_feature
('forks');
933 follow_fast
=> 1, # follow symbolic links
934 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
936 # skip project-list toplevel, if we get it.
937 return if (m!^[/.]$!);
938 # only directories can be git repositories
939 return unless (-d
$_);
941 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
942 # we check related file in $projectroot
943 if ($check_forks and $subdir =~ m
#/.#) {
944 $File::Find
::prune
= 1;
945 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
946 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
947 $File::Find
::prune
= 1;
952 } elsif (-f
$projects_list) {
953 # read from file(url-encoded):
954 # 'git%2Fgit.git Linus+Torvalds'
955 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
956 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
957 open my ($fd), $projects_list or return;
958 while (my $line = <$fd>) {
960 my ($path, $owner) = split ' ', $line;
961 $path = unescape
($path);
962 $owner = unescape
($owner);
963 if (!defined $path) {
968 my $pfx = substr($path, 0, length($filter));
969 if ($pfx ne $filter) {
972 my $sfx = substr($path, length($filter));
973 if ($sfx !~ /^\/.*\
.git
$/) {
977 if (check_export_ok
("$projectroot/$path")) {
980 owner
=> to_utf8
($owner),
987 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
991 sub git_get_project_owner
{
995 return undef unless $project;
997 # read from file (url-encoded):
998 # 'git%2Fgit.git Linus+Torvalds'
999 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1000 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1001 if (-f
$projects_list) {
1002 open (my $fd , $projects_list);
1003 while (my $line = <$fd>) {
1005 my ($pr, $ow) = split ' ', $line;
1006 $pr = unescape
($pr);
1007 $ow = unescape
($ow);
1008 if ($pr eq $project) {
1009 $owner = to_utf8
($ow);
1015 if (!defined $owner) {
1016 $owner = get_file_owner
("$projectroot/$project");
1022 sub git_get_last_activity
{
1026 $git_dir = "$projectroot/$path";
1027 open($fd, "-|", git_cmd
(), 'for-each-ref',
1028 '--format=%(refname) %(committer)',
1029 '--sort=-committerdate',
1030 'refs/heads') or return;
1031 my $most_recent = <$fd>;
1032 close $fd or return;
1033 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1035 my $age = time - $timestamp;
1036 return ($age, age_string
($age));
1040 sub git_get_references
{
1041 my $type = shift || "";
1043 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1044 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1045 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1048 while (my $line = <$fd>) {
1050 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
1051 if (defined $refs{$1}) {
1052 push @{$refs{$1}}, $2;
1058 close $fd or return;
1062 sub git_get_rev_name_tags
{
1063 my $hash = shift || return undef;
1065 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1067 my $name_rev = <$fd>;
1070 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1073 # catches also '$hash undefined' output
1078 ## ----------------------------------------------------------------------
1079 ## parse to hash functions
1083 my $tz = shift || "-0000";
1086 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1087 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1088 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1089 $date{'hour'} = $hour;
1090 $date{'minute'} = $min;
1091 $date{'mday'} = $mday;
1092 $date{'day'} = $days[$wday];
1093 $date{'month'} = $months[$mon];
1094 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1095 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1096 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1097 $mday, $months[$mon], $hour ,$min;
1099 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1100 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1101 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1102 $date{'hour_local'} = $hour;
1103 $date{'minute_local'} = $min;
1104 $date{'tz_local'} = $tz;
1105 $date{'iso-tz'} = sprintf ("%04d-%02d-%02d %02d:%02d:%02d %s",
1106 1900+$year, $mon+1, $mday,
1107 $hour, $min, $sec, $tz);
1116 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1117 $tag{'id'} = $tag_id;
1118 while (my $line = <$fd>) {
1120 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1121 $tag{'object'} = $1;
1122 } elsif ($line =~ m/^type (.+)$/) {
1124 } elsif ($line =~ m/^tag (.+)$/) {
1126 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1127 $tag{'author'} = $1;
1130 } elsif ($line =~ m/--BEGIN/) {
1131 push @comment, $line;
1133 } elsif ($line eq "") {
1137 push @comment, <$fd>;
1138 $tag{'comment'} = \
@comment;
1139 close $fd or return;
1140 if (!defined $tag{'name'}) {
1147 my $commit_id = shift;
1148 my $commit_text = shift;
1153 if (defined $commit_text) {
1154 @commit_lines = @$commit_text;
1157 open my $fd, "-|", git_cmd
(), "rev-list",
1158 "--header", "--parents", "--max-count=1",
1161 @commit_lines = split '\n', <$fd>;
1162 close $fd or return;
1165 my $header = shift @commit_lines;
1166 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1169 ($co{'id'}, my @parents) = split ' ', $header;
1170 $co{'parents'} = \
@parents;
1171 $co{'parent'} = $parents[0];
1172 while (my $line = shift @commit_lines) {
1173 last if $line eq "\n";
1174 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1176 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1178 $co{'author_epoch'} = $2;
1179 $co{'author_tz'} = $3;
1180 if ($co{'author'} =~ m/^([^<]+) </) {
1181 $co{'author_name'} = $1;
1183 $co{'author_name'} = $co{'author'};
1185 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1186 $co{'committer'} = $1;
1187 $co{'committer_epoch'} = $2;
1188 $co{'committer_tz'} = $3;
1189 $co{'committer_name'} = $co{'committer'};
1190 $co{'committer_name'} =~ s/ <.*//;
1193 if (!defined $co{'tree'}) {
1197 foreach my $title (@commit_lines) {
1200 $co{'title'} = chop_str
($title, 80, 5);
1201 # remove leading stuff of merges to make the interesting part visible
1202 if (length($title) > 50) {
1203 $title =~ s/^Automatic //;
1204 $title =~ s/^merge (of|with) /Merge ... /i;
1205 if (length($title) > 50) {
1206 $title =~ s/(http|rsync):\/\///;
1208 if (length($title) > 50) {
1209 $title =~ s/(master|www|rsync)\.//;
1211 if (length($title) > 50) {
1212 $title =~ s/kernel.org:?//;
1214 if (length($title) > 50) {
1215 $title =~ s/\/pub\/scm//;
1218 $co{'title_short'} = chop_str
($title, 50, 5);
1222 if ($co{'title'} eq "") {
1223 $co{'title'} = $co{'title_short'} = '(no commit message)';
1225 # remove added spaces
1226 foreach my $line (@commit_lines) {
1229 $co{'comment'} = \
@commit_lines;
1231 my $age = time - $co{'committer_epoch'};
1233 $co{'age_string'} = age_string
($age);
1234 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1235 if ($age > 60*60*24*7*2) {
1236 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1237 $co{'age_string_age'} = $co{'age_string'};
1239 $co{'age_string_date'} = $co{'age_string'};
1240 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1245 # parse ref from ref_file, given by ref_id, with given type
1247 my $ref_file = shift;
1249 my $type = shift || git_get_type
($ref_id);
1252 $ref_item{'type'} = $type;
1253 $ref_item{'id'} = $ref_id;
1254 $ref_item{'epoch'} = 0;
1255 $ref_item{'age'} = "unknown";
1256 if ($type eq "tag") {
1257 my %tag = parse_tag
($ref_id);
1258 $ref_item{'comment'} = $tag{'comment'};
1259 if ($tag{'type'} eq "commit") {
1260 my %co = parse_commit
($tag{'object'});
1261 $ref_item{'epoch'} = $co{'committer_epoch'};
1262 $ref_item{'age'} = $co{'age_string'};
1263 } elsif (defined($tag{'epoch'})) {
1264 my $age = time - $tag{'epoch'};
1265 $ref_item{'epoch'} = $tag{'epoch'};
1266 $ref_item{'age'} = age_string
($age);
1268 $ref_item{'reftype'} = $tag{'type'};
1269 $ref_item{'name'} = $tag{'name'};
1270 $ref_item{'refid'} = $tag{'object'};
1271 } elsif ($type eq "commit"){
1272 my %co = parse_commit
($ref_id);
1273 $ref_item{'reftype'} = "commit";
1274 $ref_item{'name'} = $ref_file;
1275 $ref_item{'title'} = $co{'title'};
1276 $ref_item{'refid'} = $ref_id;
1277 $ref_item{'epoch'} = $co{'committer_epoch'};
1278 $ref_item{'age'} = $co{'age_string'};
1280 $ref_item{'reftype'} = $type;
1281 $ref_item{'name'} = $ref_file;
1282 $ref_item{'refid'} = $ref_id;
1288 # parse line of git-diff-tree "raw" output
1289 sub parse_difftree_raw_line
{
1293 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1294 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1295 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1296 $res{'from_mode'} = $1;
1297 $res{'to_mode'} = $2;
1298 $res{'from_id'} = $3;
1300 $res{'status'} = $5;
1301 $res{'similarity'} = $6;
1302 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1303 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1305 $res{'file'} = unquote
($7);
1308 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1309 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1310 $res{'commit'} = $1;
1313 return wantarray ? %res : \
%res;
1316 # parse line of git-ls-tree output
1317 sub parse_ls_tree_line
($;%) {
1322 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1323 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1331 $res{'name'} = unquote
($4);
1334 return wantarray ? %res : \
%res;
1337 ## ......................................................................
1338 ## parse to array of hashes functions
1340 sub git_get_heads_list
{
1344 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1345 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1346 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1349 while (my $line = <$fd>) {
1353 my ($refinfo, $committerinfo) = split(/\0/, $line);
1354 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1355 my ($committer, $epoch, $tz) =
1356 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1357 $name =~ s!^refs/heads/!!;
1359 $ref_item{'name'} = $name;
1360 $ref_item{'id'} = $hash;
1361 $ref_item{'title'} = $title || '(no commit message)';
1362 $ref_item{'epoch'} = $epoch;
1364 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1366 $ref_item{'age'} = "unknown";
1369 push @headslist, \
%ref_item;
1373 return wantarray ? @headslist : \
@headslist;
1376 sub git_get_tags_list
{
1380 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1381 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1382 '--format=%(objectname) %(objecttype) %(refname) '.
1383 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1386 while (my $line = <$fd>) {
1390 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1391 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1392 my ($creator, $epoch, $tz) =
1393 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1394 $name =~ s!^refs/tags/!!;
1396 $ref_item{'type'} = $type;
1397 $ref_item{'id'} = $id;
1398 $ref_item{'name'} = $name;
1399 if ($type eq "tag") {
1400 $ref_item{'subject'} = $title;
1401 $ref_item{'reftype'} = $reftype;
1402 $ref_item{'refid'} = $refid;
1404 $ref_item{'reftype'} = $type;
1405 $ref_item{'refid'} = $id;
1408 if ($type eq "tag" || $type eq "commit") {
1409 $ref_item{'epoch'} = $epoch;
1411 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1413 $ref_item{'age'} = "unknown";
1417 push @tagslist, \
%ref_item;
1421 return wantarray ? @tagslist : \
@tagslist;
1424 ## ----------------------------------------------------------------------
1425 ## filesystem-related functions
1427 sub get_file_owner
{
1430 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1431 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1432 if (!defined $gcos) {
1436 $owner =~ s/[,;].*$//;
1437 return to_utf8
($owner);
1440 ## ......................................................................
1441 ## mimetype related functions
1443 sub mimetype_guess_file
{
1444 my $filename = shift;
1445 my $mimemap = shift;
1446 -r
$mimemap or return undef;
1449 open(MIME
, $mimemap) or return undef;
1451 next if m/^#/; # skip comments
1452 my ($mime, $exts) = split(/\t+/);
1453 if (defined $exts) {
1454 my @exts = split(/\s+/, $exts);
1455 foreach my $ext (@exts) {
1456 $mimemap{$ext} = $mime;
1462 $filename =~ /\.([^.]*)$/;
1463 return $mimemap{$1};
1466 sub mimetype_guess
{
1467 my $filename = shift;
1469 $filename =~ /\./ or return undef;
1471 if ($mimetypes_file) {
1472 my $file = $mimetypes_file;
1473 if ($file !~ m!^/!) { # if it is relative path
1474 # it is relative to project
1475 $file = "$projectroot/$project/$file";
1477 $mime = mimetype_guess_file
($filename, $file);
1479 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1485 my $filename = shift;
1488 my $mime = mimetype_guess
($filename);
1489 $mime and return $mime;
1493 return $default_blob_plain_mimetype unless $fd;
1496 return 'text/plain' .
1497 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1498 } elsif (! $filename) {
1499 return 'application/octet-stream';
1500 } elsif ($filename =~ m/\.png$/i) {
1502 } elsif ($filename =~ m/\.gif$/i) {
1504 } elsif ($filename =~ m/\.jpe?g$/i) {
1505 return 'image/jpeg';
1507 return 'application/octet-stream';
1511 ## ======================================================================
1512 ## functions printing HTML: header, footer, error page
1514 sub git_header_html
{
1515 my $status = shift || "200 OK";
1516 my $expires = shift;
1518 my $title = "$site_name";
1519 if (defined $project) {
1520 $title .= " - $project";
1521 if (defined $action) {
1522 $title .= "/$action";
1523 if (defined $file_name) {
1524 $title .= " - " . esc_html
($file_name);
1525 if ($action eq "tree" && $file_name !~ m
|/$|) {
1532 # require explicit support from the UA if we are to send the page as
1533 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1534 # we have to do this because MSIE sometimes globs '*/*', pretending to
1535 # support xhtml+xml but choking when it gets what it asked for.
1536 if (defined $cgi->http('HTTP_ACCEPT') &&
1537 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1538 $cgi->Accept('application/xhtml+xml') != 0) {
1539 $content_type = 'application/xhtml+xml';
1541 $content_type = 'text/html';
1543 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1544 -status
=> $status, -expires
=> $expires);
1546 <?xml version="1.0" encoding="utf-8"?>
1547 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1548 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1549 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1550 <!-- git core binaries version $git_version -->
1552 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1553 <meta name="generator" content="gitweb/$version git/$git_version"/>
1554 <meta name="robots" content="index, nofollow"/>
1555 <title>$title</title>
1557 # print out each stylesheet that exist
1558 if (defined $stylesheet) {
1559 #provides backwards capability for those people who define style sheet in a config file
1560 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1562 foreach my $stylesheet (@stylesheets) {
1563 next unless $stylesheet;
1564 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1567 if (defined $project) {
1568 printf('<link rel="alternate" title="%s log" '.
1569 'href="%s" type="application/rss+xml"/>'."\n",
1570 esc_param
($project), href
(action
=>"rss"));
1572 printf('<link rel="alternate" title="%s projects list" '.
1573 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1574 $site_name, href
(project
=>undef, action
=>"project_index"));
1575 printf('<link rel="alternate" title="%s projects logs" '.
1576 'href="%s" type="text/x-opml"/>'."\n",
1577 $site_name, href
(project
=>undef, action
=>"opml"));
1579 if (defined $favicon) {
1580 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1586 if (-f
$site_header) {
1587 open (my $fd, $site_header);
1592 print "<div class=\"page_header\">\n" .
1593 $cgi->a({-href
=> esc_url
($logo_url),
1594 -title
=> $logo_label},
1595 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1596 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1597 if (defined $project) {
1598 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1599 if (defined $action) {
1603 if (!defined $searchtext) {
1607 if (defined $hash_base) {
1608 $search_hash = $hash_base;
1609 } elsif (defined $hash) {
1610 $search_hash = $hash;
1612 $search_hash = "HEAD";
1614 $cgi->param("a", "search");
1615 $cgi->param("h", $search_hash);
1616 $cgi->param("p", $project);
1617 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1618 "<div class=\"search\">\n" .
1619 $cgi->hidden(-name
=> "p") . "\n" .
1620 $cgi->hidden(-name
=> "a") . "\n" .
1621 $cgi->hidden(-name
=> "h") . "\n" .
1622 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1623 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1624 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1626 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1628 $cgi->end_form() . "\n";
1633 sub git_footer_html
{
1634 print "<div class=\"page_footer\">\n";
1635 if (defined $project) {
1636 my $descr = git_get_project_description
($project);
1637 if (defined $descr) {
1638 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1640 print $cgi->a({-href
=> href
(action
=>"rss"),
1641 -class => "rss_logo"}, "RSS") . "\n";
1643 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1644 -class => "rss_logo"}, "OPML") . " ";
1645 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1646 -class => "rss_logo"}, "TXT") . "\n";
1650 if (-f
$site_footer) {
1651 open (my $fd, $site_footer);
1661 my $status = shift || "403 Forbidden";
1662 my $error = shift || "Malformed query, file missing or permission denied";
1664 git_header_html
($status);
1666 <div class="page_body">
1676 ## ----------------------------------------------------------------------
1677 ## functions printing or outputting HTML: navigation
1679 sub git_print_page_nav
{
1680 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1681 $extra = '' if !defined $extra; # pager or formats
1683 my @navs = qw(summary shortlog log commit commitdiff tree);
1685 @navs = grep { $_ ne $suppress } @navs;
1688 my %arg = map { $_ => {action
=>$_} } @navs;
1689 if (defined $head) {
1690 for (qw(commit commitdiff)) {
1691 $arg{$_}{hash
} = $head;
1693 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1694 for (qw(shortlog log)) {
1695 $arg{$_}{hash
} = $head;
1699 $arg{tree
}{hash
} = $treehead if defined $treehead;
1700 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1702 print "<div class=\"page_nav\">\n" .
1704 map { $_ eq $current ?
1705 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1707 print "<br/>\n$extra<br/>\n" .
1711 sub format_paging_nav
{
1712 my ($action, $hash, $head, $page, $nrevs) = @_;
1716 if ($hash ne $head || $page) {
1717 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1719 $paging_nav .= "HEAD";
1723 $paging_nav .= " ⋅ " .
1724 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1725 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1727 $paging_nav .= " ⋅ prev";
1730 if ($nrevs >= (100 * ($page+1)-1)) {
1731 $paging_nav .= " ⋅ " .
1732 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1733 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1735 $paging_nav .= " ⋅ next";
1741 ## ......................................................................
1742 ## functions printing or outputting HTML: div
1744 sub git_print_header_div
{
1745 my ($action, $title, $hash, $hash_base) = @_;
1748 $args{action
} = $action;
1749 $args{hash
} = $hash if $hash;
1750 $args{hash_base
} = $hash_base if $hash_base;
1752 print "<div class=\"header\">\n" .
1753 $cgi->a({-href
=> href
(%args), -class => "title"},
1754 $title ? $title : $action) .
1758 #sub git_print_authorship (\%) {
1759 sub git_print_authorship
{
1762 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1763 print "<div class=\"author_date\">" .
1764 esc_html
($co->{'author_name'}) .
1766 if ($ad{'hour_local'} < 6) {
1767 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1768 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1770 printf(" (%02d:%02d %s)",
1771 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1776 sub git_print_page_path
{
1782 print "<div class=\"page_path\">";
1783 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1784 -title
=> 'tree root'}, "[$project]");
1786 if (defined $name) {
1787 my @dirname = split '/', $name;
1788 my $basename = pop @dirname;
1791 foreach my $dir (@dirname) {
1792 $fullname .= ($fullname ? '/' : '') . $dir;
1793 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1795 -title
=> $fullname}, esc_html
($dir));
1798 if (defined $type && $type eq 'blob') {
1799 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1801 -title
=> $name}, esc_html
($basename));
1802 } elsif (defined $type && $type eq 'tree') {
1803 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1805 -title
=> $name}, esc_html
($basename));
1808 print esc_html
($basename);
1811 print "<br/></div>\n";
1814 # sub git_print_log (\@;%) {
1815 sub git_print_log
($;%) {
1819 if ($opts{'-remove_title'}) {
1820 # remove title, i.e. first line of log
1823 # remove leading empty lines
1824 while (defined $log->[0] && $log->[0] eq "") {
1831 foreach my $line (@$log) {
1832 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1835 if (! $opts{'-remove_signoff'}) {
1836 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1839 # remove signoff lines
1846 # print only one empty line
1847 # do not print empty line after signoff
1849 next if ($empty || $signoff);
1855 print format_log_line_html
($line) . "<br/>\n";
1858 if ($opts{'-final_empty_line'}) {
1859 # end with single empty line
1860 print "<br/>\n" unless $empty;
1864 # print tree entry (row of git_tree), but without encompassing <tr> element
1865 sub git_print_tree_entry
{
1866 my ($t, $basedir, $hash_base, $have_blame) = @_;
1869 $base_key{hash_base
} = $hash_base if defined $hash_base;
1871 # The format of a table row is: mode list link. Where mode is
1872 # the mode of the entry, list is the name of the entry, an href,
1873 # and link is the action links of the entry.
1875 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1876 if ($t->{'type'} eq "blob") {
1877 print "<td class=\"list\">" .
1878 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1879 file_name
=>"$basedir$t->{'name'}", %base_key),
1880 -class => "list"}, esc_html
($t->{'name'})) . "</td>\n";
1881 print "<td class=\"link\">";
1882 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1883 file_name
=>"$basedir$t->{'name'}", %base_key)},
1887 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1888 file_name
=>"$basedir$t->{'name'}", %base_key)},
1891 if (defined $hash_base) {
1893 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1894 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1898 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
1899 file_name
=>"$basedir$t->{'name'}")},
1903 } elsif ($t->{'type'} eq "tree") {
1904 print "<td class=\"list\">";
1905 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1906 file_name
=>"$basedir$t->{'name'}", %base_key)},
1907 esc_html
($t->{'name'}));
1909 print "<td class=\"link\">";
1910 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1911 file_name
=>"$basedir$t->{'name'}", %base_key)},
1913 if (defined $hash_base) {
1915 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1916 file_name
=>"$basedir$t->{'name'}")},
1923 ## ......................................................................
1924 ## functions printing large fragments of HTML
1926 sub git_difftree_body
{
1927 my ($difftree, $hash, $parent) = @_;
1929 print "<div class=\"list_head\">\n";
1930 if ($#{$difftree} > 10) {
1931 print(($#{$difftree} + 1) . " files changed:\n");
1935 print "<table class=\"diff_tree\">\n";
1938 foreach my $line (@{$difftree}) {
1939 my %diff = parse_difftree_raw_line
($line);
1942 print "<tr class=\"dark\">\n";
1944 print "<tr class=\"light\">\n";
1948 my ($to_mode_oct, $to_mode_str, $to_file_type);
1949 my ($from_mode_oct, $from_mode_str, $from_file_type);
1950 if ($diff{'to_mode'} ne ('0' x
6)) {
1951 $to_mode_oct = oct $diff{'to_mode'};
1952 if (S_ISREG
($to_mode_oct)) { # only for regular file
1953 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1955 $to_file_type = file_type
($diff{'to_mode'});
1957 if ($diff{'from_mode'} ne ('0' x
6)) {
1958 $from_mode_oct = oct $diff{'from_mode'};
1959 if (S_ISREG
($to_mode_oct)) { # only for regular file
1960 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1962 $from_file_type = file_type
($diff{'from_mode'});
1965 if ($diff{'status'} eq "A") { # created
1966 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1967 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1968 $mode_chng .= "]</span>";
1970 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1971 hash_base
=>$hash, file_name
=>$diff{'file'}),
1972 -class => "list"}, esc_html
($diff{'file'}));
1974 print "<td>$mode_chng</td>\n";
1975 print "<td class=\"link\">";
1976 if ($action eq 'commitdiff') {
1979 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1983 } elsif ($diff{'status'} eq "D") { # deleted
1984 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1986 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1987 hash_base
=>$parent, file_name
=>$diff{'file'}),
1988 -class => "list"}, esc_html
($diff{'file'}));
1990 print "<td>$mode_chng</td>\n";
1991 print "<td class=\"link\">";
1992 if ($action eq 'commitdiff') {
1995 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1998 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1999 hash_base
=>$parent, file_name
=>$diff{'file'})},
2001 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2002 file_name
=>$diff{'file'})},
2004 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2005 file_name
=>$diff{'file'})},
2009 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
2010 my $mode_chnge = "";
2011 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2012 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2013 if ($from_file_type != $to_file_type) {
2014 $mode_chnge .= " from $from_file_type to $to_file_type";
2016 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2017 if ($from_mode_str && $to_mode_str) {
2018 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2019 } elsif ($to_mode_str) {
2020 $mode_chnge .= " mode: $to_mode_str";
2023 $mode_chnge .= "]</span>\n";
2026 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2027 hash_base
=>$hash, file_name
=>$diff{'file'}),
2028 -class => "list"}, esc_html
($diff{'file'}));
2030 print "<td>$mode_chnge</td>\n";
2031 print "<td class=\"link\">";
2032 if ($action eq 'commitdiff') {
2035 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2037 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2038 # "commit" view and modified file (not onlu mode changed)
2039 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2040 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2041 hash_base
=>$hash, hash_parent_base
=>$parent,
2042 file_name
=>$diff{'file'})},
2046 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2047 hash_base
=>$hash, file_name
=>$diff{'file'})},
2049 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2050 file_name
=>$diff{'file'})},
2052 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2053 file_name
=>$diff{'file'})},
2057 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
2058 my %status_name = ('R' => 'moved', 'C' => 'copied');
2059 my $nstatus = $status_name{$diff{'status'}};
2061 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2062 # mode also for directories, so we cannot use $to_mode_str
2063 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2066 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2067 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
2068 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
2069 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2070 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2071 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
2072 -class => "list"}, esc_html
($diff{'from_file'})) .
2073 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2074 "<td class=\"link\">";
2075 if ($action eq 'commitdiff') {
2078 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2080 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2081 # "commit" view and modified file (not only pure rename or copy)
2082 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2083 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2084 hash_base
=>$hash, hash_parent_base
=>$parent,
2085 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
2089 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2090 hash_base
=>$parent, file_name
=>$diff{'from_file'})},
2092 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2093 file_name
=>$diff{'from_file'})},
2095 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2096 file_name
=>$diff{'from_file'})},
2100 } # we should not encounter Unmerged (U) or Unknown (X) status
2106 sub git_patchset_body
{
2107 my ($fd, $difftree, $hash, $hash_parent) = @_;
2111 my $patch_found = 0;
2114 print "<div class=\"patchset\">\n";
2117 while (my $patch_line = <$fd>) {
2120 if ($patch_line =~ m/^diff /) { # "git diff" header
2121 # beginning of patch (in patchset)
2123 # close previous patch
2124 print "</div>\n"; # class="patch"
2126 # first patch in patchset
2129 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2131 if (ref($difftree->[$patch_idx]) eq "HASH") {
2132 $diffinfo = $difftree->[$patch_idx];
2134 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2138 if ($diffinfo->{'status'} eq "A") { # added
2139 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
2140 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2141 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2142 $diffinfo->{'to_id'}) . " (new)" .
2143 "</div>\n"; # class="diff_info"
2145 } elsif ($diffinfo->{'status'} eq "D") { # deleted
2146 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
2147 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2148 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2149 $diffinfo->{'from_id'}) . " (deleted)" .
2150 "</div>\n"; # class="diff_info"
2152 } elsif ($diffinfo->{'status'} eq "R" || # renamed
2153 $diffinfo->{'status'} eq "C" || # copied
2154 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
2155 print "<div class=\"diff_info\">" .
2156 file_type
($diffinfo->{'from_mode'}) . ":" .
2157 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2158 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
2159 $diffinfo->{'from_id'}) .
2161 file_type
($diffinfo->{'to_mode'}) . ":" .
2162 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2163 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
2164 $diffinfo->{'to_id'});
2165 print "</div>\n"; # class="diff_info"
2167 } else { # modified, mode changed, ...
2168 print "<div class=\"diff_info\">" .
2169 file_type
($diffinfo->{'from_mode'}) . ":" .
2170 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2171 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2172 $diffinfo->{'from_id'}) .
2174 file_type
($diffinfo->{'to_mode'}) . ":" .
2175 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2176 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2177 $diffinfo->{'to_id'});
2178 print "</div>\n"; # class="diff_info"
2181 #print "<div class=\"diff extended_header\">\n";
2184 } # start of patch in patchset
2187 if ($in_header && $patch_line =~ m/^---/) {
2188 #print "</div>\n"; # class="diff extended_header"
2191 my $file = $diffinfo->{'from_file'};
2192 $file ||= $diffinfo->{'file'};
2193 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2194 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
2195 -class => "list"}, esc_html
($file));
2196 $patch_line =~ s
|a
/.*$|a/$file|g
;
2197 print "<div class=\"diff from_file\">$patch_line</div>\n";
2199 $patch_line = <$fd>;
2202 #$patch_line =~ m/^+++/;
2203 $file = $diffinfo->{'to_file'};
2204 $file ||= $diffinfo->{'file'};
2205 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2206 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
2207 -class => "list"}, esc_html
($file));
2208 $patch_line =~ s
|b
/.*|b/$file|g
;
2209 print "<div class=\"diff to_file\">$patch_line</div>\n";
2213 next LINE
if $in_header;
2215 print format_diff_line
($patch_line);
2217 print "</div>\n" if $patch_found; # class="patch"
2219 print "</div>\n"; # class="patchset"
2222 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2224 sub git_project_list_body
{
2225 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2227 my ($check_forks) = gitweb_check_feature
('forks');
2230 foreach my $pr (@$projlist) {
2231 my (@aa) = git_get_last_activity
($pr->{'path'});
2235 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2236 if (!defined $pr->{'descr'}) {
2237 my $descr = git_get_project_description
($pr->{'path'}) || "";
2238 $pr->{'descr'} = chop_str
($descr, 25, 5);
2240 if (!defined $pr->{'owner'}) {
2241 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2244 my $pname = $pr->{'path'};
2245 if (($pname =~ s/\.git$//) &&
2246 ($pname !~ /\/$/) &&
2247 (-d
"$projectroot/$pname")) {
2248 $pr->{'forks'} = "-d $projectroot/$pname";
2254 push @projects, $pr;
2257 $order ||= "project";
2258 $from = 0 unless defined $from;
2259 $to = $#projects if (!defined $to || $#projects < $to);
2261 print "<table class=\"project_list\">\n";
2262 unless ($no_header) {
2265 print "<th></th>\n";
2267 if ($order eq "project") {
2268 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2269 print "<th>Project</th>\n";
2272 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2273 -class => "header"}, "Project") .
2276 if ($order eq "descr") {
2277 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2278 print "<th>Description</th>\n";
2281 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2282 -class => "header"}, "Description") .
2285 if ($order eq "owner") {
2286 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2287 print "<th>Owner</th>\n";
2290 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2291 -class => "header"}, "Owner") .
2294 if ($order eq "age") {
2295 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2296 print "<th>Last Change</th>\n";
2299 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2300 -class => "header"}, "Last Change") .
2303 print "<th></th>\n" .
2307 for (my $i = $from; $i <= $to; $i++) {
2308 my $pr = $projects[$i];
2310 print "<tr class=\"dark\">\n";
2312 print "<tr class=\"light\">\n";
2317 if ($pr->{'forks'}) {
2318 print "<!-- $pr->{'forks'} -->\n";
2319 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2323 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2324 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2325 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2326 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2327 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2328 $pr->{'age_string'} . "</td>\n" .
2329 "<td class=\"link\">" .
2330 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2331 $cgi->a({-href
=> '/git-browser/by-commit.html?r='.$pr->{'path'}}, "graphiclog") . " | " .
2332 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2333 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2334 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
2338 if (defined $extra) {
2341 print "<td></td>\n";
2343 print "<td colspan=\"5\">$extra</td>\n" .
2349 sub git_shortlog_body
{
2350 # uses global variable $project
2351 my ($revlist, $from, $to, $refs, $extra) = @_;
2353 $from = 0 unless defined $from;
2354 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2356 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2358 for (my $i = $from; $i <= $to; $i++) {
2359 my $commit = $revlist->[$i];
2360 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2361 my $ref = format_ref_marker
($refs, $commit);
2362 my %co = parse_commit
($commit);
2364 print "<tr class=\"dark\">\n";
2366 print "<tr class=\"light\">\n";
2369 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2370 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2371 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2373 print format_subject_html
($co{'title'}, $co{'title_short'},
2374 href
(action
=>"commit", hash
=>$commit), $ref);
2376 "<td class=\"link\">" .
2377 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
2378 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2379 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2380 if (gitweb_have_snapshot
()) {
2381 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2386 if (defined $extra) {
2388 "<td colspan=\"4\">$extra</td>\n" .
2394 sub git_history_body
{
2395 # Warning: assumes constant type (blob or tree) during history
2396 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2398 $from = 0 unless defined $from;
2399 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2401 print "<table class=\"history\" cellspacing=\"0\">\n";
2403 for (my $i = $from; $i <= $to; $i++) {
2404 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2409 my %co = parse_commit
($commit);
2414 my $ref = format_ref_marker
($refs, $commit);
2417 print "<tr class=\"dark\">\n";
2419 print "<tr class=\"light\">\n";
2422 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2423 # shortlog uses chop_str($co{'author_name'}, 10)
2424 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2426 # originally git_history used chop_str($co{'title'}, 50)
2427 print format_subject_html
($co{'title'}, $co{'title_short'},
2428 href
(action
=>"commit", hash
=>$commit), $ref);
2430 "<td class=\"link\">" .
2431 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2432 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2434 if ($ftype eq 'blob') {
2435 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2436 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2437 if (defined $blob_current && defined $blob_parent &&
2438 $blob_current ne $blob_parent) {
2440 $cgi->a({-href
=> href
(action
=>"blobdiff",
2441 hash
=>$blob_current, hash_parent
=>$blob_parent,
2442 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2443 file_name
=>$file_name)},
2450 if (defined $extra) {
2452 "<td colspan=\"4\">$extra</td>\n" .
2459 # uses global variable $project
2460 my ($taglist, $from, $to, $extra) = @_;
2461 $from = 0 unless defined $from;
2462 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2464 print "<table class=\"tags\" cellspacing=\"0\">\n";
2466 for (my $i = $from; $i <= $to; $i++) {
2467 my $entry = $taglist->[$i];
2469 my $comment = $tag{'subject'};
2471 if (defined $comment) {
2472 $comment_short = chop_str
($comment, 30, 5);
2475 print "<tr class=\"dark\">\n";
2477 print "<tr class=\"light\">\n";
2480 print "<td><i>$tag{'age'}</i></td>\n" .
2482 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2483 -class => "list name"}, esc_html
($tag{'name'})) .
2486 if (defined $comment) {
2487 print format_subject_html
($comment, $comment_short,
2488 href
(action
=>"tag", hash
=>$tag{'id'}));
2491 "<td class=\"selflink\">";
2492 if ($tag{'type'} eq "tag") {
2493 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2498 "<td class=\"link\">" . " | " .
2499 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2500 if ($tag{'reftype'} eq "commit") {
2501 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2502 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
2503 } elsif ($tag{'reftype'} eq "blob") {
2504 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2509 if (defined $extra) {
2511 "<td colspan=\"5\">$extra</td>\n" .
2517 sub git_heads_body
{
2518 # uses global variable $project
2519 my ($headlist, $head, $from, $to, $extra) = @_;
2520 $from = 0 unless defined $from;
2521 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2523 print "<table class=\"heads\" cellspacing=\"0\">\n";
2525 for (my $i = $from; $i <= $to; $i++) {
2526 my $entry = $headlist->[$i];
2528 my $curr = $ref{'id'} eq $head;
2530 print "<tr class=\"dark\">\n";
2532 print "<tr class=\"light\">\n";
2535 print "<td><i>$ref{'age'}</i></td>\n" .
2536 ($curr ? "<td class=\"current_head\">" : "<td>") .
2537 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
2538 -class => "list name"},esc_html
($ref{'name'})) .
2540 "<td class=\"link\">" .
2541 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
2542 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
2543 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
2547 if (defined $extra) {
2549 "<td colspan=\"3\">$extra</td>\n" .
2555 ## ======================================================================
2556 ## ======================================================================
2559 sub git_project_list
{
2560 my $order = $cgi->param('o');
2561 if (defined $order && $order !~ m/project|descr|owner|age/) {
2562 die_error
(undef, "Unknown order parameter");
2565 my @list = git_get_projects_list
();
2567 die_error
(undef, "No projects found");
2571 if (-f
$home_text) {
2572 print "<div class=\"index_include\">\n";
2573 open (my $fd, $home_text);
2578 git_project_list_body
(\
@list, $order);
2583 my $order = $cgi->param('o');
2584 if (defined $order && $order !~ m/project|descr|owner|age/) {
2585 die_error
(undef, "Unknown order parameter");
2588 my @list = git_get_projects_list
($project);
2590 die_error
(undef, "No forks found");
2594 git_print_page_nav
('','');
2595 git_print_header_div
('summary', "$project forks");
2596 git_project_list_body
(\
@list, $order);
2600 sub git_project_index
{
2601 my @projects = git_get_projects_list
($project);
2604 -type
=> 'text/plain',
2605 -charset
=> 'utf-8',
2606 -content_disposition
=> 'inline; filename="index.aux"');
2608 foreach my $pr (@projects) {
2609 if (!exists $pr->{'owner'}) {
2610 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2613 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2614 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2615 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2616 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2620 print "$path $owner\n";
2625 my $descr = git_get_project_description
($project) || "none";
2626 my $head = git_get_head_hash
($project);
2627 my %co = parse_commit
($head);
2628 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2630 my $owner = git_get_project_owner
($project);
2632 my $refs = git_get_references
();
2633 my @taglist = git_get_tags_list
(15);
2634 my @headlist = git_get_heads_list
(15);
2636 my ($check_forks) = gitweb_check_feature
('forks');
2639 @forklist = git_get_projects_list
($project);
2643 git_print_page_nav
('summary','', $head);
2645 print "<div class=\"title\"> </div>\n";
2646 print "<table cellspacing=\"0\">\n" .
2647 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2648 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2649 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2650 # use per project git URL list in $projectroot/$project/cloneurl
2651 # or make project git URL from git base URL and project name
2652 my $url_tag = "URL";
2653 my @url_list = git_get_project_url_list
($project);
2654 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2655 foreach my $git_url (@url_list) {
2656 next unless $git_url;
2657 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2662 if (-s
"$projectroot/$project/README.html") {
2663 if (open my $fd, "$projectroot/$project/README.html") {
2664 print "<div class=\"title\">readme</div>\n";
2665 print $_ while (<$fd>);
2670 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2671 git_get_head_hash
($project), "--"
2672 or die_error
(undef, "Open git-rev-list failed");
2673 my @revlist = map { chomp; $_ } <$fd>;
2675 git_print_header_div
('shortlog');
2676 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2677 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2680 git_print_header_div
('tags');
2681 git_tags_body
(\
@taglist, 0, 15,
2682 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2686 git_print_header_div
('heads');
2687 git_heads_body
(\
@headlist, $head, 0, 15,
2688 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2692 git_print_header_div
('forks');
2693 git_project_list_body
(\
@forklist, undef, 0, 15,
2694 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
2702 my $head = git_get_head_hash
($project);
2704 git_print_page_nav
('','', $head,undef,$head);
2705 my %tag = parse_tag
($hash);
2706 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2707 print "<div class=\"title_text\">\n" .
2708 "<table cellspacing=\"0\">\n" .
2710 "<td>object</td>\n" .
2711 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2712 $tag{'object'}) . "</td>\n" .
2713 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2714 $tag{'type'}) . "</td>\n" .
2716 if (defined($tag{'author'})) {
2717 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2718 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2719 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2720 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2723 print "</table>\n\n" .
2725 print "<div class=\"page_body\">";
2726 my $comment = $tag{'comment'};
2727 foreach my $line (@$comment) {
2728 print esc_html
($line) . "<br/>\n";
2738 my ($have_blame) = gitweb_check_feature
('blame');
2740 die_error
('403 Permission denied', "Permission denied");
2742 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2743 $hash_base ||= git_get_head_hash
($project);
2744 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2745 my %co = parse_commit
($hash_base)
2746 or die_error
(undef, "Reading commit failed");
2747 if (!defined $hash) {
2748 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2749 or die_error
(undef, "Error looking up file");
2751 $ftype = git_get_type
($hash);
2752 if ($ftype !~ "blob") {
2753 die_error
("400 Bad Request", "Object is not a blob");
2755 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
2756 $file_name, $hash_base)
2757 or die_error
(undef, "Open git-blame failed");
2760 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2763 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2766 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2768 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2769 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2770 git_print_page_path
($file_name, $ftype, $hash_base);
2771 my @rev_color = (qw(light2 dark2));
2772 my $num_colors = scalar(@rev_color);
2773 my $current_color = 0;
2776 <div class="page_body">
2777 <table class="blame">
2778 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2783 last unless defined $_;
2784 my ($full_rev, $orig_lineno, $lineno, $group_size) =
2785 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
2786 if (!exists $metainfo{$full_rev}) {
2787 $metainfo{$full_rev} = {};
2789 my $meta = $metainfo{$full_rev};
2792 if (/^(\S+) (.*)$/) {
2797 my $rev = substr($full_rev, 0, 8);
2798 my $author = $meta->{'author'};
2799 my %date = parse_date
($meta->{'author-time'},
2800 $meta->{'author-tz'});
2801 my $date = $date{'iso-tz'};
2803 $current_color = ++$current_color % $num_colors;
2805 print "<tr class=\"$rev_color[$current_color]\">\n";
2807 print "<td class=\"sha1\"";
2808 print " title=\"". esc_html
($author) . ", $date\"";
2809 print " rowspan=\"$group_size\"" if ($group_size > 1);
2811 print $cgi->a({-href
=> href
(action
=>"commit",
2813 file_name
=>$file_name)},
2817 my $blamed = href
(action
=> 'blame',
2818 file_name
=> $meta->{'filename'},
2819 hash_base
=> $full_rev);
2820 print "<td class=\"linenr\">";
2821 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
2823 -class => "linenr" },
2826 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2832 or print "Reading blob failed\n";
2839 my ($have_blame) = gitweb_check_feature
('blame');
2841 die_error
('403 Permission denied', "Permission denied");
2843 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2844 $hash_base ||= git_get_head_hash
($project);
2845 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2846 my %co = parse_commit
($hash_base)
2847 or die_error
(undef, "Reading commit failed");
2848 if (!defined $hash) {
2849 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2850 or die_error
(undef, "Error lookup file");
2852 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2853 or die_error
(undef, "Open git-annotate failed");
2856 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2859 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2862 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2864 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2865 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2866 git_print_page_path
($file_name, 'blob', $hash_base);
2867 print "<div class=\"page_body\">\n";
2869 <table class="blame">
2878 my @line_class = (qw(light dark));
2879 my $line_class_len = scalar (@line_class);
2880 my $line_class_num = $#line_class;
2881 while (my $line = <$fd>) {
2893 $line_class_num = ($line_class_num + 1) % $line_class_len;
2895 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2902 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
2905 $short_rev = substr ($long_rev, 0, 8);
2906 $age = time () - $time;
2907 $age_str = age_string
($age);
2908 $age_str =~ s/ / /g;
2909 $age_class = age_class
($age);
2910 $author = esc_html
($author);
2911 $author =~ s/ / /g;
2913 $data = untabify
($data);
2914 $data = esc_html
($data);
2917 <tr class="$line_class[$line_class_num]">
2918 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2919 <td class="$age_class">$age_str</td>
2921 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2922 <td class="pre">$data</td>
2925 } # while (my $line = <$fd>)
2926 print "</table>\n\n";
2928 or print "Reading blob failed.\n";
2934 my $head = git_get_head_hash
($project);
2936 git_print_page_nav
('','', $head,undef,$head);
2937 git_print_header_div
('summary', $project);
2939 my @tagslist = git_get_tags_list
();
2941 git_tags_body
(\
@tagslist);
2947 my $head = git_get_head_hash
($project);
2949 git_print_page_nav
('','', $head,undef,$head);
2950 git_print_header_div
('summary', $project);
2952 my @headslist = git_get_heads_list
();
2954 git_heads_body
(\
@headslist, $head);
2959 sub git_blob_plain
{
2962 if (!defined $hash) {
2963 if (defined $file_name) {
2964 my $base = $hash_base || git_get_head_hash
($project);
2965 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2966 or die_error
(undef, "Error lookup file");
2968 die_error
(undef, "No file name defined");
2970 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2971 # blobs defined by non-textual hash id's can be cached
2976 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2977 or die_error
(undef, "Couldn't cat $file_name, $hash");
2979 $type ||= blob_mimetype
($fd, $file_name);
2981 # save as filename, even when no $file_name is given
2982 my $save_as = "$hash";
2983 if (defined $file_name) {
2984 $save_as = $file_name;
2985 } elsif ($type =~ m/^text\//) {
2992 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
2994 binmode STDOUT
, ':raw';
2996 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3004 if (!defined $hash) {
3005 if (defined $file_name) {
3006 my $base = $hash_base || git_get_head_hash
($project);
3007 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3008 or die_error
(undef, "Error lookup file");
3010 die_error
(undef, "No file name defined");
3012 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3013 # blobs defined by non-textual hash id's can be cached
3017 my ($have_blame) = gitweb_check_feature
('blame');
3018 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3019 or die_error
(undef, "Couldn't cat $file_name, $hash");
3020 my $mimetype = blob_mimetype
($fd, $file_name);
3021 if ($mimetype !~ m/^text\//) {
3023 return git_blob_plain
($mimetype);
3025 git_header_html
(undef, $expires);
3026 my $formats_nav = '';
3027 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3028 if (defined $file_name) {
3031 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3032 hash
=>$hash, file_name
=>$file_name)},
3037 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3038 hash
=>$hash, file_name
=>$file_name)},
3041 $cgi->a({-href
=> href
(action
=>"blob_plain",
3042 hash
=>$hash, file_name
=>$file_name)},
3045 $cgi->a({-href
=> href
(action
=>"blob",
3046 hash_base
=>"HEAD", file_name
=>$file_name)},
3050 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3052 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3053 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3055 print "<div class=\"page_nav\">\n" .
3056 "<br/><br/></div>\n" .
3057 "<div class=\"title\">$hash</div>\n";
3059 git_print_page_path
($file_name, "blob", $hash_base);
3060 print "<div class=\"page_body\">\n";
3062 while (my $line = <$fd>) {
3065 $line = untabify
($line);
3066 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3067 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3070 or print "Reading blob failed.\n";
3076 my $have_snapshot = gitweb_have_snapshot
();
3078 if (!defined $hash_base) {
3079 $hash_base = "HEAD";
3081 if (!defined $hash) {
3082 if (defined $file_name) {
3083 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3089 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3090 or die_error
(undef, "Open git-ls-tree failed");
3091 my @entries = map { chomp; $_ } <$fd>;
3092 close $fd or die_error
(undef, "Reading tree failed");
3095 my $refs = git_get_references
();
3096 my $ref = format_ref_marker
($refs, $hash_base);
3099 my ($have_blame) = gitweb_check_feature
('blame');
3100 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3102 if (defined $file_name) {
3104 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3105 hash
=>$hash, file_name
=>$file_name)},
3107 $cgi->a({-href
=> href
(action
=>"tree",
3108 hash_base
=>"HEAD", file_name
=>$file_name)},
3111 if ($have_snapshot) {
3112 # FIXME: Should be available when we have no hash base as well.
3114 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3117 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3118 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3121 print "<div class=\"page_nav\">\n";
3122 print "<br/><br/></div>\n";
3123 print "<div class=\"title\">$hash</div>\n";
3125 if (defined $file_name) {
3126 $basedir = $file_name;
3127 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3131 git_print_page_path
($file_name, 'tree', $hash_base);
3132 print "<div class=\"page_body\">\n";
3133 print "<table cellspacing=\"0\">\n";
3135 # '..' (top directory) link if possible
3136 if (defined $hash_base &&
3137 defined $file_name && $file_name =~ m![^/]+$!) {
3139 print "<tr class=\"dark\">\n";
3141 print "<tr class=\"light\">\n";
3145 my $up = $file_name;
3146 $up =~ s!/?[^/]+$!!;
3147 undef $up unless $up;
3148 # based on git_print_tree_entry
3149 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3150 print '<td class="list">';
3151 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3155 print "<td class=\"link\"></td>\n";
3159 foreach my $line (@entries) {
3160 my %t = parse_ls_tree_line
($line, -z
=> 1);
3163 print "<tr class=\"dark\">\n";
3165 print "<tr class=\"light\">\n";
3169 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3173 print "</table>\n" .
3179 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3180 my $have_snapshot = (defined $ctype && defined $suffix);
3181 if (!$have_snapshot) {
3182 die_error
('403 Permission denied', "Permission denied");
3185 if (!defined $hash) {
3186 $hash = git_get_head_hash
($project);
3189 my $filename = basename
($project) . "-$hash.tar.$suffix";
3192 -type
=> 'application/x-tar',
3193 -content_encoding
=> $ctype,
3194 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3195 -status
=> '200 OK');
3197 my $git = git_cmd_str
();
3198 my $name = $project;
3199 $name =~ s/\047/\047\\\047\047/g;
3201 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3202 or die_error
(undef, "Execute git-tar-tree failed.");
3203 binmode STDOUT
, ':raw';
3205 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3211 my $head = git_get_head_hash
($project);
3212 if (!defined $hash) {
3215 if (!defined $page) {
3218 my $refs = git_get_references
();
3220 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3221 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash, "--"
3222 or die_error
(undef, "Open git-rev-list failed");
3223 my @revlist = map { chomp; $_ } <$fd>;
3226 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
3229 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3232 my %co = parse_commit
($hash);
3234 git_print_header_div
('summary', $project);
3235 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3237 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
3238 my $commit = $revlist[$i];
3239 my $ref = format_ref_marker
($refs, $commit);
3240 my %co = parse_commit
($commit);
3242 my %ad = parse_date
($co{'author_epoch'});
3243 git_print_header_div
('commit',
3244 "<span class=\"age\">$co{'age_string'}</span>" .
3245 esc_html
($co{'title'}) . $ref,
3247 print "<div class=\"title_text\">\n" .
3248 "<div class=\"log_link\">\n" .
3249 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3251 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3253 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3256 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3259 print "<div class=\"log_body\">\n";
3260 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
3267 my %co = parse_commit
($hash);
3269 die_error
(undef, "Unknown commit object");
3271 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3272 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3274 my $parent = $co{'parent'};
3275 if (!defined $parent) {
3278 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
3279 @diff_opts, $parent, $hash, "--"
3280 or die_error
(undef, "Open git-diff-tree failed");
3281 my @difftree = map { chomp; $_ } <$fd>;
3282 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3284 # non-textual hash id's can be cached
3286 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3289 my $refs = git_get_references
();
3290 my $ref = format_ref_marker
($refs, $co{'id'});
3292 my $have_snapshot = gitweb_have_snapshot
();
3295 if (defined $file_name && defined $co{'parent'}) {
3297 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
3300 git_header_html
(undef, $expires);
3301 git_print_page_nav
('commit', '',
3302 $hash, $co{'tree'}, $hash,
3303 join (' | ', @views_nav));
3305 if (defined $co{'parent'}) {
3306 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3308 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3310 print "<div class=\"title_text\">\n" .
3311 "<table cellspacing=\"0\">\n";
3312 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3314 "<td></td><td> $ad{'rfc2822'}";
3315 if ($ad{'hour_local'} < 6) {
3316 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3317 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3319 printf(" (%02d:%02d %s)",
3320 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3324 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3325 print "<tr><td></td><td> $cd{'rfc2822'}" .
3326 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3328 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3331 "<td class=\"sha1\">" .
3332 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3333 class => "list"}, $co{'tree'}) .
3335 "<td class=\"link\">" .
3336 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3338 if ($have_snapshot) {
3340 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3344 my $parents = $co{'parents'};
3345 foreach my $par (@$parents) {
3348 "<td class=\"sha1\">" .
3349 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3350 class => "list"}, $par) .
3352 "<td class=\"link\">" .
3353 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3355 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3362 print "<div class=\"page_body\">\n";
3363 git_print_log
($co{'comment'});
3366 git_difftree_body
(\
@difftree, $hash, $parent);
3372 my $format = shift || 'html';
3379 # preparing $fd and %diffinfo for git_patchset_body
3381 if (defined $hash_base && defined $hash_parent_base) {
3382 if (defined $file_name) {
3384 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3385 $hash_parent_base, $hash_base,
3387 or die_error
(undef, "Open git-diff-tree failed");
3388 @difftree = map { chomp; $_ } <$fd>;
3390 or die_error
(undef, "Reading git-diff-tree failed");
3392 or die_error
('404 Not Found', "Blob diff not found");
3394 } elsif (defined $hash &&
3395 $hash =~ /[0-9a-fA-F]{40}/) {
3396 # try to find filename from $hash
3398 # read filtered raw output
3399 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3400 $hash_parent_base, $hash_base, "--"
3401 or die_error
(undef, "Open git-diff-tree failed");
3403 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3405 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3406 map { chomp; $_ } <$fd>;
3408 or die_error
(undef, "Reading git-diff-tree failed");
3410 or die_error
('404 Not Found', "Blob diff not found");
3413 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3416 if (@difftree > 1) {
3417 die_error
('404 Not Found', "Ambiguous blob diff specification");
3420 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3421 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3422 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3424 $hash_parent ||= $diffinfo{'from_id'};
3425 $hash ||= $diffinfo{'to_id'};
3427 # non-textual hash id's can be cached
3428 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3429 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3434 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3435 '-p', $hash_parent_base, $hash_base,
3437 or die_error
(undef, "Open git-diff-tree failed");
3440 # old/legacy style URI
3441 if (!%diffinfo && # if new style URI failed
3442 defined $hash && defined $hash_parent) {
3443 # fake git-diff-tree raw output
3444 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3445 $diffinfo{'from_id'} = $hash_parent;
3446 $diffinfo{'to_id'} = $hash;
3447 if (defined $file_name) {
3448 if (defined $file_parent) {
3449 $diffinfo{'status'} = '2';
3450 $diffinfo{'from_file'} = $file_parent;
3451 $diffinfo{'to_file'} = $file_name;
3452 } else { # assume not renamed
3453 $diffinfo{'status'} = '1';
3454 $diffinfo{'from_file'} = $file_name;
3455 $diffinfo{'to_file'} = $file_name;
3457 } else { # no filename given
3458 $diffinfo{'status'} = '2';
3459 $diffinfo{'from_file'} = $hash_parent;
3460 $diffinfo{'to_file'} = $hash;
3463 # non-textual hash id's can be cached
3464 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3465 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3470 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts,
3471 $hash_parent, $hash, "--"
3472 or die_error
(undef, "Open git-diff failed");
3474 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3479 if ($format eq 'html') {
3481 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3482 hash
=>$hash, hash_parent
=>$hash_parent,
3483 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3484 file_name
=>$file_name, file_parent
=>$file_parent)},
3486 git_header_html
(undef, $expires);
3487 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3488 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3489 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3491 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3492 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3494 if (defined $file_name) {
3495 git_print_page_path
($file_name, "blob", $hash_base);
3497 print "<div class=\"page_path\"></div>\n";
3500 } elsif ($format eq 'plain') {
3502 -type
=> 'text/plain',
3503 -charset
=> 'utf-8',
3504 -expires
=> $expires,
3505 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3507 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3510 die_error
(undef, "Unknown blobdiff format");
3514 if ($format eq 'html') {
3515 print "<div class=\"page_body\">\n";
3517 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3520 print "</div>\n"; # class="page_body"
3524 while (my $line = <$fd>) {
3525 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_html($diffinfo{'from_file'})!eg;
3526 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_html($diffinfo{'to_file'})!eg;
3530 last if $line =~ m!^\+\+\+!;
3538 sub git_blobdiff_plain
{
3539 git_blobdiff
('plain');
3542 sub git_commitdiff
{
3543 my $format = shift || 'html';
3544 my %co = parse_commit
($hash);
3546 die_error
(undef, "Unknown commit object");
3549 # we need to prepare $formats_nav before any parameter munging
3551 if ($format eq 'html') {
3553 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3554 hash
=>$hash, hash_parent
=>$hash_parent)},
3557 if (defined $hash_parent) {
3558 # commitdiff with two commits given
3559 my $hash_parent_short = $hash_parent;
3560 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3561 $hash_parent_short = substr($hash_parent, 0, 7);
3565 $cgi->a({-href
=> href
(action
=>"commitdiff",
3566 hash
=>$hash_parent)},
3567 esc_html
($hash_parent_short)) .
3569 } elsif (!$co{'parent'}) {
3571 $formats_nav .= ' (initial)';
3572 } elsif (scalar @{$co{'parents'}} == 1) {
3573 # single parent commit
3576 $cgi->a({-href
=> href
(action
=>"commitdiff",
3577 hash
=>$co{'parent'})},
3578 esc_html
(substr($co{'parent'}, 0, 7))) .
3585 $cgi->a({-href
=> href
(action
=>"commitdiff",
3587 esc_html
(substr($_, 0, 7)));
3588 } @{$co{'parents'}} ) .
3593 if (!defined $hash_parent) {
3594 $hash_parent = $co{'parent'} || '--root';
3600 if ($format eq 'html') {
3601 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3602 "--no-commit-id", "--patch-with-raw", "--full-index",
3603 $hash_parent, $hash, "--"
3604 or die_error
(undef, "Open git-diff-tree failed");
3606 while (chomp(my $line = <$fd>)) {
3607 # empty line ends raw part of diff-tree output
3609 push @difftree, $line;
3612 } elsif ($format eq 'plain') {
3613 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3614 '-p', $hash_parent, $hash, "--"
3615 or die_error
(undef, "Open git-diff-tree failed");
3618 die_error
(undef, "Unknown commitdiff format");
3621 # non-textual hash id's can be cached
3623 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3627 # write commit message
3628 if ($format eq 'html') {
3629 my $refs = git_get_references
();
3630 my $ref = format_ref_marker
($refs, $co{'id'});
3632 git_header_html
(undef, $expires);
3633 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3634 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3635 git_print_authorship
(\
%co);
3636 print "<div class=\"page_body\">\n";
3637 if (@{$co{'comment'}} > 1) {
3638 print "<div class=\"log\">\n";
3639 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
3640 print "</div>\n"; # class="log"
3643 } elsif ($format eq 'plain') {
3644 my $refs = git_get_references
("tags");
3645 my $tagname = git_get_rev_name_tags
($hash);
3646 my $filename = basename
($project) . "-$hash.patch";
3649 -type
=> 'text/plain',
3650 -charset
=> 'utf-8',
3651 -expires
=> $expires,
3652 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3653 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3656 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3657 Subject: $co{'title'}
3659 print "X-Git-Tag: $tagname\n" if $tagname;
3660 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3662 foreach my $line (@{$co{'comment'}}) {
3669 if ($format eq 'html') {
3670 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3673 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3675 print "</div>\n"; # class="page_body"
3678 } elsif ($format eq 'plain') {
3682 or print "Reading git-diff-tree failed\n";
3686 sub git_commitdiff_plain
{
3687 git_commitdiff
('plain');
3691 if (!defined $hash_base) {
3692 $hash_base = git_get_head_hash
($project);
3694 if (!defined $page) {
3698 my %co = parse_commit
($hash_base);
3700 die_error
(undef, "Unknown commit object");
3703 my $refs = git_get_references
();
3704 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3706 if (!defined $hash && defined $file_name) {
3707 $hash = git_get_hash_by_path
($hash_base, $file_name);
3709 if (defined $hash) {
3710 $ftype = git_get_type
($hash);
3714 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3715 or die_error
(undef, "Open git-rev-list-failed");
3716 my @revlist = map { chomp; $_ } <$fd>;
3718 or die_error
(undef, "Reading git-rev-list failed");
3720 my $paging_nav = '';
3723 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3724 file_name
=>$file_name)},
3726 $paging_nav .= " ⋅ " .
3727 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3728 file_name
=>$file_name, page
=>$page-1),
3729 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3731 $paging_nav .= "first";
3732 $paging_nav .= " ⋅ prev";
3734 if ($#revlist >= (100 * ($page+1)-1)) {
3735 $paging_nav .= " ⋅ " .
3736 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3737 file_name
=>$file_name, page
=>$page+1),
3738 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3740 $paging_nav .= " ⋅ next";
3743 if ($#revlist >= (100 * ($page+1)-1)) {
3745 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3746 file_name
=>$file_name, page
=>$page+1),
3747 -title
=> "Alt-n"}, "next");
3751 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3752 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3753 git_print_page_path
($file_name, $ftype, $hash_base);
3755 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3756 $refs, $hash_base, $ftype, $next_link);
3762 if (!defined $searchtext) {
3763 die_error
(undef, "Text field empty");
3765 if (!defined $hash) {
3766 $hash = git_get_head_hash
($project);
3768 my %co = parse_commit
($hash);
3770 die_error
(undef, "Unknown commit object");
3773 $searchtype ||= 'commit';
3774 if ($searchtype eq 'pickaxe') {
3775 # pickaxe may take all resources of your box and run for several minutes
3776 # with every query - so decide by yourself how public you make this feature
3777 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3778 if (!$have_pickaxe) {
3779 die_error
('403 Permission denied', "Permission denied");
3784 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3785 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3787 print "<table cellspacing=\"0\">\n";
3789 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
3791 open my $fd, "-|", git_cmd
(), "rev-list",
3792 "--header", "--parents", $hash, "--"
3794 while (my $commit_text = <$fd>) {
3795 if (!grep m/$searchtext/i, $commit_text) {
3798 if ($searchtype eq 'author' && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3801 if ($searchtype eq 'committer' && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3804 my @commit_lines = split "\n", $commit_text;
3805 my %co = parse_commit
(undef, \
@commit_lines);
3810 print "<tr class=\"dark\">\n";
3812 print "<tr class=\"light\">\n";
3815 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3816 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3818 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3819 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3820 my $comment = $co{'comment'};
3821 foreach my $line (@$comment) {
3822 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3823 my $lead = esc_html
($1) || "";
3824 $lead = chop_str
($lead, 30, 10);
3825 my $match = esc_html
($2) || "";
3826 my $trail = esc_html
($3) || "";
3827 $trail = chop_str
($trail, 30, 10);
3828 my $text = "$lead<span class=\"match\">$match</span>$trail";
3829 print chop_str
($text, 80, 5) . "<br/>\n";
3833 "<td class=\"link\">" .
3834 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3836 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3843 if ($searchtype eq 'pickaxe') {
3845 my $git_command = git_cmd_str
();
3846 open my $fd, "-|", "$git_command rev-list $hash | " .
3847 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3850 while (my $line = <$fd>) {
3851 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3854 $set{'from_id'} = $3;
3856 $set{'id'} = $set{'to_id'};
3857 if ($set{'id'} =~ m/0{40}/) {
3858 $set{'id'} = $set{'from_id'};
3860 if ($set{'id'} =~ m/0{40}/) {
3864 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3867 print "<tr class=\"dark\">\n";
3869 print "<tr class=\"light\">\n";
3872 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3873 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3875 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3876 -class => "list subject"},
3877 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3878 while (my $setref = shift @files) {
3880 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3881 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3883 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3887 "<td class=\"link\">" .
3888 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3890 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3894 %co = parse_commit
($1);
3903 sub git_search_help
{
3905 git_print_page_nav
('','', $hash,$hash,$hash);
3908 <dt><b>commit</b></dt>
3909 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
3910 <dt><b>author</b></dt>
3911 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
3912 <dt><b>committer</b></dt>
3913 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
3915 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3916 if ($have_pickaxe) {
3918 <dt><b>pickaxe</b></dt>
3919 <dd>All commits that caused the string to appear or disappear from any file (changes that
3920 added, removed or "modified" the string) will be listed. This search can take a while and
3921 takes a lot of strain on the server, so please use it wisely.</dd>
3929 my $head = git_get_head_hash
($project);
3930 if (!defined $hash) {
3933 if (!defined $page) {
3936 my $refs = git_get_references
();
3938 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3939 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash, "--"
3940 or die_error
(undef, "Open git-rev-list failed");
3941 my @revlist = map { chomp; $_ } <$fd>;
3944 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3946 if ($#revlist >= (100 * ($page+1)-1)) {
3948 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3949 -title
=> "Alt-n"}, "next");
3954 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3955 git_print_header_div
('summary', $project);
3957 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3962 ## ......................................................................
3963 ## feeds (RSS, OPML)
3966 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3967 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150",
3968 git_get_head_hash
($project), "--"
3969 or die_error
(undef, "Open git-rev-list failed");
3970 my @revlist = map { chomp; $_ } <$fd>;
3971 close $fd or die_error
(undef, "Reading git-rev-list failed");
3972 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3974 <?xml version="1.0" encoding="utf-8"?>
3975 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3977 <title>$project $my_uri $my_url</title>
3978 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3979 <description>$project log</description>
3980 <language>en</language>
3983 for (my $i = 0; $i <= $#revlist; $i++) {
3984 my $commit = $revlist[$i];
3985 my %co = parse_commit
($commit);
3986 # we read 150, we always show 30 and the ones more recent than 48 hours
3987 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3990 my %cd = parse_date
($co{'committer_epoch'});
3991 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3992 $co{'parent'}, $co{'id'}, "--"
3994 my @difftree = map { chomp; $_ } <$fd>;
3999 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
4001 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
4002 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
4003 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
4004 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
4005 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
4006 "<content:encoded>" .
4008 my $comment = $co{'comment'};
4009 foreach my $line (@$comment) {
4010 $line = to_utf8
($line);
4011 print "$line<br/>\n";
4014 foreach my $line (@difftree) {
4015 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
4018 my $file = esc_html
(unquote
($7));
4019 $file = to_utf8
($file);
4020 print "$file<br/>\n";
4023 "</content:encoded>\n" .
4026 print "</channel></rss>";
4030 my @list = git_get_projects_list
();
4032 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
4034 <?xml version="1.0" encoding="utf-8"?>
4035 <opml version="1.0">
4037 <title>$site_name OPML Export</title>
4040 <outline text="git RSS feeds">
4043 foreach my $pr (@list) {
4045 my $head = git_get_head_hash
($proj{'path'});
4046 if (!defined $head) {
4049 $git_dir = "$projectroot/$proj{'path'}";
4050 my %co = parse_commit
($head);
4055 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
4056 my $rss = "$my_url?p=$proj{'path'};a=rss";
4057 my $html = "$my_url?p=$proj{'path'};a=summary";
4058 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";