diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 4106cb8eb6..57f4a2e263 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -227,7 +227,7 @@ if (!defined $action || $action eq "summary") { git_tag(); exit; } elsif ($action eq "blame") { - git_blame(); + git_blame2(); exit; } else { undef $action; @@ -1252,6 +1252,75 @@ sub git_tag { git_footer_html(); } +sub git_read_blame_line { + my %bl; + $_ = shift; + + ($bl{'hash'}, $bl{'lineno'}, $bl{'data'}) = /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/; + + return %bl; +} + +sub git_blame2 { + my $fd; + my $ftype; + die_error(undef, "Permission denied.") if (!git_get_project_config_bool ('blame')); + die_error('404 Not Found', "File name not defined") if (!$file_name); + $hash_base ||= git_read_head($project); + die_error(undef, "Reading commit failed") unless ($hash_base); + my %co = git_read_commit($hash_base) + or die_error(undef, "Reading commit failed"); + if (!defined $hash) { + $hash = git_get_hash_by_path($hash_base, $file_name, "blob") + or die_error(undef, "Error looking up file"); + } + $ftype = git_get_type($hash); + if ($ftype !~ "blob") { + die_error("400 Bad Request", "object is not a blob"); + } + open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base) + or die_error(undef, "Open failed"); + git_header_html(); + print "
Commit | Line | Data |
---|---|---|
" . + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html($rev)) . " | \n"; + print "" . esc_html($lineno) . " | \n"; + print "" . esc_html($data) . " | \n"; + print "