@@ -108,7 +108,7 @@ int gently_parse_list_objects_filter(
108108
109109 strbuf_addf (errbuf , _ ("invalid filter-spec '%s'" ), arg );
110110
111- memset (filter_options , 0 , sizeof ( * filter_options ) );
111+ list_objects_filter_init (filter_options );
112112 return 1 ;
113113}
114114
@@ -187,10 +187,8 @@ static int parse_combine_filter(
187187
188188cleanup :
189189 strbuf_list_free (subspecs );
190- if (result ) {
190+ if (result )
191191 list_objects_filter_release (filter_options );
192- memset (filter_options , 0 , sizeof (* filter_options ));
193- }
194192 return result ;
195193}
196194
@@ -204,10 +202,10 @@ static int allow_unencoded(char ch)
204202static void filter_spec_append_urlencode (
205203 struct list_objects_filter_options * filter , const char * raw )
206204{
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 );
211209}
212210
213211/*
@@ -225,22 +223,21 @@ static void transform_to_combine_type(
225223 struct list_objects_filter_options * sub_array =
226224 xcalloc (initial_sub_alloc , sizeof (* sub_array ));
227225 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 );
230227 filter_options -> sub = sub_array ;
231228 filter_options -> sub_alloc = initial_sub_alloc ;
232229 }
233230 filter_options -> sub_nr = 1 ;
234231 filter_options -> choice = LOFC_COMBINE ;
235- string_list_append (& filter_options -> filter_spec , "combine:" );
232+ strbuf_addstr (& filter_options -> filter_spec , "combine:" );
236233 filter_spec_append_urlencode (
237234 filter_options ,
238235 list_objects_filter_spec (& filter_options -> sub [0 ]));
239236 /*
240237 * We don't need the filter_spec strings for subfilter specs, only the
241238 * top level.
242239 */
243- string_list_clear (& filter_options -> sub [0 ].filter_spec , /*free_util=*/ 0 );
240+ strbuf_release (& filter_options -> sub [0 ].filter_spec );
244241}
245242
246243void list_objects_filter_die_if_populated (
@@ -257,14 +254,11 @@ void parse_list_objects_filter(
257254 struct strbuf errbuf = STRBUF_INIT ;
258255 int parse_error ;
259256
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" );
265259
266260 if (!filter_options -> choice ) {
267- string_list_append (& filter_options -> filter_spec , arg );
261+ strbuf_addstr (& filter_options -> filter_spec , arg );
268262
269263 parse_error = gently_parse_list_objects_filter (
270264 filter_options , arg , & errbuf );
@@ -275,7 +269,7 @@ void parse_list_objects_filter(
275269 */
276270 transform_to_combine_type (filter_options );
277271
278- string_list_append (& filter_options -> filter_spec , "+" );
272+ strbuf_addch (& filter_options -> filter_spec , '+' );
279273 filter_spec_append_urlencode (filter_options , arg );
280274 ALLOC_GROW_BY (filter_options -> sub , filter_options -> sub_nr , 1 ,
281275 filter_options -> sub_alloc );
@@ -306,31 +300,18 @@ int opt_parse_list_objects_filter(const struct option *opt,
306300
307301const char * list_objects_filter_spec (struct list_objects_filter_options * filter )
308302{
309- if (!filter -> filter_spec .nr )
303+ if (!filter -> filter_spec .len )
310304 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 ;
321306}
322307
323308const char * expand_list_objects_filter_spec (
324309 struct list_objects_filter_options * filter )
325310{
326311 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" ,
329314 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 ));
334315 }
335316
336317 return list_objects_filter_spec (filter );
@@ -343,12 +324,12 @@ void list_objects_filter_release(
343324
344325 if (!filter_options )
345326 return ;
346- string_list_clear (& filter_options -> filter_spec , /*free_util=*/ 0 );
327+ strbuf_release (& filter_options -> filter_spec );
347328 free (filter_options -> sparse_oid_name );
348329 for (sub = 0 ; sub < filter_options -> sub_nr ; sub ++ )
349330 list_objects_filter_release (& filter_options -> sub [sub ]);
350331 free (filter_options -> sub );
351- memset (filter_options , 0 , sizeof ( * filter_options ) );
332+ list_objects_filter_init (filter_options );
352333}
353334
354335void partial_clone_register (
@@ -401,11 +382,11 @@ void partial_clone_get_default_filter_spec(
401382 /*
402383 * Parse default value, but silently ignore it if it is invalid.
403384 */
404- if (!promisor )
385+ if (!promisor || ! promisor -> partial_clone_filter )
405386 return ;
406387
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 );
409390 gently_parse_list_objects_filter (filter_options ,
410391 promisor -> partial_clone_filter ,
411392 & errbuf );
@@ -417,17 +398,21 @@ void list_objects_filter_copy(
417398 const struct list_objects_filter_options * src )
418399{
419400 int i ;
420- struct string_list_item * item ;
421401
422402 /* Copy everything. We will overwrite the pointers shortly. */
423403 memcpy (dest , src , sizeof (struct list_objects_filter_options ));
424404
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 );
428407 dest -> sparse_oid_name = xstrdup_or_null (src -> sparse_oid_name );
429408
430409 ALLOC_ARRAY (dest -> sub , dest -> sub_alloc );
431410 for (i = 0 ; i < src -> sub_nr ; i ++ )
432411 list_objects_filter_copy (& dest -> sub [i ], & src -> sub [i ]);
433412}
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