From: Ivan Shapovalov <intelfx@intelfx.name>
To: git@vger.kernel.org
Cc: "Ivan Shapovalov" <intelfx@intelfx.name>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Junio C Hamano" <gitster@pobox.com>
Subject: [PATCH 1/3] clean, dir: add and use new helper `add_patterns_from_string_list()`
Date: Mon, 10 Feb 2025 23:14:37 +0400 [thread overview]
Message-ID: <20250210191504.309661-2-intelfx@intelfx.name> (raw)
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
next prev parent reply other threads:[~2025-02-10 19:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-10 19:14 [PATCH 0/3] clean: add `config.exclude` and `--remove-excluded` Ivan Shapovalov
2025-02-10 19:14 ` Ivan Shapovalov [this message]
2025-02-10 19:14 ` [PATCH 2/3] clean: rename `ignored` -> `remove_ignored` Ivan Shapovalov
2025-02-10 19:14 ` [PATCH 3/3] clean: add `config.exclude` and `--remove-excluded` Ivan Shapovalov
2025-02-11 23:00 ` Junio C Hamano
2025-02-11 18:37 ` [PATCH 0/3] " Junio C Hamano
2025-02-11 18:47 ` Ivan Shapovalov
2025-02-11 21:24 ` Junio C Hamano
2025-02-11 21:42 ` Ivan Shapovalov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250210191504.309661-2-intelfx@intelfx.name \
--to=intelfx@intelfx.name \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox