@@ -93,6 +93,61 @@ pub(crate) mod convert_to_diffable {
93
93
Ok ( ( ) )
94
94
}
95
95
96
+ #[ test]
97
+ fn binary_below_large_file_threshold ( ) -> crate :: Result {
98
+ let tmp = gix_testtools:: tempfile:: TempDir :: new ( ) ?;
99
+ let mut filter = gix_diff:: blob:: Pipeline :: new (
100
+ WorktreeRoots {
101
+ old_root : None ,
102
+ new_root : Some ( tmp. path ( ) . to_owned ( ) ) ,
103
+ } ,
104
+ gix_filter:: Pipeline :: default ( ) ,
105
+ vec ! [ ] ,
106
+ gix_diff:: blob:: pipeline:: Options {
107
+ large_file_threshold_bytes : 5 ,
108
+ ..default_options ( )
109
+ } ,
110
+ ) ;
111
+
112
+ let does_not_matter = gix_hash:: Kind :: Sha1 . null ( ) ;
113
+ let mut buf = Vec :: new ( ) ;
114
+ let a_name = "a" ;
115
+ let large_content = "a\0 b" ;
116
+ std:: fs:: write ( tmp. path ( ) . join ( a_name) , large_content. as_bytes ( ) ) ?;
117
+ let out = filter. convert_to_diffable (
118
+ & does_not_matter,
119
+ EntryKind :: BlobExecutable ,
120
+ a_name. into ( ) ,
121
+ ResourceKind :: NewOrDestination ,
122
+ & mut |_, _| { } ,
123
+ & gix_object:: find:: Never ,
124
+ pipeline:: Mode :: default ( ) ,
125
+ & mut buf,
126
+ ) ?;
127
+ assert ! ( out. driver_index. is_none( ) , "there was no driver" ) ;
128
+ assert_eq ! ( out. data, Some ( pipeline:: Data :: Binary { size: 3 } ) , "detected in buffer" ) ;
129
+ assert_eq ! ( buf. len( ) , 0 , "it should avoid querying that data in the first place" ) ;
130
+
131
+ let mut db = ObjectDb :: default ( ) ;
132
+ let id = db. insert ( large_content) ;
133
+ let out = filter. convert_to_diffable (
134
+ & id,
135
+ EntryKind :: Blob ,
136
+ a_name. into ( ) ,
137
+ ResourceKind :: OldOrSource ,
138
+ & mut |_, _| { } ,
139
+ & db,
140
+ pipeline:: Mode :: default ( ) ,
141
+ & mut buf,
142
+ ) ?;
143
+
144
+ assert ! ( out. driver_index. is_none( ) , "there was no driver" ) ;
145
+ assert_eq ! ( out. data, Some ( pipeline:: Data :: Binary { size: 3 } ) ) ;
146
+ assert_eq ! ( buf. len( ) , 0 , "it should avoid querying that data in the first place" ) ;
147
+
148
+ Ok ( ( ) )
149
+ }
150
+
96
151
#[ test]
97
152
fn above_large_file_threshold ( ) -> crate :: Result {
98
153
let tmp = gix_testtools:: tempfile:: TempDir :: new ( ) ?;
0 commit comments