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
58 our $logo = "++GITWEB_LOGO++";
59 # URI of GIT favicon, assumed to be image/png type
60 our $favicon = "++GITWEB_FAVICON++";
62 # source of projects list
63 our $projects_list = "++GITWEB_LIST++";
65 # show repository only if this file exists
66 # (only effective if this variable evaluates to true)
67 our $export_ok = "++GITWEB_EXPORT_OK++";
69 # only allow viewing of repositories also shown on the overview page
70 our $strict_export = "++GITWEB_STRICT_EXPORT++";
72 # list of git base URLs used for URL to where fetch project from,
73 # i.e. full URL is "$git_base_url/$project"
74 our @git_base_url_list = ("++GITWEB_BASE_URL++");
76 # default blob_plain mimetype and default charset for text/plain blob
77 our $default_blob_plain_mimetype = 'text/plain';
78 our $default_text_plain_charset = undef;
80 # file to use for guessing MIME types before trying /etc/mime.types
81 # (relative to the current git repository)
82 our $mimetypes_file = undef;
84 # You define site-wide feature defaults here; override them with
85 # $GITWEB_CONFIG as necessary.
88 # 'sub' => feature-sub (subroutine),
89 # 'override' => allow-override (boolean),
90 # 'default' => [ default options...] (array reference)}
92 # if feature is overridable (it means that allow-override has true value,
93 # then feature-sub will be called with default options as parameters;
94 # return value of feature-sub indicates if to enable specified feature
96 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
99 'sub' => \
&feature_blame
,
104 'sub' => \
&feature_snapshot
,
106 # => [content-encoding, suffix, program]
107 'default' => ['x-gzip', 'gz', 'gzip']},
110 'sub' => \
&feature_pickaxe
,
119 sub gitweb_check_feature
{
121 return unless exists $feature{$name};
122 my ($sub, $override, @defaults) = (
123 $feature{$name}{'sub'},
124 $feature{$name}{'override'},
125 @{$feature{$name}{'default'}});
126 if (!$override) { return @defaults; }
128 warn "feature $name is not overrideable";
131 return $sub->(@defaults);
134 # To enable system wide have in $GITWEB_CONFIG
135 # $feature{'blame'}{'default'} = [1];
136 # To have project specific config enable override in $GITWEB_CONFIG
137 # $feature{'blame'}{'override'} = 1;
138 # and in project config gitweb.blame = 0|1;
141 my ($val) = git_get_project_config
('blame', '--bool');
143 if ($val eq 'true') {
145 } elsif ($val eq 'false') {
152 # To disable system wide have in $GITWEB_CONFIG
153 # $feature{'snapshot'}{'default'} = [undef];
154 # To have project specific config enable override in $GITWEB_CONFIG
155 # $feature{'blame'}{'override'} = 1;
156 # and in project config gitweb.snapshot = none|gzip|bzip2
158 sub feature_snapshot
{
159 my ($ctype, $suffix, $command) = @_;
161 my ($val) = git_get_project_config
('snapshot');
163 if ($val eq 'gzip') {
164 return ('x-gzip', 'gz', 'gzip');
165 } elsif ($val eq 'bzip2') {
166 return ('x-bzip2', 'bz2', 'bzip2');
167 } elsif ($val eq 'none') {
171 return ($ctype, $suffix, $command);
174 sub gitweb_have_snapshot
{
175 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
176 my $have_snapshot = (defined $ctype && defined $suffix);
178 return $have_snapshot;
181 # To enable system wide have in $GITWEB_CONFIG
182 # $feature{'pickaxe'}{'default'} = [1];
183 # To have project specific config enable override in $GITWEB_CONFIG
184 # $feature{'pickaxe'}{'override'} = 1;
185 # and in project config gitweb.pickaxe = 0|1;
187 sub feature_pickaxe
{
188 my ($val) = git_get_project_config
('pickaxe', '--bool');
190 if ($val eq 'true') {
192 } elsif ($val eq 'false') {
199 # checking HEAD file with -e is fragile if the repository was
200 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
202 sub check_head_link
{
204 my $headfile = "$dir/HEAD";
205 return ((-e
$headfile) ||
206 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
209 sub check_export_ok
{
211 return (check_head_link
($dir) &&
212 (!$export_ok || -e
"$dir/$export_ok"));
215 # rename detection options for git-diff and git-diff-tree
216 # - default is '-M', with the cost proportional to
217 # (number of removed files) * (number of new files).
218 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
219 # (number of changed files + number of removed files) * (number of new files)
220 # - even more costly is '-C', '--find-copies-harder' with cost
221 # (number of files in the original tree) * (number of new files)
222 # - one might want to include '-B' option, e.g. '-B', '-M'
223 our @diff_opts = ('-M'); # taken from git_commit
225 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
226 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
228 # version of the core git binary
229 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
231 $projects_list ||= $projectroot;
233 # ======================================================================
234 # input validation and dispatch
235 our $action = $cgi->param('a');
236 if (defined $action) {
237 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
238 die_error
(undef, "Invalid action parameter");
242 # parameters which are pathnames
243 our $project = $cgi->param('p');
244 if (defined $project) {
245 if (!validate_pathname
($project) ||
246 !(-d
"$projectroot/$project") ||
247 !check_head_link
("$projectroot/$project") ||
248 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
249 ($strict_export && !project_in_list
($project))) {
251 die_error
(undef, "No such project");
255 our $file_name = $cgi->param('f');
256 if (defined $file_name) {
257 if (!validate_pathname
($file_name)) {
258 die_error
(undef, "Invalid file parameter");
262 our $file_parent = $cgi->param('fp');
263 if (defined $file_parent) {
264 if (!validate_pathname
($file_parent)) {
265 die_error
(undef, "Invalid file parent parameter");
269 # parameters which are refnames
270 our $hash = $cgi->param('h');
272 if (!validate_refname
($hash)) {
273 die_error
(undef, "Invalid hash parameter");
277 our $hash_parent = $cgi->param('hp');
278 if (defined $hash_parent) {
279 if (!validate_refname
($hash_parent)) {
280 die_error
(undef, "Invalid hash parent parameter");
284 our $hash_base = $cgi->param('hb');
285 if (defined $hash_base) {
286 if (!validate_refname
($hash_base)) {
287 die_error
(undef, "Invalid hash base parameter");
291 our $hash_parent_base = $cgi->param('hpb');
292 if (defined $hash_parent_base) {
293 if (!validate_refname
($hash_parent_base)) {
294 die_error
(undef, "Invalid hash parent base parameter");
299 our $page = $cgi->param('pg');
301 if ($page =~ m/[^0-9]/) {
302 die_error
(undef, "Invalid page parameter");
306 our $searchtext = $cgi->param('s');
307 if (defined $searchtext) {
308 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
309 die_error
(undef, "Invalid search parameter");
311 $searchtext = quotemeta $searchtext;
314 # now read PATH_INFO and use it as alternative to parameters
315 sub evaluate_path_info
{
316 return if defined $project;
317 my $path_info = $ENV{"PATH_INFO"};
318 return if !$path_info;
319 $path_info =~ s
,^/+,,;
320 return if !$path_info;
321 # find which part of PATH_INFO is project
322 $project = $path_info;
324 while ($project && !check_head_link
("$projectroot/$project")) {
325 $project =~ s
,/*[^/]*$,,;
328 $project = validate_pathname
($project);
330 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
331 ($strict_export && !project_in_list
($project))) {
335 # do not change any parameters if an action is given using the query string
337 $path_info =~ s
,^$project/*,,;
338 my ($refname, $pathname) = split(/:/, $path_info, 2);
339 if (defined $pathname) {
340 # we got "project.git/branch:filename" or "project.git/branch:dir/"
341 # we could use git_get_type(branch:pathname), but it needs $git_dir
342 $pathname =~ s
,^/+,,;
343 if (!$pathname || substr($pathname, -1) eq "/") {
347 $action ||= "blob_plain";
349 $hash_base ||= validate_refname
($refname);
350 $file_name ||= validate_pathname
($pathname);
351 } elsif (defined $refname) {
352 # we got "project.git/branch"
353 $action ||= "shortlog";
354 $hash ||= validate_refname
($refname);
357 evaluate_path_info
();
359 # path to the current git repository
361 $git_dir = "$projectroot/$project" if $project;
365 "blame" => \
&git_blame2
,
366 "blobdiff" => \
&git_blobdiff
,
367 "blobdiff_plain" => \
&git_blobdiff_plain
,
368 "blob" => \
&git_blob
,
369 "blob_plain" => \
&git_blob_plain
,
370 "commitdiff" => \
&git_commitdiff
,
371 "commitdiff_plain" => \
&git_commitdiff_plain
,
372 "commit" => \
&git_commit
,
373 "heads" => \
&git_heads
,
374 "history" => \
&git_history
,
377 "search" => \
&git_search
,
378 "shortlog" => \
&git_shortlog
,
379 "summary" => \
&git_summary
,
381 "tags" => \
&git_tags
,
382 "tree" => \
&git_tree
,
383 "snapshot" => \
&git_snapshot
,
384 # those below don't need $project
385 "opml" => \
&git_opml
,
386 "project_list" => \
&git_project_list
,
387 "project_index" => \
&git_project_index
,
390 if (defined $project) {
391 $action ||= 'summary';
393 $action ||= 'project_list';
395 if (!defined($actions{$action})) {
396 die_error
(undef, "Unknown action");
398 if ($action !~ m/^(opml|project_list|project_index)$/ &&
400 die_error
(undef, "Project needed");
402 $actions{$action}->();
405 ## ======================================================================
420 hash_parent_base
=> "hpb",
425 my %mapping = @mapping;
427 $params{'project'} = $project unless exists $params{'project'};
429 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
431 # use PATH_INFO for project name
432 $href .= "/$params{'project'}" if defined $params{'project'};
433 delete $params{'project'};
435 # Summary just uses the project path URL
436 if (defined $params{'action'} && $params{'action'} eq 'summary') {
437 delete $params{'action'};
441 # now encode the parameters explicitly
443 for (my $i = 0; $i < @mapping; $i += 2) {
444 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
445 if (defined $params{$name}) {
446 push @result, $symbol . "=" . esc_param
($params{$name});
449 $href .= "?" . join(';', @result) if scalar @result;
455 ## ======================================================================
456 ## validation, quoting/unquoting and escaping
458 sub validate_pathname
{
459 my $input = shift || return undef;
461 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
462 # at the beginning, at the end, and between slashes.
463 # also this catches doubled slashes
464 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
468 if ($input =~ m!\0!) {
474 sub validate_refname
{
475 my $input = shift || return undef;
477 # textual hashes are O.K.
478 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
481 # it must be correct pathname
482 $input = validate_pathname
($input)
484 # restrictions on ref name according to git-check-ref-format
485 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
491 # quote unsafe chars, but keep the slash, even when it's not
492 # correct, but quoted slashes look too horrible in bookmarks
495 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
501 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
504 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
510 # replace invalid utf8 character with SUBSTITUTION sequence
513 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
514 $str = escapeHTML
($str);
515 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
516 $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1)
520 # git may return quoted and escaped filenames
523 if ($str =~ m/^"(.*)"$/) {
525 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
530 # escape tabs (convert tabs to spaces)
534 while ((my $pos = index($line, "\t")) != -1) {
535 if (my $count = (8 - ($pos % 8))) {
536 my $spaces = ' ' x
$count;
537 $line =~ s/\t/$spaces/;
544 sub project_in_list
{
546 my @list = git_get_projects_list
();
547 return @list && scalar(grep { $_->{'path'} eq $project } @list);
550 ## ----------------------------------------------------------------------
551 ## HTML aware string manipulation
556 my $add_len = shift || 10;
558 # allow only $len chars, but don't cut a word if it would fit in $add_len
559 # if it doesn't fit, cut it if it's still longer than the dots we would add
560 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
563 if (length($tail) > 4) {
565 $body =~ s/&[^;]*$//; # remove chopped character entities
570 ## ----------------------------------------------------------------------
571 ## functions returning short strings
573 # CSS class for given age value (in seconds)
577 if ($age < 60*60*2) {
579 } elsif ($age < 60*60*24*2) {
586 # convert age in seconds to "nn units ago" string
591 if ($age > 60*60*24*365*2) {
592 $age_str = (int $age/60/60/24/365);
593 $age_str .= " years ago";
594 } elsif ($age > 60*60*24*(365/12)*2) {
595 $age_str = int $age/60/60/24/(365/12);
596 $age_str .= " months ago";
597 } elsif ($age > 60*60*24*7*2) {
598 $age_str = int $age/60/60/24/7;
599 $age_str .= " weeks ago";
600 } elsif ($age > 60*60*24*2) {
601 $age_str = int $age/60/60/24;
602 $age_str .= " days ago";
603 } elsif ($age > 60*60*2) {
604 $age_str = int $age/60/60;
605 $age_str .= " hours ago";
606 } elsif ($age > 60*2) {
607 $age_str = int $age/60;
608 $age_str .= " min ago";
611 $age_str .= " sec ago";
613 $age_str .= " right now";
618 # convert file mode in octal to symbolic file mode string
620 my $mode = oct shift;
622 if (S_ISDIR
($mode & S_IFMT
)) {
624 } elsif (S_ISLNK
($mode)) {
626 } elsif (S_ISREG
($mode)) {
627 # git cares only about the executable bit
628 if ($mode & S_IXUSR
) {
638 # convert file mode in octal to file type string
642 if ($mode !~ m/^[0-7]+$/) {
648 if (S_ISDIR
($mode & S_IFMT
)) {
650 } elsif (S_ISLNK
($mode)) {
652 } elsif (S_ISREG
($mode)) {
659 ## ----------------------------------------------------------------------
660 ## functions returning short HTML fragments, or transforming HTML fragments
661 ## which don't beling to other sections
663 # format line of commit message or tag comment
664 sub format_log_line_html
{
667 $line = esc_html
($line);
668 $line =~ s/ / /g;
669 if ($line =~ m/([0-9a-fA-F]{40})/) {
671 if (git_get_type
($hash_text) eq "commit") {
673 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
674 -class => "text"}, $hash_text);
675 $line =~ s/$hash_text/$link/;
681 # format marker of refs pointing to given object
682 sub format_ref_marker
{
683 my ($refs, $id) = @_;
686 if (defined $refs->{$id}) {
687 foreach my $ref (@{$refs->{$id}}) {
688 my ($type, $name) = qw();
689 # e.g. tags/v2.6.11 or heads/next
690 if ($ref =~ m!^(.*?)s?/(.*)$!) {
698 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
703 return ' <span class="refs">'. $markers . '</span>';
709 # format, perhaps shortened and with markers, title line
710 sub format_subject_html
{
711 my ($long, $short, $href, $extra) = @_;
712 $extra = '' unless defined($extra);
714 if (length($short) < length($long)) {
715 return $cgi->a({-href
=> $href, -class => "list subject",
716 -title
=> decode
("utf8", $long, Encode
::FB_DEFAULT
)},
717 esc_html
($short) . $extra);
719 return $cgi->a({-href
=> $href, -class => "list subject"},
720 esc_html
($long) . $extra);
724 sub format_diff_line
{
726 my $char = substr($line, 0, 1);
732 $diff_class = " add";
733 } elsif ($char eq "-") {
734 $diff_class = " rem";
735 } elsif ($char eq "@") {
736 $diff_class = " chunk_header";
737 } elsif ($char eq "\\") {
738 $diff_class = " incomplete";
740 $line = untabify
($line);
741 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
744 ## ----------------------------------------------------------------------
745 ## git utility subroutines, invoking git commands
747 # returns path to the core git executable and the --git-dir parameter as list
749 return $GIT, '--git-dir='.$git_dir;
752 # returns path to the core git executable and the --git-dir parameter as string
754 return join(' ', git_cmd
());
757 # get HEAD ref of given project as hash
758 sub git_get_head_hash
{
760 my $o_git_dir = $git_dir;
762 $git_dir = "$projectroot/$project";
763 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
766 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
770 if (defined $o_git_dir) {
771 $git_dir = $o_git_dir;
776 # get type of given object
780 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
787 sub git_get_project_config
{
788 my ($key, $type) = @_;
790 return unless ($key);
791 $key =~ s/^gitweb\.//;
792 return if ($key =~ m/\W/);
794 my @x = (git_cmd
(), 'repo-config');
795 if (defined $type) { push @x, $type; }
797 push @x, "gitweb.$key";
803 # get hash of given path at given ref
804 sub git_get_hash_by_path
{
806 my $path = shift || return undef;
811 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
812 or die_error
(undef, "Open git-ls-tree failed");
814 close $fd or return undef;
816 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
817 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
818 if (defined $type && $type ne $2) {
825 ## ......................................................................
826 ## git utility functions, directly accessing git repository
828 sub git_get_project_description
{
831 open my $fd, "$projectroot/$path/description" or return undef;
838 sub git_get_project_url_list
{
841 open my $fd, "$projectroot/$path/cloneurl" or return;
842 my @git_project_url_list = map { chomp; $_ } <$fd>;
845 return wantarray ? @git_project_url_list : \
@git_project_url_list;
848 sub git_get_projects_list
{
851 if (-d
$projects_list) {
852 # search in directory
853 my $dir = $projects_list;
854 my $pfxlen = length("$dir");
857 follow_fast
=> 1, # follow symbolic links
858 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
860 # skip project-list toplevel, if we get it.
861 return if (m!^[/.]$!);
862 # only directories can be git repositories
863 return unless (-d
$_);
865 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
866 # we check related file in $projectroot
867 if (check_export_ok
("$projectroot/$subdir")) {
868 push @list, { path
=> $subdir };
869 $File::Find
::prune
= 1;
874 } elsif (-f
$projects_list) {
875 # read from file(url-encoded):
876 # 'git%2Fgit.git Linus+Torvalds'
877 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
878 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
879 open my ($fd), $projects_list or return;
880 while (my $line = <$fd>) {
882 my ($path, $owner) = split ' ', $line;
883 $path = unescape
($path);
884 $owner = unescape
($owner);
885 if (!defined $path) {
888 if (check_export_ok
("$projectroot/$path")) {
891 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
898 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
902 sub git_get_project_owner
{
906 return undef unless $project;
908 # read from file (url-encoded):
909 # 'git%2Fgit.git Linus+Torvalds'
910 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
911 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
912 if (-f
$projects_list) {
913 open (my $fd , $projects_list);
914 while (my $line = <$fd>) {
916 my ($pr, $ow) = split ' ', $line;
919 if ($pr eq $project) {
920 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
926 if (!defined $owner) {
927 $owner = get_file_owner
("$projectroot/$project");
933 sub git_get_references
{
934 my $type = shift || "";
936 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
937 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
938 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
941 while (my $line = <$fd>) {
943 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
944 if (defined $refs{$1}) {
945 push @{$refs{$1}}, $2;
955 sub git_get_rev_name_tags
{
956 my $hash = shift || return undef;
958 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
960 my $name_rev = <$fd>;
963 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
966 # catches also '$hash undefined' output
971 ## ----------------------------------------------------------------------
972 ## parse to hash functions
976 my $tz = shift || "-0000";
979 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
980 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
981 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
982 $date{'hour'} = $hour;
983 $date{'minute'} = $min;
984 $date{'mday'} = $mday;
985 $date{'day'} = $days[$wday];
986 $date{'month'} = $months[$mon];
987 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
988 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
989 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
990 $mday, $months[$mon], $hour ,$min;
992 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
993 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
994 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
995 $date{'hour_local'} = $hour;
996 $date{'minute_local'} = $min;
997 $date{'tz_local'} = $tz;
1006 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1007 $tag{'id'} = $tag_id;
1008 while (my $line = <$fd>) {
1010 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1011 $tag{'object'} = $1;
1012 } elsif ($line =~ m/^type (.+)$/) {
1014 } elsif ($line =~ m/^tag (.+)$/) {
1016 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1017 $tag{'author'} = $1;
1020 } elsif ($line =~ m/--BEGIN/) {
1021 push @comment, $line;
1023 } elsif ($line eq "") {
1027 push @comment, <$fd>;
1028 $tag{'comment'} = \
@comment;
1029 close $fd or return;
1030 if (!defined $tag{'name'}) {
1037 my $commit_id = shift;
1038 my $commit_text = shift;
1043 if (defined $commit_text) {
1044 @commit_lines = @$commit_text;
1047 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
1049 @commit_lines = split '\n', <$fd>;
1050 close $fd or return;
1054 my $header = shift @commit_lines;
1055 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1058 ($co{'id'}, my @parents) = split ' ', $header;
1059 $co{'parents'} = \
@parents;
1060 $co{'parent'} = $parents[0];
1061 while (my $line = shift @commit_lines) {
1062 last if $line eq "\n";
1063 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1065 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1067 $co{'author_epoch'} = $2;
1068 $co{'author_tz'} = $3;
1069 if ($co{'author'} =~ m/^([^<]+) </) {
1070 $co{'author_name'} = $1;
1072 $co{'author_name'} = $co{'author'};
1074 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1075 $co{'committer'} = $1;
1076 $co{'committer_epoch'} = $2;
1077 $co{'committer_tz'} = $3;
1078 $co{'committer_name'} = $co{'committer'};
1079 $co{'committer_name'} =~ s/ <.*//;
1082 if (!defined $co{'tree'}) {
1086 foreach my $title (@commit_lines) {
1089 $co{'title'} = chop_str
($title, 80, 5);
1090 # remove leading stuff of merges to make the interesting part visible
1091 if (length($title) > 50) {
1092 $title =~ s/^Automatic //;
1093 $title =~ s/^merge (of|with) /Merge ... /i;
1094 if (length($title) > 50) {
1095 $title =~ s/(http|rsync):\/\///;
1097 if (length($title) > 50) {
1098 $title =~ s/(master|www|rsync)\.//;
1100 if (length($title) > 50) {
1101 $title =~ s/kernel.org:?//;
1103 if (length($title) > 50) {
1104 $title =~ s/\/pub\/scm//;
1107 $co{'title_short'} = chop_str
($title, 50, 5);
1111 # remove added spaces
1112 foreach my $line (@commit_lines) {
1115 $co{'comment'} = \
@commit_lines;
1117 my $age = time - $co{'committer_epoch'};
1119 $co{'age_string'} = age_string
($age);
1120 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1121 if ($age > 60*60*24*7*2) {
1122 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1123 $co{'age_string_age'} = $co{'age_string'};
1125 $co{'age_string_date'} = $co{'age_string'};
1126 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1131 # parse ref from ref_file, given by ref_id, with given type
1133 my $ref_file = shift;
1135 my $type = shift || git_get_type
($ref_id);
1138 $ref_item{'type'} = $type;
1139 $ref_item{'id'} = $ref_id;
1140 $ref_item{'epoch'} = 0;
1141 $ref_item{'age'} = "unknown";
1142 if ($type eq "tag") {
1143 my %tag = parse_tag
($ref_id);
1144 $ref_item{'comment'} = $tag{'comment'};
1145 if ($tag{'type'} eq "commit") {
1146 my %co = parse_commit
($tag{'object'});
1147 $ref_item{'epoch'} = $co{'committer_epoch'};
1148 $ref_item{'age'} = $co{'age_string'};
1149 } elsif (defined($tag{'epoch'})) {
1150 my $age = time - $tag{'epoch'};
1151 $ref_item{'epoch'} = $tag{'epoch'};
1152 $ref_item{'age'} = age_string
($age);
1154 $ref_item{'reftype'} = $tag{'type'};
1155 $ref_item{'name'} = $tag{'name'};
1156 $ref_item{'refid'} = $tag{'object'};
1157 } elsif ($type eq "commit"){
1158 my %co = parse_commit
($ref_id);
1159 $ref_item{'reftype'} = "commit";
1160 $ref_item{'name'} = $ref_file;
1161 $ref_item{'title'} = $co{'title'};
1162 $ref_item{'refid'} = $ref_id;
1163 $ref_item{'epoch'} = $co{'committer_epoch'};
1164 $ref_item{'age'} = $co{'age_string'};
1166 $ref_item{'reftype'} = $type;
1167 $ref_item{'name'} = $ref_file;
1168 $ref_item{'refid'} = $ref_id;
1174 # parse line of git-diff-tree "raw" output
1175 sub parse_difftree_raw_line
{
1179 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1180 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1181 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1182 $res{'from_mode'} = $1;
1183 $res{'to_mode'} = $2;
1184 $res{'from_id'} = $3;
1186 $res{'status'} = $5;
1187 $res{'similarity'} = $6;
1188 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1189 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1191 $res{'file'} = unquote
($7);
1194 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1195 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1196 $res{'commit'} = $1;
1199 return wantarray ? %res : \
%res;
1202 # parse line of git-ls-tree output
1203 sub parse_ls_tree_line
($;%) {
1208 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1209 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1217 $res{'name'} = unquote
($4);
1220 return wantarray ? %res : \
%res;
1223 ## ......................................................................
1224 ## parse to array of hashes functions
1226 sub git_get_refs_list
{
1227 my $type = shift || "";
1232 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1234 while (my $line = <$fd>) {
1236 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?([^\^]+))(\^\{\})?$/) {
1237 if (defined $refs{$1}) {
1238 push @{$refs{$1}}, $2;
1243 if (! $4) { # unpeeled, direct reference
1244 push @refs, { hash
=> $1, name
=> $3 }; # without type
1245 } elsif ($3 eq $refs[-1]{'name'}) {
1246 # most likely a tag is followed by its peeled
1247 # (deref) one, and when that happens we know the
1248 # previous one was of type 'tag'.
1249 $refs[-1]{'type'} = "tag";
1255 foreach my $ref (@refs) {
1256 my $ref_file = $ref->{'name'};
1257 my $ref_id = $ref->{'hash'};
1259 my $type = $ref->{'type'} || git_get_type
($ref_id) || next;
1260 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1262 push @reflist, \
%ref_item;
1265 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1266 return (\
@reflist, \
%refs);
1269 ## ----------------------------------------------------------------------
1270 ## filesystem-related functions
1272 sub get_file_owner
{
1275 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1276 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1277 if (!defined $gcos) {
1281 $owner =~ s/[,;].*$//;
1282 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
1285 ## ......................................................................
1286 ## mimetype related functions
1288 sub mimetype_guess_file
{
1289 my $filename = shift;
1290 my $mimemap = shift;
1291 -r
$mimemap or return undef;
1294 open(MIME
, $mimemap) or return undef;
1296 next if m/^#/; # skip comments
1297 my ($mime, $exts) = split(/\t+/);
1298 if (defined $exts) {
1299 my @exts = split(/\s+/, $exts);
1300 foreach my $ext (@exts) {
1301 $mimemap{$ext} = $mime;
1307 $filename =~ /\.([^.]*)$/;
1308 return $mimemap{$1};
1311 sub mimetype_guess
{
1312 my $filename = shift;
1314 $filename =~ /\./ or return undef;
1316 if ($mimetypes_file) {
1317 my $file = $mimetypes_file;
1318 if ($file !~ m!^/!) { # if it is relative path
1319 # it is relative to project
1320 $file = "$projectroot/$project/$file";
1322 $mime = mimetype_guess_file
($filename, $file);
1324 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1330 my $filename = shift;
1333 my $mime = mimetype_guess
($filename);
1334 $mime and return $mime;
1338 return $default_blob_plain_mimetype unless $fd;
1341 return 'text/plain' .
1342 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1343 } elsif (! $filename) {
1344 return 'application/octet-stream';
1345 } elsif ($filename =~ m/\.png$/i) {
1347 } elsif ($filename =~ m/\.gif$/i) {
1349 } elsif ($filename =~ m/\.jpe?g$/i) {
1350 return 'image/jpeg';
1352 return 'application/octet-stream';
1356 ## ======================================================================
1357 ## functions printing HTML: header, footer, error page
1359 sub git_header_html
{
1360 my $status = shift || "200 OK";
1361 my $expires = shift;
1363 my $title = "$site_name git";
1364 if (defined $project) {
1365 $title .= " - $project";
1366 if (defined $action) {
1367 $title .= "/$action";
1368 if (defined $file_name) {
1369 $title .= " - " . esc_html
($file_name);
1370 if ($action eq "tree" && $file_name !~ m
|/$|) {
1377 # require explicit support from the UA if we are to send the page as
1378 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1379 # we have to do this because MSIE sometimes globs '*/*', pretending to
1380 # support xhtml+xml but choking when it gets what it asked for.
1381 if (defined $cgi->http('HTTP_ACCEPT') &&
1382 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1383 $cgi->Accept('application/xhtml+xml') != 0) {
1384 $content_type = 'application/xhtml+xml';
1386 $content_type = 'text/html';
1388 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1389 -status
=> $status, -expires
=> $expires);
1391 <?xml version="1.0" encoding="utf-8"?>
1392 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1393 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1394 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1395 <!-- git core binaries version $git_version -->
1397 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1398 <meta name="generator" content="gitweb/$version git/$git_version"/>
1399 <meta name="robots" content="index, nofollow"/>
1400 <title>$title</title>
1402 # print out each stylesheet that exist
1403 if (defined $stylesheet) {
1404 #provides backwards capability for those people who define style sheet in a config file
1405 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1407 foreach my $stylesheet (@stylesheets) {
1408 next unless $stylesheet;
1409 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1412 if (defined $project) {
1413 printf('<link rel="alternate" title="%s log" '.
1414 'href="%s" type="application/rss+xml"/>'."\n",
1415 esc_param
($project), href
(action
=>"rss"));
1417 printf('<link rel="alternate" title="%s projects list" '.
1418 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1419 $site_name, href
(project
=>undef, action
=>"project_index"));
1420 printf('<link rel="alternate" title="%s projects logs" '.
1421 'href="%s" type="text/x-opml"/>'."\n",
1422 $site_name, href
(project
=>undef, action
=>"opml"));
1424 if (defined $favicon) {
1425 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1431 if (-f
$site_header) {
1432 open (my $fd, $site_header);
1437 print "<div class=\"page_header\">\n" .
1438 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1439 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1441 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1442 if (defined $project) {
1443 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1444 if (defined $action) {
1448 if (!defined $searchtext) {
1452 if (defined $hash_base) {
1453 $search_hash = $hash_base;
1454 } elsif (defined $hash) {
1455 $search_hash = $hash;
1457 $search_hash = "HEAD";
1459 $cgi->param("a", "search");
1460 $cgi->param("h", $search_hash);
1461 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1462 "<div class=\"search\">\n" .
1463 $cgi->hidden(-name
=> "p") . "\n" .
1464 $cgi->hidden(-name
=> "a") . "\n" .
1465 $cgi->hidden(-name
=> "h") . "\n" .
1466 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1468 $cgi->end_form() . "\n";
1473 sub git_footer_html
{
1474 print "<div class=\"page_footer\">\n";
1475 if (defined $project) {
1476 my $descr = git_get_project_description
($project);
1477 if (defined $descr) {
1478 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1480 print $cgi->a({-href
=> href
(action
=>"rss"),
1481 -class => "rss_logo"}, "RSS") . "\n";
1483 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1484 -class => "rss_logo"}, "OPML") . " ";
1485 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1486 -class => "rss_logo"}, "TXT") . "\n";
1490 if (-f
$site_footer) {
1491 open (my $fd, $site_footer);
1501 my $status = shift || "403 Forbidden";
1502 my $error = shift || "Malformed query, file missing or permission denied";
1504 git_header_html
($status);
1506 <div class="page_body">
1516 ## ----------------------------------------------------------------------
1517 ## functions printing or outputting HTML: navigation
1519 sub git_print_page_nav
{
1520 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1521 $extra = '' if !defined $extra; # pager or formats
1523 my @navs = qw(summary shortlog log commit commitdiff tree);
1525 @navs = grep { $_ ne $suppress } @navs;
1528 my %arg = map { $_ => {action
=>$_} } @navs;
1529 if (defined $head) {
1530 for (qw(commit commitdiff)) {
1531 $arg{$_}{hash
} = $head;
1533 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1534 for (qw(shortlog log)) {
1535 $arg{$_}{hash
} = $head;
1539 $arg{tree
}{hash
} = $treehead if defined $treehead;
1540 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1542 print "<div class=\"page_nav\">\n" .
1544 map { $_ eq $current ?
1545 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1547 print "<br/>\n$extra<br/>\n" .
1551 sub format_paging_nav
{
1552 my ($action, $hash, $head, $page, $nrevs) = @_;
1556 if ($hash ne $head || $page) {
1557 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1559 $paging_nav .= "HEAD";
1563 $paging_nav .= " ⋅ " .
1564 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1565 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1567 $paging_nav .= " ⋅ prev";
1570 if ($nrevs >= (100 * ($page+1)-1)) {
1571 $paging_nav .= " ⋅ " .
1572 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1573 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1575 $paging_nav .= " ⋅ next";
1581 ## ......................................................................
1582 ## functions printing or outputting HTML: div
1584 sub git_print_header_div
{
1585 my ($action, $title, $hash, $hash_base) = @_;
1588 $args{action
} = $action;
1589 $args{hash
} = $hash if $hash;
1590 $args{hash_base
} = $hash_base if $hash_base;
1592 print "<div class=\"header\">\n" .
1593 $cgi->a({-href
=> href
(%args), -class => "title"},
1594 $title ? $title : $action) .
1598 #sub git_print_authorship (\%) {
1599 sub git_print_authorship
{
1602 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1603 print "<div class=\"author_date\">" .
1604 esc_html
($co->{'author_name'}) .
1606 if ($ad{'hour_local'} < 6) {
1607 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1608 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1610 printf(" (%02d:%02d %s)",
1611 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1616 sub git_print_page_path
{
1621 if (!defined $name) {
1622 print "<div class=\"page_path\">/</div>\n";
1624 my @dirname = split '/', $name;
1625 my $basename = pop @dirname;
1628 print "<div class=\"page_path\">";
1629 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1630 -title
=> 'tree root'}, "[$project]");
1632 foreach my $dir (@dirname) {
1633 $fullname .= ($fullname ? '/' : '') . $dir;
1634 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1636 -title
=> $fullname}, esc_html
($dir));
1639 if (defined $type && $type eq 'blob') {
1640 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1642 -title
=> $name}, esc_html
($basename));
1643 } elsif (defined $type && $type eq 'tree') {
1644 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1646 -title
=> $name}, esc_html
($basename));
1648 print esc_html
($basename);
1650 print "<br/></div>\n";
1654 # sub git_print_log (\@;%) {
1655 sub git_print_log
($;%) {
1659 if ($opts{'-remove_title'}) {
1660 # remove title, i.e. first line of log
1663 # remove leading empty lines
1664 while (defined $log->[0] && $log->[0] eq "") {
1671 foreach my $line (@$log) {
1672 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1675 if (! $opts{'-remove_signoff'}) {
1676 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1679 # remove signoff lines
1686 # print only one empty line
1687 # do not print empty line after signoff
1689 next if ($empty || $signoff);
1695 print format_log_line_html
($line) . "<br/>\n";
1698 if ($opts{'-final_empty_line'}) {
1699 # end with single empty line
1700 print "<br/>\n" unless $empty;
1704 sub git_print_simplified_log
{
1706 my $remove_title = shift;
1709 -final_empty_line
=> 1,
1710 -remove_title
=> $remove_title);
1713 # print tree entry (row of git_tree), but without encompassing <tr> element
1714 sub git_print_tree_entry
{
1715 my ($t, $basedir, $hash_base, $have_blame) = @_;
1718 $base_key{hash_base
} = $hash_base if defined $hash_base;
1720 # The format of a table row is: mode list link. Where mode is
1721 # the mode of the entry, list is the name of the entry, an href,
1722 # and link is the action links of the entry.
1724 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1725 if ($t->{'type'} eq "blob") {
1726 print "<td class=\"list\">" .
1727 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1728 file_name
=>"$basedir$t->{'name'}", %base_key),
1729 -class => "list"}, esc_html
($t->{'name'})) . "</td>\n";
1730 print "<td class=\"link\">";
1732 print $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1733 file_name
=>"$basedir$t->{'name'}", %base_key)},
1736 if (defined $hash_base) {
1740 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1741 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1745 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
1746 file_name
=>"$basedir$t->{'name'}")},
1750 } elsif ($t->{'type'} eq "tree") {
1751 print "<td class=\"list\">";
1752 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1753 file_name
=>"$basedir$t->{'name'}", %base_key)},
1754 esc_html
($t->{'name'}));
1756 print "<td class=\"link\">";
1757 if (defined $hash_base) {
1758 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1759 file_name
=>"$basedir$t->{'name'}")},
1766 ## ......................................................................
1767 ## functions printing large fragments of HTML
1769 sub git_difftree_body
{
1770 my ($difftree, $hash, $parent) = @_;
1772 print "<div class=\"list_head\">\n";
1773 if ($#{$difftree} > 10) {
1774 print(($#{$difftree} + 1) . " files changed:\n");
1778 print "<table class=\"diff_tree\">\n";
1781 foreach my $line (@{$difftree}) {
1782 my %diff = parse_difftree_raw_line
($line);
1785 print "<tr class=\"dark\">\n";
1787 print "<tr class=\"light\">\n";
1791 my ($to_mode_oct, $to_mode_str, $to_file_type);
1792 my ($from_mode_oct, $from_mode_str, $from_file_type);
1793 if ($diff{'to_mode'} ne ('0' x
6)) {
1794 $to_mode_oct = oct $diff{'to_mode'};
1795 if (S_ISREG
($to_mode_oct)) { # only for regular file
1796 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1798 $to_file_type = file_type
($diff{'to_mode'});
1800 if ($diff{'from_mode'} ne ('0' x
6)) {
1801 $from_mode_oct = oct $diff{'from_mode'};
1802 if (S_ISREG
($to_mode_oct)) { # only for regular file
1803 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1805 $from_file_type = file_type
($diff{'from_mode'});
1808 if ($diff{'status'} eq "A") { # created
1809 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1810 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1811 $mode_chng .= "]</span>";
1813 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1814 hash_base
=>$hash, file_name
=>$diff{'file'}),
1815 -class => "list"}, esc_html
($diff{'file'}));
1817 print "<td>$mode_chng</td>\n";
1818 print "<td class=\"link\">";
1819 if ($action eq 'commitdiff') {
1822 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1826 } elsif ($diff{'status'} eq "D") { # deleted
1827 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1829 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1830 hash_base
=>$parent, file_name
=>$diff{'file'}),
1831 -class => "list"}, esc_html
($diff{'file'}));
1833 print "<td>$mode_chng</td>\n";
1834 print "<td class=\"link\">";
1835 if ($action eq 'commitdiff') {
1838 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1841 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1842 file_name
=>$diff{'file'})},
1844 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1845 file_name
=>$diff{'file'})},
1849 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1850 my $mode_chnge = "";
1851 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1852 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1853 if ($from_file_type != $to_file_type) {
1854 $mode_chnge .= " from $from_file_type to $to_file_type";
1856 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1857 if ($from_mode_str && $to_mode_str) {
1858 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1859 } elsif ($to_mode_str) {
1860 $mode_chnge .= " mode: $to_mode_str";
1863 $mode_chnge .= "]</span>\n";
1866 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1867 hash_base
=>$hash, file_name
=>$diff{'file'}),
1868 -class => "list"}, esc_html
($diff{'file'}));
1870 print "<td>$mode_chnge</td>\n";
1871 print "<td class=\"link\">";
1872 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1873 if ($action eq 'commitdiff') {
1876 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1878 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1879 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1880 hash_base
=>$hash, hash_parent_base
=>$parent,
1881 file_name
=>$diff{'file'})},
1886 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
1887 file_name
=>$diff{'file'})},
1889 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
1890 file_name
=>$diff{'file'})},
1894 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1895 my %status_name = ('R' => 'moved', 'C' => 'copied');
1896 my $nstatus = $status_name{$diff{'status'}};
1898 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1899 # mode also for directories, so we cannot use $to_mode_str
1900 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1903 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1904 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1905 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1906 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1907 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1908 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1909 -class => "list"}, esc_html
($diff{'from_file'})) .
1910 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1911 "<td class=\"link\">";
1912 if ($diff{'to_id'} ne $diff{'from_id'}) {
1913 if ($action eq 'commitdiff') {
1916 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1918 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1919 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1920 hash_base
=>$hash, hash_parent_base
=>$parent,
1921 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1926 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1927 file_name
=>$diff{'from_file'})},
1929 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1930 file_name
=>$diff{'from_file'})},
1934 } # we should not encounter Unmerged (U) or Unknown (X) status
1940 sub git_patchset_body
{
1941 my ($fd, $difftree, $hash, $hash_parent) = @_;
1945 my $patch_found = 0;
1948 print "<div class=\"patchset\">\n";
1951 while (my $patch_line = <$fd>) {
1954 if ($patch_line =~ m/^diff /) { # "git diff" header
1955 # beginning of patch (in patchset)
1957 # close previous patch
1958 print "</div>\n"; # class="patch"
1960 # first patch in patchset
1963 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1965 if (ref($difftree->[$patch_idx]) eq "HASH") {
1966 $diffinfo = $difftree->[$patch_idx];
1968 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1972 # for now, no extended header, hence we skip empty patches
1973 # companion to next LINE if $in_header;
1974 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1979 if ($diffinfo->{'status'} eq "A") { # added
1980 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1981 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1982 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1983 $diffinfo->{'to_id'}) . "(new)" .
1984 "</div>\n"; # class="diff_info"
1986 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1987 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
1988 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1989 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1990 $diffinfo->{'from_id'}) . "(deleted)" .
1991 "</div>\n"; # class="diff_info"
1993 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1994 $diffinfo->{'status'} eq "C" || # copied
1995 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1996 print "<div class=\"diff_info\">" .
1997 file_type
($diffinfo->{'from_mode'}) . ":" .
1998 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1999 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
2000 $diffinfo->{'from_id'}) .
2002 file_type
($diffinfo->{'to_mode'}) . ":" .
2003 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2004 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
2005 $diffinfo->{'to_id'});
2006 print "</div>\n"; # class="diff_info"
2008 } else { # modified, mode changed, ...
2009 print "<div class=\"diff_info\">" .
2010 file_type
($diffinfo->{'from_mode'}) . ":" .
2011 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2012 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2013 $diffinfo->{'from_id'}) .
2015 file_type
($diffinfo->{'to_mode'}) . ":" .
2016 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2017 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2018 $diffinfo->{'to_id'});
2019 print "</div>\n"; # class="diff_info"
2022 #print "<div class=\"diff extended_header\">\n";
2025 } # start of patch in patchset
2028 if ($in_header && $patch_line =~ m/^---/) {
2029 #print "</div>\n"; # class="diff extended_header"
2032 my $file = $diffinfo->{'from_file'};
2033 $file ||= $diffinfo->{'file'};
2034 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2035 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
2036 -class => "list"}, esc_html
($file));
2037 $patch_line =~ s
|a
/.*$|a/$file|g
;
2038 print "<div class=\"diff from_file\">$patch_line</div>\n";
2040 $patch_line = <$fd>;
2043 #$patch_line =~ m/^+++/;
2044 $file = $diffinfo->{'to_file'};
2045 $file ||= $diffinfo->{'file'};
2046 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2047 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
2048 -class => "list"}, esc_html
($file));
2049 $patch_line =~ s
|b
/.*|b/$file|g
;
2050 print "<div class=\"diff to_file\">$patch_line</div>\n";
2054 next LINE
if $in_header;
2056 print format_diff_line
($patch_line);
2058 print "</div>\n" if $patch_found; # class="patch"
2060 print "</div>\n"; # class="patchset"
2063 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2065 sub git_shortlog_body
{
2066 # uses global variable $project
2067 my ($revlist, $from, $to, $refs, $extra) = @_;
2069 $from = 0 unless defined $from;
2070 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2072 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2074 for (my $i = $from; $i <= $to; $i++) {
2075 my $commit = $revlist->[$i];
2076 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2077 my $ref = format_ref_marker
($refs, $commit);
2078 my %co = parse_commit
($commit);
2080 print "<tr class=\"dark\">\n";
2082 print "<tr class=\"light\">\n";
2085 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2086 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2087 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2089 print format_subject_html
($co{'title'}, $co{'title_short'},
2090 href
(action
=>"commit", hash
=>$commit), $ref);
2092 "<td class=\"link\">" .
2093 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2094 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") . " | " .
2095 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2099 if (defined $extra) {
2101 "<td colspan=\"4\">$extra</td>\n" .
2107 sub git_history_body
{
2108 # Warning: assumes constant type (blob or tree) during history
2109 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2111 $from = 0 unless defined $from;
2112 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2114 print "<table class=\"history\" cellspacing=\"0\">\n";
2116 for (my $i = $from; $i <= $to; $i++) {
2117 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2122 my %co = parse_commit
($commit);
2127 my $ref = format_ref_marker
($refs, $commit);
2130 print "<tr class=\"dark\">\n";
2132 print "<tr class=\"light\">\n";
2135 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2136 # shortlog uses chop_str($co{'author_name'}, 10)
2137 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2139 # originally git_history used chop_str($co{'title'}, 50)
2140 print format_subject_html
($co{'title'}, $co{'title_short'},
2141 href
(action
=>"commit", hash
=>$commit), $ref);
2143 "<td class=\"link\">" .
2144 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2145 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2147 if ($ftype eq 'blob') {
2148 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2149 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2150 if (defined $blob_current && defined $blob_parent &&
2151 $blob_current ne $blob_parent) {
2153 $cgi->a({-href
=> href
(action
=>"blobdiff",
2154 hash
=>$blob_current, hash_parent
=>$blob_parent,
2155 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2156 file_name
=>$file_name)},
2163 if (defined $extra) {
2165 "<td colspan=\"4\">$extra</td>\n" .
2172 # uses global variable $project
2173 my ($taglist, $from, $to, $extra) = @_;
2174 $from = 0 unless defined $from;
2175 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2177 print "<table class=\"tags\" cellspacing=\"0\">\n";
2179 for (my $i = $from; $i <= $to; $i++) {
2180 my $entry = $taglist->[$i];
2182 my $comment_lines = $tag{'comment'};
2183 my $comment = shift @$comment_lines;
2185 if (defined $comment) {
2186 $comment_short = chop_str
($comment, 30, 5);
2189 print "<tr class=\"dark\">\n";
2191 print "<tr class=\"light\">\n";
2194 print "<td><i>$tag{'age'}</i></td>\n" .
2196 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2197 -class => "list name"}, esc_html
($tag{'name'})) .
2200 if (defined $comment) {
2201 print format_subject_html
($comment, $comment_short,
2202 href
(action
=>"tag", hash
=>$tag{'id'}));
2205 "<td class=\"selflink\">";
2206 if ($tag{'type'} eq "tag") {
2207 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2212 "<td class=\"link\">" . " | " .
2213 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2214 if ($tag{'reftype'} eq "commit") {
2215 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2216 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
2217 } elsif ($tag{'reftype'} eq "blob") {
2218 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2223 if (defined $extra) {
2225 "<td colspan=\"5\">$extra</td>\n" .
2231 sub git_heads_body
{
2232 # uses global variable $project
2233 my ($headlist, $head, $from, $to, $extra) = @_;
2234 $from = 0 unless defined $from;
2235 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2237 print "<table class=\"heads\" cellspacing=\"0\">\n";
2239 for (my $i = $from; $i <= $to; $i++) {
2240 my $entry = $headlist->[$i];
2242 my $curr = $tag{'id'} eq $head;
2244 print "<tr class=\"dark\">\n";
2246 print "<tr class=\"light\">\n";
2249 print "<td><i>$tag{'age'}</i></td>\n" .
2250 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
2251 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
2252 -class => "list name"},esc_html
($tag{'name'})) .
2254 "<td class=\"link\">" .
2255 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
2256 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") . " | " .
2257 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$tag{'name'}, hash_base
=>$tag{'name'})}, "tree") .
2261 if (defined $extra) {
2263 "<td colspan=\"3\">$extra</td>\n" .
2269 ## ======================================================================
2270 ## ======================================================================
2273 sub git_project_list
{
2274 my $order = $cgi->param('o');
2275 if (defined $order && $order !~ m/project|descr|owner|age/) {
2276 die_error
(undef, "Unknown order parameter");
2279 my @list = git_get_projects_list
();
2282 die_error
(undef, "No projects found");
2284 foreach my $pr (@list) {
2285 my $head = git_get_head_hash
($pr->{'path'});
2286 if (!defined $head) {
2289 $git_dir = "$projectroot/$pr->{'path'}";
2290 my %co = parse_commit
($head);
2294 $pr->{'commit'} = \
%co;
2295 if (!defined $pr->{'descr'}) {
2296 my $descr = git_get_project_description
($pr->{'path'}) || "";
2297 $pr->{'descr'} = chop_str
($descr, 25, 5);
2299 if (!defined $pr->{'owner'}) {
2300 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2302 push @projects, $pr;
2306 if (-f
$home_text) {
2307 print "<div class=\"index_include\">\n";
2308 open (my $fd, $home_text);
2313 print "<table class=\"project_list\">\n" .
2315 $order ||= "project";
2316 if ($order eq "project") {
2317 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2318 print "<th>Project</th>\n";
2321 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2322 -class => "header"}, "Project") .
2325 if ($order eq "descr") {
2326 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2327 print "<th>Description</th>\n";
2330 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2331 -class => "header"}, "Description") .
2334 if ($order eq "owner") {
2335 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2336 print "<th>Owner</th>\n";
2339 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2340 -class => "header"}, "Owner") .
2343 if ($order eq "age") {
2344 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2345 print "<th>Last Change</th>\n";
2348 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2349 -class => "header"}, "Last Change") .
2352 print "<th></th>\n" .
2355 foreach my $pr (@projects) {
2357 print "<tr class=\"dark\">\n";
2359 print "<tr class=\"light\">\n";
2362 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2363 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2364 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2365 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2366 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2367 $pr->{'commit'}{'age_string'} . "</td>\n" .
2368 "<td class=\"link\">" .
2369 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2370 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2371 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2372 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2380 sub git_project_index
{
2381 my @projects = git_get_projects_list
();
2384 -type
=> 'text/plain',
2385 -charset
=> 'utf-8',
2386 -content_disposition
=> 'inline; filename="index.aux"');
2388 foreach my $pr (@projects) {
2389 if (!exists $pr->{'owner'}) {
2390 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2393 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2394 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2395 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2396 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2400 print "$path $owner\n";
2405 my $descr = git_get_project_description
($project) || "none";
2406 my $head = git_get_head_hash
($project);
2407 my %co = parse_commit
($head);
2408 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2410 my $owner = git_get_project_owner
($project);
2412 my ($reflist, $refs) = git_get_refs_list
();
2416 foreach my $ref (@$reflist) {
2417 if ($ref->{'name'} =~ s!^heads/!!) {
2418 push @headlist, $ref;
2420 $ref->{'name'} =~ s!^tags/!!;
2421 push @taglist, $ref;
2426 git_print_page_nav
('summary','', $head);
2428 print "<div class=\"title\"> </div>\n";
2429 print "<table cellspacing=\"0\">\n" .
2430 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2431 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2432 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2433 # use per project git URL list in $projectroot/$project/cloneurl
2434 # or make project git URL from git base URL and project name
2435 my $url_tag = "URL";
2436 my @url_list = git_get_project_url_list
($project);
2437 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2438 foreach my $git_url (@url_list) {
2439 next unless $git_url;
2440 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2445 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2446 git_get_head_hash
($project)
2447 or die_error
(undef, "Open git-rev-list failed");
2448 my @revlist = map { chomp; $_ } <$fd>;
2450 git_print_header_div
('shortlog');
2451 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2452 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2455 git_print_header_div
('tags');
2456 git_tags_body
(\
@taglist, 0, 15,
2457 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2461 git_print_header_div
('heads');
2462 git_heads_body
(\
@headlist, $head, 0, 15,
2463 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2470 my $head = git_get_head_hash
($project);
2472 git_print_page_nav
('','', $head,undef,$head);
2473 my %tag = parse_tag
($hash);
2474 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2475 print "<div class=\"title_text\">\n" .
2476 "<table cellspacing=\"0\">\n" .
2478 "<td>object</td>\n" .
2479 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2480 $tag{'object'}) . "</td>\n" .
2481 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2482 $tag{'type'}) . "</td>\n" .
2484 if (defined($tag{'author'})) {
2485 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2486 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2487 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2488 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2491 print "</table>\n\n" .
2493 print "<div class=\"page_body\">";
2494 my $comment = $tag{'comment'};
2495 foreach my $line (@$comment) {
2496 print esc_html
($line) . "<br/>\n";
2506 my ($have_blame) = gitweb_check_feature
('blame');
2508 die_error
('403 Permission denied', "Permission denied");
2510 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2511 $hash_base ||= git_get_head_hash
($project);
2512 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2513 my %co = parse_commit
($hash_base)
2514 or die_error
(undef, "Reading commit failed");
2515 if (!defined $hash) {
2516 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2517 or die_error
(undef, "Error looking up file");
2519 $ftype = git_get_type
($hash);
2520 if ($ftype !~ "blob") {
2521 die_error
("400 Bad Request", "Object is not a blob");
2523 open ($fd, "-|", git_cmd
(), "blame", '-l', '--', $file_name, $hash_base)
2524 or die_error
(undef, "Open git-blame failed");
2527 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2530 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2533 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2535 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2536 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2537 git_print_page_path
($file_name, $ftype, $hash_base);
2538 my @rev_color = (qw(light2 dark2));
2539 my $num_colors = scalar(@rev_color);
2540 my $current_color = 0;
2543 <div class="page_body">
2544 <table class="blame">
2545 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2548 my ($full_rev, $author, $date, $lineno, $data) =
2549 /^([0-9a-f]{40}).*?\s\((.*?)\s+([-\d]+ [:\d]+ [-+\d]+)\s+(\d+)\)\s(.*)/;
2550 my $rev = substr($full_rev, 0, 8);
2553 if (!defined $last_rev) {
2554 $last_rev = $full_rev;
2556 } elsif ($last_rev ne $full_rev) {
2557 $last_rev = $full_rev;
2558 $current_color = ++$current_color % $num_colors;
2561 print "<tr class=\"$rev_color[$current_color]\">\n";
2562 print "<td class=\"sha1\"";
2563 if ($print_c8 == 1) {
2564 print " title=\"$author, $date\"";
2567 if ($print_c8 == 1) {
2568 print $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)},
2572 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2573 esc_html
($lineno) . "</a></td>\n";
2574 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2580 or print "Reading blob failed\n";
2587 my ($have_blame) = gitweb_check_feature
('blame');
2589 die_error
('403 Permission denied', "Permission denied");
2591 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2592 $hash_base ||= git_get_head_hash
($project);
2593 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2594 my %co = parse_commit
($hash_base)
2595 or die_error
(undef, "Reading commit failed");
2596 if (!defined $hash) {
2597 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2598 or die_error
(undef, "Error lookup file");
2600 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2601 or die_error
(undef, "Open git-annotate failed");
2604 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2607 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2610 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2612 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2613 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2614 git_print_page_path
($file_name, 'blob', $hash_base);
2615 print "<div class=\"page_body\">\n";
2617 <table class="blame">
2626 my @line_class = (qw(light dark));
2627 my $line_class_len = scalar (@line_class);
2628 my $line_class_num = $#line_class;
2629 while (my $line = <$fd>) {
2641 $line_class_num = ($line_class_num + 1) % $line_class_len;
2643 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2650 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
2653 $short_rev = substr ($long_rev, 0, 8);
2654 $age = time () - $time;
2655 $age_str = age_string
($age);
2656 $age_str =~ s/ / /g;
2657 $age_class = age_class
($age);
2658 $author = esc_html
($author);
2659 $author =~ s/ / /g;
2661 $data = untabify
($data);
2662 $data = esc_html
($data);
2665 <tr class="$line_class[$line_class_num]">
2666 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2667 <td class="$age_class">$age_str</td>
2669 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2670 <td class="pre">$data</td>
2673 } # while (my $line = <$fd>)
2674 print "</table>\n\n";
2676 or print "Reading blob failed.\n";
2682 my $head = git_get_head_hash
($project);
2684 git_print_page_nav
('','', $head,undef,$head);
2685 git_print_header_div
('summary', $project);
2687 my ($taglist) = git_get_refs_list
("tags");
2689 git_tags_body
($taglist);
2695 my $head = git_get_head_hash
($project);
2697 git_print_page_nav
('','', $head,undef,$head);
2698 git_print_header_div
('summary', $project);
2700 my ($headlist) = git_get_refs_list
("heads");
2702 git_heads_body
($headlist, $head);
2707 sub git_blob_plain
{
2710 if (!defined $hash) {
2711 if (defined $file_name) {
2712 my $base = $hash_base || git_get_head_hash
($project);
2713 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2714 or die_error
(undef, "Error lookup file");
2716 die_error
(undef, "No file name defined");
2718 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2719 # blobs defined by non-textual hash id's can be cached
2724 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2725 or die_error
(undef, "Couldn't cat $file_name, $hash");
2727 $type ||= blob_mimetype
($fd, $file_name);
2729 # save as filename, even when no $file_name is given
2730 my $save_as = "$hash";
2731 if (defined $file_name) {
2732 $save_as = $file_name;
2733 } elsif ($type =~ m/^text\//) {
2740 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
2742 binmode STDOUT
, ':raw';
2744 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2752 if (!defined $hash) {
2753 if (defined $file_name) {
2754 my $base = $hash_base || git_get_head_hash
($project);
2755 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2756 or die_error
(undef, "Error lookup file");
2758 die_error
(undef, "No file name defined");
2760 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2761 # blobs defined by non-textual hash id's can be cached
2765 my ($have_blame) = gitweb_check_feature
('blame');
2766 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2767 or die_error
(undef, "Couldn't cat $file_name, $hash");
2768 my $mimetype = blob_mimetype
($fd, $file_name);
2769 if ($mimetype !~ m/^text\//) {
2771 return git_blob_plain
($mimetype);
2773 git_header_html
(undef, $expires);
2774 my $formats_nav = '';
2775 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2776 if (defined $file_name) {
2779 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2780 hash
=>$hash, file_name
=>$file_name)},
2785 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2786 hash
=>$hash, file_name
=>$file_name)},
2789 $cgi->a({-href
=> href
(action
=>"blob_plain",
2790 hash
=>$hash, file_name
=>$file_name)},
2793 $cgi->a({-href
=> href
(action
=>"blob",
2794 hash_base
=>"HEAD", file_name
=>$file_name)},
2798 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
2800 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2801 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2803 print "<div class=\"page_nav\">\n" .
2804 "<br/><br/></div>\n" .
2805 "<div class=\"title\">$hash</div>\n";
2807 git_print_page_path
($file_name, "blob", $hash_base);
2808 print "<div class=\"page_body\">\n";
2810 while (my $line = <$fd>) {
2813 $line = untabify
($line);
2814 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2815 $nr, $nr, $nr, esc_html
($line);
2818 or print "Reading blob failed.\n";
2824 my $have_snapshot = gitweb_have_snapshot
();
2826 if (!defined $hash_base) {
2827 $hash_base = "HEAD";
2829 if (!defined $hash) {
2830 if (defined $file_name) {
2831 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
2837 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
2838 or die_error
(undef, "Open git-ls-tree failed");
2839 my @entries = map { chomp; $_ } <$fd>;
2840 close $fd or die_error
(undef, "Reading tree failed");
2843 my $refs = git_get_references
();
2844 my $ref = format_ref_marker
($refs, $hash_base);
2847 my ($have_blame) = gitweb_check_feature
('blame');
2848 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2850 if (defined $file_name) {
2852 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2853 hash
=>$hash, file_name
=>$file_name)},
2855 $cgi->a({-href
=> href
(action
=>"tree",
2856 hash_base
=>"HEAD", file_name
=>$file_name)},
2859 if ($have_snapshot) {
2860 # FIXME: Should be available when we have no hash base as well.
2862 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
2865 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
2866 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2869 print "<div class=\"page_nav\">\n";
2870 print "<br/><br/></div>\n";
2871 print "<div class=\"title\">$hash</div>\n";
2873 if (defined $file_name) {
2874 $base = esc_html
("$file_name/");
2876 git_print_page_path
($file_name, 'tree', $hash_base);
2877 print "<div class=\"page_body\">\n";
2878 print "<table cellspacing=\"0\">\n";
2880 foreach my $line (@entries) {
2881 my %t = parse_ls_tree_line
($line, -z
=> 1);
2884 print "<tr class=\"dark\">\n";
2886 print "<tr class=\"light\">\n";
2890 git_print_tree_entry
(\
%t, $base, $hash_base, $have_blame);
2894 print "</table>\n" .
2900 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2901 my $have_snapshot = (defined $ctype && defined $suffix);
2902 if (!$have_snapshot) {
2903 die_error
('403 Permission denied', "Permission denied");
2906 if (!defined $hash) {
2907 $hash = git_get_head_hash
($project);
2910 my $filename = basename
($project) . "-$hash.tar.$suffix";
2913 -type
=> 'application/x-tar',
2914 -content_encoding
=> $ctype,
2915 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
2916 -status
=> '200 OK');
2918 my $git = git_cmd_str
();
2919 my $name = $project;
2920 $name =~ s/\047/\047\\\047\047/g;
2922 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
2923 or die_error
(undef, "Execute git-tar-tree failed.");
2924 binmode STDOUT
, ':raw';
2926 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2932 my $head = git_get_head_hash
($project);
2933 if (!defined $hash) {
2936 if (!defined $page) {
2939 my $refs = git_get_references
();
2941 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2942 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
2943 or die_error
(undef, "Open git-rev-list failed");
2944 my @revlist = map { chomp; $_ } <$fd>;
2947 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2950 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2953 my %co = parse_commit
($hash);
2955 git_print_header_div
('summary', $project);
2956 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2958 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2959 my $commit = $revlist[$i];
2960 my $ref = format_ref_marker
($refs, $commit);
2961 my %co = parse_commit
($commit);
2963 my %ad = parse_date
($co{'author_epoch'});
2964 git_print_header_div
('commit',
2965 "<span class=\"age\">$co{'age_string'}</span>" .
2966 esc_html
($co{'title'}) . $ref,
2968 print "<div class=\"title_text\">\n" .
2969 "<div class=\"log_link\">\n" .
2970 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2972 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2974 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
2977 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2980 print "<div class=\"log_body\">\n";
2981 git_print_simplified_log
($co{'comment'});
2988 my %co = parse_commit
($hash);
2990 die_error
(undef, "Unknown commit object");
2992 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2993 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2995 my $parent = $co{'parent'};
2996 if (!defined $parent) {
2999 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $parent, $hash
3000 or die_error
(undef, "Open git-diff-tree failed");
3001 my @difftree = map { chomp; $_ } <$fd>;
3002 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3004 # non-textual hash id's can be cached
3006 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3009 my $refs = git_get_references
();
3010 my $ref = format_ref_marker
($refs, $co{'id'});
3012 my $have_snapshot = gitweb_have_snapshot
();
3015 if (defined $file_name && defined $co{'parent'}) {
3017 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
3020 if (defined $co{'parent'}) {
3022 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash)}, "shortlog"),
3023 $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash)}, "log");
3025 git_header_html
(undef, $expires);
3026 git_print_page_nav
('commit', defined $co{'parent'} ? '' : 'commitdiff',
3027 $hash, $co{'tree'}, $hash,
3028 join (' | ', @views_nav));
3030 if (defined $co{'parent'}) {
3031 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3033 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3035 print "<div class=\"title_text\">\n" .
3036 "<table cellspacing=\"0\">\n";
3037 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3039 "<td></td><td> $ad{'rfc2822'}";
3040 if ($ad{'hour_local'} < 6) {
3041 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3042 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3044 printf(" (%02d:%02d %s)",
3045 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3049 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3050 print "<tr><td></td><td> $cd{'rfc2822'}" .
3051 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3053 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3056 "<td class=\"sha1\">" .
3057 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3058 class => "list"}, $co{'tree'}) .
3060 "<td class=\"link\">" .
3061 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3063 if ($have_snapshot) {
3065 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3069 my $parents = $co{'parents'};
3070 foreach my $par (@$parents) {
3073 "<td class=\"sha1\">" .
3074 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3075 class => "list"}, $par) .
3077 "<td class=\"link\">" .
3078 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3080 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3087 print "<div class=\"page_body\">\n";
3088 git_print_log
($co{'comment'});
3091 git_difftree_body
(\
@difftree, $hash, $parent);
3097 my $format = shift || 'html';
3104 # preparing $fd and %diffinfo for git_patchset_body
3106 if (defined $hash_base && defined $hash_parent_base) {
3107 if (defined $file_name) {
3109 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
3111 or die_error
(undef, "Open git-diff-tree failed");
3112 @difftree = map { chomp; $_ } <$fd>;
3114 or die_error
(undef, "Reading git-diff-tree failed");
3116 or die_error
('404 Not Found', "Blob diff not found");
3118 } elsif (defined $hash &&
3119 $hash =~ /[0-9a-fA-F]{40}/) {
3120 # try to find filename from $hash
3122 # read filtered raw output
3123 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
3124 or die_error
(undef, "Open git-diff-tree failed");
3126 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3128 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3129 map { chomp; $_ } <$fd>;
3131 or die_error
(undef, "Reading git-diff-tree failed");
3133 or die_error
('404 Not Found', "Blob diff not found");
3136 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3139 if (@difftree > 1) {
3140 die_error
('404 Not Found', "Ambiguous blob diff specification");
3143 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3144 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3145 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3147 $hash_parent ||= $diffinfo{'from_id'};
3148 $hash ||= $diffinfo{'to_id'};
3150 # non-textual hash id's can be cached
3151 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3152 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3157 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3158 '-p', $hash_parent_base, $hash_base,
3160 or die_error
(undef, "Open git-diff-tree failed");
3163 # old/legacy style URI
3164 if (!%diffinfo && # if new style URI failed
3165 defined $hash && defined $hash_parent) {
3166 # fake git-diff-tree raw output
3167 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3168 $diffinfo{'from_id'} = $hash_parent;
3169 $diffinfo{'to_id'} = $hash;
3170 if (defined $file_name) {
3171 if (defined $file_parent) {
3172 $diffinfo{'status'} = '2';
3173 $diffinfo{'from_file'} = $file_parent;
3174 $diffinfo{'to_file'} = $file_name;
3175 } else { # assume not renamed
3176 $diffinfo{'status'} = '1';
3177 $diffinfo{'from_file'} = $file_name;
3178 $diffinfo{'to_file'} = $file_name;
3180 } else { # no filename given
3181 $diffinfo{'status'} = '2';
3182 $diffinfo{'from_file'} = $hash_parent;
3183 $diffinfo{'to_file'} = $hash;
3186 # non-textual hash id's can be cached
3187 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3188 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3193 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts, $hash_parent, $hash
3194 or die_error
(undef, "Open git-diff failed");
3196 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3201 if ($format eq 'html') {
3203 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3204 hash
=>$hash, hash_parent
=>$hash_parent,
3205 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3206 file_name
=>$file_name, file_parent
=>$file_parent)},
3208 git_header_html
(undef, $expires);
3209 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3210 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3211 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3213 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3214 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3216 if (defined $file_name) {
3217 git_print_page_path
($file_name, "blob", $hash_base);
3219 print "<div class=\"page_path\"></div>\n";
3222 } elsif ($format eq 'plain') {
3224 -type
=> 'text/plain',
3225 -charset
=> 'utf-8',
3226 -expires
=> $expires,
3227 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3229 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3232 die_error
(undef, "Unknown blobdiff format");
3236 if ($format eq 'html') {
3237 print "<div class=\"page_body\">\n";
3239 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3242 print "</div>\n"; # class="page_body"
3246 while (my $line = <$fd>) {
3247 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_html($diffinfo{'from_file'})!eg;
3248 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_html($diffinfo{'to_file'})!eg;
3252 last if $line =~ m!^\+\+\+!;
3260 sub git_blobdiff_plain
{
3261 git_blobdiff
('plain');
3264 sub git_commitdiff
{
3265 my $format = shift || 'html';
3266 my %co = parse_commit
($hash);
3268 die_error
(undef, "Unknown commit object");
3270 if (!defined $hash_parent) {
3271 $hash_parent = $co{'parent'} || '--root';
3277 if ($format eq 'html') {
3278 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3279 "--patch-with-raw", "--full-index", $hash_parent, $hash
3280 or die_error
(undef, "Open git-diff-tree failed");
3282 while (chomp(my $line = <$fd>)) {
3283 # empty line ends raw part of diff-tree output
3285 push @difftree, $line;
3288 } elsif ($format eq 'plain') {
3289 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3290 '-p', $hash_parent, $hash
3291 or die_error
(undef, "Open git-diff-tree failed");
3294 die_error
(undef, "Unknown commitdiff format");
3297 # non-textual hash id's can be cached
3299 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3303 # write commit message
3304 if ($format eq 'html') {
3305 my $refs = git_get_references
();
3306 my $ref = format_ref_marker
($refs, $co{'id'});
3308 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3309 hash
=>$hash, hash_parent
=>$hash_parent)},
3312 git_header_html
(undef, $expires);
3313 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3314 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3315 git_print_authorship
(\
%co);
3316 print "<div class=\"page_body\">\n";
3317 print "<div class=\"log\">\n";
3318 git_print_simplified_log
($co{'comment'}, 1); # skip title
3319 print "</div>\n"; # class="log"
3321 } elsif ($format eq 'plain') {
3322 my $refs = git_get_references
("tags");
3323 my $tagname = git_get_rev_name_tags
($hash);
3324 my $filename = basename
($project) . "-$hash.patch";
3327 -type
=> 'text/plain',
3328 -charset
=> 'utf-8',
3329 -expires
=> $expires,
3330 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3331 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3334 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3335 Subject: $co{'title'}
3337 print "X-Git-Tag: $tagname\n" if $tagname;
3338 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3340 foreach my $line (@{$co{'comment'}}) {
3347 if ($format eq 'html') {
3348 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3351 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3353 print "</div>\n"; # class="page_body"
3356 } elsif ($format eq 'plain') {
3360 or print "Reading git-diff-tree failed\n";
3364 sub git_commitdiff_plain
{
3365 git_commitdiff
('plain');
3369 if (!defined $hash_base) {
3370 $hash_base = git_get_head_hash
($project);
3372 if (!defined $page) {
3376 my %co = parse_commit
($hash_base);
3378 die_error
(undef, "Unknown commit object");
3381 my $refs = git_get_references
();
3382 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3384 if (!defined $hash && defined $file_name) {
3385 $hash = git_get_hash_by_path
($hash_base, $file_name);
3387 if (defined $hash) {
3388 $ftype = git_get_type
($hash);
3392 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3393 or die_error
(undef, "Open git-rev-list-failed");
3394 my @revlist = map { chomp; $_ } <$fd>;
3396 or die_error
(undef, "Reading git-rev-list failed");
3398 my $paging_nav = '';
3401 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3402 file_name
=>$file_name)},
3404 $paging_nav .= " ⋅ " .
3405 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3406 file_name
=>$file_name, page
=>$page-1),
3407 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3409 $paging_nav .= "first";
3410 $paging_nav .= " ⋅ prev";
3412 if ($#revlist >= (100 * ($page+1)-1)) {
3413 $paging_nav .= " ⋅ " .
3414 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3415 file_name
=>$file_name, page
=>$page+1),
3416 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3418 $paging_nav .= " ⋅ next";
3421 if ($#revlist >= (100 * ($page+1)-1)) {
3423 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3424 file_name
=>$file_name, page
=>$page+1),
3425 -title
=> "Alt-n"}, "next");
3429 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3430 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3431 git_print_page_path
($file_name, $ftype, $hash_base);
3433 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3434 $refs, $hash_base, $ftype, $next_link);
3440 if (!defined $searchtext) {
3441 die_error
(undef, "Text field empty");
3443 if (!defined $hash) {
3444 $hash = git_get_head_hash
($project);
3446 my %co = parse_commit
($hash);
3448 die_error
(undef, "Unknown commit object");
3451 my $commit_search = 1;
3452 my $author_search = 0;
3453 my $committer_search = 0;
3454 my $pickaxe_search = 0;
3455 if ($searchtext =~ s/^author\\://i) {
3457 } elsif ($searchtext =~ s/^committer\\://i) {
3458 $committer_search = 1;
3459 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3461 $pickaxe_search = 1;
3463 # pickaxe may take all resources of your box and run for several minutes
3464 # with every query - so decide by yourself how public you make this feature
3465 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3466 if (!$have_pickaxe) {
3467 die_error
('403 Permission denied', "Permission denied");
3471 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3472 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3474 print "<table cellspacing=\"0\">\n";
3476 if ($commit_search) {
3478 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", $hash or next;
3479 while (my $commit_text = <$fd>) {
3480 if (!grep m/$searchtext/i, $commit_text) {
3483 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3486 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3489 my @commit_lines = split "\n", $commit_text;
3490 my %co = parse_commit
(undef, \
@commit_lines);
3495 print "<tr class=\"dark\">\n";
3497 print "<tr class=\"light\">\n";
3500 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3501 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3503 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3504 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3505 my $comment = $co{'comment'};
3506 foreach my $line (@$comment) {
3507 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3508 my $lead = esc_html
($1) || "";
3509 $lead = chop_str
($lead, 30, 10);
3510 my $match = esc_html
($2) || "";
3511 my $trail = esc_html
($3) || "";
3512 $trail = chop_str
($trail, 30, 10);
3513 my $text = "$lead<span class=\"match\">$match</span>$trail";
3514 print chop_str
($text, 80, 5) . "<br/>\n";
3518 "<td class=\"link\">" .
3519 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3521 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3528 if ($pickaxe_search) {
3530 my $git_command = git_cmd_str
();
3531 open my $fd, "-|", "$git_command rev-list $hash | " .
3532 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3535 while (my $line = <$fd>) {
3536 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3539 $set{'from_id'} = $3;
3541 $set{'id'} = $set{'to_id'};
3542 if ($set{'id'} =~ m/0{40}/) {
3543 $set{'id'} = $set{'from_id'};
3545 if ($set{'id'} =~ m/0{40}/) {
3549 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3552 print "<tr class=\"dark\">\n";
3554 print "<tr class=\"light\">\n";
3557 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3558 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3560 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3561 -class => "list subject"},
3562 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3563 while (my $setref = shift @files) {
3565 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3566 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3568 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3572 "<td class=\"link\">" .
3573 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3575 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3579 %co = parse_commit
($1);
3589 my $head = git_get_head_hash
($project);
3590 if (!defined $hash) {
3593 if (!defined $page) {
3596 my $refs = git_get_references
();
3598 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3599 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3600 or die_error
(undef, "Open git-rev-list failed");
3601 my @revlist = map { chomp; $_ } <$fd>;
3604 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3606 if ($#revlist >= (100 * ($page+1)-1)) {
3608 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3609 -title
=> "Alt-n"}, "next");
3614 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3615 git_print_header_div
('summary', $project);
3617 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3622 ## ......................................................................
3623 ## feeds (RSS, OPML)
3626 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3627 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150", git_get_head_hash
($project)
3628 or die_error
(undef, "Open git-rev-list failed");
3629 my @revlist = map { chomp; $_ } <$fd>;
3630 close $fd or die_error
(undef, "Reading git-rev-list failed");
3631 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3633 <?xml version="1.0" encoding="utf-8"?>
3634 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3636 <title>$project $my_uri $my_url</title>
3637 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3638 <description>$project log</description>
3639 <language>en</language>
3642 for (my $i = 0; $i <= $#revlist; $i++) {
3643 my $commit = $revlist[$i];
3644 my %co = parse_commit
($commit);
3645 # we read 150, we always show 30 and the ones more recent than 48 hours
3646 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3649 my %cd = parse_date
($co{'committer_epoch'});
3650 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3651 $co{'parent'}, $co{'id'}
3653 my @difftree = map { chomp; $_ } <$fd>;
3658 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3660 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3661 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3662 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3663 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3664 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3665 "<content:encoded>" .
3667 my $comment = $co{'comment'};
3668 foreach my $line (@$comment) {
3669 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
3670 print "$line<br/>\n";
3673 foreach my $line (@difftree) {
3674 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3677 my $file = esc_html
(unquote
($7));
3678 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
3679 print "$file<br/>\n";
3682 "</content:encoded>\n" .
3685 print "</channel></rss>";
3689 my @list = git_get_projects_list
();
3691 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3693 <?xml version="1.0" encoding="utf-8"?>
3694 <opml version="1.0">
3696 <title>$site_name Git OPML Export</title>
3699 <outline text="git RSS feeds">
3702 foreach my $pr (@list) {
3704 my $head = git_get_head_hash
($proj{'path'});
3705 if (!defined $head) {
3708 $git_dir = "$projectroot/$proj{'path'}";
3709 my %co = parse_commit
($head);
3714 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3715 my $rss = "$my_url?p=$proj{'path'};a=rss";
3716 my $html = "$my_url?p=$proj{'path'};a=summary";
3717 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";