[RFC PATCH 2/6] dir.h: replace pattern macros with enum in attr.h
- From
Mirko Faina <mroik@delayed.space>
- Date
- Oct 8, 2026, 12:06 UTC
- Message-ID
- <adbfbf5aab70bdf8cdb2ac080ed79a3144edcb8d.1791460418.git.mroik@delayed.space>
- In-Reply-To
- <cover.1791460418.git.mroik@delayed.space>
dir.h defines some macros that are used in the dir.c machinery for .gitignore files. These macros are only used for the pattern struct defined in attr.h so it really should belong there.
Remove the macro definitions from dir.h and replace them with the pattern_flags enum in attr.h.
Signed-off-by: Mirko Faina <mroik@delayed.space> --- attr.h | 9 ++++++++- builtin/check-ignore.c | 1 + builtin/sparse-checkout.c | 1 + dir.c | 5 +++-- dir.h | 8 ++------ 5 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/attr.h b/attr.h index a04a521092..c083d47df5 100644 --- a/attr.h +++ b/attr.h @@ -250,11 +250,18 @@ struct attr_state { const char *setto; }; +enum pattern_flags { + PATTERN_FLAG_NODIR = 1, + PATTERN_FLAG_ENDSWITH = 4, + PATTERN_FLAG_MUSTBEDIR = 8, + PATTERN_FLAG_NEGATIVE = 16, +}; + struct pattern { const char *pattern; int patternlen; int nowildcardlen; - unsigned flags; /* PATTERN_FLAG_* */ + enum pattern_flags flags; /* PATTERN_FLAG_* */ }; /* diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c index 644c9a414f..fdf7610178 100644 --- a/builtin/check-ignore.c +++ b/builtin/check-ignore.c @@ -9,6 +9,7 @@ #include "parse-options.h" #include "submodule.h" #include "write-or-die.h" +#include "attr.h" static int quiet, verbose, stdin_paths, show_non_matching, no_index; static const char * const check_ignore_usage[] = { diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index cb4a037b77..83981e2b1e 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -20,6 +20,7 @@ #include "setup.h" #include "sparse-index.h" #include "worktree.h" +#include "attr.h" static const char *empty_base = ""; diff --git a/dir.c b/dir.c index d896e7be4b..c6342c882a 100644 --- a/dir.c +++ b/dir.c @@ -36,6 +36,7 @@ #include "trace2.h" #include "tree.h" #include "hex.h" +#include "attr.h" /* * The maximum size of a pattern/exclude file. If the file exceeds this size @@ -701,7 +702,7 @@ int no_wildcard(const char *string) void parse_path_pattern(const char **pattern, int *patternlen, - unsigned *flags, + enum pattern_flags *flags, int *nowildcardlen) { const char *p = *pattern; @@ -979,7 +980,7 @@ void add_pattern(const char *string, const char *base, { struct path_pattern *pattern; int patternlen; - unsigned flags; + enum pattern_flags flags; int nowildcardlen; parse_path_pattern(&string, &patternlen, &flags, &nowildcardlen); diff --git a/dir.h b/dir.h index 83e0f648a8..210ee8a98d 100644 --- a/dir.h +++ b/dir.h @@ -6,6 +6,7 @@ #include "pathspec.h" #include "statinfo.h" #include "strbuf.h" +#include "attr.h" struct repository; @@ -49,11 +50,6 @@ struct dir_entry { char name[FLEX_ARRAY]; /* more */ }; -#define PATTERN_FLAG_NODIR 1 -#define PATTERN_FLAG_ENDSWITH 4 -#define PATTERN_FLAG_MUSTBEDIR 8 -#define PATTERN_FLAG_NEGATIVE 16 - struct path_pattern { /* * This allows callers of last_matching_pattern() etc. @@ -469,7 +465,7 @@ int add_patterns_from_blob_to_list(struct object_id *oid, int add_patterns_from_buffer(char *buf, size_t size, const char *base, int baselen, struct pattern_list *pl); -void parse_path_pattern(const char **string, int *patternlen, unsigned *flags, int *nowildcardlen); +void parse_path_pattern(const char **string, int *patternlen, enum pattern_flags *flags, int *nowildcardlen); void add_pattern(const char *string, const char *base, int baselen, struct pattern_list *pl, int srcpos); void clear_pattern_list(struct pattern_list *pl);
-- 2.56.0