]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
repobrowse: tree: handle lack of trailing newline
authorEric Wong <e@80x24.org>
Mon, 4 Jan 2016 21:20:29 +0000 (21:20 +0000)
committerEric Wong <e@80x24.org>
Tue, 5 Apr 2016 18:58:27 +0000 (18:58 +0000)
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

index d5c74e7e6a40d1430b8c9105c5995f09d67523ac..6d5d4b8c96e398996d8f0fa27a207d7611c27536 100644 (file)
@@ -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{<pre>path: $t\n\nblob: $hex (<a\nhref="$plain">plain</a>)};
+       my $end = '';
 
        $git->cat_file($hex, sub {
                my ($cat, $left) = @_; # $$left == $size
@@ -111,7 +112,16 @@ sub git_blob_show {
                                $fh->write("<a\nid=n$n>". utf8_html($l).
                                                "</a>\n");
                        }
-                       last if ($$left == 0 || !defined $buf);
+                       # no trailing newline:
+                       if ($$left == 0 && $buf ne '') {
+                               ++$n;
+                               $buf = utf8_html($buf);
+                               $fh->write("<a\nid=n$n>". $buf ."</a>");
+                               $end = '<pre>\ No newline at end of file</pre>';
+                               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('</pre></td><td><pre>');
        $fh->write(qq(<a\nhref="#n$_">$_</a>\n)) foreach (1..$n);
-       $fh->write('</pre></td></tr></table>');
+       $fh->write("</pre></td></tr></table><hr />$end");
 }
 
 sub git_tree_show {