3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 our $version = "++GIT_VERSION++";
23 our $my_url = $cgi->url();
24 our $my_uri = $cgi->url(-absolute
=> 1);
26 # core git executable to use
27 # this can just be "git" if your webserver has a sensible PATH
28 our $GIT = "++GIT_BINDIR++/git";
30 # absolute fs-path which will be prepended to the project path
31 #our $projectroot = "/pub/scm";
32 our $projectroot = "++GITWEB_PROJECTROOT++";
34 # target of the home link on top of all pages
35 our $home_link = $my_uri || "/";
37 # string of the home link on top of all pages
38 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
40 # name of your site or organization to appear in page titles
41 # replace this with something more descriptive for clearer bookmarks
42 our $site_name = "++GITWEB_SITENAME++"
43 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
45 # filename of html text to include at top of each page
46 our $site_header = "++GITWEB_SITE_HEADER++";
47 # html text to include at home page
48 our $home_text = "++GITWEB_HOMETEXT++";
49 # filename of html text to include at bottom of each page
50 our $site_footer = "++GITWEB_SITE_FOOTER++";
53 our @stylesheets = ("++GITWEB_CSS++");
54 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
55 our $stylesheet = undef;
57 # URI of GIT logo (72x27 size)
58 our $logo = "++GITWEB_LOGO++";
59 # URI of GIT favicon, assumed to be image/png type
60 our $favicon = "++GITWEB_FAVICON++";
62 # URI and label (title) of GIT logo link
63 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
64 #our $logo_label = "git documentation";
65 our $logo_url = "http://git.or.cz/";
66 our $logo_label = "git homepage";
68 # source of projects list
69 our $projects_list = "++GITWEB_LIST++";
71 # show repository only if this file exists
72 # (only effective if this variable evaluates to true)
73 our $export_ok = "++GITWEB_EXPORT_OK++";
75 # only allow viewing of repositories also shown on the overview page
76 our $strict_export = "++GITWEB_STRICT_EXPORT++";
78 # list of git base URLs used for URL to where fetch project from,
79 # i.e. full URL is "$git_base_url/$project"
80 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
82 # default blob_plain mimetype and default charset for text/plain blob
83 our $default_blob_plain_mimetype = 'text/plain';
84 our $default_text_plain_charset = undef;
86 # file to use for guessing MIME types before trying /etc/mime.types
87 # (relative to the current git repository)
88 our $mimetypes_file = undef;
90 # You define site-wide feature defaults here; override them with
91 # $GITWEB_CONFIG as necessary.
94 # 'sub' => feature-sub (subroutine),
95 # 'override' => allow-override (boolean),
96 # 'default' => [ default options...] (array reference)}
98 # if feature is overridable (it means that allow-override has true value,
99 # then feature-sub will be called with default options as parameters;
100 # return value of feature-sub indicates if to enable specified feature
102 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
104 # Enable the 'blame' blob view, showing the last commit that modified
105 # each line in the file. This can be very CPU-intensive.
107 # To enable system wide have in $GITWEB_CONFIG
108 # $feature{'blame'}{'default'} = [1];
109 # To have project specific config enable override in $GITWEB_CONFIG
110 # $feature{'blame'}{'override'} = 1;
111 # and in project config gitweb.blame = 0|1;
113 'sub' => \
&feature_blame
,
117 # Enable the 'snapshot' link, providing a compressed tarball of any
118 # tree. This can potentially generate high traffic if you have large
121 # To disable system wide have in $GITWEB_CONFIG
122 # $feature{'snapshot'}{'default'} = [undef];
123 # To have project specific config enable override in $GITWEB_CONFIG
124 # $feature{'blame'}{'override'} = 1;
125 # and in project config gitweb.snapshot = none|gzip|bzip2;
127 'sub' => \
&feature_snapshot
,
129 # => [content-encoding, suffix, program]
130 'default' => ['x-gzip', 'gz', 'gzip']},
132 # Enable the pickaxe search, which will list the commits that modified
133 # a given string in a file. This can be practical and quite faster
134 # alternative to 'blame', but still potentially CPU-intensive.
136 # To enable system wide have in $GITWEB_CONFIG
137 # $feature{'pickaxe'}{'default'} = [1];
138 # To have project specific config enable override in $GITWEB_CONFIG
139 # $feature{'pickaxe'}{'override'} = 1;
140 # and in project config gitweb.pickaxe = 0|1;
142 'sub' => \
&feature_pickaxe
,
146 # Make gitweb use an alternative format of the URLs which can be
147 # more readable and natural-looking: project name is embedded
148 # directly in the path and the query string contains other
149 # auxiliary information. All gitweb installations recognize
150 # URL in either format; this configures in which formats gitweb
153 # To enable system wide have in $GITWEB_CONFIG
154 # $feature{'pathinfo'}{'default'} = [1];
155 # Project specific override is not supported.
157 # Note that you will need to change the default location of CSS,
158 # favicon, logo and possibly other files to an absolute URL. Also,
159 # if gitweb.cgi serves as your indexfile, you will need to force
160 # $my_uri to contain the script name in your $GITWEB_CONFIG.
165 # Make gitweb consider projects in project root subdirectories
166 # to be forks of existing projects. Given project $projname.git,
167 # projects matching $projname/*.git will not be shown in the main
168 # projects list, instead a '+' mark will be added to $projname
169 # there and a 'forks' view will be enabled for the project, listing
170 # all the forks. This feature is supported only if project list
171 # is taken from a directory, not file.
173 # To enable system wide have in $GITWEB_CONFIG
174 # $feature{'forks'}{'default'} = [1];
175 # Project specific override is not supported.
181 sub gitweb_check_feature
{
183 return unless exists $feature{$name};
184 my ($sub, $override, @defaults) = (
185 $feature{$name}{'sub'},
186 $feature{$name}{'override'},
187 @{$feature{$name}{'default'}});
188 if (!$override) { return @defaults; }
190 warn "feature $name is not overrideable";
193 return $sub->(@defaults);
197 my ($val) = git_get_project_config
('blame', '--bool');
199 if ($val eq 'true') {
201 } elsif ($val eq 'false') {
208 sub feature_snapshot
{
209 my ($ctype, $suffix, $command) = @_;
211 my ($val) = git_get_project_config
('snapshot');
213 if ($val eq 'gzip') {
214 return ('x-gzip', 'gz', 'gzip');
215 } elsif ($val eq 'bzip2') {
216 return ('x-bzip2', 'bz2', 'bzip2');
217 } elsif ($val eq 'none') {
221 return ($ctype, $suffix, $command);
224 sub gitweb_have_snapshot
{
225 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
226 my $have_snapshot = (defined $ctype && defined $suffix);
228 return $have_snapshot;
231 sub feature_pickaxe
{
232 my ($val) = git_get_project_config
('pickaxe', '--bool');
234 if ($val eq 'true') {
236 } elsif ($val eq 'false') {
243 # checking HEAD file with -e is fragile if the repository was
244 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
246 sub check_head_link
{
248 my $headfile = "$dir/HEAD";
249 return ((-e
$headfile) ||
250 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
253 sub check_export_ok
{
255 return (check_head_link
($dir) &&
256 (!$export_ok || -e
"$dir/$export_ok"));
259 # rename detection options for git-diff and git-diff-tree
260 # - default is '-M', with the cost proportional to
261 # (number of removed files) * (number of new files).
262 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
263 # (number of changed files + number of removed files) * (number of new files)
264 # - even more costly is '-C', '--find-copies-harder' with cost
265 # (number of files in the original tree) * (number of new files)
266 # - one might want to include '-B' option, e.g. '-B', '-M'
267 our @diff_opts = ('-M'); # taken from git_commit
269 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
270 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
272 # version of the core git binary
273 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
275 $projects_list ||= $projectroot;
277 # ======================================================================
278 # input validation and dispatch
279 our $action = $cgi->param('a');
280 if (defined $action) {
281 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
282 die_error
(undef, "Invalid action parameter");
286 # parameters which are pathnames
287 our $project = $cgi->param('p');
288 if (defined $project) {
289 if (!validate_pathname
($project) ||
290 !(-d
"$projectroot/$project") ||
291 !check_head_link
("$projectroot/$project") ||
292 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
293 ($strict_export && !project_in_list
($project))) {
295 die_error
(undef, "No such project");
299 our $file_name = $cgi->param('f');
300 if (defined $file_name) {
301 if (!validate_pathname
($file_name)) {
302 die_error
(undef, "Invalid file parameter");
306 our $file_parent = $cgi->param('fp');
307 if (defined $file_parent) {
308 if (!validate_pathname
($file_parent)) {
309 die_error
(undef, "Invalid file parent parameter");
313 # parameters which are refnames
314 our $hash = $cgi->param('h');
316 if (!validate_refname
($hash)) {
317 die_error
(undef, "Invalid hash parameter");
321 our $hash_parent = $cgi->param('hp');
322 if (defined $hash_parent) {
323 if (!validate_refname
($hash_parent)) {
324 die_error
(undef, "Invalid hash parent parameter");
328 our $hash_base = $cgi->param('hb');
329 if (defined $hash_base) {
330 if (!validate_refname
($hash_base)) {
331 die_error
(undef, "Invalid hash base parameter");
335 our $hash_parent_base = $cgi->param('hpb');
336 if (defined $hash_parent_base) {
337 if (!validate_refname
($hash_parent_base)) {
338 die_error
(undef, "Invalid hash parent base parameter");
343 our $page = $cgi->param('pg');
345 if ($page =~ m/[^0-9]/) {
346 die_error
(undef, "Invalid page parameter");
350 our $searchtext = $cgi->param('s');
351 if (defined $searchtext) {
352 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
353 die_error
(undef, "Invalid search parameter");
355 $searchtext = quotemeta $searchtext;
358 our $searchtype = $cgi->param('st');
359 if (defined $searchtype) {
360 if ($searchtype =~ m/[^a-z]/) {
361 die_error
(undef, "Invalid searchtype parameter");
365 # now read PATH_INFO and use it as alternative to parameters
366 sub evaluate_path_info
{
367 return if defined $project;
368 my $path_info = $ENV{"PATH_INFO"};
369 return if !$path_info;
370 $path_info =~ s
,^/+,,;
371 return if !$path_info;
372 # find which part of PATH_INFO is project
373 $project = $path_info;
375 while ($project && !check_head_link
("$projectroot/$project")) {
376 $project =~ s
,/*[^/]*$,,;
379 $project = validate_pathname
($project);
381 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
382 ($strict_export && !project_in_list
($project))) {
386 # do not change any parameters if an action is given using the query string
388 $path_info =~ s
,^$project/*,,;
389 my ($refname, $pathname) = split(/:/, $path_info, 2);
390 if (defined $pathname) {
391 # we got "project.git/branch:filename" or "project.git/branch:dir/"
392 # we could use git_get_type(branch:pathname), but it needs $git_dir
393 $pathname =~ s
,^/+,,;
394 if (!$pathname || substr($pathname, -1) eq "/") {
398 $action ||= "blob_plain";
400 $hash_base ||= validate_refname
($refname);
401 $file_name ||= validate_pathname
($pathname);
402 } elsif (defined $refname) {
403 # we got "project.git/branch"
404 $action ||= "shortlog";
405 $hash ||= validate_refname
($refname);
408 evaluate_path_info
();
410 # path to the current git repository
412 $git_dir = "$projectroot/$project" if $project;
416 "blame" => \
&git_blame2
,
417 "blobdiff" => \
&git_blobdiff
,
418 "blobdiff_plain" => \
&git_blobdiff_plain
,
419 "blob" => \
&git_blob
,
420 "blob_plain" => \
&git_blob_plain
,
421 "commitdiff" => \
&git_commitdiff
,
422 "commitdiff_plain" => \
&git_commitdiff_plain
,
423 "commit" => \
&git_commit
,
424 "forks" => \
&git_forks
,
425 "heads" => \
&git_heads
,
426 "history" => \
&git_history
,
429 "search" => \
&git_search
,
430 "search_help" => \
&git_search_help
,
431 "shortlog" => \
&git_shortlog
,
432 "summary" => \
&git_summary
,
434 "tags" => \
&git_tags
,
435 "tree" => \
&git_tree
,
436 "snapshot" => \
&git_snapshot
,
437 # those below don't need $project
438 "opml" => \
&git_opml
,
439 "project_list" => \
&git_project_list
,
440 "project_index" => \
&git_project_index
,
443 if (defined $project) {
444 $action ||= 'summary';
446 $action ||= 'project_list';
448 if (!defined($actions{$action})) {
449 die_error
(undef, "Unknown action");
451 if ($action !~ m/^(opml|project_list|project_index)$/ &&
453 die_error
(undef, "Project needed");
455 $actions{$action}->();
458 ## ======================================================================
465 # XXX: Warning: If you touch this, check the search form for updating,
476 hash_parent_base
=> "hpb",
482 my %mapping = @mapping;
484 $params{'project'} = $project unless exists $params{'project'};
486 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
488 # use PATH_INFO for project name
489 $href .= "/$params{'project'}" if defined $params{'project'};
490 delete $params{'project'};
492 # Summary just uses the project path URL
493 if (defined $params{'action'} && $params{'action'} eq 'summary') {
494 delete $params{'action'};
498 # now encode the parameters explicitly
500 for (my $i = 0; $i < @mapping; $i += 2) {
501 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
502 if (defined $params{$name}) {
503 push @result, $symbol . "=" . esc_param
($params{$name});
506 $href .= "?" . join(';', @result) if scalar @result;
512 ## ======================================================================
513 ## validation, quoting/unquoting and escaping
515 sub validate_pathname
{
516 my $input = shift || return undef;
518 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
519 # at the beginning, at the end, and between slashes.
520 # also this catches doubled slashes
521 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
525 if ($input =~ m!\0!) {
531 sub validate_refname
{
532 my $input = shift || return undef;
534 # textual hashes are O.K.
535 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
538 # it must be correct pathname
539 $input = validate_pathname
($input)
541 # restrictions on ref name according to git-check-ref-format
542 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
548 # very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT);
551 return decode
("utf8", $str, Encode
::FB_DEFAULT
);
554 # quote unsafe chars, but keep the slash, even when it's not
555 # correct, but quoted slashes look too horrible in bookmarks
558 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
564 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
567 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
573 # replace invalid utf8 character with SUBSTITUTION sequence
576 $str = to_utf8
($str);
577 $str = escapeHTML
($str);
578 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
579 $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1)
583 # git may return quoted and escaped filenames
586 if ($str =~ m/^"(.*)"$/) {
588 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
593 # escape tabs (convert tabs to spaces)
597 while ((my $pos = index($line, "\t")) != -1) {
598 if (my $count = (8 - ($pos % 8))) {
599 my $spaces = ' ' x
$count;
600 $line =~ s/\t/$spaces/;
607 sub project_in_list
{
609 my @list = git_get_projects_list
();
610 return @list && scalar(grep { $_->{'path'} eq $project } @list);
613 ## ----------------------------------------------------------------------
614 ## HTML aware string manipulation
619 my $add_len = shift || 10;
621 # allow only $len chars, but don't cut a word if it would fit in $add_len
622 # if it doesn't fit, cut it if it's still longer than the dots we would add
623 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
626 if (length($tail) > 4) {
628 $body =~ s/&[^;]*$//; # remove chopped character entities
633 ## ----------------------------------------------------------------------
634 ## functions returning short strings
636 # CSS class for given age value (in seconds)
640 if ($age < 60*60*2) {
642 } elsif ($age < 60*60*24*2) {
649 # convert age in seconds to "nn units ago" string
654 if ($age > 60*60*24*365*2) {
655 $age_str = (int $age/60/60/24/365);
656 $age_str .= " years ago";
657 } elsif ($age > 60*60*24*(365/12)*2) {
658 $age_str = int $age/60/60/24/(365/12);
659 $age_str .= " months ago";
660 } elsif ($age > 60*60*24*7*2) {
661 $age_str = int $age/60/60/24/7;
662 $age_str .= " weeks ago";
663 } elsif ($age > 60*60*24*2) {
664 $age_str = int $age/60/60/24;
665 $age_str .= " days ago";
666 } elsif ($age > 60*60*2) {
667 $age_str = int $age/60/60;
668 $age_str .= " hours ago";
669 } elsif ($age > 60*2) {
670 $age_str = int $age/60;
671 $age_str .= " min ago";
674 $age_str .= " sec ago";
676 $age_str .= " right now";
681 # convert file mode in octal to symbolic file mode string
683 my $mode = oct shift;
685 if (S_ISDIR
($mode & S_IFMT
)) {
687 } elsif (S_ISLNK
($mode)) {
689 } elsif (S_ISREG
($mode)) {
690 # git cares only about the executable bit
691 if ($mode & S_IXUSR
) {
701 # convert file mode in octal to file type string
705 if ($mode !~ m/^[0-7]+$/) {
711 if (S_ISDIR
($mode & S_IFMT
)) {
713 } elsif (S_ISLNK
($mode)) {
715 } elsif (S_ISREG
($mode)) {
722 ## ----------------------------------------------------------------------
723 ## functions returning short HTML fragments, or transforming HTML fragments
724 ## which don't beling to other sections
726 # format line of commit message or tag comment
727 sub format_log_line_html
{
730 $line = esc_html
($line);
731 $line =~ s/ / /g;
732 if ($line =~ m/([0-9a-fA-F]{40})/) {
734 if (git_get_type
($hash_text) eq "commit") {
736 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
737 -class => "text"}, $hash_text);
738 $line =~ s/$hash_text/$link/;
744 # format marker of refs pointing to given object
745 sub format_ref_marker
{
746 my ($refs, $id) = @_;
749 if (defined $refs->{$id}) {
750 foreach my $ref (@{$refs->{$id}}) {
751 my ($type, $name) = qw();
752 # e.g. tags/v2.6.11 or heads/next
753 if ($ref =~ m!^(.*?)s?/(.*)$!) {
761 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
766 return ' <span class="refs">'. $markers . '</span>';
772 # format, perhaps shortened and with markers, title line
773 sub format_subject_html
{
774 my ($long, $short, $href, $extra) = @_;
775 $extra = '' unless defined($extra);
777 if (length($short) < length($long)) {
778 return $cgi->a({-href
=> $href, -class => "list subject",
779 -title
=> to_utf8
($long)},
780 esc_html
($short) . $extra);
782 return $cgi->a({-href
=> $href, -class => "list subject"},
783 esc_html
($long) . $extra);
787 sub format_diff_line
{
789 my $char = substr($line, 0, 1);
795 $diff_class = " add";
796 } elsif ($char eq "-") {
797 $diff_class = " rem";
798 } elsif ($char eq "@") {
799 $diff_class = " chunk_header";
800 } elsif ($char eq "\\") {
801 $diff_class = " incomplete";
803 $line = untabify
($line);
804 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
807 ## ----------------------------------------------------------------------
808 ## git utility subroutines, invoking git commands
810 # returns path to the core git executable and the --git-dir parameter as list
812 return $GIT, '--git-dir='.$git_dir;
815 # returns path to the core git executable and the --git-dir parameter as string
817 return join(' ', git_cmd
());
820 # get HEAD ref of given project as hash
821 sub git_get_head_hash
{
823 my $o_git_dir = $git_dir;
825 $git_dir = "$projectroot/$project";
826 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
829 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
833 if (defined $o_git_dir) {
834 $git_dir = $o_git_dir;
839 # get type of given object
843 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
850 sub git_get_project_config
{
851 my ($key, $type) = @_;
853 return unless ($key);
854 $key =~ s/^gitweb\.//;
855 return if ($key =~ m/\W/);
857 my @x = (git_cmd
(), 'repo-config');
858 if (defined $type) { push @x, $type; }
860 push @x, "gitweb.$key";
866 # get hash of given path at given ref
867 sub git_get_hash_by_path
{
869 my $path = shift || return undef;
874 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
875 or die_error
(undef, "Open git-ls-tree failed");
877 close $fd or return undef;
879 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
880 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
881 if (defined $type && $type ne $2) {
888 ## ......................................................................
889 ## git utility functions, directly accessing git repository
891 sub git_get_project_description
{
894 open my $fd, "$projectroot/$path/description" or return undef;
901 sub git_get_project_url_list
{
904 open my $fd, "$projectroot/$path/cloneurl" or return;
905 my @git_project_url_list = map { chomp; $_ } <$fd>;
908 return wantarray ? @git_project_url_list : \
@git_project_url_list;
911 sub git_get_projects_list
{
916 $filter =~ s/\.git$//;
918 if (-d
$projects_list) {
919 # search in directory
920 my $dir = $projects_list . ($filter ? "/$filter" : '');
921 my $pfxlen = length("$dir");
923 my $check_forks = gitweb_check_feature
('forks');
926 follow_fast
=> 1, # follow symbolic links
927 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
929 # skip project-list toplevel, if we get it.
930 return if (m!^[/.]$!);
931 # only directories can be git repositories
932 return unless (-d
$_);
934 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
935 # we check related file in $projectroot
936 if ($check_forks and $subdir =~ m
#/.#) {
937 $File::Find
::prune
= 1;
938 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
939 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
940 $File::Find
::prune
= 1;
945 } elsif (-f
$projects_list) {
946 # read from file(url-encoded):
947 # 'git%2Fgit.git Linus+Torvalds'
948 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
949 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
950 open my ($fd), $projects_list or return;
951 while (my $line = <$fd>) {
953 my ($path, $owner) = split ' ', $line;
954 $path = unescape
($path);
955 $owner = unescape
($owner);
956 if (!defined $path) {
959 if (check_export_ok
("$projectroot/$path")) {
962 owner
=> to_utf8
($owner),
969 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
973 sub git_get_project_owner
{
977 return undef unless $project;
979 # read from file (url-encoded):
980 # 'git%2Fgit.git Linus+Torvalds'
981 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
982 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
983 if (-f
$projects_list) {
984 open (my $fd , $projects_list);
985 while (my $line = <$fd>) {
987 my ($pr, $ow) = split ' ', $line;
990 if ($pr eq $project) {
991 $owner = to_utf8
($ow);
997 if (!defined $owner) {
998 $owner = get_file_owner
("$projectroot/$project");
1004 sub git_get_last_activity
{
1008 $git_dir = "$projectroot/$path";
1009 open($fd, "-|", git_cmd
(), 'for-each-ref',
1010 '--format=%(refname) %(committer)',
1011 '--sort=-committerdate',
1012 'refs/heads') or return;
1013 my $most_recent = <$fd>;
1014 close $fd or return;
1015 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1017 my $age = time - $timestamp;
1018 return ($age, age_string
($age));
1022 sub git_get_references
{
1023 my $type = shift || "";
1025 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1026 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1027 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1030 while (my $line = <$fd>) {
1032 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
1033 if (defined $refs{$1}) {
1034 push @{$refs{$1}}, $2;
1040 close $fd or return;
1044 sub git_get_rev_name_tags
{
1045 my $hash = shift || return undef;
1047 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1049 my $name_rev = <$fd>;
1052 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1055 # catches also '$hash undefined' output
1060 ## ----------------------------------------------------------------------
1061 ## parse to hash functions
1065 my $tz = shift || "-0000";
1068 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1069 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1070 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1071 $date{'hour'} = $hour;
1072 $date{'minute'} = $min;
1073 $date{'mday'} = $mday;
1074 $date{'day'} = $days[$wday];
1075 $date{'month'} = $months[$mon];
1076 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1077 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1078 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1079 $mday, $months[$mon], $hour ,$min;
1081 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1082 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1083 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1084 $date{'hour_local'} = $hour;
1085 $date{'minute_local'} = $min;
1086 $date{'tz_local'} = $tz;
1087 $date{'iso-tz'} = sprintf ("%04d-%02d-%02d %02d:%02d:%02d %s",
1088 1900+$year, $mon+1, $mday,
1089 $hour, $min, $sec, $tz);
1098 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1099 $tag{'id'} = $tag_id;
1100 while (my $line = <$fd>) {
1102 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1103 $tag{'object'} = $1;
1104 } elsif ($line =~ m/^type (.+)$/) {
1106 } elsif ($line =~ m/^tag (.+)$/) {
1108 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1109 $tag{'author'} = $1;
1112 } elsif ($line =~ m/--BEGIN/) {
1113 push @comment, $line;
1115 } elsif ($line eq "") {
1119 push @comment, <$fd>;
1120 $tag{'comment'} = \
@comment;
1121 close $fd or return;
1122 if (!defined $tag{'name'}) {
1129 my $commit_id = shift;
1130 my $commit_text = shift;
1135 if (defined $commit_text) {
1136 @commit_lines = @$commit_text;
1139 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
1141 @commit_lines = split '\n', <$fd>;
1142 close $fd or return;
1145 my $header = shift @commit_lines;
1146 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1149 ($co{'id'}, my @parents) = split ' ', $header;
1150 $co{'parents'} = \
@parents;
1151 $co{'parent'} = $parents[0];
1152 while (my $line = shift @commit_lines) {
1153 last if $line eq "\n";
1154 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1156 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1158 $co{'author_epoch'} = $2;
1159 $co{'author_tz'} = $3;
1160 if ($co{'author'} =~ m/^([^<]+) </) {
1161 $co{'author_name'} = $1;
1163 $co{'author_name'} = $co{'author'};
1165 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1166 $co{'committer'} = $1;
1167 $co{'committer_epoch'} = $2;
1168 $co{'committer_tz'} = $3;
1169 $co{'committer_name'} = $co{'committer'};
1170 $co{'committer_name'} =~ s/ <.*//;
1173 if (!defined $co{'tree'}) {
1177 foreach my $title (@commit_lines) {
1180 $co{'title'} = chop_str
($title, 80, 5);
1181 # remove leading stuff of merges to make the interesting part visible
1182 if (length($title) > 50) {
1183 $title =~ s/^Automatic //;
1184 $title =~ s/^merge (of|with) /Merge ... /i;
1185 if (length($title) > 50) {
1186 $title =~ s/(http|rsync):\/\///;
1188 if (length($title) > 50) {
1189 $title =~ s/(master|www|rsync)\.//;
1191 if (length($title) > 50) {
1192 $title =~ s/kernel.org:?//;
1194 if (length($title) > 50) {
1195 $title =~ s/\/pub\/scm//;
1198 $co{'title_short'} = chop_str
($title, 50, 5);
1202 if ($co{'title'} eq "") {
1203 $co{'title'} = $co{'title_short'} = '(no commit message)';
1205 # remove added spaces
1206 foreach my $line (@commit_lines) {
1209 $co{'comment'} = \
@commit_lines;
1211 my $age = time - $co{'committer_epoch'};
1213 $co{'age_string'} = age_string
($age);
1214 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1215 if ($age > 60*60*24*7*2) {
1216 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1217 $co{'age_string_age'} = $co{'age_string'};
1219 $co{'age_string_date'} = $co{'age_string'};
1220 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1225 # parse ref from ref_file, given by ref_id, with given type
1227 my $ref_file = shift;
1229 my $type = shift || git_get_type
($ref_id);
1232 $ref_item{'type'} = $type;
1233 $ref_item{'id'} = $ref_id;
1234 $ref_item{'epoch'} = 0;
1235 $ref_item{'age'} = "unknown";
1236 if ($type eq "tag") {
1237 my %tag = parse_tag
($ref_id);
1238 $ref_item{'comment'} = $tag{'comment'};
1239 if ($tag{'type'} eq "commit") {
1240 my %co = parse_commit
($tag{'object'});
1241 $ref_item{'epoch'} = $co{'committer_epoch'};
1242 $ref_item{'age'} = $co{'age_string'};
1243 } elsif (defined($tag{'epoch'})) {
1244 my $age = time - $tag{'epoch'};
1245 $ref_item{'epoch'} = $tag{'epoch'};
1246 $ref_item{'age'} = age_string
($age);
1248 $ref_item{'reftype'} = $tag{'type'};
1249 $ref_item{'name'} = $tag{'name'};
1250 $ref_item{'refid'} = $tag{'object'};
1251 } elsif ($type eq "commit"){
1252 my %co = parse_commit
($ref_id);
1253 $ref_item{'reftype'} = "commit";
1254 $ref_item{'name'} = $ref_file;
1255 $ref_item{'title'} = $co{'title'};
1256 $ref_item{'refid'} = $ref_id;
1257 $ref_item{'epoch'} = $co{'committer_epoch'};
1258 $ref_item{'age'} = $co{'age_string'};
1260 $ref_item{'reftype'} = $type;
1261 $ref_item{'name'} = $ref_file;
1262 $ref_item{'refid'} = $ref_id;
1268 # parse line of git-diff-tree "raw" output
1269 sub parse_difftree_raw_line
{
1273 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1274 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1275 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1276 $res{'from_mode'} = $1;
1277 $res{'to_mode'} = $2;
1278 $res{'from_id'} = $3;
1280 $res{'status'} = $5;
1281 $res{'similarity'} = $6;
1282 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1283 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1285 $res{'file'} = unquote
($7);
1288 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1289 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1290 $res{'commit'} = $1;
1293 return wantarray ? %res : \
%res;
1296 # parse line of git-ls-tree output
1297 sub parse_ls_tree_line
($;%) {
1302 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1303 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1311 $res{'name'} = unquote
($4);
1314 return wantarray ? %res : \
%res;
1317 ## ......................................................................
1318 ## parse to array of hashes functions
1320 sub git_get_refs_list
{
1321 my $type = shift || "";
1326 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1328 while (my $line = <$fd>) {
1330 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?([^\^]+))(\^\{\})?$/) {
1331 if (defined $refs{$1}) {
1332 push @{$refs{$1}}, $2;
1337 if (! $4) { # unpeeled, direct reference
1338 push @refs, { hash
=> $1, name
=> $3 }; # without type
1339 } elsif ($3 eq $refs[-1]{'name'}) {
1340 # most likely a tag is followed by its peeled
1341 # (deref) one, and when that happens we know the
1342 # previous one was of type 'tag'.
1343 $refs[-1]{'type'} = "tag";
1349 foreach my $ref (@refs) {
1350 my $ref_file = $ref->{'name'};
1351 my $ref_id = $ref->{'hash'};
1353 my $type = $ref->{'type'} || git_get_type
($ref_id) || next;
1354 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1356 push @reflist, \
%ref_item;
1359 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1360 return (\
@reflist, \
%refs);
1363 ## ----------------------------------------------------------------------
1364 ## filesystem-related functions
1366 sub get_file_owner
{
1369 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1370 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1371 if (!defined $gcos) {
1375 $owner =~ s/[,;].*$//;
1376 return to_utf8
($owner);
1379 ## ......................................................................
1380 ## mimetype related functions
1382 sub mimetype_guess_file
{
1383 my $filename = shift;
1384 my $mimemap = shift;
1385 -r
$mimemap or return undef;
1388 open(MIME
, $mimemap) or return undef;
1390 next if m/^#/; # skip comments
1391 my ($mime, $exts) = split(/\t+/);
1392 if (defined $exts) {
1393 my @exts = split(/\s+/, $exts);
1394 foreach my $ext (@exts) {
1395 $mimemap{$ext} = $mime;
1401 $filename =~ /\.([^.]*)$/;
1402 return $mimemap{$1};
1405 sub mimetype_guess
{
1406 my $filename = shift;
1408 $filename =~ /\./ or return undef;
1410 if ($mimetypes_file) {
1411 my $file = $mimetypes_file;
1412 if ($file !~ m!^/!) { # if it is relative path
1413 # it is relative to project
1414 $file = "$projectroot/$project/$file";
1416 $mime = mimetype_guess_file
($filename, $file);
1418 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1424 my $filename = shift;
1427 my $mime = mimetype_guess
($filename);
1428 $mime and return $mime;
1432 return $default_blob_plain_mimetype unless $fd;
1435 return 'text/plain' .
1436 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1437 } elsif (! $filename) {
1438 return 'application/octet-stream';
1439 } elsif ($filename =~ m/\.png$/i) {
1441 } elsif ($filename =~ m/\.gif$/i) {
1443 } elsif ($filename =~ m/\.jpe?g$/i) {
1444 return 'image/jpeg';
1446 return 'application/octet-stream';
1450 ## ======================================================================
1451 ## functions printing HTML: header, footer, error page
1453 sub git_header_html
{
1454 my $status = shift || "200 OK";
1455 my $expires = shift;
1457 my $title = "$site_name";
1458 if (defined $project) {
1459 $title .= " - $project";
1460 if (defined $action) {
1461 $title .= "/$action";
1462 if (defined $file_name) {
1463 $title .= " - " . esc_html
($file_name);
1464 if ($action eq "tree" && $file_name !~ m
|/$|) {
1471 # require explicit support from the UA if we are to send the page as
1472 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1473 # we have to do this because MSIE sometimes globs '*/*', pretending to
1474 # support xhtml+xml but choking when it gets what it asked for.
1475 if (defined $cgi->http('HTTP_ACCEPT') &&
1476 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1477 $cgi->Accept('application/xhtml+xml') != 0) {
1478 $content_type = 'application/xhtml+xml';
1480 $content_type = 'text/html';
1482 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1483 -status
=> $status, -expires
=> $expires);
1485 <?xml version="1.0" encoding="utf-8"?>
1486 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1487 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1488 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1489 <!-- git core binaries version $git_version -->
1491 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1492 <meta name="generator" content="gitweb/$version git/$git_version"/>
1493 <meta name="robots" content="index, nofollow"/>
1494 <title>$title</title>
1496 # print out each stylesheet that exist
1497 if (defined $stylesheet) {
1498 #provides backwards capability for those people who define style sheet in a config file
1499 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1501 foreach my $stylesheet (@stylesheets) {
1502 next unless $stylesheet;
1503 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1506 if (defined $project) {
1507 printf('<link rel="alternate" title="%s log" '.
1508 'href="%s" type="application/rss+xml"/>'."\n",
1509 esc_param
($project), href
(action
=>"rss"));
1511 printf('<link rel="alternate" title="%s projects list" '.
1512 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1513 $site_name, href
(project
=>undef, action
=>"project_index"));
1514 printf('<link rel="alternate" title="%s projects logs" '.
1515 'href="%s" type="text/x-opml"/>'."\n",
1516 $site_name, href
(project
=>undef, action
=>"opml"));
1518 if (defined $favicon) {
1519 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1525 if (-f
$site_header) {
1526 open (my $fd, $site_header);
1531 print "<div class=\"page_header\">\n" .
1532 $cgi->a({-href
=> esc_url
($logo_url),
1533 -title
=> $logo_label},
1534 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1535 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1536 if (defined $project) {
1537 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1538 if (defined $action) {
1542 if (!defined $searchtext) {
1546 if (defined $hash_base) {
1547 $search_hash = $hash_base;
1548 } elsif (defined $hash) {
1549 $search_hash = $hash;
1551 $search_hash = "HEAD";
1553 $cgi->param("a", "search");
1554 $cgi->param("h", $search_hash);
1555 $cgi->param("p", $project);
1556 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1557 "<div class=\"search\">\n" .
1558 $cgi->hidden(-name
=> "p") . "\n" .
1559 $cgi->hidden(-name
=> "a") . "\n" .
1560 $cgi->hidden(-name
=> "h") . "\n" .
1561 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1562 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1563 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1565 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1567 $cgi->end_form() . "\n";
1572 sub git_footer_html
{
1573 print "<div class=\"page_footer\">\n";
1574 if (defined $project) {
1575 my $descr = git_get_project_description
($project);
1576 if (defined $descr) {
1577 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1579 print $cgi->a({-href
=> href
(action
=>"rss"),
1580 -class => "rss_logo"}, "RSS") . "\n";
1582 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1583 -class => "rss_logo"}, "OPML") . " ";
1584 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1585 -class => "rss_logo"}, "TXT") . "\n";
1589 if (-f
$site_footer) {
1590 open (my $fd, $site_footer);
1600 my $status = shift || "403 Forbidden";
1601 my $error = shift || "Malformed query, file missing or permission denied";
1603 git_header_html
($status);
1605 <div class="page_body">
1615 ## ----------------------------------------------------------------------
1616 ## functions printing or outputting HTML: navigation
1618 sub git_print_page_nav
{
1619 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1620 $extra = '' if !defined $extra; # pager or formats
1622 my @navs = qw(summary shortlog log commit commitdiff tree);
1624 @navs = grep { $_ ne $suppress } @navs;
1627 my %arg = map { $_ => {action
=>$_} } @navs;
1628 if (defined $head) {
1629 for (qw(commit commitdiff)) {
1630 $arg{$_}{hash
} = $head;
1632 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1633 for (qw(shortlog log)) {
1634 $arg{$_}{hash
} = $head;
1638 $arg{tree
}{hash
} = $treehead if defined $treehead;
1639 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1641 print "<div class=\"page_nav\">\n" .
1643 map { $_ eq $current ?
1644 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1646 print "<br/>\n$extra<br/>\n" .
1650 sub format_paging_nav
{
1651 my ($action, $hash, $head, $page, $nrevs) = @_;
1655 if ($hash ne $head || $page) {
1656 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1658 $paging_nav .= "HEAD";
1662 $paging_nav .= " ⋅ " .
1663 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1664 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1666 $paging_nav .= " ⋅ prev";
1669 if ($nrevs >= (100 * ($page+1)-1)) {
1670 $paging_nav .= " ⋅ " .
1671 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1672 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1674 $paging_nav .= " ⋅ next";
1680 ## ......................................................................
1681 ## functions printing or outputting HTML: div
1683 sub git_print_header_div
{
1684 my ($action, $title, $hash, $hash_base) = @_;
1687 $args{action
} = $action;
1688 $args{hash
} = $hash if $hash;
1689 $args{hash_base
} = $hash_base if $hash_base;
1691 print "<div class=\"header\">\n" .
1692 $cgi->a({-href
=> href
(%args), -class => "title"},
1693 $title ? $title : $action) .
1697 #sub git_print_authorship (\%) {
1698 sub git_print_authorship
{
1701 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1702 print "<div class=\"author_date\">" .
1703 esc_html
($co->{'author_name'}) .
1705 if ($ad{'hour_local'} < 6) {
1706 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1707 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1709 printf(" (%02d:%02d %s)",
1710 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1715 sub git_print_page_path
{
1721 print "<div class=\"page_path\">";
1722 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1723 -title
=> 'tree root'}, "[$project]");
1725 if (defined $name) {
1726 my @dirname = split '/', $name;
1727 my $basename = pop @dirname;
1730 foreach my $dir (@dirname) {
1731 $fullname .= ($fullname ? '/' : '') . $dir;
1732 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1734 -title
=> $fullname}, esc_html
($dir));
1737 if (defined $type && $type eq 'blob') {
1738 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1740 -title
=> $name}, esc_html
($basename));
1741 } elsif (defined $type && $type eq 'tree') {
1742 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1744 -title
=> $name}, esc_html
($basename));
1747 print esc_html
($basename);
1750 print "<br/></div>\n";
1753 # sub git_print_log (\@;%) {
1754 sub git_print_log
($;%) {
1758 if ($opts{'-remove_title'}) {
1759 # remove title, i.e. first line of log
1762 # remove leading empty lines
1763 while (defined $log->[0] && $log->[0] eq "") {
1770 foreach my $line (@$log) {
1771 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1774 if (! $opts{'-remove_signoff'}) {
1775 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1778 # remove signoff lines
1785 # print only one empty line
1786 # do not print empty line after signoff
1788 next if ($empty || $signoff);
1794 print format_log_line_html
($line) . "<br/>\n";
1797 if ($opts{'-final_empty_line'}) {
1798 # end with single empty line
1799 print "<br/>\n" unless $empty;
1803 # print tree entry (row of git_tree), but without encompassing <tr> element
1804 sub git_print_tree_entry
{
1805 my ($t, $basedir, $hash_base, $have_blame) = @_;
1808 $base_key{hash_base
} = $hash_base if defined $hash_base;
1810 # The format of a table row is: mode list link. Where mode is
1811 # the mode of the entry, list is the name of the entry, an href,
1812 # and link is the action links of the entry.
1814 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1815 if ($t->{'type'} eq "blob") {
1816 print "<td class=\"list\">" .
1817 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1818 file_name
=>"$basedir$t->{'name'}", %base_key),
1819 -class => "list"}, esc_html
($t->{'name'})) . "</td>\n";
1820 print "<td class=\"link\">";
1821 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1822 file_name
=>"$basedir$t->{'name'}", %base_key)},
1826 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1827 file_name
=>"$basedir$t->{'name'}", %base_key)},
1830 if (defined $hash_base) {
1832 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1833 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1837 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
1838 file_name
=>"$basedir$t->{'name'}")},
1842 } elsif ($t->{'type'} eq "tree") {
1843 print "<td class=\"list\">";
1844 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1845 file_name
=>"$basedir$t->{'name'}", %base_key)},
1846 esc_html
($t->{'name'}));
1848 print "<td class=\"link\">";
1849 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1850 file_name
=>"$basedir$t->{'name'}", %base_key)},
1852 if (defined $hash_base) {
1854 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1855 file_name
=>"$basedir$t->{'name'}")},
1862 ## ......................................................................
1863 ## functions printing large fragments of HTML
1865 sub git_difftree_body
{
1866 my ($difftree, $hash, $parent) = @_;
1868 print "<div class=\"list_head\">\n";
1869 if ($#{$difftree} > 10) {
1870 print(($#{$difftree} + 1) . " files changed:\n");
1874 print "<table class=\"diff_tree\">\n";
1877 foreach my $line (@{$difftree}) {
1878 my %diff = parse_difftree_raw_line
($line);
1881 print "<tr class=\"dark\">\n";
1883 print "<tr class=\"light\">\n";
1887 my ($to_mode_oct, $to_mode_str, $to_file_type);
1888 my ($from_mode_oct, $from_mode_str, $from_file_type);
1889 if ($diff{'to_mode'} ne ('0' x
6)) {
1890 $to_mode_oct = oct $diff{'to_mode'};
1891 if (S_ISREG
($to_mode_oct)) { # only for regular file
1892 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1894 $to_file_type = file_type
($diff{'to_mode'});
1896 if ($diff{'from_mode'} ne ('0' x
6)) {
1897 $from_mode_oct = oct $diff{'from_mode'};
1898 if (S_ISREG
($to_mode_oct)) { # only for regular file
1899 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1901 $from_file_type = file_type
($diff{'from_mode'});
1904 if ($diff{'status'} eq "A") { # created
1905 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1906 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1907 $mode_chng .= "]</span>";
1909 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1910 hash_base
=>$hash, file_name
=>$diff{'file'}),
1911 -class => "list"}, esc_html
($diff{'file'}));
1913 print "<td>$mode_chng</td>\n";
1914 print "<td class=\"link\">";
1915 if ($action eq 'commitdiff') {
1918 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1922 } elsif ($diff{'status'} eq "D") { # deleted
1923 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1925 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1926 hash_base
=>$parent, file_name
=>$diff{'file'}),
1927 -class => "list"}, esc_html
($diff{'file'}));
1929 print "<td>$mode_chng</td>\n";
1930 print "<td class=\"link\">";
1931 if ($action eq 'commitdiff') {
1934 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1937 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1938 hash_base
=>$parent, file_name
=>$diff{'file'})},
1940 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1941 file_name
=>$diff{'file'})},
1943 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1944 file_name
=>$diff{'file'})},
1948 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1949 my $mode_chnge = "";
1950 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1951 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1952 if ($from_file_type != $to_file_type) {
1953 $mode_chnge .= " from $from_file_type to $to_file_type";
1955 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1956 if ($from_mode_str && $to_mode_str) {
1957 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1958 } elsif ($to_mode_str) {
1959 $mode_chnge .= " mode: $to_mode_str";
1962 $mode_chnge .= "]</span>\n";
1965 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1966 hash_base
=>$hash, file_name
=>$diff{'file'}),
1967 -class => "list"}, esc_html
($diff{'file'}));
1969 print "<td>$mode_chnge</td>\n";
1970 print "<td class=\"link\">";
1971 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1972 if ($action eq 'commitdiff') {
1975 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1977 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1978 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1979 hash_base
=>$hash, hash_parent_base
=>$parent,
1980 file_name
=>$diff{'file'})},
1985 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1986 hash_base
=>$hash, file_name
=>$diff{'file'})},
1988 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
1989 file_name
=>$diff{'file'})},
1991 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
1992 file_name
=>$diff{'file'})},
1996 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1997 my %status_name = ('R' => 'moved', 'C' => 'copied');
1998 my $nstatus = $status_name{$diff{'status'}};
2000 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2001 # mode also for directories, so we cannot use $to_mode_str
2002 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2005 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2006 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
2007 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
2008 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2009 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2010 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
2011 -class => "list"}, esc_html
($diff{'from_file'})) .
2012 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2013 "<td class=\"link\">";
2014 if ($diff{'to_id'} ne $diff{'from_id'}) {
2015 if ($action eq 'commitdiff') {
2018 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2020 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2021 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2022 hash_base
=>$hash, hash_parent_base
=>$parent,
2023 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
2028 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2029 hash_base
=>$parent, file_name
=>$diff{'from_file'})},
2031 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2032 file_name
=>$diff{'from_file'})},
2034 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2035 file_name
=>$diff{'from_file'})},
2039 } # we should not encounter Unmerged (U) or Unknown (X) status
2045 sub git_patchset_body
{
2046 my ($fd, $difftree, $hash, $hash_parent) = @_;
2050 my $patch_found = 0;
2053 print "<div class=\"patchset\">\n";
2056 while (my $patch_line = <$fd>) {
2059 if ($patch_line =~ m/^diff /) { # "git diff" header
2060 # beginning of patch (in patchset)
2062 # close previous patch
2063 print "</div>\n"; # class="patch"
2065 # first patch in patchset
2068 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2070 if (ref($difftree->[$patch_idx]) eq "HASH") {
2071 $diffinfo = $difftree->[$patch_idx];
2073 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2077 # for now, no extended header, hence we skip empty patches
2078 # companion to next LINE if $in_header;
2079 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
2084 if ($diffinfo->{'status'} eq "A") { # added
2085 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
2086 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2087 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2088 $diffinfo->{'to_id'}) . " (new)" .
2089 "</div>\n"; # class="diff_info"
2091 } elsif ($diffinfo->{'status'} eq "D") { # deleted
2092 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
2093 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2094 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2095 $diffinfo->{'from_id'}) . " (deleted)" .
2096 "</div>\n"; # class="diff_info"
2098 } elsif ($diffinfo->{'status'} eq "R" || # renamed
2099 $diffinfo->{'status'} eq "C" || # copied
2100 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
2101 print "<div class=\"diff_info\">" .
2102 file_type
($diffinfo->{'from_mode'}) . ":" .
2103 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2104 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
2105 $diffinfo->{'from_id'}) .
2107 file_type
($diffinfo->{'to_mode'}) . ":" .
2108 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2109 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
2110 $diffinfo->{'to_id'});
2111 print "</div>\n"; # class="diff_info"
2113 } else { # modified, mode changed, ...
2114 print "<div class=\"diff_info\">" .
2115 file_type
($diffinfo->{'from_mode'}) . ":" .
2116 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2117 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2118 $diffinfo->{'from_id'}) .
2120 file_type
($diffinfo->{'to_mode'}) . ":" .
2121 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2122 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2123 $diffinfo->{'to_id'});
2124 print "</div>\n"; # class="diff_info"
2127 #print "<div class=\"diff extended_header\">\n";
2130 } # start of patch in patchset
2133 if ($in_header && $patch_line =~ m/^---/) {
2134 #print "</div>\n"; # class="diff extended_header"
2137 my $file = $diffinfo->{'from_file'};
2138 $file ||= $diffinfo->{'file'};
2139 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2140 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
2141 -class => "list"}, esc_html
($file));
2142 $patch_line =~ s
|a
/.*$|a/$file|g
;
2143 print "<div class=\"diff from_file\">$patch_line</div>\n";
2145 $patch_line = <$fd>;
2148 #$patch_line =~ m/^+++/;
2149 $file = $diffinfo->{'to_file'};
2150 $file ||= $diffinfo->{'file'};
2151 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2152 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
2153 -class => "list"}, esc_html
($file));
2154 $patch_line =~ s
|b
/.*|b/$file|g
;
2155 print "<div class=\"diff to_file\">$patch_line</div>\n";
2159 next LINE
if $in_header;
2161 print format_diff_line
($patch_line);
2163 print "</div>\n" if $patch_found; # class="patch"
2165 print "</div>\n"; # class="patchset"
2168 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2170 sub git_project_list_body
{
2171 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2173 my $check_forks = gitweb_check_feature
('forks');
2176 foreach my $pr (@$projlist) {
2177 my (@aa) = git_get_last_activity
($pr->{'path'});
2181 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2182 if (!defined $pr->{'descr'}) {
2183 my $descr = git_get_project_description
($pr->{'path'}) || "";
2184 $pr->{'descr'} = chop_str
($descr, 25, 5);
2186 if (!defined $pr->{'owner'}) {
2187 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2190 my $pname = $pr->{'path'};
2191 $pname =~ s/\.git$//;
2192 $pr->{'forks'} = -d
"$projectroot/$pname";
2194 push @projects, $pr;
2197 $order ||= "project";
2198 $from = 0 unless defined $from;
2199 $to = $#projects if (!defined $to || $#projects < $to);
2201 print "<table class=\"project_list\">\n";
2202 unless ($no_header) {
2205 print "<th></th>\n";
2207 if ($order eq "project") {
2208 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2209 print "<th>Project</th>\n";
2212 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2213 -class => "header"}, "Project") .
2216 if ($order eq "descr") {
2217 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2218 print "<th>Description</th>\n";
2221 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2222 -class => "header"}, "Description") .
2225 if ($order eq "owner") {
2226 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2227 print "<th>Owner</th>\n";
2230 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2231 -class => "header"}, "Owner") .
2234 if ($order eq "age") {
2235 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2236 print "<th>Last Change</th>\n";
2239 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2240 -class => "header"}, "Last Change") .
2243 print "<th></th>\n" .
2247 for (my $i = $from; $i <= $to; $i++) {
2248 my $pr = $projects[$i];
2250 print "<tr class=\"dark\">\n";
2252 print "<tr class=\"light\">\n";
2257 if ($pr->{'forks'}) {
2258 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2262 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2263 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2264 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2265 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2266 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2267 $pr->{'age_string'} . "</td>\n" .
2268 "<td class=\"link\">" .
2269 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2270 $cgi->a({-href
=> '/git-browser/by-commit.html?r='.$pr->{'path'}}, "graphiclog") . " | " .
2271 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2272 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2273 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
2277 if (defined $extra) {
2280 print "<td></td>\n";
2282 print "<td colspan=\"5\">$extra</td>\n" .
2288 sub git_shortlog_body
{
2289 # uses global variable $project
2290 my ($revlist, $from, $to, $refs, $extra) = @_;
2292 $from = 0 unless defined $from;
2293 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2295 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2297 for (my $i = $from; $i <= $to; $i++) {
2298 my $commit = $revlist->[$i];
2299 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2300 my $ref = format_ref_marker
($refs, $commit);
2301 my %co = parse_commit
($commit);
2303 print "<tr class=\"dark\">\n";
2305 print "<tr class=\"light\">\n";
2308 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2309 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2310 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2312 print format_subject_html
($co{'title'}, $co{'title_short'},
2313 href
(action
=>"commit", hash
=>$commit), $ref);
2315 "<td class=\"link\">" .
2316 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
2317 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2318 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2319 if (gitweb_have_snapshot
()) {
2320 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2325 if (defined $extra) {
2327 "<td colspan=\"4\">$extra</td>\n" .
2333 sub git_history_body
{
2334 # Warning: assumes constant type (blob or tree) during history
2335 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2337 $from = 0 unless defined $from;
2338 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2340 print "<table class=\"history\" cellspacing=\"0\">\n";
2342 for (my $i = $from; $i <= $to; $i++) {
2343 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2348 my %co = parse_commit
($commit);
2353 my $ref = format_ref_marker
($refs, $commit);
2356 print "<tr class=\"dark\">\n";
2358 print "<tr class=\"light\">\n";
2361 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2362 # shortlog uses chop_str($co{'author_name'}, 10)
2363 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2365 # originally git_history used chop_str($co{'title'}, 50)
2366 print format_subject_html
($co{'title'}, $co{'title_short'},
2367 href
(action
=>"commit", hash
=>$commit), $ref);
2369 "<td class=\"link\">" .
2370 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2371 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2373 if ($ftype eq 'blob') {
2374 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2375 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2376 if (defined $blob_current && defined $blob_parent &&
2377 $blob_current ne $blob_parent) {
2379 $cgi->a({-href
=> href
(action
=>"blobdiff",
2380 hash
=>$blob_current, hash_parent
=>$blob_parent,
2381 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2382 file_name
=>$file_name)},
2389 if (defined $extra) {
2391 "<td colspan=\"4\">$extra</td>\n" .
2398 # uses global variable $project
2399 my ($taglist, $from, $to, $extra) = @_;
2400 $from = 0 unless defined $from;
2401 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2403 print "<table class=\"tags\" cellspacing=\"0\">\n";
2405 for (my $i = $from; $i <= $to; $i++) {
2406 my $entry = $taglist->[$i];
2408 my $comment_lines = $tag{'comment'};
2409 my $comment = shift @$comment_lines;
2411 if (defined $comment) {
2412 $comment_short = chop_str
($comment, 30, 5);
2415 print "<tr class=\"dark\">\n";
2417 print "<tr class=\"light\">\n";
2420 print "<td><i>$tag{'age'}</i></td>\n" .
2422 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2423 -class => "list name"}, esc_html
($tag{'name'})) .
2426 if (defined $comment) {
2427 print format_subject_html
($comment, $comment_short,
2428 href
(action
=>"tag", hash
=>$tag{'id'}));
2431 "<td class=\"selflink\">";
2432 if ($tag{'type'} eq "tag") {
2433 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2438 "<td class=\"link\">" . " | " .
2439 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2440 if ($tag{'reftype'} eq "commit") {
2441 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2442 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
2443 } elsif ($tag{'reftype'} eq "blob") {
2444 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2449 if (defined $extra) {
2451 "<td colspan=\"5\">$extra</td>\n" .
2457 sub git_heads_body
{
2458 # uses global variable $project
2459 my ($headlist, $head, $from, $to, $extra) = @_;
2460 $from = 0 unless defined $from;
2461 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2463 print "<table class=\"heads\" cellspacing=\"0\">\n";
2465 for (my $i = $from; $i <= $to; $i++) {
2466 my $entry = $headlist->[$i];
2468 my $curr = $tag{'id'} eq $head;
2470 print "<tr class=\"dark\">\n";
2472 print "<tr class=\"light\">\n";
2475 print "<td><i>$tag{'age'}</i></td>\n" .
2476 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
2477 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
2478 -class => "list name"},esc_html
($tag{'name'})) .
2480 "<td class=\"link\">" .
2481 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
2482 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") . " | " .
2483 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$tag{'name'}, hash_base
=>$tag{'name'})}, "tree") .
2487 if (defined $extra) {
2489 "<td colspan=\"3\">$extra</td>\n" .
2495 ## ======================================================================
2496 ## ======================================================================
2499 sub git_project_list
{
2500 my $order = $cgi->param('o');
2501 if (defined $order && $order !~ m/project|descr|owner|age/) {
2502 die_error
(undef, "Unknown order parameter");
2505 my @list = git_get_projects_list
();
2507 die_error
(undef, "No projects found");
2511 if (-f
$home_text) {
2512 print "<div class=\"index_include\">\n";
2513 open (my $fd, $home_text);
2518 git_project_list_body
(\
@list, $order);
2523 my $order = $cgi->param('o');
2524 if (defined $order && $order !~ m/project|descr|owner|age/) {
2525 die_error
(undef, "Unknown order parameter");
2528 my @list = git_get_projects_list
($project);
2530 die_error
(undef, "No forks found");
2534 git_print_page_nav
('','');
2535 git_print_header_div
('summary', "$project forks");
2536 git_project_list_body
(\
@list, $order);
2540 sub git_project_index
{
2541 my @projects = git_get_projects_list
($project);
2544 -type
=> 'text/plain',
2545 -charset
=> 'utf-8',
2546 -content_disposition
=> 'inline; filename="index.aux"');
2548 foreach my $pr (@projects) {
2549 if (!exists $pr->{'owner'}) {
2550 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2553 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2554 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2555 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2556 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2560 print "$path $owner\n";
2565 my $descr = git_get_project_description
($project) || "none";
2566 my $head = git_get_head_hash
($project);
2567 my %co = parse_commit
($head);
2568 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2570 my $owner = git_get_project_owner
($project);
2572 my ($reflist, $refs) = git_get_refs_list
();
2576 foreach my $ref (@$reflist) {
2577 if ($ref->{'name'} =~ s!^heads/!!) {
2578 push @headlist, $ref;
2580 $ref->{'name'} =~ s!^tags/!!;
2581 push @taglist, $ref;
2585 if (gitweb_check_feature
('forks')) {
2586 @forklist = git_get_projects_list
($project);
2590 git_print_page_nav
('summary','', $head);
2592 print "<div class=\"title\"> </div>\n";
2593 print "<table cellspacing=\"0\">\n" .
2594 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2595 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2596 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2597 # use per project git URL list in $projectroot/$project/cloneurl
2598 # or make project git URL from git base URL and project name
2599 my $url_tag = "URL";
2600 my @url_list = git_get_project_url_list
($project);
2601 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2602 foreach my $git_url (@url_list) {
2603 next unless $git_url;
2604 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2609 if (-s
"$projectroot/$project/README.html") {
2610 if (open my $fd, "$projectroot/$project/README.html") {
2611 print "<div class=\"title\">readme</div>\n";
2612 print $_ while (<$fd>);
2617 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2618 git_get_head_hash
($project)
2619 or die_error
(undef, "Open git-rev-list failed");
2620 my @revlist = map { chomp; $_ } <$fd>;
2622 git_print_header_div
('shortlog');
2623 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2624 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2627 git_print_header_div
('tags');
2628 git_tags_body
(\
@taglist, 0, 15,
2629 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2633 git_print_header_div
('heads');
2634 git_heads_body
(\
@headlist, $head, 0, 15,
2635 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2639 git_print_header_div
('forks');
2640 git_project_list_body
(\
@forklist, undef, 0, 15,
2641 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
2649 my $head = git_get_head_hash
($project);
2651 git_print_page_nav
('','', $head,undef,$head);
2652 my %tag = parse_tag
($hash);
2653 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2654 print "<div class=\"title_text\">\n" .
2655 "<table cellspacing=\"0\">\n" .
2657 "<td>object</td>\n" .
2658 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2659 $tag{'object'}) . "</td>\n" .
2660 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2661 $tag{'type'}) . "</td>\n" .
2663 if (defined($tag{'author'})) {
2664 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2665 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2666 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2667 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2670 print "</table>\n\n" .
2672 print "<div class=\"page_body\">";
2673 my $comment = $tag{'comment'};
2674 foreach my $line (@$comment) {
2675 print esc_html
($line) . "<br/>\n";
2685 my ($have_blame) = gitweb_check_feature
('blame');
2687 die_error
('403 Permission denied', "Permission denied");
2689 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2690 $hash_base ||= git_get_head_hash
($project);
2691 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2692 my %co = parse_commit
($hash_base)
2693 or die_error
(undef, "Reading commit failed");
2694 if (!defined $hash) {
2695 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2696 or die_error
(undef, "Error looking up file");
2698 $ftype = git_get_type
($hash);
2699 if ($ftype !~ "blob") {
2700 die_error
("400 Bad Request", "Object is not a blob");
2702 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
2703 $file_name, $hash_base)
2704 or die_error
(undef, "Open git-blame failed");
2707 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2710 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2713 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2715 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2716 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2717 git_print_page_path
($file_name, $ftype, $hash_base);
2718 my @rev_color = (qw(light2 dark2));
2719 my $num_colors = scalar(@rev_color);
2720 my $current_color = 0;
2723 <div class="page_body">
2724 <table class="blame">
2725 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2730 last unless defined $_;
2731 my ($full_rev, $orig_lineno, $lineno, $group_size) =
2732 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
2733 if (!exists $metainfo{$full_rev}) {
2734 $metainfo{$full_rev} = {};
2736 my $meta = $metainfo{$full_rev};
2739 if (/^(\S+) (.*)$/) {
2744 my $rev = substr($full_rev, 0, 8);
2745 my $author = $meta->{'author'};
2746 my %date = parse_date
($meta->{'author-time'},
2747 $meta->{'author-tz'});
2748 my $date = $date{'iso-tz'};
2750 $current_color = ++$current_color % $num_colors;
2752 print "<tr class=\"$rev_color[$current_color]\">\n";
2754 print "<td class=\"sha1\"";
2755 print " title=\"$author, $date\"";
2756 print " rowspan=\"$group_size\"" if ($group_size > 1);
2758 print $cgi->a({-href
=> href
(action
=>"commit",
2760 file_name
=>$file_name)},
2764 my $blamed = href
(action
=> 'blame',
2765 file_name
=> $meta->{'filename'},
2766 hash_base
=> $full_rev);
2767 print "<td class=\"linenr\">";
2768 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
2770 -class => "linenr" },
2773 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2779 or print "Reading blob failed\n";
2786 my ($have_blame) = gitweb_check_feature
('blame');
2788 die_error
('403 Permission denied', "Permission denied");
2790 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2791 $hash_base ||= git_get_head_hash
($project);
2792 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2793 my %co = parse_commit
($hash_base)
2794 or die_error
(undef, "Reading commit failed");
2795 if (!defined $hash) {
2796 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2797 or die_error
(undef, "Error lookup file");
2799 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2800 or die_error
(undef, "Open git-annotate failed");
2803 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2806 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2809 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2811 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2812 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2813 git_print_page_path
($file_name, 'blob', $hash_base);
2814 print "<div class=\"page_body\">\n";
2816 <table class="blame">
2825 my @line_class = (qw(light dark));
2826 my $line_class_len = scalar (@line_class);
2827 my $line_class_num = $#line_class;
2828 while (my $line = <$fd>) {
2840 $line_class_num = ($line_class_num + 1) % $line_class_len;
2842 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2849 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
2852 $short_rev = substr ($long_rev, 0, 8);
2853 $age = time () - $time;
2854 $age_str = age_string
($age);
2855 $age_str =~ s/ / /g;
2856 $age_class = age_class
($age);
2857 $author = esc_html
($author);
2858 $author =~ s/ / /g;
2860 $data = untabify
($data);
2861 $data = esc_html
($data);
2864 <tr class="$line_class[$line_class_num]">
2865 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2866 <td class="$age_class">$age_str</td>
2868 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2869 <td class="pre">$data</td>
2872 } # while (my $line = <$fd>)
2873 print "</table>\n\n";
2875 or print "Reading blob failed.\n";
2881 my $head = git_get_head_hash
($project);
2883 git_print_page_nav
('','', $head,undef,$head);
2884 git_print_header_div
('summary', $project);
2886 my ($taglist) = git_get_refs_list
("tags");
2888 git_tags_body
($taglist);
2894 my $head = git_get_head_hash
($project);
2896 git_print_page_nav
('','', $head,undef,$head);
2897 git_print_header_div
('summary', $project);
2899 my ($headlist) = git_get_refs_list
("heads");
2901 git_heads_body
($headlist, $head);
2906 sub git_blob_plain
{
2909 if (!defined $hash) {
2910 if (defined $file_name) {
2911 my $base = $hash_base || git_get_head_hash
($project);
2912 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2913 or die_error
(undef, "Error lookup file");
2915 die_error
(undef, "No file name defined");
2917 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2918 # blobs defined by non-textual hash id's can be cached
2923 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2924 or die_error
(undef, "Couldn't cat $file_name, $hash");
2926 $type ||= blob_mimetype
($fd, $file_name);
2928 # save as filename, even when no $file_name is given
2929 my $save_as = "$hash";
2930 if (defined $file_name) {
2931 $save_as = $file_name;
2932 } elsif ($type =~ m/^text\//) {
2939 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
2941 binmode STDOUT
, ':raw';
2943 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2951 if (!defined $hash) {
2952 if (defined $file_name) {
2953 my $base = $hash_base || git_get_head_hash
($project);
2954 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2955 or die_error
(undef, "Error lookup file");
2957 die_error
(undef, "No file name defined");
2959 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2960 # blobs defined by non-textual hash id's can be cached
2964 my ($have_blame) = gitweb_check_feature
('blame');
2965 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2966 or die_error
(undef, "Couldn't cat $file_name, $hash");
2967 my $mimetype = blob_mimetype
($fd, $file_name);
2968 if ($mimetype !~ m/^text\//) {
2970 return git_blob_plain
($mimetype);
2972 git_header_html
(undef, $expires);
2973 my $formats_nav = '';
2974 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2975 if (defined $file_name) {
2978 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2979 hash
=>$hash, file_name
=>$file_name)},
2984 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2985 hash
=>$hash, file_name
=>$file_name)},
2988 $cgi->a({-href
=> href
(action
=>"blob_plain",
2989 hash
=>$hash, file_name
=>$file_name)},
2992 $cgi->a({-href
=> href
(action
=>"blob",
2993 hash_base
=>"HEAD", file_name
=>$file_name)},
2997 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
2999 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3000 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3002 print "<div class=\"page_nav\">\n" .
3003 "<br/><br/></div>\n" .
3004 "<div class=\"title\">$hash</div>\n";
3006 git_print_page_path
($file_name, "blob", $hash_base);
3007 print "<div class=\"page_body\">\n";
3009 while (my $line = <$fd>) {
3012 $line = untabify
($line);
3013 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3014 $nr, $nr, $nr, esc_html
($line);
3017 or print "Reading blob failed.\n";
3023 my $have_snapshot = gitweb_have_snapshot
();
3025 if (!defined $hash_base) {
3026 $hash_base = "HEAD";
3028 if (!defined $hash) {
3029 if (defined $file_name) {
3030 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3036 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3037 or die_error
(undef, "Open git-ls-tree failed");
3038 my @entries = map { chomp; $_ } <$fd>;
3039 close $fd or die_error
(undef, "Reading tree failed");
3042 my $refs = git_get_references
();
3043 my $ref = format_ref_marker
($refs, $hash_base);
3046 my ($have_blame) = gitweb_check_feature
('blame');
3047 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3049 if (defined $file_name) {
3051 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3052 hash
=>$hash, file_name
=>$file_name)},
3054 $cgi->a({-href
=> href
(action
=>"tree",
3055 hash_base
=>"HEAD", file_name
=>$file_name)},
3058 if ($have_snapshot) {
3059 # FIXME: Should be available when we have no hash base as well.
3061 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3064 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3065 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3068 print "<div class=\"page_nav\">\n";
3069 print "<br/><br/></div>\n";
3070 print "<div class=\"title\">$hash</div>\n";
3072 if (defined $file_name) {
3073 $basedir = $file_name;
3074 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3078 git_print_page_path
($file_name, 'tree', $hash_base);
3079 print "<div class=\"page_body\">\n";
3080 print "<table cellspacing=\"0\">\n";
3082 # '..' (top directory) link if possible
3083 if (defined $hash_base &&
3084 defined $file_name && $file_name =~ m![^/]+$!) {
3086 print "<tr class=\"dark\">\n";
3088 print "<tr class=\"light\">\n";
3092 my $up = $file_name;
3093 $up =~ s!/?[^/]+$!!;
3094 undef $up unless $up;
3095 # based on git_print_tree_entry
3096 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3097 print '<td class="list">';
3098 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3102 print "<td class=\"link\"></td>\n";
3106 foreach my $line (@entries) {
3107 my %t = parse_ls_tree_line
($line, -z
=> 1);
3110 print "<tr class=\"dark\">\n";
3112 print "<tr class=\"light\">\n";
3116 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3120 print "</table>\n" .
3126 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3127 my $have_snapshot = (defined $ctype && defined $suffix);
3128 if (!$have_snapshot) {
3129 die_error
('403 Permission denied', "Permission denied");
3132 if (!defined $hash) {
3133 $hash = git_get_head_hash
($project);
3136 my $filename = basename
($project) . "-$hash.tar.$suffix";
3139 -type
=> 'application/x-tar',
3140 -content_encoding
=> $ctype,
3141 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3142 -status
=> '200 OK');
3144 my $git = git_cmd_str
();
3145 my $name = $project;
3146 $name =~ s/\047/\047\\\047\047/g;
3148 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3149 or die_error
(undef, "Execute git-tar-tree failed.");
3150 binmode STDOUT
, ':raw';
3152 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3158 my $head = git_get_head_hash
($project);
3159 if (!defined $hash) {
3162 if (!defined $page) {
3165 my $refs = git_get_references
();
3167 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3168 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3169 or die_error
(undef, "Open git-rev-list failed");
3170 my @revlist = map { chomp; $_ } <$fd>;
3173 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
3176 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3179 my %co = parse_commit
($hash);
3181 git_print_header_div
('summary', $project);
3182 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3184 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
3185 my $commit = $revlist[$i];
3186 my $ref = format_ref_marker
($refs, $commit);
3187 my %co = parse_commit
($commit);
3189 my %ad = parse_date
($co{'author_epoch'});
3190 git_print_header_div
('commit',
3191 "<span class=\"age\">$co{'age_string'}</span>" .
3192 esc_html
($co{'title'}) . $ref,
3194 print "<div class=\"title_text\">\n" .
3195 "<div class=\"log_link\">\n" .
3196 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3198 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3200 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3203 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3206 print "<div class=\"log_body\">\n";
3207 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
3214 my %co = parse_commit
($hash);
3216 die_error
(undef, "Unknown commit object");
3218 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3219 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3221 my $parent = $co{'parent'};
3222 if (!defined $parent) {
3225 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
3226 @diff_opts, $parent, $hash
3227 or die_error
(undef, "Open git-diff-tree failed");
3228 my @difftree = map { chomp; $_ } <$fd>;
3229 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3231 # non-textual hash id's can be cached
3233 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3236 my $refs = git_get_references
();
3237 my $ref = format_ref_marker
($refs, $co{'id'});
3239 my $have_snapshot = gitweb_have_snapshot
();
3242 if (defined $file_name && defined $co{'parent'}) {
3244 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
3247 git_header_html
(undef, $expires);
3248 git_print_page_nav
('commit', '',
3249 $hash, $co{'tree'}, $hash,
3250 join (' | ', @views_nav));
3252 if (defined $co{'parent'}) {
3253 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3255 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3257 print "<div class=\"title_text\">\n" .
3258 "<table cellspacing=\"0\">\n";
3259 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3261 "<td></td><td> $ad{'rfc2822'}";
3262 if ($ad{'hour_local'} < 6) {
3263 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3264 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3266 printf(" (%02d:%02d %s)",
3267 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3271 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3272 print "<tr><td></td><td> $cd{'rfc2822'}" .
3273 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3275 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3278 "<td class=\"sha1\">" .
3279 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3280 class => "list"}, $co{'tree'}) .
3282 "<td class=\"link\">" .
3283 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3285 if ($have_snapshot) {
3287 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3291 my $parents = $co{'parents'};
3292 foreach my $par (@$parents) {
3295 "<td class=\"sha1\">" .
3296 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3297 class => "list"}, $par) .
3299 "<td class=\"link\">" .
3300 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3302 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3309 print "<div class=\"page_body\">\n";
3310 git_print_log
($co{'comment'});
3313 git_difftree_body
(\
@difftree, $hash, $parent);
3319 my $format = shift || 'html';
3326 # preparing $fd and %diffinfo for git_patchset_body
3328 if (defined $hash_base && defined $hash_parent_base) {
3329 if (defined $file_name) {
3331 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
3333 or die_error
(undef, "Open git-diff-tree failed");
3334 @difftree = map { chomp; $_ } <$fd>;
3336 or die_error
(undef, "Reading git-diff-tree failed");
3338 or die_error
('404 Not Found', "Blob diff not found");
3340 } elsif (defined $hash &&
3341 $hash =~ /[0-9a-fA-F]{40}/) {
3342 # try to find filename from $hash
3344 # read filtered raw output
3345 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
3346 or die_error
(undef, "Open git-diff-tree failed");
3348 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3350 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3351 map { chomp; $_ } <$fd>;
3353 or die_error
(undef, "Reading git-diff-tree failed");
3355 or die_error
('404 Not Found', "Blob diff not found");
3358 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3361 if (@difftree > 1) {
3362 die_error
('404 Not Found', "Ambiguous blob diff specification");
3365 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3366 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3367 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3369 $hash_parent ||= $diffinfo{'from_id'};
3370 $hash ||= $diffinfo{'to_id'};
3372 # non-textual hash id's can be cached
3373 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3374 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3379 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3380 '-p', $hash_parent_base, $hash_base,
3382 or die_error
(undef, "Open git-diff-tree failed");
3385 # old/legacy style URI
3386 if (!%diffinfo && # if new style URI failed
3387 defined $hash && defined $hash_parent) {
3388 # fake git-diff-tree raw output
3389 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3390 $diffinfo{'from_id'} = $hash_parent;
3391 $diffinfo{'to_id'} = $hash;
3392 if (defined $file_name) {
3393 if (defined $file_parent) {
3394 $diffinfo{'status'} = '2';
3395 $diffinfo{'from_file'} = $file_parent;
3396 $diffinfo{'to_file'} = $file_name;
3397 } else { # assume not renamed
3398 $diffinfo{'status'} = '1';
3399 $diffinfo{'from_file'} = $file_name;
3400 $diffinfo{'to_file'} = $file_name;
3402 } else { # no filename given
3403 $diffinfo{'status'} = '2';
3404 $diffinfo{'from_file'} = $hash_parent;
3405 $diffinfo{'to_file'} = $hash;
3408 # non-textual hash id's can be cached
3409 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3410 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3415 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts, $hash_parent, $hash
3416 or die_error
(undef, "Open git-diff failed");
3418 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3423 if ($format eq 'html') {
3425 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3426 hash
=>$hash, hash_parent
=>$hash_parent,
3427 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3428 file_name
=>$file_name, file_parent
=>$file_parent)},
3430 git_header_html
(undef, $expires);
3431 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3432 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3433 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3435 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3436 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3438 if (defined $file_name) {
3439 git_print_page_path
($file_name, "blob", $hash_base);
3441 print "<div class=\"page_path\"></div>\n";
3444 } elsif ($format eq 'plain') {
3446 -type
=> 'text/plain',
3447 -charset
=> 'utf-8',
3448 -expires
=> $expires,
3449 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3451 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3454 die_error
(undef, "Unknown blobdiff format");
3458 if ($format eq 'html') {
3459 print "<div class=\"page_body\">\n";
3461 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3464 print "</div>\n"; # class="page_body"
3468 while (my $line = <$fd>) {
3469 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_html($diffinfo{'from_file'})!eg;
3470 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_html($diffinfo{'to_file'})!eg;
3474 last if $line =~ m!^\+\+\+!;
3482 sub git_blobdiff_plain
{
3483 git_blobdiff
('plain');
3486 sub git_commitdiff
{
3487 my $format = shift || 'html';
3488 my %co = parse_commit
($hash);
3490 die_error
(undef, "Unknown commit object");
3492 if (!defined $hash_parent) {
3493 $hash_parent = $co{'parent'} || '--root';
3499 if ($format eq 'html') {
3500 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3502 "--patch-with-raw", "--full-index", $hash_parent, $hash
3503 or die_error
(undef, "Open git-diff-tree failed");
3505 while (chomp(my $line = <$fd>)) {
3506 # empty line ends raw part of diff-tree output
3508 push @difftree, $line;
3511 } elsif ($format eq 'plain') {
3512 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3513 '-p', $hash_parent, $hash
3514 or die_error
(undef, "Open git-diff-tree failed");
3517 die_error
(undef, "Unknown commitdiff format");
3520 # non-textual hash id's can be cached
3522 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3526 # write commit message
3527 if ($format eq 'html') {
3528 my $refs = git_get_references
();
3529 my $ref = format_ref_marker
($refs, $co{'id'});
3531 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3532 hash
=>$hash, hash_parent
=>$hash_parent)},
3535 git_header_html
(undef, $expires);
3536 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3537 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3538 git_print_authorship
(\
%co);
3539 print "<div class=\"page_body\">\n";
3540 if (@{$co{'comment'}} > 1) {
3541 print "<div class=\"log\">\n";
3542 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
3543 print "</div>\n"; # class="log"
3546 } elsif ($format eq 'plain') {
3547 my $refs = git_get_references
("tags");
3548 my $tagname = git_get_rev_name_tags
($hash);
3549 my $filename = basename
($project) . "-$hash.patch";
3552 -type
=> 'text/plain',
3553 -charset
=> 'utf-8',
3554 -expires
=> $expires,
3555 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3556 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3559 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3560 Subject: $co{'title'}
3562 print "X-Git-Tag: $tagname\n" if $tagname;
3563 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3565 foreach my $line (@{$co{'comment'}}) {
3572 if ($format eq 'html') {
3573 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3576 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3578 print "</div>\n"; # class="page_body"
3581 } elsif ($format eq 'plain') {
3585 or print "Reading git-diff-tree failed\n";
3589 sub git_commitdiff_plain
{
3590 git_commitdiff
('plain');
3594 if (!defined $hash_base) {
3595 $hash_base = git_get_head_hash
($project);
3597 if (!defined $page) {
3601 my %co = parse_commit
($hash_base);
3603 die_error
(undef, "Unknown commit object");
3606 my $refs = git_get_references
();
3607 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3609 if (!defined $hash && defined $file_name) {
3610 $hash = git_get_hash_by_path
($hash_base, $file_name);
3612 if (defined $hash) {
3613 $ftype = git_get_type
($hash);
3617 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3618 or die_error
(undef, "Open git-rev-list-failed");
3619 my @revlist = map { chomp; $_ } <$fd>;
3621 or die_error
(undef, "Reading git-rev-list failed");
3623 my $paging_nav = '';
3626 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3627 file_name
=>$file_name)},
3629 $paging_nav .= " ⋅ " .
3630 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3631 file_name
=>$file_name, page
=>$page-1),
3632 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3634 $paging_nav .= "first";
3635 $paging_nav .= " ⋅ prev";
3637 if ($#revlist >= (100 * ($page+1)-1)) {
3638 $paging_nav .= " ⋅ " .
3639 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3640 file_name
=>$file_name, page
=>$page+1),
3641 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3643 $paging_nav .= " ⋅ next";
3646 if ($#revlist >= (100 * ($page+1)-1)) {
3648 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3649 file_name
=>$file_name, page
=>$page+1),
3650 -title
=> "Alt-n"}, "next");
3654 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3655 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3656 git_print_page_path
($file_name, $ftype, $hash_base);
3658 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3659 $refs, $hash_base, $ftype, $next_link);
3665 if (!defined $searchtext) {
3666 die_error
(undef, "Text field empty");
3668 if (!defined $hash) {
3669 $hash = git_get_head_hash
($project);
3671 my %co = parse_commit
($hash);
3673 die_error
(undef, "Unknown commit object");
3676 $searchtype ||= 'commit';
3677 if ($searchtype eq 'pickaxe') {
3678 # pickaxe may take all resources of your box and run for several minutes
3679 # with every query - so decide by yourself how public you make this feature
3680 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3681 if (!$have_pickaxe) {
3682 die_error
('403 Permission denied', "Permission denied");
3687 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3688 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3690 print "<table cellspacing=\"0\">\n";
3692 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
3694 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", $hash or next;
3695 while (my $commit_text = <$fd>) {
3696 if (!grep m/$searchtext/i, $commit_text) {
3699 if ($searchtype eq 'author' && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3702 if ($searchtype eq 'committer' && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3705 my @commit_lines = split "\n", $commit_text;
3706 my %co = parse_commit
(undef, \
@commit_lines);
3711 print "<tr class=\"dark\">\n";
3713 print "<tr class=\"light\">\n";
3716 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3717 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3719 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3720 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3721 my $comment = $co{'comment'};
3722 foreach my $line (@$comment) {
3723 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3724 my $lead = esc_html
($1) || "";
3725 $lead = chop_str
($lead, 30, 10);
3726 my $match = esc_html
($2) || "";
3727 my $trail = esc_html
($3) || "";
3728 $trail = chop_str
($trail, 30, 10);
3729 my $text = "$lead<span class=\"match\">$match</span>$trail";
3730 print chop_str
($text, 80, 5) . "<br/>\n";
3734 "<td class=\"link\">" .
3735 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3737 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3744 if ($searchtype eq 'pickaxe') {
3746 my $git_command = git_cmd_str
();
3747 open my $fd, "-|", "$git_command rev-list $hash | " .
3748 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3751 while (my $line = <$fd>) {
3752 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3755 $set{'from_id'} = $3;
3757 $set{'id'} = $set{'to_id'};
3758 if ($set{'id'} =~ m/0{40}/) {
3759 $set{'id'} = $set{'from_id'};
3761 if ($set{'id'} =~ m/0{40}/) {
3765 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3768 print "<tr class=\"dark\">\n";
3770 print "<tr class=\"light\">\n";
3773 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3774 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3776 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3777 -class => "list subject"},
3778 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3779 while (my $setref = shift @files) {
3781 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3782 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3784 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3788 "<td class=\"link\">" .
3789 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3791 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3795 %co = parse_commit
($1);
3804 sub git_search_help
{
3806 git_print_page_nav
('','', $hash,$hash,$hash);
3809 <dt><b>commit</b></dt>
3810 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
3811 <dt><b>author</b></dt>
3812 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
3813 <dt><b>committer</b></dt>
3814 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
3816 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3817 if ($have_pickaxe) {
3819 <dt><b>pickaxe</b></dt>
3820 <dd>All commits that caused the string to appear or disappear from any file (changes that
3821 added, removed or "modified" the string) will be listed. This search can take a while and
3822 takes a lot of strain on the server, so please use it wisely.</dd>
3830 my $head = git_get_head_hash
($project);
3831 if (!defined $hash) {
3834 if (!defined $page) {
3837 my $refs = git_get_references
();
3839 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3840 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3841 or die_error
(undef, "Open git-rev-list failed");
3842 my @revlist = map { chomp; $_ } <$fd>;
3845 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3847 if ($#revlist >= (100 * ($page+1)-1)) {
3849 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3850 -title
=> "Alt-n"}, "next");
3855 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3856 git_print_header_div
('summary', $project);
3858 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3863 ## ......................................................................
3864 ## feeds (RSS, OPML)
3867 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3868 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150", git_get_head_hash
($project)
3869 or die_error
(undef, "Open git-rev-list failed");
3870 my @revlist = map { chomp; $_ } <$fd>;
3871 close $fd or die_error
(undef, "Reading git-rev-list failed");
3872 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3874 <?xml version="1.0" encoding="utf-8"?>
3875 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3877 <title>$project $my_uri $my_url</title>
3878 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3879 <description>$project log</description>
3880 <language>en</language>
3883 for (my $i = 0; $i <= $#revlist; $i++) {
3884 my $commit = $revlist[$i];
3885 my %co = parse_commit
($commit);
3886 # we read 150, we always show 30 and the ones more recent than 48 hours
3887 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3890 my %cd = parse_date
($co{'committer_epoch'});
3891 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3892 $co{'parent'}, $co{'id'}
3894 my @difftree = map { chomp; $_ } <$fd>;
3899 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3901 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3902 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3903 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3904 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3905 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3906 "<content:encoded>" .
3908 my $comment = $co{'comment'};
3909 foreach my $line (@$comment) {
3910 $line = to_utf8
($line);
3911 print "$line<br/>\n";
3914 foreach my $line (@difftree) {
3915 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3918 my $file = esc_html
(unquote
($7));
3919 $file = to_utf8
($file);
3920 print "$file<br/>\n";
3923 "</content:encoded>\n" .
3926 print "</channel></rss>";
3930 my @list = git_get_projects_list
();
3932 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3934 <?xml version="1.0" encoding="utf-8"?>
3935 <opml version="1.0">
3937 <title>$site_name OPML Export</title>
3940 <outline text="git RSS feeds">
3943 foreach my $pr (@list) {
3945 my $head = git_get_head_hash
($proj{'path'});
3946 if (!defined $head) {
3949 $git_dir = "$projectroot/$proj{'path'}";
3950 my %co = parse_commit
($head);
3955 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3956 my $rss = "$my_url?p=$proj{'path'};a=rss";
3957 my $html = "$my_url?p=$proj{'path'};a=summary";
3958 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";