Merge branch 'jn/gitweb-blame' (early part)

* 'jn/gitweb-blame' (early part):
  gitweb: Use light/dark for class names also in 'blame' view
  gitweb: Add author initials in 'blame' view, a la "git gui blame"
  gitweb: Mark commits with no "previous" in 'blame' view
  gitweb: Use "previous" header of git-blame -p in 'blame' view
  gitweb: Mark boundary commits in 'blame' view
  gitweb: Make .error style generic
maint
Junio C Hamano 2009-08-14 16:32:52 -07:00
commit 5a3669340b
2 changed files with 49 additions and 25 deletions

View File

@ -226,22 +226,30 @@ th {
text-align: left; text-align: left;
} }


tr.light:hover { /* do not change row style on hover for 'blame' view */
background-color: #edece6; tr.light,
table.blame .light:hover {
background-color: #ffffff;
} }


tr.dark { tr.dark,
background-color: #f6f6f0; table.blame .dark:hover {
}

tr.dark2 {
background-color: #f6f6f0; background-color: #f6f6f0;
} }


/* currently both use the same, but it can change */
tr.light:hover,
tr.dark:hover { tr.dark:hover {
background-color: #edece6; background-color: #edece6;
} }


/* boundary commits in 'blame' view */
/* and commits without "previous" */
tr.boundary td.sha1,
tr.no-previous td.linenr {
font-weight: bold;
}

td { td {
padding: 2px 5px; padding: 2px 5px;
font-size: 100%; font-size: 100%;
@ -262,7 +270,7 @@ td.sha1 {
font-family: monospace; font-family: monospace;
} }


td.error { .error {
color: red; color: red;
background-color: yellow; background-color: yellow;
} }

View File

@ -4803,7 +4803,7 @@ sub git_blame {
git_print_page_path($file_name, $ftype, $hash_base); git_print_page_path($file_name, $ftype, $hash_base);


# page body # page body
my @rev_color = qw(light2 dark2); my @rev_color = qw(light dark);
my $num_colors = scalar(@rev_color); my $num_colors = scalar(@rev_color);
my $current_color = 0; my $current_color = 0;
my %metainfo = (); my %metainfo = ();
@ -4821,15 +4821,18 @@ HTML
my ($full_rev, $orig_lineno, $lineno, $group_size) = my ($full_rev, $orig_lineno, $lineno, $group_size) =
($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/); ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
if (!exists $metainfo{$full_rev}) { if (!exists $metainfo{$full_rev}) {
$metainfo{$full_rev} = {}; $metainfo{$full_rev} = { 'nprevious' => 0 };
} }
my $meta = $metainfo{$full_rev}; my $meta = $metainfo{$full_rev};
my $data; my $data;
while ($data = <$fd>) { while ($data = <$fd>) {
chomp $data; chomp $data;
last if ($data =~ s/^\t//); # contents of line last if ($data =~ s/^\t//); # contents of line
if ($data =~ /^(\S+) (.*)$/) { if ($data =~ /^(\S+)(?: (.*))?$/) {
$meta->{$1} = $2; $meta->{$1} = $2 unless exists $meta->{$1};
}
if ($data =~ /^previous /) {
$meta->{'nprevious'}++;
} }
} }
my $short_rev = substr($full_rev, 0, 8); my $short_rev = substr($full_rev, 0, 8);
@ -4840,7 +4843,11 @@ HTML
if ($group_size) { if ($group_size) {
$current_color = ($current_color + 1) % $num_colors; $current_color = ($current_color + 1) % $num_colors;
} }
print "<tr id=\"l$lineno\" class=\"$rev_color[$current_color]\">\n"; my $tr_class = $rev_color[$current_color];
$tr_class .= ' boundary' if (exists $meta->{'boundary'});
$tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
$tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
if ($group_size) { if ($group_size) {
print "<td class=\"sha1\""; print "<td class=\"sha1\"";
print " title=\"". esc_html($author) . ", $date\""; print " title=\"". esc_html($author) . ", $date\"";
@ -4850,22 +4857,31 @@ HTML
hash=>$full_rev, hash=>$full_rev,
file_name=>$file_name)}, file_name=>$file_name)},
esc_html($short_rev)); esc_html($short_rev));
if ($group_size >= 2) {
my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
if (@author_initials) {
print "<br />" .
esc_html(join('', @author_initials));
# or join('.', ...)
}
}
print "</td>\n"; print "</td>\n";
} }
my $parent_commit; # 'previous' <sha1 of parent commit> <filename at commit>
if (!exists $meta->{'parent'}) { if (exists $meta->{'previous'} &&
open (my $dd, "-|", git_cmd(), "rev-parse", "$full_rev^") $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
or die_error(500, "Open git-rev-parse failed"); $meta->{'parent'} = $1;
$parent_commit = <$dd>; $meta->{'file_parent'} = unquote($2);
close $dd;
chomp($parent_commit);
$meta->{'parent'} = $parent_commit;
} else {
$parent_commit = $meta->{'parent'};
} }
my $linenr_commit =
exists($meta->{'parent'}) ?
$meta->{'parent'} : $full_rev;
my $linenr_filename =
exists($meta->{'file_parent'}) ?
$meta->{'file_parent'} : unquote($meta->{'filename'});
my $blamed = href(action => 'blame', my $blamed = href(action => 'blame',
file_name => $meta->{'filename'}, file_name => $linenr_filename,
hash_base => $parent_commit); hash_base => $linenr_commit);
print "<td class=\"linenr\">"; print "<td class=\"linenr\">";
print $cgi->a({ -href => "$blamed#l$orig_lineno", print $cgi->a({ -href => "$blamed#l$orig_lineno",
-class => "linenr" }, -class => "linenr" },