From f6db2426e8cd17d15f1c4818e975dc3bbb15ef3a Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sat, 26 Oct 2024 17:35:13 +0900 Subject: [PATCH] annotate: impl Debug on AnnotateResults type, use BString for readability I'm going to add snapshot tests. Debug isn't strictly needed, but it should help printf debugging. --- lib/src/annotate.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/src/annotate.rs b/lib/src/annotate.rs index 623106653..297033351 100644 --- a/lib/src/annotate.rs +++ b/lib/src/annotate.rs @@ -20,6 +20,7 @@ use std::collections::HashMap; +use bstr::BString; use pollster::FutureExt; use crate::backend::BackendError; @@ -42,13 +43,14 @@ use crate::revset::RevsetFilterPredicate; use crate::store::Store; /// Annotation results for a specific file +#[derive(Clone, Debug)] pub struct AnnotateResults { /// An array of annotation results ordered by line. /// For each value in the array, the commit_id is the commit id of the /// originator of the line and the string is the actual line itself (without /// newline terminators). The vector is ordered by appearance in the /// file - pub file_annotations: Vec<(CommitId, Vec)>, + pub file_annotations: Vec<(CommitId, BString)>, } /// A map from commits to line mappings. @@ -93,19 +95,12 @@ fn convert_to_results( original_line_map: OriginalLineMap, original_contents: &[u8], ) -> AnnotateResults { - let result_lines = original_contents + let file_annotations = original_contents .split_inclusive(|b| *b == b'\n') .enumerate() - .map(|(idx, line)| { - ( - original_line_map.get(&idx).unwrap().clone(), - line.to_owned(), - ) - }) + .map(|(idx, line)| (original_line_map.get(&idx).unwrap().clone(), line.into())) .collect(); - AnnotateResults { - file_annotations: result_lines, - } + AnnotateResults { file_annotations } } /// loads a given file into the cache under a specific commit id.