Skip to content

Commit 9755f70

Browse files
committed
Merge branch 'ds/include-exclude'
The internal code originally invented for ".gitignore" processing got reshuffled and renamed to make it less tied to "excluding" and stress more that it is about "matching", as it has been reused for things like sparse checkout specification that want to check if a path is "included". * ds/include-exclude: unpack-trees: rename 'is_excluded_from_list()' treewide: rename 'exclude' methods to 'pattern' treewide: rename 'EXCL_FLAG_' to 'PATTERN_FLAG_' treewide: rename 'struct exclude_list' to 'struct pattern_list' treewide: rename 'struct exclude' to 'struct path_pattern'
2 parents 93fc876 + 468ce99 commit 9755f70

File tree

12 files changed

+285
-252
lines changed

12 files changed

+285
-252
lines changed

Documentation/RelNotes/2.7.1.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Fixes since v2.7
1010
setting GIT_WORK_TREE environment themselves.
1111

1212
* The "exclude_list" structure has the usual "alloc, nr" pair of
13-
fields to be used by ALLOC_GROW(), but clear_exclude_list() forgot
13+
fields to be used by ALLOC_GROW(), but clear_pattern_list() forgot
1414
to reset 'alloc' to 0 when it cleared 'nr' to discard the managed
1515
array.
1616

Documentation/RelNotes/2.8.0.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ notes for details).
270270
setting GIT_WORK_TREE environment themselves.
271271

272272
* The "exclude_list" structure has the usual "alloc, nr" pair of
273-
fields to be used by ALLOC_GROW(), but clear_exclude_list() forgot
273+
fields to be used by ALLOC_GROW(), but clear_pattern_list() forgot
274274
to reset 'alloc' to 0 when it cleared 'nr' to discard the managed
275275
array.
276276

Documentation/technical/api-directory-listing.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ marked. If you to exclude files, make sure you have loaded index first.
111111
* Prepare `struct dir_struct dir` and clear it with `memset(&dir, 0,
112112
sizeof(dir))`.
113113

114-
* To add single exclude pattern, call `add_exclude_list()` and then
115-
`add_exclude()`.
114+
* To add single exclude pattern, call `add_pattern_list()` and then
115+
`add_pattern()`.
116116

117117
* To add patterns from a file (e.g. `.git/info/exclude`), call
118-
`add_excludes_from_file()` , and/or set `dir.exclude_per_dir`. A
118+
`add_patterns_from_file()` , and/or set `dir.exclude_per_dir`. A
119119
short-hand function `setup_standard_excludes()` can be used to set
120120
up the standard set of exclude settings.
121121

attr.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ struct pattern {
259259
const char *pattern;
260260
int patternlen;
261261
int nowildcardlen;
262-
unsigned flags; /* EXC_FLAG_* */
262+
unsigned flags; /* PATTERN_FLAG_* */
263263
};
264264

