Skip to content

Commit 4a4c3f9

Browse files
derrickstoleegitster
authored andcommitted
list-objects-filter-options: create copy helper
As we add more embedded members with type 'struct list_objects_filter_options', it will be important to easily perform a deep copy across multiple such structs. Create list_objects_filter_copy() to satisfy this need. This method is recursive to match the recursive nature of the struct. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1f52cdf commit 4a4c3f9

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

list-objects-filter-options.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,3 +415,22 @@ void partial_clone_get_default_filter_spec(
415415
&errbuf);
416416
strbuf_release(&errbuf);
417417
}
418+
419+
void list_objects_filter_copy(
420+
struct list_objects_filter_options *dest,
421+
const struct list_objects_filter_options *src)
422+
{
423+
int i;
424+
struct string_list_item *item;
425+
426+
/* Copy everything. We will overwrite the pointers shortly. */
427+
memcpy(dest, src, sizeof(struct list_objects_filter_options));
428+
429+
string_list_init_dup(&dest->filter_spec);
430+
for_each_string_list_item(item, &src->filter_spec)
431+
string_list_append(&dest->filter_spec, item->string);
432+
433+
ALLOC_ARRAY(dest->sub, dest->sub_alloc);
434+
for (i = 0; i < src->sub_nr; i++)
435+
list_objects_filter_copy(&dest->sub[i], &src->sub[i]);
436+
}

list-objects-filter-options.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,8 @@ void partial_clone_get_default_filter_spec(
132132
struct list_objects_filter_options *filter_options,
133133
const char *remote);
134134

135+
void list_objects_filter_copy(
136+
struct list_objects_filter_options *dest,
137+
const struct list_objects_filter_options *src);
138+
135139
#endif /* LIST_OBJECTS_FILTER_OPTIONS_H */

0 commit comments

Comments
 (0)