Skip to content

Commit caa3d55

Browse files
derrickstoleegitster
authored andcommitted
treewide: rename 'struct exclude_list' to 'struct pattern_list'
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 renames 'struct exclude_list' to 'struct pattern_list' and renames several variables called 'el' to 'pl'. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ab8db61 commit caa3d55

File tree

8 files changed

+100
-100
lines changed

8 files changed

+100
-100
lines changed

builtin/check-ignore.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static void output_pattern(const char *path, struct path_pattern *pattern)
4141
write_name_quoted(path, stdout, '\n');
4242
} else {
4343
if (pattern) {
44-
quote_c_style(pattern->el->src, NULL, stdout, 0);
44+
quote_c_style(pattern->pl->src, NULL, stdout, 0);
4545
printf(":%d:%s%s%s\t",
4646
pattern->srcpos,
4747
bang, pattern->pattern, slash);
@@ -58,7 +58,7 @@ static void output_pattern(const char *path, struct path_pattern *pattern)
5858
} else {
5959
if (pattern)
6060
printf("%s%c%d%c%s%s%s%c%s%c",
61-
pattern->el->src, '\0',
61+
pattern->pl->src, '\0',
6262
pattern->srcpos, '\0',
6363
bang, pattern->pattern, slash, '\0',
6464
path, '\0');

builtin/clean.c

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

653653
for (;;) {
@@ -670,15 +670,15 @@ static int filter_by_patterns_cmd(void)
670670
break;
671671

672672
memset(&dir, 0, sizeof(dir));
673-
el = add_exclude_list(&dir, EXC_CMDL, "manual exclude");
673+
pl = add_exclude_list(&dir, EXC_CMDL, "manual exclude");
674674
ignore_list = strbuf_split_max(&confirm, ' ', 0);
675675

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

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

684684
changed = 0;
@@ -900,7 +900,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
900900
struct pathspec pathspec;
901901
struct strbuf buf = STRBUF_INIT;
902902
struct string_list exclude_list = STRING_LIST_INIT_NODUP;
903-
struct exclude_list *el;
903+
struct pattern_list *pl;
904904
struct string_list_item *item;
905905
const char *qname;
906906
struct option options[] = {
@@ -957,9 +957,9 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
957957
if (!ignored)
958958
setup_standard_excludes(&dir);
959959

960-
el = add_exclude_list(&dir, EXC_CMDL, "--exclude option");
960+
pl = add_exclude_list(&dir, EXC_CMDL, "--exclude option");
961961
for (i = 0; i < exclude_list.nr; i++)
962-
add_exclude(exclude_list.items[i].string, "", 0, el, -(i+1));
962+
add_exclude(exclude_list.items[i].string, "", 0, pl, -(i+1));
963963

964964
parse_pathspec(&pathspec, 0,
965965
PATHSPEC_PREFER_CWD,

builtin/ls-files.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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_exclude_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_exclude(exclude_list.items[i].string, "", 0, pl, --exclude_args);
600600
}
601601
if (show_tag || show_valid_bit || show_fsmonitor_bit) {
602602
tag_cached = "H ";

dir.c

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ void parse_exclude_pattern(const char **pattern,
600600
}
601601

602602
void add_exclude(const char *string, const char *base,
603-
int baselen, struct exclude_list *el, int srcpos)
603+
int baselen, struct pattern_list *pl, int srcpos)
604604
{
605605
struct path_pattern *pattern;
606606
int patternlen;
@@ -620,9 +620,9 @@ void add_exclude(const char *string, const char *base,
620620
pattern->baselen = baselen;
621621
pattern->flags = flags;
622622
pattern->srcpos = srcpos;
623-
ALLOC_GROW(el->patterns, el->nr + 1, el->alloc);
624-
el->patterns[el->nr++] = pattern;
625-
pattern->el = el;
623+
ALLOC_GROW(pl->patterns, pl->nr + 1, pl->alloc);
624+
pl->patterns[pl->nr++] = pattern;
625+
pattern->pl = pl;
626626
}
627627

628628
static int read_skip_worktree_file_from_index(const struct index_state *istate,
@@ -643,19 +643,19 @@ static int read_skip_worktree_file_from_index(const struct index_state *istate,
643643
}
644644

645645
/*
646-
* Frees memory within el which was allocated for exclude patterns and
647-
* the file buffer. Does not free el itself.
646+
* Frees memory within pl which was allocated for exclude patterns and
647+
* the file buffer. Does not free pl itself.
648648
*/
649-
void clear_exclude_list(struct exclude_list *el)
649+
void clear_exclude_list(struct pattern_list *pl)
650650
{
651651
int i;
652652

653-
for (i = 0; i < el->nr; i++)
654-
free(el->patterns[i]);
655-
free(el->patterns);
656-
free(el->filebuf);
653+
for (i = 0; i < pl->nr; i++)
654+
free(pl->patterns[i]);
655+
free(pl->patterns);
656+
free(pl->filebuf);
657657

658-
memset(el, 0, sizeof(*el));
658+
memset(pl, 0, sizeof(*pl));
659659
}
660660

661661
static void trim_trailing_spaces(char *buf)
@@ -764,19 +764,19 @@ static void invalidate_directory(struct untracked_cache *uc,
764764

765765
static int add_excludes_from_buffer(char *buf, size_t size,
766766
const char *base, int baselen,
767-
struct exclude_list *el);
767+
struct pattern_list *pl);
768768

769769
/*
770770
* Given a file with name "fname", read it (either from disk, or from
771771
* an index if 'istate' is non-null), parse it and store the
772-
* exclude rules in "el".
772+
* exclude rules in "pl".
773773
*
774774
* If "ss" is not NULL, compute SHA-1 of the exclude file and fill
775775
* stat data from disk (only valid if add_excludes returns zero). If
776776
* ss_valid is non-zero, "ss" must contain good value as input.
777777
*/
778778
static int add_excludes(const char *fname, const char *base, int baselen,
779-
struct exclude_list *el, struct index_state *istate,
779+
struct pattern_list *pl, struct index_state *istate,
780780
struct oid_stat *oid_stat)
781781
{
782782
struct stat st;
@@ -837,21 +837,21 @@ static int add_excludes(const char *fname, const char *base, int baselen,
837837
}
838838
}
839839

840-
add_excludes_from_buffer(buf, size, base, baselen, el);
840+
add_excludes_from_buffer(buf, size, base, baselen, pl);
841841
return 0;
842842
}
843843

844844
static int add_excludes_from_buffer(char *buf, size_t size,
845845
const char *base, int baselen,
846-
struct exclude_list *el)
846+
struct pattern_list *pl)
847847
{
848848
int i, lineno = 1;
849849
char *entry;
850850

851-
el->filebuf = buf;
851+
pl->filebuf = buf;
852852

853853
if (skip_utf8_bom(&buf, size))
854-
size -= buf - el->filebuf;
854+
size -= buf - pl->filebuf;
855855

856856
entry = buf;
857857

@@ -860,7 +860,7 @@ static int add_excludes_from_buffer(char *buf, size_t size,
860860
if (entry != buf + i && entry[0] != '#') {
861861
buf[i - (i && buf[i-1] == '\r')] = 0;
862862
trim_trailing_spaces(entry);
863-
add_exclude(entry, base, baselen, el, lineno);
863+
add_exclude(entry, base, baselen, pl, lineno);
864864
}
865865
lineno++;
866866
entry = buf + i + 1;
@@ -870,16 +870,16 @@ static int add_excludes_from_buffer(char *buf, size_t size,
870870
}
871871

872872
int add_excludes_from_file_to_list(const char *fname, const char *base,
873-
int baselen, struct exclude_list *el,
873+
int baselen, struct pattern_list *pl,
874874
struct index_state *istate)
875875
{
876-
return add_excludes(fname, base, baselen, el, istate, NULL);
876+
return add_excludes(fname, base, baselen, pl, istate, NULL);
877877
}
878878

879879
int add_excludes_from_blob_to_list(
880880
struct object_id *oid,
881881
const char *base, int baselen,
882-
struct exclude_list *el)
882+
struct pattern_list *pl)
883883
{
884884
char *buf;
885885
size_t size;
@@ -889,22 +889,22 @@ int add_excludes_from_blob_to_list(
889889
if (r != 1)
890890
return r;
891891

892-
add_excludes_from_buffer(buf, size, base, baselen, el);
892+
add_excludes_from_buffer(buf, size, base, baselen, pl);
893893
return 0;
894894
}
895895

896-
struct exclude_list *add_exclude_list(struct dir_struct *dir,
896+
struct pattern_list *add_exclude_list(struct dir_struct *dir,
897897
int group_type, const char *src)
898898
{
899-
struct exclude_list *el;
899+
struct pattern_list *pl;
900900
struct exclude_list_group *group;
901901

902902
group = &dir->exclude_list_group[group_type];
903-
ALLOC_GROW(group->el, group->nr + 1, group->alloc);
904-
el = &group->el[group->nr++];
905-
memset(el, 0, sizeof(*el));
906-
el->src = src;
907-
return el;
903+
ALLOC_GROW(group->pl, group->nr + 1, group->alloc);
904+
pl = &group->pl[group->nr++];
905+
memset(pl, 0, sizeof(*pl));
906+
pl->src = src;
907+
return pl;
908908
}
909909

910910
/*
@@ -913,16 +913,16 @@ struct exclude_list *add_exclude_list(struct dir_struct *dir,
913913
static void add_excludes_from_file_1(struct dir_struct *dir, const char *fname,
914914
struct oid_stat *oid_stat)
915915
{
916-
struct exclude_list *el;
916+
struct pattern_list *pl;
917917
/*
918918
* catch setup_standard_excludes() that's called before
919919
* dir->untracked is assigned. That function behaves
920920
* differently when dir->untracked is non-NULL.
921921
*/
922922
if (!dir->untracked)
923923
dir->unmanaged_exclude_files++;
924-
el = add_exclude_list(dir, EXC_FILE, fname);
925-
if (add_excludes(fname, "", 0, el, NULL, oid_stat) < 0)
924+
pl = add_exclude_list(dir, EXC_FILE, fname);
925+
if (add_excludes(fname, "", 0, pl, NULL, oid_stat) < 0)
926926
die(_("cannot use %s as an exclude file"), fname);
927927
}
928928

@@ -1025,17 +1025,17 @@ static struct path_pattern *last_exclude_matching_from_list(const char *pathname
10251025
int pathlen,
10261026
const char *basename,
10271027
int *dtype,
1028-
struct exclude_list *el,
1028+
struct pattern_list *pl,
10291029
struct index_state *istate)
10301030
{
10311031
struct path_pattern *res = NULL; /* undecided */
10321032
int i;
10331033

1034-
if (!el->nr)
1034+
if (!pl->nr)
10351035
return NULL; /* undefined */
10361036

1037-
for (i = el->nr - 1; 0 <= i; i--) {
1038-
struct path_pattern *pattern = el->patterns[i];
1037+
for (i = pl->nr - 1; 0 <= i; i--) {
1038+
struct path_pattern *pattern = pl->patterns[i];
10391039
const char *exclude = pattern->pattern;
10401040
int prefix = pattern->nowildcardlen;
10411041

@@ -1077,11 +1077,11 @@ static struct path_pattern *last_exclude_matching_from_list(const char *pathname
10771077
*/
10781078
int is_excluded_from_list(const char *pathname,
10791079
int pathlen, const char *basename, int *dtype,
1080-
struct exclude_list *el, struct index_state *istate)
1080+
struct pattern_list *pl, struct index_state *istate)
10811081
{
10821082
struct path_pattern *pattern;
10831083
pattern = last_exclude_matching_from_list(pathname, pathlen, basename,
1084-
dtype, el, istate);
1084+
dtype, pl, istate);
10851085
if (pattern)
10861086
return pattern->flags & EXC_FLAG_NEGATIVE ? 0 : 1;
10871087
return -1; /* undecided */
@@ -1100,7 +1100,7 @@ static struct path_pattern *last_exclude_matching_from_lists(
11001100
for (j = group->nr - 1; j >= 0; j--) {
11011101
pattern = last_exclude_matching_from_list(
11021102
pathname, pathlen, basename, dtype_p,
1103-
&group->el[j], istate);
1103+
&group->pl[j], istate);
11041104
if (pattern)
11051105
return pattern;
11061106
}
@@ -1117,7 +1117,7 @@ static void prep_exclude(struct dir_struct *dir,
11171117
const char *base, int baselen)
11181118
{
11191119
struct exclude_list_group *group;
1120-
struct exclude_list *el;
1120+
struct pattern_list *pl;
11211121
struct exclude_stack *stk = NULL;
11221122
struct untracked_cache_dir *untracked;
11231123
int current;
@@ -1133,11 +1133,11 @@ static void prep_exclude(struct dir_struct *dir,
11331133
if (stk->baselen <= baselen &&
11341134
!strncmp(dir->basebuf.buf, base, stk->baselen))
11351135
break;
1136-
el = &group->el[dir->exclude_stack->exclude_ix];
1136+
pl = &group->pl[dir->exclude_stack->exclude_ix];
11371137
dir->exclude_stack = stk->prev;
11381138
dir->pattern = NULL;
1139-
free((char *)el->src); /* see strbuf_detach() below */
1140-
clear_exclude_list(el);
1139+
free((char *)pl->src); /* see strbuf_detach() below */
1140+
clear_exclude_list(pl);
11411141
free(stk);
11421142
group->nr--;
11431143
}
@@ -1184,7 +1184,7 @@ static void prep_exclude(struct dir_struct *dir,
11841184
stk->baselen = cp - base;
11851185
stk->exclude_ix = group->nr;
11861186
stk->ucd = untracked;
1187-
el = add_exclude_list(dir, EXC_DIRS, NULL);
1187+
pl = add_exclude_list(dir, EXC_DIRS, NULL);
11881188
strbuf_add(&dir->basebuf, base + current, stk->baselen - current);
11891189
assert(stk->baselen == dir->basebuf.len);
11901190

@@ -1234,8 +1234,8 @@ static void prep_exclude(struct dir_struct *dir,
12341234
struct strbuf sb = STRBUF_INIT;
12351235
strbuf_addbuf(&sb, &dir->basebuf);
12361236
strbuf_addstr(&sb, dir->exclude_per_dir);
1237-
el->src = strbuf_detach(&sb, NULL);
1238-
add_excludes(el->src, el->src, stk->baselen, el, istate,
1237+
pl->src = strbuf_detach(&sb, NULL);
1238+
add_excludes(pl->src, pl->src, stk->baselen, pl, istate,
12391239
untracked ? &oid_stat : NULL);
12401240
}
12411241
/*
@@ -2530,18 +2530,18 @@ void clear_directory(struct dir_struct *dir)
25302530
{
25312531
int i, j;
25322532
struct exclude_list_group *group;
2533-
struct exclude_list *el;
2533+
struct pattern_list *pl;
25342534
struct exclude_stack *stk;
25352535

25362536
for (i = EXC_CMDL; i <= EXC_FILE; i++) {
25372537
group = &dir->exclude_list_group[i];
25382538
for (j = 0; j < group->nr; j++) {
2539-
el = &group->el[j];
2539+
pl = &group->pl[j];
25402540
if (i == EXC_DIRS)
2541-
free((char *)el->src);
2542-
clear_exclude_list(el);
2541+
free((char *)pl->src);
2542+
clear_exclude_list(pl);
25432543
}
2544-
free(group->el);
2544+
free(group->pl);
25452545
}
25462546

25472547
stk = dir->exclude_stack;

0 commit comments

Comments
 (0)