@@ -8,7 +8,6 @@ use std::{
88
99use gix:: bstr:: BStr ;
1010use itertools:: Itertools ;
11- use smallvec:: SmallVec ;
1211
1312use crate :: hours:: {
1413 util:: { add_lines, remove_lines} ,
@@ -92,25 +91,16 @@ pub fn spawn_tree_delta_threads<'scope>(
9291 move || -> Result < _ , anyhow:: Error > {
9392 let mut out = Vec :: new ( ) ;
9493 let ( commits, changes, lines_count) = stats_counters;
95- let mut attributes = line_stats
94+ let mut cache = line_stats
9695 . then ( || -> anyhow:: Result < _ > {
97- repo. index_or_load_from_head ( ) . map_err ( Into :: into) . and_then ( |index| {
98- repo. attributes (
99- & index,
100- gix:: worktree:: stack:: state:: attributes:: Source :: IdMapping ,
101- gix:: worktree:: stack:: state:: ignore:: Source :: IdMapping ,
102- None ,
103- )
104- . map_err ( Into :: into)
105- . map ( |attrs| {
106- let matches = attrs. selected_attribute_matches ( [ "binary" , "text" ] ) ;
107- ( attrs, matches)
108- } )
109- } )
96+ Ok ( repo. diff_resource_cache ( gix:: diff:: blob:: pipeline:: Mode :: ToGit , Default :: default ( ) ) ?)
11097 } )
11198 . transpose ( ) ?;
11299 for chunk in rx {
113100 for ( commit_idx, parent_commit, commit) in chunk {
101+ if let Some ( cache) = cache. as_mut ( ) {
102+ cache. clear_resource_cache ( ) ;
103+ }
114104 commits. fetch_add ( 1 , Ordering :: Relaxed ) ;
115105 if gix:: interrupt:: is_triggered ( ) {
116106 return Ok ( out) ;
@@ -155,47 +145,34 @@ pub fn spawn_tree_delta_threads<'scope>(
155145 previous_entry_mode,
156146 id,
157147 previous_id,
158- } => {
159- match ( previous_entry_mode. is_blob ( ) , entry_mode. is_blob ( ) ) {
160- ( false , false ) => { }
161- ( false , true ) => {
162- files. added += 1 ;
163- add_lines ( line_stats, & lines_count, & mut lines, id) ;
164- }
165- ( true , false ) => {
166- files. removed += 1 ;
167- remove_lines ( line_stats, & lines_count, & mut lines, previous_id) ;
168- }
169- ( true , true ) => {
170- files. modified += 1 ;
171- if let Some ( ( attrs, matches) ) = attributes. as_mut ( ) {
172- let entry = attrs. at_entry ( change. location , Some ( false ) ) ?;
173- let is_text_file = if entry. matching_attributes ( matches) {
174- let attrs: SmallVec < [ _ ; 2 ] > =
175- matches. iter_selected ( ) . collect ( ) ;
176- let binary = & attrs[ 0 ] ;
177- let text = & attrs[ 1 ] ;
178- !binary. assignment . state . is_set ( )
179- && !text. assignment . state . is_unset ( )
180- } else {
181- // In the absence of binary or text markers, we assume it's text.
182- true
183- } ;
184-
185- if let Some ( Ok ( diff) ) =
186- is_text_file. then ( || change. event . diff ( ) ) . flatten ( )
187- {
188- let mut nl = 0 ;
189- let counts = diff. line_counts ( ) ;
190- nl += counts. insertions as usize + counts. removals as usize ;
191- lines. added += counts. insertions as usize ;
192- lines. removed += counts. removals as usize ;
193- lines_count. fetch_add ( nl, Ordering :: Relaxed ) ;
194- }
148+ } => match ( previous_entry_mode. is_blob ( ) , entry_mode. is_blob ( ) ) {
149+ ( false , false ) => { }
150+ ( false , true ) => {
151+ files. added += 1 ;
152+ add_lines ( line_stats, & lines_count, & mut lines, id) ;
153+ }
154+ ( true , false ) => {
155+ files. removed += 1 ;
156+ remove_lines ( line_stats, & lines_count, & mut lines, previous_id) ;
157+ }
158+ ( true , true ) => {
159+ files. modified += 1 ;
160+ if let Some ( cache) = cache. as_mut ( ) {
161+ let mut diff = change. diff ( cache) . map_err ( |err| {
162+ std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , err)
163+ } ) ?;
164+ let mut nl = 0 ;
165+ if let Some ( counts) = diff. line_counts ( ) . map_err ( |err| {
166+ std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , err)
167+ } ) ? {
168+ nl += counts. insertions as usize + counts. removals as usize ;
169+ lines. added += counts. insertions as usize ;
170+ lines. removed += counts. removals as usize ;
171+ lines_count. fetch_add ( nl, Ordering :: Relaxed ) ;
195172 }
196173 }
197174 }
198- }
175+ } ,
199176 }
200177 Ok :: < _ , std:: io:: Error > ( Default :: default ( ) )
201178 } ) ?;
0 commit comments