From e94833be510a788c9ac6c358e2081b36cbbbec84 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 31 Oct 2026 13:28:23 -0700 Subject: Test a blob for binary before blaming it --- source/ui-blame.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'source/ui-blame.c') diff --git a/source/ui-blame.c b/source/ui-blame.c index efa9470..32a76fa 100644 --- a/source/ui-blame.c +++ b/source/ui-blame.c @@ -277,6 +277,7 @@ static void print_blame_page(const struct object_id *oid, const char *path, size_t size; struct rev_info revs; struct blame_scoreboard sb; + int binary; type = odb_read_object_info(the_repository->objects, oid, &size); if (type == OBJ_BAD) { @@ -295,7 +296,13 @@ static void print_blame_page(const struct object_id *oid, const char *path, return; } - run_blame(&sb, &revs, path, rev); + // A NUL past the window buffer_is_binary sniffs would end a Lua + // filter's output early while the hash and line number columns still + // cover the whole file, so a blob holding one anywhere is treated as + // binary too. + binary = buffer_is_binary(buf, size) || memchr(buf, 0, size); + if (!binary) + run_blame(&sb, &revs, path, rev); cgit_set_title_from_path(path); cgit_prefix_title("blame"); @@ -307,20 +314,7 @@ static void print_blame_page(const struct object_id *oid, const char *path, cgit_tree_link("tree", NULL, NULL, ctx.qry.head, rev, path); html(")\n"); - // A NUL past the window buffer_is_binary sniffs would end a Lua - // filter's output early while the hash and line number columns still - // cover the whole file, so a blob holding one anywhere is treated as - // binary too. - if (buffer_is_binary(buf, size) || memchr(buf, 0, size)) { - struct blame_entry *ent = sb.ent, *next; - - // The scoreboard is normally consumed by the column passes, - // so this early exit has to release it itself. - for (; ent; ent = next) { - next = ent->next; - free(ent); - } - free((void *)sb.final_buf); + if (binary) { html("
Blob is binary
"); goto cleanup; } -- cgit 2.11.1