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 ## ======================================================================
449 hash_parent_base
=> "hpb",
454 my %mapping = @mapping;
456 $params{'project'} = $project unless exists $params{'project'};
458 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
460 # use PATH_INFO for project name
461 $href .= "/$params{'project'}" if defined $params{'project'};
462 delete $params{'project'};
464 # Summary just uses the project path URL
465 if (defined $params{'action'} && $params{'action'} eq 'summary') {
466 delete $params{'action'};
470 # now encode the parameters explicitly
472 for (my $i = 0; $i < @mapping; $i += 2) {
473 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
474 if (defined $params{$name}) {
475 push @result, $symbol . "=" . esc_param
($params{$name});
478 $href .= "?" . join(';', @result) if scalar @result;
484 ## ======================================================================
485 ## validation, quoting/unquoting and escaping
487 sub validate_pathname
{
488 my $input = shift || return undef;
490 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
491 # at the beginning, at the end, and between slashes.
492 # also this catches doubled slashes
493 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
497 if ($input =~ m!\0!) {
503 sub validate_refname
{
504 my $input = shift || return undef;
506 # textual hashes are O.K.
507 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
510 # it must be correct pathname
511 $input = validate_pathname
($input)
513 # restrictions on ref name according to git-check-ref-format
514 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
520 # very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT);
523 return decode
("utf8", $str, Encode
::FB_DEFAULT
);
526 # quote unsafe chars, but keep the slash, even when it's not
527 # correct, but quoted slashes look too horrible in bookmarks
530 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
536 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
539 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
545 # replace invalid utf8 character with SUBSTITUTION sequence
548 $str = to_utf8
($str);
549 $str = escapeHTML
($str);
550 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
551 $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1)
555 # git may return quoted and escaped filenames
558 if ($str =~ m/^"(.*)"$/) {
560 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
565 # escape tabs (convert tabs to spaces)
569 while ((my $pos = index($line, "\t")) != -1) {
570 if (my $count = (8 - ($pos % 8))) {
571 my $spaces = ' ' x
$count;
572 $line =~ s/\t/$spaces/;
579 sub project_in_list
{
581 my @list = git_get_projects_list
();
582 return @list && scalar(grep { $_->{'path'} eq $project } @list);
585 ## ----------------------------------------------------------------------
586 ## HTML aware string manipulation
591 my $add_len = shift || 10;
593 # allow only $len chars, but don't cut a word if it would fit in $add_len
594 # if it doesn't fit, cut it if it's still longer than the dots we would add
595 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
598 if (length($tail) > 4) {
600 $body =~ s/&[^;]*$//; # remove chopped character entities
605 ## ----------------------------------------------------------------------
606 ## functions returning short strings
608 # CSS class for given age value (in seconds)
612 if ($age < 60*60*2) {
614 } elsif ($age < 60*60*24*2) {
621 # convert age in seconds to "nn units ago" string
626 if ($age > 60*60*24*365*2) {
627 $age_str = (int $age/60/60/24/365);
628 $age_str .= " years ago";
629 } elsif ($age > 60*60*24*(365/12)*2) {
630 $age_str = int $age/60/60/24/(365/12);
631 $age_str .= " months ago";
632 } elsif ($age > 60*60*24*7*2) {
633 $age_str = int $age/60/60/24/7;
634 $age_str .= " weeks ago";
635 } elsif ($age > 60*60*24*2) {
636 $age_str = int $age/60/60/24;
637 $age_str .= " days ago";
638 } elsif ($age > 60*60*2) {
639 $age_str = int $age/60/60;
640 $age_str .= " hours ago";
641 } elsif ($age > 60*2) {
642 $age_str = int $age/60;
643 $age_str .= " min ago";
646 $age_str .= " sec ago";
648 $age_str .= " right now";
653 # convert file mode in octal to symbolic file mode string
655 my $mode = oct shift;
657 if (S_ISDIR
($mode & S_IFMT
)) {
659 } elsif (S_ISLNK
($mode)) {
661 } elsif (S_ISREG
($mode)) {
662 # git cares only about the executable bit
663 if ($mode & S_IXUSR
) {
673 # convert file mode in octal to file type string
677 if ($mode !~ m/^[0-7]+$/) {
683 if (S_ISDIR
($mode & S_IFMT
)) {
685 } elsif (S_ISLNK
($mode)) {
687 } elsif (S_ISREG
($mode)) {
694 ## ----------------------------------------------------------------------
695 ## functions returning short HTML fragments, or transforming HTML fragments
696 ## which don't beling to other sections
698 # format line of commit message or tag comment
699 sub format_log_line_html
{
702 $line = esc_html
($line);
703 $line =~ s/ / /g;
704 if ($line =~ m/([0-9a-fA-F]{40})/) {
706 if (git_get_type
($hash_text) eq "commit") {
708 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
709 -class => "text"}, $hash_text);
710 $line =~ s/$hash_text/$link/;
716 # format marker of refs pointing to given object
717 sub format_ref_marker
{
718 my ($refs, $id) = @_;
721 if (defined $refs->{$id}) {
722 foreach my $ref (@{$refs->{$id}}) {
723 my ($type, $name) = qw();
724 # e.g. tags/v2.6.11 or heads/next
725 if ($ref =~ m!^(.*?)s?/(.*)$!) {
733 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
738 return ' <span class="refs">'. $markers . '</span>';
744 # format, perhaps shortened and with markers, title line
745 sub format_subject_html
{
746 my ($long, $short, $href, $extra) = @_;
747 $extra = '' unless defined($extra);
749 if (length($short) < length($long)) {
750 return $cgi->a({-href
=> $href, -class => "list subject",
751 -title
=> to_utf8
($long)},
752 esc_html
($short) . $extra);
754 return $cgi->a({-href
=> $href, -class => "list subject"},
755 esc_html
($long) . $extra);
759 sub format_diff_line
{
761 my $char = substr($line, 0, 1);
767 $diff_class = " add";
768 } elsif ($char eq "-") {
769 $diff_class = " rem";
770 } elsif ($char eq "@") {
771 $diff_class = " chunk_header";
772 } elsif ($char eq "\\") {
773 $diff_class = " incomplete";
775 $line = untabify
($line);
776 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
779 ## ----------------------------------------------------------------------
780 ## git utility subroutines, invoking git commands
782 # returns path to the core git executable and the --git-dir parameter as list
784 return $GIT, '--git-dir='.$git_dir;
787 # returns path to the core git executable and the --git-dir parameter as string
789 return join(' ', git_cmd
());
792 # get HEAD ref of given project as hash
793 sub git_get_head_hash
{
795 my $o_git_dir = $git_dir;
797 $git_dir = "$projectroot/$project";
798 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
801 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
805 if (defined $o_git_dir) {
806 $git_dir = $o_git_dir;
811 # get type of given object
815 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
822 sub git_get_project_config
{
823 my ($key, $type) = @_;
825 return unless ($key);
826 $key =~ s/^gitweb\.//;
827 return if ($key =~ m/\W/);
829 my @x = (git_cmd
(), 'repo-config');
830 if (defined $type) { push @x, $type; }
832 push @x, "gitweb.$key";
838 # get hash of given path at given ref
839 sub git_get_hash_by_path
{
841 my $path = shift || return undef;
846 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
847 or die_error
(undef, "Open git-ls-tree failed");
849 close $fd or return undef;
851 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
852 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
853 if (defined $type && $type ne $2) {
860 ## ......................................................................
861 ## git utility functions, directly accessing git repository
863 sub git_get_project_description
{
866 open my $fd, "$projectroot/$path/description" or return undef;
873 sub git_get_project_url_list
{
876 open my $fd, "$projectroot/$path/cloneurl" or return;
877 my @git_project_url_list = map { chomp; $_ } <$fd>;
880 return wantarray ? @git_project_url_list : \
@git_project_url_list;
883 sub git_get_projects_list
{
886 if (-d
$projects_list) {
887 # search in directory
888 my $dir = $projects_list;
889 my $pfxlen = length("$dir");
892 follow_fast
=> 1, # follow symbolic links
893 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
895 # skip project-list toplevel, if we get it.
896 return if (m!^[/.]$!);
897 # only directories can be git repositories
898 return unless (-d
$_);
900 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
901 # we check related file in $projectroot
902 if (check_export_ok
("$projectroot/$subdir")) {
903 push @list, { path
=> $subdir };
904 $File::Find
::prune
= 1;
909 } elsif (-f
$projects_list) {
910 # read from file(url-encoded):
911 # 'git%2Fgit.git Linus+Torvalds'
912 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
913 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
914 open my ($fd), $projects_list or return;
915 while (my $line = <$fd>) {
917 my ($path, $owner) = split ' ', $line;
918 $path = unescape
($path);
919 $owner = unescape
($owner);
920 if (!defined $path) {
923 if (check_export_ok
("$projectroot/$path")) {
926 owner
=> to_utf8
($owner),
933 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
937 sub git_get_project_owner
{
941 return undef unless $project;
943 # read from file (url-encoded):
944 # 'git%2Fgit.git Linus+Torvalds'
945 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
946 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
947 if (-f
$projects_list) {
948 open (my $fd , $projects_list);
949 while (my $line = <$fd>) {
951 my ($pr, $ow) = split ' ', $line;
954 if ($pr eq $project) {
955 $owner = to_utf8
($ow);
961 if (!defined $owner) {
962 $owner = get_file_owner
("$projectroot/$project");
968 sub git_get_references
{
969 my $type = shift || "";
971 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
972 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
973 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
976 while (my $line = <$fd>) {
978 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
979 if (defined $refs{$1}) {
980 push @{$refs{$1}}, $2;
990 sub git_get_rev_name_tags
{
991 my $hash = shift || return undef;
993 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
995 my $name_rev = <$fd>;
998 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1001 # catches also '$hash undefined' output
1006 ## ----------------------------------------------------------------------
1007 ## parse to hash functions
1011 my $tz = shift || "-0000";
1014 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1015 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1016 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1017 $date{'hour'} = $hour;
1018 $date{'minute'} = $min;
1019 $date{'mday'} = $mday;
1020 $date{'day'} = $days[$wday];
1021 $date{'month'} = $months[$mon];
1022 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1023 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1024 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1025 $mday, $months[$mon], $hour ,$min;
1027 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1028 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1029 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1030 $date{'hour_local'} = $hour;
1031 $date{'minute_local'} = $min;
1032 $date{'tz_local'} = $tz;
1033 $date{'iso-tz'} = sprintf ("%04d-%02d-%02d %02d:%02d:%02d %s",
1034 1900+$year, $mon+1, $mday,
1035 $hour, $min, $sec, $tz);
1044 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1045 $tag{'id'} = $tag_id;
1046 while (my $line = <$fd>) {
1048 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1049 $tag{'object'} = $1;
1050 } elsif ($line =~ m/^type (.+)$/) {
1052 } elsif ($line =~ m/^tag (.+)$/) {
1054 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1055 $tag{'author'} = $1;
1058 } elsif ($line =~ m/--BEGIN/) {
1059 push @comment, $line;
1061 } elsif ($line eq "") {
1065 push @comment, <$fd>;
1066 $tag{'comment'} = \
@comment;
1067 close $fd or return;
1068 if (!defined $tag{'name'}) {
1075 my $commit_id = shift;
1076 my $commit_text = shift;
1081 if (defined $commit_text) {
1082 @commit_lines = @$commit_text;
1085 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
1087 @commit_lines = split '\n', <$fd>;
1088 close $fd or return;
1092 my $header = shift @commit_lines;
1093 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1096 ($co{'id'}, my @parents) = split ' ', $header;
1097 $co{'parents'} = \
@parents;
1098 $co{'parent'} = $parents[0];
1099 while (my $line = shift @commit_lines) {
1100 last if $line eq "\n";
1101 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1103 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1105 $co{'author_epoch'} = $2;
1106 $co{'author_tz'} = $3;
1107 if ($co{'author'} =~ m/^([^<]+) </) {
1108 $co{'author_name'} = $1;
1110 $co{'author_name'} = $co{'author'};
1112 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1113 $co{'committer'} = $1;
1114 $co{'committer_epoch'} = $2;
1115 $co{'committer_tz'} = $3;
1116 $co{'committer_name'} = $co{'committer'};
1117 $co{'committer_name'} =~ s/ <.*//;
1120 if (!defined $co{'tree'}) {
1124 foreach my $title (@commit_lines) {
1127 $co{'title'} = chop_str
($title, 80, 5);
1128 # remove leading stuff of merges to make the interesting part visible
1129 if (length($title) > 50) {
1130 $title =~ s/^Automatic //;
1131 $title =~ s/^merge (of|with) /Merge ... /i;
1132 if (length($title) > 50) {
1133 $title =~ s/(http|rsync):\/\///;
1135 if (length($title) > 50) {
1136 $title =~ s/(master|www|rsync)\.//;
1138 if (length($title) > 50) {
1139 $title =~ s/kernel.org:?//;
1141 if (length($title) > 50) {
1142 $title =~ s/\/pub\/scm//;
1145 $co{'title_short'} = chop_str
($title, 50, 5);
1149 if ($co{'title'} eq "") {
1150 $co{'title'} = $co{'title_short'} = '(no commit message)';
1152 # remove added spaces
1153 foreach my $line (@commit_lines) {
1156 $co{'comment'} = \
@commit_lines;
1158 my $age = time - $co{'committer_epoch'};
1160 $co{'age_string'} = age_string
($age);
1161 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1162 if ($age > 60*60*24*7*2) {
1163 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1164 $co{'age_string_age'} = $co{'age_string'};
1166 $co{'age_string_date'} = $co{'age_string'};
1167 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1172 # parse ref from ref_file, given by ref_id, with given type
1174 my $ref_file = shift;
1176 my $type = shift || git_get_type
($ref_id);
1179 $ref_item{'type'} = $type;
1180 $ref_item{'id'} = $ref_id;
1181 $ref_item{'epoch'} = 0;
1182 $ref_item{'age'} = "unknown";
1183 if ($type eq "tag") {
1184 my %tag = parse_tag
($ref_id);
1185 $ref_item{'comment'} = $tag{'comment'};
1186 if ($tag{'type'} eq "commit") {
1187 my %co = parse_commit
($tag{'object'});
1188 $ref_item{'epoch'} = $co{'committer_epoch'};
1189 $ref_item{'age'} = $co{'age_string'};
1190 } elsif (defined($tag{'epoch'})) {
1191 my $age = time - $tag{'epoch'};
1192 $ref_item{'epoch'} = $tag{'epoch'};
1193 $ref_item{'age'} = age_string
($age);
1195 $ref_item{'reftype'} = $tag{'type'};
1196 $ref_item{'name'} = $tag{'name'};
1197 $ref_item{'refid'} = $tag{'object'};
1198 } elsif ($type eq "commit"){
1199 my %co = parse_commit
($ref_id);
1200 $ref_item{'reftype'} = "commit";
1201 $ref_item{'name'} = $ref_file;
1202 $ref_item{'title'} = $co{'title'};
1203 $ref_item{'refid'} = $ref_id;
1204 $ref_item{'epoch'} = $co{'committer_epoch'};
1205 $ref_item{'age'} = $co{'age_string'};
1207 $ref_item{'reftype'} = $type;
1208 $ref_item{'name'} = $ref_file;
1209 $ref_item{'refid'} = $ref_id;
1215 # parse line of git-diff-tree "raw" output
1216 sub parse_difftree_raw_line
{
1220 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1221 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1222 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1223 $res{'from_mode'} = $1;
1224 $res{'to_mode'} = $2;
1225 $res{'from_id'} = $3;
1227 $res{'status'} = $5;
1228 $res{'similarity'} = $6;
1229 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1230 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1232 $res{'file'} = unquote
($7);
1235 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1236 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1237 $res{'commit'} = $1;
1240 return wantarray ? %res : \
%res;
1243 # parse line of git-ls-tree output
1244 sub parse_ls_tree_line
($;%) {
1249 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1250 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1258 $res{'name'} = unquote
($4);
1261 return wantarray ? %res : \
%res;
1264 ## ......................................................................
1265 ## parse to array of hashes functions
1267 sub git_get_refs_list
{
1268 my $type = shift || "";
1273 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1275 while (my $line = <$fd>) {
1277 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?([^\^]+))(\^\{\})?$/) {
1278 if (defined $refs{$1}) {
1279 push @{$refs{$1}}, $2;
1284 if (! $4) { # unpeeled, direct reference
1285 push @refs, { hash
=> $1, name
=> $3 }; # without type
1286 } elsif ($3 eq $refs[-1]{'name'}) {
1287 # most likely a tag is followed by its peeled
1288 # (deref) one, and when that happens we know the
1289 # previous one was of type 'tag'.
1290 $refs[-1]{'type'} = "tag";
1296 foreach my $ref (@refs) {
1297 my $ref_file = $ref->{'name'};
1298 my $ref_id = $ref->{'hash'};
1300 my $type = $ref->{'type'} || git_get_type
($ref_id) || next;
1301 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1303 push @reflist, \
%ref_item;
1306 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1307 return (\
@reflist, \
%refs);
1310 ## ----------------------------------------------------------------------
1311 ## filesystem-related functions
1313 sub get_file_owner
{
1316 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1317 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1318 if (!defined $gcos) {
1322 $owner =~ s/[,;].*$//;
1323 return to_utf8
($owner);
1326 ## ......................................................................
1327 ## mimetype related functions
1329 sub mimetype_guess_file
{
1330 my $filename = shift;
1331 my $mimemap = shift;
1332 -r
$mimemap or return undef;
1335 open(MIME
, $mimemap) or return undef;
1337 next if m/^#/; # skip comments
1338 my ($mime, $exts) = split(/\t+/);
1339 if (defined $exts) {
1340 my @exts = split(/\s+/, $exts);
1341 foreach my $ext (@exts) {
1342 $mimemap{$ext} = $mime;
1348 $filename =~ /\.([^.]*)$/;
1349 return $mimemap{$1};
1352 sub mimetype_guess
{
1353 my $filename = shift;
1355 $filename =~ /\./ or return undef;
1357 if ($mimetypes_file) {
1358 my $file = $mimetypes_file;
1359 if ($file !~ m!^/!) { # if it is relative path
1360 # it is relative to project
1361 $file = "$projectroot/$project/$file";
1363 $mime = mimetype_guess_file
($filename, $file);
1365 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1371 my $filename = shift;
1374 my $mime = mimetype_guess
($filename);
1375 $mime and return $mime;
1379 return $default_blob_plain_mimetype unless $fd;
1382 return 'text/plain' .
1383 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1384 } elsif (! $filename) {
1385 return 'application/octet-stream';
1386 } elsif ($filename =~ m/\.png$/i) {
1388 } elsif ($filename =~ m/\.gif$/i) {
1390 } elsif ($filename =~ m/\.jpe?g$/i) {
1391 return 'image/jpeg';
1393 return 'application/octet-stream';
1397 ## ======================================================================
1398 ## functions printing HTML: header, footer, error page
1400 sub git_header_html
{
1401 my $status = shift || "200 OK";
1402 my $expires = shift;
1404 my $title = "$site_name git";
1405 if (defined $project) {
1406 $title .= " - $project";
1407 if (defined $action) {
1408 $title .= "/$action";
1409 if (defined $file_name) {
1410 $title .= " - " . esc_html
($file_name);
1411 if ($action eq "tree" && $file_name !~ m
|/$|) {
1418 # require explicit support from the UA if we are to send the page as
1419 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1420 # we have to do this because MSIE sometimes globs '*/*', pretending to
1421 # support xhtml+xml but choking when it gets what it asked for.
1422 if (defined $cgi->http('HTTP_ACCEPT') &&
1423 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1424 $cgi->Accept('application/xhtml+xml') != 0) {
1425 $content_type = 'application/xhtml+xml';
1427 $content_type = 'text/html';
1429 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1430 -status
=> $status, -expires
=> $expires);
1432 <?xml version="1.0" encoding="utf-8"?>
1433 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1434 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1435 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1436 <!-- git core binaries version $git_version -->
1438 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1439 <meta name="generator" content="gitweb/$version git/$git_version"/>
1440 <meta name="robots" content="index, nofollow"/>
1441 <title>$title</title>
1443 # print out each stylesheet that exist
1444 if (defined $stylesheet) {
1445 #provides backwards capability for those people who define style sheet in a config file
1446 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1448 foreach my $stylesheet (@stylesheets) {
1449 next unless $stylesheet;
1450 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1453 if (defined $project) {
1454 printf('<link rel="alternate" title="%s log" '.
1455 'href="%s" type="application/rss+xml"/>'."\n",
1456 esc_param
($project), href
(action
=>"rss"));
1458 printf('<link rel="alternate" title="%s projects list" '.
1459 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1460 $site_name, href
(project
=>undef, action
=>"project_index"));
1461 printf('<link rel="alternate" title="%s projects logs" '.
1462 'href="%s" type="text/x-opml"/>'."\n",
1463 $site_name, href
(project
=>undef, action
=>"opml"));
1465 if (defined $favicon) {
1466 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1472 if (-f
$site_header) {
1473 open (my $fd, $site_header);
1478 print "<div class=\"page_header\">\n" .
1479 $cgi->a({-href
=> esc_url
($logo_url),
1480 -title
=> $logo_label},
1481 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1482 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1483 if (defined $project) {
1484 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1485 if (defined $action) {
1489 if (!defined $searchtext) {
1493 if (defined $hash_base) {
1494 $search_hash = $hash_base;
1495 } elsif (defined $hash) {
1496 $search_hash = $hash;
1498 $search_hash = "HEAD";
1500 $cgi->param("a", "search");
1501 $cgi->param("h", $search_hash);
1502 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1503 "<div class=\"search\">\n" .
1504 $cgi->hidden(-name
=> "p") . "\n" .
1505 $cgi->hidden(-name
=> "a") . "\n" .
1506 $cgi->hidden(-name
=> "h") . "\n" .
1507 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1509 $cgi->end_form() . "\n";
1514 sub git_footer_html
{
1515 print "<div class=\"page_footer\">\n";
1516 if (defined $project) {
1517 my $descr = git_get_project_description
($project);
1518 if (defined $descr) {
1519 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1521 print $cgi->a({-href
=> href
(action
=>"rss"),
1522 -class => "rss_logo"}, "RSS") . "\n";
1524 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1525 -class => "rss_logo"}, "OPML") . " ";
1526 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1527 -class => "rss_logo"}, "TXT") . "\n";
1531 if (-f
$site_footer) {
1532 open (my $fd, $site_footer);
1542 my $status = shift || "403 Forbidden";
1543 my $error = shift || "Malformed query, file missing or permission denied";
1545 git_header_html
($status);
1547 <div class="page_body">
1557 ## ----------------------------------------------------------------------
1558 ## functions printing or outputting HTML: navigation
1560 sub git_print_page_nav
{
1561 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1562 $extra = '' if !defined $extra; # pager or formats
1564 my @navs = qw(summary shortlog log commit commitdiff tree);
1566 @navs = grep { $_ ne $suppress } @navs;
1569 my %arg = map { $_ => {action
=>$_} } @navs;
1570 if (defined $head) {
1571 for (qw(commit commitdiff)) {
1572 $arg{$_}{hash
} = $head;
1574 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1575 for (qw(shortlog log)) {
1576 $arg{$_}{hash
} = $head;
1580 $arg{tree
}{hash
} = $treehead if defined $treehead;
1581 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1583 print "<div class=\"page_nav\">\n" .
1585 map { $_ eq $current ?
1586 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1588 print "<br/>\n$extra<br/>\n" .
1592 sub format_paging_nav
{
1593 my ($action, $hash, $head, $page, $nrevs) = @_;
1597 if ($hash ne $head || $page) {
1598 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1600 $paging_nav .= "HEAD";
1604 $paging_nav .= " ⋅ " .
1605 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1606 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1608 $paging_nav .= " ⋅ prev";
1611 if ($nrevs >= (100 * ($page+1)-1)) {
1612 $paging_nav .= " ⋅ " .
1613 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1614 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1616 $paging_nav .= " ⋅ next";
1622 ## ......................................................................
1623 ## functions printing or outputting HTML: div
1625 sub git_print_header_div
{
1626 my ($action, $title, $hash, $hash_base) = @_;
1629 $args{action
} = $action;
1630 $args{hash
} = $hash if $hash;
1631 $args{hash_base
} = $hash_base if $hash_base;
1633 print "<div class=\"header\">\n" .
1634 $cgi->a({-href
=> href
(%args), -class => "title"},
1635 $title ? $title : $action) .
1639 #sub git_print_authorship (\%) {
1640 sub git_print_authorship
{
1643 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1644 print "<div class=\"author_date\">" .
1645 esc_html
($co->{'author_name'}) .
1647 if ($ad{'hour_local'} < 6) {
1648 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1649 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1651 printf(" (%02d:%02d %s)",
1652 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1657 sub git_print_page_path
{
1662 if (!defined $name) {
1663 print "<div class=\"page_path\">/</div>\n";
1665 my @dirname = split '/', $name;
1666 my $basename = pop @dirname;
1669 print "<div class=\"page_path\">";
1670 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1671 -title
=> 'tree root'}, "[$project]");
1673 foreach my $dir (@dirname) {
1674 $fullname .= ($fullname ? '/' : '') . $dir;
1675 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1677 -title
=> $fullname}, esc_html
($dir));
1680 if (defined $type && $type eq 'blob') {
1681 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1683 -title
=> $name}, esc_html
($basename));
1684 } elsif (defined $type && $type eq 'tree') {
1685 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1687 -title
=> $name}, esc_html
($basename));
1689 print esc_html
($basename);
1691 print "<br/></div>\n";
1695 # sub git_print_log (\@;%) {
1696 sub git_print_log
($;%) {
1700 if ($opts{'-remove_title'}) {
1701 # remove title, i.e. first line of log
1704 # remove leading empty lines
1705 while (defined $log->[0] && $log->[0] eq "") {
1712 foreach my $line (@$log) {
1713 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1716 if (! $opts{'-remove_signoff'}) {
1717 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1720 # remove signoff lines
1727 # print only one empty line
1728 # do not print empty line after signoff
1730 next if ($empty || $signoff);
1736 print format_log_line_html
($line) . "<br/>\n";
1739 if ($opts{'-final_empty_line'}) {
1740 # end with single empty line
1741 print "<br/>\n" unless $empty;
1745 sub git_print_simplified_log
{
1747 my $remove_title = shift;
1750 -final_empty_line
=> 1,
1751 -remove_title
=> $remove_title);
1754 # print tree entry (row of git_tree), but without encompassing <tr> element
1755 sub git_print_tree_entry
{
1756 my ($t, $basedir, $hash_base, $have_blame) = @_;
1759 $base_key{hash_base
} = $hash_base if defined $hash_base;
1761 # The format of a table row is: mode list link. Where mode is
1762 # the mode of the entry, list is the name of the entry, an href,
1763 # and link is the action links of the entry.
1765 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1766 if ($t->{'type'} eq "blob") {
1767 print "<td class=\"list\">" .
1768 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1769 file_name
=>"$basedir$t->{'name'}", %base_key),
1770 -class => "list"}, esc_html
($t->{'name'})) . "</td>\n";
1771 print "<td class=\"link\">";
1773 print $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1774 file_name
=>"$basedir$t->{'name'}", %base_key)},
1777 if (defined $hash_base) {
1781 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1782 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1786 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
1787 file_name
=>"$basedir$t->{'name'}")},
1791 } elsif ($t->{'type'} eq "tree") {
1792 print "<td class=\"list\">";
1793 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1794 file_name
=>"$basedir$t->{'name'}", %base_key)},
1795 esc_html
($t->{'name'}));
1797 print "<td class=\"link\">";
1798 if (defined $hash_base) {
1799 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1800 file_name
=>"$basedir$t->{'name'}")},
1807 ## ......................................................................
1808 ## functions printing large fragments of HTML
1810 sub git_difftree_body
{
1811 my ($difftree, $hash, $parent) = @_;
1813 print "<div class=\"list_head\">\n";
1814 if ($#{$difftree} > 10) {
1815 print(($#{$difftree} + 1) . " files changed:\n");
1819 print "<table class=\"diff_tree\">\n";
1822 foreach my $line (@{$difftree}) {
1823 my %diff = parse_difftree_raw_line
($line);
1826 print "<tr class=\"dark\">\n";
1828 print "<tr class=\"light\">\n";
1832 my ($to_mode_oct, $to_mode_str, $to_file_type);
1833 my ($from_mode_oct, $from_mode_str, $from_file_type);
1834 if ($diff{'to_mode'} ne ('0' x
6)) {
1835 $to_mode_oct = oct $diff{'to_mode'};
1836 if (S_ISREG
($to_mode_oct)) { # only for regular file
1837 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1839 $to_file_type = file_type
($diff{'to_mode'});
1841 if ($diff{'from_mode'} ne ('0' x
6)) {
1842 $from_mode_oct = oct $diff{'from_mode'};
1843 if (S_ISREG
($to_mode_oct)) { # only for regular file
1844 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1846 $from_file_type = file_type
($diff{'from_mode'});
1849 if ($diff{'status'} eq "A") { # created
1850 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1851 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1852 $mode_chng .= "]</span>";
1854 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1855 hash_base
=>$hash, file_name
=>$diff{'file'}),
1856 -class => "list"}, esc_html
($diff{'file'}));
1858 print "<td>$mode_chng</td>\n";
1859 print "<td class=\"link\">";
1860 if ($action eq 'commitdiff') {
1863 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1867 } elsif ($diff{'status'} eq "D") { # deleted
1868 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1870 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1871 hash_base
=>$parent, file_name
=>$diff{'file'}),
1872 -class => "list"}, esc_html
($diff{'file'}));
1874 print "<td>$mode_chng</td>\n";
1875 print "<td class=\"link\">";
1876 if ($action eq 'commitdiff') {
1879 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1882 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1883 file_name
=>$diff{'file'})},
1885 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1886 file_name
=>$diff{'file'})},
1890 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1891 my $mode_chnge = "";
1892 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1893 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1894 if ($from_file_type != $to_file_type) {
1895 $mode_chnge .= " from $from_file_type to $to_file_type";
1897 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1898 if ($from_mode_str && $to_mode_str) {
1899 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1900 } elsif ($to_mode_str) {
1901 $mode_chnge .= " mode: $to_mode_str";
1904 $mode_chnge .= "]</span>\n";
1907 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1908 hash_base
=>$hash, file_name
=>$diff{'file'}),
1909 -class => "list"}, esc_html
($diff{'file'}));
1911 print "<td>$mode_chnge</td>\n";
1912 print "<td class=\"link\">";
1913 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1914 if ($action eq 'commitdiff') {
1917 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1919 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1920 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1921 hash_base
=>$hash, hash_parent_base
=>$parent,
1922 file_name
=>$diff{'file'})},
1927 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
1928 file_name
=>$diff{'file'})},
1930 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
1931 file_name
=>$diff{'file'})},
1935 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1936 my %status_name = ('R' => 'moved', 'C' => 'copied');
1937 my $nstatus = $status_name{$diff{'status'}};
1939 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1940 # mode also for directories, so we cannot use $to_mode_str
1941 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1944 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1945 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1946 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1947 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1948 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1949 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1950 -class => "list"}, esc_html
($diff{'from_file'})) .
1951 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1952 "<td class=\"link\">";
1953 if ($diff{'to_id'} ne $diff{'from_id'}) {
1954 if ($action eq 'commitdiff') {
1957 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1959 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1960 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1961 hash_base
=>$hash, hash_parent_base
=>$parent,
1962 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1967 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1968 file_name
=>$diff{'from_file'})},
1970 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1971 file_name
=>$diff{'from_file'})},
1975 } # we should not encounter Unmerged (U) or Unknown (X) status
1981 sub git_patchset_body
{
1982 my ($fd, $difftree, $hash, $hash_parent) = @_;
1986 my $patch_found = 0;
1989 print "<div class=\"patchset\">\n";
1992 while (my $patch_line = <$fd>) {
1995 if ($patch_line =~ m/^diff /) { # "git diff" header
1996 # beginning of patch (in patchset)
1998 # close previous patch
1999 print "</div>\n"; # class="patch"
2001 # first patch in patchset
2004 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2006 if (ref($difftree->[$patch_idx]) eq "HASH") {
2007 $diffinfo = $difftree->[$patch_idx];
2009 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2013 # for now, no extended header, hence we skip empty patches
2014 # companion to next LINE if $in_header;
2015 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
2020 if ($diffinfo->{'status'} eq "A") { # added
2021 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
2022 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2023 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2024 $diffinfo->{'to_id'}) . " (new)" .
2025 "</div>\n"; # class="diff_info"
2027 } elsif ($diffinfo->{'status'} eq "D") { # deleted
2028 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
2029 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2030 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2031 $diffinfo->{'from_id'}) . " (deleted)" .
2032 "</div>\n"; # class="diff_info"
2034 } elsif ($diffinfo->{'status'} eq "R" || # renamed
2035 $diffinfo->{'status'} eq "C" || # copied
2036 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
2037 print "<div class=\"diff_info\">" .
2038 file_type
($diffinfo->{'from_mode'}) . ":" .
2039 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2040 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
2041 $diffinfo->{'from_id'}) .
2043 file_type
($diffinfo->{'to_mode'}) . ":" .
2044 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2045 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
2046 $diffinfo->{'to_id'});
2047 print "</div>\n"; # class="diff_info"
2049 } else { # modified, mode changed, ...
2050 print "<div class=\"diff_info\">" .
2051 file_type
($diffinfo->{'from_mode'}) . ":" .
2052 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2053 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2054 $diffinfo->{'from_id'}) .
2056 file_type
($diffinfo->{'to_mode'}) . ":" .
2057 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2058 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2059 $diffinfo->{'to_id'});
2060 print "</div>\n"; # class="diff_info"
2063 #print "<div class=\"diff extended_header\">\n";
2066 } # start of patch in patchset
2069 if ($in_header && $patch_line =~ m/^---/) {
2070 #print "</div>\n"; # class="diff extended_header"
2073 my $file = $diffinfo->{'from_file'};
2074 $file ||= $diffinfo->{'file'};
2075 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2076 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
2077 -class => "list"}, esc_html
($file));
2078 $patch_line =~ s
|a
/.*$|a/$file|g
;
2079 print "<div class=\"diff from_file\">$patch_line</div>\n";
2081 $patch_line = <$fd>;
2084 #$patch_line =~ m/^+++/;
2085 $file = $diffinfo->{'to_file'};
2086 $file ||= $diffinfo->{'file'};
2087 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2088 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
2089 -class => "list"}, esc_html
($file));
2090 $patch_line =~ s
|b
/.*|b/$file|g
;
2091 print "<div class=\"diff to_file\">$patch_line</div>\n";
2095 next LINE
if $in_header;
2097 print format_diff_line
($patch_line);
2099 print "</div>\n" if $patch_found; # class="patch"
2101 print "</div>\n"; # class="patchset"
2104 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2106 sub git_shortlog_body
{
2107 # uses global variable $project
2108 my ($revlist, $from, $to, $refs, $extra) = @_;
2110 $from = 0 unless defined $from;
2111 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2113 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2115 for (my $i = $from; $i <= $to; $i++) {
2116 my $commit = $revlist->[$i];
2117 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2118 my $ref = format_ref_marker
($refs, $commit);
2119 my %co = parse_commit
($commit);
2121 print "<tr class=\"dark\">\n";
2123 print "<tr class=\"light\">\n";
2126 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2127 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2128 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2130 print format_subject_html
($co{'title'}, $co{'title_short'},
2131 href
(action
=>"commit", hash
=>$commit), $ref);
2133 "<td class=\"link\">" .
2134 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2135 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2136 if (gitweb_have_snapshot
()) {
2137 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2142 if (defined $extra) {
2144 "<td colspan=\"4\">$extra</td>\n" .
2150 sub git_history_body
{
2151 # Warning: assumes constant type (blob or tree) during history
2152 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2154 $from = 0 unless defined $from;
2155 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2157 print "<table class=\"history\" cellspacing=\"0\">\n";
2159 for (my $i = $from; $i <= $to; $i++) {
2160 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2165 my %co = parse_commit
($commit);
2170 my $ref = format_ref_marker
($refs, $commit);
2173 print "<tr class=\"dark\">\n";
2175 print "<tr class=\"light\">\n";
2178 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2179 # shortlog uses chop_str($co{'author_name'}, 10)
2180 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2182 # originally git_history used chop_str($co{'title'}, 50)
2183 print format_subject_html
($co{'title'}, $co{'title_short'},
2184 href
(action
=>"commit", hash
=>$commit), $ref);
2186 "<td class=\"link\">" .
2187 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2188 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2190 if ($ftype eq 'blob') {
2191 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2192 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2193 if (defined $blob_current && defined $blob_parent &&
2194 $blob_current ne $blob_parent) {
2196 $cgi->a({-href
=> href
(action
=>"blobdiff",
2197 hash
=>$blob_current, hash_parent
=>$blob_parent,
2198 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2199 file_name
=>$file_name)},
2206 if (defined $extra) {
2208 "<td colspan=\"4\">$extra</td>\n" .
2215 # uses global variable $project
2216 my ($taglist, $from, $to, $extra) = @_;
2217 $from = 0 unless defined $from;
2218 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2220 print "<table class=\"tags\" cellspacing=\"0\">\n";
2222 for (my $i = $from; $i <= $to; $i++) {
2223 my $entry = $taglist->[$i];
2225 my $comment_lines = $tag{'comment'};
2226 my $comment = shift @$comment_lines;
2228 if (defined $comment) {
2229 $comment_short = chop_str
($comment, 30, 5);
2232 print "<tr class=\"dark\">\n";
2234 print "<tr class=\"light\">\n";
2237 print "<td><i>$tag{'age'}</i></td>\n" .
2239 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2240 -class => "list name"}, esc_html
($tag{'name'})) .
2243 if (defined $comment) {
2244 print format_subject_html
($comment, $comment_short,
2245 href
(action
=>"tag", hash
=>$tag{'id'}));
2248 "<td class=\"selflink\">";
2249 if ($tag{'type'} eq "tag") {
2250 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2255 "<td class=\"link\">" . " | " .
2256 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2257 if ($tag{'reftype'} eq "commit") {
2258 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2259 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
2260 } elsif ($tag{'reftype'} eq "blob") {
2261 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2266 if (defined $extra) {
2268 "<td colspan=\"5\">$extra</td>\n" .
2274 sub git_heads_body
{
2275 # uses global variable $project
2276 my ($headlist, $head, $from, $to, $extra) = @_;
2277 $from = 0 unless defined $from;
2278 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2280 print "<table class=\"heads\" cellspacing=\"0\">\n";
2282 for (my $i = $from; $i <= $to; $i++) {
2283 my $entry = $headlist->[$i];
2285 my $curr = $tag{'id'} eq $head;
2287 print "<tr class=\"dark\">\n";
2289 print "<tr class=\"light\">\n";
2292 print "<td><i>$tag{'age'}</i></td>\n" .
2293 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
2294 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
2295 -class => "list name"},esc_html
($tag{'name'})) .
2297 "<td class=\"link\">" .
2298 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
2299 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") . " | " .
2300 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$tag{'name'}, hash_base
=>$tag{'name'})}, "tree") .
2304 if (defined $extra) {
2306 "<td colspan=\"3\">$extra</td>\n" .
2312 ## ======================================================================
2313 ## ======================================================================
2316 sub git_project_list
{
2317 my $order = $cgi->param('o');
2318 if (defined $order && $order !~ m/project|descr|owner|age/) {
2319 die_error
(undef, "Unknown order parameter");
2322 my @list = git_get_projects_list
();
2325 die_error
(undef, "No projects found");
2327 foreach my $pr (@list) {
2328 my $head = git_get_head_hash
($pr->{'path'});
2329 if (!defined $head) {
2332 $git_dir = "$projectroot/$pr->{'path'}";
2333 my %co = parse_commit
($head);
2337 $pr->{'commit'} = \
%co;
2338 if (!defined $pr->{'descr'}) {
2339 my $descr = git_get_project_description
($pr->{'path'}) || "";
2340 $pr->{'descr'} = chop_str
($descr, 25, 5);
2342 if (!defined $pr->{'owner'}) {
2343 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2345 push @projects, $pr;
2349 if (-f
$home_text) {
2350 print "<div class=\"index_include\">\n";
2351 open (my $fd, $home_text);
2356 print "<table class=\"project_list\">\n" .
2358 $order ||= "project";
2359 if ($order eq "project") {
2360 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2361 print "<th>Project</th>\n";
2364 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2365 -class => "header"}, "Project") .
2368 if ($order eq "descr") {
2369 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2370 print "<th>Description</th>\n";
2373 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2374 -class => "header"}, "Description") .
2377 if ($order eq "owner") {
2378 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2379 print "<th>Owner</th>\n";
2382 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2383 -class => "header"}, "Owner") .
2386 if ($order eq "age") {
2387 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2388 print "<th>Last Change</th>\n";
2391 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2392 -class => "header"}, "Last Change") .
2395 print "<th></th>\n" .
2398 foreach my $pr (@projects) {
2400 print "<tr class=\"dark\">\n";
2402 print "<tr class=\"light\">\n";
2405 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2406 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2407 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2408 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2409 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2410 $pr->{'commit'}{'age_string'} . "</td>\n" .
2411 "<td class=\"link\">" .
2412 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2413 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2414 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2415 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2423 sub git_project_index
{
2424 my @projects = git_get_projects_list
();
2427 -type
=> 'text/plain',
2428 -charset
=> 'utf-8',
2429 -content_disposition
=> 'inline; filename="index.aux"');
2431 foreach my $pr (@projects) {
2432 if (!exists $pr->{'owner'}) {
2433 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2436 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2437 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2438 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2439 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2443 print "$path $owner\n";
2448 my $descr = git_get_project_description
($project) || "none";
2449 my $head = git_get_head_hash
($project);
2450 my %co = parse_commit
($head);
2451 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2453 my $owner = git_get_project_owner
($project);
2455 my ($reflist, $refs) = git_get_refs_list
();
2459 foreach my $ref (@$reflist) {
2460 if ($ref->{'name'} =~ s!^heads/!!) {
2461 push @headlist, $ref;
2463 $ref->{'name'} =~ s!^tags/!!;
2464 push @taglist, $ref;
2469 git_print_page_nav
('summary','', $head);
2471 print "<div class=\"title\"> </div>\n";
2472 print "<table cellspacing=\"0\">\n" .
2473 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2474 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2475 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2476 # use per project git URL list in $projectroot/$project/cloneurl
2477 # or make project git URL from git base URL and project name
2478 my $url_tag = "URL";
2479 my @url_list = git_get_project_url_list
($project);
2480 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2481 foreach my $git_url (@url_list) {
2482 next unless $git_url;
2483 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2488 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2489 git_get_head_hash
($project)
2490 or die_error
(undef, "Open git-rev-list failed");
2491 my @revlist = map { chomp; $_ } <$fd>;
2493 git_print_header_div
('shortlog');
2494 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2495 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2498 git_print_header_div
('tags');
2499 git_tags_body
(\
@taglist, 0, 15,
2500 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2504 git_print_header_div
('heads');
2505 git_heads_body
(\
@headlist, $head, 0, 15,
2506 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2513 my $head = git_get_head_hash
($project);
2515 git_print_page_nav
('','', $head,undef,$head);
2516 my %tag = parse_tag
($hash);
2517 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2518 print "<div class=\"title_text\">\n" .
2519 "<table cellspacing=\"0\">\n" .
2521 "<td>object</td>\n" .
2522 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2523 $tag{'object'}) . "</td>\n" .
2524 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2525 $tag{'type'}) . "</td>\n" .
2527 if (defined($tag{'author'})) {
2528 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2529 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2530 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2531 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2534 print "</table>\n\n" .
2536 print "<div class=\"page_body\">";
2537 my $comment = $tag{'comment'};
2538 foreach my $line (@$comment) {
2539 print esc_html
($line) . "<br/>\n";
2549 my ($have_blame) = gitweb_check_feature
('blame');
2551 die_error
('403 Permission denied', "Permission denied");
2553 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2554 $hash_base ||= git_get_head_hash
($project);
2555 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2556 my %co = parse_commit
($hash_base)
2557 or die_error
(undef, "Reading commit failed");
2558 if (!defined $hash) {
2559 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2560 or die_error
(undef, "Error looking up file");
2562 $ftype = git_get_type
($hash);
2563 if ($ftype !~ "blob") {
2564 die_error
("400 Bad Request", "Object is not a blob");
2566 open ($fd, "-|", git_cmd
(), "blame", '--porcelain', '--',
2567 $file_name, $hash_base)
2568 or die_error
(undef, "Open git-blame failed");
2571 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2574 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2577 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2579 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2580 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2581 git_print_page_path
($file_name, $ftype, $hash_base);
2582 my @rev_color = (qw(light2 dark2));
2583 my $num_colors = scalar(@rev_color);
2584 my $current_color = 0;
2587 <div class="page_body">
2588 <table class="blame">
2589 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2594 last unless defined $_;
2595 my ($full_rev, $lineno, $orig_lineno, $group_size) =
2596 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
2597 if (!exists $metainfo{$full_rev}) {
2598 $metainfo{$full_rev} = {};
2600 my $meta = $metainfo{$full_rev};
2603 if (/^(\S+) (.*)$/) {
2608 my $rev = substr($full_rev, 0, 8);
2609 my $author = $meta->{'author'};
2610 my %date = parse_date
($meta->{'author-time'},
2611 $meta->{'author-tz'});
2612 my $date = $date{'iso-tz'};
2614 $current_color = ++$current_color % $num_colors;
2616 print "<tr class=\"$rev_color[$current_color]\">\n";
2618 print "<td class=\"sha1\"";
2619 print " title=\"$author, $date\"";
2620 print " rowspan=\"$group_size\"" if ($group_size > 1);
2622 print $cgi->a({-href
=> href
(action
=>"commit",
2624 file_name
=>$file_name)},
2628 my $blamed = href
(action
=> 'blame',
2629 file_name
=> $meta->{'filename'},
2630 hash_base
=> $full_rev);
2631 print "<td class=\"linenr\">";
2632 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
2634 -class => "linenr" },
2637 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2643 or print "Reading blob failed\n";
2650 my ($have_blame) = gitweb_check_feature
('blame');
2652 die_error
('403 Permission denied', "Permission denied");
2654 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2655 $hash_base ||= git_get_head_hash
($project);
2656 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2657 my %co = parse_commit
($hash_base)
2658 or die_error
(undef, "Reading commit failed");
2659 if (!defined $hash) {
2660 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2661 or die_error
(undef, "Error lookup file");
2663 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2664 or die_error
(undef, "Open git-annotate failed");
2667 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2670 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2673 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2675 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2676 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2677 git_print_page_path
($file_name, 'blob', $hash_base);
2678 print "<div class=\"page_body\">\n";
2680 <table class="blame">
2689 my @line_class = (qw(light dark));
2690 my $line_class_len = scalar (@line_class);
2691 my $line_class_num = $#line_class;
2692 while (my $line = <$fd>) {
2704 $line_class_num = ($line_class_num + 1) % $line_class_len;
2706 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2713 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
2716 $short_rev = substr ($long_rev, 0, 8);
2717 $age = time () - $time;
2718 $age_str = age_string
($age);
2719 $age_str =~ s/ / /g;
2720 $age_class = age_class
($age);
2721 $author = esc_html
($author);
2722 $author =~ s/ / /g;
2724 $data = untabify
($data);
2725 $data = esc_html
($data);
2728 <tr class="$line_class[$line_class_num]">
2729 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2730 <td class="$age_class">$age_str</td>
2732 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2733 <td class="pre">$data</td>
2736 } # while (my $line = <$fd>)
2737 print "</table>\n\n";
2739 or print "Reading blob failed.\n";
2745 my $head = git_get_head_hash
($project);
2747 git_print_page_nav
('','', $head,undef,$head);
2748 git_print_header_div
('summary', $project);
2750 my ($taglist) = git_get_refs_list
("tags");
2752 git_tags_body
($taglist);
2758 my $head = git_get_head_hash
($project);
2760 git_print_page_nav
('','', $head,undef,$head);
2761 git_print_header_div
('summary', $project);
2763 my ($headlist) = git_get_refs_list
("heads");
2765 git_heads_body
($headlist, $head);
2770 sub git_blob_plain
{
2773 if (!defined $hash) {
2774 if (defined $file_name) {
2775 my $base = $hash_base || git_get_head_hash
($project);
2776 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2777 or die_error
(undef, "Error lookup file");
2779 die_error
(undef, "No file name defined");
2781 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2782 # blobs defined by non-textual hash id's can be cached
2787 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2788 or die_error
(undef, "Couldn't cat $file_name, $hash");
2790 $type ||= blob_mimetype
($fd, $file_name);
2792 # save as filename, even when no $file_name is given
2793 my $save_as = "$hash";
2794 if (defined $file_name) {
2795 $save_as = $file_name;
2796 } elsif ($type =~ m/^text\//) {
2803 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
2805 binmode STDOUT
, ':raw';
2807 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2815 if (!defined $hash) {
2816 if (defined $file_name) {
2817 my $base = $hash_base || git_get_head_hash
($project);
2818 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2819 or die_error
(undef, "Error lookup file");
2821 die_error
(undef, "No file name defined");
2823 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2824 # blobs defined by non-textual hash id's can be cached
2828 my ($have_blame) = gitweb_check_feature
('blame');
2829 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2830 or die_error
(undef, "Couldn't cat $file_name, $hash");
2831 my $mimetype = blob_mimetype
($fd, $file_name);
2832 if ($mimetype !~ m/^text\//) {
2834 return git_blob_plain
($mimetype);
2836 git_header_html
(undef, $expires);
2837 my $formats_nav = '';
2838 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2839 if (defined $file_name) {
2842 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2843 hash
=>$hash, file_name
=>$file_name)},
2848 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2849 hash
=>$hash, file_name
=>$file_name)},
2852 $cgi->a({-href
=> href
(action
=>"blob_plain",
2853 hash
=>$hash, file_name
=>$file_name)},
2856 $cgi->a({-href
=> href
(action
=>"blob",
2857 hash_base
=>"HEAD", file_name
=>$file_name)},
2861 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
2863 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2864 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2866 print "<div class=\"page_nav\">\n" .
2867 "<br/><br/></div>\n" .
2868 "<div class=\"title\">$hash</div>\n";
2870 git_print_page_path
($file_name, "blob", $hash_base);
2871 print "<div class=\"page_body\">\n";
2873 while (my $line = <$fd>) {
2876 $line = untabify
($line);
2877 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2878 $nr, $nr, $nr, esc_html
($line);
2881 or print "Reading blob failed.\n";
2887 my $have_snapshot = gitweb_have_snapshot
();
2889 if (!defined $hash_base) {
2890 $hash_base = "HEAD";
2892 if (!defined $hash) {
2893 if (defined $file_name) {
2894 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
2900 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
2901 or die_error
(undef, "Open git-ls-tree failed");
2902 my @entries = map { chomp; $_ } <$fd>;
2903 close $fd or die_error
(undef, "Reading tree failed");
2906 my $refs = git_get_references
();
2907 my $ref = format_ref_marker
($refs, $hash_base);
2910 my ($have_blame) = gitweb_check_feature
('blame');
2911 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2913 if (defined $file_name) {
2915 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2916 hash
=>$hash, file_name
=>$file_name)},
2918 $cgi->a({-href
=> href
(action
=>"tree",
2919 hash_base
=>"HEAD", file_name
=>$file_name)},
2922 if ($have_snapshot) {
2923 # FIXME: Should be available when we have no hash base as well.
2925 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
2928 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
2929 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2932 print "<div class=\"page_nav\">\n";
2933 print "<br/><br/></div>\n";
2934 print "<div class=\"title\">$hash</div>\n";
2936 if (defined $file_name) {
2937 $base = esc_html
("$file_name/");
2939 git_print_page_path
($file_name, 'tree', $hash_base);
2940 print "<div class=\"page_body\">\n";
2941 print "<table cellspacing=\"0\">\n";
2943 foreach my $line (@entries) {
2944 my %t = parse_ls_tree_line
($line, -z
=> 1);
2947 print "<tr class=\"dark\">\n";
2949 print "<tr class=\"light\">\n";
2953 git_print_tree_entry
(\
%t, $base, $hash_base, $have_blame);
2957 print "</table>\n" .
2963 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2964 my $have_snapshot = (defined $ctype && defined $suffix);
2965 if (!$have_snapshot) {
2966 die_error
('403 Permission denied', "Permission denied");
2969 if (!defined $hash) {
2970 $hash = git_get_head_hash
($project);
2973 my $filename = basename
($project) . "-$hash.tar.$suffix";
2976 -type
=> 'application/x-tar',
2977 -content_encoding
=> $ctype,
2978 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
2979 -status
=> '200 OK');
2981 my $git = git_cmd_str
();
2982 my $name = $project;
2983 $name =~ s/\047/\047\\\047\047/g;
2985 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
2986 or die_error
(undef, "Execute git-tar-tree failed.");
2987 binmode STDOUT
, ':raw';
2989 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2995 my $head = git_get_head_hash
($project);
2996 if (!defined $hash) {
2999 if (!defined $page) {
3002 my $refs = git_get_references
();
3004 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3005 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3006 or die_error
(undef, "Open git-rev-list failed");
3007 my @revlist = map { chomp; $_ } <$fd>;
3010 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
3013 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3016 my %co = parse_commit
($hash);
3018 git_print_header_div
('summary', $project);
3019 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3021 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
3022 my $commit = $revlist[$i];
3023 my $ref = format_ref_marker
($refs, $commit);
3024 my %co = parse_commit
($commit);
3026 my %ad = parse_date
($co{'author_epoch'});
3027 git_print_header_div
('commit',
3028 "<span class=\"age\">$co{'age_string'}</span>" .
3029 esc_html
($co{'title'}) . $ref,
3031 print "<div class=\"title_text\">\n" .
3032 "<div class=\"log_link\">\n" .
3033 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3035 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3037 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3040 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3043 print "<div class=\"log_body\">\n";
3044 git_print_simplified_log
($co{'comment'});
3051 my %co = parse_commit
($hash);
3053 die_error
(undef, "Unknown commit object");
3055 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3056 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3058 my $parent = $co{'parent'};
3059 if (!defined $parent) {
3062 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $parent, $hash
3063 or die_error
(undef, "Open git-diff-tree failed");
3064 my @difftree = map { chomp; $_ } <$fd>;
3065 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3067 # non-textual hash id's can be cached
3069 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3072 my $refs = git_get_references
();
3073 my $ref = format_ref_marker
($refs, $co{'id'});
3075 my $have_snapshot = gitweb_have_snapshot
();
3078 if (defined $file_name && defined $co{'parent'}) {
3080 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
3083 git_header_html
(undef, $expires);
3084 git_print_page_nav
('commit', '',
3085 $hash, $co{'tree'}, $hash,
3086 join (' | ', @views_nav));
3088 if (defined $co{'parent'}) {
3089 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3091 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3093 print "<div class=\"title_text\">\n" .
3094 "<table cellspacing=\"0\">\n";
3095 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3097 "<td></td><td> $ad{'rfc2822'}";
3098 if ($ad{'hour_local'} < 6) {
3099 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3100 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3102 printf(" (%02d:%02d %s)",
3103 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3107 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3108 print "<tr><td></td><td> $cd{'rfc2822'}" .
3109 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3111 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3114 "<td class=\"sha1\">" .
3115 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3116 class => "list"}, $co{'tree'}) .
3118 "<td class=\"link\">" .
3119 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3121 if ($have_snapshot) {
3123 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3127 my $parents = $co{'parents'};
3128 foreach my $par (@$parents) {
3131 "<td class=\"sha1\">" .
3132 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3133 class => "list"}, $par) .
3135 "<td class=\"link\">" .
3136 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3138 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3145 print "<div class=\"page_body\">\n";
3146 git_print_log
($co{'comment'});
3149 git_difftree_body
(\
@difftree, $hash, $parent);
3155 my $format = shift || 'html';
3162 # preparing $fd and %diffinfo for git_patchset_body
3164 if (defined $hash_base && defined $hash_parent_base) {
3165 if (defined $file_name) {
3167 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
3169 or die_error
(undef, "Open git-diff-tree failed");
3170 @difftree = map { chomp; $_ } <$fd>;
3172 or die_error
(undef, "Reading git-diff-tree failed");
3174 or die_error
('404 Not Found', "Blob diff not found");
3176 } elsif (defined $hash &&
3177 $hash =~ /[0-9a-fA-F]{40}/) {
3178 # try to find filename from $hash
3180 # read filtered raw output
3181 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
3182 or die_error
(undef, "Open git-diff-tree failed");
3184 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3186 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3187 map { chomp; $_ } <$fd>;
3189 or die_error
(undef, "Reading git-diff-tree failed");
3191 or die_error
('404 Not Found', "Blob diff not found");
3194 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3197 if (@difftree > 1) {
3198 die_error
('404 Not Found', "Ambiguous blob diff specification");
3201 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3202 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3203 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3205 $hash_parent ||= $diffinfo{'from_id'};
3206 $hash ||= $diffinfo{'to_id'};
3208 # non-textual hash id's can be cached
3209 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3210 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3215 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3216 '-p', $hash_parent_base, $hash_base,
3218 or die_error
(undef, "Open git-diff-tree failed");
3221 # old/legacy style URI
3222 if (!%diffinfo && # if new style URI failed
3223 defined $hash && defined $hash_parent) {
3224 # fake git-diff-tree raw output
3225 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3226 $diffinfo{'from_id'} = $hash_parent;
3227 $diffinfo{'to_id'} = $hash;
3228 if (defined $file_name) {
3229 if (defined $file_parent) {
3230 $diffinfo{'status'} = '2';
3231 $diffinfo{'from_file'} = $file_parent;
3232 $diffinfo{'to_file'} = $file_name;
3233 } else { # assume not renamed
3234 $diffinfo{'status'} = '1';
3235 $diffinfo{'from_file'} = $file_name;
3236 $diffinfo{'to_file'} = $file_name;
3238 } else { # no filename given
3239 $diffinfo{'status'} = '2';
3240 $diffinfo{'from_file'} = $hash_parent;
3241 $diffinfo{'to_file'} = $hash;
3244 # non-textual hash id's can be cached
3245 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3246 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3251 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts, $hash_parent, $hash
3252 or die_error
(undef, "Open git-diff failed");
3254 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3259 if ($format eq 'html') {
3261 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3262 hash
=>$hash, hash_parent
=>$hash_parent,
3263 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3264 file_name
=>$file_name, file_parent
=>$file_parent)},
3266 git_header_html
(undef, $expires);
3267 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3268 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3269 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3271 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3272 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3274 if (defined $file_name) {
3275 git_print_page_path
($file_name, "blob", $hash_base);
3277 print "<div class=\"page_path\"></div>\n";
3280 } elsif ($format eq 'plain') {
3282 -type
=> 'text/plain',
3283 -charset
=> 'utf-8',
3284 -expires
=> $expires,
3285 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3287 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3290 die_error
(undef, "Unknown blobdiff format");
3294 if ($format eq 'html') {
3295 print "<div class=\"page_body\">\n";
3297 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3300 print "</div>\n"; # class="page_body"
3304 while (my $line = <$fd>) {
3305 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_html($diffinfo{'from_file'})!eg;
3306 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_html($diffinfo{'to_file'})!eg;
3310 last if $line =~ m!^\+\+\+!;
3318 sub git_blobdiff_plain
{
3319 git_blobdiff
('plain');
3322 sub git_commitdiff
{
3323 my $format = shift || 'html';
3324 my %co = parse_commit
($hash);
3326 die_error
(undef, "Unknown commit object");
3328 if (!defined $hash_parent) {
3329 $hash_parent = $co{'parent'} || '--root';
3335 if ($format eq 'html') {
3336 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3337 "--patch-with-raw", "--full-index", $hash_parent, $hash
3338 or die_error
(undef, "Open git-diff-tree failed");
3340 while (chomp(my $line = <$fd>)) {
3341 # empty line ends raw part of diff-tree output
3343 push @difftree, $line;
3346 } elsif ($format eq 'plain') {
3347 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3348 '-p', $hash_parent, $hash
3349 or die_error
(undef, "Open git-diff-tree failed");
3352 die_error
(undef, "Unknown commitdiff format");
3355 # non-textual hash id's can be cached
3357 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3361 # write commit message
3362 if ($format eq 'html') {
3363 my $refs = git_get_references
();
3364 my $ref = format_ref_marker
($refs, $co{'id'});
3366 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3367 hash
=>$hash, hash_parent
=>$hash_parent)},
3370 git_header_html
(undef, $expires);
3371 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3372 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3373 git_print_authorship
(\
%co);
3374 print "<div class=\"page_body\">\n";
3375 print "<div class=\"log\">\n";
3376 git_print_simplified_log
($co{'comment'}, 1); # skip title
3377 print "</div>\n"; # class="log"
3379 } elsif ($format eq 'plain') {
3380 my $refs = git_get_references
("tags");
3381 my $tagname = git_get_rev_name_tags
($hash);
3382 my $filename = basename
($project) . "-$hash.patch";
3385 -type
=> 'text/plain',
3386 -charset
=> 'utf-8',
3387 -expires
=> $expires,
3388 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3389 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3392 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3393 Subject: $co{'title'}
3395 print "X-Git-Tag: $tagname\n" if $tagname;
3396 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3398 foreach my $line (@{$co{'comment'}}) {
3405 if ($format eq 'html') {
3406 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3409 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3411 print "</div>\n"; # class="page_body"
3414 } elsif ($format eq 'plain') {
3418 or print "Reading git-diff-tree failed\n";
3422 sub git_commitdiff_plain
{
3423 git_commitdiff
('plain');
3427 if (!defined $hash_base) {
3428 $hash_base = git_get_head_hash
($project);
3430 if (!defined $page) {
3434 my %co = parse_commit
($hash_base);
3436 die_error
(undef, "Unknown commit object");
3439 my $refs = git_get_references
();
3440 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3442 if (!defined $hash && defined $file_name) {
3443 $hash = git_get_hash_by_path
($hash_base, $file_name);
3445 if (defined $hash) {
3446 $ftype = git_get_type
($hash);
3450 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3451 or die_error
(undef, "Open git-rev-list-failed");
3452 my @revlist = map { chomp; $_ } <$fd>;
3454 or die_error
(undef, "Reading git-rev-list failed");
3456 my $paging_nav = '';
3459 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3460 file_name
=>$file_name)},
3462 $paging_nav .= " ⋅ " .
3463 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3464 file_name
=>$file_name, page
=>$page-1),
3465 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3467 $paging_nav .= "first";
3468 $paging_nav .= " ⋅ prev";
3470 if ($#revlist >= (100 * ($page+1)-1)) {
3471 $paging_nav .= " ⋅ " .
3472 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3473 file_name
=>$file_name, page
=>$page+1),
3474 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3476 $paging_nav .= " ⋅ next";
3479 if ($#revlist >= (100 * ($page+1)-1)) {
3481 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3482 file_name
=>$file_name, page
=>$page+1),
3483 -title
=> "Alt-n"}, "next");
3487 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3488 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3489 git_print_page_path
($file_name, $ftype, $hash_base);
3491 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3492 $refs, $hash_base, $ftype, $next_link);
3498 if (!defined $searchtext) {
3499 die_error
(undef, "Text field empty");
3501 if (!defined $hash) {
3502 $hash = git_get_head_hash
($project);
3504 my %co = parse_commit
($hash);
3506 die_error
(undef, "Unknown commit object");
3509 my $commit_search = 1;
3510 my $author_search = 0;
3511 my $committer_search = 0;
3512 my $pickaxe_search = 0;
3513 if ($searchtext =~ s/^author\\://i) {
3515 } elsif ($searchtext =~ s/^committer\\://i) {
3516 $committer_search = 1;
3517 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3519 $pickaxe_search = 1;
3521 # pickaxe may take all resources of your box and run for several minutes
3522 # with every query - so decide by yourself how public you make this feature
3523 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3524 if (!$have_pickaxe) {
3525 die_error
('403 Permission denied', "Permission denied");
3529 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3530 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3532 print "<table cellspacing=\"0\">\n";
3534 if ($commit_search) {
3536 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", $hash or next;
3537 while (my $commit_text = <$fd>) {
3538 if (!grep m/$searchtext/i, $commit_text) {
3541 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3544 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3547 my @commit_lines = split "\n", $commit_text;
3548 my %co = parse_commit
(undef, \
@commit_lines);
3553 print "<tr class=\"dark\">\n";
3555 print "<tr class=\"light\">\n";
3558 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3559 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3561 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3562 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3563 my $comment = $co{'comment'};
3564 foreach my $line (@$comment) {
3565 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3566 my $lead = esc_html
($1) || "";
3567 $lead = chop_str
($lead, 30, 10);
3568 my $match = esc_html
($2) || "";
3569 my $trail = esc_html
($3) || "";
3570 $trail = chop_str
($trail, 30, 10);
3571 my $text = "$lead<span class=\"match\">$match</span>$trail";
3572 print chop_str
($text, 80, 5) . "<br/>\n";
3576 "<td class=\"link\">" .
3577 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3579 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3586 if ($pickaxe_search) {
3588 my $git_command = git_cmd_str
();
3589 open my $fd, "-|", "$git_command rev-list $hash | " .
3590 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3593 while (my $line = <$fd>) {
3594 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3597 $set{'from_id'} = $3;
3599 $set{'id'} = $set{'to_id'};
3600 if ($set{'id'} =~ m/0{40}/) {
3601 $set{'id'} = $set{'from_id'};
3603 if ($set{'id'} =~ m/0{40}/) {
3607 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3610 print "<tr class=\"dark\">\n";
3612 print "<tr class=\"light\">\n";
3615 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3616 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3618 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3619 -class => "list subject"},
3620 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3621 while (my $setref = shift @files) {
3623 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3624 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3626 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3630 "<td class=\"link\">" .
3631 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3633 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3637 %co = parse_commit
($1);
3647 my $head = git_get_head_hash
($project);
3648 if (!defined $hash) {
3651 if (!defined $page) {
3654 my $refs = git_get_references
();
3656 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3657 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3658 or die_error
(undef, "Open git-rev-list failed");
3659 my @revlist = map { chomp; $_ } <$fd>;
3662 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3664 if ($#revlist >= (100 * ($page+1)-1)) {
3666 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3667 -title
=> "Alt-n"}, "next");
3672 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3673 git_print_header_div
('summary', $project);
3675 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3680 ## ......................................................................
3681 ## feeds (RSS, OPML)
3684 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3685 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150", git_get_head_hash
($project)
3686 or die_error
(undef, "Open git-rev-list failed");
3687 my @revlist = map { chomp; $_ } <$fd>;
3688 close $fd or die_error
(undef, "Reading git-rev-list failed");
3689 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3691 <?xml version="1.0" encoding="utf-8"?>
3692 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3694 <title>$project $my_uri $my_url</title>
3695 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3696 <description>$project log</description>
3697 <language>en</language>
3700 for (my $i = 0; $i <= $#revlist; $i++) {
3701 my $commit = $revlist[$i];
3702 my %co = parse_commit
($commit);
3703 # we read 150, we always show 30 and the ones more recent than 48 hours
3704 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3707 my %cd = parse_date
($co{'committer_epoch'});
3708 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3709 $co{'parent'}, $co{'id'}
3711 my @difftree = map { chomp; $_ } <$fd>;
3716 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3718 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3719 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3720 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3721 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3722 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3723 "<content:encoded>" .
3725 my $comment = $co{'comment'};
3726 foreach my $line (@$comment) {
3727 $line = to_utf8
($line);
3728 print "$line<br/>\n";
3731 foreach my $line (@difftree) {
3732 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3735 my $file = esc_html
(unquote
($7));
3736 $file = to_utf8
($file);
3737 print "$file<br/>\n";
3740 "</content:encoded>\n" .
3743 print "</channel></rss>";
3747 my @list = git_get_projects_list
();
3749 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3751 <?xml version="1.0" encoding="utf-8"?>
3752 <opml version="1.0">
3754 <title>$site_name Git OPML Export</title>
3757 <outline text="git RSS feeds">
3760 foreach my $pr (@list) {
3762 my $head = git_get_head_hash
($proj{'path'});
3763 if (!defined $head) {
3766 $git_dir = "$projectroot/$proj{'path'}";
3767 my %co = parse_commit
($head);
3772 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3773 my $rss = "$my_url?p=$proj{'path'};a=rss";
3774 my $html = "$my_url?p=$proj{'path'};a=summary";
3775 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";