From 847adc832f3ca6c42241db5ac889101574433b72 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Mon, 30 Oct 2023 06:33:14 +0900 Subject: [PATCH] git_backend: use lossy conversion to decode non-UTF-8 commit message If message() returned None, it doesn't mean the commit message is empty. I originally mapped it to an error, but that made import of linux repo fail. https://docs.rs/git2/latest/git2/struct.Commit.html#method.message --- lib/src/git_backend.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/git_backend.rs b/lib/src/git_backend.rs index 7a846608e..2d8539043 100644 --- a/lib/src/git_backend.rs +++ b/lib/src/git_backend.rs @@ -316,7 +316,9 @@ fn commit_from_git_without_root_parent( } else { MergedTreeId::Legacy(tree_id) }; - let description = commit.message().unwrap_or("").to_owned(); + // Use lossy conversion as commit message with "mojibake" is still better than + // nothing. + let description = String::from_utf8_lossy(commit.message_bytes()).into_owned(); let author = signature_from_git(commit.author()); let committer = signature_from_git(commit.committer());