+
+sub git_search {
+ if (!defined $searchtext) {
+ die_error("", "Text field empty.");
+ }
+ if (!defined $hash) {
+ $hash = git_read_hash("$project/HEAD");
+ }
+ my %co = git_read_commit($hash);
+ if (!%co) {
+ die_error(undef, "Unknown commit object.");
+ }
+ # pickaxe may take all resources of your box and run for several minutes
+ # with every query - so decide by yourself how public you make this feature :)
+ my $commit_search = 1;
+ my $author_search = 0;
+ my $committer_search = 0;
+ my $pickaxe_search = 0;
+ if ($searchtext =~ s/^author\\://i) {
+ $author_search = 1;
+ } elsif ($searchtext =~ s/^committer\\://i) {
+ $committer_search = 1;
+ } elsif ($searchtext =~ s/^pickaxe\\://i) {
+ $commit_search = 0;
+ $pickaxe_search = 1;
+ }
+ git_header_html();
+ print "<div class=\"page_nav\">\n" .
+ $cgi->a({-href => "$my_uri?p=$project;a=summary;h=$hash"}, "summary") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
+ "<br/><br/>\n" .
+ "</div>\n";
+
+ print "<div>\n" .
+ $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
+ "</div>\n";
+ print "<table cellspacing=\"0\">\n";
+ my $alternate = 0;
+ if ($commit_search) {
+ $/ = "\0";
+ open my $fd, "-|", "$gitbin/git-rev-list --header $hash";
+ while (my $commit_text = <$fd>) {
+ if (!grep m/$searchtext/i, $commit_text) {
+ next;
+ }
+ if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
+ next;
+ }
+ if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
+ next;
+ }
+ my @commit_lines = split "\n", $commit_text;
+ my $commit = shift @commit_lines;
+ my %co = git_read_commit($commit, \@commit_lines);
+ if (!%co) {
+ next;
+ }
+ if ($alternate) {
+ print "<tr class=\"dark\">\n";
+ } else {
+ print "<tr class=\"light\">\n";
+ }
+ $alternate ^= 1;
+ print "<td><i>$co{'age_string'}</i></td>\n" .
+ "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
+ "<td>" .
+ $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "<b>" . escapeHTML(chop_str($co{'title'}, 50)) . "</b><br/>");
+ my $comment = $co{'comment'};
+ foreach my $line (@$comment) {
+ if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
+ my $lead = escapeHTML($1) || "";
+ $lead = chop_str($lead, 30, 10);
+ my $match = escapeHTML($2) || "";
+ my $trail = escapeHTML($3) || "";
+ $trail = chop_str($trail, 30, 10);
+ my $text = "$lead<span style=\"color:#e00000\">$match</span>$trail";
+ print chop_str($text, 80, 5) . "<br/>\n";
+ }
+ }
+ print "</td>\n" .
+ "<td class=\"link\">" .
+ $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$commit"}, "tree");
+ print "</td>\n" .
+ "</tr>\n";
+ }
+ close $fd;
+ }
+
+ if ($pickaxe_search) {
+ $/ = "\n";
+ open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S$searchtext";
+ undef %co;
+ my @files;
+ while (my $line = <$fd>) {
+ if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
+ my %set;
+ $set{'file'} = $6;
+ $set{'from_id'} = $3;
+ $set{'to_id'} = $4;
+ $set{'id'} = $set{'to_id'};
+ if ($set{'id'} =~ m/0{40}/) {
+ $set{'id'} = $set{'from_id'};
+ }
+ if ($set{'id'} =~ m/0{40}/) {
+ next;
+ }
+ push @files, \%set;
+ } elsif ($line =~ m/^([0-9a-fA-F]{40}) /){
+ if (%co) {
+ if ($alternate) {
+ print "<tr class=\"dark\">\n";
+ } else {
+ print "<tr class=\"light\">\n";
+ }
+ $alternate ^= 1;
+ print "<td><i>$co{'age_string'}</i></td>\n" .
+ "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
+ "<td>" .
+ $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$co{'id'}", -class => "list"}, "<b>" .
+ escapeHTML(chop_str($co{'title'}, 50)) . "</b><br/>");
+ while (my $setref = shift @files) {
+ my %set = %$setref;
+ print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}", class => "list"},
+ "<span style=\"color:#e00000\">" . escapeHTML($set{'file'}) . "</span>") .
+ "<br/>\n";
+ }
+ print "</td>\n" .
+ "<td class=\"link\">" .
+ $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$co{'id'}"}, "commit") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}"}, "tree");
+ print "</td>\n" .
+ "</tr>\n";
+ }
+ %co = git_read_commit($1);
+ }
+ }
+ close $fd;
+ }
+ print "</table>\n";
+ git_footer_html();
+}
+
+sub git_shortlog {
+ my $head = git_read_hash("$project/HEAD");
+ if (!defined $hash) {
+ $hash = $head;
+ }
+ if (!defined $page) {
+ $page = 0;
+ }
+ git_header_html();
+ print "<div class=\"page_nav\">\n" .
+ $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
+ " | shortlog" .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash;hb=$hash"}, "tree") . "<br/>\n";
+
+ my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
+ open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
+ my (@revlist) = map { chomp; $_ } <$fd>;
+ close $fd;
+
+ if ($hash ne $head || $page) {
+ print $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "HEAD");
+ } else {
+ print "HEAD";
+ }
+ if ($page > 0) {
+ print " ⋅ " .
+ $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page-1), -accesskey => "p", -title => "Alt-p"}, "prev");
+ } else {
+ print " ⋅ prev";
+ }
+ if ($#revlist >= (100 * ($page+1)-1)) {
+ print " ⋅ " .
+ $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page+1), -accesskey => "n", -title => "Alt-n"}, "next");
+ } else {
+ print " ⋅ next";
+ }
+ print "<br/>\n" .
+ "</div>\n";
+ print "<div>\n" .
+ $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, " ") .
+ "</div>\n";
+ print "<table cellspacing=\"0\">\n";
+ my $alternate = 0;
+ for (my $i = ($page * 100); $i <= $#revlist; $i++) {
+ my $commit = $revlist[$i];
+ my %co = git_read_commit($commit);
+ my %ad = date_str($co{'author_epoch'});
+ if ($alternate) {
+ print "<tr class=\"dark\">\n";
+ } else {
+ print "<tr class=\"light\">\n";
+ }
+ $alternate ^= 1;
+ print "<td><i>$co{'age_string'}</i></td>\n" .
+ "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
+ "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "<b>" .
+ escapeHTML($co{'title_short'}) . "</b>") . "</td>\n" .
+ "<td class=\"link\">" .
+ $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .
+ "</td>\n" .
+ "</tr>";
+ }
+ if ($#revlist >= (100 * ($page+1)-1)) {
+ print "<tr>\n" .
+ "<td>" .
+ $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page+1), -title => "Alt-n"}, "next") .
+ "</td>\n" .
+ "</tr>\n";
+ }
+ print "</table\n>";
+ git_footer_html();
+}