@@ -4,7 +4,7 @@ use super::{stash::is_stash_commit, utils::repo, CommitId};
4
4
use crate :: {
5
5
error:: Error , error:: Result , StatusItem , StatusItemType ,
6
6
} ;
7
- use git2:: { Diff , DiffDelta , DiffOptions , Repository } ;
7
+ use git2:: { Diff , DiffOptions , Repository } ;
8
8
use scopetime:: scope_time;
9
9
10
10
/// get all files that are part of a commit
@@ -23,24 +23,30 @@ pub fn get_commit_files(
23
23
get_commit_diff ( & repo, id, None ) ?
24
24
} ;
25
25
26
- let mut res = Vec :: new ( ) ;
26
+ let deltas = {
27
+ scope_time ! ( "get_commit_files.delta-count" ) ;
28
+ diff. deltas ( ) . count ( )
29
+ } ;
30
+
31
+ log:: debug!( "deltas in diff: {}" , deltas) ;
32
+
33
+ let mut res = Vec :: with_capacity ( deltas) ;
34
+
35
+ {
36
+ scope_time ! ( "get_commit_files.diff-foreach" ) ;
37
+ for delta in diff. deltas ( ) {
38
+ let status = StatusItemType :: from ( delta. status ( ) ) ;
27
39
28
- diff. foreach (
29
- & mut |delta : DiffDelta < ' _ > , _progress| {
30
40
res. push ( StatusItem {
31
41
path : delta
32
42
. new_file ( )
33
43
. path ( )
34
44
. map ( |p| p. to_str ( ) . unwrap_or ( "" ) . to_string ( ) )
35
45
. unwrap_or_default ( ) ,
36
- status : StatusItemType :: from ( delta . status ( ) ) ,
46
+ status,
37
47
} ) ;
38
- true
39
- } ,
40
- None ,
41
- None ,
42
- None ,
43
- ) ?;
48
+ }
49
+ }
44
50
45
51
Ok ( res)
46
52
}
@@ -51,7 +57,7 @@ pub fn get_compare_commits_diff(
51
57
ids : ( CommitId , CommitId ) ,
52
58
pathspec : Option < String > ,
53
59
) -> Result < Diff < ' _ > > {
54
- // scope_time!("get_compare_commits_diff");
60
+ scope_time ! ( "get_compare_commits_diff" ) ;
55
61
56
62
let commits = (
57
63
repo. find_commit ( ids. 0 . into ( ) ) ?,
@@ -89,7 +95,7 @@ pub(crate) fn get_commit_diff(
89
95
id : CommitId ,
90
96
pathspec : Option < String > ,
91
97
) -> Result < Diff < ' _ > > {
92
- // scope_time!("get_commit_diff");
98
+ scope_time ! ( "get_commit_diff" ) ;
93
99
94
100
let commit = repo. find_commit ( id. into ( ) ) ?;
95
101
let commit_tree = commit. tree ( ) ?;
0 commit comments