@matheusbsbs / matheus-bagliano / commits / f16db173a4
Fork 0

gitweb: Refactor untabifying - converting tabs to spaces

Add untabify subroutine and use it. It also fixes git_diff_print which used to get the tabstop wrong. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Jakub Narebski committed Aug 6, 2006 at 02:08 UTC f16db173a4680aebc2f14c103a1e125c3f4d4531
1 file changed +18 -19
gitweb/gitweb.perl
+18 -19
@@ -221,6 +221,20 @@ sub unquote {
221 return $str;
222 }
223
224 +# escape tabs (convert tabs to spaces)
225 +sub untabify {
226 + my $line = shift;
227 +
228 + while ((my $pos = index($line, "\t")) != -1) {
229 + if (my $count = (8 - ($pos % 8))) {
230 + my $spaces = ' ' x $count;
231 + $line =~ s/\t/$spaces/;
232 + }
233 + }
234 +
235 + return $line;
236 +}
237 +
238 ## ----------------------------------------------------------------------
239 ## HTML aware string manipulation
240
@@ -1237,12 +1251,7 @@ sub git_diff_print {
1251 # skip errors
1252 next;
1253 }
1240 - while ((my $pos = index($line, "\t")) != -1) {
1241 - if (my $count = (8 - (($pos-1) % 8))) {
1242 - my $spaces = ' ' x $count;
1243 - $line =~ s/\t/$spaces/;
1244 - }
1245 - }
1254 + $line = untabify($line);
1255 print "<div class=\"diff$diff_class\">" . esc_html($line) . "</div>\n";
1256 }
1257 }
@@ -1582,13 +1591,8 @@ HTML
1591 $age_class = age_class($age);
1592 $author = esc_html ($author);
1593 $author =~ s/ /&nbsp;/g;
1585 - # escape tabs
1586 - while ((my $pos = index($data, "\t")) != -1) {
1587 - if (my $count = (8 - ($pos % 8))) {
1588 - my $spaces = ' ' x $count;
1589 - $data =~ s/\t/$spaces/;
1590 - }
1591 - }
1594 +
1595 + $data = untabify($data);
1596 $data = esc_html ($data);
1597
1598 print <<HTML;
@@ -1711,12 +1715,7 @@ sub git_blob {
1715 while (my $line = <$fd>) {
1716 chomp $line;
1717 $nr++;
1714 - while ((my $pos = index($line, "\t")) != -1) {
1715 - if (my $count = (8 - ($pos % 8))) {
1716 - my $spaces = ' ' x $count;
1717 - $line =~ s/\t/$spaces/;
1718 - }
1719 - }
1718 + $line = untabify($line);
1719 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html($line);
1720 }
1721 close $fd or print "Reading blob failed.\n";