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 # show repository only if this file exists
58 # (only effective if this variable evaluates to true)
59 our $export_ok = "++GITWEB_EXPORT_OK++";
61 # only allow viewing of repositories also shown on the overview page
62 our $strict_export = "++GITWEB_STRICT_EXPORT++";
64 # list of git base URLs used for URL to where fetch project from,
65 # i.e. full URL is "$git_base_url/$project"
66 our @git_base_url_list = ("++GITWEB_BASE_URL++");
68 # default blob_plain mimetype and default charset for text/plain blob
69 our $default_blob_plain_mimetype = 'text/plain';
70 our $default_text_plain_charset = undef;
72 # file to use for guessing MIME types before trying /etc/mime.types
73 # (relative to the current git repository)
74 our $mimetypes_file = undef;
76 # You define site-wide feature defaults here; override them with
77 # $GITWEB_CONFIG as necessary.
80 # 'sub' => feature-sub (subroutine),
81 # 'override' => allow-override (boolean),
82 # 'default' => [ default options...] (array reference)}
84 # if feature is overridable (it means that allow-override has true value,
85 # then feature-sub will be called with default options as parameters;
86 # return value of feature-sub indicates if to enable specified feature
88 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
91 'sub' => \
&feature_blame
,
96 'sub' => \
&feature_snapshot
,
98 # => [content-encoding, suffix, program]
99 'default' => ['x-gzip', 'gz', 'gzip']},
102 'sub' => \
&feature_pickaxe
,
107 sub gitweb_check_feature
{
109 return undef unless exists $feature{$name};
110 my ($sub, $override, @defaults) = (
111 $feature{$name}{'sub'},
112 $feature{$name}{'override'},
113 @
{$feature{$name}{'default'}});
114 if (!$override) { return @defaults; }
115 return $sub->(@defaults);
118 # To enable system wide have in $GITWEB_CONFIG
119 # $feature{'blame'}{'default'} = [1];
120 # To have project specific config enable override in $GITWEB_CONFIG
121 # $feature{'blame'}{'override'} = 1;
122 # and in project config gitweb.blame = 0|1;
125 my ($val) = git_get_project_config
('blame', '--bool');
127 if ($val eq 'true') {
129 } elsif ($val eq 'false') {
136 # To disable system wide have in $GITWEB_CONFIG
137 # $feature{'snapshot'}{'default'} = [undef];
138 # To have project specific config enable override in $GITWEB_CONFIG
139 # $feature{'blame'}{'override'} = 1;
140 # and in project config gitweb.snapshot = none|gzip|bzip2
142 sub feature_snapshot
{
143 my ($ctype, $suffix, $command) = @_;
145 my ($val) = git_get_project_config
('snapshot');
147 if ($val eq 'gzip') {
148 return ('x-gzip', 'gz', 'gzip');
149 } elsif ($val eq 'bzip2') {
150 return ('x-bzip2', 'bz2', 'bzip2');
151 } elsif ($val eq 'none') {
155 return ($ctype, $suffix, $command);
158 # To enable system wide have in $GITWEB_CONFIG
159 # $feature{'pickaxe'}{'default'} = [1];
160 # To have project specific config enable override in $GITWEB_CONFIG
161 # $feature{'pickaxe'}{'override'} = 1;
162 # and in project config gitweb.pickaxe = 0|1;
164 sub feature_pickaxe
{
165 my ($val) = git_get_project_config
('pickaxe', '--bool');
167 if ($val eq 'true') {
169 } elsif ($val eq 'false') {
176 # rename detection options for git-diff and git-diff-tree
177 # - default is '-M', with the cost proportional to
178 # (number of removed files) * (number of new files).
179 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
180 # (number of changed files + number of removed files) * (number of new files)
181 # - even more costly is '-C', '--find-copies-harder' with cost
182 # (number of files in the original tree) * (number of new files)
183 # - one might want to include '-B' option, e.g. '-B', '-M'
184 our @diff_opts = ('-M'); # taken from git_commit
186 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
187 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
189 # version of the core git binary
190 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
192 $projects_list ||= $projectroot;
194 # ======================================================================
195 # input validation and dispatch
196 our $action = $cgi->param('a');
197 if (defined $action) {
198 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
199 die_error
(undef, "Invalid action parameter");
203 our $project = $cgi->param('p');
204 if (defined $project) {
205 if (!validate_input
($project) ||
206 !(-d
"$projectroot/$project") ||
207 !(-e
"$projectroot/$project/HEAD") ||
208 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
209 ($strict_export && !project_in_list
($project))) {
211 die_error
(undef, "No such project");
215 # We have to handle those containing any characters:
216 our $file_name = $cgi->param('f');
217 our $file_parent = $cgi->param('fp');
219 our $hash = $cgi->param('h');
221 if (!validate_input
($hash)) {
222 die_error
(undef, "Invalid hash parameter");
226 our $hash_parent = $cgi->param('hp');
227 if (defined $hash_parent) {
228 if (!validate_input
($hash_parent)) {
229 die_error
(undef, "Invalid hash parent parameter");
233 our $hash_base = $cgi->param('hb');
234 if (defined $hash_base) {
235 if (!validate_input
($hash_base)) {
236 die_error
(undef, "Invalid hash base parameter");
240 our $hash_parent_base = $cgi->param('hpb');
241 if (defined $hash_parent_base) {
242 if (!validate_input
($hash_parent_base)) {
243 die_error
(undef, "Invalid hash parent base parameter");
247 our $page = $cgi->param('pg');
249 if ($page =~ m/[^0-9]/) {
250 die_error
(undef, "Invalid page parameter");
254 our $searchtext = $cgi->param('s');
255 if (defined $searchtext) {
256 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
257 die_error
(undef, "Invalid search parameter");
259 $searchtext = quotemeta $searchtext;
262 # now read PATH_INFO and use it as alternative to parameters
263 sub evaluate_path_info
{
264 return if defined $project;
265 my $path_info = $ENV{"PATH_INFO"};
266 return if !$path_info;
267 $path_info =~ s
,^/+,,;
268 return if !$path_info;
269 # find which part of PATH_INFO is project
270 $project = $path_info;
272 while ($project && !-e
"$projectroot/$project/HEAD") {
273 $project =~ s
,/*[^/]*$,,;
276 $project = validate_input
($project);
278 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
279 ($strict_export && !project_in_list
($project))) {
283 # do not change any parameters if an action is given using the query string
285 $path_info =~ s
,^$project/*,,;
286 my ($refname, $pathname) = split(/:/, $path_info, 2);
287 if (defined $pathname) {
288 # we got "project.git/branch:filename" or "project.git/branch:dir/"
289 # we could use git_get_type(branch:pathname), but it needs $git_dir
290 $pathname =~ s
,^/+,,;
291 if (!$pathname || substr($pathname, -1) eq "/") {
295 $action ||= "blob_plain";
297 $hash_base ||= validate_input
($refname);
298 $file_name ||= $pathname;
299 } elsif (defined $refname) {
300 # we got "project.git/branch"
301 $action ||= "shortlog";
302 $hash ||= validate_input
($refname);
305 evaluate_path_info
();
307 # path to the current git repository
309 $git_dir = "$projectroot/$project" if $project;
313 "blame" => \
&git_blame2
,
314 "blobdiff" => \
&git_blobdiff
,
315 "blobdiff_plain" => \
&git_blobdiff_plain
,
316 "blob" => \
&git_blob
,
317 "blob_plain" => \
&git_blob_plain
,
318 "commitdiff" => \
&git_commitdiff
,
319 "commitdiff_plain" => \
&git_commitdiff_plain
,
320 "commit" => \
&git_commit
,
321 "heads" => \
&git_heads
,
322 "history" => \
&git_history
,
325 "search" => \
&git_search
,
326 "shortlog" => \
&git_shortlog
,
327 "summary" => \
&git_summary
,
329 "tags" => \
&git_tags
,
330 "tree" => \
&git_tree
,
331 "snapshot" => \
&git_snapshot
,
332 # those below don't need $project
333 "opml" => \
&git_opml
,
334 "project_list" => \
&git_project_list
,
335 "project_index" => \
&git_project_index
,
338 if (defined $project) {
339 $action ||= 'summary';
341 $action ||= 'project_list';
343 if (!defined($actions{$action})) {
344 die_error
(undef, "Unknown action");
346 if ($action !~ m/^(opml|project_list|project_index)$/ &&
348 die_error
(undef, "Project needed");
350 $actions{$action}->();
353 ## ======================================================================
367 hash_parent_base
=> "hpb",
372 my %mapping = @mapping;
374 $params{'project'} = $project unless exists $params{'project'};
377 for (my $i = 0; $i < @mapping; $i += 2) {
378 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
379 if (defined $params{$name}) {
380 push @result, $symbol . "=" . esc_param
($params{$name});
383 return "$my_uri?" . join(';', @result);
387 ## ======================================================================
388 ## validation, quoting/unquoting and escaping
393 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
396 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
399 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
405 # quote unsafe chars, but keep the slash, even when it's not
406 # correct, but quoted slashes look too horrible in bookmarks
409 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
415 # replace invalid utf8 character with SUBSTITUTION sequence
418 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
419 $str = escapeHTML
($str);
420 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
424 # git may return quoted and escaped filenames
427 if ($str =~ m/^"(.*)"$/) {
429 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
434 # escape tabs (convert tabs to spaces)
438 while ((my $pos = index($line, "\t")) != -1) {
439 if (my $count = (8 - ($pos % 8))) {
440 my $spaces = ' ' x
$count;
441 $line =~ s/\t/$spaces/;
448 sub project_in_list
{
450 my @list = git_get_projects_list
();
451 return @list && scalar(grep { $_->{'path'} eq $project } @list);
454 ## ----------------------------------------------------------------------
455 ## HTML aware string manipulation
460 my $add_len = shift || 10;
462 # allow only $len chars, but don't cut a word if it would fit in $add_len
463 # if it doesn't fit, cut it if it's still longer than the dots we would add
464 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
467 if (length($tail) > 4) {
469 $body =~ s/&[^;]*$//; # remove chopped character entities
474 ## ----------------------------------------------------------------------
475 ## functions returning short strings
477 # CSS class for given age value (in seconds)
481 if ($age < 60*60*2) {
483 } elsif ($age < 60*60*24*2) {
490 # convert age in seconds to "nn units ago" string
495 if ($age > 60*60*24*365*2) {
496 $age_str = (int $age/60/60/24/365);
497 $age_str .= " years ago";
498 } elsif ($age > 60*60*24*(365/12)*2) {
499 $age_str = int $age/60/60/24/(365/12);
500 $age_str .= " months ago";
501 } elsif ($age > 60*60*24*7*2) {
502 $age_str = int $age/60/60/24/7;
503 $age_str .= " weeks ago";
504 } elsif ($age > 60*60*24*2) {
505 $age_str = int $age/60/60/24;
506 $age_str .= " days ago";
507 } elsif ($age > 60*60*2) {
508 $age_str = int $age/60/60;
509 $age_str .= " hours ago";
510 } elsif ($age > 60*2) {
511 $age_str = int $age/60;
512 $age_str .= " min ago";
515 $age_str .= " sec ago";
517 $age_str .= " right now";
522 # convert file mode in octal to symbolic file mode string
524 my $mode = oct shift;
526 if (S_ISDIR
($mode & S_IFMT
)) {
528 } elsif (S_ISLNK
($mode)) {
530 } elsif (S_ISREG
($mode)) {
531 # git cares only about the executable bit
532 if ($mode & S_IXUSR
) {
542 # convert file mode in octal to file type string
546 if ($mode !~ m/^[0-7]+$/) {
552 if (S_ISDIR
($mode & S_IFMT
)) {
554 } elsif (S_ISLNK
($mode)) {
556 } elsif (S_ISREG
($mode)) {
563 ## ----------------------------------------------------------------------
564 ## functions returning short HTML fragments, or transforming HTML fragments
565 ## which don't beling to other sections
567 # format line of commit message or tag comment
568 sub format_log_line_html
{
571 $line = esc_html
($line);
572 $line =~ s/ / /g;
573 if ($line =~ m/([0-9a-fA-F]{40})/) {
575 if (git_get_type
($hash_text) eq "commit") {
577 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
578 -class => "text"}, $hash_text);
579 $line =~ s/$hash_text/$link/;
585 # format marker of refs pointing to given object
586 sub format_ref_marker
{
587 my ($refs, $id) = @_;
590 if (defined $refs->{$id}) {
591 foreach my $ref (@
{$refs->{$id}}) {
592 my ($type, $name) = qw();
593 # e.g. tags/v2.6.11 or heads/next
594 if ($ref =~ m!^(.*?)s?/(.*)$!) {
602 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
607 return ' <span class="refs">'. $markers . '</span>';
613 # format, perhaps shortened and with markers, title line
614 sub format_subject_html
{
615 my ($long, $short, $href, $extra) = @_;
616 $extra = '' unless defined($extra);
618 if (length($short) < length($long)) {
619 return $cgi->a({-href
=> $href, -class => "list subject",
620 -title
=> decode
("utf8", $long, Encode
::FB_DEFAULT
)},
621 esc_html
($short) . $extra);
623 return $cgi->a({-href
=> $href, -class => "list subject"},
624 esc_html
($long) . $extra);
628 sub format_diff_line
{
630 my $char = substr($line, 0, 1);
636 $diff_class = " add";
637 } elsif ($char eq "-") {
638 $diff_class = " rem";
639 } elsif ($char eq "@") {
640 $diff_class = " chunk_header";
641 } elsif ($char eq "\\") {
642 $diff_class = " incomplete";
644 $line = untabify
($line);
645 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
648 ## ----------------------------------------------------------------------
649 ## git utility subroutines, invoking git commands
651 # returns path to the core git executable and the --git-dir parameter as list
653 return $GIT, '--git-dir='.$git_dir;
656 # returns path to the core git executable and the --git-dir parameter as string
658 return join(' ', git_cmd
());
661 # get HEAD ref of given project as hash
662 sub git_get_head_hash
{
664 my $o_git_dir = $git_dir;
666 $git_dir = "$projectroot/$project";
667 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
670 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
674 if (defined $o_git_dir) {
675 $git_dir = $o_git_dir;
680 # get type of given object
684 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
691 sub git_get_project_config
{
692 my ($key, $type) = @_;
694 return unless ($key);
695 $key =~ s/^gitweb\.//;
696 return if ($key =~ m/\W/);
698 my @x = (git_cmd
(), 'repo-config');
699 if (defined $type) { push @x, $type; }
701 push @x, "gitweb.$key";
707 # get hash of given path at given ref
708 sub git_get_hash_by_path
{
710 my $path = shift || return undef;
715 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
716 or die_error
(undef, "Open git-ls-tree failed");
718 close $fd or return undef;
720 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
721 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
722 if (defined $type && $type ne $2) {
729 ## ......................................................................
730 ## git utility functions, directly accessing git repository
732 sub git_get_project_description
{
735 open my $fd, "$projectroot/$path/description" or return undef;
742 sub git_get_project_url_list
{
745 open my $fd, "$projectroot/$path/cloneurl" or return;
746 my @git_project_url_list = map { chomp; $_ } <$fd>;
749 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
752 sub git_get_projects_list
{
755 if (-d
$projects_list) {
756 # search in directory
757 my $dir = $projects_list;
758 my $pfxlen = length("$dir");
761 follow_fast
=> 1, # follow symbolic links
762 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
764 # skip project-list toplevel, if we get it.
765 return if (m!^[/.]$!);
766 # only directories can be git repositories
767 return unless (-d
$_);
769 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
770 # we check related file in $projectroot
771 if (-e
"$projectroot/$subdir/HEAD" && (!$export_ok ||
772 -e
"$projectroot/$subdir/$export_ok")) {
773 push @list, { path
=> $subdir };
774 $File::Find
::prune
= 1;
779 } elsif (-f
$projects_list) {
780 # read from file(url-encoded):
781 # 'git%2Fgit.git Linus+Torvalds'
782 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
783 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
784 open my ($fd), $projects_list or return undef;
785 while (my $line = <$fd>) {
787 my ($path, $owner) = split ' ', $line;
788 $path = unescape
($path);
789 $owner = unescape
($owner);
790 if (!defined $path) {
793 if (-e
"$projectroot/$path/HEAD" && (!$export_ok ||
794 -e
"$projectroot/$path/$export_ok")) {
797 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
804 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
808 sub git_get_project_owner
{
812 return undef unless $project;
814 # read from file (url-encoded):
815 # 'git%2Fgit.git Linus+Torvalds'
816 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
817 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
818 if (-f
$projects_list) {
819 open (my $fd , $projects_list);
820 while (my $line = <$fd>) {
822 my ($pr, $ow) = split ' ', $line;
825 if ($pr eq $project) {
826 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
832 if (!defined $owner) {
833 $owner = get_file_owner
("$projectroot/$project");
839 sub git_get_references
{
840 my $type = shift || "";
842 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
843 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
844 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
847 while (my $line = <$fd>) {
849 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
850 if (defined $refs{$1}) {
851 push @
{$refs{$1}}, $2;
861 sub git_get_rev_name_tags
{
862 my $hash = shift || return undef;
864 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
866 my $name_rev = <$fd>;
869 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
872 # catches also '$hash undefined' output
877 ## ----------------------------------------------------------------------
878 ## parse to hash functions
882 my $tz = shift || "-0000";
885 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
886 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
887 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
888 $date{'hour'} = $hour;
889 $date{'minute'} = $min;
890 $date{'mday'} = $mday;
891 $date{'day'} = $days[$wday];
892 $date{'month'} = $months[$mon];
893 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
894 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
895 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
896 $mday, $months[$mon], $hour ,$min;
898 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
899 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
900 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
901 $date{'hour_local'} = $hour;
902 $date{'minute_local'} = $min;
903 $date{'tz_local'} = $tz;
912 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
913 $tag{'id'} = $tag_id;
914 while (my $line = <$fd>) {
916 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
918 } elsif ($line =~ m/^type (.+)$/) {
920 } elsif ($line =~ m/^tag (.+)$/) {
922 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
926 } elsif ($line =~ m/--BEGIN/) {
927 push @comment, $line;
929 } elsif ($line eq "") {
933 push @comment, <$fd>;
934 $tag{'comment'} = \
@comment;
936 if (!defined $tag{'name'}) {
943 my $commit_id = shift;
944 my $commit_text = shift;
949 if (defined $commit_text) {
950 @commit_lines = @
$commit_text;
953 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
955 @commit_lines = split '\n', <$fd>;
960 my $header = shift @commit_lines;
961 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
964 ($co{'id'}, my @parents) = split ' ', $header;
965 $co{'parents'} = \
@parents;
966 $co{'parent'} = $parents[0];
967 while (my $line = shift @commit_lines) {
968 last if $line eq "\n";
969 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
971 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
973 $co{'author_epoch'} = $2;
974 $co{'author_tz'} = $3;
975 if ($co{'author'} =~ m/^([^<]+) </) {
976 $co{'author_name'} = $1;
978 $co{'author_name'} = $co{'author'};
980 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
981 $co{'committer'} = $1;
982 $co{'committer_epoch'} = $2;
983 $co{'committer_tz'} = $3;
984 $co{'committer_name'} = $co{'committer'};
985 $co{'committer_name'} =~ s/ <.*//;
988 if (!defined $co{'tree'}) {
992 foreach my $title (@commit_lines) {
995 $co{'title'} = chop_str
($title, 80, 5);
996 # remove leading stuff of merges to make the interesting part visible
997 if (length($title) > 50) {
998 $title =~ s/^Automatic //;
999 $title =~ s/^merge (of|with) /Merge ... /i;
1000 if (length($title) > 50) {
1001 $title =~ s/(http|rsync):\/\///;
1003 if (length($title) > 50) {
1004 $title =~ s/(master|www|rsync)\.//;
1006 if (length($title) > 50) {
1007 $title =~ s/kernel.org:?//;
1009 if (length($title) > 50) {
1010 $title =~ s/\/pub\/scm//;
1013 $co{'title_short'} = chop_str
($title, 50, 5);
1017 # remove added spaces
1018 foreach my $line (@commit_lines) {
1021 $co{'comment'} = \
@commit_lines;
1023 my $age = time - $co{'committer_epoch'};
1025 $co{'age_string'} = age_string
($age);
1026 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1027 if ($age > 60*60*24*7*2) {
1028 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1029 $co{'age_string_age'} = $co{'age_string'};
1031 $co{'age_string_date'} = $co{'age_string'};
1032 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1037 # parse ref from ref_file, given by ref_id, with given type
1039 my $ref_file = shift;
1041 my $type = shift || git_get_type
($ref_id);
1044 $ref_item{'type'} = $type;
1045 $ref_item{'id'} = $ref_id;
1046 $ref_item{'epoch'} = 0;
1047 $ref_item{'age'} = "unknown";
1048 if ($type eq "tag") {
1049 my %tag = parse_tag
($ref_id);
1050 $ref_item{'comment'} = $tag{'comment'};
1051 if ($tag{'type'} eq "commit") {
1052 my %co = parse_commit
($tag{'object'});
1053 $ref_item{'epoch'} = $co{'committer_epoch'};
1054 $ref_item{'age'} = $co{'age_string'};
1055 } elsif (defined($tag{'epoch'})) {
1056 my $age = time - $tag{'epoch'};
1057 $ref_item{'epoch'} = $tag{'epoch'};
1058 $ref_item{'age'} = age_string
($age);
1060 $ref_item{'reftype'} = $tag{'type'};
1061 $ref_item{'name'} = $tag{'name'};
1062 $ref_item{'refid'} = $tag{'object'};
1063 } elsif ($type eq "commit"){
1064 my %co = parse_commit
($ref_id);
1065 $ref_item{'reftype'} = "commit";
1066 $ref_item{'name'} = $ref_file;
1067 $ref_item{'title'} = $co{'title'};
1068 $ref_item{'refid'} = $ref_id;
1069 $ref_item{'epoch'} = $co{'committer_epoch'};
1070 $ref_item{'age'} = $co{'age_string'};
1072 $ref_item{'reftype'} = $type;
1073 $ref_item{'name'} = $ref_file;
1074 $ref_item{'refid'} = $ref_id;
1080 # parse line of git-diff-tree "raw" output
1081 sub parse_difftree_raw_line
{
1085 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1086 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1087 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1088 $res{'from_mode'} = $1;
1089 $res{'to_mode'} = $2;
1090 $res{'from_id'} = $3;
1092 $res{'status'} = $5;
1093 $res{'similarity'} = $6;
1094 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1095 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1097 $res{'file'} = unquote
($7);
1100 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1101 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1102 $res{'commit'} = $1;
1105 return wantarray ?
%res : \
%res;
1108 # parse line of git-ls-tree output
1109 sub parse_ls_tree_line
($;%) {
1114 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1115 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1123 $res{'name'} = unquote
($4);
1126 return wantarray ?
%res : \
%res;
1129 ## ......................................................................
1130 ## parse to array of hashes functions
1132 sub git_get_refs_list
{
1133 my $type = shift || "";
1138 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1140 while (my $line = <$fd>) {
1142 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?([^\^]+))(\^\{\})?$/) {
1143 if (defined $refs{$1}) {
1144 push @
{$refs{$1}}, $2;
1149 if (! $4) { # unpeeled, direct reference
1150 push @refs, { hash
=> $1, name
=> $3 }; # without type
1151 } elsif ($3 eq $refs[-1]{'name'}) {
1152 # most likely a tag is followed by its peeled
1153 # (deref) one, and when that happens we know the
1154 # previous one was of type 'tag'.
1155 $refs[-1]{'type'} = "tag";
1161 foreach my $ref (@refs) {
1162 my $ref_file = $ref->{'name'};
1163 my $ref_id = $ref->{'hash'};
1165 my $type = $ref->{'type'} || git_get_type
($ref_id) || next;
1166 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1168 push @reflist, \
%ref_item;
1171 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1172 return (\
@reflist, \
%refs);
1175 ## ----------------------------------------------------------------------
1176 ## filesystem-related functions
1178 sub get_file_owner
{
1181 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1182 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1183 if (!defined $gcos) {
1187 $owner =~ s/[,;].*$//;
1188 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
1191 ## ......................................................................
1192 ## mimetype related functions
1194 sub mimetype_guess_file
{
1195 my $filename = shift;
1196 my $mimemap = shift;
1197 -r
$mimemap or return undef;
1200 open(MIME
, $mimemap) or return undef;
1202 next if m/^#/; # skip comments
1203 my ($mime, $exts) = split(/\t+/);
1204 if (defined $exts) {
1205 my @exts = split(/\s+/, $exts);
1206 foreach my $ext (@exts) {
1207 $mimemap{$ext} = $mime;
1213 $filename =~ /\.([^.]*)$/;
1214 return $mimemap{$1};
1217 sub mimetype_guess
{
1218 my $filename = shift;
1220 $filename =~ /\./ or return undef;
1222 if ($mimetypes_file) {
1223 my $file = $mimetypes_file;
1224 if ($file !~ m!^/!) { # if it is relative path
1225 # it is relative to project
1226 $file = "$projectroot/$project/$file";
1228 $mime = mimetype_guess_file
($filename, $file);
1230 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1236 my $filename = shift;
1239 my $mime = mimetype_guess
($filename);
1240 $mime and return $mime;
1244 return $default_blob_plain_mimetype unless $fd;
1247 return 'text/plain' .
1248 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1249 } elsif (! $filename) {
1250 return 'application/octet-stream';
1251 } elsif ($filename =~ m/\.png$/i) {
1253 } elsif ($filename =~ m/\.gif$/i) {
1255 } elsif ($filename =~ m/\.jpe?g$/i) {
1256 return 'image/jpeg';
1258 return 'application/octet-stream';
1262 ## ======================================================================
1263 ## functions printing HTML: header, footer, error page
1265 sub git_header_html
{
1266 my $status = shift || "200 OK";
1267 my $expires = shift;
1269 my $title = "$site_name git";
1270 if (defined $project) {
1271 $title .= " - $project";
1272 if (defined $action) {
1273 $title .= "/$action";
1274 if (defined $file_name) {
1275 $title .= " - " . esc_html
($file_name);
1276 if ($action eq "tree" && $file_name !~ m
|/$|) {
1283 # require explicit support from the UA if we are to send the page as
1284 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1285 # we have to do this because MSIE sometimes globs '*/*', pretending to
1286 # support xhtml+xml but choking when it gets what it asked for.
1287 if (defined $cgi->http('HTTP_ACCEPT') &&
1288 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1289 $cgi->Accept('application/xhtml+xml') != 0) {
1290 $content_type = 'application/xhtml+xml';
1292 $content_type = 'text/html';
1294 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1295 -status
=> $status, -expires
=> $expires);
1297 <?xml version="1.0" encoding="utf-8"?>
1298 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1299 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1300 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1301 <!-- git core binaries version $git_version -->
1303 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1304 <meta name="generator" content="gitweb/$version git/$git_version"/>
1305 <meta name="robots" content="index, nofollow"/>
1306 <title>$title</title>
1307 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1309 if (defined $project) {
1310 printf('<link rel="alternate" title="%s log" '.
1311 'href="%s" type="application/rss+xml"/>'."\n",
1312 esc_param
($project), href
(action
=>"rss"));
1314 printf('<link rel="alternate" title="%s projects list" '.
1315 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1316 $site_name, href
(project
=>undef, action
=>"project_index"));
1317 printf('<link rel="alternate" title="%s projects logs" '.
1318 'href="%s" type="text/x-opml"/>'."\n",
1319 $site_name, href
(project
=>undef, action
=>"opml"));
1321 if (defined $favicon) {
1322 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
1327 "<div class=\"page_header\">\n" .
1328 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1329 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1331 print $cgi->a({-href
=> esc_param
($home_link)}, $home_link_str) . " / ";
1332 if (defined $project) {
1333 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1334 if (defined $action) {
1338 if (!defined $searchtext) {
1342 if (defined $hash_base) {
1343 $search_hash = $hash_base;
1344 } elsif (defined $hash) {
1345 $search_hash = $hash;
1347 $search_hash = "HEAD";
1349 $cgi->param("a", "search");
1350 $cgi->param("h", $search_hash);
1351 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1352 "<div class=\"search\">\n" .
1353 $cgi->hidden(-name
=> "p") . "\n" .
1354 $cgi->hidden(-name
=> "a") . "\n" .
1355 $cgi->hidden(-name
=> "h") . "\n" .
1356 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1358 $cgi->end_form() . "\n";
1363 sub git_footer_html
{
1364 print "<div class=\"page_footer\">\n";
1365 if (defined $project) {
1366 my $descr = git_get_project_description
($project);
1367 if (defined $descr) {
1368 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1370 print $cgi->a({-href
=> href
(action
=>"rss"),
1371 -class => "rss_logo"}, "RSS") . "\n";
1373 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1374 -class => "rss_logo"}, "OPML") . " ";
1375 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1376 -class => "rss_logo"}, "TXT") . "\n";
1384 my $status = shift || "403 Forbidden";
1385 my $error = shift || "Malformed query, file missing or permission denied";
1387 git_header_html
($status);
1389 <div class="page_body">
1399 ## ----------------------------------------------------------------------
1400 ## functions printing or outputting HTML: navigation
1402 sub git_print_page_nav
{
1403 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1404 $extra = '' if !defined $extra; # pager or formats
1406 my @navs = qw(summary shortlog log commit commitdiff tree);
1408 @navs = grep { $_ ne $suppress } @navs;
1411 my %arg = map { $_ => {action
=>$_} } @navs;
1412 if (defined $head) {
1413 for (qw(commit commitdiff)) {
1414 $arg{$_}{hash
} = $head;
1416 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1417 for (qw(shortlog log)) {
1418 $arg{$_}{hash
} = $head;
1422 $arg{tree
}{hash
} = $treehead if defined $treehead;
1423 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1425 print "<div class=\"page_nav\">\n" .
1427 map { $_ eq $current ?
1428 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1430 print "<br/>\n$extra<br/>\n" .
1434 sub format_paging_nav
{
1435 my ($action, $hash, $head, $page, $nrevs) = @_;
1439 if ($hash ne $head || $page) {
1440 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1442 $paging_nav .= "HEAD";
1446 $paging_nav .= " ⋅ " .
1447 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1448 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1450 $paging_nav .= " ⋅ prev";
1453 if ($nrevs >= (100 * ($page+1)-1)) {
1454 $paging_nav .= " ⋅ " .
1455 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1456 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1458 $paging_nav .= " ⋅ next";
1464 ## ......................................................................
1465 ## functions printing or outputting HTML: div
1467 sub git_print_header_div
{
1468 my ($action, $title, $hash, $hash_base) = @_;
1471 $args{action
} = $action;
1472 $args{hash
} = $hash if $hash;
1473 $args{hash_base
} = $hash_base if $hash_base;
1475 print "<div class=\"header\">\n" .
1476 $cgi->a({-href
=> href
(%args), -class => "title"},
1477 $title ?
$title : $action) .
1481 #sub git_print_authorship (\%) {
1482 sub git_print_authorship
{
1485 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1486 print "<div class=\"author_date\">" .
1487 esc_html
($co->{'author_name'}) .
1489 if ($ad{'hour_local'} < 6) {
1490 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1491 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1493 printf(" (%02d:%02d %s)",
1494 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1499 sub git_print_page_path
{
1504 if (!defined $name) {
1505 print "<div class=\"page_path\">/</div>\n";
1507 my @dirname = split '/', $name;
1508 my $basename = pop @dirname;
1511 print "<div class=\"page_path\">";
1512 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1513 -title
=> 'tree root'}, "[$project]");
1515 foreach my $dir (@dirname) {
1516 $fullname .= ($fullname ?
'/' : '') . $dir;
1517 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1519 -title
=> $fullname}, esc_html
($dir));
1522 if (defined $type && $type eq 'blob') {
1523 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1525 -title
=> $name}, esc_html
($basename));
1526 } elsif (defined $type && $type eq 'tree') {
1527 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1529 -title
=> $name}, esc_html
($basename));
1531 print esc_html
($basename);
1533 print "<br/></div>\n";
1537 # sub git_print_log (\@;%) {
1538 sub git_print_log
($;%) {
1542 if ($opts{'-remove_title'}) {
1543 # remove title, i.e. first line of log
1546 # remove leading empty lines
1547 while (defined $log->[0] && $log->[0] eq "") {
1554 foreach my $line (@
$log) {
1555 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1558 if (! $opts{'-remove_signoff'}) {
1559 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1562 # remove signoff lines
1569 # print only one empty line
1570 # do not print empty line after signoff
1572 next if ($empty || $signoff);
1578 print format_log_line_html
($line) . "<br/>\n";
1581 if ($opts{'-final_empty_line'}) {
1582 # end with single empty line
1583 print "<br/>\n" unless $empty;
1587 sub git_print_simplified_log
{
1589 my $remove_title = shift;
1592 -final_empty_line
=> 1,
1593 -remove_title
=> $remove_title);
1596 # print tree entry (row of git_tree), but without encompassing <tr> element
1597 sub git_print_tree_entry
{
1598 my ($t, $basedir, $hash_base, $have_blame) = @_;
1601 $base_key{hash_base
} = $hash_base if defined $hash_base;
1603 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1604 if ($t->{'type'} eq "blob") {
1605 print "<td class=\"list\">" .
1606 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1607 file_name
=>"$basedir$t->{'name'}", %base_key),
1608 -class => "list"}, esc_html
($t->{'name'})) .
1610 "<td class=\"link\">" .
1611 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1612 file_name
=>"$basedir$t->{'name'}", %base_key)},
1616 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1617 file_name
=>"$basedir$t->{'name'}", %base_key)},
1620 if (defined $hash_base) {
1622 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1623 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1627 $cgi->a({-href
=> href
(action
=>"blob_plain",
1628 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1632 } elsif ($t->{'type'} eq "tree") {
1633 print "<td class=\"list\">" .
1634 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1635 file_name
=>"$basedir$t->{'name'}", %base_key)},
1636 esc_html
($t->{'name'})) .
1638 "<td class=\"link\">" .
1639 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1640 file_name
=>"$basedir$t->{'name'}", %base_key)},
1642 if (defined $hash_base) {
1644 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1645 file_name
=>"$basedir$t->{'name'}")},
1652 ## ......................................................................
1653 ## functions printing large fragments of HTML
1655 sub git_difftree_body
{
1656 my ($difftree, $hash, $parent) = @_;
1658 print "<div class=\"list_head\">\n";
1659 if ($#{$difftree} > 10) {
1660 print(($#{$difftree} + 1) . " files changed:\n");
1664 print "<table class=\"diff_tree\">\n";
1667 foreach my $line (@
{$difftree}) {
1668 my %diff = parse_difftree_raw_line
($line);
1671 print "<tr class=\"dark\">\n";
1673 print "<tr class=\"light\">\n";
1677 my ($to_mode_oct, $to_mode_str, $to_file_type);
1678 my ($from_mode_oct, $from_mode_str, $from_file_type);
1679 if ($diff{'to_mode'} ne ('0' x
6)) {
1680 $to_mode_oct = oct $diff{'to_mode'};
1681 if (S_ISREG
($to_mode_oct)) { # only for regular file
1682 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1684 $to_file_type = file_type
($diff{'to_mode'});
1686 if ($diff{'from_mode'} ne ('0' x
6)) {
1687 $from_mode_oct = oct $diff{'from_mode'};
1688 if (S_ISREG
($to_mode_oct)) { # only for regular file
1689 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1691 $from_file_type = file_type
($diff{'from_mode'});
1694 if ($diff{'status'} eq "A") { # created
1695 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1696 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1697 $mode_chng .= "]</span>";
1699 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1700 hash_base
=>$hash, file_name
=>$diff{'file'}),
1701 -class => "list"}, esc_html
($diff{'file'})) .
1703 "<td>$mode_chng</td>\n" .
1704 "<td class=\"link\">" .
1705 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1706 hash_base
=>$hash, file_name
=>$diff{'file'})},
1708 if ($action eq 'commitdiff') {
1712 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1716 } elsif ($diff{'status'} eq "D") { # deleted
1717 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1719 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1720 hash_base
=>$parent, file_name
=>$diff{'file'}),
1721 -class => "list"}, esc_html
($diff{'file'})) .
1723 "<td>$mode_chng</td>\n" .
1724 "<td class=\"link\">" .
1725 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1726 hash_base
=>$parent, file_name
=>$diff{'file'})},
1729 if ($action eq 'commitdiff') {
1733 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1735 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1736 file_name
=>$diff{'file'})},
1740 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1741 my $mode_chnge = "";
1742 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1743 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1744 if ($from_file_type != $to_file_type) {
1745 $mode_chnge .= " from $from_file_type to $to_file_type";
1747 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1748 if ($from_mode_str && $to_mode_str) {
1749 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1750 } elsif ($to_mode_str) {
1751 $mode_chnge .= " mode: $to_mode_str";
1754 $mode_chnge .= "]</span>\n";
1757 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1758 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1759 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1760 hash_base
=>$hash, hash_parent_base
=>$parent,
1761 file_name
=>$diff{'file'}),
1762 -class => "list"}, esc_html
($diff{'file'}));
1763 } else { # only mode changed
1764 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1765 hash_base
=>$hash, file_name
=>$diff{'file'}),
1766 -class => "list"}, esc_html
($diff{'file'}));
1769 "<td>$mode_chnge</td>\n" .
1770 "<td class=\"link\">" .
1771 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1772 hash_base
=>$hash, file_name
=>$diff{'file'})},
1774 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1775 if ($action eq 'commitdiff') {
1779 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1782 $cgi->a({-href
=> href
(action
=>"blobdiff",
1783 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1784 hash_base
=>$hash, hash_parent_base
=>$parent,
1785 file_name
=>$diff{'file'})},
1790 $cgi->a({-href
=> href
(action
=>"history",
1791 hash_base
=>$hash, file_name
=>$diff{'file'})},
1795 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1796 my %status_name = ('R' => 'moved', 'C' => 'copied');
1797 my $nstatus = $status_name{$diff{'status'}};
1799 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1800 # mode also for directories, so we cannot use $to_mode_str
1801 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1804 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1805 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1806 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1807 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1808 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1809 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1810 -class => "list"}, esc_html
($diff{'from_file'})) .
1811 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1812 "<td class=\"link\">" .
1813 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1814 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'})},
1816 if ($diff{'to_id'} ne $diff{'from_id'}) {
1817 if ($action eq 'commitdiff') {
1821 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1824 $cgi->a({-href
=> href
(action
=>"blobdiff",
1825 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1826 hash_base
=>$hash, hash_parent_base
=>$parent,
1827 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1833 } # we should not encounter Unmerged (U) or Unknown (X) status
1839 sub git_patchset_body
{
1840 my ($fd, $difftree, $hash, $hash_parent) = @_;
1844 my $patch_found = 0;
1847 print "<div class=\"patchset\">\n";
1850 while (my $patch_line = <$fd>) {
1853 if ($patch_line =~ m/^diff /) { # "git diff" header
1854 # beginning of patch (in patchset)
1856 # close previous patch
1857 print "</div>\n"; # class="patch"
1859 # first patch in patchset
1862 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1864 if (ref($difftree->[$patch_idx]) eq "HASH") {
1865 $diffinfo = $difftree->[$patch_idx];
1867 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1871 # for now, no extended header, hence we skip empty patches
1872 # companion to next LINE if $in_header;
1873 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1878 if ($diffinfo->{'status'} eq "A") { # added
1879 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1880 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1881 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1882 $diffinfo->{'to_id'}) . "(new)" .
1883 "</div>\n"; # class="diff_info"
1885 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1886 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
1887 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1888 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1889 $diffinfo->{'from_id'}) . "(deleted)" .
1890 "</div>\n"; # class="diff_info"
1892 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1893 $diffinfo->{'status'} eq "C" || # copied
1894 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1895 print "<div class=\"diff_info\">" .
1896 file_type
($diffinfo->{'from_mode'}) . ":" .
1897 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1898 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
1899 $diffinfo->{'from_id'}) .
1901 file_type
($diffinfo->{'to_mode'}) . ":" .
1902 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1903 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
1904 $diffinfo->{'to_id'});
1905 print "</div>\n"; # class="diff_info"
1907 } else { # modified, mode changed, ...
1908 print "<div class=\"diff_info\">" .
1909 file_type
($diffinfo->{'from_mode'}) . ":" .
1910 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1911 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1912 $diffinfo->{'from_id'}) .
1914 file_type
($diffinfo->{'to_mode'}) . ":" .
1915 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1916 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1917 $diffinfo->{'to_id'});
1918 print "</div>\n"; # class="diff_info"
1921 #print "<div class=\"diff extended_header\">\n";
1924 } # start of patch in patchset
1927 if ($in_header && $patch_line =~ m/^---/) {
1928 #print "</div>\n"; # class="diff extended_header"
1931 my $file = $diffinfo->{'from_file'};
1932 $file ||= $diffinfo->{'file'};
1933 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1934 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
1935 -class => "list"}, esc_html
($file));
1936 $patch_line =~ s
|a
/.*$|a/$file|g
;
1937 print "<div class=\"diff from_file\">$patch_line</div>\n";
1939 $patch_line = <$fd>;
1942 #$patch_line =~ m/^+++/;
1943 $file = $diffinfo->{'to_file'};
1944 $file ||= $diffinfo->{'file'};
1945 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1946 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
1947 -class => "list"}, esc_html
($file));
1948 $patch_line =~ s
|b
/.*|b/$file|g
;
1949 print "<div class=\"diff to_file\">$patch_line</div>\n";
1953 next LINE
if $in_header;
1955 print format_diff_line
($patch_line);
1957 print "</div>\n" if $patch_found; # class="patch"
1959 print "</div>\n"; # class="patchset"
1962 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1964 sub git_shortlog_body
{
1965 # uses global variable $project
1966 my ($revlist, $from, $to, $refs, $extra) = @_;
1968 $from = 0 unless defined $from;
1969 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1971 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1973 for (my $i = $from; $i <= $to; $i++) {
1974 my $commit = $revlist->[$i];
1975 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1976 my $ref = format_ref_marker
($refs, $commit);
1977 my %co = parse_commit
($commit);
1979 print "<tr class=\"dark\">\n";
1981 print "<tr class=\"light\">\n";
1984 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1985 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1986 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1988 print format_subject_html
($co{'title'}, $co{'title_short'},
1989 href
(action
=>"commit", hash
=>$commit), $ref);
1991 "<td class=\"link\">" .
1992 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1993 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
1994 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
1998 if (defined $extra) {
2000 "<td colspan=\"4\">$extra</td>\n" .
2006 sub git_history_body
{
2007 # Warning: assumes constant type (blob or tree) during history
2008 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2010 $from = 0 unless defined $from;
2011 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2013 print "<table class=\"history\" cellspacing=\"0\">\n";
2015 for (my $i = $from; $i <= $to; $i++) {
2016 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2021 my %co = parse_commit
($commit);
2026 my $ref = format_ref_marker
($refs, $commit);
2029 print "<tr class=\"dark\">\n";
2031 print "<tr class=\"light\">\n";
2034 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2035 # shortlog uses chop_str($co{'author_name'}, 10)
2036 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2038 # originally git_history used chop_str($co{'title'}, 50)
2039 print format_subject_html
($co{'title'}, $co{'title_short'},
2040 href
(action
=>"commit", hash
=>$commit), $ref);
2042 "<td class=\"link\">" .
2043 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
2044 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2045 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype);
2047 if ($ftype eq 'blob') {
2048 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2049 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2050 if (defined $blob_current && defined $blob_parent &&
2051 $blob_current ne $blob_parent) {
2053 $cgi->a({-href
=> href
(action
=>"blobdiff",
2054 hash
=>$blob_current, hash_parent
=>$blob_parent,
2055 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2056 file_name
=>$file_name)},
2063 if (defined $extra) {
2065 "<td colspan=\"4\">$extra</td>\n" .
2072 # uses global variable $project
2073 my ($taglist, $from, $to, $extra) = @_;
2074 $from = 0 unless defined $from;
2075 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2077 print "<table class=\"tags\" cellspacing=\"0\">\n";
2079 for (my $i = $from; $i <= $to; $i++) {
2080 my $entry = $taglist->[$i];
2082 my $comment_lines = $tag{'comment'};
2083 my $comment = shift @
$comment_lines;
2085 if (defined $comment) {
2086 $comment_short = chop_str
($comment, 30, 5);
2089 print "<tr class=\"dark\">\n";
2091 print "<tr class=\"light\">\n";
2094 print "<td><i>$tag{'age'}</i></td>\n" .
2096 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2097 -class => "list name"}, esc_html
($tag{'name'})) .
2100 if (defined $comment) {
2101 print format_subject_html
($comment, $comment_short,
2102 href
(action
=>"tag", hash
=>$tag{'id'}));
2105 "<td class=\"selflink\">";
2106 if ($tag{'type'} eq "tag") {
2107 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2112 "<td class=\"link\">" . " | " .
2113 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2114 if ($tag{'reftype'} eq "commit") {
2115 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2116 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
2117 } elsif ($tag{'reftype'} eq "blob") {
2118 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2123 if (defined $extra) {
2125 "<td colspan=\"5\">$extra</td>\n" .
2131 sub git_heads_body
{
2132 # uses global variable $project
2133 my ($headlist, $head, $from, $to, $extra) = @_;
2134 $from = 0 unless defined $from;
2135 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2137 print "<table class=\"heads\" cellspacing=\"0\">\n";
2139 for (my $i = $from; $i <= $to; $i++) {
2140 my $entry = $headlist->[$i];
2142 my $curr = $tag{'id'} eq $head;
2144 print "<tr class=\"dark\">\n";
2146 print "<tr class=\"light\">\n";
2149 print "<td><i>$tag{'age'}</i></td>\n" .
2150 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
2151 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
2152 -class => "list name"},esc_html
($tag{'name'})) .
2154 "<td class=\"link\">" .
2155 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
2156 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") . " | " .
2157 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$tag{'name'}, hash_base
=>$tag{'name'})}, "tree") .
2161 if (defined $extra) {
2163 "<td colspan=\"3\">$extra</td>\n" .
2169 ## ======================================================================
2170 ## ======================================================================
2173 sub git_project_list
{
2174 my $order = $cgi->param('o');
2175 if (defined $order && $order !~ m/project|descr|owner|age/) {
2176 die_error
(undef, "Unknown order parameter");
2179 my @list = git_get_projects_list
();
2182 die_error
(undef, "No projects found");
2184 foreach my $pr (@list) {
2185 my $head = git_get_head_hash
($pr->{'path'});
2186 if (!defined $head) {
2189 $git_dir = "$projectroot/$pr->{'path'}";
2190 my %co = parse_commit
($head);
2194 $pr->{'commit'} = \
%co;
2195 if (!defined $pr->{'descr'}) {
2196 my $descr = git_get_project_description
($pr->{'path'}) || "";
2197 $pr->{'descr'} = chop_str
($descr, 25, 5);
2199 if (!defined $pr->{'owner'}) {
2200 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2202 push @projects, $pr;
2206 if (-f
$home_text) {
2207 print "<div class=\"index_include\">\n";
2208 open (my $fd, $home_text);
2213 print "<table class=\"project_list\">\n" .
2215 $order ||= "project";
2216 if ($order eq "project") {
2217 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2218 print "<th>Project</th>\n";
2221 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2222 -class => "header"}, "Project") .
2225 if ($order eq "descr") {
2226 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2227 print "<th>Description</th>\n";
2230 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2231 -class => "header"}, "Description") .
2234 if ($order eq "owner") {
2235 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2236 print "<th>Owner</th>\n";
2239 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2240 -class => "header"}, "Owner") .
2243 if ($order eq "age") {
2244 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2245 print "<th>Last Change</th>\n";
2248 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2249 -class => "header"}, "Last Change") .
2252 print "<th></th>\n" .
2255 foreach my $pr (@projects) {
2257 print "<tr class=\"dark\">\n";
2259 print "<tr class=\"light\">\n";
2262 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2263 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2264 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2265 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2266 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2267 $pr->{'commit'}{'age_string'} . "</td>\n" .
2268 "<td class=\"link\">" .
2269 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2270 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2271 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2272 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2280 sub git_project_index
{
2281 my @projects = git_get_projects_list
();
2284 -type
=> 'text/plain',
2285 -charset
=> 'utf-8',
2286 -content_disposition
=> qq(inline
; filename
="index.aux"));
2288 foreach my $pr (@projects) {
2289 if (!exists $pr->{'owner'}) {
2290 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2293 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2294 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2295 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2296 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2300 print "$path $owner\n";
2305 my $descr = git_get_project_description
($project) || "none";
2306 my $head = git_get_head_hash
($project);
2307 my %co = parse_commit
($head);
2308 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2310 my $owner = git_get_project_owner
($project);
2312 my ($reflist, $refs) = git_get_refs_list
();
2316 foreach my $ref (@
$reflist) {
2317 if ($ref->{'name'} =~ s!^heads/!!) {
2318 push @headlist, $ref;
2320 $ref->{'name'} =~ s!^tags/!!;
2321 push @taglist, $ref;
2326 git_print_page_nav
('summary','', $head);
2328 print "<div class=\"title\"> </div>\n";
2329 print "<table cellspacing=\"0\">\n" .
2330 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2331 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2332 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2333 # use per project git URL list in $projectroot/$project/cloneurl
2334 # or make project git URL from git base URL and project name
2335 my $url_tag = "URL";
2336 my @url_list = git_get_project_url_list
($project);
2337 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2338 foreach my $git_url (@url_list) {
2339 next unless $git_url;
2340 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2345 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2346 git_get_head_hash
($project)
2347 or die_error
(undef, "Open git-rev-list failed");
2348 my @revlist = map { chomp; $_ } <$fd>;
2350 git_print_header_div
('shortlog');
2351 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2352 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2355 git_print_header_div
('tags');
2356 git_tags_body
(\
@taglist, 0, 15,
2357 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2361 git_print_header_div
('heads');
2362 git_heads_body
(\
@headlist, $head, 0, 15,
2363 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2370 my $head = git_get_head_hash
($project);
2372 git_print_page_nav
('','', $head,undef,$head);
2373 my %tag = parse_tag
($hash);
2374 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2375 print "<div class=\"title_text\">\n" .
2376 "<table cellspacing=\"0\">\n" .
2378 "<td>object</td>\n" .
2379 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2380 $tag{'object'}) . "</td>\n" .
2381 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2382 $tag{'type'}) . "</td>\n" .
2384 if (defined($tag{'author'})) {
2385 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2386 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2387 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2388 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2391 print "</table>\n\n" .
2393 print "<div class=\"page_body\">";
2394 my $comment = $tag{'comment'};
2395 foreach my $line (@
$comment) {
2396 print esc_html
($line) . "<br/>\n";
2406 my ($have_blame) = gitweb_check_feature
('blame');
2408 die_error
('403 Permission denied', "Permission denied");
2410 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2411 $hash_base ||= git_get_head_hash
($project);
2412 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2413 my %co = parse_commit
($hash_base)
2414 or die_error
(undef, "Reading commit failed");
2415 if (!defined $hash) {
2416 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2417 or die_error
(undef, "Error looking up file");
2419 $ftype = git_get_type
($hash);
2420 if ($ftype !~ "blob") {
2421 die_error
("400 Bad Request", "Object is not a blob");
2423 open ($fd, "-|", git_cmd
(), "blame", '-l', '--', $file_name, $hash_base)
2424 or die_error
(undef, "Open git-blame failed");
2427 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2430 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2433 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2435 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2436 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2437 git_print_page_path
($file_name, $ftype, $hash_base);
2438 my @rev_color = (qw(light2 dark2));
2439 my $num_colors = scalar(@rev_color);
2440 my $current_color = 0;
2443 <div class="page_body">
2444 <table class="blame">
2445 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2448 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2450 my $rev = substr($full_rev, 0, 8);
2454 if (!defined $last_rev) {
2455 $last_rev = $full_rev;
2456 } elsif ($last_rev ne $full_rev) {
2457 $last_rev = $full_rev;
2458 $current_color = ++$current_color % $num_colors;
2460 print "<tr class=\"$rev_color[$current_color]\">\n";
2461 print "<td class=\"sha1\">" .
2462 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)},
2463 esc_html
($rev)) . "</td>\n";
2464 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2465 esc_html
($lineno) . "</a></td>\n";
2466 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2472 or print "Reading blob failed\n";
2479 my ($have_blame) = gitweb_check_feature
('blame');
2481 die_error
('403 Permission denied', "Permission denied");
2483 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2484 $hash_base ||= git_get_head_hash
($project);
2485 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2486 my %co = parse_commit
($hash_base)
2487 or die_error
(undef, "Reading commit failed");
2488 if (!defined $hash) {
2489 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2490 or die_error
(undef, "Error lookup file");
2492 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2493 or die_error
(undef, "Open git-annotate failed");
2496 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2499 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2502 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2504 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2505 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2506 git_print_page_path
($file_name, 'blob', $hash_base);
2507 print "<div class=\"page_body\">\n";
2509 <table class="blame">
2518 my @line_class = (qw(light dark));
2519 my $line_class_len = scalar (@line_class);
2520 my $line_class_num = $#line_class;
2521 while (my $line = <$fd>) {
2533 $line_class_num = ($line_class_num + 1) % $line_class_len;
2535 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2542 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2545 $short_rev = substr ($long_rev, 0, 8);
2546 $age = time () - $time;
2547 $age_str = age_string
($age);
2548 $age_str =~ s/ / /g;
2549 $age_class = age_class
($age);
2550 $author = esc_html
($author);
2551 $author =~ s/ / /g;
2553 $data = untabify
($data);
2554 $data = esc_html
($data);
2557 <tr class="$line_class[$line_class_num]">
2558 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2559 <td class="$age_class">$age_str</td>
2561 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2562 <td class="pre">$data</td>
2565 } # while (my $line = <$fd>)
2566 print "</table>\n\n";
2568 or print "Reading blob failed.\n";
2574 my $head = git_get_head_hash
($project);
2576 git_print_page_nav
('','', $head,undef,$head);
2577 git_print_header_div
('summary', $project);
2579 my ($taglist) = git_get_refs_list
("tags");
2581 git_tags_body
($taglist);
2587 my $head = git_get_head_hash
($project);
2589 git_print_page_nav
('','', $head,undef,$head);
2590 git_print_header_div
('summary', $project);
2592 my ($headlist) = git_get_refs_list
("heads");
2594 git_heads_body
($headlist, $head);
2599 sub git_blob_plain
{
2602 if (!defined $hash) {
2603 if (defined $file_name) {
2604 my $base = $hash_base || git_get_head_hash
($project);
2605 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2606 or die_error
(undef, "Error lookup file");
2608 die_error
(undef, "No file name defined");
2610 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2611 # blobs defined by non-textual hash id's can be cached
2616 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2617 or die_error
(undef, "Couldn't cat $file_name, $hash");
2619 $type ||= blob_mimetype
($fd, $file_name);
2621 # save as filename, even when no $file_name is given
2622 my $save_as = "$hash";
2623 if (defined $file_name) {
2624 $save_as = $file_name;
2625 } elsif ($type =~ m/^text\//) {
2632 -content_disposition
=> "inline; filename=\"$save_as\"");
2634 binmode STDOUT
, ':raw';
2636 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2644 if (!defined $hash) {
2645 if (defined $file_name) {
2646 my $base = $hash_base || git_get_head_hash
($project);
2647 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2648 or die_error
(undef, "Error lookup file");
2650 die_error
(undef, "No file name defined");
2652 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2653 # blobs defined by non-textual hash id's can be cached
2657 my ($have_blame) = gitweb_check_feature
('blame');
2658 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2659 or die_error
(undef, "Couldn't cat $file_name, $hash");
2660 my $mimetype = blob_mimetype
($fd, $file_name);
2661 if ($mimetype !~ m/^text\//) {
2663 return git_blob_plain
($mimetype);
2665 git_header_html
(undef, $expires);
2666 my $formats_nav = '';
2667 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2668 if (defined $file_name) {
2671 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2672 hash
=>$hash, file_name
=>$file_name)},
2677 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2678 hash
=>$hash, file_name
=>$file_name)},
2681 $cgi->a({-href
=> href
(action
=>"blob_plain",
2682 hash
=>$hash, file_name
=>$file_name)},
2685 $cgi->a({-href
=> href
(action
=>"blob",
2686 hash_base
=>"HEAD", file_name
=>$file_name)},
2690 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
2692 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2693 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2695 print "<div class=\"page_nav\">\n" .
2696 "<br/><br/></div>\n" .
2697 "<div class=\"title\">$hash</div>\n";
2699 git_print_page_path
($file_name, "blob", $hash_base);
2700 print "<div class=\"page_body\">\n";
2702 while (my $line = <$fd>) {
2705 $line = untabify
($line);
2706 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2707 $nr, $nr, $nr, esc_html
($line);
2710 or print "Reading blob failed.\n";
2716 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2717 my $have_snapshot = (defined $ctype && defined $suffix);
2719 if (!defined $hash) {
2720 $hash = git_get_head_hash
($project);
2721 if (defined $file_name) {
2722 my $base = $hash_base || $hash;
2723 $hash = git_get_hash_by_path
($base, $file_name, "tree");
2725 if (!defined $hash_base) {
2730 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
2731 or die_error
(undef, "Open git-ls-tree failed");
2732 my @entries = map { chomp; $_ } <$fd>;
2733 close $fd or die_error
(undef, "Reading tree failed");
2736 my $refs = git_get_references
();
2737 my $ref = format_ref_marker
($refs, $hash_base);
2740 my ($have_blame) = gitweb_check_feature
('blame');
2741 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2743 if (defined $file_name) {
2745 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2746 hash
=>$hash, file_name
=>$file_name)},
2748 $cgi->a({-href
=> href
(action
=>"tree",
2749 hash_base
=>"HEAD", file_name
=>$file_name)},
2752 if ($have_snapshot) {
2753 # FIXME: Should be available when we have no hash base as well.
2755 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
2758 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
2759 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2762 print "<div class=\"page_nav\">\n";
2763 print "<br/><br/></div>\n";
2764 print "<div class=\"title\">$hash</div>\n";
2766 if (defined $file_name) {
2767 $base = esc_html
("$file_name/");
2769 git_print_page_path
($file_name, 'tree', $hash_base);
2770 print "<div class=\"page_body\">\n";
2771 print "<table cellspacing=\"0\">\n";
2773 foreach my $line (@entries) {
2774 my %t = parse_ls_tree_line
($line, -z
=> 1);
2777 print "<tr class=\"dark\">\n";
2779 print "<tr class=\"light\">\n";
2783 git_print_tree_entry
(\
%t, $base, $hash_base, $have_blame);
2787 print "</table>\n" .
2794 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2795 my $have_snapshot = (defined $ctype && defined $suffix);
2796 if (!$have_snapshot) {
2797 die_error
('403 Permission denied', "Permission denied");
2800 if (!defined $hash) {
2801 $hash = git_get_head_hash
($project);
2804 my $filename = basename
($project) . "-$hash.tar.$suffix";
2806 print $cgi->header(-type
=> 'application/x-tar',
2807 -content_encoding
=> $ctype,
2808 -content_disposition
=> "inline; filename=\"$filename\"",
2809 -status
=> '200 OK');
2811 my $git_command = git_cmd_str
();
2812 open my $fd, "-|", "$git_command tar-tree $hash \'$project\' | $command" or
2813 die_error
(undef, "Execute git-tar-tree failed.");
2814 binmode STDOUT
, ':raw';
2816 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2822 my $head = git_get_head_hash
($project);
2823 if (!defined $hash) {
2826 if (!defined $page) {
2829 my $refs = git_get_references
();
2831 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2832 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
2833 or die_error
(undef, "Open git-rev-list failed");
2834 my @revlist = map { chomp; $_ } <$fd>;
2837 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2840 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2843 my %co = parse_commit
($hash);
2845 git_print_header_div
('summary', $project);
2846 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2848 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2849 my $commit = $revlist[$i];
2850 my $ref = format_ref_marker
($refs, $commit);
2851 my %co = parse_commit
($commit);
2853 my %ad = parse_date
($co{'author_epoch'});
2854 git_print_header_div
('commit',
2855 "<span class=\"age\">$co{'age_string'}</span>" .
2856 esc_html
($co{'title'}) . $ref,
2858 print "<div class=\"title_text\">\n" .
2859 "<div class=\"log_link\">\n" .
2860 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2862 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2864 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
2867 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2870 print "<div class=\"log_body\">\n";
2871 git_print_simplified_log
($co{'comment'});
2878 my %co = parse_commit
($hash);
2880 die_error
(undef, "Unknown commit object");
2882 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2883 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2885 my $parent = $co{'parent'};
2886 if (!defined $parent) {
2889 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $parent, $hash
2890 or die_error
(undef, "Open git-diff-tree failed");
2891 my @difftree = map { chomp; $_ } <$fd>;
2892 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2894 # non-textual hash id's can be cached
2896 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2899 my $refs = git_get_references
();
2900 my $ref = format_ref_marker
($refs, $co{'id'});
2902 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2903 my $have_snapshot = (defined $ctype && defined $suffix);
2906 if (defined $file_name && defined $co{'parent'}) {
2907 my $parent = $co{'parent'};
2909 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
2912 if (defined $co{'parent'}) {
2914 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash)}, "shortlog"),
2915 $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash)}, "log");
2917 git_header_html
(undef, $expires);
2918 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
2919 $hash, $co{'tree'}, $hash,
2920 join (' | ', @views_nav));
2922 if (defined $co{'parent'}) {
2923 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2925 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
2927 print "<div class=\"title_text\">\n" .
2928 "<table cellspacing=\"0\">\n";
2929 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2931 "<td></td><td> $ad{'rfc2822'}";
2932 if ($ad{'hour_local'} < 6) {
2933 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2934 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2936 printf(" (%02d:%02d %s)",
2937 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2941 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2942 print "<tr><td></td><td> $cd{'rfc2822'}" .
2943 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2945 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2948 "<td class=\"sha1\">" .
2949 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
2950 class => "list"}, $co{'tree'}) .
2952 "<td class=\"link\">" .
2953 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
2955 if ($have_snapshot) {
2957 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
2961 my $parents = $co{'parents'};
2962 foreach my $par (@
$parents) {
2965 "<td class=\"sha1\">" .
2966 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
2967 class => "list"}, $par) .
2969 "<td class=\"link\">" .
2970 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
2972 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
2979 print "<div class=\"page_body\">\n";
2980 git_print_log
($co{'comment'});
2983 git_difftree_body
(\
@difftree, $hash, $parent);
2989 my $format = shift || 'html';
2996 # preparing $fd and %diffinfo for git_patchset_body
2998 if (defined $hash_base && defined $hash_parent_base) {
2999 if (defined $file_name) {
3001 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
3003 or die_error
(undef, "Open git-diff-tree failed");
3004 @difftree = map { chomp; $_ } <$fd>;
3006 or die_error
(undef, "Reading git-diff-tree failed");
3008 or die_error
('404 Not Found', "Blob diff not found");
3010 } elsif (defined $hash &&
3011 $hash =~ /[0-9a-fA-F]{40}/) {
3012 # try to find filename from $hash
3014 # read filtered raw output
3015 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
3016 or die_error
(undef, "Open git-diff-tree failed");
3018 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3020 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3021 map { chomp; $_ } <$fd>;
3023 or die_error
(undef, "Reading git-diff-tree failed");
3025 or die_error
('404 Not Found', "Blob diff not found");
3028 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3031 if (@difftree > 1) {
3032 die_error
('404 Not Found', "Ambiguous blob diff specification");
3035 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3036 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3037 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3039 $hash_parent ||= $diffinfo{'from_id'};
3040 $hash ||= $diffinfo{'to_id'};
3042 # non-textual hash id's can be cached
3043 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3044 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3049 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3050 '-p', $hash_parent_base, $hash_base,
3052 or die_error
(undef, "Open git-diff-tree failed");
3055 # old/legacy style URI
3056 if (!%diffinfo && # if new style URI failed
3057 defined $hash && defined $hash_parent) {
3058 # fake git-diff-tree raw output
3059 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3060 $diffinfo{'from_id'} = $hash_parent;
3061 $diffinfo{'to_id'} = $hash;
3062 if (defined $file_name) {
3063 if (defined $file_parent) {
3064 $diffinfo{'status'} = '2';
3065 $diffinfo{'from_file'} = $file_parent;
3066 $diffinfo{'to_file'} = $file_name;
3067 } else { # assume not renamed
3068 $diffinfo{'status'} = '1';
3069 $diffinfo{'from_file'} = $file_name;
3070 $diffinfo{'to_file'} = $file_name;
3072 } else { # no filename given
3073 $diffinfo{'status'} = '2';
3074 $diffinfo{'from_file'} = $hash_parent;
3075 $diffinfo{'to_file'} = $hash;
3078 # non-textual hash id's can be cached
3079 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3080 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3085 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts, $hash_parent, $hash
3086 or die_error
(undef, "Open git-diff failed");
3088 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3093 if ($format eq 'html') {
3095 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3096 hash
=>$hash, hash_parent
=>$hash_parent,
3097 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3098 file_name
=>$file_name, file_parent
=>$file_parent)},
3100 git_header_html
(undef, $expires);
3101 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3102 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3103 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3105 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3106 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3108 if (defined $file_name) {
3109 git_print_page_path
($file_name, "blob", $hash_base);
3111 print "<div class=\"page_path\"></div>\n";
3114 } elsif ($format eq 'plain') {
3116 -type
=> 'text/plain',
3117 -charset
=> 'utf-8',
3118 -expires
=> $expires,
3119 -content_disposition
=> qq(inline
; filename
=") . quotemeta($file_name) . qq(.patch"));
3121 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3124 die_error
(undef, "Unknown blobdiff format");
3128 if ($format eq 'html') {
3129 print "<div class=\"page_body\">\n";
3131 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3134 print "</div>\n"; # class="page_body"
3138 while (my $line = <$fd>) {
3139 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_html($diffinfo{'from_file'})!eg;
3140 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_html($diffinfo{'to_file'})!eg;
3144 last if $line =~ m!^\+\+\+!;
3152 sub git_blobdiff_plain
{
3153 git_blobdiff
('plain');
3156 sub git_commitdiff
{
3157 my $format = shift || 'html';
3158 my %co = parse_commit
($hash);
3160 die_error
(undef, "Unknown commit object");
3162 if (!defined $hash_parent) {
3163 $hash_parent = $co{'parent'} || '--root';
3169 if ($format eq 'html') {
3170 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3171 "--patch-with-raw", "--full-index", $hash_parent, $hash
3172 or die_error
(undef, "Open git-diff-tree failed");
3174 while (chomp(my $line = <$fd>)) {
3175 # empty line ends raw part of diff-tree output
3177 push @difftree, $line;
3180 } elsif ($format eq 'plain') {
3181 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3182 '-p', $hash_parent, $hash
3183 or die_error
(undef, "Open git-diff-tree failed");
3186 die_error
(undef, "Unknown commitdiff format");
3189 # non-textual hash id's can be cached
3191 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3195 # write commit message
3196 if ($format eq 'html') {
3197 my $refs = git_get_references
();
3198 my $ref = format_ref_marker
($refs, $co{'id'});
3200 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3201 hash
=>$hash, hash_parent
=>$hash_parent)},
3204 git_header_html
(undef, $expires);
3205 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3206 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3207 git_print_authorship
(\
%co);
3208 print "<div class=\"page_body\">\n";
3209 print "<div class=\"log\">\n";
3210 git_print_simplified_log
($co{'comment'}, 1); # skip title
3211 print "</div>\n"; # class="log"
3213 } elsif ($format eq 'plain') {
3214 my $refs = git_get_references
("tags");
3215 my $tagname = git_get_rev_name_tags
($hash);
3216 my $filename = basename
($project) . "-$hash.patch";
3219 -type
=> 'text/plain',
3220 -charset
=> 'utf-8',
3221 -expires
=> $expires,
3222 -content_disposition
=> qq(inline
; filename
="$filename"));
3223 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3226 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3227 Subject: $co{'title'}
3229 print "X-Git-Tag: $tagname\n" if $tagname;
3230 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3232 foreach my $line (@
{$co{'comment'}}) {
3239 if ($format eq 'html') {
3240 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3243 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3245 print "</div>\n"; # class="page_body"
3248 } elsif ($format eq 'plain') {
3252 or print "Reading git-diff-tree failed\n";
3256 sub git_commitdiff_plain
{
3257 git_commitdiff
('plain');
3261 if (!defined $hash_base) {
3262 $hash_base = git_get_head_hash
($project);
3264 if (!defined $page) {
3268 my %co = parse_commit
($hash_base);
3270 die_error
(undef, "Unknown commit object");
3273 my $refs = git_get_references
();
3274 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3276 if (!defined $hash && defined $file_name) {
3277 $hash = git_get_hash_by_path
($hash_base, $file_name);
3279 if (defined $hash) {
3280 $ftype = git_get_type
($hash);
3284 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3285 or die_error
(undef, "Open git-rev-list-failed");
3286 my @revlist = map { chomp; $_ } <$fd>;
3288 or die_error
(undef, "Reading git-rev-list failed");
3290 my $paging_nav = '';
3293 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3294 file_name
=>$file_name)},
3296 $paging_nav .= " ⋅ " .
3297 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3298 file_name
=>$file_name, page
=>$page-1),
3299 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3301 $paging_nav .= "first";
3302 $paging_nav .= " ⋅ prev";
3304 if ($#revlist >= (100 * ($page+1)-1)) {
3305 $paging_nav .= " ⋅ " .
3306 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3307 file_name
=>$file_name, page
=>$page+1),
3308 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3310 $paging_nav .= " ⋅ next";
3313 if ($#revlist >= (100 * ($page+1)-1)) {
3315 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3316 file_name
=>$file_name, page
=>$page+1),
3317 -title
=> "Alt-n"}, "next");
3321 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3322 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3323 git_print_page_path
($file_name, $ftype, $hash_base);
3325 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3326 $refs, $hash_base, $ftype, $next_link);
3332 if (!defined $searchtext) {
3333 die_error
(undef, "Text field empty");
3335 if (!defined $hash) {
3336 $hash = git_get_head_hash
($project);
3338 my %co = parse_commit
($hash);
3340 die_error
(undef, "Unknown commit object");
3343 my $commit_search = 1;
3344 my $author_search = 0;
3345 my $committer_search = 0;
3346 my $pickaxe_search = 0;
3347 if ($searchtext =~ s/^author\\://i) {
3349 } elsif ($searchtext =~ s/^committer\\://i) {
3350 $committer_search = 1;
3351 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3353 $pickaxe_search = 1;
3355 # pickaxe may take all resources of your box and run for several minutes
3356 # with every query - so decide by yourself how public you make this feature
3357 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3358 if (!$have_pickaxe) {
3359 die_error
('403 Permission denied', "Permission denied");
3363 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3364 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3366 print "<table cellspacing=\"0\">\n";
3368 if ($commit_search) {
3370 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", $hash or next;
3371 while (my $commit_text = <$fd>) {
3372 if (!grep m/$searchtext/i, $commit_text) {
3375 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3378 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3381 my @commit_lines = split "\n", $commit_text;
3382 my %co = parse_commit
(undef, \
@commit_lines);
3387 print "<tr class=\"dark\">\n";
3389 print "<tr class=\"light\">\n";
3392 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3393 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3395 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3396 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3397 my $comment = $co{'comment'};
3398 foreach my $line (@
$comment) {
3399 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3400 my $lead = esc_html
($1) || "";
3401 $lead = chop_str
($lead, 30, 10);
3402 my $match = esc_html
($2) || "";
3403 my $trail = esc_html
($3) || "";
3404 $trail = chop_str
($trail, 30, 10);
3405 my $text = "$lead<span class=\"match\">$match</span>$trail";
3406 print chop_str
($text, 80, 5) . "<br/>\n";
3410 "<td class=\"link\">" .
3411 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3413 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3420 if ($pickaxe_search) {
3422 my $git_command = git_cmd_str
();
3423 open my $fd, "-|", "$git_command rev-list $hash | " .
3424 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3427 while (my $line = <$fd>) {
3428 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3431 $set{'from_id'} = $3;
3433 $set{'id'} = $set{'to_id'};
3434 if ($set{'id'} =~ m/0{40}/) {
3435 $set{'id'} = $set{'from_id'};
3437 if ($set{'id'} =~ m/0{40}/) {
3441 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3444 print "<tr class=\"dark\">\n";
3446 print "<tr class=\"light\">\n";
3449 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3450 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3452 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3453 -class => "list subject"},
3454 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3455 while (my $setref = shift @files) {
3457 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3458 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3460 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3464 "<td class=\"link\">" .
3465 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3467 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3471 %co = parse_commit
($1);
3481 my $head = git_get_head_hash
($project);
3482 if (!defined $hash) {
3485 if (!defined $page) {
3488 my $refs = git_get_references
();
3490 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3491 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3492 or die_error
(undef, "Open git-rev-list failed");
3493 my @revlist = map { chomp; $_ } <$fd>;
3496 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3498 if ($#revlist >= (100 * ($page+1)-1)) {
3500 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3501 -title
=> "Alt-n"}, "next");
3506 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3507 git_print_header_div
('summary', $project);
3509 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3514 ## ......................................................................
3515 ## feeds (RSS, OPML)
3518 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3519 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150", git_get_head_hash
($project)
3520 or die_error
(undef, "Open git-rev-list failed");
3521 my @revlist = map { chomp; $_ } <$fd>;
3522 close $fd or die_error
(undef, "Reading git-rev-list failed");
3523 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3525 <?xml version="1.0" encoding="utf-8"?>
3526 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3528 <title>$project $my_uri $my_url</title>
3529 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3530 <description>$project log</description>
3531 <language>en</language>
3534 for (my $i = 0; $i <= $#revlist; $i++) {
3535 my $commit = $revlist[$i];
3536 my %co = parse_commit
($commit);
3537 # we read 150, we always show 30 and the ones more recent than 48 hours
3538 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3541 my %cd = parse_date
($co{'committer_epoch'});
3542 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3543 $co{'parent'}, $co{'id'}
3545 my @difftree = map { chomp; $_ } <$fd>;
3550 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3552 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3553 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3554 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3555 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3556 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3557 "<content:encoded>" .
3559 my $comment = $co{'comment'};
3560 foreach my $line (@
$comment) {
3561 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
3562 print "$line<br/>\n";
3565 foreach my $line (@difftree) {
3566 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3569 my $file = esc_html
(unquote
($7));
3570 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
3571 print "$file<br/>\n";
3574 "</content:encoded>\n" .
3577 print "</channel></rss>";
3581 my @list = git_get_projects_list
();
3583 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3585 <?xml version="1.0" encoding="utf-8"?>
3586 <opml version="1.0">
3588 <title>$site_name Git OPML Export</title>
3591 <outline text="git RSS feeds">
3594 foreach my $pr (@list) {
3596 my $head = git_get_head_hash
($proj{'path'});
3597 if (!defined $head) {
3600 $git_dir = "$projectroot/$proj{'path'}";
3601 my %co = parse_commit
($head);
3606 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3607 my $rss = "$my_url?p=$proj{'path'};a=rss";
3608 my $html = "$my_url?p=$proj{'path'};a=summary";
3609 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";