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 our $githelp_url = "http://git.or.cz/";
63 our $githelp_label = "git homepage";
65 # source of projects list
66 our $projects_list = "++GITWEB_LIST++";
68 # show repository only if this file exists
69 # (only effective if this variable evaluates to true)
70 our $export_ok = "++GITWEB_EXPORT_OK++";
72 # only allow viewing of repositories also shown on the overview page
73 our $strict_export = "++GITWEB_STRICT_EXPORT++";
75 # list of git base URLs used for URL to where fetch project from,
76 # i.e. full URL is "$git_base_url/$project"
77 our @git_base_url_list = ("++GITWEB_BASE_URL++");
79 # default blob_plain mimetype and default charset for text/plain blob
80 our $default_blob_plain_mimetype = 'text/plain';
81 our $default_text_plain_charset = undef;
83 # file to use for guessing MIME types before trying /etc/mime.types
84 # (relative to the current git repository)
85 our $mimetypes_file = undef;
87 # You define site-wide feature defaults here; override them with
88 # $GITWEB_CONFIG as necessary.
91 # 'sub' => feature-sub (subroutine),
92 # 'override' => allow-override (boolean),
93 # 'default' => [ default options...] (array reference)}
95 # if feature is overridable (it means that allow-override has true value,
96 # then feature-sub will be called with default options as parameters;
97 # return value of feature-sub indicates if to enable specified feature
99 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
102 'sub' => \
&feature_blame
,
107 'sub' => \
&feature_snapshot
,
109 # => [content-encoding, suffix, program]
110 'default' => ['x-gzip', 'gz', 'gzip']},
113 'sub' => \
&feature_pickaxe
,
118 sub gitweb_check_feature
{
120 return unless exists $feature{$name};
121 my ($sub, $override, @defaults) = (
122 $feature{$name}{'sub'},
123 $feature{$name}{'override'},
124 @
{$feature{$name}{'default'}});
125 if (!$override) { return @defaults; }
126 return $sub->(@defaults);
129 # To enable system wide have in $GITWEB_CONFIG
130 # $feature{'blame'}{'default'} = [1];
131 # To have project specific config enable override in $GITWEB_CONFIG
132 # $feature{'blame'}{'override'} = 1;
133 # and in project config gitweb.blame = 0|1;
136 my ($val) = git_get_project_config
('blame', '--bool');
138 if ($val eq 'true') {
140 } elsif ($val eq 'false') {
147 # To disable system wide have in $GITWEB_CONFIG
148 # $feature{'snapshot'}{'default'} = [undef];
149 # To have project specific config enable override in $GITWEB_CONFIG
150 # $feature{'blame'}{'override'} = 1;
151 # and in project config gitweb.snapshot = none|gzip|bzip2
153 sub feature_snapshot
{
154 my ($ctype, $suffix, $command) = @_;
156 my ($val) = git_get_project_config
('snapshot');
158 if ($val eq 'gzip') {
159 return ('x-gzip', 'gz', 'gzip');
160 } elsif ($val eq 'bzip2') {
161 return ('x-bzip2', 'bz2', 'bzip2');
162 } elsif ($val eq 'none') {
166 return ($ctype, $suffix, $command);
169 sub gitweb_have_snapshot
{
170 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
171 my $have_snapshot = (defined $ctype && defined $suffix);
173 return $have_snapshot;
176 # To enable system wide have in $GITWEB_CONFIG
177 # $feature{'pickaxe'}{'default'} = [1];
178 # To have project specific config enable override in $GITWEB_CONFIG
179 # $feature{'pickaxe'}{'override'} = 1;
180 # and in project config gitweb.pickaxe = 0|1;
182 sub feature_pickaxe
{
183 my ($val) = git_get_project_config
('pickaxe', '--bool');
185 if ($val eq 'true') {
187 } elsif ($val eq 'false') {
194 # checking HEAD file with -e is fragile if the repository was
195 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
197 sub check_head_link
{
199 my $headfile = "$dir/HEAD";
200 return ((-e
$headfile) ||
201 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
204 sub check_export_ok
{
206 return (check_head_link
($dir) &&
207 (!$export_ok || -e
"$dir/$export_ok"));
210 # rename detection options for git-diff and git-diff-tree
211 # - default is '-M', with the cost proportional to
212 # (number of removed files) * (number of new files).
213 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
214 # (number of changed files + number of removed files) * (number of new files)
215 # - even more costly is '-C', '--find-copies-harder' with cost
216 # (number of files in the original tree) * (number of new files)
217 # - one might want to include '-B' option, e.g. '-B', '-M'
218 our @diff_opts = ('-M'); # taken from git_commit
220 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
221 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
223 # version of the core git binary
224 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
226 $projects_list ||= $projectroot;
228 # ======================================================================
229 # input validation and dispatch
230 our $action = $cgi->param('a');
231 if (defined $action) {
232 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
233 die_error
(undef, "Invalid action parameter");
237 # parameters which are pathnames
238 our $project = $cgi->param('p');
239 if (defined $project) {
240 if (!validate_pathname
($project) ||
241 !(-d
"$projectroot/$project") ||
242 !check_head_link
("$projectroot/$project") ||
243 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
244 ($strict_export && !project_in_list
($project))) {
246 die_error
(undef, "No such project");
250 our $file_name = $cgi->param('f');
251 if (defined $file_name) {
252 if (!validate_pathname
($file_name)) {
253 die_error
(undef, "Invalid file parameter");
257 our $file_parent = $cgi->param('fp');
258 if (defined $file_parent) {
259 if (!validate_pathname
($file_parent)) {
260 die_error
(undef, "Invalid file parent parameter");
264 # parameters which are refnames
265 our $hash = $cgi->param('h');
267 if (!validate_refname
($hash)) {
268 die_error
(undef, "Invalid hash parameter");
272 our $hash_parent = $cgi->param('hp');
273 if (defined $hash_parent) {
274 if (!validate_refname
($hash_parent)) {
275 die_error
(undef, "Invalid hash parent parameter");
279 our $hash_base = $cgi->param('hb');
280 if (defined $hash_base) {
281 if (!validate_refname
($hash_base)) {
282 die_error
(undef, "Invalid hash base parameter");
286 our $hash_parent_base = $cgi->param('hpb');
287 if (defined $hash_parent_base) {
288 if (!validate_refname
($hash_parent_base)) {
289 die_error
(undef, "Invalid hash parent base parameter");
294 our $page = $cgi->param('pg');
296 if ($page =~ m/[^0-9]/) {
297 die_error
(undef, "Invalid page parameter");
301 our $searchtext = $cgi->param('s');
302 if (defined $searchtext) {
303 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
304 die_error
(undef, "Invalid search parameter");
306 $searchtext = quotemeta $searchtext;
309 # now read PATH_INFO and use it as alternative to parameters
310 sub evaluate_path_info
{
311 return if defined $project;
312 my $path_info = $ENV{"PATH_INFO"};
313 return if !$path_info;
314 $path_info =~ s
,^/+,,;
315 return if !$path_info;
316 # find which part of PATH_INFO is project
317 $project = $path_info;
319 while ($project && !check_head_link
("$projectroot/$project")) {
320 $project =~ s
,/*[^/]*$,,;
323 $project = validate_pathname
($project);
325 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
326 ($strict_export && !project_in_list
($project))) {
330 # do not change any parameters if an action is given using the query string
332 $path_info =~ s
,^$project/*,,;
333 my ($refname, $pathname) = split(/:/, $path_info, 2);
334 if (defined $pathname) {
335 # we got "project.git/branch:filename" or "project.git/branch:dir/"
336 # we could use git_get_type(branch:pathname), but it needs $git_dir
337 $pathname =~ s
,^/+,,;
338 if (!$pathname || substr($pathname, -1) eq "/") {
342 $action ||= "blob_plain";
344 $hash_base ||= validate_refname
($refname);
345 $file_name ||= validate_pathname
($pathname);
346 } elsif (defined $refname) {
347 # we got "project.git/branch"
348 $action ||= "shortlog";
349 $hash ||= validate_refname
($refname);
352 evaluate_path_info
();
354 # path to the current git repository
356 $git_dir = "$projectroot/$project" if $project;
360 "blame" => \
&git_blame2
,
361 "blobdiff" => \
&git_blobdiff
,
362 "blobdiff_plain" => \
&git_blobdiff_plain
,
363 "blob" => \
&git_blob
,
364 "blob_plain" => \
&git_blob_plain
,
365 "commitdiff" => \
&git_commitdiff
,
366 "commitdiff_plain" => \
&git_commitdiff_plain
,
367 "commit" => \
&git_commit
,
368 "heads" => \
&git_heads
,
369 "history" => \
&git_history
,
372 "search" => \
&git_search
,
373 "shortlog" => \
&git_shortlog
,
374 "summary" => \
&git_summary
,
376 "tags" => \
&git_tags
,
377 "tree" => \
&git_tree
,
378 "snapshot" => \
&git_snapshot
,
379 # those below don't need $project
380 "opml" => \
&git_opml
,
381 "project_list" => \
&git_project_list
,
382 "project_index" => \
&git_project_index
,
385 if (defined $project) {
386 $action ||= 'summary';
388 $action ||= 'project_list';
390 if (!defined($actions{$action})) {
391 die_error
(undef, "Unknown action");
393 if ($action !~ m/^(opml|project_list|project_index)$/ &&
395 die_error
(undef, "Project needed");
397 $actions{$action}->();
400 ## ======================================================================
414 hash_parent_base
=> "hpb",
419 my %mapping = @mapping;
421 $params{'project'} = $project unless exists $params{'project'};
424 for (my $i = 0; $i < @mapping; $i += 2) {
425 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
426 if (defined $params{$name}) {
427 push @result, $symbol . "=" . esc_param
($params{$name});
430 return "$my_uri?" . join(';', @result);
434 ## ======================================================================
435 ## validation, quoting/unquoting and escaping
437 sub validate_pathname
{
438 my $input = shift || return undef;
440 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
441 # at the beginning, at the end, and between slashes.
442 # also this catches doubled slashes
443 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
447 if ($input =~ m!\0!) {
453 sub validate_refname
{
454 my $input = shift || return undef;
456 # textual hashes are O.K.
457 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
460 # it must be correct pathname
461 $input = validate_pathname
($input)
463 # restrictions on ref name according to git-check-ref-format
464 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
470 # quote unsafe chars, but keep the slash, even when it's not
471 # correct, but quoted slashes look too horrible in bookmarks
474 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
480 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
483 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
489 # replace invalid utf8 character with SUBSTITUTION sequence
492 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
493 $str = escapeHTML
($str);
494 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
495 $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1)
499 # git may return quoted and escaped filenames
502 if ($str =~ m/^"(.*)"$/) {
504 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
509 # escape tabs (convert tabs to spaces)
513 while ((my $pos = index($line, "\t")) != -1) {
514 if (my $count = (8 - ($pos % 8))) {
515 my $spaces = ' ' x
$count;
516 $line =~ s/\t/$spaces/;
523 sub project_in_list
{
525 my @list = git_get_projects_list
();
526 return @list && scalar(grep { $_->{'path'} eq $project } @list);
529 ## ----------------------------------------------------------------------
530 ## HTML aware string manipulation
535 my $add_len = shift || 10;
537 # allow only $len chars, but don't cut a word if it would fit in $add_len
538 # if it doesn't fit, cut it if it's still longer than the dots we would add
539 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
542 if (length($tail) > 4) {
544 $body =~ s/&[^;]*$//; # remove chopped character entities
549 ## ----------------------------------------------------------------------
550 ## functions returning short strings
552 # CSS class for given age value (in seconds)
556 if ($age < 60*60*2) {
558 } elsif ($age < 60*60*24*2) {
565 # convert age in seconds to "nn units ago" string
570 if ($age > 60*60*24*365*2) {
571 $age_str = (int $age/60/60/24/365);
572 $age_str .= " years ago";
573 } elsif ($age > 60*60*24*(365/12)*2) {
574 $age_str = int $age/60/60/24/(365/12);
575 $age_str .= " months ago";
576 } elsif ($age > 60*60*24*7*2) {
577 $age_str = int $age/60/60/24/7;
578 $age_str .= " weeks ago";
579 } elsif ($age > 60*60*24*2) {
580 $age_str = int $age/60/60/24;
581 $age_str .= " days ago";
582 } elsif ($age > 60*60*2) {
583 $age_str = int $age/60/60;
584 $age_str .= " hours ago";
585 } elsif ($age > 60*2) {
586 $age_str = int $age/60;
587 $age_str .= " min ago";
590 $age_str .= " sec ago";
592 $age_str .= " right now";
597 # convert file mode in octal to symbolic file mode string
599 my $mode = oct shift;
601 if (S_ISDIR
($mode & S_IFMT
)) {
603 } elsif (S_ISLNK
($mode)) {
605 } elsif (S_ISREG
($mode)) {
606 # git cares only about the executable bit
607 if ($mode & S_IXUSR
) {
617 # convert file mode in octal to file type string
621 if ($mode !~ m/^[0-7]+$/) {
627 if (S_ISDIR
($mode & S_IFMT
)) {
629 } elsif (S_ISLNK
($mode)) {
631 } elsif (S_ISREG
($mode)) {
638 ## ----------------------------------------------------------------------
639 ## functions returning short HTML fragments, or transforming HTML fragments
640 ## which don't beling to other sections
642 # format line of commit message or tag comment
643 sub format_log_line_html
{
646 $line = esc_html
($line);
647 $line =~ s/ / /g;
648 if ($line =~ m/([0-9a-fA-F]{40})/) {
650 if (git_get_type
($hash_text) eq "commit") {
652 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
653 -class => "text"}, $hash_text);
654 $line =~ s/$hash_text/$link/;
660 # format marker of refs pointing to given object
661 sub format_ref_marker
{
662 my ($refs, $id) = @_;
665 if (defined $refs->{$id}) {
666 foreach my $ref (@
{$refs->{$id}}) {
667 my ($type, $name) = qw();
668 # e.g. tags/v2.6.11 or heads/next
669 if ($ref =~ m!^(.*?)s?/(.*)$!) {
677 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
682 return ' <span class="refs">'. $markers . '</span>';
688 # format, perhaps shortened and with markers, title line
689 sub format_subject_html
{
690 my ($long, $short, $href, $extra) = @_;
691 $extra = '' unless defined($extra);
693 if (length($short) < length($long)) {
694 return $cgi->a({-href
=> $href, -class => "list subject",
695 -title
=> decode
("utf8", $long, Encode
::FB_DEFAULT
)},
696 esc_html
($short) . $extra);
698 return $cgi->a({-href
=> $href, -class => "list subject"},
699 esc_html
($long) . $extra);
703 sub format_diff_line
{
705 my $char = substr($line, 0, 1);
711 $diff_class = " add";
712 } elsif ($char eq "-") {
713 $diff_class = " rem";
714 } elsif ($char eq "@") {
715 $diff_class = " chunk_header";
716 } elsif ($char eq "\\") {
717 $diff_class = " incomplete";
719 $line = untabify
($line);
720 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
723 ## ----------------------------------------------------------------------
724 ## git utility subroutines, invoking git commands
726 # returns path to the core git executable and the --git-dir parameter as list
728 return $GIT, '--git-dir='.$git_dir;
731 # returns path to the core git executable and the --git-dir parameter as string
733 return join(' ', git_cmd
());
736 # get HEAD ref of given project as hash
737 sub git_get_head_hash
{
739 my $o_git_dir = $git_dir;
741 $git_dir = "$projectroot/$project";
742 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
745 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
749 if (defined $o_git_dir) {
750 $git_dir = $o_git_dir;
755 # get type of given object
759 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
766 sub git_get_project_config
{
767 my ($key, $type) = @_;
769 return unless ($key);
770 $key =~ s/^gitweb\.//;
771 return if ($key =~ m/\W/);
773 my @x = (git_cmd
(), 'repo-config');
774 if (defined $type) { push @x, $type; }
776 push @x, "gitweb.$key";
782 # get hash of given path at given ref
783 sub git_get_hash_by_path
{
785 my $path = shift || return undef;
790 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
791 or die_error
(undef, "Open git-ls-tree failed");
793 close $fd or return undef;
795 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
796 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
797 if (defined $type && $type ne $2) {
804 ## ......................................................................
805 ## git utility functions, directly accessing git repository
807 sub git_get_project_description
{
810 open my $fd, "$projectroot/$path/description" or return undef;
817 sub git_get_project_url_list
{
820 open my $fd, "$projectroot/$path/cloneurl" or return;
821 my @git_project_url_list = map { chomp; $_ } <$fd>;
824 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
827 sub git_get_projects_list
{
830 if (-d
$projects_list) {
831 # search in directory
832 my $dir = $projects_list;
833 my $pfxlen = length("$dir");
836 follow_fast
=> 1, # follow symbolic links
837 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
839 # skip project-list toplevel, if we get it.
840 return if (m!^[/.]$!);
841 # only directories can be git repositories
842 return unless (-d
$_);
844 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
845 # we check related file in $projectroot
846 if (check_export_ok
("$projectroot/$subdir")) {
847 push @list, { path
=> $subdir };
848 $File::Find
::prune
= 1;
853 } elsif (-f
$projects_list) {
854 # read from file(url-encoded):
855 # 'git%2Fgit.git Linus+Torvalds'
856 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
857 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
858 open my ($fd), $projects_list or return;
859 while (my $line = <$fd>) {
861 my ($path, $owner) = split ' ', $line;
862 $path = unescape
($path);
863 $owner = unescape
($owner);
864 if (!defined $path) {
867 if (check_export_ok
("$projectroot/$path")) {
870 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
877 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
881 sub git_get_project_owner
{
885 return undef unless $project;
887 # read from file (url-encoded):
888 # 'git%2Fgit.git Linus+Torvalds'
889 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
890 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
891 if (-f
$projects_list) {
892 open (my $fd , $projects_list);
893 while (my $line = <$fd>) {
895 my ($pr, $ow) = split ' ', $line;
898 if ($pr eq $project) {
899 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
905 if (!defined $owner) {
906 $owner = get_file_owner
("$projectroot/$project");
912 sub git_get_references
{
913 my $type = shift || "";
915 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
916 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
917 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
920 while (my $line = <$fd>) {
922 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
923 if (defined $refs{$1}) {
924 push @
{$refs{$1}}, $2;
934 sub git_get_rev_name_tags
{
935 my $hash = shift || return undef;
937 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
939 my $name_rev = <$fd>;
942 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
945 # catches also '$hash undefined' output
950 ## ----------------------------------------------------------------------
951 ## parse to hash functions
955 my $tz = shift || "-0000";
958 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
959 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
960 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
961 $date{'hour'} = $hour;
962 $date{'minute'} = $min;
963 $date{'mday'} = $mday;
964 $date{'day'} = $days[$wday];
965 $date{'month'} = $months[$mon];
966 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
967 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
968 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
969 $mday, $months[$mon], $hour ,$min;
971 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
972 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
973 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
974 $date{'hour_local'} = $hour;
975 $date{'minute_local'} = $min;
976 $date{'tz_local'} = $tz;
977 $date{'iso-tz'} = sprintf ("%04d-%02d-%02d %02d:%02d:%02d %s",
978 1900+$year, $mon+1, $mday,
979 $hour, $min, $sec, $tz);
988 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
989 $tag{'id'} = $tag_id;
990 while (my $line = <$fd>) {
992 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
994 } elsif ($line =~ m/^type (.+)$/) {
996 } elsif ($line =~ m/^tag (.+)$/) {
998 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1002 } elsif ($line =~ m/--BEGIN/) {
1003 push @comment, $line;
1005 } elsif ($line eq "") {
1009 push @comment, <$fd>;
1010 $tag{'comment'} = \
@comment;
1011 close $fd or return;
1012 if (!defined $tag{'name'}) {
1019 my $commit_id = shift;
1020 my $commit_text = shift;
1025 if (defined $commit_text) {
1026 @commit_lines = @
$commit_text;
1029 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
1031 @commit_lines = split '\n', <$fd>;
1032 close $fd or return;
1036 my $header = shift @commit_lines;
1037 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1040 ($co{'id'}, my @parents) = split ' ', $header;
1041 $co{'parents'} = \
@parents;
1042 $co{'parent'} = $parents[0];
1043 while (my $line = shift @commit_lines) {
1044 last if $line eq "\n";
1045 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1047 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1049 $co{'author_epoch'} = $2;
1050 $co{'author_tz'} = $3;
1051 if ($co{'author'} =~ m/^([^<]+) </) {
1052 $co{'author_name'} = $1;
1054 $co{'author_name'} = $co{'author'};
1056 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1057 $co{'committer'} = $1;
1058 $co{'committer_epoch'} = $2;
1059 $co{'committer_tz'} = $3;
1060 $co{'committer_name'} = $co{'committer'};
1061 $co{'committer_name'} =~ s/ <.*//;
1064 if (!defined $co{'tree'}) {
1068 foreach my $title (@commit_lines) {
1071 $co{'title'} = chop_str
($title, 80, 5);
1072 # remove leading stuff of merges to make the interesting part visible
1073 if (length($title) > 50) {
1074 $title =~ s/^Automatic //;
1075 $title =~ s/^merge (of|with) /Merge ... /i;
1076 if (length($title) > 50) {
1077 $title =~ s/(http|rsync):\/\///;
1079 if (length($title) > 50) {
1080 $title =~ s/(master|www|rsync)\.//;
1082 if (length($title) > 50) {
1083 $title =~ s/kernel.org:?//;
1085 if (length($title) > 50) {
1086 $title =~ s/\/pub\/scm//;
1089 $co{'title_short'} = chop_str
($title, 50, 5);
1093 # remove added spaces
1094 foreach my $line (@commit_lines) {
1097 $co{'comment'} = \
@commit_lines;
1099 my $age = time - $co{'committer_epoch'};
1101 $co{'age_string'} = age_string
($age);
1102 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1103 if ($age > 60*60*24*7*2) {
1104 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1105 $co{'age_string_age'} = $co{'age_string'};
1107 $co{'age_string_date'} = $co{'age_string'};
1108 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1113 # parse ref from ref_file, given by ref_id, with given type
1115 my $ref_file = shift;
1117 my $type = shift || git_get_type
($ref_id);
1120 $ref_item{'type'} = $type;
1121 $ref_item{'id'} = $ref_id;
1122 $ref_item{'epoch'} = 0;
1123 $ref_item{'age'} = "unknown";
1124 if ($type eq "tag") {
1125 my %tag = parse_tag
($ref_id);
1126 $ref_item{'comment'} = $tag{'comment'};
1127 if ($tag{'type'} eq "commit") {
1128 my %co = parse_commit
($tag{'object'});
1129 $ref_item{'epoch'} = $co{'committer_epoch'};
1130 $ref_item{'age'} = $co{'age_string'};
1131 } elsif (defined($tag{'epoch'})) {
1132 my $age = time - $tag{'epoch'};
1133 $ref_item{'epoch'} = $tag{'epoch'};
1134 $ref_item{'age'} = age_string
($age);
1136 $ref_item{'reftype'} = $tag{'type'};
1137 $ref_item{'name'} = $tag{'name'};
1138 $ref_item{'refid'} = $tag{'object'};
1139 } elsif ($type eq "commit"){
1140 my %co = parse_commit
($ref_id);
1141 $ref_item{'reftype'} = "commit";
1142 $ref_item{'name'} = $ref_file;
1143 $ref_item{'title'} = $co{'title'};
1144 $ref_item{'refid'} = $ref_id;
1145 $ref_item{'epoch'} = $co{'committer_epoch'};
1146 $ref_item{'age'} = $co{'age_string'};
1148 $ref_item{'reftype'} = $type;
1149 $ref_item{'name'} = $ref_file;
1150 $ref_item{'refid'} = $ref_id;
1156 # parse line of git-diff-tree "raw" output
1157 sub parse_difftree_raw_line
{
1161 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1162 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1163 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1164 $res{'from_mode'} = $1;
1165 $res{'to_mode'} = $2;
1166 $res{'from_id'} = $3;
1168 $res{'status'} = $5;
1169 $res{'similarity'} = $6;
1170 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1171 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1173 $res{'file'} = unquote
($7);
1176 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1177 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1178 $res{'commit'} = $1;
1181 return wantarray ?
%res : \
%res;
1184 # parse line of git-ls-tree output
1185 sub parse_ls_tree_line
($;%) {
1190 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1191 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1199 $res{'name'} = unquote
($4);
1202 return wantarray ?
%res : \
%res;
1205 ## ......................................................................
1206 ## parse to array of hashes functions
1208 sub git_get_refs_list
{
1209 my $type = shift || "";
1214 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1216 while (my $line = <$fd>) {
1218 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?([^\^]+))(\^\{\})?$/) {
1219 if (defined $refs{$1}) {
1220 push @
{$refs{$1}}, $2;
1225 if (! $4) { # unpeeled, direct reference
1226 push @refs, { hash
=> $1, name
=> $3 }; # without type
1227 } elsif ($3 eq $refs[-1]{'name'}) {
1228 # most likely a tag is followed by its peeled
1229 # (deref) one, and when that happens we know the
1230 # previous one was of type 'tag'.
1231 $refs[-1]{'type'} = "tag";
1237 foreach my $ref (@refs) {
1238 my $ref_file = $ref->{'name'};
1239 my $ref_id = $ref->{'hash'};
1241 my $type = $ref->{'type'} || git_get_type
($ref_id) || next;
1242 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1244 push @reflist, \
%ref_item;
1247 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1248 return (\
@reflist, \
%refs);
1251 ## ----------------------------------------------------------------------
1252 ## filesystem-related functions
1254 sub get_file_owner
{
1257 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1258 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1259 if (!defined $gcos) {
1263 $owner =~ s/[,;].*$//;
1264 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
1267 ## ......................................................................
1268 ## mimetype related functions
1270 sub mimetype_guess_file
{
1271 my $filename = shift;
1272 my $mimemap = shift;
1273 -r
$mimemap or return undef;
1276 open(MIME
, $mimemap) or return undef;
1278 next if m/^#/; # skip comments
1279 my ($mime, $exts) = split(/\t+/);
1280 if (defined $exts) {
1281 my @exts = split(/\s+/, $exts);
1282 foreach my $ext (@exts) {
1283 $mimemap{$ext} = $mime;
1289 $filename =~ /\.([^.]*)$/;
1290 return $mimemap{$1};
1293 sub mimetype_guess
{
1294 my $filename = shift;
1296 $filename =~ /\./ or return undef;
1298 if ($mimetypes_file) {
1299 my $file = $mimetypes_file;
1300 if ($file !~ m!^/!) { # if it is relative path
1301 # it is relative to project
1302 $file = "$projectroot/$project/$file";
1304 $mime = mimetype_guess_file
($filename, $file);
1306 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1312 my $filename = shift;
1315 my $mime = mimetype_guess
($filename);
1316 $mime and return $mime;
1320 return $default_blob_plain_mimetype unless $fd;
1323 return 'text/plain' .
1324 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1325 } elsif (! $filename) {
1326 return 'application/octet-stream';
1327 } elsif ($filename =~ m/\.png$/i) {
1329 } elsif ($filename =~ m/\.gif$/i) {
1331 } elsif ($filename =~ m/\.jpe?g$/i) {
1332 return 'image/jpeg';
1334 return 'application/octet-stream';
1338 ## ======================================================================
1339 ## functions printing HTML: header, footer, error page
1341 sub git_header_html
{
1342 my $status = shift || "200 OK";
1343 my $expires = shift;
1345 my $title = "$site_name git";
1346 if (defined $project) {
1347 $title .= " - $project";
1348 if (defined $action) {
1349 $title .= "/$action";
1350 if (defined $file_name) {
1351 $title .= " - " . esc_html
($file_name);
1352 if ($action eq "tree" && $file_name !~ m
|/$|) {
1359 # require explicit support from the UA if we are to send the page as
1360 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1361 # we have to do this because MSIE sometimes globs '*/*', pretending to
1362 # support xhtml+xml but choking when it gets what it asked for.
1363 if (defined $cgi->http('HTTP_ACCEPT') &&
1364 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1365 $cgi->Accept('application/xhtml+xml') != 0) {
1366 $content_type = 'application/xhtml+xml';
1368 $content_type = 'text/html';
1370 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1371 -status
=> $status, -expires
=> $expires);
1373 <?xml version="1.0" encoding="utf-8"?>
1374 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1375 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1376 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1377 <!-- git core binaries version $git_version -->
1379 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1380 <meta name="generator" content="gitweb/$version git/$git_version"/>
1381 <meta name="robots" content="index, nofollow"/>
1382 <title>$title</title>
1384 # print out each stylesheet that exist
1385 if (defined $stylesheet) {
1386 #provides backwards capability for those people who define style sheet in a config file
1387 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1389 foreach my $stylesheet (@stylesheets) {
1390 next unless $stylesheet;
1391 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1394 if (defined $project) {
1395 printf('<link rel="alternate" title="%s log" '.
1396 'href="%s" type="application/rss+xml"/>'."\n",
1397 esc_param
($project), href
(action
=>"rss"));
1399 printf('<link rel="alternate" title="%s projects list" '.
1400 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1401 $site_name, href
(project
=>undef, action
=>"project_index"));
1402 printf('<link rel="alternate" title="%s projects logs" '.
1403 'href="%s" type="text/x-opml"/>'."\n",
1404 $site_name, href
(project
=>undef, action
=>"opml"));
1406 if (defined $favicon) {
1407 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
1413 if (-f
$site_header) {
1414 open (my $fd, $site_header);
1419 print "<div class=\"page_header\">\n" .
1420 "<a href=\"" . esc_html
($githelp_url) .
1421 "\" title=\"" . esc_html
($githelp_label) .
1423 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1425 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1426 if (defined $project) {
1427 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1428 if (defined $action) {
1432 if (!defined $searchtext) {
1436 if (defined $hash_base) {
1437 $search_hash = $hash_base;
1438 } elsif (defined $hash) {
1439 $search_hash = $hash;
1441 $search_hash = "HEAD";
1443 $cgi->param("a", "search");
1444 $cgi->param("h", $search_hash);
1445 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1446 "<div class=\"search\">\n" .
1447 $cgi->hidden(-name
=> "p") . "\n" .
1448 $cgi->hidden(-name
=> "a") . "\n" .
1449 $cgi->hidden(-name
=> "h") . "\n" .
1450 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1452 $cgi->end_form() . "\n";
1457 sub git_footer_html
{
1458 print "<div class=\"page_footer\">\n";
1459 if (defined $project) {
1460 my $descr = git_get_project_description
($project);
1461 if (defined $descr) {
1462 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1464 print $cgi->a({-href
=> href
(action
=>"rss"),
1465 -class => "rss_logo"}, "RSS") . "\n";
1467 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1468 -class => "rss_logo"}, "OPML") . " ";
1469 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1470 -class => "rss_logo"}, "TXT") . "\n";
1474 if (-f
$site_footer) {
1475 open (my $fd, $site_footer);
1485 my $status = shift || "403 Forbidden";
1486 my $error = shift || "Malformed query, file missing or permission denied";
1488 git_header_html
($status);
1490 <div class="page_body">
1500 ## ----------------------------------------------------------------------
1501 ## functions printing or outputting HTML: navigation
1503 sub git_print_page_nav
{
1504 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1505 $extra = '' if !defined $extra; # pager or formats
1507 my @navs = qw(summary shortlog log commit commitdiff tree);
1509 @navs = grep { $_ ne $suppress } @navs;
1512 my %arg = map { $_ => {action
=>$_} } @navs;
1513 if (defined $head) {
1514 for (qw(commit commitdiff)) {
1515 $arg{$_}{hash
} = $head;
1517 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1518 for (qw(shortlog log)) {
1519 $arg{$_}{hash
} = $head;
1523 $arg{tree
}{hash
} = $treehead if defined $treehead;
1524 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1526 print "<div class=\"page_nav\">\n" .
1528 map { $_ eq $current ?
1529 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1531 print "<br/>\n$extra<br/>\n" .
1535 sub format_paging_nav
{
1536 my ($action, $hash, $head, $page, $nrevs) = @_;
1540 if ($hash ne $head || $page) {
1541 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1543 $paging_nav .= "HEAD";
1547 $paging_nav .= " ⋅ " .
1548 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1549 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1551 $paging_nav .= " ⋅ prev";
1554 if ($nrevs >= (100 * ($page+1)-1)) {
1555 $paging_nav .= " ⋅ " .
1556 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1557 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1559 $paging_nav .= " ⋅ next";
1565 ## ......................................................................
1566 ## functions printing or outputting HTML: div
1568 sub git_print_header_div
{
1569 my ($action, $title, $hash, $hash_base) = @_;
1572 $args{action
} = $action;
1573 $args{hash
} = $hash if $hash;
1574 $args{hash_base
} = $hash_base if $hash_base;
1576 print "<div class=\"header\">\n" .
1577 $cgi->a({-href
=> href
(%args), -class => "title"},
1578 $title ?
$title : $action) .
1582 #sub git_print_authorship (\%) {
1583 sub git_print_authorship
{
1586 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1587 print "<div class=\"author_date\">" .
1588 esc_html
($co->{'author_name'}) .
1590 if ($ad{'hour_local'} < 6) {
1591 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1592 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1594 printf(" (%02d:%02d %s)",
1595 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1600 sub git_print_page_path
{
1605 if (!defined $name) {
1606 print "<div class=\"page_path\">/</div>\n";
1608 my @dirname = split '/', $name;
1609 my $basename = pop @dirname;
1612 print "<div class=\"page_path\">";
1613 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1614 -title
=> 'tree root'}, "[$project]");
1616 foreach my $dir (@dirname) {
1617 $fullname .= ($fullname ?
'/' : '') . $dir;
1618 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1620 -title
=> $fullname}, esc_html
($dir));
1623 if (defined $type && $type eq 'blob') {
1624 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1626 -title
=> $name}, esc_html
($basename));
1627 } elsif (defined $type && $type eq 'tree') {
1628 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1630 -title
=> $name}, esc_html
($basename));
1632 print esc_html
($basename);
1634 print "<br/></div>\n";
1638 # sub git_print_log (\@;%) {
1639 sub git_print_log
($;%) {
1643 if ($opts{'-remove_title'}) {
1644 # remove title, i.e. first line of log
1647 # remove leading empty lines
1648 while (defined $log->[0] && $log->[0] eq "") {
1655 foreach my $line (@
$log) {
1656 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1659 if (! $opts{'-remove_signoff'}) {
1660 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1663 # remove signoff lines
1670 # print only one empty line
1671 # do not print empty line after signoff
1673 next if ($empty || $signoff);
1679 print format_log_line_html
($line) . "<br/>\n";
1682 if ($opts{'-final_empty_line'}) {
1683 # end with single empty line
1684 print "<br/>\n" unless $empty;
1688 sub git_print_simplified_log
{
1690 my $remove_title = shift;
1693 -final_empty_line
=> 1,
1694 -remove_title
=> $remove_title);
1697 # print tree entry (row of git_tree), but without encompassing <tr> element
1698 sub git_print_tree_entry
{
1699 my ($t, $basedir, $hash_base, $have_blame) = @_;
1702 $base_key{hash_base
} = $hash_base if defined $hash_base;
1704 # The format of a table row is: mode list link. Where mode is
1705 # the mode of the entry, list is the name of the entry, an href,
1706 # and link is the action links of the entry.
1708 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1709 if ($t->{'type'} eq "blob") {
1710 print "<td class=\"list\">" .
1711 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1712 file_name
=>"$basedir$t->{'name'}", %base_key),
1713 -class => "list"}, esc_html
($t->{'name'})) . "</td>\n";
1714 print "<td class=\"link\">";
1716 print $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1717 file_name
=>"$basedir$t->{'name'}", %base_key)},
1720 if (defined $hash_base) {
1724 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1725 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1729 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
1730 file_name
=>"$basedir$t->{'name'}")},
1734 } elsif ($t->{'type'} eq "tree") {
1735 print "<td class=\"list\">";
1736 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1737 file_name
=>"$basedir$t->{'name'}", %base_key)},
1738 esc_html
($t->{'name'}));
1740 print "<td class=\"link\">";
1741 if (defined $hash_base) {
1742 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1743 file_name
=>"$basedir$t->{'name'}")},
1750 ## ......................................................................
1751 ## functions printing large fragments of HTML
1753 sub git_difftree_body
{
1754 my ($difftree, $hash, $parent) = @_;
1756 print "<div class=\"list_head\">\n";
1757 if ($#{$difftree} > 10) {
1758 print(($#{$difftree} + 1) . " files changed:\n");
1762 print "<table class=\"diff_tree\">\n";
1765 foreach my $line (@
{$difftree}) {
1766 my %diff = parse_difftree_raw_line
($line);
1769 print "<tr class=\"dark\">\n";
1771 print "<tr class=\"light\">\n";
1775 my ($to_mode_oct, $to_mode_str, $to_file_type);
1776 my ($from_mode_oct, $from_mode_str, $from_file_type);
1777 if ($diff{'to_mode'} ne ('0' x
6)) {
1778 $to_mode_oct = oct $diff{'to_mode'};
1779 if (S_ISREG
($to_mode_oct)) { # only for regular file
1780 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1782 $to_file_type = file_type
($diff{'to_mode'});
1784 if ($diff{'from_mode'} ne ('0' x
6)) {
1785 $from_mode_oct = oct $diff{'from_mode'};
1786 if (S_ISREG
($to_mode_oct)) { # only for regular file
1787 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1789 $from_file_type = file_type
($diff{'from_mode'});
1792 if ($diff{'status'} eq "A") { # created
1793 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1794 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1795 $mode_chng .= "]</span>";
1797 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1798 hash_base
=>$hash, file_name
=>$diff{'file'}),
1799 -class => "list"}, esc_html
($diff{'file'}));
1801 print "<td>$mode_chng</td>\n";
1802 print "<td class=\"link\">";
1803 if ($action eq 'commitdiff') {
1806 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1810 } elsif ($diff{'status'} eq "D") { # deleted
1811 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1813 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1814 hash_base
=>$parent, 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");
1825 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1826 file_name
=>$diff{'file'})},
1828 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1829 file_name
=>$diff{'file'})},
1833 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1834 my $mode_chnge = "";
1835 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1836 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1837 if ($from_file_type != $to_file_type) {
1838 $mode_chnge .= " from $from_file_type to $to_file_type";
1840 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1841 if ($from_mode_str && $to_mode_str) {
1842 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1843 } elsif ($to_mode_str) {
1844 $mode_chnge .= " mode: $to_mode_str";
1847 $mode_chnge .= "]</span>\n";
1850 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1851 hash_base
=>$hash, file_name
=>$diff{'file'}),
1852 -class => "list"}, esc_html
($diff{'file'}));
1854 print "<td>$mode_chnge</td>\n";
1855 print "<td class=\"link\">";
1856 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1857 if ($action eq 'commitdiff') {
1860 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1862 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1863 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1864 hash_base
=>$hash, hash_parent_base
=>$parent,
1865 file_name
=>$diff{'file'})},
1870 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
1871 file_name
=>$diff{'file'})},
1873 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
1874 file_name
=>$diff{'file'})},
1878 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1879 my %status_name = ('R' => 'moved', 'C' => 'copied');
1880 my $nstatus = $status_name{$diff{'status'}};
1882 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1883 # mode also for directories, so we cannot use $to_mode_str
1884 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1887 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1888 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1889 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1890 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1891 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1892 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1893 -class => "list"}, esc_html
($diff{'from_file'})) .
1894 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1895 "<td class=\"link\">";
1896 if ($diff{'to_id'} ne $diff{'from_id'}) {
1897 if ($action eq 'commitdiff') {
1900 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1902 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1903 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1904 hash_base
=>$hash, hash_parent_base
=>$parent,
1905 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1910 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1911 file_name
=>$diff{'from_file'})},
1913 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1914 file_name
=>$diff{'from_file'})},
1918 } # we should not encounter Unmerged (U) or Unknown (X) status
1924 sub git_patchset_body
{
1925 my ($fd, $difftree, $hash, $hash_parent) = @_;
1929 my $patch_found = 0;
1932 print "<div class=\"patchset\">\n";
1935 while (my $patch_line = <$fd>) {
1938 if ($patch_line =~ m/^diff /) { # "git diff" header
1939 # beginning of patch (in patchset)
1941 # close previous patch
1942 print "</div>\n"; # class="patch"
1944 # first patch in patchset
1947 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1949 if (ref($difftree->[$patch_idx]) eq "HASH") {
1950 $diffinfo = $difftree->[$patch_idx];
1952 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1956 # for now, no extended header, hence we skip empty patches
1957 # companion to next LINE if $in_header;
1958 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1963 if ($diffinfo->{'status'} eq "A") { # added
1964 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1965 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1966 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1967 $diffinfo->{'to_id'}) . "(new)" .
1968 "</div>\n"; # class="diff_info"
1970 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1971 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
1972 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1973 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1974 $diffinfo->{'from_id'}) . "(deleted)" .
1975 "</div>\n"; # class="diff_info"
1977 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1978 $diffinfo->{'status'} eq "C" || # copied
1979 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1980 print "<div class=\"diff_info\">" .
1981 file_type
($diffinfo->{'from_mode'}) . ":" .
1982 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1983 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
1984 $diffinfo->{'from_id'}) .
1986 file_type
($diffinfo->{'to_mode'}) . ":" .
1987 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1988 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
1989 $diffinfo->{'to_id'});
1990 print "</div>\n"; # class="diff_info"
1992 } else { # modified, mode changed, ...
1993 print "<div class=\"diff_info\">" .
1994 file_type
($diffinfo->{'from_mode'}) . ":" .
1995 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1996 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1997 $diffinfo->{'from_id'}) .
1999 file_type
($diffinfo->{'to_mode'}) . ":" .
2000 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2001 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2002 $diffinfo->{'to_id'});
2003 print "</div>\n"; # class="diff_info"
2006 #print "<div class=\"diff extended_header\">\n";
2009 } # start of patch in patchset
2012 if ($in_header && $patch_line =~ m/^---/) {
2013 #print "</div>\n"; # class="diff extended_header"
2016 my $file = $diffinfo->{'from_file'};
2017 $file ||= $diffinfo->{'file'};
2018 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2019 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
2020 -class => "list"}, esc_html
($file));
2021 $patch_line =~ s
|a
/.*$|a/$file|g
;
2022 print "<div class=\"diff from_file\">$patch_line</div>\n";
2024 $patch_line = <$fd>;
2027 #$patch_line =~ m/^+++/;
2028 $file = $diffinfo->{'to_file'};
2029 $file ||= $diffinfo->{'file'};
2030 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2031 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
2032 -class => "list"}, esc_html
($file));
2033 $patch_line =~ s
|b
/.*|b/$file|g
;
2034 print "<div class=\"diff to_file\">$patch_line</div>\n";
2038 next LINE
if $in_header;
2040 print format_diff_line
($patch_line);
2042 print "</div>\n" if $patch_found; # class="patch"
2044 print "</div>\n"; # class="patchset"
2047 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2049 sub git_shortlog_body
{
2050 # uses global variable $project
2051 my ($revlist, $from, $to, $refs, $extra) = @_;
2053 $from = 0 unless defined $from;
2054 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2056 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2058 for (my $i = $from; $i <= $to; $i++) {
2059 my $commit = $revlist->[$i];
2060 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2061 my $ref = format_ref_marker
($refs, $commit);
2062 my %co = parse_commit
($commit);
2064 print "<tr class=\"dark\">\n";
2066 print "<tr class=\"light\">\n";
2069 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2070 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2071 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2073 print format_subject_html
($co{'title'}, $co{'title_short'},
2074 href
(action
=>"commit", hash
=>$commit), $ref);
2076 "<td class=\"link\">" .
2077 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2078 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") . " | " .
2079 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2083 if (defined $extra) {
2085 "<td colspan=\"4\">$extra</td>\n" .
2091 sub git_history_body
{
2092 # Warning: assumes constant type (blob or tree) during history
2093 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2095 $from = 0 unless defined $from;
2096 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2098 print "<table class=\"history\" cellspacing=\"0\">\n";
2100 for (my $i = $from; $i <= $to; $i++) {
2101 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2106 my %co = parse_commit
($commit);
2111 my $ref = format_ref_marker
($refs, $commit);
2114 print "<tr class=\"dark\">\n";
2116 print "<tr class=\"light\">\n";
2119 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2120 # shortlog uses chop_str($co{'author_name'}, 10)
2121 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2123 # originally git_history used chop_str($co{'title'}, 50)
2124 print format_subject_html
($co{'title'}, $co{'title_short'},
2125 href
(action
=>"commit", hash
=>$commit), $ref);
2127 "<td class=\"link\">" .
2128 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2129 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2131 if ($ftype eq 'blob') {
2132 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2133 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2134 if (defined $blob_current && defined $blob_parent &&
2135 $blob_current ne $blob_parent) {
2137 $cgi->a({-href
=> href
(action
=>"blobdiff",
2138 hash
=>$blob_current, hash_parent
=>$blob_parent,
2139 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2140 file_name
=>$file_name)},
2147 if (defined $extra) {
2149 "<td colspan=\"4\">$extra</td>\n" .
2156 # uses global variable $project
2157 my ($taglist, $from, $to, $extra) = @_;
2158 $from = 0 unless defined $from;
2159 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2161 print "<table class=\"tags\" cellspacing=\"0\">\n";
2163 for (my $i = $from; $i <= $to; $i++) {
2164 my $entry = $taglist->[$i];
2166 my $comment_lines = $tag{'comment'};
2167 my $comment = shift @
$comment_lines;
2169 if (defined $comment) {
2170 $comment_short = chop_str
($comment, 30, 5);
2173 print "<tr class=\"dark\">\n";
2175 print "<tr class=\"light\">\n";
2178 print "<td><i>$tag{'age'}</i></td>\n" .
2180 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2181 -class => "list name"}, esc_html
($tag{'name'})) .
2184 if (defined $comment) {
2185 print format_subject_html
($comment, $comment_short,
2186 href
(action
=>"tag", hash
=>$tag{'id'}));
2189 "<td class=\"selflink\">";
2190 if ($tag{'type'} eq "tag") {
2191 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2196 "<td class=\"link\">" . " | " .
2197 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2198 if ($tag{'reftype'} eq "commit") {
2199 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2200 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
2201 } elsif ($tag{'reftype'} eq "blob") {
2202 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2207 if (defined $extra) {
2209 "<td colspan=\"5\">$extra</td>\n" .
2215 sub git_heads_body
{
2216 # uses global variable $project
2217 my ($headlist, $head, $from, $to, $extra) = @_;
2218 $from = 0 unless defined $from;
2219 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2221 print "<table class=\"heads\" cellspacing=\"0\">\n";
2223 for (my $i = $from; $i <= $to; $i++) {
2224 my $entry = $headlist->[$i];
2226 my $curr = $tag{'id'} eq $head;
2228 print "<tr class=\"dark\">\n";
2230 print "<tr class=\"light\">\n";
2233 print "<td><i>$tag{'age'}</i></td>\n" .
2234 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
2235 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
2236 -class => "list name"},esc_html
($tag{'name'})) .
2238 "<td class=\"link\">" .
2239 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
2240 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") . " | " .
2241 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$tag{'name'}, hash_base
=>$tag{'name'})}, "tree") .
2245 if (defined $extra) {
2247 "<td colspan=\"3\">$extra</td>\n" .
2253 ## ======================================================================
2254 ## ======================================================================
2257 sub git_project_list
{
2258 my $order = $cgi->param('o');
2259 if (defined $order && $order !~ m/project|descr|owner|age/) {
2260 die_error
(undef, "Unknown order parameter");
2263 my @list = git_get_projects_list
();
2266 die_error
(undef, "No projects found");
2268 foreach my $pr (@list) {
2269 my $head = git_get_head_hash
($pr->{'path'});
2270 if (!defined $head) {
2273 $git_dir = "$projectroot/$pr->{'path'}";
2274 my %co = parse_commit
($head);
2278 $pr->{'commit'} = \
%co;
2279 if (!defined $pr->{'descr'}) {
2280 my $descr = git_get_project_description
($pr->{'path'}) || "";
2281 $pr->{'descr'} = chop_str
($descr, 25, 5);
2283 if (!defined $pr->{'owner'}) {
2284 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2286 push @projects, $pr;
2290 if (-f
$home_text) {
2291 print "<div class=\"index_include\">\n";
2292 open (my $fd, $home_text);
2297 print "<table class=\"project_list\">\n" .
2299 $order ||= "project";
2300 if ($order eq "project") {
2301 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2302 print "<th>Project</th>\n";
2305 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2306 -class => "header"}, "Project") .
2309 if ($order eq "descr") {
2310 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2311 print "<th>Description</th>\n";
2314 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2315 -class => "header"}, "Description") .
2318 if ($order eq "owner") {
2319 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2320 print "<th>Owner</th>\n";
2323 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2324 -class => "header"}, "Owner") .
2327 if ($order eq "age") {
2328 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2329 print "<th>Last Change</th>\n";
2332 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2333 -class => "header"}, "Last Change") .
2336 print "<th></th>\n" .
2339 foreach my $pr (@projects) {
2341 print "<tr class=\"dark\">\n";
2343 print "<tr class=\"light\">\n";
2346 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2347 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2348 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2349 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2350 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2351 $pr->{'commit'}{'age_string'} . "</td>\n" .
2352 "<td class=\"link\">" .
2353 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2354 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2355 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2356 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2364 sub git_project_index
{
2365 my @projects = git_get_projects_list
();
2368 -type
=> 'text/plain',
2369 -charset
=> 'utf-8',
2370 -content_disposition
=> 'inline; filename="index.aux"');
2372 foreach my $pr (@projects) {
2373 if (!exists $pr->{'owner'}) {
2374 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2377 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2378 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2379 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2380 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2384 print "$path $owner\n";
2389 my $descr = git_get_project_description
($project) || "none";
2390 my $head = git_get_head_hash
($project);
2391 my %co = parse_commit
($head);
2392 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2394 my $owner = git_get_project_owner
($project);
2396 my ($reflist, $refs) = git_get_refs_list
();
2400 foreach my $ref (@
$reflist) {
2401 if ($ref->{'name'} =~ s!^heads/!!) {
2402 push @headlist, $ref;
2404 $ref->{'name'} =~ s!^tags/!!;
2405 push @taglist, $ref;
2410 git_print_page_nav
('summary','', $head);
2412 print "<div class=\"title\"> </div>\n";
2413 print "<table cellspacing=\"0\">\n" .
2414 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2415 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2416 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2417 # use per project git URL list in $projectroot/$project/cloneurl
2418 # or make project git URL from git base URL and project name
2419 my $url_tag = "URL";
2420 my @url_list = git_get_project_url_list
($project);
2421 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2422 foreach my $git_url (@url_list) {
2423 next unless $git_url;
2424 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2429 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2430 git_get_head_hash
($project)
2431 or die_error
(undef, "Open git-rev-list failed");
2432 my @revlist = map { chomp; $_ } <$fd>;
2434 git_print_header_div
('shortlog');
2435 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2436 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2439 git_print_header_div
('tags');
2440 git_tags_body
(\
@taglist, 0, 15,
2441 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2445 git_print_header_div
('heads');
2446 git_heads_body
(\
@headlist, $head, 0, 15,
2447 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2454 my $head = git_get_head_hash
($project);
2456 git_print_page_nav
('','', $head,undef,$head);
2457 my %tag = parse_tag
($hash);
2458 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2459 print "<div class=\"title_text\">\n" .
2460 "<table cellspacing=\"0\">\n" .
2462 "<td>object</td>\n" .
2463 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2464 $tag{'object'}) . "</td>\n" .
2465 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2466 $tag{'type'}) . "</td>\n" .
2468 if (defined($tag{'author'})) {
2469 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2470 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2471 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2472 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2475 print "</table>\n\n" .
2477 print "<div class=\"page_body\">";
2478 my $comment = $tag{'comment'};
2479 foreach my $line (@
$comment) {
2480 print esc_html
($line) . "<br/>\n";
2490 my ($have_blame) = gitweb_check_feature
('blame');
2492 die_error
('403 Permission denied', "Permission denied");
2494 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2495 $hash_base ||= git_get_head_hash
($project);
2496 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2497 my %co = parse_commit
($hash_base)
2498 or die_error
(undef, "Reading commit failed");
2499 if (!defined $hash) {
2500 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2501 or die_error
(undef, "Error looking up file");
2503 $ftype = git_get_type
($hash);
2504 if ($ftype !~ "blob") {
2505 die_error
("400 Bad Request", "Object is not a blob");
2507 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
2508 $file_name, $hash_base)
2509 or die_error
(undef, "Open git-blame failed");
2512 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2515 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2518 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2520 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2521 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2522 git_print_page_path
($file_name, $ftype, $hash_base);
2523 my @rev_color = (qw(light2 dark2));
2524 my $num_colors = scalar(@rev_color);
2525 my $current_color = 0;
2528 <div class="page_body">
2529 <table class="blame">
2530 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2535 last unless defined $_;
2536 my ($full_rev, $orig_lineno, $lineno, $group_size) =
2537 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
2538 if (!exists $metainfo{$full_rev}) {
2539 $metainfo{$full_rev} = {};
2541 my $meta = $metainfo{$full_rev};
2544 if (/^(\S+) (.*)$/) {
2549 my $rev = substr($full_rev, 0, 8);
2550 my $author = $meta->{'author'};
2551 my %date = parse_date
($meta->{'author-time'},
2552 $meta->{'author-tz'});
2553 my $date = $date{'iso-tz'};
2555 $current_color = ++$current_color % $num_colors;
2557 print "<tr class=\"$rev_color[$current_color]\">\n";
2559 print "<td class=\"sha1\"";
2560 print " title=\"$author, $date\"";
2561 print " rowspan=\"$group_size\"" if ($group_size > 1);
2563 print $cgi->a({-href
=> href
(action
=>"commit",
2565 file_name
=>$file_name)},
2569 my $blamed = href
(action
=> 'blame',
2570 file_name
=> $meta->{'filename'},
2571 hash_base
=> $full_rev);
2572 print "<td class=\"linenr\">";
2573 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
2575 -class => "linenr" },
2578 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2584 or print "Reading blob failed\n";
2591 my ($have_blame) = gitweb_check_feature
('blame');
2593 die_error
('403 Permission denied', "Permission denied");
2595 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2596 $hash_base ||= git_get_head_hash
($project);
2597 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2598 my %co = parse_commit
($hash_base)
2599 or die_error
(undef, "Reading commit failed");
2600 if (!defined $hash) {
2601 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2602 or die_error
(undef, "Error lookup file");
2604 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2605 or die_error
(undef, "Open git-annotate failed");
2608 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2611 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2614 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2616 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2617 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2618 git_print_page_path
($file_name, 'blob', $hash_base);
2619 print "<div class=\"page_body\">\n";
2621 <table class="blame">
2630 my @line_class = (qw(light dark));
2631 my $line_class_len = scalar (@line_class);
2632 my $line_class_num = $#line_class;
2633 while (my $line = <$fd>) {
2645 $line_class_num = ($line_class_num + 1) % $line_class_len;
2647 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2654 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2657 $short_rev = substr ($long_rev, 0, 8);
2658 $age = time () - $time;
2659 $age_str = age_string
($age);
2660 $age_str =~ s/ / /g;
2661 $age_class = age_class
($age);
2662 $author = esc_html
($author);
2663 $author =~ s/ / /g;
2665 $data = untabify
($data);
2666 $data = esc_html
($data);
2669 <tr class="$line_class[$line_class_num]">
2670 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2671 <td class="$age_class">$age_str</td>
2673 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2674 <td class="pre">$data</td>
2677 } # while (my $line = <$fd>)
2678 print "</table>\n\n";
2680 or print "Reading blob failed.\n";
2686 my $head = git_get_head_hash
($project);
2688 git_print_page_nav
('','', $head,undef,$head);
2689 git_print_header_div
('summary', $project);
2691 my ($taglist) = git_get_refs_list
("tags");
2693 git_tags_body
($taglist);
2699 my $head = git_get_head_hash
($project);
2701 git_print_page_nav
('','', $head,undef,$head);
2702 git_print_header_div
('summary', $project);
2704 my ($headlist) = git_get_refs_list
("heads");
2706 git_heads_body
($headlist, $head);
2711 sub git_blob_plain
{
2714 if (!defined $hash) {
2715 if (defined $file_name) {
2716 my $base = $hash_base || git_get_head_hash
($project);
2717 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2718 or die_error
(undef, "Error lookup file");
2720 die_error
(undef, "No file name defined");
2722 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2723 # blobs defined by non-textual hash id's can be cached
2728 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2729 or die_error
(undef, "Couldn't cat $file_name, $hash");
2731 $type ||= blob_mimetype
($fd, $file_name);
2733 # save as filename, even when no $file_name is given
2734 my $save_as = "$hash";
2735 if (defined $file_name) {
2736 $save_as = $file_name;
2737 } elsif ($type =~ m/^text\//) {
2744 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
2746 binmode STDOUT
, ':raw';
2748 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2756 if (!defined $hash) {
2757 if (defined $file_name) {
2758 my $base = $hash_base || git_get_head_hash
($project);
2759 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2760 or die_error
(undef, "Error lookup file");
2762 die_error
(undef, "No file name defined");
2764 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2765 # blobs defined by non-textual hash id's can be cached
2769 my ($have_blame) = gitweb_check_feature
('blame');
2770 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2771 or die_error
(undef, "Couldn't cat $file_name, $hash");
2772 my $mimetype = blob_mimetype
($fd, $file_name);
2773 if ($mimetype !~ m/^text\//) {
2775 return git_blob_plain
($mimetype);
2777 git_header_html
(undef, $expires);
2778 my $formats_nav = '';
2779 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2780 if (defined $file_name) {
2783 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2784 hash
=>$hash, file_name
=>$file_name)},
2789 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2790 hash
=>$hash, file_name
=>$file_name)},
2793 $cgi->a({-href
=> href
(action
=>"blob_plain",
2794 hash
=>$hash, file_name
=>$file_name)},
2797 $cgi->a({-href
=> href
(action
=>"blob",
2798 hash_base
=>"HEAD", file_name
=>$file_name)},
2802 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
2804 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2805 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2807 print "<div class=\"page_nav\">\n" .
2808 "<br/><br/></div>\n" .
2809 "<div class=\"title\">$hash</div>\n";
2811 git_print_page_path
($file_name, "blob", $hash_base);
2812 print "<div class=\"page_body\">\n";
2814 while (my $line = <$fd>) {
2817 $line = untabify
($line);
2818 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2819 $nr, $nr, $nr, esc_html
($line);
2822 or print "Reading blob failed.\n";
2828 my $have_snapshot = gitweb_have_snapshot
();
2830 if (!defined $hash_base) {
2831 $hash_base = "HEAD";
2833 if (!defined $hash) {
2834 if (defined $file_name) {
2835 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
2841 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
2842 or die_error
(undef, "Open git-ls-tree failed");
2843 my @entries = map { chomp; $_ } <$fd>;
2844 close $fd or die_error
(undef, "Reading tree failed");
2847 my $refs = git_get_references
();
2848 my $ref = format_ref_marker
($refs, $hash_base);
2851 my ($have_blame) = gitweb_check_feature
('blame');
2852 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2854 if (defined $file_name) {
2856 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2857 hash
=>$hash, file_name
=>$file_name)},
2859 $cgi->a({-href
=> href
(action
=>"tree",
2860 hash_base
=>"HEAD", file_name
=>$file_name)},
2863 if ($have_snapshot) {
2864 # FIXME: Should be available when we have no hash base as well.
2866 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
2869 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
2870 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2873 print "<div class=\"page_nav\">\n";
2874 print "<br/><br/></div>\n";
2875 print "<div class=\"title\">$hash</div>\n";
2877 if (defined $file_name) {
2878 $base = esc_html
("$file_name/");
2880 git_print_page_path
($file_name, 'tree', $hash_base);
2881 print "<div class=\"page_body\">\n";
2882 print "<table cellspacing=\"0\">\n";
2884 foreach my $line (@entries) {
2885 my %t = parse_ls_tree_line
($line, -z
=> 1);
2888 print "<tr class=\"dark\">\n";
2890 print "<tr class=\"light\">\n";
2894 git_print_tree_entry
(\
%t, $base, $hash_base, $have_blame);
2898 print "</table>\n" .
2904 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2905 my $have_snapshot = (defined $ctype && defined $suffix);
2906 if (!$have_snapshot) {
2907 die_error
('403 Permission denied', "Permission denied");
2910 if (!defined $hash) {
2911 $hash = git_get_head_hash
($project);
2914 my $filename = basename
($project) . "-$hash.tar.$suffix";
2917 -type
=> 'application/x-tar',
2918 -content_encoding
=> $ctype,
2919 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
2920 -status
=> '200 OK');
2922 my $git = git_cmd_str
();
2923 my $name = $project;
2924 $name =~ s/\047/\047\\\047\047/g;
2926 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
2927 or die_error
(undef, "Execute git-tar-tree failed.");
2928 binmode STDOUT
, ':raw';
2930 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2936 my $head = git_get_head_hash
($project);
2937 if (!defined $hash) {
2940 if (!defined $page) {
2943 my $refs = git_get_references
();
2945 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2946 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
2947 or die_error
(undef, "Open git-rev-list failed");
2948 my @revlist = map { chomp; $_ } <$fd>;
2951 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2954 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2957 my %co = parse_commit
($hash);
2959 git_print_header_div
('summary', $project);
2960 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2962 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2963 my $commit = $revlist[$i];
2964 my $ref = format_ref_marker
($refs, $commit);
2965 my %co = parse_commit
($commit);
2967 my %ad = parse_date
($co{'author_epoch'});
2968 git_print_header_div
('commit',
2969 "<span class=\"age\">$co{'age_string'}</span>" .
2970 esc_html
($co{'title'}) . $ref,
2972 print "<div class=\"title_text\">\n" .
2973 "<div class=\"log_link\">\n" .
2974 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2976 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2978 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
2981 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2984 print "<div class=\"log_body\">\n";
2985 git_print_simplified_log
($co{'comment'});
2992 my %co = parse_commit
($hash);
2994 die_error
(undef, "Unknown commit object");
2996 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2997 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2999 my $parent = $co{'parent'};
3000 if (!defined $parent) {
3003 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $parent, $hash
3004 or die_error
(undef, "Open git-diff-tree failed");
3005 my @difftree = map { chomp; $_ } <$fd>;
3006 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3008 # non-textual hash id's can be cached
3010 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3013 my $refs = git_get_references
();
3014 my $ref = format_ref_marker
($refs, $co{'id'});
3016 my $have_snapshot = gitweb_have_snapshot
();
3019 if (defined $file_name && defined $co{'parent'}) {
3021 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
3024 git_header_html
(undef, $expires);
3025 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
3026 $hash, $co{'tree'}, $hash,
3027 join (' | ', @views_nav));
3029 if (defined $co{'parent'}) {
3030 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3032 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3034 print "<div class=\"title_text\">\n" .
3035 "<table cellspacing=\"0\">\n";
3036 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3038 "<td></td><td> $ad{'rfc2822'}";
3039 if ($ad{'hour_local'} < 6) {
3040 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3041 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3043 printf(" (%02d:%02d %s)",
3044 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3048 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3049 print "<tr><td></td><td> $cd{'rfc2822'}" .
3050 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3052 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3055 "<td class=\"sha1\">" .
3056 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3057 class => "list"}, $co{'tree'}) .
3059 "<td class=\"link\">" .
3060 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3062 if ($have_snapshot) {
3064 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3068 my $parents = $co{'parents'};
3069 foreach my $par (@
$parents) {
3072 "<td class=\"sha1\">" .
3073 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3074 class => "list"}, $par) .
3076 "<td class=\"link\">" .
3077 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3079 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3086 print "<div class=\"page_body\">\n";
3087 git_print_log
($co{'comment'});
3090 git_difftree_body
(\
@difftree, $hash, $parent);
3096 my $format = shift || 'html';
3103 # preparing $fd and %diffinfo for git_patchset_body
3105 if (defined $hash_base && defined $hash_parent_base) {
3106 if (defined $file_name) {
3108 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
3110 or die_error
(undef, "Open git-diff-tree failed");
3111 @difftree = map { chomp; $_ } <$fd>;
3113 or die_error
(undef, "Reading git-diff-tree failed");
3115 or die_error
('404 Not Found', "Blob diff not found");
3117 } elsif (defined $hash &&
3118 $hash =~ /[0-9a-fA-F]{40}/) {
3119 # try to find filename from $hash
3121 # read filtered raw output
3122 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
3123 or die_error
(undef, "Open git-diff-tree failed");
3125 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3127 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3128 map { chomp; $_ } <$fd>;
3130 or die_error
(undef, "Reading git-diff-tree failed");
3132 or die_error
('404 Not Found', "Blob diff not found");
3135 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3138 if (@difftree > 1) {
3139 die_error
('404 Not Found', "Ambiguous blob diff specification");
3142 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3143 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3144 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3146 $hash_parent ||= $diffinfo{'from_id'};
3147 $hash ||= $diffinfo{'to_id'};
3149 # non-textual hash id's can be cached
3150 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3151 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3156 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3157 '-p', $hash_parent_base, $hash_base,
3159 or die_error
(undef, "Open git-diff-tree failed");
3162 # old/legacy style URI
3163 if (!%diffinfo && # if new style URI failed
3164 defined $hash && defined $hash_parent) {
3165 # fake git-diff-tree raw output
3166 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3167 $diffinfo{'from_id'} = $hash_parent;
3168 $diffinfo{'to_id'} = $hash;
3169 if (defined $file_name) {
3170 if (defined $file_parent) {
3171 $diffinfo{'status'} = '2';
3172 $diffinfo{'from_file'} = $file_parent;
3173 $diffinfo{'to_file'} = $file_name;
3174 } else { # assume not renamed
3175 $diffinfo{'status'} = '1';
3176 $diffinfo{'from_file'} = $file_name;
3177 $diffinfo{'to_file'} = $file_name;
3179 } else { # no filename given
3180 $diffinfo{'status'} = '2';
3181 $diffinfo{'from_file'} = $hash_parent;
3182 $diffinfo{'to_file'} = $hash;
3185 # non-textual hash id's can be cached
3186 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3187 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3192 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts, $hash_parent, $hash
3193 or die_error
(undef, "Open git-diff failed");
3195 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3200 if ($format eq 'html') {
3202 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3203 hash
=>$hash, hash_parent
=>$hash_parent,
3204 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3205 file_name
=>$file_name, file_parent
=>$file_parent)},
3207 git_header_html
(undef, $expires);
3208 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3209 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3210 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3212 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3213 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3215 if (defined $file_name) {
3216 git_print_page_path
($file_name, "blob", $hash_base);
3218 print "<div class=\"page_path\"></div>\n";
3221 } elsif ($format eq 'plain') {
3223 -type
=> 'text/plain',
3224 -charset
=> 'utf-8',
3225 -expires
=> $expires,
3226 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3228 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3231 die_error
(undef, "Unknown blobdiff format");
3235 if ($format eq 'html') {
3236 print "<div class=\"page_body\">\n";
3238 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3241 print "</div>\n"; # class="page_body"
3245 while (my $line = <$fd>) {
3246 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_html($diffinfo{'from_file'})!eg;
3247 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_html($diffinfo{'to_file'})!eg;
3251 last if $line =~ m!^\+\+\+!;
3259 sub git_blobdiff_plain
{
3260 git_blobdiff
('plain');
3263 sub git_commitdiff
{
3264 my $format = shift || 'html';
3265 my %co = parse_commit
($hash);
3267 die_error
(undef, "Unknown commit object");
3269 if (!defined $hash_parent) {
3270 $hash_parent = $co{'parent'} || '--root';
3276 if ($format eq 'html') {
3277 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3278 "--patch-with-raw", "--full-index", $hash_parent, $hash
3279 or die_error
(undef, "Open git-diff-tree failed");
3281 while (chomp(my $line = <$fd>)) {
3282 # empty line ends raw part of diff-tree output
3284 push @difftree, $line;
3287 } elsif ($format eq 'plain') {
3288 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3289 '-p', $hash_parent, $hash
3290 or die_error
(undef, "Open git-diff-tree failed");
3293 die_error
(undef, "Unknown commitdiff format");
3296 # non-textual hash id's can be cached
3298 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3302 # write commit message
3303 if ($format eq 'html') {
3304 my $refs = git_get_references
();
3305 my $ref = format_ref_marker
($refs, $co{'id'});
3307 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3308 hash
=>$hash, hash_parent
=>$hash_parent)},
3311 git_header_html
(undef, $expires);
3312 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3313 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3314 git_print_authorship
(\
%co);
3315 print "<div class=\"page_body\">\n";
3316 print "<div class=\"log\">\n";
3317 git_print_simplified_log
($co{'comment'}, 1); # skip title
3318 print "</div>\n"; # class="log"
3320 } elsif ($format eq 'plain') {
3321 my $refs = git_get_references
("tags");
3322 my $tagname = git_get_rev_name_tags
($hash);
3323 my $filename = basename
($project) . "-$hash.patch";
3326 -type
=> 'text/plain',
3327 -charset
=> 'utf-8',
3328 -expires
=> $expires,
3329 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3330 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3333 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3334 Subject: $co{'title'}
3336 print "X-Git-Tag: $tagname\n" if $tagname;
3337 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3339 foreach my $line (@
{$co{'comment'}}) {
3346 if ($format eq 'html') {
3347 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3350 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3352 print "</div>\n"; # class="page_body"
3355 } elsif ($format eq 'plain') {
3359 or print "Reading git-diff-tree failed\n";
3363 sub git_commitdiff_plain
{
3364 git_commitdiff
('plain');
3368 if (!defined $hash_base) {
3369 $hash_base = git_get_head_hash
($project);
3371 if (!defined $page) {
3375 my %co = parse_commit
($hash_base);
3377 die_error
(undef, "Unknown commit object");
3380 my $refs = git_get_references
();
3381 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3383 if (!defined $hash && defined $file_name) {
3384 $hash = git_get_hash_by_path
($hash_base, $file_name);
3386 if (defined $hash) {
3387 $ftype = git_get_type
($hash);
3391 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3392 or die_error
(undef, "Open git-rev-list-failed");
3393 my @revlist = map { chomp; $_ } <$fd>;
3395 or die_error
(undef, "Reading git-rev-list failed");
3397 my $paging_nav = '';
3400 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3401 file_name
=>$file_name)},
3403 $paging_nav .= " ⋅ " .
3404 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3405 file_name
=>$file_name, page
=>$page-1),
3406 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3408 $paging_nav .= "first";
3409 $paging_nav .= " ⋅ prev";
3411 if ($#revlist >= (100 * ($page+1)-1)) {
3412 $paging_nav .= " ⋅ " .
3413 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3414 file_name
=>$file_name, page
=>$page+1),
3415 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3417 $paging_nav .= " ⋅ next";
3420 if ($#revlist >= (100 * ($page+1)-1)) {
3422 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3423 file_name
=>$file_name, page
=>$page+1),
3424 -title
=> "Alt-n"}, "next");
3428 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3429 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3430 git_print_page_path
($file_name, $ftype, $hash_base);
3432 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3433 $refs, $hash_base, $ftype, $next_link);
3439 if (!defined $searchtext) {
3440 die_error
(undef, "Text field empty");
3442 if (!defined $hash) {
3443 $hash = git_get_head_hash
($project);
3445 my %co = parse_commit
($hash);
3447 die_error
(undef, "Unknown commit object");
3450 my $commit_search = 1;
3451 my $author_search = 0;
3452 my $committer_search = 0;
3453 my $pickaxe_search = 0;
3454 if ($searchtext =~ s/^author\\://i) {
3456 } elsif ($searchtext =~ s/^committer\\://i) {
3457 $committer_search = 1;
3458 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3460 $pickaxe_search = 1;
3462 # pickaxe may take all resources of your box and run for several minutes
3463 # with every query - so decide by yourself how public you make this feature
3464 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3465 if (!$have_pickaxe) {
3466 die_error
('403 Permission denied', "Permission denied");
3470 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3471 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3473 print "<table cellspacing=\"0\">\n";
3475 if ($commit_search) {
3477 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", $hash or next;
3478 while (my $commit_text = <$fd>) {
3479 if (!grep m/$searchtext/i, $commit_text) {
3482 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3485 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3488 my @commit_lines = split "\n", $commit_text;
3489 my %co = parse_commit
(undef, \
@commit_lines);
3494 print "<tr class=\"dark\">\n";
3496 print "<tr class=\"light\">\n";
3499 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3500 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3502 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3503 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3504 my $comment = $co{'comment'};
3505 foreach my $line (@
$comment) {
3506 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3507 my $lead = esc_html
($1) || "";
3508 $lead = chop_str
($lead, 30, 10);
3509 my $match = esc_html
($2) || "";
3510 my $trail = esc_html
($3) || "";
3511 $trail = chop_str
($trail, 30, 10);
3512 my $text = "$lead<span class=\"match\">$match</span>$trail";
3513 print chop_str
($text, 80, 5) . "<br/>\n";
3517 "<td class=\"link\">" .
3518 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3520 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3527 if ($pickaxe_search) {
3529 my $git_command = git_cmd_str
();
3530 open my $fd, "-|", "$git_command rev-list $hash | " .
3531 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3534 while (my $line = <$fd>) {
3535 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3538 $set{'from_id'} = $3;
3540 $set{'id'} = $set{'to_id'};
3541 if ($set{'id'} =~ m/0{40}/) {
3542 $set{'id'} = $set{'from_id'};
3544 if ($set{'id'} =~ m/0{40}/) {
3548 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3551 print "<tr class=\"dark\">\n";
3553 print "<tr class=\"light\">\n";
3556 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3557 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3559 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3560 -class => "list subject"},
3561 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3562 while (my $setref = shift @files) {
3564 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3565 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3567 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3571 "<td class=\"link\">" .
3572 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3574 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3578 %co = parse_commit
($1);
3588 my $head = git_get_head_hash
($project);
3589 if (!defined $hash) {
3592 if (!defined $page) {
3595 my $refs = git_get_references
();
3597 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3598 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3599 or die_error
(undef, "Open git-rev-list failed");
3600 my @revlist = map { chomp; $_ } <$fd>;
3603 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3605 if ($#revlist >= (100 * ($page+1)-1)) {
3607 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3608 -title
=> "Alt-n"}, "next");
3613 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3614 git_print_header_div
('summary', $project);
3616 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3621 ## ......................................................................
3622 ## feeds (RSS, OPML)
3625 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3626 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150", git_get_head_hash
($project)
3627 or die_error
(undef, "Open git-rev-list failed");
3628 my @revlist = map { chomp; $_ } <$fd>;
3629 close $fd or die_error
(undef, "Reading git-rev-list failed");
3630 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3632 <?xml version="1.0" encoding="utf-8"?>
3633 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3635 <title>$project $my_uri $my_url</title>
3636 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3637 <description>$project log</description>
3638 <language>en</language>
3641 for (my $i = 0; $i <= $#revlist; $i++) {
3642 my $commit = $revlist[$i];
3643 my %co = parse_commit
($commit);
3644 # we read 150, we always show 30 and the ones more recent than 48 hours
3645 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3648 my %cd = parse_date
($co{'committer_epoch'});
3649 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3650 $co{'parent'}, $co{'id'}
3652 my @difftree = map { chomp; $_ } <$fd>;
3657 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3659 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3660 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3661 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3662 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3663 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3664 "<content:encoded>" .
3666 my $comment = $co{'comment'};
3667 foreach my $line (@
$comment) {
3668 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
3669 print "$line<br/>\n";
3672 foreach my $line (@difftree) {
3673 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3676 my $file = esc_html
(unquote
($7));
3677 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
3678 print "$file<br/>\n";
3681 "</content:encoded>\n" .
3684 print "</channel></rss>";
3688 my @list = git_get_projects_list
();
3690 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3692 <?xml version="1.0" encoding="utf-8"?>
3693 <opml version="1.0">
3695 <title>$site_name Git OPML Export</title>
3698 <outline text="git RSS feeds">
3701 foreach my $pr (@list) {
3703 my $head = git_get_head_hash
($proj{'path'});
3704 if (!defined $head) {
3707 $git_dir = "$projectroot/$proj{'path'}";
3708 my %co = parse_commit
($head);
3713 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3714 my $rss = "$my_url?p=$proj{'path'};a=rss";
3715 my $html = "$my_url?p=$proj{'path'};a=summary";
3716 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";