Count lines only if file is valid utf-8

This commit is contained in:
Joscha 2023-01-23 13:16:09 +01:00
parent 7b50e1de2c
commit 11c97ab4a2

View file

@ -24,8 +24,9 @@ fn count_lines(repo: &Repository, commit: &Commit) -> anyhow::Result<usize> {
if matches!(entry.mode, EntryMode::Blob | EntryMode::BlobExecutable) { if matches!(entry.mode, EntryMode::Blob | EntryMode::BlobExecutable) {
let object = repo.find_object(entry.oid)?; let object = repo.find_object(entry.oid)?;
let data = object.detach().data; let data = object.detach().data;
let text = String::from_utf8(data)?; if let Ok(text) = String::from_utf8(data) {
lines += text.lines().count(); lines += text.lines().count();
}
} }
} }
Ok(lines) Ok(lines)