From 5b5432f6edbd27ab3d020bf99e71dd8329899dcd Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sun, 1 Nov 2026 12:09:32 -1000 Subject: Offer blame only where it works The blame page answers 404 for a symlink, since git blames a regular file alone, and it refuses a binary file and one past max-blob-size, yet a tree listing offered blame for all of them, and so did a symlink's own page. Each row already knows its size, and git calls a file binary by its first 8000 bytes alone, which a stream reads without inflating the rest. With blame on, a listing of 2,000 delta-packed files went from about 11 to 15 ms. --- tests/t0104-tree.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tests') diff --git a/tests/t0104-tree.sh b/tests/t0104-tree.sh index 490abb3..ca29bdc 100755 --- a/tests/t0104-tree.sh +++ b/tests/t0104-tree.sh @@ -190,6 +190,17 @@ test_expect_success 'only a link target inside the tree is linked' ' ! grep "href=./links/tree/etc/passwd" tmp ' +# Blame takes a regular file alone, so a symlink is not offered it. +test_expect_success 'a symlink is not offered blame' ' + cgitrc_repo linksblamerc links enable-blame=1 && + cgit_rc linksblamerc "url=links/tree/" >tmp && + grep "href=./links/blame/target.txt.>blame" tmp && + ! grep "href=./links/blame/rel.>blame" tmp && + cgit_rc linksblamerc "url=links/tree/rel" >tmp && + grep "
" tmp && + ! grep ">blame" tmp +' + # A row follows a chain of single directories for a set number of levels and # stops on the last one it links, with no separator left hanging after it. test_expect_success 'a long directory chain ends on a link' ' @@ -265,4 +276,22 @@ test_expect_success 'a large binary is dumped only in part' ' grep "
Only the first 64 KB of this file are shown. View the whole file.
" tmp ' +# The blame page refuses a file git counts as binary and one past +# max-blob-size, so a listing offers blame for neither. +test_expect_success 'a listing offers blame only where it works' ' + ( + cd repos/bin && + echo hello >small.txt && + test_seq 1 2000 >large.txt && + git add small.txt large.txt && + git commit -m "text files" + ) && + cgitrc_repo binblamerc bin enable-blame=1 max-blob-size=4 && + cgit_rc binblamerc "url=bin/tree/" >tmp && + grep "href=./bin/blame/small.txt.>blame" tmp && + ! grep "href=./bin/blame/large.txt.>blame" tmp && + ! grep "href=./bin/blame/blob.bin.>blame" tmp && + ! grep "href=./bin/blame/big.bin.>blame" tmp +' + test_done -- cgit 2.12.1