3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI qw(:standard :escapeHTML -nosticky);
13 use CGI::Util qw(unescape);
14 use CGI::Carp qw(fatalsToBrowser);
18 use File::Basename qw(basename);
19 binmode STDOUT, ':utf8';
22 our $version = "++GIT_VERSION++";
23 our $my_url = $cgi->url();
24 our $my_uri = $cgi->url(-absolute => 1);
26 # core git executable to use
27 # this can just be "git" if your webserver has a sensible PATH
28 our $GIT = "++GIT_BINDIR++/git";
30 # absolute fs-path which will be prepended to the project path
31 #our $projectroot = "/pub/scm";
32 our $projectroot = "++GITWEB_PROJECTROOT++";
34 # target of the home link on top of all pages
35 our $home_link = $my_uri || "/";
37 # string of the home link on top of all pages
38 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
40 # name of your site or organization to appear in page titles
41 # replace this with something more descriptive for clearer bookmarks
42 our $site_name = "++GITWEB_SITENAME++" || $ENV{'SERVER_NAME'} || "Untitled";
44 # html text to include at home page
45 our $home_text = "++GITWEB_HOMETEXT++";
47 # URI of default stylesheet
48 our $stylesheet = "++GITWEB_CSS++";
50 our $logo = "++GITWEB_LOGO++";
51 # URI of GIT favicon, assumed to be image/png type
52 our $favicon = "++GITWEB_FAVICON++";
54 # source of projects list
55 our $projects_list = "++GITWEB_LIST++";
57 # list of git base URLs used for URL to where fetch project from,
58 # i.e. full URL is "$git_base_url/$project"
59 our @git_base_url_list = ("++GITWEB_BASE_URL++");
61 # default blob_plain mimetype and default charset for text/plain blob
62 our $default_blob_plain_mimetype = 'text/plain';
63 our $default_text_plain_charset = undef;
65 # file to use for guessing MIME types before trying /etc/mime.types
66 # (relative to the current git repository)
67 our $mimetypes_file = undef;
69 # You define site-wide feature defaults here; override them with
70 # $GITWEB_CONFIG as necessary.
73 # 'sub' => feature-sub (subroutine),
74 # 'override' => allow-override (boolean),
75 # 'default' => [ default options...] (array reference)}
77 # if feature is overridable (it means that allow-override has true value,
78 # then feature-sub will be called with default options as parameters;
79 # return value of feature-sub indicates if to enable specified feature
81 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
84 'sub' => \&feature_blame,
89 'sub' => \&feature_snapshot,
91 # => [content-encoding, suffix, program]
92 'default' => ['x-gzip', 'gz', 'gzip']},
95 'sub' => \&feature_pickaxe,
100 sub gitweb_check_feature {
102 return undef unless exists $feature{$name};
103 my ($sub, $override, @defaults) = (
104 $feature{$name}{'sub'},
105 $feature{$name}{'override'},
106 @{$feature{$name}{'default'}});
107 if (!$override) { return @defaults; }
108 return $sub->(@defaults);
111 # To enable system wide have in $GITWEB_CONFIG
112 # $feature{'blame'}{'default'} = [1];
113 # To have project specific config enable override in $GITWEB_CONFIG
114 # $feature{'blame'}{'override'} = 1;
115 # and in project config gitweb.blame = 0|1;
118 my ($val) = git_get_project_config('blame', '--bool');
120 if ($val eq 'true') {
122 } elsif ($val eq 'false') {
129 # To disable system wide have in $GITWEB_CONFIG
130 # $feature{'snapshot'}{'default'} = [undef];
131 # To have project specific config enable override in $GITWEB_CONFIG
132 # $feature{'blame'}{'override'} = 1;
133 # and in project config gitweb.snapshot = none|gzip|bzip2
135 sub feature_snapshot {
136 my ($ctype, $suffix, $command) = @_;
138 my ($val) = git_get_project_config('snapshot');
140 if ($val eq 'gzip') {
141 return ('x-gzip', 'gz', 'gzip');
142 } elsif ($val eq 'bzip2') {
143 return ('x-bzip2', 'bz2', 'bzip2');
144 } elsif ($val eq 'none') {
148 return ($ctype, $suffix, $command);
151 # To enable system wide have in $GITWEB_CONFIG
152 # $feature{'pickaxe'}{'default'} = [1];
153 # To have project specific config enable override in $GITWEB_CONFIG
154 # $feature{'pickaxe'}{'override'} = 1;
155 # and in project config gitweb.pickaxe = 0|1;
157 sub feature_pickaxe {
158 my ($val) = git_get_project_config('pickaxe', '--bool');
160 if ($val eq 'true') {
162 } elsif ($val eq 'false') {
169 # rename detection options for git-diff and git-diff-tree
170 # - default is '-M', with the cost proportional to
171 # (number of removed files) * (number of new files).
172 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
173 # (number of changed files + number of removed files) * (number of new files)
174 # - even more costly is '-C', '--find-copies-harder' with cost
175 # (number of files in the original tree) * (number of new files)
176 # - one might want to include '-B' option, e.g. '-B', '-M'
177 our @diff_opts = ('-M'); # taken from git_commit
179 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
180 do $GITWEB_CONFIG if -e $GITWEB_CONFIG;
182 # version of the core git binary
183 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
185 # path to the current git repository
188 $projects_list ||= $projectroot;
190 # ======================================================================
191 # input validation and dispatch
192 our $action = $cgi->param('a');
193 if (defined $action) {
194 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
195 die_error(undef, "Invalid action parameter");
199 our $project = $cgi->param('p');
200 if (defined $project) {
201 if (!validate_input($project) ||
202 !(-d "$projectroot/$project") ||
203 !(-e "$projectroot/$project/HEAD")) {
205 die_error(undef, "No such project");
209 our $file_name = $cgi->param('f');
210 if (defined $file_name) {
211 if (!validate_input($file_name)) {
212 die_error(undef, "Invalid file parameter");
216 our $file_parent = $cgi->param('fp');
217 if (defined $file_parent) {
218 if (!validate_input($file_parent)) {
219 die_error(undef, "Invalid file parent parameter");
223 our $hash = $cgi->param('h');
225 if (!validate_input($hash)) {
226 die_error(undef, "Invalid hash parameter");
230 our $hash_parent = $cgi->param('hp');
231 if (defined $hash_parent) {
232 if (!validate_input($hash_parent)) {
233 die_error(undef, "Invalid hash parent parameter");
237 our $hash_base = $cgi->param('hb');
238 if (defined $hash_base) {
239 if (!validate_input($hash_base)) {
240 die_error(undef, "Invalid hash base parameter");
244 our $hash_parent_base = $cgi->param('hpb');
245 if (defined $hash_parent_base) {
246 if (!validate_input($hash_parent_base)) {
247 die_error(undef, "Invalid hash parent base parameter");
251 our $page = $cgi->param('pg');
253 if ($page =~ m/[^0-9]$/) {
254 die_error(undef, "Invalid page parameter");
258 our $searchtext = $cgi->param('s');
259 if (defined $searchtext) {
260 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) {
261 die_error(undef, "Invalid search parameter");
263 $searchtext = quotemeta $searchtext;
266 # now read PATH_INFO and use it as alternative to parameters
267 our $path_info = $ENV{"PATH_INFO"};
268 $path_info =~ s|^/||;
269 $path_info =~ s|/$||;
270 if (validate_input($path_info) && !defined $project) {
271 $project = $path_info;
272 while ($project && !-e "$projectroot/$project/HEAD") {
273 $project =~ s,/*[^/]*$,,;
275 if (defined $project) {
276 $project = undef unless $project;
278 if ($path_info =~ m,^$project/([^/]+)/(.+)$,) {
279 # we got "project.git/branch/filename"
280 $action ||= "blob_plain";
283 } elsif ($path_info =~ m,^$project/([^/]+)$,) {
284 # we got "project.git/branch"
285 $action ||= "shortlog";
290 $git_dir = "$projectroot/$project";
294 "blame" => \&git_blame2,
295 "blobdiff" => \&git_blobdiff,
296 "blobdiff_plain" => \&git_blobdiff_plain,
297 "blob" => \&git_blob,
298 "blob_plain" => \&git_blob_plain,
299 "commitdiff" => \&git_commitdiff,
300 "commitdiff_plain" => \&git_commitdiff_plain,
301 "commit" => \&git_commit,
302 "heads" => \&git_heads,
303 "history" => \&git_history,
306 "search" => \&git_search,
307 "shortlog" => \&git_shortlog,
308 "summary" => \&git_summary,
310 "tags" => \&git_tags,
311 "tree" => \&git_tree,
312 "snapshot" => \&git_snapshot,
313 # those below don't need $project
314 "opml" => \&git_opml,
315 "project_list" => \&git_project_list,
316 "project_index" => \&git_project_index,
319 if (defined $project) {
320 $action ||= 'summary';
322 $action ||= 'project_list';
324 if (!defined($actions{$action})) {
325 die_error(undef, "Unknown action");
327 $actions{$action}->();
330 ## ======================================================================
344 hash_parent_base => "hpb",
349 my %mapping = @mapping;
351 $params{'project'} = $project unless exists $params{'project'};
354 for (my $i = 0; $i < @mapping; $i += 2) {
355 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
356 if (defined $params{$name}) {
357 push @result, $symbol . "=" . esc_param($params{$name});
360 return "$my_uri?" . join(';', @result);
364 ## ======================================================================
365 ## validation, quoting/unquoting and escaping
370 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
373 if ($input =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
376 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\-\+\#\~\%]/) {
382 # quote unsafe chars, but keep the slash, even when it's not
383 # correct, but quoted slashes look too horrible in bookmarks
386 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
392 # replace invalid utf8 character with SUBSTITUTION sequence
395 $str = decode("utf8", $str, Encode::FB_DEFAULT);
396 $str = escapeHTML($str);
397 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
401 # git may return quoted and escaped filenames
404 if ($str =~ m/^"(.*)"$/) {
406 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
411 # escape tabs (convert tabs to spaces)
415 while ((my $pos = index($line, "\t")) != -1) {
416 if (my $count = (8 - ($pos % 8))) {
417 my $spaces = ' ' x $count;
418 $line =~ s/\t/$spaces/;
425 ## ----------------------------------------------------------------------
426 ## HTML aware string manipulation
431 my $add_len = shift || 10;
433 # allow only $len chars, but don't cut a word if it would fit in $add_len
434 # if it doesn't fit, cut it if it's still longer than the dots we would add
435 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
438 if (length($tail) > 4) {
440 $body =~ s/&[^;]*$//; # remove chopped character entities
445 ## ----------------------------------------------------------------------
446 ## functions returning short strings
448 # CSS class for given age value (in seconds)
452 if ($age < 60*60*2) {
454 } elsif ($age < 60*60*24*2) {
461 # convert age in seconds to "nn units ago" string
466 if ($age > 60*60*24*365*2) {
467 $age_str = (int $age/60/60/24/365);
468 $age_str .= " years ago";
469 } elsif ($age > 60*60*24*(365/12)*2) {
470 $age_str = int $age/60/60/24/(365/12);
471 $age_str .= " months ago";
472 } elsif ($age > 60*60*24*7*2) {
473 $age_str = int $age/60/60/24/7;
474 $age_str .= " weeks ago";
475 } elsif ($age > 60*60*24*2) {
476 $age_str = int $age/60/60/24;
477 $age_str .= " days ago";
478 } elsif ($age > 60*60*2) {
479 $age_str = int $age/60/60;
480 $age_str .= " hours ago";
481 } elsif ($age > 60*2) {
482 $age_str = int $age/60;
483 $age_str .= " min ago";
486 $age_str .= " sec ago";
488 $age_str .= " right now";
493 # convert file mode in octal to symbolic file mode string
495 my $mode = oct shift;
497 if (S_ISDIR($mode & S_IFMT)) {
499 } elsif (S_ISLNK($mode)) {
501 } elsif (S_ISREG($mode)) {
502 # git cares only about the executable bit
503 if ($mode & S_IXUSR) {
513 # convert file mode in octal to file type string
517 if ($mode !~ m/^[0-7]+$/) {
523 if (S_ISDIR($mode & S_IFMT)) {
525 } elsif (S_ISLNK($mode)) {
527 } elsif (S_ISREG($mode)) {
534 ## ----------------------------------------------------------------------
535 ## functions returning short HTML fragments, or transforming HTML fragments
536 ## which don't beling to other sections
538 # format line of commit message or tag comment
539 sub format_log_line_html {
542 $line = esc_html($line);
543 $line =~ s/ / /g;
544 if ($line =~ m/([0-9a-fA-F]{40})/) {
546 if (git_get_type($hash_text) eq "commit") {
548 $cgi->a({-href => href(action=>"commit", hash=>$hash_text),
549 -class => "text"}, $hash_text);
550 $line =~ s/$hash_text/$link/;
556 # format marker of refs pointing to given object
557 sub format_ref_marker {
558 my ($refs, $id) = @_;
561 if (defined $refs->{$id}) {
562 foreach my $ref (@{$refs->{$id}}) {
563 my ($type, $name) = qw();
564 # e.g. tags/v2.6.11 or heads/next
565 if ($ref =~ m!^(.*?)s?/(.*)$!) {
573 $markers .= " <span class=\"$type\">" . esc_html($name) . "</span>";
578 return ' <span class="refs">'. $markers . '</span>';
584 # format, perhaps shortened and with markers, title line
585 sub format_subject_html {
586 my ($long, $short, $href, $extra) = @_;
587 $extra = '' unless defined($extra);
589 if (length($short) < length($long)) {
590 return $cgi->a({-href => $href, -class => "list subject",
592 esc_html($short) . $extra);
594 return $cgi->a({-href => $href, -class => "list subject"},
595 esc_html($long) . $extra);
599 sub format_diff_line {
601 my $char = substr($line, 0, 1);
607 $diff_class = " add";
608 } elsif ($char eq "-") {
609 $diff_class = " rem";
610 } elsif ($char eq "@") {
611 $diff_class = " chunk_header";
612 } elsif ($char eq "\\") {
613 $diff_class = " incomplete";
615 $line = untabify($line);
616 return "<div class=\"diff$diff_class\">" . esc_html($line) . "</div>\n";
619 ## ----------------------------------------------------------------------
620 ## git utility subroutines, invoking git commands
622 # returns path to the core git executable and the --git-dir parameter as list
624 return $GIT, '--git-dir='.$git_dir;
627 # returns path to the core git executable and the --git-dir parameter as string
629 return join(' ', git_cmd());
632 # get HEAD ref of given project as hash
633 sub git_get_head_hash {
635 my $o_git_dir = $git_dir;
637 $git_dir = "$projectroot/$project";
638 if (open my $fd, "-|", git_cmd(), "rev-parse", "--verify", "HEAD") {
641 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
645 if (defined $o_git_dir) {
646 $git_dir = $o_git_dir;
651 # get type of given object
655 open my $fd, "-|", git_cmd(), "cat-file", '-t', $hash or return;
662 sub git_get_project_config {
663 my ($key, $type) = @_;
665 return unless ($key);
666 $key =~ s/^gitweb\.//;
667 return if ($key =~ m/\W/);
669 my @x = (git_cmd(), 'repo-config');
670 if (defined $type) { push @x, $type; }
672 push @x, "gitweb.$key";
678 # get hash of given path at given ref
679 sub git_get_hash_by_path {
681 my $path = shift || return undef;
685 open my $fd, "-|", git_cmd(), "ls-tree", $base, "--", $path
686 or die_error(undef, "Open git-ls-tree failed");
688 close $fd or return undef;
690 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
691 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
695 ## ......................................................................
696 ## git utility functions, directly accessing git repository
698 sub git_get_project_description {
701 open my $fd, "$projectroot/$path/description" or return undef;
708 sub git_get_project_url_list {
711 open my $fd, "$projectroot/$path/cloneurl" or return undef;
712 my @git_project_url_list = map { chomp; $_ } <$fd>;
715 return wantarray ? @git_project_url_list : \@git_project_url_list;
718 sub git_get_projects_list {
721 if (-d $projects_list) {
722 # search in directory
723 my $dir = $projects_list;
724 my $pfxlen = length("$dir");
727 follow_fast => 1, # follow symbolic links
728 dangling_symlinks => 0, # ignore dangling symlinks, silently
730 # skip project-list toplevel, if we get it.
731 return if (m!^[/.]$!);
732 # only directories can be git repositories
733 return unless (-d $_);
735 my $subdir = substr($File::Find::name, $pfxlen + 1);
736 # we check related file in $projectroot
737 if (-e "$projectroot/$subdir/HEAD") {
738 push @list, { path => $subdir };
739 $File::Find::prune = 1;
744 } elsif (-f $projects_list) {
745 # read from file(url-encoded):
746 # 'git%2Fgit.git Linus+Torvalds'
747 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
748 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
749 open my ($fd), $projects_list or return undef;
750 while (my $line = <$fd>) {
752 my ($path, $owner) = split ' ', $line;
753 $path = unescape($path);
754 $owner = unescape($owner);
755 if (!defined $path) {
758 if (-e "$projectroot/$path/HEAD") {
761 owner => decode("utf8", $owner, Encode::FB_DEFAULT),
768 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
772 sub git_get_project_owner {
776 return undef unless $project;
778 # read from file (url-encoded):
779 # 'git%2Fgit.git Linus+Torvalds'
780 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
781 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
782 if (-f $projects_list) {
783 open (my $fd , $projects_list);
784 while (my $line = <$fd>) {
786 my ($pr, $ow) = split ' ', $line;
789 if ($pr eq $project) {
790 $owner = decode("utf8", $ow, Encode::FB_DEFAULT);
796 if (!defined $owner) {
797 $owner = get_file_owner("$projectroot/$project");
803 sub git_get_references {
804 my $type = shift || "";
807 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
808 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
809 if (-f "$projectroot/$project/info/refs") {
810 open $fd, "$projectroot/$project/info/refs"
813 open $fd, "-|", git_cmd(), "ls-remote", "."
817 while (my $line = <$fd>) {
819 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?[^\^]+)/) {
820 if (defined $refs{$1}) {
821 push @{$refs{$1}}, $2;
831 sub git_get_rev_name_tags {
832 my $hash = shift || return undef;
834 open my $fd, "-|", git_cmd(), "name-rev", "--tags", $hash
836 my $name_rev = <$fd>;
839 if ($name_rev =~ m|^$hash tags/(.*)$|) {
842 # catches also '$hash undefined' output
847 ## ----------------------------------------------------------------------
848 ## parse to hash functions
852 my $tz = shift || "-0000";
855 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
856 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
857 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
858 $date{'hour'} = $hour;
859 $date{'minute'} = $min;
860 $date{'mday'} = $mday;
861 $date{'day'} = $days[$wday];
862 $date{'month'} = $months[$mon];
863 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
864 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
865 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
866 $mday, $months[$mon], $hour ,$min;
868 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
869 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
870 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
871 $date{'hour_local'} = $hour;
872 $date{'minute_local'} = $min;
873 $date{'tz_local'} = $tz;
882 open my $fd, "-|", git_cmd(), "cat-file", "tag", $tag_id or return;
883 $tag{'id'} = $tag_id;
884 while (my $line = <$fd>) {
886 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
888 } elsif ($line =~ m/^type (.+)$/) {
890 } elsif ($line =~ m/^tag (.+)$/) {
892 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
896 } elsif ($line =~ m/--BEGIN/) {
897 push @comment, $line;
899 } elsif ($line eq "") {
903 push @comment, <$fd>;
904 $tag{'comment'} = \@comment;
906 if (!defined $tag{'name'}) {
913 my $commit_id = shift;
914 my $commit_text = shift;
919 if (defined $commit_text) {
920 @commit_lines = @$commit_text;
923 open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
925 @commit_lines = split '\n', <$fd>;
930 my $header = shift @commit_lines;
931 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
934 ($co{'id'}, my @parents) = split ' ', $header;
935 $co{'parents'} = \@parents;
936 $co{'parent'} = $parents[0];
937 while (my $line = shift @commit_lines) {
938 last if $line eq "\n";
939 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
941 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
943 $co{'author_epoch'} = $2;
944 $co{'author_tz'} = $3;
945 if ($co{'author'} =~ m/^([^<]+) </) {
946 $co{'author_name'} = $1;
948 $co{'author_name'} = $co{'author'};
950 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
951 $co{'committer'} = $1;
952 $co{'committer_epoch'} = $2;
953 $co{'committer_tz'} = $3;
954 $co{'committer_name'} = $co{'committer'};
955 $co{'committer_name'} =~ s/ <.*//;
958 if (!defined $co{'tree'}) {
962 foreach my $title (@commit_lines) {
965 $co{'title'} = chop_str($title, 80, 5);
966 # remove leading stuff of merges to make the interesting part visible
967 if (length($title) > 50) {
968 $title =~ s/^Automatic //;
969 $title =~ s/^merge (of|with) /Merge ... /i;
970 if (length($title) > 50) {
971 $title =~ s/(http|rsync):\/\///;
973 if (length($title) > 50) {
974 $title =~ s/(master|www|rsync)\.//;
976 if (length($title) > 50) {
977 $title =~ s/kernel.org:?//;
979 if (length($title) > 50) {
980 $title =~ s/\/pub\/scm//;
983 $co{'title_short'} = chop_str($title, 50, 5);
987 # remove added spaces
988 foreach my $line (@commit_lines) {
991 $co{'comment'} = \@commit_lines;
993 my $age = time - $co{'committer_epoch'};
995 $co{'age_string'} = age_string($age);
996 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
997 if ($age > 60*60*24*7*2) {
998 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
999 $co{'age_string_age'} = $co{'age_string'};
1001 $co{'age_string_date'} = $co{'age_string'};
1002 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1007 # parse ref from ref_file, given by ref_id, with given type
1009 my $ref_file = shift;
1011 my $type = shift || git_get_type($ref_id);
1014 $ref_item{'type'} = $type;
1015 $ref_item{'id'} = $ref_id;
1016 $ref_item{'epoch'} = 0;
1017 $ref_item{'age'} = "unknown";
1018 if ($type eq "tag") {
1019 my %tag = parse_tag($ref_id);
1020 $ref_item{'comment'} = $tag{'comment'};
1021 if ($tag{'type'} eq "commit") {
1022 my %co = parse_commit($tag{'object'});
1023 $ref_item{'epoch'} = $co{'committer_epoch'};
1024 $ref_item{'age'} = $co{'age_string'};
1025 } elsif (defined($tag{'epoch'})) {
1026 my $age = time - $tag{'epoch'};
1027 $ref_item{'epoch'} = $tag{'epoch'};
1028 $ref_item{'age'} = age_string($age);
1030 $ref_item{'reftype'} = $tag{'type'};
1031 $ref_item{'name'} = $tag{'name'};
1032 $ref_item{'refid'} = $tag{'object'};
1033 } elsif ($type eq "commit"){
1034 my %co = parse_commit($ref_id);
1035 $ref_item{'reftype'} = "commit";
1036 $ref_item{'name'} = $ref_file;
1037 $ref_item{'title'} = $co{'title'};
1038 $ref_item{'refid'} = $ref_id;
1039 $ref_item{'epoch'} = $co{'committer_epoch'};
1040 $ref_item{'age'} = $co{'age_string'};
1042 $ref_item{'reftype'} = $type;
1043 $ref_item{'name'} = $ref_file;
1044 $ref_item{'refid'} = $ref_id;
1050 # parse line of git-diff-tree "raw" output
1051 sub parse_difftree_raw_line {
1055 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1056 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1057 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1058 $res{'from_mode'} = $1;
1059 $res{'to_mode'} = $2;
1060 $res{'from_id'} = $3;
1062 $res{'status'} = $5;
1063 $res{'similarity'} = $6;
1064 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1065 ($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
1067 $res{'file'} = unquote($7);
1070 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1071 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1072 $res{'commit'} = $1;
1075 return wantarray ? %res : \%res;
1078 # parse line of git-ls-tree output
1079 sub parse_ls_tree_line ($;%) {
1084 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1085 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1093 $res{'name'} = unquote($4);
1096 return wantarray ? %res : \%res;
1099 ## ......................................................................
1100 ## parse to array of hashes functions
1102 sub git_get_refs_list {
1103 my $ref_dir = shift;
1107 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1109 while (my $line = <$fd>) {
1111 if ($line =~ m/^([0-9a-fA-F]{40})\t$ref_dir\/?([^\^]+)$/) {
1112 push @refs, { hash => $1, name => $2 };
1113 } elsif ($line =~ m/^[0-9a-fA-F]{40}\t$ref_dir\/?(.*)\^\{\}$/ &&
1114 $1 eq $refs[-1]{'name'}) {
1115 # most likely a tag is followed by its peeled
1116 # (deref) one, and when that happens we know the
1117 # previous one was of type 'tag'.
1118 $refs[-1]{'type'} = "tag";
1123 foreach my $ref (@refs) {
1124 my $ref_file = $ref->{'name'};
1125 my $ref_id = $ref->{'hash'};
1127 my $type = $ref->{'type'} || git_get_type($ref_id) || next;
1128 my %ref_item = parse_ref($ref_file, $ref_id, $type);
1130 push @reflist, \%ref_item;
1133 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1137 ## ----------------------------------------------------------------------
1138 ## filesystem-related functions
1140 sub get_file_owner {
1143 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1144 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1145 if (!defined $gcos) {
1149 $owner =~ s/[,;].*$//;
1150 return decode("utf8", $owner, Encode::FB_DEFAULT);
1153 ## ......................................................................
1154 ## mimetype related functions
1156 sub mimetype_guess_file {
1157 my $filename = shift;
1158 my $mimemap = shift;
1159 -r $mimemap or return undef;
1162 open(MIME, $mimemap) or return undef;
1164 next if m/^#/; # skip comments
1165 my ($mime, $exts) = split(/\t+/);
1166 if (defined $exts) {
1167 my @exts = split(/\s+/, $exts);
1168 foreach my $ext (@exts) {
1169 $mimemap{$ext} = $mime;
1175 $filename =~ /\.(.*?)$/;
1176 return $mimemap{$1};
1179 sub mimetype_guess {
1180 my $filename = shift;
1182 $filename =~ /\./ or return undef;
1184 if ($mimetypes_file) {
1185 my $file = $mimetypes_file;
1186 if ($file !~ m!^/!) { # if it is relative path
1187 # it is relative to project
1188 $file = "$projectroot/$project/$file";
1190 $mime = mimetype_guess_file($filename, $file);
1192 $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
1198 my $filename = shift;
1201 my $mime = mimetype_guess($filename);
1202 $mime and return $mime;
1206 return $default_blob_plain_mimetype unless $fd;
1209 return 'text/plain' .
1210 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1211 } elsif (! $filename) {
1212 return 'application/octet-stream';
1213 } elsif ($filename =~ m/\.png$/i) {
1215 } elsif ($filename =~ m/\.gif$/i) {
1217 } elsif ($filename =~ m/\.jpe?g$/i) {
1218 return 'image/jpeg';
1220 return 'application/octet-stream';
1224 ## ======================================================================
1225 ## functions printing HTML: header, footer, error page
1227 sub git_header_html {
1228 my $status = shift || "200 OK";
1229 my $expires = shift;
1231 my $title = "$site_name git";
1232 if (defined $project) {
1233 $title .= " - $project";
1234 if (defined $action) {
1235 $title .= "/$action";
1236 if (defined $file_name) {
1237 $title .= " - $file_name";
1238 if ($action eq "tree" && $file_name !~ m|/$|) {
1245 # require explicit support from the UA if we are to send the page as
1246 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1247 # we have to do this because MSIE sometimes globs '*/*', pretending to
1248 # support xhtml+xml but choking when it gets what it asked for.
1249 if (defined $cgi->http('HTTP_ACCEPT') &&
1250 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&
1251 $cgi->Accept('application/xhtml+xml') != 0) {
1252 $content_type = 'application/xhtml+xml';
1254 $content_type = 'text/html';
1256 print $cgi->header(-type=>$content_type, -charset => 'utf-8',
1257 -status=> $status, -expires => $expires);
1259 <?xml version="1.0" encoding="utf-8"?>
1260 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1261 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1262 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1263 <!-- git core binaries version $git_version -->
1265 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1266 <meta name="generator" content="gitweb/$version git/$git_version"/>
1267 <meta name="robots" content="index, nofollow"/>
1268 <title>$title</title>
1269 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1271 if (defined $project) {
1272 printf('<link rel="alternate" title="%s log" '.
1273 'href="%s" type="application/rss+xml"/>'."\n",
1274 esc_param($project), href(action=>"rss"));
1276 printf('<link rel="alternate" title="%s projects list" '.
1277 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1278 $site_name, href(project=>undef, action=>"project_index"));
1279 printf('<link rel="alternate" title="%s projects logs" '.
1280 'href="%s" type="text/x-opml"/>'."\n",
1281 $site_name, href(project=>undef, action=>"opml"));
1283 if (defined $favicon) {
1284 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1289 "<div class=\"page_header\">\n" .
1290 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1291 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1293 print $cgi->a({-href => esc_param($home_link)}, $home_link_str) . " / ";
1294 if (defined $project) {
1295 print $cgi->a({-href => href(action=>"summary")}, esc_html($project));
1296 if (defined $action) {
1300 if (!defined $searchtext) {
1304 if (defined $hash_base) {
1305 $search_hash = $hash_base;
1306 } elsif (defined $hash) {
1307 $search_hash = $hash;
1309 $search_hash = "HEAD";
1311 $cgi->param("a", "search");
1312 $cgi->param("h", $search_hash);
1313 print $cgi->startform(-method => "get", -action => $my_uri) .
1314 "<div class=\"search\">\n" .
1315 $cgi->hidden(-name => "p") . "\n" .
1316 $cgi->hidden(-name => "a") . "\n" .
1317 $cgi->hidden(-name => "h") . "\n" .
1318 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
1320 $cgi->end_form() . "\n";
1325 sub git_footer_html {
1326 print "<div class=\"page_footer\">\n";
1327 if (defined $project) {
1328 my $descr = git_get_project_description($project);
1329 if (defined $descr) {
1330 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
1332 print $cgi->a({-href => href(action=>"rss"),
1333 -class => "rss_logo"}, "RSS") . "\n";
1335 print $cgi->a({-href => href(project=>undef, action=>"opml"),
1336 -class => "rss_logo"}, "OPML") . " ";
1337 print $cgi->a({-href => href(project=>undef, action=>"project_index"),
1338 -class => "rss_logo"}, "TXT") . "\n";
1346 my $status = shift || "403 Forbidden";
1347 my $error = shift || "Malformed query, file missing or permission denied";
1349 git_header_html($status);
1351 <div class="page_body">
1361 ## ----------------------------------------------------------------------
1362 ## functions printing or outputting HTML: navigation
1364 sub git_print_page_nav {
1365 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1366 $extra = '' if !defined $extra; # pager or formats
1368 my @navs = qw(summary shortlog log commit commitdiff tree);
1370 @navs = grep { $_ ne $suppress } @navs;
1373 my %arg = map { $_ => {action=>$_} } @navs;
1374 if (defined $head) {
1375 for (qw(commit commitdiff)) {
1376 $arg{$_}{hash} = $head;
1378 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1379 for (qw(shortlog log)) {
1380 $arg{$_}{hash} = $head;
1384 $arg{tree}{hash} = $treehead if defined $treehead;
1385 $arg{tree}{hash_base} = $treebase if defined $treebase;
1387 print "<div class=\"page_nav\">\n" .
1389 map { $_ eq $current ?
1390 $_ : $cgi->a({-href => href(%{$arg{$_}})}, "$_")
1392 print "<br/>\n$extra<br/>\n" .
1396 sub format_paging_nav {
1397 my ($action, $hash, $head, $page, $nrevs) = @_;
1401 if ($hash ne $head || $page) {
1402 $paging_nav .= $cgi->a({-href => href(action=>$action)}, "HEAD");
1404 $paging_nav .= "HEAD";
1408 $paging_nav .= " ⋅ " .
1409 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page-1),
1410 -accesskey => "p", -title => "Alt-p"}, "prev");
1412 $paging_nav .= " ⋅ prev";
1415 if ($nrevs >= (100 * ($page+1)-1)) {
1416 $paging_nav .= " ⋅ " .
1417 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page+1),
1418 -accesskey => "n", -title => "Alt-n"}, "next");
1420 $paging_nav .= " ⋅ next";
1426 ## ......................................................................
1427 ## functions printing or outputting HTML: div
1429 sub git_print_header_div {
1430 my ($action, $title, $hash, $hash_base) = @_;
1433 $args{action} = $action;
1434 $args{hash} = $hash if $hash;
1435 $args{hash_base} = $hash_base if $hash_base;
1437 print "<div class=\"header\">\n" .
1438 $cgi->a({-href => href(%args), -class => "title"},
1439 $title ? $title : $action) .
1443 #sub git_print_authorship (\%) {
1444 sub git_print_authorship {
1447 my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
1448 print "<div class=\"author_date\">" .
1449 esc_html($co->{'author_name'}) .
1451 if ($ad{'hour_local'} < 6) {
1452 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1453 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1455 printf(" (%02d:%02d %s)",
1456 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1461 sub git_print_page_path {
1466 if (!defined $name) {
1467 print "<div class=\"page_path\">/</div>\n";
1469 my @dirname = split '/', $name;
1470 my $basename = pop @dirname;
1473 print "<div class=\"page_path\">";
1474 foreach my $dir (@dirname) {
1475 $fullname .= $dir . '/';
1476 print $cgi->a({-href => href(action=>"tree", file_name=>$fullname,
1478 -title => $fullname}, esc_html($dir));
1481 if (defined $type && $type eq 'blob') {
1482 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,
1484 -title => $name}, esc_html($basename));
1485 } elsif (defined $type && $type eq 'tree') {
1486 print $cgi->a({-href => href(action=>"tree", file_name=>$file_name,
1488 -title => $name}, esc_html($basename));
1491 print esc_html($basename);
1493 print "<br/></div>\n";
1497 # sub git_print_log (\@;%) {
1498 sub git_print_log ($;%) {
1502 if ($opts{'-remove_title'}) {
1503 # remove title, i.e. first line of log
1506 # remove leading empty lines
1507 while (defined $log->[0] && $log->[0] eq "") {
1514 foreach my $line (@$log) {
1515 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1518 if (! $opts{'-remove_signoff'}) {
1519 print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
1522 # remove signoff lines
1529 # print only one empty line
1530 # do not print empty line after signoff
1532 next if ($empty || $signoff);
1538 print format_log_line_html($line) . "<br/>\n";
1541 if ($opts{'-final_empty_line'}) {
1542 # end with single empty line
1543 print "<br/>\n" unless $empty;
1547 sub git_print_simplified_log {
1549 my $remove_title = shift;
1552 -final_empty_line=> 1,
1553 -remove_title => $remove_title);
1556 # print tree entry (row of git_tree), but without encompassing <tr> element
1557 sub git_print_tree_entry {
1558 my ($t, $basedir, $hash_base, $have_blame) = @_;
1561 $base_key{hash_base} = $hash_base if defined $hash_base;
1563 print "<td class=\"mode\">" . mode_str($t->{'mode'}) . "</td>\n";
1564 if ($t->{'type'} eq "blob") {
1565 print "<td class=\"list\">" .
1566 $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
1567 file_name=>"$basedir$t->{'name'}", %base_key),
1568 -class => "list"}, esc_html($t->{'name'})) .
1570 "<td class=\"link\">" .
1571 $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
1572 file_name=>"$basedir$t->{'name'}", %base_key)},
1576 $cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},
1577 file_name=>"$basedir$t->{'name'}", %base_key)},
1580 if (defined $hash_base) {
1582 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
1583 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},
1587 $cgi->a({-href => href(action=>"blob_plain",
1588 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},
1592 } elsif ($t->{'type'} eq "tree") {
1593 print "<td class=\"list\">" .
1594 $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
1595 file_name=>"$basedir$t->{'name'}", %base_key)},
1596 esc_html($t->{'name'})) .
1598 "<td class=\"link\">" .
1599 $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
1600 file_name=>"$basedir$t->{'name'}", %base_key)},
1602 if (defined $hash_base) {
1604 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
1605 file_name=>"$basedir$t->{'name'}")},
1612 ## ......................................................................
1613 ## functions printing large fragments of HTML
1615 sub git_difftree_body {
1616 my ($difftree, $hash, $parent) = @_;
1618 print "<div class=\"list_head\">\n";
1619 if ($#{$difftree} > 10) {
1620 print(($#{$difftree} + 1) . " files changed:\n");
1624 print "<table class=\"diff_tree\">\n";
1627 foreach my $line (@{$difftree}) {
1628 my %diff = parse_difftree_raw_line($line);
1631 print "<tr class=\"dark\">\n";
1633 print "<tr class=\"light\">\n";
1637 my ($to_mode_oct, $to_mode_str, $to_file_type);
1638 my ($from_mode_oct, $from_mode_str, $from_file_type);
1639 if ($diff{'to_mode'} ne ('0' x 6)) {
1640 $to_mode_oct = oct $diff{'to_mode'};
1641 if (S_ISREG($to_mode_oct)) { # only for regular file
1642 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1644 $to_file_type = file_type($diff{'to_mode'});
1646 if ($diff{'from_mode'} ne ('0' x 6)) {
1647 $from_mode_oct = oct $diff{'from_mode'};
1648 if (S_ISREG($to_mode_oct)) { # only for regular file
1649 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1651 $from_file_type = file_type($diff{'from_mode'});
1654 if ($diff{'status'} eq "A") { # created
1655 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1656 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1657 $mode_chng .= "]</span>";
1659 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1660 hash_base=>$hash, file_name=>$diff{'file'}),
1661 -class => "list"}, esc_html($diff{'file'})) .
1663 "<td>$mode_chng</td>\n" .
1664 "<td class=\"link\">" .
1665 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1666 hash_base=>$hash, file_name=>$diff{'file'})},
1668 if ($action eq 'commitdiff') {
1672 $cgi->a({-href => "#patch$patchno"}, "patch");
1676 } elsif ($diff{'status'} eq "D") { # deleted
1677 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1679 $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
1680 hash_base=>$parent, file_name=>$diff{'file'}),
1681 -class => "list"}, esc_html($diff{'file'})) .
1683 "<td>$mode_chng</td>\n" .
1684 "<td class=\"link\">" .
1685 $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
1686 hash_base=>$parent, file_name=>$diff{'file'})},
1689 if ($action eq 'commitdiff') {
1693 $cgi->a({-href => "#patch$patchno"}, "patch");
1695 print $cgi->a({-href => href(action=>"history", hash_base=>$parent,
1696 file_name=>$diff{'file'})},
1700 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1701 my $mode_chnge = "";
1702 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1703 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1704 if ($from_file_type != $to_file_type) {
1705 $mode_chnge .= " from $from_file_type to $to_file_type";
1707 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1708 if ($from_mode_str && $to_mode_str) {
1709 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1710 } elsif ($to_mode_str) {
1711 $mode_chnge .= " mode: $to_mode_str";
1714 $mode_chnge .= "]</span>\n";
1717 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1718 print $cgi->a({-href => href(action=>"blobdiff",
1719 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1720 hash_base=>$hash, hash_parent_base=>$parent,
1721 file_name=>$diff{'file'}),
1722 -class => "list"}, esc_html($diff{'file'}));
1723 } else { # only mode changed
1724 print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1725 hash_base=>$hash, file_name=>$diff{'file'}),
1726 -class => "list"}, esc_html($diff{'file'}));
1729 "<td>$mode_chnge</td>\n" .
1730 "<td class=\"link\">" .
1731 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1732 hash_base=>$hash, file_name=>$diff{'file'})},
1734 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1735 if ($action eq 'commitdiff') {
1739 $cgi->a({-href => "#patch$patchno"}, "patch");
1742 $cgi->a({-href => href(action=>"blobdiff",
1743 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1744 hash_base=>$hash, hash_parent_base=>$parent,
1745 file_name=>$diff{'file'})},
1750 $cgi->a({-href => href(action=>"history",
1751 hash_base=>$hash, file_name=>$diff{'file'})},
1755 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1756 my %status_name = ('R' => 'moved', 'C' => 'copied');
1757 my $nstatus = $status_name{$diff{'status'}};
1759 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1760 # mode also for directories, so we cannot use $to_mode_str
1761 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1764 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1765 hash=>$diff{'to_id'}, file_name=>$diff{'to_file'}),
1766 -class => "list"}, esc_html($diff{'to_file'})) . "</td>\n" .
1767 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1768 $cgi->a({-href => href(action=>"blob", hash_base=>$parent,
1769 hash=>$diff{'from_id'}, file_name=>$diff{'from_file'}),
1770 -class => "list"}, esc_html($diff{'from_file'})) .
1771 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1772 "<td class=\"link\">" .
1773 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1774 hash=>$diff{'to_id'}, file_name=>$diff{'to_file'})},
1776 if ($diff{'to_id'} ne $diff{'from_id'}) {
1777 if ($action eq 'commitdiff') {
1781 $cgi->a({-href => "#patch$patchno"}, "patch");
1784 $cgi->a({-href => href(action=>"blobdiff",
1785 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1786 hash_base=>$hash, hash_parent_base=>$parent,
1787 file_name=>$diff{'to_file'}, file_parent=>$diff{'from_file'})},
1793 } # we should not encounter Unmerged (U) or Unknown (X) status
1799 sub git_patchset_body {
1800 my ($fd, $difftree, $hash, $hash_parent) = @_;
1804 my $patch_found = 0;
1807 print "<div class=\"patchset\">\n";
1810 while (my $patch_line = <$fd>) {
1813 if ($patch_line =~ m/^diff /) { # "git diff" header
1814 # beginning of patch (in patchset)
1816 # close previous patch
1817 print "</div>\n"; # class="patch"
1819 # first patch in patchset
1822 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1824 if (ref($difftree->[$patch_idx]) eq "HASH") {
1825 $diffinfo = $difftree->[$patch_idx];
1827 $diffinfo = parse_difftree_raw_line($difftree->[$patch_idx]);
1831 # for now, no extended header, hence we skip empty patches
1832 # companion to next LINE if $in_header;
1833 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1838 if ($diffinfo->{'status'} eq "A") { # added
1839 print "<div class=\"diff_info\">" . file_type($diffinfo->{'to_mode'}) . ":" .
1840 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1841 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'file'})},
1842 $diffinfo->{'to_id'}) . "(new)" .
1843 "</div>\n"; # class="diff_info"
1845 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1846 print "<div class=\"diff_info\">" . file_type($diffinfo->{'from_mode'}) . ":" .
1847 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1848 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'file'})},
1849 $diffinfo->{'from_id'}) . "(deleted)" .
1850 "</div>\n"; # class="diff_info"
1852 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1853 $diffinfo->{'status'} eq "C" || # copied
1854 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1855 print "<div class=\"diff_info\">" .
1856 file_type($diffinfo->{'from_mode'}) . ":" .
1857 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1858 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'from_file'})},
1859 $diffinfo->{'from_id'}) .
1861 file_type($diffinfo->{'to_mode'}) . ":" .
1862 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1863 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'to_file'})},
1864 $diffinfo->{'to_id'});
1865 print "</div>\n"; # class="diff_info"
1867 } else { # modified, mode changed, ...
1868 print "<div class=\"diff_info\">" .
1869 file_type($diffinfo->{'from_mode'}) . ":" .
1870 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1871 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'file'})},
1872 $diffinfo->{'from_id'}) .
1874 file_type($diffinfo->{'to_mode'}) . ":" .
1875 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1876 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'file'})},
1877 $diffinfo->{'to_id'});
1878 print "</div>\n"; # class="diff_info"
1881 #print "<div class=\"diff extended_header\">\n";
1884 } # start of patch in patchset
1887 if ($in_header && $patch_line =~ m/^---/) {
1888 #print "</div>\n"; # class="diff extended_header"
1891 my $file = $diffinfo->{'from_file'};
1892 $file ||= $diffinfo->{'file'};
1893 $file = $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1894 hash=>$diffinfo->{'from_id'}, file_name=>$file),
1895 -class => "list"}, esc_html($file));
1896 $patch_line =~ s|a/.*$|a/$file|g;
1897 print "<div class=\"diff from_file\">$patch_line</div>\n";
1899 $patch_line = <$fd>;
1902 #$patch_line =~ m/^+++/;
1903 $file = $diffinfo->{'to_file'};
1904 $file ||= $diffinfo->{'file'};
1905 $file = $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1906 hash=>$diffinfo->{'to_id'}, file_name=>$file),
1907 -class => "list"}, esc_html($file));
1908 $patch_line =~ s|b/.*|b/$file|g;
1909 print "<div class=\"diff to_file\">$patch_line</div>\n";
1913 next LINE if $in_header;
1915 print format_diff_line($patch_line);
1917 print "</div>\n" if $patch_found; # class="patch"
1919 print "</div>\n"; # class="patchset"
1922 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1924 sub git_shortlog_body {
1925 # uses global variable $project
1926 my ($revlist, $from, $to, $refs, $extra) = @_;
1928 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
1929 my $have_snapshot = (defined $ctype && defined $suffix);
1931 $from = 0 unless defined $from;
1932 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1934 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1936 for (my $i = $from; $i <= $to; $i++) {
1937 my $commit = $revlist->[$i];
1938 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1939 my $ref = format_ref_marker($refs, $commit);
1940 my %co = parse_commit($commit);
1942 print "<tr class=\"dark\">\n";
1944 print "<tr class=\"light\">\n";
1947 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1948 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1949 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1951 print format_subject_html($co{'title'}, $co{'title_short'},
1952 href(action=>"commit", hash=>$commit), $ref);
1954 "<td class=\"link\">" .
1955 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
1956 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff");
1957 if ($have_snapshot) {
1958 print " | " . $cgi->a({-href => href(action=>"snapshot", hash=>$commit)}, "snapshot");
1963 if (defined $extra) {
1965 "<td colspan=\"4\">$extra</td>\n" .
1971 sub git_history_body {
1972 # Warning: assumes constant type (blob or tree) during history
1973 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
1975 $from = 0 unless defined $from;
1976 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
1978 print "<table class=\"history\" cellspacing=\"0\">\n";
1980 for (my $i = $from; $i <= $to; $i++) {
1981 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
1986 my %co = parse_commit($commit);
1991 my $ref = format_ref_marker($refs, $commit);
1994 print "<tr class=\"dark\">\n";
1996 print "<tr class=\"light\">\n";
1999 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2000 # shortlog uses chop_str($co{'author_name'}, 10)
2001 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2003 # originally git_history used chop_str($co{'title'}, 50)
2004 print format_subject_html($co{'title'}, $co{'title_short'},
2005 href(action=>"commit", hash=>$commit), $ref);
2007 "<td class=\"link\">" .
2008 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
2009 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
2010 $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype);
2012 if ($ftype eq 'blob') {
2013 my $blob_current = git_get_hash_by_path($hash_base, $file_name);
2014 my $blob_parent = git_get_hash_by_path($commit, $file_name);
2015 if (defined $blob_current && defined $blob_parent &&
2016 $blob_current ne $blob_parent) {
2018 $cgi->a({-href => href(action=>"blobdiff",
2019 hash=>$blob_current, hash_parent=>$blob_parent,
2020 hash_base=>$hash_base, hash_parent_base=>$commit,
2021 file_name=>$file_name)},
2028 if (defined $extra) {
2030 "<td colspan=\"4\">$extra</td>\n" .
2037 # uses global variable $project
2038 my ($taglist, $from, $to, $extra) = @_;
2039 $from = 0 unless defined $from;
2040 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2042 print "<table class=\"tags\" cellspacing=\"0\">\n";
2044 for (my $i = $from; $i <= $to; $i++) {
2045 my $entry = $taglist->[$i];
2047 my $comment_lines = $tag{'comment'};
2048 my $comment = shift @$comment_lines;
2050 if (defined $comment) {
2051 $comment_short = chop_str($comment, 30, 5);
2054 print "<tr class=\"dark\">\n";
2056 print "<tr class=\"light\">\n";
2059 print "<td><i>$tag{'age'}</i></td>\n" .
2061 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),
2062 -class => "list name"}, esc_html($tag{'name'})) .
2065 if (defined $comment) {
2066 print format_subject_html($comment, $comment_short,
2067 href(action=>"tag", hash=>$tag{'id'}));
2070 "<td class=\"selflink\">";
2071 if ($tag{'type'} eq "tag") {
2072 print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag");
2077 "<td class=\"link\">" . " | " .
2078 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'});
2079 if ($tag{'reftype'} eq "commit") {
2080 print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") .
2081 " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'refid'})}, "log");
2082 } elsif ($tag{'reftype'} eq "blob") {
2083 print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw");
2088 if (defined $extra) {
2090 "<td colspan=\"5\">$extra</td>\n" .
2096 sub git_heads_body {
2097 # uses global variable $project
2098 my ($taglist, $head, $from, $to, $extra) = @_;
2099 $from = 0 unless defined $from;
2100 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2102 print "<table class=\"heads\" cellspacing=\"0\">\n";
2104 for (my $i = $from; $i <= $to; $i++) {
2105 my $entry = $taglist->[$i];
2107 my $curr = $tag{'id'} eq $head;
2109 print "<tr class=\"dark\">\n";
2111 print "<tr class=\"light\">\n";
2114 print "<td><i>$tag{'age'}</i></td>\n" .
2115 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
2116 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'}),
2117 -class => "list name"},esc_html($tag{'name'})) .
2119 "<td class=\"link\">" .
2120 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") . " | " .
2121 $cgi->a({-href => href(action=>"log", hash=>$tag{'name'})}, "log") .
2125 if (defined $extra) {
2127 "<td colspan=\"3\">$extra</td>\n" .
2133 ## ======================================================================
2134 ## ======================================================================
2137 sub git_project_list {
2138 my $order = $cgi->param('o');
2139 if (defined $order && $order !~ m/project|descr|owner|age/) {
2140 die_error(undef, "Unknown order parameter");
2143 my @list = git_get_projects_list();
2146 die_error(undef, "No projects found");
2148 foreach my $pr (@list) {
2149 my $head = git_get_head_hash($pr->{'path'});
2150 if (!defined $head) {
2153 $git_dir = "$projectroot/$pr->{'path'}";
2154 my %co = parse_commit($head);
2158 $pr->{'commit'} = \%co;
2159 if (!defined $pr->{'descr'}) {
2160 my $descr = git_get_project_description($pr->{'path'}) || "";
2161 $pr->{'descr'} = chop_str($descr, 25, 5);
2163 if (!defined $pr->{'owner'}) {
2164 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
2166 push @projects, $pr;
2170 if (-f $home_text) {
2171 print "<div class=\"index_include\">\n";
2172 open (my $fd, $home_text);
2177 print "<table class=\"project_list\">\n" .
2179 $order ||= "project";
2180 if ($order eq "project") {
2181 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2182 print "<th>Project</th>\n";
2185 $cgi->a({-href => href(project=>undef, order=>'project'),
2186 -class => "header"}, "Project") .
2189 if ($order eq "descr") {
2190 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2191 print "<th>Description</th>\n";
2194 $cgi->a({-href => href(project=>undef, order=>'descr'),
2195 -class => "header"}, "Description") .
2198 if ($order eq "owner") {
2199 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2200 print "<th>Owner</th>\n";
2203 $cgi->a({-href => href(project=>undef, order=>'owner'),
2204 -class => "header"}, "Owner") .
2207 if ($order eq "age") {
2208 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2209 print "<th>Last Change</th>\n";
2212 $cgi->a({-href => href(project=>undef, order=>'age'),
2213 -class => "header"}, "Last Change") .
2216 print "<th></th>\n" .
2219 foreach my $pr (@projects) {
2221 print "<tr class=\"dark\">\n";
2223 print "<tr class=\"light\">\n";
2226 print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
2227 -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
2228 "<td>" . esc_html($pr->{'descr'}) . "</td>\n" .
2229 "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
2230 print "<td class=\"". age_class($pr->{'commit'}{'age'}) . "\">" .
2231 $pr->{'commit'}{'age_string'} . "</td>\n" .
2232 "<td class=\"link\">" .
2233 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
2234 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
2235 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") .
2243 sub git_project_index {
2244 my @projects = git_get_projects_list();
2247 -type => 'text/plain',
2248 -charset => 'utf-8',
2249 -content_disposition => qq(inline; filename="index.aux"));
2251 foreach my $pr (@projects) {
2252 if (!exists $pr->{'owner'}) {
2253 $pr->{'owner'} = get_file_owner("$projectroot/$project");
2256 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2257 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2258 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
2259 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
2263 print "$path $owner\n";
2268 my $descr = git_get_project_description($project) || "none";
2269 my $head = git_get_head_hash($project);
2270 my %co = parse_commit($head);
2271 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
2273 my $owner = git_get_project_owner($project);
2275 my $refs = git_get_references();
2277 git_print_page_nav('summary','', $head);
2279 print "<div class=\"title\"> </div>\n";
2280 print "<table cellspacing=\"0\">\n" .
2281 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
2282 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2283 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2284 # use per project git URL list in $projectroot/$project/cloneurl
2285 # or make project git URL from git base URL and project name
2286 my $url_tag = "URL";
2287 my @url_list = git_get_project_url_list($project);
2288 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2289 foreach my $git_url (@url_list) {
2290 next unless $git_url;
2291 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2296 open my $fd, "-|", git_cmd(), "rev-list", "--max-count=17",
2297 git_get_head_hash($project)
2298 or die_error(undef, "Open git-rev-list failed");
2299 my @revlist = map { chomp; $_ } <$fd>;
2301 git_print_header_div('shortlog');
2302 git_shortlog_body(\@revlist, 0, 15, $refs,
2303 $cgi->a({-href => href(action=>"shortlog")}, "..."));
2305 my $taglist = git_get_refs_list("refs/tags");
2306 if (defined @$taglist) {
2307 git_print_header_div('tags');
2308 git_tags_body($taglist, 0, 15,
2309 $cgi->a({-href => href(action=>"tags")}, "..."));
2312 my $headlist = git_get_refs_list("refs/heads");
2313 if (defined @$headlist) {
2314 git_print_header_div('heads');
2315 git_heads_body($headlist, $head, 0, 15,
2316 $cgi->a({-href => href(action=>"heads")}, "..."));
2323 my $head = git_get_head_hash($project);
2325 git_print_page_nav('','', $head,undef,$head);
2326 my %tag = parse_tag($hash);
2327 git_print_header_div('commit', esc_html($tag{'name'}), $hash);
2328 print "<div class=\"title_text\">\n" .
2329 "<table cellspacing=\"0\">\n" .
2331 "<td>object</td>\n" .
2332 "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
2333 $tag{'object'}) . "</td>\n" .
2334 "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
2335 $tag{'type'}) . "</td>\n" .
2337 if (defined($tag{'author'})) {
2338 my %ad = parse_date($tag{'epoch'}, $tag{'tz'});
2339 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
2340 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2341 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2344 print "</table>\n\n" .
2346 print "<div class=\"page_body\">";
2347 my $comment = $tag{'comment'};
2348 foreach my $line (@$comment) {
2349 print esc_html($line) . "<br/>\n";
2359 my ($have_blame) = gitweb_check_feature('blame');
2361 die_error('403 Permission denied', "Permission denied");
2363 die_error('404 Not Found', "File name not defined") if (!$file_name);
2364 $hash_base ||= git_get_head_hash($project);
2365 die_error(undef, "Couldn't find base commit") unless ($hash_base);
2366 my %co = parse_commit($hash_base)
2367 or die_error(undef, "Reading commit failed");
2368 if (!defined $hash) {
2369 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
2370 or die_error(undef, "Error looking up file");
2372 $ftype = git_get_type($hash);
2373 if ($ftype !~ "blob") {
2374 die_error("400 Bad Request", "Object is not a blob");
2376 open ($fd, "-|", git_cmd(), "blame", '-l', $file_name, $hash_base)
2377 or die_error(undef, "Open git-blame failed");
2380 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2383 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
2385 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2386 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2387 git_print_page_path($file_name, $ftype, $hash_base);
2388 my @rev_color = (qw(light2 dark2));
2389 my $num_colors = scalar(@rev_color);
2390 my $current_color = 0;
2393 <div class="page_body">
2394 <table class="blame">
2395 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2398 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2400 my $rev = substr($full_rev, 0, 8);
2404 if (!defined $last_rev) {
2405 $last_rev = $full_rev;
2406 } elsif ($last_rev ne $full_rev) {
2407 $last_rev = $full_rev;
2408 $current_color = ++$current_color % $num_colors;
2410 print "<tr class=\"$rev_color[$current_color]\">\n";
2411 print "<td class=\"sha1\">" .
2412 $cgi->a({-href => href(action=>"commit", hash=>$full_rev, file_name=>$file_name)},
2413 esc_html($rev)) . "</td>\n";
2414 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2415 esc_html($lineno) . "</a></td>\n";
2416 print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
2422 or print "Reading blob failed\n";
2429 my ($have_blame) = gitweb_check_feature('blame');
2431 die_error('403 Permission denied', "Permission denied");
2433 die_error('404 Not Found', "File name not defined") if (!$file_name);
2434 $hash_base ||= git_get_head_hash($project);
2435 die_error(undef, "Couldn't find base commit") unless ($hash_base);
2436 my %co = parse_commit($hash_base)
2437 or die_error(undef, "Reading commit failed");
2438 if (!defined $hash) {
2439 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
2440 or die_error(undef, "Error lookup file");
2442 open ($fd, "-|", git_cmd(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2443 or die_error(undef, "Open git-annotate failed");
2446 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2449 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
2451 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2452 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2453 git_print_page_path($file_name, 'blob', $hash_base);
2454 print "<div class=\"page_body\">\n";
2456 <table class="blame">
2465 my @line_class = (qw(light dark));
2466 my $line_class_len = scalar (@line_class);
2467 my $line_class_num = $#line_class;
2468 while (my $line = <$fd>) {
2480 $line_class_num = ($line_class_num + 1) % $line_class_len;
2482 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2489 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
2492 $short_rev = substr ($long_rev, 0, 8);
2493 $age = time () - $time;
2494 $age_str = age_string ($age);
2495 $age_str =~ s/ / /g;
2496 $age_class = age_class($age);
2497 $author = esc_html ($author);
2498 $author =~ s/ / /g;
2500 $data = untabify($data);
2501 $data = esc_html ($data);
2504 <tr class="$line_class[$line_class_num]">
2505 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2506 <td class="$age_class">$age_str</td>
2508 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2509 <td class="pre">$data</td>
2512 } # while (my $line = <$fd>)
2513 print "</table>\n\n";
2515 or print "Reading blob failed.\n";
2521 my $head = git_get_head_hash($project);
2523 git_print_page_nav('','', $head,undef,$head);
2524 git_print_header_div('summary', $project);
2526 my $taglist = git_get_refs_list("refs/tags");
2527 if (defined @$taglist) {
2528 git_tags_body($taglist);
2534 my $head = git_get_head_hash($project);
2536 git_print_page_nav('','', $head,undef,$head);
2537 git_print_header_div('summary', $project);
2539 my $taglist = git_get_refs_list("refs/heads");
2540 if (defined @$taglist) {
2541 git_heads_body($taglist, $head);
2546 sub git_blob_plain {
2549 if (!defined $hash) {
2550 if (defined $file_name) {
2551 my $base = $hash_base || git_get_head_hash($project);
2552 $hash = git_get_hash_by_path($base, $file_name, "blob")
2553 or die_error(undef, "Error lookup file");
2555 die_error(undef, "No file name defined");
2557 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2558 # blobs defined by non-textual hash id's can be cached
2563 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
2564 or die_error(undef, "Couldn't cat $file_name, $hash");
2566 $type ||= blob_mimetype($fd, $file_name);
2568 # save as filename, even when no $file_name is given
2569 my $save_as = "$hash";
2570 if (defined $file_name) {
2571 $save_as = $file_name;
2572 } elsif ($type =~ m/^text\//) {
2579 -content_disposition => "inline; filename=\"$save_as\"");
2581 binmode STDOUT, ':raw';
2583 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
2591 if (!defined $hash) {
2592 if (defined $file_name) {
2593 my $base = $hash_base || git_get_head_hash($project);
2594 $hash = git_get_hash_by_path($base, $file_name, "blob")
2595 or die_error(undef, "Error lookup file");
2597 die_error(undef, "No file name defined");
2599 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2600 # blobs defined by non-textual hash id's can be cached
2604 my ($have_blame) = gitweb_check_feature('blame');
2605 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
2606 or die_error(undef, "Couldn't cat $file_name, $hash");
2607 my $mimetype = blob_mimetype($fd, $file_name);
2608 if ($mimetype !~ m/^text\//) {
2610 return git_blob_plain($mimetype);
2612 git_header_html(undef, $expires);
2613 my $formats_nav = '';
2614 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2615 if (defined $file_name) {
2618 $cgi->a({-href => href(action=>"blame", hash_base=>$hash_base,
2619 hash=>$hash, file_name=>$file_name)},
2624 $cgi->a({-href => href(action=>"blob_plain",
2625 hash=>$hash, file_name=>$file_name)},
2628 $cgi->a({-href => href(action=>"blob",
2629 hash_base=>"HEAD", file_name=>$file_name)},
2633 $cgi->a({-href => href(action=>"blob_plain", hash=>$hash)}, "plain");
2635 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2636 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2638 print "<div class=\"page_nav\">\n" .
2639 "<br/><br/></div>\n" .
2640 "<div class=\"title\">$hash</div>\n";
2642 git_print_page_path($file_name, "blob", $hash_base);
2643 print "<div class=\"page_body\">\n";
2645 while (my $line = <$fd>) {
2648 $line = untabify($line);
2649 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2650 $nr, $nr, $nr, esc_html($line);
2653 or print "Reading blob failed.\n";
2659 if (!defined $hash) {
2660 $hash = git_get_head_hash($project);
2661 if (defined $file_name) {
2662 my $base = $hash_base || $hash;
2663 $hash = git_get_hash_by_path($base, $file_name, "tree");
2665 if (!defined $hash_base) {
2670 open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
2671 or die_error(undef, "Open git-ls-tree failed");
2672 my @entries = map { chomp; $_ } <$fd>;
2673 close $fd or die_error(undef, "Reading tree failed");
2676 my $refs = git_get_references();
2677 my $ref = format_ref_marker($refs, $hash_base);
2680 my ($have_blame) = gitweb_check_feature('blame');
2681 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2682 git_print_page_nav('tree','', $hash_base);
2683 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
2686 print "<div class=\"page_nav\">\n";
2687 print "<br/><br/></div>\n";
2688 print "<div class=\"title\">$hash</div>\n";
2690 if (defined $file_name) {
2691 $base = esc_html("$file_name/");
2693 git_print_page_path($file_name, 'tree', $hash_base);
2694 print "<div class=\"page_body\">\n";
2695 print "<table cellspacing=\"0\">\n";
2697 foreach my $line (@entries) {
2698 my %t = parse_ls_tree_line($line, -z => 1);
2701 print "<tr class=\"dark\">\n";
2703 print "<tr class=\"light\">\n";
2707 git_print_tree_entry(\%t, $base, $hash_base, $have_blame);
2711 print "</table>\n" .
2718 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
2719 my $have_snapshot = (defined $ctype && defined $suffix);
2720 if (!$have_snapshot) {
2721 die_error('403 Permission denied', "Permission denied");
2724 if (!defined $hash) {
2725 $hash = git_get_head_hash($project);
2728 my $filename = basename($project) . "-$hash.tar.$suffix";
2730 print $cgi->header(-type => 'application/x-tar',
2731 -content_encoding => $ctype,
2732 -content_disposition => "inline; filename=\"$filename\"",
2733 -status => '200 OK');
2735 my $git_command = git_cmd_str();
2736 open my $fd, "-|", "$git_command tar-tree $hash \'$project\' | $command" or
2737 die_error(undef, "Execute git-tar-tree failed.");
2738 binmode STDOUT, ':raw';
2740 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
2746 my $head = git_get_head_hash($project);
2747 if (!defined $hash) {
2750 if (!defined $page) {
2753 my $refs = git_get_references();
2755 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2756 open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash
2757 or die_error(undef, "Open git-rev-list failed");
2758 my @revlist = map { chomp; $_ } <$fd>;
2761 my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#revlist);
2764 git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
2767 my %co = parse_commit($hash);
2769 git_print_header_div('summary', $project);
2770 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2772 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2773 my $commit = $revlist[$i];
2774 my $ref = format_ref_marker($refs, $commit);
2775 my %co = parse_commit($commit);
2777 my %ad = parse_date($co{'author_epoch'});
2778 git_print_header_div('commit',
2779 "<span class=\"age\">$co{'age_string'}</span>" .
2780 esc_html($co{'title'}) . $ref,
2782 print "<div class=\"title_text\">\n" .
2783 "<div class=\"log_link\">\n" .
2784 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
2786 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
2789 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2792 print "<div class=\"log_body\">\n";
2793 git_print_simplified_log($co{'comment'});
2800 my %co = parse_commit($hash);
2802 die_error(undef, "Unknown commit object");
2804 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
2805 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
2807 my $parent = $co{'parent'};
2808 if (!defined $parent) {
2811 open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $parent, $hash
2812 or die_error(undef, "Open git-diff-tree failed");
2813 my @difftree = map { chomp; $_ } <$fd>;
2814 close $fd or die_error(undef, "Reading git-diff-tree failed");
2816 # non-textual hash id's can be cached
2818 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2821 my $refs = git_get_references();
2822 my $ref = format_ref_marker($refs, $co{'id'});
2824 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
2825 my $have_snapshot = (defined $ctype && defined $suffix);
2827 my $formats_nav = '';
2828 if (defined $file_name && defined $co{'parent'}) {
2829 my $parent = $co{'parent'};
2831 $cgi->a({-href => href(action=>"blame", hash_parent=>$parent, file_name=>$file_name)},
2834 git_header_html(undef, $expires);
2835 git_print_page_nav('commit', defined $co{'parent'} ? '' : 'commitdiff',
2836 $hash, $co{'tree'}, $hash,
2839 if (defined $co{'parent'}) {
2840 git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash);
2842 git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash);
2844 print "<div class=\"title_text\">\n" .
2845 "<table cellspacing=\"0\">\n";
2846 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
2848 "<td></td><td> $ad{'rfc2822'}";
2849 if ($ad{'hour_local'} < 6) {
2850 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2851 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2853 printf(" (%02d:%02d %s)",
2854 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2858 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
2859 print "<tr><td></td><td> $cd{'rfc2822'}" .
2860 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2862 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2865 "<td class=\"sha1\">" .
2866 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),
2867 class => "list"}, $co{'tree'}) .
2869 "<td class=\"link\">" .
2870 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},
2872 if ($have_snapshot) {
2874 $cgi->a({-href => href(action=>"snapshot", hash=>$hash)}, "snapshot");
2878 my $parents = $co{'parents'};
2879 foreach my $par (@$parents) {
2882 "<td class=\"sha1\">" .
2883 $cgi->a({-href => href(action=>"commit", hash=>$par),
2884 class => "list"}, $par) .
2886 "<td class=\"link\">" .
2887 $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") .
2889 $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "diff") .
2896 print "<div class=\"page_body\">\n";
2897 git_print_log($co{'comment'});
2900 git_difftree_body(\@difftree, $hash, $parent);
2906 my $format = shift || 'html';
2913 # preparing $fd and %diffinfo for git_patchset_body
2915 if (defined $hash_base && defined $hash_parent_base) {
2916 if (defined $file_name) {
2918 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
2920 or die_error(undef, "Open git-diff-tree failed");
2921 @difftree = map { chomp; $_ } <$fd>;
2923 or die_error(undef, "Reading git-diff-tree failed");
2925 or die_error('404 Not Found', "Blob diff not found");
2927 } elsif (defined $hash &&
2928 $hash =~ /[0-9a-fA-F]{40}/) {
2929 # try to find filename from $hash
2931 # read filtered raw output
2932 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
2933 or die_error(undef, "Open git-diff-tree failed");
2935 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
2937 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
2938 map { chomp; $_ } <$fd>;
2940 or die_error(undef, "Reading git-diff-tree failed");
2942 or die_error('404 Not Found', "Blob diff not found");
2945 die_error('404 Not Found', "Missing one of the blob diff parameters");
2948 if (@difftree > 1) {
2949 die_error('404 Not Found', "Ambiguous blob diff specification");
2952 %diffinfo = parse_difftree_raw_line($difftree[0]);
2953 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
2954 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
2956 $hash_parent ||= $diffinfo{'from_id'};
2957 $hash ||= $diffinfo{'to_id'};
2959 # non-textual hash id's can be cached
2960 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
2961 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
2966 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
2967 '-p', $hash_parent_base, $hash_base,
2969 or die_error(undef, "Open git-diff-tree failed");
2972 # old/legacy style URI
2973 if (!%diffinfo && # if new style URI failed
2974 defined $hash && defined $hash_parent) {
2975 # fake git-diff-tree raw output
2976 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
2977 $diffinfo{'from_id'} = $hash_parent;
2978 $diffinfo{'to_id'} = $hash;
2979 if (defined $file_name) {
2980 if (defined $file_parent) {
2981 $diffinfo{'status'} = '2';
2982 $diffinfo{'from_file'} = $file_parent;
2983 $diffinfo{'to_file'} = $file_name;
2984 } else { # assume not renamed
2985 $diffinfo{'status'} = '1';
2986 $diffinfo{'from_file'} = $file_name;
2987 $diffinfo{'to_file'} = $file_name;
2989 } else { # no filename given
2990 $diffinfo{'status'} = '2';
2991 $diffinfo{'from_file'} = $hash_parent;
2992 $diffinfo{'to_file'} = $hash;
2995 # non-textual hash id's can be cached
2996 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
2997 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3002 open $fd, "-|", git_cmd(), "diff", '-p', @diff_opts, $hash_parent, $hash
3003 or die_error(undef, "Open git-diff failed");
3005 die_error('404 Not Found', "Missing one of the blob diff parameters")
3010 if ($format eq 'html') {
3012 $cgi->a({-href => href(action=>"blobdiff_plain",
3013 hash=>$hash, hash_parent=>$hash_parent,
3014 hash_base=>$hash_base, hash_parent_base=>$hash_parent_base,
3015 file_name=>$file_name, file_parent=>$file_parent)},
3017 git_header_html(undef, $expires);
3018 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
3019 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3020 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
3022 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3023 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3025 if (defined $file_name) {
3026 git_print_page_path($file_name, "blob", $hash_base);
3028 print "<div class=\"page_path\"></div>\n";
3031 } elsif ($format eq 'plain') {
3033 -type => 'text/plain',
3034 -charset => 'utf-8',
3035 -expires => $expires,
3036 -content_disposition => qq(inline; filename="${file_name}.patch"));
3038 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3041 die_error(undef, "Unknown blobdiff format");
3045 if ($format eq 'html') {
3046 print "<div class=\"page_body\">\n";
3048 git_patchset_body($fd, [ \%diffinfo ], $hash_base, $hash_parent_base);
3051 print "</div>\n"; # class="page_body"
3055 while (my $line = <$fd>) {
3056 $line =~ s!a/($hash|$hash_parent)!a/$diffinfo{'from_file'}!g;
3057 $line =~ s!b/($hash|$hash_parent)!b/$diffinfo{'to_file'}!g;
3061 last if $line =~ m!^\+\+\+!;
3069 sub git_blobdiff_plain {
3070 git_blobdiff('plain');
3073 sub git_commitdiff {
3074 my $format = shift || 'html';
3075 my %co = parse_commit($hash);
3077 die_error(undef, "Unknown commit object");
3079 if (!defined $hash_parent) {
3080 $hash_parent = $co{'parent'} || '--root';
3086 if ($format eq 'html') {
3087 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
3088 "--patch-with-raw", "--full-index", $hash_parent, $hash
3089 or die_error(undef, "Open git-diff-tree failed");
3091 while (chomp(my $line = <$fd>)) {
3092 # empty line ends raw part of diff-tree output
3094 push @difftree, $line;
3097 } elsif ($format eq 'plain') {
3098 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
3099 '-p', $hash_parent, $hash
3100 or die_error(undef, "Open git-diff-tree failed");
3103 die_error(undef, "Unknown commitdiff format");
3106 # non-textual hash id's can be cached
3108 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3112 # write commit message
3113 if ($format eq 'html') {
3114 my $refs = git_get_references();
3115 my $ref = format_ref_marker($refs, $co{'id'});
3117 $cgi->a({-href => href(action=>"commitdiff_plain",
3118 hash=>$hash, hash_parent=>$hash_parent)},
3121 git_header_html(undef, $expires);
3122 git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3123 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
3124 git_print_authorship(\%co);
3125 print "<div class=\"page_body\">\n";
3126 print "<div class=\"log\">\n";
3127 git_print_simplified_log($co{'comment'}, 1); # skip title
3128 print "</div>\n"; # class="log"
3130 } elsif ($format eq 'plain') {
3131 my $refs = git_get_references("tags");
3132 my $tagname = git_get_rev_name_tags($hash);
3133 my $filename = basename($project) . "-$hash.patch";
3136 -type => 'text/plain',
3137 -charset => 'utf-8',
3138 -expires => $expires,
3139 -content_disposition => qq(inline; filename="$filename"));
3140 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
3143 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3144 Subject: $co{'title'}
3146 print "X-Git-Tag: $tagname\n" if $tagname;
3147 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3149 foreach my $line (@{$co{'comment'}}) {
3156 if ($format eq 'html') {
3157 git_difftree_body(\@difftree, $hash, $hash_parent);
3160 git_patchset_body($fd, \@difftree, $hash, $hash_parent);
3162 print "</div>\n"; # class="page_body"
3165 } elsif ($format eq 'plain') {
3169 or print "Reading git-diff-tree failed\n";
3173 sub git_commitdiff_plain {
3174 git_commitdiff('plain');
3178 if (!defined $hash_base) {
3179 $hash_base = git_get_head_hash($project);
3181 if (!defined $page) {
3185 my %co = parse_commit($hash_base);
3187 die_error(undef, "Unknown commit object");
3190 my $refs = git_get_references();
3191 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3193 if (!defined $hash && defined $file_name) {
3194 $hash = git_get_hash_by_path($hash_base, $file_name);
3196 if (defined $hash) {
3197 $ftype = git_get_type($hash);
3201 git_cmd(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3202 or die_error(undef, "Open git-rev-list-failed");
3203 my @revlist = map { chomp; $_ } <$fd>;
3205 or die_error(undef, "Reading git-rev-list failed");
3207 my $paging_nav = '';
3210 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3211 file_name=>$file_name)},
3213 $paging_nav .= " ⋅ " .
3214 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3215 file_name=>$file_name, page=>$page-1),
3216 -accesskey => "p", -title => "Alt-p"}, "prev");
3218 $paging_nav .= "first";
3219 $paging_nav .= " ⋅ prev";
3221 if ($#revlist >= (100 * ($page+1)-1)) {
3222 $paging_nav .= " ⋅ " .
3223 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3224 file_name=>$file_name, page=>$page+1),
3225 -accesskey => "n", -title => "Alt-n"}, "next");
3227 $paging_nav .= " ⋅ next";
3230 if ($#revlist >= (100 * ($page+1)-1)) {
3232 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3233 file_name=>$file_name, page=>$page+1),
3234 -title => "Alt-n"}, "next");
3238 git_print_page_nav('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3239 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
3240 git_print_page_path($file_name, $ftype, $hash_base);
3242 git_history_body(\@revlist, ($page * 100), $#revlist,
3243 $refs, $hash_base, $ftype, $next_link);
3249 if (!defined $searchtext) {
3250 die_error(undef, "Text field empty");
3252 if (!defined $hash) {
3253 $hash = git_get_head_hash($project);
3255 my %co = parse_commit($hash);
3257 die_error(undef, "Unknown commit object");
3260 my $commit_search = 1;
3261 my $author_search = 0;
3262 my $committer_search = 0;
3263 my $pickaxe_search = 0;
3264 if ($searchtext =~ s/^author\\://i) {
3266 } elsif ($searchtext =~ s/^committer\\://i) {
3267 $committer_search = 1;
3268 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3270 $pickaxe_search = 1;
3272 # pickaxe may take all resources of your box and run for several minutes
3273 # with every query - so decide by yourself how public you make this feature
3274 my ($have_pickaxe) = gitweb_check_feature('pickaxe');
3275 if (!$have_pickaxe) {
3276 die_error('403 Permission denied', "Permission denied");
3280 git_print_page_nav('','', $hash,$co{'tree'},$hash);
3281 git_print_header_div('commit', esc_html($co{'title'}), $hash);
3283 print "<table cellspacing=\"0\">\n";
3285 if ($commit_search) {
3287 open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", $hash or next;
3288 while (my $commit_text = <$fd>) {
3289 if (!grep m/$searchtext/i, $commit_text) {
3292 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3295 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3298 my @commit_lines = split "\n", $commit_text;
3299 my %co = parse_commit(undef, \@commit_lines);
3304 print "<tr class=\"dark\">\n";
3306 print "<tr class=\"light\">\n";
3309 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3310 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3312 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"},
3313 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
3314 my $comment = $co{'comment'};
3315 foreach my $line (@$comment) {
3316 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3317 my $lead = esc_html($1) || "";
3318 $lead = chop_str($lead, 30, 10);
3319 my $match = esc_html($2) || "";
3320 my $trail = esc_html($3) || "";
3321 $trail = chop_str($trail, 30, 10);
3322 my $text = "$lead<span class=\"match\">$match</span>$trail";
3323 print chop_str($text, 80, 5) . "<br/>\n";
3327 "<td class=\"link\">" .
3328 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
3330 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
3337 if ($pickaxe_search) {
3339 my $git_command = git_cmd_str();
3340 open my $fd, "-|", "$git_command rev-list $hash | " .
3341 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3344 while (my $line = <$fd>) {
3345 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3348 $set{'from_id'} = $3;
3350 $set{'id'} = $set{'to_id'};
3351 if ($set{'id'} =~ m/0{40}/) {
3352 $set{'id'} = $set{'from_id'};
3354 if ($set{'id'} =~ m/0{40}/) {
3358 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3361 print "<tr class=\"dark\">\n";
3363 print "<tr class=\"light\">\n";
3366 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3367 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3369 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
3370 -class => "list subject"},
3371 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
3372 while (my $setref = shift @files) {
3374 print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},
3375 hash=>$set{'id'}, file_name=>$set{'file'}),
3377 "<span class=\"match\">" . esc_html($set{'file'}) . "</span>") .
3381 "<td class=\"link\">" .
3382 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
3384 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
3388 %co = parse_commit($1);
3398 my $head = git_get_head_hash($project);
3399 if (!defined $hash) {
3402 if (!defined $page) {
3405 my $refs = git_get_references();
3407 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3408 open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash
3409 or die_error(undef, "Open git-rev-list failed");
3410 my @revlist = map { chomp; $_ } <$fd>;
3413 my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, $#revlist);
3415 if ($#revlist >= (100 * ($page+1)-1)) {
3417 $cgi->a({-href => href(action=>"shortlog", hash=>$hash, page=>$page+1),
3418 -title => "Alt-n"}, "next");
3423 git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);
3424 git_print_header_div('summary', $project);
3426 git_shortlog_body(\@revlist, ($page * 100), $#revlist, $refs, $next_link);
3431 ## ......................................................................
3432 ## feeds (RSS, OPML)
3435 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3436 open my $fd, "-|", git_cmd(), "rev-list", "--max-count=150", git_get_head_hash($project)
3437 or die_error(undef, "Open git-rev-list failed");
3438 my @revlist = map { chomp; $_ } <$fd>;
3439 close $fd or die_error(undef, "Reading git-rev-list failed");
3440 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
3442 <?xml version="1.0" encoding="utf-8"?>
3443 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3445 <title>$project $my_uri $my_url</title>
3446 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3447 <description>$project log</description>
3448 <language>en</language>
3451 for (my $i = 0; $i <= $#revlist; $i++) {
3452 my $commit = $revlist[$i];
3453 my %co = parse_commit($commit);
3454 # we read 150, we always show 30 and the ones more recent than 48 hours
3455 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3458 my %cd = parse_date($co{'committer_epoch'});
3459 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
3460 $co{'parent'}, $co{'id'}
3462 my @difftree = map { chomp; $_ } <$fd>;
3467 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) .
3469 "<author>" . esc_html($co{'author'}) . "</author>\n" .
3470 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3471 "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3472 "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3473 "<description>" . esc_html($co{'title'}) . "</description>\n" .
3474 "<content:encoded>" .
3476 my $comment = $co{'comment'};
3477 foreach my $line (@$comment) {
3478 $line = decode("utf8", $line, Encode::FB_DEFAULT);
3479 print "$line<br/>\n";
3482 foreach my $line (@difftree) {
3483 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3486 my $file = validate_input(unquote($7));
3487 $file = decode("utf8", $file, Encode::FB_DEFAULT);
3488 print "$file<br/>\n";
3491 "</content:encoded>\n" .
3494 print "</channel></rss>";
3498 my @list = git_get_projects_list();
3500 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
3502 <?xml version="1.0" encoding="utf-8"?>
3503 <opml version="1.0">
3505 <title>$site_name Git OPML Export</title>
3508 <outline text="git RSS feeds">
3511 foreach my $pr (@list) {
3513 my $head = git_get_head_hash($proj{'path'});
3514 if (!defined $head) {
3517 $git_dir = "$projectroot/$proj{'path'}";
3518 my %co = parse_commit($head);
3523 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
3524 my $rss = "$my_url?p=$proj{'path'};a=rss";
3525 my $html = "$my_url?p=$proj{'path'};a=summary";
3526 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";