From 20634e5c15655ce398cf85f689e796fad73099fe Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 4 Jan 2016 21:20:29 +0000 Subject: [PATCH] repobrowse: tree: handle lack of trailing newline This fixes a bug where the trailing newline was not shown correctly and tells the reader the file is missing a trailing newline. --- lib/PublicInbox/RepoBrowseGitTree.pm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/PublicInbox/RepoBrowseGitTree.pm b/lib/PublicInbox/RepoBrowseGitTree.pm index d5c74e7e6..6d5d4b8c9 100644 --- a/lib/PublicInbox/RepoBrowseGitTree.pm +++ b/lib/PublicInbox/RepoBrowseGitTree.pm @@ -88,6 +88,7 @@ sub git_blob_show { $plain = PublicInbox::Hval->utf8($plain)->as_path . $q->qs; my $t = cur_path($req, $q); my $h = qq{
path: $t\n\nblob: $hex (plain)};
+	my $end = '';
 
 	$git->cat_file($hex, sub {
 		my ($cat, $left) = @_; # $$left == $size
@@ -111,7 +112,16 @@ sub git_blob_show {
 				$fh->write("". utf8_html($l).
 						"\n");
 			}
-			last if ($$left == 0 || !defined $buf);
+			# no trailing newline:
+			if ($$left == 0 && $buf ne '') {
+				++$n;
+				$buf = utf8_html($buf);
+				$fh->write("". $buf ."");
+				$end = '
\ No newline at end of file
'; + last; + } + + last unless defined($buf); $to_read = $$left if $to_read > $$left; my $off = length $buf; # last line from previous read @@ -125,7 +135,7 @@ sub git_blob_show { # line numbers go in a second column: $fh->write('
');
 	$fh->write(qq($_\n)) foreach (1..$n);
-	$fh->write('
'); + $fh->write("
$end"); } sub git_tree_show { -- 2.47.3