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

[PATCH 2/7] gitweb: Refactor printing commit message

From
Jakub Narebski <jnareb@gmail.com>
Date
Aug 17, 2006, 09:21 UTC
Message-ID
<11558064891330-git-send-email-jnareb@gmail.com>
In-Reply-To
<11558064883957-git-send-email-jnareb@gmail.com>

Separate pretty-printing commit message (comment) into git_print_log and git_print_simplified_log subroutines. As of now the former is used in git_commit, the latter in git_log and git_commitdiff.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
 gitweb/gitweb.perl |  132 ++++++++++++++++++++++++++--------------------------
 1 files changed, 67 insertions(+), 65 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 7c92ac3..0d869f2 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1174,6 +1174,66 @@ sub git_print_page_path {
 	}
 }
 
+sub git_print_log {
+	my $log = shift;
+
+	# remove leading empty lines
+	while (defined $log->[0] && $log->[0] eq "") {
+		shift @$log;
+	}
+
+	# print log
+	my $signoff = 0;
+	my $empty = 0;
+	foreach my $line (@$log) {
+		# print only one empty line
+		# do not print empty line after signoff
+		if ($line eq "") {
+			next if ($empty || $signoff);
+			$empty = 1;
+		} else {
+			$empty = 0;
+		}
+		if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
+			$signoff = 1;
+			print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
+		} else {
+			$signoff = 0;
+			print format_log_line_html($line) . "<br/>\n";
+		}
+	}
+}
+
+sub git_print_simplified_log {
+	my $log = shift;
+	my $remove_title = shift;
+
+	shift @$log if $remove_title;
+	# remove leading empty lines
+	while (defined $log->[0] && $log->[0] eq "") {
+		shift @$log;
+	}
+
+	# simplify and print log
+	my $empty = 0;
+	foreach my $line (@$log) {
+		# remove signoff lines
+		if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
+			next;
+		}
+		# print only one empty line
+		if ($line eq "") {
+			next if $empty;
+			$empty = 1;
+		} else {
+			$empty = 0;
+		}
+		print format_log_line_html($line) . "<br/>\n";
+	}
+	# end with single empty line
+	print "<br/>\n" unless $empty;
+}
+
 ## ......................................................................
 ## functions printing large fragments of HTML
 
@@ -2155,27 +2215,10 @@ sub git_log {
 		      "<br/>\n" .
 		      "</div>\n" .
 		      "<i>" . esc_html($co{'author_name'}) .  " [$ad{'rfc2822'}]</i><br/>\n" .
-		      "</div>\n" .
-		      "<div class=\"log_body\">\n";
-		my $comment = $co{'comment'};
-		my $empty = 0;
-		foreach my $line (@$comment) {
-			if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
-				next;
-			}
-			if ($line eq "") {
-				if ($empty) {
-					next;
-				}
-				$empty = 1;
-			} else {
-				$empty = 0;
-			}
-			print format_log_line_html($line) . "<br/>\n";
-		}
-		if (!$empty) {
-			print "<br/>\n";
-		}
+		      "</div>\n";
+
+		print "<div class=\"log_body\">\n";
+		git_print_simplified_log($co{'comment'});
 		print "</div>\n";
 	}
 	git_footer_html();
@@ -2256,28 +2299,9 @@ sub git_commit {
 	}
 	print "</table>".
 	      "</div>\n";
+
 	print "<div class=\"page_body\">\n";
-	my $comment = $co{'comment'};
-	my $empty = 0;
-	my $signed = 0;
-	foreach my $line (@$comment) {
-		# print only one empty line
-		if ($line eq "") {
-			if ($empty || $signed) {
-				next;
-			}
-			$empty = 1;
-		} else {
-			$empty = 0;
-		}
-		if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
-			$signed = 1;
-			print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
-		} else {
-			$signed = 0;
-			print format_log_line_html($line) . "<br/>\n";
-		}
-	}
+	git_print_log($co{'comment'});
 	print "</div>\n";
 
 	git_difftree_body(\@difftree, $parent);
@@ -2343,29 +2367,7 @@ sub git_commitdiff {
 	git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
 	git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
 	print "<div class=\"page_body\">\n";
-	my $comment = $co{'comment'};
-	my $empty = 0;
-	my $signed = 0;
-	my @log = @$comment;
-	# remove first and empty lines after that
-	shift @log;
-	while (defined $log[0] && $log[0] eq "") {
-		shift @log;
-	}
-	foreach my $line (@log) {
-		if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
-			next;
-		}
-		if ($line eq "") {
-			if ($empty) {
-				next;
-			}
-			$empty = 1;
-		} else {
-			$empty = 0;
-		}
-		print format_log_line_html($line) . "<br/>\n";
-	}
+	git_print_simplified_log($co{'comment'}, 1); # skip title
 	print "<br/>\n";
 	foreach my $line (@difftree) {
 		# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M      ls-files.c'
-- 
1.4.1.1
Previous: David RientjesNext: Jakub Narebski
Message 4 of 12 in “A few gitweb cleanups and improvements”
  1. 0/7 A few gitweb cleanups and improvementsJakub Narebski, Aug 17, 2006
  2. 1/7 gitweb: Add support for per project git URLsJakub Narebski, Aug 17, 2006
  3. David RientjesAug 17, 2006
  4. 2/7 gitweb: Refactor printing commit messageJakub Narebski, Aug 17, 2006
  5. 3/7 gitweb: Fix typo in separation of git_difftree_bodyJakub Narebski, Aug 17, 2006
  6. 4/7 gitweb: Expand href() function to use key as param name for no mappingJakub Narebski, Aug 17, 2006
  7. Junio C HamanoAug 17, 2006
  8. Jakub NarebskiAug 17, 2006
  9. 5/7 gitweb: Added parse_difftree_raw_line function for later useJakub Narebski, Aug 17, 2006
  10. Junio C HamanoAug 17, 2006
  11. 6/7 gitweb: Sort query string parameters in href() functionJakub Narebski, Aug 17, 2006
  12. 7/7 gitweb: Uniquify version info output, add meta generator in page headerJakub Narebski, Aug 17, 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.