git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] gitweb: split output routine of blame2

From
Junio C Hamano <junkio@cox.net>
Date
Aug 29, 2006, 09:06 UTC
Message-ID
<7vhczvoqrj.fsf_-_@assigned-by-dhcp.cox.net>
In-Reply-To
<7vveocpfa3.fsf@assigned-by-dhcp.cox.net>

Make the loop over blame output to collect lines belonging to the same revision, and send it over to the output routine "flush_blame_lines". This will let me do interesting things later.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 gitweb/gitweb.perl |   73 +++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 52 insertions(+), 21 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 555441d..28e1cfd 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2170,6 +2170,33 @@ sub git_tag {
 	git_footer_html();
 }
 
+sub flush_blame_lines {
+	my ($color, $file_name, @line) = @_;
+	my $full_rev = shift @line;
+	my $rev = substr($full_rev, 0, 8);
+
+	for (@line) {
+		unless (/^[0-9a-fA-F]{40}.*?(\d+)\)\s(.*)/) {
+			print "<tr><td>(malformed blame output)</td></tr>";
+			next;
+		}
+		my $lineno = $1;
+		my $data = $2;
+		print "<tr class=\"$color\">\n";
+		print "<td class=\"sha1\">" .
+		$cgi->a({-href => href(action=>"commit",
+				       hash=>$full_rev,
+				       file_name=>$file_name)},
+			esc_html($rev)) . "</td>\n";
+		print +("<td class=\"linenr\">".
+			"<a id=\"l$lineno\" href=\"#l$lineno\" ".
+			"class=\"linenr\">" .
+			esc_html($lineno) . "</a></td>\n");
+		print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
+		print "</tr>\n";
+	}
+}
+
 sub git_blame2 {
 	my $fd;
 	my $ftype;
@@ -2205,33 +2232,37 @@ sub git_blame2 {
 	my @rev_color = (qw(light2 dark2));
 	my $num_colors = scalar(@rev_color);
 	my $current_color = 0;
-	my $last_rev;
+	my @current_group = ();
 	print <<HTML;
 <div class="page_body">
 <table class="blame">
 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
 HTML
 	while (<$fd>) {
-		/^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
-		my $full_rev = $1;
-		my $rev = substr($full_rev, 0, 8);
-		my $lineno = $2;
-		my $data = $3;
-
-		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 "<tr class=\"$rev_color[$current_color]\">\n";
-		print "<td class=\"sha1\">" .
-			$cgi->a({-href => href(action=>"commit", hash=>$full_rev, file_name=>$file_name)},
-			        esc_html($rev)) . "</td>\n";
-		print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
-		      esc_html($lineno) . "</a></td>\n";
-		print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
-		print "</tr>\n";
+		my $full_rev;
+		unless (($full_rev) = /^([0-9a-fA-F]{40})/) {
+			print "<tr><td>(malformed blame output)</td></tr>\n";
+			next;
+		}
+		if (@current_group) {
+			if (($current_group[0] ne $full_rev)) {
+				$current_color = ++$current_color % $num_colors;
+				flush_blame_lines($rev_color[$current_color],
+						  $file_name,
+						  @current_group);
+			}
+			else {
+				push @current_group, $_;
+				next;
+			}
+		}
+		@current_group = ($full_rev, $_);
+	}
+	if (@current_group) {
+		$current_color = ++$current_color % $num_colors;
+		flush_blame_lines($rev_color[$current_color],
+				  $file_name,
+				  @current_group);
 	}
 	print "</table>\n";
 	print "</div>";
-- 
1.4.2.g39ee
Previous: Jakub NarebskiNext: Junio C Hamano
Message 15 of 16 in “gitweb: Additions to commitdiff view”
  1. 0/5 gitweb: Additions to commitdiff viewJakub Narebski, Aug 28, 2006
  2. 1/5 gitweb: Make git_print_log generic; git_print_simplified_log uses itJakub Narebski, Aug 28, 2006
  3. 2/5 gitweb: Do not remove signoff lines in git_print_simplified_logJakub Narebski, Aug 28, 2006
  4. 3/5 gitweb: Add author information to commitdiff viewJakub Narebski, Aug 28, 2006
  5. 4/5 gitweb: git_print_log: signoff line is non-empty lineJakub Narebski, Aug 28, 2006
  6. 5/5 gitweb: Add diff tree, with links to patches, to commitdiff viewJakub Narebski, Aug 28, 2006
  7. Linus TorvaldsAug 28, 2006
  8. gitweb: Add local time and timezone to git_print_authorshipJakub Narebski, Aug 28, 2006
  9. Junio C HamanoAug 29, 2006
  10. Jakub NarebskiAug 29, 2006
  11. Junio C HamanoAug 29, 2006
  12. Jakub NarebskiAug 29, 2006
  13. Junio C HamanoAug 30, 2006
  14. Jakub NarebskiAug 30, 2006
  15. gitweb: split output routine of blame2Junio C Hamano, Aug 29, 2006
  16. gitweb: show rev only on the first line of each group in blameJunio C Hamano, Aug 29, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.