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 # html text to include at home page
45 our $home_text = "++GITWEB_HOMETEXT++";
47 # URI of default stylesheet
48 our $stylesheet = "++GITWEB_CSS++";
50 our $logo = "++GITWEB_LOGO++";
51 # URI of GIT favicon, assumed to be image/png type
52 our $favicon = "++GITWEB_FAVICON++";
54 # source of projects list
55 our $projects_list = "++GITWEB_LIST++";
57 # list of git base URLs used for URL to where fetch project from,
58 # i.e. full URL is "$git_base_url/$project"
59 our @git_base_url_list = ("++GITWEB_BASE_URL++");
61 # default blob_plain mimetype and default charset for text/plain blob
62 our $default_blob_plain_mimetype = 'text/plain';
63 our $default_text_plain_charset = undef;
65 # file to use for guessing MIME types before trying /etc/mime.types
66 # (relative to the current git repository)
67 our $mimetypes_file = undef;
69 # You define site-wide feature defaults here; override them with
70 # $GITWEB_CONFIG as necessary.
73 # 'sub' => feature-sub (subroutine),
74 # 'override' => allow-override (boolean),
75 # 'default' => [ default options...] (array reference)}
77 # if feature is overridable (it means that allow-override has true value,
78 # then feature-sub will be called with default options as parameters;
79 # return value of feature-sub indicates if to enable specified feature
81 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
84 'sub' => \
&feature_blame
,
89 'sub' => \
&feature_snapshot
,
91 # => [content-encoding, suffix, program]
92 'default' => ['x-gzip', 'gz', 'gzip']},
95 'sub' => \
&feature_pickaxe
,
100 sub gitweb_check_feature
{
102 return undef unless exists $feature{$name};
103 my ($sub, $override, @defaults) = (
104 $feature{$name}{'sub'},
105 $feature{$name}{'override'},
106 @
{$feature{$name}{'default'}});
107 if (!$override) { return @defaults; }
108 return $sub->(@defaults);
111 # To enable system wide have in $GITWEB_CONFIG
112 # $feature{'blame'}{'default'} = [1];
113 # To have project specific config enable override in $GITWEB_CONFIG
114 # $feature{'blame'}{'override'} = 1;
115 # and in project config gitweb.blame = 0|1;
118 my ($val) = git_get_project_config
('blame', '--bool');
120 if ($val eq 'true') {
122 } elsif ($val eq 'false') {
129 # To disable system wide have in $GITWEB_CONFIG
130 # $feature{'snapshot'}{'default'} = [undef];
131 # To have project specific config enable override in $GITWEB_CONFIG
132 # $feature{'blame'}{'override'} = 1;
133 # and in project config gitweb.snapshot = none|gzip|bzip2
135 sub feature_snapshot
{
136 my ($ctype, $suffix, $command) = @_;
138 my ($val) = git_get_project_config
('snapshot');
140 if ($val eq 'gzip') {
141 return ('x-gzip', 'gz', 'gzip');
142 } elsif ($val eq 'bzip2') {
143 return ('x-bzip2', 'bz2', 'bzip2');
144 } elsif ($val eq 'none') {
148 return ($ctype, $suffix, $command);
151 # To enable system wide have in $GITWEB_CONFIG
152 # $feature{'pickaxe'}{'default'} = [1];
153 # To have project specific config enable override in $GITWEB_CONFIG
154 # $feature{'pickaxe'}{'override'} = 1;
155 # and in project config gitweb.pickaxe = 0|1;
157 sub feature_pickaxe
{
158 my ($val) = git_get_project_config
('pickaxe', '--bool');
160 if ($val eq 'true') {
162 } elsif ($val eq 'false') {
169 # rename detection options for git-diff and git-diff-tree
170 # - default is '-M', with the cost proportional to
171 # (number of removed files) * (number of new files).
172 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
173 # (number of changed files + number of removed files) * (number of new files)
174 # - even more costly is '-C', '--find-copies-harder' with cost
175 # (number of files in the original tree) * (number of new files)
176 # - one might want to include '-B' option, e.g. '-B', '-M'
177 our @diff_opts = ('-M'); # taken from git_commit
179 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
180 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
182 # version of the core git binary
183 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
185 # path to the current git repository
188 $projects_list ||= $projectroot;
190 # ======================================================================
191 # input validation and dispatch
192 our $action = $cgi->param('a');
193 if (defined $action) {
194 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
195 die_error
(undef, "Invalid action parameter");
199 our $project = $cgi->param('p');
200 if (defined $project) {
201 if (!validate_input
($project)) {
202 die_error
(undef, "Invalid project parameter");
204 if (!(-d
"$projectroot/$project")) {
205 die_error
(undef, "No such directory");
207 if (!(-e
"$projectroot/$project/HEAD")) {
208 die_error
(undef, "No such project");
212 our $file_name = $cgi->param('f');
213 if (defined $file_name) {
214 if (!validate_input
($file_name)) {
215 die_error
(undef, "Invalid file parameter");
219 our $file_parent = $cgi->param('fp');
220 if (defined $file_parent) {
221 if (!validate_input
($file_parent)) {
222 die_error
(undef, "Invalid file parent parameter");
226 our $hash = $cgi->param('h');
228 if (!validate_input
($hash)) {
229 die_error
(undef, "Invalid hash parameter");
233 our $hash_parent = $cgi->param('hp');
234 if (defined $hash_parent) {
235 if (!validate_input
($hash_parent)) {
236 die_error
(undef, "Invalid hash parent parameter");
240 our $hash_base = $cgi->param('hb');
241 if (defined $hash_base) {
242 if (!validate_input
($hash_base)) {
243 die_error
(undef, "Invalid hash base parameter");
247 our $hash_parent_base = $cgi->param('hpb');
248 if (defined $hash_parent_base) {
249 if (!validate_input
($hash_parent_base)) {
250 die_error
(undef, "Invalid hash parent base parameter");
254 our $page = $cgi->param('pg');
256 if ($page =~ m/[^0-9]$/) {
257 die_error
(undef, "Invalid page parameter");
261 our $searchtext = $cgi->param('s');
262 if (defined $searchtext) {
263 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
264 die_error
(undef, "Invalid search parameter");
266 $searchtext = quotemeta $searchtext;
269 # now read PATH_INFO and use it as alternative to parameters
270 our $path_info = $ENV{"PATH_INFO"};
271 $path_info =~ s
|^/||;
272 $path_info =~ s
|/$||;
273 if (validate_input
($path_info) && !defined $project) {
274 $project = $path_info;
275 while ($project && !-e
"$projectroot/$project/HEAD") {
276 $project =~ s
,/*[^/]*$,,;
278 if (defined $project) {
279 $project = undef unless $project;
281 if ($path_info =~ m
,^$project/([^/]+)/(.+)$,) {
282 # we got "project.git/branch/filename"
283 $action ||= "blob_plain";
286 } elsif ($path_info =~ m
,^$project/([^/]+)$,) {
287 # we got "project.git/branch"
288 $action ||= "shortlog";
293 $git_dir = "$projectroot/$project";
297 "blame" => \
&git_blame2
,
298 "blobdiff" => \
&git_blobdiff
,
299 "blobdiff_plain" => \
&git_blobdiff_plain
,
300 "blob" => \
&git_blob
,
301 "blob_plain" => \
&git_blob_plain
,
302 "commitdiff" => \
&git_commitdiff
,
303 "commitdiff_plain" => \
&git_commitdiff_plain
,
304 "commit" => \
&git_commit
,
305 "heads" => \
&git_heads
,
306 "history" => \
&git_history
,
309 "search" => \
&git_search
,
310 "shortlog" => \
&git_shortlog
,
311 "summary" => \
&git_summary
,
313 "tags" => \
&git_tags
,
314 "tree" => \
&git_tree
,
315 "snapshot" => \
&git_snapshot
,
316 # those below don't need $project
317 "opml" => \
&git_opml
,
318 "project_list" => \
&git_project_list
,
319 "project_index" => \
&git_project_index
,
322 if (defined $project) {
323 $action ||= 'summary';
325 $action ||= 'project_list';
327 if (!defined($actions{$action})) {
328 die_error
(undef, "Unknown action");
330 $actions{$action}->();
333 ## ======================================================================
347 hash_parent_base
=> "hpb",
352 my %mapping = @mapping;
354 $params{'project'} = $project unless exists $params{'project'};
357 for (my $i = 0; $i < @mapping; $i += 2) {
358 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
359 if (defined $params{$name}) {
360 push @result, $symbol . "=" . esc_param
($params{$name});
363 return "$my_uri?" . join(';', @result);
367 ## ======================================================================
368 ## validation, quoting/unquoting and escaping
373 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
376 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
379 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
385 # quote unsafe chars, but keep the slash, even when it's not
386 # correct, but quoted slashes look too horrible in bookmarks
389 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
395 # replace invalid utf8 character with SUBSTITUTION sequence
398 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
399 $str = escapeHTML
($str);
400 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
404 # git may return quoted and escaped filenames
407 if ($str =~ m/^"(.*)"$/) {
409 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
414 # escape tabs (convert tabs to spaces)
418 while ((my $pos = index($line, "\t")) != -1) {
419 if (my $count = (8 - ($pos % 8))) {
420 my $spaces = ' ' x
$count;
421 $line =~ s/\t/$spaces/;
428 ## ----------------------------------------------------------------------
429 ## HTML aware string manipulation
434 my $add_len = shift || 10;
436 # allow only $len chars, but don't cut a word if it would fit in $add_len
437 # if it doesn't fit, cut it if it's still longer than the dots we would add
438 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
441 if (length($tail) > 4) {
443 $body =~ s/&[^;]*$//; # remove chopped character entities
448 ## ----------------------------------------------------------------------
449 ## functions returning short strings
451 # CSS class for given age value (in seconds)
455 if ($age < 60*60*2) {
457 } elsif ($age < 60*60*24*2) {
464 # convert age in seconds to "nn units ago" string
469 if ($age > 60*60*24*365*2) {
470 $age_str = (int $age/60/60/24/365);
471 $age_str .= " years ago";
472 } elsif ($age > 60*60*24*(365/12)*2) {
473 $age_str = int $age/60/60/24/(365/12);
474 $age_str .= " months ago";
475 } elsif ($age > 60*60*24*7*2) {
476 $age_str = int $age/60/60/24/7;
477 $age_str .= " weeks ago";
478 } elsif ($age > 60*60*24*2) {
479 $age_str = int $age/60/60/24;
480 $age_str .= " days ago";
481 } elsif ($age > 60*60*2) {
482 $age_str = int $age/60/60;
483 $age_str .= " hours ago";
484 } elsif ($age > 60*2) {
485 $age_str = int $age/60;
486 $age_str .= " min ago";
489 $age_str .= " sec ago";
491 $age_str .= " right now";
496 # convert file mode in octal to symbolic file mode string
498 my $mode = oct shift;
500 if (S_ISDIR
($mode & S_IFMT
)) {
502 } elsif (S_ISLNK
($mode)) {
504 } elsif (S_ISREG
($mode)) {
505 # git cares only about the executable bit
506 if ($mode & S_IXUSR
) {
516 # convert file mode in octal to file type string
520 if ($mode !~ m/^[0-7]+$/) {
526 if (S_ISDIR
($mode & S_IFMT
)) {
528 } elsif (S_ISLNK
($mode)) {
530 } elsif (S_ISREG
($mode)) {
537 ## ----------------------------------------------------------------------
538 ## functions returning short HTML fragments, or transforming HTML fragments
539 ## which don't beling to other sections
541 # format line of commit message or tag comment
542 sub format_log_line_html
{
545 $line = esc_html
($line);
546 $line =~ s/ / /g;
547 if ($line =~ m/([0-9a-fA-F]{40})/) {
549 if (git_get_type
($hash_text) eq "commit") {
551 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
552 -class => "text"}, $hash_text);
553 $line =~ s/$hash_text/$link/;
559 # format marker of refs pointing to given object
560 sub format_ref_marker
{
561 my ($refs, $id) = @_;
564 if (defined $refs->{$id}) {
565 foreach my $ref (@
{$refs->{$id}}) {
566 my ($type, $name) = qw();
567 # e.g. tags/v2.6.11 or heads/next
568 if ($ref =~ m!^(.*?)s?/(.*)$!) {
576 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
581 return ' <span class="refs">'. $markers . '</span>';
587 # format, perhaps shortened and with markers, title line
588 sub format_subject_html
{
589 my ($long, $short, $href, $extra) = @_;
590 $extra = '' unless defined($extra);
592 if (length($short) < length($long)) {
593 return $cgi->a({-href
=> $href, -class => "list subject",
595 esc_html
($short) . $extra);
597 return $cgi->a({-href
=> $href, -class => "list subject"},
598 esc_html
($long) . $extra);
602 sub format_diff_line
{
604 my $char = substr($line, 0, 1);
610 $diff_class = " add";
611 } elsif ($char eq "-") {
612 $diff_class = " rem";
613 } elsif ($char eq "@") {
614 $diff_class = " chunk_header";
615 } elsif ($char eq "\\") {
616 $diff_class = " incomplete";
618 $line = untabify
($line);
619 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
622 ## ----------------------------------------------------------------------
623 ## git utility subroutines, invoking git commands
625 # returns path to the core git executable and the --git-dir parameter as list
627 return $GIT, '--git-dir='.$git_dir;
630 # returns path to the core git executable and the --git-dir parameter as string
632 return join(' ', git_cmd
());
635 # get HEAD ref of given project as hash
636 sub git_get_head_hash
{
638 my $o_git_dir = $git_dir;
640 $git_dir = "$projectroot/$project";
641 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
644 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
648 if (defined $o_git_dir) {
649 $git_dir = $o_git_dir;
654 # get type of given object
658 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
665 sub git_get_project_config
{
666 my ($key, $type) = @_;
668 return unless ($key);
669 $key =~ s/^gitweb\.//;
670 return if ($key =~ m/\W/);
672 my @x = (git_cmd
(), 'repo-config');
673 if (defined $type) { push @x, $type; }
675 push @x, "gitweb.$key";
681 # get hash of given path at given ref
682 sub git_get_hash_by_path
{
684 my $path = shift || return undef;
688 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
689 or die_error
(undef, "Open git-ls-tree failed");
691 close $fd or return undef;
693 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
694 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
698 ## ......................................................................
699 ## git utility functions, directly accessing git repository
701 sub git_get_project_description
{
704 open my $fd, "$projectroot/$path/description" or return undef;
711 sub git_get_project_url_list
{
714 open my $fd, "$projectroot/$path/cloneurl" or return undef;
715 my @git_project_url_list = map { chomp; $_ } <$fd>;
718 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
721 sub git_get_projects_list
{
724 if (-d
$projects_list) {
725 # search in directory
726 my $dir = $projects_list;
727 my $pfxlen = length("$dir");
730 follow_fast
=> 1, # follow symbolic links
731 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
733 # skip project-list toplevel, if we get it.
734 return if (m!^[/.]$!);
735 # only directories can be git repositories
736 return unless (-d
$_);
738 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
739 # we check related file in $projectroot
740 if (-e
"$projectroot/$subdir/HEAD") {
741 push @list, { path
=> $subdir };
742 $File::Find
::prune
= 1;
747 } elsif (-f
$projects_list) {
748 # read from file(url-encoded):
749 # 'git%2Fgit.git Linus+Torvalds'
750 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
751 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
752 open my ($fd), $projects_list or return undef;
753 while (my $line = <$fd>) {
755 my ($path, $owner) = split ' ', $line;
756 $path = unescape
($path);
757 $owner = unescape
($owner);
758 if (!defined $path) {
761 if (-e
"$projectroot/$path/HEAD") {
764 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
771 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
775 sub git_get_project_owner
{
779 return undef unless $project;
781 # read from file (url-encoded):
782 # 'git%2Fgit.git Linus+Torvalds'
783 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
784 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
785 if (-f
$projects_list) {
786 open (my $fd , $projects_list);
787 while (my $line = <$fd>) {
789 my ($pr, $ow) = split ' ', $line;
792 if ($pr eq $project) {
793 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
799 if (!defined $owner) {
800 $owner = get_file_owner
("$projectroot/$project");
806 sub git_get_references
{
807 my $type = shift || "";
810 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
811 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
812 if (-f
"$projectroot/$project/info/refs") {
813 open $fd, "$projectroot/$project/info/refs"
816 open $fd, "-|", git_cmd
(), "ls-remote", "."
820 while (my $line = <$fd>) {
822 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
823 if (defined $refs{$1}) {
824 push @
{$refs{$1}}, $2;
834 sub git_get_rev_name_tags
{
835 my $hash = shift || return undef;
837 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
839 my $name_rev = <$fd>;
842 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
845 # catches also '$hash undefined' output
850 ## ----------------------------------------------------------------------
851 ## parse to hash functions
855 my $tz = shift || "-0000";
858 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
859 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
860 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
861 $date{'hour'} = $hour;
862 $date{'minute'} = $min;
863 $date{'mday'} = $mday;
864 $date{'day'} = $days[$wday];
865 $date{'month'} = $months[$mon];
866 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
867 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
868 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
869 $mday, $months[$mon], $hour ,$min;
871 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
872 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
873 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
874 $date{'hour_local'} = $hour;
875 $date{'minute_local'} = $min;
876 $date{'tz_local'} = $tz;
885 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
886 $tag{'id'} = $tag_id;
887 while (my $line = <$fd>) {
889 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
891 } elsif ($line =~ m/^type (.+)$/) {
893 } elsif ($line =~ m/^tag (.+)$/) {
895 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
899 } elsif ($line =~ m/--BEGIN/) {
900 push @comment, $line;
902 } elsif ($line eq "") {
906 push @comment, <$fd>;
907 $tag{'comment'} = \
@comment;
909 if (!defined $tag{'name'}) {
916 my $commit_id = shift;
917 my $commit_text = shift;
922 if (defined $commit_text) {
923 @commit_lines = @
$commit_text;
926 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
928 @commit_lines = split '\n', <$fd>;
933 my $header = shift @commit_lines;
934 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
937 ($co{'id'}, my @parents) = split ' ', $header;
938 $co{'parents'} = \
@parents;
939 $co{'parent'} = $parents[0];
940 while (my $line = shift @commit_lines) {
941 last if $line eq "\n";
942 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
944 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
946 $co{'author_epoch'} = $2;
947 $co{'author_tz'} = $3;
948 if ($co{'author'} =~ m/^([^<]+) </) {
949 $co{'author_name'} = $1;
951 $co{'author_name'} = $co{'author'};
953 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
954 $co{'committer'} = $1;
955 $co{'committer_epoch'} = $2;
956 $co{'committer_tz'} = $3;
957 $co{'committer_name'} = $co{'committer'};
958 $co{'committer_name'} =~ s/ <.*//;
961 if (!defined $co{'tree'}) {
965 foreach my $title (@commit_lines) {
968 $co{'title'} = chop_str
($title, 80, 5);
969 # remove leading stuff of merges to make the interesting part visible
970 if (length($title) > 50) {
971 $title =~ s/^Automatic //;
972 $title =~ s/^merge (of|with) /Merge ... /i;
973 if (length($title) > 50) {
974 $title =~ s/(http|rsync):\/\///;
976 if (length($title) > 50) {
977 $title =~ s/(master|www|rsync)\.//;
979 if (length($title) > 50) {
980 $title =~ s/kernel.org:?//;
982 if (length($title) > 50) {
983 $title =~ s/\/pub\/scm//;
986 $co{'title_short'} = chop_str
($title, 50, 5);
990 # remove added spaces
991 foreach my $line (@commit_lines) {
994 $co{'comment'} = \
@commit_lines;
996 my $age = time - $co{'committer_epoch'};
998 $co{'age_string'} = age_string
($age);
999 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1000 if ($age > 60*60*24*7*2) {
1001 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1002 $co{'age_string_age'} = $co{'age_string'};
1004 $co{'age_string_date'} = $co{'age_string'};
1005 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1010 # parse ref from ref_file, given by ref_id, with given type
1012 my $ref_file = shift;
1014 my $type = shift || git_get_type
($ref_id);
1017 $ref_item{'type'} = $type;
1018 $ref_item{'id'} = $ref_id;
1019 $ref_item{'epoch'} = 0;
1020 $ref_item{'age'} = "unknown";
1021 if ($type eq "tag") {
1022 my %tag = parse_tag
($ref_id);
1023 $ref_item{'comment'} = $tag{'comment'};
1024 if ($tag{'type'} eq "commit") {
1025 my %co = parse_commit
($tag{'object'});
1026 $ref_item{'epoch'} = $co{'committer_epoch'};
1027 $ref_item{'age'} = $co{'age_string'};
1028 } elsif (defined($tag{'epoch'})) {
1029 my $age = time - $tag{'epoch'};
1030 $ref_item{'epoch'} = $tag{'epoch'};
1031 $ref_item{'age'} = age_string
($age);
1033 $ref_item{'reftype'} = $tag{'type'};
1034 $ref_item{'name'} = $tag{'name'};
1035 $ref_item{'refid'} = $tag{'object'};
1036 } elsif ($type eq "commit"){
1037 my %co = parse_commit
($ref_id);
1038 $ref_item{'reftype'} = "commit";
1039 $ref_item{'name'} = $ref_file;
1040 $ref_item{'title'} = $co{'title'};
1041 $ref_item{'refid'} = $ref_id;
1042 $ref_item{'epoch'} = $co{'committer_epoch'};
1043 $ref_item{'age'} = $co{'age_string'};
1045 $ref_item{'reftype'} = $type;
1046 $ref_item{'name'} = $ref_file;
1047 $ref_item{'refid'} = $ref_id;
1053 # parse line of git-diff-tree "raw" output
1054 sub parse_difftree_raw_line
{
1058 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1059 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1060 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1061 $res{'from_mode'} = $1;
1062 $res{'to_mode'} = $2;
1063 $res{'from_id'} = $3;
1065 $res{'status'} = $5;
1066 $res{'similarity'} = $6;
1067 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1068 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1070 $res{'file'} = unquote
($7);
1073 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1074 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1075 $res{'commit'} = $1;
1078 return wantarray ?
%res : \
%res;
1081 # parse line of git-ls-tree output
1082 sub parse_ls_tree_line
($;%) {
1087 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1088 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1096 $res{'name'} = unquote
($4);
1099 return wantarray ?
%res : \
%res;
1102 ## ......................................................................
1103 ## parse to array of hashes functions
1105 sub git_get_refs_list
{
1106 my $ref_dir = shift;
1110 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1112 while (my $line = <$fd>) {
1114 if ($line =~ m/^([0-9a-fA-F]{40})\t$ref_dir\/?
([^\
^]+)$/) {
1115 push @refs, { hash
=> $1, name
=> $2 };
1116 } elsif ($line =~ m/^[0-9a-fA-F]{40}\t$ref_dir\/?
(.*)\
^\
{\
}$/ &&
1117 $1 eq $refs[-1]{'name'}) {
1118 # most likely a tag is followed by its peeled
1119 # (deref) one, and when that happens we know the
1120 # previous one was of type 'tag'.
1121 $refs[-1]{'type'} = "tag";
1126 foreach my $ref (@refs) {
1127 my $ref_file = $ref->{'name'};
1128 my $ref_id = $ref->{'hash'};
1130 my $type = $ref->{'type'} || git_get_type
($ref_id) || next;
1131 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1133 push @reflist, \
%ref_item;
1136 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1140 ## ----------------------------------------------------------------------
1141 ## filesystem-related functions
1143 sub get_file_owner
{
1146 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1147 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1148 if (!defined $gcos) {
1152 $owner =~ s/[,;].*$//;
1153 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
1156 ## ......................................................................
1157 ## mimetype related functions
1159 sub mimetype_guess_file
{
1160 my $filename = shift;
1161 my $mimemap = shift;
1162 -r
$mimemap or return undef;
1165 open(MIME
, $mimemap) or return undef;
1167 next if m/^#/; # skip comments
1168 my ($mime, $exts) = split(/\t+/);
1169 if (defined $exts) {
1170 my @exts = split(/\s+/, $exts);
1171 foreach my $ext (@exts) {
1172 $mimemap{$ext} = $mime;
1178 $filename =~ /\.(.*?)$/;
1179 return $mimemap{$1};
1182 sub mimetype_guess
{
1183 my $filename = shift;
1185 $filename =~ /\./ or return undef;
1187 if ($mimetypes_file) {
1188 my $file = $mimetypes_file;
1189 if ($file !~ m!^/!) { # if it is relative path
1190 # it is relative to project
1191 $file = "$projectroot/$project/$file";
1193 $mime = mimetype_guess_file
($filename, $file);
1195 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1201 my $filename = shift;
1204 my $mime = mimetype_guess
($filename);
1205 $mime and return $mime;
1209 return $default_blob_plain_mimetype unless $fd;
1212 return 'text/plain' .
1213 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1214 } elsif (! $filename) {
1215 return 'application/octet-stream';
1216 } elsif ($filename =~ m/\.png$/i) {
1218 } elsif ($filename =~ m/\.gif$/i) {
1220 } elsif ($filename =~ m/\.jpe?g$/i) {
1221 return 'image/jpeg';
1223 return 'application/octet-stream';
1227 ## ======================================================================
1228 ## functions printing HTML: header, footer, error page
1230 sub git_header_html
{
1231 my $status = shift || "200 OK";
1232 my $expires = shift;
1234 my $title = "$site_name git";
1235 if (defined $project) {
1236 $title .= " - $project";
1237 if (defined $action) {
1238 $title .= "/$action";
1239 if (defined $file_name) {
1240 $title .= " - $file_name";
1241 if ($action eq "tree" && $file_name !~ m
|/$|) {
1248 # require explicit support from the UA if we are to send the page as
1249 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1250 # we have to do this because MSIE sometimes globs '*/*', pretending to
1251 # support xhtml+xml but choking when it gets what it asked for.
1252 if (defined $cgi->http('HTTP_ACCEPT') &&
1253 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1254 $cgi->Accept('application/xhtml+xml') != 0) {
1255 $content_type = 'application/xhtml+xml';
1257 $content_type = 'text/html';
1259 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1260 -status
=> $status, -expires
=> $expires);
1262 <?xml version="1.0" encoding="utf-8"?>
1263 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1264 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1265 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1266 <!-- git core binaries version $git_version -->
1268 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1269 <meta name="generator" content="gitweb/$version git/$git_version"/>
1270 <meta name="robots" content="index, nofollow"/>
1271 <title>$title</title>
1272 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1274 if (defined $project) {
1275 printf('<link rel="alternate" title="%s log" '.
1276 'href="%s" type="application/rss+xml"/>'."\n",
1277 esc_param
($project), href
(action
=>"rss"));
1279 printf('<link rel="alternate" title="%s projects list" '.
1280 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1281 $site_name, href
(project
=>undef, action
=>"project_index"));
1282 printf('<link rel="alternate" title="%s projects logs" '.
1283 'href="%s" type="text/x-opml"/>'."\n",
1284 $site_name, href
(project
=>undef, action
=>"opml"));
1286 if (defined $favicon) {
1287 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
1292 "<div class=\"page_header\">\n" .
1293 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1294 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1296 print $cgi->a({-href
=> esc_param
($home_link)}, $home_link_str) . " / ";
1297 if (defined $project) {
1298 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1299 if (defined $action) {
1303 if (!defined $searchtext) {
1307 if (defined $hash_base) {
1308 $search_hash = $hash_base;
1309 } elsif (defined $hash) {
1310 $search_hash = $hash;
1312 $search_hash = "HEAD";
1314 $cgi->param("a", "search");
1315 $cgi->param("h", $search_hash);
1316 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1317 "<div class=\"search\">\n" .
1318 $cgi->hidden(-name
=> "p") . "\n" .
1319 $cgi->hidden(-name
=> "a") . "\n" .
1320 $cgi->hidden(-name
=> "h") . "\n" .
1321 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1323 $cgi->end_form() . "\n";
1328 sub git_footer_html
{
1329 print "<div class=\"page_footer\">\n";
1330 if (defined $project) {
1331 my $descr = git_get_project_description
($project);
1332 if (defined $descr) {
1333 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1335 print $cgi->a({-href
=> href
(action
=>"rss"),
1336 -class => "rss_logo"}, "RSS") . "\n";
1338 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1339 -class => "rss_logo"}, "OPML") . " ";
1340 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1341 -class => "rss_logo"}, "TXT") . "\n";
1349 my $status = shift || "403 Forbidden";
1350 my $error = shift || "Malformed query, file missing or permission denied";
1352 git_header_html
($status);
1354 <div class="page_body">
1364 ## ----------------------------------------------------------------------
1365 ## functions printing or outputting HTML: navigation
1367 sub git_print_page_nav
{
1368 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1369 $extra = '' if !defined $extra; # pager or formats
1371 my @navs = qw(summary shortlog log commit commitdiff tree);
1373 @navs = grep { $_ ne $suppress } @navs;
1376 my %arg = map { $_ => {action
=>$_} } @navs;
1377 if (defined $head) {
1378 for (qw(commit commitdiff)) {
1379 $arg{$_}{hash
} = $head;
1381 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1382 for (qw(shortlog log)) {
1383 $arg{$_}{hash
} = $head;
1387 $arg{tree
}{hash
} = $treehead if defined $treehead;
1388 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1390 print "<div class=\"page_nav\">\n" .
1392 map { $_ eq $current ?
1393 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1395 print "<br/>\n$extra<br/>\n" .
1399 sub format_paging_nav
{
1400 my ($action, $hash, $head, $page, $nrevs) = @_;
1404 if ($hash ne $head || $page) {
1405 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1407 $paging_nav .= "HEAD";
1411 $paging_nav .= " ⋅ " .
1412 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1413 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1415 $paging_nav .= " ⋅ prev";
1418 if ($nrevs >= (100 * ($page+1)-1)) {
1419 $paging_nav .= " ⋅ " .
1420 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1421 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1423 $paging_nav .= " ⋅ next";
1429 ## ......................................................................
1430 ## functions printing or outputting HTML: div
1432 sub git_print_header_div
{
1433 my ($action, $title, $hash, $hash_base) = @_;
1436 $args{action
} = $action;
1437 $args{hash
} = $hash if $hash;
1438 $args{hash_base
} = $hash_base if $hash_base;
1440 print "<div class=\"header\">\n" .
1441 $cgi->a({-href
=> href
(%args), -class => "title"},
1442 $title ?
$title : $action) .
1446 #sub git_print_authorship (\%) {
1447 sub git_print_authorship
{
1450 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1451 print "<div class=\"author_date\">" .
1452 esc_html
($co->{'author_name'}) .
1454 if ($ad{'hour_local'} < 6) {
1455 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1456 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1458 printf(" (%02d:%02d %s)",
1459 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1464 sub git_print_page_path
{
1469 if (!defined $name) {
1470 print "<div class=\"page_path\">/</div>\n";
1472 my @dirname = split '/', $name;
1473 my $basename = pop @dirname;
1476 print "<div class=\"page_path\">";
1477 foreach my $dir (@dirname) {
1478 $fullname .= $dir . '/';
1479 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1481 -title
=> $fullname}, esc_html
($dir));
1484 if (defined $type && $type eq 'blob') {
1485 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1487 -title
=> $name}, esc_html
($basename));
1488 } elsif (defined $type && $type eq 'tree') {
1489 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1491 -title
=> $name}, esc_html
($basename));
1494 print esc_html
($basename);
1496 print "<br/></div>\n";
1500 # sub git_print_log (\@;%) {
1501 sub git_print_log
($;%) {
1505 if ($opts{'-remove_title'}) {
1506 # remove title, i.e. first line of log
1509 # remove leading empty lines
1510 while (defined $log->[0] && $log->[0] eq "") {
1517 foreach my $line (@
$log) {
1518 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1521 if (! $opts{'-remove_signoff'}) {
1522 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1525 # remove signoff lines
1532 # print only one empty line
1533 # do not print empty line after signoff
1535 next if ($empty || $signoff);
1541 print format_log_line_html
($line) . "<br/>\n";
1544 if ($opts{'-final_empty_line'}) {
1545 # end with single empty line
1546 print "<br/>\n" unless $empty;
1550 sub git_print_simplified_log
{
1552 my $remove_title = shift;
1555 -final_empty_line
=> 1,
1556 -remove_title
=> $remove_title);
1559 # print tree entry (row of git_tree), but without encompassing <tr> element
1560 sub git_print_tree_entry
{
1561 my ($t, $basedir, $hash_base, $have_blame) = @_;
1564 $base_key{hash_base
} = $hash_base if defined $hash_base;
1566 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1567 if ($t->{'type'} eq "blob") {
1568 print "<td class=\"list\">" .
1569 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1570 file_name
=>"$basedir$t->{'name'}", %base_key),
1571 -class => "list"}, esc_html
($t->{'name'})) .
1573 "<td class=\"link\">" .
1574 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1575 file_name
=>"$basedir$t->{'name'}", %base_key)},
1579 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1580 file_name
=>"$basedir$t->{'name'}", %base_key)},
1583 if (defined $hash_base) {
1585 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1586 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1590 $cgi->a({-href
=> href
(action
=>"blob_plain",
1591 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1595 } elsif ($t->{'type'} eq "tree") {
1596 print "<td class=\"list\">" .
1597 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1598 file_name
=>"$basedir$t->{'name'}", %base_key)},
1599 esc_html
($t->{'name'})) .
1601 "<td class=\"link\">" .
1602 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1603 file_name
=>"$basedir$t->{'name'}", %base_key)},
1605 if (defined $hash_base) {
1607 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1608 file_name
=>"$basedir$t->{'name'}")},
1615 ## ......................................................................
1616 ## functions printing large fragments of HTML
1618 sub git_difftree_body
{
1619 my ($difftree, $hash, $parent) = @_;
1621 print "<div class=\"list_head\">\n";
1622 if ($#{$difftree} > 10) {
1623 print(($#{$difftree} + 1) . " files changed:\n");
1627 print "<table class=\"diff_tree\">\n";
1630 foreach my $line (@
{$difftree}) {
1631 my %diff = parse_difftree_raw_line
($line);
1634 print "<tr class=\"dark\">\n";
1636 print "<tr class=\"light\">\n";
1640 my ($to_mode_oct, $to_mode_str, $to_file_type);
1641 my ($from_mode_oct, $from_mode_str, $from_file_type);
1642 if ($diff{'to_mode'} ne ('0' x
6)) {
1643 $to_mode_oct = oct $diff{'to_mode'};
1644 if (S_ISREG
($to_mode_oct)) { # only for regular file
1645 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1647 $to_file_type = file_type
($diff{'to_mode'});
1649 if ($diff{'from_mode'} ne ('0' x
6)) {
1650 $from_mode_oct = oct $diff{'from_mode'};
1651 if (S_ISREG
($to_mode_oct)) { # only for regular file
1652 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1654 $from_file_type = file_type
($diff{'from_mode'});
1657 if ($diff{'status'} eq "A") { # created
1658 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1659 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1660 $mode_chng .= "]</span>";
1662 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1663 hash_base
=>$hash, file_name
=>$diff{'file'}),
1664 -class => "list"}, esc_html
($diff{'file'})) .
1666 "<td>$mode_chng</td>\n" .
1667 "<td class=\"link\">" .
1668 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1669 hash_base
=>$hash, file_name
=>$diff{'file'})},
1671 if ($action eq 'commitdiff') {
1675 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1679 } elsif ($diff{'status'} eq "D") { # deleted
1680 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1682 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1683 hash_base
=>$parent, file_name
=>$diff{'file'}),
1684 -class => "list"}, esc_html
($diff{'file'})) .
1686 "<td>$mode_chng</td>\n" .
1687 "<td class=\"link\">" .
1688 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1689 hash_base
=>$parent, file_name
=>$diff{'file'})},
1692 if ($action eq 'commitdiff') {
1696 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1698 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1699 file_name
=>$diff{'file'})},
1703 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1704 my $mode_chnge = "";
1705 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1706 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1707 if ($from_file_type != $to_file_type) {
1708 $mode_chnge .= " from $from_file_type to $to_file_type";
1710 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1711 if ($from_mode_str && $to_mode_str) {
1712 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1713 } elsif ($to_mode_str) {
1714 $mode_chnge .= " mode: $to_mode_str";
1717 $mode_chnge .= "]</span>\n";
1720 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1721 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1722 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1723 hash_base
=>$hash, hash_parent_base
=>$parent,
1724 file_name
=>$diff{'file'}),
1725 -class => "list"}, esc_html
($diff{'file'}));
1726 } else { # only mode changed
1727 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1728 hash_base
=>$hash, file_name
=>$diff{'file'}),
1729 -class => "list"}, esc_html
($diff{'file'}));
1732 "<td>$mode_chnge</td>\n" .
1733 "<td class=\"link\">" .
1734 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1735 hash_base
=>$hash, file_name
=>$diff{'file'})},
1737 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1738 if ($action eq 'commitdiff') {
1742 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1745 $cgi->a({-href
=> href
(action
=>"blobdiff",
1746 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1747 hash_base
=>$hash, hash_parent_base
=>$parent,
1748 file_name
=>$diff{'file'})},
1753 $cgi->a({-href
=> href
(action
=>"history",
1754 hash_base
=>$hash, file_name
=>$diff{'file'})},
1758 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1759 my %status_name = ('R' => 'moved', 'C' => 'copied');
1760 my $nstatus = $status_name{$diff{'status'}};
1762 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1763 # mode also for directories, so we cannot use $to_mode_str
1764 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1767 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1768 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1769 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1770 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1771 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1772 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1773 -class => "list"}, esc_html
($diff{'from_file'})) .
1774 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1775 "<td class=\"link\">" .
1776 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1777 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'})},
1779 if ($diff{'to_id'} ne $diff{'from_id'}) {
1780 if ($action eq 'commitdiff') {
1784 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1787 $cgi->a({-href
=> href
(action
=>"blobdiff",
1788 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1789 hash_base
=>$hash, hash_parent_base
=>$parent,
1790 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1796 } # we should not encounter Unmerged (U) or Unknown (X) status
1802 sub git_patchset_body
{
1803 my ($fd, $difftree, $hash, $hash_parent) = @_;
1807 my $patch_found = 0;
1810 print "<div class=\"patchset\">\n";
1813 while (my $patch_line = <$fd>) {
1816 if ($patch_line =~ m/^diff /) { # "git diff" header
1817 # beginning of patch (in patchset)
1819 # close previous patch
1820 print "</div>\n"; # class="patch"
1822 # first patch in patchset
1825 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1827 if (ref($difftree->[$patch_idx]) eq "HASH") {
1828 $diffinfo = $difftree->[$patch_idx];
1830 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1834 # for now, no extended header, hence we skip empty patches
1835 # companion to next LINE if $in_header;
1836 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1841 if ($diffinfo->{'status'} eq "A") { # added
1842 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1843 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1844 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1845 $diffinfo->{'to_id'}) . "(new)" .
1846 "</div>\n"; # class="diff_info"
1848 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1849 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
1850 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1851 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1852 $diffinfo->{'from_id'}) . "(deleted)" .
1853 "</div>\n"; # class="diff_info"
1855 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1856 $diffinfo->{'status'} eq "C" || # copied
1857 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1858 print "<div class=\"diff_info\">" .
1859 file_type
($diffinfo->{'from_mode'}) . ":" .
1860 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1861 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
1862 $diffinfo->{'from_id'}) .
1864 file_type
($diffinfo->{'to_mode'}) . ":" .
1865 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1866 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
1867 $diffinfo->{'to_id'});
1868 print "</div>\n"; # class="diff_info"
1870 } else { # modified, mode changed, ...
1871 print "<div class=\"diff_info\">" .
1872 file_type
($diffinfo->{'from_mode'}) . ":" .
1873 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1874 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1875 $diffinfo->{'from_id'}) .
1877 file_type
($diffinfo->{'to_mode'}) . ":" .
1878 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1879 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1880 $diffinfo->{'to_id'});
1881 print "</div>\n"; # class="diff_info"
1884 #print "<div class=\"diff extended_header\">\n";
1887 } # start of patch in patchset
1890 if ($in_header && $patch_line =~ m/^---/) {
1891 #print "</div>\n"; # class="diff extended_header"
1894 my $file = $diffinfo->{'from_file'};
1895 $file ||= $diffinfo->{'file'};
1896 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1897 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
1898 -class => "list"}, esc_html
($file));
1899 $patch_line =~ s
|a
/.*$|a/$file|g
;
1900 print "<div class=\"diff from_file\">$patch_line</div>\n";
1902 $patch_line = <$fd>;
1905 #$patch_line =~ m/^+++/;
1906 $file = $diffinfo->{'to_file'};
1907 $file ||= $diffinfo->{'file'};
1908 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1909 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
1910 -class => "list"}, esc_html
($file));
1911 $patch_line =~ s
|b
/.*|b/$file|g
;
1912 print "<div class=\"diff to_file\">$patch_line</div>\n";
1916 next LINE
if $in_header;
1918 print format_diff_line
($patch_line);
1920 print "</div>\n" if $patch_found; # class="patch"
1922 print "</div>\n"; # class="patchset"
1925 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1927 sub git_shortlog_body
{
1928 # uses global variable $project
1929 my ($revlist, $from, $to, $refs, $extra) = @_;
1931 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
1932 my $have_snapshot = (defined $ctype && defined $suffix);
1934 $from = 0 unless defined $from;
1935 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1937 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1939 for (my $i = $from; $i <= $to; $i++) {
1940 my $commit = $revlist->[$i];
1941 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1942 my $ref = format_ref_marker
($refs, $commit);
1943 my %co = parse_commit
($commit);
1945 print "<tr class=\"dark\">\n";
1947 print "<tr class=\"light\">\n";
1950 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1951 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1952 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1954 print format_subject_html
($co{'title'}, $co{'title_short'},
1955 href
(action
=>"commit", hash
=>$commit), $ref);
1957 "<td class=\"link\">" .
1958 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1959 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
1960 if ($have_snapshot) {
1961 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
1966 if (defined $extra) {
1968 "<td colspan=\"4\">$extra</td>\n" .
1974 sub git_history_body
{
1975 # Warning: assumes constant type (blob or tree) during history
1976 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
1978 $from = 0 unless defined $from;
1979 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
1981 print "<table class=\"history\" cellspacing=\"0\">\n";
1983 for (my $i = $from; $i <= $to; $i++) {
1984 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
1989 my %co = parse_commit
($commit);
1994 my $ref = format_ref_marker
($refs, $commit);
1997 print "<tr class=\"dark\">\n";
1999 print "<tr class=\"light\">\n";
2002 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2003 # shortlog uses chop_str($co{'author_name'}, 10)
2004 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2006 # originally git_history used chop_str($co{'title'}, 50)
2007 print format_subject_html
($co{'title'}, $co{'title_short'},
2008 href
(action
=>"commit", hash
=>$commit), $ref);
2010 "<td class=\"link\">" .
2011 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
2012 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2013 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype);
2015 if ($ftype eq 'blob') {
2016 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2017 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2018 if (defined $blob_current && defined $blob_parent &&
2019 $blob_current ne $blob_parent) {
2021 $cgi->a({-href
=> href
(action
=>"blobdiff",
2022 hash
=>$blob_current, hash_parent
=>$blob_parent,
2023 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2024 file_name
=>$file_name)},
2031 if (defined $extra) {
2033 "<td colspan=\"4\">$extra</td>\n" .
2040 # uses global variable $project
2041 my ($taglist, $from, $to, $extra) = @_;
2042 $from = 0 unless defined $from;
2043 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2045 print "<table class=\"tags\" cellspacing=\"0\">\n";
2047 for (my $i = $from; $i <= $to; $i++) {
2048 my $entry = $taglist->[$i];
2050 my $comment_lines = $tag{'comment'};
2051 my $comment = shift @
$comment_lines;
2053 if (defined $comment) {
2054 $comment_short = chop_str
($comment, 30, 5);
2057 print "<tr class=\"dark\">\n";
2059 print "<tr class=\"light\">\n";
2062 print "<td><i>$tag{'age'}</i></td>\n" .
2064 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2065 -class => "list name"}, esc_html
($tag{'name'})) .
2068 if (defined $comment) {
2069 print format_subject_html
($comment, $comment_short,
2070 href
(action
=>"tag", hash
=>$tag{'id'}));
2073 "<td class=\"selflink\">";
2074 if ($tag{'type'} eq "tag") {
2075 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2080 "<td class=\"link\">" . " | " .
2081 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2082 if ($tag{'reftype'} eq "commit") {
2083 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2084 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
2085 } elsif ($tag{'reftype'} eq "blob") {
2086 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2091 if (defined $extra) {
2093 "<td colspan=\"5\">$extra</td>\n" .
2099 sub git_heads_body
{
2100 # uses global variable $project
2101 my ($taglist, $head, $from, $to, $extra) = @_;
2102 $from = 0 unless defined $from;
2103 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2105 print "<table class=\"heads\" cellspacing=\"0\">\n";
2107 for (my $i = $from; $i <= $to; $i++) {
2108 my $entry = $taglist->[$i];
2110 my $curr = $tag{'id'} eq $head;
2112 print "<tr class=\"dark\">\n";
2114 print "<tr class=\"light\">\n";
2117 print "<td><i>$tag{'age'}</i></td>\n" .
2118 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
2119 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
2120 -class => "list name"},esc_html
($tag{'name'})) .
2122 "<td class=\"link\">" .
2123 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
2124 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") .
2128 if (defined $extra) {
2130 "<td colspan=\"3\">$extra</td>\n" .
2136 ## ======================================================================
2137 ## ======================================================================
2140 sub git_project_list
{
2141 my $order = $cgi->param('o');
2142 if (defined $order && $order !~ m/project|descr|owner|age/) {
2143 die_error
(undef, "Unknown order parameter");
2146 my @list = git_get_projects_list
();
2149 die_error
(undef, "No projects found");
2151 foreach my $pr (@list) {
2152 my $head = git_get_head_hash
($pr->{'path'});
2153 if (!defined $head) {
2156 $git_dir = "$projectroot/$pr->{'path'}";
2157 my %co = parse_commit
($head);
2161 $pr->{'commit'} = \
%co;
2162 if (!defined $pr->{'descr'}) {
2163 my $descr = git_get_project_description
($pr->{'path'}) || "";
2164 $pr->{'descr'} = chop_str
($descr, 25, 5);
2166 if (!defined $pr->{'owner'}) {
2167 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2169 push @projects, $pr;
2173 if (-f
$home_text) {
2174 print "<div class=\"index_include\">\n";
2175 open (my $fd, $home_text);
2180 print "<table class=\"project_list\">\n" .
2182 $order ||= "project";
2183 if ($order eq "project") {
2184 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2185 print "<th>Project</th>\n";
2188 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2189 -class => "header"}, "Project") .
2192 if ($order eq "descr") {
2193 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2194 print "<th>Description</th>\n";
2197 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2198 -class => "header"}, "Description") .
2201 if ($order eq "owner") {
2202 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2203 print "<th>Owner</th>\n";
2206 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2207 -class => "header"}, "Owner") .
2210 if ($order eq "age") {
2211 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2212 print "<th>Last Change</th>\n";
2215 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2216 -class => "header"}, "Last Change") .
2219 print "<th></th>\n" .
2222 foreach my $pr (@projects) {
2224 print "<tr class=\"dark\">\n";
2226 print "<tr class=\"light\">\n";
2229 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2230 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2231 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2232 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2233 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2234 $pr->{'commit'}{'age_string'} . "</td>\n" .
2235 "<td class=\"link\">" .
2236 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2237 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2238 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") .
2246 sub git_project_index
{
2247 my @projects = git_get_projects_list
();
2250 -type
=> 'text/plain',
2251 -charset
=> 'utf-8',
2252 -content_disposition
=> qq(inline
; filename
="index.aux"));
2254 foreach my $pr (@projects) {
2255 if (!exists $pr->{'owner'}) {
2256 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2259 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2260 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2261 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2262 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2266 print "$path $owner\n";
2271 my $descr = git_get_project_description
($project) || "none";
2272 my $head = git_get_head_hash
($project);
2273 my %co = parse_commit
($head);
2274 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2276 my $owner = git_get_project_owner
($project);
2278 my $refs = git_get_references
();
2280 git_print_page_nav
('summary','', $head);
2282 print "<div class=\"title\"> </div>\n";
2283 print "<table cellspacing=\"0\">\n" .
2284 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2285 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2286 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2287 # use per project git URL list in $projectroot/$project/cloneurl
2288 # or make project git URL from git base URL and project name
2289 my $url_tag = "URL";
2290 my @url_list = git_get_project_url_list
($project);
2291 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2292 foreach my $git_url (@url_list) {
2293 next unless $git_url;
2294 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2299 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2300 git_get_head_hash
($project)
2301 or die_error
(undef, "Open git-rev-list failed");
2302 my @revlist = map { chomp; $_ } <$fd>;
2304 git_print_header_div
('shortlog');
2305 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2306 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2308 my $taglist = git_get_refs_list
("refs/tags");
2309 if (defined @
$taglist) {
2310 git_print_header_div
('tags');
2311 git_tags_body
($taglist, 0, 15,
2312 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2315 my $headlist = git_get_refs_list
("refs/heads");
2316 if (defined @
$headlist) {
2317 git_print_header_div
('heads');
2318 git_heads_body
($headlist, $head, 0, 15,
2319 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2326 my $head = git_get_head_hash
($project);
2328 git_print_page_nav
('','', $head,undef,$head);
2329 my %tag = parse_tag
($hash);
2330 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2331 print "<div class=\"title_text\">\n" .
2332 "<table cellspacing=\"0\">\n" .
2334 "<td>object</td>\n" .
2335 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2336 $tag{'object'}) . "</td>\n" .
2337 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2338 $tag{'type'}) . "</td>\n" .
2340 if (defined($tag{'author'})) {
2341 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2342 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2343 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2344 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2347 print "</table>\n\n" .
2349 print "<div class=\"page_body\">";
2350 my $comment = $tag{'comment'};
2351 foreach my $line (@
$comment) {
2352 print esc_html
($line) . "<br/>\n";
2362 my ($have_blame) = gitweb_check_feature
('blame');
2364 die_error
('403 Permission denied', "Permission denied");
2366 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2367 $hash_base ||= git_get_head_hash
($project);
2368 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2369 my %co = parse_commit
($hash_base)
2370 or die_error
(undef, "Reading commit failed");
2371 if (!defined $hash) {
2372 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2373 or die_error
(undef, "Error looking up file");
2375 $ftype = git_get_type
($hash);
2376 if ($ftype !~ "blob") {
2377 die_error
("400 Bad Request", "Object is not a blob");
2379 open ($fd, "-|", git_cmd
(), "blame", '-l', $file_name, $hash_base)
2380 or die_error
(undef, "Open git-blame failed");
2383 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2386 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2388 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2389 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2390 git_print_page_path
($file_name, $ftype, $hash_base);
2391 my @rev_color = (qw(light2 dark2));
2392 my $num_colors = scalar(@rev_color);
2393 my $current_color = 0;
2396 <div class="page_body">
2397 <table class="blame">
2398 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2401 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2403 my $rev = substr($full_rev, 0, 8);
2407 if (!defined $last_rev) {
2408 $last_rev = $full_rev;
2409 } elsif ($last_rev ne $full_rev) {
2410 $last_rev = $full_rev;
2411 $current_color = ++$current_color % $num_colors;
2413 print "<tr class=\"$rev_color[$current_color]\">\n";
2414 print "<td class=\"sha1\">" .
2415 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)},
2416 esc_html
($rev)) . "</td>\n";
2417 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2418 esc_html
($lineno) . "</a></td>\n";
2419 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2425 or print "Reading blob failed\n";
2432 my ($have_blame) = gitweb_check_feature
('blame');
2434 die_error
('403 Permission denied', "Permission denied");
2436 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2437 $hash_base ||= git_get_head_hash
($project);
2438 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2439 my %co = parse_commit
($hash_base)
2440 or die_error
(undef, "Reading commit failed");
2441 if (!defined $hash) {
2442 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2443 or die_error
(undef, "Error lookup file");
2445 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2446 or die_error
(undef, "Open git-annotate failed");
2449 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2452 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2454 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2455 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2456 git_print_page_path
($file_name, 'blob', $hash_base);
2457 print "<div class=\"page_body\">\n";
2459 <table class="blame">
2468 my @line_class = (qw(light dark));
2469 my $line_class_len = scalar (@line_class);
2470 my $line_class_num = $#line_class;
2471 while (my $line = <$fd>) {
2483 $line_class_num = ($line_class_num + 1) % $line_class_len;
2485 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2492 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2495 $short_rev = substr ($long_rev, 0, 8);
2496 $age = time () - $time;
2497 $age_str = age_string
($age);
2498 $age_str =~ s/ / /g;
2499 $age_class = age_class
($age);
2500 $author = esc_html
($author);
2501 $author =~ s/ / /g;
2503 $data = untabify
($data);
2504 $data = esc_html
($data);
2507 <tr class="$line_class[$line_class_num]">
2508 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2509 <td class="$age_class">$age_str</td>
2511 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2512 <td class="pre">$data</td>
2515 } # while (my $line = <$fd>)
2516 print "</table>\n\n";
2518 or print "Reading blob failed.\n";
2524 my $head = git_get_head_hash
($project);
2526 git_print_page_nav
('','', $head,undef,$head);
2527 git_print_header_div
('summary', $project);
2529 my $taglist = git_get_refs_list
("refs/tags");
2530 if (defined @
$taglist) {
2531 git_tags_body
($taglist);
2537 my $head = git_get_head_hash
($project);
2539 git_print_page_nav
('','', $head,undef,$head);
2540 git_print_header_div
('summary', $project);
2542 my $taglist = git_get_refs_list
("refs/heads");
2543 if (defined @
$taglist) {
2544 git_heads_body
($taglist, $head);
2549 sub git_blob_plain
{
2552 if (!defined $hash) {
2553 if (defined $file_name) {
2554 my $base = $hash_base || git_get_head_hash
($project);
2555 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2556 or die_error
(undef, "Error lookup file");
2558 die_error
(undef, "No file name defined");
2560 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2561 # blobs defined by non-textual hash id's can be cached
2566 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2567 or die_error
(undef, "Couldn't cat $file_name, $hash");
2569 $type ||= blob_mimetype
($fd, $file_name);
2571 # save as filename, even when no $file_name is given
2572 my $save_as = "$hash";
2573 if (defined $file_name) {
2574 $save_as = $file_name;
2575 } elsif ($type =~ m/^text\//) {
2582 -content_disposition
=> "inline; filename=\"$save_as\"");
2584 binmode STDOUT
, ':raw';
2586 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2594 if (!defined $hash) {
2595 if (defined $file_name) {
2596 my $base = $hash_base || git_get_head_hash
($project);
2597 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2598 or die_error
(undef, "Error lookup file");
2600 die_error
(undef, "No file name defined");
2602 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2603 # blobs defined by non-textual hash id's can be cached
2607 my ($have_blame) = gitweb_check_feature
('blame');
2608 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2609 or die_error
(undef, "Couldn't cat $file_name, $hash");
2610 my $mimetype = blob_mimetype
($fd, $file_name);
2611 if ($mimetype !~ m/^text\//) {
2613 return git_blob_plain
($mimetype);
2615 git_header_html
(undef, $expires);
2616 my $formats_nav = '';
2617 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2618 if (defined $file_name) {
2621 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2622 hash
=>$hash, file_name
=>$file_name)},
2627 $cgi->a({-href
=> href
(action
=>"blob_plain",
2628 hash
=>$hash, file_name
=>$file_name)},
2631 $cgi->a({-href
=> href
(action
=>"blob",
2632 hash_base
=>"HEAD", file_name
=>$file_name)},
2636 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "plain");
2638 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2639 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2641 print "<div class=\"page_nav\">\n" .
2642 "<br/><br/></div>\n" .
2643 "<div class=\"title\">$hash</div>\n";
2645 git_print_page_path
($file_name, "blob", $hash_base);
2646 print "<div class=\"page_body\">\n";
2648 while (my $line = <$fd>) {
2651 $line = untabify
($line);
2652 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2653 $nr, $nr, $nr, esc_html
($line);
2656 or print "Reading blob failed.\n";
2662 if (!defined $hash) {
2663 $hash = git_get_head_hash
($project);
2664 if (defined $file_name) {
2665 my $base = $hash_base || $hash;
2666 $hash = git_get_hash_by_path
($base, $file_name, "tree");
2668 if (!defined $hash_base) {
2673 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
2674 or die_error
(undef, "Open git-ls-tree failed");
2675 my @entries = map { chomp; $_ } <$fd>;
2676 close $fd or die_error
(undef, "Reading tree failed");
2679 my $refs = git_get_references
();
2680 my $ref = format_ref_marker
($refs, $hash_base);
2683 my ($have_blame) = gitweb_check_feature
('blame');
2684 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2685 git_print_page_nav
('tree','', $hash_base);
2686 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2689 print "<div class=\"page_nav\">\n";
2690 print "<br/><br/></div>\n";
2691 print "<div class=\"title\">$hash</div>\n";
2693 if (defined $file_name) {
2694 $base = esc_html
("$file_name/");
2696 git_print_page_path
($file_name, 'tree', $hash_base);
2697 print "<div class=\"page_body\">\n";
2698 print "<table cellspacing=\"0\">\n";
2700 foreach my $line (@entries) {
2701 my %t = parse_ls_tree_line
($line, -z
=> 1);
2704 print "<tr class=\"dark\">\n";
2706 print "<tr class=\"light\">\n";
2710 git_print_tree_entry
(\
%t, $base, $hash_base, $have_blame);
2714 print "</table>\n" .
2721 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2722 my $have_snapshot = (defined $ctype && defined $suffix);
2723 if (!$have_snapshot) {
2724 die_error
('403 Permission denied', "Permission denied");
2727 if (!defined $hash) {
2728 $hash = git_get_head_hash
($project);
2731 my $filename = basename
($project) . "-$hash.tar.$suffix";
2733 print $cgi->header(-type
=> 'application/x-tar',
2734 -content_encoding
=> $ctype,
2735 -content_disposition
=> "inline; filename=\"$filename\"",
2736 -status
=> '200 OK');
2738 my $git_command = git_cmd_str
();
2739 open my $fd, "-|", "$git_command tar-tree $hash \'$project\' | $command" or
2740 die_error
(undef, "Execute git-tar-tree failed.");
2741 binmode STDOUT
, ':raw';
2743 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2749 my $head = git_get_head_hash
($project);
2750 if (!defined $hash) {
2753 if (!defined $page) {
2756 my $refs = git_get_references
();
2758 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2759 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
2760 or die_error
(undef, "Open git-rev-list failed");
2761 my @revlist = map { chomp; $_ } <$fd>;
2764 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2767 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2770 my %co = parse_commit
($hash);
2772 git_print_header_div
('summary', $project);
2773 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2775 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2776 my $commit = $revlist[$i];
2777 my $ref = format_ref_marker
($refs, $commit);
2778 my %co = parse_commit
($commit);
2780 my %ad = parse_date
($co{'author_epoch'});
2781 git_print_header_div
('commit',
2782 "<span class=\"age\">$co{'age_string'}</span>" .
2783 esc_html
($co{'title'}) . $ref,
2785 print "<div class=\"title_text\">\n" .
2786 "<div class=\"log_link\">\n" .
2787 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2789 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2792 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2795 print "<div class=\"log_body\">\n";
2796 git_print_simplified_log
($co{'comment'});
2803 my %co = parse_commit
($hash);
2805 die_error
(undef, "Unknown commit object");
2807 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2808 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2810 my $parent = $co{'parent'};
2811 if (!defined $parent) {
2814 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $parent, $hash
2815 or die_error
(undef, "Open git-diff-tree failed");
2816 my @difftree = map { chomp; $_ } <$fd>;
2817 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2819 # non-textual hash id's can be cached
2821 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2824 my $refs = git_get_references
();
2825 my $ref = format_ref_marker
($refs, $co{'id'});
2827 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2828 my $have_snapshot = (defined $ctype && defined $suffix);
2830 my $formats_nav = '';
2831 if (defined $file_name && defined $co{'parent'}) {
2832 my $parent = $co{'parent'};
2834 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
2837 git_header_html
(undef, $expires);
2838 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
2839 $hash, $co{'tree'}, $hash,
2842 if (defined $co{'parent'}) {
2843 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2845 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
2847 print "<div class=\"title_text\">\n" .
2848 "<table cellspacing=\"0\">\n";
2849 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2851 "<td></td><td> $ad{'rfc2822'}";
2852 if ($ad{'hour_local'} < 6) {
2853 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2854 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2856 printf(" (%02d:%02d %s)",
2857 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2861 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2862 print "<tr><td></td><td> $cd{'rfc2822'}" .
2863 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2865 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2868 "<td class=\"sha1\">" .
2869 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
2870 class => "list"}, $co{'tree'}) .
2872 "<td class=\"link\">" .
2873 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
2875 if ($have_snapshot) {
2877 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
2881 my $parents = $co{'parents'};
2882 foreach my $par (@
$parents) {
2885 "<td class=\"sha1\">" .
2886 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
2887 class => "list"}, $par) .
2889 "<td class=\"link\">" .
2890 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
2892 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
2899 print "<div class=\"page_body\">\n";
2900 git_print_log
($co{'comment'});
2903 git_difftree_body
(\
@difftree, $hash, $parent);
2909 my $format = shift || 'html';
2916 # preparing $fd and %diffinfo for git_patchset_body
2918 if (defined $hash_base && defined $hash_parent_base) {
2919 if (defined $file_name) {
2921 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
2923 or die_error
(undef, "Open git-diff-tree failed");
2924 @difftree = map { chomp; $_ } <$fd>;
2926 or die_error
(undef, "Reading git-diff-tree failed");
2928 or die_error
('404 Not Found', "Blob diff not found");
2930 } elsif (defined $hash &&
2931 $hash =~ /[0-9a-fA-F]{40}/) {
2932 # try to find filename from $hash
2934 # read filtered raw output
2935 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
2936 or die_error
(undef, "Open git-diff-tree failed");
2938 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
2940 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
2941 map { chomp; $_ } <$fd>;
2943 or die_error
(undef, "Reading git-diff-tree failed");
2945 or die_error
('404 Not Found', "Blob diff not found");
2948 die_error
('404 Not Found', "Missing one of the blob diff parameters");
2951 if (@difftree > 1) {
2952 die_error
('404 Not Found', "Ambiguous blob diff specification");
2955 %diffinfo = parse_difftree_raw_line
($difftree[0]);
2956 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
2957 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
2959 $hash_parent ||= $diffinfo{'from_id'};
2960 $hash ||= $diffinfo{'to_id'};
2962 # non-textual hash id's can be cached
2963 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
2964 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
2969 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
2970 '-p', $hash_parent_base, $hash_base,
2972 or die_error
(undef, "Open git-diff-tree failed");
2975 # old/legacy style URI
2976 if (!%diffinfo && # if new style URI failed
2977 defined $hash && defined $hash_parent) {
2978 # fake git-diff-tree raw output
2979 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
2980 $diffinfo{'from_id'} = $hash_parent;
2981 $diffinfo{'to_id'} = $hash;
2982 if (defined $file_name) {
2983 if (defined $file_parent) {
2984 $diffinfo{'status'} = '2';
2985 $diffinfo{'from_file'} = $file_parent;
2986 $diffinfo{'to_file'} = $file_name;
2987 } else { # assume not renamed
2988 $diffinfo{'status'} = '1';
2989 $diffinfo{'from_file'} = $file_name;
2990 $diffinfo{'to_file'} = $file_name;
2992 } else { # no filename given
2993 $diffinfo{'status'} = '2';
2994 $diffinfo{'from_file'} = $hash_parent;
2995 $diffinfo{'to_file'} = $hash;
2998 # non-textual hash id's can be cached
2999 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3000 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3005 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts, $hash_parent, $hash
3006 or die_error
(undef, "Open git-diff failed");
3008 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3013 if ($format eq 'html') {
3015 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3016 hash
=>$hash, hash_parent
=>$hash_parent,
3017 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3018 file_name
=>$file_name, file_parent
=>$file_parent)},
3020 git_header_html
(undef, $expires);
3021 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3022 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3023 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3025 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3026 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3028 if (defined $file_name) {
3029 git_print_page_path
($file_name, "blob", $hash_base);
3031 print "<div class=\"page_path\"></div>\n";
3034 } elsif ($format eq 'plain') {
3036 -type
=> 'text/plain',
3037 -charset
=> 'utf-8',
3038 -expires
=> $expires,
3039 -content_disposition
=> qq(inline
; filename
="${file_name}.patch"));
3041 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3044 die_error
(undef, "Unknown blobdiff format");
3048 if ($format eq 'html') {
3049 print "<div class=\"page_body\">\n";
3051 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3054 print "</div>\n"; # class="page_body"
3058 while (my $line = <$fd>) {
3059 $line =~ s!a/($hash|$hash_parent)!a/$diffinfo{'from_file'}!g;
3060 $line =~ s!b/($hash|$hash_parent)!b/$diffinfo{'to_file'}!g;
3064 last if $line =~ m!^\+\+\+!;
3072 sub git_blobdiff_plain
{
3073 git_blobdiff
('plain');
3076 sub git_commitdiff
{
3077 my $format = shift || 'html';
3078 my %co = parse_commit
($hash);
3080 die_error
(undef, "Unknown commit object");
3082 if (!defined $hash_parent) {
3083 $hash_parent = $co{'parent'} || '--root';
3089 if ($format eq 'html') {
3090 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3091 "--patch-with-raw", "--full-index", $hash_parent, $hash
3092 or die_error
(undef, "Open git-diff-tree failed");
3094 while (chomp(my $line = <$fd>)) {
3095 # empty line ends raw part of diff-tree output
3097 push @difftree, $line;
3100 } elsif ($format eq 'plain') {
3101 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3102 '-p', $hash_parent, $hash
3103 or die_error
(undef, "Open git-diff-tree failed");
3106 die_error
(undef, "Unknown commitdiff format");
3109 # non-textual hash id's can be cached
3111 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3115 # write commit message
3116 if ($format eq 'html') {
3117 my $refs = git_get_references
();
3118 my $ref = format_ref_marker
($refs, $co{'id'});
3120 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3121 hash
=>$hash, hash_parent
=>$hash_parent)},
3124 git_header_html
(undef, $expires);
3125 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3126 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3127 git_print_authorship
(\
%co);
3128 print "<div class=\"page_body\">\n";
3129 print "<div class=\"log\">\n";
3130 git_print_simplified_log
($co{'comment'}, 1); # skip title
3131 print "</div>\n"; # class="log"
3133 } elsif ($format eq 'plain') {
3134 my $refs = git_get_references
("tags");
3135 my $tagname = git_get_rev_name_tags
($hash);
3136 my $filename = basename
($project) . "-$hash.patch";
3139 -type
=> 'text/plain',
3140 -charset
=> 'utf-8',
3141 -expires
=> $expires,
3142 -content_disposition
=> qq(inline
; filename
="$filename"));
3143 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3146 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3147 Subject: $co{'title'}
3149 print "X-Git-Tag: $tagname\n" if $tagname;
3150 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3152 foreach my $line (@
{$co{'comment'}}) {
3159 if ($format eq 'html') {
3160 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3163 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3165 print "</div>\n"; # class="page_body"
3168 } elsif ($format eq 'plain') {
3172 or print "Reading git-diff-tree failed\n";
3176 sub git_commitdiff_plain
{
3177 git_commitdiff
('plain');
3181 if (!defined $hash_base) {
3182 $hash_base = git_get_head_hash
($project);
3184 if (!defined $page) {
3188 my %co = parse_commit
($hash_base);
3190 die_error
(undef, "Unknown commit object");
3193 my $refs = git_get_references
();
3194 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3196 if (!defined $hash && defined $file_name) {
3197 $hash = git_get_hash_by_path
($hash_base, $file_name);
3199 if (defined $hash) {
3200 $ftype = git_get_type
($hash);
3204 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3205 or die_error
(undef, "Open git-rev-list-failed");
3206 my @revlist = map { chomp; $_ } <$fd>;
3208 or die_error
(undef, "Reading git-rev-list failed");
3210 my $paging_nav = '';
3213 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3214 file_name
=>$file_name)},
3216 $paging_nav .= " ⋅ " .
3217 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3218 file_name
=>$file_name, page
=>$page-1),
3219 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3221 $paging_nav .= "first";
3222 $paging_nav .= " ⋅ prev";
3224 if ($#revlist >= (100 * ($page+1)-1)) {
3225 $paging_nav .= " ⋅ " .
3226 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3227 file_name
=>$file_name, page
=>$page+1),
3228 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3230 $paging_nav .= " ⋅ next";
3233 if ($#revlist >= (100 * ($page+1)-1)) {
3235 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3236 file_name
=>$file_name, page
=>$page+1),
3237 -title
=> "Alt-n"}, "next");
3241 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3242 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3243 git_print_page_path
($file_name, $ftype, $hash_base);
3245 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3246 $refs, $hash_base, $ftype, $next_link);
3252 if (!defined $searchtext) {
3253 die_error
(undef, "Text field empty");
3255 if (!defined $hash) {
3256 $hash = git_get_head_hash
($project);
3258 my %co = parse_commit
($hash);
3260 die_error
(undef, "Unknown commit object");
3263 my $commit_search = 1;
3264 my $author_search = 0;
3265 my $committer_search = 0;
3266 my $pickaxe_search = 0;
3267 if ($searchtext =~ s/^author\\://i) {
3269 } elsif ($searchtext =~ s/^committer\\://i) {
3270 $committer_search = 1;
3271 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3273 $pickaxe_search = 1;
3275 # pickaxe may take all resources of your box and run for several minutes
3276 # with every query - so decide by yourself how public you make this feature
3277 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3278 if (!$have_pickaxe) {
3279 die_error
('403 Permission denied', "Permission denied");
3283 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3284 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3286 print "<table cellspacing=\"0\">\n";
3288 if ($commit_search) {
3290 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", $hash or next;
3291 while (my $commit_text = <$fd>) {
3292 if (!grep m/$searchtext/i, $commit_text) {
3295 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3298 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3301 my @commit_lines = split "\n", $commit_text;
3302 my %co = parse_commit
(undef, \
@commit_lines);
3307 print "<tr class=\"dark\">\n";
3309 print "<tr class=\"light\">\n";
3312 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3313 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3315 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3316 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3317 my $comment = $co{'comment'};
3318 foreach my $line (@
$comment) {
3319 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3320 my $lead = esc_html
($1) || "";
3321 $lead = chop_str
($lead, 30, 10);
3322 my $match = esc_html
($2) || "";
3323 my $trail = esc_html
($3) || "";
3324 $trail = chop_str
($trail, 30, 10);
3325 my $text = "$lead<span class=\"match\">$match</span>$trail";
3326 print chop_str
($text, 80, 5) . "<br/>\n";
3330 "<td class=\"link\">" .
3331 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3333 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3340 if ($pickaxe_search) {
3342 my $git_command = git_cmd_str
();
3343 open my $fd, "-|", "$git_command rev-list $hash | " .
3344 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3347 while (my $line = <$fd>) {
3348 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3351 $set{'from_id'} = $3;
3353 $set{'id'} = $set{'to_id'};
3354 if ($set{'id'} =~ m/0{40}/) {
3355 $set{'id'} = $set{'from_id'};
3357 if ($set{'id'} =~ m/0{40}/) {
3361 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3364 print "<tr class=\"dark\">\n";
3366 print "<tr class=\"light\">\n";
3369 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3370 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3372 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3373 -class => "list subject"},
3374 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3375 while (my $setref = shift @files) {
3377 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3378 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3380 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3384 "<td class=\"link\">" .
3385 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3387 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3391 %co = parse_commit
($1);
3401 my $head = git_get_head_hash
($project);
3402 if (!defined $hash) {
3405 if (!defined $page) {
3408 my $refs = git_get_references
();
3410 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3411 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3412 or die_error
(undef, "Open git-rev-list failed");
3413 my @revlist = map { chomp; $_ } <$fd>;
3416 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3418 if ($#revlist >= (100 * ($page+1)-1)) {
3420 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3421 -title
=> "Alt-n"}, "next");
3426 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3427 git_print_header_div
('summary', $project);
3429 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3434 ## ......................................................................
3435 ## feeds (RSS, OPML)
3438 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3439 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150", git_get_head_hash
($project)
3440 or die_error
(undef, "Open git-rev-list failed");
3441 my @revlist = map { chomp; $_ } <$fd>;
3442 close $fd or die_error
(undef, "Reading git-rev-list failed");
3443 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3445 <?xml version="1.0" encoding="utf-8"?>
3446 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3448 <title>$project $my_uri $my_url</title>
3449 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3450 <description>$project log</description>
3451 <language>en</language>
3454 for (my $i = 0; $i <= $#revlist; $i++) {
3455 my $commit = $revlist[$i];
3456 my %co = parse_commit
($commit);
3457 # we read 150, we always show 30 and the ones more recent than 48 hours
3458 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3461 my %cd = parse_date
($co{'committer_epoch'});
3462 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3463 $co{'parent'}, $co{'id'}
3465 my @difftree = map { chomp; $_ } <$fd>;
3470 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3472 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3473 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3474 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3475 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3476 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3477 "<content:encoded>" .
3479 my $comment = $co{'comment'};
3480 foreach my $line (@
$comment) {
3481 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
3482 print "$line<br/>\n";
3485 foreach my $line (@difftree) {
3486 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3489 my $file = validate_input
(unquote
($7));
3490 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
3491 print "$file<br/>\n";
3494 "</content:encoded>\n" .
3497 print "</channel></rss>";
3501 my @list = git_get_projects_list
();
3503 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3505 <?xml version="1.0" encoding="utf-8"?>
3506 <opml version="1.0">
3508 <title>$site_name Git OPML Export</title>
3511 <outline text="git RSS feeds">
3514 foreach my $pr (@list) {
3516 my $head = git_get_head_hash
($proj{'path'});
3517 if (!defined $head) {
3520 $git_dir = "$projectroot/$proj{'path'}";
3521 my %co = parse_commit
($head);
3526 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3527 my $rss = "$my_url?p=$proj{'path'};a=rss";
3528 my $html = "$my_url?p=$proj{'path'};a=summary";
3529 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";