561
return string[simple_length(string)] == '\0';
562
}
563
564
-void parse_exclude_pattern(const char **pattern,
564
+void parse_path_pattern(const char **pattern,
565
int *patternlen,
566
unsigned *flags,
567
int *nowildcardlen)
599
*patternlen = len;
600
}
601
602
-void add_exclude(const char *string, const char *base,
602
+void add_pattern(const char *string, const char *base,
603
int baselen, struct pattern_list *pl, int srcpos)
604
{
605
struct path_pattern *pattern;
607
unsigned flags;
608
int nowildcardlen;
609
610
- parse_exclude_pattern(&string, &patternlen, &flags, &nowildcardlen);
610
+ parse_path_pattern(&string, &patternlen, &flags, &nowildcardlen);
611
if (flags & PATTERN_FLAG_MUSTBEDIR) {
612
FLEXPTR_ALLOC_MEM(pattern, pattern, string, patternlen);
613
} else {
646
* Frees memory within pl which was allocated for exclude patterns and
647
* the file buffer. Does not free pl itself.
648
*/
649
-void clear_exclude_list(struct pattern_list *pl)
649
+void clear_pattern_list(struct pattern_list *pl)
650
{
651
int i;
652
762
dir->dirs[i]->recurse = 0;
763
}
764
765
-static int add_excludes_from_buffer(char *buf, size_t size,
765
+static int add_patterns_from_buffer(char *buf, size_t size,
766
const char *base, int baselen,
767
struct pattern_list *pl);
768
772
* exclude rules in "pl".
773
*
774
* If "ss" is not NULL, compute SHA-1 of the exclude file and fill
775
- * stat data from disk (only valid if add_excludes returns zero). If
775
+ * stat data from disk (only valid if add_patterns returns zero). If
776
* ss_valid is non-zero, "ss" must contain good value as input.
777
*/
778
-static int add_excludes(const char *fname, const char *base, int baselen,
778
+static int add_patterns(const char *fname, const char *base, int baselen,
779
struct pattern_list *pl, struct index_state *istate,
780
struct oid_stat *oid_stat)
781
{
837
}
838
}
839
840
- add_excludes_from_buffer(buf, size, base, baselen, pl);
840
+ add_patterns_from_buffer(buf, size, base, baselen, pl);
841
return 0;
842
}
843
844
-static int add_excludes_from_buffer(char *buf, size_t size,
844
+static int add_patterns_from_buffer(char *buf, size_t size,
845
const char *base, int baselen,
846
struct pattern_list *pl)
847
{
860
if (entry != buf + i && entry[0] != '#') {
861
buf[i - (i && buf[i-1] == '\r')] = 0;
862
trim_trailing_spaces(entry);
863
- add_exclude(entry, base, baselen, pl, lineno);
863
+ add_pattern(entry, base, baselen, pl, lineno);
864
}
865
lineno++;
866
entry = buf + i + 1;
869
return 0;
870
}
871
872
-int add_excludes_from_file_to_list(const char *fname, const char *base,
872
+int add_patterns_from_file_to_list(const char *fname, const char *base,
873
int baselen, struct pattern_list *pl,
874
struct index_state *istate)
875
{
876
- return add_excludes(fname, base, baselen, pl, istate, NULL);
876
+ return add_patterns(fname, base, baselen, pl, istate, NULL);
877
}
878
879
-int add_excludes_from_blob_to_list(
879
+int add_patterns_from_blob_to_list(
880
struct object_id *oid,
881
const char *base, int baselen,
882
struct pattern_list *pl)
889
if (r != 1)
890
return r;
891
892
- add_excludes_from_buffer(buf, size, base, baselen, pl);
892
+ add_patterns_from_buffer(buf, size, base, baselen, pl);
893
return 0;
894
}
895
896
-struct pattern_list *add_exclude_list(struct dir_struct *dir,
896
+struct pattern_list *add_pattern_list(struct dir_struct *dir,
897
int group_type, const char *src)
898
{
899
struct pattern_list *pl;
910
/*
911
* Used to set up core.excludesfile and .git/info/exclude lists.
912
*/
913
-static void add_excludes_from_file_1(struct dir_struct *dir, const char *fname,
913
+static void add_patterns_from_file_1(struct dir_struct *dir, const char *fname,
914
struct oid_stat *oid_stat)
915
{
916
struct pattern_list *pl;
921
*/
922
if (!dir->untracked)
923
dir->unmanaged_exclude_files++;
924
- pl = add_exclude_list(dir, EXC_FILE, fname);
925
- if (add_excludes(fname, "", 0, pl, NULL, oid_stat) < 0)
924
+ pl = add_pattern_list(dir, EXC_FILE, fname);
925
+ if (add_patterns(fname, "", 0, pl, NULL, oid_stat) < 0)
926
die(_("cannot use %s as an exclude file"), fname);
927
}
928
929
-void add_excludes_from_file(struct dir_struct *dir, const char *fname)
929
+void add_patterns_from_file(struct dir_struct *dir, const char *fname)
930
{
931
dir->unmanaged_exclude_files++; /* see validate_untracked_cache() */
932
- add_excludes_from_file_1(dir, fname, NULL);
932
+ add_patterns_from_file_1(dir, fname, NULL);
933
}
934
935
int match_basename(const char *basename, int basenamelen,
1021
* any, determines the fate. Returns the exclude_list element which
1022
* matched, or NULL for undecided.
1023
*/
1024
-static struct path_pattern *last_exclude_matching_from_list(const char *pathname,
1024
+static struct path_pattern *last_matching_pattern_from_list(const char *pathname,
1025
int pathlen,
1026
const char *basename,
1027
int *dtype,
1080
struct pattern_list *pl, struct index_state *istate)
1081
{
1082
struct path_pattern *pattern;
1083
- pattern = last_exclude_matching_from_list(pathname, pathlen, basename,
1083
+ pattern = last_matching_pattern_from_list(pathname, pathlen, basename,
1084
dtype, pl, istate);
1085
if (pattern)
1086
return pattern->flags & PATTERN_FLAG_NEGATIVE ? 0 : 1;
1087
return -1; /* undecided */
1088
}
1089
1090
-static struct path_pattern *last_exclude_matching_from_lists(
1090
+static struct path_pattern *last_matching_pattern_from_lists(
1091
struct dir_struct *dir, struct index_state *istate,
1092
const char *pathname, int pathlen,
1093
const char *basename, int *dtype_p)
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--) {
1101
- pattern = last_exclude_matching_from_list(
1101
+ pattern = last_matching_pattern_from_list(
1102
pathname, pathlen, basename, dtype_p,
1103
&group->pl[j], istate);
1104
if (pattern)
1137
dir->exclude_stack = stk->prev;
1138
dir->pattern = NULL;
1139
free((char *)pl->src); /* see strbuf_detach() below */
1140
- clear_exclude_list(pl);
1140
+ clear_pattern_list(pl);
1141
free(stk);
1142
group->nr--;
1143
}
1184
stk->baselen = cp - base;
1185
stk->exclude_ix = group->nr;
1186
stk->ucd = untracked;
1187
- pl = add_exclude_list(dir, EXC_DIRS, NULL);
1187
+ pl = add_pattern_list(dir, EXC_DIRS, NULL);
1188
strbuf_add(&dir->basebuf, base + current, stk->baselen - current);
1189
assert(stk->baselen == dir->basebuf.len);
1190
1192
if (stk->baselen) {
1193
int dt = DT_DIR;
1194
dir->basebuf.buf[stk->baselen - 1] = 0;
1195
- dir->pattern = last_exclude_matching_from_lists(dir,
1195
+ dir->pattern = last_matching_pattern_from_lists(dir,
1196
istate,
1197
dir->basebuf.buf, stk->baselen - 1,
1198
dir->basebuf.buf + current, &dt);
1228
* need fname to remain unchanged to ensure the src
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
1231
+ * of add_pattern_list provide stable strings, so we
1232
* strbuf_detach() and free() here in the caller.
1233
*/
1234
struct strbuf sb = STRBUF_INIT;
1235
strbuf_addbuf(&sb, &dir->basebuf);
1236
strbuf_addstr(&sb, dir->exclude_per_dir);
1237
pl->src = strbuf_detach(&sb, NULL);
1238
- add_excludes(pl->src, pl->src, stk->baselen, pl, istate,
1238
+ add_patterns(pl->src, pl->src, stk->baselen, pl, istate,
1239
untracked ? &oid_stat : NULL);
1240
}
1241
/*
1242
* NEEDSWORK: when untracked cache is enabled, prep_exclude()
1243
* will first be called in valid_cached_dir() then maybe many
1244
- * times more in last_exclude_matching(). When the cache is
1245
- * used, last_exclude_matching() will not be called and
1244
+ * times more in last_matching_pattern(). When the cache is
1245
+ * used, last_matching_pattern() will not be called and
1246
* reading .gitignore content will be a waste.
1247
*
1248
* So when it's called by valid_cached_dir() and we can get
1249
* .gitignore SHA-1 from the index (i.e. .gitignore is not
1250
* modified on work tree), we could delay reading the
1251
* .gitignore content until we absolutely need it in
1252
- * last_exclude_matching(). Be careful about ignore rule
1252
+ * last_matching_pattern(). Be careful about ignore rule
1253
* order, though, if you do that.
1254
*/
1255
if (untracked &&
1269
* Returns the exclude_list element which matched, or NULL for
1270
* undecided.
1271
*/
1272
-struct path_pattern *last_exclude_matching(struct dir_struct *dir,
1272
+struct path_pattern *last_matching_pattern(struct dir_struct *dir,
1273
struct index_state *istate,
1274
const char *pathname,
1275
int *dtype_p)
1283
if (dir->pattern)
1284
return dir->pattern;
1285
1286
- return last_exclude_matching_from_lists(dir, istate, pathname, pathlen,
1286
+ return last_matching_pattern_from_lists(dir, istate, pathname, pathlen,
1287
basename, dtype_p);
1288
}
1289
1296
const char *pathname, int *dtype_p)
1297
{
1298
struct path_pattern *pattern =
1299
- last_exclude_matching(dir, istate, pathname, dtype_p);
1299
+ last_matching_pattern(dir, istate, pathname, dtype_p);
1300
if (pattern)
1301
return pattern->flags & PATTERN_FLAG_NEGATIVE ? 0 : 1;
1302
return 0;
1811
1812
/*
1813
* prep_exclude will be called eventually on this directory,
1814
- * but it's called much later in last_exclude_matching(). We
1814
+ * but it's called much later in last_matching_pattern(). We
1815
* need it now to determine the validity of the cache for this
1816
* path. The next calls will be nearly no-op, the way
1817
* prep_exclude() is designed.
2491
if (!excludes_file)
2492
excludes_file = xdg_config_home("ignore");
2493
if (excludes_file && !access_or_warn(excludes_file, R_OK, 0))
2494
- add_excludes_from_file_1(dir, excludes_file,
2494
+ add_patterns_from_file_1(dir, excludes_file,
2495
dir->untracked ? &dir->ss_excludes_file : NULL);
2496
2497
/* per repository user preference */
2498
if (startup_info->have_repository) {
2499
const char *path = git_path_info_exclude();
2500
if (!access_or_warn(path, R_OK, 0))
2501
- add_excludes_from_file_1(dir, path,
2501
+ add_patterns_from_file_1(dir, path,
2502
dir->untracked ? &dir->ss_info_exclude : NULL);
2503
}
2504
}
2539
pl = &group->pl[j];
2540
if (i == EXC_DIRS)
2541
free((char *)pl->src);
2542
- clear_exclude_list(pl);
2542
+ clear_pattern_list(pl);
2543
}
2544
free(group->pl);
2545
}