git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC 08/11] string_list_append_list(): new function

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Dec 4, 2013, 05:44 UTC
Message-ID
<1386135890-13954-9-git-send-email-mhagger@alum.mit.edu>
In-Reply-To
<1386135890-13954-1-git-send-email-mhagger@alum.mit.edu>

Add a new function that appends the strings from one string_list onto another string_list.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 Documentation/technical/api-string-list.txt | 10 ++++++++--
 string-list.c                               |  9 +++++++++
 string-list.h                               |  8 ++++++++
 3 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/Documentation/technical/api-string-list.txt b/Documentation/technical/api-string-list.txt
index 20be348..2072cf7 100644
--- a/Documentation/technical/api-string-list.txt
+++ b/Documentation/technical/api-string-list.txt
@@ -22,8 +22,9 @@ member (you need this if you add things later) and you should set the
 `nr` and `alloc` members in that case, too.
 
 . Adds new items to the list, using `string_list_append`,
-  `string_list_append_nodup`, `string_list_insert`,
-  `string_list_split`, and/or `string_list_split_in_place`.
+  `string_list_append_nodup`, `string_list_append_list`,
+  `string_list_insert`, `string_list_split`, and/or
+  `string_list_split_in_place`.
 
 . Can check if a string is in the list using `string_list_has_string` or
   `unsorted_string_list_has_string` and get it from the list using
@@ -141,6 +142,11 @@ write `string_list_insert(...)->util = ...;`.
 	ownership of a malloc()ed string to a `string_list` that has
 	`strdup_string` set.
 
+`string_list_append_list`::
+
+	Append the strings from one string_list to the end of another
+	one.
+
 `sort_string_list`::
 
 	Sort the list's entries by string value in `strcmp()` order.
diff --git a/string-list.c b/string-list.c
index aabb25e..803acd1 100644
--- a/string-list.c
+++ b/string-list.c
@@ -212,6 +212,15 @@ struct string_list_item *string_list_append(struct string_list *list,
 			list->strdup_strings ? xstrdup(string) : (char *)string);
 }
 
+void string_list_append_list(struct string_list *dst, struct string_list *src)
+{
+	struct string_list_item *item;
+
+	ALLOC_GROW(dst->items, dst->nr + src->nr, dst->alloc);
+	for_each_string_list_item(item, src)
+		string_list_append(dst, item->string);
+}
+
 /* Yuck */
 static compare_strings_fn compare_for_qsort;
 
diff --git a/string-list.h b/string-list.h
index de6769c..7b0ae86 100644
--- a/string-list.h
+++ b/string-list.h
@@ -76,6 +76,14 @@ void string_list_remove_duplicates(struct string_list *sorted_list, int free_uti
 struct string_list_item *string_list_append(struct string_list *list, const char *string);
 
 /*
+ * Add all strings from src to the end of dst.  If dst->strdup_string
+ * is set, then the strings are copied; otherwise the new
+ * string_list_entries refer to the input strings.  src is left
+ * unchanged.
+ */
+void string_list_append_list(struct string_list *dst, struct string_list *src);
+
+/*
  * Like string_list_append(), except string is never copied.  When
  * list->strdup_strings is set, this function can be used to hand
  * ownership of a malloc()ed string to list without making an extra
-- 
1.8.4.3
Previous: Michael HaggertyNext: Michael Haggerty
Message 11 of 15 in “[RFC 00/11] Make reference pruning more configurable”
  1. Michael HaggertyDec 4, 2013
  2. 01/11 get_stale_heads(): allow limiting to refname patternsMichael Haggerty, Dec 4, 2013
  3. 02/11 remote.c: add infrastructure for parsing --prune optionsMichael Haggerty, Dec 4, 2013
  4. Duy NguyenDec 4, 2013
  5. Michael HaggertyDec 4, 2013
  6. 03/11 fetch: use the new functions for handling --prune optionsMichael Haggerty, Dec 4, 2013
  7. 04/11 remote: use the new functions for handling --prune optionsMichael Haggerty, Dec 4, 2013
  8. 05/11 remote.c: add infrastructure to handle --prune=<pattern>Michael Haggerty, Dec 4, 2013
  9. 06/11 fetch --prune: allow refname patterns to be specifiedMichael Haggerty, Dec 4, 2013
  10. 07/11 remote update --prune: allow refname patterns to be specifiedMichael Haggerty, Dec 4, 2013
  11. 08/11 string_list_append_list(): new functionMichael Haggerty, Dec 4, 2013
  12. 09/11 remote prune: allow --prune=<pattern> optionsMichael Haggerty, Dec 4, 2013
  13. 10/11 remote show: allow --prune=<pattern> optionsMichael Haggerty, Dec 4, 2013
  14. 11/11 remote: allow prune patterns to be configuredMichael Haggerty, Dec 4, 2013
  15. Junio C HamanoDec 4, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.