gitweb: linkify author/committer names with search
PATCH 1/1 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.
---
This is on top of Giuseppe's fix esc_param patch.
gitweb/gitweb.css | 1 + gitweb/gitweb.perl | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-)
gitweb/gitweb.css +1 -0
@@ -30,6 +30,7 @@ img.logo { img.avatar { vertical-align: middle; + border-width: 0px; } div.page_header {
gitweb/gitweb.perl +16 -5
@@ -1602,8 +1602,12 @@ sub format_author_html { my $co = shift; my $author = chop_and_escape_str($co->{'author_name'}, @_); return "<$tag class=\"author\">" . - git_get_avatar($co->{'author_email'}, -pad_after => 1) . - $author . "</$tag>"; + $cgi->a({-href => href(action=>"search", hash=>$hash, + searchtext=>$co->{'author_name'}, + searchtype=>"author"), class=>"list"}, + git_get_avatar($co->{'author_email'}, -pad_after => 1) . + $author) . + "</$tag>"; } # format git diff header line, i.e. "diff --(git|combined|cc) ..."
@@ -3372,10 +3376,13 @@ sub git_print_authorship { my $co = shift; my %opts = @_; my $tag = $opts{-tag} || 'div'; + my $author = $co->{'author_name'}; my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'}); print "<$tag class=\"author_date\">" . - esc_html($co->{'author_name'}) . + $cgi->a({-href => href(action=>"search", searchtext=>$author, + searchtype=>"author"), class=>"list"}, + esc_html($author)) . " [$ad{'rfc2822'}"; print_local_time(%ad) if ($opts{-localtime}); print "]" . git_get_avatar($co->{'author_email'}, -pad_before => 1)
@@ -3394,8 +3401,12 @@ sub git_print_authorship_rows { @people = ('author', 'committer') unless @people; foreach my $who (@people) { my %wd = parse_date($co->{"${who}_epoch"}, $co->{"${who}_tz"}); - print "<tr><td>$who</td><td>" . esc_html($co->{$who}) . "</td>" . - "<td rowspan=\"2\">" . + print "<tr><td>$who</td><td>" . + $cgi->a({-href => href(action=>"search", + searchtext=>$co->{"${who}_name"}, + searchtype=>$who), class=>"list"}, + esc_html($co->{$who})) . + "</td><td rowspan=\"2\">" . git_get_avatar($co->{"${who}_email"}, -size => 'double') . "</td></tr>\n" . "<tr>" .
Signature · 1 line
1.6.5.1.g75846.dirty
PATCH v2 1/1 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.
---
This is based off next now that Giuseppe's patch is there.
Changes since v1:
* CSS hack has been cleaned up to only remove the link border from avatar icons when actually linked.
* Checking for search capability to avoid generating search links (Wincent)
* Linking of name and email are separate in commit/commitdiff/tag views
The last one I figured I'd throw in because I'm doing it again.
gitweb/gitweb.css | 4 ++++ gitweb/gitweb.perl | 33 ++++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-)
gitweb/gitweb.css +4 -0
@@ -32,6 +32,10 @@ img.avatar { vertical-align: middle; } +a.list img.avatar { + border-style: none; +} + div.page_header { height: 25px; padding: 8px;
gitweb/gitweb.perl +28 -5
@@ -1625,6 +1625,22 @@ sub git_get_avatar { } } +sub format_search_author { + my $searchtext = shift; + my $searchtype = shift; + my $displaytext = shift; + my $have_search = gitweb_check_feature('search'); + if ($have_search) { + return $cgi->a({-href => href(action=>"search", hash=>$hash, + searchtext=>$searchtext, + searchtype=>$searchtype), class=>"list"}, + $displaytext); + + } else { + return $displaytext; + } +} + # format the author name of the given commit with the given tag # the author name is chopped and escaped according to the other # optional parameters (see chop_str).
@@ -1633,8 +1649,10 @@ sub format_author_html { my $co = shift; my $author = chop_and_escape_str($co->{'author_name'}, @_); return "<$tag class=\"author\">" . - git_get_avatar($co->{'author_email'}, -pad_after => 1) . - $author . "</$tag>"; + format_search_author($co->{'author_name'}, "author", + git_get_avatar($co->{'author_email'}, -pad_after => 1) . + $author) . + "</$tag>"; } # format git diff header line, i.e. "diff --(git|combined|cc) ..."
@@ -3433,10 +3451,11 @@ sub git_print_authorship { my $co = shift; my %opts = @_; my $tag = $opts{-tag} || 'div'; + my $author = $co->{'author_name'}; my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'}); print "<$tag class=\"author_date\">" . - esc_html($co->{'author_name'}) . + format_search_author($author, "author", esc_html($author)) . " [$ad{'rfc2822'}"; print_local_time(%ad) if ($opts{-localtime}); print "]" . git_get_avatar($co->{'author_email'}, -pad_before => 1)
@@ -3455,8 +3474,12 @@ sub git_print_authorship_rows { @people = ('author', 'committer') unless @people; foreach my $who (@people) { my %wd = parse_date($co->{"${who}_epoch"}, $co->{"${who}_tz"}); - print "<tr><td>$who</td><td>" . esc_html($co->{$who}) . "</td>" . - "<td rowspan=\"2\">" . + print "<tr><td>$who</td><td>" . + format_search_author($co->{"${who}_name"}, $who, + esc_html($co->{"${who}_name"})) . " " . + format_search_author($co->{"${who}_email"}, $who, + esc_html("<" . $co->{"${who}_email"} . ">")) . + "</td><td rowspan=\"2\">" . git_get_avatar($co->{"${who}_email"}, -size => 'double') . "</td></tr>\n" . "<tr>" .
Signature · 1 line
1.6.5.94.gcd2f3
PATCH v3 1/1 gitweb: linkify author/committer names with search
In reply to Stephen BoydIt'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.
---
Changes since v2:
* Add a title to make it not so suprising before you click (Jakub)
Changes since v1:
* CSS hack has been cleaned up to only remove the link border from avatar icons when actually linked.
* Checking for search capability to avoid generating search links (Wincent)
* Linking of name and email are separate in commit/commitdiff/tag views
gitweb/gitweb.css | 4 ++++ gitweb/gitweb.perl | 40 +++++++++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-)
gitweb/gitweb.css +4 -0
@@ -32,6 +32,10 @@ img.avatar { vertical-align: middle; } +a.list img.avatar { + border-style: none; +} + div.page_header { height: 25px; padding: 8px;
gitweb/gitweb.perl +35 -5
@@ -1625,6 +1625,29 @@ sub git_get_avatar { } } +sub format_search_author { + my ($author, $searchtype, $displaytext) = @_; + my $have_search = gitweb_check_feature('search'); + + if ($have_search) { + my $performed = ""; + if ($searchtype eq 'author') { + $performed = "authored"; + } elsif ($searchtype eq 'committer') { + $performed = "committed"; + } + + return $cgi->a({-href => href(action=>"search", hash=>$hash, + searchtext=>$author, + searchtype=>$searchtype), class=>"list", + title=>"Search for commits $performed by $author"}, + $displaytext); + + } else { + return $displaytext; + } +} + # format the author name of the given commit with the given tag # the author name is chopped and escaped according to the other # optional parameters (see chop_str).
@@ -1633,8 +1656,10 @@ sub format_author_html { my $co = shift; my $author = chop_and_escape_str($co->{'author_name'}, @_); return "<$tag class=\"author\">" . - git_get_avatar($co->{'author_email'}, -pad_after => 1) . - $author . "</$tag>"; + format_search_author($co->{'author_name'}, "author", + git_get_avatar($co->{'author_email'}, -pad_after => 1) . + $author) . + "</$tag>"; } # format git diff header line, i.e. "diff --(git|combined|cc) ..."
@@ -3433,10 +3458,11 @@ sub git_print_authorship { my $co = shift; my %opts = @_; my $tag = $opts{-tag} || 'div'; + my $author = $co->{'author_name'}; my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'}); print "<$tag class=\"author_date\">" . - esc_html($co->{'author_name'}) . + format_search_author($author, "author", esc_html($author)) . " [$ad{'rfc2822'}"; print_local_time(%ad) if ($opts{-localtime}); print "]" . git_get_avatar($co->{'author_email'}, -pad_before => 1)
@@ -3455,8 +3481,12 @@ sub git_print_authorship_rows { @people = ('author', 'committer') unless @people; foreach my $who (@people) { my %wd = parse_date($co->{"${who}_epoch"}, $co->{"${who}_tz"}); - print "<tr><td>$who</td><td>" . esc_html($co->{$who}) . "</td>" . - "<td rowspan=\"2\">" . + print "<tr><td>$who</td><td>" . + format_search_author($co->{"${who}_name"}, $who, + esc_html($co->{"${who}_name"})) . " " . + format_search_author($co->{"${who}_email"}, $who, + esc_html("<" . $co->{"${who}_email"} . ">")) . + "</td><td rowspan=\"2\">" . git_get_avatar($co->{"${who}_email"}, -size => 'double') . "</td></tr>\n" . "<tr>" .
Signature · 1 line
1.6.5.94.gb6c65
Quoted 4 lines · Stephen Boyd
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.
[...]
I see that it can be useful. But is this discoverable, and does this do expected thing? Most of links in gitweb lead to some view (page) that is specific to link; other lead to anchor on same page. Leading to search results can be unexpected.
Perhaps title explaining what does such link does would help? Or making style of this link distinct from other (dashed underline, dashed underline on mouseover, double underline, different mouse cursor on mouseover, etc.)?
Just my 2 eurocents. Feel free to ignore my ramblings.
Signature · 2 lines
Jakub Narebski Poland
Quoted 10 lines · Jakub Narebski
I see that it can be useful. But is this discoverable, and does this do expected thing? Most of links in gitweb lead to some view (page) that is specific to link; other lead to anchor on same page. Leading to search results can be unexpected.
Perhaps title explaining what does such link does would help? Or making style of this link distinct from other (dashed underline, dashed underline on mouseover, double underline, different mouse cursor on mouseover, etc.)?
A title sounds good. Something like "List commits by $author"? I'll try to write something up by tonight.
Quoted 23 lines · Stephen Boyd
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 <[email protected]>---
This is on top of Giuseppe's fix
esc_parampatch.gitweb/gitweb.css | 1 + gitweb/gitweb.perl | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-)gitweb/gitweb.css +0
-0
gitweb/gitweb.css img.logo { · line 34
Quoted 5 lines
gitweb/gitweb.css +1
-0@@ -30,6 +30,7 @@ img.logo { img.avatar { vertical-align: middle; + border-width: 0px; }
Even though it _might_ be a good thing to do, this looks an unrelated change,
Quoted 52 lines
gitweb/gitweb.css +0
-0div.page_header {gitweb/gitweb.perl +16
-5@@ -1602,8 +1602,12 @@ sub format_author_html { my $co = shift; my $author = chop_and_escape_str($co->{'author_name'}, @_); return "<$tag class=\"author\">" . - git_get_avatar($co->{'author_email'}, -pad_after => 1) . - $author . "</$tag>"; + $cgi->a({-href => href(action=>"search", hash=>$hash, + searchtext=>$co->{'author_name'}, + searchtype=>"author"), class=>"list"}, + git_get_avatar($co->{'author_email'}, -pad_after => 1) . + $author) . + "</$tag>"; } # format git diff header line, i.e. "diff --(git|combined|cc) ..."@@ -3372,10 +3376,13 @@ sub git_print_authorship { my $co = shift; my %opts = @_; my $tag = $opts{-tag} || 'div'; + my $author = $co->{'author_name'}; my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'}); print "<$tag class=\"author_date\">" . - esc_html($co->{'author_name'}) . + $cgi->a({-href => href(action=>"search", searchtext=>$author, + searchtype=>"author"), class=>"list"}, + esc_html($author)) . " [$ad{'rfc2822'}"; print_local_time(%ad) if ($opts{-localtime}); print "]" . git_get_avatar($co->{'author_email'}, -pad_before => 1)@@ -3394,8 +3401,12 @@ sub git_print_authorship_rows { @people = ('author', 'committer') unless @people; foreach my $who (@people) { my %wd = parse_date($co->{"${who}_epoch"}, $co->{"${who}_tz"}); - print "<tr><td>$who</td><td>" . esc_html($co->{$who}) . "</td>" . - "<td rowspan=\"2\">" . + print "<tr><td>$who</td><td>" . + $cgi->a({-href => href(action=>"search", + searchtext=>$co->{"${who}_name"}, + searchtype=>$who), class=>"list"}, + esc_html($co->{$who})) . + "</td><td rowspan=\"2\">" . git_get_avatar($co->{"${who}_email"}, -size => 'double') . "</td></tr>\n" . "<tr>" .Signature · 1 line
1.6.5.1.g75846.dirty
Quoted 4 lines · Stephen Boyd
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.
What about installs where search is turned off? (ie. with "$feature {'search'}{'default'} = [undef];" in gitweb.conf)
Cheers,
Wincent