265265
/*
@@ -400,11 +400,11 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
400400
char *p = (char *)&(res->state[num_attr]);
401401
memcpy(p, name, namelen);
402402
res->u.pat.pattern = p;
403-
parse_exclude_pattern(&res->u.pat.pattern,
403+
parse_path_pattern(&res->u.pat.pattern,
404404
&res->u.pat.patternlen,
405405
&res->u.pat.flags,
406406
&res->u.pat.nowildcardlen);
407-
if (res->u.pat.flags & EXC_FLAG_NEGATIVE) {
407+
if (res->u.pat.flags & PATTERN_FLAG_NEGATIVE) {
408408
warning(_("Negative patterns are ignored in git attributes\n"
409409
"Use '\\!' for literal leading exclamation."));
410410
goto fail_return;
@@ -991,10 +991,10 @@ static int path_matches(const char *pathname, int pathlen,
991991
int prefix = pat->nowildcardlen;
992992
int isdir = (pathlen && pathname[pathlen - 1] == '/');
993993

994-
if ((pat->flags & EXC_FLAG_MUSTBEDIR) && !isdir)
994+
if ((pat->flags & PATTERN_FLAG_MUSTBEDIR) && !isdir)
995995
return 0;
996996

997-
if (pat->flags & EXC_FLAG_NODIR) {
997+
if (pat->flags & PATTERN_FLAG_NODIR) {
998998
return match_basename(pathname + basename_offset,
999999
pathlen - basename_offset - isdir,
10001000
pattern, prefix,

builtin/check-ignore.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ static const struct option check_ignore_options[] = {
3232
OPT_END()
3333
};
3434

35-
static void output_exclude(const char *path, struct exclude *exclude)
35+
static void output_pattern(const char *path, struct path_pattern *pattern)
3636
{
37-
char *bang = (exclude && exclude->flags & EXC_FLAG_NEGATIVE) ? "!" : "";
38-
char *slash = (exclude && exclude->flags & EXC_FLAG_MUSTBEDIR) ? "/" : "";
37+
char *bang = (pattern && pattern->flags & PATTERN_FLAG_NEGATIVE) ? "!" : "";
38+
char *slash = (pattern && pattern->flags & PATTERN_FLAG_MUSTBEDIR) ? "/" : "";
3939
if (!nul_term_line) {
4040
if (!verbose) {
4141
write_name_quoted(path, stdout, '\n');
4242
} else {
43-
if (exclude) {
44-
quote_c_style(exclude->el->src, NULL, stdout, 0);
43+
if (pattern) {
44+
quote_c_style(pattern->pl->src, NULL, stdout, 0);
4545
printf(":%d:%s%s%s\t",
46-
exclude->srcpos,
47-
bang, exclude->pattern, slash);
46+
pattern->srcpos,
47+
bang, pattern->pattern, slash);
4848
}
4949
else {
5050
printf("::\t");
@@ -56,11 +56,11 @@ static void output_exclude(const char *path, struct exclude *exclude)
5656
if (!verbose) {
5757
printf("%s%c", path, '\0');
5858
} else {
59-
if (exclude)
59+
if (pattern)
6060
printf("%s%c%d%c%s%s%s%c%s%c",
61-
exclude->el->src, '\0',
62-
exclude->srcpos, '\0',
63-
bang, exclude->pattern, slash, '\0',
61+
pattern->pl->src, '\0',
62+
pattern->srcpos, '\0',
63+
bang, pattern->pattern, slash, '\0',
6464
path, '\0');
6565
else
6666
printf("%c%c%c%s%c", '\0', '\0', '\0', path, '\0');
@@ -74,7 +74,7 @@ static int check_ignore(struct dir_struct *dir,
7474
const char *full_path;
7575
char *seen;
7676
int num_ignored = 0, i;
77-
struct exclude *exclude;
77+
struct path_pattern *pattern;
7878
struct pathspec pathspec;
7979

8080
if (!argc) {
@@ -103,15 +103,15 @@ static int check_ignore(struct dir_struct *dir,
103103
seen = find_pathspecs_matching_against_index(&pathspec, &the_index);
104104
for (i = 0; i < pathspec.nr; i++) {
105105
full_path = pathspec.items[i].match;
106-
exclude = NULL;
106+
pattern = NULL;
107107
if (!seen[i]) {
108108
int dtype = DT_UNKNOWN;
109-
exclude = last_exclude_matching(dir, &the_index,
109+
pattern = last_matching_pattern(dir, &the_index,
110110
full_path, &dtype);
111111
}
112-
if (!quiet && (exclude || show_non_matching))
113-
output_exclude(pathspec.items[i].original, exclude);
114-
if (exclude)
112+
if (!quiet && (pattern || show_non_matching))
113+
output_pattern(pathspec.items[i].original, pattern);
114+
if (pattern)
115115
num_ignored++;
116116
}
117117
free(seen);

builtin/clean.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ static int filter_by_patterns_cmd(void)
648648
struct strbuf confirm = STRBUF_INIT;
649649
struct strbuf **ignore_list;
650650
struct string_list_item *item;
651-
struct exclude_list *el;
651+
struct pattern_list *pl;
652652
int changed = -1, i;
653653

654654
for (;;) {
@@ -671,15 +671,15 @@ static int filter_by_patterns_cmd(void)
671671
break;
672672

673673
memset(&dir, 0, sizeof(dir));
674-
el = add_exclude_list(&dir, EXC_CMDL, "manual exclude");
674+
pl = add_pattern_list(&dir, EXC_CMDL, "manual exclude");
675675
ignore_list = strbuf_split_max(&confirm, ' ', 0);
676676

677677
for (i = 0; ignore_list[i]; i++) {
678678
strbuf_trim(ignore_list[i]);
679679
if (!ignore_list[i]->len)
680680
continue;
681681

682-
add_exclude(ignore_list[i]->buf, "", 0, el, -(i+1));
682+
add_pattern(ignore_list[i]->buf, "", 0, pl, -(i+1));
683683
}
684684

685685
changed = 0;
@@ -901,7 +901,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
901901
struct pathspec pathspec;
902902
struct strbuf buf = STRBUF_INIT;
903903
struct string_list exclude_list = STRING_LIST_INIT_NODUP;
904-
struct exclude_list *el;
904+
struct pattern_list *pl;
905905
struct string_list_item *item;
906906
const char *qname;
907907
struct option options[] = {
@@ -958,9 +958,9 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
958958
if (!ignored)
959959
setup_standard_excludes(&dir);
960960

961-
el = add_exclude_list(&dir, EXC_CMDL, "--exclude option");
961+
pl = add_pattern_list(&dir, EXC_CMDL, "--exclude option");
962962
for (i = 0; i < exclude_list.nr; i++)
963-
add_exclude(exclude_list.items[i].string, "", 0, el, -(i+1));
963+
add_pattern(exclude_list.items[i].string, "", 0, pl, -(i+1));
964964

965965
parse_pathspec(&pathspec, 0,
966966
PATHSPEC_PREFER_CWD,

builtin/ls-files.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ static int option_parse_exclude_from(const struct option *opt,
492492
BUG_ON_OPT_NEG(unset);
493493

494494
exc_given = 1;
495-
add_excludes_from_file(dir, arg);
495+
add_patterns_from_file(dir, arg);
496496

497497
return 0;
498498
}
@@ -516,7 +516,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
516516
int require_work_tree = 0, show_tag = 0, i;
517517
const char *max_prefix;
518518
struct dir_struct dir;
519-
struct exclude_list *el;
519+
struct pattern_list *pl;
520520
struct string_list exclude_list = STRING_LIST_INIT_NODUP;
521521
struct option builtin_ls_files_options[] = {
522522
/* Think twice before adding "--nul" synonym to this */
@@ -594,9 +594,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
594594

595595
argc = parse_options(argc, argv, prefix, builtin_ls_files_options,
596596
ls_files_usage, 0);
597-
el = add_exclude_list(&dir, EXC_CMDL, "--exclude option");
597+
pl = add_pattern_list(&dir, EXC_CMDL, "--exclude option");
598598
for (i = 0; i < exclude_list.nr; i++) {
599-
add_exclude(exclude_list.items[i].string, "", 0, el, --exclude_args);
599+
add_pattern(exclude_list.items[i].string, "", 0, pl, --exclude_args);
600600
}
601601
if (show_tag || show_valid_bit || show_fsmonitor_bit) {
602602
tag_cached = "H ";

0 commit comments

Comments
 (0)