From 11c97ab4a2b3d624339a8b1559ce893e80d8863e Mon Sep 17 00:00:00 2001 From: Joscha Date: Mon, 23 Jan 2023 13:16:09 +0100 Subject: [PATCH] Count lines only if file is valid utf-8 --- src/main.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index b00a093..29b45ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,8 +24,9 @@ fn count_lines(repo: &Repository, commit: &Commit) -> anyhow::Result { if matches!(entry.mode, EntryMode::Blob | EntryMode::BlobExecutable) { let object = repo.find_object(entry.oid)?; let data = object.detach().data; - let text = String::from_utf8(data)?; - lines += text.lines().count(); + if let Ok(text) = String::from_utf8(data) { + lines += text.lines().count(); + } } } Ok(lines)