3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 our $version = "++GIT_VERSION++";
23 our $my_url = $cgi->url();
24 our $my_uri = $cgi->url(-absolute
=> 1);
26 # core git executable to use
27 # this can just be "git" if your webserver has a sensible PATH
28 our $GIT = "++GIT_BINDIR++/git";
30 # absolute fs-path which will be prepended to the project path
31 #our $projectroot = "/pub/scm";
32 our $projectroot = "++GITWEB_PROJECTROOT++";
34 # target of the home link on top of all pages
35 our $home_link = $my_uri || "/";
37 # string of the home link on top of all pages
38 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
40 # name of your site or organization to appear in page titles
41 # replace this with something more descriptive for clearer bookmarks
42 our $site_name = "++GITWEB_SITENAME++"
43 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
45 # filename of html text to include at top of each page
46 our $site_header = "++GITWEB_SITE_HEADER++";
47 # html text to include at home page
48 our $home_text = "++GITWEB_HOMETEXT++";
49 # filename of html text to include at bottom of each page
50 our $site_footer = "++GITWEB_SITE_FOOTER++";
53 our @stylesheets = ("++GITWEB_CSS++");
54 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
55 our $stylesheet = undef;
56 # URI of GIT logo (72x27 size)
57 our $logo = "++GITWEB_LOGO++";
58 # URI of GIT favicon, assumed to be image/png type
59 our $favicon = "++GITWEB_FAVICON++";
61 # URI and label (title) of GIT logo link
62 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
63 #our $logo_label = "git documentation";
64 our $logo_url = "http://git.or.cz/";
65 our $logo_label = "git homepage";
67 # source of projects list
68 our $projects_list = "++GITWEB_LIST++";
70 # show repository only if this file exists
71 # (only effective if this variable evaluates to true)
72 our $export_ok = "++GITWEB_EXPORT_OK++";
74 # only allow viewing of repositories also shown on the overview page
75 our $strict_export = "++GITWEB_STRICT_EXPORT++";
77 # list of git base URLs used for URL to where fetch project from,
78 # i.e. full URL is "$git_base_url/$project"
79 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
81 # default blob_plain mimetype and default charset for text/plain blob
82 our $default_blob_plain_mimetype = 'text/plain';
83 our $default_text_plain_charset = undef;
85 # file to use for guessing MIME types before trying /etc/mime.types
86 # (relative to the current git repository)
87 our $mimetypes_file = undef;
89 # You define site-wide feature defaults here; override them with
90 # $GITWEB_CONFIG as necessary.
93 # 'sub' => feature-sub (subroutine),
94 # 'override' => allow-override (boolean),
95 # 'default' => [ default options...] (array reference)}
97 # if feature is overridable (it means that allow-override has true value,
98 # then feature-sub will be called with default options as parameters;
99 # return value of feature-sub indicates if to enable specified feature
101 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
103 # Enable the 'blame' blob view, showing the last commit that modified
104 # each line in the file. This can be very CPU-intensive.
106 # To enable system wide have in $GITWEB_CONFIG
107 # $feature{'blame'}{'default'} = [1];
108 # To have project specific config enable override in $GITWEB_CONFIG
109 # $feature{'blame'}{'override'} = 1;
110 # and in project config gitweb.blame = 0|1;
112 'sub' => \
&feature_blame
,
116 # Enable the 'snapshot' link, providing a compressed tarball of any
117 # tree. This can potentially generate high traffic if you have large
120 # To disable system wide have in $GITWEB_CONFIG
121 # $feature{'snapshot'}{'default'} = [undef];
122 # To have project specific config enable override in $GITWEB_CONFIG
123 # $feature{'blame'}{'override'} = 1;
124 # and in project config gitweb.snapshot = none|gzip|bzip2;
126 'sub' => \
&feature_snapshot
,
128 # => [content-encoding, suffix, program]
129 'default' => ['x-gzip', 'gz', 'gzip']},
131 # Enable the pickaxe search, which will list the commits that modified
132 # a given string in a file. This can be practical and quite faster
133 # alternative to 'blame', but still potentially CPU-intensive.
135 # To enable system wide have in $GITWEB_CONFIG
136 # $feature{'pickaxe'}{'default'} = [1];
137 # To have project specific config enable override in $GITWEB_CONFIG
138 # $feature{'pickaxe'}{'override'} = 1;
139 # and in project config gitweb.pickaxe = 0|1;
141 'sub' => \
&feature_pickaxe
,
145 # Make gitweb use an alternative format of the URLs which can be
146 # more readable and natural-looking: project name is embedded
147 # directly in the path and the query string contains other
148 # auxiliary information. All gitweb installations recognize
149 # URL in either format; this configures in which formats gitweb
152 # To enable system wide have in $GITWEB_CONFIG
153 # $feature{'pathinfo'}{'default'} = [1];
154 # Project specific override is not supported.
156 # Note that you will need to change the default location of CSS,
157 # favicon, logo and possibly other files to an absolute URL. Also,
158 # if gitweb.cgi serves as your indexfile, you will need to force
159 # $my_uri to contain the script name in your $GITWEB_CONFIG.
165 sub gitweb_check_feature
{
167 return unless exists $feature{$name};
168 my ($sub, $override, @defaults) = (
169 $feature{$name}{'sub'},
170 $feature{$name}{'override'},
171 @
{$feature{$name}{'default'}});
172 if (!$override) { return @defaults; }
174 warn "feature $name is not overrideable";
177 return $sub->(@defaults);
181 my ($val) = git_get_project_config
('blame', '--bool');
183 if ($val eq 'true') {
185 } elsif ($val eq 'false') {
192 sub feature_snapshot
{
193 my ($ctype, $suffix, $command) = @_;
195 my ($val) = git_get_project_config
('snapshot');
197 if ($val eq 'gzip') {
198 return ('x-gzip', 'gz', 'gzip');
199 } elsif ($val eq 'bzip2') {
200 return ('x-bzip2', 'bz2', 'bzip2');
201 } elsif ($val eq 'none') {
205 return ($ctype, $suffix, $command);
208 sub gitweb_have_snapshot
{
209 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
210 my $have_snapshot = (defined $ctype && defined $suffix);
212 return $have_snapshot;
215 sub feature_pickaxe
{
216 my ($val) = git_get_project_config
('pickaxe', '--bool');
218 if ($val eq 'true') {
220 } elsif ($val eq 'false') {
227 # checking HEAD file with -e is fragile if the repository was
228 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
230 sub check_head_link
{
232 my $headfile = "$dir/HEAD";
233 return ((-e
$headfile) ||
234 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
237 sub check_export_ok
{
239 return (check_head_link
($dir) &&
240 (!$export_ok || -e
"$dir/$export_ok"));
243 # rename detection options for git-diff and git-diff-tree
244 # - default is '-M', with the cost proportional to
245 # (number of removed files) * (number of new files).
246 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
247 # (number of changed files + number of removed files) * (number of new files)
248 # - even more costly is '-C', '--find-copies-harder' with cost
249 # (number of files in the original tree) * (number of new files)
250 # - one might want to include '-B' option, e.g. '-B', '-M'
251 our @diff_opts = ('-M'); # taken from git_commit
253 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
254 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
256 # version of the core git binary
257 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
259 $projects_list ||= $projectroot;
261 # ======================================================================
262 # input validation and dispatch
263 our $action = $cgi->param('a');
264 if (defined $action) {
265 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
266 die_error
(undef, "Invalid action parameter");
270 # parameters which are pathnames
271 our $project = $cgi->param('p');
272 if (defined $project) {
273 if (!validate_pathname
($project) ||
274 !(-d
"$projectroot/$project") ||
275 !check_head_link
("$projectroot/$project") ||
276 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
277 ($strict_export && !project_in_list
($project))) {
279 die_error
(undef, "No such project");
283 our $file_name = $cgi->param('f');
284 if (defined $file_name) {
285 if (!validate_pathname
($file_name)) {
286 die_error
(undef, "Invalid file parameter");
290 our $file_parent = $cgi->param('fp');
291 if (defined $file_parent) {
292 if (!validate_pathname
($file_parent)) {
293 die_error
(undef, "Invalid file parent parameter");
297 # parameters which are refnames
298 our $hash = $cgi->param('h');
300 if (!validate_refname
($hash)) {
301 die_error
(undef, "Invalid hash parameter");
305 our $hash_parent = $cgi->param('hp');
306 if (defined $hash_parent) {
307 if (!validate_refname
($hash_parent)) {
308 die_error
(undef, "Invalid hash parent parameter");
312 our $hash_base = $cgi->param('hb');
313 if (defined $hash_base) {
314 if (!validate_refname
($hash_base)) {
315 die_error
(undef, "Invalid hash base parameter");
319 our $hash_parent_base = $cgi->param('hpb');
320 if (defined $hash_parent_base) {
321 if (!validate_refname
($hash_parent_base)) {
322 die_error
(undef, "Invalid hash parent base parameter");
327 our $page = $cgi->param('pg');
329 if ($page =~ m/[^0-9]/) {
330 die_error
(undef, "Invalid page parameter");
334 our $searchtext = $cgi->param('s');
335 if (defined $searchtext) {
336 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
337 die_error
(undef, "Invalid search parameter");
339 $searchtext = quotemeta $searchtext;
342 our $searchtype = $cgi->param('st');
343 if (defined $searchtype) {
344 if ($searchtype =~ m/[^a-z]/) {
345 die_error
(undef, "Invalid searchtype parameter");
349 # now read PATH_INFO and use it as alternative to parameters
350 sub evaluate_path_info
{
351 return if defined $project;
352 my $path_info = $ENV{"PATH_INFO"};
353 return if !$path_info;
354 $path_info =~ s
,^/+,,;
355 return if !$path_info;
356 # find which part of PATH_INFO is project
357 $project = $path_info;
359 while ($project && !check_head_link
("$projectroot/$project")) {
360 $project =~ s
,/*[^/]*$,,;
363 $project = validate_pathname
($project);
365 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
366 ($strict_export && !project_in_list
($project))) {
370 # do not change any parameters if an action is given using the query string
372 $path_info =~ s
,^$project/*,,;
373 my ($refname, $pathname) = split(/:/, $path_info, 2);
374 if (defined $pathname) {
375 # we got "project.git/branch:filename" or "project.git/branch:dir/"
376 # we could use git_get_type(branch:pathname), but it needs $git_dir
377 $pathname =~ s
,^/+,,;
378 if (!$pathname || substr($pathname, -1) eq "/") {
382 $action ||= "blob_plain";
384 $hash_base ||= validate_refname
($refname);
385 $file_name ||= validate_pathname
($pathname);
386 } elsif (defined $refname) {
387 # we got "project.git/branch"
388 $action ||= "shortlog";
389 $hash ||= validate_refname
($refname);
392 evaluate_path_info
();
394 # path to the current git repository
396 $git_dir = "$projectroot/$project" if $project;
400 "blame" => \
&git_blame2
,
401 "blobdiff" => \
&git_blobdiff
,
402 "blobdiff_plain" => \
&git_blobdiff_plain
,
403 "blob" => \
&git_blob
,
404 "blob_plain" => \
&git_blob_plain
,
405 "commitdiff" => \
&git_commitdiff
,
406 "commitdiff_plain" => \
&git_commitdiff_plain
,
407 "commit" => \
&git_commit
,
408 "heads" => \
&git_heads
,
409 "history" => \
&git_history
,
412 "search" => \
&git_search
,
413 "search_help" => \
&git_search_help
,
414 "shortlog" => \
&git_shortlog
,
415 "summary" => \
&git_summary
,
417 "tags" => \
&git_tags
,
418 "tree" => \
&git_tree
,
419 "snapshot" => \
&git_snapshot
,
420 # those below don't need $project
421 "opml" => \
&git_opml
,
422 "project_list" => \
&git_project_list
,
423 "project_index" => \
&git_project_index
,
426 if (defined $project) {
427 $action ||= 'summary';
429 $action ||= 'project_list';
431 if (!defined($actions{$action})) {
432 die_error
(undef, "Unknown action");
434 if ($action !~ m/^(opml|project_list|project_index)$/ &&
436 die_error
(undef, "Project needed");
438 $actions{$action}->();
441 ## ======================================================================
448 # XXX: Warning: If you touch this, check the search form for updating,
459 hash_parent_base
=> "hpb",
465 my %mapping = @mapping;
467 $params{'project'} = $project unless exists $params{'project'};
469 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
471 # use PATH_INFO for project name
472 $href .= "/$params{'project'}" if defined $params{'project'};
473 delete $params{'project'};
475 # Summary just uses the project path URL
476 if (defined $params{'action'} && $params{'action'} eq 'summary') {
477 delete $params{'action'};
481 # now encode the parameters explicitly
483 for (my $i = 0; $i < @mapping; $i += 2) {
484 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
485 if (defined $params{$name}) {
486 push @result, $symbol . "=" . esc_param
($params{$name});
489 $href .= "?" . join(';', @result) if scalar @result;
495 ## ======================================================================
496 ## validation, quoting/unquoting and escaping
498 sub validate_pathname
{
499 my $input = shift || return undef;
501 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
502 # at the beginning, at the end, and between slashes.
503 # also this catches doubled slashes
504 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
508 if ($input =~ m!\0!) {
514 sub validate_refname
{
515 my $input = shift || return undef;
517 # textual hashes are O.K.
518 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
521 # it must be correct pathname
522 $input = validate_pathname
($input)
524 # restrictions on ref name according to git-check-ref-format
525 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
531 # very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT);
534 return decode
("utf8", $str, Encode
::FB_DEFAULT
);
537 # quote unsafe chars, but keep the slash, even when it's not
538 # correct, but quoted slashes look too horrible in bookmarks
541 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
547 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
550 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
556 # replace invalid utf8 character with SUBSTITUTION sequence
559 $str = to_utf8
($str);
560 $str = escapeHTML
($str);
561 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
562 $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1)
566 # quote unsafe characters (TODO) and escape filename to HTML
569 return esc_html
($str);
572 # git may return quoted and escaped filenames
575 if ($str =~ m/^"(.*)"$/) {
577 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
582 # escape tabs (convert tabs to spaces)
586 while ((my $pos = index($line, "\t")) != -1) {
587 if (my $count = (8 - ($pos % 8))) {
588 my $spaces = ' ' x
$count;
589 $line =~ s/\t/$spaces/;
596 sub project_in_list
{
598 my @list = git_get_projects_list
();
599 return @list && scalar(grep { $_->{'path'} eq $project } @list);
602 ## ----------------------------------------------------------------------
603 ## HTML aware string manipulation
608 my $add_len = shift || 10;
610 # allow only $len chars, but don't cut a word if it would fit in $add_len
611 # if it doesn't fit, cut it if it's still longer than the dots we would add
612 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
615 if (length($tail) > 4) {
617 $body =~ s/&[^;]*$//; # remove chopped character entities
622 ## ----------------------------------------------------------------------
623 ## functions returning short strings
625 # CSS class for given age value (in seconds)
629 if ($age < 60*60*2) {
631 } elsif ($age < 60*60*24*2) {
638 # convert age in seconds to "nn units ago" string
643 if ($age > 60*60*24*365*2) {
644 $age_str = (int $age/60/60/24/365);
645 $age_str .= " years ago";
646 } elsif ($age > 60*60*24*(365/12)*2) {
647 $age_str = int $age/60/60/24/(365/12);
648 $age_str .= " months ago";
649 } elsif ($age > 60*60*24*7*2) {
650 $age_str = int $age/60/60/24/7;
651 $age_str .= " weeks ago";
652 } elsif ($age > 60*60*24*2) {
653 $age_str = int $age/60/60/24;
654 $age_str .= " days ago";
655 } elsif ($age > 60*60*2) {
656 $age_str = int $age/60/60;
657 $age_str .= " hours ago";
658 } elsif ($age > 60*2) {
659 $age_str = int $age/60;
660 $age_str .= " min ago";
663 $age_str .= " sec ago";
665 $age_str .= " right now";
670 # convert file mode in octal to symbolic file mode string
672 my $mode = oct shift;
674 if (S_ISDIR
($mode & S_IFMT
)) {
676 } elsif (S_ISLNK
($mode)) {
678 } elsif (S_ISREG
($mode)) {
679 # git cares only about the executable bit
680 if ($mode & S_IXUSR
) {
690 # convert file mode in octal to file type string
694 if ($mode !~ m/^[0-7]+$/) {
700 if (S_ISDIR
($mode & S_IFMT
)) {
702 } elsif (S_ISLNK
($mode)) {
704 } elsif (S_ISREG
($mode)) {
711 ## ----------------------------------------------------------------------
712 ## functions returning short HTML fragments, or transforming HTML fragments
713 ## which don't beling to other sections
715 # format line of commit message or tag comment
716 sub format_log_line_html
{
719 $line = esc_html
($line);
720 $line =~ s/ / /g;
721 if ($line =~ m/([0-9a-fA-F]{40})/) {
723 if (git_get_type
($hash_text) eq "commit") {
725 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
726 -class => "text"}, $hash_text);
727 $line =~ s/$hash_text/$link/;
733 # format marker of refs pointing to given object
734 sub format_ref_marker
{
735 my ($refs, $id) = @_;
738 if (defined $refs->{$id}) {
739 foreach my $ref (@
{$refs->{$id}}) {
740 my ($type, $name) = qw();
741 # e.g. tags/v2.6.11 or heads/next
742 if ($ref =~ m!^(.*?)s?/(.*)$!) {
750 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
755 return ' <span class="refs">'. $markers . '</span>';
761 # format, perhaps shortened and with markers, title line
762 sub format_subject_html
{
763 my ($long, $short, $href, $extra) = @_;
764 $extra = '' unless defined($extra);
766 if (length($short) < length($long)) {
767 return $cgi->a({-href
=> $href, -class => "list subject",
768 -title
=> to_utf8
($long)},
769 esc_html
($short) . $extra);
771 return $cgi->a({-href
=> $href, -class => "list subject"},
772 esc_html
($long) . $extra);
776 sub format_diff_line
{
778 my $char = substr($line, 0, 1);
784 $diff_class = " add";
785 } elsif ($char eq "-") {
786 $diff_class = " rem";
787 } elsif ($char eq "@") {
788 $diff_class = " chunk_header";
789 } elsif ($char eq "\\") {
790 $diff_class = " incomplete";
792 $line = untabify
($line);
793 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
796 ## ----------------------------------------------------------------------
797 ## git utility subroutines, invoking git commands
799 # returns path to the core git executable and the --git-dir parameter as list
801 return $GIT, '--git-dir='.$git_dir;
804 # returns path to the core git executable and the --git-dir parameter as string
806 return join(' ', git_cmd
());
809 # get HEAD ref of given project as hash
810 sub git_get_head_hash
{
812 my $o_git_dir = $git_dir;
814 $git_dir = "$projectroot/$project";
815 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
818 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
822 if (defined $o_git_dir) {
823 $git_dir = $o_git_dir;
828 # get type of given object
832 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
839 sub git_get_project_config
{
840 my ($key, $type) = @_;
842 return unless ($key);
843 $key =~ s/^gitweb\.//;
844 return if ($key =~ m/\W/);
846 my @x = (git_cmd
(), 'repo-config');
847 if (defined $type) { push @x, $type; }
849 push @x, "gitweb.$key";
855 # get hash of given path at given ref
856 sub git_get_hash_by_path
{
858 my $path = shift || return undef;
863 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
864 or die_error
(undef, "Open git-ls-tree failed");
866 close $fd or return undef;
868 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
869 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
870 if (defined $type && $type ne $2) {
877 ## ......................................................................
878 ## git utility functions, directly accessing git repository
880 sub git_get_project_description
{
883 open my $fd, "$projectroot/$path/description" or return undef;
890 sub git_get_project_url_list
{
893 open my $fd, "$projectroot/$path/cloneurl" or return;
894 my @git_project_url_list = map { chomp; $_ } <$fd>;
897 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
900 sub git_get_projects_list
{
903 if (-d
$projects_list) {
904 # search in directory
905 my $dir = $projects_list;
906 my $pfxlen = length("$dir");
909 follow_fast
=> 1, # follow symbolic links
910 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
912 # skip project-list toplevel, if we get it.
913 return if (m!^[/.]$!);
914 # only directories can be git repositories
915 return unless (-d
$_);
917 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
918 # we check related file in $projectroot
919 if (check_export_ok
("$projectroot/$subdir")) {
920 push @list, { path
=> $subdir };
921 $File::Find
::prune
= 1;
926 } elsif (-f
$projects_list) {
927 # read from file(url-encoded):
928 # 'git%2Fgit.git Linus+Torvalds'
929 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
930 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
931 open my ($fd), $projects_list or return;
932 while (my $line = <$fd>) {
934 my ($path, $owner) = split ' ', $line;
935 $path = unescape
($path);
936 $owner = unescape
($owner);
937 if (!defined $path) {
940 if (check_export_ok
("$projectroot/$path")) {
943 owner
=> to_utf8
($owner),
950 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
954 sub git_get_project_owner
{
958 return undef unless $project;
960 # read from file (url-encoded):
961 # 'git%2Fgit.git Linus+Torvalds'
962 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
963 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
964 if (-f
$projects_list) {
965 open (my $fd , $projects_list);
966 while (my $line = <$fd>) {
968 my ($pr, $ow) = split ' ', $line;
971 if ($pr eq $project) {
972 $owner = to_utf8
($ow);
978 if (!defined $owner) {
979 $owner = get_file_owner
("$projectroot/$project");
985 sub git_get_last_activity
{
989 $git_dir = "$projectroot/$path";
990 open($fd, "-|", git_cmd
(), 'for-each-ref',
991 '--format=%(refname) %(committer)',
992 '--sort=-committerdate',
993 'refs/heads') or return;
994 my $most_recent = <$fd>;
996 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
998 my $age = time - $timestamp;
999 return ($age, age_string
($age));
1003 sub git_get_references
{
1004 my $type = shift || "";
1006 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1007 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1008 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1011 while (my $line = <$fd>) {
1013 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
1014 if (defined $refs{$1}) {
1015 push @
{$refs{$1}}, $2;
1021 close $fd or return;
1025 sub git_get_rev_name_tags
{
1026 my $hash = shift || return undef;
1028 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1030 my $name_rev = <$fd>;
1033 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1036 # catches also '$hash undefined' output
1041 ## ----------------------------------------------------------------------
1042 ## parse to hash functions
1046 my $tz = shift || "-0000";
1049 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1050 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1051 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1052 $date{'hour'} = $hour;
1053 $date{'minute'} = $min;
1054 $date{'mday'} = $mday;
1055 $date{'day'} = $days[$wday];
1056 $date{'month'} = $months[$mon];
1057 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1058 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1059 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1060 $mday, $months[$mon], $hour ,$min;
1062 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1063 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1064 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1065 $date{'hour_local'} = $hour;
1066 $date{'minute_local'} = $min;
1067 $date{'tz_local'} = $tz;
1068 $date{'iso-tz'} = sprintf ("%04d-%02d-%02d %02d:%02d:%02d %s",
1069 1900+$year, $mon+1, $mday,
1070 $hour, $min, $sec, $tz);
1079 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1080 $tag{'id'} = $tag_id;
1081 while (my $line = <$fd>) {
1083 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1084 $tag{'object'} = $1;
1085 } elsif ($line =~ m/^type (.+)$/) {
1087 } elsif ($line =~ m/^tag (.+)$/) {
1089 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1090 $tag{'author'} = $1;
1093 } elsif ($line =~ m/--BEGIN/) {
1094 push @comment, $line;
1096 } elsif ($line eq "") {
1100 push @comment, <$fd>;
1101 $tag{'comment'} = \
@comment;
1102 close $fd or return;
1103 if (!defined $tag{'name'}) {
1110 my $commit_id = shift;
1111 my $commit_text = shift;
1116 if (defined $commit_text) {
1117 @commit_lines = @
$commit_text;
1120 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
1122 @commit_lines = split '\n', <$fd>;
1123 close $fd or return;
1126 my $header = shift @commit_lines;
1127 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1130 ($co{'id'}, my @parents) = split ' ', $header;
1131 $co{'parents'} = \
@parents;
1132 $co{'parent'} = $parents[0];
1133 while (my $line = shift @commit_lines) {
1134 last if $line eq "\n";
1135 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1137 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1139 $co{'author_epoch'} = $2;
1140 $co{'author_tz'} = $3;
1141 if ($co{'author'} =~ m/^([^<]+) </) {
1142 $co{'author_name'} = $1;
1144 $co{'author_name'} = $co{'author'};
1146 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1147 $co{'committer'} = $1;
1148 $co{'committer_epoch'} = $2;
1149 $co{'committer_tz'} = $3;
1150 $co{'committer_name'} = $co{'committer'};
1151 $co{'committer_name'} =~ s/ <.*//;
1154 if (!defined $co{'tree'}) {
1158 foreach my $title (@commit_lines) {
1161 $co{'title'} = chop_str
($title, 80, 5);
1162 # remove leading stuff of merges to make the interesting part visible
1163 if (length($title) > 50) {
1164 $title =~ s/^Automatic //;
1165 $title =~ s/^merge (of|with) /Merge ... /i;
1166 if (length($title) > 50) {
1167 $title =~ s/(http|rsync):\/\///;
1169 if (length($title) > 50) {
1170 $title =~ s/(master|www|rsync)\.//;
1172 if (length($title) > 50) {
1173 $title =~ s/kernel.org:?//;
1175 if (length($title) > 50) {
1176 $title =~ s/\/pub\/scm//;
1179 $co{'title_short'} = chop_str
($title, 50, 5);
1183 if ($co{'title'} eq "") {
1184 $co{'title'} = $co{'title_short'} = '(no commit message)';
1186 # remove added spaces
1187 foreach my $line (@commit_lines) {
1190 $co{'comment'} = \
@commit_lines;
1192 my $age = time - $co{'committer_epoch'};
1194 $co{'age_string'} = age_string
($age);
1195 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1196 if ($age > 60*60*24*7*2) {
1197 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1198 $co{'age_string_age'} = $co{'age_string'};
1200 $co{'age_string_date'} = $co{'age_string'};
1201 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1206 # parse ref from ref_file, given by ref_id, with given type
1208 my $ref_file = shift;
1210 my $type = shift || git_get_type
($ref_id);
1213 $ref_item{'type'} = $type;
1214 $ref_item{'id'} = $ref_id;
1215 $ref_item{'epoch'} = 0;
1216 $ref_item{'age'} = "unknown";
1217 if ($type eq "tag") {
1218 my %tag = parse_tag
($ref_id);
1219 $ref_item{'comment'} = $tag{'comment'};
1220 if ($tag{'type'} eq "commit") {
1221 my %co = parse_commit
($tag{'object'});
1222 $ref_item{'epoch'} = $co{'committer_epoch'};
1223 $ref_item{'age'} = $co{'age_string'};
1224 } elsif (defined($tag{'epoch'})) {
1225 my $age = time - $tag{'epoch'};
1226 $ref_item{'epoch'} = $tag{'epoch'};
1227 $ref_item{'age'} = age_string
($age);
1229 $ref_item{'reftype'} = $tag{'type'};
1230 $ref_item{'name'} = $tag{'name'};
1231 $ref_item{'refid'} = $tag{'object'};
1232 } elsif ($type eq "commit"){
1233 my %co = parse_commit
($ref_id);
1234 $ref_item{'reftype'} = "commit";
1235 $ref_item{'name'} = $ref_file;
1236 $ref_item{'title'} = $co{'title'};
1237 $ref_item{'refid'} = $ref_id;
1238 $ref_item{'epoch'} = $co{'committer_epoch'};
1239 $ref_item{'age'} = $co{'age_string'};
1241 $ref_item{'reftype'} = $type;
1242 $ref_item{'name'} = $ref_file;
1243 $ref_item{'refid'} = $ref_id;
1249 # parse line of git-diff-tree "raw" output
1250 sub parse_difftree_raw_line
{
1255 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1256 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1257 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1258 $res{'from_mode'} = $1;
1259 $res{'to_mode'} = $2;
1260 $res{'from_id'} = $3;
1262 $res{'status'} = $5;
1263 $res{'similarity'} = $6;
1264 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1266 ($res{'from_file'}, $res{'to_file'}) = split("\0", $7);
1268 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1274 $res{'file'} = unquote
($7);
1278 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1279 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1280 $res{'commit'} = $1;
1283 return wantarray ?
%res : \
%res;
1286 # parse line of git-ls-tree output
1287 sub parse_ls_tree_line
($;%) {
1292 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1293 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1301 $res{'name'} = unquote
($4);
1304 return wantarray ?
%res : \
%res;
1307 ## ......................................................................
1308 ## parse to array of hashes functions
1310 sub git_get_refs_list
{
1311 my $type = shift || "";
1316 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1318 while (my $line = <$fd>) {
1320 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?([^\^]+))(\^\{\})?$/) {
1321 if (defined $refs{$1}) {
1322 push @
{$refs{$1}}, $2;
1327 if (! $4) { # unpeeled, direct reference
1328 push @refs, { hash
=> $1, name
=> $3 }; # without type
1329 } elsif ($3 eq $refs[-1]{'name'}) {
1330 # most likely a tag is followed by its peeled
1331 # (deref) one, and when that happens we know the
1332 # previous one was of type 'tag'.
1333 $refs[-1]{'type'} = "tag";
1339 foreach my $ref (@refs) {
1340 my $ref_file = $ref->{'name'};
1341 my $ref_id = $ref->{'hash'};
1343 my $type = $ref->{'type'} || git_get_type
($ref_id) || next;
1344 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1346 push @reflist, \
%ref_item;
1349 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1350 return (\
@reflist, \
%refs);
1353 ## ----------------------------------------------------------------------
1354 ## filesystem-related functions
1356 sub get_file_owner
{
1359 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1360 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1361 if (!defined $gcos) {
1365 $owner =~ s/[,;].*$//;
1366 return to_utf8
($owner);
1369 ## ......................................................................
1370 ## mimetype related functions
1372 sub mimetype_guess_file
{
1373 my $filename = shift;
1374 my $mimemap = shift;
1375 -r
$mimemap or return undef;
1378 open(MIME
, $mimemap) or return undef;
1380 next if m/^#/; # skip comments
1381 my ($mime, $exts) = split(/\t+/);
1382 if (defined $exts) {
1383 my @exts = split(/\s+/, $exts);
1384 foreach my $ext (@exts) {
1385 $mimemap{$ext} = $mime;
1391 $filename =~ /\.([^.]*)$/;
1392 return $mimemap{$1};
1395 sub mimetype_guess
{
1396 my $filename = shift;
1398 $filename =~ /\./ or return undef;
1400 if ($mimetypes_file) {
1401 my $file = $mimetypes_file;
1402 if ($file !~ m!^/!) { # if it is relative path
1403 # it is relative to project
1404 $file = "$projectroot/$project/$file";
1406 $mime = mimetype_guess_file
($filename, $file);
1408 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1414 my $filename = shift;
1417 my $mime = mimetype_guess
($filename);
1418 $mime and return $mime;
1422 return $default_blob_plain_mimetype unless $fd;
1425 return 'text/plain' .
1426 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1427 } elsif (! $filename) {
1428 return 'application/octet-stream';
1429 } elsif ($filename =~ m/\.png$/i) {
1431 } elsif ($filename =~ m/\.gif$/i) {
1433 } elsif ($filename =~ m/\.jpe?g$/i) {
1434 return 'image/jpeg';
1436 return 'application/octet-stream';
1440 ## ======================================================================
1441 ## functions printing HTML: header, footer, error page
1443 sub git_header_html
{
1444 my $status = shift || "200 OK";
1445 my $expires = shift;
1447 my $title = "$site_name";
1448 if (defined $project) {
1449 $title .= " - $project";
1450 if (defined $action) {
1451 $title .= "/$action";
1452 if (defined $file_name) {
1453 $title .= " - " . esc_html
($file_name);
1454 if ($action eq "tree" && $file_name !~ m
|/$|) {
1461 # require explicit support from the UA if we are to send the page as
1462 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1463 # we have to do this because MSIE sometimes globs '*/*', pretending to
1464 # support xhtml+xml but choking when it gets what it asked for.
1465 if (defined $cgi->http('HTTP_ACCEPT') &&
1466 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1467 $cgi->Accept('application/xhtml+xml') != 0) {
1468 $content_type = 'application/xhtml+xml';
1470 $content_type = 'text/html';
1472 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1473 -status
=> $status, -expires
=> $expires);
1475 <?xml version="1.0" encoding="utf-8"?>
1476 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1477 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1478 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1479 <!-- git core binaries version $git_version -->
1481 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1482 <meta name="generator" content="gitweb/$version git/$git_version"/>
1483 <meta name="robots" content="index, nofollow"/>
1484 <title>$title</title>
1486 # print out each stylesheet that exist
1487 if (defined $stylesheet) {
1488 #provides backwards capability for those people who define style sheet in a config file
1489 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1491 foreach my $stylesheet (@stylesheets) {
1492 next unless $stylesheet;
1493 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1496 if (defined $project) {
1497 printf('<link rel="alternate" title="%s log" '.
1498 'href="%s" type="application/rss+xml"/>'."\n",
1499 esc_param
($project), href
(action
=>"rss"));
1501 printf('<link rel="alternate" title="%s projects list" '.
1502 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1503 $site_name, href
(project
=>undef, action
=>"project_index"));
1504 printf('<link rel="alternate" title="%s projects logs" '.
1505 'href="%s" type="text/x-opml"/>'."\n",
1506 $site_name, href
(project
=>undef, action
=>"opml"));
1508 if (defined $favicon) {
1509 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
1515 if (-f
$site_header) {
1516 open (my $fd, $site_header);
1521 print "<div class=\"page_header\">\n" .
1522 $cgi->a({-href
=> esc_url
($logo_url),
1523 -title
=> $logo_label},
1524 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
1525 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1526 if (defined $project) {
1527 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1528 if (defined $action) {
1532 if (!defined $searchtext) {
1536 if (defined $hash_base) {
1537 $search_hash = $hash_base;
1538 } elsif (defined $hash) {
1539 $search_hash = $hash;
1541 $search_hash = "HEAD";
1543 $cgi->param("a", "search");
1544 $cgi->param("h", $search_hash);
1545 $cgi->param("p", $project);
1546 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1547 "<div class=\"search\">\n" .
1548 $cgi->hidden(-name
=> "p") . "\n" .
1549 $cgi->hidden(-name
=> "a") . "\n" .
1550 $cgi->hidden(-name
=> "h") . "\n" .
1551 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1552 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1553 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1555 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1557 $cgi->end_form() . "\n";
1562 sub git_footer_html
{
1563 print "<div class=\"page_footer\">\n";
1564 if (defined $project) {
1565 my $descr = git_get_project_description
($project);
1566 if (defined $descr) {
1567 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1569 print $cgi->a({-href
=> href
(action
=>"rss"),
1570 -class => "rss_logo"}, "RSS") . "\n";
1572 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1573 -class => "rss_logo"}, "OPML") . " ";
1574 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1575 -class => "rss_logo"}, "TXT") . "\n";
1579 if (-f
$site_footer) {
1580 open (my $fd, $site_footer);
1590 my $status = shift || "403 Forbidden";
1591 my $error = shift || "Malformed query, file missing or permission denied";
1593 git_header_html
($status);
1595 <div class="page_body">
1605 ## ----------------------------------------------------------------------
1606 ## functions printing or outputting HTML: navigation
1608 sub git_print_page_nav
{
1609 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1610 $extra = '' if !defined $extra; # pager or formats
1612 my @navs = qw(summary shortlog log commit commitdiff tree);
1614 @navs = grep { $_ ne $suppress } @navs;
1617 my %arg = map { $_ => {action
=>$_} } @navs;
1618 if (defined $head) {
1619 for (qw(commit commitdiff)) {
1620 $arg{$_}{hash
} = $head;
1622 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1623 for (qw(shortlog log)) {
1624 $arg{$_}{hash
} = $head;
1628 $arg{tree
}{hash
} = $treehead if defined $treehead;
1629 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1631 print "<div class=\"page_nav\">\n" .
1633 map { $_ eq $current ?
1634 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1636 print "<br/>\n$extra<br/>\n" .
1640 sub format_paging_nav
{
1641 my ($action, $hash, $head, $page, $nrevs) = @_;
1645 if ($hash ne $head || $page) {
1646 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1648 $paging_nav .= "HEAD";
1652 $paging_nav .= " ⋅ " .
1653 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1654 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1656 $paging_nav .= " ⋅ prev";
1659 if ($nrevs >= (100 * ($page+1)-1)) {
1660 $paging_nav .= " ⋅ " .
1661 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1662 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1664 $paging_nav .= " ⋅ next";
1670 ## ......................................................................
1671 ## functions printing or outputting HTML: div
1673 sub git_print_header_div
{
1674 my ($action, $title, $hash, $hash_base) = @_;
1677 $args{action
} = $action;
1678 $args{hash
} = $hash if $hash;
1679 $args{hash_base
} = $hash_base if $hash_base;
1681 print "<div class=\"header\">\n" .
1682 $cgi->a({-href
=> href
(%args), -class => "title"},
1683 $title ?
$title : $action) .
1687 #sub git_print_authorship (\%) {
1688 sub git_print_authorship
{
1691 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1692 print "<div class=\"author_date\">" .
1693 esc_html
($co->{'author_name'}) .
1695 if ($ad{'hour_local'} < 6) {
1696 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1697 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1699 printf(" (%02d:%02d %s)",
1700 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1705 sub git_print_page_path
{
1711 print "<div class=\"page_path\">";
1712 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1713 -title
=> 'tree root'}, "[$project]");
1715 if (defined $name) {
1716 my @dirname = split '/', $name;
1717 my $basename = pop @dirname;
1720 foreach my $dir (@dirname) {
1721 $fullname .= ($fullname ?
'/' : '') . $dir;
1722 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1724 -title
=> $fullname}, esc_html
($dir));
1727 if (defined $type && $type eq 'blob') {
1728 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1730 -title
=> $name}, esc_html
($basename));
1731 } elsif (defined $type && $type eq 'tree') {
1732 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1734 -title
=> $name}, esc_html
($basename));
1737 print esc_html
($basename);
1740 print "<br/></div>\n";
1743 # sub git_print_log (\@;%) {
1744 sub git_print_log
($;%) {
1748 if ($opts{'-remove_title'}) {
1749 # remove title, i.e. first line of log
1752 # remove leading empty lines
1753 while (defined $log->[0] && $log->[0] eq "") {
1760 foreach my $line (@
$log) {
1761 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1764 if (! $opts{'-remove_signoff'}) {
1765 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1768 # remove signoff lines
1775 # print only one empty line
1776 # do not print empty line after signoff
1778 next if ($empty || $signoff);
1784 print format_log_line_html
($line) . "<br/>\n";
1787 if ($opts{'-final_empty_line'}) {
1788 # end with single empty line
1789 print "<br/>\n" unless $empty;
1793 # print tree entry (row of git_tree), but without encompassing <tr> element
1794 sub git_print_tree_entry
{
1795 my ($t, $basedir, $hash_base, $have_blame) = @_;
1798 $base_key{hash_base
} = $hash_base if defined $hash_base;
1800 # The format of a table row is: mode list link. Where mode is
1801 # the mode of the entry, list is the name of the entry, an href,
1802 # and link is the action links of the entry.
1804 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1805 if ($t->{'type'} eq "blob") {
1806 print "<td class=\"list\">" .
1807 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1808 file_name
=>"$basedir$t->{'name'}", %base_key),
1809 -class => "list"}, esc_html
($t->{'name'})) . "</td>\n";
1810 print "<td class=\"link\">";
1811 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1812 file_name
=>"$basedir$t->{'name'}", %base_key)},
1816 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1817 file_name
=>"$basedir$t->{'name'}", %base_key)},
1820 if (defined $hash_base) {
1822 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1823 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1827 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
1828 file_name
=>"$basedir$t->{'name'}")},
1832 } elsif ($t->{'type'} eq "tree") {
1833 print "<td class=\"list\">";
1834 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1835 file_name
=>"$basedir$t->{'name'}", %base_key)},
1836 esc_html
($t->{'name'}));
1838 print "<td class=\"link\">";
1839 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1840 file_name
=>"$basedir$t->{'name'}", %base_key)},
1842 if (defined $hash_base) {
1844 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1845 file_name
=>"$basedir$t->{'name'}")},
1852 ## ......................................................................
1853 ## functions printing large fragments of HTML
1855 sub git_difftree_body
{
1856 my ($difftree, $hash, $parent) = @_;
1858 if ($#{$difftree} > 10) {
1859 print "<div class=\"list_head\">\n";
1860 print(($#{$difftree} + 1) . " files changed:\n");
1864 print "<table class=\"diff_tree\">\n";
1867 foreach my $line (@
{$difftree}) {
1868 my %diff = parse_difftree_raw_line
($line);
1871 print "<tr class=\"dark\">\n";
1873 print "<tr class=\"light\">\n";
1877 my ($to_mode_oct, $to_mode_str, $to_file_type);
1878 my ($from_mode_oct, $from_mode_str, $from_file_type);
1879 if ($diff{'to_mode'} ne ('0' x
6)) {
1880 $to_mode_oct = oct $diff{'to_mode'};
1881 if (S_ISREG
($to_mode_oct)) { # only for regular file
1882 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1884 $to_file_type = file_type
($diff{'to_mode'});
1886 if ($diff{'from_mode'} ne ('0' x
6)) {
1887 $from_mode_oct = oct $diff{'from_mode'};
1888 if (S_ISREG
($to_mode_oct)) { # only for regular file
1889 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1891 $from_file_type = file_type
($diff{'from_mode'});
1894 if ($diff{'status'} eq "A") { # created
1895 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1896 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1897 $mode_chng .= "]</span>";
1899 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1900 hash_base
=>$hash, file_name
=>$diff{'file'}),
1901 -class => "list"}, esc_html
($diff{'file'}));
1903 print "<td>$mode_chng</td>\n";
1904 print "<td class=\"link\">";
1905 if ($action eq 'commitdiff') {
1908 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1912 } elsif ($diff{'status'} eq "D") { # deleted
1913 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1915 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1916 hash_base
=>$parent, file_name
=>$diff{'file'}),
1917 -class => "list"}, esc_html
($diff{'file'}));
1919 print "<td>$mode_chng</td>\n";
1920 print "<td class=\"link\">";
1921 if ($action eq 'commitdiff') {
1924 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1927 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1928 hash_base
=>$parent, file_name
=>$diff{'file'})},
1930 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1931 file_name
=>$diff{'file'})},
1933 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1934 file_name
=>$diff{'file'})},
1938 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1939 my $mode_chnge = "";
1940 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1941 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1942 if ($from_file_type != $to_file_type) {
1943 $mode_chnge .= " from $from_file_type to $to_file_type";
1945 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1946 if ($from_mode_str && $to_mode_str) {
1947 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1948 } elsif ($to_mode_str) {
1949 $mode_chnge .= " mode: $to_mode_str";
1952 $mode_chnge .= "]</span>\n";
1955 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1956 hash_base
=>$hash, file_name
=>$diff{'file'}),
1957 -class => "list"}, esc_html
($diff{'file'}));
1959 print "<td>$mode_chnge</td>\n";
1960 print "<td class=\"link\">";
1961 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1962 if ($action eq 'commitdiff') {
1965 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1967 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1968 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1969 hash_base
=>$hash, hash_parent_base
=>$parent,
1970 file_name
=>$diff{'file'})},
1975 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1976 hash_base
=>$hash, file_name
=>$diff{'file'})},
1978 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
1979 file_name
=>$diff{'file'})},
1981 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
1982 file_name
=>$diff{'file'})},
1986 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1987 my %status_name = ('R' => 'moved', 'C' => 'copied');
1988 my $nstatus = $status_name{$diff{'status'}};
1990 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1991 # mode also for directories, so we cannot use $to_mode_str
1992 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1995 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1996 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1997 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1998 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1999 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2000 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
2001 -class => "list"}, esc_html
($diff{'from_file'})) .
2002 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2003 "<td class=\"link\">";
2004 if ($diff{'to_id'} ne $diff{'from_id'}) {
2005 if ($action eq 'commitdiff') {
2008 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2010 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2011 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2012 hash_base
=>$hash, hash_parent_base
=>$parent,
2013 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
2018 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2019 hash_base
=>$parent, file_name
=>$diff{'from_file'})},
2021 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2022 file_name
=>$diff{'from_file'})},
2024 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2025 file_name
=>$diff{'from_file'})},
2029 } # we should not encounter Unmerged (U) or Unknown (X) status
2035 sub git_patchset_body
{
2036 my ($fd, $difftree, $hash, $hash_parent) = @_;
2040 my $patch_found = 0;
2045 print "<div class=\"patchset\">\n";
2048 while (my $patch_line = <$fd>) {
2051 if ($patch_line =~ m/^diff /) { # "git diff" header
2052 # beginning of patch (in patchset)
2056 # close previous patch
2057 print "</div>\n"; # class="patch"
2059 # first patch in patchset
2062 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2064 # read and prepare patch information
2065 if (ref($difftree->[$patch_idx]) eq "HASH") {
2066 # pre-parsed (or generated by hand)
2067 $diffinfo = $difftree->[$patch_idx];
2069 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2071 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2072 $from{'name'} = $diffinfo->{'from_file_raw'} || $diffinfo->{'file_raw'};
2073 # because of "a/file" not a/"file"
2074 $from{'quoted'} = ($from{'name'} =~ s/^"(.*)"$/$1/);
2076 my $file = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2077 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2078 hash
=>$diffinfo->{'from_id'}, file_name
=>$file);
2080 if ($diffinfo->{'status'} ne "D") { # not deleted file
2081 $to{'name'} = $diffinfo->{'to_file_raw'} || $diffinfo->{'file_raw'};
2082 # because of "b/file" not b/"file"
2083 $to{'quoted'} = ($to{'name'} =~ s/^"(.*)"$/$1/);
2085 my $file = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2086 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2087 hash
=>$diffinfo->{'to_id'}, file_name
=>$file);
2091 # for now we skip empty patches
2092 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) {
2093 # no change, empty patch
2099 # print "git diff" header
2100 if ($from{'name'}) {
2101 my $from_link = $cgi->a({-href
=> $from{'href'}, -class => "path"},
2102 'a/' . esc_html
($from{'name'}));
2103 my ($q, $qq) = $from{'quoted'} ?
('"', '"') : ('', '');
2104 $patch_line =~ s
|${q
}a
/\Q
$from{'name'}\E
${q
}|${qq}$from_link${qq}|;
2106 # at least one of %from and %to must be set
2107 $patch_line =~ s
|(["]?a/\Q$to{'name'}\E["]?
)|esc_html
($1)|e
;
2110 my $to_link = $cgi->a({-href
=> $to{'href'}, -class => "path"},
2111 'b/' . esc_html
($to{'name'}));
2112 my ($q, $qq) = $to{'quoted'} ?
('"', '"') : ('', '');
2113 $patch_line =~ s
|${q
}b
/\Q
$to{'name'}\E
${q
}$|${qq}$to_link${qq}|;
2115 # at least one of %from and %to must be set
2116 $patch_line =~ s
|(["]?b/\Q$from{'name'}\E["]?
)$|esc_html
($1)|e
;
2119 print "<div class=\"diff header\">$patch_line</div>\n";
2120 print "<div class=\"diff extended_header\">\n";
2124 next LINE
if $skip_patch;
2125 } # start of patch in patchset
2128 if ($patch_line !~ m/^---/) {
2130 if ($patch_line =~ m!^(copy|rename) from ! && $from{'name'}) {
2131 my $qq = $from{'quoted'} ?
'"' : '';
2132 my $from_link = $cgi->a({-href
=>$from{'href'},-class=>"list"},
2133 esc_html
($from{'name'}));
2134 $patch_line =~ s!from .*$!from $qq$from_link$qq!;
2136 if ($patch_line =~ m!^(copy|rename) to ! && $to{'name'}) {
2137 my $qq = $to{'quoted'} ?
'"' : '';
2138 my $to_link = $cgi->a({-href
=>$to{'href'},-class=>"list"},
2139 esc_html
($to{'name'}));
2140 $patch_line =~ s!to .*$!to $qq$to_link$qq!;
2143 if ($patch_line =~ m/\s(\d{6})$/) {
2144 $patch_line .= '<span class="info"> (' . file_type
($1) . ')</span>';
2147 if ($patch_line =~ m/^index/) {
2148 my ($from_link, $to_link);
2149 if ($from{'href'}) {
2150 $from_link = $cgi->a({-href
=>$from{'href'},-class=>"list"},
2151 substr($diffinfo->{'from_id'},0,7));
2153 $from_link = '0' x
7;
2156 $to_link = $cgi->a({-href
=>$to{'href'},-class=>"list"},
2157 substr($diffinfo->{'to_id'},0,7));
2161 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2162 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2164 print $patch_line . "<br/>\n";
2167 #$patch_line =~ m/^---/;
2168 print "</div>\n"; # class="diff extended_header"
2171 if ($from{'name'}) {
2172 my $qq = $from{'quoted'} ?
'"' : '';
2173 my $from_link = $cgi->a({-href
=>$from{'href'},-class=>"list"},
2174 esc_html
($from{'name'}));
2175 $patch_line =~ s!["]?a/.*$!${qq}a/$from_link${qq}!;
2177 print "<div class=\"diff from_file\">$patch_line</div>\n";
2179 $patch_line = <$fd>;
2182 #$patch_line =~ m/^+++/;
2184 my $qq = $to{'quoted'} ?
'"' : '';
2185 my $from_link = $cgi->a({-href
=>$to{'href'},-class=>"list"},
2186 esc_html
($to{'name'}));
2187 $patch_line =~ s!["]?b/.*$!${qq}b/$from_link${qq}!;
2189 print "<div class=\"diff to_file\">$patch_line</div>\n";
2196 print format_diff_line
($patch_line);
2198 print "</div>\n" if $patch_found; # class="patch"
2200 print "</div>\n"; # class="patchset"
2203 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2205 sub git_shortlog_body
{
2206 # uses global variable $project
2207 my ($revlist, $from, $to, $refs, $extra) = @_;
2209 $from = 0 unless defined $from;
2210 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2212 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2214 for (my $i = $from; $i <= $to; $i++) {
2215 my $commit = $revlist->[$i];
2216 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2217 my $ref = format_ref_marker
($refs, $commit);
2218 my %co = parse_commit
($commit);
2220 print "<tr class=\"dark\">\n";
2222 print "<tr class=\"light\">\n";
2225 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2226 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2227 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2229 print format_subject_html
($co{'title'}, $co{'title_short'},
2230 href
(action
=>"commit", hash
=>$commit), $ref);
2232 "<td class=\"link\">" .
2233 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
2234 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2235 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2236 if (gitweb_have_snapshot
()) {
2237 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2242 if (defined $extra) {
2244 "<td colspan=\"4\">$extra</td>\n" .
2250 sub git_history_body
{
2251 # Warning: assumes constant type (blob or tree) during history
2252 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2254 $from = 0 unless defined $from;
2255 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2257 print "<table class=\"history\" cellspacing=\"0\">\n";
2259 for (my $i = $from; $i <= $to; $i++) {
2260 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2265 my %co = parse_commit
($commit);
2270 my $ref = format_ref_marker
($refs, $commit);
2273 print "<tr class=\"dark\">\n";
2275 print "<tr class=\"light\">\n";
2278 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2279 # shortlog uses chop_str($co{'author_name'}, 10)
2280 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2282 # originally git_history used chop_str($co{'title'}, 50)
2283 print format_subject_html
($co{'title'}, $co{'title_short'},
2284 href
(action
=>"commit", hash
=>$commit), $ref);
2286 "<td class=\"link\">" .
2287 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2288 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2290 if ($ftype eq 'blob') {
2291 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2292 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2293 if (defined $blob_current && defined $blob_parent &&
2294 $blob_current ne $blob_parent) {
2296 $cgi->a({-href
=> href
(action
=>"blobdiff",
2297 hash
=>$blob_current, hash_parent
=>$blob_parent,
2298 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2299 file_name
=>$file_name)},
2306 if (defined $extra) {
2308 "<td colspan=\"4\">$extra</td>\n" .
2315 # uses global variable $project
2316 my ($taglist, $from, $to, $extra) = @_;
2317 $from = 0 unless defined $from;
2318 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2320 print "<table class=\"tags\" cellspacing=\"0\">\n";
2322 for (my $i = $from; $i <= $to; $i++) {
2323 my $entry = $taglist->[$i];
2325 my $comment_lines = $tag{'comment'};
2326 my $comment = shift @
$comment_lines;
2328 if (defined $comment) {
2329 $comment_short = chop_str
($comment, 30, 5);
2332 print "<tr class=\"dark\">\n";
2334 print "<tr class=\"light\">\n";
2337 print "<td><i>$tag{'age'}</i></td>\n" .
2339 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2340 -class => "list name"}, esc_html
($tag{'name'})) .
2343 if (defined $comment) {
2344 print format_subject_html
($comment, $comment_short,
2345 href
(action
=>"tag", hash
=>$tag{'id'}));
2348 "<td class=\"selflink\">";
2349 if ($tag{'type'} eq "tag") {
2350 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2355 "<td class=\"link\">" . " | " .
2356 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2357 if ($tag{'reftype'} eq "commit") {
2358 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2359 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
2360 } elsif ($tag{'reftype'} eq "blob") {
2361 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2366 if (defined $extra) {
2368 "<td colspan=\"5\">$extra</td>\n" .
2374 sub git_heads_body
{
2375 # uses global variable $project
2376 my ($headlist, $head, $from, $to, $extra) = @_;
2377 $from = 0 unless defined $from;
2378 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2380 print "<table class=\"heads\" cellspacing=\"0\">\n";
2382 for (my $i = $from; $i <= $to; $i++) {
2383 my $entry = $headlist->[$i];
2385 my $curr = $tag{'id'} eq $head;
2387 print "<tr class=\"dark\">\n";
2389 print "<tr class=\"light\">\n";
2392 print "<td><i>$tag{'age'}</i></td>\n" .
2393 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
2394 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
2395 -class => "list name"},esc_html
($tag{'name'})) .
2397 "<td class=\"link\">" .
2398 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
2399 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") . " | " .
2400 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$tag{'name'}, hash_base
=>$tag{'name'})}, "tree") .
2404 if (defined $extra) {
2406 "<td colspan=\"3\">$extra</td>\n" .
2412 ## ======================================================================
2413 ## ======================================================================
2416 sub git_project_list
{
2417 my $order = $cgi->param('o');
2418 if (defined $order && $order !~ m/project|descr|owner|age/) {
2419 die_error
(undef, "Unknown order parameter");
2422 my @list = git_get_projects_list
();
2425 die_error
(undef, "No projects found");
2427 foreach my $pr (@list) {
2428 my (@aa) = git_get_last_activity
($pr->{'path'});
2432 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2433 if (!defined $pr->{'descr'}) {
2434 my $descr = git_get_project_description
($pr->{'path'}) || "";
2435 $pr->{'descr'} = chop_str
($descr, 25, 5);
2437 if (!defined $pr->{'owner'}) {
2438 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2440 push @projects, $pr;
2444 if (-f
$home_text) {
2445 print "<div class=\"index_include\">\n";
2446 open (my $fd, $home_text);
2451 print "<table class=\"project_list\">\n" .
2453 $order ||= "project";
2454 if ($order eq "project") {
2455 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2456 print "<th>Project</th>\n";
2459 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2460 -class => "header"}, "Project") .
2463 if ($order eq "descr") {
2464 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2465 print "<th>Description</th>\n";
2468 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2469 -class => "header"}, "Description") .
2472 if ($order eq "owner") {
2473 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2474 print "<th>Owner</th>\n";
2477 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2478 -class => "header"}, "Owner") .
2481 if ($order eq "age") {
2482 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2483 print "<th>Last Change</th>\n";
2486 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2487 -class => "header"}, "Last Change") .
2490 print "<th></th>\n" .
2493 foreach my $pr (@projects) {
2495 print "<tr class=\"dark\">\n";
2497 print "<tr class=\"light\">\n";
2500 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2501 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2502 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2503 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2504 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2505 $pr->{'age_string'} . "</td>\n" .
2506 "<td class=\"link\">" .
2507 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2508 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2509 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2510 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2518 sub git_project_index
{
2519 my @projects = git_get_projects_list
();
2522 -type
=> 'text/plain',
2523 -charset
=> 'utf-8',
2524 -content_disposition
=> 'inline; filename="index.aux"');
2526 foreach my $pr (@projects) {
2527 if (!exists $pr->{'owner'}) {
2528 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2531 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2532 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2533 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2534 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2538 print "$path $owner\n";
2543 my $descr = git_get_project_description
($project) || "none";
2544 my $head = git_get_head_hash
($project);
2545 my %co = parse_commit
($head);
2546 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2548 my $owner = git_get_project_owner
($project);
2550 my ($reflist, $refs) = git_get_refs_list
();
2554 foreach my $ref (@
$reflist) {
2555 if ($ref->{'name'} =~ s!^heads/!!) {
2556 push @headlist, $ref;
2558 $ref->{'name'} =~ s!^tags/!!;
2559 push @taglist, $ref;
2564 git_print_page_nav
('summary','', $head);
2566 print "<div class=\"title\"> </div>\n";
2567 print "<table cellspacing=\"0\">\n" .
2568 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2569 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2570 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2571 # use per project git URL list in $projectroot/$project/cloneurl
2572 # or make project git URL from git base URL and project name
2573 my $url_tag = "URL";
2574 my @url_list = git_get_project_url_list
($project);
2575 @url_list = map { $_ ?
"$_/$project" : () }
2576 @git_base_url_list unless @url_list;
2577 foreach my $git_url (@url_list) {
2578 next unless $git_url;
2579 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2584 if (-s
"$projectroot/$project/README.html") {
2585 if (open my $fd, "$projectroot/$project/README.html") {
2586 print "<div class=\"title\">readme</div>\n";
2587 print $_ while (<$fd>);
2592 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2593 git_get_head_hash
($project)
2594 or die_error
(undef, "Open git-rev-list failed");
2595 my @revlist = map { chomp; $_ } <$fd>;
2597 git_print_header_div
('shortlog');
2598 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2599 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2602 git_print_header_div
('tags');
2603 git_tags_body
(\
@taglist, 0, 15,
2604 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2608 git_print_header_div
('heads');
2609 git_heads_body
(\
@headlist, $head, 0, 15,
2610 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2617 my $head = git_get_head_hash
($project);
2619 git_print_page_nav
('','', $head,undef,$head);
2620 my %tag = parse_tag
($hash);
2621 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2622 print "<div class=\"title_text\">\n" .
2623 "<table cellspacing=\"0\">\n" .
2625 "<td>object</td>\n" .
2626 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2627 $tag{'object'}) . "</td>\n" .
2628 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2629 $tag{'type'}) . "</td>\n" .
2631 if (defined($tag{'author'})) {
2632 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2633 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2634 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2635 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2638 print "</table>\n\n" .
2640 print "<div class=\"page_body\">";
2641 my $comment = $tag{'comment'};
2642 foreach my $line (@
$comment) {
2643 print esc_html
($line) . "<br/>\n";
2653 my ($have_blame) = gitweb_check_feature
('blame');
2655 die_error
('403 Permission denied', "Permission denied");
2657 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2658 $hash_base ||= git_get_head_hash
($project);
2659 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2660 my %co = parse_commit
($hash_base)
2661 or die_error
(undef, "Reading commit failed");
2662 if (!defined $hash) {
2663 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2664 or die_error
(undef, "Error looking up file");
2666 $ftype = git_get_type
($hash);
2667 if ($ftype !~ "blob") {
2668 die_error
("400 Bad Request", "Object is not a blob");
2670 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
2671 $file_name, $hash_base)
2672 or die_error
(undef, "Open git-blame failed");
2675 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2678 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2681 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2683 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2684 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2685 git_print_page_path
($file_name, $ftype, $hash_base);
2686 my @rev_color = (qw(light2 dark2));
2687 my $num_colors = scalar(@rev_color);
2688 my $current_color = 0;
2691 <div class="page_body">
2692 <table class="blame">
2693 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2698 last unless defined $_;
2699 my ($full_rev, $orig_lineno, $lineno, $group_size) =
2700 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
2701 if (!exists $metainfo{$full_rev}) {
2702 $metainfo{$full_rev} = {};
2704 my $meta = $metainfo{$full_rev};
2707 if (/^(\S+) (.*)$/) {
2712 my $rev = substr($full_rev, 0, 8);
2713 my $author = $meta->{'author'};
2714 my %date = parse_date
($meta->{'author-time'},
2715 $meta->{'author-tz'});
2716 my $date = $date{'iso-tz'};
2718 $current_color = ++$current_color % $num_colors;
2720 print "<tr class=\"$rev_color[$current_color]\">\n";
2722 print "<td class=\"sha1\"";
2723 print " title=\"$author, $date\"";
2724 print " rowspan=\"$group_size\"" if ($group_size > 1);
2726 print $cgi->a({-href
=> href
(action
=>"commit",
2728 file_name
=>$file_name)},
2732 my $blamed = href
(action
=> 'blame',
2733 file_name
=> $meta->{'filename'},
2734 hash_base
=> $full_rev);
2735 print "<td class=\"linenr\">";
2736 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
2738 -class => "linenr" },
2741 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2747 or print "Reading blob failed\n";
2754 my ($have_blame) = gitweb_check_feature
('blame');
2756 die_error
('403 Permission denied', "Permission denied");
2758 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2759 $hash_base ||= git_get_head_hash
($project);
2760 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2761 my %co = parse_commit
($hash_base)
2762 or die_error
(undef, "Reading commit failed");
2763 if (!defined $hash) {
2764 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2765 or die_error
(undef, "Error lookup file");
2767 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2768 or die_error
(undef, "Open git-annotate failed");
2771 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2774 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2777 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2779 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2780 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2781 git_print_page_path
($file_name, 'blob', $hash_base);
2782 print "<div class=\"page_body\">\n";
2784 <table class="blame">
2793 my @line_class = (qw(light dark));
2794 my $line_class_len = scalar (@line_class);
2795 my $line_class_num = $#line_class;
2796 while (my $line = <$fd>) {
2808 $line_class_num = ($line_class_num + 1) % $line_class_len;
2810 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2817 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2820 $short_rev = substr ($long_rev, 0, 8);
2821 $age = time () - $time;
2822 $age_str = age_string
($age);
2823 $age_str =~ s/ / /g;
2824 $age_class = age_class
($age);
2825 $author = esc_html
($author);
2826 $author =~ s/ / /g;
2828 $data = untabify
($data);
2829 $data = esc_html
($data);
2832 <tr class="$line_class[$line_class_num]">
2833 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2834 <td class="$age_class">$age_str</td>
2836 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2837 <td class="pre">$data</td>
2840 } # while (my $line = <$fd>)
2841 print "</table>\n\n";
2843 or print "Reading blob failed.\n";
2849 my $head = git_get_head_hash
($project);
2851 git_print_page_nav
('','', $head,undef,$head);
2852 git_print_header_div
('summary', $project);
2854 my ($taglist) = git_get_refs_list
("tags");
2856 git_tags_body
($taglist);
2862 my $head = git_get_head_hash
($project);
2864 git_print_page_nav
('','', $head,undef,$head);
2865 git_print_header_div
('summary', $project);
2867 my ($headlist) = git_get_refs_list
("heads");
2869 git_heads_body
($headlist, $head);
2874 sub git_blob_plain
{
2877 if (!defined $hash) {
2878 if (defined $file_name) {
2879 my $base = $hash_base || git_get_head_hash
($project);
2880 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2881 or die_error
(undef, "Error lookup file");
2883 die_error
(undef, "No file name defined");
2885 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2886 # blobs defined by non-textual hash id's can be cached
2891 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2892 or die_error
(undef, "Couldn't cat $file_name, $hash");
2894 $type ||= blob_mimetype
($fd, $file_name);
2896 # save as filename, even when no $file_name is given
2897 my $save_as = "$hash";
2898 if (defined $file_name) {
2899 $save_as = $file_name;
2900 } elsif ($type =~ m/^text\//) {
2907 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
2909 binmode STDOUT
, ':raw';
2911 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2919 if (!defined $hash) {
2920 if (defined $file_name) {
2921 my $base = $hash_base || git_get_head_hash
($project);
2922 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2923 or die_error
(undef, "Error lookup file");
2925 die_error
(undef, "No file name defined");
2927 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2928 # blobs defined by non-textual hash id's can be cached
2932 my ($have_blame) = gitweb_check_feature
('blame');
2933 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2934 or die_error
(undef, "Couldn't cat $file_name, $hash");
2935 my $mimetype = blob_mimetype
($fd, $file_name);
2936 if ($mimetype !~ m/^text\//) {
2938 return git_blob_plain
($mimetype);
2940 git_header_html
(undef, $expires);
2941 my $formats_nav = '';
2942 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2943 if (defined $file_name) {
2946 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2947 hash
=>$hash, file_name
=>$file_name)},
2952 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2953 hash
=>$hash, file_name
=>$file_name)},
2956 $cgi->a({-href
=> href
(action
=>"blob_plain",
2957 hash
=>$hash, file_name
=>$file_name)},
2960 $cgi->a({-href
=> href
(action
=>"blob",
2961 hash_base
=>"HEAD", file_name
=>$file_name)},
2965 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
2967 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2968 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2970 print "<div class=\"page_nav\">\n" .
2971 "<br/><br/></div>\n" .
2972 "<div class=\"title\">$hash</div>\n";
2974 git_print_page_path
($file_name, "blob", $hash_base);
2975 print "<div class=\"page_body\">\n";
2977 while (my $line = <$fd>) {
2980 $line = untabify
($line);
2981 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2982 $nr, $nr, $nr, esc_html
($line);
2985 or print "Reading blob failed.\n";
2991 my $have_snapshot = gitweb_have_snapshot
();
2993 if (!defined $hash_base) {
2994 $hash_base = "HEAD";
2996 if (!defined $hash) {
2997 if (defined $file_name) {
2998 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3004 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3005 or die_error
(undef, "Open git-ls-tree failed");
3006 my @entries = map { chomp; $_ } <$fd>;
3007 close $fd or die_error
(undef, "Reading tree failed");
3010 my $refs = git_get_references
();
3011 my $ref = format_ref_marker
($refs, $hash_base);
3014 my ($have_blame) = gitweb_check_feature
('blame');
3015 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3017 if (defined $file_name) {
3019 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3020 hash
=>$hash, file_name
=>$file_name)},
3022 $cgi->a({-href
=> href
(action
=>"tree",
3023 hash_base
=>"HEAD", file_name
=>$file_name)},
3026 if ($have_snapshot) {
3027 # FIXME: Should be available when we have no hash base as well.
3029 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3032 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3033 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3036 print "<div class=\"page_nav\">\n";
3037 print "<br/><br/></div>\n";
3038 print "<div class=\"title\">$hash</div>\n";
3040 if (defined $file_name) {
3041 $basedir = $file_name;
3042 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3046 git_print_page_path
($file_name, 'tree', $hash_base);
3047 print "<div class=\"page_body\">\n";
3048 print "<table cellspacing=\"0\">\n";
3050 # '..' (top directory) link if possible
3051 if (defined $hash_base &&
3052 defined $file_name && $file_name =~ m![^/]+$!) {
3054 print "<tr class=\"dark\">\n";
3056 print "<tr class=\"light\">\n";
3060 my $up = $file_name;
3061 $up =~ s!/?[^/]+$!!;
3062 undef $up unless $up;
3063 # based on git_print_tree_entry
3064 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3065 print '<td class="list">';
3066 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3070 print "<td class=\"link\"></td>\n";
3074 foreach my $line (@entries) {
3075 my %t = parse_ls_tree_line
($line, -z
=> 1);
3078 print "<tr class=\"dark\">\n";
3080 print "<tr class=\"light\">\n";
3084 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3088 print "</table>\n" .
3094 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3095 my $have_snapshot = (defined $ctype && defined $suffix);
3096 if (!$have_snapshot) {
3097 die_error
('403 Permission denied', "Permission denied");
3100 if (!defined $hash) {
3101 $hash = git_get_head_hash
($project);
3104 my $filename = basename
($project) . "-$hash.tar.$suffix";
3107 -type
=> 'application/x-tar',
3108 -content_encoding
=> $ctype,
3109 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3110 -status
=> '200 OK');
3112 my $git = git_cmd_str
();
3113 my $name = $project;
3114 $name =~ s/\047/\047\\\047\047/g;
3116 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3117 or die_error
(undef, "Execute git-tar-tree failed.");
3118 binmode STDOUT
, ':raw';
3120 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3126 my $head = git_get_head_hash
($project);
3127 if (!defined $hash) {
3130 if (!defined $page) {
3133 my $refs = git_get_references
();
3135 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3136 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3137 or die_error
(undef, "Open git-rev-list failed");
3138 my @revlist = map { chomp; $_ } <$fd>;
3141 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
3144 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3147 my %co = parse_commit
($hash);
3149 git_print_header_div
('summary', $project);
3150 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3152 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
3153 my $commit = $revlist[$i];
3154 my $ref = format_ref_marker
($refs, $commit);
3155 my %co = parse_commit
($commit);
3157 my %ad = parse_date
($co{'author_epoch'});
3158 git_print_header_div
('commit',
3159 "<span class=\"age\">$co{'age_string'}</span>" .
3160 esc_html
($co{'title'}) . $ref,
3162 print "<div class=\"title_text\">\n" .
3163 "<div class=\"log_link\">\n" .
3164 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3166 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3168 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3171 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3174 print "<div class=\"log_body\">\n";
3175 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
3182 my %co = parse_commit
($hash);
3184 die_error
(undef, "Unknown commit object");
3186 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3187 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3189 my $parent = $co{'parent'};
3190 if (!defined $parent) {
3193 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
3194 @diff_opts, $parent, $hash
3195 or die_error
(undef, "Open git-diff-tree failed");
3196 my @difftree = map { chomp; $_ } <$fd>;
3197 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3199 # non-textual hash id's can be cached
3201 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3204 my $refs = git_get_references
();
3205 my $ref = format_ref_marker
($refs, $co{'id'});
3207 my $have_snapshot = gitweb_have_snapshot
();
3210 if (defined $file_name && defined $co{'parent'}) {
3212 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
3215 git_header_html
(undef, $expires);
3216 git_print_page_nav
('commit', '',
3217 $hash, $co{'tree'}, $hash,
3218 join (' | ', @views_nav));
3220 if (defined $co{'parent'}) {
3221 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3223 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3225 print "<div class=\"title_text\">\n" .
3226 "<table cellspacing=\"0\">\n";
3227 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3229 "<td></td><td> $ad{'rfc2822'}";
3230 if ($ad{'hour_local'} < 6) {
3231 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3232 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3234 printf(" (%02d:%02d %s)",
3235 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3239 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3240 print "<tr><td></td><td> $cd{'rfc2822'}" .
3241 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3243 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3246 "<td class=\"sha1\">" .
3247 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3248 class => "list"}, $co{'tree'}) .
3250 "<td class=\"link\">" .
3251 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3253 if ($have_snapshot) {
3255 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3259 my $parents = $co{'parents'};
3260 foreach my $par (@
$parents) {
3263 "<td class=\"sha1\">" .
3264 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3265 class => "list"}, $par) .
3267 "<td class=\"link\">" .
3268 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3270 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3277 print "<div class=\"page_body\">\n";
3278 git_print_log
($co{'comment'});
3281 git_difftree_body
(\
@difftree, $hash, $parent);
3287 my $format = shift || 'html';
3294 # preparing $fd and %diffinfo for git_patchset_body
3296 if (defined $hash_base && defined $hash_parent_base) {
3297 if (defined $file_name) {
3299 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
3301 or die_error
(undef, "Open git-diff-tree failed");
3302 @difftree = map { chomp; $_ } <$fd>;
3304 or die_error
(undef, "Reading git-diff-tree failed");
3306 or die_error
('404 Not Found', "Blob diff not found");
3308 } elsif (defined $hash &&
3309 $hash =~ /[0-9a-fA-F]{40}/) {
3310 # try to find filename from $hash
3312 # read filtered raw output
3313 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
3314 or die_error
(undef, "Open git-diff-tree failed");
3316 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3318 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3319 map { chomp; $_ } <$fd>;
3321 or die_error
(undef, "Reading git-diff-tree failed");
3323 or die_error
('404 Not Found', "Blob diff not found");
3326 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3329 if (@difftree > 1) {
3330 die_error
('404 Not Found', "Ambiguous blob diff specification");
3333 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3334 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3335 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3337 $hash_parent ||= $diffinfo{'from_id'};
3338 $hash ||= $diffinfo{'to_id'};
3340 # non-textual hash id's can be cached
3341 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3342 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3347 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3348 '-p', $hash_parent_base, $hash_base,
3350 or die_error
(undef, "Open git-diff-tree failed");
3353 # old/legacy style URI
3354 if (!%diffinfo && # if new style URI failed
3355 defined $hash && defined $hash_parent) {
3356 # fake git-diff-tree raw output
3357 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3358 $diffinfo{'from_id'} = $hash_parent;
3359 $diffinfo{'to_id'} = $hash;
3360 if (defined $file_name) {
3361 if (defined $file_parent) {
3362 $diffinfo{'status'} = '2';
3363 $diffinfo{'from_file'} = $file_parent;
3364 $diffinfo{'to_file'} = $file_name;
3365 } else { # assume not renamed
3366 $diffinfo{'status'} = '1';
3367 $diffinfo{'from_file'} = $file_name;
3368 $diffinfo{'to_file'} = $file_name;
3370 } else { # no filename given
3371 $diffinfo{'status'} = '2';
3372 $diffinfo{'from_file'} = $hash_parent;
3373 $diffinfo{'to_file'} = $hash;
3376 # non-textual hash id's can be cached
3377 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3378 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3383 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts, $hash_parent, $hash
3384 or die_error
(undef, "Open git-diff failed");
3386 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3391 if ($format eq 'html') {
3393 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3394 hash
=>$hash, hash_parent
=>$hash_parent,
3395 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3396 file_name
=>$file_name, file_parent
=>$file_parent)},
3398 git_header_html
(undef, $expires);
3399 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3400 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3401 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3403 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3404 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3406 if (defined $file_name) {
3407 git_print_page_path
($file_name, "blob", $hash_base);
3409 print "<div class=\"page_path\"></div>\n";
3412 } elsif ($format eq 'plain') {
3414 -type
=> 'text/plain',
3415 -charset
=> 'utf-8',
3416 -expires
=> $expires,
3417 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3419 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3422 die_error
(undef, "Unknown blobdiff format");
3426 if ($format eq 'html') {
3427 print "<div class=\"page_body\">\n";
3429 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3432 print "</div>\n"; # class="page_body"
3436 while (my $line = <$fd>) {
3437 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_html($diffinfo{'from_file'})!eg;
3438 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_html($diffinfo{'to_file'})!eg;
3442 last if $line =~ m!^\+\+\+!;
3450 sub git_blobdiff_plain
{
3451 git_blobdiff
('plain');
3454 sub git_commitdiff
{
3455 my $format = shift || 'html';
3456 my %co = parse_commit
($hash);
3458 die_error
(undef, "Unknown commit object");
3461 # we need to prepare $formats_nav before any parameter munging
3463 if ($format eq 'html') {
3465 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3466 hash
=>$hash, hash_parent
=>$hash_parent)},
3469 if (defined $hash_parent && $hash_parent !~ m/^-/) {
3470 # commitdiff with two commits given
3471 # second "commit" is not in fact diff option
3474 $cgi->a({-href
=> href
(action
=>"commitdiff",
3475 hash
=>$hash_parent)},
3478 } elsif (!$co{'parent'}) {
3480 $formats_nav .= ' (initial)';
3481 } elsif (scalar @
{$co{'parents'}} == 1) {
3482 # single parent commit
3485 $cgi->a({-href
=> href
(action
=>"commitdiff",
3486 hash
=>$co{'parent'})},
3494 $cgi->a({-href
=> href
(action
=>"commitdiff",
3497 } @
{$co{'parents'}} ) .
3502 if (!defined $hash_parent) {
3503 $hash_parent = $co{'parent'} || '--root';
3509 if ($format eq 'html') {
3510 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3512 "--patch-with-raw", "--full-index", $hash_parent, $hash
3513 or die_error
(undef, "Open git-diff-tree failed");
3515 while (chomp(my $line = <$fd>)) {
3516 # empty line ends raw part of diff-tree output
3518 push @difftree, $line;
3521 } elsif ($format eq 'plain') {
3522 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3523 '-p', $hash_parent, $hash
3524 or die_error
(undef, "Open git-diff-tree failed");
3527 die_error
(undef, "Unknown commitdiff format");
3530 # non-textual hash id's can be cached
3532 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3536 # write commit message
3537 if ($format eq 'html') {
3538 my $refs = git_get_references
();
3539 my $ref = format_ref_marker
($refs, $co{'id'});
3541 git_header_html
(undef, $expires);
3542 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3543 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3544 git_print_authorship
(\
%co);
3546 if (@
{$co{'comment'}} > 1) {
3547 print "<div class=\"commitdiff_log\">\n";
3548 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
3549 print "</div>\n"; # class="commitdiff_log"
3552 print "<div class=\"page_body\">\n";
3554 } elsif ($format eq 'plain') {
3555 my $refs = git_get_references
("tags");
3556 my $tagname = git_get_rev_name_tags
($hash);
3557 my $filename = basename
($project) . "-$hash.patch";
3560 -type
=> 'text/plain',
3561 -charset
=> 'utf-8',
3562 -expires
=> $expires,
3563 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3564 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3567 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3568 Subject: $co{'title'}
3570 print "X-Git-Tag: $tagname\n" if $tagname;
3571 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3573 foreach my $line (@
{$co{'comment'}}) {
3580 if ($format eq 'html') {
3581 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3584 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3586 print "</div>\n"; # class="page_body"
3589 } elsif ($format eq 'plain') {
3593 or print "Reading git-diff-tree failed\n";
3597 sub git_commitdiff_plain
{
3598 git_commitdiff
('plain');
3602 if (!defined $hash_base) {
3603 $hash_base = git_get_head_hash
($project);
3605 if (!defined $page) {
3609 my %co = parse_commit
($hash_base);
3611 die_error
(undef, "Unknown commit object");
3614 my $refs = git_get_references
();
3615 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3617 if (!defined $hash && defined $file_name) {
3618 $hash = git_get_hash_by_path
($hash_base, $file_name);
3620 if (defined $hash) {
3621 $ftype = git_get_type
($hash);
3625 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3626 or die_error
(undef, "Open git-rev-list-failed");
3627 my @revlist = map { chomp; $_ } <$fd>;
3629 or die_error
(undef, "Reading git-rev-list failed");
3631 my $paging_nav = '';
3634 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3635 file_name
=>$file_name)},
3637 $paging_nav .= " ⋅ " .
3638 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3639 file_name
=>$file_name, page
=>$page-1),
3640 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3642 $paging_nav .= "first";
3643 $paging_nav .= " ⋅ prev";
3645 if ($#revlist >= (100 * ($page+1)-1)) {
3646 $paging_nav .= " ⋅ " .
3647 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3648 file_name
=>$file_name, page
=>$page+1),
3649 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3651 $paging_nav .= " ⋅ next";
3654 if ($#revlist >= (100 * ($page+1)-1)) {
3656 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3657 file_name
=>$file_name, page
=>$page+1),
3658 -title
=> "Alt-n"}, "next");
3662 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3663 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3664 git_print_page_path
($file_name, $ftype, $hash_base);
3666 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3667 $refs, $hash_base, $ftype, $next_link);
3673 if (!defined $searchtext) {
3674 die_error
(undef, "Text field empty");
3676 if (!defined $hash) {
3677 $hash = git_get_head_hash
($project);
3679 my %co = parse_commit
($hash);
3681 die_error
(undef, "Unknown commit object");
3684 $searchtype ||= 'commit';
3685 if ($searchtype eq 'pickaxe') {
3686 # pickaxe may take all resources of your box and run for several minutes
3687 # with every query - so decide by yourself how public you make this feature
3688 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3689 if (!$have_pickaxe) {
3690 die_error
('403 Permission denied', "Permission denied");
3695 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3696 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3698 print "<table cellspacing=\"0\">\n";
3700 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
3702 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", $hash or next;
3703 while (my $commit_text = <$fd>) {
3704 if (!grep m/$searchtext/i, $commit_text) {
3707 if ($searchtype eq 'author' && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3710 if ($searchtype eq 'committer' && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3713 my @commit_lines = split "\n", $commit_text;
3714 my %co = parse_commit
(undef, \
@commit_lines);
3719 print "<tr class=\"dark\">\n";
3721 print "<tr class=\"light\">\n";
3724 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3725 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3727 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3728 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3729 my $comment = $co{'comment'};
3730 foreach my $line (@
$comment) {
3731 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3732 my $lead = esc_html
($1) || "";
3733 $lead = chop_str
($lead, 30, 10);
3734 my $match = esc_html
($2) || "";
3735 my $trail = esc_html
($3) || "";
3736 $trail = chop_str
($trail, 30, 10);
3737 my $text = "$lead<span class=\"match\">$match</span>$trail";
3738 print chop_str
($text, 80, 5) . "<br/>\n";
3742 "<td class=\"link\">" .
3743 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3745 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3752 if ($searchtype eq 'pickaxe') {
3754 my $git_command = git_cmd_str
();
3755 open my $fd, "-|", "$git_command rev-list $hash | " .
3756 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3759 while (my $line = <$fd>) {
3760 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3763 $set{'from_id'} = $3;
3765 $set{'id'} = $set{'to_id'};
3766 if ($set{'id'} =~ m/0{40}/) {
3767 $set{'id'} = $set{'from_id'};
3769 if ($set{'id'} =~ m/0{40}/) {
3773 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3776 print "<tr class=\"dark\">\n";
3778 print "<tr class=\"light\">\n";
3781 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3782 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3784 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3785 -class => "list subject"},
3786 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3787 while (my $setref = shift @files) {
3789 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3790 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3792 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3796 "<td class=\"link\">" .
3797 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3799 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3803 %co = parse_commit
($1);
3812 sub git_search_help
{
3814 git_print_page_nav
('','', $hash,$hash,$hash);
3817 <dt><b>commit</b></dt>
3818 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
3819 <dt><b>author</b></dt>
3820 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
3821 <dt><b>committer</b></dt>
3822 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
3824 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3825 if ($have_pickaxe) {
3827 <dt><b>pickaxe</b></dt>
3828 <dd>All commits that caused the string to appear or disappear from any file (changes that
3829 added, removed or "modified" the string) will be listed. This search can take a while and
3830 takes a lot of strain on the server, so please use it wisely.</dd>
3838 my $head = git_get_head_hash
($project);
3839 if (!defined $hash) {
3842 if (!defined $page) {
3845 my $refs = git_get_references
();
3847 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3848 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3849 or die_error
(undef, "Open git-rev-list failed");
3850 my @revlist = map { chomp; $_ } <$fd>;
3853 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3855 if ($#revlist >= (100 * ($page+1)-1)) {
3857 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3858 -title
=> "Alt-n"}, "next");
3863 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3864 git_print_header_div
('summary', $project);
3866 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3871 ## ......................................................................
3872 ## feeds (RSS, OPML)
3875 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3876 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150", git_get_head_hash
($project)
3877 or die_error
(undef, "Open git-rev-list failed");
3878 my @revlist = map { chomp; $_ } <$fd>;
3879 close $fd or die_error
(undef, "Reading git-rev-list failed");
3880 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3882 <?xml version="1.0" encoding="utf-8"?>
3883 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3885 <title>$project $my_uri $my_url</title>
3886 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3887 <description>$project log</description>
3888 <language>en</language>
3891 for (my $i = 0; $i <= $#revlist; $i++) {
3892 my $commit = $revlist[$i];
3893 my %co = parse_commit
($commit);
3894 # we read 150, we always show 30 and the ones more recent than 48 hours
3895 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3898 my %cd = parse_date
($co{'committer_epoch'});
3899 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3900 $co{'parent'}, $co{'id'}
3902 my @difftree = map { chomp; $_ } <$fd>;
3907 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3909 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3910 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3911 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3912 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3913 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3914 "<content:encoded>" .
3916 my $comment = $co{'comment'};
3917 foreach my $line (@
$comment) {
3918 $line = to_utf8
($line);
3919 print "$line<br/>\n";
3922 foreach my $line (@difftree) {
3923 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3926 my $file = esc_html
(unquote
($7));
3927 $file = to_utf8
($file);
3928 print "$file<br/>\n";
3931 "</content:encoded>\n" .
3934 print "</channel></rss>";
3938 my @list = git_get_projects_list
();
3940 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3942 <?xml version="1.0" encoding="utf-8"?>
3943 <opml version="1.0">
3945 <title>$site_name OPML Export</title>
3948 <outline text="git RSS feeds">
3951 foreach my $pr (@list) {
3953 my $head = git_get_head_hash
($proj{'path'});
3954 if (!defined $head) {
3957 $git_dir = "$projectroot/$proj{'path'}";
3958 my %co = parse_commit
($head);
3963 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3964 my $rss = "$my_url?p=$proj{'path'};a=rss";
3965 my $html = "$my_url?p=$proj{'path'};a=summary";
3966 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";