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++" || $ENV{'SERVER_NAME'} || "Untitled";
44 # filename of html text to include at top of each page
45 our $site_header = "++GITWEB_SITE_HEADER++";
46 # html text to include at home page
47 our $home_text = "++GITWEB_HOMETEXT++";
48 # filename of html text to include at bottom of each page
49 our $site_footer = "++GITWEB_SITE_FOOTER++";
52 our @stylesheets = ("++GITWEB_CSS++");
54 # default is not to define style sheet, but it can be overwritten later
57 # URI of default stylesheet
58 our $stylesheet = "++GITWEB_CSS++";
59 # URI of GIT logo (72x27 size)
60 our $logo = "++GITWEB_LOGO++";
61 # URI of GIT favicon, assumed to be image/png type
62 our $favicon = "++GITWEB_FAVICON++";
64 # URI and label (title) of GIT logo link
65 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
66 #our $logo_label = "git documentation";
67 our $logo_url = "http://git.or.cz/";
68 our $logo_label = "git homepage";
70 # source of projects list
71 our $projects_list = "++GITWEB_LIST++";
73 # show repository only if this file exists
74 # (only effective if this variable evaluates to true)
75 our $export_ok = "++GITWEB_EXPORT_OK++";
77 # only allow viewing of repositories also shown on the overview page
78 our $strict_export = "++GITWEB_STRICT_EXPORT++";
80 # list of git base URLs used for URL to where fetch project from,
81 # i.e. full URL is "$git_base_url/$project"
82 our @git_base_url_list = ("++GITWEB_BASE_URL++");
84 # default blob_plain mimetype and default charset for text/plain blob
85 our $default_blob_plain_mimetype = 'text/plain';
86 our $default_text_plain_charset = undef;
88 # file to use for guessing MIME types before trying /etc/mime.types
89 # (relative to the current git repository)
90 our $mimetypes_file = undef;
92 # You define site-wide feature defaults here; override them with
93 # $GITWEB_CONFIG as necessary.
96 # 'sub' => feature-sub (subroutine),
97 # 'override' => allow-override (boolean),
98 # 'default' => [ default options...] (array reference)}
100 # if feature is overridable (it means that allow-override has true value,
101 # then feature-sub will be called with default options as parameters;
102 # return value of feature-sub indicates if to enable specified feature
104 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
106 # Enable the 'blame' blob view, showing the last commit that modified
107 # each line in the file. This can be very CPU-intensive.
109 # To enable system wide have in $GITWEB_CONFIG
110 # $feature{'blame'}{'default'} = [1];
111 # To have project specific config enable override in $GITWEB_CONFIG
112 # $feature{'blame'}{'override'} = 1;
113 # and in project config gitweb.blame = 0|1;
115 'sub' => \
&feature_blame
,
119 # Enable the 'snapshot' link, providing a compressed tarball of any
120 # tree. This can potentially generate high traffic if you have large
123 # To disable system wide have in $GITWEB_CONFIG
124 # $feature{'snapshot'}{'default'} = [undef];
125 # To have project specific config enable override in $GITWEB_CONFIG
126 # $feature{'blame'}{'override'} = 1;
127 # and in project config gitweb.snapshot = none|gzip|bzip2;
129 'sub' => \
&feature_snapshot
,
131 # => [content-encoding, suffix, program]
132 'default' => ['x-gzip', 'gz', 'gzip']},
134 # Enable the pickaxe search, which will list the commits that modified
135 # a given string in a file. This can be practical and quite faster
136 # alternative to 'blame', but still potentially CPU-intensive.
138 # To enable system wide have in $GITWEB_CONFIG
139 # $feature{'pickaxe'}{'default'} = [1];
140 # To have project specific config enable override in $GITWEB_CONFIG
141 # $feature{'pickaxe'}{'override'} = 1;
142 # and in project config gitweb.pickaxe = 0|1;
144 'sub' => \
&feature_pickaxe
,
148 # Make gitweb use an alternative format of the URLs which can be
149 # more readable and natural-looking: project name is embedded
150 # directly in the path and the query string contains other
151 # auxiliary information. All gitweb installations recognize
152 # URL in either format; this configures in which formats gitweb
155 # To enable system wide have in $GITWEB_CONFIG
156 # $feature{'pathinfo'}{'default'} = [1];
157 # Project specific override is not supported.
159 # Note that you will need to change the default location of CSS,
160 # favicon, logo and possibly other files to an absolute URL. Also,
161 # if gitweb.cgi serves as your indexfile, you will need to force
162 # $my_uri to contain the script name in your $GITWEB_CONFIG.
168 sub gitweb_check_feature
{
170 return unless exists $feature{$name};
171 my ($sub, $override, @defaults) = (
172 $feature{$name}{'sub'},
173 $feature{$name}{'override'},
174 @
{$feature{$name}{'default'}});
175 if (!$override) { return @defaults; }
177 warn "feature $name is not overrideable";
180 return $sub->(@defaults);
184 my ($val) = git_get_project_config
('blame', '--bool');
186 if ($val eq 'true') {
188 } elsif ($val eq 'false') {
195 sub feature_snapshot
{
196 my ($ctype, $suffix, $command) = @_;
198 my ($val) = git_get_project_config
('snapshot');
200 if ($val eq 'gzip') {
201 return ('x-gzip', 'gz', 'gzip');
202 } elsif ($val eq 'bzip2') {
203 return ('x-bzip2', 'bz2', 'bzip2');
204 } elsif ($val eq 'none') {
208 return ($ctype, $suffix, $command);
211 sub gitweb_have_snapshot
{
212 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
213 my $have_snapshot = (defined $ctype && defined $suffix);
215 return $have_snapshot;
218 sub feature_pickaxe
{
219 my ($val) = git_get_project_config
('pickaxe', '--bool');
221 if ($val eq 'true') {
223 } elsif ($val eq 'false') {
230 # checking HEAD file with -e is fragile if the repository was
231 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
233 sub check_head_link
{
235 my $headfile = "$dir/HEAD";
236 return ((-e
$headfile) ||
237 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
240 sub check_export_ok
{
242 return (check_head_link
($dir) &&
243 (!$export_ok || -e
"$dir/$export_ok"));
246 # rename detection options for git-diff and git-diff-tree
247 # - default is '-M', with the cost proportional to
248 # (number of removed files) * (number of new files).
249 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
250 # (number of changed files + number of removed files) * (number of new files)
251 # - even more costly is '-C', '--find-copies-harder' with cost
252 # (number of files in the original tree) * (number of new files)
253 # - one might want to include '-B' option, e.g. '-B', '-M'
254 our @diff_opts = ('-M'); # taken from git_commit
256 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
257 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
259 # version of the core git binary
260 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
262 $projects_list ||= $projectroot;
264 # ======================================================================
265 # input validation and dispatch
266 our $action = $cgi->param('a');
267 if (defined $action) {
268 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
269 die_error
(undef, "Invalid action parameter");
273 # parameters which are pathnames
274 our $project = $cgi->param('p');
275 if (defined $project) {
276 if (!validate_pathname
($project) ||
277 !(-d
"$projectroot/$project") ||
278 !check_head_link
("$projectroot/$project") ||
279 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
280 ($strict_export && !project_in_list
($project))) {
282 die_error
(undef, "No such project");
286 our $file_name = $cgi->param('f');
287 if (defined $file_name) {
288 if (!validate_pathname
($file_name)) {
289 die_error
(undef, "Invalid file parameter");
293 our $file_parent = $cgi->param('fp');
294 if (defined $file_parent) {
295 if (!validate_pathname
($file_parent)) {
296 die_error
(undef, "Invalid file parent parameter");
300 # parameters which are refnames
301 our $hash = $cgi->param('h');
303 if (!validate_refname
($hash)) {
304 die_error
(undef, "Invalid hash parameter");
308 our $hash_parent = $cgi->param('hp');
309 if (defined $hash_parent) {
310 if (!validate_refname
($hash_parent)) {
311 die_error
(undef, "Invalid hash parent parameter");
315 our $hash_base = $cgi->param('hb');
316 if (defined $hash_base) {
317 if (!validate_refname
($hash_base)) {
318 die_error
(undef, "Invalid hash base parameter");
322 our $hash_parent_base = $cgi->param('hpb');
323 if (defined $hash_parent_base) {
324 if (!validate_refname
($hash_parent_base)) {
325 die_error
(undef, "Invalid hash parent base parameter");
330 our $page = $cgi->param('pg');
332 if ($page =~ m/[^0-9]/) {
333 die_error
(undef, "Invalid page parameter");
337 our $searchtext = $cgi->param('s');
338 if (defined $searchtext) {
339 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
340 die_error
(undef, "Invalid search parameter");
342 $searchtext = quotemeta $searchtext;
345 # now read PATH_INFO and use it as alternative to parameters
346 sub evaluate_path_info
{
347 return if defined $project;
348 my $path_info = $ENV{"PATH_INFO"};
349 return if !$path_info;
350 $path_info =~ s
,^/+,,;
351 return if !$path_info;
352 # find which part of PATH_INFO is project
353 $project = $path_info;
355 while ($project && !check_head_link
("$projectroot/$project")) {
356 $project =~ s
,/*[^/]*$,,;
359 $project = validate_pathname
($project);
361 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
362 ($strict_export && !project_in_list
($project))) {
366 # do not change any parameters if an action is given using the query string
368 $path_info =~ s
,^$project/*,,;
369 my ($refname, $pathname) = split(/:/, $path_info, 2);
370 if (defined $pathname) {
371 # we got "project.git/branch:filename" or "project.git/branch:dir/"
372 # we could use git_get_type(branch:pathname), but it needs $git_dir
373 $pathname =~ s
,^/+,,;
374 if (!$pathname || substr($pathname, -1) eq "/") {
378 $action ||= "blob_plain";
380 $hash_base ||= validate_refname
($refname);
381 $file_name ||= validate_pathname
($pathname);
382 } elsif (defined $refname) {
383 # we got "project.git/branch"
384 $action ||= "shortlog";
385 $hash ||= validate_refname
($refname);
388 evaluate_path_info
();
390 # path to the current git repository
392 $git_dir = "$projectroot/$project" if $project;
396 "blame" => \
&git_blame2
,
397 "blobdiff" => \
&git_blobdiff
,
398 "blobdiff_plain" => \
&git_blobdiff_plain
,
399 "blob" => \
&git_blob
,
400 "blob_plain" => \
&git_blob_plain
,
401 "commitdiff" => \
&git_commitdiff
,
402 "commitdiff_plain" => \
&git_commitdiff_plain
,
403 "commit" => \
&git_commit
,
404 "heads" => \
&git_heads
,
405 "history" => \
&git_history
,
408 "search" => \
&git_search
,
409 "shortlog" => \
&git_shortlog
,
410 "summary" => \
&git_summary
,
412 "tags" => \
&git_tags
,
413 "tree" => \
&git_tree
,
414 "snapshot" => \
&git_snapshot
,
415 # those below don't need $project
416 "opml" => \
&git_opml
,
417 "project_list" => \
&git_project_list
,
418 "project_index" => \
&git_project_index
,
421 if (defined $project) {
422 $action ||= 'summary';
424 $action ||= 'project_list';
426 if (!defined($actions{$action})) {
427 die_error
(undef, "Unknown action");
429 if ($action !~ m/^(opml|project_list|project_index)$/ &&
431 die_error
(undef, "Project needed");
433 $actions{$action}->();
436 ## ======================================================================
443 # XXX: Warning: If you touch this, check the search form for updating,
454 hash_parent_base
=> "hpb",
459 my %mapping = @mapping;
461 $params{'project'} = $project unless exists $params{'project'};
463 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
465 # use PATH_INFO for project name
466 $href .= "/$params{'project'}" if defined $params{'project'};
467 delete $params{'project'};
469 # Summary just uses the project path URL
470 if (defined $params{'action'} && $params{'action'} eq 'summary') {
471 delete $params{'action'};
475 # now encode the parameters explicitly
477 for (my $i = 0; $i < @mapping; $i += 2) {
478 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
479 if (defined $params{$name}) {
480 push @result, $symbol . "=" . esc_param
($params{$name});
483 $href .= "?" . join(';', @result) if scalar @result;
489 ## ======================================================================
490 ## validation, quoting/unquoting and escaping
492 sub validate_pathname
{
493 my $input = shift || return undef;
495 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
496 # at the beginning, at the end, and between slashes.
497 # also this catches doubled slashes
498 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
502 if ($input =~ m!\0!) {
508 sub validate_refname
{
509 my $input = shift || return undef;
511 # textual hashes are O.K.
512 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
515 # it must be correct pathname
516 $input = validate_pathname
($input)
518 # restrictions on ref name according to git-check-ref-format
519 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
525 # very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT);
528 return decode
("utf8", $str, Encode
::FB_DEFAULT
);
531 # quote unsafe chars, but keep the slash, even when it's not
532 # correct, but quoted slashes look too horrible in bookmarks
535 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
541 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
544 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
550 # replace invalid utf8 character with SUBSTITUTION sequence
553 $str = to_utf8
($str);
554 $str = escapeHTML
($str);
555 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
556 $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1)
560 # git may return quoted and escaped filenames
563 if ($str =~ m/^"(.*)"$/) {
565 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
570 # escape tabs (convert tabs to spaces)
574 while ((my $pos = index($line, "\t")) != -1) {
575 if (my $count = (8 - ($pos % 8))) {
576 my $spaces = ' ' x
$count;
577 $line =~ s/\t/$spaces/;
584 sub project_in_list
{
586 my @list = git_get_projects_list
();
587 return @list && scalar(grep { $_->{'path'} eq $project } @list);
590 ## ----------------------------------------------------------------------
591 ## HTML aware string manipulation
596 my $add_len = shift || 10;
598 # allow only $len chars, but don't cut a word if it would fit in $add_len
599 # if it doesn't fit, cut it if it's still longer than the dots we would add
600 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
603 if (length($tail) > 4) {
605 $body =~ s/&[^;]*$//; # remove chopped character entities
610 ## ----------------------------------------------------------------------
611 ## functions returning short strings
613 # CSS class for given age value (in seconds)
617 if ($age < 60*60*2) {
619 } elsif ($age < 60*60*24*2) {
626 # convert age in seconds to "nn units ago" string
631 if ($age > 60*60*24*365*2) {
632 $age_str = (int $age/60/60/24/365);
633 $age_str .= " years ago";
634 } elsif ($age > 60*60*24*(365/12)*2) {
635 $age_str = int $age/60/60/24/(365/12);
636 $age_str .= " months ago";
637 } elsif ($age > 60*60*24*7*2) {
638 $age_str = int $age/60/60/24/7;
639 $age_str .= " weeks ago";
640 } elsif ($age > 60*60*24*2) {
641 $age_str = int $age/60/60/24;
642 $age_str .= " days ago";
643 } elsif ($age > 60*60*2) {
644 $age_str = int $age/60/60;
645 $age_str .= " hours ago";
646 } elsif ($age > 60*2) {
647 $age_str = int $age/60;
648 $age_str .= " min ago";
651 $age_str .= " sec ago";
653 $age_str .= " right now";
658 # convert file mode in octal to symbolic file mode string
660 my $mode = oct shift;
662 if (S_ISDIR
($mode & S_IFMT
)) {
664 } elsif (S_ISLNK
($mode)) {
666 } elsif (S_ISREG
($mode)) {
667 # git cares only about the executable bit
668 if ($mode & S_IXUSR
) {
678 # convert file mode in octal to file type string
682 if ($mode !~ m/^[0-7]+$/) {
688 if (S_ISDIR
($mode & S_IFMT
)) {
690 } elsif (S_ISLNK
($mode)) {
692 } elsif (S_ISREG
($mode)) {
699 ## ----------------------------------------------------------------------
700 ## functions returning short HTML fragments, or transforming HTML fragments
701 ## which don't beling to other sections
703 # format line of commit message or tag comment
704 sub format_log_line_html
{
707 $line = esc_html
($line);
708 $line =~ s/ / /g;
709 if ($line =~ m/([0-9a-fA-F]{40})/) {
711 if (git_get_type
($hash_text) eq "commit") {
713 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
714 -class => "text"}, $hash_text);
715 $line =~ s/$hash_text/$link/;
721 # format marker of refs pointing to given object
722 sub format_ref_marker
{
723 my ($refs, $id) = @_;
726 if (defined $refs->{$id}) {
727 foreach my $ref (@
{$refs->{$id}}) {
728 my ($type, $name) = qw();
729 # e.g. tags/v2.6.11 or heads/next
730 if ($ref =~ m!^(.*?)s?/(.*)$!) {
738 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
743 return ' <span class="refs">'. $markers . '</span>';
749 # format, perhaps shortened and with markers, title line
750 sub format_subject_html
{
751 my ($long, $short, $href, $extra) = @_;
752 $extra = '' unless defined($extra);
754 if (length($short) < length($long)) {
755 return $cgi->a({-href
=> $href, -class => "list subject",
756 -title
=> to_utf8
($long)},
757 esc_html
($short) . $extra);
759 return $cgi->a({-href
=> $href, -class => "list subject"},
760 esc_html
($long) . $extra);
764 sub format_diff_line
{
766 my $char = substr($line, 0, 1);
772 $diff_class = " add";
773 } elsif ($char eq "-") {
774 $diff_class = " rem";
775 } elsif ($char eq "@") {
776 $diff_class = " chunk_header";
777 } elsif ($char eq "\\") {
778 $diff_class = " incomplete";
780 $line = untabify
($line);
781 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
784 ## ----------------------------------------------------------------------
785 ## git utility subroutines, invoking git commands
787 # returns path to the core git executable and the --git-dir parameter as list
789 return $GIT, '--git-dir='.$git_dir;
792 # returns path to the core git executable and the --git-dir parameter as string
794 return join(' ', git_cmd
());
797 # get HEAD ref of given project as hash
798 sub git_get_head_hash
{
800 my $o_git_dir = $git_dir;
802 $git_dir = "$projectroot/$project";
803 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
806 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
810 if (defined $o_git_dir) {
811 $git_dir = $o_git_dir;
816 # get type of given object
820 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
827 sub git_get_project_config
{
828 my ($key, $type) = @_;
830 return unless ($key);
831 $key =~ s/^gitweb\.//;
832 return if ($key =~ m/\W/);
834 my @x = (git_cmd
(), 'repo-config');
835 if (defined $type) { push @x, $type; }
837 push @x, "gitweb.$key";
843 # get hash of given path at given ref
844 sub git_get_hash_by_path
{
846 my $path = shift || return undef;
851 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
852 or die_error
(undef, "Open git-ls-tree failed");
854 close $fd or return undef;
856 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
857 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
858 if (defined $type && $type ne $2) {
865 ## ......................................................................
866 ## git utility functions, directly accessing git repository
868 sub git_get_project_description
{
871 open my $fd, "$projectroot/$path/description" or return undef;
878 sub git_get_project_url_list
{
881 open my $fd, "$projectroot/$path/cloneurl" or return;
882 my @git_project_url_list = map { chomp; $_ } <$fd>;
885 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
888 sub git_get_projects_list
{
891 if (-d
$projects_list) {
892 # search in directory
893 my $dir = $projects_list;
894 my $pfxlen = length("$dir");
897 follow_fast
=> 1, # follow symbolic links
898 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
900 # skip project-list toplevel, if we get it.
901 return if (m!^[/.]$!);
902 # only directories can be git repositories
903 return unless (-d
$_);
905 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
906 # we check related file in $projectroot
907 if (check_export_ok
("$projectroot/$subdir")) {
908 push @list, { path
=> $subdir };
909 $File::Find
::prune
= 1;
914 } elsif (-f
$projects_list) {
915 # read from file(url-encoded):
916 # 'git%2Fgit.git Linus+Torvalds'
917 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
918 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
919 open my ($fd), $projects_list or return;
920 while (my $line = <$fd>) {
922 my ($path, $owner) = split ' ', $line;
923 $path = unescape
($path);
924 $owner = unescape
($owner);
925 if (!defined $path) {
928 if (check_export_ok
("$projectroot/$path")) {
931 owner
=> to_utf8
($owner),
938 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
942 sub git_get_project_owner
{
946 return undef unless $project;
948 # read from file (url-encoded):
949 # 'git%2Fgit.git Linus+Torvalds'
950 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
951 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
952 if (-f
$projects_list) {
953 open (my $fd , $projects_list);
954 while (my $line = <$fd>) {
956 my ($pr, $ow) = split ' ', $line;
959 if ($pr eq $project) {
960 $owner = to_utf8
($ow);
966 if (!defined $owner) {
967 $owner = get_file_owner
("$projectroot/$project");
973 sub git_get_references
{
974 my $type = shift || "";
976 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
977 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
978 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
981 while (my $line = <$fd>) {
983 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
984 if (defined $refs{$1}) {
985 push @
{$refs{$1}}, $2;
995 sub git_get_rev_name_tags
{
996 my $hash = shift || return undef;
998 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1000 my $name_rev = <$fd>;
1003 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1006 # catches also '$hash undefined' output
1011 ## ----------------------------------------------------------------------
1012 ## parse to hash functions
1016 my $tz = shift || "-0000";
1019 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1020 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1021 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1022 $date{'hour'} = $hour;
1023 $date{'minute'} = $min;
1024 $date{'mday'} = $mday;
1025 $date{'day'} = $days[$wday];
1026 $date{'month'} = $months[$mon];
1027 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1028 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1029 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1030 $mday, $months[$mon], $hour ,$min;
1032 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1033 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1034 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1035 $date{'hour_local'} = $hour;
1036 $date{'minute_local'} = $min;
1037 $date{'tz_local'} = $tz;
1046 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1047 $tag{'id'} = $tag_id;
1048 while (my $line = <$fd>) {
1050 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1051 $tag{'object'} = $1;
1052 } elsif ($line =~ m/^type (.+)$/) {
1054 } elsif ($line =~ m/^tag (.+)$/) {
1056 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1057 $tag{'author'} = $1;
1060 } elsif ($line =~ m/--BEGIN/) {
1061 push @comment, $line;
1063 } elsif ($line eq "") {
1067 push @comment, <$fd>;
1068 $tag{'comment'} = \
@comment;
1069 close $fd or return;
1070 if (!defined $tag{'name'}) {
1076 sub git_get_last_activity
{
1080 $git_dir = "$projectroot/$path";
1081 open($fd, "-|", git_cmd
(), 'for-each-ref',
1082 '--format=%(refname) %(committer)',
1083 '--sort=-committerdate',
1084 'refs/heads') or return;
1085 my $most_recent = <$fd>;
1086 close $fd or return;
1087 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1089 my $age = time - $timestamp;
1090 return ($age, age_string
($age));
1095 my $commit_id = shift;
1096 my $commit_text = shift;
1101 if (defined $commit_text) {
1102 @commit_lines = @
$commit_text;
1105 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
1107 @commit_lines = split '\n', <$fd>;
1108 close $fd or return;
1111 my $header = shift @commit_lines;
1112 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1115 ($co{'id'}, my @parents) = split ' ', $header;
1116 $co{'parents'} = \
@parents;
1117 $co{'parent'} = $parents[0];
1118 while (my $line = shift @commit_lines) {
1119 last if $line eq "\n";
1120 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1122 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1124 $co{'author_epoch'} = $2;
1125 $co{'author_tz'} = $3;
1126 if ($co{'author'} =~ m/^([^<]+) </) {
1127 $co{'author_name'} = $1;
1129 $co{'author_name'} = $co{'author'};
1131 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1132 $co{'committer'} = $1;
1133 $co{'committer_epoch'} = $2;
1134 $co{'committer_tz'} = $3;
1135 $co{'committer_name'} = $co{'committer'};
1136 $co{'committer_name'} =~ s/ <.*//;
1139 if (!defined $co{'tree'}) {
1143 foreach my $title (@commit_lines) {
1146 $co{'title'} = chop_str
($title, 80, 5);
1147 # remove leading stuff of merges to make the interesting part visible
1148 if (length($title) > 50) {
1149 $title =~ s/^Automatic //;
1150 $title =~ s/^merge (of|with) /Merge ... /i;
1151 if (length($title) > 50) {
1152 $title =~ s/(http|rsync):\/\///;
1154 if (length($title) > 50) {
1155 $title =~ s/(master|www|rsync)\.//;
1157 if (length($title) > 50) {
1158 $title =~ s/kernel.org:?//;
1160 if (length($title) > 50) {
1161 $title =~ s/\/pub\/scm//;
1164 $co{'title_short'} = chop_str
($title, 50, 5);
1168 if ($co{'title'} eq "") {
1169 $co{'title'} = $co{'title_short'} = '(no commit message)';
1171 # remove added spaces
1172 foreach my $line (@commit_lines) {
1175 $co{'comment'} = \
@commit_lines;
1177 my $age = time - $co{'committer_epoch'};
1179 $co{'age_string'} = age_string
($age);
1180 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1181 if ($age > 60*60*24*7*2) {
1182 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1183 $co{'age_string_age'} = $co{'age_string'};
1185 $co{'age_string_date'} = $co{'age_string'};
1186 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1191 # parse ref from ref_file, given by ref_id, with given type
1193 my $ref_file = shift;
1195 my $type = shift || git_get_type
($ref_id);
1198 $ref_item{'type'} = $type;
1199 $ref_item{'id'} = $ref_id;
1200 $ref_item{'epoch'} = 0;
1201 $ref_item{'age'} = "unknown";
1202 if ($type eq "tag") {
1203 my %tag = parse_tag
($ref_id);
1204 $ref_item{'comment'} = $tag{'comment'};
1205 if ($tag{'type'} eq "commit") {
1206 my %co = parse_commit
($tag{'object'});
1207 $ref_item{'epoch'} = $co{'committer_epoch'};
1208 $ref_item{'age'} = $co{'age_string'};
1209 } elsif (defined($tag{'epoch'})) {
1210 my $age = time - $tag{'epoch'};
1211 $ref_item{'epoch'} = $tag{'epoch'};
1212 $ref_item{'age'} = age_string
($age);
1214 $ref_item{'reftype'} = $tag{'type'};
1215 $ref_item{'name'} = $tag{'name'};
1216 $ref_item{'refid'} = $tag{'object'};
1217 } elsif ($type eq "commit"){
1218 my %co = parse_commit
($ref_id);
1219 $ref_item{'reftype'} = "commit";
1220 $ref_item{'name'} = $ref_file;
1221 $ref_item{'title'} = $co{'title'};
1222 $ref_item{'refid'} = $ref_id;
1223 $ref_item{'epoch'} = $co{'committer_epoch'};
1224 $ref_item{'age'} = $co{'age_string'};
1226 $ref_item{'reftype'} = $type;
1227 $ref_item{'name'} = $ref_file;
1228 $ref_item{'refid'} = $ref_id;
1234 # parse line of git-diff-tree "raw" output
1235 sub parse_difftree_raw_line
{
1239 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1240 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1241 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1242 $res{'from_mode'} = $1;
1243 $res{'to_mode'} = $2;
1244 $res{'from_id'} = $3;
1246 $res{'status'} = $5;
1247 $res{'similarity'} = $6;
1248 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1249 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1251 $res{'file'} = unquote
($7);
1254 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1255 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1256 $res{'commit'} = $1;
1259 return wantarray ?
%res : \
%res;
1262 # parse line of git-ls-tree output
1263 sub parse_ls_tree_line
($;%) {
1268 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1269 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1277 $res{'name'} = unquote
($4);
1280 return wantarray ?
%res : \
%res;
1283 ## ......................................................................
1284 ## parse to array of hashes functions
1286 sub git_get_refs_list
{
1287 my $type = shift || "";
1292 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1294 while (my $line = <$fd>) {
1296 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?([^\^]+))(\^\{\})?$/) {
1297 if (defined $refs{$1}) {
1298 push @
{$refs{$1}}, $2;
1303 if (! $4) { # unpeeled, direct reference
1304 push @refs, { hash
=> $1, name
=> $3 }; # without type
1305 } elsif ($3 eq $refs[-1]{'name'}) {
1306 # most likely a tag is followed by its peeled
1307 # (deref) one, and when that happens we know the
1308 # previous one was of type 'tag'.
1309 $refs[-1]{'type'} = "tag";
1315 foreach my $ref (@refs) {
1316 my $ref_file = $ref->{'name'};
1317 my $ref_id = $ref->{'hash'};
1319 my $type = $ref->{'type'} || git_get_type
($ref_id) || next;
1320 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1322 push @reflist, \
%ref_item;
1325 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1326 return (\
@reflist, \
%refs);
1329 ## ----------------------------------------------------------------------
1330 ## filesystem-related functions
1332 sub get_file_owner
{
1335 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1336 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1337 if (!defined $gcos) {
1341 $owner =~ s/[,;].*$//;
1342 return to_utf8
($owner);
1345 ## ......................................................................
1346 ## mimetype related functions
1348 sub mimetype_guess_file
{
1349 my $filename = shift;
1350 my $mimemap = shift;
1351 -r
$mimemap or return undef;
1354 open(MIME
, $mimemap) or return undef;
1356 next if m/^#/; # skip comments
1357 my ($mime, $exts) = split(/\t+/);
1358 if (defined $exts) {
1359 my @exts = split(/\s+/, $exts);
1360 foreach my $ext (@exts) {
1361 $mimemap{$ext} = $mime;
1367 $filename =~ /\.([^.]*)$/;
1368 return $mimemap{$1};
1371 sub mimetype_guess
{
1372 my $filename = shift;
1374 $filename =~ /\./ or return undef;
1376 if ($mimetypes_file) {
1377 my $file = $mimetypes_file;
1378 if ($file !~ m!^/!) { # if it is relative path
1379 # it is relative to project
1380 $file = "$projectroot/$project/$file";
1382 $mime = mimetype_guess_file
($filename, $file);
1384 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1390 my $filename = shift;
1393 my $mime = mimetype_guess
($filename);
1394 $mime and return $mime;
1398 return $default_blob_plain_mimetype unless $fd;
1401 return 'text/plain' .
1402 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1403 } elsif (! $filename) {
1404 return 'application/octet-stream';
1405 } elsif ($filename =~ m/\.png$/i) {
1407 } elsif ($filename =~ m/\.gif$/i) {
1409 } elsif ($filename =~ m/\.jpe?g$/i) {
1410 return 'image/jpeg';
1412 return 'application/octet-stream';
1416 ## ======================================================================
1417 ## functions printing HTML: header, footer, error page
1419 sub git_header_html
{
1420 my $status = shift || "200 OK";
1421 my $expires = shift;
1423 my $title = "$site_name git";
1424 if (defined $project) {
1425 $title .= " - $project";
1426 if (defined $action) {
1427 $title .= "/$action";
1428 if (defined $file_name) {
1429 $title .= " - " . esc_html
($file_name);
1430 if ($action eq "tree" && $file_name !~ m
|/$|) {
1437 # require explicit support from the UA if we are to send the page as
1438 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1439 # we have to do this because MSIE sometimes globs '*/*', pretending to
1440 # support xhtml+xml but choking when it gets what it asked for.
1441 if (defined $cgi->http('HTTP_ACCEPT') &&
1442 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1443 $cgi->Accept('application/xhtml+xml') != 0) {
1444 $content_type = 'application/xhtml+xml';
1446 $content_type = 'text/html';
1448 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1449 -status
=> $status, -expires
=> $expires);
1451 <?xml version="1.0" encoding="utf-8"?>
1452 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1453 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1454 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1455 <!-- git core binaries version $git_version -->
1457 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1458 <meta name="generator" content="gitweb/$version git/$git_version"/>
1459 <meta name="robots" content="index, nofollow"/>
1460 <title>$title</title>
1462 # print out each stylesheet that exist
1463 if (defined $stylesheet) {
1464 #provides backwards capability for those people who define style sheet in a config file
1465 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1467 foreach my $stylesheet (@stylesheets) {
1468 next unless $stylesheet;
1469 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1472 if (defined $project) {
1473 printf('<link rel="alternate" title="%s log" '.
1474 'href="%s" type="application/rss+xml"/>'."\n",
1475 esc_param
($project), href
(action
=>"rss"));
1477 printf('<link rel="alternate" title="%s projects list" '.
1478 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1479 $site_name, href
(project
=>undef, action
=>"project_index"));
1480 printf('<link rel="alternate" title="%s projects logs" '.
1481 'href="%s" type="text/x-opml"/>'."\n",
1482 $site_name, href
(project
=>undef, action
=>"opml"));
1484 if (defined $favicon) {
1485 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
1491 if (-f
$site_header) {
1492 open (my $fd, $site_header);
1497 print "<div class=\"page_header\">\n" .
1498 $cgi->a({-href
=> esc_url
($logo_url),
1499 -title
=> $logo_label},
1500 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
1501 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1502 if (defined $project) {
1503 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1504 if (defined $action) {
1508 if (!defined $searchtext) {
1512 if (defined $hash_base) {
1513 $search_hash = $hash_base;
1514 } elsif (defined $hash) {
1515 $search_hash = $hash;
1517 $search_hash = "HEAD";
1519 $cgi->param("a", "search");
1520 $cgi->param("h", $search_hash);
1521 $cgi->param("p", $project);
1522 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1523 "<div class=\"search\">\n" .
1524 $cgi->hidden(-name
=> "p") . "\n" .
1525 $cgi->hidden(-name
=> "a") . "\n" .
1526 $cgi->hidden(-name
=> "h") . "\n" .
1527 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1529 $cgi->end_form() . "\n";
1534 sub git_footer_html
{
1535 print "<div class=\"page_footer\">\n";
1536 if (defined $project) {
1537 my $descr = git_get_project_description
($project);
1538 if (defined $descr) {
1539 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1541 print $cgi->a({-href
=> href
(action
=>"rss"),
1542 -class => "rss_logo"}, "RSS") . "\n";
1544 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1545 -class => "rss_logo"}, "OPML") . " ";
1546 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1547 -class => "rss_logo"}, "TXT") . "\n";
1551 if (-f
$site_footer) {
1552 open (my $fd, $site_footer);
1562 my $status = shift || "403 Forbidden";
1563 my $error = shift || "Malformed query, file missing or permission denied";
1565 git_header_html
($status);
1567 <div class="page_body">
1577 ## ----------------------------------------------------------------------
1578 ## functions printing or outputting HTML: navigation
1580 sub git_print_page_nav
{
1581 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1582 $extra = '' if !defined $extra; # pager or formats
1584 my @navs = qw(summary shortlog log commit commitdiff tree);
1586 @navs = grep { $_ ne $suppress } @navs;
1589 my %arg = map { $_ => {action
=>$_} } @navs;
1590 if (defined $head) {
1591 for (qw(commit commitdiff)) {
1592 $arg{$_}{hash
} = $head;
1594 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1595 for (qw(shortlog log)) {
1596 $arg{$_}{hash
} = $head;
1600 $arg{tree
}{hash
} = $treehead if defined $treehead;
1601 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1603 print "<div class=\"page_nav\">\n" .
1605 map { $_ eq $current ?
1606 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1608 print "<br/>\n$extra<br/>\n" .
1612 sub format_paging_nav
{
1613 my ($action, $hash, $head, $page, $nrevs) = @_;
1617 if ($hash ne $head || $page) {
1618 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1620 $paging_nav .= "HEAD";
1624 $paging_nav .= " ⋅ " .
1625 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1626 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1628 $paging_nav .= " ⋅ prev";
1631 if ($nrevs >= (100 * ($page+1)-1)) {
1632 $paging_nav .= " ⋅ " .
1633 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1634 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1636 $paging_nav .= " ⋅ next";
1642 ## ......................................................................
1643 ## functions printing or outputting HTML: div
1645 sub git_print_header_div
{
1646 my ($action, $title, $hash, $hash_base) = @_;
1649 $args{action
} = $action;
1650 $args{hash
} = $hash if $hash;
1651 $args{hash_base
} = $hash_base if $hash_base;
1653 print "<div class=\"header\">\n" .
1654 $cgi->a({-href
=> href
(%args), -class => "title"},
1655 $title ?
$title : $action) .
1659 #sub git_print_authorship (\%) {
1660 sub git_print_authorship
{
1663 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1664 print "<div class=\"author_date\">" .
1665 esc_html
($co->{'author_name'}) .
1667 if ($ad{'hour_local'} < 6) {
1668 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1669 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1671 printf(" (%02d:%02d %s)",
1672 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1677 sub git_print_page_path
{
1683 print "<div class=\"page_path\">";
1684 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1685 -title
=> 'tree root'}, "[$project]");
1687 if (defined $name) {
1688 my @dirname = split '/', $name;
1689 my $basename = pop @dirname;
1692 foreach my $dir (@dirname) {
1693 $fullname .= ($fullname ?
'/' : '') . $dir;
1694 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1696 -title
=> $fullname}, esc_html
($dir));
1699 if (defined $type && $type eq 'blob') {
1700 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1702 -title
=> $name}, esc_html
($basename));
1703 } elsif (defined $type && $type eq 'tree') {
1704 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1706 -title
=> $name}, esc_html
($basename));
1709 print esc_html
($basename);
1712 print "<br/></div>\n";
1715 # sub git_print_log (\@;%) {
1716 sub git_print_log
($;%) {
1720 if ($opts{'-remove_title'}) {
1721 # remove title, i.e. first line of log
1724 # remove leading empty lines
1725 while (defined $log->[0] && $log->[0] eq "") {
1732 foreach my $line (@
$log) {
1733 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1736 if (! $opts{'-remove_signoff'}) {
1737 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1740 # remove signoff lines
1747 # print only one empty line
1748 # do not print empty line after signoff
1750 next if ($empty || $signoff);
1756 print format_log_line_html
($line) . "<br/>\n";
1759 if ($opts{'-final_empty_line'}) {
1760 # end with single empty line
1761 print "<br/>\n" unless $empty;
1765 sub git_print_simplified_log
{
1767 my $remove_title = shift;
1770 -final_empty_line
=> 1,
1771 -remove_title
=> $remove_title);
1774 # print tree entry (row of git_tree), but without encompassing <tr> element
1775 sub git_print_tree_entry
{
1776 my ($t, $basedir, $hash_base, $have_blame) = @_;
1779 $base_key{hash_base
} = $hash_base if defined $hash_base;
1781 # The format of a table row is: mode list link. Where mode is
1782 # the mode of the entry, list is the name of the entry, an href,
1783 # and link is the action links of the entry.
1785 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1786 if ($t->{'type'} eq "blob") {
1787 print "<td class=\"list\">" .
1788 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1789 file_name
=>"$basedir$t->{'name'}", %base_key),
1790 -class => "list"}, esc_html
($t->{'name'})) . "</td>\n";
1791 print "<td class=\"link\">";
1792 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1793 file_name
=>"$basedir$t->{'name'}", %base_key)},
1797 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1798 file_name
=>"$basedir$t->{'name'}", %base_key)},
1801 if (defined $hash_base) {
1803 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1804 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1808 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
1809 file_name
=>"$basedir$t->{'name'}")},
1813 } elsif ($t->{'type'} eq "tree") {
1814 print "<td class=\"list\">";
1815 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1816 file_name
=>"$basedir$t->{'name'}", %base_key)},
1817 esc_html
($t->{'name'}));
1819 print "<td class=\"link\">";
1820 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1821 file_name
=>"$basedir$t->{'name'}", %base_key)},
1823 if (defined $hash_base) {
1825 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1826 file_name
=>"$basedir$t->{'name'}")},
1833 ## ......................................................................
1834 ## functions printing large fragments of HTML
1836 sub git_difftree_body
{
1837 my ($difftree, $hash, $parent) = @_;
1839 print "<div class=\"list_head\">\n";
1840 if ($#{$difftree} > 10) {
1841 print(($#{$difftree} + 1) . " files changed:\n");
1845 print "<table class=\"diff_tree\">\n";
1848 foreach my $line (@
{$difftree}) {
1849 my %diff = parse_difftree_raw_line
($line);
1852 print "<tr class=\"dark\">\n";
1854 print "<tr class=\"light\">\n";
1858 my ($to_mode_oct, $to_mode_str, $to_file_type);
1859 my ($from_mode_oct, $from_mode_str, $from_file_type);
1860 if ($diff{'to_mode'} ne ('0' x
6)) {
1861 $to_mode_oct = oct $diff{'to_mode'};
1862 if (S_ISREG
($to_mode_oct)) { # only for regular file
1863 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1865 $to_file_type = file_type
($diff{'to_mode'});
1867 if ($diff{'from_mode'} ne ('0' x
6)) {
1868 $from_mode_oct = oct $diff{'from_mode'};
1869 if (S_ISREG
($to_mode_oct)) { # only for regular file
1870 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1872 $from_file_type = file_type
($diff{'from_mode'});
1875 if ($diff{'status'} eq "A") { # created
1876 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1877 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1878 $mode_chng .= "]</span>";
1880 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1881 hash_base
=>$hash, file_name
=>$diff{'file'}),
1882 -class => "list"}, esc_html
($diff{'file'}));
1884 print "<td>$mode_chng</td>\n";
1885 print "<td class=\"link\">";
1886 if ($action eq 'commitdiff') {
1889 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1893 } elsif ($diff{'status'} eq "D") { # deleted
1894 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1896 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1897 hash_base
=>$parent, file_name
=>$diff{'file'}),
1898 -class => "list"}, esc_html
($diff{'file'}));
1900 print "<td>$mode_chng</td>\n";
1901 print "<td class=\"link\">";
1902 if ($action eq 'commitdiff') {
1905 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1908 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1909 hash_base
=>$parent, file_name
=>$diff{'file'})},
1911 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1912 file_name
=>$diff{'file'})},
1914 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1915 file_name
=>$diff{'file'})},
1919 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1920 my $mode_chnge = "";
1921 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1922 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1923 if ($from_file_type != $to_file_type) {
1924 $mode_chnge .= " from $from_file_type to $to_file_type";
1926 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1927 if ($from_mode_str && $to_mode_str) {
1928 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1929 } elsif ($to_mode_str) {
1930 $mode_chnge .= " mode: $to_mode_str";
1933 $mode_chnge .= "]</span>\n";
1936 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1937 hash_base
=>$hash, file_name
=>$diff{'file'}),
1938 -class => "list"}, esc_html
($diff{'file'}));
1940 print "<td>$mode_chnge</td>\n";
1941 print "<td class=\"link\">";
1942 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1943 if ($action eq 'commitdiff') {
1946 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1948 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1949 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1950 hash_base
=>$hash, hash_parent_base
=>$parent,
1951 file_name
=>$diff{'file'})},
1956 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1957 hash_base
=>$hash, file_name
=>$diff{'file'})},
1959 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
1960 file_name
=>$diff{'file'})},
1962 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
1963 file_name
=>$diff{'file'})},
1967 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1968 my %status_name = ('R' => 'moved', 'C' => 'copied');
1969 my $nstatus = $status_name{$diff{'status'}};
1971 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1972 # mode also for directories, so we cannot use $to_mode_str
1973 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1976 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1977 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1978 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1979 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1980 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1981 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1982 -class => "list"}, esc_html
($diff{'from_file'})) .
1983 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1984 "<td class=\"link\">";
1985 if ($diff{'to_id'} ne $diff{'from_id'}) {
1986 if ($action eq 'commitdiff') {
1989 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1991 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1992 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1993 hash_base
=>$hash, hash_parent_base
=>$parent,
1994 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1999 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2000 hash_base
=>$parent, file_name
=>$diff{'from_file'})},
2002 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2003 file_name
=>$diff{'from_file'})},
2005 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2006 file_name
=>$diff{'from_file'})},
2010 } # we should not encounter Unmerged (U) or Unknown (X) status
2016 sub git_patchset_body
{
2017 my ($fd, $difftree, $hash, $hash_parent) = @_;
2021 my $patch_found = 0;
2024 print "<div class=\"patchset\">\n";
2027 while (my $patch_line = <$fd>) {
2030 if ($patch_line =~ m/^diff /) { # "git diff" header
2031 # beginning of patch (in patchset)
2033 # close previous patch
2034 print "</div>\n"; # class="patch"
2036 # first patch in patchset
2039 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2041 if (ref($difftree->[$patch_idx]) eq "HASH") {
2042 $diffinfo = $difftree->[$patch_idx];
2044 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2048 # for now, no extended header, hence we skip empty patches
2049 # companion to next LINE if $in_header;
2050 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
2055 if ($diffinfo->{'status'} eq "A") { # added
2056 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
2057 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2058 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2059 $diffinfo->{'to_id'}) . " (new)" .
2060 "</div>\n"; # class="diff_info"
2062 } elsif ($diffinfo->{'status'} eq "D") { # deleted
2063 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
2064 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2065 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2066 $diffinfo->{'from_id'}) . " (deleted)" .
2067 "</div>\n"; # class="diff_info"
2069 } elsif ($diffinfo->{'status'} eq "R" || # renamed
2070 $diffinfo->{'status'} eq "C" || # copied
2071 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
2072 print "<div class=\"diff_info\">" .
2073 file_type
($diffinfo->{'from_mode'}) . ":" .
2074 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2075 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
2076 $diffinfo->{'from_id'}) .
2078 file_type
($diffinfo->{'to_mode'}) . ":" .
2079 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2080 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
2081 $diffinfo->{'to_id'});
2082 print "</div>\n"; # class="diff_info"
2084 } else { # modified, mode changed, ...
2085 print "<div class=\"diff_info\">" .
2086 file_type
($diffinfo->{'from_mode'}) . ":" .
2087 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2088 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2089 $diffinfo->{'from_id'}) .
2091 file_type
($diffinfo->{'to_mode'}) . ":" .
2092 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2093 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2094 $diffinfo->{'to_id'});
2095 print "</div>\n"; # class="diff_info"
2098 #print "<div class=\"diff extended_header\">\n";
2101 } # start of patch in patchset
2104 if ($in_header && $patch_line =~ m/^---/) {
2105 #print "</div>\n"; # class="diff extended_header"
2108 my $file = $diffinfo->{'from_file'};
2109 $file ||= $diffinfo->{'file'};
2110 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2111 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
2112 -class => "list"}, esc_html
($file));
2113 $patch_line =~ s
|a
/.*$|a/$file|g
;
2114 print "<div class=\"diff from_file\">$patch_line</div>\n";
2116 $patch_line = <$fd>;
2119 #$patch_line =~ m/^+++/;
2120 $file = $diffinfo->{'to_file'};
2121 $file ||= $diffinfo->{'file'};
2122 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2123 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
2124 -class => "list"}, esc_html
($file));
2125 $patch_line =~ s
|b
/.*|b/$file|g
;
2126 print "<div class=\"diff to_file\">$patch_line</div>\n";
2130 next LINE
if $in_header;
2132 print format_diff_line
($patch_line);
2134 print "</div>\n" if $patch_found; # class="patch"
2136 print "</div>\n"; # class="patchset"
2139 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2141 sub git_shortlog_body
{
2142 # uses global variable $project
2143 my ($revlist, $from, $to, $refs, $extra) = @_;
2145 $from = 0 unless defined $from;
2146 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2148 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2150 for (my $i = $from; $i <= $to; $i++) {
2151 my $commit = $revlist->[$i];
2152 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2153 my $ref = format_ref_marker
($refs, $commit);
2154 my %co = parse_commit
($commit);
2156 print "<tr class=\"dark\">\n";
2158 print "<tr class=\"light\">\n";
2161 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2162 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2163 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2165 print format_subject_html
($co{'title'}, $co{'title_short'},
2166 href
(action
=>"commit", hash
=>$commit), $ref);
2168 "<td class=\"link\">" .
2169 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
2170 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2171 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2172 if (gitweb_have_snapshot
()) {
2173 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2178 if (defined $extra) {
2180 "<td colspan=\"4\">$extra</td>\n" .
2186 sub git_history_body
{
2187 # Warning: assumes constant type (blob or tree) during history
2188 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2190 $from = 0 unless defined $from;
2191 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2193 print "<table class=\"history\" cellspacing=\"0\">\n";
2195 for (my $i = $from; $i <= $to; $i++) {
2196 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2201 my %co = parse_commit
($commit);
2206 my $ref = format_ref_marker
($refs, $commit);
2209 print "<tr class=\"dark\">\n";
2211 print "<tr class=\"light\">\n";
2214 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2215 # shortlog uses chop_str($co{'author_name'}, 10)
2216 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2218 # originally git_history used chop_str($co{'title'}, 50)
2219 print format_subject_html
($co{'title'}, $co{'title_short'},
2220 href
(action
=>"commit", hash
=>$commit), $ref);
2222 "<td class=\"link\">" .
2223 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2224 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2226 if ($ftype eq 'blob') {
2227 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2228 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2229 if (defined $blob_current && defined $blob_parent &&
2230 $blob_current ne $blob_parent) {
2232 $cgi->a({-href
=> href
(action
=>"blobdiff",
2233 hash
=>$blob_current, hash_parent
=>$blob_parent,
2234 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2235 file_name
=>$file_name)},
2242 if (defined $extra) {
2244 "<td colspan=\"4\">$extra</td>\n" .
2251 # uses global variable $project
2252 my ($taglist, $from, $to, $extra) = @_;
2253 $from = 0 unless defined $from;
2254 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2256 print "<table class=\"tags\" cellspacing=\"0\">\n";
2258 for (my $i = $from; $i <= $to; $i++) {
2259 my $entry = $taglist->[$i];
2261 my $comment_lines = $tag{'comment'};
2262 my $comment = shift @
$comment_lines;
2264 if (defined $comment) {
2265 $comment_short = chop_str
($comment, 30, 5);
2268 print "<tr class=\"dark\">\n";
2270 print "<tr class=\"light\">\n";
2273 print "<td><i>$tag{'age'}</i></td>\n" .
2275 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2276 -class => "list name"}, esc_html
($tag{'name'})) .
2279 if (defined $comment) {
2280 print format_subject_html
($comment, $comment_short,
2281 href
(action
=>"tag", hash
=>$tag{'id'}));
2284 "<td class=\"selflink\">";
2285 if ($tag{'type'} eq "tag") {
2286 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2291 "<td class=\"link\">" . " | " .
2292 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2293 if ($tag{'reftype'} eq "commit") {
2294 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2295 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
2296 } elsif ($tag{'reftype'} eq "blob") {
2297 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2302 if (defined $extra) {
2304 "<td colspan=\"5\">$extra</td>\n" .
2310 sub git_heads_body
{
2311 # uses global variable $project
2312 my ($headlist, $head, $from, $to, $extra) = @_;
2313 $from = 0 unless defined $from;
2314 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2316 print "<table class=\"heads\" cellspacing=\"0\">\n";
2318 for (my $i = $from; $i <= $to; $i++) {
2319 my $entry = $headlist->[$i];
2321 my $curr = $tag{'id'} eq $head;
2323 print "<tr class=\"dark\">\n";
2325 print "<tr class=\"light\">\n";
2328 print "<td><i>$tag{'age'}</i></td>\n" .
2329 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
2330 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
2331 -class => "list name"},esc_html
($tag{'name'})) .
2333 "<td class=\"link\">" .
2334 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
2335 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") . " | " .
2336 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$tag{'name'}, hash_base
=>$tag{'name'})}, "tree") .
2340 if (defined $extra) {
2342 "<td colspan=\"3\">$extra</td>\n" .
2348 ## ======================================================================
2349 ## ======================================================================
2352 sub git_project_list
{
2353 my $order = $cgi->param('o');
2354 if (defined $order && $order !~ m/project|descr|owner|age/) {
2355 die_error
(undef, "Unknown order parameter");
2358 my @list = git_get_projects_list
();
2361 die_error
(undef, "No projects found");
2363 foreach my $pr (@list) {
2364 my (@aa) = git_get_last_activity
($pr->{'path'});
2368 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2369 if (!defined $pr->{'descr'}) {
2370 my $descr = git_get_project_description
($pr->{'path'}) || "";
2371 $pr->{'descr'} = chop_str
($descr, 25, 5);
2373 if (!defined $pr->{'owner'}) {
2374 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2376 push @projects, $pr;
2380 if (-f
$home_text) {
2381 print "<div class=\"index_include\">\n";
2382 open (my $fd, $home_text);
2387 print "<table class=\"project_list\">\n" .
2389 $order ||= "project";
2390 if ($order eq "project") {
2391 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2392 print "<th>Project</th>\n";
2395 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2396 -class => "header"}, "Project") .
2399 if ($order eq "descr") {
2400 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2401 print "<th>Description</th>\n";
2404 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2405 -class => "header"}, "Description") .
2408 if ($order eq "owner") {
2409 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2410 print "<th>Owner</th>\n";
2413 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2414 -class => "header"}, "Owner") .
2417 if ($order eq "age") {
2418 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2419 print "<th>Last Change</th>\n";
2422 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2423 -class => "header"}, "Last Change") .
2426 print "<th></th>\n" .
2429 foreach my $pr (@projects) {
2431 print "<tr class=\"dark\">\n";
2433 print "<tr class=\"light\">\n";
2436 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2437 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2438 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2439 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2440 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2441 $pr->{'age_string'} . "</td>\n" .
2442 "<td class=\"link\">" .
2443 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2444 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2445 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2446 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2454 sub git_project_index
{
2455 my @projects = git_get_projects_list
();
2458 -type
=> 'text/plain',
2459 -charset
=> 'utf-8',
2460 -content_disposition
=> 'inline; filename="index.aux"');
2462 foreach my $pr (@projects) {
2463 if (!exists $pr->{'owner'}) {
2464 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2467 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2468 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2469 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2470 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2474 print "$path $owner\n";
2479 my $descr = git_get_project_description
($project) || "none";
2480 my $head = git_get_head_hash
($project);
2481 my %co = parse_commit
($head);
2482 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2484 my $owner = git_get_project_owner
($project);
2486 my ($reflist, $refs) = git_get_refs_list
();
2490 foreach my $ref (@
$reflist) {
2491 if ($ref->{'name'} =~ s!^heads/!!) {
2492 push @headlist, $ref;
2494 $ref->{'name'} =~ s!^tags/!!;
2495 push @taglist, $ref;
2500 git_print_page_nav
('summary','', $head);
2502 print "<div class=\"title\"> </div>\n";
2503 print "<table cellspacing=\"0\">\n" .
2504 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2505 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2506 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2507 # use per project git URL list in $projectroot/$project/cloneurl
2508 # or make project git URL from git base URL and project name
2509 my $url_tag = "URL";
2510 my @url_list = git_get_project_url_list
($project);
2511 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2512 foreach my $git_url (@url_list) {
2513 next unless $git_url;
2514 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2519 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2520 git_get_head_hash
($project)
2521 or die_error
(undef, "Open git-rev-list failed");
2522 my @revlist = map { chomp; $_ } <$fd>;
2524 git_print_header_div
('shortlog');
2525 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2526 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2529 git_print_header_div
('tags');
2530 git_tags_body
(\
@taglist, 0, 15,
2531 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2535 git_print_header_div
('heads');
2536 git_heads_body
(\
@headlist, $head, 0, 15,
2537 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2544 my $head = git_get_head_hash
($project);
2546 git_print_page_nav
('','', $head,undef,$head);
2547 my %tag = parse_tag
($hash);
2548 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2549 print "<div class=\"title_text\">\n" .
2550 "<table cellspacing=\"0\">\n" .
2552 "<td>object</td>\n" .
2553 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2554 $tag{'object'}) . "</td>\n" .
2555 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2556 $tag{'type'}) . "</td>\n" .
2558 if (defined($tag{'author'})) {
2559 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2560 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2561 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2562 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2565 print "</table>\n\n" .
2567 print "<div class=\"page_body\">";
2568 my $comment = $tag{'comment'};
2569 foreach my $line (@
$comment) {
2570 print esc_html
($line) . "<br/>\n";
2580 my ($have_blame) = gitweb_check_feature
('blame');
2582 die_error
('403 Permission denied', "Permission denied");
2584 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2585 $hash_base ||= git_get_head_hash
($project);
2586 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2587 my %co = parse_commit
($hash_base)
2588 or die_error
(undef, "Reading commit failed");
2589 if (!defined $hash) {
2590 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2591 or die_error
(undef, "Error looking up file");
2593 $ftype = git_get_type
($hash);
2594 if ($ftype !~ "blob") {
2595 die_error
("400 Bad Request", "Object is not a blob");
2597 open ($fd, "-|", git_cmd
(), "blame", '-l', '--', $file_name, $hash_base)
2598 or die_error
(undef, "Open git-blame failed");
2601 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2604 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2607 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2609 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2610 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2611 git_print_page_path
($file_name, $ftype, $hash_base);
2612 my @rev_color = (qw(light2 dark2));
2613 my $num_colors = scalar(@rev_color);
2614 my $current_color = 0;
2617 <div class="page_body">
2618 <table class="blame">
2619 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2622 my ($full_rev, $author, $date, $lineno, $data) =
2623 /^([0-9a-f]{40}).*?\s\((.*?)\s+([-\d]+ [:\d]+ [-+\d]+)\s+(\d+)\)\s(.*)/;
2624 my $rev = substr($full_rev, 0, 8);
2627 if (!defined $last_rev) {
2628 $last_rev = $full_rev;
2630 } elsif ($last_rev ne $full_rev) {
2631 $last_rev = $full_rev;
2632 $current_color = ++$current_color % $num_colors;
2635 print "<tr class=\"$rev_color[$current_color]\">\n";
2636 print "<td class=\"sha1\"";
2637 if ($print_c8 == 1) {
2638 print " title=\"$author, $date\"";
2641 if ($print_c8 == 1) {
2642 print $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)},
2646 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2647 esc_html
($lineno) . "</a></td>\n";
2648 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2654 or print "Reading blob failed\n";
2661 my ($have_blame) = gitweb_check_feature
('blame');
2663 die_error
('403 Permission denied', "Permission denied");
2665 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2666 $hash_base ||= git_get_head_hash
($project);
2667 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2668 my %co = parse_commit
($hash_base)
2669 or die_error
(undef, "Reading commit failed");
2670 if (!defined $hash) {
2671 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2672 or die_error
(undef, "Error lookup file");
2674 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2675 or die_error
(undef, "Open git-annotate failed");
2678 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2681 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2684 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2686 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2687 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2688 git_print_page_path
($file_name, 'blob', $hash_base);
2689 print "<div class=\"page_body\">\n";
2691 <table class="blame">
2700 my @line_class = (qw(light dark));
2701 my $line_class_len = scalar (@line_class);
2702 my $line_class_num = $#line_class;
2703 while (my $line = <$fd>) {
2715 $line_class_num = ($line_class_num + 1) % $line_class_len;
2717 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2724 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2727 $short_rev = substr ($long_rev, 0, 8);
2728 $age = time () - $time;
2729 $age_str = age_string
($age);
2730 $age_str =~ s/ / /g;
2731 $age_class = age_class
($age);
2732 $author = esc_html
($author);
2733 $author =~ s/ / /g;
2735 $data = untabify
($data);
2736 $data = esc_html
($data);
2739 <tr class="$line_class[$line_class_num]">
2740 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2741 <td class="$age_class">$age_str</td>
2743 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2744 <td class="pre">$data</td>
2747 } # while (my $line = <$fd>)
2748 print "</table>\n\n";
2750 or print "Reading blob failed.\n";
2756 my $head = git_get_head_hash
($project);
2758 git_print_page_nav
('','', $head,undef,$head);
2759 git_print_header_div
('summary', $project);
2761 my ($taglist) = git_get_refs_list
("tags");
2763 git_tags_body
($taglist);
2769 my $head = git_get_head_hash
($project);
2771 git_print_page_nav
('','', $head,undef,$head);
2772 git_print_header_div
('summary', $project);
2774 my ($headlist) = git_get_refs_list
("heads");
2776 git_heads_body
($headlist, $head);
2781 sub git_blob_plain
{
2784 if (!defined $hash) {
2785 if (defined $file_name) {
2786 my $base = $hash_base || git_get_head_hash
($project);
2787 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2788 or die_error
(undef, "Error lookup file");
2790 die_error
(undef, "No file name defined");
2792 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2793 # blobs defined by non-textual hash id's can be cached
2798 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2799 or die_error
(undef, "Couldn't cat $file_name, $hash");
2801 $type ||= blob_mimetype
($fd, $file_name);
2803 # save as filename, even when no $file_name is given
2804 my $save_as = "$hash";
2805 if (defined $file_name) {
2806 $save_as = $file_name;
2807 } elsif ($type =~ m/^text\//) {
2814 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
2816 binmode STDOUT
, ':raw';
2818 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2826 if (!defined $hash) {
2827 if (defined $file_name) {
2828 my $base = $hash_base || git_get_head_hash
($project);
2829 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2830 or die_error
(undef, "Error lookup file");
2832 die_error
(undef, "No file name defined");
2834 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2835 # blobs defined by non-textual hash id's can be cached
2839 my ($have_blame) = gitweb_check_feature
('blame');
2840 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2841 or die_error
(undef, "Couldn't cat $file_name, $hash");
2842 my $mimetype = blob_mimetype
($fd, $file_name);
2843 if ($mimetype !~ m/^text\//) {
2845 return git_blob_plain
($mimetype);
2847 git_header_html
(undef, $expires);
2848 my $formats_nav = '';
2849 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2850 if (defined $file_name) {
2853 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2854 hash
=>$hash, file_name
=>$file_name)},
2859 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2860 hash
=>$hash, file_name
=>$file_name)},
2863 $cgi->a({-href
=> href
(action
=>"blob_plain",
2864 hash
=>$hash, file_name
=>$file_name)},
2867 $cgi->a({-href
=> href
(action
=>"blob",
2868 hash_base
=>"HEAD", file_name
=>$file_name)},
2872 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
2874 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2875 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2877 print "<div class=\"page_nav\">\n" .
2878 "<br/><br/></div>\n" .
2879 "<div class=\"title\">$hash</div>\n";
2881 git_print_page_path
($file_name, "blob", $hash_base);
2882 print "<div class=\"page_body\">\n";
2884 while (my $line = <$fd>) {
2887 $line = untabify
($line);
2888 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2889 $nr, $nr, $nr, esc_html
($line);
2892 or print "Reading blob failed.\n";
2898 my $have_snapshot = gitweb_have_snapshot
();
2900 if (!defined $hash_base) {
2901 $hash_base = "HEAD";
2903 if (!defined $hash) {
2904 if (defined $file_name) {
2905 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
2911 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
2912 or die_error
(undef, "Open git-ls-tree failed");
2913 my @entries = map { chomp; $_ } <$fd>;
2914 close $fd or die_error
(undef, "Reading tree failed");
2917 my $refs = git_get_references
();
2918 my $ref = format_ref_marker
($refs, $hash_base);
2921 my ($have_blame) = gitweb_check_feature
('blame');
2922 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2924 if (defined $file_name) {
2926 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2927 hash
=>$hash, file_name
=>$file_name)},
2929 $cgi->a({-href
=> href
(action
=>"tree",
2930 hash_base
=>"HEAD", file_name
=>$file_name)},
2933 if ($have_snapshot) {
2934 # FIXME: Should be available when we have no hash base as well.
2936 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
2939 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
2940 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2943 print "<div class=\"page_nav\">\n";
2944 print "<br/><br/></div>\n";
2945 print "<div class=\"title\">$hash</div>\n";
2947 if (defined $file_name) {
2948 $basedir = $file_name;
2949 if ($basedir ne '' && substr($basedir, -1) ne '/') {
2953 git_print_page_path
($file_name, 'tree', $hash_base);
2954 print "<div class=\"page_body\">\n";
2955 print "<table cellspacing=\"0\">\n";
2957 # '..' (top directory) link if possible
2958 if (defined $hash_base &&
2959 defined $file_name && $file_name =~ m![^/]+$!) {
2961 print "<tr class=\"dark\">\n";
2963 print "<tr class=\"light\">\n";
2967 my $up = $file_name;
2968 $up =~ s!/?[^/]+$!!;
2969 undef $up unless $up;
2970 # based on git_print_tree_entry
2971 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
2972 print '<td class="list">';
2973 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
2977 print "<td class=\"link\"></td>\n";
2981 foreach my $line (@entries) {
2982 my %t = parse_ls_tree_line
($line, -z
=> 1);
2985 print "<tr class=\"dark\">\n";
2987 print "<tr class=\"light\">\n";
2991 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
2995 print "</table>\n" .
3001 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3002 my $have_snapshot = (defined $ctype && defined $suffix);
3003 if (!$have_snapshot) {
3004 die_error
('403 Permission denied', "Permission denied");
3007 if (!defined $hash) {
3008 $hash = git_get_head_hash
($project);
3011 my $filename = basename
($project) . "-$hash.tar.$suffix";
3014 -type
=> 'application/x-tar',
3015 -content_encoding
=> $ctype,
3016 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3017 -status
=> '200 OK');
3019 my $git = git_cmd_str
();
3020 my $name = $project;
3021 $name =~ s/\047/\047\\\047\047/g;
3023 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3024 or die_error
(undef, "Execute git-tar-tree failed.");
3025 binmode STDOUT
, ':raw';
3027 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3033 my $head = git_get_head_hash
($project);
3034 if (!defined $hash) {
3037 if (!defined $page) {
3040 my $refs = git_get_references
();
3042 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3043 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3044 or die_error
(undef, "Open git-rev-list failed");
3045 my @revlist = map { chomp; $_ } <$fd>;
3048 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
3051 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3054 my %co = parse_commit
($hash);
3056 git_print_header_div
('summary', $project);
3057 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3059 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
3060 my $commit = $revlist[$i];
3061 my $ref = format_ref_marker
($refs, $commit);
3062 my %co = parse_commit
($commit);
3064 my %ad = parse_date
($co{'author_epoch'});
3065 git_print_header_div
('commit',
3066 "<span class=\"age\">$co{'age_string'}</span>" .
3067 esc_html
($co{'title'}) . $ref,
3069 print "<div class=\"title_text\">\n" .
3070 "<div class=\"log_link\">\n" .
3071 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3073 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3075 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3078 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3081 print "<div class=\"log_body\">\n";
3082 git_print_simplified_log
($co{'comment'});
3089 my %co = parse_commit
($hash);
3091 die_error
(undef, "Unknown commit object");
3093 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3094 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3096 my $parent = $co{'parent'};
3097 if (!defined $parent) {
3100 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $parent, $hash
3101 or die_error
(undef, "Open git-diff-tree failed");
3102 my @difftree = map { chomp; $_ } <$fd>;
3103 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3105 # non-textual hash id's can be cached
3107 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3110 my $refs = git_get_references
();
3111 my $ref = format_ref_marker
($refs, $co{'id'});
3113 my $have_snapshot = gitweb_have_snapshot
();
3116 if (defined $file_name && defined $co{'parent'}) {
3118 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
3121 git_header_html
(undef, $expires);
3122 git_print_page_nav
('commit', '',
3123 $hash, $co{'tree'}, $hash,
3124 join (' | ', @views_nav));
3126 if (defined $co{'parent'}) {
3127 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3129 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3131 print "<div class=\"title_text\">\n" .
3132 "<table cellspacing=\"0\">\n";
3133 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3135 "<td></td><td> $ad{'rfc2822'}";
3136 if ($ad{'hour_local'} < 6) {
3137 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3138 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3140 printf(" (%02d:%02d %s)",
3141 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3145 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3146 print "<tr><td></td><td> $cd{'rfc2822'}" .
3147 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3149 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3152 "<td class=\"sha1\">" .
3153 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3154 class => "list"}, $co{'tree'}) .
3156 "<td class=\"link\">" .
3157 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3159 if ($have_snapshot) {
3161 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3165 my $parents = $co{'parents'};
3166 foreach my $par (@
$parents) {
3169 "<td class=\"sha1\">" .
3170 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3171 class => "list"}, $par) .
3173 "<td class=\"link\">" .
3174 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3176 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3183 print "<div class=\"page_body\">\n";
3184 git_print_log
($co{'comment'});
3187 git_difftree_body
(\
@difftree, $hash, $parent);
3193 my $format = shift || 'html';
3200 # preparing $fd and %diffinfo for git_patchset_body
3202 if (defined $hash_base && defined $hash_parent_base) {
3203 if (defined $file_name) {
3205 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
3207 or die_error
(undef, "Open git-diff-tree failed");
3208 @difftree = map { chomp; $_ } <$fd>;
3210 or die_error
(undef, "Reading git-diff-tree failed");
3212 or die_error
('404 Not Found', "Blob diff not found");
3214 } elsif (defined $hash &&
3215 $hash =~ /[0-9a-fA-F]{40}/) {
3216 # try to find filename from $hash
3218 # read filtered raw output
3219 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
3220 or die_error
(undef, "Open git-diff-tree failed");
3222 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3224 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3225 map { chomp; $_ } <$fd>;
3227 or die_error
(undef, "Reading git-diff-tree failed");
3229 or die_error
('404 Not Found', "Blob diff not found");
3232 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3235 if (@difftree > 1) {
3236 die_error
('404 Not Found', "Ambiguous blob diff specification");
3239 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3240 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3241 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3243 $hash_parent ||= $diffinfo{'from_id'};
3244 $hash ||= $diffinfo{'to_id'};
3246 # non-textual hash id's can be cached
3247 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3248 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3253 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3254 '-p', $hash_parent_base, $hash_base,
3256 or die_error
(undef, "Open git-diff-tree failed");
3259 # old/legacy style URI
3260 if (!%diffinfo && # if new style URI failed
3261 defined $hash && defined $hash_parent) {
3262 # fake git-diff-tree raw output
3263 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3264 $diffinfo{'from_id'} = $hash_parent;
3265 $diffinfo{'to_id'} = $hash;
3266 if (defined $file_name) {
3267 if (defined $file_parent) {
3268 $diffinfo{'status'} = '2';
3269 $diffinfo{'from_file'} = $file_parent;
3270 $diffinfo{'to_file'} = $file_name;
3271 } else { # assume not renamed
3272 $diffinfo{'status'} = '1';
3273 $diffinfo{'from_file'} = $file_name;
3274 $diffinfo{'to_file'} = $file_name;
3276 } else { # no filename given
3277 $diffinfo{'status'} = '2';
3278 $diffinfo{'from_file'} = $hash_parent;
3279 $diffinfo{'to_file'} = $hash;
3282 # non-textual hash id's can be cached
3283 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3284 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3289 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts, $hash_parent, $hash
3290 or die_error
(undef, "Open git-diff failed");
3292 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3297 if ($format eq 'html') {
3299 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3300 hash
=>$hash, hash_parent
=>$hash_parent,
3301 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3302 file_name
=>$file_name, file_parent
=>$file_parent)},
3304 git_header_html
(undef, $expires);
3305 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3306 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3307 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3309 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3310 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3312 if (defined $file_name) {
3313 git_print_page_path
($file_name, "blob", $hash_base);
3315 print "<div class=\"page_path\"></div>\n";
3318 } elsif ($format eq 'plain') {
3320 -type
=> 'text/plain',
3321 -charset
=> 'utf-8',
3322 -expires
=> $expires,
3323 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3325 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3328 die_error
(undef, "Unknown blobdiff format");
3332 if ($format eq 'html') {
3333 print "<div class=\"page_body\">\n";
3335 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3338 print "</div>\n"; # class="page_body"
3342 while (my $line = <$fd>) {
3343 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_html($diffinfo{'from_file'})!eg;
3344 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_html($diffinfo{'to_file'})!eg;
3348 last if $line =~ m!^\+\+\+!;
3356 sub git_blobdiff_plain
{
3357 git_blobdiff
('plain');
3360 sub git_commitdiff
{
3361 my $format = shift || 'html';
3362 my %co = parse_commit
($hash);
3364 die_error
(undef, "Unknown commit object");
3366 if (!defined $hash_parent) {
3367 $hash_parent = $co{'parent'} || '--root';
3373 if ($format eq 'html') {
3374 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3375 "--patch-with-raw", "--full-index", $hash_parent, $hash
3376 or die_error
(undef, "Open git-diff-tree failed");
3378 while (chomp(my $line = <$fd>)) {
3379 # empty line ends raw part of diff-tree output
3381 push @difftree, $line;
3384 } elsif ($format eq 'plain') {
3385 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3386 '-p', $hash_parent, $hash
3387 or die_error
(undef, "Open git-diff-tree failed");
3390 die_error
(undef, "Unknown commitdiff format");
3393 # non-textual hash id's can be cached
3395 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3399 # write commit message
3400 if ($format eq 'html') {
3401 my $refs = git_get_references
();
3402 my $ref = format_ref_marker
($refs, $co{'id'});
3404 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3405 hash
=>$hash, hash_parent
=>$hash_parent)},
3408 git_header_html
(undef, $expires);
3409 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3410 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3411 git_print_authorship
(\
%co);
3412 print "<div class=\"page_body\">\n";
3413 print "<div class=\"log\">\n";
3414 git_print_simplified_log
($co{'comment'}, 1); # skip title
3415 print "</div>\n"; # class="log"
3417 } elsif ($format eq 'plain') {
3418 my $refs = git_get_references
("tags");
3419 my $tagname = git_get_rev_name_tags
($hash);
3420 my $filename = basename
($project) . "-$hash.patch";
3423 -type
=> 'text/plain',
3424 -charset
=> 'utf-8',
3425 -expires
=> $expires,
3426 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3427 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3430 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3431 Subject: $co{'title'}
3433 print "X-Git-Tag: $tagname\n" if $tagname;
3434 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3436 foreach my $line (@
{$co{'comment'}}) {
3443 if ($format eq 'html') {
3444 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3447 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3449 print "</div>\n"; # class="page_body"
3452 } elsif ($format eq 'plain') {
3456 or print "Reading git-diff-tree failed\n";
3460 sub git_commitdiff_plain
{
3461 git_commitdiff
('plain');
3465 if (!defined $hash_base) {
3466 $hash_base = git_get_head_hash
($project);
3468 if (!defined $page) {
3472 my %co = parse_commit
($hash_base);
3474 die_error
(undef, "Unknown commit object");
3477 my $refs = git_get_references
();
3478 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3480 if (!defined $hash && defined $file_name) {
3481 $hash = git_get_hash_by_path
($hash_base, $file_name);
3483 if (defined $hash) {
3484 $ftype = git_get_type
($hash);
3488 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3489 or die_error
(undef, "Open git-rev-list-failed");
3490 my @revlist = map { chomp; $_ } <$fd>;
3492 or die_error
(undef, "Reading git-rev-list failed");
3494 my $paging_nav = '';
3497 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3498 file_name
=>$file_name)},
3500 $paging_nav .= " ⋅ " .
3501 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3502 file_name
=>$file_name, page
=>$page-1),
3503 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3505 $paging_nav .= "first";
3506 $paging_nav .= " ⋅ prev";
3508 if ($#revlist >= (100 * ($page+1)-1)) {
3509 $paging_nav .= " ⋅ " .
3510 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3511 file_name
=>$file_name, page
=>$page+1),
3512 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3514 $paging_nav .= " ⋅ next";
3517 if ($#revlist >= (100 * ($page+1)-1)) {
3519 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3520 file_name
=>$file_name, page
=>$page+1),
3521 -title
=> "Alt-n"}, "next");
3525 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3526 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3527 git_print_page_path
($file_name, $ftype, $hash_base);
3529 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3530 $refs, $hash_base, $ftype, $next_link);
3536 if (!defined $searchtext) {
3537 die_error
(undef, "Text field empty");
3539 if (!defined $hash) {
3540 $hash = git_get_head_hash
($project);
3542 my %co = parse_commit
($hash);
3544 die_error
(undef, "Unknown commit object");
3547 my $commit_search = 1;
3548 my $author_search = 0;
3549 my $committer_search = 0;
3550 my $pickaxe_search = 0;
3551 if ($searchtext =~ s/^author\\://i) {
3553 } elsif ($searchtext =~ s/^committer\\://i) {
3554 $committer_search = 1;
3555 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3557 $pickaxe_search = 1;
3559 # pickaxe may take all resources of your box and run for several minutes
3560 # with every query - so decide by yourself how public you make this feature
3561 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3562 if (!$have_pickaxe) {
3563 die_error
('403 Permission denied', "Permission denied");
3567 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3568 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3570 print "<table cellspacing=\"0\">\n";
3572 if ($commit_search) {
3574 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", $hash or next;
3575 while (my $commit_text = <$fd>) {
3576 if (!grep m/$searchtext/i, $commit_text) {
3579 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3582 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3585 my @commit_lines = split "\n", $commit_text;
3586 my %co = parse_commit
(undef, \
@commit_lines);
3591 print "<tr class=\"dark\">\n";
3593 print "<tr class=\"light\">\n";
3596 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3597 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3599 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3600 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3601 my $comment = $co{'comment'};
3602 foreach my $line (@
$comment) {
3603 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3604 my $lead = esc_html
($1) || "";
3605 $lead = chop_str
($lead, 30, 10);
3606 my $match = esc_html
($2) || "";
3607 my $trail = esc_html
($3) || "";
3608 $trail = chop_str
($trail, 30, 10);
3609 my $text = "$lead<span class=\"match\">$match</span>$trail";
3610 print chop_str
($text, 80, 5) . "<br/>\n";
3614 "<td class=\"link\">" .
3615 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3617 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3624 if ($pickaxe_search) {
3626 my $git_command = git_cmd_str
();
3627 open my $fd, "-|", "$git_command rev-list $hash | " .
3628 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3631 while (my $line = <$fd>) {
3632 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3635 $set{'from_id'} = $3;
3637 $set{'id'} = $set{'to_id'};
3638 if ($set{'id'} =~ m/0{40}/) {
3639 $set{'id'} = $set{'from_id'};
3641 if ($set{'id'} =~ m/0{40}/) {
3645 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3648 print "<tr class=\"dark\">\n";
3650 print "<tr class=\"light\">\n";
3653 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3654 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3656 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3657 -class => "list subject"},
3658 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3659 while (my $setref = shift @files) {
3661 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3662 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3664 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3668 "<td class=\"link\">" .
3669 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3671 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3675 %co = parse_commit
($1);
3685 my $head = git_get_head_hash
($project);
3686 if (!defined $hash) {
3689 if (!defined $page) {
3692 my $refs = git_get_references
();
3694 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3695 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3696 or die_error
(undef, "Open git-rev-list failed");
3697 my @revlist = map { chomp; $_ } <$fd>;
3700 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3702 if ($#revlist >= (100 * ($page+1)-1)) {
3704 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3705 -title
=> "Alt-n"}, "next");
3710 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3711 git_print_header_div
('summary', $project);
3713 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3718 ## ......................................................................
3719 ## feeds (RSS, OPML)
3722 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3723 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150", git_get_head_hash
($project)
3724 or die_error
(undef, "Open git-rev-list failed");
3725 my @revlist = map { chomp; $_ } <$fd>;
3726 close $fd or die_error
(undef, "Reading git-rev-list failed");
3727 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3729 <?xml version="1.0" encoding="utf-8"?>
3730 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3732 <title>$project $my_uri $my_url</title>
3733 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3734 <description>$project log</description>
3735 <language>en</language>
3738 for (my $i = 0; $i <= $#revlist; $i++) {
3739 my $commit = $revlist[$i];
3740 my %co = parse_commit
($commit);
3741 # we read 150, we always show 30 and the ones more recent than 48 hours
3742 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3745 my %cd = parse_date
($co{'committer_epoch'});
3746 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3747 $co{'parent'}, $co{'id'}
3749 my @difftree = map { chomp; $_ } <$fd>;
3754 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3756 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3757 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3758 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3759 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3760 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3761 "<content:encoded>" .
3763 my $comment = $co{'comment'};
3764 foreach my $line (@
$comment) {
3765 $line = to_utf8
($line);
3766 print "$line<br/>\n";
3769 foreach my $line (@difftree) {
3770 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3773 my $file = esc_html
(unquote
($7));
3774 $file = to_utf8
($file);
3775 print "$file<br/>\n";
3778 "</content:encoded>\n" .
3781 print "</channel></rss>";
3785 my @list = git_get_projects_list
();
3787 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3789 <?xml version="1.0" encoding="utf-8"?>
3790 <opml version="1.0">
3792 <title>$site_name Git OPML Export</title>
3795 <outline text="git RSS feeds">
3798 foreach my $pr (@list) {
3800 my $head = git_get_head_hash
($proj{'path'});
3801 if (!defined $head) {
3804 $git_dir = "$projectroot/$proj{'path'}";
3805 my %co = parse_commit
($head);
3810 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3811 my $rss = "$my_url?p=$proj{'path'};a=rss";
3812 my $html = "$my_url?p=$proj{'path'};a=summary";
3813 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";