Thread (79 messages) 79 messages, 4 authors, 2022-03-10
STALE1554d
Revisions (4)
  1. v1 [diff vs current]
  2. v2 [diff vs current]
  3. v3 [diff vs current]
  4. v4 current

[PATCH v4 02/13] list-objects-filter-options: create copy helper

From: Derrick Stolee via GitGitGadget <hidden>
Date: 2022-03-09 16:02:47
Subsystem: the rest · Maintainer: Linus Torvalds

From: Derrick Stolee <redacted>

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 <redacted>
---
 list-objects-filter-options.c | 19 +++++++++++++++++++
 list-objects-filter-options.h |  4 ++++
 2 files changed, 23 insertions(+)
diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c
index fd8d59f653a..449d53af69f 100644
--- a/list-objects-filter-options.c
+++ b/list-objects-filter-options.c
@@ -415,3 +415,22 @@ void partial_clone_get_default_filter_spec(
 					 &errbuf);
 	strbuf_release(&errbuf);
 }
+
+void list_objects_filter_copy(
+	struct list_objects_filter_options *dest,
+	const struct list_objects_filter_options *src)
+{
+	int i;
+	struct string_list_item *item;
+
+	/* Copy everything. We will overwrite the pointers shortly. */
+	memcpy(dest, src, sizeof(struct list_objects_filter_options));
+
+	string_list_init_dup(&dest->filter_spec);
+	for_each_string_list_item(item, &src->filter_spec)
+		string_list_append(&dest->filter_spec, item->string);
+
+	ALLOC_ARRAY(dest->sub, dest->sub_alloc);
+	for (i = 0; i < src->sub_nr; i++)
+		list_objects_filter_copy(&dest->sub[i], &src->sub[i]);
+}
diff --git a/list-objects-filter-options.h b/list-objects-filter-options.h
index da5b6737e27..425c38cae9d 100644
--- a/list-objects-filter-options.h
+++ b/list-objects-filter-options.h
@@ -132,4 +132,8 @@ void partial_clone_get_default_filter_spec(
 	struct list_objects_filter_options *filter_options,
 	const char *remote);
 
+void list_objects_filter_copy(
+	struct list_objects_filter_options *dest,
+	const struct list_objects_filter_options *src);
+
 #endif /* LIST_OBJECTS_FILTER_OPTIONS_H */
-- 
gitgitgadget
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help