@matheusbsbs / matheus-bagliano / commits / e133d65c3e
Fork 0

gitweb: linkify author/committer names with search

It's nice to search for an author by merely clicking on their name in gitweb. This is usually faster than selecting the name, copying the selection, pasting it into the search box, selecting between author/committer and then hitting enter. Linkify the avatar icon in log/shortlog view because the icon is directly adjacent to the name and thus more related. The same is not true when in commit/tag view where the icon is farther away. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stephen Boyd committed Oct 15, 2009 at 21:14 UTC e133d65c3e3d7f5f869edb2d6205af68af0fe38f
2 files changed +39 -5
gitweb/gitweb.css
+4
@@ -32,6 +32,10 @@ img.avatar {
32 vertical-align: middle;
33 }
34
35 +a.list img.avatar {
36 + border-style: none;
37 +}
38 +
39 div.page_header {
40 height: 25px;
41 padding: 8px;
gitweb/gitweb.perl
+35 -5
@@ -1594,6 +1594,29 @@ sub git_get_avatar {
1594 }
1595 }
1596
1597 +sub format_search_author {
1598 + my ($author, $searchtype, $displaytext) = @_;
1599 + my $have_search = gitweb_check_feature('search');
1600 +
1601 + if ($have_search) {
1602 + my $performed = "";
1603 + if ($searchtype eq 'author') {
1604 + $performed = "authored";
1605 + } elsif ($searchtype eq 'committer') {
1606 + $performed = "committed";
1607 + }
1608 +
1609 + return $cgi->a({-href => href(action=>"search", hash=>$hash,
1610 + searchtext=>$author,
1611 + searchtype=>$searchtype), class=>"list",
1612 + title=>"Search for commits $performed by $author"},
1613 + $displaytext);
1614 +
1615 + } else {
1616 + return $displaytext;
1617 + }
1618 +}
1619 +
1620 # format the author name of the given commit with the given tag
1621 # the author name is chopped and escaped according to the other
1622 # optional parameters (see chop_str).
@@ -1602,8 +1625,10 @@ sub format_author_html {
1625 my $co = shift;
1626 my $author = chop_and_escape_str($co->{'author_name'}, @_);
1627 return "<$tag class=\"author\">" .
1605 - git_get_avatar($co->{'author_email'}, -pad_after => 1) .
1606 - $author . "</$tag>";
1628 + format_search_author($co->{'author_name'}, "author",
1629 + git_get_avatar($co->{'author_email'}, -pad_after => 1) .
1630 + $author) .
1631 + "</$tag>";
1632 }
1633
1634 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
@@ -3372,10 +3397,11 @@ sub git_print_authorship {
3397 my $co = shift;
3398 my %opts = @_;
3399 my $tag = $opts{-tag} || 'div';
3400 + my $author = $co->{'author_name'};
3401
3402 my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
3403 print "<$tag class=\"author_date\">" .
3378 - esc_html($co->{'author_name'}) .
3404 + format_search_author($author, "author", esc_html($author)) .
3405 " [$ad{'rfc2822'}";
3406 print_local_time(%ad) if ($opts{-localtime});
3407 print "]" . git_get_avatar($co->{'author_email'}, -pad_before => 1)
@@ -3394,8 +3420,12 @@ sub git_print_authorship_rows {
3420 @people = ('author', 'committer') unless @people;
3421 foreach my $who (@people) {
3422 my %wd = parse_date($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3397 - print "<tr><td>$who</td><td>" . esc_html($co->{$who}) . "</td>" .
3398 - "<td rowspan=\"2\">" .
3423 + print "<tr><td>$who</td><td>" .
3424 + format_search_author($co->{"${who}_name"}, $who,
3425 + esc_html($co->{"${who}_name"})) . " " .
3426 + format_search_author($co->{"${who}_email"}, $who,
3427 + esc_html("<" . $co->{"${who}_email"} . ">")) .
3428 + "</td><td rowspan=\"2\">" .
3429 git_get_avatar($co->{"${who}_email"}, -size => 'double') .
3430 "</td></tr>\n" .
3431 "<tr>" .