Skip to content

Commit 3b1a004

Browse files
cruesslerStephan Dilly
authored andcommitted
Call get_commits_info instead of get_commit_info
This results in far fewer calls to `repo.find_commit` in almost all cases.
1 parent 95c41db commit 3b1a004

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

asyncgit/src/sync/blame.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
use super::{utils, CommitId};
44
use crate::{
55
error::{Error, Result},
6-
sync::get_commit_info,
6+
sync::get_commits_info,
77
};
8+
use std::collections::{HashMap, HashSet};
89
use std::io::{BufRead, BufReader};
910
use std::path::Path;
1011

@@ -70,6 +71,19 @@ pub fn blame_file(
7071

7172
let reader = BufReader::new(blob.content());
7273

74+
let unique_commit_ids: HashSet<_> = blame
75+
.iter()
76+
.map(|hunk| CommitId::new(hunk.final_commit_id()))
77+
.collect();
78+
let mut commit_ids = Vec::with_capacity(unique_commit_ids.len());
79+
commit_ids.extend(unique_commit_ids);
80+
81+
let commit_infos = get_commits_info(repo_path, &commit_ids, 0)?;
82+
let unique_commit_infos: HashMap<_, _> = commit_infos
83+
.iter()
84+
.map(|commit_info| (commit_info.id, commit_info))
85+
.collect();
86+
7387
let lines: Vec<(Option<BlameHunk>, String)> = reader
7488
.lines()
7589
.enumerate()
@@ -85,8 +99,8 @@ pub fn blame_file(
8599
let end_line =
86100
start_line.saturating_add(hunk.lines_in_hunk());
87101

88-
if let Ok(commit_info) =
89-
get_commit_info(repo_path, &commit_id)
102+
if let Some(commit_info) =
103+
unique_commit_infos.get(&commit_id)
90104
{
91105
let hunk = BlameHunk {
92106
commit_id,

0 commit comments

Comments
 (0)