@@ -108,7 +108,7 @@ int gently_parse_list_objects_filter(
108
108
109
109
strbuf_addf (errbuf , _ ("invalid filter-spec '%s'" ), arg );
110
110
111
- memset (filter_options , 0 , sizeof ( * filter_options ) );
111
+ list_objects_filter_init (filter_options );
112
112
return 1 ;
113
113
}
114
114
@@ -187,10 +187,8 @@ static int parse_combine_filter(
187
187
188
188
cleanup :
189
189
strbuf_list_free (subspecs );
190
- if (result ) {
190
+ if (result )
191
191
list_objects_filter_release (filter_options );
192
- memset (filter_options , 0 , sizeof (* filter_options ));
193
- }
194
192
return result ;
195
193
}
196
194
@@ -204,10 +202,10 @@ static int allow_unencoded(char ch)
204
202
static void filter_spec_append_urlencode (
205
203
struct list_objects_filter_options * filter , const char * raw )
206
204
{
207
- struct strbuf buf = STRBUF_INIT ;
208
- strbuf_addstr_urlencode (& buf , raw , allow_unencoded );
209
- trace_printf ("Add to combine filter-spec: %s\n" , buf . buf );
210
- string_list_append_nodup ( & filter -> filter_spec , strbuf_detach ( & buf , NULL ) );
205
+ size_t orig_len = filter -> filter_spec . len ;
206
+ strbuf_addstr_urlencode (& filter -> filter_spec , raw , allow_unencoded );
207
+ trace_printf ("Add to combine filter-spec: %s\n" ,
208
+ filter -> filter_spec . buf + orig_len );
211
209
}
212
210
213
211
/*
@@ -225,22 +223,21 @@ static void transform_to_combine_type(
225
223
struct list_objects_filter_options * sub_array =
226
224
xcalloc (initial_sub_alloc , sizeof (* sub_array ));
227
225
sub_array [0 ] = * filter_options ;
228
- memset (filter_options , 0 , sizeof (* filter_options ));
229
- string_list_init_dup (& filter_options -> filter_spec );
226
+ list_objects_filter_init (filter_options );
230
227
filter_options -> sub = sub_array ;
231
228
filter_options -> sub_alloc = initial_sub_alloc ;
232
229
}
233
230
filter_options -> sub_nr = 1 ;
234
231
filter_options -> choice = LOFC_COMBINE ;
235
- string_list_append (& filter_options -> filter_spec , "combine:" );
232
+ strbuf_addstr (& filter_options -> filter_spec , "combine:" );
236
233
filter_spec_append_urlencode (
237
234
filter_options ,
238
235
list_objects_filter_spec (& filter_options -> sub [0 ]));
239
236
/*
240
237
* We don't need the filter_spec strings for subfilter specs, only the
241
238
* top level.
242
239
*/
243
- string_list_clear (& filter_options -> sub [0 ].filter_spec , /*free_util=*/ 0 );
240
+ strbuf_release (& filter_options -> sub [0 ].filter_spec );
244
241
}
245
242
246
243
void list_objects_filter_die_if_populated (
@@ -257,14 +254,11 @@ void parse_list_objects_filter(
257
254
struct strbuf errbuf = STRBUF_INIT ;
258
255
int parse_error ;
259
256
260
- if (!filter_options -> filter_spec .strdup_strings ) {
261
- if (filter_options -> filter_spec .nr )
262
- BUG ("unexpected non-allocated string in filter_spec" );
263
- filter_options -> filter_spec .strdup_strings = 1 ;
264
- }
257
+ if (!filter_options -> filter_spec .buf )
258
+ BUG ("filter_options not properly initialized" );
265
259
266
260
if (!filter_options -> choice ) {
267
- string_list_append (& filter_options -> filter_spec , arg );
261
+ strbuf_addstr (& filter_options -> filter_spec , arg );
268
262
269
263
parse_error = gently_parse_list_objects_filter (
270
264
filter_options , arg , & errbuf );
@@ -275,7 +269,7 @@ void parse_list_objects_filter(
275
269
*/
276
270
transform_to_combine_type (filter_options );
277
271
278
- string_list_append (& filter_options -> filter_spec , "+" );
272
+ strbuf_addch (& filter_options -> filter_spec , '+' );
279
273
filter_spec_append_urlencode (filter_options , arg );
280
274
ALLOC_GROW_BY (filter_options -> sub , filter_options -> sub_nr , 1 ,
281
275
filter_options -> sub_alloc );
@@ -306,31 +300,18 @@ int opt_parse_list_objects_filter(const struct option *opt,
306
300
307
301
const char * list_objects_filter_spec (struct list_objects_filter_options * filter )
308
302
{
309
- if (!filter -> filter_spec .nr )
303
+ if (!filter -> filter_spec .len )
310
304
BUG ("no filter_spec available for this filter" );
311
- if (filter -> filter_spec .nr != 1 ) {
312
- struct strbuf concatted = STRBUF_INIT ;
313
- strbuf_add_separated_string_list (
314
- & concatted , "" , & filter -> filter_spec );
315
- string_list_clear (& filter -> filter_spec , /*free_util=*/ 0 );
316
- string_list_append_nodup (
317
- & filter -> filter_spec , strbuf_detach (& concatted , NULL ));
318
- }
319
-
320
- return filter -> filter_spec .items [0 ].string ;
305
+ return filter -> filter_spec .buf ;
321
306
}
322
307
323
308
const char * expand_list_objects_filter_spec (
324
309
struct list_objects_filter_options * filter )
325
310
{
326
311
if (filter -> choice == LOFC_BLOB_LIMIT ) {
327
- struct strbuf expanded_spec = STRBUF_INIT ;
328
- strbuf_addf (& expanded_spec , "blob:limit=%lu" ,
312
+ strbuf_release ( & filter -> filter_spec ) ;
313
+ strbuf_addf (& filter -> filter_spec , "blob:limit=%lu" ,
329
314
filter -> blob_limit_value );
330
- string_list_clear (& filter -> filter_spec , /*free_util=*/ 0 );
331
- string_list_append_nodup (
332
- & filter -> filter_spec ,
333
- strbuf_detach (& expanded_spec , NULL ));
334
315
}
335
316
336
317
return list_objects_filter_spec (filter );
@@ -343,12 +324,12 @@ void list_objects_filter_release(
343
324
344
325
if (!filter_options )
345
326
return ;
346
- string_list_clear (& filter_options -> filter_spec , /*free_util=*/ 0 );
327
+ strbuf_release (& filter_options -> filter_spec );
347
328
free (filter_options -> sparse_oid_name );
348
329
for (sub = 0 ; sub < filter_options -> sub_nr ; sub ++ )
349
330
list_objects_filter_release (& filter_options -> sub [sub ]);
350
331
free (filter_options -> sub );
351
- memset (filter_options , 0 , sizeof ( * filter_options ) );
332
+ list_objects_filter_init (filter_options );
352
333
}
353
334
354
335
void partial_clone_register (
@@ -401,11 +382,11 @@ void partial_clone_get_default_filter_spec(
401
382
/*
402
383
* Parse default value, but silently ignore it if it is invalid.
403
384
*/
404
- if (!promisor )
385
+ if (!promisor || ! promisor -> partial_clone_filter )
405
386
return ;
406
387
407
- string_list_append (& filter_options -> filter_spec ,
408
- promisor -> partial_clone_filter );
388
+ strbuf_addstr (& filter_options -> filter_spec ,
389
+ promisor -> partial_clone_filter );
409
390
gently_parse_list_objects_filter (filter_options ,
410
391
promisor -> partial_clone_filter ,
411
392
& errbuf );
@@ -417,17 +398,21 @@ void list_objects_filter_copy(
417
398
const struct list_objects_filter_options * src )
418
399
{
419
400
int i ;
420
- struct string_list_item * item ;
421
401
422
402
/* Copy everything. We will overwrite the pointers shortly. */
423
403
memcpy (dest , src , sizeof (struct list_objects_filter_options ));
424
404
425
- string_list_init_dup (& dest -> filter_spec );
426
- for_each_string_list_item (item , & src -> filter_spec )
427
- string_list_append (& dest -> filter_spec , item -> string );
405
+ strbuf_init (& dest -> filter_spec , 0 );
406
+ strbuf_addbuf (& dest -> filter_spec , & src -> filter_spec );
428
407
dest -> sparse_oid_name = xstrdup_or_null (src -> sparse_oid_name );
429
408
430
409
ALLOC_ARRAY (dest -> sub , dest -> sub_alloc );
431
410
for (i = 0 ; i < src -> sub_nr ; i ++ )
432
411
list_objects_filter_copy (& dest -> sub [i ], & src -> sub [i ]);
433
412
}
413
+
414
+ void list_objects_filter_init (struct list_objects_filter_options * filter_options )
415
+ {
416
+ struct list_objects_filter_options blank = LIST_OBJECTS_FILTER_INIT ;
417
+ memcpy (filter_options , & blank , sizeof (* filter_options ));
418
+ }
0 commit comments