3
3
use super :: { utils, CommitId } ;
4
4
use crate :: {
5
5
error:: { Error , Result } ,
6
- sync:: get_commit_info ,
6
+ sync:: get_commits_info ,
7
7
} ;
8
+ use std:: collections:: { HashMap , HashSet } ;
8
9
use std:: io:: { BufRead , BufReader } ;
9
10
use std:: path:: Path ;
10
11
@@ -70,6 +71,19 @@ pub fn blame_file(
70
71
71
72
let reader = BufReader :: new ( blob. content ( ) ) ;
72
73
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
+
73
87
let lines: Vec < ( Option < BlameHunk > , String ) > = reader
74
88
. lines ( )
75
89
. enumerate ( )
@@ -85,8 +99,8 @@ pub fn blame_file(
85
99
let end_line =
86
100
start_line. saturating_add ( hunk. lines_in_hunk ( ) ) ;
87
101
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)
90
104
{
91
105
let hunk = BlameHunk {
92
106
commit_id,
0 commit comments