602
void add_exclude(const char *string, const char *base,
603
int baselen, struct exclude_list *el, int srcpos)
604
{
605
- struct exclude *x;
605
+ struct path_pattern *pattern;
606
int patternlen;
607
unsigned flags;
608
int nowildcardlen;
609
610
parse_exclude_pattern(&string, &patternlen, &flags, &nowildcardlen);
611
if (flags & EXC_FLAG_MUSTBEDIR) {
612
- FLEXPTR_ALLOC_MEM(x, pattern, string, patternlen);
612
+ FLEXPTR_ALLOC_MEM(pattern, pattern, string, patternlen);
613
} else {
614
- x = xmalloc(sizeof(*x));
615
- x->pattern = string;
614
+ pattern = xmalloc(sizeof(*pattern));
615
+ pattern->pattern = string;
616
}
617
- x->patternlen = patternlen;
618
- x->nowildcardlen = nowildcardlen;
619
- x->base = base;
620
- x->baselen = baselen;
621
- x->flags = flags;
622
- x->srcpos = srcpos;
623
- ALLOC_GROW(el->excludes, el->nr + 1, el->alloc);
624
- el->excludes[el->nr++] = x;
625
- x->el = el;
617
+ pattern->patternlen = patternlen;
618
+ pattern->nowildcardlen = nowildcardlen;
619
+ pattern->base = base;
620
+ pattern->baselen = baselen;
621
+ pattern->flags = flags;
622
+ pattern->srcpos = srcpos;
623
+ ALLOC_GROW(el->patterns, el->nr + 1, el->alloc);
624
+ el->patterns[el->nr++] = pattern;
625
+ pattern->el = el;
626
}
627
628
static int read_skip_worktree_file_from_index(const struct index_state *istate,
651
int i;
652
653
for (i = 0; i < el->nr; i++)
654
- free(el->excludes[i]);
655
- free(el->excludes);
654
+ free(el->patterns[i]);
655
+ free(el->patterns);
656
free(el->filebuf);
657
658
memset(el, 0, sizeof(*el));
1021
* any, determines the fate. Returns the exclude_list element which
1022
* matched, or NULL for undecided.
1023
*/
1024
-static struct exclude *last_exclude_matching_from_list(const char *pathname,
1024
+static struct path_pattern *last_exclude_matching_from_list(const char *pathname,
1025
int pathlen,
1026
const char *basename,
1027
int *dtype,
1028
struct exclude_list *el,
1029
struct index_state *istate)
1030
{
1031
- struct exclude *exc = NULL; /* undecided */
1031
+ struct path_pattern *res = NULL; /* undecided */
1032
int i;
1033
1034
if (!el->nr)
1035
return NULL; /* undefined */
1036
1037
for (i = el->nr - 1; 0 <= i; i--) {
1038
- struct exclude *x = el->excludes[i];
1039
- const char *exclude = x->pattern;
1040
- int prefix = x->nowildcardlen;
1038
+ struct path_pattern *pattern = el->patterns[i];
1039
+ const char *exclude = pattern->pattern;
1040
+ int prefix = pattern->nowildcardlen;
1041
1042
- if (x->flags & EXC_FLAG_MUSTBEDIR) {
1042
+ if (pattern->flags & EXC_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 (x->flags & EXC_FLAG_NODIR) {
1049
+ if (pattern->flags & EXC_FLAG_NODIR) {
1050
if (match_basename(basename,
1051
pathlen - (basename - pathname),
1052
- exclude, prefix, x->patternlen,
1053
- x->flags)) {
1054
- exc = x;
1052
+ exclude, prefix, pattern->patternlen,
1053
+ pattern->flags)) {
1054
+ res = pattern;
1055
break;
1056
}
1057
continue;
1058
}
1059
1060
- assert(x->baselen == 0 || x->base[x->baselen - 1] == '/');
1060
+ assert(pattern->baselen == 0 ||
1061
+ pattern->base[pattern->baselen - 1] == '/');
1062
if (match_pathname(pathname, pathlen,
1062
- x->base, x->baselen ? x->baselen - 1 : 0,
1063
- exclude, prefix, x->patternlen, x->flags)) {
1064
- exc = x;
1063
+ pattern->base,
1064
+ pattern->baselen ? pattern->baselen - 1 : 0,
1065
+ exclude, prefix, pattern->patternlen,
1066
+ pattern->flags)) {
1067
+ res = pattern;
1068
break;
1069
}
1070
}
1068
- return exc;
1071
+ return res;
1072
}
1073
1074
/*
1079
int pathlen, const char *basename, int *dtype,
1080
struct exclude_list *el, struct index_state *istate)
1081
{
1079
- struct exclude *exclude;
1080
- exclude = last_exclude_matching_from_list(pathname, pathlen, basename,
1082
+ struct path_pattern *pattern;
1083
+ pattern = last_exclude_matching_from_list(pathname, pathlen, basename,
1084
dtype, el, istate);
1082
- if (exclude)
1083
- return exclude->flags & EXC_FLAG_NEGATIVE ? 0 : 1;
1085
+ if (pattern)
1086
+ return pattern->flags & EXC_FLAG_NEGATIVE ? 0 : 1;
1087
return -1; /* undecided */
1088
}
1089
1087
-static struct exclude *last_exclude_matching_from_lists(struct dir_struct *dir,
1088
- struct index_state *istate,
1089
- const char *pathname, int pathlen, const char *basename,
1090
- int *dtype_p)
1090
+static struct path_pattern *last_exclude_matching_from_lists(
1091
+ struct dir_struct *dir, struct index_state *istate,
1092
+ const char *pathname, int pathlen,
1093
+ const char *basename, int *dtype_p)
1094
{
1095
int i, j;
1096
struct exclude_list_group *group;
1094
- struct exclude *exclude;
1097
+ struct path_pattern *pattern;
1098
for (i = EXC_CMDL; i <= EXC_FILE; i++) {
1099
group = &dir->exclude_list_group[i];
1100
for (j = group->nr - 1; j >= 0; j--) {
1098
- exclude = last_exclude_matching_from_list(
1101
+ pattern = last_exclude_matching_from_list(
1102
pathname, pathlen, basename, dtype_p,
1103
&group->el[j], istate);
1101
- if (exclude)
1102
- return exclude;
1104
+ if (pattern)
1105
+ return pattern;
1106
}
1107
}
1108
return NULL;
1135
break;
1136
el = &group->el[dir->exclude_stack->exclude_ix];
1137
dir->exclude_stack = stk->prev;
1135
- dir->exclude = NULL;
1138
+ dir->pattern = NULL;
1139
free((char *)el->src); /* see strbuf_detach() below */
1140
clear_exclude_list(el);
1141
free(stk);
1143
}
1144
1145
/* Skip traversing into sub directories if the parent is excluded */
1143
- if (dir->exclude)
1146
+ if (dir->pattern)
1147
return;
1148
1149
/*
1192
if (stk->baselen) {
1193
int dt = DT_DIR;
1194
dir->basebuf.buf[stk->baselen - 1] = 0;
1192
- dir->exclude = last_exclude_matching_from_lists(dir,
1195
+ dir->pattern = last_exclude_matching_from_lists(dir,
1196
istate,
1197
dir->basebuf.buf, stk->baselen - 1,
1198
dir->basebuf.buf + current, &dt);
1199
dir->basebuf.buf[stk->baselen - 1] = '/';
1197
- if (dir->exclude &&
1198
- dir->exclude->flags & EXC_FLAG_NEGATIVE)
1199
- dir->exclude = NULL;
1200
- if (dir->exclude) {
1200
+ if (dir->pattern &&
1201
+ dir->pattern->flags & EXC_FLAG_NEGATIVE)
1202
+ dir->pattern = NULL;
1203
+ if (dir->pattern) {
1204
dir->exclude_stack = stk;
1205
return;
1206
}
1226
/*
1227
* dir->basebuf gets reused by the traversal, but we
1228
* need fname to remain unchanged to ensure the src
1226
- * member of each struct exclude correctly
1229
+ * member of each struct path_pattern correctly
1230
* back-references its source file. Other invocations
1231
* of add_exclude_list provide stable strings, so we
1232
* strbuf_detach() and free() here in the caller.
1269
* Returns the exclude_list element which matched, or NULL for
1270
* undecided.
1271
*/
1269
-struct exclude *last_exclude_matching(struct dir_struct *dir,
1272
+struct path_pattern *last_exclude_matching(struct dir_struct *dir,
1273
struct index_state *istate,
1274
const char *pathname,
1275
int *dtype_p)
1280
1281
prep_exclude(dir, istate, pathname, basename-pathname);
1282
1280
- if (dir->exclude)
1281
- return dir->exclude;
1283
+ if (dir->pattern)
1284
+ return dir->pattern;
1285
1286
return last_exclude_matching_from_lists(dir, istate, pathname, pathlen,
1287
basename, dtype_p);
1295
int is_excluded(struct dir_struct *dir, struct index_state *istate,
1296
const char *pathname, int *dtype_p)
1297
{
1295
- struct exclude *exclude =
1298
+ struct path_pattern *pattern =
1299
last_exclude_matching(dir, istate, pathname, dtype_p);
1297
- if (exclude)
1298
- return exclude->flags & EXC_FLAG_NEGATIVE ? 0 : 1;
1300
+ if (pattern)
1301
+ return pattern->flags & EXC_FLAG_NEGATIVE ? 0 : 1;
1302
return 0;
1303
}
1304