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 our $file_name = $cgi->param('f');
216 if (defined $file_name) {
217 if (!validate_input($file_name)) {
218 die_error(undef, "Invalid file parameter");
222 our $file_parent = $cgi->param('fp');
223 if (defined $file_parent) {
224 if (!validate_input($file_parent)) {
225 die_error(undef, "Invalid file parent parameter");
229 our $hash = $cgi->param('h');
231 if (!validate_input($hash)) {
232 die_error(undef, "Invalid hash parameter");
236 our $hash_parent = $cgi->param('hp');
237 if (defined $hash_parent) {
238 if (!validate_input($hash_parent)) {
239 die_error(undef, "Invalid hash parent parameter");
243 our $hash_base = $cgi->param('hb');
244 if (defined $hash_base) {
245 if (!validate_input($hash_base)) {
246 die_error(undef, "Invalid hash base parameter");
250 our $hash_parent_base = $cgi->param('hpb');
251 if (defined $hash_parent_base) {
252 if (!validate_input($hash_parent_base)) {
253 die_error(undef, "Invalid hash parent base parameter");
257 our $page = $cgi->param('pg');
259 if ($page =~ m/[^0-9]/) {
260 die_error(undef, "Invalid page parameter");
264 our $searchtext = $cgi->param('s');
265 if (defined $searchtext) {
266 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) {
267 die_error(undef, "Invalid search parameter");
269 $searchtext = quotemeta $searchtext;
272 # now read PATH_INFO and use it as alternative to parameters
273 sub evaluate_path_info {
274 return if defined $project;
275 my $path_info = $ENV{"PATH_INFO"};
276 return if !$path_info;
277 $path_info =~ s,^/+,,;
278 return if !$path_info;
279 # find which part of PATH_INFO is project
280 $project = $path_info;
282 while ($project && !-e "$projectroot/$project/HEAD") {
283 $project =~ s,/*[^/]*$,,;
286 $project = validate_input($project);
288 ($export_ok && !-e "$projectroot/$project/$export_ok") ||
289 ($strict_export && !project_in_list($project))) {
293 # do not change any parameters if an action is given using the query string
295 $path_info =~ s,^$project/*,,;
296 my ($refname, $pathname) = split(/:/, $path_info, 2);
297 if (defined $pathname) {
298 # we got "project.git/branch:filename" or "project.git/branch:dir/"
299 # we could use git_get_type(branch:pathname), but it needs $git_dir
300 $pathname =~ s,^/+,,;
301 if (!$pathname || substr($pathname, -1) eq "/") {
305 $action ||= "blob_plain";
307 $hash_base ||= validate_input($refname);
308 $file_name ||= validate_input($pathname);
309 } elsif (defined $refname) {
310 # we got "project.git/branch"
311 $action ||= "shortlog";
312 $hash ||= validate_input($refname);
315 evaluate_path_info();
317 # path to the current git repository
319 $git_dir = "$projectroot/$project" if $project;
323 "blame" => \&git_blame2,
324 "blobdiff" => \&git_blobdiff,
325 "blobdiff_plain" => \&git_blobdiff_plain,
326 "blob" => \&git_blob,
327 "blob_plain" => \&git_blob_plain,
328 "commitdiff" => \&git_commitdiff,
329 "commitdiff_plain" => \&git_commitdiff_plain,
330 "commit" => \&git_commit,
331 "heads" => \&git_heads,
332 "history" => \&git_history,
335 "search" => \&git_search,
336 "shortlog" => \&git_shortlog,
337 "summary" => \&git_summary,
339 "tags" => \&git_tags,
340 "tree" => \&git_tree,
341 "snapshot" => \&git_snapshot,
342 # those below don't need $project
343 "opml" => \&git_opml,
344 "project_list" => \&git_project_list,
345 "project_index" => \&git_project_index,
348 if (defined $project) {
349 $action ||= 'summary';
351 $action ||= 'project_list';
353 if (!defined($actions{$action})) {
354 die_error(undef, "Unknown action");
356 if ($action !~ m/^(opml|project_list|project_index)$/ &&
358 die_error(undef, "Project needed");
360 $actions{$action}->();
363 ## ======================================================================
377 hash_parent_base => "hpb",
382 my %mapping = @mapping;
384 $params{'project'} = $project unless exists $params{'project'};
387 for (my $i = 0; $i < @mapping; $i += 2) {
388 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
389 if (defined $params{$name}) {
390 push @result, $symbol . "=" . esc_param($params{$name});
393 return "$my_uri?" . join(';', @result);
397 ## ======================================================================
398 ## validation, quoting/unquoting and escaping
403 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
406 if ($input =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
409 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\-\+\#\~\%]/) {
415 # quote unsafe chars, but keep the slash, even when it's not
416 # correct, but quoted slashes look too horrible in bookmarks
419 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
425 # replace invalid utf8 character with SUBSTITUTION sequence
428 $str = decode("utf8", $str, Encode::FB_DEFAULT);
429 $str = escapeHTML($str);
430 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
434 # git may return quoted and escaped filenames
437 if ($str =~ m/^"(.*)"$/) {
439 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
444 # escape tabs (convert tabs to spaces)
448 while ((my $pos = index($line, "\t")) != -1) {
449 if (my $count = (8 - ($pos % 8))) {
450 my $spaces = ' ' x $count;
451 $line =~ s/\t/$spaces/;
458 sub project_in_list {
460 my @list = git_get_projects_list();
461 return @list && scalar(grep { $_->{'path'} eq $project } @list);
464 ## ----------------------------------------------------------------------
465 ## HTML aware string manipulation
470 my $add_len = shift || 10;
472 # allow only $len chars, but don't cut a word if it would fit in $add_len
473 # if it doesn't fit, cut it if it's still longer than the dots we would add
474 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
477 if (length($tail) > 4) {
479 $body =~ s/&[^;]*$//; # remove chopped character entities
484 ## ----------------------------------------------------------------------
485 ## functions returning short strings
487 # CSS class for given age value (in seconds)
491 if ($age < 60*60*2) {
493 } elsif ($age < 60*60*24*2) {
500 # convert age in seconds to "nn units ago" string
505 if ($age > 60*60*24*365*2) {
506 $age_str = (int $age/60/60/24/365);
507 $age_str .= " years ago";
508 } elsif ($age > 60*60*24*(365/12)*2) {
509 $age_str = int $age/60/60/24/(365/12);
510 $age_str .= " months ago";
511 } elsif ($age > 60*60*24*7*2) {
512 $age_str = int $age/60/60/24/7;
513 $age_str .= " weeks ago";
514 } elsif ($age > 60*60*24*2) {
515 $age_str = int $age/60/60/24;
516 $age_str .= " days ago";
517 } elsif ($age > 60*60*2) {
518 $age_str = int $age/60/60;
519 $age_str .= " hours ago";
520 } elsif ($age > 60*2) {
521 $age_str = int $age/60;
522 $age_str .= " min ago";
525 $age_str .= " sec ago";
527 $age_str .= " right now";
532 # convert file mode in octal to symbolic file mode string
534 my $mode = oct shift;
536 if (S_ISDIR($mode & S_IFMT)) {
538 } elsif (S_ISLNK($mode)) {
540 } elsif (S_ISREG($mode)) {
541 # git cares only about the executable bit
542 if ($mode & S_IXUSR) {
552 # convert file mode in octal to file type string
556 if ($mode !~ m/^[0-7]+$/) {
562 if (S_ISDIR($mode & S_IFMT)) {
564 } elsif (S_ISLNK($mode)) {
566 } elsif (S_ISREG($mode)) {
573 ## ----------------------------------------------------------------------
574 ## functions returning short HTML fragments, or transforming HTML fragments
575 ## which don't beling to other sections
577 # format line of commit message or tag comment
578 sub format_log_line_html {
581 $line = esc_html($line);
582 $line =~ s/ / /g;
583 if ($line =~ m/([0-9a-fA-F]{40})/) {
585 if (git_get_type($hash_text) eq "commit") {
587 $cgi->a({-href => href(action=>"commit", hash=>$hash_text),
588 -class => "text"}, $hash_text);
589 $line =~ s/$hash_text/$link/;
595 # format marker of refs pointing to given object
596 sub format_ref_marker {
597 my ($refs, $id) = @_;
600 if (defined $refs->{$id}) {
601 foreach my $ref (@{$refs->{$id}}) {
602 my ($type, $name) = qw();
603 # e.g. tags/v2.6.11 or heads/next
604 if ($ref =~ m!^(.*?)s?/(.*)$!) {
612 $markers .= " <span class=\"$type\">" . esc_html($name) . "</span>";
617 return ' <span class="refs">'. $markers . '</span>';
623 # format, perhaps shortened and with markers, title line
624 sub format_subject_html {
625 my ($long, $short, $href, $extra) = @_;
626 $extra = '' unless defined($extra);
628 if (length($short) < length($long)) {
629 return $cgi->a({-href => $href, -class => "list subject",
631 esc_html($short) . $extra);
633 return $cgi->a({-href => $href, -class => "list subject"},
634 esc_html($long) . $extra);
638 sub format_diff_line {
640 my $char = substr($line, 0, 1);
646 $diff_class = " add";
647 } elsif ($char eq "-") {
648 $diff_class = " rem";
649 } elsif ($char eq "@") {
650 $diff_class = " chunk_header";
651 } elsif ($char eq "\\") {
652 $diff_class = " incomplete";
654 $line = untabify($line);
655 return "<div class=\"diff$diff_class\">" . esc_html($line) . "</div>\n";
658 ## ----------------------------------------------------------------------
659 ## git utility subroutines, invoking git commands
661 # returns path to the core git executable and the --git-dir parameter as list
663 return $GIT, '--git-dir='.$git_dir;
666 # returns path to the core git executable and the --git-dir parameter as string
668 return join(' ', git_cmd());
671 # get HEAD ref of given project as hash
672 sub git_get_head_hash {
674 my $o_git_dir = $git_dir;
676 $git_dir = "$projectroot/$project";
677 if (open my $fd, "-|", git_cmd(), "rev-parse", "--verify", "HEAD") {
680 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
684 if (defined $o_git_dir) {
685 $git_dir = $o_git_dir;
690 # get type of given object
694 open my $fd, "-|", git_cmd(), "cat-file", '-t', $hash or return;
701 sub git_get_project_config {
702 my ($key, $type) = @_;
704 return unless ($key);
705 $key =~ s/^gitweb\.//;
706 return if ($key =~ m/\W/);
708 my @x = (git_cmd(), 'repo-config');
709 if (defined $type) { push @x, $type; }
711 push @x, "gitweb.$key";
717 # get hash of given path at given ref
718 sub git_get_hash_by_path {
720 my $path = shift || return undef;
725 open my $fd, "-|", git_cmd(), "ls-tree", $base, "--", $path
726 or die_error(undef, "Open git-ls-tree failed");
728 close $fd or return undef;
730 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
731 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
732 if (defined $type && $type ne $2) {
739 ## ......................................................................
740 ## git utility functions, directly accessing git repository
742 sub git_get_project_description {
745 open my $fd, "$projectroot/$path/description" or return undef;
752 sub git_get_project_url_list {
755 open my $fd, "$projectroot/$path/cloneurl" or return undef;
756 my @git_project_url_list = map { chomp; $_ } <$fd>;
759 return wantarray ? @git_project_url_list : \@git_project_url_list;
762 sub git_get_projects_list {
765 if (-d $projects_list) {
766 # search in directory
767 my $dir = $projects_list;
768 my $pfxlen = length("$dir");
771 follow_fast => 1, # follow symbolic links
772 dangling_symlinks => 0, # ignore dangling symlinks, silently
774 # skip project-list toplevel, if we get it.
775 return if (m!^[/.]$!);
776 # only directories can be git repositories
777 return unless (-d $_);
779 my $subdir = substr($File::Find::name, $pfxlen + 1);
780 # we check related file in $projectroot
781 if (-e "$projectroot/$subdir/HEAD" && (!$export_ok ||
782 -e "$projectroot/$subdir/$export_ok")) {
783 push @list, { path => $subdir };
784 $File::Find::prune = 1;
789 } elsif (-f $projects_list) {
790 # read from file(url-encoded):
791 # 'git%2Fgit.git Linus+Torvalds'
792 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
793 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
794 open my ($fd), $projects_list or return undef;
795 while (my $line = <$fd>) {
797 my ($path, $owner) = split ' ', $line;
798 $path = unescape($path);
799 $owner = unescape($owner);
800 if (!defined $path) {
803 if (-e "$projectroot/$path/HEAD" && (!$export_ok ||
804 -e "$projectroot/$path/$export_ok")) {
807 owner => decode("utf8", $owner, Encode::FB_DEFAULT),
814 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
818 sub git_get_project_owner {
822 return undef unless $project;
824 # read from file (url-encoded):
825 # 'git%2Fgit.git Linus+Torvalds'
826 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
827 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
828 if (-f $projects_list) {
829 open (my $fd , $projects_list);
830 while (my $line = <$fd>) {
832 my ($pr, $ow) = split ' ', $line;
835 if ($pr eq $project) {
836 $owner = decode("utf8", $ow, Encode::FB_DEFAULT);
842 if (!defined $owner) {
843 $owner = get_file_owner("$projectroot/$project");
849 sub git_get_references {
850 my $type = shift || "";
852 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
853 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
854 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
857 while (my $line = <$fd>) {
859 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?[^\^]+)/) {
860 if (defined $refs{$1}) {
861 push @{$refs{$1}}, $2;
871 sub git_get_rev_name_tags {
872 my $hash = shift || return undef;
874 open my $fd, "-|", git_cmd(), "name-rev", "--tags", $hash
876 my $name_rev = <$fd>;
879 if ($name_rev =~ m|^$hash tags/(.*)$|) {
882 # catches also '$hash undefined' output
887 ## ----------------------------------------------------------------------
888 ## parse to hash functions
892 my $tz = shift || "-0000";
895 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
896 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
897 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
898 $date{'hour'} = $hour;
899 $date{'minute'} = $min;
900 $date{'mday'} = $mday;
901 $date{'day'} = $days[$wday];
902 $date{'month'} = $months[$mon];
903 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
904 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
905 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
906 $mday, $months[$mon], $hour ,$min;
908 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
909 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
910 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
911 $date{'hour_local'} = $hour;
912 $date{'minute_local'} = $min;
913 $date{'tz_local'} = $tz;
922 open my $fd, "-|", git_cmd(), "cat-file", "tag", $tag_id or return;
923 $tag{'id'} = $tag_id;
924 while (my $line = <$fd>) {
926 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
928 } elsif ($line =~ m/^type (.+)$/) {
930 } elsif ($line =~ m/^tag (.+)$/) {
932 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
936 } elsif ($line =~ m/--BEGIN/) {
937 push @comment, $line;
939 } elsif ($line eq "") {
943 push @comment, <$fd>;
944 $tag{'comment'} = \@comment;
946 if (!defined $tag{'name'}) {
953 my $commit_id = shift;
954 my $commit_text = shift;
959 if (defined $commit_text) {
960 @commit_lines = @$commit_text;
963 open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
965 @commit_lines = split '\n', <$fd>;
970 my $header = shift @commit_lines;
971 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
974 ($co{'id'}, my @parents) = split ' ', $header;
975 $co{'parents'} = \@parents;
976 $co{'parent'} = $parents[0];
977 while (my $line = shift @commit_lines) {
978 last if $line eq "\n";
979 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
981 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
983 $co{'author_epoch'} = $2;
984 $co{'author_tz'} = $3;
985 if ($co{'author'} =~ m/^([^<]+) </) {
986 $co{'author_name'} = $1;
988 $co{'author_name'} = $co{'author'};
990 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
991 $co{'committer'} = $1;
992 $co{'committer_epoch'} = $2;
993 $co{'committer_tz'} = $3;
994 $co{'committer_name'} = $co{'committer'};
995 $co{'committer_name'} =~ s/ <.*//;
998 if (!defined $co{'tree'}) {
1002 foreach my $title (@commit_lines) {
1005 $co{'title'} = chop_str($title, 80, 5);
1006 # remove leading stuff of merges to make the interesting part visible
1007 if (length($title) > 50) {
1008 $title =~ s/^Automatic //;
1009 $title =~ s/^merge (of|with) /Merge ... /i;
1010 if (length($title) > 50) {
1011 $title =~ s/(http|rsync):\/\///;
1013 if (length($title) > 50) {
1014 $title =~ s/(master|www|rsync)\.//;
1016 if (length($title) > 50) {
1017 $title =~ s/kernel.org:?//;
1019 if (length($title) > 50) {
1020 $title =~ s/\/pub\/scm//;
1023 $co{'title_short'} = chop_str($title, 50, 5);
1027 # remove added spaces
1028 foreach my $line (@commit_lines) {
1031 $co{'comment'} = \@commit_lines;
1033 my $age = time - $co{'committer_epoch'};
1035 $co{'age_string'} = age_string($age);
1036 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1037 if ($age > 60*60*24*7*2) {
1038 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1039 $co{'age_string_age'} = $co{'age_string'};
1041 $co{'age_string_date'} = $co{'age_string'};
1042 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1047 # parse ref from ref_file, given by ref_id, with given type
1049 my $ref_file = shift;
1051 my $type = shift || git_get_type($ref_id);
1054 $ref_item{'type'} = $type;
1055 $ref_item{'id'} = $ref_id;
1056 $ref_item{'epoch'} = 0;
1057 $ref_item{'age'} = "unknown";
1058 if ($type eq "tag") {
1059 my %tag = parse_tag($ref_id);
1060 $ref_item{'comment'} = $tag{'comment'};
1061 if ($tag{'type'} eq "commit") {
1062 my %co = parse_commit($tag{'object'});
1063 $ref_item{'epoch'} = $co{'committer_epoch'};
1064 $ref_item{'age'} = $co{'age_string'};
1065 } elsif (defined($tag{'epoch'})) {
1066 my $age = time - $tag{'epoch'};
1067 $ref_item{'epoch'} = $tag{'epoch'};
1068 $ref_item{'age'} = age_string($age);
1070 $ref_item{'reftype'} = $tag{'type'};
1071 $ref_item{'name'} = $tag{'name'};
1072 $ref_item{'refid'} = $tag{'object'};
1073 } elsif ($type eq "commit"){
1074 my %co = parse_commit($ref_id);
1075 $ref_item{'reftype'} = "commit";
1076 $ref_item{'name'} = $ref_file;
1077 $ref_item{'title'} = $co{'title'};
1078 $ref_item{'refid'} = $ref_id;
1079 $ref_item{'epoch'} = $co{'committer_epoch'};
1080 $ref_item{'age'} = $co{'age_string'};
1082 $ref_item{'reftype'} = $type;
1083 $ref_item{'name'} = $ref_file;
1084 $ref_item{'refid'} = $ref_id;
1090 # parse line of git-diff-tree "raw" output
1091 sub parse_difftree_raw_line {
1095 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1096 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1097 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1098 $res{'from_mode'} = $1;
1099 $res{'to_mode'} = $2;
1100 $res{'from_id'} = $3;
1102 $res{'status'} = $5;
1103 $res{'similarity'} = $6;
1104 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1105 ($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
1107 $res{'file'} = unquote($7);
1110 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1111 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1112 $res{'commit'} = $1;
1115 return wantarray ? %res : \%res;
1118 # parse line of git-ls-tree output
1119 sub parse_ls_tree_line ($;%) {
1124 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1125 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1133 $res{'name'} = unquote($4);
1136 return wantarray ? %res : \%res;
1139 ## ......................................................................
1140 ## parse to array of hashes functions
1142 sub git_get_refs_list {
1143 my $type = shift || "";
1148 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1150 while (my $line = <$fd>) {
1152 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?([^\^]+))(\^\{\})?$/) {
1153 if (defined $refs{$1}) {
1154 push @{$refs{$1}}, $2;
1159 if (! $4) { # unpeeled, direct reference
1160 push @refs, { hash => $1, name => $3 }; # without type
1161 } elsif ($3 eq $refs[-1]{'name'}) {
1162 # most likely a tag is followed by its peeled
1163 # (deref) one, and when that happens we know the
1164 # previous one was of type 'tag'.
1165 $refs[-1]{'type'} = "tag";
1171 foreach my $ref (@refs) {
1172 my $ref_file = $ref->{'name'};
1173 my $ref_id = $ref->{'hash'};
1175 my $type = $ref->{'type'} || git_get_type($ref_id) || next;
1176 my %ref_item = parse_ref($ref_file, $ref_id, $type);
1178 push @reflist, \%ref_item;
1181 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1182 return (\@reflist, \%refs);
1185 ## ----------------------------------------------------------------------
1186 ## filesystem-related functions
1188 sub get_file_owner {
1191 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1192 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1193 if (!defined $gcos) {
1197 $owner =~ s/[,;].*$//;
1198 return decode("utf8", $owner, Encode::FB_DEFAULT);
1201 ## ......................................................................
1202 ## mimetype related functions
1204 sub mimetype_guess_file {
1205 my $filename = shift;
1206 my $mimemap = shift;
1207 -r $mimemap or return undef;
1210 open(MIME, $mimemap) or return undef;
1212 next if m/^#/; # skip comments
1213 my ($mime, $exts) = split(/\t+/);
1214 if (defined $exts) {
1215 my @exts = split(/\s+/, $exts);
1216 foreach my $ext (@exts) {
1217 $mimemap{$ext} = $mime;
1223 $filename =~ /\.([^.]*)$/;
1224 return $mimemap{$1};
1227 sub mimetype_guess {
1228 my $filename = shift;
1230 $filename =~ /\./ or return undef;
1232 if ($mimetypes_file) {
1233 my $file = $mimetypes_file;
1234 if ($file !~ m!^/!) { # if it is relative path
1235 # it is relative to project
1236 $file = "$projectroot/$project/$file";
1238 $mime = mimetype_guess_file($filename, $file);
1240 $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
1246 my $filename = shift;
1249 my $mime = mimetype_guess($filename);
1250 $mime and return $mime;
1254 return $default_blob_plain_mimetype unless $fd;
1257 return 'text/plain' .
1258 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1259 } elsif (! $filename) {
1260 return 'application/octet-stream';
1261 } elsif ($filename =~ m/\.png$/i) {
1263 } elsif ($filename =~ m/\.gif$/i) {
1265 } elsif ($filename =~ m/\.jpe?g$/i) {
1266 return 'image/jpeg';
1268 return 'application/octet-stream';
1272 ## ======================================================================
1273 ## functions printing HTML: header, footer, error page
1275 sub git_header_html {
1276 my $status = shift || "200 OK";
1277 my $expires = shift;
1279 my $title = "$site_name git";
1280 if (defined $project) {
1281 $title .= " - $project";
1282 if (defined $action) {
1283 $title .= "/$action";
1284 if (defined $file_name) {
1285 $title .= " - $file_name";
1286 if ($action eq "tree" && $file_name !~ m|/$|) {
1293 # require explicit support from the UA if we are to send the page as
1294 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1295 # we have to do this because MSIE sometimes globs '*/*', pretending to
1296 # support xhtml+xml but choking when it gets what it asked for.
1297 if (defined $cgi->http('HTTP_ACCEPT') &&
1298 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&
1299 $cgi->Accept('application/xhtml+xml') != 0) {
1300 $content_type = 'application/xhtml+xml';
1302 $content_type = 'text/html';
1304 print $cgi->header(-type=>$content_type, -charset => 'utf-8',
1305 -status=> $status, -expires => $expires);
1307 <?xml version="1.0" encoding="utf-8"?>
1308 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1309 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1310 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1311 <!-- git core binaries version $git_version -->
1313 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1314 <meta name="generator" content="gitweb/$version git/$git_version"/>
1315 <meta name="robots" content="index, nofollow"/>
1316 <title>$title</title>
1317 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1319 if (defined $project) {
1320 printf('<link rel="alternate" title="%s log" '.
1321 'href="%s" type="application/rss+xml"/>'."\n",
1322 esc_param($project), href(action=>"rss"));
1324 printf('<link rel="alternate" title="%s projects list" '.
1325 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1326 $site_name, href(project=>undef, action=>"project_index"));
1327 printf('<link rel="alternate" title="%s projects logs" '.
1328 'href="%s" type="text/x-opml"/>'."\n",
1329 $site_name, href(project=>undef, action=>"opml"));
1331 if (defined $favicon) {
1332 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1337 "<div class=\"page_header\">\n" .
1338 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1339 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1341 print $cgi->a({-href => esc_param($home_link)}, $home_link_str) . " / ";
1342 if (defined $project) {
1343 print $cgi->a({-href => href(action=>"summary")}, esc_html($project));
1344 if (defined $action) {
1348 if (!defined $searchtext) {
1352 if (defined $hash_base) {
1353 $search_hash = $hash_base;
1354 } elsif (defined $hash) {
1355 $search_hash = $hash;
1357 $search_hash = "HEAD";
1359 $cgi->param("a", "search");
1360 $cgi->param("h", $search_hash);
1361 print $cgi->startform(-method => "get", -action => $my_uri) .
1362 "<div class=\"search\">\n" .
1363 $cgi->hidden(-name => "p") . "\n" .
1364 $cgi->hidden(-name => "a") . "\n" .
1365 $cgi->hidden(-name => "h") . "\n" .
1366 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
1368 $cgi->end_form() . "\n";
1373 sub git_footer_html {
1374 print "<div class=\"page_footer\">\n";
1375 if (defined $project) {
1376 my $descr = git_get_project_description($project);
1377 if (defined $descr) {
1378 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
1380 print $cgi->a({-href => href(action=>"rss"),
1381 -class => "rss_logo"}, "RSS") . "\n";
1383 print $cgi->a({-href => href(project=>undef, action=>"opml"),
1384 -class => "rss_logo"}, "OPML") . " ";
1385 print $cgi->a({-href => href(project=>undef, action=>"project_index"),
1386 -class => "rss_logo"}, "TXT") . "\n";
1394 my $status = shift || "403 Forbidden";
1395 my $error = shift || "Malformed query, file missing or permission denied";
1397 git_header_html($status);
1399 <div class="page_body">
1409 ## ----------------------------------------------------------------------
1410 ## functions printing or outputting HTML: navigation
1412 sub git_print_page_nav {
1413 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1414 $extra = '' if !defined $extra; # pager or formats
1416 my @navs = qw(summary shortlog log commit commitdiff tree);
1418 @navs = grep { $_ ne $suppress } @navs;
1421 my %arg = map { $_ => {action=>$_} } @navs;
1422 if (defined $head) {
1423 for (qw(commit commitdiff)) {
1424 $arg{$_}{hash} = $head;
1426 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1427 for (qw(shortlog log)) {
1428 $arg{$_}{hash} = $head;
1432 $arg{tree}{hash} = $treehead if defined $treehead;
1433 $arg{tree}{hash_base} = $treebase if defined $treebase;
1435 print "<div class=\"page_nav\">\n" .
1437 map { $_ eq $current ?
1438 $_ : $cgi->a({-href => href(%{$arg{$_}})}, "$_")
1440 print "<br/>\n$extra<br/>\n" .
1444 sub format_paging_nav {
1445 my ($action, $hash, $head, $page, $nrevs) = @_;
1449 if ($hash ne $head || $page) {
1450 $paging_nav .= $cgi->a({-href => href(action=>$action)}, "HEAD");
1452 $paging_nav .= "HEAD";
1456 $paging_nav .= " ⋅ " .
1457 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page-1),
1458 -accesskey => "p", -title => "Alt-p"}, "prev");
1460 $paging_nav .= " ⋅ prev";
1463 if ($nrevs >= (100 * ($page+1)-1)) {
1464 $paging_nav .= " ⋅ " .
1465 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page+1),
1466 -accesskey => "n", -title => "Alt-n"}, "next");
1468 $paging_nav .= " ⋅ next";
1474 ## ......................................................................
1475 ## functions printing or outputting HTML: div
1477 sub git_print_header_div {
1478 my ($action, $title, $hash, $hash_base) = @_;
1481 $args{action} = $action;
1482 $args{hash} = $hash if $hash;
1483 $args{hash_base} = $hash_base if $hash_base;
1485 print "<div class=\"header\">\n" .
1486 $cgi->a({-href => href(%args), -class => "title"},
1487 $title ? $title : $action) .
1491 #sub git_print_authorship (\%) {
1492 sub git_print_authorship {
1495 my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
1496 print "<div class=\"author_date\">" .
1497 esc_html($co->{'author_name'}) .
1499 if ($ad{'hour_local'} < 6) {
1500 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1501 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1503 printf(" (%02d:%02d %s)",
1504 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1509 sub git_print_page_path {
1514 if (!defined $name) {
1515 print "<div class=\"page_path\">/</div>\n";
1517 my @dirname = split '/', $name;
1518 my $basename = pop @dirname;
1521 print "<div class=\"page_path\">";
1522 print $cgi->a({-href => href(action=>"tree", hash_base=>$hb),
1523 -title => '/'}, '/');
1525 foreach my $dir (@dirname) {
1526 $fullname .= ($fullname ? '/' : '') . $dir;
1527 print $cgi->a({-href => href(action=>"tree", file_name=>$fullname,
1529 -title => $fullname}, esc_html($dir . '/'));
1532 if (defined $type && $type eq 'blob') {
1533 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,
1535 -title => $name}, esc_html($basename));
1536 } elsif (defined $type && $type eq 'tree') {
1537 print $cgi->a({-href => href(action=>"tree", file_name=>$file_name,
1539 -title => $name}, esc_html($basename . '/'));
1541 print esc_html($basename);
1543 print "<br/></div>\n";
1547 # sub git_print_log (\@;%) {
1548 sub git_print_log ($;%) {
1552 if ($opts{'-remove_title'}) {
1553 # remove title, i.e. first line of log
1556 # remove leading empty lines
1557 while (defined $log->[0] && $log->[0] eq "") {
1564 foreach my $line (@$log) {
1565 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1568 if (! $opts{'-remove_signoff'}) {
1569 print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
1572 # remove signoff lines
1579 # print only one empty line
1580 # do not print empty line after signoff
1582 next if ($empty || $signoff);
1588 print format_log_line_html($line) . "<br/>\n";
1591 if ($opts{'-final_empty_line'}) {
1592 # end with single empty line
1593 print "<br/>\n" unless $empty;
1597 sub git_print_simplified_log {
1599 my $remove_title = shift;
1602 -final_empty_line=> 1,
1603 -remove_title => $remove_title);
1606 # print tree entry (row of git_tree), but without encompassing <tr> element
1607 sub git_print_tree_entry {
1608 my ($t, $basedir, $hash_base, $have_blame) = @_;
1611 $base_key{hash_base} = $hash_base if defined $hash_base;
1613 print "<td class=\"mode\">" . mode_str($t->{'mode'}) . "</td>\n";
1614 if ($t->{'type'} eq "blob") {
1615 print "<td class=\"list\">" .
1616 $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
1617 file_name=>"$basedir$t->{'name'}", %base_key),
1618 -class => "list"}, esc_html($t->{'name'})) .
1620 "<td class=\"link\">" .
1621 $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
1622 file_name=>"$basedir$t->{'name'}", %base_key)},
1626 $cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},
1627 file_name=>"$basedir$t->{'name'}", %base_key)},
1630 if (defined $hash_base) {
1632 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
1633 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},
1637 $cgi->a({-href => href(action=>"blob_plain",
1638 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},
1642 } elsif ($t->{'type'} eq "tree") {
1643 print "<td class=\"list\">" .
1644 $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
1645 file_name=>"$basedir$t->{'name'}", %base_key)},
1646 esc_html($t->{'name'})) .
1648 "<td class=\"link\">" .
1649 $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
1650 file_name=>"$basedir$t->{'name'}", %base_key)},
1652 if (defined $hash_base) {
1654 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
1655 file_name=>"$basedir$t->{'name'}")},
1662 ## ......................................................................
1663 ## functions printing large fragments of HTML
1665 sub git_difftree_body {
1666 my ($difftree, $hash, $parent) = @_;
1668 print "<div class=\"list_head\">\n";
1669 if ($#{$difftree} > 10) {
1670 print(($#{$difftree} + 1) . " files changed:\n");
1674 print "<table class=\"diff_tree\">\n";
1677 foreach my $line (@{$difftree}) {
1678 my %diff = parse_difftree_raw_line($line);
1681 print "<tr class=\"dark\">\n";
1683 print "<tr class=\"light\">\n";
1687 my ($to_mode_oct, $to_mode_str, $to_file_type);
1688 my ($from_mode_oct, $from_mode_str, $from_file_type);
1689 if ($diff{'to_mode'} ne ('0' x 6)) {
1690 $to_mode_oct = oct $diff{'to_mode'};
1691 if (S_ISREG($to_mode_oct)) { # only for regular file
1692 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1694 $to_file_type = file_type($diff{'to_mode'});
1696 if ($diff{'from_mode'} ne ('0' x 6)) {
1697 $from_mode_oct = oct $diff{'from_mode'};
1698 if (S_ISREG($to_mode_oct)) { # only for regular file
1699 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1701 $from_file_type = file_type($diff{'from_mode'});
1704 if ($diff{'status'} eq "A") { # created
1705 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1706 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1707 $mode_chng .= "]</span>";
1709 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1710 hash_base=>$hash, file_name=>$diff{'file'}),
1711 -class => "list"}, esc_html($diff{'file'})) .
1713 "<td>$mode_chng</td>\n" .
1714 "<td class=\"link\">" .
1715 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1716 hash_base=>$hash, file_name=>$diff{'file'})},
1718 if ($action eq 'commitdiff') {
1722 $cgi->a({-href => "#patch$patchno"}, "patch");
1726 } elsif ($diff{'status'} eq "D") { # deleted
1727 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1729 $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
1730 hash_base=>$parent, file_name=>$diff{'file'}),
1731 -class => "list"}, esc_html($diff{'file'})) .
1733 "<td>$mode_chng</td>\n" .
1734 "<td class=\"link\">" .
1735 $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
1736 hash_base=>$parent, file_name=>$diff{'file'})},
1739 if ($action eq 'commitdiff') {
1743 $cgi->a({-href => "#patch$patchno"}, "patch");
1745 print $cgi->a({-href => href(action=>"history", hash_base=>$parent,
1746 file_name=>$diff{'file'})},
1750 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1751 my $mode_chnge = "";
1752 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1753 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1754 if ($from_file_type != $to_file_type) {
1755 $mode_chnge .= " from $from_file_type to $to_file_type";
1757 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1758 if ($from_mode_str && $to_mode_str) {
1759 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1760 } elsif ($to_mode_str) {
1761 $mode_chnge .= " mode: $to_mode_str";
1764 $mode_chnge .= "]</span>\n";
1767 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1768 print $cgi->a({-href => href(action=>"blobdiff",
1769 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1770 hash_base=>$hash, hash_parent_base=>$parent,
1771 file_name=>$diff{'file'}),
1772 -class => "list"}, esc_html($diff{'file'}));
1773 } else { # only mode changed
1774 print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1775 hash_base=>$hash, file_name=>$diff{'file'}),
1776 -class => "list"}, esc_html($diff{'file'}));
1779 "<td>$mode_chnge</td>\n" .
1780 "<td class=\"link\">" .
1781 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1782 hash_base=>$hash, file_name=>$diff{'file'})},
1784 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1785 if ($action eq 'commitdiff') {
1789 $cgi->a({-href => "#patch$patchno"}, "patch");
1792 $cgi->a({-href => href(action=>"blobdiff",
1793 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1794 hash_base=>$hash, hash_parent_base=>$parent,
1795 file_name=>$diff{'file'})},
1800 $cgi->a({-href => href(action=>"history",
1801 hash_base=>$hash, file_name=>$diff{'file'})},
1805 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1806 my %status_name = ('R' => 'moved', 'C' => 'copied');
1807 my $nstatus = $status_name{$diff{'status'}};
1809 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1810 # mode also for directories, so we cannot use $to_mode_str
1811 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1814 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1815 hash=>$diff{'to_id'}, file_name=>$diff{'to_file'}),
1816 -class => "list"}, esc_html($diff{'to_file'})) . "</td>\n" .
1817 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1818 $cgi->a({-href => href(action=>"blob", hash_base=>$parent,
1819 hash=>$diff{'from_id'}, file_name=>$diff{'from_file'}),
1820 -class => "list"}, esc_html($diff{'from_file'})) .
1821 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1822 "<td class=\"link\">" .
1823 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1824 hash=>$diff{'to_id'}, file_name=>$diff{'to_file'})},
1826 if ($diff{'to_id'} ne $diff{'from_id'}) {
1827 if ($action eq 'commitdiff') {
1831 $cgi->a({-href => "#patch$patchno"}, "patch");
1834 $cgi->a({-href => href(action=>"blobdiff",
1835 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1836 hash_base=>$hash, hash_parent_base=>$parent,
1837 file_name=>$diff{'to_file'}, file_parent=>$diff{'from_file'})},
1843 } # we should not encounter Unmerged (U) or Unknown (X) status
1849 sub git_patchset_body {
1850 my ($fd, $difftree, $hash, $hash_parent) = @_;
1854 my $patch_found = 0;
1857 print "<div class=\"patchset\">\n";
1860 while (my $patch_line = <$fd>) {
1863 if ($patch_line =~ m/^diff /) { # "git diff" header
1864 # beginning of patch (in patchset)
1866 # close previous patch
1867 print "</div>\n"; # class="patch"
1869 # first patch in patchset
1872 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1874 if (ref($difftree->[$patch_idx]) eq "HASH") {
1875 $diffinfo = $difftree->[$patch_idx];
1877 $diffinfo = parse_difftree_raw_line($difftree->[$patch_idx]);
1881 # for now, no extended header, hence we skip empty patches
1882 # companion to next LINE if $in_header;
1883 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1888 if ($diffinfo->{'status'} eq "A") { # added
1889 print "<div class=\"diff_info\">" . file_type($diffinfo->{'to_mode'}) . ":" .
1890 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1891 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'file'})},
1892 $diffinfo->{'to_id'}) . "(new)" .
1893 "</div>\n"; # class="diff_info"
1895 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1896 print "<div class=\"diff_info\">" . file_type($diffinfo->{'from_mode'}) . ":" .
1897 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1898 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'file'})},
1899 $diffinfo->{'from_id'}) . "(deleted)" .
1900 "</div>\n"; # class="diff_info"
1902 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1903 $diffinfo->{'status'} eq "C" || # copied
1904 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1905 print "<div class=\"diff_info\">" .
1906 file_type($diffinfo->{'from_mode'}) . ":" .
1907 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1908 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'from_file'})},
1909 $diffinfo->{'from_id'}) .
1911 file_type($diffinfo->{'to_mode'}) . ":" .
1912 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1913 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'to_file'})},
1914 $diffinfo->{'to_id'});
1915 print "</div>\n"; # class="diff_info"
1917 } else { # modified, mode changed, ...
1918 print "<div class=\"diff_info\">" .
1919 file_type($diffinfo->{'from_mode'}) . ":" .
1920 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1921 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'file'})},
1922 $diffinfo->{'from_id'}) .
1924 file_type($diffinfo->{'to_mode'}) . ":" .
1925 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1926 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'file'})},
1927 $diffinfo->{'to_id'});
1928 print "</div>\n"; # class="diff_info"
1931 #print "<div class=\"diff extended_header\">\n";
1934 } # start of patch in patchset
1937 if ($in_header && $patch_line =~ m/^---/) {
1938 #print "</div>\n"; # class="diff extended_header"
1941 my $file = $diffinfo->{'from_file'};
1942 $file ||= $diffinfo->{'file'};
1943 $file = $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1944 hash=>$diffinfo->{'from_id'}, file_name=>$file),
1945 -class => "list"}, esc_html($file));
1946 $patch_line =~ s|a/.*$|a/$file|g;
1947 print "<div class=\"diff from_file\">$patch_line</div>\n";
1949 $patch_line = <$fd>;
1952 #$patch_line =~ m/^+++/;
1953 $file = $diffinfo->{'to_file'};
1954 $file ||= $diffinfo->{'file'};
1955 $file = $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1956 hash=>$diffinfo->{'to_id'}, file_name=>$file),
1957 -class => "list"}, esc_html($file));
1958 $patch_line =~ s|b/.*|b/$file|g;
1959 print "<div class=\"diff to_file\">$patch_line</div>\n";
1963 next LINE if $in_header;
1965 print format_diff_line($patch_line);
1967 print "</div>\n" if $patch_found; # class="patch"
1969 print "</div>\n"; # class="patchset"
1972 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1974 sub git_shortlog_body {
1975 # uses global variable $project
1976 my ($revlist, $from, $to, $refs, $extra) = @_;
1978 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
1979 my $have_snapshot = (defined $ctype && defined $suffix);
1981 $from = 0 unless defined $from;
1982 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1984 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1986 for (my $i = $from; $i <= $to; $i++) {
1987 my $commit = $revlist->[$i];
1988 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1989 my $ref = format_ref_marker($refs, $commit);
1990 my %co = parse_commit($commit);
1992 print "<tr class=\"dark\">\n";
1994 print "<tr class=\"light\">\n";
1997 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1998 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1999 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
2001 print format_subject_html($co{'title'}, $co{'title_short'},
2002 href(action=>"commit", hash=>$commit), $ref);
2004 "<td class=\"link\">" .
2005 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
2006 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff");
2007 if ($have_snapshot) {
2008 print " | " . $cgi->a({-href => href(action=>"snapshot", hash=>$commit)}, "snapshot");
2013 if (defined $extra) {
2015 "<td colspan=\"4\">$extra</td>\n" .
2021 sub git_history_body {
2022 # Warning: assumes constant type (blob or tree) during history
2023 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2025 $from = 0 unless defined $from;
2026 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2028 print "<table class=\"history\" cellspacing=\"0\">\n";
2030 for (my $i = $from; $i <= $to; $i++) {
2031 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2036 my %co = parse_commit($commit);
2041 my $ref = format_ref_marker($refs, $commit);
2044 print "<tr class=\"dark\">\n";
2046 print "<tr class=\"light\">\n";
2049 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2050 # shortlog uses chop_str($co{'author_name'}, 10)
2051 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2053 # originally git_history used chop_str($co{'title'}, 50)
2054 print format_subject_html($co{'title'}, $co{'title_short'},
2055 href(action=>"commit", hash=>$commit), $ref);
2057 "<td class=\"link\">" .
2058 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
2059 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
2060 $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype);
2062 if ($ftype eq 'blob') {
2063 my $blob_current = git_get_hash_by_path($hash_base, $file_name);
2064 my $blob_parent = git_get_hash_by_path($commit, $file_name);
2065 if (defined $blob_current && defined $blob_parent &&
2066 $blob_current ne $blob_parent) {
2068 $cgi->a({-href => href(action=>"blobdiff",
2069 hash=>$blob_current, hash_parent=>$blob_parent,
2070 hash_base=>$hash_base, hash_parent_base=>$commit,
2071 file_name=>$file_name)},
2078 if (defined $extra) {
2080 "<td colspan=\"4\">$extra</td>\n" .
2087 # uses global variable $project
2088 my ($taglist, $from, $to, $extra) = @_;
2089 $from = 0 unless defined $from;
2090 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2092 print "<table class=\"tags\" cellspacing=\"0\">\n";
2094 for (my $i = $from; $i <= $to; $i++) {
2095 my $entry = $taglist->[$i];
2097 my $comment_lines = $tag{'comment'};
2098 my $comment = shift @$comment_lines;
2100 if (defined $comment) {
2101 $comment_short = chop_str($comment, 30, 5);
2104 print "<tr class=\"dark\">\n";
2106 print "<tr class=\"light\">\n";
2109 print "<td><i>$tag{'age'}</i></td>\n" .
2111 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),
2112 -class => "list name"}, esc_html($tag{'name'})) .
2115 if (defined $comment) {
2116 print format_subject_html($comment, $comment_short,
2117 href(action=>"tag", hash=>$tag{'id'}));
2120 "<td class=\"selflink\">";
2121 if ($tag{'type'} eq "tag") {
2122 print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag");
2127 "<td class=\"link\">" . " | " .
2128 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'});
2129 if ($tag{'reftype'} eq "commit") {
2130 print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") .
2131 " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'refid'})}, "log");
2132 } elsif ($tag{'reftype'} eq "blob") {
2133 print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw");
2138 if (defined $extra) {
2140 "<td colspan=\"5\">$extra</td>\n" .
2146 sub git_heads_body {
2147 # uses global variable $project
2148 my ($headlist, $head, $from, $to, $extra) = @_;
2149 $from = 0 unless defined $from;
2150 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2152 print "<table class=\"heads\" cellspacing=\"0\">\n";
2154 for (my $i = $from; $i <= $to; $i++) {
2155 my $entry = $headlist->[$i];
2157 my $curr = $tag{'id'} eq $head;
2159 print "<tr class=\"dark\">\n";
2161 print "<tr class=\"light\">\n";
2164 print "<td><i>$tag{'age'}</i></td>\n" .
2165 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
2166 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'}),
2167 -class => "list name"},esc_html($tag{'name'})) .
2169 "<td class=\"link\">" .
2170 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") . " | " .
2171 $cgi->a({-href => href(action=>"log", hash=>$tag{'name'})}, "log") .
2175 if (defined $extra) {
2177 "<td colspan=\"3\">$extra</td>\n" .
2183 ## ======================================================================
2184 ## ======================================================================
2187 sub git_project_list {
2188 my $order = $cgi->param('o');
2189 if (defined $order && $order !~ m/project|descr|owner|age/) {
2190 die_error(undef, "Unknown order parameter");
2193 my @list = git_get_projects_list();
2196 die_error(undef, "No projects found");
2198 foreach my $pr (@list) {
2199 my $head = git_get_head_hash($pr->{'path'});
2200 if (!defined $head) {
2203 $git_dir = "$projectroot/$pr->{'path'}";
2204 my %co = parse_commit($head);
2208 $pr->{'commit'} = \%co;
2209 if (!defined $pr->{'descr'}) {
2210 my $descr = git_get_project_description($pr->{'path'}) || "";
2211 $pr->{'descr'} = chop_str($descr, 25, 5);
2213 if (!defined $pr->{'owner'}) {
2214 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
2216 push @projects, $pr;
2220 if (-f $home_text) {
2221 print "<div class=\"index_include\">\n";
2222 open (my $fd, $home_text);
2227 print "<table class=\"project_list\">\n" .
2229 $order ||= "project";
2230 if ($order eq "project") {
2231 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2232 print "<th>Project</th>\n";
2235 $cgi->a({-href => href(project=>undef, order=>'project'),
2236 -class => "header"}, "Project") .
2239 if ($order eq "descr") {
2240 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2241 print "<th>Description</th>\n";
2244 $cgi->a({-href => href(project=>undef, order=>'descr'),
2245 -class => "header"}, "Description") .
2248 if ($order eq "owner") {
2249 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2250 print "<th>Owner</th>\n";
2253 $cgi->a({-href => href(project=>undef, order=>'owner'),
2254 -class => "header"}, "Owner") .
2257 if ($order eq "age") {
2258 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2259 print "<th>Last Change</th>\n";
2262 $cgi->a({-href => href(project=>undef, order=>'age'),
2263 -class => "header"}, "Last Change") .
2266 print "<th></th>\n" .
2269 foreach my $pr (@projects) {
2271 print "<tr class=\"dark\">\n";
2273 print "<tr class=\"light\">\n";
2276 print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
2277 -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
2278 "<td>" . esc_html($pr->{'descr'}) . "</td>\n" .
2279 "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
2280 print "<td class=\"". age_class($pr->{'commit'}{'age'}) . "\">" .
2281 $pr->{'commit'}{'age_string'} . "</td>\n" .
2282 "<td class=\"link\">" .
2283 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
2284 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
2285 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") .
2293 sub git_project_index {
2294 my @projects = git_get_projects_list();
2297 -type => 'text/plain',
2298 -charset => 'utf-8',
2299 -content_disposition => qq(inline; filename="index.aux"));
2301 foreach my $pr (@projects) {
2302 if (!exists $pr->{'owner'}) {
2303 $pr->{'owner'} = get_file_owner("$projectroot/$project");
2306 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2307 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2308 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
2309 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
2313 print "$path $owner\n";
2318 my $descr = git_get_project_description($project) || "none";
2319 my $head = git_get_head_hash($project);
2320 my %co = parse_commit($head);
2321 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
2323 my $owner = git_get_project_owner($project);
2325 my ($reflist, $refs) = git_get_refs_list();
2329 foreach my $ref (@$reflist) {
2330 if ($ref->{'name'} =~ s!^heads/!!) {
2331 push @headlist, $ref;
2333 $ref->{'name'} =~ s!^tags/!!;
2334 push @taglist, $ref;
2339 git_print_page_nav('summary','', $head);
2341 print "<div class=\"title\"> </div>\n";
2342 print "<table cellspacing=\"0\">\n" .
2343 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
2344 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2345 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2346 # use per project git URL list in $projectroot/$project/cloneurl
2347 # or make project git URL from git base URL and project name
2348 my $url_tag = "URL";
2349 my @url_list = git_get_project_url_list($project);
2350 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2351 foreach my $git_url (@url_list) {
2352 next unless $git_url;
2353 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2358 open my $fd, "-|", git_cmd(), "rev-list", "--max-count=17",
2359 git_get_head_hash($project)
2360 or die_error(undef, "Open git-rev-list failed");
2361 my @revlist = map { chomp; $_ } <$fd>;
2363 git_print_header_div('shortlog');
2364 git_shortlog_body(\@revlist, 0, 15, $refs,
2365 $cgi->a({-href => href(action=>"shortlog")}, "..."));
2368 git_print_header_div('tags');
2369 git_tags_body(\@taglist, 0, 15,
2370 $cgi->a({-href => href(action=>"tags")}, "..."));
2374 git_print_header_div('heads');
2375 git_heads_body(\@headlist, $head, 0, 15,
2376 $cgi->a({-href => href(action=>"heads")}, "..."));
2383 my $head = git_get_head_hash($project);
2385 git_print_page_nav('','', $head,undef,$head);
2386 my %tag = parse_tag($hash);
2387 git_print_header_div('commit', esc_html($tag{'name'}), $hash);
2388 print "<div class=\"title_text\">\n" .
2389 "<table cellspacing=\"0\">\n" .
2391 "<td>object</td>\n" .
2392 "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
2393 $tag{'object'}) . "</td>\n" .
2394 "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
2395 $tag{'type'}) . "</td>\n" .
2397 if (defined($tag{'author'})) {
2398 my %ad = parse_date($tag{'epoch'}, $tag{'tz'});
2399 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
2400 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2401 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2404 print "</table>\n\n" .
2406 print "<div class=\"page_body\">";
2407 my $comment = $tag{'comment'};
2408 foreach my $line (@$comment) {
2409 print esc_html($line) . "<br/>\n";
2419 my ($have_blame) = gitweb_check_feature('blame');
2421 die_error('403 Permission denied', "Permission denied");
2423 die_error('404 Not Found', "File name not defined") if (!$file_name);
2424 $hash_base ||= git_get_head_hash($project);
2425 die_error(undef, "Couldn't find base commit") unless ($hash_base);
2426 my %co = parse_commit($hash_base)
2427 or die_error(undef, "Reading commit failed");
2428 if (!defined $hash) {
2429 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
2430 or die_error(undef, "Error looking up file");
2432 $ftype = git_get_type($hash);
2433 if ($ftype !~ "blob") {
2434 die_error("400 Bad Request", "Object is not a blob");
2436 open ($fd, "-|", git_cmd(), "blame", '-l', $file_name, $hash_base)
2437 or die_error(undef, "Open git-blame failed");
2440 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2443 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
2445 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2446 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2447 git_print_page_path($file_name, $ftype, $hash_base);
2448 my @rev_color = (qw(light2 dark2));
2449 my $num_colors = scalar(@rev_color);
2450 my $current_color = 0;
2453 <div class="page_body">
2454 <table class="blame">
2455 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2458 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2460 my $rev = substr($full_rev, 0, 8);
2464 if (!defined $last_rev) {
2465 $last_rev = $full_rev;
2466 } elsif ($last_rev ne $full_rev) {
2467 $last_rev = $full_rev;
2468 $current_color = ++$current_color % $num_colors;
2470 print "<tr class=\"$rev_color[$current_color]\">\n";
2471 print "<td class=\"sha1\">" .
2472 $cgi->a({-href => href(action=>"commit", hash=>$full_rev, file_name=>$file_name)},
2473 esc_html($rev)) . "</td>\n";
2474 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2475 esc_html($lineno) . "</a></td>\n";
2476 print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
2482 or print "Reading blob failed\n";
2489 my ($have_blame) = gitweb_check_feature('blame');
2491 die_error('403 Permission denied', "Permission denied");
2493 die_error('404 Not Found', "File name not defined") if (!$file_name);
2494 $hash_base ||= git_get_head_hash($project);
2495 die_error(undef, "Couldn't find base commit") unless ($hash_base);
2496 my %co = parse_commit($hash_base)
2497 or die_error(undef, "Reading commit failed");
2498 if (!defined $hash) {
2499 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
2500 or die_error(undef, "Error lookup file");
2502 open ($fd, "-|", git_cmd(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2503 or die_error(undef, "Open git-annotate failed");
2506 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2509 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
2511 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2512 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2513 git_print_page_path($file_name, 'blob', $hash_base);
2514 print "<div class=\"page_body\">\n";
2516 <table class="blame">
2525 my @line_class = (qw(light dark));
2526 my $line_class_len = scalar (@line_class);
2527 my $line_class_num = $#line_class;
2528 while (my $line = <$fd>) {
2540 $line_class_num = ($line_class_num + 1) % $line_class_len;
2542 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2549 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
2552 $short_rev = substr ($long_rev, 0, 8);
2553 $age = time () - $time;
2554 $age_str = age_string ($age);
2555 $age_str =~ s/ / /g;
2556 $age_class = age_class($age);
2557 $author = esc_html ($author);
2558 $author =~ s/ / /g;
2560 $data = untabify($data);
2561 $data = esc_html ($data);
2564 <tr class="$line_class[$line_class_num]">
2565 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2566 <td class="$age_class">$age_str</td>
2568 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2569 <td class="pre">$data</td>
2572 } # while (my $line = <$fd>)
2573 print "</table>\n\n";
2575 or print "Reading blob failed.\n";
2581 my $head = git_get_head_hash($project);
2583 git_print_page_nav('','', $head,undef,$head);
2584 git_print_header_div('summary', $project);
2586 my ($taglist) = git_get_refs_list("tags");
2588 git_tags_body($taglist);
2594 my $head = git_get_head_hash($project);
2596 git_print_page_nav('','', $head,undef,$head);
2597 git_print_header_div('summary', $project);
2599 my ($headlist) = git_get_refs_list("heads");
2601 git_heads_body($headlist, $head);
2606 sub git_blob_plain {
2609 if (!defined $hash) {
2610 if (defined $file_name) {
2611 my $base = $hash_base || git_get_head_hash($project);
2612 $hash = git_get_hash_by_path($base, $file_name, "blob")
2613 or die_error(undef, "Error lookup file");
2615 die_error(undef, "No file name defined");
2617 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2618 # blobs defined by non-textual hash id's can be cached
2623 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
2624 or die_error(undef, "Couldn't cat $file_name, $hash");
2626 $type ||= blob_mimetype($fd, $file_name);
2628 # save as filename, even when no $file_name is given
2629 my $save_as = "$hash";
2630 if (defined $file_name) {
2631 $save_as = $file_name;
2632 } elsif ($type =~ m/^text\//) {
2639 -content_disposition => "inline; filename=\"$save_as\"");
2641 binmode STDOUT, ':raw';
2643 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
2651 if (!defined $hash) {
2652 if (defined $file_name) {
2653 my $base = $hash_base || git_get_head_hash($project);
2654 $hash = git_get_hash_by_path($base, $file_name, "blob")
2655 or die_error(undef, "Error lookup file");
2657 die_error(undef, "No file name defined");
2659 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2660 # blobs defined by non-textual hash id's can be cached
2664 my ($have_blame) = gitweb_check_feature('blame');
2665 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
2666 or die_error(undef, "Couldn't cat $file_name, $hash");
2667 my $mimetype = blob_mimetype($fd, $file_name);
2668 if ($mimetype !~ m/^text\//) {
2670 return git_blob_plain($mimetype);
2672 git_header_html(undef, $expires);
2673 my $formats_nav = '';
2674 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2675 if (defined $file_name) {
2678 $cgi->a({-href => href(action=>"blame", hash_base=>$hash_base,
2679 hash=>$hash, file_name=>$file_name)},
2684 $cgi->a({-href => href(action=>"blob_plain",
2685 hash=>$hash, file_name=>$file_name)},
2688 $cgi->a({-href => href(action=>"blob",
2689 hash_base=>"HEAD", file_name=>$file_name)},
2693 $cgi->a({-href => href(action=>"blob_plain", hash=>$hash)}, "plain");
2695 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2696 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2698 print "<div class=\"page_nav\">\n" .
2699 "<br/><br/></div>\n" .
2700 "<div class=\"title\">$hash</div>\n";
2702 git_print_page_path($file_name, "blob", $hash_base);
2703 print "<div class=\"page_body\">\n";
2705 while (my $line = <$fd>) {
2708 $line = untabify($line);
2709 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2710 $nr, $nr, $nr, esc_html($line);
2713 or print "Reading blob failed.\n";
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))) {
2742 git_print_page_nav('tree','', $hash_base);
2743 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
2746 print "<div class=\"page_nav\">\n";
2747 print "<br/><br/></div>\n";
2748 print "<div class=\"title\">$hash</div>\n";
2750 if (defined $file_name) {
2751 $base = esc_html("$file_name/");
2753 git_print_page_path($file_name, 'tree', $hash_base);
2754 print "<div class=\"page_body\">\n";
2755 print "<table cellspacing=\"0\">\n";
2757 foreach my $line (@entries) {
2758 my %t = parse_ls_tree_line($line, -z => 1);
2761 print "<tr class=\"dark\">\n";
2763 print "<tr class=\"light\">\n";
2767 git_print_tree_entry(\%t, $base, $hash_base, $have_blame);
2771 print "</table>\n" .
2778 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
2779 my $have_snapshot = (defined $ctype && defined $suffix);
2780 if (!$have_snapshot) {
2781 die_error('403 Permission denied', "Permission denied");
2784 if (!defined $hash) {
2785 $hash = git_get_head_hash($project);
2788 my $filename = basename($project) . "-$hash.tar.$suffix";
2790 print $cgi->header(-type => 'application/x-tar',
2791 -content_encoding => $ctype,
2792 -content_disposition => "inline; filename=\"$filename\"",
2793 -status => '200 OK');
2795 my $git_command = git_cmd_str();
2796 open my $fd, "-|", "$git_command tar-tree $hash \'$project\' | $command" or
2797 die_error(undef, "Execute git-tar-tree failed.");
2798 binmode STDOUT, ':raw';
2800 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
2806 my $head = git_get_head_hash($project);
2807 if (!defined $hash) {
2810 if (!defined $page) {
2813 my $refs = git_get_references();
2815 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2816 open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash
2817 or die_error(undef, "Open git-rev-list failed");
2818 my @revlist = map { chomp; $_ } <$fd>;
2821 my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#revlist);
2824 git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
2827 my %co = parse_commit($hash);
2829 git_print_header_div('summary', $project);
2830 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2832 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2833 my $commit = $revlist[$i];
2834 my $ref = format_ref_marker($refs, $commit);
2835 my %co = parse_commit($commit);
2837 my %ad = parse_date($co{'author_epoch'});
2838 git_print_header_div('commit',
2839 "<span class=\"age\">$co{'age_string'}</span>" .
2840 esc_html($co{'title'}) . $ref,
2842 print "<div class=\"title_text\">\n" .
2843 "<div class=\"log_link\">\n" .
2844 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
2846 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
2849 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2852 print "<div class=\"log_body\">\n";
2853 git_print_simplified_log($co{'comment'});
2860 my %co = parse_commit($hash);
2862 die_error(undef, "Unknown commit object");
2864 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
2865 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
2867 my $parent = $co{'parent'};
2868 if (!defined $parent) {
2871 open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $parent, $hash
2872 or die_error(undef, "Open git-diff-tree failed");
2873 my @difftree = map { chomp; $_ } <$fd>;
2874 close $fd or die_error(undef, "Reading git-diff-tree failed");
2876 # non-textual hash id's can be cached
2878 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2881 my $refs = git_get_references();
2882 my $ref = format_ref_marker($refs, $co{'id'});
2884 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
2885 my $have_snapshot = (defined $ctype && defined $suffix);
2887 my $formats_nav = '';
2888 if (defined $file_name && defined $co{'parent'}) {
2889 my $parent = $co{'parent'};
2891 $cgi->a({-href => href(action=>"blame", hash_parent=>$parent, file_name=>$file_name)},
2894 git_header_html(undef, $expires);
2895 git_print_page_nav('commit', defined $co{'parent'} ? '' : 'commitdiff',
2896 $hash, $co{'tree'}, $hash,
2899 if (defined $co{'parent'}) {
2900 git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash);
2902 git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash);
2904 print "<div class=\"title_text\">\n" .
2905 "<table cellspacing=\"0\">\n";
2906 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
2908 "<td></td><td> $ad{'rfc2822'}";
2909 if ($ad{'hour_local'} < 6) {
2910 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2911 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2913 printf(" (%02d:%02d %s)",
2914 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2918 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
2919 print "<tr><td></td><td> $cd{'rfc2822'}" .
2920 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2922 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2925 "<td class=\"sha1\">" .
2926 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),
2927 class => "list"}, $co{'tree'}) .
2929 "<td class=\"link\">" .
2930 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},
2932 if ($have_snapshot) {
2934 $cgi->a({-href => href(action=>"snapshot", hash=>$hash)}, "snapshot");
2938 my $parents = $co{'parents'};
2939 foreach my $par (@$parents) {
2942 "<td class=\"sha1\">" .
2943 $cgi->a({-href => href(action=>"commit", hash=>$par),
2944 class => "list"}, $par) .
2946 "<td class=\"link\">" .
2947 $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") .
2949 $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "diff") .
2956 print "<div class=\"page_body\">\n";
2957 git_print_log($co{'comment'});
2960 git_difftree_body(\@difftree, $hash, $parent);
2966 my $format = shift || 'html';
2973 # preparing $fd and %diffinfo for git_patchset_body
2975 if (defined $hash_base && defined $hash_parent_base) {
2976 if (defined $file_name) {
2978 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
2980 or die_error(undef, "Open git-diff-tree failed");
2981 @difftree = map { chomp; $_ } <$fd>;
2983 or die_error(undef, "Reading git-diff-tree failed");
2985 or die_error('404 Not Found', "Blob diff not found");
2987 } elsif (defined $hash &&
2988 $hash =~ /[0-9a-fA-F]{40}/) {
2989 # try to find filename from $hash
2991 # read filtered raw output
2992 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
2993 or die_error(undef, "Open git-diff-tree failed");
2995 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
2997 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
2998 map { chomp; $_ } <$fd>;
3000 or die_error(undef, "Reading git-diff-tree failed");
3002 or die_error('404 Not Found', "Blob diff not found");
3005 die_error('404 Not Found', "Missing one of the blob diff parameters");
3008 if (@difftree > 1) {
3009 die_error('404 Not Found', "Ambiguous blob diff specification");
3012 %diffinfo = parse_difftree_raw_line($difftree[0]);
3013 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3014 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3016 $hash_parent ||= $diffinfo{'from_id'};
3017 $hash ||= $diffinfo{'to_id'};
3019 # non-textual hash id's can be cached
3020 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3021 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3026 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
3027 '-p', $hash_parent_base, $hash_base,
3029 or die_error(undef, "Open git-diff-tree failed");
3032 # old/legacy style URI
3033 if (!%diffinfo && # if new style URI failed
3034 defined $hash && defined $hash_parent) {
3035 # fake git-diff-tree raw output
3036 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3037 $diffinfo{'from_id'} = $hash_parent;
3038 $diffinfo{'to_id'} = $hash;
3039 if (defined $file_name) {
3040 if (defined $file_parent) {
3041 $diffinfo{'status'} = '2';
3042 $diffinfo{'from_file'} = $file_parent;
3043 $diffinfo{'to_file'} = $file_name;
3044 } else { # assume not renamed
3045 $diffinfo{'status'} = '1';
3046 $diffinfo{'from_file'} = $file_name;
3047 $diffinfo{'to_file'} = $file_name;
3049 } else { # no filename given
3050 $diffinfo{'status'} = '2';
3051 $diffinfo{'from_file'} = $hash_parent;
3052 $diffinfo{'to_file'} = $hash;
3055 # non-textual hash id's can be cached
3056 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3057 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3062 open $fd, "-|", git_cmd(), "diff", '-p', @diff_opts, $hash_parent, $hash
3063 or die_error(undef, "Open git-diff failed");
3065 die_error('404 Not Found', "Missing one of the blob diff parameters")
3070 if ($format eq 'html') {
3072 $cgi->a({-href => href(action=>"blobdiff_plain",
3073 hash=>$hash, hash_parent=>$hash_parent,
3074 hash_base=>$hash_base, hash_parent_base=>$hash_parent_base,
3075 file_name=>$file_name, file_parent=>$file_parent)},
3077 git_header_html(undef, $expires);
3078 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
3079 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3080 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
3082 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3083 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3085 if (defined $file_name) {
3086 git_print_page_path($file_name, "blob", $hash_base);
3088 print "<div class=\"page_path\"></div>\n";
3091 } elsif ($format eq 'plain') {
3093 -type => 'text/plain',
3094 -charset => 'utf-8',
3095 -expires => $expires,
3096 -content_disposition => qq(inline; filename="${file_name}.patch"));
3098 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3101 die_error(undef, "Unknown blobdiff format");
3105 if ($format eq 'html') {
3106 print "<div class=\"page_body\">\n";
3108 git_patchset_body($fd, [ \%diffinfo ], $hash_base, $hash_parent_base);
3111 print "</div>\n"; # class="page_body"
3115 while (my $line = <$fd>) {
3116 $line =~ s!a/($hash|$hash_parent)!a/$diffinfo{'from_file'}!g;
3117 $line =~ s!b/($hash|$hash_parent)!b/$diffinfo{'to_file'}!g;
3121 last if $line =~ m!^\+\+\+!;
3129 sub git_blobdiff_plain {
3130 git_blobdiff('plain');
3133 sub git_commitdiff {
3134 my $format = shift || 'html';
3135 my %co = parse_commit($hash);
3137 die_error(undef, "Unknown commit object");
3139 if (!defined $hash_parent) {
3140 $hash_parent = $co{'parent'} || '--root';
3146 if ($format eq 'html') {
3147 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
3148 "--patch-with-raw", "--full-index", $hash_parent, $hash
3149 or die_error(undef, "Open git-diff-tree failed");
3151 while (chomp(my $line = <$fd>)) {
3152 # empty line ends raw part of diff-tree output
3154 push @difftree, $line;
3157 } elsif ($format eq 'plain') {
3158 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
3159 '-p', $hash_parent, $hash
3160 or die_error(undef, "Open git-diff-tree failed");
3163 die_error(undef, "Unknown commitdiff format");
3166 # non-textual hash id's can be cached
3168 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3172 # write commit message
3173 if ($format eq 'html') {
3174 my $refs = git_get_references();
3175 my $ref = format_ref_marker($refs, $co{'id'});
3177 $cgi->a({-href => href(action=>"commitdiff_plain",
3178 hash=>$hash, hash_parent=>$hash_parent)},
3181 git_header_html(undef, $expires);
3182 git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3183 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
3184 git_print_authorship(\%co);
3185 print "<div class=\"page_body\">\n";
3186 print "<div class=\"log\">\n";
3187 git_print_simplified_log($co{'comment'}, 1); # skip title
3188 print "</div>\n"; # class="log"
3190 } elsif ($format eq 'plain') {
3191 my $refs = git_get_references("tags");
3192 my $tagname = git_get_rev_name_tags($hash);
3193 my $filename = basename($project) . "-$hash.patch";
3196 -type => 'text/plain',
3197 -charset => 'utf-8',
3198 -expires => $expires,
3199 -content_disposition => qq(inline; filename="$filename"));
3200 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
3203 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3204 Subject: $co{'title'}
3206 print "X-Git-Tag: $tagname\n" if $tagname;
3207 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3209 foreach my $line (@{$co{'comment'}}) {
3216 if ($format eq 'html') {
3217 git_difftree_body(\@difftree, $hash, $hash_parent);
3220 git_patchset_body($fd, \@difftree, $hash, $hash_parent);
3222 print "</div>\n"; # class="page_body"
3225 } elsif ($format eq 'plain') {
3229 or print "Reading git-diff-tree failed\n";
3233 sub git_commitdiff_plain {
3234 git_commitdiff('plain');
3238 if (!defined $hash_base) {
3239 $hash_base = git_get_head_hash($project);
3241 if (!defined $page) {
3245 my %co = parse_commit($hash_base);
3247 die_error(undef, "Unknown commit object");
3250 my $refs = git_get_references();
3251 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3253 if (!defined $hash && defined $file_name) {
3254 $hash = git_get_hash_by_path($hash_base, $file_name);
3256 if (defined $hash) {
3257 $ftype = git_get_type($hash);
3261 git_cmd(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3262 or die_error(undef, "Open git-rev-list-failed");
3263 my @revlist = map { chomp; $_ } <$fd>;
3265 or die_error(undef, "Reading git-rev-list failed");
3267 my $paging_nav = '';
3270 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3271 file_name=>$file_name)},
3273 $paging_nav .= " ⋅ " .
3274 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3275 file_name=>$file_name, page=>$page-1),
3276 -accesskey => "p", -title => "Alt-p"}, "prev");
3278 $paging_nav .= "first";
3279 $paging_nav .= " ⋅ prev";
3281 if ($#revlist >= (100 * ($page+1)-1)) {
3282 $paging_nav .= " ⋅ " .
3283 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3284 file_name=>$file_name, page=>$page+1),
3285 -accesskey => "n", -title => "Alt-n"}, "next");
3287 $paging_nav .= " ⋅ next";
3290 if ($#revlist >= (100 * ($page+1)-1)) {
3292 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3293 file_name=>$file_name, page=>$page+1),
3294 -title => "Alt-n"}, "next");
3298 git_print_page_nav('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3299 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
3300 git_print_page_path($file_name, $ftype, $hash_base);
3302 git_history_body(\@revlist, ($page * 100), $#revlist,
3303 $refs, $hash_base, $ftype, $next_link);
3309 if (!defined $searchtext) {
3310 die_error(undef, "Text field empty");
3312 if (!defined $hash) {
3313 $hash = git_get_head_hash($project);
3315 my %co = parse_commit($hash);
3317 die_error(undef, "Unknown commit object");
3320 my $commit_search = 1;
3321 my $author_search = 0;
3322 my $committer_search = 0;
3323 my $pickaxe_search = 0;
3324 if ($searchtext =~ s/^author\\://i) {
3326 } elsif ($searchtext =~ s/^committer\\://i) {
3327 $committer_search = 1;
3328 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3330 $pickaxe_search = 1;
3332 # pickaxe may take all resources of your box and run for several minutes
3333 # with every query - so decide by yourself how public you make this feature
3334 my ($have_pickaxe) = gitweb_check_feature('pickaxe');
3335 if (!$have_pickaxe) {
3336 die_error('403 Permission denied', "Permission denied");
3340 git_print_page_nav('','', $hash,$co{'tree'},$hash);
3341 git_print_header_div('commit', esc_html($co{'title'}), $hash);
3343 print "<table cellspacing=\"0\">\n";
3345 if ($commit_search) {
3347 open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", $hash or next;
3348 while (my $commit_text = <$fd>) {
3349 if (!grep m/$searchtext/i, $commit_text) {
3352 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3355 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3358 my @commit_lines = split "\n", $commit_text;
3359 my %co = parse_commit(undef, \@commit_lines);
3364 print "<tr class=\"dark\">\n";
3366 print "<tr class=\"light\">\n";
3369 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3370 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3372 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"},
3373 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
3374 my $comment = $co{'comment'};
3375 foreach my $line (@$comment) {
3376 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3377 my $lead = esc_html($1) || "";
3378 $lead = chop_str($lead, 30, 10);
3379 my $match = esc_html($2) || "";
3380 my $trail = esc_html($3) || "";
3381 $trail = chop_str($trail, 30, 10);
3382 my $text = "$lead<span class=\"match\">$match</span>$trail";
3383 print chop_str($text, 80, 5) . "<br/>\n";
3387 "<td class=\"link\">" .
3388 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
3390 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
3397 if ($pickaxe_search) {
3399 my $git_command = git_cmd_str();
3400 open my $fd, "-|", "$git_command rev-list $hash | " .
3401 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3404 while (my $line = <$fd>) {
3405 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3408 $set{'from_id'} = $3;
3410 $set{'id'} = $set{'to_id'};
3411 if ($set{'id'} =~ m/0{40}/) {
3412 $set{'id'} = $set{'from_id'};
3414 if ($set{'id'} =~ m/0{40}/) {
3418 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3421 print "<tr class=\"dark\">\n";
3423 print "<tr class=\"light\">\n";
3426 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3427 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3429 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
3430 -class => "list subject"},
3431 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
3432 while (my $setref = shift @files) {
3434 print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},
3435 hash=>$set{'id'}, file_name=>$set{'file'}),
3437 "<span class=\"match\">" . esc_html($set{'file'}) . "</span>") .
3441 "<td class=\"link\">" .
3442 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
3444 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
3448 %co = parse_commit($1);
3458 my $head = git_get_head_hash($project);
3459 if (!defined $hash) {
3462 if (!defined $page) {
3465 my $refs = git_get_references();
3467 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3468 open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash
3469 or die_error(undef, "Open git-rev-list failed");
3470 my @revlist = map { chomp; $_ } <$fd>;
3473 my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, $#revlist);
3475 if ($#revlist >= (100 * ($page+1)-1)) {
3477 $cgi->a({-href => href(action=>"shortlog", hash=>$hash, page=>$page+1),
3478 -title => "Alt-n"}, "next");
3483 git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);
3484 git_print_header_div('summary', $project);
3486 git_shortlog_body(\@revlist, ($page * 100), $#revlist, $refs, $next_link);
3491 ## ......................................................................
3492 ## feeds (RSS, OPML)
3495 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3496 open my $fd, "-|", git_cmd(), "rev-list", "--max-count=150", git_get_head_hash($project)
3497 or die_error(undef, "Open git-rev-list failed");
3498 my @revlist = map { chomp; $_ } <$fd>;
3499 close $fd or die_error(undef, "Reading git-rev-list failed");
3500 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
3502 <?xml version="1.0" encoding="utf-8"?>
3503 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3505 <title>$project $my_uri $my_url</title>
3506 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3507 <description>$project log</description>
3508 <language>en</language>
3511 for (my $i = 0; $i <= $#revlist; $i++) {
3512 my $commit = $revlist[$i];
3513 my %co = parse_commit($commit);
3514 # we read 150, we always show 30 and the ones more recent than 48 hours
3515 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3518 my %cd = parse_date($co{'committer_epoch'});
3519 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
3520 $co{'parent'}, $co{'id'}
3522 my @difftree = map { chomp; $_ } <$fd>;
3527 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) .
3529 "<author>" . esc_html($co{'author'}) . "</author>\n" .
3530 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3531 "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3532 "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3533 "<description>" . esc_html($co{'title'}) . "</description>\n" .
3534 "<content:encoded>" .
3536 my $comment = $co{'comment'};
3537 foreach my $line (@$comment) {
3538 $line = decode("utf8", $line, Encode::FB_DEFAULT);
3539 print "$line<br/>\n";
3542 foreach my $line (@difftree) {
3543 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3546 my $file = validate_input(unquote($7));
3547 $file = decode("utf8", $file, Encode::FB_DEFAULT);
3548 print "$file<br/>\n";
3551 "</content:encoded>\n" .
3554 print "</channel></rss>";
3558 my @list = git_get_projects_list();
3560 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
3562 <?xml version="1.0" encoding="utf-8"?>
3563 <opml version="1.0">
3565 <title>$site_name Git OPML Export</title>
3568 <outline text="git RSS feeds">
3571 foreach my $pr (@list) {
3573 my $head = git_get_head_hash($proj{'path'});
3574 if (!defined $head) {
3577 $git_dir = "$projectroot/$proj{'path'}";
3578 my %co = parse_commit($head);
3583 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
3584 my $rss = "$my_url?p=$proj{'path'};a=rss";
3585 my $html = "$my_url?p=$proj{'path'};a=summary";
3586 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";