treewide: rename 'EXCL_FLAG_' to 'PATTERN_FLAG_'

The first consumer of pattern-matching filenames was the .gitignore feature. In that context, storing a list of patterns as a 'struct exclude_list' makes sense. However, the sparse-checkout feature then adopted these structures and methods, but with the opposite meaning: these patterns match the files that should be included! It would be clearer to rename this entire library as a "pattern matching" library, and the callers apply exclusion/inclusion logic accordingly based on their needs. This commit replaces 'EXCL_FLAG_' to 'PATTERN_FLAG_' in the names of the flags used on 'struct path_pattern'. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Sep 3, 2019 at 11:04 UTC 4ff89ee52cd3cf6e38a11bb94e43df1b53c56eec
4 files changed +22 -22
attr.c
+4 -4
@@ -259,7 +259,7 @@ struct pattern {
259 const char *pattern;
260 int patternlen;
261 int nowildcardlen;
262 - unsigned flags; /* EXC_FLAG_* */
262 + unsigned flags; /* PATTERN_FLAG_* */
263 };
264
265 /*
@@ -404,7 +404,7 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
404 &res->u.pat.patternlen,
405 &res->u.pat.flags,
406 &res->u.pat.nowildcardlen);
407 - if (res->u.pat.flags & EXC_FLAG_NEGATIVE) {
407 + if (res->u.pat.flags & PATTERN_FLAG_NEGATIVE) {
408 warning(_("Negative patterns are ignored in git attributes\n"
409 "Use '\\!' for literal leading exclamation."));
410 goto fail_return;
@@ -991,10 +991,10 @@ static int path_matches(const char *pathname, int pathlen,
991 int prefix = pat->nowildcardlen;
992 int isdir = (pathlen && pathname[pathlen - 1] == '/');
993
994 - if ((pat->flags & EXC_FLAG_MUSTBEDIR) && !isdir)
994 + if ((pat->flags & PATTERN_FLAG_MUSTBEDIR) && !isdir)
995 return 0;
996
997 - if (pat->flags & EXC_FLAG_NODIR) {
997 + if (pat->flags & PATTERN_FLAG_NODIR) {
998 return match_basename(pathname + basename_offset,
999 pathlen - basename_offset - isdir,
1000 pattern, prefix,
builtin/check-ignore.c
+2 -2
@@ -34,8 +34,8 @@ static const struct option check_ignore_options[] = {
34
35 static void output_pattern(const char *path, struct path_pattern *pattern)
36 {
37 - char *bang = (pattern && pattern->flags & EXC_FLAG_NEGATIVE) ? "!" : "";
38 - char *slash = (pattern && pattern->flags & EXC_FLAG_MUSTBEDIR) ? "/" : "";
37 + char *bang = (pattern && pattern->flags & PATTERN_FLAG_NEGATIVE) ? "!" : "";
38 + char *slash = (pattern && pattern->flags & PATTERN_FLAG_MUSTBEDIR) ? "/" : "";
39 if (!nul_term_line) {
40 if (!verbose) {
41 write_name_quoted(path, stdout, '\n');
dir.c
+11 -11
@@ -571,20 +571,20 @@ void parse_exclude_pattern(const char **pattern,
571
572 *flags = 0;
573 if (*p == '!') {
574 - *flags |= EXC_FLAG_NEGATIVE;
574 + *flags |= PATTERN_FLAG_NEGATIVE;
575 p++;
576 }
577 len = strlen(p);
578 if (len && p[len - 1] == '/') {
579 len--;
580 - *flags |= EXC_FLAG_MUSTBEDIR;
580 + *flags |= PATTERN_FLAG_MUSTBEDIR;
581 }
582 for (i = 0; i < len; i++) {
583 if (p[i] == '/')
584 break;
585 }
586 if (i == len)
587 - *flags |= EXC_FLAG_NODIR;
587 + *flags |= PATTERN_FLAG_NODIR;
588 *nowildcardlen = simple_length(p);
589 /*
590 * we should have excluded the trailing slash from 'p' too,
@@ -594,7 +594,7 @@ void parse_exclude_pattern(const char **pattern,
594 if (*nowildcardlen > len)
595 *nowildcardlen = len;
596 if (*p == '*' && no_wildcard(p + 1))
597 - *flags |= EXC_FLAG_ENDSWITH;
597 + *flags |= PATTERN_FLAG_ENDSWITH;
598 *pattern = p;
599 *patternlen = len;
600 }
@@ -608,7 +608,7 @@ void add_exclude(const char *string, const char *base,
608 int nowildcardlen;
609
610 parse_exclude_pattern(&string, &patternlen, &flags, &nowildcardlen);
611 - if (flags & EXC_FLAG_MUSTBEDIR) {
611 + if (flags & PATTERN_FLAG_MUSTBEDIR) {
612 FLEXPTR_ALLOC_MEM(pattern, pattern, string, patternlen);
613 } else {
614 pattern = xmalloc(sizeof(*pattern));
@@ -940,7 +940,7 @@ int match_basename(const char *basename, int basenamelen,
940 if (patternlen == basenamelen &&
941 !fspathncmp(pattern, basename, basenamelen))
942 return 1;
943 - } else if (flags & EXC_FLAG_ENDSWITH) {
943 + } else if (flags & PATTERN_FLAG_ENDSWITH) {
944 /* "*literal" matching against "fooliteral" */
945 if (patternlen - 1 <= basenamelen &&
946 !fspathncmp(pattern + 1,
@@ -1039,14 +1039,14 @@ static struct path_pattern *last_exclude_matching_from_list(const char *pathname
1039 const char *exclude = pattern->pattern;
1040 int prefix = pattern->nowildcardlen;
1041
1042 - if (pattern->flags & EXC_FLAG_MUSTBEDIR) {
1042 + if (pattern->flags & PATTERN_FLAG_MUSTBEDIR) {
1043 if (*dtype == DT_UNKNOWN)
1044 *dtype = get_dtype(NULL, istate, pathname, pathlen);
1045 if (*dtype != DT_DIR)
1046 continue;
1047 }
1048
1049 - if (pattern->flags & EXC_FLAG_NODIR) {
1049 + if (pattern->flags & PATTERN_FLAG_NODIR) {
1050 if (match_basename(basename,
1051 pathlen - (basename - pathname),
1052 exclude, prefix, pattern->patternlen,
@@ -1083,7 +1083,7 @@ int is_excluded_from_list(const char *pathname,
1083 pattern = last_exclude_matching_from_list(pathname, pathlen, basename,
1084 dtype, pl, istate);
1085 if (pattern)
1086 - return pattern->flags & EXC_FLAG_NEGATIVE ? 0 : 1;
1086 + return pattern->flags & PATTERN_FLAG_NEGATIVE ? 0 : 1;
1087 return -1; /* undecided */
1088 }
1089
@@ -1198,7 +1198,7 @@ static void prep_exclude(struct dir_struct *dir,
1198 dir->basebuf.buf + current, &dt);
1199 dir->basebuf.buf[stk->baselen - 1] = '/';
1200 if (dir->pattern &&
1201 - dir->pattern->flags & EXC_FLAG_NEGATIVE)
1201 + dir->pattern->flags & PATTERN_FLAG_NEGATIVE)
1202 dir->pattern = NULL;
1203 if (dir->pattern) {
1204 dir->exclude_stack = stk;
@@ -1298,7 +1298,7 @@ int is_excluded(struct dir_struct *dir, struct index_state *istate,
1298 struct path_pattern *pattern =
1299 last_exclude_matching(dir, istate, pathname, dtype_p);
1300 if (pattern)
1301 - return pattern->flags & EXC_FLAG_NEGATIVE ? 0 : 1;
1301 + return pattern->flags & PATTERN_FLAG_NEGATIVE ? 0 : 1;
1302 return 0;
1303 }
1304
dir.h
+5 -5
@@ -11,10 +11,10 @@ struct dir_entry {
11 char name[FLEX_ARRAY]; /* more */
12 };
13
14 -#define EXC_FLAG_NODIR 1
15 -#define EXC_FLAG_ENDSWITH 4
16 -#define EXC_FLAG_MUSTBEDIR 8
17 -#define EXC_FLAG_NEGATIVE 16
14 +#define PATTERN_FLAG_NODIR 1
15 +#define PATTERN_FLAG_ENDSWITH 4
16 +#define PATTERN_FLAG_MUSTBEDIR 8
17 +#define PATTERN_FLAG_NEGATIVE 16
18
19 struct path_pattern {
20 /*
@@ -28,7 +28,7 @@ struct path_pattern {
28 int nowildcardlen;
29 const char *base;
30 int baselen;
31 - unsigned flags; /* EXC_FLAG_* */
31 + unsigned flags; /* PATTERN_FLAG_* */
32
33 /*
34 * Counting starts from 1 for line numbers in ignore files,