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

[PATCH 1/6] gitweb: Refactor untabifying - converting tabs to spaces

From
Jakub Narebski <jnareb@gmail.com>
Date
Aug 6, 2006, 00:08 UTC
Message-ID
<200608060208.31862.jnareb@gmail.com>
In-Reply-To
<200608060206.49086.jnareb@gmail.com>
Add untabify subroutine and use it.
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
 gitweb/gitweb.perl |   38 +++++++++++++++++++-------------------
 1 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index bf1b10f..60113da 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -222,6 +222,21 @@ sub unquote {
 	return $str;
 }
 
+# escape tabs (convert tabs to spaces)
+sub untabify {
+	my $line = shift;
+
+	while ((my $pos = index($line, "\t")) != -1) {
+		# one out of three implementations used ($pos - 1) instead of $pos
+		if (my $count = (8 - ($pos % 8))) {
+			my $spaces = ' ' x $count;
+			$line =~ s/\t/$spaces/;
+		}
+	}
+
+	return $line;
+}
+
 ## ----------------------------------------------------------------------
 ## HTML aware string manipulation
 
@@ -1255,12 +1270,7 @@ sub git_diff_print {
 				# skip errors
 				next;
 			}
-			while ((my $pos = index($line, "\t")) != -1) {
-				if (my $count = (8 - (($pos-1) % 8))) {
-					my $spaces = ' ' x $count;
-					$line =~ s/\t/$spaces/;
-				}
-			}
+			$line = untabify($line);
 			print "<div class=\"diff$diff_class\">" . esc_html($line) . "</div>\n";
 		}
 	}
@@ -1600,13 +1610,8 @@ HTML
 		$age_class  = age_class($age);
 		$author     = esc_html ($author);
 		$author     =~ s/ /&nbsp;/g;
-		# escape tabs
-		while ((my $pos = index($data, "\t")) != -1) {
-			if (my $count = (8 - ($pos % 8))) {
-				my $spaces = ' ' x $count;
-				$data =~ s/\t/$spaces/;
-			}
-		}
+
+		$data = untabify($data);
 		$data = esc_html ($data);
 
 		print <<HTML;
@@ -1728,12 +1733,7 @@ sub git_blob {
 	while (my $line = <$fd>) {
 		chomp $line;
 		$nr++;
-		while ((my $pos = index($line, "\t")) != -1) {
-			if (my $count = (8 - ($pos % 8))) {
-				my $spaces = ' ' x $count;
-				$line =~ s/\t/$spaces/;
-			}
-		}
+		$line = untabify($line);
 		printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html($line);
 	}
 	close $fd or print "Reading blob failed.\n";
-- 
1.4.1.1
Previous: Jakub NarebskiNext: Matthias Lederhofer
Message 2 of 12 in “gitweb: Further refactoring”
  1. 0/6 gitweb: Further refactoringJakub Narebski, Aug 6, 2006
  2. 1/6 gitweb: Refactor untabifying - converting tabs to spacesJakub Narebski, Aug 6, 2006
  3. Matthias LederhoferAug 6, 2006
  4. 2/6 gitweb: Simplify git_diff_printJakub Narebski, Aug 6, 2006
  5. Junio C HamanoAug 6, 2006
  6. Jakub NarebskiAug 6, 2006
  7. 3/6 gitweb: Remove unused parse_date invocation from git_shortlog_bodyJakub Narebski, Aug 6, 2006
  8. 4/6 gitweb: Make blob diff -p1 like commit diffJakub Narebski, Aug 6, 2006
  9. 5/6 gitweb: Refactor printing shortened title in git_shortlog_body and git_tags_bodyJakub Narebski, Aug 6, 2006
  10. 6/6 gitweb: Refactor git_history_bodyJakub Narebski, Aug 6, 2006
  11. Junio C HamanoAug 6, 2006
  12. Jakub NarebskiAug 6, 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.