@@ -146,35 +146,31 @@ struct expand_id_test_data expand_id_test_data[] = {
146
146
};
147
147
148
148
static void setup_prefix_query (
149
- git_oid * * out_ids ,
150
- size_t * * out_lengths ,
151
- git_otype * * out_types ,
149
+ git_odb_expand_id * * out_ids ,
152
150
size_t * out_num )
153
151
{
154
- git_oid * ids ;
155
- git_otype * types ;
156
- size_t num , * lengths , i ;
152
+ git_odb_expand_id * ids ;
153
+ size_t num , i ;
157
154
158
155
num = ARRAY_SIZE (expand_id_test_data );
159
156
160
- cl_assert ((ids = git__calloc (num , sizeof (git_oid ))));
161
- cl_assert ((lengths = git__calloc (num , sizeof (size_t ))));
162
- cl_assert ((types = git__calloc (num , sizeof (git_otype ))));
157
+ cl_assert ((ids = git__calloc (num , sizeof (git_odb_expand_id ))));
163
158
164
159
for (i = 0 ; i < num ; i ++ ) {
165
- lengths [i ] = strlen (expand_id_test_data [i ].lookup_id );
166
- git_oid_fromstrn (& ids [i ], expand_id_test_data [i ].lookup_id , lengths [i ]);
167
- types [i ] = expand_id_test_data [i ].expected_type ;
160
+ git_odb_expand_id * id = & ids [i ];
161
+
162
+ size_t len = strlen (expand_id_test_data [i ].lookup_id );
163
+
164
+ git_oid_fromstrn (& id -> id , expand_id_test_data [i ].lookup_id , len );
165
+ id -> length = (unsigned short )len ;
166
+ id -> type = expand_id_test_data [i ].expected_type ;
168
167
}
169
168
170
169
* out_ids = ids ;
171
- * out_lengths = lengths ;
172
- * out_types = types ;
173
170
* out_num = num ;
174
171
}
175
172
176
- static void assert_found_objects (
177
- git_oid * ids , size_t * lengths , git_otype * types )
173
+ static void assert_found_objects (git_odb_expand_id * ids )
178
174
{
179
175
size_t num , i ;
180
176
@@ -191,71 +187,70 @@ static void assert_found_objects(
191
187
expected_type = expand_id_test_data [i ].expected_type ;
192
188
}
193
189
194
- cl_assert_equal_i (expected_len , lengths [i ]);
195
- cl_assert_equal_oid (& expected_id , & ids [i ]);
196
-
197
- if (types )
198
- cl_assert_equal_i (expected_type , types [i ]);
190
+ cl_assert_equal_oid (& expected_id , & ids [i ].id );
191
+ cl_assert_equal_i (expected_len , ids [i ].length );
192
+ cl_assert_equal_i (expected_type , ids [i ].type );
199
193
}
200
194
}
201
195
202
- static void assert_notfound_objects (
203
- git_oid * ids , size_t * lengths , git_otype * types )
196
+ static void assert_notfound_objects (git_odb_expand_id * ids )
204
197
{
205
198
git_oid expected_id = {{0 }};
206
199
size_t num , i ;
207
200
208
201
num = ARRAY_SIZE (expand_id_test_data );
209
202
210
203
for (i = 0 ; i < num ; i ++ ) {
211
- cl_assert_equal_i (0 , lengths [i ]);
212
- cl_assert_equal_oid (& expected_id , & ids [i ]);
213
-
214
- if (types )
215
- cl_assert_equal_i (0 , types [i ]);
204
+ cl_assert_equal_oid (& expected_id , & ids [i ].id );
205
+ cl_assert_equal_i (0 , ids [i ].length );
206
+ cl_assert_equal_i (0 , ids [i ].type );
216
207
}
217
208
}
218
209
219
210
void test_odb_mixed__expand_ids (void )
220
211
{
221
- git_oid * ids ;
222
- size_t i , num , * lengths ;
223
- git_otype * types ;
212
+ git_odb_expand_id * ids ;
213
+ size_t i , num ;
224
214
225
215
/* test looking for the actual (correct) types */
226
216
227
- setup_prefix_query (& ids , & lengths , & types , & num );
228
- cl_git_pass (git_odb_expand_ids (_odb , ids , lengths , types , num ));
229
- assert_found_objects (ids , lengths , types );
230
- git__free (ids ); git__free (lengths ); git__free (types );
217
+ setup_prefix_query (& ids , & num );
218
+ cl_git_pass (git_odb_expand_ids (_odb , ids , num ));
219
+ assert_found_objects (ids );
220
+ git__free (ids );
221
+
222
+ /* test looking for an explicit `type == 0` */
231
223
232
- /* test looking for no specified types (types array == NULL) */
224
+ setup_prefix_query (& ids , & num );
225
+
226
+ for (i = 0 ; i < num ; i ++ )
227
+ ids [i ].type = 0 ;
233
228
234
- setup_prefix_query (& ids , & lengths , & types , & num );
235
- cl_git_pass (git_odb_expand_ids (_odb , ids , lengths , NULL , num ));
236
- assert_found_objects (ids , lengths , NULL );
237
- git__free (ids ); git__free (lengths ); git__free (types );
229
+ cl_git_pass (git_odb_expand_ids (_odb , ids , num ));
230
+ assert_found_objects (ids );
231
+ git__free (ids );
238
232
239
233
/* test looking for an explicit GIT_OBJ_ANY */
240
234
241
- setup_prefix_query (& ids , & lengths , & types , & num );
235
+ setup_prefix_query (& ids , & num );
242
236
243
237
for (i = 0 ; i < num ; i ++ )
244
- types [i ] = GIT_OBJ_ANY ;
238
+ ids [i ]. type = GIT_OBJ_ANY ;
245
239
246
- cl_git_pass (git_odb_expand_ids (_odb , ids , lengths , types , num ));
247
- assert_found_objects (ids , lengths , types );
248
- git__free (ids ); git__free ( lengths ); git__free ( types );
240
+ cl_git_pass (git_odb_expand_ids (_odb , ids , num ));
241
+ assert_found_objects (ids );
242
+ git__free (ids );
249
243
250
244
/* test looking for the completely wrong type */
251
245
252
- setup_prefix_query (& ids , & lengths , & types , & num );
246
+ setup_prefix_query (& ids , & num );
253
247
254
248
for (i = 0 ; i < num ; i ++ )
255
- types [i ] = (types [i ] == GIT_OBJ_BLOB ) ? GIT_OBJ_TREE : GIT_OBJ_BLOB ;
249
+ ids [i ].type = (ids [i ].type == GIT_OBJ_BLOB ) ?
250
+ GIT_OBJ_TREE : GIT_OBJ_BLOB ;
256
251
257
- cl_git_pass (git_odb_expand_ids (_odb , ids , lengths , types , num ));
258
- assert_notfound_objects (ids , lengths , types );
259
- git__free (ids ); git__free ( lengths ); git__free ( types );
252
+ cl_git_pass (git_odb_expand_ids (_odb , ids , num ));
253
+ assert_notfound_objects (ids );
254
+ git__free (ids );
260
255
}
261
256
0 commit comments