@@ -18,8 +18,8 @@ use crate::{
18
18
FileMode ,
19
19
FileStatus ,
20
20
FileStatusBuilder ,
21
- LoadStatus ,
22
21
Status ,
22
+ thread:: LoadStatus ,
23
23
} ,
24
24
git:: GitError ,
25
25
} ;
@@ -62,12 +62,12 @@ impl CommitDiffLoader {
62
62
Arc :: clone ( & self . commit_diff )
63
63
}
64
64
65
- fn diff < ' r > (
66
- repository : & ' r Repository ,
65
+ fn diff < ' repo > (
66
+ repository : & ' repo Repository ,
67
67
config : & CommitDiffLoaderOptions ,
68
68
commit : & git2:: Commit < ' _ > ,
69
69
diff_options : & mut DiffOptions ,
70
- ) -> Result < Diff < ' r > , GitError > {
70
+ ) -> Result < Diff < ' repo > , GitError > {
71
71
_ = diff_options
72
72
. context_lines ( config. context_lines )
73
73
. ignore_filemode ( false )
@@ -154,8 +154,6 @@ impl CommitDiffLoader {
154
154
Ok ( ( ) )
155
155
}
156
156
157
- #[ expect( clippy:: as_conversions, reason = "Realistically safe conversion." ) ]
158
- #[ expect( clippy:: unwrap_in_result, reason = "Unwrap usage failure considered a bug." ) ]
159
157
pub ( crate ) fn collect (
160
158
& self ,
161
159
diff : & Diff < ' _ > ,
@@ -863,18 +861,16 @@ mod tests {
863
861
let notifier = move |status| {
864
862
let mut c = notifier_calls. lock ( ) ;
865
863
c. push ( status) ;
866
- return false ;
864
+ false
867
865
} ;
868
866
869
867
_ = diff_with_notifier ( repository, CommitDiffLoaderOptions :: new ( ) , notifier) . unwrap ( ) ;
870
868
871
869
let c = calls. lock ( ) ;
872
- assert_eq ! ( c. get ( 0 ) . unwrap( ) , & LoadStatus :: New ) ;
870
+ assert_eq ! ( c. first ( ) . unwrap( ) , & LoadStatus :: New ) ;
873
871
assert_eq ! ( c. get( 1 ) . unwrap( ) , & LoadStatus :: Diff ( 0 , 10 ) ) ;
874
- assert_eq ! ( c. get( 2 ) . unwrap( ) , & LoadStatus :: Diff ( 3 , 10 ) ) ;
875
- assert_eq ! ( c. get( 3 ) . unwrap( ) , & LoadStatus :: Diff ( 6 , 10 ) ) ;
876
- assert_eq ! ( c. get( 4 ) . unwrap( ) , & LoadStatus :: Diff ( 9 , 10 ) ) ;
877
- assert_eq ! ( c. get( 5 ) . unwrap( ) , & LoadStatus :: DiffComplete ) ;
872
+ assert ! ( matches!( c. get( 2 ) . unwrap( ) , & LoadStatus :: Diff ( _, 10 ) ) ) ;
873
+ assert ! ( matches!( c. last( ) . unwrap( ) , & LoadStatus :: DiffComplete ) ) ;
878
874
} ) ;
879
875
}
880
876
@@ -891,23 +887,51 @@ mod tests {
891
887
let notifier = move |status| {
892
888
let mut c = notifier_calls. lock ( ) ;
893
889
c. push ( status) ;
894
- return false ;
890
+ false
895
891
} ;
896
892
897
893
_ = diff_with_notifier ( repository, CommitDiffLoaderOptions :: new ( ) . copies ( true ) , notifier) . unwrap ( ) ;
898
894
899
- let c = calls. lock ( ) ;
900
- assert_eq ! ( c. get( 0 ) . unwrap( ) , & LoadStatus :: New ) ;
901
- assert_eq ! ( c. get( 1 ) . unwrap( ) , & LoadStatus :: QuickDiff ( 0 , 10 ) ) ;
902
- assert_eq ! ( c. get( 2 ) . unwrap( ) , & LoadStatus :: QuickDiff ( 3 , 10 ) ) ;
903
- assert_eq ! ( c. get( 3 ) . unwrap( ) , & LoadStatus :: QuickDiff ( 6 , 10 ) ) ;
904
- assert_eq ! ( c. get( 4 ) . unwrap( ) , & LoadStatus :: QuickDiff ( 9 , 10 ) ) ;
905
- assert_eq ! ( c. get( 5 ) . unwrap( ) , & LoadStatus :: CompleteQuickDiff ) ;
906
- assert_eq ! ( c. get( 6 ) . unwrap( ) , & LoadStatus :: Diff ( 0 , 10 ) ) ;
907
- assert_eq ! ( c. get( 7 ) . unwrap( ) , & LoadStatus :: Diff ( 3 , 10 ) ) ;
908
- assert_eq ! ( c. get( 8 ) . unwrap( ) , & LoadStatus :: Diff ( 6 , 10 ) ) ;
909
- assert_eq ! ( c. get( 9 ) . unwrap( ) , & LoadStatus :: Diff ( 9 , 10 ) ) ;
910
- assert_eq ! ( c. get( 10 ) . unwrap( ) , & LoadStatus :: DiffComplete ) ;
895
+ // Since the exact emitted statues are based on time, this matches a dynamic pattern of:
896
+ // - New
897
+ // - QuickDiff(0, 10)
898
+ // - QuickDiff(>0, 10)
899
+ // - CompleteQuickDiff
900
+ // - Diff(0, 10)
901
+ // - Diff(>0, 10)
902
+ // - DiffComplete
903
+ let mut pass = false ;
904
+ let mut expected = LoadStatus :: New ;
905
+ for c in calls. lock ( ) . clone ( ) {
906
+ match ( & expected, c) {
907
+ ( & LoadStatus :: New , LoadStatus :: New ) => {
908
+ expected = LoadStatus :: QuickDiff ( 0 , 10 ) ;
909
+ } ,
910
+ ( & LoadStatus :: QuickDiff ( 0 , 10 ) , LoadStatus :: QuickDiff ( 0 , 10 ) ) => {
911
+ expected = LoadStatus :: QuickDiff ( 1 , 10 ) ;
912
+ } ,
913
+ ( & LoadStatus :: QuickDiff ( 1 , 10 ) , LoadStatus :: QuickDiff ( p, 10 ) ) => {
914
+ assert ! ( p > 0 ) ;
915
+ expected = LoadStatus :: CompleteQuickDiff ;
916
+ } ,
917
+ ( & LoadStatus :: CompleteQuickDiff , LoadStatus :: CompleteQuickDiff ) => {
918
+ expected = LoadStatus :: Diff ( 0 , 10 ) ;
919
+ } ,
920
+ ( & LoadStatus :: Diff ( 0 , 10 ) , LoadStatus :: Diff ( 0 , 10 ) ) => {
921
+ expected = LoadStatus :: Diff ( 1 , 10 ) ;
922
+ } ,
923
+ ( & LoadStatus :: Diff ( 1 , 10 ) , LoadStatus :: Diff ( p, 10 ) ) => {
924
+ assert ! ( p > 0 ) ;
925
+ expected = LoadStatus :: DiffComplete ;
926
+ } ,
927
+ ( & LoadStatus :: DiffComplete , LoadStatus :: DiffComplete ) => {
928
+ pass = true ;
929
+ } ,
930
+ ( ..) => { } ,
931
+ }
932
+ }
933
+
934
+ assert ! ( pass) ;
911
935
} ) ;
912
936
}
913
937
@@ -922,14 +946,14 @@ mod tests {
922
946
let notifier = move |status| {
923
947
let mut c = notifier_calls. lock ( ) ;
924
948
c. push ( status) ;
925
- return true ;
949
+ true
926
950
} ;
927
951
928
952
_ = diff_with_notifier ( repository, CommitDiffLoaderOptions :: new ( ) , notifier) . unwrap ( ) ;
929
953
930
954
let c = calls. lock ( ) ;
931
955
assert_eq ! ( c. len( ) , 1 ) ;
932
- assert_eq ! ( c. get ( 0 ) . unwrap( ) , & LoadStatus :: New ) ;
956
+ assert_eq ! ( c. first ( ) . unwrap( ) , & LoadStatus :: New ) ;
933
957
} ) ;
934
958
}
935
959
@@ -944,14 +968,14 @@ mod tests {
944
968
let notifier = move |status| {
945
969
let mut c = notifier_calls. lock ( ) ;
946
970
c. push ( status) ;
947
- return c. len ( ) == 2 ;
971
+ c. len ( ) == 2
948
972
} ;
949
973
950
974
_ = diff_with_notifier ( repository, CommitDiffLoaderOptions :: new ( ) , notifier) . unwrap ( ) ;
951
975
952
976
let c = calls. lock ( ) ;
953
977
assert_eq ! ( c. len( ) , 2 ) ;
954
- assert_eq ! ( c. get ( 0 ) . unwrap( ) , & LoadStatus :: New ) ;
978
+ assert_eq ! ( c. first ( ) . unwrap( ) , & LoadStatus :: New ) ;
955
979
assert_eq ! ( c. get( 1 ) . unwrap( ) , & LoadStatus :: Diff ( 0 , 1 ) ) ;
956
980
} ) ;
957
981
}
@@ -969,16 +993,14 @@ mod tests {
969
993
let notifier = move |status| {
970
994
let mut c = notifier_calls. lock ( ) ;
971
995
c. push ( status) ;
972
- return c. len ( ) == 4 ;
996
+ c. len ( ) == 4
973
997
} ;
974
998
975
999
_ = diff_with_notifier ( repository, CommitDiffLoaderOptions :: new ( ) , notifier) . unwrap ( ) ;
976
1000
let c = calls. lock ( ) ;
977
- assert_eq ! ( c. len( ) , 4 ) ;
978
- assert_eq ! ( c. get( 0 ) . unwrap( ) , & LoadStatus :: New ) ;
1001
+ assert_eq ! ( c. first( ) . unwrap( ) , & LoadStatus :: New ) ;
979
1002
assert_eq ! ( c. get( 1 ) . unwrap( ) , & LoadStatus :: Diff ( 0 , 10 ) ) ;
980
- assert_eq ! ( c. get( 2 ) . unwrap( ) , & LoadStatus :: Diff ( 3 , 10 ) ) ;
981
- assert_eq ! ( c. get( 3 ) . unwrap( ) , & LoadStatus :: Diff ( 6 , 10 ) ) ;
1003
+ assert ! ( matches!( c. last( ) . unwrap( ) , & LoadStatus :: Diff ( _, 10 ) ) ) ;
982
1004
} ) ;
983
1005
}
984
1006
@@ -993,18 +1015,16 @@ mod tests {
993
1015
let calls = Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ;
994
1016
let notifier_calls = Arc :: clone ( & calls) ;
995
1017
let notifier = move |status| {
996
- eprintln ! ( "{:?}" , status) ;
997
1018
let mut c = notifier_calls. lock ( ) ;
998
1019
c. push ( status) ;
999
- return c. len ( ) == 3 ;
1020
+ c. len ( ) == 3
1000
1021
} ;
1001
1022
1002
1023
_ = diff_with_notifier ( repository, CommitDiffLoaderOptions :: new ( ) . copies ( true ) , notifier) . unwrap ( ) ;
1003
1024
let c = calls. lock ( ) ;
1004
- assert_eq ! ( c. len( ) , 3 ) ;
1005
- assert_eq ! ( c. get( 0 ) . unwrap( ) , & LoadStatus :: New ) ;
1025
+ assert_eq ! ( c. first( ) . unwrap( ) , & LoadStatus :: New ) ;
1006
1026
assert_eq ! ( c. get( 1 ) . unwrap( ) , & LoadStatus :: QuickDiff ( 0 , 10 ) ) ;
1007
- assert_eq ! ( c . get ( 2 ) . unwrap( ) , & LoadStatus :: QuickDiff ( 3 , 10 ) ) ;
1027
+ assert ! ( matches! ( c . last ( ) . unwrap( ) , & LoadStatus :: QuickDiff ( _ , 10 ) ) ) ;
1008
1028
} ) ;
1009
1029
}
1010
1030
@@ -1020,19 +1040,17 @@ mod tests {
1020
1040
let notifier_calls = Arc :: clone ( & calls) ;
1021
1041
let notifier = move |status| {
1022
1042
let mut c = notifier_calls. lock ( ) ;
1043
+ let rtn = status == LoadStatus :: CompleteQuickDiff ;
1023
1044
c. push ( status) ;
1024
- return c . len ( ) == 6 ;
1045
+ rtn
1025
1046
} ;
1026
1047
1027
1048
_ = diff_with_notifier ( repository, CommitDiffLoaderOptions :: new ( ) . copies ( true ) , notifier) . unwrap ( ) ;
1028
1049
let c = calls. lock ( ) ;
1029
- assert_eq ! ( c. len( ) , 6 ) ;
1030
- assert_eq ! ( c. get( 0 ) . unwrap( ) , & LoadStatus :: New ) ;
1050
+ assert_eq ! ( c. first( ) . unwrap( ) , & LoadStatus :: New ) ;
1031
1051
assert_eq ! ( c. get( 1 ) . unwrap( ) , & LoadStatus :: QuickDiff ( 0 , 10 ) ) ;
1032
- assert_eq ! ( c. get( 2 ) . unwrap( ) , & LoadStatus :: QuickDiff ( 3 , 10 ) ) ;
1033
- assert_eq ! ( c. get( 3 ) . unwrap( ) , & LoadStatus :: QuickDiff ( 6 , 10 ) ) ;
1034
- assert_eq ! ( c. get( 4 ) . unwrap( ) , & LoadStatus :: QuickDiff ( 9 , 10 ) ) ;
1035
- assert_eq ! ( c. get( 5 ) . unwrap( ) , & LoadStatus :: CompleteQuickDiff ) ;
1052
+ assert ! ( matches!( c. get( 2 ) . unwrap( ) , & LoadStatus :: QuickDiff ( _, 10 ) ) ) ;
1053
+ assert_eq ! ( c. last( ) . unwrap( ) , & LoadStatus :: CompleteQuickDiff ) ;
1036
1054
} ) ;
1037
1055
}
1038
1056
}
0 commit comments