From 1f2857ea32fa82ba6039b7fd298dc763b1e6c112 Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Sun, 23 Jul 2006 13:34:55 -0700 Subject: gitweb.cgi: git_blame2: an alternative simple working git blame This patch adds an alternative simple working git-blame called git_blame2(). Simple, because it displays just three columns: the commit, the line number and the line of code. Alternative, because the original git_blame() is left untouched. Lines of code are printed html escaped, but as-is. git_blame2() uses git-blame as opposed to git-annotate used by git_blame(). Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) (limited to 'gitweb') 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 "
\n" . + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "
\n"; + print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;f=$file_name")}, "head") . "
\n"; + print "
\n". + "
" . + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . + "
\n"; + git_print_page_path($file_name, $ftype); + + print "
\n"; + + print "\n"; + print "\n"; + while (my $line = <$fd>) { + my %blame_line = git_read_blame_line($line); + my $full_rev = $blame_line{'hash'}; + my $rev = substr($full_rev, 0, 8); + my $lineno = $blame_line{'lineno'}; + my $data = $blame_line{'data'}; + + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + } + print "
CommitLineData
" . + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html($rev)) . "" . esc_html($lineno) . "" . esc_html($data) . "
\n"; + print "
"; + + close $fd or print "Reading blob failed\n"; + git_footer_html(); +} + sub git_blame { my $fd; die_error('403 Permission denied', "Permission denied.") if (!git_get_project_config_bool ('blame')); -- cgit v1.2.3 From 4f7b34c98f6f3853c6b82a85f3e49121c59180f7 Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Sun, 23 Jul 2006 13:36:32 -0700 Subject: gitweb.cgi: git_blame2: Allow back-trekking through commits This patch adds the capability of back-trekking through commits from git_blame2() as follows: blame2->commit->blame2->commit->blame2->...->initial commit. Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'gitweb') diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 57f4a2e263..2c2d9c8d8f 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -2022,7 +2022,13 @@ sub git_commit { print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff"); } print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "\n" . - "

\n"; + "
\n"; + if (defined $file_name && defined $co{'parent'}) { + my $parent = $co{'parent'}; + print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;hb=$parent;f=$file_name")}, "blame") . "\n"; + } + print "
\n"; + if (defined $co{'parent'}) { print "
\n" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html($co{'title'}) . $ref) . "\n" . -- cgit v1.2.3 From cc1bf97e24129db2b8c4634bc733ae0a16b2beba Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Sun, 23 Jul 2006 13:37:53 -0700 Subject: gitweb.cgi: git_blame2: Revision blocks now have alternating colors A revision block is the largest number of adjacent lines of code originating from the same revision. This patch adds color to git_blame2(), in that no two adjacent revision blocks have the same color. The color alternates between light and dark. As we annotate the code lines, we alternate the color (light, dark) of code lines _per revision_. This makes it easier to see line conglomerations per revision. Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'gitweb') diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 2c2d9c8d8f..16340f2106 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -1295,9 +1295,11 @@ sub git_blame2 { $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "
\n"; git_print_page_path($file_name, $ftype); - + my @rev_color = (qw(light dark)); + my $num_colors = scalar(@rev_color); + my $current_color = 0; + my $last_rev; print "
\n"; - print "\n"; print "\n"; while (my $line = <$fd>) { @@ -1307,7 +1309,13 @@ sub git_blame2 { my $lineno = $blame_line{'lineno'}; my $data = $blame_line{'data'}; - print "\n"; + if (!defined $last_rev) { + $last_rev = $full_rev; + } elsif ($last_rev ne $full_rev) { + $last_rev = $full_rev; + $current_color = ++$current_color % $num_colors; + } + print "\n"; print "\n"; print "\n"; @@ -1316,7 +1324,6 @@ sub git_blame2 { } print "
CommitLineData
" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html($rev)) . "" . esc_html($lineno) . "
\n"; print "
"; - close $fd or print "Reading blob failed\n"; git_footer_html(); } -- cgit v1.2.3 From acb0f6f33760b43c1fc9617a45346ab3738f021a Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Sun, 23 Jul 2006 14:17:48 -0700 Subject: gitweb.cgi: git_blame2: slight optimization reading the blame lines Eliminate git_read_blame_line() -- move that code inline and optimize it. Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'gitweb') diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 16340f2106..7fbfc0d226 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -1252,15 +1252,6 @@ 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; @@ -1302,12 +1293,12 @@ sub git_blame2 { print "
\n"; print "\n"; print "\n"; - while (my $line = <$fd>) { - my %blame_line = git_read_blame_line($line); - my $full_rev = $blame_line{'hash'}; + while (<$fd>) { + /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/; + my $full_rev = $1; my $rev = substr($full_rev, 0, 8); - my $lineno = $blame_line{'lineno'}; - my $data = $blame_line{'data'}; + my $lineno = $2; + my $data = $3; if (!defined $last_rev) { $last_rev = $full_rev; -- cgit v1.2.3
CommitLineData