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

[PATCH 5/5] string_list_add_refs_from_colon_sep(): use string_list_split()

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Nov 4, 2012, 07:07 UTC
Message-ID
<1352012830-13591-6-git-send-email-mhagger@alum.mit.edu>
In-Reply-To
<1352012830-13591-1-git-send-email-mhagger@alum.mit.edu>
It makes for simpler code than strbuf_split().
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 notes.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/notes.c b/notes.c
index 63b2a09..b823701 100644
--- a/notes.c
+++ b/notes.c
@@ -943,23 +943,18 @@ void string_list_add_refs_by_glob(struct string_list *list, const char *glob)
 void string_list_add_refs_from_colon_sep(struct string_list *list,
 					 const char *globs)
 {
-	struct strbuf globbuf = STRBUF_INIT;
-	struct strbuf **split;
+	struct string_list split = STRING_LIST_INIT_NODUP;
+	char *globs_copy = xstrdup(globs);
 	int i;
 
-	strbuf_addstr(&globbuf, globs);
-	split = strbuf_split(&globbuf, ':');
+	string_list_split_in_place(&split, globs_copy, ':', -1);
+	string_list_remove_empty_items(&split, 0);
 
-	for (i = 0; split[i]; i++) {
-		if (split[i]->len && split[i]->buf[split[i]->len-1] == ':')
-			strbuf_setlen(split[i], split[i]->len-1);
-		if (!split[i]->len)
-			continue;
-		string_list_add_refs_by_glob(list, split[i]->buf);
-	}
+	for (i = 0; i < split.nr; i++)
+		string_list_add_refs_by_glob(list, split.items[i].string);
 
-	strbuf_list_free(split);
-	strbuf_release(&globbuf);
+	string_list_clear(&split, 0);
+	free(globs_copy);
 }
 
 static int notes_display_config(const char *k, const char *v, void *cb)
-- 
1.8.0
Previous: Michael HaggertyNext: Jeff King
Message 6 of 8 in “Use string_lists when processing notes”
  1. 0/5 Use string_lists when processing notesMichael Haggerty, Nov 4, 2012
  2. 1/5 string_list: add a function string_list_remove_empty_items()Michael Haggerty, Nov 4, 2012
  3. 2/5 Initialize sort_uniq_list using named constantMichael Haggerty, Nov 4, 2012
  4. 3/5 combine_notes_cat_sort_uniq(): sort and dedup lines all at onceMichael Haggerty, Nov 4, 2012
  5. 4/5 notes: fix handling of colon-separated valuesMichael Haggerty, Nov 4, 2012
  6. 5/5 string_list_add_refs_from_colon_sep(): use string_list_split()Michael Haggerty, Nov 4, 2012
  7. Jeff KingNov 4, 2012
  8. Johan HerlandNov 6, 2012

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.