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 GIT logo (72x27 size)
58 our $logo = "++GITWEB_LOGO++";
59 # URI of GIT favicon, assumed to be image/png type
60 our $favicon = "++GITWEB_FAVICON++";
62 # URI and label (title) of GIT logo link
63 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
64 #our $logo_label = "git documentation";
65 our $logo_url = "http://git.or.cz/";
66 our $logo_label = "git homepage";
68 # source of projects list
69 our $projects_list = "++GITWEB_LIST++";
71 # show repository only if this file exists
72 # (only effective if this variable evaluates to true)
73 our $export_ok = "++GITWEB_EXPORT_OK++";
75 # only allow viewing of repositories also shown on the overview page
76 our $strict_export = "++GITWEB_STRICT_EXPORT++";
78 # list of git base URLs used for URL to where fetch project from,
79 # i.e. full URL is "$git_base_url/$project"
80 our @git_base_url_list = ("++GITWEB_BASE_URL++");
82 # default blob_plain mimetype and default charset for text/plain blob
83 our $default_blob_plain_mimetype = 'text/plain';
84 our $default_text_plain_charset = undef;
86 # file to use for guessing MIME types before trying /etc/mime.types
87 # (relative to the current git repository)
88 our $mimetypes_file = undef;
90 # You define site-wide feature defaults here; override them with
91 # $GITWEB_CONFIG as necessary.
94 # 'sub' => feature-sub (subroutine),
95 # 'override' => allow-override (boolean),
96 # 'default' => [ default options...] (array reference)}
98 # if feature is overridable (it means that allow-override has true value,
99 # then feature-sub will be called with default options as parameters;
100 # return value of feature-sub indicates if to enable specified feature
102 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
104 # Enable the 'blame' blob view, showing the last commit that modified
105 # each line in the file. This can be very CPU-intensive.
107 # To enable system wide have in $GITWEB_CONFIG
108 # $feature{'blame'}{'default'} = [1];
109 # To have project specific config enable override in $GITWEB_CONFIG
110 # $feature{'blame'}{'override'} = 1;
111 # and in project config gitweb.blame = 0|1;
113 'sub' => \
&feature_blame
,
117 # Enable the 'snapshot' link, providing a compressed tarball of any
118 # tree. This can potentially generate high traffic if you have large
121 # To disable system wide have in $GITWEB_CONFIG
122 # $feature{'snapshot'}{'default'} = [undef];
123 # To have project specific config enable override in $GITWEB_CONFIG
124 # $feature{'blame'}{'override'} = 1;
125 # and in project config gitweb.snapshot = none|gzip|bzip2;
127 'sub' => \
&feature_snapshot
,
129 # => [content-encoding, suffix, program]
130 'default' => ['x-gzip', 'gz', 'gzip']},
132 # Enable the pickaxe search, which will list the commits that modified
133 # a given string in a file. This can be practical and quite faster
134 # alternative to 'blame', but still potentially CPU-intensive.
136 # To enable system wide have in $GITWEB_CONFIG
137 # $feature{'pickaxe'}{'default'} = [1];
138 # To have project specific config enable override in $GITWEB_CONFIG
139 # $feature{'pickaxe'}{'override'} = 1;
140 # and in project config gitweb.pickaxe = 0|1;
142 'sub' => \
&feature_pickaxe
,
146 # Make gitweb use an alternative format of the URLs which can be
147 # more readable and natural-looking: project name is embedded
148 # directly in the path and the query string contains other
149 # auxiliary information. All gitweb installations recognize
150 # URL in either format; this configures in which formats gitweb
153 # To enable system wide have in $GITWEB_CONFIG
154 # $feature{'pathinfo'}{'default'} = [1];
155 # Project specific override is not supported.
157 # Note that you will need to change the default location of CSS,
158 # favicon, logo and possibly other files to an absolute URL. Also,
159 # if gitweb.cgi serves as your indexfile, you will need to force
160 # $my_uri to contain the script name in your $GITWEB_CONFIG.
166 sub gitweb_check_feature
{
168 return unless exists $feature{$name};
169 my ($sub, $override, @defaults) = (
170 $feature{$name}{'sub'},
171 $feature{$name}{'override'},
172 @{$feature{$name}{'default'}});
173 if (!$override) { return @defaults; }
175 warn "feature $name is not overrideable";
178 return $sub->(@defaults);
182 my ($val) = git_get_project_config
('blame', '--bool');
184 if ($val eq 'true') {
186 } elsif ($val eq 'false') {
193 sub feature_snapshot
{
194 my ($ctype, $suffix, $command) = @_;
196 my ($val) = git_get_project_config
('snapshot');
198 if ($val eq 'gzip') {
199 return ('x-gzip', 'gz', 'gzip');
200 } elsif ($val eq 'bzip2') {
201 return ('x-bzip2', 'bz2', 'bzip2');
202 } elsif ($val eq 'none') {
206 return ($ctype, $suffix, $command);
209 sub gitweb_have_snapshot
{
210 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
211 my $have_snapshot = (defined $ctype && defined $suffix);
213 return $have_snapshot;
216 sub feature_pickaxe
{
217 my ($val) = git_get_project_config
('pickaxe', '--bool');
219 if ($val eq 'true') {
221 } elsif ($val eq 'false') {
228 # checking HEAD file with -e is fragile if the repository was
229 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
231 sub check_head_link
{
233 my $headfile = "$dir/HEAD";
234 return ((-e
$headfile) ||
235 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
238 sub check_export_ok
{
240 return (check_head_link
($dir) &&
241 (!$export_ok || -e
"$dir/$export_ok"));
244 # rename detection options for git-diff and git-diff-tree
245 # - default is '-M', with the cost proportional to
246 # (number of removed files) * (number of new files).
247 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
248 # (number of changed files + number of removed files) * (number of new files)
249 # - even more costly is '-C', '--find-copies-harder' with cost
250 # (number of files in the original tree) * (number of new files)
251 # - one might want to include '-B' option, e.g. '-B', '-M'
252 our @diff_opts = ('-M'); # taken from git_commit
254 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
255 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
257 # version of the core git binary
258 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
260 $projects_list ||= $projectroot;
262 # ======================================================================
263 # input validation and dispatch
264 our $action = $cgi->param('a');
265 if (defined $action) {
266 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
267 die_error
(undef, "Invalid action parameter");
271 # parameters which are pathnames
272 our $project = $cgi->param('p');
273 if (defined $project) {
274 if (!validate_pathname
($project) ||
275 !(-d
"$projectroot/$project") ||
276 !check_head_link
("$projectroot/$project") ||
277 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
278 ($strict_export && !project_in_list
($project))) {
280 die_error
(undef, "No such project");
284 our $file_name = $cgi->param('f');
285 if (defined $file_name) {
286 if (!validate_pathname
($file_name)) {
287 die_error
(undef, "Invalid file parameter");
291 our $file_parent = $cgi->param('fp');
292 if (defined $file_parent) {
293 if (!validate_pathname
($file_parent)) {
294 die_error
(undef, "Invalid file parent parameter");
298 # parameters which are refnames
299 our $hash = $cgi->param('h');
301 if (!validate_refname
($hash)) {
302 die_error
(undef, "Invalid hash parameter");
306 our $hash_parent = $cgi->param('hp');
307 if (defined $hash_parent) {
308 if (!validate_refname
($hash_parent)) {
309 die_error
(undef, "Invalid hash parent parameter");
313 our $hash_base = $cgi->param('hb');
314 if (defined $hash_base) {
315 if (!validate_refname
($hash_base)) {
316 die_error
(undef, "Invalid hash base parameter");
320 our $hash_parent_base = $cgi->param('hpb');
321 if (defined $hash_parent_base) {
322 if (!validate_refname
($hash_parent_base)) {
323 die_error
(undef, "Invalid hash parent base parameter");
328 our $page = $cgi->param('pg');
330 if ($page =~ m/[^0-9]/) {
331 die_error
(undef, "Invalid page parameter");
335 our $searchtext = $cgi->param('s');
336 if (defined $searchtext) {
337 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
338 die_error
(undef, "Invalid search parameter");
340 $searchtext = quotemeta $searchtext;
343 # now read PATH_INFO and use it as alternative to parameters
344 sub evaluate_path_info
{
345 return if defined $project;
346 my $path_info = $ENV{"PATH_INFO"};
347 return if !$path_info;
348 $path_info =~ s
,^/+,,;
349 return if !$path_info;
350 # find which part of PATH_INFO is project
351 $project = $path_info;
353 while ($project && !check_head_link
("$projectroot/$project")) {
354 $project =~ s
,/*[^/]*$,,;
357 $project = validate_pathname
($project);
359 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
360 ($strict_export && !project_in_list
($project))) {
364 # do not change any parameters if an action is given using the query string
366 $path_info =~ s
,^$project/*,,;
367 my ($refname, $pathname) = split(/:/, $path_info, 2);
368 if (defined $pathname) {
369 # we got "project.git/branch:filename" or "project.git/branch:dir/"
370 # we could use git_get_type(branch:pathname), but it needs $git_dir
371 $pathname =~ s
,^/+,,;
372 if (!$pathname || substr($pathname, -1) eq "/") {
376 $action ||= "blob_plain";
378 $hash_base ||= validate_refname
($refname);
379 $file_name ||= validate_pathname
($pathname);
380 } elsif (defined $refname) {
381 # we got "project.git/branch"
382 $action ||= "shortlog";
383 $hash ||= validate_refname
($refname);
386 evaluate_path_info
();
388 # path to the current git repository
390 $git_dir = "$projectroot/$project" if $project;
394 "blame" => \
&git_blame2
,
395 "blobdiff" => \
&git_blobdiff
,
396 "blobdiff_plain" => \
&git_blobdiff_plain
,
397 "blob" => \
&git_blob
,
398 "blob_plain" => \
&git_blob_plain
,
399 "commitdiff" => \
&git_commitdiff
,
400 "commitdiff_plain" => \
&git_commitdiff_plain
,
401 "commit" => \
&git_commit
,
402 "heads" => \
&git_heads
,
403 "history" => \
&git_history
,
406 "search" => \
&git_search
,
407 "shortlog" => \
&git_shortlog
,
408 "summary" => \
&git_summary
,
410 "tags" => \
&git_tags
,
411 "tree" => \
&git_tree
,
412 "snapshot" => \
&git_snapshot
,
413 # those below don't need $project
414 "opml" => \
&git_opml
,
415 "project_list" => \
&git_project_list
,
416 "project_index" => \
&git_project_index
,
419 if (defined $project) {
420 $action ||= 'summary';
422 $action ||= 'project_list';
424 if (!defined($actions{$action})) {
425 die_error
(undef, "Unknown action");
427 if ($action !~ m/^(opml|project_list|project_index)$/ &&
429 die_error
(undef, "Project needed");
431 $actions{$action}->();
434 ## ======================================================================
441 # XXX: Warning: If you touch this, check the search form for updating,
452 hash_parent_base
=> "hpb",
457 my %mapping = @mapping;
459 $params{'project'} = $project unless exists $params{'project'};
461 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
463 # use PATH_INFO for project name
464 $href .= "/$params{'project'}" if defined $params{'project'};
465 delete $params{'project'};
467 # Summary just uses the project path URL
468 if (defined $params{'action'} && $params{'action'} eq 'summary') {
469 delete $params{'action'};
473 # now encode the parameters explicitly
475 for (my $i = 0; $i < @mapping; $i += 2) {
476 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
477 if (defined $params{$name}) {
478 push @result, $symbol . "=" . esc_param
($params{$name});
481 $href .= "?" . join(';', @result) if scalar @result;
487 ## ======================================================================
488 ## validation, quoting/unquoting and escaping
490 sub validate_pathname
{
491 my $input = shift || return undef;
493 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
494 # at the beginning, at the end, and between slashes.
495 # also this catches doubled slashes
496 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
500 if ($input =~ m!\0!) {
506 sub validate_refname
{
507 my $input = shift || return undef;
509 # textual hashes are O.K.
510 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
513 # it must be correct pathname
514 $input = validate_pathname
($input)
516 # restrictions on ref name according to git-check-ref-format
517 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
523 # very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT);
526 return decode
("utf8", $str, Encode
::FB_DEFAULT
);
529 # quote unsafe chars, but keep the slash, even when it's not
530 # correct, but quoted slashes look too horrible in bookmarks
533 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
539 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
542 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
548 # replace invalid utf8 character with SUBSTITUTION sequence
551 $str = to_utf8
($str);
552 $str = escapeHTML
($str);
553 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
554 $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1)
558 # git may return quoted and escaped filenames
561 if ($str =~ m/^"(.*)"$/) {
563 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
568 # escape tabs (convert tabs to spaces)
572 while ((my $pos = index($line, "\t")) != -1) {
573 if (my $count = (8 - ($pos % 8))) {
574 my $spaces = ' ' x
$count;
575 $line =~ s/\t/$spaces/;
582 sub project_in_list
{
584 my @list = git_get_projects_list
();
585 return @list && scalar(grep { $_->{'path'} eq $project } @list);
588 ## ----------------------------------------------------------------------
589 ## HTML aware string manipulation
594 my $add_len = shift || 10;
596 # allow only $len chars, but don't cut a word if it would fit in $add_len
597 # if it doesn't fit, cut it if it's still longer than the dots we would add
598 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
601 if (length($tail) > 4) {
603 $body =~ s/&[^;]*$//; # remove chopped character entities
608 ## ----------------------------------------------------------------------
609 ## functions returning short strings
611 # CSS class for given age value (in seconds)
615 if ($age < 60*60*2) {
617 } elsif ($age < 60*60*24*2) {
624 # convert age in seconds to "nn units ago" string
629 if ($age > 60*60*24*365*2) {
630 $age_str = (int $age/60/60/24/365);
631 $age_str .= " years ago";
632 } elsif ($age > 60*60*24*(365/12)*2) {
633 $age_str = int $age/60/60/24/(365/12);
634 $age_str .= " months ago";
635 } elsif ($age > 60*60*24*7*2) {
636 $age_str = int $age/60/60/24/7;
637 $age_str .= " weeks ago";
638 } elsif ($age > 60*60*24*2) {
639 $age_str = int $age/60/60/24;
640 $age_str .= " days ago";
641 } elsif ($age > 60*60*2) {
642 $age_str = int $age/60/60;
643 $age_str .= " hours ago";
644 } elsif ($age > 60*2) {
645 $age_str = int $age/60;
646 $age_str .= " min ago";
649 $age_str .= " sec ago";
651 $age_str .= " right now";
656 # convert file mode in octal to symbolic file mode string
658 my $mode = oct shift;
660 if (S_ISDIR
($mode & S_IFMT
)) {
662 } elsif (S_ISLNK
($mode)) {
664 } elsif (S_ISREG
($mode)) {
665 # git cares only about the executable bit
666 if ($mode & S_IXUSR
) {
676 # convert file mode in octal to file type string
680 if ($mode !~ m/^[0-7]+$/) {
686 if (S_ISDIR
($mode & S_IFMT
)) {
688 } elsif (S_ISLNK
($mode)) {
690 } elsif (S_ISREG
($mode)) {
697 ## ----------------------------------------------------------------------
698 ## functions returning short HTML fragments, or transforming HTML fragments
699 ## which don't beling to other sections
701 # format line of commit message or tag comment
702 sub format_log_line_html
{
705 $line = esc_html
($line);
706 $line =~ s/ / /g;
707 if ($line =~ m/([0-9a-fA-F]{40})/) {
709 if (git_get_type
($hash_text) eq "commit") {
711 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
712 -class => "text"}, $hash_text);
713 $line =~ s/$hash_text/$link/;
719 # format marker of refs pointing to given object
720 sub format_ref_marker
{
721 my ($refs, $id) = @_;
724 if (defined $refs->{$id}) {
725 foreach my $ref (@{$refs->{$id}}) {
726 my ($type, $name) = qw();
727 # e.g. tags/v2.6.11 or heads/next
728 if ($ref =~ m!^(.*?)s?/(.*)$!) {
736 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
741 return ' <span class="refs">'. $markers . '</span>';
747 # format, perhaps shortened and with markers, title line
748 sub format_subject_html
{
749 my ($long, $short, $href, $extra) = @_;
750 $extra = '' unless defined($extra);
752 if (length($short) < length($long)) {
753 return $cgi->a({-href
=> $href, -class => "list subject",
754 -title
=> to_utf8
($long)},
755 esc_html
($short) . $extra);
757 return $cgi->a({-href
=> $href, -class => "list subject"},
758 esc_html
($long) . $extra);
762 sub format_diff_line
{
764 my $char = substr($line, 0, 1);
770 $diff_class = " add";
771 } elsif ($char eq "-") {
772 $diff_class = " rem";
773 } elsif ($char eq "@") {
774 $diff_class = " chunk_header";
775 } elsif ($char eq "\\") {
776 $diff_class = " incomplete";
778 $line = untabify
($line);
779 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
782 ## ----------------------------------------------------------------------
783 ## git utility subroutines, invoking git commands
785 # returns path to the core git executable and the --git-dir parameter as list
787 return $GIT, '--git-dir='.$git_dir;
790 # returns path to the core git executable and the --git-dir parameter as string
792 return join(' ', git_cmd
());
795 # get HEAD ref of given project as hash
796 sub git_get_head_hash
{
798 my $o_git_dir = $git_dir;
800 $git_dir = "$projectroot/$project";
801 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
804 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
808 if (defined $o_git_dir) {
809 $git_dir = $o_git_dir;
814 # get type of given object
818 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
825 sub git_get_project_config
{
826 my ($key, $type) = @_;
828 return unless ($key);
829 $key =~ s/^gitweb\.//;
830 return if ($key =~ m/\W/);
832 my @x = (git_cmd
(), 'repo-config');
833 if (defined $type) { push @x, $type; }
835 push @x, "gitweb.$key";
841 # get hash of given path at given ref
842 sub git_get_hash_by_path
{
844 my $path = shift || return undef;
849 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
850 or die_error
(undef, "Open git-ls-tree failed");
852 close $fd or return undef;
854 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
855 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
856 if (defined $type && $type ne $2) {
863 ## ......................................................................
864 ## git utility functions, directly accessing git repository
866 sub git_get_project_description
{
869 open my $fd, "$projectroot/$path/description" or return undef;
876 sub git_get_project_url_list
{
879 open my $fd, "$projectroot/$path/cloneurl" or return;
880 my @git_project_url_list = map { chomp; $_ } <$fd>;
883 return wantarray ? @git_project_url_list : \
@git_project_url_list;
886 sub git_get_projects_list
{
889 if (-d
$projects_list) {
890 # search in directory
891 my $dir = $projects_list;
892 my $pfxlen = length("$dir");
895 follow_fast
=> 1, # follow symbolic links
896 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
898 # skip project-list toplevel, if we get it.
899 return if (m!^[/.]$!);
900 # only directories can be git repositories
901 return unless (-d
$_);
903 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
904 # we check related file in $projectroot
905 if (check_export_ok
("$projectroot/$subdir")) {
906 push @list, { path
=> $subdir };
907 $File::Find
::prune
= 1;
912 } elsif (-f
$projects_list) {
913 # read from file(url-encoded):
914 # 'git%2Fgit.git Linus+Torvalds'
915 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
916 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
917 open my ($fd), $projects_list or return;
918 while (my $line = <$fd>) {
920 my ($path, $owner) = split ' ', $line;
921 $path = unescape
($path);
922 $owner = unescape
($owner);
923 if (!defined $path) {
926 if (check_export_ok
("$projectroot/$path")) {
929 owner
=> to_utf8
($owner),
936 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
940 sub git_get_project_owner
{
944 return undef unless $project;
946 # read from file (url-encoded):
947 # 'git%2Fgit.git Linus+Torvalds'
948 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
949 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
950 if (-f
$projects_list) {
951 open (my $fd , $projects_list);
952 while (my $line = <$fd>) {
954 my ($pr, $ow) = split ' ', $line;
957 if ($pr eq $project) {
958 $owner = to_utf8
($ow);
964 if (!defined $owner) {
965 $owner = get_file_owner
("$projectroot/$project");
971 sub git_get_references
{
972 my $type = shift || "";
974 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
975 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
976 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
979 while (my $line = <$fd>) {
981 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
982 if (defined $refs{$1}) {
983 push @{$refs{$1}}, $2;
993 sub git_get_rev_name_tags
{
994 my $hash = shift || return undef;
996 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
998 my $name_rev = <$fd>;
1001 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1004 # catches also '$hash undefined' output
1009 ## ----------------------------------------------------------------------
1010 ## parse to hash functions
1014 my $tz = shift || "-0000";
1017 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1018 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1019 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1020 $date{'hour'} = $hour;
1021 $date{'minute'} = $min;
1022 $date{'mday'} = $mday;
1023 $date{'day'} = $days[$wday];
1024 $date{'month'} = $months[$mon];
1025 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1026 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1027 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1028 $mday, $months[$mon], $hour ,$min;
1030 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1031 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1032 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1033 $date{'hour_local'} = $hour;
1034 $date{'minute_local'} = $min;
1035 $date{'tz_local'} = $tz;
1036 $date{'iso-tz'} = sprintf ("%04d-%02d-%02d %02d:%02d:%02d %s",
1037 1900+$year, $mon+1, $mday,
1038 $hour, $min, $sec, $tz);
1047 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1048 $tag{'id'} = $tag_id;
1049 while (my $line = <$fd>) {
1051 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1052 $tag{'object'} = $1;
1053 } elsif ($line =~ m/^type (.+)$/) {
1055 } elsif ($line =~ m/^tag (.+)$/) {
1057 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1058 $tag{'author'} = $1;
1061 } elsif ($line =~ m/--BEGIN/) {
1062 push @comment, $line;
1064 } elsif ($line eq "") {
1068 push @comment, <$fd>;
1069 $tag{'comment'} = \
@comment;
1070 close $fd or return;
1071 if (!defined $tag{'name'}) {
1077 sub git_get_last_activity
{
1081 $git_dir = "$projectroot/$path";
1082 open($fd, "-|", git_cmd
(), 'for-each-ref',
1083 '--format=%(refname) %(committer)',
1084 '--sort=-committerdate',
1085 'refs/heads') or return;
1086 my $most_recent = <$fd>;
1087 close $fd or return;
1088 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1090 my $age = time - $timestamp;
1091 return ($age, age_string
($age));
1096 my $commit_id = shift;
1097 my $commit_text = shift;
1102 if (defined $commit_text) {
1103 @commit_lines = @$commit_text;
1106 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
1108 @commit_lines = split '\n', <$fd>;
1109 close $fd or return;
1112 my $header = shift @commit_lines;
1113 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1116 ($co{'id'}, my @parents) = split ' ', $header;
1117 $co{'parents'} = \
@parents;
1118 $co{'parent'} = $parents[0];
1119 while (my $line = shift @commit_lines) {
1120 last if $line eq "\n";
1121 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1123 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1125 $co{'author_epoch'} = $2;
1126 $co{'author_tz'} = $3;
1127 if ($co{'author'} =~ m/^([^<]+) </) {
1128 $co{'author_name'} = $1;
1130 $co{'author_name'} = $co{'author'};
1132 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1133 $co{'committer'} = $1;
1134 $co{'committer_epoch'} = $2;
1135 $co{'committer_tz'} = $3;
1136 $co{'committer_name'} = $co{'committer'};
1137 $co{'committer_name'} =~ s/ <.*//;
1140 if (!defined $co{'tree'}) {
1144 foreach my $title (@commit_lines) {
1147 $co{'title'} = chop_str
($title, 80, 5);
1148 # remove leading stuff of merges to make the interesting part visible
1149 if (length($title) > 50) {
1150 $title =~ s/^Automatic //;
1151 $title =~ s/^merge (of|with) /Merge ... /i;
1152 if (length($title) > 50) {
1153 $title =~ s/(http|rsync):\/\///;
1155 if (length($title) > 50) {
1156 $title =~ s/(master|www|rsync)\.//;
1158 if (length($title) > 50) {
1159 $title =~ s/kernel.org:?//;
1161 if (length($title) > 50) {
1162 $title =~ s/\/pub\/scm//;
1165 $co{'title_short'} = chop_str
($title, 50, 5);
1169 if ($co{'title'} eq "") {
1170 $co{'title'} = $co{'title_short'} = '(no commit message)';
1172 # remove added spaces
1173 foreach my $line (@commit_lines) {
1176 $co{'comment'} = \
@commit_lines;
1178 my $age = time - $co{'committer_epoch'};
1180 $co{'age_string'} = age_string
($age);
1181 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1182 if ($age > 60*60*24*7*2) {
1183 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1184 $co{'age_string_age'} = $co{'age_string'};
1186 $co{'age_string_date'} = $co{'age_string'};
1187 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1192 # parse ref from ref_file, given by ref_id, with given type
1194 my $ref_file = shift;
1196 my $type = shift || git_get_type
($ref_id);
1199 $ref_item{'type'} = $type;
1200 $ref_item{'id'} = $ref_id;
1201 $ref_item{'epoch'} = 0;
1202 $ref_item{'age'} = "unknown";
1203 if ($type eq "tag") {
1204 my %tag = parse_tag
($ref_id);
1205 $ref_item{'comment'} = $tag{'comment'};
1206 if ($tag{'type'} eq "commit") {
1207 my %co = parse_commit
($tag{'object'});
1208 $ref_item{'epoch'} = $co{'committer_epoch'};
1209 $ref_item{'age'} = $co{'age_string'};
1210 } elsif (defined($tag{'epoch'})) {
1211 my $age = time - $tag{'epoch'};
1212 $ref_item{'epoch'} = $tag{'epoch'};
1213 $ref_item{'age'} = age_string
($age);
1215 $ref_item{'reftype'} = $tag{'type'};
1216 $ref_item{'name'} = $tag{'name'};
1217 $ref_item{'refid'} = $tag{'object'};
1218 } elsif ($type eq "commit"){
1219 my %co = parse_commit
($ref_id);
1220 $ref_item{'reftype'} = "commit";
1221 $ref_item{'name'} = $ref_file;
1222 $ref_item{'title'} = $co{'title'};
1223 $ref_item{'refid'} = $ref_id;
1224 $ref_item{'epoch'} = $co{'committer_epoch'};
1225 $ref_item{'age'} = $co{'age_string'};
1227 $ref_item{'reftype'} = $type;
1228 $ref_item{'name'} = $ref_file;
1229 $ref_item{'refid'} = $ref_id;
1235 # parse line of git-diff-tree "raw" output
1236 sub parse_difftree_raw_line
{
1240 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1241 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1242 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1243 $res{'from_mode'} = $1;
1244 $res{'to_mode'} = $2;
1245 $res{'from_id'} = $3;
1247 $res{'status'} = $5;
1248 $res{'similarity'} = $6;
1249 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1250 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1252 $res{'file'} = unquote
($7);
1255 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1256 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1257 $res{'commit'} = $1;
1260 return wantarray ? %res : \
%res;
1263 # parse line of git-ls-tree output
1264 sub parse_ls_tree_line
($;%) {
1269 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1270 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1278 $res{'name'} = unquote
($4);
1281 return wantarray ? %res : \
%res;
1284 ## ......................................................................
1285 ## parse to array of hashes functions
1287 sub git_get_refs_list
{
1288 my $type = shift || "";
1293 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1295 while (my $line = <$fd>) {
1297 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?([^\^]+))(\^\{\})?$/) {
1298 if (defined $refs{$1}) {
1299 push @{$refs{$1}}, $2;
1304 if (! $4) { # unpeeled, direct reference
1305 push @refs, { hash
=> $1, name
=> $3 }; # without type
1306 } elsif ($3 eq $refs[-1]{'name'}) {
1307 # most likely a tag is followed by its peeled
1308 # (deref) one, and when that happens we know the
1309 # previous one was of type 'tag'.
1310 $refs[-1]{'type'} = "tag";
1316 foreach my $ref (@refs) {
1317 my $ref_file = $ref->{'name'};
1318 my $ref_id = $ref->{'hash'};
1320 my $type = $ref->{'type'} || git_get_type
($ref_id) || next;
1321 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1323 push @reflist, \
%ref_item;
1326 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1327 return (\
@reflist, \
%refs);
1330 ## ----------------------------------------------------------------------
1331 ## filesystem-related functions
1333 sub get_file_owner
{
1336 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1337 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1338 if (!defined $gcos) {
1342 $owner =~ s/[,;].*$//;
1343 return to_utf8
($owner);
1346 ## ......................................................................
1347 ## mimetype related functions
1349 sub mimetype_guess_file
{
1350 my $filename = shift;
1351 my $mimemap = shift;
1352 -r
$mimemap or return undef;
1355 open(MIME
, $mimemap) or return undef;
1357 next if m/^#/; # skip comments
1358 my ($mime, $exts) = split(/\t+/);
1359 if (defined $exts) {
1360 my @exts = split(/\s+/, $exts);
1361 foreach my $ext (@exts) {
1362 $mimemap{$ext} = $mime;
1368 $filename =~ /\.([^.]*)$/;
1369 return $mimemap{$1};
1372 sub mimetype_guess
{
1373 my $filename = shift;
1375 $filename =~ /\./ or return undef;
1377 if ($mimetypes_file) {
1378 my $file = $mimetypes_file;
1379 if ($file !~ m!^/!) { # if it is relative path
1380 # it is relative to project
1381 $file = "$projectroot/$project/$file";
1383 $mime = mimetype_guess_file
($filename, $file);
1385 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1391 my $filename = shift;
1394 my $mime = mimetype_guess
($filename);
1395 $mime and return $mime;
1399 return $default_blob_plain_mimetype unless $fd;
1402 return 'text/plain' .
1403 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1404 } elsif (! $filename) {
1405 return 'application/octet-stream';
1406 } elsif ($filename =~ m/\.png$/i) {
1408 } elsif ($filename =~ m/\.gif$/i) {
1410 } elsif ($filename =~ m/\.jpe?g$/i) {
1411 return 'image/jpeg';
1413 return 'application/octet-stream';
1417 ## ======================================================================
1418 ## functions printing HTML: header, footer, error page
1420 sub git_header_html
{
1421 my $status = shift || "200 OK";
1422 my $expires = shift;
1424 my $title = "$site_name git";
1425 if (defined $project) {
1426 $title .= " - $project";
1427 if (defined $action) {
1428 $title .= "/$action";
1429 if (defined $file_name) {
1430 $title .= " - " . esc_html
($file_name);
1431 if ($action eq "tree" && $file_name !~ m
|/$|) {
1438 # require explicit support from the UA if we are to send the page as
1439 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1440 # we have to do this because MSIE sometimes globs '*/*', pretending to
1441 # support xhtml+xml but choking when it gets what it asked for.
1442 if (defined $cgi->http('HTTP_ACCEPT') &&
1443 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1444 $cgi->Accept('application/xhtml+xml') != 0) {
1445 $content_type = 'application/xhtml+xml';
1447 $content_type = 'text/html';
1449 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1450 -status
=> $status, -expires
=> $expires);
1452 <?xml version="1.0" encoding="utf-8"?>
1453 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1454 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1455 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1456 <!-- git core binaries version $git_version -->
1458 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1459 <meta name="generator" content="gitweb/$version git/$git_version"/>
1460 <meta name="robots" content="index, nofollow"/>
1461 <title>$title</title>
1463 # print out each stylesheet that exist
1464 if (defined $stylesheet) {
1465 #provides backwards capability for those people who define style sheet in a config file
1466 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1468 foreach my $stylesheet (@stylesheets) {
1469 next unless $stylesheet;
1470 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1473 if (defined $project) {
1474 printf('<link rel="alternate" title="%s log" '.
1475 'href="%s" type="application/rss+xml"/>'."\n",
1476 esc_param
($project), href
(action
=>"rss"));
1478 printf('<link rel="alternate" title="%s projects list" '.
1479 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1480 $site_name, href
(project
=>undef, action
=>"project_index"));
1481 printf('<link rel="alternate" title="%s projects logs" '.
1482 'href="%s" type="text/x-opml"/>'."\n",
1483 $site_name, href
(project
=>undef, action
=>"opml"));
1485 if (defined $favicon) {
1486 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1492 if (-f
$site_header) {
1493 open (my $fd, $site_header);
1498 print "<div class=\"page_header\">\n" .
1499 $cgi->a({-href
=> esc_url
($logo_url),
1500 -title
=> $logo_label},
1501 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1502 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1503 if (defined $project) {
1504 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1505 if (defined $action) {
1509 if (!defined $searchtext) {
1513 if (defined $hash_base) {
1514 $search_hash = $hash_base;
1515 } elsif (defined $hash) {
1516 $search_hash = $hash;
1518 $search_hash = "HEAD";
1520 $cgi->param("a", "search");
1521 $cgi->param("h", $search_hash);
1522 $cgi->param("p", $project);
1523 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1524 "<div class=\"search\">\n" .
1525 $cgi->hidden(-name
=> "p") . "\n" .
1526 $cgi->hidden(-name
=> "a") . "\n" .
1527 $cgi->hidden(-name
=> "h") . "\n" .
1528 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1530 $cgi->end_form() . "\n";
1535 sub git_footer_html
{
1536 print "<div class=\"page_footer\">\n";
1537 if (defined $project) {
1538 my $descr = git_get_project_description
($project);
1539 if (defined $descr) {
1540 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1542 print $cgi->a({-href
=> href
(action
=>"rss"),
1543 -class => "rss_logo"}, "RSS") . "\n";
1545 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1546 -class => "rss_logo"}, "OPML") . " ";
1547 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1548 -class => "rss_logo"}, "TXT") . "\n";
1552 if (-f
$site_footer) {
1553 open (my $fd, $site_footer);
1563 my $status = shift || "403 Forbidden";
1564 my $error = shift || "Malformed query, file missing or permission denied";
1566 git_header_html
($status);
1568 <div class="page_body">
1578 ## ----------------------------------------------------------------------
1579 ## functions printing or outputting HTML: navigation
1581 sub git_print_page_nav
{
1582 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1583 $extra = '' if !defined $extra; # pager or formats
1585 my @navs = qw(summary shortlog log commit commitdiff tree);
1587 @navs = grep { $_ ne $suppress } @navs;
1590 my %arg = map { $_ => {action
=>$_} } @navs;
1591 if (defined $head) {
1592 for (qw(commit commitdiff)) {
1593 $arg{$_}{hash
} = $head;
1595 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1596 for (qw(shortlog log)) {
1597 $arg{$_}{hash
} = $head;
1601 $arg{tree
}{hash
} = $treehead if defined $treehead;
1602 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1604 print "<div class=\"page_nav\">\n" .
1606 map { $_ eq $current ?
1607 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1609 print "<br/>\n$extra<br/>\n" .
1613 sub format_paging_nav
{
1614 my ($action, $hash, $head, $page, $nrevs) = @_;
1618 if ($hash ne $head || $page) {
1619 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1621 $paging_nav .= "HEAD";
1625 $paging_nav .= " ⋅ " .
1626 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1627 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1629 $paging_nav .= " ⋅ prev";
1632 if ($nrevs >= (100 * ($page+1)-1)) {
1633 $paging_nav .= " ⋅ " .
1634 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1635 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1637 $paging_nav .= " ⋅ next";
1643 ## ......................................................................
1644 ## functions printing or outputting HTML: div
1646 sub git_print_header_div
{
1647 my ($action, $title, $hash, $hash_base) = @_;
1650 $args{action
} = $action;
1651 $args{hash
} = $hash if $hash;
1652 $args{hash_base
} = $hash_base if $hash_base;
1654 print "<div class=\"header\">\n" .
1655 $cgi->a({-href
=> href
(%args), -class => "title"},
1656 $title ? $title : $action) .
1660 #sub git_print_authorship (\%) {
1661 sub git_print_authorship
{
1664 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1665 print "<div class=\"author_date\">" .
1666 esc_html
($co->{'author_name'}) .
1668 if ($ad{'hour_local'} < 6) {
1669 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1670 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1672 printf(" (%02d:%02d %s)",
1673 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1678 sub git_print_page_path
{
1684 print "<div class=\"page_path\">";
1685 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1686 -title
=> 'tree root'}, "[$project]");
1688 if (defined $name) {
1689 my @dirname = split '/', $name;
1690 my $basename = pop @dirname;
1693 foreach my $dir (@dirname) {
1694 $fullname .= ($fullname ? '/' : '') . $dir;
1695 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1697 -title
=> $fullname}, esc_html
($dir));
1700 if (defined $type && $type eq 'blob') {
1701 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1703 -title
=> $name}, esc_html
($basename));
1704 } elsif (defined $type && $type eq 'tree') {
1705 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1707 -title
=> $name}, esc_html
($basename));
1710 print esc_html
($basename);
1713 print "<br/></div>\n";
1716 # sub git_print_log (\@;%) {
1717 sub git_print_log
($;%) {
1721 if ($opts{'-remove_title'}) {
1722 # remove title, i.e. first line of log
1725 # remove leading empty lines
1726 while (defined $log->[0] && $log->[0] eq "") {
1733 foreach my $line (@$log) {
1734 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1737 if (! $opts{'-remove_signoff'}) {
1738 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1741 # remove signoff lines
1748 # print only one empty line
1749 # do not print empty line after signoff
1751 next if ($empty || $signoff);
1757 print format_log_line_html
($line) . "<br/>\n";
1760 if ($opts{'-final_empty_line'}) {
1761 # end with single empty line
1762 print "<br/>\n" unless $empty;
1766 sub git_print_simplified_log
{
1768 my $remove_title = shift;
1771 -final_empty_line
=> 1,
1772 -remove_title
=> $remove_title);
1775 # print tree entry (row of git_tree), but without encompassing <tr> element
1776 sub git_print_tree_entry
{
1777 my ($t, $basedir, $hash_base, $have_blame) = @_;
1780 $base_key{hash_base
} = $hash_base if defined $hash_base;
1782 # The format of a table row is: mode list link. Where mode is
1783 # the mode of the entry, list is the name of the entry, an href,
1784 # and link is the action links of the entry.
1786 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1787 if ($t->{'type'} eq "blob") {
1788 print "<td class=\"list\">" .
1789 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1790 file_name
=>"$basedir$t->{'name'}", %base_key),
1791 -class => "list"}, esc_html
($t->{'name'})) . "</td>\n";
1792 print "<td class=\"link\">";
1794 print $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1795 file_name
=>"$basedir$t->{'name'}", %base_key)},
1798 if (defined $hash_base) {
1802 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1803 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1807 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
1808 file_name
=>"$basedir$t->{'name'}")},
1812 } elsif ($t->{'type'} eq "tree") {
1813 print "<td class=\"list\">";
1814 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1815 file_name
=>"$basedir$t->{'name'}", %base_key)},
1816 esc_html
($t->{'name'}));
1818 print "<td class=\"link\">";
1819 if (defined $hash_base) {
1820 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1821 file_name
=>"$basedir$t->{'name'}")},
1828 ## ......................................................................
1829 ## functions printing large fragments of HTML
1831 sub git_difftree_body
{
1832 my ($difftree, $hash, $parent) = @_;
1834 print "<div class=\"list_head\">\n";
1835 if ($#{$difftree} > 10) {
1836 print(($#{$difftree} + 1) . " files changed:\n");
1840 print "<table class=\"diff_tree\">\n";
1843 foreach my $line (@{$difftree}) {
1844 my %diff = parse_difftree_raw_line
($line);
1847 print "<tr class=\"dark\">\n";
1849 print "<tr class=\"light\">\n";
1853 my ($to_mode_oct, $to_mode_str, $to_file_type);
1854 my ($from_mode_oct, $from_mode_str, $from_file_type);
1855 if ($diff{'to_mode'} ne ('0' x
6)) {
1856 $to_mode_oct = oct $diff{'to_mode'};
1857 if (S_ISREG
($to_mode_oct)) { # only for regular file
1858 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1860 $to_file_type = file_type
($diff{'to_mode'});
1862 if ($diff{'from_mode'} ne ('0' x
6)) {
1863 $from_mode_oct = oct $diff{'from_mode'};
1864 if (S_ISREG
($to_mode_oct)) { # only for regular file
1865 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1867 $from_file_type = file_type
($diff{'from_mode'});
1870 if ($diff{'status'} eq "A") { # created
1871 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1872 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1873 $mode_chng .= "]</span>";
1875 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1876 hash_base
=>$hash, file_name
=>$diff{'file'}),
1877 -class => "list"}, esc_html
($diff{'file'}));
1879 print "<td>$mode_chng</td>\n";
1880 print "<td class=\"link\">";
1881 if ($action eq 'commitdiff') {
1884 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1888 } elsif ($diff{'status'} eq "D") { # deleted
1889 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1891 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1892 hash_base
=>$parent, file_name
=>$diff{'file'}),
1893 -class => "list"}, esc_html
($diff{'file'}));
1895 print "<td>$mode_chng</td>\n";
1896 print "<td class=\"link\">";
1897 if ($action eq 'commitdiff') {
1900 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1903 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1904 file_name
=>$diff{'file'})},
1906 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1907 file_name
=>$diff{'file'})},
1911 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1912 my $mode_chnge = "";
1913 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1914 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1915 if ($from_file_type != $to_file_type) {
1916 $mode_chnge .= " from $from_file_type to $to_file_type";
1918 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1919 if ($from_mode_str && $to_mode_str) {
1920 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1921 } elsif ($to_mode_str) {
1922 $mode_chnge .= " mode: $to_mode_str";
1925 $mode_chnge .= "]</span>\n";
1928 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1929 hash_base
=>$hash, file_name
=>$diff{'file'}),
1930 -class => "list"}, esc_html
($diff{'file'}));
1932 print "<td>$mode_chnge</td>\n";
1933 print "<td class=\"link\">";
1934 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1935 if ($action eq 'commitdiff') {
1938 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1940 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1941 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1942 hash_base
=>$hash, hash_parent_base
=>$parent,
1943 file_name
=>$diff{'file'})},
1948 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
1949 file_name
=>$diff{'file'})},
1951 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
1952 file_name
=>$diff{'file'})},
1956 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1957 my %status_name = ('R' => 'moved', 'C' => 'copied');
1958 my $nstatus = $status_name{$diff{'status'}};
1960 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1961 # mode also for directories, so we cannot use $to_mode_str
1962 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1965 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1966 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1967 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1968 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1969 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1970 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1971 -class => "list"}, esc_html
($diff{'from_file'})) .
1972 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1973 "<td class=\"link\">";
1974 if ($diff{'to_id'} ne $diff{'from_id'}) {
1975 if ($action eq 'commitdiff') {
1978 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1980 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1981 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1982 hash_base
=>$hash, hash_parent_base
=>$parent,
1983 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1988 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1989 file_name
=>$diff{'from_file'})},
1991 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1992 file_name
=>$diff{'from_file'})},
1996 } # we should not encounter Unmerged (U) or Unknown (X) status
2002 sub git_patchset_body
{
2003 my ($fd, $difftree, $hash, $hash_parent) = @_;
2007 my $patch_found = 0;
2010 print "<div class=\"patchset\">\n";
2013 while (my $patch_line = <$fd>) {
2016 if ($patch_line =~ m/^diff /) { # "git diff" header
2017 # beginning of patch (in patchset)
2019 # close previous patch
2020 print "</div>\n"; # class="patch"
2022 # first patch in patchset
2025 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2027 if (ref($difftree->[$patch_idx]) eq "HASH") {
2028 $diffinfo = $difftree->[$patch_idx];
2030 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2034 # for now, no extended header, hence we skip empty patches
2035 # companion to next LINE if $in_header;
2036 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
2041 if ($diffinfo->{'status'} eq "A") { # added
2042 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
2043 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2044 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2045 $diffinfo->{'to_id'}) . " (new)" .
2046 "</div>\n"; # class="diff_info"
2048 } elsif ($diffinfo->{'status'} eq "D") { # deleted
2049 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
2050 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2051 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2052 $diffinfo->{'from_id'}) . " (deleted)" .
2053 "</div>\n"; # class="diff_info"
2055 } elsif ($diffinfo->{'status'} eq "R" || # renamed
2056 $diffinfo->{'status'} eq "C" || # copied
2057 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
2058 print "<div class=\"diff_info\">" .
2059 file_type
($diffinfo->{'from_mode'}) . ":" .
2060 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2061 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
2062 $diffinfo->{'from_id'}) .
2064 file_type
($diffinfo->{'to_mode'}) . ":" .
2065 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2066 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
2067 $diffinfo->{'to_id'});
2068 print "</div>\n"; # class="diff_info"
2070 } else { # modified, mode changed, ...
2071 print "<div class=\"diff_info\">" .
2072 file_type
($diffinfo->{'from_mode'}) . ":" .
2073 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2074 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2075 $diffinfo->{'from_id'}) .
2077 file_type
($diffinfo->{'to_mode'}) . ":" .
2078 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2079 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2080 $diffinfo->{'to_id'});
2081 print "</div>\n"; # class="diff_info"
2084 #print "<div class=\"diff extended_header\">\n";
2087 } # start of patch in patchset
2090 if ($in_header && $patch_line =~ m/^---/) {
2091 #print "</div>\n"; # class="diff extended_header"
2094 my $file = $diffinfo->{'from_file'};
2095 $file ||= $diffinfo->{'file'};
2096 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2097 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
2098 -class => "list"}, esc_html
($file));
2099 $patch_line =~ s
|a
/.*$|a/$file|g
;
2100 print "<div class=\"diff from_file\">$patch_line</div>\n";
2102 $patch_line = <$fd>;
2105 #$patch_line =~ m/^+++/;
2106 $file = $diffinfo->{'to_file'};
2107 $file ||= $diffinfo->{'file'};
2108 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2109 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
2110 -class => "list"}, esc_html
($file));
2111 $patch_line =~ s
|b
/.*|b/$file|g
;
2112 print "<div class=\"diff to_file\">$patch_line</div>\n";
2116 next LINE
if $in_header;
2118 print format_diff_line
($patch_line);
2120 print "</div>\n" if $patch_found; # class="patch"
2122 print "</div>\n"; # class="patchset"
2125 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2127 sub git_shortlog_body
{
2128 # uses global variable $project
2129 my ($revlist, $from, $to, $refs, $extra) = @_;
2131 $from = 0 unless defined $from;
2132 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2134 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2136 for (my $i = $from; $i <= $to; $i++) {
2137 my $commit = $revlist->[$i];
2138 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2139 my $ref = format_ref_marker
($refs, $commit);
2140 my %co = parse_commit
($commit);
2142 print "<tr class=\"dark\">\n";
2144 print "<tr class=\"light\">\n";
2147 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2148 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2149 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2151 print format_subject_html
($co{'title'}, $co{'title_short'},
2152 href
(action
=>"commit", hash
=>$commit), $ref);
2154 "<td class=\"link\">" .
2155 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2156 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2157 if (gitweb_have_snapshot
()) {
2158 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2163 if (defined $extra) {
2165 "<td colspan=\"4\">$extra</td>\n" .
2171 sub git_history_body
{
2172 # Warning: assumes constant type (blob or tree) during history
2173 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2175 $from = 0 unless defined $from;
2176 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2178 print "<table class=\"history\" cellspacing=\"0\">\n";
2180 for (my $i = $from; $i <= $to; $i++) {
2181 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2186 my %co = parse_commit
($commit);
2191 my $ref = format_ref_marker
($refs, $commit);
2194 print "<tr class=\"dark\">\n";
2196 print "<tr class=\"light\">\n";
2199 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2200 # shortlog uses chop_str($co{'author_name'}, 10)
2201 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2203 # originally git_history used chop_str($co{'title'}, 50)
2204 print format_subject_html
($co{'title'}, $co{'title_short'},
2205 href
(action
=>"commit", hash
=>$commit), $ref);
2207 "<td class=\"link\">" .
2208 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2209 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2211 if ($ftype eq 'blob') {
2212 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2213 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2214 if (defined $blob_current && defined $blob_parent &&
2215 $blob_current ne $blob_parent) {
2217 $cgi->a({-href
=> href
(action
=>"blobdiff",
2218 hash
=>$blob_current, hash_parent
=>$blob_parent,
2219 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2220 file_name
=>$file_name)},
2227 if (defined $extra) {
2229 "<td colspan=\"4\">$extra</td>\n" .
2236 # uses global variable $project
2237 my ($taglist, $from, $to, $extra) = @_;
2238 $from = 0 unless defined $from;
2239 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2241 print "<table class=\"tags\" cellspacing=\"0\">\n";
2243 for (my $i = $from; $i <= $to; $i++) {
2244 my $entry = $taglist->[$i];
2246 my $comment_lines = $tag{'comment'};
2247 my $comment = shift @$comment_lines;
2249 if (defined $comment) {
2250 $comment_short = chop_str
($comment, 30, 5);
2253 print "<tr class=\"dark\">\n";
2255 print "<tr class=\"light\">\n";
2258 print "<td><i>$tag{'age'}</i></td>\n" .
2260 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2261 -class => "list name"}, esc_html
($tag{'name'})) .
2264 if (defined $comment) {
2265 print format_subject_html
($comment, $comment_short,
2266 href
(action
=>"tag", hash
=>$tag{'id'}));
2269 "<td class=\"selflink\">";
2270 if ($tag{'type'} eq "tag") {
2271 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2276 "<td class=\"link\">" . " | " .
2277 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2278 if ($tag{'reftype'} eq "commit") {
2279 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2280 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
2281 } elsif ($tag{'reftype'} eq "blob") {
2282 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2287 if (defined $extra) {
2289 "<td colspan=\"5\">$extra</td>\n" .
2295 sub git_heads_body
{
2296 # uses global variable $project
2297 my ($headlist, $head, $from, $to, $extra) = @_;
2298 $from = 0 unless defined $from;
2299 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2301 print "<table class=\"heads\" cellspacing=\"0\">\n";
2303 for (my $i = $from; $i <= $to; $i++) {
2304 my $entry = $headlist->[$i];
2306 my $curr = $tag{'id'} eq $head;
2308 print "<tr class=\"dark\">\n";
2310 print "<tr class=\"light\">\n";
2313 print "<td><i>$tag{'age'}</i></td>\n" .
2314 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
2315 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
2316 -class => "list name"},esc_html
($tag{'name'})) .
2318 "<td class=\"link\">" .
2319 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
2320 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") . " | " .
2321 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$tag{'name'}, hash_base
=>$tag{'name'})}, "tree") .
2325 if (defined $extra) {
2327 "<td colspan=\"3\">$extra</td>\n" .
2333 ## ======================================================================
2334 ## ======================================================================
2337 sub git_project_list
{
2338 my $order = $cgi->param('o');
2339 if (defined $order && $order !~ m/project|descr|owner|age/) {
2340 die_error
(undef, "Unknown order parameter");
2343 my @list = git_get_projects_list
();
2346 die_error
(undef, "No projects found");
2348 foreach my $pr (@list) {
2349 my (@aa) = git_get_last_activity
($pr->{'path'});
2353 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2354 if (!defined $pr->{'descr'}) {
2355 my $descr = git_get_project_description
($pr->{'path'}) || "";
2356 $pr->{'descr'} = chop_str
($descr, 25, 5);
2358 if (!defined $pr->{'owner'}) {
2359 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2361 push @projects, $pr;
2365 if (-f
$home_text) {
2366 print "<div class=\"index_include\">\n";
2367 open (my $fd, $home_text);
2372 print "<table class=\"project_list\">\n" .
2374 $order ||= "project";
2375 if ($order eq "project") {
2376 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2377 print "<th>Project</th>\n";
2380 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2381 -class => "header"}, "Project") .
2384 if ($order eq "descr") {
2385 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2386 print "<th>Description</th>\n";
2389 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2390 -class => "header"}, "Description") .
2393 if ($order eq "owner") {
2394 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2395 print "<th>Owner</th>\n";
2398 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2399 -class => "header"}, "Owner") .
2402 if ($order eq "age") {
2403 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2404 print "<th>Last Change</th>\n";
2407 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2408 -class => "header"}, "Last Change") .
2411 print "<th></th>\n" .
2414 foreach my $pr (@projects) {
2416 print "<tr class=\"dark\">\n";
2418 print "<tr class=\"light\">\n";
2421 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2422 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2423 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2424 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2425 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2426 $pr->{'age_string'} . "</td>\n" .
2427 "<td class=\"link\">" .
2428 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2429 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2430 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2431 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2439 sub git_project_index
{
2440 my @projects = git_get_projects_list
();
2443 -type
=> 'text/plain',
2444 -charset
=> 'utf-8',
2445 -content_disposition
=> 'inline; filename="index.aux"');
2447 foreach my $pr (@projects) {
2448 if (!exists $pr->{'owner'}) {
2449 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2452 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2453 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2454 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2455 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2459 print "$path $owner\n";
2464 my $descr = git_get_project_description
($project) || "none";
2465 my $head = git_get_head_hash
($project);
2466 my %co = parse_commit
($head);
2467 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2469 my $owner = git_get_project_owner
($project);
2471 my ($reflist, $refs) = git_get_refs_list
();
2475 foreach my $ref (@$reflist) {
2476 if ($ref->{'name'} =~ s!^heads/!!) {
2477 push @headlist, $ref;
2479 $ref->{'name'} =~ s!^tags/!!;
2480 push @taglist, $ref;
2485 git_print_page_nav
('summary','', $head);
2487 print "<div class=\"title\"> </div>\n";
2488 print "<table cellspacing=\"0\">\n" .
2489 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2490 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2491 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2492 # use per project git URL list in $projectroot/$project/cloneurl
2493 # or make project git URL from git base URL and project name
2494 my $url_tag = "URL";
2495 my @url_list = git_get_project_url_list
($project);
2496 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2497 foreach my $git_url (@url_list) {
2498 next unless $git_url;
2499 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2504 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2505 git_get_head_hash
($project)
2506 or die_error
(undef, "Open git-rev-list failed");
2507 my @revlist = map { chomp; $_ } <$fd>;
2509 git_print_header_div
('shortlog');
2510 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2511 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2514 git_print_header_div
('tags');
2515 git_tags_body
(\
@taglist, 0, 15,
2516 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2520 git_print_header_div
('heads');
2521 git_heads_body
(\
@headlist, $head, 0, 15,
2522 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2529 my $head = git_get_head_hash
($project);
2531 git_print_page_nav
('','', $head,undef,$head);
2532 my %tag = parse_tag
($hash);
2533 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2534 print "<div class=\"title_text\">\n" .
2535 "<table cellspacing=\"0\">\n" .
2537 "<td>object</td>\n" .
2538 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2539 $tag{'object'}) . "</td>\n" .
2540 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2541 $tag{'type'}) . "</td>\n" .
2543 if (defined($tag{'author'})) {
2544 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2545 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2546 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2547 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2550 print "</table>\n\n" .
2552 print "<div class=\"page_body\">";
2553 my $comment = $tag{'comment'};
2554 foreach my $line (@$comment) {
2555 print esc_html
($line) . "<br/>\n";
2565 my ($have_blame) = gitweb_check_feature
('blame');
2567 die_error
('403 Permission denied', "Permission denied");
2569 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2570 $hash_base ||= git_get_head_hash
($project);
2571 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2572 my %co = parse_commit
($hash_base)
2573 or die_error
(undef, "Reading commit failed");
2574 if (!defined $hash) {
2575 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2576 or die_error
(undef, "Error looking up file");
2578 $ftype = git_get_type
($hash);
2579 if ($ftype !~ "blob") {
2580 die_error
("400 Bad Request", "Object is not a blob");
2582 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
2583 $file_name, $hash_base)
2584 or die_error
(undef, "Open git-blame failed");
2587 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2590 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2593 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2595 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2596 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2597 git_print_page_path
($file_name, $ftype, $hash_base);
2598 my @rev_color = (qw(light2 dark2));
2599 my $num_colors = scalar(@rev_color);
2600 my $current_color = 0;
2603 <div class="page_body">
2604 <table class="blame">
2605 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2610 last unless defined $_;
2611 my ($full_rev, $orig_lineno, $lineno, $group_size) =
2612 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
2613 if (!exists $metainfo{$full_rev}) {
2614 $metainfo{$full_rev} = {};
2616 my $meta = $metainfo{$full_rev};
2619 if (/^(\S+) (.*)$/) {
2624 my $rev = substr($full_rev, 0, 8);
2625 my $author = $meta->{'author'};
2626 my %date = parse_date
($meta->{'author-time'},
2627 $meta->{'author-tz'});
2628 my $date = $date{'iso-tz'};
2630 $current_color = ++$current_color % $num_colors;
2632 print "<tr class=\"$rev_color[$current_color]\">\n";
2634 print "<td class=\"sha1\"";
2635 print " title=\"$author, $date\"";
2636 print " rowspan=\"$group_size\"" if ($group_size > 1);
2638 print $cgi->a({-href
=> href
(action
=>"commit",
2640 file_name
=>$file_name)},
2644 my $blamed = href
(action
=> 'blame',
2645 file_name
=> $meta->{'filename'},
2646 hash_base
=> $full_rev);
2647 print "<td class=\"linenr\">";
2648 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
2650 -class => "linenr" },
2653 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2659 or print "Reading blob failed\n";
2666 my ($have_blame) = gitweb_check_feature
('blame');
2668 die_error
('403 Permission denied', "Permission denied");
2670 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2671 $hash_base ||= git_get_head_hash
($project);
2672 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2673 my %co = parse_commit
($hash_base)
2674 or die_error
(undef, "Reading commit failed");
2675 if (!defined $hash) {
2676 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2677 or die_error
(undef, "Error lookup file");
2679 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2680 or die_error
(undef, "Open git-annotate failed");
2683 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2686 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2689 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2691 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2692 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2693 git_print_page_path
($file_name, 'blob', $hash_base);
2694 print "<div class=\"page_body\">\n";
2696 <table class="blame">
2705 my @line_class = (qw(light dark));
2706 my $line_class_len = scalar (@line_class);
2707 my $line_class_num = $#line_class;
2708 while (my $line = <$fd>) {
2720 $line_class_num = ($line_class_num + 1) % $line_class_len;
2722 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2729 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
2732 $short_rev = substr ($long_rev, 0, 8);
2733 $age = time () - $time;
2734 $age_str = age_string
($age);
2735 $age_str =~ s/ / /g;
2736 $age_class = age_class
($age);
2737 $author = esc_html
($author);
2738 $author =~ s/ / /g;
2740 $data = untabify
($data);
2741 $data = esc_html
($data);
2744 <tr class="$line_class[$line_class_num]">
2745 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2746 <td class="$age_class">$age_str</td>
2748 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2749 <td class="pre">$data</td>
2752 } # while (my $line = <$fd>)
2753 print "</table>\n\n";
2755 or print "Reading blob failed.\n";
2761 my $head = git_get_head_hash
($project);
2763 git_print_page_nav
('','', $head,undef,$head);
2764 git_print_header_div
('summary', $project);
2766 my ($taglist) = git_get_refs_list
("tags");
2768 git_tags_body
($taglist);
2774 my $head = git_get_head_hash
($project);
2776 git_print_page_nav
('','', $head,undef,$head);
2777 git_print_header_div
('summary', $project);
2779 my ($headlist) = git_get_refs_list
("heads");
2781 git_heads_body
($headlist, $head);
2786 sub git_blob_plain
{
2789 if (!defined $hash) {
2790 if (defined $file_name) {
2791 my $base = $hash_base || git_get_head_hash
($project);
2792 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2793 or die_error
(undef, "Error lookup file");
2795 die_error
(undef, "No file name defined");
2797 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2798 # blobs defined by non-textual hash id's can be cached
2803 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2804 or die_error
(undef, "Couldn't cat $file_name, $hash");
2806 $type ||= blob_mimetype
($fd, $file_name);
2808 # save as filename, even when no $file_name is given
2809 my $save_as = "$hash";
2810 if (defined $file_name) {
2811 $save_as = $file_name;
2812 } elsif ($type =~ m/^text\//) {
2819 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
2821 binmode STDOUT
, ':raw';
2823 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2831 if (!defined $hash) {
2832 if (defined $file_name) {
2833 my $base = $hash_base || git_get_head_hash
($project);
2834 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2835 or die_error
(undef, "Error lookup file");
2837 die_error
(undef, "No file name defined");
2839 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2840 # blobs defined by non-textual hash id's can be cached
2844 my ($have_blame) = gitweb_check_feature
('blame');
2845 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2846 or die_error
(undef, "Couldn't cat $file_name, $hash");
2847 my $mimetype = blob_mimetype
($fd, $file_name);
2848 if ($mimetype !~ m/^text\//) {
2850 return git_blob_plain
($mimetype);
2852 git_header_html
(undef, $expires);
2853 my $formats_nav = '';
2854 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2855 if (defined $file_name) {
2858 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2859 hash
=>$hash, file_name
=>$file_name)},
2864 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2865 hash
=>$hash, file_name
=>$file_name)},
2868 $cgi->a({-href
=> href
(action
=>"blob_plain",
2869 hash
=>$hash, file_name
=>$file_name)},
2872 $cgi->a({-href
=> href
(action
=>"blob",
2873 hash_base
=>"HEAD", file_name
=>$file_name)},
2877 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
2879 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2880 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2882 print "<div class=\"page_nav\">\n" .
2883 "<br/><br/></div>\n" .
2884 "<div class=\"title\">$hash</div>\n";
2886 git_print_page_path
($file_name, "blob", $hash_base);
2887 print "<div class=\"page_body\">\n";
2889 while (my $line = <$fd>) {
2892 $line = untabify
($line);
2893 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2894 $nr, $nr, $nr, esc_html
($line);
2897 or print "Reading blob failed.\n";
2903 my $have_snapshot = gitweb_have_snapshot
();
2905 if (!defined $hash_base) {
2906 $hash_base = "HEAD";
2908 if (!defined $hash) {
2909 if (defined $file_name) {
2910 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
2916 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
2917 or die_error
(undef, "Open git-ls-tree failed");
2918 my @entries = map { chomp; $_ } <$fd>;
2919 close $fd or die_error
(undef, "Reading tree failed");
2922 my $refs = git_get_references
();
2923 my $ref = format_ref_marker
($refs, $hash_base);
2926 my ($have_blame) = gitweb_check_feature
('blame');
2927 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2929 if (defined $file_name) {
2931 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2932 hash
=>$hash, file_name
=>$file_name)},
2934 $cgi->a({-href
=> href
(action
=>"tree",
2935 hash_base
=>"HEAD", file_name
=>$file_name)},
2938 if ($have_snapshot) {
2939 # FIXME: Should be available when we have no hash base as well.
2941 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
2944 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
2945 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2948 print "<div class=\"page_nav\">\n";
2949 print "<br/><br/></div>\n";
2950 print "<div class=\"title\">$hash</div>\n";
2952 if (defined $file_name) {
2953 $basedir = $file_name;
2954 if ($basedir ne '' && substr($basedir, -1) ne '/') {
2958 git_print_page_path
($file_name, 'tree', $hash_base);
2959 print "<div class=\"page_body\">\n";
2960 print "<table cellspacing=\"0\">\n";
2962 # '..' (top directory) link if possible
2963 if (defined $hash_base &&
2964 defined $file_name && $file_name =~ m![^/]+$!) {
2966 print "<tr class=\"dark\">\n";
2968 print "<tr class=\"light\">\n";
2972 my $up = $file_name;
2973 $up =~ s!/?[^/]+$!!;
2974 undef $up unless $up;
2975 # based on git_print_tree_entry
2976 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
2977 print '<td class="list">';
2978 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
2982 print "<td class=\"link\"></td>\n";
2986 foreach my $line (@entries) {
2987 my %t = parse_ls_tree_line
($line, -z
=> 1);
2990 print "<tr class=\"dark\">\n";
2992 print "<tr class=\"light\">\n";
2996 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3000 print "</table>\n" .
3006 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3007 my $have_snapshot = (defined $ctype && defined $suffix);
3008 if (!$have_snapshot) {
3009 die_error
('403 Permission denied', "Permission denied");
3012 if (!defined $hash) {
3013 $hash = git_get_head_hash
($project);
3016 my $filename = basename
($project) . "-$hash.tar.$suffix";
3019 -type
=> 'application/x-tar',
3020 -content_encoding
=> $ctype,
3021 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3022 -status
=> '200 OK');
3024 my $git = git_cmd_str
();
3025 my $name = $project;
3026 $name =~ s/\047/\047\\\047\047/g;
3028 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3029 or die_error
(undef, "Execute git-tar-tree failed.");
3030 binmode STDOUT
, ':raw';
3032 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3038 my $head = git_get_head_hash
($project);
3039 if (!defined $hash) {
3042 if (!defined $page) {
3045 my $refs = git_get_references
();
3047 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3048 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3049 or die_error
(undef, "Open git-rev-list failed");
3050 my @revlist = map { chomp; $_ } <$fd>;
3053 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
3056 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3059 my %co = parse_commit
($hash);
3061 git_print_header_div
('summary', $project);
3062 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3064 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
3065 my $commit = $revlist[$i];
3066 my $ref = format_ref_marker
($refs, $commit);
3067 my %co = parse_commit
($commit);
3069 my %ad = parse_date
($co{'author_epoch'});
3070 git_print_header_div
('commit',
3071 "<span class=\"age\">$co{'age_string'}</span>" .
3072 esc_html
($co{'title'}) . $ref,
3074 print "<div class=\"title_text\">\n" .
3075 "<div class=\"log_link\">\n" .
3076 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3078 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3080 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3083 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3086 print "<div class=\"log_body\">\n";
3087 git_print_simplified_log
($co{'comment'});
3094 my %co = parse_commit
($hash);
3096 die_error
(undef, "Unknown commit object");
3098 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3099 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3101 my $parent = $co{'parent'};
3102 if (!defined $parent) {
3105 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $parent, $hash
3106 or die_error
(undef, "Open git-diff-tree failed");
3107 my @difftree = map { chomp; $_ } <$fd>;
3108 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3110 # non-textual hash id's can be cached
3112 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3115 my $refs = git_get_references
();
3116 my $ref = format_ref_marker
($refs, $co{'id'});
3118 my $have_snapshot = gitweb_have_snapshot
();
3121 if (defined $file_name && defined $co{'parent'}) {
3123 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
3126 git_header_html
(undef, $expires);
3127 git_print_page_nav
('commit', '',
3128 $hash, $co{'tree'}, $hash,
3129 join (' | ', @views_nav));
3131 if (defined $co{'parent'}) {
3132 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3134 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3136 print "<div class=\"title_text\">\n" .
3137 "<table cellspacing=\"0\">\n";
3138 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3140 "<td></td><td> $ad{'rfc2822'}";
3141 if ($ad{'hour_local'} < 6) {
3142 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3143 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3145 printf(" (%02d:%02d %s)",
3146 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3150 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3151 print "<tr><td></td><td> $cd{'rfc2822'}" .
3152 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3154 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3157 "<td class=\"sha1\">" .
3158 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3159 class => "list"}, $co{'tree'}) .
3161 "<td class=\"link\">" .
3162 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3164 if ($have_snapshot) {
3166 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3170 my $parents = $co{'parents'};
3171 foreach my $par (@$parents) {
3174 "<td class=\"sha1\">" .
3175 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3176 class => "list"}, $par) .
3178 "<td class=\"link\">" .
3179 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3181 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3188 print "<div class=\"page_body\">\n";
3189 git_print_log
($co{'comment'});
3192 git_difftree_body
(\
@difftree, $hash, $parent);
3198 my $format = shift || 'html';
3205 # preparing $fd and %diffinfo for git_patchset_body
3207 if (defined $hash_base && defined $hash_parent_base) {
3208 if (defined $file_name) {
3210 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
3212 or die_error
(undef, "Open git-diff-tree failed");
3213 @difftree = map { chomp; $_ } <$fd>;
3215 or die_error
(undef, "Reading git-diff-tree failed");
3217 or die_error
('404 Not Found', "Blob diff not found");
3219 } elsif (defined $hash &&
3220 $hash =~ /[0-9a-fA-F]{40}/) {
3221 # try to find filename from $hash
3223 # read filtered raw output
3224 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
3225 or die_error
(undef, "Open git-diff-tree failed");
3227 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3229 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3230 map { chomp; $_ } <$fd>;
3232 or die_error
(undef, "Reading git-diff-tree failed");
3234 or die_error
('404 Not Found', "Blob diff not found");
3237 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3240 if (@difftree > 1) {
3241 die_error
('404 Not Found', "Ambiguous blob diff specification");
3244 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3245 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3246 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3248 $hash_parent ||= $diffinfo{'from_id'};
3249 $hash ||= $diffinfo{'to_id'};
3251 # non-textual hash id's can be cached
3252 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3253 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3258 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3259 '-p', $hash_parent_base, $hash_base,
3261 or die_error
(undef, "Open git-diff-tree failed");
3264 # old/legacy style URI
3265 if (!%diffinfo && # if new style URI failed
3266 defined $hash && defined $hash_parent) {
3267 # fake git-diff-tree raw output
3268 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3269 $diffinfo{'from_id'} = $hash_parent;
3270 $diffinfo{'to_id'} = $hash;
3271 if (defined $file_name) {
3272 if (defined $file_parent) {
3273 $diffinfo{'status'} = '2';
3274 $diffinfo{'from_file'} = $file_parent;
3275 $diffinfo{'to_file'} = $file_name;
3276 } else { # assume not renamed
3277 $diffinfo{'status'} = '1';
3278 $diffinfo{'from_file'} = $file_name;
3279 $diffinfo{'to_file'} = $file_name;
3281 } else { # no filename given
3282 $diffinfo{'status'} = '2';
3283 $diffinfo{'from_file'} = $hash_parent;
3284 $diffinfo{'to_file'} = $hash;
3287 # non-textual hash id's can be cached
3288 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3289 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3294 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts, $hash_parent, $hash
3295 or die_error
(undef, "Open git-diff failed");
3297 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3302 if ($format eq 'html') {
3304 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3305 hash
=>$hash, hash_parent
=>$hash_parent,
3306 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3307 file_name
=>$file_name, file_parent
=>$file_parent)},
3309 git_header_html
(undef, $expires);
3310 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3311 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3312 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3314 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3315 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3317 if (defined $file_name) {
3318 git_print_page_path
($file_name, "blob", $hash_base);
3320 print "<div class=\"page_path\"></div>\n";
3323 } elsif ($format eq 'plain') {
3325 -type
=> 'text/plain',
3326 -charset
=> 'utf-8',
3327 -expires
=> $expires,
3328 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3330 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3333 die_error
(undef, "Unknown blobdiff format");
3337 if ($format eq 'html') {
3338 print "<div class=\"page_body\">\n";
3340 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3343 print "</div>\n"; # class="page_body"
3347 while (my $line = <$fd>) {
3348 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_html($diffinfo{'from_file'})!eg;
3349 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_html($diffinfo{'to_file'})!eg;
3353 last if $line =~ m!^\+\+\+!;
3361 sub git_blobdiff_plain
{
3362 git_blobdiff
('plain');
3365 sub git_commitdiff
{
3366 my $format = shift || 'html';
3367 my %co = parse_commit
($hash);
3369 die_error
(undef, "Unknown commit object");
3371 if (!defined $hash_parent) {
3372 $hash_parent = $co{'parent'} || '--root';
3378 if ($format eq 'html') {
3379 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3380 "--patch-with-raw", "--full-index", $hash_parent, $hash
3381 or die_error
(undef, "Open git-diff-tree failed");
3383 while (chomp(my $line = <$fd>)) {
3384 # empty line ends raw part of diff-tree output
3386 push @difftree, $line;
3389 } elsif ($format eq 'plain') {
3390 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3391 '-p', $hash_parent, $hash
3392 or die_error
(undef, "Open git-diff-tree failed");
3395 die_error
(undef, "Unknown commitdiff format");
3398 # non-textual hash id's can be cached
3400 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3404 # write commit message
3405 if ($format eq 'html') {
3406 my $refs = git_get_references
();
3407 my $ref = format_ref_marker
($refs, $co{'id'});
3409 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3410 hash
=>$hash, hash_parent
=>$hash_parent)},
3413 git_header_html
(undef, $expires);
3414 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3415 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3416 git_print_authorship
(\
%co);
3417 print "<div class=\"page_body\">\n";
3418 print "<div class=\"log\">\n";
3419 git_print_simplified_log
($co{'comment'}, 1); # skip title
3420 print "</div>\n"; # class="log"
3422 } elsif ($format eq 'plain') {
3423 my $refs = git_get_references
("tags");
3424 my $tagname = git_get_rev_name_tags
($hash);
3425 my $filename = basename
($project) . "-$hash.patch";
3428 -type
=> 'text/plain',
3429 -charset
=> 'utf-8',
3430 -expires
=> $expires,
3431 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3432 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3435 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3436 Subject: $co{'title'}
3438 print "X-Git-Tag: $tagname\n" if $tagname;
3439 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3441 foreach my $line (@{$co{'comment'}}) {
3448 if ($format eq 'html') {
3449 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3452 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3454 print "</div>\n"; # class="page_body"
3457 } elsif ($format eq 'plain') {
3461 or print "Reading git-diff-tree failed\n";
3465 sub git_commitdiff_plain
{
3466 git_commitdiff
('plain');
3470 if (!defined $hash_base) {
3471 $hash_base = git_get_head_hash
($project);
3473 if (!defined $page) {
3477 my %co = parse_commit
($hash_base);
3479 die_error
(undef, "Unknown commit object");
3482 my $refs = git_get_references
();
3483 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3485 if (!defined $hash && defined $file_name) {
3486 $hash = git_get_hash_by_path
($hash_base, $file_name);
3488 if (defined $hash) {
3489 $ftype = git_get_type
($hash);
3493 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3494 or die_error
(undef, "Open git-rev-list-failed");
3495 my @revlist = map { chomp; $_ } <$fd>;
3497 or die_error
(undef, "Reading git-rev-list failed");
3499 my $paging_nav = '';
3502 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3503 file_name
=>$file_name)},
3505 $paging_nav .= " ⋅ " .
3506 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3507 file_name
=>$file_name, page
=>$page-1),
3508 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3510 $paging_nav .= "first";
3511 $paging_nav .= " ⋅ prev";
3513 if ($#revlist >= (100 * ($page+1)-1)) {
3514 $paging_nav .= " ⋅ " .
3515 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3516 file_name
=>$file_name, page
=>$page+1),
3517 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3519 $paging_nav .= " ⋅ next";
3522 if ($#revlist >= (100 * ($page+1)-1)) {
3524 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3525 file_name
=>$file_name, page
=>$page+1),
3526 -title
=> "Alt-n"}, "next");
3530 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3531 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3532 git_print_page_path
($file_name, $ftype, $hash_base);
3534 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3535 $refs, $hash_base, $ftype, $next_link);
3541 if (!defined $searchtext) {
3542 die_error
(undef, "Text field empty");
3544 if (!defined $hash) {
3545 $hash = git_get_head_hash
($project);
3547 my %co = parse_commit
($hash);
3549 die_error
(undef, "Unknown commit object");
3552 my $commit_search = 1;
3553 my $author_search = 0;
3554 my $committer_search = 0;
3555 my $pickaxe_search = 0;
3556 if ($searchtext =~ s/^author\\://i) {
3558 } elsif ($searchtext =~ s/^committer\\://i) {
3559 $committer_search = 1;
3560 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3562 $pickaxe_search = 1;
3564 # pickaxe may take all resources of your box and run for several minutes
3565 # with every query - so decide by yourself how public you make this feature
3566 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3567 if (!$have_pickaxe) {
3568 die_error
('403 Permission denied', "Permission denied");
3572 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3573 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3575 print "<table cellspacing=\"0\">\n";
3577 if ($commit_search) {
3579 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", $hash or next;
3580 while (my $commit_text = <$fd>) {
3581 if (!grep m/$searchtext/i, $commit_text) {
3584 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3587 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3590 my @commit_lines = split "\n", $commit_text;
3591 my %co = parse_commit
(undef, \
@commit_lines);
3596 print "<tr class=\"dark\">\n";
3598 print "<tr class=\"light\">\n";
3601 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3602 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3604 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3605 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3606 my $comment = $co{'comment'};
3607 foreach my $line (@$comment) {
3608 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3609 my $lead = esc_html
($1) || "";
3610 $lead = chop_str
($lead, 30, 10);
3611 my $match = esc_html
($2) || "";
3612 my $trail = esc_html
($3) || "";
3613 $trail = chop_str
($trail, 30, 10);
3614 my $text = "$lead<span class=\"match\">$match</span>$trail";
3615 print chop_str
($text, 80, 5) . "<br/>\n";
3619 "<td class=\"link\">" .
3620 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3622 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3629 if ($pickaxe_search) {
3631 my $git_command = git_cmd_str
();
3632 open my $fd, "-|", "$git_command rev-list $hash | " .
3633 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3636 while (my $line = <$fd>) {
3637 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3640 $set{'from_id'} = $3;
3642 $set{'id'} = $set{'to_id'};
3643 if ($set{'id'} =~ m/0{40}/) {
3644 $set{'id'} = $set{'from_id'};
3646 if ($set{'id'} =~ m/0{40}/) {
3650 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3653 print "<tr class=\"dark\">\n";
3655 print "<tr class=\"light\">\n";
3658 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3659 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3661 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3662 -class => "list subject"},
3663 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3664 while (my $setref = shift @files) {
3666 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3667 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3669 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3673 "<td class=\"link\">" .
3674 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3676 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3680 %co = parse_commit
($1);
3690 my $head = git_get_head_hash
($project);
3691 if (!defined $hash) {
3694 if (!defined $page) {
3697 my $refs = git_get_references
();
3699 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3700 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3701 or die_error
(undef, "Open git-rev-list failed");
3702 my @revlist = map { chomp; $_ } <$fd>;
3705 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3707 if ($#revlist >= (100 * ($page+1)-1)) {
3709 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3710 -title
=> "Alt-n"}, "next");
3715 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3716 git_print_header_div
('summary', $project);
3718 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3723 ## ......................................................................
3724 ## feeds (RSS, OPML)
3727 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3728 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150", git_get_head_hash
($project)
3729 or die_error
(undef, "Open git-rev-list failed");
3730 my @revlist = map { chomp; $_ } <$fd>;
3731 close $fd or die_error
(undef, "Reading git-rev-list failed");
3732 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3734 <?xml version="1.0" encoding="utf-8"?>
3735 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3737 <title>$project $my_uri $my_url</title>
3738 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3739 <description>$project log</description>
3740 <language>en</language>
3743 for (my $i = 0; $i <= $#revlist; $i++) {
3744 my $commit = $revlist[$i];
3745 my %co = parse_commit
($commit);
3746 # we read 150, we always show 30 and the ones more recent than 48 hours
3747 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3750 my %cd = parse_date
($co{'committer_epoch'});
3751 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3752 $co{'parent'}, $co{'id'}
3754 my @difftree = map { chomp; $_ } <$fd>;
3759 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3761 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3762 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3763 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3764 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3765 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3766 "<content:encoded>" .
3768 my $comment = $co{'comment'};
3769 foreach my $line (@$comment) {
3770 $line = to_utf8
($line);
3771 print "$line<br/>\n";
3774 foreach my $line (@difftree) {
3775 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3778 my $file = esc_html
(unquote
($7));
3779 $file = to_utf8
($file);
3780 print "$file<br/>\n";
3783 "</content:encoded>\n" .
3786 print "</channel></rss>";
3790 my @list = git_get_projects_list
();
3792 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3794 <?xml version="1.0" encoding="utf-8"?>
3795 <opml version="1.0">
3797 <title>$site_name Git OPML Export</title>
3800 <outline text="git RSS feeds">
3803 foreach my $pr (@list) {
3805 my $head = git_get_head_hash
($proj{'path'});
3806 if (!defined $head) {
3809 $git_dir = "$projectroot/$proj{'path'}";
3810 my %co = parse_commit
($head);
3815 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3816 my $rss = "$my_url?p=$proj{'path'};a=rss";
3817 my $html = "$my_url?p=$proj{'path'};a=summary";
3818 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";