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

[PATCH 1/3] clean, dir: add and use new helper `add_patterns_from_string_list()`

From
Ivan Shapovalov <intelfx@intelfx.name>
Date
Feb 10, 2025, 19:14 UTC
Message-ID
<20250210191504.309661-2-intelfx@intelfx.name>
In-Reply-To
<20250210191504.309661-1-intelfx@intelfx.name>
Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
---
 builtin/clean.c |  5 +----
 dir.c           | 15 +++++++++++++++
 dir.h           |  4 ++++
 3 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/builtin/clean.c b/builtin/clean.c
index 053c94fc6b..eaddf6a06e 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -931,7 +931,6 @@ int cmd_clean(int argc,
 	struct pathspec pathspec;
 	struct strbuf buf = STRBUF_INIT;
 	struct string_list exclude_list = STRING_LIST_INIT_NODUP;
-	struct pattern_list *pl;
 	struct string_list_item *item;
 	const char *qname;
 	struct option options[] = {
@@ -1017,9 +1016,7 @@ int cmd_clean(int argc,
 	if (repo_read_index(the_repository) < 0)
 		die(_("index file corrupt"));
 
-	pl = add_pattern_list(&dir, EXC_CMDL, "--exclude option");
-	for (i = 0; i < exclude_list.nr; i++)
-		add_pattern(exclude_list.items[i].string, "", 0, pl, -(i+1));
+	add_patterns_from_string_list(&dir, EXC_CMDL, "--exclude option", &exclude_list);
 
 	parse_pathspec(&pathspec, 0,
 		       PATHSPEC_PREFER_CWD,
diff --git a/dir.c b/dir.c
index 5b2181e589..fa3fd53649 100644
--- a/dir.c
+++ b/dir.c
@@ -1263,6 +1263,21 @@ struct pattern_list *add_pattern_list(struct dir_struct *dir,
 	return pl;
 }
 
+/*
+ * Convenience function to convert a string_list into pattern_list.
+ */
+struct pattern_list *add_patterns_from_string_list(struct dir_struct *dir,
+						   int group_type,
+						   const char *src,
+						   struct string_list *sl)
+{
+	struct pattern_list *pl;
+	pl = add_pattern_list(dir, group_type, src);
+	for (int i = 0; i < sl->nr; i++)
+		add_pattern(sl->items[i].string, "", 0, pl, -(i+1));
+	return pl;
+}
+
 /*
  * Used to set up core.excludesfile and .git/info/exclude lists.
  */
diff --git a/dir.h b/dir.h
index a3a2f00f5d..eb843c9bb6 100644
--- a/dir.h
+++ b/dir.h
@@ -460,6 +460,10 @@ int hashmap_contains_parent(struct hashmap *map,
 			    struct strbuf *buffer);
 struct pattern_list *add_pattern_list(struct dir_struct *dir,
 				      int group_type, const char *src);
+struct pattern_list *add_patterns_from_string_list(struct dir_struct *dir,
+						   int group_type,
+						   const char *src,
+						   struct string_list *lst);
 int add_patterns_from_file_to_list(const char *fname, const char *base, int baselen,
 				   struct pattern_list *pl, struct index_state *istate,
 				   unsigned flags);
-- 
2.48.1.5.g9188e14f140
Previous: Ivan ShapovalovNext: Ivan Shapovalov
Message 2 of 9 in “clean: add `config.exclude` and `--remove-excluded`”
  1. 0/3 clean: add `config.exclude` and `--remove-excluded`Ivan Shapovalov, Feb 10, 2025
  2. 1/3 clean, dir: add and use new helper `add_patterns_from_string_list()`Ivan Shapovalov, Feb 10, 2025
  3. 2/3 clean: rename `ignored` -> `remove_ignored`Ivan Shapovalov, Feb 10, 2025
  4. 3/3 clean: add `config.exclude` and `--remove-excluded`Ivan Shapovalov, Feb 10, 2025
  5. Junio C HamanoFeb 11, 2025
  6. Junio C HamanoFeb 11, 2025
  7. Ivan ShapovalovFeb 11, 2025
  8. Junio C HamanoFeb 11, 2025
  9. Ivan ShapovalovFeb 11, 2025

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.