gitweb: Correct typo: '==' instead of 'eq' in git_difftree_body
[git/jnareb-git.git] / gitweb / gitweb.perl
blobe7d7bd7ac079527e30aacc2f683271b8116c17cb
1 #!/usr/bin/perl
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
10 use strict;
11 use warnings;
12 use CGI qw(:standard :escapeHTML -nosticky);
13 use CGI::Util qw(unescape);
14 use CGI::Carp qw(fatalsToBrowser);
15 use Encode;
16 use Fcntl ':mode';
17 use File::Find qw();
18 use File::Basename qw(basename);
19 binmode STDOUT, ':utf8';
21 our $cgi = new CGI;
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++";
49 # URI of GIT logo
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.
71 our %feature = (
72 # feature => {
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,
80 # and is taken to be current parameters of the feature
82 # use gitweb_check_feature(<feature>) to check if <feature> is enabled;
83 # to be more exact to get current parameters of <feature>;
84 # gitweb_check_feature(<feature>) returns array (list) of current options
86 'blame' => {
87 'sub' => \&feature_blame,
88 'override' => 0,
89 'default' => [0]},
91 'snapshot' => {
92 'sub' => \&feature_snapshot,
93 'override' => 0,
94 # => [content-encoding, suffix, program]
95 'default' => ['x-gzip', 'gz', 'gzip']},
98 sub gitweb_check_feature {
99 my ($name) = @_;
100 return undef unless exists $feature{$name};
101 my ($sub, $override, @defaults) = (
102 $feature{$name}{'sub'},
103 $feature{$name}{'override'},
104 @{$feature{$name}{'default'}});
105 if (!$override) { return @defaults; }
106 return $sub->(@defaults);
109 # To enable system wide have in $GITWEB_CONFIG
110 # $feature{'blame'}{'default'} = [1];
111 # To have project specific config enable override in $GITWEB_CONFIG
112 # $feature{'blame'}{'override'} = 1;
113 # and in project config gitweb.blame = 0|1;
115 sub feature_blame {
116 my ($val) = git_get_project_config('blame', '--bool');
118 if ($val eq 'true') {
119 return (1);
120 } elsif ($val eq 'false') {
121 return (0);
124 return ($_[0]);
127 # To disable system wide have in $GITWEB_CONFIG
128 # $feature{'snapshot'}{'default'} = [undef];
129 # To have project specific config enable override in $GITWEB_CONFIG
130 # $feature{'blame'}{'override'} = 1;
131 # and in project config gitweb.snapshot = none|gzip|bzip2
133 sub feature_snapshot {
134 my ($ctype, $suffix, $command) = @_;
136 my ($val) = git_get_project_config('snapshot');
138 if ($val eq 'gzip') {
139 return ('x-gzip', 'gz', 'gzip');
140 } elsif ($val eq 'bzip2') {
141 return ('x-bzip2', 'bz2', 'bzip2');
142 } elsif ($val eq 'none') {
143 return ();
146 return ($ctype, $suffix, $command);
149 # rename detection options for git-diff and git-diff-tree
150 # - default is '-M', with the cost proportional to
151 # (number of removed files) * (number of new files).
152 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
153 # (number of changed files + number of removed files) * (number of new files)
154 # - even more costly is '-C', '--find-copies-harder' with cost
155 # (number of files in the original tree) * (number of new files)
156 # - one might want to include '-B' option, e.g. '-B', '-M'
157 our @diff_opts = ('-M'); # taken from git_commit
159 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
160 require $GITWEB_CONFIG if -e $GITWEB_CONFIG;
162 # version of the core git binary
163 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
165 $projects_list ||= $projectroot;
167 # ======================================================================
168 # input validation and dispatch
169 our $action = $cgi->param('a');
170 if (defined $action) {
171 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
172 die_error(undef, "Invalid action parameter");
176 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
177 if (defined $project) {
178 $project =~ s|^/||;
179 $project =~ s|/$||;
180 $project = undef unless $project;
182 if (defined $project) {
183 if (!validate_input($project)) {
184 die_error(undef, "Invalid project parameter");
186 if (!(-d "$projectroot/$project")) {
187 die_error(undef, "No such directory");
189 if (!(-e "$projectroot/$project/HEAD")) {
190 die_error(undef, "No such project");
192 $ENV{'GIT_DIR'} = "$projectroot/$project";
195 our $file_name = $cgi->param('f');
196 if (defined $file_name) {
197 if (!validate_input($file_name)) {
198 die_error(undef, "Invalid file parameter");
202 our $file_parent = $cgi->param('fp');
203 if (defined $file_parent) {
204 if (!validate_input($file_parent)) {
205 die_error(undef, "Invalid file parent parameter");
209 our $hash = $cgi->param('h');
210 if (defined $hash) {
211 if (!validate_input($hash)) {
212 die_error(undef, "Invalid hash parameter");
216 our $hash_parent = $cgi->param('hp');
217 if (defined $hash_parent) {
218 if (!validate_input($hash_parent)) {
219 die_error(undef, "Invalid hash parent parameter");
223 our $hash_base = $cgi->param('hb');
224 if (defined $hash_base) {
225 if (!validate_input($hash_base)) {
226 die_error(undef, "Invalid hash base parameter");
230 our $hash_parent_base = $cgi->param('hpb');
231 if (defined $hash_parent_base) {
232 if (!validate_input($hash_parent_base)) {
233 die_error(undef, "Invalid hash parent base parameter");
237 our $page = $cgi->param('pg');
238 if (defined $page) {
239 if ($page =~ m/[^0-9]$/) {
240 die_error(undef, "Invalid page parameter");
244 our $searchtext = $cgi->param('s');
245 if (defined $searchtext) {
246 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) {
247 die_error(undef, "Invalid search parameter");
249 $searchtext = quotemeta $searchtext;
252 # dispatch
253 my %actions = (
254 "blame" => \&git_blame2,
255 "blobdiff" => \&git_blobdiff,
256 "blobdiff_plain" => \&git_blobdiff_plain,
257 "blob" => \&git_blob,
258 "blob_plain" => \&git_blob_plain,
259 "commitdiff" => \&git_commitdiff,
260 "commitdiff_plain" => \&git_commitdiff_plain,
261 "commit" => \&git_commit,
262 "heads" => \&git_heads,
263 "history" => \&git_history,
264 "log" => \&git_log,
265 "rss" => \&git_rss,
266 "search" => \&git_search,
267 "shortlog" => \&git_shortlog,
268 "summary" => \&git_summary,
269 "tag" => \&git_tag,
270 "tags" => \&git_tags,
271 "tree" => \&git_tree,
272 "snapshot" => \&git_snapshot,
273 # those below don't need $project
274 "opml" => \&git_opml,
275 "project_list" => \&git_project_list,
276 "project_index" => \&git_project_index,
279 if (defined $project) {
280 $action ||= 'summary';
281 } else {
282 $action ||= 'project_list';
284 if (!defined($actions{$action})) {
285 die_error(undef, "Unknown action");
287 $actions{$action}->();
288 exit;
290 ## ======================================================================
291 ## action links
293 sub href(%) {
294 my %params = @_;
296 my @mapping = (
297 project => "p",
298 action => "a",
299 file_name => "f",
300 file_parent => "fp",
301 hash => "h",
302 hash_parent => "hp",
303 hash_base => "hb",
304 hash_parent_base => "hpb",
305 page => "pg",
306 searchtext => "s",
308 my %mapping = @mapping;
310 $params{"project"} ||= $project;
312 my @result = ();
313 for (my $i = 0; $i < @mapping; $i += 2) {
314 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
315 if (defined $params{$name}) {
316 push @result, $symbol . "=" . esc_param($params{$name});
319 return "$my_uri?" . join(';', @result);
323 ## ======================================================================
324 ## validation, quoting/unquoting and escaping
326 sub validate_input {
327 my $input = shift;
329 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
330 return $input;
332 if ($input =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
333 return undef;
335 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\-\+\#\~\%]/) {
336 return undef;
338 return $input;
341 # quote unsafe chars, but keep the slash, even when it's not
342 # correct, but quoted slashes look too horrible in bookmarks
343 sub esc_param {
344 my $str = shift;
345 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
346 $str =~ s/\+/%2B/g;
347 $str =~ s/ /\+/g;
348 return $str;
351 # replace invalid utf8 character with SUBSTITUTION sequence
352 sub esc_html {
353 my $str = shift;
354 $str = decode("utf8", $str, Encode::FB_DEFAULT);
355 $str = escapeHTML($str);
356 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
357 return $str;
360 # git may return quoted and escaped filenames
361 sub unquote {
362 my $str = shift;
363 if ($str =~ m/^"(.*)"$/) {
364 $str = $1;
365 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
367 return $str;
370 # escape tabs (convert tabs to spaces)
371 sub untabify {
372 my $line = shift;
374 while ((my $pos = index($line, "\t")) != -1) {
375 if (my $count = (8 - ($pos % 8))) {
376 my $spaces = ' ' x $count;
377 $line =~ s/\t/$spaces/;
381 return $line;
384 ## ----------------------------------------------------------------------
385 ## HTML aware string manipulation
387 sub chop_str {
388 my $str = shift;
389 my $len = shift;
390 my $add_len = shift || 10;
392 # allow only $len chars, but don't cut a word if it would fit in $add_len
393 # if it doesn't fit, cut it if it's still longer than the dots we would add
394 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
395 my $body = $1;
396 my $tail = $2;
397 if (length($tail) > 4) {
398 $tail = " ...";
399 $body =~ s/&[^;]*$//; # remove chopped character entities
401 return "$body$tail";
404 ## ----------------------------------------------------------------------
405 ## functions returning short strings
407 # CSS class for given age value (in seconds)
408 sub age_class {
409 my $age = shift;
411 if ($age < 60*60*2) {
412 return "age0";
413 } elsif ($age < 60*60*24*2) {
414 return "age1";
415 } else {
416 return "age2";
420 # convert age in seconds to "nn units ago" string
421 sub age_string {
422 my $age = shift;
423 my $age_str;
425 if ($age > 60*60*24*365*2) {
426 $age_str = (int $age/60/60/24/365);
427 $age_str .= " years ago";
428 } elsif ($age > 60*60*24*(365/12)*2) {
429 $age_str = int $age/60/60/24/(365/12);
430 $age_str .= " months ago";
431 } elsif ($age > 60*60*24*7*2) {
432 $age_str = int $age/60/60/24/7;
433 $age_str .= " weeks ago";
434 } elsif ($age > 60*60*24*2) {
435 $age_str = int $age/60/60/24;
436 $age_str .= " days ago";
437 } elsif ($age > 60*60*2) {
438 $age_str = int $age/60/60;
439 $age_str .= " hours ago";
440 } elsif ($age > 60*2) {
441 $age_str = int $age/60;
442 $age_str .= " min ago";
443 } elsif ($age > 2) {
444 $age_str = int $age;
445 $age_str .= " sec ago";
446 } else {
447 $age_str .= " right now";
449 return $age_str;
452 # convert file mode in octal to symbolic file mode string
453 sub mode_str {
454 my $mode = oct shift;
456 if (S_ISDIR($mode & S_IFMT)) {
457 return 'drwxr-xr-x';
458 } elsif (S_ISLNK($mode)) {
459 return 'lrwxrwxrwx';
460 } elsif (S_ISREG($mode)) {
461 # git cares only about the executable bit
462 if ($mode & S_IXUSR) {
463 return '-rwxr-xr-x';
464 } else {
465 return '-rw-r--r--';
467 } else {
468 return '----------';
472 # convert file mode in octal to file type string
473 sub file_type {
474 my $mode = shift;
476 if ($mode !~ m/^[0-7]+$/) {
477 return $mode;
478 } else {
479 $mode = oct $mode;
482 if (S_ISDIR($mode & S_IFMT)) {
483 return "directory";
484 } elsif (S_ISLNK($mode)) {
485 return "symlink";
486 } elsif (S_ISREG($mode)) {
487 return "file";
488 } else {
489 return "unknown";
493 ## ----------------------------------------------------------------------
494 ## functions returning short HTML fragments, or transforming HTML fragments
495 ## which don't beling to other sections
497 # format line of commit message or tag comment
498 sub format_log_line_html {
499 my $line = shift;
501 $line = esc_html($line);
502 $line =~ s/ /&nbsp;/g;
503 if ($line =~ m/([0-9a-fA-F]{40})/) {
504 my $hash_text = $1;
505 if (git_get_type($hash_text) eq "commit") {
506 my $link =
507 $cgi->a({-href => href(action=>"commit", hash=>$hash_text),
508 -class => "text"}, $hash_text);
509 $line =~ s/$hash_text/$link/;
512 return $line;
515 # format marker of refs pointing to given object
516 sub format_ref_marker {
517 my ($refs, $id) = @_;
518 my $markers = '';
520 if (defined $refs->{$id}) {
521 foreach my $ref (@{$refs->{$id}}) {
522 my ($type, $name) = qw();
523 # e.g. tags/v2.6.11 or heads/next
524 if ($ref =~ m!^(.*?)s?/(.*)$!) {
525 $type = $1;
526 $name = $2;
527 } else {
528 $type = "ref";
529 $name = $ref;
532 $markers .= " <span class=\"$type\">" . esc_html($name) . "</span>";
536 if ($markers) {
537 return ' <span class="refs">'. $markers . '</span>';
538 } else {
539 return "";
543 # format, perhaps shortened and with markers, title line
544 sub format_subject_html {
545 my ($long, $short, $href, $extra) = @_;
546 $extra = '' unless defined($extra);
548 if (length($short) < length($long)) {
549 return $cgi->a({-href => $href, -class => "list subject",
550 -title => $long},
551 esc_html($short) . $extra);
552 } else {
553 return $cgi->a({-href => $href, -class => "list subject"},
554 esc_html($long) . $extra);
558 sub format_diff_line {
559 my $line = shift;
560 my $char = substr($line, 0, 1);
561 my $diff_class = "";
563 chomp $line;
565 if ($char eq '+') {
566 $diff_class = " add";
567 } elsif ($char eq "-") {
568 $diff_class = " rem";
569 } elsif ($char eq "@") {
570 $diff_class = " chunk_header";
571 } elsif ($char eq "\\") {
572 $diff_class = " incomplete";
574 $line = untabify($line);
575 return "<div class=\"diff$diff_class\">" . esc_html($line) . "</div>\n";
578 ## ----------------------------------------------------------------------
579 ## git utility subroutines, invoking git commands
581 # get HEAD ref of given project as hash
582 sub git_get_head_hash {
583 my $project = shift;
584 my $oENV = $ENV{'GIT_DIR'};
585 my $retval = undef;
586 $ENV{'GIT_DIR'} = "$projectroot/$project";
587 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
588 my $head = <$fd>;
589 close $fd;
590 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
591 $retval = $1;
594 if (defined $oENV) {
595 $ENV{'GIT_DIR'} = $oENV;
597 return $retval;
600 # get type of given object
601 sub git_get_type {
602 my $hash = shift;
604 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
605 my $type = <$fd>;
606 close $fd or return;
607 chomp $type;
608 return $type;
611 sub git_get_project_config {
612 my ($key, $type) = @_;
614 return unless ($key);
615 $key =~ s/^gitweb\.//;
616 return if ($key =~ m/\W/);
618 my @x = ($GIT, 'repo-config');
619 if (defined $type) { push @x, $type; }
620 push @x, "--get";
621 push @x, "gitweb.$key";
622 my $val = qx(@x);
623 chomp $val;
624 return ($val);
627 # get hash of given path at given ref
628 sub git_get_hash_by_path {
629 my $base = shift;
630 my $path = shift || return undef;
632 my $tree = $base;
634 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
635 or die_error(undef, "Open git-ls-tree failed");
636 my $line = <$fd>;
637 close $fd or return undef;
639 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
640 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
641 return $3;
644 ## ......................................................................
645 ## git utility functions, directly accessing git repository
647 # assumes that PATH is not symref
648 sub git_get_hash_by_ref {
649 my $path = shift;
651 open my $fd, "$projectroot/$path" or return undef;
652 my $head = <$fd>;
653 close $fd;
654 chomp $head;
655 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
656 return $head;
660 sub git_get_project_description {
661 my $path = shift;
663 open my $fd, "$projectroot/$path/description" or return undef;
664 my $descr = <$fd>;
665 close $fd;
666 chomp $descr;
667 return $descr;
670 sub git_get_project_url_list {
671 my $path = shift;
673 open my $fd, "$projectroot/$path/cloneurl" or return undef;
674 my @git_project_url_list = map { chomp; $_ } <$fd>;
675 close $fd;
677 return wantarray ? @git_project_url_list : \@git_project_url_list;
680 sub git_get_projects_list {
681 my @list;
683 if (-d $projects_list) {
684 # search in directory
685 my $dir = $projects_list;
686 opendir my ($dh), $dir or return undef;
687 while (my $dir = readdir($dh)) {
688 if (-e "$projectroot/$dir/HEAD") {
689 my $pr = {
690 path => $dir,
692 push @list, $pr
695 closedir($dh);
696 } elsif (-f $projects_list) {
697 # read from file(url-encoded):
698 # 'git%2Fgit.git Linus+Torvalds'
699 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
700 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
701 open my ($fd), $projects_list or return undef;
702 while (my $line = <$fd>) {
703 chomp $line;
704 my ($path, $owner) = split ' ', $line;
705 $path = unescape($path);
706 $owner = unescape($owner);
707 if (!defined $path) {
708 next;
710 if (-e "$projectroot/$path/HEAD") {
711 my $pr = {
712 path => $path,
713 owner => decode("utf8", $owner, Encode::FB_DEFAULT),
715 push @list, $pr
718 close $fd;
720 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
721 return @list;
724 sub git_get_project_owner {
725 my $project = shift;
726 my $owner;
728 return undef unless $project;
730 # read from file (url-encoded):
731 # 'git%2Fgit.git Linus+Torvalds'
732 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
733 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
734 if (-f $projects_list) {
735 open (my $fd , $projects_list);
736 while (my $line = <$fd>) {
737 chomp $line;
738 my ($pr, $ow) = split ' ', $line;
739 $pr = unescape($pr);
740 $ow = unescape($ow);
741 if ($pr eq $project) {
742 $owner = decode("utf8", $ow, Encode::FB_DEFAULT);
743 last;
746 close $fd;
748 if (!defined $owner) {
749 $owner = get_file_owner("$projectroot/$project");
752 return $owner;
755 sub git_get_references {
756 my $type = shift || "";
757 my %refs;
758 my $fd;
759 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
760 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
761 if (-f "$projectroot/$project/info/refs") {
762 open $fd, "$projectroot/$project/info/refs"
763 or return;
764 } else {
765 open $fd, "-|", $GIT, "ls-remote", "."
766 or return;
769 while (my $line = <$fd>) {
770 chomp $line;
771 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?[^\^]+)/) {
772 if (defined $refs{$1}) {
773 push @{$refs{$1}}, $2;
774 } else {
775 $refs{$1} = [ $2 ];
779 close $fd or return;
780 return \%refs;
783 sub git_get_rev_name_tags {
784 my $hash = shift || return undef;
786 open my $fd, "-|", $GIT, "name-rev", "--tags", $hash
787 or return;
788 my $name_rev = <$fd>;
789 close $fd;
791 if ($name_rev =~ m|^$hash tags/(.*)$|) {
792 return $1;
793 } else {
794 # catches also '$hash undefined' output
795 return undef;
799 ## ----------------------------------------------------------------------
800 ## parse to hash functions
802 sub parse_date {
803 my $epoch = shift;
804 my $tz = shift || "-0000";
806 my %date;
807 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
808 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
809 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
810 $date{'hour'} = $hour;
811 $date{'minute'} = $min;
812 $date{'mday'} = $mday;
813 $date{'day'} = $days[$wday];
814 $date{'month'} = $months[$mon];
815 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
816 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
817 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
818 $mday, $months[$mon], $hour ,$min;
820 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
821 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
822 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
823 $date{'hour_local'} = $hour;
824 $date{'minute_local'} = $min;
825 $date{'tz_local'} = $tz;
826 return %date;
829 sub parse_tag {
830 my $tag_id = shift;
831 my %tag;
832 my @comment;
834 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
835 $tag{'id'} = $tag_id;
836 while (my $line = <$fd>) {
837 chomp $line;
838 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
839 $tag{'object'} = $1;
840 } elsif ($line =~ m/^type (.+)$/) {
841 $tag{'type'} = $1;
842 } elsif ($line =~ m/^tag (.+)$/) {
843 $tag{'name'} = $1;
844 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
845 $tag{'author'} = $1;
846 $tag{'epoch'} = $2;
847 $tag{'tz'} = $3;
848 } elsif ($line =~ m/--BEGIN/) {
849 push @comment, $line;
850 last;
851 } elsif ($line eq "") {
852 last;
855 push @comment, <$fd>;
856 $tag{'comment'} = \@comment;
857 close $fd or return;
858 if (!defined $tag{'name'}) {
859 return
861 return %tag
864 sub parse_commit {
865 my $commit_id = shift;
866 my $commit_text = shift;
868 my @commit_lines;
869 my %co;
871 if (defined $commit_text) {
872 @commit_lines = @$commit_text;
873 } else {
874 $/ = "\0";
875 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id
876 or return;
877 @commit_lines = split '\n', <$fd>;
878 close $fd or return;
879 $/ = "\n";
880 pop @commit_lines;
882 my $header = shift @commit_lines;
883 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
884 return;
886 ($co{'id'}, my @parents) = split ' ', $header;
887 $co{'parents'} = \@parents;
888 $co{'parent'} = $parents[0];
889 while (my $line = shift @commit_lines) {
890 last if $line eq "\n";
891 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
892 $co{'tree'} = $1;
893 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
894 $co{'author'} = $1;
895 $co{'author_epoch'} = $2;
896 $co{'author_tz'} = $3;
897 if ($co{'author'} =~ m/^([^<]+) </) {
898 $co{'author_name'} = $1;
899 } else {
900 $co{'author_name'} = $co{'author'};
902 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
903 $co{'committer'} = $1;
904 $co{'committer_epoch'} = $2;
905 $co{'committer_tz'} = $3;
906 $co{'committer_name'} = $co{'committer'};
907 $co{'committer_name'} =~ s/ <.*//;
910 if (!defined $co{'tree'}) {
911 return;
914 foreach my $title (@commit_lines) {
915 $title =~ s/^ //;
916 if ($title ne "") {
917 $co{'title'} = chop_str($title, 80, 5);
918 # remove leading stuff of merges to make the interesting part visible
919 if (length($title) > 50) {
920 $title =~ s/^Automatic //;
921 $title =~ s/^merge (of|with) /Merge ... /i;
922 if (length($title) > 50) {
923 $title =~ s/(http|rsync):\/\///;
925 if (length($title) > 50) {
926 $title =~ s/(master|www|rsync)\.//;
928 if (length($title) > 50) {
929 $title =~ s/kernel.org:?//;
931 if (length($title) > 50) {
932 $title =~ s/\/pub\/scm//;
935 $co{'title_short'} = chop_str($title, 50, 5);
936 last;
939 # remove added spaces
940 foreach my $line (@commit_lines) {
941 $line =~ s/^ //;
943 $co{'comment'} = \@commit_lines;
945 my $age = time - $co{'committer_epoch'};
946 $co{'age'} = $age;
947 $co{'age_string'} = age_string($age);
948 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
949 if ($age > 60*60*24*7*2) {
950 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
951 $co{'age_string_age'} = $co{'age_string'};
952 } else {
953 $co{'age_string_date'} = $co{'age_string'};
954 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
956 return %co;
959 # parse ref from ref_file, given by ref_id, with given type
960 sub parse_ref {
961 my $ref_file = shift;
962 my $ref_id = shift;
963 my $type = shift || git_get_type($ref_id);
964 my %ref_item;
966 $ref_item{'type'} = $type;
967 $ref_item{'id'} = $ref_id;
968 $ref_item{'epoch'} = 0;
969 $ref_item{'age'} = "unknown";
970 if ($type eq "tag") {
971 my %tag = parse_tag($ref_id);
972 $ref_item{'comment'} = $tag{'comment'};
973 if ($tag{'type'} eq "commit") {
974 my %co = parse_commit($tag{'object'});
975 $ref_item{'epoch'} = $co{'committer_epoch'};
976 $ref_item{'age'} = $co{'age_string'};
977 } elsif (defined($tag{'epoch'})) {
978 my $age = time - $tag{'epoch'};
979 $ref_item{'epoch'} = $tag{'epoch'};
980 $ref_item{'age'} = age_string($age);
982 $ref_item{'reftype'} = $tag{'type'};
983 $ref_item{'name'} = $tag{'name'};
984 $ref_item{'refid'} = $tag{'object'};
985 } elsif ($type eq "commit"){
986 my %co = parse_commit($ref_id);
987 $ref_item{'reftype'} = "commit";
988 $ref_item{'name'} = $ref_file;
989 $ref_item{'title'} = $co{'title'};
990 $ref_item{'refid'} = $ref_id;
991 $ref_item{'epoch'} = $co{'committer_epoch'};
992 $ref_item{'age'} = $co{'age_string'};
993 } else {
994 $ref_item{'reftype'} = $type;
995 $ref_item{'name'} = $ref_file;
996 $ref_item{'refid'} = $ref_id;
999 return %ref_item;
1002 # parse line of git-diff-tree "raw" output
1003 sub parse_difftree_raw_line {
1004 my $line = shift;
1005 my %res;
1007 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1008 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1009 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1010 $res{'from_mode'} = $1;
1011 $res{'to_mode'} = $2;
1012 $res{'from_id'} = $3;
1013 $res{'to_id'} = $4;
1014 $res{'status'} = $5;
1015 $res{'similarity'} = $6;
1016 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1017 ($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
1018 } else {
1019 $res{'file'} = unquote($7);
1022 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1023 #elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1024 # $res{'commit'} = $1;
1027 return wantarray ? %res : \%res;
1030 ## ......................................................................
1031 ## parse to array of hashes functions
1033 sub git_get_refs_list {
1034 my $ref_dir = shift;
1035 my @reflist;
1037 my @refs;
1038 my $pfxlen = length("$projectroot/$project/$ref_dir");
1039 File::Find::find(sub {
1040 return if (/^\./);
1041 if (-f $_) {
1042 push @refs, substr($File::Find::name, $pfxlen + 1);
1044 }, "$projectroot/$project/$ref_dir");
1046 foreach my $ref_file (@refs) {
1047 my $ref_id = git_get_hash_by_ref("$project/$ref_dir/$ref_file");
1048 my $type = git_get_type($ref_id) || next;
1049 my %ref_item = parse_ref($ref_file, $ref_id, $type);
1051 push @reflist, \%ref_item;
1053 # sort refs by age
1054 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1055 return \@reflist;
1058 ## ----------------------------------------------------------------------
1059 ## filesystem-related functions
1061 sub get_file_owner {
1062 my $path = shift;
1064 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1065 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1066 if (!defined $gcos) {
1067 return undef;
1069 my $owner = $gcos;
1070 $owner =~ s/[,;].*$//;
1071 return decode("utf8", $owner, Encode::FB_DEFAULT);
1074 ## ......................................................................
1075 ## mimetype related functions
1077 sub mimetype_guess_file {
1078 my $filename = shift;
1079 my $mimemap = shift;
1080 -r $mimemap or return undef;
1082 my %mimemap;
1083 open(MIME, $mimemap) or return undef;
1084 while (<MIME>) {
1085 next if m/^#/; # skip comments
1086 my ($mime, $exts) = split(/\t+/);
1087 if (defined $exts) {
1088 my @exts = split(/\s+/, $exts);
1089 foreach my $ext (@exts) {
1090 $mimemap{$ext} = $mime;
1094 close(MIME);
1096 $filename =~ /\.(.*?)$/;
1097 return $mimemap{$1};
1100 sub mimetype_guess {
1101 my $filename = shift;
1102 my $mime;
1103 $filename =~ /\./ or return undef;
1105 if ($mimetypes_file) {
1106 my $file = $mimetypes_file;
1107 if ($file !~ m!^/!) { # if it is relative path
1108 # it is relative to project
1109 $file = "$projectroot/$project/$file";
1111 $mime = mimetype_guess_file($filename, $file);
1113 $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
1114 return $mime;
1117 sub blob_mimetype {
1118 my $fd = shift;
1119 my $filename = shift;
1121 if ($filename) {
1122 my $mime = mimetype_guess($filename);
1123 $mime and return $mime;
1126 # just in case
1127 return $default_blob_plain_mimetype unless $fd;
1129 if (-T $fd) {
1130 return 'text/plain' .
1131 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1132 } elsif (! $filename) {
1133 return 'application/octet-stream';
1134 } elsif ($filename =~ m/\.png$/i) {
1135 return 'image/png';
1136 } elsif ($filename =~ m/\.gif$/i) {
1137 return 'image/gif';
1138 } elsif ($filename =~ m/\.jpe?g$/i) {
1139 return 'image/jpeg';
1140 } else {
1141 return 'application/octet-stream';
1145 ## ======================================================================
1146 ## functions printing HTML: header, footer, error page
1148 sub git_header_html {
1149 my $status = shift || "200 OK";
1150 my $expires = shift;
1152 my $title = "$site_name git";
1153 if (defined $project) {
1154 $title .= " - $project";
1155 if (defined $action) {
1156 $title .= "/$action";
1157 if (defined $file_name) {
1158 $title .= " - $file_name";
1159 if ($action eq "tree" && $file_name !~ m|/$|) {
1160 $title .= "/";
1165 my $content_type;
1166 # require explicit support from the UA if we are to send the page as
1167 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1168 # we have to do this because MSIE sometimes globs '*/*', pretending to
1169 # support xhtml+xml but choking when it gets what it asked for.
1170 if (defined $cgi->http('HTTP_ACCEPT') &&
1171 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&
1172 $cgi->Accept('application/xhtml+xml') != 0) {
1173 $content_type = 'application/xhtml+xml';
1174 } else {
1175 $content_type = 'text/html';
1177 print $cgi->header(-type=>$content_type, -charset => 'utf-8',
1178 -status=> $status, -expires => $expires);
1179 print <<EOF;
1180 <?xml version="1.0" encoding="utf-8"?>
1181 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1182 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1183 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1184 <!-- git core binaries version $git_version -->
1185 <head>
1186 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1187 <meta name="generator" content="gitweb/$version git/$git_version"/>
1188 <meta name="robots" content="index, nofollow"/>
1189 <title>$title</title>
1190 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1192 if (defined $project) {
1193 printf('<link rel="alternate" title="%s log" '.
1194 'href="%s" type="application/rss+xml"/>'."\n",
1195 esc_param($project), href(action=>"rss"));
1197 if (defined $favicon) {
1198 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1201 print "</head>\n" .
1202 "<body>\n" .
1203 "<div class=\"page_header\">\n" .
1204 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1205 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1206 "</a>\n";
1207 print $cgi->a({-href => esc_param($home_link)}, $home_link_str) . " / ";
1208 if (defined $project) {
1209 print $cgi->a({-href => href(action=>"summary")}, esc_html($project));
1210 if (defined $action) {
1211 print " / $action";
1213 print "\n";
1214 if (!defined $searchtext) {
1215 $searchtext = "";
1217 my $search_hash;
1218 if (defined $hash_base) {
1219 $search_hash = $hash_base;
1220 } elsif (defined $hash) {
1221 $search_hash = $hash;
1222 } else {
1223 $search_hash = "HEAD";
1225 $cgi->param("a", "search");
1226 $cgi->param("h", $search_hash);
1227 print $cgi->startform(-method => "get", -action => $my_uri) .
1228 "<div class=\"search\">\n" .
1229 $cgi->hidden(-name => "p") . "\n" .
1230 $cgi->hidden(-name => "a") . "\n" .
1231 $cgi->hidden(-name => "h") . "\n" .
1232 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
1233 "</div>" .
1234 $cgi->end_form() . "\n";
1236 print "</div>\n";
1239 sub git_footer_html {
1240 print "<div class=\"page_footer\">\n";
1241 if (defined $project) {
1242 my $descr = git_get_project_description($project);
1243 if (defined $descr) {
1244 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
1246 print $cgi->a({-href => href(action=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1247 } else {
1248 print $cgi->a({-href => href(action=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1250 print "</div>\n" .
1251 "</body>\n" .
1252 "</html>";
1255 sub die_error {
1256 my $status = shift || "403 Forbidden";
1257 my $error = shift || "Malformed query, file missing or permission denied";
1259 git_header_html($status);
1260 print <<EOF;
1261 <div class="page_body">
1262 <br /><br />
1263 $status - $error
1264 <br />
1265 </div>
1267 git_footer_html();
1268 exit;
1271 ## ----------------------------------------------------------------------
1272 ## functions printing or outputting HTML: navigation
1274 sub git_print_page_nav {
1275 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1276 $extra = '' if !defined $extra; # pager or formats
1278 my @navs = qw(summary shortlog log commit commitdiff tree);
1279 if ($suppress) {
1280 @navs = grep { $_ ne $suppress } @navs;
1283 my %arg = map { $_ => {action=>$_} } @navs;
1284 if (defined $head) {
1285 for (qw(commit commitdiff)) {
1286 $arg{$_}{hash} = $head;
1288 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1289 for (qw(shortlog log)) {
1290 $arg{$_}{hash} = $head;
1294 $arg{tree}{hash} = $treehead if defined $treehead;
1295 $arg{tree}{hash_base} = $treebase if defined $treebase;
1297 print "<div class=\"page_nav\">\n" .
1298 (join " | ",
1299 map { $_ eq $current ?
1300 $_ : $cgi->a({-href => href(%{$arg{$_}})}, "$_")
1301 } @navs);
1302 print "<br/>\n$extra<br/>\n" .
1303 "</div>\n";
1306 sub format_paging_nav {
1307 my ($action, $hash, $head, $page, $nrevs) = @_;
1308 my $paging_nav;
1311 if ($hash ne $head || $page) {
1312 $paging_nav .= $cgi->a({-href => href(action=>$action)}, "HEAD");
1313 } else {
1314 $paging_nav .= "HEAD";
1317 if ($page > 0) {
1318 $paging_nav .= " &sdot; " .
1319 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page-1),
1320 -accesskey => "p", -title => "Alt-p"}, "prev");
1321 } else {
1322 $paging_nav .= " &sdot; prev";
1325 if ($nrevs >= (100 * ($page+1)-1)) {
1326 $paging_nav .= " &sdot; " .
1327 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page+1),
1328 -accesskey => "n", -title => "Alt-n"}, "next");
1329 } else {
1330 $paging_nav .= " &sdot; next";
1333 return $paging_nav;
1336 ## ......................................................................
1337 ## functions printing or outputting HTML: div
1339 sub git_print_header_div {
1340 my ($action, $title, $hash, $hash_base) = @_;
1341 my %args = ();
1343 $args{action} = $action;
1344 $args{hash} = $hash if $hash;
1345 $args{hash_base} = $hash_base if $hash_base;
1347 print "<div class=\"header\">\n" .
1348 $cgi->a({-href => href(%args), -class => "title"},
1349 $title ? $title : $action) .
1350 "\n</div>\n";
1353 #sub git_print_authorship (\%) {
1354 sub git_print_authorship {
1355 my $co = shift;
1357 my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
1358 print "<div class=\"author_date\">" .
1359 esc_html($co->{'author_name'}) .
1360 " [$ad{'rfc2822'}";
1361 if ($ad{'hour_local'} < 6) {
1362 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1363 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1364 } else {
1365 printf(" (%02d:%02d %s)",
1366 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1368 print "]</div>\n";
1371 sub git_print_page_path {
1372 my $name = shift;
1373 my $type = shift;
1374 my $hb = shift;
1376 if (!defined $name) {
1377 print "<div class=\"page_path\">/</div>\n";
1378 } else {
1379 my @dirname = split '/', $name;
1380 my $basename = pop @dirname;
1381 my $fullname = '';
1383 print "<div class=\"page_path\">";
1384 foreach my $dir (@dirname) {
1385 $fullname .= $dir . '/';
1386 print $cgi->a({-href => href(action=>"tree", file_name=>$fullname,
1387 hash_base=>$hb),
1388 -title => $fullname}, esc_html($dir));
1389 print "/";
1391 if (defined $type && $type eq 'blob') {
1392 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,
1393 hash_base=>$hb),
1394 -title => $name}, esc_html($basename));
1395 } elsif (defined $type && $type eq 'tree') {
1396 print $cgi->a({-href => href(action=>"tree", file_name=>$file_name,
1397 hash_base=>$hb),
1398 -title => $name}, esc_html($basename));
1399 print "/";
1400 } else {
1401 print esc_html($basename);
1403 print "<br/></div>\n";
1407 # sub git_print_log (\@;%) {
1408 sub git_print_log ($;%) {
1409 my $log = shift;
1410 my %opts = @_;
1412 if ($opts{'-remove_title'}) {
1413 # remove title, i.e. first line of log
1414 shift @$log;
1416 # remove leading empty lines
1417 while (defined $log->[0] && $log->[0] eq "") {
1418 shift @$log;
1421 # print log
1422 my $signoff = 0;
1423 my $empty = 0;
1424 foreach my $line (@$log) {
1425 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1426 $signoff = 1;
1427 $empty = 0;
1428 if (! $opts{'-remove_signoff'}) {
1429 print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
1430 next;
1431 } else {
1432 # remove signoff lines
1433 next;
1435 } else {
1436 $signoff = 0;
1439 # print only one empty line
1440 # do not print empty line after signoff
1441 if ($line eq "") {
1442 next if ($empty || $signoff);
1443 $empty = 1;
1444 } else {
1445 $empty = 0;
1448 print format_log_line_html($line) . "<br/>\n";
1451 if ($opts{'-final_empty_line'}) {
1452 # end with single empty line
1453 print "<br/>\n" unless $empty;
1457 sub git_print_simplified_log {
1458 my $log = shift;
1459 my $remove_title = shift;
1461 git_print_log($log,
1462 -final_empty_line=> 1,
1463 -remove_title => $remove_title);
1466 ## ......................................................................
1467 ## functions printing large fragments of HTML
1469 sub git_difftree_body {
1470 my ($difftree, $hash, $parent) = @_;
1472 print "<div class=\"list_head\">\n";
1473 if ($#{$difftree} > 10) {
1474 print(($#{$difftree} + 1) . " files changed:\n");
1476 print "</div>\n";
1478 print "<table class=\"diff_tree\">\n";
1479 my $alternate = 0;
1480 my $patchno = 0;
1481 foreach my $line (@{$difftree}) {
1482 my %diff = parse_difftree_raw_line($line);
1484 if ($alternate) {
1485 print "<tr class=\"dark\">\n";
1486 } else {
1487 print "<tr class=\"light\">\n";
1489 $alternate ^= 1;
1491 my ($to_mode_oct, $to_mode_str, $to_file_type);
1492 my ($from_mode_oct, $from_mode_str, $from_file_type);
1493 if ($diff{'to_mode'} ne ('0' x 6)) {
1494 $to_mode_oct = oct $diff{'to_mode'};
1495 if (S_ISREG($to_mode_oct)) { # only for regular file
1496 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1498 $to_file_type = file_type($diff{'to_mode'});
1500 if ($diff{'from_mode'} ne ('0' x 6)) {
1501 $from_mode_oct = oct $diff{'from_mode'};
1502 if (S_ISREG($to_mode_oct)) { # only for regular file
1503 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1505 $from_file_type = file_type($diff{'from_mode'});
1508 if ($diff{'status'} eq "A") { # created
1509 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1510 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1511 $mode_chng .= "]</span>";
1512 print "<td>" .
1513 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1514 hash_base=>$hash, file_name=>$diff{'file'}),
1515 -class => "list"}, esc_html($diff{'file'})) .
1516 "</td>\n" .
1517 "<td>$mode_chng</td>\n" .
1518 "<td class=\"link\">" .
1519 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1520 hash_base=>$hash, file_name=>$diff{'file'})},
1521 "blob");
1522 if ($action eq 'commitdiff') {
1523 # link to patch
1524 $patchno++;
1525 print " | " .
1526 $cgi->a({-href => "#patch$patchno"}, "patch");
1528 print "</td>\n";
1530 } elsif ($diff{'status'} eq "D") { # deleted
1531 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1532 print "<td>" .
1533 $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
1534 hash_base=>$parent, file_name=>$diff{'file'}),
1535 -class => "list"}, esc_html($diff{'file'})) .
1536 "</td>\n" .
1537 "<td>$mode_chng</td>\n" .
1538 "<td class=\"link\">" .
1539 $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
1540 hash_base=>$parent, file_name=>$diff{'file'})},
1541 "blob") .
1542 " | ";
1543 if ($action eq 'commitdiff') {
1544 # link to patch
1545 $patchno++;
1546 print " | " .
1547 $cgi->a({-href => "#patch$patchno"}, "patch");
1549 print $cgi->a({-href => href(action=>"history", hash_base=>$parent,
1550 file_name=>$diff{'file'})},
1551 "history") .
1552 "</td>\n";
1554 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1555 my $mode_chnge = "";
1556 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1557 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1558 if ($from_file_type != $to_file_type) {
1559 $mode_chnge .= " from $from_file_type to $to_file_type";
1561 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1562 if ($from_mode_str && $to_mode_str) {
1563 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1564 } elsif ($to_mode_str) {
1565 $mode_chnge .= " mode: $to_mode_str";
1568 $mode_chnge .= "]</span>\n";
1570 print "<td>";
1571 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1572 print $cgi->a({-href => href(action=>"blobdiff",
1573 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1574 hash_base=>$hash, hash_parent_base=>$parent,
1575 file_name=>$diff{'file'}),
1576 -class => "list"}, esc_html($diff{'file'}));
1577 } else { # only mode changed
1578 print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1579 hash_base=>$hash, file_name=>$diff{'file'}),
1580 -class => "list"}, esc_html($diff{'file'}));
1582 print "</td>\n" .
1583 "<td>$mode_chnge</td>\n" .
1584 "<td class=\"link\">" .
1585 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1586 hash_base=>$hash, file_name=>$diff{'file'})},
1587 "blob");
1588 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1589 if ($action eq 'commitdiff') {
1590 # link to patch
1591 $patchno++;
1592 print " | " .
1593 $cgi->a({-href => "#patch$patchno"}, "patch");
1594 } else {
1595 print " | " .
1596 $cgi->a({-href => href(action=>"blobdiff",
1597 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1598 hash_base=>$hash, hash_parent_base=>$parent,
1599 file_name=>$diff{'file'})},
1600 "diff");
1603 print " | " .
1604 $cgi->a({-href => href(action=>"history",
1605 hash_base=>$hash, file_name=>$diff{'file'})},
1606 "history");
1607 print "</td>\n";
1609 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1610 my %status_name = ('R' => 'moved', 'C' => 'copied');
1611 my $nstatus = $status_name{$diff{'status'}};
1612 my $mode_chng = "";
1613 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1614 # mode also for directories, so we cannot use $to_mode_str
1615 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1617 print "<td>" .
1618 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1619 hash=>$diff{'to_id'}, file_name=>$diff{'to_file'}),
1620 -class => "list"}, esc_html($diff{'to_file'})) . "</td>\n" .
1621 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1622 $cgi->a({-href => href(action=>"blob", hash_base=>$parent,
1623 hash=>$diff{'from_id'}, file_name=>$diff{'from_file'}),
1624 -class => "list"}, esc_html($diff{'from_file'})) .
1625 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1626 "<td class=\"link\">" .
1627 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1628 hash=>$diff{'to_id'}, file_name=>$diff{'to_file'})},
1629 "blob");
1630 if ($diff{'to_id'} ne $diff{'from_id'}) {
1631 if ($action eq 'commitdiff') {
1632 # link to patch
1633 $patchno++;
1634 print " | " .
1635 $cgi->a({-href => "#patch$patchno"}, "patch");
1636 } else {
1637 print " | " .
1638 $cgi->a({-href => href(action=>"blobdiff",
1639 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1640 hash_base=>$hash, hash_parent_base=>$parent,
1641 file_name=>$diff{'to_file'}, file_parent=>$diff{'from_file'})},
1642 "diff");
1645 print "</td>\n";
1647 } # we should not encounter Unmerged (U) or Unknown (X) status
1648 print "</tr>\n";
1650 print "</table>\n";
1653 sub git_patchset_body {
1654 my ($fd, $difftree, $hash, $hash_parent) = @_;
1656 my $patch_idx = 0;
1657 my $in_header = 0;
1658 my $patch_found = 0;
1659 my $diffinfo;
1661 print "<div class=\"patchset\">\n";
1663 LINE:
1664 while (my $patch_line = <$fd>) {
1665 chomp $patch_line;
1667 if ($patch_line =~ m/^diff /) { # "git diff" header
1668 # beginning of patch (in patchset)
1669 if ($patch_found) {
1670 # close previous patch
1671 print "</div>\n"; # class="patch"
1672 } else {
1673 # first patch in patchset
1674 $patch_found = 1;
1676 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1678 if (ref($difftree->[$patch_idx]) eq "HASH") {
1679 $diffinfo = $difftree->[$patch_idx];
1680 } else {
1681 $diffinfo = parse_difftree_raw_line($difftree->[$patch_idx]);
1683 $patch_idx++;
1685 # for now, no extended header, hence we skip empty patches
1686 # companion to next LINE if $in_header;
1687 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1688 $in_header = 1;
1689 next LINE;
1692 if ($diffinfo->{'status'} eq "A") { # added
1693 print "<div class=\"diff_info\">" . file_type($diffinfo->{'to_mode'}) . ":" .
1694 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1695 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'file'})},
1696 $diffinfo->{'to_id'}) . "(new)" .
1697 "</div>\n"; # class="diff_info"
1699 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1700 print "<div class=\"diff_info\">" . file_type($diffinfo->{'from_mode'}) . ":" .
1701 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1702 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'file'})},
1703 $diffinfo->{'from_id'}) . "(deleted)" .
1704 "</div>\n"; # class="diff_info"
1706 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1707 $diffinfo->{'status'} eq "C" || # copied
1708 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1709 print "<div class=\"diff_info\">" .
1710 file_type($diffinfo->{'from_mode'}) . ":" .
1711 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1712 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'from_file'})},
1713 $diffinfo->{'from_id'}) .
1714 " -> " .
1715 file_type($diffinfo->{'to_mode'}) . ":" .
1716 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1717 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'to_file'})},
1718 $diffinfo->{'to_id'});
1719 print "</div>\n"; # class="diff_info"
1721 } else { # modified, mode changed, ...
1722 print "<div class=\"diff_info\">" .
1723 file_type($diffinfo->{'from_mode'}) . ":" .
1724 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1725 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'file'})},
1726 $diffinfo->{'from_id'}) .
1727 " -> " .
1728 file_type($diffinfo->{'to_mode'}) . ":" .
1729 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1730 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'file'})},
1731 $diffinfo->{'to_id'});
1732 print "</div>\n"; # class="diff_info"
1735 #print "<div class=\"diff extended_header\">\n";
1736 $in_header = 1;
1737 next LINE;
1738 } # start of patch in patchset
1741 if ($in_header && $patch_line =~ m/^---/) {
1742 #print "</div>\n"; # class="diff extended_header"
1743 $in_header = 0;
1745 my $file = $diffinfo->{'from_file'};
1746 $file ||= $diffinfo->{'file'};
1747 $file = $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1748 hash=>$diffinfo->{'from_id'}, file_name=>$file),
1749 -class => "list"}, esc_html($file));
1750 $patch_line =~ s|a/.*$|a/$file|g;
1751 print "<div class=\"diff from_file\">$patch_line</div>\n";
1753 $patch_line = <$fd>;
1754 chomp $patch_line;
1756 #$patch_line =~ m/^+++/;
1757 $file = $diffinfo->{'to_file'};
1758 $file ||= $diffinfo->{'file'};
1759 $file = $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1760 hash=>$diffinfo->{'to_id'}, file_name=>$file),
1761 -class => "list"}, esc_html($file));
1762 $patch_line =~ s|b/.*|b/$file|g;
1763 print "<div class=\"diff to_file\">$patch_line</div>\n";
1765 next LINE;
1767 next LINE if $in_header;
1769 print format_diff_line($patch_line);
1771 print "</div>\n" if $patch_found; # class="patch"
1773 print "</div>\n"; # class="patchset"
1776 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1778 sub git_shortlog_body {
1779 # uses global variable $project
1780 my ($revlist, $from, $to, $refs, $extra) = @_;
1782 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
1783 my $have_snapshot = (defined $ctype && defined $suffix);
1785 $from = 0 unless defined $from;
1786 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1788 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1789 my $alternate = 0;
1790 for (my $i = $from; $i <= $to; $i++) {
1791 my $commit = $revlist->[$i];
1792 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1793 my $ref = format_ref_marker($refs, $commit);
1794 my %co = parse_commit($commit);
1795 if ($alternate) {
1796 print "<tr class=\"dark\">\n";
1797 } else {
1798 print "<tr class=\"light\">\n";
1800 $alternate ^= 1;
1801 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1802 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1803 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1804 "<td>";
1805 print format_subject_html($co{'title'}, $co{'title_short'},
1806 href(action=>"commit", hash=>$commit), $ref);
1807 print "</td>\n" .
1808 "<td class=\"link\">" .
1809 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
1810 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff");
1811 if ($have_snapshot) {
1812 print " | " . $cgi->a({-href => href(action=>"snapshot", hash=>$commit)}, "snapshot");
1814 print "</td>\n" .
1815 "</tr>\n";
1817 if (defined $extra) {
1818 print "<tr>\n" .
1819 "<td colspan=\"4\">$extra</td>\n" .
1820 "</tr>\n";
1822 print "</table>\n";
1825 sub git_history_body {
1826 # Warning: assumes constant type (blob or tree) during history
1827 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1829 print "<table class=\"history\" cellspacing=\"0\">\n";
1830 my $alternate = 0;
1831 while (my $line = <$fd>) {
1832 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1833 next;
1836 my $commit = $1;
1837 my %co = parse_commit($commit);
1838 if (!%co) {
1839 next;
1842 my $ref = format_ref_marker($refs, $commit);
1844 if ($alternate) {
1845 print "<tr class=\"dark\">\n";
1846 } else {
1847 print "<tr class=\"light\">\n";
1849 $alternate ^= 1;
1850 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1851 # shortlog uses chop_str($co{'author_name'}, 10)
1852 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1853 "<td>";
1854 # originally git_history used chop_str($co{'title'}, 50)
1855 print format_subject_html($co{'title'}, $co{'title_short'},
1856 href(action=>"commit", hash=>$commit), $ref);
1857 print "</td>\n" .
1858 "<td class=\"link\">" .
1859 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
1860 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
1861 $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype);
1863 if ($ftype eq 'blob') {
1864 my $blob_current = git_get_hash_by_path($hash_base, $file_name);
1865 my $blob_parent = git_get_hash_by_path($commit, $file_name);
1866 if (defined $blob_current && defined $blob_parent &&
1867 $blob_current ne $blob_parent) {
1868 print " | " .
1869 $cgi->a({-href => href(action=>"blobdiff",
1870 hash=>$blob_current, hash_parent=>$blob_parent,
1871 hash_base=>$hash_base, hash_parent_base=>$commit,
1872 file_name=>$file_name)},
1873 "diff to current");
1876 print "</td>\n" .
1877 "</tr>\n";
1879 if (defined $extra) {
1880 print "<tr>\n" .
1881 "<td colspan=\"4\">$extra</td>\n" .
1882 "</tr>\n";
1884 print "</table>\n";
1887 sub git_tags_body {
1888 # uses global variable $project
1889 my ($taglist, $from, $to, $extra) = @_;
1890 $from = 0 unless defined $from;
1891 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1893 print "<table class=\"tags\" cellspacing=\"0\">\n";
1894 my $alternate = 0;
1895 for (my $i = $from; $i <= $to; $i++) {
1896 my $entry = $taglist->[$i];
1897 my %tag = %$entry;
1898 my $comment_lines = $tag{'comment'};
1899 my $comment = shift @$comment_lines;
1900 my $comment_short;
1901 if (defined $comment) {
1902 $comment_short = chop_str($comment, 30, 5);
1904 if ($alternate) {
1905 print "<tr class=\"dark\">\n";
1906 } else {
1907 print "<tr class=\"light\">\n";
1909 $alternate ^= 1;
1910 print "<td><i>$tag{'age'}</i></td>\n" .
1911 "<td>" .
1912 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),
1913 -class => "list name"}, esc_html($tag{'name'})) .
1914 "</td>\n" .
1915 "<td>";
1916 if (defined $comment) {
1917 print format_subject_html($comment, $comment_short,
1918 href(action=>"tag", hash=>$tag{'id'}));
1920 print "</td>\n" .
1921 "<td class=\"selflink\">";
1922 if ($tag{'type'} eq "tag") {
1923 print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag");
1924 } else {
1925 print "&nbsp;";
1927 print "</td>\n" .
1928 "<td class=\"link\">" . " | " .
1929 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'});
1930 if ($tag{'reftype'} eq "commit") {
1931 print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") .
1932 " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'refid'})}, "log");
1933 } elsif ($tag{'reftype'} eq "blob") {
1934 print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw");
1936 print "</td>\n" .
1937 "</tr>";
1939 if (defined $extra) {
1940 print "<tr>\n" .
1941 "<td colspan=\"5\">$extra</td>\n" .
1942 "</tr>\n";
1944 print "</table>\n";
1947 sub git_heads_body {
1948 # uses global variable $project
1949 my ($taglist, $head, $from, $to, $extra) = @_;
1950 $from = 0 unless defined $from;
1951 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1953 print "<table class=\"heads\" cellspacing=\"0\">\n";
1954 my $alternate = 0;
1955 for (my $i = $from; $i <= $to; $i++) {
1956 my $entry = $taglist->[$i];
1957 my %tag = %$entry;
1958 my $curr = $tag{'id'} eq $head;
1959 if ($alternate) {
1960 print "<tr class=\"dark\">\n";
1961 } else {
1962 print "<tr class=\"light\">\n";
1964 $alternate ^= 1;
1965 print "<td><i>$tag{'age'}</i></td>\n" .
1966 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
1967 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'}),
1968 -class => "list name"},esc_html($tag{'name'})) .
1969 "</td>\n" .
1970 "<td class=\"link\">" .
1971 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") . " | " .
1972 $cgi->a({-href => href(action=>"log", hash=>$tag{'name'})}, "log") .
1973 "</td>\n" .
1974 "</tr>";
1976 if (defined $extra) {
1977 print "<tr>\n" .
1978 "<td colspan=\"3\">$extra</td>\n" .
1979 "</tr>\n";
1981 print "</table>\n";
1984 ## ======================================================================
1985 ## ======================================================================
1986 ## actions
1988 sub git_project_list {
1989 my $order = $cgi->param('o');
1990 if (defined $order && $order !~ m/project|descr|owner|age/) {
1991 die_error(undef, "Unknown order parameter");
1994 my @list = git_get_projects_list();
1995 my @projects;
1996 if (!@list) {
1997 die_error(undef, "No projects found");
1999 foreach my $pr (@list) {
2000 my $head = git_get_head_hash($pr->{'path'});
2001 if (!defined $head) {
2002 next;
2004 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
2005 my %co = parse_commit($head);
2006 if (!%co) {
2007 next;
2009 $pr->{'commit'} = \%co;
2010 if (!defined $pr->{'descr'}) {
2011 my $descr = git_get_project_description($pr->{'path'}) || "";
2012 $pr->{'descr'} = chop_str($descr, 25, 5);
2014 if (!defined $pr->{'owner'}) {
2015 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
2017 push @projects, $pr;
2020 git_header_html();
2021 if (-f $home_text) {
2022 print "<div class=\"index_include\">\n";
2023 open (my $fd, $home_text);
2024 print <$fd>;
2025 close $fd;
2026 print "</div>\n";
2028 print "<table class=\"project_list\">\n" .
2029 "<tr>\n";
2030 $order ||= "project";
2031 if ($order eq "project") {
2032 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2033 print "<th>Project</th>\n";
2034 } else {
2035 print "<th>" .
2036 $cgi->a({-href => "$my_uri?" . esc_param("o=project"),
2037 -class => "header"}, "Project") .
2038 "</th>\n";
2040 if ($order eq "descr") {
2041 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2042 print "<th>Description</th>\n";
2043 } else {
2044 print "<th>" .
2045 $cgi->a({-href => "$my_uri?" . esc_param("o=descr"),
2046 -class => "header"}, "Description") .
2047 "</th>\n";
2049 if ($order eq "owner") {
2050 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2051 print "<th>Owner</th>\n";
2052 } else {
2053 print "<th>" .
2054 $cgi->a({-href => "$my_uri?" . esc_param("o=owner"),
2055 -class => "header"}, "Owner") .
2056 "</th>\n";
2058 if ($order eq "age") {
2059 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2060 print "<th>Last Change</th>\n";
2061 } else {
2062 print "<th>" .
2063 $cgi->a({-href => "$my_uri?" . esc_param("o=age"),
2064 -class => "header"}, "Last Change") .
2065 "</th>\n";
2067 print "<th></th>\n" .
2068 "</tr>\n";
2069 my $alternate = 0;
2070 foreach my $pr (@projects) {
2071 if ($alternate) {
2072 print "<tr class=\"dark\">\n";
2073 } else {
2074 print "<tr class=\"light\">\n";
2076 $alternate ^= 1;
2077 print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
2078 -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
2079 "<td>" . esc_html($pr->{'descr'}) . "</td>\n" .
2080 "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
2081 print "<td class=\"". age_class($pr->{'commit'}{'age'}) . "\">" .
2082 $pr->{'commit'}{'age_string'} . "</td>\n" .
2083 "<td class=\"link\">" .
2084 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
2085 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
2086 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") .
2087 "</td>\n" .
2088 "</tr>\n";
2090 print "</table>\n";
2091 git_footer_html();
2094 sub git_project_index {
2095 my @projects = git_get_projects_list();
2097 print $cgi->header(
2098 -type => 'text/plain',
2099 -charset => 'utf-8',
2100 -content_disposition => qq(inline; filename="index.aux"));
2102 foreach my $pr (@projects) {
2103 if (!exists $pr->{'owner'}) {
2104 $pr->{'owner'} = get_file_owner("$projectroot/$project");
2107 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2108 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2109 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
2110 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
2111 $path =~ s/ /\+/g;
2112 $owner =~ s/ /\+/g;
2114 print "$path $owner\n";
2118 sub git_summary {
2119 my $descr = git_get_project_description($project) || "none";
2120 my $head = git_get_head_hash($project);
2121 my %co = parse_commit($head);
2122 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
2124 my $owner = git_get_project_owner($project);
2126 my $refs = git_get_references();
2127 git_header_html();
2128 git_print_page_nav('summary','', $head);
2130 print "<div class=\"title\">&nbsp;</div>\n";
2131 print "<table cellspacing=\"0\">\n" .
2132 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
2133 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2134 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2135 # use per project git URL list in $projectroot/$project/cloneurl
2136 # or make project git URL from git base URL and project name
2137 my $url_tag = "URL";
2138 my @url_list = git_get_project_url_list($project);
2139 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2140 foreach my $git_url (@url_list) {
2141 next unless $git_url;
2142 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2143 $url_tag = "";
2145 print "</table>\n";
2147 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash($project)
2148 or die_error(undef, "Open git-rev-list failed");
2149 my @revlist = map { chomp; $_ } <$fd>;
2150 close $fd;
2151 git_print_header_div('shortlog');
2152 git_shortlog_body(\@revlist, 0, 15, $refs,
2153 $cgi->a({-href => href(action=>"shortlog")}, "..."));
2155 my $taglist = git_get_refs_list("refs/tags");
2156 if (defined @$taglist) {
2157 git_print_header_div('tags');
2158 git_tags_body($taglist, 0, 15,
2159 $cgi->a({-href => href(action=>"tags")}, "..."));
2162 my $headlist = git_get_refs_list("refs/heads");
2163 if (defined @$headlist) {
2164 git_print_header_div('heads');
2165 git_heads_body($headlist, $head, 0, 15,
2166 $cgi->a({-href => href(action=>"heads")}, "..."));
2169 git_footer_html();
2172 sub git_tag {
2173 my $head = git_get_head_hash($project);
2174 git_header_html();
2175 git_print_page_nav('','', $head,undef,$head);
2176 my %tag = parse_tag($hash);
2177 git_print_header_div('commit', esc_html($tag{'name'}), $hash);
2178 print "<div class=\"title_text\">\n" .
2179 "<table cellspacing=\"0\">\n" .
2180 "<tr>\n" .
2181 "<td>object</td>\n" .
2182 "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
2183 $tag{'object'}) . "</td>\n" .
2184 "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
2185 $tag{'type'}) . "</td>\n" .
2186 "</tr>\n";
2187 if (defined($tag{'author'})) {
2188 my %ad = parse_date($tag{'epoch'}, $tag{'tz'});
2189 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
2190 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2191 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2192 "</td></tr>\n";
2194 print "</table>\n\n" .
2195 "</div>\n";
2196 print "<div class=\"page_body\">";
2197 my $comment = $tag{'comment'};
2198 foreach my $line (@$comment) {
2199 print esc_html($line) . "<br/>\n";
2201 print "</div>\n";
2202 git_footer_html();
2205 sub git_blame2 {
2206 my $fd;
2207 my $ftype;
2209 if (!gitweb_check_feature('blame')) {
2210 die_error('403 Permission denied', "Permission denied");
2212 die_error('404 Not Found', "File name not defined") if (!$file_name);
2213 $hash_base ||= git_get_head_hash($project);
2214 die_error(undef, "Couldn't find base commit") unless ($hash_base);
2215 my %co = parse_commit($hash_base)
2216 or die_error(undef, "Reading commit failed");
2217 if (!defined $hash) {
2218 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
2219 or die_error(undef, "Error looking up file");
2221 $ftype = git_get_type($hash);
2222 if ($ftype !~ "blob") {
2223 die_error("400 Bad Request", "Object is not a blob");
2225 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
2226 or die_error(undef, "Open git-blame failed");
2227 git_header_html();
2228 my $formats_nav =
2229 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2230 "blob") .
2231 " | " .
2232 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
2233 "head");
2234 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2235 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2236 git_print_page_path($file_name, $ftype, $hash_base);
2237 my @rev_color = (qw(light2 dark2));
2238 my $num_colors = scalar(@rev_color);
2239 my $current_color = 0;
2240 my $last_rev;
2241 print <<HTML;
2242 <div class="page_body">
2243 <table class="blame">
2244 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2245 HTML
2246 while (<$fd>) {
2247 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2248 my $full_rev = $1;
2249 my $rev = substr($full_rev, 0, 8);
2250 my $lineno = $2;
2251 my $data = $3;
2253 if (!defined $last_rev) {
2254 $last_rev = $full_rev;
2255 } elsif ($last_rev ne $full_rev) {
2256 $last_rev = $full_rev;
2257 $current_color = ++$current_color % $num_colors;
2259 print "<tr class=\"$rev_color[$current_color]\">\n";
2260 print "<td class=\"sha1\">" .
2261 $cgi->a({-href => href(action=>"commit", hash=>$full_rev, file_name=>$file_name)},
2262 esc_html($rev)) . "</td>\n";
2263 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2264 esc_html($lineno) . "</a></td>\n";
2265 print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
2266 print "</tr>\n";
2268 print "</table>\n";
2269 print "</div>";
2270 close $fd
2271 or print "Reading blob failed\n";
2272 git_footer_html();
2275 sub git_blame {
2276 my $fd;
2278 if (!gitweb_check_feature('blame')) {
2279 die_error('403 Permission denied', "Permission denied");
2281 die_error('404 Not Found', "File name not defined") if (!$file_name);
2282 $hash_base ||= git_get_head_hash($project);
2283 die_error(undef, "Couldn't find base commit") unless ($hash_base);
2284 my %co = parse_commit($hash_base)
2285 or die_error(undef, "Reading commit failed");
2286 if (!defined $hash) {
2287 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
2288 or die_error(undef, "Error lookup file");
2290 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2291 or die_error(undef, "Open git-annotate failed");
2292 git_header_html();
2293 my $formats_nav =
2294 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2295 "blob") .
2296 " | " .
2297 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
2298 "head");
2299 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2300 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2301 git_print_page_path($file_name, 'blob', $hash_base);
2302 print "<div class=\"page_body\">\n";
2303 print <<HTML;
2304 <table class="blame">
2305 <tr>
2306 <th>Commit</th>
2307 <th>Age</th>
2308 <th>Author</th>
2309 <th>Line</th>
2310 <th>Data</th>
2311 </tr>
2312 HTML
2313 my @line_class = (qw(light dark));
2314 my $line_class_len = scalar (@line_class);
2315 my $line_class_num = $#line_class;
2316 while (my $line = <$fd>) {
2317 my $long_rev;
2318 my $short_rev;
2319 my $author;
2320 my $time;
2321 my $lineno;
2322 my $data;
2323 my $age;
2324 my $age_str;
2325 my $age_class;
2327 chomp $line;
2328 $line_class_num = ($line_class_num + 1) % $line_class_len;
2330 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2331 $long_rev = $1;
2332 $author = $2;
2333 $time = $3;
2334 $lineno = $4;
2335 $data = $5;
2336 } else {
2337 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
2338 next;
2340 $short_rev = substr ($long_rev, 0, 8);
2341 $age = time () - $time;
2342 $age_str = age_string ($age);
2343 $age_str =~ s/ /&nbsp;/g;
2344 $age_class = age_class($age);
2345 $author = esc_html ($author);
2346 $author =~ s/ /&nbsp;/g;
2348 $data = untabify($data);
2349 $data = esc_html ($data);
2351 print <<HTML;
2352 <tr class="$line_class[$line_class_num]">
2353 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2354 <td class="$age_class">$age_str</td>
2355 <td>$author</td>
2356 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2357 <td class="pre">$data</td>
2358 </tr>
2359 HTML
2360 } # while (my $line = <$fd>)
2361 print "</table>\n\n";
2362 close $fd
2363 or print "Reading blob failed.\n";
2364 print "</div>";
2365 git_footer_html();
2368 sub git_tags {
2369 my $head = git_get_head_hash($project);
2370 git_header_html();
2371 git_print_page_nav('','', $head,undef,$head);
2372 git_print_header_div('summary', $project);
2374 my $taglist = git_get_refs_list("refs/tags");
2375 if (defined @$taglist) {
2376 git_tags_body($taglist);
2378 git_footer_html();
2381 sub git_heads {
2382 my $head = git_get_head_hash($project);
2383 git_header_html();
2384 git_print_page_nav('','', $head,undef,$head);
2385 git_print_header_div('summary', $project);
2387 my $taglist = git_get_refs_list("refs/heads");
2388 if (defined @$taglist) {
2389 git_heads_body($taglist, $head);
2391 git_footer_html();
2394 sub git_blob_plain {
2395 # blobs defined by non-textual hash id's can be cached
2396 my $expires;
2397 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2398 $expires = "+1d";
2401 if (!defined $hash) {
2402 if (defined $file_name) {
2403 my $base = $hash_base || git_get_head_hash($project);
2404 $hash = git_get_hash_by_path($base, $file_name, "blob")
2405 or die_error(undef, "Error lookup file");
2406 } else {
2407 die_error(undef, "No file name defined");
2410 my $type = shift;
2411 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2412 or die_error(undef, "Couldn't cat $file_name, $hash");
2414 $type ||= blob_mimetype($fd, $file_name);
2416 # save as filename, even when no $file_name is given
2417 my $save_as = "$hash";
2418 if (defined $file_name) {
2419 $save_as = $file_name;
2420 } elsif ($type =~ m/^text\//) {
2421 $save_as .= '.txt';
2424 print $cgi->header(
2425 -type => "$type",
2426 -expires=>$expires,
2427 -content_disposition => "inline; filename=\"$save_as\"");
2428 undef $/;
2429 binmode STDOUT, ':raw';
2430 print <$fd>;
2431 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
2432 $/ = "\n";
2433 close $fd;
2436 sub git_blob {
2437 # blobs defined by non-textual hash id's can be cached
2438 my $expires;
2439 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2440 $expires = "+1d";
2443 if (!defined $hash) {
2444 if (defined $file_name) {
2445 my $base = $hash_base || git_get_head_hash($project);
2446 $hash = git_get_hash_by_path($base, $file_name, "blob")
2447 or die_error(undef, "Error lookup file");
2448 } else {
2449 die_error(undef, "No file name defined");
2452 my $have_blame = gitweb_check_feature('blame');
2453 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2454 or die_error(undef, "Couldn't cat $file_name, $hash");
2455 my $mimetype = blob_mimetype($fd, $file_name);
2456 if ($mimetype !~ m/^text\//) {
2457 close $fd;
2458 return git_blob_plain($mimetype);
2460 git_header_html(undef, $expires);
2461 my $formats_nav = '';
2462 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2463 if (defined $file_name) {
2464 if ($have_blame) {
2465 $formats_nav .=
2466 $cgi->a({-href => href(action=>"blame", hash_base=>$hash_base,
2467 hash=>$hash, file_name=>$file_name)},
2468 "blame") .
2469 " | ";
2471 $formats_nav .=
2472 $cgi->a({-href => href(action=>"blob_plain",
2473 hash=>$hash, file_name=>$file_name)},
2474 "plain") .
2475 " | " .
2476 $cgi->a({-href => href(action=>"blob",
2477 hash_base=>"HEAD", file_name=>$file_name)},
2478 "head");
2479 } else {
2480 $formats_nav .=
2481 $cgi->a({-href => href(action=>"blob_plain", hash=>$hash)}, "plain");
2483 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2484 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2485 } else {
2486 print "<div class=\"page_nav\">\n" .
2487 "<br/><br/></div>\n" .
2488 "<div class=\"title\">$hash</div>\n";
2490 git_print_page_path($file_name, "blob", $hash_base);
2491 print "<div class=\"page_body\">\n";
2492 my $nr;
2493 while (my $line = <$fd>) {
2494 chomp $line;
2495 $nr++;
2496 $line = untabify($line);
2497 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2498 $nr, $nr, $nr, esc_html($line);
2500 close $fd
2501 or print "Reading blob failed.\n";
2502 print "</div>";
2503 git_footer_html();
2506 sub git_tree {
2507 if (!defined $hash) {
2508 $hash = git_get_head_hash($project);
2509 if (defined $file_name) {
2510 my $base = $hash_base || $hash;
2511 $hash = git_get_hash_by_path($base, $file_name, "tree");
2513 if (!defined $hash_base) {
2514 $hash_base = $hash;
2517 $/ = "\0";
2518 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
2519 or die_error(undef, "Open git-ls-tree failed");
2520 my @entries = map { chomp; $_ } <$fd>;
2521 close $fd or die_error(undef, "Reading tree failed");
2522 $/ = "\n";
2524 my $refs = git_get_references();
2525 my $ref = format_ref_marker($refs, $hash_base);
2526 git_header_html();
2527 my %base_key = ();
2528 my $base = "";
2529 my $have_blame = gitweb_check_feature('blame');
2530 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2531 $base_key{hash_base} = $hash_base;
2532 git_print_page_nav('tree','', $hash_base);
2533 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
2534 } else {
2535 print "<div class=\"page_nav\">\n";
2536 print "<br/><br/></div>\n";
2537 print "<div class=\"title\">$hash</div>\n";
2539 if (defined $file_name) {
2540 $base = esc_html("$file_name/");
2542 git_print_page_path($file_name, 'tree', $hash_base);
2543 print "<div class=\"page_body\">\n";
2544 print "<table cellspacing=\"0\">\n";
2545 my $alternate = 0;
2546 foreach my $line (@entries) {
2547 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2548 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2549 my $t_mode = $1;
2550 my $t_type = $2;
2551 my $t_hash = $3;
2552 my $t_name = validate_input($4);
2553 if ($alternate) {
2554 print "<tr class=\"dark\">\n";
2555 } else {
2556 print "<tr class=\"light\">\n";
2558 $alternate ^= 1;
2559 print "<td class=\"mode\">" . mode_str($t_mode) . "</td>\n";
2560 if ($t_type eq "blob") {
2561 print "<td class=\"list\">" .
2562 $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key),
2563 -class => "list"}, esc_html($t_name)) .
2564 "</td>\n" .
2565 "<td class=\"link\">" .
2566 $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2567 "blob");
2568 if ($have_blame) {
2569 print " | " .
2570 $cgi->a({-href => href(action=>"blame", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2571 "blame");
2573 print " | " .
2574 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
2575 hash=>$t_hash, file_name=>"$base$t_name")},
2576 "history") .
2577 " | " .
2578 $cgi->a({-href => href(action=>"blob_plain",
2579 hash=>$t_hash, file_name=>"$base$t_name")},
2580 "raw") .
2581 "</td>\n";
2582 } elsif ($t_type eq "tree") {
2583 print "<td class=\"list\">" .
2584 $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2585 esc_html($t_name)) .
2586 "</td>\n" .
2587 "<td class=\"link\">" .
2588 $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2589 "tree") .
2590 " | " .
2591 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, file_name=>"$base$t_name")},
2592 "history") .
2593 "</td>\n";
2595 print "</tr>\n";
2597 print "</table>\n" .
2598 "</div>";
2599 git_footer_html();
2602 sub git_snapshot {
2604 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
2605 my $have_snapshot = (defined $ctype && defined $suffix);
2606 if (!$have_snapshot) {
2607 die_error('403 Permission denied', "Permission denied");
2610 if (!defined $hash) {
2611 $hash = git_get_head_hash($project);
2614 my $filename = basename($project) . "-$hash.tar.$suffix";
2616 print $cgi->header(-type => 'application/x-tar',
2617 -content_encoding => $ctype,
2618 -content_disposition => "inline; filename=\"$filename\"",
2619 -status => '200 OK');
2621 open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | $command" or
2622 die_error(undef, "Execute git-tar-tree failed.");
2623 binmode STDOUT, ':raw';
2624 print <$fd>;
2625 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
2626 close $fd;
2630 sub git_log {
2631 my $head = git_get_head_hash($project);
2632 if (!defined $hash) {
2633 $hash = $head;
2635 if (!defined $page) {
2636 $page = 0;
2638 my $refs = git_get_references();
2640 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2641 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2642 or die_error(undef, "Open git-rev-list failed");
2643 my @revlist = map { chomp; $_ } <$fd>;
2644 close $fd;
2646 my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#revlist);
2648 git_header_html();
2649 git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
2651 if (!@revlist) {
2652 my %co = parse_commit($hash);
2654 git_print_header_div('summary', $project);
2655 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2657 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2658 my $commit = $revlist[$i];
2659 my $ref = format_ref_marker($refs, $commit);
2660 my %co = parse_commit($commit);
2661 next if !%co;
2662 my %ad = parse_date($co{'author_epoch'});
2663 git_print_header_div('commit',
2664 "<span class=\"age\">$co{'age_string'}</span>" .
2665 esc_html($co{'title'}) . $ref,
2666 $commit);
2667 print "<div class=\"title_text\">\n" .
2668 "<div class=\"log_link\">\n" .
2669 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
2670 " | " .
2671 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
2672 "<br/>\n" .
2673 "</div>\n" .
2674 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2675 "</div>\n";
2677 print "<div class=\"log_body\">\n";
2678 git_print_simplified_log($co{'comment'});
2679 print "</div>\n";
2681 git_footer_html();
2684 sub git_commit {
2685 my %co = parse_commit($hash);
2686 if (!%co) {
2687 die_error(undef, "Unknown commit object");
2689 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
2690 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
2692 my $parent = $co{'parent'};
2693 if (!defined $parent) {
2694 $parent = "--root";
2696 open my $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts, $parent, $hash
2697 or die_error(undef, "Open git-diff-tree failed");
2698 my @difftree = map { chomp; $_ } <$fd>;
2699 close $fd or die_error(undef, "Reading git-diff-tree failed");
2701 # non-textual hash id's can be cached
2702 my $expires;
2703 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2704 $expires = "+1d";
2706 my $refs = git_get_references();
2707 my $ref = format_ref_marker($refs, $co{'id'});
2709 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
2710 my $have_snapshot = (defined $ctype && defined $suffix);
2712 my $formats_nav = '';
2713 if (defined $file_name && defined $co{'parent'}) {
2714 my $parent = $co{'parent'};
2715 $formats_nav .=
2716 $cgi->a({-href => href(action=>"blame", hash_parent=>$parent, file_name=>$file_name)},
2717 "blame");
2719 git_header_html(undef, $expires);
2720 git_print_page_nav('commit', defined $co{'parent'} ? '' : 'commitdiff',
2721 $hash, $co{'tree'}, $hash,
2722 $formats_nav);
2724 if (defined $co{'parent'}) {
2725 git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash);
2726 } else {
2727 git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash);
2729 print "<div class=\"title_text\">\n" .
2730 "<table cellspacing=\"0\">\n";
2731 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
2732 "<tr>" .
2733 "<td></td><td> $ad{'rfc2822'}";
2734 if ($ad{'hour_local'} < 6) {
2735 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2736 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2737 } else {
2738 printf(" (%02d:%02d %s)",
2739 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2741 print "</td>" .
2742 "</tr>\n";
2743 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
2744 print "<tr><td></td><td> $cd{'rfc2822'}" .
2745 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2746 "</td></tr>\n";
2747 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2748 print "<tr>" .
2749 "<td>tree</td>" .
2750 "<td class=\"sha1\">" .
2751 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),
2752 class => "list"}, $co{'tree'}) .
2753 "</td>" .
2754 "<td class=\"link\">" .
2755 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},
2756 "tree");
2757 if ($have_snapshot) {
2758 print " | " .
2759 $cgi->a({-href => href(action=>"snapshot", hash=>$hash)}, "snapshot");
2761 print "</td>" .
2762 "</tr>\n";
2763 my $parents = $co{'parents'};
2764 foreach my $par (@$parents) {
2765 print "<tr>" .
2766 "<td>parent</td>" .
2767 "<td class=\"sha1\">" .
2768 $cgi->a({-href => href(action=>"commit", hash=>$par),
2769 class => "list"}, $par) .
2770 "</td>" .
2771 "<td class=\"link\">" .
2772 $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") .
2773 " | " .
2774 $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "diff") .
2775 "</td>" .
2776 "</tr>\n";
2778 print "</table>".
2779 "</div>\n";
2781 print "<div class=\"page_body\">\n";
2782 git_print_log($co{'comment'});
2783 print "</div>\n";
2785 git_difftree_body(\@difftree, $hash, $parent);
2787 git_footer_html();
2790 sub git_blobdiff {
2791 my $format = shift || 'html';
2793 my $fd;
2794 my @difftree;
2795 my %diffinfo;
2796 my $expires;
2798 # preparing $fd and %diffinfo for git_patchset_body
2799 # new style URI
2800 if (defined $hash_base && defined $hash_parent_base) {
2801 if (defined $file_name) {
2802 # read raw output
2803 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
2804 "--", $file_name
2805 or die_error(undef, "Open git-diff-tree failed");
2806 @difftree = map { chomp; $_ } <$fd>;
2807 close $fd
2808 or die_error(undef, "Reading git-diff-tree failed");
2809 @difftree
2810 or die_error('404 Not Found', "Blob diff not found");
2812 } elsif (defined $hash &&
2813 $hash =~ /[0-9a-fA-F]{40}/) {
2814 # try to find filename from $hash
2816 # read filtered raw output
2817 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
2818 or die_error(undef, "Open git-diff-tree failed");
2819 @difftree =
2820 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
2821 # $hash == to_id
2822 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
2823 map { chomp; $_ } <$fd>;
2824 close $fd
2825 or die_error(undef, "Reading git-diff-tree failed");
2826 @difftree
2827 or die_error('404 Not Found', "Blob diff not found");
2829 } else {
2830 die_error('404 Not Found', "Missing one of the blob diff parameters");
2833 if (@difftree > 1) {
2834 die_error('404 Not Found', "Ambiguous blob diff specification");
2837 %diffinfo = parse_difftree_raw_line($difftree[0]);
2838 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
2839 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
2841 $hash_parent ||= $diffinfo{'from_id'};
2842 $hash ||= $diffinfo{'to_id'};
2844 # non-textual hash id's can be cached
2845 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
2846 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
2847 $expires = '+1d';
2850 # open patch output
2851 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts,
2852 '-p', $hash_parent_base, $hash_base,
2853 "--", $file_name
2854 or die_error(undef, "Open git-diff-tree failed");
2857 # old/legacy style URI
2858 if (!%diffinfo && # if new style URI failed
2859 defined $hash && defined $hash_parent) {
2860 # fake git-diff-tree raw output
2861 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
2862 $diffinfo{'from_id'} = $hash_parent;
2863 $diffinfo{'to_id'} = $hash;
2864 if (defined $file_name) {
2865 if (defined $file_parent) {
2866 $diffinfo{'status'} = '2';
2867 $diffinfo{'from_file'} = $file_parent;
2868 $diffinfo{'to_file'} = $file_name;
2869 } else { # assume not renamed
2870 $diffinfo{'status'} = '1';
2871 $diffinfo{'from_file'} = $file_name;
2872 $diffinfo{'to_file'} = $file_name;
2874 } else { # no filename given
2875 $diffinfo{'status'} = '2';
2876 $diffinfo{'from_file'} = $hash_parent;
2877 $diffinfo{'to_file'} = $hash;
2880 # non-textual hash id's can be cached
2881 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
2882 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
2883 $expires = '+1d';
2886 # open patch output
2887 open $fd, "-|", $GIT, "diff", '-p', @diff_opts, $hash_parent, $hash
2888 or die_error(undef, "Open git-diff failed");
2889 } else {
2890 die_error('404 Not Found', "Missing one of the blob diff parameters")
2891 unless %diffinfo;
2894 # header
2895 if ($format eq 'html') {
2896 my $formats_nav =
2897 $cgi->a({-href => href(action=>"blobdiff_plain",
2898 hash=>$hash, hash_parent=>$hash_parent,
2899 hash_base=>$hash_base, hash_parent_base=>$hash_parent_base,
2900 file_name=>$file_name, file_parent=>$file_parent)},
2901 "plain");
2902 git_header_html(undef, $expires);
2903 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2904 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2905 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2906 } else {
2907 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
2908 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
2910 if (defined $file_name) {
2911 git_print_page_path($file_name, "blob", $hash_base);
2912 } else {
2913 print "<div class=\"page_path\"></div>\n";
2916 } elsif ($format eq 'plain') {
2917 print $cgi->header(
2918 -type => 'text/plain',
2919 -charset => 'utf-8',
2920 -expires => $expires,
2921 -content_disposition => qq(inline; filename="${file_name}.patch"));
2923 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
2925 } else {
2926 die_error(undef, "Unknown blobdiff format");
2929 # patch
2930 if ($format eq 'html') {
2931 print "<div class=\"page_body\">\n";
2933 git_patchset_body($fd, [ \%diffinfo ], $hash_base, $hash_parent_base);
2934 close $fd;
2936 print "</div>\n"; # class="page_body"
2937 git_footer_html();
2939 } else {
2940 while (my $line = <$fd>) {
2941 $line =~ s!a/($hash|$hash_parent)!a/$diffinfo{'from_file'}!g;
2942 $line =~ s!b/($hash|$hash_parent)!b/$diffinfo{'to_file'}!g;
2944 print $line;
2946 last if $line =~ m!^\+\+\+!;
2948 local $/ = undef;
2949 print <$fd>;
2950 close $fd;
2954 sub git_blobdiff_plain {
2955 git_blobdiff('plain');
2958 sub git_commitdiff {
2959 my $format = shift || 'html';
2960 my %co = parse_commit($hash);
2961 if (!%co) {
2962 die_error(undef, "Unknown commit object");
2964 if (!defined $hash_parent) {
2965 $hash_parent = $co{'parent'} || '--root';
2968 # read commitdiff
2969 my $fd;
2970 my @difftree;
2971 if ($format eq 'html') {
2972 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts,
2973 "--patch-with-raw", "--full-index", $hash_parent, $hash
2974 or die_error(undef, "Open git-diff-tree failed");
2976 while (chomp(my $line = <$fd>)) {
2977 # empty line ends raw part of diff-tree output
2978 last unless $line;
2979 push @difftree, $line;
2982 } elsif ($format eq 'plain') {
2983 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts,
2984 '-p', $hash_parent, $hash
2985 or die_error(undef, "Open git-diff-tree failed");
2987 } else {
2988 die_error(undef, "Unknown commitdiff format");
2991 # non-textual hash id's can be cached
2992 my $expires;
2993 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2994 $expires = "+1d";
2997 # write commit message
2998 if ($format eq 'html') {
2999 my $refs = git_get_references();
3000 my $ref = format_ref_marker($refs, $co{'id'});
3001 my $formats_nav =
3002 $cgi->a({-href => href(action=>"commitdiff_plain",
3003 hash=>$hash, hash_parent=>$hash_parent)},
3004 "plain");
3006 git_header_html(undef, $expires);
3007 git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3008 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
3009 git_print_authorship(\%co);
3010 print "<div class=\"page_body\">\n";
3011 print "<div class=\"log\">\n";
3012 git_print_simplified_log($co{'comment'}, 1); # skip title
3013 print "</div>\n"; # class="log"
3015 } elsif ($format eq 'plain') {
3016 my $refs = git_get_references("tags");
3017 my $tagname = git_get_rev_name_tags($hash);
3018 my $filename = basename($project) . "-$hash.patch";
3020 print $cgi->header(
3021 -type => 'text/plain',
3022 -charset => 'utf-8',
3023 -expires => $expires,
3024 -content_disposition => qq(inline; filename="$filename"));
3025 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
3026 print <<TEXT;
3027 From: $co{'author'}
3028 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3029 Subject: $co{'title'}
3030 TEXT
3031 print "X-Git-Tag: $tagname\n" if $tagname;
3032 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3034 foreach my $line (@{$co{'comment'}}) {
3035 print "$line\n";
3037 print "---\n\n";
3040 # write patch
3041 if ($format eq 'html') {
3042 git_difftree_body(\@difftree, $hash, $hash_parent);
3043 print "<br/>\n";
3045 git_patchset_body($fd, \@difftree, $hash, $hash_parent);
3046 close $fd;
3047 print "</div>\n"; # class="page_body"
3048 git_footer_html();
3050 } elsif ($format eq 'plain') {
3051 local $/ = undef;
3052 print <$fd>;
3053 close $fd
3054 or print "Reading git-diff-tree failed\n";
3058 sub git_commitdiff_plain {
3059 git_commitdiff('plain');
3062 sub git_history {
3063 if (!defined $hash_base) {
3064 $hash_base = git_get_head_hash($project);
3066 my $ftype;
3067 my %co = parse_commit($hash_base);
3068 if (!%co) {
3069 die_error(undef, "Unknown commit object");
3071 my $refs = git_get_references();
3072 git_header_html();
3073 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base);
3074 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
3075 if (!defined $hash && defined $file_name) {
3076 $hash = git_get_hash_by_path($hash_base, $file_name);
3078 if (defined $hash) {
3079 $ftype = git_get_type($hash);
3081 git_print_page_path($file_name, $ftype, $hash_base);
3083 open my $fd, "-|",
3084 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
3085 git_history_body($fd, $refs, $hash_base, $ftype);
3087 close $fd;
3088 git_footer_html();
3091 sub git_search {
3092 if (!defined $searchtext) {
3093 die_error(undef, "Text field empty");
3095 if (!defined $hash) {
3096 $hash = git_get_head_hash($project);
3098 my %co = parse_commit($hash);
3099 if (!%co) {
3100 die_error(undef, "Unknown commit object");
3102 # pickaxe may take all resources of your box and run for several minutes
3103 # with every query - so decide by yourself how public you make this feature :)
3104 my $commit_search = 1;
3105 my $author_search = 0;
3106 my $committer_search = 0;
3107 my $pickaxe_search = 0;
3108 if ($searchtext =~ s/^author\\://i) {
3109 $author_search = 1;
3110 } elsif ($searchtext =~ s/^committer\\://i) {
3111 $committer_search = 1;
3112 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3113 $commit_search = 0;
3114 $pickaxe_search = 1;
3116 git_header_html();
3117 git_print_page_nav('','', $hash,$co{'tree'},$hash);
3118 git_print_header_div('commit', esc_html($co{'title'}), $hash);
3120 print "<table cellspacing=\"0\">\n";
3121 my $alternate = 0;
3122 if ($commit_search) {
3123 $/ = "\0";
3124 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
3125 while (my $commit_text = <$fd>) {
3126 if (!grep m/$searchtext/i, $commit_text) {
3127 next;
3129 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3130 next;
3132 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3133 next;
3135 my @commit_lines = split "\n", $commit_text;
3136 my %co = parse_commit(undef, \@commit_lines);
3137 if (!%co) {
3138 next;
3140 if ($alternate) {
3141 print "<tr class=\"dark\">\n";
3142 } else {
3143 print "<tr class=\"light\">\n";
3145 $alternate ^= 1;
3146 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3147 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3148 "<td>" .
3149 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"},
3150 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
3151 my $comment = $co{'comment'};
3152 foreach my $line (@$comment) {
3153 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3154 my $lead = esc_html($1) || "";
3155 $lead = chop_str($lead, 30, 10);
3156 my $match = esc_html($2) || "";
3157 my $trail = esc_html($3) || "";
3158 $trail = chop_str($trail, 30, 10);
3159 my $text = "$lead<span class=\"match\">$match</span>$trail";
3160 print chop_str($text, 80, 5) . "<br/>\n";
3163 print "</td>\n" .
3164 "<td class=\"link\">" .
3165 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
3166 " | " .
3167 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
3168 print "</td>\n" .
3169 "</tr>\n";
3171 close $fd;
3174 if ($pickaxe_search) {
3175 $/ = "\n";
3176 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
3177 undef %co;
3178 my @files;
3179 while (my $line = <$fd>) {
3180 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3181 my %set;
3182 $set{'file'} = $6;
3183 $set{'from_id'} = $3;
3184 $set{'to_id'} = $4;
3185 $set{'id'} = $set{'to_id'};
3186 if ($set{'id'} =~ m/0{40}/) {
3187 $set{'id'} = $set{'from_id'};
3189 if ($set{'id'} =~ m/0{40}/) {
3190 next;
3192 push @files, \%set;
3193 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3194 if (%co) {
3195 if ($alternate) {
3196 print "<tr class=\"dark\">\n";
3197 } else {
3198 print "<tr class=\"light\">\n";
3200 $alternate ^= 1;
3201 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3202 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3203 "<td>" .
3204 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
3205 -class => "list subject"},
3206 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
3207 while (my $setref = shift @files) {
3208 my %set = %$setref;
3209 print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},
3210 hash=>$set{'id'}, file_name=>$set{'file'}),
3211 -class => "list"},
3212 "<span class=\"match\">" . esc_html($set{'file'}) . "</span>") .
3213 "<br/>\n";
3215 print "</td>\n" .
3216 "<td class=\"link\">" .
3217 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
3218 " | " .
3219 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
3220 print "</td>\n" .
3221 "</tr>\n";
3223 %co = parse_commit($1);
3226 close $fd;
3228 print "</table>\n";
3229 git_footer_html();
3232 sub git_shortlog {
3233 my $head = git_get_head_hash($project);
3234 if (!defined $hash) {
3235 $hash = $head;
3237 if (!defined $page) {
3238 $page = 0;
3240 my $refs = git_get_references();
3242 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3243 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
3244 or die_error(undef, "Open git-rev-list failed");
3245 my @revlist = map { chomp; $_ } <$fd>;
3246 close $fd;
3248 my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, $#revlist);
3249 my $next_link = '';
3250 if ($#revlist >= (100 * ($page+1)-1)) {
3251 $next_link =
3252 $cgi->a({-href => href(action=>"shortlog", hash=>$hash, page=>$page+1),
3253 -title => "Alt-n"}, "next");
3257 git_header_html();
3258 git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);
3259 git_print_header_div('summary', $project);
3261 git_shortlog_body(\@revlist, ($page * 100), $#revlist, $refs, $next_link);
3263 git_footer_html();
3266 ## ......................................................................
3267 ## feeds (RSS, OPML)
3269 sub git_rss {
3270 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3271 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash($project)
3272 or die_error(undef, "Open git-rev-list failed");
3273 my @revlist = map { chomp; $_ } <$fd>;
3274 close $fd or die_error(undef, "Reading git-rev-list failed");
3275 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
3276 print <<XML;
3277 <?xml version="1.0" encoding="utf-8"?>
3278 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3279 <channel>
3280 <title>$project $my_uri $my_url</title>
3281 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3282 <description>$project log</description>
3283 <language>en</language>
3286 for (my $i = 0; $i <= $#revlist; $i++) {
3287 my $commit = $revlist[$i];
3288 my %co = parse_commit($commit);
3289 # we read 150, we always show 30 and the ones more recent than 48 hours
3290 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3291 last;
3293 my %cd = parse_date($co{'committer_epoch'});
3294 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts,
3295 $co{'parent'}, $co{'id'}
3296 or next;
3297 my @difftree = map { chomp; $_ } <$fd>;
3298 close $fd
3299 or next;
3300 print "<item>\n" .
3301 "<title>" .
3302 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) .
3303 "</title>\n" .
3304 "<author>" . esc_html($co{'author'}) . "</author>\n" .
3305 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3306 "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3307 "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3308 "<description>" . esc_html($co{'title'}) . "</description>\n" .
3309 "<content:encoded>" .
3310 "<![CDATA[\n";
3311 my $comment = $co{'comment'};
3312 foreach my $line (@$comment) {
3313 $line = decode("utf8", $line, Encode::FB_DEFAULT);
3314 print "$line<br/>\n";
3316 print "<br/>\n";
3317 foreach my $line (@difftree) {
3318 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3319 next;
3321 my $file = validate_input(unquote($7));
3322 $file = decode("utf8", $file, Encode::FB_DEFAULT);
3323 print "$file<br/>\n";
3325 print "]]>\n" .
3326 "</content:encoded>\n" .
3327 "</item>\n";
3329 print "</channel></rss>";
3332 sub git_opml {
3333 my @list = git_get_projects_list();
3335 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
3336 print <<XML;
3337 <?xml version="1.0" encoding="utf-8"?>
3338 <opml version="1.0">
3339 <head>
3340 <title>$site_name Git OPML Export</title>
3341 </head>
3342 <body>
3343 <outline text="git RSS feeds">
3346 foreach my $pr (@list) {
3347 my %proj = %$pr;
3348 my $head = git_get_head_hash($proj{'path'});
3349 if (!defined $head) {
3350 next;
3352 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
3353 my %co = parse_commit($head);
3354 if (!%co) {
3355 next;
3358 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
3359 my $rss = "$my_url?p=$proj{'path'};a=rss";
3360 my $html = "$my_url?p=$proj{'path'};a=summary";
3361 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
3363 print <<XML;
3364 </outline>
3365 </body>
3366 </opml>